@@ -316,19 +316,24 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station);
316316//| password: Union[str | ReadableBuffer] = b"",
317317//| *,
318318//| channel: int = 1,
319- //| authmode: Optional [AuthMode] = None ,
319+ //| authmode: Iterable [AuthMode] = () ,
320320//| max_connections: Optional[int] = 4,
321321//| ) -> None:
322322//| """Starts running an access point with the specified ssid and password.
323323//|
324324//| If ``channel`` is given, the access point will use that channel unless
325325//| a station is already operating on a different channel.
326326//|
327- //| If ``authmode`` is not None, the access point will use that Authentication
328- //| mode. If a non-empty password is given, ``authmode`` must not be ``OPEN``.
329- //| If ``authmode`` is not given or is None,
330- //| ``OPEN`` will be used when the password is the empty string,
331- //| otherwise ``authmode`` will be ``WPA_WPA2_PSK``.
327+ //| If ``authmode`` is not None, the access point will use the given authentication modes.
328+ //| If a non-empty password is given, ``authmode`` must not include ``OPEN``.
329+ //| If ``authmode`` is not given or is an empty iterable,
330+ //| ``(wifi.AuthMode.OPEN,)`` will be used when the password is the empty string,
331+ //| otherwise ``authmode`` will be ``(wifi.AuthMode.WPA, wifi.AuthMode.WPA2, wifi.AuthMode.PSK)``.
332+ //|
333+ //| **Limitations:** On Espressif, ``authmode`` with a non-empty password must include
334+ //| `wifi.AuthMode.PSK`, and one or both of `wifi.AuthMode.WPA` and `wifi.AuthMode.WPA2`.
335+ //| On Pi Pico W, ``authmode`` is ignored; it is always ``(wifi.AuthMode.WPA2, wifi.AuthMode.PSK)`
336+ //| with a non-empty password, or ``(wifi.AuthMode.OPEN,)`` when no password is given.
332337//|
333338//| The length of ``password`` must be 8-63 characters if it is ASCII,
334339//| or exactly 64 hexadecimal characters if it is the hex form of the 256-bit key.
@@ -342,22 +347,20 @@ STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_
342347 { MP_QSTR_ssid , MP_ARG_REQUIRED | MP_ARG_OBJ },
343348 { MP_QSTR_password , MP_ARG_OBJ , {.u_obj = mp_const_empty_bytes } },
344349 { MP_QSTR_channel , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 1 } },
345- { MP_QSTR_authmode , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } },
350+ { MP_QSTR_authmode , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_empty_tuple } },
346351 { MP_QSTR_max_connections , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 4 } },
347352 };
348353
349354 wifi_radio_obj_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
350355 mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
351356 mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
352357
353- // 0 indicates mode wasn't given.
354- uint32_t authmodes = 0 ;
355- if (args [ARG_authmode ].u_obj != mp_const_none ) {
356- mp_obj_iter_buf_t iter_buf ;
357- mp_obj_t item , iterable = mp_getiter (args [ARG_authmode ].u_obj , & iter_buf );
358- while ((item = mp_iternext (iterable )) != MP_OBJ_STOP_ITERATION ) {
359- authmodes |= cp_enum_value (& wifi_authmode_type , item , MP_QSTR_authmode );
360- }
358+ // 0 indicates no modes were given. Otherwise authmode is the OR of bits signifying the modes.
359+ uint32_t authmode = 0 ;
360+ mp_obj_iter_buf_t iter_buf ;
361+ mp_obj_t item , iterable = mp_getiter (args [ARG_authmode ].u_obj , & iter_buf );
362+ while ((item = mp_iternext (iterable )) != MP_OBJ_STOP_ITERATION ) {
363+ authmode |= cp_enum_value (& wifi_authmode_type , item , MP_QSTR_authmode );
361364 }
362365
363366 mp_buffer_info_t ssid ;
@@ -366,28 +369,28 @@ STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_
366369
367370 mp_buffer_info_t password ;
368371 mp_get_buffer_raise (args [ARG_password ].u_obj , & password , MP_BUFFER_READ );
369- if (authmodes == 0 ) {
372+ if (authmode == 0 ) {
370373 if (password .len == 0 ) {
371- authmodes = AUTHMODE_OPEN ;
374+ authmode = AUTHMODE_OPEN ;
372375 } else {
373- authmodes = AUTHMODE_WPA | AUTHMODE_WPA2 | AUTHMODE_PSK ;
376+ authmode = AUTHMODE_WPA | AUTHMODE_WPA2 | AUTHMODE_PSK ;
374377 }
375378 }
376379
377380 mp_int_t channel = mp_arg_validate_int_range (args [ARG_channel ].u_int , 1 , 13 , MP_QSTR_channel );
378381
379- if (authmodes == AUTHMODE_OPEN && password .len > 0 ) {
382+ if (authmode == AUTHMODE_OPEN && password .len > 0 ) {
380383 mp_raise_ValueError (translate ("AuthMode.OPEN is not used with password" ));
381384 }
382385
383- if (authmodes != AUTHMODE_OPEN ) {
386+ if (authmode != AUTHMODE_OPEN ) {
384387 mp_arg_validate_length_range (password .len , 8 , 64 , MP_QSTR_password );
385388 if (password .len == 64 ) {
386389 validate_hex_password (password .buf , password .len );
387390 }
388391 }
389392
390- common_hal_wifi_radio_start_ap (self , ssid .buf , ssid .len , password .buf , password .len , channel , authmodes , args [ARG_max_connections ].u_int );
393+ common_hal_wifi_radio_start_ap (self , ssid .buf , ssid .len , password .buf , password .len , channel , authmode , args [ARG_max_connections ].u_int );
391394 return mp_const_none ;
392395}
393396STATIC MP_DEFINE_CONST_FUN_OBJ_KW (wifi_radio_start_ap_obj , 1 , wifi_radio_start_ap );
0 commit comments