aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Poulsen2019-08-27 10:11:03 -0700
committerDamien George2019-08-28 13:11:48 +1000
commit5635b96461e7806c06fccfa237dae670cc2a1377 (patch)
treeeba38815b13b46ee365dd5097b661f57b6b1c5f5
parentafc8596c154f86b8d612a7ac28b999e8ea26df55 (diff)
esp32: Add 'config' function to network.LAN, reusing network.WLAN.
-rw-r--r--ports/esp32/modnetwork.c48
-rw-r--r--ports/esp32/modnetwork.h1
-rw-r--r--ports/esp32/network_lan.c1
3 files changed, 36 insertions, 14 deletions
diff --git a/ports/esp32/modnetwork.c b/ports/esp32/modnetwork.c
index 3dfe3945b..45ea5139c 100644
--- a/ports/esp32/modnetwork.c
+++ b/ports/esp32/modnetwork.c
@@ -550,17 +550,24 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]);
- // get the config for the interface
+ bool is_wifi = self->if_id == WIFI_IF_AP || self->if_id == WIFI_IF_STA;
+
wifi_config_t cfg;
- ESP_EXCEPTIONS(esp_wifi_get_config(self->if_id, &cfg));
+ if (is_wifi) {
+ ESP_EXCEPTIONS(esp_wifi_get_config(self->if_id, &cfg));
+ }
+
+ #define QS(x) (uintptr_t)MP_OBJ_NEW_QSTR(x)
if (kwargs->used != 0) {
+ if (!is_wifi) {
+ goto unknown;
+ }
for (size_t i = 0; i < kwargs->alloc; i++) {
if (mp_map_slot_is_filled(kwargs, i)) {
int req_if = -1;
- #define QS(x) (uintptr_t)MP_OBJ_NEW_QSTR(x)
switch ((uintptr_t)kwargs->table[i].key) {
case QS(MP_QSTR_mac): {
mp_buffer_info_t bufinfo;
@@ -612,7 +619,6 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
default:
goto unknown;
}
- #undef QS
// We post-check interface requirements to save on code size
if (req_if >= 0) {
@@ -633,20 +639,34 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
}
int req_if = -1;
- mp_obj_t val;
+ mp_obj_t val = mp_const_none;
- #define QS(x) (uintptr_t)MP_OBJ_NEW_QSTR(x)
switch ((uintptr_t)args[1]) {
case QS(MP_QSTR_mac): {
uint8_t mac[6];
- ESP_EXCEPTIONS(esp_wifi_get_mac(self->if_id, mac));
- return mp_obj_new_bytes(mac, sizeof(mac));
+ switch (self->if_id) {
+ case WIFI_IF_AP: // fallthrough intentional
+ case WIFI_IF_STA:
+ ESP_EXCEPTIONS(esp_wifi_get_mac(self->if_id, mac));
+ return mp_obj_new_bytes(mac, sizeof(mac));
+
+ case ESP_IF_ETH:
+ esp_eth_get_mac(mac);
+ return mp_obj_new_bytes(mac, sizeof(mac));
+ default:
+ goto unknown;
+ }
}
case QS(MP_QSTR_essid):
- if (self->if_id == WIFI_IF_STA) {
- val = mp_obj_new_str((char*)cfg.sta.ssid, strlen((char*)cfg.sta.ssid));
- } else {
- val = mp_obj_new_str((char*)cfg.ap.ssid, cfg.ap.ssid_len);
+ switch (self->if_id) {
+ case WIFI_IF_STA:
+ val = mp_obj_new_str((char*)cfg.sta.ssid, strlen((char*)cfg.sta.ssid));
+ break;
+ case WIFI_IF_AP:
+ val = mp_obj_new_str((char*)cfg.ap.ssid, cfg.ap.ssid_len);
+ break;
+ default:
+ req_if = WIFI_IF_AP;
}
break;
case QS(MP_QSTR_hidden):
@@ -670,6 +690,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
default:
goto unknown;
}
+
#undef QS
// We post-check interface requirements to save on code size
@@ -682,8 +703,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
unknown:
mp_raise_ValueError("unknown config param");
}
-
-STATIC MP_DEFINE_CONST_FUN_OBJ_KW(esp_config_obj, 1, esp_config);
+MP_DEFINE_CONST_FUN_OBJ_KW(esp_config_obj, 1, esp_config);
STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&esp_active_obj) },
diff --git a/ports/esp32/modnetwork.h b/ports/esp32/modnetwork.h
index f39a2919d..64d2da018 100644
--- a/ports/esp32/modnetwork.h
+++ b/ports/esp32/modnetwork.h
@@ -31,6 +31,7 @@ enum { PHY_LAN8720, PHY_TLK110 };
MP_DECLARE_CONST_FUN_OBJ_KW(get_lan_obj);
MP_DECLARE_CONST_FUN_OBJ_1(ppp_make_new_obj);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(esp_ifconfig_obj);
+MP_DECLARE_CONST_FUN_OBJ_KW(esp_config_obj);
void usocket_events_deinit(void);
diff --git a/ports/esp32/network_lan.c b/ports/esp32/network_lan.c
index 10f17ebcf..100894b2e 100644
--- a/ports/esp32/network_lan.c
+++ b/ports/esp32/network_lan.c
@@ -205,6 +205,7 @@ STATIC const mp_rom_map_elem_t lan_if_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&lan_active_obj) },
{ MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&lan_isconnected_obj) },
{ MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&lan_status_obj) },
+ { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&esp_config_obj) },
{ MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&esp_ifconfig_obj) },
};