@@ -532,6 +532,7 @@ wifi_err_t R_WIFI_SX_ULPGN_Scan(wifi_scan_result_t * ap_results, uint32_t max_ne
532532 int32_t i ;
533533 static uint8_t retry_max = 3 ;
534534 static uint8_t ssid_tmp [33 ];
535+ uint32_t vals [6 ];
535536
536537 /* Disconnected WiFi module? */
537538 if (MODULE_DISCONNECTED == wifi_system_state_get ())
@@ -586,14 +587,21 @@ wifi_err_t R_WIFI_SX_ULPGN_Scan(wifi_scan_result_t * ap_results, uint32_t max_ne
586587
587588 /* bssid */
588589 at_read ("bssid = %2x:%2x:%2x:%2x:%2x:%2x\r\n" ,
589- & ap_results [i ].bssid [0 ], & ap_results [i ].bssid [1 ], & ap_results [i ].bssid [2 ],
590- & ap_results [i ].bssid [3 ], & ap_results [i ].bssid [4 ], & ap_results [i ].bssid [5 ]);
590+ & vals [0 ], & vals [1 ], & vals [2 ], & vals [3 ], & vals [4 ], & vals [5 ]);
591+ ap_results [i ].bssid [0 ] = (uint8_t )(vals [0 ] & 0xff );
592+ ap_results [i ].bssid [1 ] = (uint8_t )(vals [1 ] & 0xff );
593+ ap_results [i ].bssid [2 ] = (uint8_t )(vals [2 ] & 0xff );
594+ ap_results [i ].bssid [3 ] = (uint8_t )(vals [3 ] & 0xff );
595+ ap_results [i ].bssid [4 ] = (uint8_t )(vals [4 ] & 0xff );
596+ ap_results [i ].bssid [5 ] = (uint8_t )(vals [5 ] & 0xff );
591597
592598 /* channel */
593- at_read ("channel = %d\r\n" , & ap_results [i ].channel );
599+ at_read ("channel = %d\r\n" , & vals [0 ]);
600+ ap_results [i ].channel = (int8_t )(vals [0 ] & 0xff );
594601
595602 /* indicator */
596- at_read ("indicator = %d\r\n" , & ap_results [i ].rssi );
603+ at_read ("indicator = %d\r\n" , & vals [0 ]);
604+ ap_results [i ].rssi = (int8_t )(vals [0 ] & 0xff );
597605
598606 /* security */
599607 if (0 == strncmp ((const char * )at_get_current_line (), "security = NONE!" , 16 ))
@@ -841,6 +849,7 @@ wifi_err_t R_WIFI_SX_ULPGN_GetMacAddress(uint8_t * mac_address)
841849{
842850 wifi_err_t api_ret = WIFI_SUCCESS ;
843851 uint32_t mac [6 ];
852+ uint32_t i ;
844853
845854 /* Disconnected WiFi module? */
846855 if (MODULE_DISCONNECTED == wifi_system_state_get ())
@@ -861,17 +870,15 @@ wifi_err_t R_WIFI_SX_ULPGN_GetMacAddress(uint8_t * mac_address)
861870 }
862871
863872 /* Show current Wi-Fi status. */
864- memset (mac , 0xAA , sizeof (mac ));
873+ memset (mac , 0 , sizeof (mac ));
865874 if (AT_OK == at_exec (g_cmd_port , "ATW\r" ))
866875 {
867876 /* Get MAC address */
868877 at_read ("Mac Addr = %2x:%2x:%2x:%2x:%2x:%2x\r\n" , & mac [0 ], & mac [1 ], & mac [2 ], & mac [3 ], & mac [4 ], & mac [5 ]);
869- mac_address [0 ] = mac [0 ];
870- mac_address [1 ] = mac [1 ];
871- mac_address [2 ] = mac [2 ];
872- mac_address [3 ] = mac [3 ];
873- mac_address [4 ] = mac [4 ];
874- mac_address [5 ] = mac [5 ];
878+ for (i = 0 ; i < 6 ; i ++ )
879+ {
880+ mac_address [i ] = (uint8_t )(mac [i ] & 0xff );
881+ }
875882 }
876883 else
877884 {
@@ -1678,7 +1685,7 @@ int32_t R_WIFI_SX_ULPGN_GetTcpSocketStatus(uint8_t socket_number)
16781685 int32_t ret = (-1 );
16791686 static char sock_status [24 ];
16801687 static char sock_type [8 ];
1681- static uint8_t sock_ver ;
1688+ static uint32_t sock_ver ;
16821689 uint16_t i ;
16831690
16841691 static const uint8_t * p_sock_sts_tbl [ULPGN_SOCKET_STATUS_MAX ] =
@@ -2433,6 +2440,7 @@ static int32_t get_server_certificate(wifi_certificate_infomation_t * p_cert)
24332440{
24342441 uint8_t i ;
24352442 int32_t ret = E_FAIL ;
2443+ uint32_t num_of_files ;
24362444
24372445 /* Initialize */
24382446 memset (p_cert , 0 , sizeof (wifi_certificate_infomation_t ));
@@ -2441,7 +2449,8 @@ static int32_t get_server_certificate(wifi_certificate_infomation_t * p_cert)
24412449 if (AT_OK == at_exec (g_cmd_port , "ATNSSLCERT=?\r" ))
24422450 {
24432451 at_move_to_next_line ();
2444- at_read_wo_prefix ("%d\r\n" , & p_cert -> num_of_files );
2452+ at_read_wo_prefix ("%d\r\n" , & num_of_files );
2453+ p_cert -> num_of_files = (uint8_t )(num_of_files & 0xff );
24452454 for (i = 0 ; i < p_cert -> num_of_files ; i ++ )
24462455 {
24472456 at_move_to_next_line ();
@@ -3146,34 +3155,44 @@ static byteq_err_t wrap_byteq_put(uint8_t sock_idx, uint8_t const byte)
31463155 * End of function wrap_byteq_put
31473156 *********************************************************************************************************************/
31483157
3149- static uint32_t get_dnsaddr (uint32_t * dns_address )
3158+ static uint32_t get_dnsaddr (uint32_t * dns_address , uint32_t * dns_address_count )
31503159{
31513160 uint32_t ret ;
31523161 uint32_t rslt ;
31533162 uint32_t dnsaddr [4 ];
31543163
3164+ * dns_address = 0 ;
3165+ memset (dns_address , 0 , * dns_address_count * sizeof (uint32_t ));
3166+ 31553167 /* Perform DNS query. */
31563168 ret = at_exec (g_cmd_port , "ATNDNSSVR=\?\r" );
3157- 31583169 if (AT_OK == ret )
31593170 {
31603171 at_move_to_next_line ();
31613172 at_read_wo_prefix ("%d\r\n" , & rslt );
31623173
3163- /* success? */
3164- if (1 == rslt )
3165- {
3174+ // we can only return as many as we have asked for
3175+ if (rslt > * dns_address_count )
3176+ {
3177+ rslt = * dns_address_count ;
3178+ }
3179+ 3180+ for (uint32_t i = 0 ; i < rslt ; ++ i )
3181+ {
31663182 at_move_to_next_line ();
31673183 at_read_wo_prefix ("%d.%d.%d.%d\r\n" , & dnsaddr [0 ], & dnsaddr [1 ], & dnsaddr [2 ], & dnsaddr [3 ]);
3168- * dns_address = IPADR_UB_TO_UL (dnsaddr [0 ], dnsaddr [1 ], dnsaddr [2 ], dnsaddr [3 ]);
3169- }
3184+ dns_address [i ] = IPADR_UB_TO_UL (dnsaddr [0 ], dnsaddr [1 ], dnsaddr [2 ], dnsaddr [3 ]);
3185+ }
3186+ 3187+ // return the number of entries processed
3188+ * dns_address_count = rslt ;
31703189 }
31713190
31723191 return ret ;
31733192}
31743193
31753194
3176- wifi_err_t R_WIFI_SX_ULPGN_GetDnsServerAddress (uint32_t * dns_address )
3195+ wifi_err_t R_WIFI_SX_ULPGN_GetDnsServerAddress (uint32_t * dns_address , uint32_t * dns_address_count )
31773196{
31783197 wifi_err_t api_ret = WIFI_SUCCESS ;
31793198
@@ -3196,7 +3215,7 @@ wifi_err_t R_WIFI_SX_ULPGN_GetDnsServerAddress(uint32_t *dns_address)
31963215 }
31973216
31983217 /* Get IP address */
3199- if (AT_OK != get_dnsaddr (dns_address ))
3218+ if (AT_OK != get_dnsaddr (dns_address , dns_address_count ))
32003219 {
32013220 api_ret = WIFI_ERR_MODULE_COM ;
32023221 }
@@ -3206,4 +3225,3 @@ wifi_err_t R_WIFI_SX_ULPGN_GetDnsServerAddress(uint32_t *dns_address)
32063225
32073226 return api_ret ;
32083227}
3209-
0 commit comments