15
15
#include "siwx91x_wifi_ps.h"
16
16
#include "siwx91x_wifi_scan.h"
17
17
#include "siwx91x_wifi_socket.h"
18
+ #include "siwx91x_wifi_sta.h"
18
19
19
20
#include "sl_rsi_utility.h"
20
21
#include "sl_net_constants.h"
@@ -31,98 +32,6 @@ LOG_MODULE_REGISTER(siwx91x_wifi);
31
32
32
33
NET_BUF_POOL_FIXED_DEFINE (siwx91x_tx_pool , 1 , _NET_ETH_MAX_FRAME_SIZE , 0 , NULL );
33
34
34
- enum {
35
- STATE_IDLE = 0x00 ,
36
- /* Failover Roam */
37
- STATE_BEACON_LOSS = 0x10 ,
38
- /* AP induced Roam/Deauth from supplicant */
39
- STATE_DEAUTHENTICATION = 0x20 ,
40
- STATE_CURRENT_AP_BEST = 0x50 ,
41
- /* While roaming */
42
- STATE_BETTER_AP_FOUND = 0x60 ,
43
- STATE_NO_AP_FOUND = 0x70 ,
44
- STATE_ASSOCIATED = 0x80 ,
45
- STATE_UNASSOCIATED = 0x90
46
- };
47
-
48
- enum {
49
- WLAN_REASON_NO_REASON = 0x00 ,
50
- WLAN_REASON_AUTH_DENIAL ,
51
- WLAN_REASON_ASSOC_DENIAL ,
52
- WLAN_REASON_AP_NOT_PRESENT ,
53
- WLAN_REASON_UNKNOWN ,
54
- WLAN_REASON_HANDSHAKE_FAILURE ,
55
- WLAN_REASON_USER_DEAUTH ,
56
- WLAN_REASON_PSK_NOT_CONFIGURED ,
57
- WLAN_REASON_AP_INITIATED_DEAUTH ,
58
- WLAN_REASON_ROAMING_DISABLED ,
59
- WLAN_REASON_MAX
60
- };
61
-
62
- static const char * siwx91x_get_reason_string (uint8_t reason_code )
63
- {
64
- static const struct {
65
- uint8_t code ;
66
- const char * str ;
67
- } reason_strings [] = {
68
- { WLAN_REASON_NO_REASON , "No reason specified" },
69
- { WLAN_REASON_AUTH_DENIAL , "Authentication denial" },
70
- { WLAN_REASON_ASSOC_DENIAL , "Association denial" },
71
- { WLAN_REASON_AP_NOT_PRESENT , "AP not present" },
72
- { WLAN_REASON_UNKNOWN , "Unknown" },
73
- { WLAN_REASON_HANDSHAKE_FAILURE , "Four way handshake failure" },
74
- { WLAN_REASON_USER_DEAUTH , "Deauthentication from User" },
75
- { WLAN_REASON_PSK_NOT_CONFIGURED , "PSK not configured" },
76
- { WLAN_REASON_AP_INITIATED_DEAUTH ,
77
- "De-authentication (AP induced Roam/Deauth from supplicant)" },
78
- { WLAN_REASON_ROAMING_DISABLED , "Roaming not enabled" },
79
- };
80
-
81
- ARRAY_FOR_EACH (reason_strings , i ) {
82
- if (reason_strings [i ].code == reason_code ) {
83
- return reason_strings [i ].str ;
84
- }
85
- }
86
-
87
- return "Unknown" ;
88
- }
89
-
90
- static sl_status_t siwx91x_wifi_module_stats_event_handler (sl_wifi_event_t event , void * response ,
91
- uint32_t result_length , void * arg )
92
- {
93
- ARG_UNUSED (event );
94
- ARG_UNUSED (result_length );
95
- sl_si91x_module_state_stats_response_t * notif = response ;
96
- uint8_t module_state = notif -> state_code & 0xF0 ;
97
- struct siwx91x_dev * sidev = arg ;
98
- const char * reason_str ;
99
-
100
- reason_str = siwx91x_get_reason_string (notif -> reason_code );
101
-
102
- switch (module_state ) {
103
- case STATE_BEACON_LOSS :
104
- LOG_WRN ("Beacon Loss" );
105
- break ;
106
- case STATE_BETTER_AP_FOUND :
107
- LOG_DBG ("Better AP found while roaming" );
108
- break ;
109
- case STATE_ASSOCIATED :
110
- sidev -> state = WIFI_STATE_COMPLETED ;
111
- break ;
112
- case STATE_UNASSOCIATED :
113
- wifi_mgmt_raise_disconnect_result_event (sidev -> iface ,
114
- WIFI_REASON_DISCONN_SUCCESS );
115
-
116
- sidev -> state = WIFI_STATE_DISCONNECTED ;
117
- break ;
118
- default :
119
- return 0 ;
120
- }
121
-
122
- LOG_DBG ("Reason: %s" , reason_str );
123
- return 0 ;
124
- }
125
-
126
35
static int siwx91x_sl_to_z_mode (sl_wifi_interface_t interface )
127
36
{
128
37
switch (interface ) {
@@ -137,82 +46,6 @@ static int siwx91x_sl_to_z_mode(sl_wifi_interface_t interface)
137
46
return 0 ;
138
47
}
139
48
140
- static enum wifi_mfp_options siwx91x_set_sta_mfp_option (sl_wifi_security_t security ,
141
- enum wifi_mfp_options mfp_conf )
142
- {
143
- uint8_t join_config ;
144
-
145
- switch (security ) {
146
- case SL_WIFI_OPEN :
147
- case SL_WIFI_WPA :
148
- return WIFI_MFP_DISABLE ;
149
- case SL_WIFI_WPA2 :
150
- case SL_WIFI_WPA_WPA2_MIXED :
151
- if (mfp_conf == WIFI_MFP_REQUIRED ) {
152
- /* Handling the case for WPA2_SHA256 security type */
153
- /* Directly enabling the MFP Required bit in the Join Feature
154
- * bitmap. This ensures that MFP is enforced for connections using
155
- * WPA2_SHA256.
156
- *
157
- * Note: This is a workaround to configure MFP as the current SDK
158
- * does not provide a dedicated API to configure MFP settings.
159
- * By manipulating the join feature bitmap directly, we achieve
160
- * the desired MFP configuration for enhanced security.
161
- *
162
- * This case will be updated in the future when the SDK adds
163
- * dedicated support for configuring MFP.
164
- */
165
- sl_si91x_get_join_configuration (SL_WIFI_CLIENT_INTERFACE , & join_config );
166
- join_config |= SL_SI91X_JOIN_FEAT_MFP_CAPABLE_REQUIRED ;
167
- sl_si91x_set_join_configuration (SL_WIFI_CLIENT_INTERFACE , join_config );
168
- return WIFI_MFP_REQUIRED ;
169
- }
170
- /* Handling the case for WPA2 security type */
171
- /* Ensuring the connection happened in WPA2-PSK
172
- * by clearing the MFP Required bit in the Join Feature bitmap.
173
- */
174
- sl_si91x_get_join_configuration (SL_WIFI_CLIENT_INTERFACE , & join_config );
175
- join_config &= ~(SL_SI91X_JOIN_FEAT_MFP_CAPABLE_REQUIRED );
176
- sl_si91x_set_join_configuration (SL_WIFI_CLIENT_INTERFACE , join_config );
177
- return WIFI_MFP_OPTIONAL ;
178
- case SL_WIFI_WPA3 :
179
- return WIFI_MFP_REQUIRED ;
180
- case SL_WIFI_WPA3_TRANSITION :
181
- return WIFI_MFP_OPTIONAL ;
182
- default :
183
- return WIFI_MFP_DISABLE ;
184
- }
185
-
186
- return WIFI_MFP_UNKNOWN ;
187
- }
188
-
189
- static unsigned int siwx91x_on_join (sl_wifi_event_t event ,
190
- char * result , uint32_t result_size , void * arg )
191
- {
192
- struct siwx91x_dev * sidev = arg ;
193
-
194
- if (* result != 'C' ) {
195
- /* TODO: report the real reason of failure */
196
- wifi_mgmt_raise_connect_result_event (sidev -> iface , WIFI_STATUS_CONN_FAIL );
197
- sidev -> state = WIFI_STATE_INACTIVE ;
198
- return 0 ;
199
- }
200
-
201
- wifi_mgmt_raise_connect_result_event (sidev -> iface , WIFI_STATUS_CONN_SUCCESS );
202
- sidev -> state = WIFI_STATE_COMPLETED ;
203
-
204
- if (IS_ENABLED (CONFIG_WIFI_SILABS_SIWX91X_NET_STACK_NATIVE )) {
205
- net_if_dormant_off (sidev -> iface );
206
- }
207
-
208
- siwx91x_on_join_ipv4 (sidev );
209
- siwx91x_on_join_ipv6 (sidev );
210
-
211
- siwx91x_apply_power_save (sidev );
212
-
213
- return 0 ;
214
- }
215
-
216
49
int siwx91x_status (const struct device * dev , struct wifi_iface_status * status )
217
50
{
218
51
sl_wifi_interface_t interface = sl_wifi_get_default_interface ();
@@ -339,30 +172,6 @@ int siwx91x_status(const struct device *dev, struct wifi_iface_status *status)
339
172
return ret ;
340
173
}
341
174
342
- static int siwx91x_disconnect (const struct device * dev )
343
- {
344
- sl_wifi_interface_t interface = sl_wifi_get_default_interface ();
345
- struct siwx91x_dev * sidev = dev -> data ;
346
- int ret ;
347
-
348
- if (sidev -> state != WIFI_STATE_COMPLETED ) {
349
- LOG_ERR ("Command given in invalid state" );
350
- return - EINVAL ;
351
- }
352
-
353
- ret = sl_wifi_disconnect (interface );
354
- if (ret != SL_STATUS_OK ) {
355
- wifi_mgmt_raise_disconnect_result_event (sidev -> iface , ret );
356
- return - EIO ;
357
- }
358
-
359
- if (IS_ENABLED (CONFIG_WIFI_SILABS_SIWX91X_NET_STACK_NATIVE )) {
360
- net_if_dormant_on (sidev -> iface );
361
- }
362
-
363
- return 0 ;
364
- }
365
-
366
175
bool siwx91x_param_changed (struct wifi_iface_status * prev_params ,
367
176
struct wifi_connect_req_params * new_params )
368
177
{
@@ -381,146 +190,6 @@ bool siwx91x_param_changed(struct wifi_iface_status *prev_params,
381
190
return false;
382
191
}
383
192
384
- static int siwx91x_disconnect_if_required (const struct device * dev ,
385
- struct wifi_connect_req_params * new_params )
386
- {
387
- struct wifi_iface_status prev_params = { };
388
- uint32_t prev_psk_length = WIFI_PSK_MAX_LEN ;
389
- uint8_t prev_psk [WIFI_PSK_MAX_LEN ];
390
- sl_net_credential_type_t psk_type ;
391
- int ret ;
392
-
393
- ret = siwx91x_status (dev , & prev_params );
394
- if (ret < 0 ) {
395
- return ret ;
396
- }
397
-
398
- if (siwx91x_param_changed (& prev_params , new_params )) {
399
- return siwx91x_disconnect (dev );
400
- }
401
-
402
- if (new_params -> security != WIFI_SECURITY_TYPE_NONE ) {
403
- ret = sl_net_get_credential (SL_NET_DEFAULT_WIFI_CLIENT_CREDENTIAL_ID , & psk_type ,
404
- prev_psk , & prev_psk_length );
405
- if (ret < 0 ) {
406
- LOG_ERR ("Failed to get credentials: 0x%x" , ret );
407
- return - EIO ;
408
- }
409
-
410
- if (new_params -> psk_length != prev_psk_length ||
411
- memcmp (new_params -> psk , prev_psk , prev_psk_length ) != 0 ) {
412
- return siwx91x_disconnect (dev );
413
- }
414
- }
415
-
416
- LOG_ERR ("Device already in active state" );
417
- return - EALREADY ;
418
- }
419
-
420
- static int siwx91x_connect (const struct device * dev , struct wifi_connect_req_params * params )
421
- {
422
- sl_wifi_interface_t interface = sl_wifi_get_default_interface ();
423
- sl_wifi_client_configuration_t wifi_config = {
424
- .bss_type = SL_WIFI_BSS_TYPE_INFRASTRUCTURE ,
425
- .encryption = SL_WIFI_DEFAULT_ENCRYPTION ,
426
- .credential_id = SL_NET_DEFAULT_WIFI_CLIENT_CREDENTIAL_ID ,
427
- };
428
- struct siwx91x_dev * sidev = dev -> data ;
429
- enum wifi_mfp_options mfp_conf ;
430
- int ret = 0 ;
431
-
432
- if (sidev -> state == WIFI_STATE_COMPLETED ) {
433
- ret = siwx91x_disconnect_if_required (dev , params );
434
- if (ret < 0 ) {
435
- wifi_mgmt_raise_connect_result_event (sidev -> iface , WIFI_STATUS_CONN_FAIL );
436
- return ret ;
437
- }
438
- }
439
-
440
- switch (params -> security ) {
441
- case WIFI_SECURITY_TYPE_NONE :
442
- wifi_config .security = SL_WIFI_OPEN ;
443
- break ;
444
- case WIFI_SECURITY_TYPE_WPA_PSK :
445
- wifi_config .security = SL_WIFI_WPA ;
446
- break ;
447
- case WIFI_SECURITY_TYPE_PSK :
448
- /* This case is meant to fall through to the next */
449
- case WIFI_SECURITY_TYPE_PSK_SHA256 :
450
- /* Use WPA2 security as the device supports only SHA256
451
- * key derivation for WPA2-PSK
452
- */
453
- wifi_config .security = SL_WIFI_WPA2 ;
454
- break ;
455
- case WIFI_SECURITY_TYPE_SAE_AUTO :
456
- /* Use WPA3 security as the device supports only HNP and H2E
457
- * methods for SAE
458
- */
459
- wifi_config .security = SL_WIFI_WPA3 ;
460
- break ;
461
- case WIFI_SECURITY_TYPE_WPA_AUTO_PERSONAL :
462
- /* Use WPA2/WPA3 security as the device supports both */
463
- wifi_config .security = SL_WIFI_WPA3_TRANSITION ;
464
- break ;
465
- /* Zephyr WiFi shell doesn't specify how to pass credential for these
466
- * key managements.
467
- */
468
- case WIFI_SECURITY_TYPE_WEP : /* SL_WIFI_WEP/SL_WIFI_WEP_ENCRYPTION */
469
- case WIFI_SECURITY_TYPE_EAP : /* SL_WIFI_WPA2_ENTERPRISE/<various> */
470
- case WIFI_SECURITY_TYPE_WAPI :
471
- default :
472
- return - ENOTSUP ;
473
- }
474
-
475
- if (params -> band != WIFI_FREQ_BAND_UNKNOWN && params -> band != WIFI_FREQ_BAND_2_4_GHZ ) {
476
- wifi_mgmt_raise_connect_result_event (sidev -> iface , WIFI_STATUS_CONN_FAIL );
477
- return - ENOTSUP ;
478
- }
479
-
480
- if (params -> psk_length ) {
481
- ret = sl_net_set_credential (SL_NET_DEFAULT_WIFI_CLIENT_CREDENTIAL_ID ,
482
- SL_NET_WIFI_PSK , params -> psk , params -> psk_length );
483
- } else if (params -> sae_password_length ) {
484
- ret = sl_net_set_credential (SL_NET_DEFAULT_WIFI_CLIENT_CREDENTIAL_ID ,
485
- SL_NET_WIFI_PSK , params -> sae_password ,
486
- params -> sae_password_length );
487
- }
488
-
489
- if (ret != SL_STATUS_OK ) {
490
- LOG_ERR ("Failed to set credentials: 0x%x" , ret );
491
- wifi_mgmt_raise_connect_result_event (sidev -> iface , WIFI_STATUS_CONN_FAIL );
492
- return - EINVAL ;
493
- }
494
-
495
- if (params -> security == WIFI_SECURITY_TYPE_PSK_SHA256 ) {
496
- mfp_conf = siwx91x_set_sta_mfp_option (wifi_config .security , WIFI_MFP_REQUIRED );
497
- } else {
498
- mfp_conf = siwx91x_set_sta_mfp_option (wifi_config .security , params -> mfp );
499
- }
500
-
501
- if (params -> mfp != mfp_conf ) {
502
- LOG_WRN ("Needed MFP %s but got MFP %s, hence setting to MFP %s" ,
503
- wifi_mfp_txt (mfp_conf ), wifi_mfp_txt (params -> mfp ), wifi_mfp_txt (mfp_conf ));
504
- }
505
-
506
- if (params -> channel != WIFI_CHANNEL_ANY ) {
507
- wifi_config .channel .channel = params -> channel ;
508
- } else {
509
- wifi_config .channel .channel = 0 ;
510
- }
511
-
512
- wifi_config .ssid .length = params -> ssid_length ,
513
- memcpy (wifi_config .ssid .value , params -> ssid , params -> ssid_length );
514
-
515
- ret = sl_wifi_connect (interface , & wifi_config , 0 );
516
- if (ret != SL_STATUS_IN_PROGRESS ) {
517
- wifi_mgmt_raise_connect_result_event (sidev -> iface , WIFI_STATUS_CONN_FAIL );
518
- return - EIO ;
519
- }
520
-
521
- return 0 ;
522
- }
523
-
524
193
static int siwx91x_mode (const struct device * dev , struct wifi_mode_info * mode )
525
194
{
526
195
sl_wifi_interface_t interface = sl_wifi_get_default_interface ();
0 commit comments