|
18 | 18 | #include "shared-bindings/wifi/ScannedNetworks.h" |
19 | 19 |
|
20 | 20 | #include "components/esp_wifi/include/esp_wifi.h" |
| 21 | +#include "soc/soc_caps.h" |
21 | 22 |
|
22 | 23 | static void wifi_scannednetworks_done(wifi_scannednetworks_obj_t *self) { |
23 | 24 | self->done = true; |
@@ -111,29 +112,38 @@ mp_obj_t common_hal_wifi_scannednetworks_next(wifi_scannednetworks_obj_t *self) |
111 | 112 | } |
112 | 113 |
|
113 | 114 | // We don't do a linear scan so that we look at a variety of spectrum up front. |
| 115 | +#if defined(SOC_WIFI_SUPPORT_5G) && SOC_WIFI_SUPPORT_5G |
| 116 | +// 2.4 GHz first, then the 5 GHz U-NII bands. DFS channels are omitted: |
| 117 | +// they require radar detection before transmitting. |
| 118 | +static uint8_t scan_pattern[] = {6, 1, 11, 3, 9, 13, 2, 4, 8, 12, 5, 7, 10, 14, |
| 119 | + 36, 40, 44, 48, 149, 153, 157, 161, 165, 0}; |
| 120 | +#else |
114 | 121 | static uint8_t scan_pattern[] = {6, 1, 11, 3, 9, 13, 2, 4, 8, 12, 5, 7, 10, 14, 0}; |
| 122 | +#endif |
115 | 123 |
|
116 | 124 | void wifi_scannednetworks_scan_next_channel(wifi_scannednetworks_obj_t *self) { |
117 | | - // There is no channel 0, so use that as a flag to indicate we've run out of channels to scan. |
118 | | - uint8_t next_channel = 0; |
119 | | - while (self->current_channel_index < sizeof(scan_pattern)) { |
120 | | - next_channel = scan_pattern[self->current_channel_index]; |
121 | | - self->current_channel_index++; |
122 | | - // Scan only channels that are in the specified range. |
123 | | - if (self->start_channel <= next_channel && next_channel <= self->end_channel) { |
124 | | - break; |
| 125 | + while (true) { |
| 126 | + // There is no channel 0, so use that as a flag to indicate we've run out of channels to scan. |
| 127 | + uint8_t next_channel = 0; |
| 128 | + while (self->current_channel_index < sizeof(scan_pattern)) { |
| 129 | + next_channel = scan_pattern[self->current_channel_index]; |
| 130 | + self->current_channel_index++; |
| 131 | + // Scan only channels that are in the specified range. |
| 132 | + if (self->start_channel <= next_channel && next_channel <= self->end_channel) { |
| 133 | + break; |
| 134 | + } |
125 | 135 | } |
126 | | - } |
127 | | - wifi_scan_config_t config = { 0 }; |
128 | | - config.channel = next_channel; |
129 | | - if (next_channel == 0) { |
130 | | - wifi_scannednetworks_done(self); |
131 | | - } else { |
132 | | - esp_err_t result = esp_wifi_scan_start(&config, false); |
133 | | - if (result != ESP_OK) { |
| 136 | + if (next_channel == 0) { |
134 | 137 | wifi_scannednetworks_done(self); |
135 | | - } else { |
| 138 | + return; |
| 139 | + } |
| 140 | + wifi_scan_config_t config = { 0 }; |
| 141 | + config.channel = next_channel; |
| 142 | + // The radio rejects channels outside the band it is set to. Skip those |
| 143 | + // rather than ending the scan, so the rest of the pattern still runs. |
| 144 | + if (esp_wifi_scan_start(&config, false) == ESP_OK) { |
136 | 145 | self->channel_scan_in_progress = true; |
| 146 | + return; |
137 | 147 | } |
138 | 148 | } |
139 | 149 | } |
|
0 commit comments