static jboolean android_net_wifi_getScanCapabilities( JNIEnv *env, jclass cls, jint iface, jobject capabilities) { wifi_interface_handle handle = getIfaceHandle(env, cls, iface); ALOGD("getting scan capabilities on interface[%d] = %p", iface, handle); wifi_gscan_capabilities c; memset(&c, 0, sizeof(c)); int result = wifi_get_gscan_capabilities(handle, &c); if (result != WIFI_SUCCESS) { ALOGD("failed to get capabilities : %d", result); return JNI_FALSE; } setIntField(env, capabilities, "max_scan_cache_size", c.max_scan_cache_size); setIntField(env, capabilities, "max_scan_buckets", c.max_scan_buckets); setIntField(env, capabilities, "max_ap_cache_per_scan", c.max_ap_cache_per_scan); setIntField(env, capabilities, "max_rssi_sample_size", c.max_rssi_sample_size); setIntField(env, capabilities, "max_scan_reporting_threshold", c.max_scan_reporting_threshold); setIntField(env, capabilities, "max_hotlist_aps", c.max_hotlist_aps); setIntField(env, capabilities, "max_significant_wifi_change_aps", c.max_significant_wifi_change_aps); return JNI_TRUE; }
static bool startScan( void (*pfnOnResultsAvailable)(wifi_request_id, unsigned), int max_ap_per_scan, int base_period, int report_threshold) { /* Get capabilties */ wifi_gscan_capabilities capabilities; int result = wifi_get_gscan_capabilities(wlan0Handle, &capabilities); if (result < 0) { printMsg("failed to get scan capabilities - %d\n", result); printMsg("trying scan anyway ..\n"); } else { printScanCapabilities(capabilities); } wifi_scan_cmd_params params; memset(¶ms, 0, sizeof(params)); if(num_channels > 0){ params.max_ap_per_scan = max_ap_per_scan; params.base_period = base_period; // 5 second by default params.report_threshold = report_threshold; params.num_buckets = 1; params.buckets[0].bucket = 0; params.buckets[0].band = WIFI_BAND_UNSPECIFIED; params.buckets[0].period = base_period; params.buckets[0].num_channels = num_channels; for(int i = 0; i < num_channels; i++){ params.buckets[0].channels[i].channel = channel_list[i]; } } else { /* create a schedule to scan channels 1, 6, 11 every 5 second and * scan 36, 40, 44, 149, 153, 157, 161 165 every 10 second */ params.max_ap_per_scan = max_ap_per_scan; params.base_period = base_period; // 5 second params.report_threshold = report_threshold; params.num_buckets = 3; params.buckets[0].bucket = 0; params.buckets[0].band = WIFI_BAND_UNSPECIFIED; params.buckets[0].period = 5000; // 5 second params.buckets[0].report_events = 0; params.buckets[0].num_channels = 2; params.buckets[0].channels[0].channel = 2412; params.buckets[0].channels[1].channel = 2437; params.buckets[1].bucket = 1; params.buckets[1].band = WIFI_BAND_A; params.buckets[1].period = 10000; // 10 second params.buckets[1].report_events = 1; params.buckets[1].num_channels = 8; // driver should ignore list since band is specified params.buckets[1].channels[0].channel = 5180; params.buckets[1].channels[1].channel = 5200; params.buckets[1].channels[2].channel = 5220; params.buckets[1].channels[3].channel = 5745; params.buckets[1].channels[4].channel = 5765; params.buckets[1].channels[5].channel = 5785; params.buckets[1].channels[6].channel = 5805; params.buckets[1].channels[7].channel = 5825; params.buckets[2].bucket = 2; params.buckets[2].band = WIFI_BAND_UNSPECIFIED; params.buckets[2].period = 15000; // 15 second params.buckets[2].report_events = 2; params.buckets[2].num_channels = 1; params.buckets[2].channels[0].channel = 2462; } wifi_scan_result_handler handler; memset(&handler, 0, sizeof(handler)); handler.on_scan_results_available = pfnOnResultsAvailable; handler.on_scan_event = on_scan_event; scanCmdId = getNewCmdId(); printMsg("Starting scan --->\n"); return wifi_start_gscan(scanCmdId, wlan0Handle, params, handler) == WIFI_SUCCESS; }