diff options
author | iabdalkader <i.abdalkader@gmail.com> | 2024-03-04 12:13:37 +0100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2024-03-14 17:40:25 +1100 |
commit | 2b6f81f2b9d5135774d1b636802194f9666678d5 (patch) | |
tree | d82853bbbf4312e0812523c03f196b74eebde6ac | |
parent | 8b4a21cd64c8199601629e6ae08c746f85fdd068 (diff) | |
download | micropython-2b6f81f2b9d5135774d1b636802194f9666678d5.tar.gz micropython-2b6f81f2b9d5135774d1b636802194f9666678d5.zip |
extmod/network_ninaw10: Set the proper security mode if none provided.
If no security mode is provided, use WPA for station and WEP for AP. Note
only WEP is supported in AP mode.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
-rw-r--r-- | extmod/network_ninaw10.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/extmod/network_ninaw10.c b/extmod/network_ninaw10.c index e53061557c..6a60faeae9 100644 --- a/extmod/network_ninaw10.c +++ b/extmod/network_ninaw10.c @@ -260,7 +260,7 @@ static mp_obj_t network_ninaw10_connect(mp_uint_t n_args, const mp_obj_t *pos_ar static const mp_arg_t allowed_args[] = { { MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_key, MP_ARG_OBJ, {.u_obj = mp_const_none} }, - { MP_QSTR_security, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = NINA_SEC_WPA_PSK} }, + { MP_QSTR_security, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, { MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} }, }; @@ -276,15 +276,21 @@ static mp_obj_t network_ninaw10_connect(mp_uint_t n_args, const mp_obj_t *pos_ar mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("SSID can't be empty!")); } - // get key and sec + // get encryption key const char *key = NULL; - mp_uint_t security = NINA_SEC_OPEN; - if (args[ARG_key].u_obj != mp_const_none) { key = mp_obj_str_get_str(args[ARG_key].u_obj); - security = args[ARG_security].u_int; } + // get security mode + mp_uint_t security = args[ARG_security].u_int; + if (security == -1 && self->itf == MOD_NETWORK_STA_IF) { + security = NINA_SEC_WPA_PSK; + } else if (security == -1 && self->itf == MOD_NETWORK_AP_IF) { + security = NINA_SEC_WEP; + } + + // Ensure that the key is not empty if a security mode is used. if (security != NINA_SEC_OPEN && strlen(key) == 0) { mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Key can't be empty!")); } @@ -316,7 +322,7 @@ static mp_obj_t network_ninaw10_connect(mp_uint_t n_args, const mp_obj_t *pos_ar mp_uint_t channel = args[ARG_channel].u_int; if (security != NINA_SEC_OPEN && security != NINA_SEC_WEP) { - mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("AP mode supports WEP security only.")); + mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("AP mode only supports WEP or OPEN security modes")); } // Initialize WiFi in AP mode. |