36
36
#include " task.h"
37
37
#include " wfx_host_events.h"
38
38
#include " wfx_rsi.h"
39
+
39
40
#include < app/icd/server/ICDServerConfig.h>
40
41
#include < inet/IPAddress.h>
42
+ #include < lib/support/CHIPMem.h>
43
+ #include < lib/support/CHIPMemString.h>
41
44
#include < lib/support/logging/CHIPLogging.h>
42
45
43
46
extern " C" {
@@ -163,8 +166,10 @@ int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap)
163
166
{
164
167
sl_status_t status = SL_STATUS_OK;
165
168
int32_t rssi = 0 ;
169
+ ap->ssid_length = wfx_rsi.sec .ssid_length ;
166
170
ap->security = wfx_rsi.sec .security ;
167
171
ap->chan = wfx_rsi.ap_chan ;
172
+ chip::Platform::CopyString (ap->ssid , ap->ssid_length , wfx_rsi.sec .ssid );
168
173
memcpy (&ap->bssid [0 ], &wfx_rsi.ap_mac .octet [0 ], BSSID_LEN);
169
174
sl_wifi_get_signal_strength (SL_WIFI_CLIENT_INTERFACE, &rssi);
170
175
ap->rssi = rssi;
@@ -196,14 +201,14 @@ int32_t wfx_rsi_get_ap_ext(wfx_wifi_scan_ext_t * extra_info)
196
201
}
197
202
198
203
/* *****************************************************************
199
- * @fn int32_t wfx_rsi_reset_count()
204
+ * @fn int32_t wfx_rsi_reset_count(void )
200
205
* @brief
201
206
* Getting the driver reset count
202
207
* @param[in] None
203
208
* @return
204
209
* status
205
210
*********************************************************************/
206
- int32_t wfx_rsi_reset_count ()
211
+ int32_t wfx_rsi_reset_count (void )
207
212
{
208
213
sl_wifi_statistics_t test = { 0 };
209
214
sl_status_t status = SL_STATUS_OK;
@@ -220,14 +225,14 @@ int32_t wfx_rsi_reset_count()
220
225
}
221
226
222
227
/* *****************************************************************
223
- * @fn wfx_rsi_disconnect()
228
+ * @fn wfx_rsi_disconnect(void )
224
229
* @brief
225
230
* Getting the driver disconnect status
226
231
* @param[in] None
227
232
* @return
228
233
* status
229
234
*********************************************************************/
230
- int32_t wfx_rsi_disconnect ()
235
+ int32_t wfx_rsi_disconnect (void )
231
236
{
232
237
return sl_wifi_disconnect (SL_WIFI_CLIENT_INTERFACE);
233
238
}
@@ -533,7 +538,9 @@ sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result)
533
538
for (int idx = 0 ; idx < (int ) scan_result->scan_count ; idx++)
534
539
{
535
540
memset (&cur_scan_result, 0 , sizeof (cur_scan_result));
536
- strncpy (cur_scan_result.ssid , (char *) &scan_result->scan_info [idx].ssid , WFX_MAX_SSID_LENGTH);
541
+
542
+ cur_scan_result.ssid_length = strnlen ((char *) &scan_result->scan_info [idx].ssid , WFX_MAX_SSID_LENGTH);
543
+ chip::Platform::CopyString (cur_scan_result.ssid , cur_scan_result.ssid_length , (char *) &scan_result->scan_info [idx].ssid );
537
544
538
545
// if user has provided ssid, then check if the current scan result ssid matches the user provided ssid
539
546
if (wfx_rsi.scan_ssid != NULL && strcmp (wfx_rsi.scan_ssid , cur_scan_result.ssid ) != CMP_SUCCESS)
@@ -556,10 +563,10 @@ sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result)
556
563
// cleanup and return
557
564
wfx_rsi.dev_state &= ~WFX_RSI_ST_SCANSTARTED;
558
565
wfx_rsi.scan_cb ((wfx_wifi_scan_result_t *) 0 );
559
- wfx_rsi.scan_cb = NULL ;
566
+ wfx_rsi.scan_cb = nullptr ;
560
567
if (wfx_rsi.scan_ssid )
561
568
{
562
- vPortFree (wfx_rsi.scan_ssid );
569
+ chip::Platform::MemoryFree (wfx_rsi.scan_ssid );
563
570
wfx_rsi.scan_ssid = NULL ;
564
571
}
565
572
return SL_STATUS_OK;
@@ -573,14 +580,14 @@ sl_status_t bg_scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_
573
580
return SL_STATUS_OK;
574
581
}
575
582
/* **************************************************************************************
576
- * @fn static void wfx_rsi_save_ap_info()
583
+ * @fn static void wfx_rsi_save_ap_info(void )
577
584
* @brief
578
585
* Saving the details of the AP
579
586
* @param[in] None
580
587
* @return
581
588
* None
582
589
*******************************************************************************************/
583
- static void wfx_rsi_save_ap_info () // translation
590
+ static void wfx_rsi_save_ap_info (void ) // translation
584
591
{
585
592
sl_status_t status = SL_STATUS_OK;
586
593
#ifndef EXP_BOARD
@@ -589,8 +596,8 @@ static void wfx_rsi_save_ap_info() // translation
589
596
#endif
590
597
sl_wifi_ssid_t ssid_arg;
591
598
memset (&ssid_arg, 0 , sizeof (ssid_arg));
592
- ssid_arg.length = strnlen ( wfx_rsi.sec .ssid , WFX_MAX_SSID_LENGTH) ;
593
- strncpy ((char *) &ssid_arg.value [0 ], wfx_rsi.sec .ssid , WFX_MAX_SSID_LENGTH );
599
+ ssid_arg.length = wfx_rsi.sec .ssid_length ;
600
+ chip::Platform::CopyString ((char *) &ssid_arg.value [0 ], ssid_arg. length , wfx_rsi.sec .ssid );
594
601
sl_wifi_set_scan_callback (scan_callback_handler, NULL );
595
602
scan_results_complete = false ;
596
603
#ifndef EXP_BOARD
@@ -616,7 +623,7 @@ static sl_status_t wfx_rsi_do_join(void)
616
623
sl_status_t status = SL_STATUS_OK;
617
624
sl_wifi_client_configuration_t ap;
618
625
memset (&ap, 0 , sizeof (ap));
619
- WfxEvent_t event;
626
+
620
627
switch (wfx_rsi.sec .security )
621
628
{
622
629
case WFX_SEC_WEP:
@@ -659,19 +666,17 @@ static sl_status_t wfx_rsi_do_join(void)
659
666
status = sl_wifi_set_advanced_client_configuration (SL_WIFI_CLIENT_INTERFACE, &client_config);
660
667
VerifyOrReturnError (status == SL_STATUS_OK, status);
661
668
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
662
- size_t psk_length = strlen (wfx_rsi.sec .passkey );
663
- VerifyOrReturnError (psk_length <= SL_WIFI_MAX_PSK_LENGTH, SL_STATUS_SI91X_INVALID_PSK_LENGTH);
664
669
sl_net_credential_id_t id = SL_NET_DEFAULT_WIFI_CLIENT_CREDENTIAL_ID;
665
- status = sl_net_set_credential (id, SL_NET_WIFI_PSK, &wfx_rsi.sec .passkey [0 ], psk_length );
670
+ status = sl_net_set_credential (id, SL_NET_WIFI_PSK, &wfx_rsi.sec .passkey [0 ], wfx_rsi. sec . passkey_length );
666
671
VerifyOrReturnError (status == SL_STATUS_OK, status);
667
672
668
673
uint32_t timeout_ms = 0 ;
669
- ap.ssid .length = strnlen ( wfx_rsi.sec .ssid , WFX_MAX_SSID_LENGTH) ;
674
+ ap.ssid .length = wfx_rsi.sec .ssid_length ;
670
675
ap.encryption = SL_WIFI_NO_ENCRYPTION;
671
676
ap.credential_id = id;
672
- memset (&ap.ssid .value , 0 , (sizeof (ap.ssid .value ) / sizeof (ap.ssid .value [0 ])));
673
- strncpy ((char *) &ap.ssid .value [0 ], wfx_rsi.sec .ssid , WFX_MAX_SSID_LENGTH);
677
+ memcpy ((char *) &ap.ssid .value [0 ], wfx_rsi.sec .ssid , wfx_rsi.sec .ssid_length );
674
678
ChipLogDetail (DeviceLayer, " wfx_rsi_do_join: SSID: %s, SECURITY: %d(%d)" , ap.ssid .value , ap.security , wfx_rsi.sec .security );
679
+
675
680
status = sl_wifi_connect (SL_WIFI_CLIENT_INTERFACE, &ap, timeout_ms);
676
681
// sl_wifi_connect returns SL_STATUS_IN_PROGRESS if join is in progress
677
682
// after the initial scan is done, the scan does not check for SSID
@@ -684,8 +689,11 @@ static sl_status_t wfx_rsi_do_join(void)
684
689
wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED);
685
690
ChipLogProgress (DeviceLayer, " wfx_rsi_do_join: retry attempt %d" , wfx_rsi.join_retries );
686
691
wfx_retry_connection (++wfx_rsi.join_retries );
692
+
693
+ WfxEvent_t event;
687
694
event.eventType = WFX_EVT_STA_START_JOIN;
688
695
WfxPostEvent (&event);
696
+
689
697
return status;
690
698
}
691
699
0 commit comments