static wifi_error setHotlistAPs() {
    wifi_bssid_hotlist_params params;
    memset(&params, 0, sizeof(params));

    params.lost_ap_sample_size = HOTLIST_LOST_WINDOW;
    if (num_hotlist_bssids > 0) {
      for (int i = 0; i < num_hotlist_bssids; i++) {
          memcpy(params.ap[i].bssid, hotlist_bssids[i], sizeof(mac_addr));
          params.ap[i].low  = -htest_low_threshold;
          params.ap[i].high = -htest_high_threshold;
      }
      params.num_ap = num_hotlist_bssids;
    } else {
      setHotlistAPsUsingScanResult(&params);
    }

    printMsg("BSSID\t\t\tHIGH\tLOW\n");
    for (int i = 0; i < params.num_ap; i++) {
        mac_addr &addr = params.ap[i].bssid;
        printMsg("%02x:%02x:%02x:%02x:%02x:%02x\t%d\t%d\n", addr[0],
                addr[1], addr[2], addr[3], addr[4], addr[5],
                params.ap[i].high, params.ap[i].low);
    }

    wifi_hotlist_ap_found_handler handler;
    handler.on_hotlist_ap_found = &onHotlistAPFound;
    handler.on_hotlist_ap_lost = &onHotlistAPLost;
    hotlistCmdId = getNewCmdId();
    printMsg("Setting hotlist APs threshold\n");
    return wifi_set_bssid_hotlist(hotlistCmdId, wlan0Handle, params, handler);
}
Beispiel #2
0
void AbstractClient::queuePendingCommand(PendingCommand *pend)
{
    // This function is always called from the client thread via signal/slot.
    const int cmdId = getNewCmdId();
    pend->getCommandContainer().set_cmd_id(cmdId);
    
    pendingCommands.insert(cmdId, pend);
    
    sendCommandContainer(pend->getCommandContainer());
}
Beispiel #3
0
void RemoteClient::slotConnected()
{
    timeRunning = lastDataReceived = 0;
    timer->start();

    // dirty hack to be compatible with v14 server
    sendCommandContainer(CommandContainer());
    getNewCmdId();
    // end of hack
}
static int SelectSignificantAPsFromScanResults() {
    wifi_scan_result results[256];
    memset(results, 0, sizeof(wifi_scan_result) * 256);
    printMsg("Retrieving scan results for significant wifi change setting\n");
    int num_results = 256;
    int result = wifi_get_cached_gscan_results(wlan0Handle, 1, num_results, results, &num_results);
    if (result < 0) {
        printMsg("failed to fetch scan results : %d\n", result);
        return WIFI_ERROR_UNKNOWN;
    } else {
        printMsg("fetched %d scan results\n", num_results);
    }

    for (int i = 0; i < num_results; i++) {
        printScanResult(results[i]);
    }

    wifi_significant_change_params params;
    memset(&params, 0, sizeof(params));

    params.rssi_sample_size = swctest_rssi_sample_size;
    params.lost_ap_sample_size = swctest_rssi_lost_ap;
    params.min_breaching = swctest_rssi_min_breaching;

    for (int i = 0; i < stest_max_ap; i++) {
        memcpy(params.ap[i].bssid, results[i].bssid, sizeof(mac_addr));
        params.ap[i].low  = results[i].rssi - swctest_rssi_ch_threshold;
        params.ap[i].high = results[i].rssi + swctest_rssi_ch_threshold;
    }
    params.num_ap = stest_max_ap;

    printMsg("Settting Significant change params rssi_sample_size#%d lost_ap_sample_size#%d"
        " and min_breaching#%d\n", params.rssi_sample_size,
        params.lost_ap_sample_size , params.min_breaching);
    printMsg("BSSID\t\t\tHIGH\tLOW\n");
    for (int i = 0; i < params.num_ap; i++) {
        mac_addr &addr = params.ap[i].bssid;
        printMsg("%02x:%02x:%02x:%02x:%02x:%02x\t%d\t%d\n", addr[0],
                addr[1], addr[2], addr[3], addr[4], addr[5],
                params.ap[i].high, params.ap[i].low);
    }
    wifi_significant_change_handler handler;
    memset(&handler, 0, sizeof(handler));
    handler.on_significant_change = &onSignificantWifiChange;

    int id = getNewCmdId();
    return wifi_set_significant_change_handler(id, wlan0Handle, params, handler);

}
static int scanOnce(wifi_band band, wifi_scan_result *results, int num_results) {

    saved_scan_results = results;
    max_saved_scan_results = num_results;
    num_saved_scan_results = 0;

    wifi_scan_cmd_params params;
    memset(&params, 0, sizeof(params));

    params.max_ap_per_scan = 10;
    params.base_period = 5000;                        // 5 second by default
    params.report_threshold = 90;
    params.num_buckets = 1;

    params.buckets[0].bucket = 0;
    params.buckets[0].band = band;
    params.buckets[0].period = 5000;                  // 5 second
    params.buckets[0].report_events = 2;              // REPORT_EVENTS_AFTER_EACH_SCAN
    params.buckets[0].num_channels = 0;

    wifi_scan_result_handler handler;
    memset(&handler, 0, sizeof(handler));
    handler.on_scan_results_available = NULL;
    handler.on_scan_event = on_single_shot_scan_event;
    handler.on_full_scan_result = on_full_scan_result;

    int scanCmdId = getNewCmdId();
    printMsg("Starting scan --->\n");
    if (wifi_start_gscan(scanCmdId, wlan0Handle, params, handler) == WIFI_SUCCESS) {
        int events = 0;
        while (true) {
            EventInfo info;
            memset(&info, 0, sizeof(info));
            getEventFromCache(info);
            if (info.type == EVENT_TYPE_SCAN_RESULTS_AVAILABLE
                || info.type == EVENT_TYPE_SCAN_COMPLETE) {
                int retrieved_num_results = num_saved_scan_results;
                if (retrieved_num_results == 0) {
                    printMsg("fetched 0 scan results, waiting for more..\n");
                    continue;
                } else {
                    printMsg("fetched %d scan results\n", retrieved_num_results);

                    /*
                    printScanHeader();

                    for (int i = 0; i < retrieved_num_results; i++) {
                        printScanResult(results[i]);
                    }
                    */

                    printMsg("Scan once completed, stopping scan\n");
                    wifi_stop_gscan(scanCmdId, wlan0Handle);
                    saved_scan_results = NULL;
                    max_saved_scan_results = 0;
                    num_saved_scan_results = 0;
                    return retrieved_num_results;
                }
            }
        }
    } else {
        return 0;
    }
}
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(&params, 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;
}