Skip to content

Commit 081249f

Browse files
authored
Merge pull request #3944 from BennyE/wifi-authmode
esp32-s2: Adding authmode keyword
2 parents 3cf4d9c + 53e4d78 commit 081249f

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

ports/esp32s2/common-hal/wifi/Network.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,37 @@ mp_obj_t common_hal_wifi_network_get_country(wifi_network_obj_t *self) {
5454
// 2 instead of strlen(cstr) as this gives us only the country-code
5555
return mp_obj_new_str(cstr, 2);
5656
}
57+
58+
mp_obj_t common_hal_wifi_network_get_authmode(wifi_network_obj_t *self) {
59+
const char* authmode = "";
60+
switch (self->record.authmode) {
61+
case WIFI_AUTH_OPEN:
62+
authmode = "OPEN";
63+
break;
64+
case WIFI_AUTH_WEP:
65+
authmode = "WEP";
66+
break;
67+
case WIFI_AUTH_WPA_PSK:
68+
authmode = "WPA_PSK";
69+
break;
70+
case WIFI_AUTH_WPA2_PSK:
71+
authmode = "WPA2_PSK";
72+
break;
73+
case WIFI_AUTH_WPA_WPA2_PSK:
74+
authmode = "WPA_WPA2_PSK";
75+
break;
76+
case WIFI_AUTH_WPA2_ENTERPRISE:
77+
authmode = "WPA2_ENTERPRISE";
78+
break;
79+
case WIFI_AUTH_WPA3_PSK:
80+
authmode = "WPA3_PSK";
81+
break;
82+
case WIFI_AUTH_WPA2_WPA3_PSK:
83+
authmode = "WPA2_WPA3_PSK";
84+
break;
85+
default:
86+
authmode = "UNKNOWN";
87+
break;
88+
}
89+
return mp_obj_new_str(authmode, strlen(authmode));
90+
}

shared-bindings/wifi/Network.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,29 @@ const mp_obj_property_t wifi_network_country_obj = {
124124
(mp_obj_t)&mp_const_none_obj },
125125
};
126126

127+
//| authmode: str
128+
//| """String id of the authmode"""
129+
//|
130+
STATIC mp_obj_t wifi_network_get_authmode(mp_obj_t self) {
131+
return common_hal_wifi_network_get_authmode(self);
132+
133+
}
134+
MP_DEFINE_CONST_FUN_OBJ_1(wifi_network_get_authmode_obj, wifi_network_get_authmode);
135+
136+
const mp_obj_property_t wifi_network_authmode_obj = {
137+
.base.type = &mp_type_property,
138+
.proxy = { (mp_obj_t)&wifi_network_get_authmode_obj,
139+
(mp_obj_t)&mp_const_none_obj,
140+
(mp_obj_t)&mp_const_none_obj },
141+
};
127142

128143
STATIC const mp_rom_map_elem_t wifi_network_locals_dict_table[] = {
129144
{ MP_ROM_QSTR(MP_QSTR_ssid), MP_ROM_PTR(&wifi_network_ssid_obj) },
130145
{ MP_ROM_QSTR(MP_QSTR_bssid), MP_ROM_PTR(&wifi_network_bssid_obj) },
131146
{ MP_ROM_QSTR(MP_QSTR_rssi), MP_ROM_PTR(&wifi_network_rssi_obj) },
132147
{ MP_ROM_QSTR(MP_QSTR_channel), MP_ROM_PTR(&wifi_network_channel_obj) },
133148
{ MP_ROM_QSTR(MP_QSTR_country), MP_ROM_PTR(&wifi_network_country_obj) },
149+
{ MP_ROM_QSTR(MP_QSTR_authmode), MP_ROM_PTR(&wifi_network_authmode_obj) },
134150
};
135151

136152
STATIC MP_DEFINE_CONST_DICT(wifi_network_locals_dict, wifi_network_locals_dict_table);

shared-bindings/wifi/Network.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@ extern mp_obj_t common_hal_wifi_network_get_bssid(wifi_network_obj_t *self);
4040
extern mp_obj_t common_hal_wifi_network_get_rssi(wifi_network_obj_t *self);
4141
extern mp_obj_t common_hal_wifi_network_get_channel(wifi_network_obj_t *self);
4242
extern mp_obj_t common_hal_wifi_network_get_country(wifi_network_obj_t *self);
43+
extern mp_obj_t common_hal_wifi_network_get_authmode(wifi_network_obj_t *self);
4344

4445
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_NETWORK_H

shared-bindings/wifi/Radio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ const mp_obj_property_t wifi_radio_ipv4_dns_obj = {
295295
};
296296

297297
//| ap_info: Optional[Network]
298-
//| """Network object containing BSSID, SSID, channel, country and RSSI when connected to an access point. None otherwise."""
298+
//| """Network object containing BSSID, SSID, authmode, channel, country and RSSI when connected to an access point. None otherwise."""
299299
//|
300300
STATIC mp_obj_t wifi_radio_get_ap_info(mp_obj_t self) {
301301
return common_hal_wifi_radio_get_ap_info(self);

0 commit comments

Comments
 (0)