extmod: Add interface and security constants at WLAN class level.

Other constants such as `machine.Pin.OUT` are defined on the class that
uses them, rather than at the module level.  This commit makes that the
case for WLAN network interfaces, adding IF_xxx and SEC_xxx constants.

The SEC_xxx constants are named as such to match the `security` keyword
that they are used with.  And the IF_xxx constants have IF as a prefix so
they are grouped together as names.

This scheme of putting constants on the class means that only the available
features (eg security configurations) are made available as constants.  It
also means that different network interfaces (eg WLAN vs LAN) can keep
their own specific constants within their class, such as PHY_xxx for LAN.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
pull/14015/head
iabdalkader 2024-03-03 16:13:55 +01:00 zatwierdzone przez Damien George
rodzic 5a7d78c732
commit 7753045a8f
3 zmienionych plików z 23 dodań i 3 usunięć

Wyświetl plik

@ -543,6 +543,11 @@ static const mp_rom_map_elem_t network_cyw43_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&network_cyw43_config_obj) },
// Class constants.
{ MP_ROM_QSTR(MP_QSTR_IF_STA), MP_ROM_INT(MOD_NETWORK_STA_IF) },
{ MP_ROM_QSTR(MP_QSTR_IF_AP), MP_ROM_INT(MOD_NETWORK_AP_IF) },
{ MP_ROM_QSTR(MP_QSTR_SEC_OPEN), MP_ROM_INT(CYW43_AUTH_OPEN) },
{ MP_ROM_QSTR(MP_QSTR_SEC_WPA_WPA2), MP_ROM_INT(CYW43_AUTH_WPA2_MIXED_PSK) },
{ MP_ROM_QSTR(MP_QSTR_PM_NONE), MP_ROM_INT(PM_NONE) },
{ MP_ROM_QSTR(MP_QSTR_PM_PERFORMANCE), MP_ROM_INT(PM_PERFORMANCE) },
{ MP_ROM_QSTR(MP_QSTR_PM_POWERSAVE), MP_ROM_INT(PM_POWERSAVE) },

Wyświetl plik

@ -309,6 +309,15 @@ static const mp_rom_map_elem_t network_esp_hosted_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_ipconfig), MP_ROM_PTR(&network_esp_hosted_ipconfig_obj) },
{ MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&network_esp_hosted_config_obj) },
{ MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&network_esp_hosted_status_obj) },
// Class constants.
{ MP_ROM_QSTR(MP_QSTR_IF_STA), MP_ROM_INT(MOD_NETWORK_STA_IF) },
{ MP_ROM_QSTR(MP_QSTR_IF_AP), MP_ROM_INT(MOD_NETWORK_AP_IF) },
{ MP_ROM_QSTR(MP_QSTR_SEC_OPEN), MP_ROM_INT(ESP_HOSTED_SEC_OPEN) },
{ MP_ROM_QSTR(MP_QSTR_SEC_WEP), MP_ROM_INT(ESP_HOSTED_SEC_WEP) },
{ MP_ROM_QSTR(MP_QSTR_SEC_WPA_WPA2), MP_ROM_INT(ESP_HOSTED_SEC_WPA_WPA2_PSK) },
// For backwards compatibility.
{ MP_ROM_QSTR(MP_QSTR_OPEN), MP_ROM_INT(ESP_HOSTED_SEC_OPEN) },
{ MP_ROM_QSTR(MP_QSTR_WEP), MP_ROM_INT(ESP_HOSTED_SEC_WEP) },
{ MP_ROM_QSTR(MP_QSTR_WPA_PSK), MP_ROM_INT(ESP_HOSTED_SEC_WPA_WPA2_PSK) },

Wyświetl plik

@ -860,11 +860,17 @@ static const mp_rom_map_elem_t nina_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&network_ninaw10_status_obj) },
{ MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&network_ninaw10_ioctl_obj) },
// Network is not secured.
// Class constants.
{ MP_ROM_QSTR(MP_QSTR_IF_STA), MP_ROM_INT(MOD_NETWORK_STA_IF) },
{ MP_ROM_QSTR(MP_QSTR_IF_AP), MP_ROM_INT(MOD_NETWORK_AP_IF) },
{ MP_ROM_QSTR(MP_QSTR_SEC_OPEN), MP_ROM_INT(NINA_SEC_OPEN) },
{ MP_ROM_QSTR(MP_QSTR_SEC_WEP), MP_ROM_INT(NINA_SEC_WEP) },
{ MP_ROM_QSTR(MP_QSTR_SEC_WPA_WPA2), MP_ROM_INT(NINA_SEC_WPA_PSK) },
// For backwards compatibility.
{ MP_ROM_QSTR(MP_QSTR_OPEN), MP_ROM_INT(NINA_SEC_OPEN) },
// Security type WEP (40 or 104).
{ MP_ROM_QSTR(MP_QSTR_WEP), MP_ROM_INT(NINA_SEC_WEP) },
// Network secured with WPA/WPA2 personal(PSK).
{ MP_ROM_QSTR(MP_QSTR_WPA_PSK), MP_ROM_INT(NINA_SEC_WPA_PSK) },
};