@@ -190,23 +190,34 @@ STATIC mp_obj_t wifi_radio_stop_station(mp_obj_t self) {
190
190
}
191
191
MP_DEFINE_CONST_FUN_OBJ_1 (wifi_radio_stop_station_obj , wifi_radio_stop_station );
192
192
193
+ //| OPEN: int
194
+ //| WPA_PSK: int
195
+ //| WPA2_PSK: int
196
+ //| WPA_WPA2_PSK: int
197
+ //|
193
198
//| def start_ap(self,
194
199
//| ssid: ReadableBuffer,
195
200
//| password: ReadableBuffer = b"",
196
201
//| *,
197
- //| channel: Optional[int] = 1) -> None:
198
- //| """Starts an Access Point with the specified ssid and password.
202
+ //| channel: Optional[int] = 1,
203
+ //| authmode: Optional[int] = WPA_WPA2_PSK) -> None:
204
+ //| """Starts an Access Point with the specified ssid and password
205
+ //| If an empty.
199
206
//|
200
207
//| If ``channel`` is given, the access point will use that channel unless
201
- //| wifi is already operating on a different channel due to an active station."""
208
+ //| a station is already operating on a different channel.
209
+ //|
210
+ //| If ``authmode`` is given, the access point will use that Authentication
211
+ //| mode. If a password is given, ``authmode`` must not be ``OPEN``."""
202
212
//| ...
203
213
//|
204
214
STATIC mp_obj_t wifi_radio_start_ap (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
205
- enum { ARG_ssid , ARG_password , ARG_channel };
215
+ enum { ARG_ssid , ARG_password , ARG_channel , ARG_authmode };
206
216
static const mp_arg_t allowed_args [] = {
207
217
{ MP_QSTR_ssid , MP_ARG_REQUIRED | MP_ARG_OBJ },
208
218
{ MP_QSTR_password , MP_ARG_OBJ , {.u_obj = MP_OBJ_NULL } },
209
219
{ MP_QSTR_channel , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 1 } },
220
+ { MP_QSTR_authmode , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = WIFI_RADIO_AUTH_WPA_WPA2_PSK } },
210
221
};
211
222
212
223
wifi_radio_obj_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
@@ -223,9 +234,12 @@ STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_
223
234
if (password .len > 0 && (password .len < 8 || password .len > 63 )) {
224
235
mp_raise_ValueError (translate ("WiFi password must be between 8 and 63 characters" ));
225
236
}
237
+ if (args [ARG_authmode ].u_int == WIFI_RADIO_AUTH_OPEN ) {
238
+ mp_raise_ValueError (translate ("WiFi password is not used with OPEN authentication" ));
239
+ }
226
240
}
227
241
228
- common_hal_wifi_radio_start_ap (self , ssid .buf , ssid .len , password .buf , password .len , args [ARG_channel ].u_int );
242
+ common_hal_wifi_radio_start_ap (self , ssid .buf , ssid .len , password .buf , password .len , args [ARG_channel ].u_int , args [ ARG_authmode ]. u_int );
229
243
return mp_const_none ;
230
244
}
231
245
STATIC MP_DEFINE_CONST_FUN_OBJ_KW (wifi_radio_start_ap_obj , 1 , wifi_radio_start_ap );
@@ -455,8 +469,13 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = {
455
469
456
470
{ MP_ROM_QSTR (MP_QSTR_start_station ), MP_ROM_PTR (& wifi_radio_start_station_obj ) },
457
471
{ MP_ROM_QSTR (MP_QSTR_stop_station ), MP_ROM_PTR (& wifi_radio_stop_station_obj ) },
458
- { MP_ROM_QSTR (MP_QSTR_start_ap ), MP_ROM_PTR (& wifi_radio_start_ap_obj ) },
459
472
{ MP_ROM_QSTR (MP_QSTR_stop_ap ), MP_ROM_PTR (& wifi_radio_stop_ap_obj ) },
473
+ { MP_ROM_QSTR (MP_QSTR_start_ap ), MP_ROM_PTR (& wifi_radio_start_ap_obj ) },
474
+ { MP_ROM_QSTR (MP_QSTR_OPEN ), MP_ROM_INT (WIFI_RADIO_AUTH_OPEN ) },
475
+ { MP_ROM_QSTR (MP_QSTR_WPA_PSK ), MP_ROM_INT (WIFI_RADIO_AUTH_WPA_PSK ) },
476
+ { MP_ROM_QSTR (MP_QSTR_WPA2_PSK ), MP_ROM_INT (WIFI_RADIO_AUTH_WPA2_PSK ) },
477
+ { MP_ROM_QSTR (MP_QSTR_WPA_WPA2_PSK ), MP_ROM_INT (WIFI_RADIO_AUTH_WPA_WPA2_PSK ) },
478
+
460
479
{ MP_ROM_QSTR (MP_QSTR_connect ), MP_ROM_PTR (& wifi_radio_connect_obj ) },
461
480
// { MP_ROM_QSTR(MP_QSTR_connect_to_enterprise), MP_ROM_PTR(&wifi_radio_connect_to_enterprise_obj) },
462
481
0 commit comments