@@ -819,35 +819,29 @@ STATIC mp_obj_t wlan_isconnected(mp_obj_t self_in) {
819819STATIC MP_DEFINE_CONST_FUN_OBJ_1 (wlan_isconnected_obj , wlan_isconnected );
820820
821821STATIC 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}
852846STATIC MP_DEFINE_CONST_FUN_OBJ_1 (wlan_ifconfig_obj , wlan_ifconfig );
853847
0 commit comments