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>
44
+ #include < lib/support/CodeUtils.h>
41
45
#include < lib/support/logging/CHIPLogging.h>
42
46
43
47
extern " C" {
@@ -120,7 +124,7 @@ static void DHCPTimerEventHandler(void * arg)
120
124
WfxPostEvent (&event);
121
125
}
122
126
123
- static void CancelDHCPTimer ()
127
+ static void CancelDHCPTimer (void )
124
128
{
125
129
osStatus_t status;
126
130
@@ -164,8 +168,10 @@ int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap)
164
168
{
165
169
sl_status_t status = SL_STATUS_OK;
166
170
int32_t rssi = 0 ;
171
+ ap->ssid_length = wfx_rsi.sec .ssid_length ;
167
172
ap->security = wfx_rsi.sec .security ;
168
173
ap->chan = wfx_rsi.ap_chan ;
174
+ chip::Platform::CopyString (ap->ssid , ap->ssid_length , wfx_rsi.sec .ssid );
169
175
memcpy (&ap->bssid [0 ], &wfx_rsi.ap_mac .octet [0 ], BSSID_LEN);
170
176
sl_wifi_get_signal_strength (SL_WIFI_CLIENT_INTERFACE, &rssi);
171
177
ap->rssi = rssi;
@@ -197,14 +203,14 @@ int32_t wfx_rsi_get_ap_ext(wfx_wifi_scan_ext_t * extra_info)
197
203
}
198
204
199
205
/* *****************************************************************
200
- * @fn int32_t wfx_rsi_reset_count()
206
+ * @fn int32_t wfx_rsi_reset_count(void )
201
207
* @brief
202
208
* Getting the driver reset count
203
209
* @param[in] None
204
210
* @return
205
211
* status
206
212
*********************************************************************/
207
- int32_t wfx_rsi_reset_count ()
213
+ int32_t wfx_rsi_reset_count (void )
208
214
{
209
215
sl_wifi_statistics_t test = { 0 };
210
216
sl_status_t status = SL_STATUS_OK;
@@ -221,14 +227,14 @@ int32_t wfx_rsi_reset_count()
221
227
}
222
228
223
229
/* *****************************************************************
224
- * @fn wfx_rsi_disconnect()
230
+ * @fn wfx_rsi_disconnect(void )
225
231
* @brief
226
232
* Getting the driver disconnect status
227
233
* @param[in] None
228
234
* @return
229
235
* status
230
236
*********************************************************************/
231
- int32_t wfx_rsi_disconnect ()
237
+ int32_t wfx_rsi_disconnect (void )
232
238
{
233
239
return sl_wifi_disconnect (SL_WIFI_CLIENT_INTERFACE);
234
240
}
@@ -251,18 +257,17 @@ sl_status_t join_callback_handler(sl_wifi_event_t event, char * result, uint32_t
251
257
*/
252
258
ChipLogDetail (DeviceLayer, " join_callback_handler: success" );
253
259
memset (&temp_reset, 0 , sizeof (temp_reset));
254
-
255
- WfxEvent.eventType = WFX_EVT_STA_CONN;
256
- WfxPostEvent (&WfxEvent);
257
260
wfx_rsi.join_retries = 0 ;
258
261
callback_status = SL_STATUS_OK;
262
+ WfxEvent.eventType = WFX_EVT_STA_CONN;
263
+ WfxPostEvent (&WfxEvent);
259
264
return SL_STATUS_OK;
260
265
}
261
266
262
267
#if CHIP_CONFIG_ENABLE_ICD_SERVER
263
268
#if SLI_SI91X_MCU_INTERFACE
264
269
// Required to invoke button press event during sleep as falling edge is not detected
265
- void sl_si91x_invoke_btn_press_event ()
270
+ void sl_si91x_invoke_btn_press_event (void )
266
271
{
267
272
// TODO: should be removed once we are getting the press interrupt for button 0 with sleep
268
273
if (!RSI_NPSSGPIO_GetPin (SL_BUTTON_BTN0_PIN) && !btn0_pressed)
@@ -298,12 +303,12 @@ void sl_si91x_invoke_btn_press_event()
298
303
#endif // SLI_SI91X_MCU_INTERFACE
299
304
300
305
/* *****************************************************************
301
- * @fn wfx_rsi_power_save()
306
+ * @fn wfx_rsi_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state )
302
307
* @brief
303
308
* Setting the RS911x in DTIM sleep based mode
304
309
*
305
310
* @param[in] sl_si91x_ble_state : State to set for the BLE
306
- sl_si91x_wifi_state : State to set for the WiFi
311
+ * @param[in] sl_si91x_wifi_state : State to set for the WiFi
307
312
* @return
308
313
* None
309
314
*********************************************************************/
@@ -339,7 +344,7 @@ int32_t wfx_rsi_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_
339
344
*****************************************************************************************/
340
345
int32_t wfx_wifi_rsi_init (void )
341
346
{
342
- ChipLogDetail (DeviceLayer, " wfx_wifi_rsi_init started" );
347
+ ChipLogDetail (DeviceLayer, " wfx_wifi_rsi_init: started" );
343
348
sl_status_t status;
344
349
status = sl_wifi_init (&config, NULL , sl_wifi_default_event_handler);
345
350
VerifyOrReturnError (status == SL_STATUS_OK, status);
@@ -534,7 +539,10 @@ sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result)
534
539
for (int idx = 0 ; idx < (int ) scan_result->scan_count ; idx++)
535
540
{
536
541
memset (&cur_scan_result, 0 , sizeof (cur_scan_result));
537
- strncpy (cur_scan_result.ssid , (char *) &scan_result->scan_info [idx].ssid , WFX_MAX_SSID_LENGTH);
542
+
543
+ cur_scan_result.ssid_length = strnlen ((char *) scan_result->scan_info [idx].ssid ,
544
+ chip::min<size_t >(sizeof (scan_result->scan_info [idx].ssid ), WFX_MAX_SSID_LENGTH));
545
+ chip::Platform::CopyString (cur_scan_result.ssid , cur_scan_result.ssid_length , (char *) scan_result->scan_info [idx].ssid );
538
546
539
547
// if user has provided ssid, then check if the current scan result ssid matches the user provided ssid
540
548
if (wfx_rsi.scan_ssid != NULL &&
@@ -559,10 +567,10 @@ sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result)
559
567
// cleanup and return
560
568
wfx_rsi.dev_state &= ~WFX_RSI_ST_SCANSTARTED;
561
569
wfx_rsi.scan_cb ((wfx_wifi_scan_result_t *) 0 );
562
- wfx_rsi.scan_cb = NULL ;
570
+ wfx_rsi.scan_cb = nullptr ;
563
571
if (wfx_rsi.scan_ssid )
564
572
{
565
- vPortFree (wfx_rsi.scan_ssid );
573
+ chip::Platform::MemoryFree (wfx_rsi.scan_ssid );
566
574
wfx_rsi.scan_ssid = NULL ;
567
575
}
568
576
return SL_STATUS_OK;
@@ -576,14 +584,14 @@ sl_status_t bg_scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_
576
584
return SL_STATUS_OK;
577
585
}
578
586
/* **************************************************************************************
579
- * @fn static void wfx_rsi_save_ap_info()
587
+ * @fn static void wfx_rsi_save_ap_info(void )
580
588
* @brief
581
589
* Saving the details of the AP
582
590
* @param[in] None
583
591
* @return
584
592
* None
585
593
*******************************************************************************************/
586
- static void wfx_rsi_save_ap_info () // translation
594
+ static void wfx_rsi_save_ap_info (void ) // translation
587
595
{
588
596
sl_status_t status = SL_STATUS_OK;
589
597
#ifndef EXP_BOARD
@@ -592,8 +600,8 @@ static void wfx_rsi_save_ap_info() // translation
592
600
#endif
593
601
sl_wifi_ssid_t ssid_arg;
594
602
memset (&ssid_arg, 0 , sizeof (ssid_arg));
595
- ssid_arg.length = strnlen ( wfx_rsi.sec .ssid , WFX_MAX_SSID_LENGTH) ;
596
- strncpy ((char *) &ssid_arg.value [0 ], wfx_rsi.sec .ssid , WFX_MAX_SSID_LENGTH );
603
+ ssid_arg.length = wfx_rsi.sec .ssid_length ;
604
+ chip::Platform::CopyString ((char *) &ssid_arg.value [0 ], ssid_arg. length , wfx_rsi.sec .ssid );
597
605
sl_wifi_set_scan_callback (scan_callback_handler, NULL );
598
606
scan_results_complete = false ;
599
607
#ifndef EXP_BOARD
@@ -619,7 +627,7 @@ static sl_status_t wfx_rsi_do_join(void)
619
627
sl_status_t status = SL_STATUS_OK;
620
628
sl_wifi_client_configuration_t ap;
621
629
memset (&ap, 0 , sizeof (ap));
622
- WfxEvent_t event;
630
+
623
631
switch (wfx_rsi.sec .security )
624
632
{
625
633
case WFX_SEC_WEP:
@@ -662,19 +670,17 @@ static sl_status_t wfx_rsi_do_join(void)
662
670
status = sl_wifi_set_advanced_client_configuration (SL_WIFI_CLIENT_INTERFACE, &client_config);
663
671
VerifyOrReturnError (status == SL_STATUS_OK, status);
664
672
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
665
- size_t psk_length = strlen (wfx_rsi.sec .passkey );
666
- VerifyOrReturnError (psk_length <= SL_WIFI_MAX_PSK_LENGTH, SL_STATUS_SI91X_INVALID_PSK_LENGTH);
667
673
sl_net_credential_id_t id = SL_NET_DEFAULT_WIFI_CLIENT_CREDENTIAL_ID;
668
- status = sl_net_set_credential (id, SL_NET_WIFI_PSK, &wfx_rsi.sec .passkey [0 ], psk_length );
674
+ status = sl_net_set_credential (id, SL_NET_WIFI_PSK, &wfx_rsi.sec .passkey [0 ], wfx_rsi. sec . passkey_length );
669
675
VerifyOrReturnError (status == SL_STATUS_OK, status);
670
676
671
677
uint32_t timeout_ms = 0 ;
672
- ap.ssid .length = strnlen ( wfx_rsi.sec .ssid , WFX_MAX_SSID_LENGTH) ;
678
+ ap.ssid .length = wfx_rsi.sec .ssid_length ;
673
679
ap.encryption = SL_WIFI_NO_ENCRYPTION;
674
680
ap.credential_id = id;
675
- memset (&ap.ssid .value , 0 , (sizeof (ap.ssid .value ) / sizeof (ap.ssid .value [0 ])));
676
- strncpy ((char *) &ap.ssid .value [0 ], wfx_rsi.sec .ssid , WFX_MAX_SSID_LENGTH);
681
+ memcpy ((char *) &ap.ssid .value [0 ], wfx_rsi.sec .ssid , wfx_rsi.sec .ssid_length );
677
682
ChipLogDetail (DeviceLayer, " wfx_rsi_do_join: SSID: %s, SECURITY: %d(%d)" , ap.ssid .value , ap.security , wfx_rsi.sec .security );
683
+
678
684
status = sl_wifi_connect (SL_WIFI_CLIENT_INTERFACE, &ap, timeout_ms);
679
685
// sl_wifi_connect returns SL_STATUS_IN_PROGRESS if join is in progress
680
686
// after the initial scan is done, the scan does not check for SSID
@@ -687,24 +693,25 @@ static sl_status_t wfx_rsi_do_join(void)
687
693
wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED);
688
694
ChipLogProgress (DeviceLayer, " wfx_rsi_do_join: retry attempt %d" , wfx_rsi.join_retries );
689
695
wfx_retry_connection (++wfx_rsi.join_retries );
696
+
697
+ WfxEvent_t event;
690
698
event.eventType = WFX_EVT_STA_START_JOIN;
691
699
WfxPostEvent (&event);
700
+
692
701
return status;
693
702
}
694
703
695
704
// / NotifyConnectivity
696
705
// / @brief Notify the application about the connectivity status if it has not been notified yet.
697
706
// / Helper function for HandleDHCPPolling.
698
- void NotifyConnectivity ()
707
+ void NotifyConnectivity (void )
699
708
{
700
- if (!hasNotifiedWifiConnectivity)
701
- {
702
- wfx_connected_notify (CONNECTION_STATUS_SUCCESS, &wfx_rsi.ap_mac );
703
- hasNotifiedWifiConnectivity = true ;
704
- }
709
+ VerifyOrReturn (!hasNotifiedWifiConnectivity);
710
+ wfx_connected_notify (CONNECTION_STATUS_SUCCESS, &wfx_rsi.ap_mac );
711
+ hasNotifiedWifiConnectivity = true ;
705
712
}
706
713
707
- void HandleDHCPPolling ()
714
+ void HandleDHCPPolling (void )
708
715
{
709
716
struct netif * sta_netif;
710
717
WfxEvent_t event;
@@ -722,6 +729,8 @@ void HandleDHCPPolling()
722
729
{
723
730
wfx_dhcp_got_ipv4 ((uint32_t ) sta_netif->ip_addr .u_addr .ip4 .addr );
724
731
hasNotifiedIPV4 = true ;
732
+ event.eventType = WFX_EVT_STA_DHCP_DONE;
733
+ WfxPostEvent (&event);
725
734
NotifyConnectivity ();
726
735
}
727
736
else if (dhcp_state == DHCP_OFF)
@@ -760,7 +769,7 @@ void WfxPostEvent(WfxEvent_t * event)
760
769
// / ResetDHCPNotificationFlags
761
770
// / @brief Reset the flags that are used to notify the application about DHCP connectivity
762
771
// / and emits a WFX_EVT_STA_DO_DHCP event to trigger DHCP polling checks. Helper function for ProcessEvent.
763
- void ResetDHCPNotificationFlags ()
772
+ void ResetDHCPNotificationFlags (void )
764
773
{
765
774
WfxEvent_t outEvent;
766
775
@@ -877,7 +886,7 @@ void ProcessEvent(WfxEvent_t inEvent)
877
886
/* ********************************************************************************
878
887
* @fn void wfx_rsi_task(void *arg)
879
888
* @brief
880
- * The main WLAN task - started by wfx_wifi_start () that interfaces with RSI.
889
+ * The main WLAN task - started by wfx_wifi_start() that interfaces with RSI.
881
890
* The rest of RSI stuff come in call-backs.
882
891
* The initialization has been already done.
883
892
* @param[in] arg:
0 commit comments