forked from risinek/esp32-wifi-penetration-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathap_scanner.c
51 lines (43 loc) · 1.32 KB
/
ap_scanner.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* @file ap_scanner.c
* @author risinek (risinek@gmail.com)
* @date 2021-04-05
* @copyright Copyright (c) 2021
*
* @brief Implements AP scanning functionality.
*/
#include "ap_scanner.h"
#define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
#include "esp_log.h"
#include "esp_err.h"
#include "esp_wifi.h"
static const char* TAG = "wifi_controller/ap_scanner";
/**
* @brief Stores last scanned AP records into linked list.
*
*/
static wifictl_ap_records_t ap_records;
void wifictl_scan_nearby_aps(){
ESP_LOGD(TAG, "Scanning nearby APs...");
ap_records.count = CONFIG_SCAN_MAX_AP;
wifi_scan_config_t scan_config = {
.ssid = NULL,
.bssid = NULL,
.channel = 0,
.scan_type = WIFI_SCAN_TYPE_ACTIVE
};
ESP_ERROR_CHECK(esp_wifi_scan_start(&scan_config, true));
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&ap_records.count, ap_records.records));
ESP_LOGI(TAG, "Found %u APs.", ap_records.count);
ESP_LOGD(TAG, "Scan done.");
}
const wifictl_ap_records_t *wifictl_get_ap_records() {
return &ap_records;
}
const wifi_ap_record_t *wifictl_get_ap_record(unsigned index) {
if(index > ap_records.count){
ESP_LOGE(TAG, "Index out of bounds! %u records available, but %u requested", ap_records.count, index);
return NULL;
}
return &ap_records.records[index];
}