Skip to content

Commit

Permalink
extmod/network_nina: Fix the AP security mode constants.
Browse files Browse the repository at this point in the history
The only AP security mode supported is actually WPA/WPA2 not WEP. The firmware
command `0x19` starts the AP using `WIFI_AUTH_WPA_WPA2_PSK` mode.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
  • Loading branch information
iabdalkader committed Apr 24, 2024
1 parent 9c7f065 commit ee9fcdd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
8 changes: 4 additions & 4 deletions drivers/ninaw10/nina_wifi_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ typedef enum {

// AP mode commands.
NINA_CMD_START_AP_OPEN = 0x18,
NINA_CMD_START_AP_WEP = 0x19,
NINA_CMD_START_AP_WPA = 0x19,

// AP mode scan commands.
NINA_CMD_AP_START_SCAN = 0x36,
Expand Down Expand Up @@ -395,7 +395,7 @@ int nina_start_ap(const char *ssid, uint8_t security, const char *key, uint16_t
uint8_t status = NINA_STATUS_AP_FAILED;

if ((key == NULL && security != NINA_SEC_OPEN) ||
(security != NINA_SEC_OPEN && security != NINA_SEC_WEP)) {
(security != NINA_SEC_OPEN && security != NINA_SEC_WPA_PSK)) {
return -1;
}

Expand All @@ -406,8 +406,8 @@ int nina_start_ap(const char *ssid, uint8_t security, const char *key, uint16_t
return -1;
}
break;
case NINA_SEC_WEP:
if (nina_send_command_read_ack(NINA_CMD_START_AP_WEP,
case NINA_SEC_WPA_PSK:
if (nina_send_command_read_ack(NINA_CMD_START_AP_WPA,
3, ARG_8BITS, NINA_ARGS(ARG_STR(ssid), ARG_STR(key), ARG_BYTE(channel))) != SPI_ACK) {
return -1;
}
Expand Down
14 changes: 1 addition & 13 deletions extmod/network_ninaw10.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = -1} },
{ MP_QSTR_security, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = NINA_SEC_WPA_PSK} },
{ MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} },
};

Expand All @@ -271,7 +271,6 @@ static mp_obj_t network_ninaw10_connect(mp_uint_t n_args, const mp_obj_t *pos_ar

// get ssid
const char *ssid = mp_obj_str_get_str(args[ARG_ssid].u_obj);

if (strlen(ssid) == 0) {
mp_raise_ValueError(MP_ERROR_TEXT("SSID can't be empty"));
}
Expand All @@ -284,12 +283,6 @@ static mp_obj_t network_ninaw10_connect(mp_uint_t n_args, const mp_obj_t *pos_ar

// 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_ValueError(MP_ERROR_TEXT("key can't be empty"));
Expand Down Expand Up @@ -320,11 +313,6 @@ static mp_obj_t network_ninaw10_connect(mp_uint_t n_args, const mp_obj_t *pos_ar
soft_timer_reinsert(&mp_wifi_poll_timer, NINAW10_POLL_INTERVAL);
} else {
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 only supports WEP or OPEN security modes"));
}

// Initialize WiFi in AP mode.
if (nina_start_ap(ssid, security, key, channel) != 0) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("failed to start in AP mode"));
Expand Down

0 comments on commit ee9fcdd

Please sign in to comment.