Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit e4c899a

Browse files
author
Daniel Campora
committed
cc3200: WLAN.ifconfig returns an attrtuple instead of a dictionary.
1 parent f54bdec commit e4c899a

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

Diff for: cc3200/mods/modwlan.c

+18-24
Original file line numberDiff line numberDiff line change
@@ -819,35 +819,29 @@ STATIC mp_obj_t wlan_isconnected(mp_obj_t self_in) {
819819
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_isconnected_obj, wlan_isconnected);
820820

821821
STATIC mp_obj_t wlan_ifconfig (mp_obj_t self_in) {
822+
STATIC const qstr wlan_ifconfig_fields[] = {
823+
MP_QSTR_mode, MP_QSTR_ssid,
824+
MP_QSTR_mac, MP_QSTR_bssid,
825+
MP_QSTR_ip, MP_QSTR_subnet,
826+
MP_QSTR_gateway, MP_QSTR_dns
827+
};
828+
822829
unsigned char len = sizeof(SlNetCfgIpV4Args_t);
823830
unsigned char dhcpIsOn;
824831
SlNetCfgIpV4Args_t ipV4;
825-
826832
sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO, &dhcpIsOn, &len, (uint8_t *)&ipV4);
827833

828-
mp_obj_t ifconfig = mp_obj_new_dict(0);
829-
mp_obj_dict_store (ifconfig, mp_obj_new_str("ip", strlen("ip"), false), mod_network_format_ipv4_addr((uint8_t *)&wlan_obj.ip));
830-
mp_obj_dict_store (ifconfig, mp_obj_new_str("subnet", strlen("subnet"), false), mod_network_format_ipv4_addr((uint8_t *)&ipV4.ipV4Mask));
831-
mp_obj_dict_store (ifconfig, mp_obj_new_str("gateway", strlen("gateway"), false), mod_network_format_ipv4_addr((uint8_t *)&wlan_obj.gateway));
832-
mp_obj_dict_store (ifconfig, mp_obj_new_str("dns", strlen("dns"), false), mod_network_format_ipv4_addr((uint8_t *)&wlan_obj.dns));
833-
char mac_str[18];
834-
mp_uint_t mac_len = snprintf(mac_str, sizeof(mac_str), "%02x:%02x:%02x:%02x:%02x:%02x", wlan_obj.mac[0], wlan_obj.mac[1], wlan_obj.mac[2],
835-
wlan_obj.mac[3], wlan_obj.mac[4], wlan_obj.mac[5]);
836-
mp_obj_dict_store (ifconfig, mp_obj_new_str("mac", strlen("mac"), false), mp_obj_new_str(mac_str, mac_len, false));
837-
char *mode_str;
838-
if (wlan_obj.mode == ROLE_STA) {
839-
mode_str = "station";
840-
}
841-
else if (wlan_obj.mode == ROLE_AP) {
842-
mode_str = "ap";
843-
}
844-
else {
845-
mode_str = "p2p";
846-
}
847-
mp_obj_dict_store (ifconfig, mp_obj_new_str("mode", strlen("mode"), false), mp_obj_new_str(mode_str, strlen(mode_str), false));
848-
mp_obj_dict_store (ifconfig, mp_obj_new_str("ssid", strlen("ssid"), false), mp_obj_new_str((const char *)wlan_obj.ssid, strlen((const char *)wlan_obj.ssid), false));
849-
850-
return ifconfig;
834+
mp_obj_t ifconfig[8];
835+
ifconfig[0] = mp_obj_new_int(wlan_obj.mode);
836+
ifconfig[1] = mp_obj_new_str((const char *)wlan_obj.ssid, strlen((const char *)wlan_obj.ssid), false);
837+
ifconfig[2] = mp_obj_new_bytes((const byte *)wlan_obj.bssid, SL_BSSID_LENGTH);
838+
ifconfig[3] = mp_obj_new_bytes((const byte *)wlan_obj.mac, SL_BSSID_LENGTH);
839+
ifconfig[4] = mod_network_format_ipv4_addr((uint8_t *)&wlan_obj.ip);
840+
ifconfig[5] = mod_network_format_ipv4_addr((uint8_t *)&ipV4.ipV4Mask);
841+
ifconfig[6] = mod_network_format_ipv4_addr((uint8_t *)&wlan_obj.gateway);
842+
ifconfig[7] = mod_network_format_ipv4_addr((uint8_t *)&wlan_obj.dns);
843+
844+
return mp_obj_new_attrtuple(wlan_ifconfig_fields, 8, ifconfig);
851845
}
852846
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_ifconfig_obj, wlan_ifconfig);
853847

Diff for: cc3200/qstrdefsport.h

+1
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ Q(ip)
262262
Q(subnet)
263263
Q(gateway)
264264
Q(dns)
265+
Q(mac)
265266
Q(STA)
266267
Q(AP)
267268
Q(P2P)

0 commit comments

Comments
 (0)