wifi_error wifi_disable_full_scan_results(wifi_request_id id, wifi_interface_handle iface) { ALOGD("[WIFI HAL]Disabling full scan results"); wifi_handle handle = getWifiHandle(iface); if(id == -1) { wifi_scan_result_handler handler; wifi_handle handle = getWifiHandle(iface); int params_dummy; memset(&handler, 0, sizeof(handler)); FullScanResultsCommand *cmd = new FullScanResultsCommand(iface, 0, ¶ms_dummy, handler); cmd->cancel(); cmd->releaseRef(); return WIFI_SUCCESS; } WifiCommand *cmd = wifi_unregister_cmd(handle, id); if (cmd) { cmd->cancel(); cmd->releaseRef(); return WIFI_SUCCESS; } return WIFI_ERROR_INVALID_ARGS; }
wifi_error wifi_stop_gscan(wifi_request_id id, wifi_interface_handle iface) { char prop_buf[PROPERTY_VALUE_MAX]; property_get("wlan.mtk.gscan", prop_buf, "0"); if(!strcmp(prop_buf, "1")) { ALOGD("[WIFI HAL]Stopping GScan"); wifi_handle handle = getWifiHandle(iface); if(id == -1) { wifi_scan_result_handler handler; wifi_scan_cmd_params dummy_params; memset(&handler, 0, sizeof(handler)); ScanCommand *cmd = new ScanCommand(iface, id, &dummy_params, handler); cmd->cancel(); cmd->releaseRef(); return WIFI_SUCCESS; } WifiCommand *cmd = wifi_unregister_cmd(handle, id); if (cmd) { cmd->cancel(); cmd->releaseRef(); return WIFI_SUCCESS; } } return WIFI_ERROR_INVALID_ARGS; }
static wifi_error get_firmware_bus_max_size_supported( wifi_interface_handle iface) { int ret = 0; interface_info *iinfo = getIfaceInfo(iface); wifi_handle handle = getWifiHandle(iface); hal_info *info = (hal_info *)handle; WifihalGeneric busSizeSupported(handle, 0, OUI_QCA, QCA_NL80211_VENDOR_SUBCMD_GET_BUS_SIZE); /* create the message */ ret = busSizeSupported.create(); if (ret < 0) goto cleanup; ret = busSizeSupported.set_iface_id(iinfo->name); if (ret < 0) goto cleanup; ret = busSizeSupported.requestResponse(); if (ret != 0) { ALOGE("%s: requestResponse Error:%d", __FUNCTION__, ret); goto cleanup; } info->firmware_bus_max_size = busSizeSupported.getBusSize(); cleanup: return mapErrorKernelToWifiHAL(ret); }
static wifi_error wifi_get_capabilities(wifi_interface_handle handle) { wifi_error ret; int requestId; WifihalGeneric *wifihalGeneric; wifi_handle wifiHandle = getWifiHandle(handle); hal_info *info = getHalInfo(wifiHandle); if (!(info->supported_feature_set & WIFI_FEATURE_GSCAN)) { ALOGE("%s: GSCAN is not supported by driver", __FUNCTION__); return WIFI_ERROR_NOT_SUPPORTED; } /* No request id from caller, so generate one and pass it on to the driver. * Generate it randomly. */ requestId = get_requestid(); wifihalGeneric = new WifihalGeneric( wifiHandle, requestId, OUI_QCA, QCA_NL80211_VENDOR_SUBCMD_GSCAN_GET_CAPABILITIES); if (!wifihalGeneric) { ALOGE("%s: Failed to create object of WifihalGeneric class", __FUNCTION__); return WIFI_ERROR_UNKNOWN; } ret = wifihalGeneric->wifiGetCapabilities(handle); delete wifihalGeneric; return ret; }
static wifi_error acquire_supported_features(wifi_interface_handle iface, feature_set *set) { int ret = 0; interface_info *iinfo = getIfaceInfo(iface); wifi_handle handle = getWifiHandle(iface); *set = 0; WifihalGeneric supportedFeatures(handle, 0, OUI_QCA, QCA_NL80211_VENDOR_SUBCMD_GET_SUPPORTED_FEATURES); /* create the message */ ret = supportedFeatures.create(); if (ret < 0) goto cleanup; ret = supportedFeatures.set_iface_id(iinfo->name); if (ret < 0) goto cleanup; ret = supportedFeatures.requestResponse(); if (ret != 0) { ALOGE("%s: requestResponse Error:%d",__func__, ret); goto cleanup; } supportedFeatures.getResponseparams(set); cleanup: return mapErrorKernelToWifiHAL(ret); }
static void android_net_wifi_waitForHalEvents(JNIEnv* env, jclass cls) { ALOGD("waitForHalEvents called, vm = %p, obj = %p, env = %p", mVM, mCls, env); wifi_handle halHandle = getWifiHandle(env, cls); wifi_event_loop(halHandle); }
wifi_error wifi_set_bssid_hotlist(wifi_request_id id, wifi_interface_handle iface, wifi_bssid_hotlist_params params, wifi_hotlist_ap_found_handler handler) { wifi_handle handle = getWifiHandle(iface); BssidHotlistCommand *cmd = new BssidHotlistCommand(iface, id, params, handler); wifi_register_cmd(handle, id, cmd); return (wifi_error)cmd->start(); }
wifi_error wifi_set_significant_change_handler(wifi_request_id id, wifi_interface_handle iface, wifi_significant_change_params params, wifi_significant_change_handler handler) { wifi_handle handle = getWifiHandle(iface); SignificantWifiChangeCommand *cmd = new SignificantWifiChangeCommand( iface, id, params, handler); wifi_register_cmd(handle, id, cmd); return (wifi_error)cmd->start(); }
wifi_error wifi_enable_full_scan_results( wifi_request_id id, wifi_interface_handle iface, wifi_scan_result_handler handler) { wifi_handle handle = getWifiHandle(iface); int params_dummy; ALOGD("[WIFI HAL]Enabling full scan results, halHandle = %p", handle); FullScanResultsCommand *cmd = new FullScanResultsCommand(iface, id, ¶ms_dummy, handler); wifi_register_cmd(handle, id, cmd); return (wifi_error)cmd->start(); }
wifi_error wifi_start_gscan( wifi_request_id id, wifi_interface_handle iface, wifi_scan_cmd_params params, wifi_scan_result_handler handler) { wifi_handle handle = getWifiHandle(iface); ALOGD("[WIFI HAL]Starting GScan, halHandle = %p", handle); ScanCommand *cmd = new ScanCommand(iface, id, ¶ms, handler); wifi_register_cmd(handle, id, cmd); return (wifi_error)cmd->start(); }
//Implementation of the functions exposed in linklayer.h wifi_error wifi_set_link_stats(wifi_interface_handle iface, wifi_link_layer_params params) { int ret = 0; LLStatsCommand *LLCommand; struct nlattr *nl_data; interface_info *iinfo = getIfaceInfo(iface); wifi_handle handle = getWifiHandle(iface); LLCommand = LLStatsCommand::instance(handle); if (LLCommand == NULL) { ALOGE("%s: Error LLStatsCommand NULL", __func__); return WIFI_ERROR_UNKNOWN; } LLCommand->setSubCmd(QCA_NL80211_VENDOR_SUBCMD_LL_STATS_SET); /* create the message */ ret = LLCommand->create(); if (ret < 0) goto cleanup; ret = LLCommand->set_iface_id(iinfo->name); if (ret < 0) goto cleanup; /*add the attributes*/ nl_data = LLCommand->attr_start(NL80211_ATTR_VENDOR_DATA); if (!nl_data) goto cleanup; /**/ ret = LLCommand->put_u32(QCA_WLAN_VENDOR_ATTR_LL_STATS_SET_CONFIG_MPDU_SIZE_THRESHOLD, params.mpdu_size_threshold); if (ret < 0) goto cleanup; /**/ ret = LLCommand->put_u32( QCA_WLAN_VENDOR_ATTR_LL_STATS_SET_CONFIG_AGGRESSIVE_STATS_GATHERING, params.aggressive_statistics_gathering); if (ret < 0) goto cleanup; LLCommand->attr_end(nl_data); ret = LLCommand->requestResponse(); if (ret != 0) { ALOGE("%s: requestResponse Error:%d",__func__, ret); } cleanup: return (wifi_error)ret; }
static jboolean android_net_wifi_startHal(JNIEnv* env, jclass cls) { wifi_handle halHandle = getWifiHandle(env, cls); if (halHandle == NULL) { wifi_error res = wifi_initialize(&halHandle); if (res == WIFI_SUCCESS) { setStaticLongField(env, cls, WifiHandleVarName, (jlong)halHandle); ALOGD("Did set static halHandle = %p", halHandle); } env->GetJavaVM(&mVM); mCls = (jclass) env->NewGlobalRef(cls); ALOGD("halHandle = %p, mVM = %p, mCls = %p", halHandle, mVM, mCls); return res == WIFI_SUCCESS; } else { return true; } }
wifi_error wifi_reset_alert_handler(wifi_request_id id, wifi_interface_handle iface) { wifi_handle handle = getWifiHandle(iface); ALOGV("Alerthandler reset, wifi_request_id = %d, handle = %p", id, handle); if (id == -1) { wifi_alert_handler handler; memset(&handler, 0, sizeof(handler)); SetAlertHandler *cmd = new SetAlertHandler(iface, id, handler); NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY); cmd->cancel(); cmd->releaseRef(); return WIFI_SUCCESS; } return wifi_cancel_cmd(id, iface); }
wifi_error wifi_reset_significant_change_handler(wifi_request_id id, wifi_interface_handle iface) { char prop_buf[PROPERTY_VALUE_MAX]; property_get("wlan.mtk.gscan", prop_buf, "0"); if(!strcmp(prop_buf, "1")) { wifi_handle handle = getWifiHandle(iface); WifiCommand *cmd = wifi_unregister_cmd(handle, id); if (cmd) { cmd->cancel(); cmd->releaseRef(); return WIFI_SUCCESS; } } return WIFI_ERROR_INVALID_ARGS; }
wifi_error wifi_set_alert_handler(wifi_request_id id, wifi_interface_handle iface, wifi_alert_handler handler) { wifi_handle handle = getWifiHandle(iface); ALOGV("Alerthandler start, handle = %p", handle); SetAlertHandler *cmd = new SetAlertHandler(iface, id, handler); NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY); wifi_error result = wifi_register_cmd(handle, id, cmd); if (result != WIFI_SUCCESS) { cmd->releaseRef(); return result; } result = (wifi_error)cmd->start(); if (result != WIFI_SUCCESS) { wifi_unregister_cmd(handle, id); cmd->releaseRef(); return result; } return result; }
static int android_net_wifi_getInterfaces(JNIEnv *env, jclass cls) { int n = 0; wifi_handle halHandle = getWifiHandle(env, cls); wifi_interface_handle *ifaceHandles = NULL; int result = wifi_get_ifaces(halHandle, &n, &ifaceHandles); if (result < 0) { return result; } if (n < 0) { THROW(env, "android_net_wifi_getInterfaces no interfaces"); return 0; } if (ifaceHandles == NULL) { THROW(env, "android_net_wifi_getInterfaces null interface array"); return 0; } if (n > 8) { THROW(env, "Too many interfaces"); return 0; } jlongArray array = (env)->NewLongArray(n); if (array == NULL) { THROW(env, "Error in accessing array"); return 0; } jlong elems[8]; for (int i = 0; i < n; i++) { elems[i] = reinterpret_cast<jlong>(ifaceHandles[i]); } env->SetLongArrayRegion(array, 0, n, elems); setStaticLongArrayField(env, cls, WifiIfaceHandleVarName, array); return (result < 0) ? result : n; }
LLStatsCommand* LLStatsCommand::instance(wifi_handle handle) { if (handle == NULL) { ALOGE("Interface Handle is invalid"); return NULL; } if (mLLStatsCommandInstance == NULL) { mLLStatsCommandInstance = new LLStatsCommand(handle, 0, OUI_QCA, QCA_NL80211_VENDOR_SUBCMD_LL_STATS_SET); ALOGV("LLStatsCommand %p created", mLLStatsCommandInstance); return mLLStatsCommandInstance; } else { if (handle != getWifiHandle(mLLStatsCommandInstance->mInfo)) { ALOGE("Handle different"); return NULL; } } ALOGV("LLStatsCommand %p created already", mLLStatsCommandInstance); return mLLStatsCommandInstance; }
static void android_net_wifi_stopHal(JNIEnv* env, jclass cls) { ALOGD("In wifi stop Hal"); wifi_handle halHandle = getWifiHandle(env, cls); wifi_cleanup(halHandle, android_net_wifi_hal_cleaned_up_handler); }
//Implementation of the functions exposed in LLStats.h wifi_error wifi_get_link_stats(wifi_request_id id, wifi_interface_handle iface, wifi_stats_result_handler handler) { int ret = 0; LLStatsCommand *LLCommand; struct nlattr *nl_data; interface_info *iinfo = getIfaceInfo(iface); wifi_handle handle = getWifiHandle(iface); pthread_t tid; LLCommand = LLStatsCommand::instance(handle); if (LLCommand == NULL) { ALOGE("%s: Error LLStatsCommand NULL", __func__); return WIFI_ERROR_UNKNOWN; } LLCommand->setSubCmd(QCA_NL80211_VENDOR_SUBCMD_LL_STATS_GET); LLCommand->initGetContext(id); LLStatsCallbackHandler callbackHandler = { .on_link_stats_results = handler.on_link_stats_results }; /* create the message */ ret = LLCommand->create(); if (ret < 0) goto cleanup; ret = LLCommand->set_iface_id(iinfo->name); if (ret < 0) goto cleanup; /*add the attributes*/ nl_data = LLCommand->attr_start(NL80211_ATTR_VENDOR_DATA); if (!nl_data) goto cleanup; ret = LLCommand->put_u32(QCA_WLAN_VENDOR_ATTR_LL_STATS_GET_CONFIG_REQ_ID, id); if (ret < 0) goto cleanup; ret = LLCommand->put_u32(QCA_WLAN_VENDOR_ATTR_LL_STATS_GET_CONFIG_REQ_MASK, 7); if (ret < 0) goto cleanup; /**/ LLCommand->attr_end(nl_data); ret = LLCommand->requestResponse(); if (ret != 0) { ALOGE("%s: requestResponse Error:%d",__func__, ret); } if (ret < 0) goto cleanup; ret = LLCommand->setCallbackHandler(callbackHandler, QCA_NL80211_VENDOR_SUBCMD_LL_STATS_RADIO_RESULTS); if (ret < 0) goto cleanup; ret = LLCommand->setCallbackHandler(callbackHandler, QCA_NL80211_VENDOR_SUBCMD_LL_STATS_IFACE_RESULTS); if (ret < 0) goto cleanup; ret = LLCommand->setCallbackHandler(callbackHandler, QCA_NL80211_VENDOR_SUBCMD_LL_STATS_PEERS_RESULTS); if (ret < 0) goto cleanup; cleanup: return (wifi_error)ret; } //Implementation of the functions exposed in LLStats.h wifi_error wifi_clear_link_stats(wifi_interface_handle iface, u32 stats_clear_req_mask, u32 *stats_clear_rsp_mask, u8 stop_req, u8 *stop_rsp) { int ret = 0; LLStatsCommand *LLCommand; struct nlattr *nl_data; interface_info *iinfo = getIfaceInfo(iface); wifi_handle handle = getWifiHandle(iface); LLCommand = LLStatsCommand::instance(handle); if (LLCommand == NULL) { ALOGE("%s: Error LLStatsCommand NULL", __func__); return WIFI_ERROR_UNKNOWN; } LLCommand->setSubCmd(QCA_NL80211_VENDOR_SUBCMD_LL_STATS_CLR); /* create the message */ ret = LLCommand->create(); if (ret < 0) goto cleanup; ret = LLCommand->set_iface_id(iinfo->name); if (ret < 0) goto cleanup; /*add the attributes*/ nl_data = LLCommand->attr_start(NL80211_ATTR_VENDOR_DATA); if (!nl_data) goto cleanup; /**/ ret = LLCommand->put_u32(QCA_WLAN_VENDOR_ATTR_LL_STATS_CLR_CONFIG_REQ_MASK, stats_clear_req_mask); if (ret < 0) goto cleanup; /**/ ret = LLCommand->put_u8(QCA_WLAN_VENDOR_ATTR_LL_STATS_CLR_CONFIG_STOP_REQ, stop_req); if (ret < 0) goto cleanup; LLCommand->attr_end(nl_data); ret = LLCommand->requestResponse(); if (ret != 0) { ALOGE("%s: requestResponse Error:%d",__func__, ret); } LLCommand->getClearRspParams(stats_clear_rsp_mask, stop_rsp); cleanup: LLCommand->unregisterHandler(QCA_NL80211_VENDOR_SUBCMD_LL_STATS_RADIO_RESULTS); LLCommand->unregisterHandler(QCA_NL80211_VENDOR_SUBCMD_LL_STATS_IFACE_RESULTS); LLCommand->unregisterHandler(QCA_NL80211_VENDOR_SUBCMD_LL_STATS_PEERS_RESULTS); delete LLCommand; return (wifi_error)ret; }