hostapd: Compile time option for Config Knobs feature

The Config Knob feature is kept under compile time
flag "CONFIG_STA_POLICY", which is Enabled by default.

BUG=b:79511734
TEST=Sanity test on hostapd
    - Verified the compilation
    - Verified that following commands are not supported if Config knobs is disabled
      sta_policy_add
      sta_policy_del
      sta_policy_get
    - Verified that Config knobs works as it is if Enabled
CQ-DEPEND=CL:*624207

Change-Id: Ic404fc3bfaa9e54e405bf7c72d9c6e46627d4928
Reviewed-on: https://chromium-review.googlesource.com/1044385
Commit-Ready: Dheeraj KM <dheeraj.km@globaledgesoft.com>
Tested-by: Dheeraj KM <dheeraj.km@globaledgesoft.com>
Reviewed-by: Srinivasa duvvuri <sduvvuri@google.com>
diff --git a/hostapd/Android.mk b/hostapd/Android.mk
index b941a42..454a2bc 100644
--- a/hostapd/Android.mk
+++ b/hostapd/Android.mk
@@ -99,7 +99,12 @@
 OBJS += src/ap/bss_load.c
 OBJS += src/ap/neighbor_db.c
 OBJS += src/ap/rrm.c
+
+ifdef CONFIG_STA_POLICY
 OBJS += src/ap/sta_policy.c
+L_CFLAGS += -DCONFIG_STA_POLICY
+endif
+
 OBJS_d =
 OBJS_p =
 LIBS =
diff --git a/hostapd/Makefile b/hostapd/Makefile
index ab4233b..ea4ed67 100644
--- a/hostapd/Makefile
+++ b/hostapd/Makefile
@@ -69,7 +69,11 @@
 OBJS += ../src/ap/blacklist.o
 OBJS += ../src/ap/neighbor_db.o
 OBJS += ../src/ap/rrm.o
+
+ifdef CONFIG_STA_POLICY
 OBJS += ../src/ap/sta_policy.o
+CFLAGS += -DCONFIG_STA_POLICY
+endif
 
 OBJS_c = hostapd_cli.o ../src/common/wpa_ctrl.o ../src/utils/os_$(CONFIG_OS).o
 
diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
index cb08fcc..6add996 100644
--- a/hostapd/ctrl_iface.c
+++ b/hostapd/ctrl_iface.c
@@ -2597,6 +2597,7 @@
 	} else if (os_strncmp(buf, "UNI_CAST_PROBING ", 17) == 0) {
 		if (hostapd_ctrl_iface_uni_cast_probing(hapd, buf + 17))
 			reply_len = -1;
+#ifdef CONFIG_STA_POLICY
 	} else if (os_strncmp(buf, "STA_POLICY_ADD ", 15) == 0) {
 		if (sta_policy_add(hapd, (buf + 15)))
 			reply_len = -1;
@@ -2607,6 +2608,7 @@
 		reply_len = sta_policy_get(hapd, (buf + 15), reply, reply_size);
 		if (reply_len < 0)
 			reply_size = -1;
+#endif /* CONFIG_STA_POLICY */
 	} else {
 		os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
 		reply_len = 16;
diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c
index f17c330..9012045 100644
--- a/hostapd/hostapd_cli.c
+++ b/hostapd/hostapd_cli.c
@@ -1277,6 +1277,7 @@
 	return wpa_ctrl_command(ctrl, cmd);
 }
 
+#ifdef CONFIG_STA_POLICY
 static int hostapd_cli_cmd_sta_policy_get(struct wpa_ctrl *ctrl,
 					int argc, char *argv[])
 {
@@ -1346,6 +1347,7 @@
 
 	return wpa_ctrl_command(ctrl, cmd);
 }
+#endif /* CONFIG_STA_POLICY */
 
 struct hostapd_cli_cmd {
 	const char *cmd;
@@ -1415,9 +1417,11 @@
 	{ "blacklist_time", hostapd_cli_cmd_blacklist_timeout},
 	{ "blacklist_conn_attempt", hostapd_cli_cmd_blacklist_conn_attempt},
 	{ "uni_cast_probing", hostapd_cli_cmd_uni_cast_probing},
+#ifdef CONFIG_STA_POLICY
 	{ "sta_policy_add", hostapd_cli_cmd_sta_policy_add },
 	{ "sta_policy_del", hostapd_cli_cmd_sta_policy_del },
 	{ "sta_policy_get", hostapd_cli_cmd_sta_policy_get },
+#endif /* CONFIG_STA_POLICY */
 	{ NULL, NULL }
 };
 
diff --git a/src/ap/beacon.c b/src/ap/beacon.c
index bf44b6f..d117f13 100644
--- a/src/ap/beacon.c
+++ b/src/ap/beacon.c
@@ -35,6 +35,7 @@
 #include "ap/steering.h"
 #include "ap/monitor_sta.h"
 #include "ap/blacklist.h"
+#include "sta_policy.h"
 #endif
 
 #ifdef CONFIG_CLIENT_TAXONOMY
diff --git a/src/ap/ieee802_11_ht.c b/src/ap/ieee802_11_ht.c
index 934adc7..6b5033e 100644
--- a/src/ap/ieee802_11_ht.c
+++ b/src/ap/ieee802_11_ht.c
@@ -20,6 +20,9 @@
 #include "hw_features.h"
 #include "ap_drv_ops.h"
 
