Commit 30691ed2 authored by Damien George's avatar Damien George

drivers/cyw43: Make wifi join fail if interface is not active.

Otherwise the Python network object continues to report that it is
attempting to connect.

Also make the return error code consistent with wifi scan.
Signed-off-by: default avatarDamien George <damien@micropython.org>
parent 52a78e69
......@@ -27,6 +27,7 @@
#include <stdio.h>
#include <string.h>
#include "py/mperrno.h"
#include "py/mphal.h"
#include "drivers/cyw43/cyw43.h"
#include "pendsv.h"
......@@ -52,6 +53,9 @@
#define WIFI_JOIN_STATE_KEYED (0x0800)
#define WIFI_JOIN_STATE_ALL (0x0e01)
#define CYW43_STA_IS_ACTIVE(self) (((self)->itf_state >> CYW43_ITF_STA) & 1)
#define CYW43_AP_IS_ACTIVE(self) (((self)->itf_state >> CYW43_ITF_AP) & 1)
cyw43_t cyw43_state;
void (*cyw43_poll)(void);
uint32_t cyw43_sleep;
......@@ -475,7 +479,7 @@ void cyw43_wifi_set_up(cyw43_t *self, int itf, bool up) {
int cyw43_wifi_scan(cyw43_t *self, cyw43_wifi_scan_options_t *opts, void *env, int (*result_cb)(void*, const cyw43_ev_scan_result_t*)) {
if (self->itf_state == 0) {
return -1;
return -MP_EPERM;
}
cyw43_ensure_up(self);
......@@ -518,6 +522,10 @@ int cyw43_wifi_link_status(cyw43_t *self, int itf) {
// WiFi STA
int cyw43_wifi_join(cyw43_t *self, size_t ssid_len, const uint8_t *ssid, size_t key_len, const uint8_t *key, uint32_t auth_type, const uint8_t *bssid, uint32_t channel) {
if (!CYW43_STA_IS_ACTIVE(self)) {
return -MP_EPERM;
}
int ret = cyw43_ensure_up(self);
if (ret) {
return ret;
......
......@@ -196,7 +196,7 @@ STATIC mp_obj_t network_cyw43_scan(size_t n_args, const mp_obj_t *pos_args, mp_m
int scan_res = cyw43_wifi_scan(self->cyw, &opts, MP_OBJ_TO_PTR(res), network_cyw43_scan_cb);
if (scan_res < 0) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("STA must be active"));
mp_raise_OSError(-scan_res);
}
// Wait for scan to finish, with a 10s timeout
......@@ -240,7 +240,7 @@ STATIC mp_obj_t network_cyw43_connect(size_t n_args, const mp_obj_t *pos_args, m
}
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);
if (ret != 0) {
mp_raise_OSError(ret);
mp_raise_OSError(-ret);
}
return mp_const_none;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment