Skip to content

Commit b8cd6c0

Browse files
committed
picow-ap progress
1 parent a234b74 commit b8cd6c0

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
lines changed

locale/circuitpython.pot

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ msgstr ""
106106
msgid "%q in use"
107107
msgstr ""
108108

109-
#: py/obj.c py/objstr.c py/objstrunicode.c
109+
#: py/objstr.c py/objstrunicode.c
110110
msgid "%q index out of range"
111111
msgstr ""
112112

@@ -171,7 +171,7 @@ msgstr ""
171171
msgid "%q must be an int"
172172
msgstr ""
173173

174-
#: py/argcheck.c
174+
#: py/argcheck.c py/obj.c
175175
msgid "%q must be of type %q"
176176
msgstr ""
177177

@@ -397,6 +397,10 @@ msgstr ""
397397
msgid "ADC2 is being used by WiFi"
398398
msgstr ""
399399

400+
#: ports/raspberrypi/common-hal/wifi/Radio.c
401+
msgid "AP cannot be stopped."
402+
msgstr ""
403+
400404
#: shared-bindings/_bleio/Address.c shared-bindings/ipaddress/IPv4Address.c
401405
#, c-format
402406
msgid "Address must be %d bytes long"
@@ -478,10 +482,18 @@ msgstr ""
478482
msgid "Already advertising."
479483
msgstr ""
480484

485+
#: ports/raspberrypi/common-hal/wifi/Radio.c
486+
msgid "Already connected to station."
487+
msgstr ""
488+
481489
#: ports/atmel-samd/common-hal/canio/Listener.c
482490
msgid "Already have all-matches listener"
483491
msgstr ""
484492

493+
#: ports/raspberrypi/common-hal/wifi/Radio.c
494+
msgid "Already in access point mode."
495+
msgstr ""
496+
485497
#: ports/espressif/common-hal/coproc/__init__.c
486498
#: shared-module/memorymonitor/AllocationAlarm.c
487499
#: shared-module/memorymonitor/AllocationSize.c
@@ -3153,7 +3165,7 @@ msgid "index is out of bounds"
31533165
msgstr ""
31543166

31553167
#: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c
3156-
#: ports/espressif/common-hal/pulseio/PulseIn.c py/obj.c
3168+
#: ports/espressif/common-hal/pulseio/PulseIn.c
31573169
#: shared-bindings/bitmaptools/__init__.c
31583170
msgid "index out of range"
31593171
msgstr ""

ports/raspberrypi/common-hal/wifi/Radio.c

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,41 +155,65 @@ void common_hal_wifi_radio_start_station(wifi_radio_obj_t *self) {
155155
}
156156

157157
void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) {
158+
159+
// <strike>This is wrong</strike> This is fine.
158160
cyw43_wifi_leave(&cyw43_state, CYW43_ITF_STA);
159-
// This is wrong, but without this call the state of ITF_STA is still
160-
// reported as CYW43_LINK_JOIN (by wifi_link_status) and CYW43_LINK_UP
161-
// (by tcpip_link_status). Until AP support is added, we can ignore the
162-
// problem.
163161
cyw43_wifi_leave(&cyw43_state, CYW43_ITF_AP);
162+
164163
bindings_cyw43_wifi_enforce_pm();
165164
}
166165

167166
void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint8_t authmode, uint8_t max_connections) {
168167
if (!common_hal_wifi_radio_get_enabled(self)) {
169168
mp_raise_RuntimeError(translate("wifi is not enabled"));
170169
}
171-
// Is there a better way?
172-
common_hal_wifi_radio_stop_station(self);
170+
171+
if (cyw43_tcpip_link_status(&cyw43_state, CYW43_ITF_STA) != CYW43_LINK_DOWN) {
172+
mp_raise_RuntimeError(translate("Already connected to station."));
173+
}
174+
175+
common_hal_wifi_radio_stop_ap(self);
173176

174177
// Channel can only be changed after inital powerup and config of ap.
175178
// Defaults to 1 if not set or invalid (i.e. 13)
176179
cyw43_wifi_ap_set_channel(&cyw43_state, (const uint32_t)channel);
177180

178181
cyw43_arch_enable_ap_mode((const char *)ssid, (const char *)password, CYW43_AUTH_WPA2_AES_PSK);
182+
179183
// TODO: Implement authmode check like in espressif
180184
bindings_cyw43_wifi_enforce_pm();
181185
}
182186

183187
void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *self) {
184-
common_hal_wifi_radio_stop_station(self);
185-
// I mean, since it already does both..
188+
if (!common_hal_wifi_radio_get_enabled(self)) {
189+
mp_raise_RuntimeError(translate("wifi is not enabled"));
190+
}
191+
192+
if (cyw43_tcpip_link_status(&cyw43_state, CYW43_ITF_AP) != CYW43_LINK_DOWN) {
193+
mp_raise_NotImplementedError(translate("AP cannot be stopped."));
194+
}
195+
196+
/*
197+
* AP cannot be disconnected. cyw43_wifi_leave is broken.
198+
* This code snippet should work, but doesn't.
199+
*
200+
* cyw43_wifi_leave(&cyw43_state, CYW43_ITF_AP);
201+
* cyw43_wifi_leave(&cyw43_state, CYW43_ITF_STA);
202+
*
203+
* bindings_cyw43_wifi_enforce_pm();
204+
*/
186205
}
187206

188207
wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t *bssid, size_t bssid_len) {
189208
if (!common_hal_wifi_radio_get_enabled(self)) {
190209
mp_raise_RuntimeError(translate("wifi is not enabled"));
191210
}
192211

212+
if (cyw43_tcpip_link_status(&cyw43_state, CYW43_ITF_AP) != CYW43_LINK_DOWN) {
213+
mp_raise_RuntimeError(translate("Already in access point mode."));
214+
}
215+
216+
193217
size_t timeout_ms = timeout <= 0 ? 8000 : (size_t)MICROPY_FLOAT_C_FUN(ceil)(timeout * 1000);
194218
uint64_t start = port_get_raw_ticks(NULL);
195219
uint64_t deadline = start + timeout_ms;

0 commit comments

Comments
 (0)