make authmode settable
This commit is contained in:
parent
7c845818b3
commit
6640db9555
@ -350,7 +350,7 @@ msgstr ""
|
|||||||
msgid "All state machines in use"
|
msgid "All state machines in use"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c
|
#: ports/atmel-samd/audio_dma.c
|
||||||
msgid "All sync event channels in use"
|
msgid "All sync event channels in use"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
@ -441,6 +441,10 @@ msgstr ""
|
|||||||
msgid "Attempted heap allocation when VM not running."
|
msgid "Attempted heap allocation when VM not running."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: shared-bindings/wifi/Radio.c
|
||||||
|
msgid "AuthMode.OPEN is not used with password"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#: shared-bindings/wifi/Radio.c
|
#: shared-bindings/wifi/Radio.c
|
||||||
msgid "Authentication failure"
|
msgid "Authentication failure"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
@ -1193,6 +1197,10 @@ msgstr ""
|
|||||||
msgid "Invalid ADC Unit value"
|
msgid "Invalid ADC Unit value"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: ports/esp32s2/common-hal/wifi/Radio.c
|
||||||
|
msgid "Invalid AuthMode"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#: shared-module/displayio/OnDiskBitmap.c
|
#: shared-module/displayio/OnDiskBitmap.c
|
||||||
msgid "Invalid BMP file"
|
msgid "Invalid BMP file"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
@ -2115,14 +2123,6 @@ msgstr ""
|
|||||||
msgid "Timeout is too long: Maximum timeout length is %d seconds"
|
msgid "Timeout is too long: Maximum timeout length is %d seconds"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c
|
|
||||||
msgid "Timeout waiting for DRDY"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c
|
|
||||||
msgid "Timeout waiting for VSYNC"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: supervisor/shared/safe_mode.c
|
#: supervisor/shared/safe_mode.c
|
||||||
msgid "To exit, please reset the board without "
|
msgid "To exit, please reset the board without "
|
||||||
msgstr ""
|
msgstr ""
|
||||||
@ -2352,10 +2352,6 @@ msgid ""
|
|||||||
"To list built-in modules please do `help(\"modules\")`.\n"
|
"To list built-in modules please do `help(\"modules\")`.\n"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: shared-bindings/wifi/Radio.c
|
|
||||||
msgid "WiFi password is not used with OPEN authentication"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: shared-bindings/wifi/Radio.c
|
#: shared-bindings/wifi/Radio.c
|
||||||
msgid "WiFi password must be between 8 and 63 characters"
|
msgid "WiFi password must be between 8 and 63 characters"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "py/enum.h"
|
|
||||||
#include "shared-bindings/wifi/Network.h"
|
#include "shared-bindings/wifi/Network.h"
|
||||||
#include "shared-bindings/wifi/AuthMode.h"
|
#include "shared-bindings/wifi/AuthMode.h"
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "shared-bindings/ipaddress/IPv4Address.h"
|
#include "shared-bindings/ipaddress/IPv4Address.h"
|
||||||
#include "shared-bindings/wifi/ScannedNetworks.h"
|
#include "shared-bindings/wifi/ScannedNetworks.h"
|
||||||
|
#include "shared-bindings/wifi/AuthMode.h"
|
||||||
#include "shared-module/ipaddress/__init__.h"
|
#include "shared-module/ipaddress/__init__.h"
|
||||||
|
|
||||||
#include "components/esp_wifi/include/esp_wifi.h"
|
#include "components/esp_wifi/include/esp_wifi.h"
|
||||||
@ -165,6 +166,33 @@ void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) {
|
|||||||
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) {
|
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);
|
||||||
|
|
||||||
|
switch (authmode) {
|
||||||
|
case (1 << AUTHMODE_OPEN):
|
||||||
|
authmode = WIFI_AUTH_OPEN;
|
||||||
|
break;
|
||||||
|
case ((1 << AUTHMODE_WPA) | (1 << AUTHMODE_PSK)):
|
||||||
|
authmode = WIFI_AUTH_WPA_PSK;
|
||||||
|
break;
|
||||||
|
case ((1 << AUTHMODE_WPA2) | (1 << AUTHMODE_PSK)):
|
||||||
|
authmode = WIFI_AUTH_WPA2_PSK;
|
||||||
|
break;
|
||||||
|
case ((1 << AUTHMODE_WPA) | (1 << AUTHMODE_WPA2) | (1 << AUTHMODE_PSK)):
|
||||||
|
authmode = WIFI_AUTH_WPA_WPA2_PSK;
|
||||||
|
break;
|
||||||
|
case ((1 << AUTHMODE_WPA2) | (1 << AUTHMODE_ENTERPRISE)):
|
||||||
|
authmode = WIFI_AUTH_WPA2_ENTERPRISE;
|
||||||
|
break;
|
||||||
|
case ((1 << AUTHMODE_WPA3) | (1 << AUTHMODE_PSK)):
|
||||||
|
authmode = WIFI_AUTH_WPA3_PSK;
|
||||||
|
break;
|
||||||
|
case ((1 << AUTHMODE_WPA2) | (1 << AUTHMODE_WPA3) | (1 << AUTHMODE_PSK)):
|
||||||
|
authmode = WIFI_AUTH_WPA2_WPA3_PSK;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
mp_raise_ValueError(translate("Invalid AuthMode"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
wifi_config_t *config = &self->ap_config;
|
wifi_config_t *config = &self->ap_config;
|
||||||
memcpy(&config->ap.ssid, ssid, ssid_len);
|
memcpy(&config->ap.ssid, ssid, ssid_len);
|
||||||
config->ap.ssid[ssid_len] = 0;
|
config->ap.ssid[ssid_len] = 0;
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_AUTHMODE_H
|
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_AUTHMODE_H
|
||||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_AUTHMODE_H
|
#define MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_AUTHMODE_H
|
||||||
|
|
||||||
|
#include "py/enum.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
AUTHMODE_OPEN,
|
AUTHMODE_OPEN,
|
||||||
AUTHMODE_WEP,
|
AUTHMODE_WEP,
|
||||||
@ -38,5 +40,6 @@ typedef enum {
|
|||||||
} wifi_authmode_t;
|
} wifi_authmode_t;
|
||||||
|
|
||||||
extern const mp_obj_type_t wifi_authmode_type;
|
extern const mp_obj_type_t wifi_authmode_type;
|
||||||
|
extern const cp_enum_obj_t authmode_OPEN_obj;
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_AUTHMODE_H
|
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_AUTHMODE_H
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "shared-bindings/wifi/__init__.h"
|
#include "shared-bindings/wifi/__init__.h"
|
||||||
|
#include "shared-bindings/wifi/AuthMode.h"
|
||||||
|
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -190,19 +191,13 @@ 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,
|
//| channel: Optional[int] = 1,
|
||||||
//| authmode: Optional[int] = WPA_WPA2_PSK) -> None:
|
//| authmode: Optional[AuthMode]) -> None:
|
||||||
//| """Starts an Access Point with the specified ssid and password
|
//| """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
|
||||||
//| a station is already operating on a different channel.
|
//| a station is already operating on a different channel.
|
||||||
@ -217,29 +212,42 @@ STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_
|
|||||||
{ 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} },
|
{ MP_QSTR_authmode, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||||
};
|
};
|
||||||
|
|
||||||
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
||||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
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);
|
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||||
|
|
||||||
|
uint8_t authmode = 0;
|
||||||
|
if (args[ARG_authmode].u_obj != MP_OBJ_NULL) {
|
||||||
|
mp_obj_iter_buf_t iter_buf;
|
||||||
|
mp_obj_t item, iterable = mp_getiter(args[ARG_authmode].u_obj, &iter_buf);
|
||||||
|
while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
|
||||||
|
authmode |= (1 << (wifi_authmode_t)cp_enum_value(&wifi_authmode_type, item));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mp_buffer_info_t ssid;
|
mp_buffer_info_t ssid;
|
||||||
mp_get_buffer_raise(args[ARG_ssid].u_obj, &ssid, MP_BUFFER_READ);
|
mp_get_buffer_raise(args[ARG_ssid].u_obj, &ssid, MP_BUFFER_READ);
|
||||||
|
|
||||||
mp_buffer_info_t password;
|
mp_buffer_info_t password;
|
||||||
password.len = 0;
|
password.len = 0;
|
||||||
if (args[ARG_password].u_obj != MP_OBJ_NULL) {
|
if (args[ARG_password].u_obj != MP_OBJ_NULL) {
|
||||||
|
if (authmode == 1) {
|
||||||
|
mp_raise_ValueError(translate("AuthMode.OPEN is not used with password"));
|
||||||
|
} else if (authmode == 0) {
|
||||||
|
authmode = (1 << AUTHMODE_WPA) | (1 << AUTHMODE_WPA2) | (1 << AUTHMODE_PSK);
|
||||||
|
}
|
||||||
mp_get_buffer_raise(args[ARG_password].u_obj, &password, MP_BUFFER_READ);
|
mp_get_buffer_raise(args[ARG_password].u_obj, &password, MP_BUFFER_READ);
|
||||||
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) {
|
} else {
|
||||||
mp_raise_ValueError(translate("WiFi password is not used with OPEN authentication"));
|
authmode = 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
common_hal_wifi_radio_start_ap(self, ssid.buf, ssid.len, password.buf, password.len, args[ARG_channel].u_int, authmode);
|
||||||
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);
|
||||||
@ -503,10 +511,6 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = {
|
|||||||
{ 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_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_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,18 +71,6 @@ 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);
|
||||||
|
|
||||||
|
@ -27,11 +27,12 @@
|
|||||||
#include "py/objexcept.h"
|
#include "py/objexcept.h"
|
||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "shared-bindings/wifi/__init__.h"
|
#include "shared-bindings/wifi/__init__.h"
|
||||||
|
#include "shared-bindings/wifi/AuthMode.h"
|
||||||
#include "shared-bindings/wifi/Network.h"
|
#include "shared-bindings/wifi/Network.h"
|
||||||
#include "shared-bindings/wifi/Radio.h"
|
#include "shared-bindings/wifi/Radio.h"
|
||||||
|
|
||||||
//| """
|
//| """
|
||||||
//| The `wifi` module provides necessary low-level functionality for managing wifi
|
//| The `wifi` module provides necessary low-level functionality for managing
|
||||||
//| wifi connections. Use `socketpool` for communicating over the network."""
|
//| wifi connections. Use `socketpool` for communicating over the network."""
|
||||||
//|
|
//|
|
||||||
//| radio: Radio
|
//| radio: Radio
|
||||||
@ -49,15 +50,16 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(wifi___init___obj, wifi___init__);
|
|||||||
|
|
||||||
|
|
||||||
STATIC const mp_rom_map_elem_t wifi_module_globals_table[] = {
|
STATIC const mp_rom_map_elem_t wifi_module_globals_table[] = {
|
||||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_wifi) },
|
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_wifi) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_Network), MP_ROM_PTR(&wifi_network_type) },
|
{ MP_ROM_QSTR(MP_QSTR_Radio), MP_ROM_PTR(&wifi_radio_type) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_Radio), MP_ROM_PTR(&wifi_radio_type) },
|
{ MP_ROM_QSTR(MP_QSTR_Network), MP_ROM_PTR(&wifi_network_type) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_AuthMode), MP_ROM_PTR(&wifi_authmode_type) },
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
{ MP_ROM_QSTR(MP_QSTR_radio), MP_ROM_PTR(&common_hal_wifi_radio_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_radio), MP_ROM_PTR(&common_hal_wifi_radio_obj) },
|
||||||
|
|
||||||
// Initialization
|
// Initialization
|
||||||
{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&wifi___init___obj) },
|
{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&wifi___init___obj) },
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user