+#ifdef HOSTAPD
+#include "sta_policy.h"
+#endif /* HOSTAPD */
 
 u8 * hostapd_eid_ht_capabilities(struct hostapd_data *hapd, u8 *eid)
 {
diff --git a/src/ap/ieee802_11_vht.c b/src/ap/ieee802_11_vht.c
index 89ba6ee..cb87bef 100644
--- a/src/ap/ieee802_11_vht.c
+++ b/src/ap/ieee802_11_vht.c
@@ -17,6 +17,9 @@
 #include "sta_info.h"
 #include "beacon.h"
 #include "ieee802_11.h"
+#ifdef HOSTAPD
+#include "sta_policy.h"
+#endif /* HOSTAPD */
 
 
 u8 * hostapd_eid_vht_capabilities(struct hostapd_data *hapd, u8 *eid)
diff --git a/src/ap/sta_policy.c b/src/ap/sta_policy.c
index 3f0541a..5ebba76 100644
--- a/src/ap/sta_policy.c
+++ b/src/ap/sta_policy.c
@@ -45,6 +45,7 @@
 	return hapd->iface->bss[0]->conf->iface;
 }
 
+#ifdef CONFIG_STA_POLICY
 void sta_policy_begin_assoc_resp(struct hostapd_data *hapd, uint8_t *sta_addr)
 {
 	struct per_interface_config *i_cfg = hapd->iface->i_cfg;
@@ -66,6 +67,7 @@
 	os_memset(i_cfg->associating_sta, 0, ETH_ALEN);
 	i_cfg->assoc_resp = 0;
 }
+#endif /* CONFIG_STA_POLICY */
 
 static void sta_policy_dump(const struct sta_policy *cfg)
 {
@@ -744,6 +746,7 @@
 	return -1;
 }
 
+#ifdef CONFIG_STA_POLICY
 /**
  * Reply with the existing sta policy setting for the given sta
  * sta_id=00:00:00:00:00:00 indicates for all STA setting request
@@ -848,6 +851,7 @@
 
 	return ret;
 }
+#endif /* CONFIG_STA_POLICY */
 
 /**
  * Add supported rate and extended rate IE if sta policy rate settings exists
@@ -878,6 +882,7 @@
 	return pos;
 }
 
+#ifdef CONFIG_STA_POLICY
 /**
  * Copy the Existing STA policy supported rate to the buffer passed,
  * if the sta_id matched the list
@@ -1222,3 +1227,4 @@
 	os_free(i_cfg);
 	iface->i_cfg = NULL;
 }
+#endif /* CONFIG_STA_POLICY */
diff --git a/src/ap/sta_policy.h b/src/ap/sta_policy.h
index 83fcade..d9abeb5 100644
--- a/src/ap/sta_policy.h
+++ b/src/ap/sta_policy.h
@@ -125,6 +125,7 @@
  * Returns 0 - Success
  * 	  -1 - Failure
  */
+ #ifdef CONFIG_STA_POLICY
 int stapolicy_interface_init(struct hostapd_iface *iface);
 
 /**
@@ -207,4 +208,59 @@
  */
 void sta_policy_send_event(struct hostapd_data *, uint8_t *);
 
+/**
+ *  Update the HT Operation Info, only if the associating STA mac addr
+ *  is part of the sta policy list
+ */
+void sta_policy_update_ht_op_info(struct hostapd_data *hapd,
+                                  struct ieee80211_ht_operation *op);
+
+#else
+static inline int stapolicy_interface_init(struct hostapd_iface *iface)
+{
+	return 0;
+}
+
+static inline int stapolicy_cfg_init(struct hostapd_iface *iface) { return 0; }
+
+static inline void stapolicy_interface_deinit(struct hostapd_iface *iface) { }
+
+static inline u8 *sta_policy_copy_supp_rate(struct hostapd_data *hapd,
+                                            u8 *sta_addr, u8 *eid, size_t *res)
+{
+	*res = -1;
+	return eid;
+}
+
+static inline int sta_policy_get_supp_rate(struct hostapd_data *hapd,
+                                           u8 *sta_addr, u8 *rate)
+{
+	return 0;
+}
+
+static inline void sta_policy_begin_assoc_resp(struct hostapd_data *hapd,
+                                               uint8_t *sta_addr) { }
+
+static inline void sta_policy_end_assoc_resp(struct hostapd_data *hapd) { }
+
+static inline void sta_policy_update_capab(struct hostapd_data *hapd,
+                                           uint16_t *capability) { }
+
+static inline
+void sta_policy_update_ht_cap(struct hostapd_data *hapd,
+                              struct ieee80211_ht_capabilities *cap) { }
+
+static inline
+void sta_policy_update_vht_cap(struct hostapd_data *hapd,
+                               struct ieee80211_vht_capabilities *cap) { }
+
+static inline void sta_policy_send_event(struct hostapd_data *hapd,
+                                         uint8_t *sta_addr) { }
+
+static inline
+void sta_policy_update_ht_op_info(struct hostapd_data *hapd,
+                                  struct ieee80211_ht_operation *op) { }
+
+#endif /* CONFIG_STA_POLICY */
+
 #endif /* AP_CONFIG_KNOBS_H */