extmod/network_cyw43: Rename WLAN keyword args to ssid/security/key.

Rename WLAN keyword args to scan(), connect() and config() to be more
consistent across ports and WLAN drivers.  This change is backwards
compatible and will support obsolete keyword args, except for positional
"essid" which is now deprecated in favor of "ssid".

The changed argument names are
- "essid" changed to "ssid"
- "auth" or "authmode" changed to "security"
- "password" changed to "key"

Addresses issue #8083.
This commit is contained in:
iabdalkader 2022-06-04 12:07:30 +02:00 committed by Damien George
parent 868f23b362
commit c502cf73e0
1 changed files with 23 additions and 7 deletions

View File

@ -163,9 +163,10 @@ STATIC int network_cyw43_scan_cb(void *env, const cyw43_ev_scan_result_t *res) {
}
STATIC mp_obj_t network_cyw43_scan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_passive, ARG_essid, ARG_bssid };
enum { ARG_passive, ARG_ssid, ARG_essid, ARG_bssid };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_passive, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
{ MP_QSTR_ssid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_essid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_bssid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
};
@ -174,13 +175,18 @@ STATIC mp_obj_t network_cyw43_scan(size_t n_args, const mp_obj_t *pos_args, mp_m
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
// Deprecated kwarg
if (args[ARG_essid].u_obj != mp_const_none) {
args[ARG_ssid].u_obj = args[ARG_essid].u_obj;
}
cyw43_wifi_scan_options_t opts;
opts.scan_type = args[ARG_passive].u_bool ? 1 : 0;
if (args[ARG_essid].u_obj == mp_const_none) {
if (args[ARG_ssid].u_obj == mp_const_none) {
opts.ssid_len = 0;
} else {
mp_buffer_info_t ssid;
mp_get_buffer_raise(args[ARG_essid].u_obj, &ssid, MP_BUFFER_READ);
mp_get_buffer_raise(args[ARG_ssid].u_obj, &ssid, MP_BUFFER_READ);
opts.ssid_len = MIN(ssid.len, sizeof(opts.ssid));
memcpy(opts.ssid, ssid.buf, opts.ssid_len);
}
@ -210,11 +216,12 @@ STATIC mp_obj_t network_cyw43_scan(size_t n_args, const mp_obj_t *pos_args, mp_m
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(network_cyw43_scan_obj, 1, network_cyw43_scan);
STATIC mp_obj_t network_cyw43_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_essid, ARG_key, ARG_auth, ARG_bssid, ARG_channel };
enum { ARG_ssid, ARG_key, ARG_auth, ARG_security, ARG_bssid, ARG_channel };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_essid, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_key, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_auth, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
{ MP_QSTR_security, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
{ MP_QSTR_bssid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
};
@ -223,8 +230,13 @@ STATIC mp_obj_t network_cyw43_connect(size_t n_args, const mp_obj_t *pos_args, m
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
// Deprecated kwarg
if (args[ARG_auth].u_int != -1) {
args[ARG_security] = args[ARG_auth];
}
mp_buffer_info_t ssid;
mp_get_buffer_raise(args[ARG_essid].u_obj, &ssid, MP_BUFFER_READ);
mp_get_buffer_raise(args[ARG_ssid].u_obj, &ssid, MP_BUFFER_READ);
mp_buffer_info_t key;
key.buf = NULL;
if (args[ARG_key].u_obj != mp_const_none) {
@ -238,7 +250,8 @@ STATIC mp_obj_t network_cyw43_connect(size_t n_args, const mp_obj_t *pos_args, m
mp_raise_ValueError(NULL);
}
}
int ret = cyw43_wifi_join(self->cyw, ssid.len, ssid.buf, key.len, key.buf, args[ARG_auth].u_int, bssid.buf, args[ARG_channel].u_int);
int ret = cyw43_wifi_join(self->cyw, ssid.len, ssid.buf, key.len, key.buf,
args[ARG_security].u_int, bssid.buf, args[ARG_channel].u_int);
if (ret != 0) {
mp_raise_OSError(-ret);
}
@ -330,6 +343,7 @@ STATIC mp_obj_t network_cyw43_config(size_t n_args, const mp_obj_t *args, mp_map
cyw43_ioctl(self->cyw, CYW43_IOCTL_GET_CHANNEL, 4, buf, self->itf);
return MP_OBJ_NEW_SMALL_INT(nw_get_le32(buf));
}
case MP_QSTR_ssid:
case MP_QSTR_essid: {
if (self->itf == CYW43_ITF_STA) {
uint8_t buf[36];
@ -376,6 +390,7 @@ STATIC mp_obj_t network_cyw43_config(size_t n_args, const mp_obj_t *args, mp_map
cyw43_wifi_ap_set_channel(self->cyw, mp_obj_get_int(e->value));
break;
}
case MP_QSTR_ssid:
case MP_QSTR_essid: {
size_t len;
const char *str = mp_obj_str_get_data(e->value, &len);
@ -397,6 +412,7 @@ STATIC mp_obj_t network_cyw43_config(size_t n_args, const mp_obj_t *args, mp_map
}
break;
}
case MP_QSTR_key:
case MP_QSTR_password: {
size_t len;
const char *str = mp_obj_str_get_data(e->value, &len);