add authmode to start_ap()
This commit is contained in:
parent
747d72f5a5
commit
f20a53177b
|
@ -164,7 +164,7 @@ void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) {
|
||||||
set_mode_station(self, false);
|
set_mode_station(self, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel) {
|
void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint8_t authmode) {
|
||||||
set_mode_ap(self, true);
|
set_mode_ap(self, true);
|
||||||
|
|
||||||
wifi_config_t *config = &self->ap_config;
|
wifi_config_t *config = &self->ap_config;
|
||||||
|
@ -173,7 +173,7 @@ void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_
|
||||||
memcpy(&config->ap.password, password, password_len);
|
memcpy(&config->ap.password, password, password_len);
|
||||||
config->ap.password[password_len] = 0;
|
config->ap.password[password_len] = 0;
|
||||||
config->ap.channel = channel;
|
config->ap.channel = channel;
|
||||||
config->ap.authmode = WIFI_AUTH_WPA2_PSK;
|
config->ap.authmode = authmode;
|
||||||
config->ap.max_connection = 4;
|
config->ap.max_connection = 4;
|
||||||
esp_wifi_set_config(WIFI_IF_AP, config);
|
esp_wifi_set_config(WIFI_IF_AP, config);
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,23 +190,34 @@ STATIC mp_obj_t wifi_radio_stop_station(mp_obj_t self) {
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station);
|
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station);
|
||||||
|
|
||||||
|
//| OPEN: int
|
||||||
|
//| WPA_PSK: int
|
||||||
|
//| WPA2_PSK: int
|
||||||
|
//| WPA_WPA2_PSK: int
|
||||||
|
//|
|
||||||
//| def start_ap(self,
|
//| def start_ap(self,
|
||||||
//| ssid: ReadableBuffer,
|
//| ssid: ReadableBuffer,
|
||||||
//| password: ReadableBuffer = b"",
|
//| password: ReadableBuffer = b"",
|
||||||
//| *,
|
//| *,
|
||||||
//| channel: Optional[int] = 1) -> None:
|
//| channel: Optional[int] = 1,
|
||||||
//| """Starts an Access Point with the specified ssid and password.
|
//| authmode: Optional[int] = WPA_WPA2_PSK) -> None:
|
||||||
|
//| """Starts an Access Point with the specified ssid and password
|
||||||
|
//| If an empty.
|
||||||
//|
|
//|
|
||||||
//| If ``channel`` is given, the access point will use that channel unless
|
//| If ``channel`` is given, the access point will use that channel unless
|
||||||
//| wifi is already operating on a different channel due to an active station."""
|
//| a station is already operating on a different channel.
|
||||||
|
//|
|
||||||
|
//| If ``authmode`` is given, the access point will use that Authentication
|
||||||
|
//| mode. If a password is given, ``authmode`` must not be ``OPEN``."""
|
||||||
//| ...
|
//| ...
|
||||||
//|
|
//|
|
||||||
STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||||
enum { ARG_ssid, ARG_password, ARG_channel };
|
enum { ARG_ssid, ARG_password, ARG_channel, ARG_authmode };
|
||||||
static const mp_arg_t allowed_args[] = {
|
static const mp_arg_t allowed_args[] = {
|
||||||
{ MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
{ MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||||
{ MP_QSTR_password, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
{ MP_QSTR_password, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||||
{ MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} },
|
{ MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} },
|
||||||
|
{ MP_QSTR_authmode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = WIFI_RADIO_AUTH_WPA_WPA2_PSK} },
|
||||||
};
|
};
|
||||||
|
|
||||||
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
||||||
|
@ -223,9 +234,12 @@ STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_
|
||||||
if (password.len > 0 && (password.len < 8 || password.len > 63)) {
|
if (password.len > 0 && (password.len < 8 || password.len > 63)) {
|
||||||
mp_raise_ValueError(translate("WiFi password must be between 8 and 63 characters"));
|
mp_raise_ValueError(translate("WiFi password must be between 8 and 63 characters"));
|
||||||
}
|
}
|
||||||
|
if (args[ARG_authmode].u_int == WIFI_RADIO_AUTH_OPEN) {
|
||||||
|
mp_raise_ValueError(translate("WiFi password is not used with OPEN authentication"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
common_hal_wifi_radio_start_ap(self, ssid.buf, ssid.len, password.buf, password.len, args[ARG_channel].u_int);
|
common_hal_wifi_radio_start_ap(self, ssid.buf, ssid.len, password.buf, password.len, args[ARG_channel].u_int, args[ARG_authmode].u_int);
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_start_ap_obj, 1, wifi_radio_start_ap);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_start_ap_obj, 1, wifi_radio_start_ap);
|
||||||
|
@ -455,8 +469,13 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = {
|
||||||
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_start_station), MP_ROM_PTR(&wifi_radio_start_station_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_start_station), MP_ROM_PTR(&wifi_radio_start_station_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_stop_station), MP_ROM_PTR(&wifi_radio_stop_station_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_stop_station), MP_ROM_PTR(&wifi_radio_stop_station_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_start_ap), MP_ROM_PTR(&wifi_radio_start_ap_obj) },
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_stop_ap), MP_ROM_PTR(&wifi_radio_stop_ap_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_stop_ap), MP_ROM_PTR(&wifi_radio_stop_ap_obj) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_start_ap), MP_ROM_PTR(&wifi_radio_start_ap_obj) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_OPEN), MP_ROM_INT(WIFI_RADIO_AUTH_OPEN) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_WPA_PSK), MP_ROM_INT(WIFI_RADIO_AUTH_WPA_PSK) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_WPA2_PSK), MP_ROM_INT(WIFI_RADIO_AUTH_WPA2_PSK) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_WPA_WPA2_PSK), MP_ROM_INT(WIFI_RADIO_AUTH_WPA_WPA2_PSK) },
|
||||||
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&wifi_radio_connect_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&wifi_radio_connect_obj) },
|
||||||
// { MP_ROM_QSTR(MP_QSTR_connect_to_enterprise), MP_ROM_PTR(&wifi_radio_connect_to_enterprise_obj) },
|
// { MP_ROM_QSTR(MP_QSTR_connect_to_enterprise), MP_ROM_PTR(&wifi_radio_connect_to_enterprise_obj) },
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,18 @@ typedef enum {
|
||||||
WIFI_RADIO_ERROR_AP_TSF_RESET = 206,
|
WIFI_RADIO_ERROR_AP_TSF_RESET = 206,
|
||||||
} wifi_radio_error_t;
|
} wifi_radio_error_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
WIFI_RADIO_AUTH_OPEN = 0, // OK
|
||||||
|
WIFI_RADIO_AUTH_WEP, // not supported in SoftAP
|
||||||
|
WIFI_RADIO_AUTH_WPA_PSK, // OK
|
||||||
|
WIFI_RADIO_AUTH_WPA2_PSK, // OK
|
||||||
|
WIFI_RADIO_AUTH_WPA_WPA2_PSK, // OK
|
||||||
|
WIFI_RADIO_AUTH_WPA2_ENTERPRISE, // not currently supported
|
||||||
|
WIFI_RADIO_AUTH_WPA3_PSK, // not currently supported
|
||||||
|
WIFI_RADIO_AUTH_WPA2_WPA3_PSK, // not currently supported
|
||||||
|
WIFI_RADIO_AUTH_MAX, // not currently supported
|
||||||
|
} wifi_radio_authmode_t;
|
||||||
|
|
||||||
extern bool common_hal_wifi_radio_get_enabled(wifi_radio_obj_t *self);
|
extern bool common_hal_wifi_radio_get_enabled(wifi_radio_obj_t *self);
|
||||||
extern void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled);
|
extern void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled);
|
||||||
|
|
||||||
|
@ -85,7 +97,7 @@ extern void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self)
|
||||||
|
|
||||||
extern void common_hal_wifi_radio_start_station(wifi_radio_obj_t *self);
|
extern void common_hal_wifi_radio_start_station(wifi_radio_obj_t *self);
|
||||||
extern void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self);
|
extern void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self);
|
||||||
extern void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel);
|
extern void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint8_t authmode);
|
||||||
extern void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *self);
|
extern void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *self);
|
||||||
|
|
||||||
extern wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t *bssid, size_t bssid_len);
|
extern wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t *bssid, size_t bssid_len);
|
||||||
|
|
Loading…
Reference in New Issue