summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaveen.cprg <naveen.cprg@broadcom.com>2022-03-21 21:28:08 +0530
committerIsaac Chiou <isaacchiou@google.com>2022-04-15 04:22:15 +0000
commit46e29fefb507bfdec16517e202c2d3a00378cb02 (patch)
treef0cd4df1014daaf49d441c5672971a04816a3b06
parent9a9493c6abbf65acf9a14bdd20c375e34adcee88 (diff)
downloadwlan-46e29fefb507bfdec16517e202c2d3a00378cb02.tar.gz
Implementation of chre nan apis, nan status callbacks to chre and pre-emption
Bug: 206614765 Test: Have CHRE interact with APIs and validate NAN session starts Test: Use halutil commands to verify no crash happens Signed-off-by: naveen.cprg <naveen.cprg@broadcom.com> Change-Id: Ie181c0e666365cc5630b2461f2c13fa609698610
-rwxr-xr-xbcmdhd/wifi_hal/common.h38
-rwxr-xr-xbcmdhd/wifi_hal/nan.cpp224
-rwxr-xr-xbcmdhd/wifi_hal/wifi_hal.cpp3
3 files changed, 237 insertions, 28 deletions
diff --git a/bcmdhd/wifi_hal/common.h b/bcmdhd/wifi_hal/common.h
index 3cfa78f..ecc1abf 100755
--- a/bcmdhd/wifi_hal/common.h
+++ b/bcmdhd/wifi_hal/common.h
@@ -306,6 +306,12 @@ typedef struct {
bool is_virtual; // mark each iface as virtual or static
} interface_info;
+typedef enum {
+ NAN_STATE_DISABLED = 0,
+ NAN_STATE_AP = 1,
+ NAN_STATE_CHRE = 2,
+} nan_enab_state_t;
+
typedef struct {
struct nl_sock *cmd_sock; // command socket object
@@ -333,6 +339,8 @@ typedef struct {
int max_num_interfaces; // max number of interfaces
wifi_subsystem_restart_handler restart_handler; // trigger sub system handler
+ wifi_chre_handler chre_nan_cb; // chre CB for nan status
+ nan_enab_state_t nan_state; // Nan enable state
// add other details
} hal_info;
@@ -533,6 +541,36 @@ wifi_error twt_get_stats(wifi_interface_handle iface, u8 config_id, TwtStats* st
wifi_error twt_clear_stats(wifi_interface_handle iface, u8 config_id);
wifi_error wifi_trigger_subsystem_restart(wifi_handle handle);
+
+/**@brief nan_chre_enable_request
+ * Request from CHRE to enable NAN
+ * @param transaction id:
+ * @param wifi_interface_handle:
+ * @param NanEnableRequest:
+ * @return Synchronous wifi_error
+ */
+wifi_error nan_chre_enable_request(transaction_id id,
+ wifi_interface_handle iface,
+ NanEnableRequest* msg);
+
+/**@brief nan_chre_disable_request
+ * Request from CHRE to disable NAN
+ * @param transaction id:
+ * @param wifi_interface_handle:
+ * @return Synchronous wifi_error
+ */
+wifi_error nan_chre_disable_request(transaction_id id,
+ wifi_interface_handle iface);
+
+/**@brief nan_chre_register_handler
+ * Register chre handler to handle NAN status
+ * @param wifi_interface_handle:
+ * @param wifi_chre_handler:
+ * @return Synchronous wifi_error
+ */
+wifi_error nan_chre_register_handler(wifi_interface_handle iface,
+ wifi_chre_handler handler);
+
// some common macros
#define min(x, y) ((x) < (y) ? (x) : (y))
diff --git a/bcmdhd/wifi_hal/nan.cpp b/bcmdhd/wifi_hal/nan.cpp
index 8fea66b..52f29e3 100755
--- a/bcmdhd/wifi_hal/nan.cpp
+++ b/bcmdhd/wifi_hal/nan.cpp
@@ -290,7 +290,8 @@ typedef enum {
NAN_ATTRIBUTE_CHANNEL_INFO = 228,
NAN_ATTRIBUTE_NUM_CHANNELS = 229,
NAN_ATTRIBUTE_INSTANT_MODE_ENABLE = 230,
- NAN_ATTRIBUTE_INSTANT_COMM_CHAN = 231
+ NAN_ATTRIBUTE_INSTANT_COMM_CHAN = 231,
+ NAN_ATTRIBUTE_CHRE_REQUEST = 232,
} NAN_ATTRIBUTE;
typedef enum {
@@ -2543,6 +2544,7 @@ class NanMacControl : public WifiCommand
wifi_interface_handle mIface;
NanRequestType mType;
u32 mVersion;
+ u8 mChreNan;
public:
NanMacControl(wifi_interface_handle iface, int id,
@@ -2582,6 +2584,10 @@ class NanMacControl : public WifiCommand
mParams = params;
}
+ void setChreNan(u8 chre_nan) {
+ mChreNan = chre_nan;
+ }
+
int createRequest(WifiRequest& request) {
ALOGI("NAN CMD: %s\n", NanCmdToString(mType));
if (mType == NAN_REQUEST_ENABLE) {
@@ -2981,6 +2987,12 @@ class NanMacControl : public WifiCommand
ALOGI("%s: instant mode channel = %d\n", __func__, mParams->instant_mode_channel);
}
+ result = request.put_u8(NAN_ATTRIBUTE_CHRE_REQUEST, mChreNan);
+ if (result < 0) {
+ ALOGE("%s: Failing in config chreNan, result = %d\n", __func__, result);
+ return result;
+ }
+
request.attr_end(data);
NAN_DBG_EXIT();
return WIFI_SUCCESS;
@@ -2997,6 +3009,12 @@ class NanMacControl : public WifiCommand
nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);
+ result = request.put_u8(NAN_ATTRIBUTE_CHRE_REQUEST, mChreNan);
+ if (result < 0) {
+ ALOGE("%s: Failing in config chreNan, result = %d\n", __func__, result);
+ return result;
+ }
+
request.attr_end(data);
NAN_DBG_EXIT();
@@ -3322,6 +3340,10 @@ class NanMacControl : public WifiCommand
return NL_SKIP;
}
+ if (mChreNan) {
+ return NL_SKIP;
+ }
+
rsp_vndr_data = (nan_hal_resp_t *)reply.get_vendor_data();
ALOGI("NanMacControl::handleResponse\n");
if (mType == NAN_VERSION_INFO) {
@@ -3401,6 +3423,10 @@ class NanMacControl : public WifiCommand
return NL_SKIP;
}
+ if (mChreNan) {
+ return NL_SKIP;
+ }
+
for (nl_iterator it(vendor_data); it.has_next(); it.next()) {
attr_type = it.get_type();
@@ -4274,32 +4300,66 @@ void nan_reset_dbg_counters()
}
///////////////////////////////////////////////////////////////////////////////
-wifi_error nan_enable_request(transaction_id id,
- wifi_interface_handle iface, NanEnableRequest* msg)
+wifi_error nan_cmn_enabe_request(transaction_id id,
+ NanMacControl *cmd, NanEnableRequest* msg)
{
wifi_error ret = WIFI_SUCCESS;
- wifi_handle handle = getWifiHandle(iface);
- NanRequestType cmdType = NAN_REQUEST_ENABLE;
-
- ALOGI("Enabling Nan, Handle = %p\n", handle);
-
#ifdef CONFIG_BRCM
// check up nan enable params from Nan manager level
dump_NanEnableRequest(msg);
#endif /* CONFIG_BRCM */
nan_reset_dbg_counters();
- /* XXX: WAR posting async enable response */
- //NanMacControl *cmd = new NanMacControl(iface, id, (void *)msg, cmdType);
- NanMacControl *cmd = (NanMacControl*)(info.nan_mac_control);
- NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);
- cmd->setType(cmdType);
+
+ cmd->setType(NAN_REQUEST_ENABLE);
cmd->setId(id);
cmd->setMsg((void *)msg);
+
ret = (wifi_error)cmd->start();
if (ret != WIFI_SUCCESS) {
ALOGE("%s : failed in start, error = %d\n", __func__, ret);
}
- //cmd->releaseRef();
+
+ return ret;
+}
+
+wifi_error nan_enable_request(transaction_id id,
+ wifi_interface_handle iface, NanEnableRequest* msg)
+{
+ wifi_error ret = WIFI_SUCCESS;
+ hal_info *h_info = getHalInfo(iface);
+
+ ALOGE("nan_enable_request: nan_state = %d\n", h_info->nan_state);
+
+#ifdef CHRE_NAN
+ //check if host NAN is pre-empting CHRE NAN
+ if (h_info->nan_state == NAN_STATE_CHRE) {
+ /* notify pre-empt to chre */
+ if (h_info->chre_nan_cb.on_chre_nan_rtt_change != NULL) {
+ h_info->chre_nan_cb.on_chre_nan_rtt_change(CHRE_PREMPTED);
+ }
+ /* first disable NAN for chre */
+ ret = nan_chre_disable_request(1, iface);
+ if (ret != WIFI_SUCCESS) {
+ ALOGE("Failed to disable NAN for CHRE ret %d\n", ret);
+ return ret;
+ }
+ }
+
+ /* notify unavailable status to chre */
+ if (h_info->chre_nan_cb.on_chre_nan_rtt_change != NULL) {
+ h_info->chre_nan_cb.on_chre_nan_rtt_change(CHRE_UNAVAILABLE);
+ }
+#endif /* CHRE_NAN */
+
+ NanMacControl *cmd = (NanMacControl*)(info.nan_mac_control);
+ NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);
+ cmd->setChreNan(0);
+ ret = nan_cmn_enabe_request(id, cmd, msg);
+
+ if (ret == WIFI_SUCCESS) {
+ h_info->nan_state = NAN_STATE_AP;
+ }
+
return ret;
}
@@ -4314,16 +4374,40 @@ void nan_dump_dbg_counters()
ALOGI("Num Transmit Success %d\n", counters.transmit_txs);
}
+wifi_error nan_cmn_disable_request(transaction_id id, NanMacControl *mac)
+{
+ wifi_error ret = WIFI_SUCCESS;
+
+ nan_dump_dbg_counters();
+
+ mac->setType(NAN_REQUEST_DISABLE);
+ ret = (wifi_error)mac->cancel();
+ if (ret != WIFI_SUCCESS) {
+ ALOGE("cancel failed, error = %d\n", ret);
+ } else {
+ ALOGE("Deinitializing Nan Mac Control = %p\n", mac);
+ }
+ mac->releaseRef();
+
+ return ret;
+}
wifi_error nan_disable_request(transaction_id id,
wifi_interface_handle iface)
{
- wifi_handle handle = getWifiHandle(iface);
- NanRequestType cmdType = NAN_REQUEST_DISABLE;
wifi_error ret = WIFI_SUCCESS;
+ hal_info *h_info = getHalInfo(iface);
+
+ ALOGE("nan_disable_request: nan_state %d\n", h_info->nan_state);
+
+ if (h_info->nan_state == NAN_STATE_CHRE) {
+ ALOGE("nan_disable_request: Not enabled for AP.. return\n");
+ return ret;
+ }
- ALOGI("Disabling Nan, Handle = %p\n", handle);
- NanMacControl *cmd = new NanMacControl(iface, id, NULL, cmdType);
NanMacControl *mac_prim = (NanMacControl*)(info.nan_mac_control);
+ NanMacControl *cmd = new NanMacControl(iface, id, NULL, NAN_REQUEST_LAST);
+
+ NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);
if (id != NAN_MAC_INVALID_TRANSID) {
ALOGE("Disable NAN MAC transId= %d\n", id);
@@ -4332,17 +4416,15 @@ wifi_error nan_disable_request(transaction_id id,
ALOGE("Invalid transId= %d cur= %d\n", id, mac_prim->getId());
}
- NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);
-
- nan_dump_dbg_counters();
-
- ret = (wifi_error)cmd->cancel();
- if (ret != WIFI_SUCCESS) {
- ALOGE("cancel failed, error = %d\n", ret);
- } else {
- ALOGE("Deinitializing Nan Mac Control = %p\n", cmd);
+ cmd->setChreNan(0);
+ ret = nan_cmn_disable_request(id, cmd);
+ if (ret == WIFI_SUCCESS) {
+ h_info->nan_state = NAN_STATE_DISABLED;
+ /* notify pre-empt / unavailable status to chre */
+ if (h_info->chre_nan_cb.on_chre_nan_rtt_change != NULL) {
+ h_info->chre_nan_cb.on_chre_nan_rtt_change(CHRE_AVAILABLE);
+ }
}
- cmd->releaseRef();
return ret;
}
@@ -5439,3 +5521,89 @@ wifi_error nan_data_end(transaction_id id,
NAN_DBG_EXIT();
return ret;
}
+
+wifi_error nan_chre_enable_request(transaction_id id,
+ wifi_interface_handle iface, NanEnableRequest* msg)
+{
+ wifi_error ret = WIFI_SUCCESS;
+ NanEnableRequest def_msg;
+ hal_info *h_info = getHalInfo(iface);
+
+ ALOGI("nan_chre_enable_request: nan_state %d\n", h_info->nan_state);
+
+ if (h_info->nan_state == NAN_STATE_CHRE) {
+ return WIFI_SUCCESS;
+ } else if (h_info->nan_state == NAN_STATE_AP) {
+ ALOGE("nan_chre_enable_request: Nan is enabled for AP. Fail CHRE request\n");
+ return WIFI_ERROR_BUSY;
+ }
+
+ NanMacControl *mac = new NanMacControl(iface, 0, NULL, NAN_REQUEST_LAST);
+ NULL_CHECK_RETURN(mac, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);
+
+ mac->setChreNan(1);
+ if (msg == NULL) {
+ /* default enable params */
+ ALOGI("Input Enable config is NULL, use default config\n");
+ memset(&def_msg, 0, sizeof(def_msg));
+ def_msg.hop_count_limit_val = 5;
+ def_msg.config_2dot4g_support = 1;
+ def_msg.support_2dot4g_val = 1;
+ def_msg.config_2dot4g_beacons = 1;
+ def_msg.beacon_2dot4g_val = 1;
+ def_msg.config_2dot4g_sdf = 1;
+ def_msg.sdf_2dot4g_val = 1;
+ def_msg.config_disc_mac_addr_randomization = true;
+ def_msg.disc_mac_addr_rand_interval_sec = 0;
+ def_msg.config_ndpe_attr = false;
+ ret = nan_cmn_enabe_request(id, mac, &def_msg);
+ } else {
+ ret = nan_cmn_enabe_request(id, mac, msg);
+ }
+
+ if (ret == WIFI_SUCCESS) {
+ h_info->nan_state = NAN_STATE_CHRE;
+ }
+
+ return ret;
+}
+
+wifi_error nan_chre_disable_request(transaction_id id,
+ wifi_interface_handle iface)
+{
+ wifi_error ret = WIFI_SUCCESS;
+ hal_info *h_info = getHalInfo(iface);
+
+ ALOGI("nan_chre_disable_request: nan_state %d\n", h_info->nan_state);
+
+ if (h_info->nan_state == NAN_STATE_AP) {
+ ALOGE("nan_chre_disable_request: Not enabled for CHRE.. return\n");
+ return ret;
+ }
+
+ NanMacControl *cmd = new NanMacControl(iface, id, NULL, NAN_REQUEST_LAST);
+ NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);
+
+ cmd->setChreNan(1);
+ ret = nan_cmn_disable_request(id, cmd);
+
+ if (ret == WIFI_SUCCESS) {
+ h_info->nan_state = NAN_STATE_DISABLED;
+ }
+
+ return ret;
+}
+
+wifi_error nan_chre_register_handler(wifi_interface_handle iface,
+ wifi_chre_handler handler)
+{
+ wifi_error ret = WIFI_SUCCESS;
+ hal_info *h_info = getHalInfo(iface);
+
+ if (h_info) {
+ ALOGE("Registering CHRE handler for Nan Status %p\n", handler.on_chre_nan_rtt_change);
+ h_info->chre_nan_cb = handler;
+ }
+
+ return ret;
+}
diff --git a/bcmdhd/wifi_hal/wifi_hal.cpp b/bcmdhd/wifi_hal/wifi_hal.cpp
index 5b65bc4..fe679ab 100755
--- a/bcmdhd/wifi_hal/wifi_hal.cpp
+++ b/bcmdhd/wifi_hal/wifi_hal.cpp
@@ -341,6 +341,9 @@ wifi_error init_wifi_vendor_hal_func_table(wifi_hal_fn *fn)
fn->wifi_get_usable_channels = wifi_get_usable_channels;
fn->wifi_trigger_subsystem_restart = wifi_trigger_subsystem_restart;
fn->wifi_get_supported_radio_combinations_matrix = wifi_get_supported_radio_combinations_matrix;
+ fn->wifi_nan_rtt_chre_enable_request = nan_chre_enable_request;
+ fn->wifi_nan_rtt_chre_disable_request = nan_chre_disable_request;
+ fn->wifi_chre_register_handler = nan_chre_register_handler;
return WIFI_SUCCESS;
}