Merge pull request #3944 from BennyE/wifi-authmode

esp32-s2: Adding authmode keyword
This commit is contained in:
Scott Shawcroft 2021-01-11 16:05:28 -08:00 committed by GitHub
commit 081249f796
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 1 deletions

View File

@ -54,3 +54,37 @@ mp_obj_t common_hal_wifi_network_get_country(wifi_network_obj_t *self) {
// 2 instead of strlen(cstr) as this gives us only the country-code // 2 instead of strlen(cstr) as this gives us only the country-code
return mp_obj_new_str(cstr, 2); return mp_obj_new_str(cstr, 2);
} }
mp_obj_t common_hal_wifi_network_get_authmode(wifi_network_obj_t *self) {
const char* authmode = "";
switch (self->record.authmode) {
case WIFI_AUTH_OPEN:
authmode = "OPEN";
break;
case WIFI_AUTH_WEP:
authmode = "WEP";
break;
case WIFI_AUTH_WPA_PSK:
authmode = "WPA_PSK";
break;
case WIFI_AUTH_WPA2_PSK:
authmode = "WPA2_PSK";
break;
case WIFI_AUTH_WPA_WPA2_PSK:
authmode = "WPA_WPA2_PSK";
break;
case WIFI_AUTH_WPA2_ENTERPRISE:
authmode = "WPA2_ENTERPRISE";
break;
case WIFI_AUTH_WPA3_PSK:
authmode = "WPA3_PSK";
break;
case WIFI_AUTH_WPA2_WPA3_PSK:
authmode = "WPA2_WPA3_PSK";
break;
default:
authmode = "UNKNOWN";
break;
}
return mp_obj_new_str(authmode, strlen(authmode));
}

View File

@ -124,6 +124,21 @@ const mp_obj_property_t wifi_network_country_obj = {
(mp_obj_t)&mp_const_none_obj }, (mp_obj_t)&mp_const_none_obj },
}; };
//| authmode: str
//| """String id of the authmode"""
//|
STATIC mp_obj_t wifi_network_get_authmode(mp_obj_t self) {
return common_hal_wifi_network_get_authmode(self);
}
MP_DEFINE_CONST_FUN_OBJ_1(wifi_network_get_authmode_obj, wifi_network_get_authmode);
const mp_obj_property_t wifi_network_authmode_obj = {
.base.type = &mp_type_property,
.proxy = { (mp_obj_t)&wifi_network_get_authmode_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj },
};
STATIC const mp_rom_map_elem_t wifi_network_locals_dict_table[] = { STATIC const mp_rom_map_elem_t wifi_network_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_ssid), MP_ROM_PTR(&wifi_network_ssid_obj) }, { MP_ROM_QSTR(MP_QSTR_ssid), MP_ROM_PTR(&wifi_network_ssid_obj) },
@ -131,6 +146,7 @@ STATIC const mp_rom_map_elem_t wifi_network_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_rssi), MP_ROM_PTR(&wifi_network_rssi_obj) }, { MP_ROM_QSTR(MP_QSTR_rssi), MP_ROM_PTR(&wifi_network_rssi_obj) },
{ MP_ROM_QSTR(MP_QSTR_channel), MP_ROM_PTR(&wifi_network_channel_obj) }, { MP_ROM_QSTR(MP_QSTR_channel), MP_ROM_PTR(&wifi_network_channel_obj) },
{ MP_ROM_QSTR(MP_QSTR_country), MP_ROM_PTR(&wifi_network_country_obj) }, { MP_ROM_QSTR(MP_QSTR_country), MP_ROM_PTR(&wifi_network_country_obj) },
{ MP_ROM_QSTR(MP_QSTR_authmode), MP_ROM_PTR(&wifi_network_authmode_obj) },
}; };
STATIC MP_DEFINE_CONST_DICT(wifi_network_locals_dict, wifi_network_locals_dict_table); STATIC MP_DEFINE_CONST_DICT(wifi_network_locals_dict, wifi_network_locals_dict_table);

View File

@ -40,5 +40,6 @@ extern mp_obj_t common_hal_wifi_network_get_bssid(wifi_network_obj_t *self);
extern mp_obj_t common_hal_wifi_network_get_rssi(wifi_network_obj_t *self); extern mp_obj_t common_hal_wifi_network_get_rssi(wifi_network_obj_t *self);
extern mp_obj_t common_hal_wifi_network_get_channel(wifi_network_obj_t *self); extern mp_obj_t common_hal_wifi_network_get_channel(wifi_network_obj_t *self);
extern mp_obj_t common_hal_wifi_network_get_country(wifi_network_obj_t *self); extern mp_obj_t common_hal_wifi_network_get_country(wifi_network_obj_t *self);
extern mp_obj_t common_hal_wifi_network_get_authmode(wifi_network_obj_t *self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_NETWORK_H #endif // MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_NETWORK_H

View File

@ -295,7 +295,7 @@ const mp_obj_property_t wifi_radio_ipv4_dns_obj = {
}; };
//| ap_info: Optional[Network] //| ap_info: Optional[Network]
//| """Network object containing BSSID, SSID, channel, country and RSSI when connected to an access point. None otherwise.""" //| """Network object containing BSSID, SSID, authmode, channel, country and RSSI when connected to an access point. None otherwise."""
//| //|
STATIC mp_obj_t wifi_radio_get_ap_info(mp_obj_t self) { STATIC mp_obj_t wifi_radio_get_ap_info(mp_obj_t self) {
return common_hal_wifi_radio_get_ap_info(self); return common_hal_wifi_radio_get_ap_info(self);