@@ -316,19 +316,24 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station);
316
316
//| password: Union[str | ReadableBuffer] = b"",
317
317
//| *,
318
318
//| channel: int = 1,
319
- //| authmode: Optional [AuthMode] = None ,
319
+ //| authmode: Iterable [AuthMode] = () ,
320
320
//| max_connections: Optional[int] = 4,
321
321
//| ) -> None:
322
322
//| """Starts running an access point with the specified ssid and password.
323
323
//|
324
324
//| If ``channel`` is given, the access point will use that channel unless
325
325
//| a station is already operating on a different channel.
326
326
//|
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.
332
337
//|
333
338
//| The length of ``password`` must be 8-63 characters if it is ASCII,
334
339
//| 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_
342
347
{ MP_QSTR_ssid , MP_ARG_REQUIRED | MP_ARG_OBJ },
343
348
{ MP_QSTR_password , MP_ARG_OBJ , {.u_obj = mp_const_empty_bytes } },
344
349
{ 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 } },
346
351
{ MP_QSTR_max_connections , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 4 } },
347
352
};
348
353
349
354
wifi_radio_obj_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
350
355
mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
351
356
mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
352
357
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 );
361
364
}
362
365
363
366
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_
366
369
367
370
mp_buffer_info_t password ;
368
371
mp_get_buffer_raise (args [ARG_password ].u_obj , & password , MP_BUFFER_READ );
369
- if (authmodes == 0 ) {
372
+ if (authmode == 0 ) {
370
373
if (password .len == 0 ) {
371
- authmodes = AUTHMODE_OPEN ;
374
+ authmode = AUTHMODE_OPEN ;
372
375
} else {
373
- authmodes = AUTHMODE_WPA | AUTHMODE_WPA2 | AUTHMODE_PSK ;
376
+ authmode = AUTHMODE_WPA | AUTHMODE_WPA2 | AUTHMODE_PSK ;
374
377
}
375
378
}
376
379
377
380
mp_int_t channel = mp_arg_validate_int_range (args [ARG_channel ].u_int , 1 , 13 , MP_QSTR_channel );
378
381
379
- if (authmodes == AUTHMODE_OPEN && password .len > 0 ) {
382
+ if (authmode == AUTHMODE_OPEN && password .len > 0 ) {
380
383
mp_raise_ValueError (translate ("AuthMode.OPEN is not used with password" ));
381
384
}
382
385
383
- if (authmodes != AUTHMODE_OPEN ) {
386
+ if (authmode != AUTHMODE_OPEN ) {
384
387
mp_arg_validate_length_range (password .len , 8 , 64 , MP_QSTR_password );
385
388
if (password .len == 64 ) {
386
389
validate_hex_password (password .buf , password .len );
387
390
}
388
391
}
389
392
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 );
391
394
return mp_const_none ;
392
395
}
393
396
STATIC MP_DEFINE_CONST_FUN_OBJ_KW (wifi_radio_start_ap_obj , 1 , wifi_radio_start_ap );
0 commit comments