6
6
7
7
#include "utils/includes.h"
8
8
#include "utils/common.h"
9
+ #include "utils/eloop.h"
9
10
#include "common/defs.h"
10
11
11
12
#include "esp_dpp_i.h"
@@ -21,8 +22,7 @@ static void *s_dpp_task_hdl = NULL;
21
22
static void * s_dpp_evt_queue = NULL ;
22
23
static void * s_dpp_api_lock = NULL ;
23
24
24
- static bool s_dpp_stop_listening ;
25
- static int s_dpp_auth_retries ;
25
+ static bool s_dpp_listen_in_progress ;
26
26
static struct esp_dpp_context_t s_dpp_ctx ;
27
27
static wifi_action_rx_cb_t s_action_rx_cb = esp_supp_rx_action ;
28
28
@@ -37,6 +37,7 @@ struct action_rx_param {
37
37
struct ieee80211_action * action_frm ;
38
38
};
39
39
40
+
40
41
static int esp_dpp_post_evt (uint32_t evt_id , uint32_t data )
41
42
{
42
43
dpp_event_t * evt = os_zalloc (sizeof (dpp_event_t ));
@@ -73,9 +74,27 @@ static int esp_dpp_post_evt(uint32_t evt_id, uint32_t data)
73
74
74
75
static void esp_dpp_call_cb (esp_supp_dpp_event_t evt , void * data )
75
76
{
77
+ if ( evt == ESP_SUPP_DPP_FAIL && s_dpp_ctx .dpp_auth ) {
78
+ dpp_auth_deinit (s_dpp_ctx .dpp_auth );
79
+ s_dpp_ctx .dpp_auth = NULL ;
80
+ }
76
81
s_dpp_ctx .dpp_event_cb (evt , data );
77
82
}
78
83
84
+ static void esp_dpp_auth_conf_wait_timeout (void * eloop_ctx , void * timeout_ctx )
85
+ {
86
+ if (!s_dpp_ctx .dpp_auth || !s_dpp_ctx .dpp_auth -> waiting_auth_conf )
87
+ return ;
88
+
89
+ wpa_printf (MSG_DEBUG ,
90
+ "DPP: Terminate authentication exchange due to Auth Confirm timeout" );
91
+ if (s_dpp_ctx .dpp_auth ) {
92
+ dpp_auth_deinit (s_dpp_ctx .dpp_auth );
93
+ s_dpp_ctx .dpp_auth = NULL ;
94
+ }
95
+ esp_dpp_call_cb (ESP_SUPP_DPP_FAIL , (void * )ESP_ERR_DPP_AUTH_TIMEOUT );
96
+ }
97
+
79
98
void esp_send_action_frame (uint8_t * dest_mac , const uint8_t * buf , uint32_t len ,
80
99
uint8_t channel , uint32_t wait_time_ms )
81
100
{
@@ -141,15 +160,20 @@ static void esp_dpp_rx_auth_req(struct action_rx_param *rx_param, uint8_t *dpp_d
141
160
rc = ESP_ERR_DPP_INVALID_ATTR ;
142
161
goto fail ;
143
162
}
144
-
163
+ if (s_dpp_ctx .dpp_auth ) {
164
+ wpa_printf (MSG_DEBUG , "DPP: Already in DPP authentication exchange - ignore new one" );
165
+ return ;
166
+ }
145
167
s_dpp_ctx .dpp_auth = dpp_auth_req_rx (NULL , DPP_CAPAB_ENROLLEE , 0 , NULL ,
146
168
own_bi , rx_param -> channel ,
147
169
(const u8 * )& rx_param -> action_frm -> u .public_action .v , dpp_data , len );
148
170
os_memcpy (s_dpp_ctx .dpp_auth -> peer_mac_addr , rx_param -> sa , ETH_ALEN );
149
-
150
171
esp_send_action_frame (rx_param -> sa , wpabuf_head (s_dpp_ctx .dpp_auth -> resp_msg ),
151
172
wpabuf_len (s_dpp_ctx .dpp_auth -> resp_msg ),
152
173
rx_param -> channel , OFFCHAN_TX_WAIT_TIME );
174
+ eloop_cancel_timeout (esp_dpp_auth_conf_wait_timeout , NULL ,NULL );
175
+ eloop_register_timeout (ESP_DPP_AUTH_TIMEOUT_SECS , 0 , esp_dpp_auth_conf_wait_timeout ,NULL , NULL );
176
+
153
177
return ;
154
178
fail :
155
179
esp_dpp_call_cb (ESP_SUPP_DPP_FAIL , (void * )rc );
@@ -203,7 +227,7 @@ static int esp_dpp_handle_config_obj(struct dpp_authentication *auth,
203
227
wpa_printf (MSG_INFO , DPP_EVENT_CONNECTOR "%s" ,
204
228
conf -> connector );
205
229
}
206
- s_dpp_stop_listening = false ;
230
+ s_dpp_listen_in_progress = true ;
207
231
esp_wifi_action_tx_req (WIFI_OFFCHAN_TX_CANCEL , 0 , 0 , NULL );
208
232
esp_dpp_call_cb (ESP_SUPP_DPP_CFG_RECVD , wifi_cfg );
209
233
@@ -234,6 +258,8 @@ static void esp_dpp_rx_auth_conf(struct action_rx_param *rx_param, uint8_t *dpp_
234
258
goto fail ;
235
259
}
236
260
261
+ eloop_cancel_timeout (esp_dpp_auth_conf_wait_timeout , NULL , NULL );
262
+
237
263
if (dpp_auth_conf_rx (auth , (const u8 * )& public_action -> v ,
238
264
dpp_data , len ) < 0 ) {
239
265
wpa_printf (MSG_DEBUG , "DPP: Authentication failed" );
@@ -283,7 +309,7 @@ static void gas_query_resp_rx(struct action_rx_param *rx_param)
283
309
int i , res ;
284
310
285
311
if (pos [1 ] == WLAN_EID_VENDOR_SPECIFIC && pos [2 ] == 5 &&
286
- WPA_GET_BE24 (& pos [3 ]) == OUI_WFA && pos [6 ] == 0x1a && pos [7 ] == 1 ) {
312
+ WPA_GET_BE24 (& pos [3 ]) == OUI_WFA && pos [6 ] == 0x1a && pos [7 ] == 1 && auth ) {
287
313
if (dpp_conf_resp_rx (auth , resp , rx_param -> vendor_data_len - 2 ) < 0 ) {
288
314
wpa_printf (MSG_DEBUG , "DPP: Configuration attempt failed" );
289
315
goto fail ;
@@ -319,7 +345,7 @@ static void esp_dpp_rx_action(struct action_rx_param *rx_param)
319
345
(size_t )(public_action -> v .pa_vendor_spec .vendor_data -
320
346
(u8 * )rx_param -> action_frm );
321
347
322
- if (! s_dpp_stop_listening ) {
348
+ if (s_dpp_listen_in_progress ) {
323
349
esp_supp_dpp_stop_listen ();
324
350
}
325
351
@@ -356,6 +382,21 @@ static void esp_dpp_task(void *pvParameters )
356
382
357
383
switch (evt -> id ) {
358
384
case SIG_DPP_DEL_TASK :
385
+ struct dpp_bootstrap_params_t * params = & s_dpp_ctx .bootstrap_params ;
386
+ eloop_cancel_timeout (esp_dpp_auth_conf_wait_timeout , NULL , NULL );
387
+ if (params -> info ) {
388
+ os_free (params -> info );
389
+ params -> info = NULL ;
390
+ }
391
+
392
+ if (s_dpp_ctx .dpp_global ) {
393
+ dpp_global_deinit (s_dpp_ctx .dpp_global );
394
+ s_dpp_ctx .dpp_global = NULL ;
395
+ }
396
+ if (s_dpp_ctx .dpp_auth ) {
397
+ dpp_auth_deinit (s_dpp_ctx .dpp_auth );
398
+ s_dpp_ctx .dpp_auth = NULL ;
399
+ }
359
400
task_del = true;
360
401
break ;
361
402
@@ -380,14 +421,20 @@ static void esp_dpp_task(void *pvParameters )
380
421
struct dpp_bootstrap_params_t * p = & s_dpp_ctx .bootstrap_params ;
381
422
static int counter ;
382
423
int channel ;
424
+ esp_err_t ret = 0 ;
383
425
384
426
if (p -> num_chan <= 0 ) {
385
427
wpa_printf (MSG_ERROR , "Listen channel not set" );
386
428
break ;
387
429
}
388
430
channel = p -> chan_list [counter ++ % p -> num_chan ];
389
- esp_wifi_remain_on_channel (WIFI_IF_STA , WIFI_ROC_REQ , channel ,
431
+ ret = esp_wifi_remain_on_channel (WIFI_IF_STA , WIFI_ROC_REQ , channel ,
390
432
BOOTSTRAP_ROC_WAIT_TIME , s_action_rx_cb );
433
+ if (ret != ESP_OK ) {
434
+ wpa_printf (MSG_ERROR , "Failed ROC. error : 0x%x" , ret );
435
+ break ;
436
+ }
437
+ s_dpp_listen_in_progress = true;
391
438
}
392
439
break ;
393
440
@@ -460,13 +507,14 @@ static void offchan_event_handler(void *arg, esp_event_base_t event_base,
460
507
evt -> status , (uint32_t )evt -> context );
461
508
462
509
if (evt -> status ) {
510
+ eloop_cancel_timeout (esp_dpp_auth_conf_wait_timeout , NULL , NULL );
463
511
esp_dpp_call_cb (ESP_SUPP_DPP_FAIL , (void * )ESP_ERR_DPP_TX_FAILURE );
464
512
}
465
513
466
514
} else if (event_id == WIFI_EVENT_ROC_DONE ) {
467
515
wifi_event_roc_done_t * evt = (wifi_event_roc_done_t * )event_data ;
468
516
469
- if (! s_dpp_stop_listening && evt -> context == (uint32_t )s_action_rx_cb ) {
517
+ if (s_dpp_listen_in_progress && evt -> context == (uint32_t )s_action_rx_cb ) {
470
518
esp_dpp_post_evt (SIG_DPP_LISTEN_NEXT_CHANNEL , 0 );
471
519
}
472
520
}
@@ -591,6 +639,11 @@ esp_supp_dpp_bootstrap_gen(const char *chan_list, enum dpp_bootstrap_type type,
591
639
592
640
esp_err_t esp_supp_dpp_start_listen (void )
593
641
{
642
+ if (s_dpp_listen_in_progress ) {
643
+ wpa_printf (MSG_ERROR , "DPP: Failed to start listen as listen is already in progress." );
644
+ return ESP_FAIL ;
645
+ }
646
+
594
647
if (!s_dpp_ctx .dpp_global || s_dpp_ctx .id < 1 ) {
595
648
wpa_printf (MSG_ERROR , "DPP: failed to start listen as dpp not initialized or bootstrapped." );
596
649
return ESP_FAIL ;
@@ -601,13 +654,12 @@ esp_err_t esp_supp_dpp_start_listen(void)
601
654
return ESP_ERR_INVALID_STATE ;
602
655
}
603
656
604
- s_dpp_stop_listening = false;
605
657
return esp_dpp_post_evt (SIG_DPP_LISTEN_NEXT_CHANNEL , 0 );
606
658
}
607
659
608
660
void esp_supp_dpp_stop_listen (void )
609
661
{
610
- s_dpp_stop_listening = true ;
662
+ s_dpp_listen_in_progress = false ;
611
663
esp_wifi_remain_on_channel (WIFI_IF_STA , WIFI_ROC_CANCEL , 0 , 0 , NULL );
612
664
}
613
665
@@ -618,6 +670,7 @@ bool is_dpp_enabled(void)
618
670
619
671
esp_err_t esp_supp_dpp_init (esp_supp_dpp_event_cb_t cb )
620
672
{
673
+ esp_err_t ret = ESP_OK ;
621
674
wifi_mode_t mode = 0 ;
622
675
if (esp_wifi_get_mode (& mode ) || ((mode != WIFI_MODE_STA ) && (mode != WIFI_MODE_APSTA ))) {
623
676
wpa_printf (MSG_ERROR , "DPP: failed to init as not in station mode." );
@@ -632,30 +685,41 @@ esp_err_t esp_supp_dpp_init(esp_supp_dpp_event_cb_t cb)
632
685
wpa_printf (MSG_ERROR , "DPP: failed to init as init already done." );
633
686
return ESP_FAIL ;
634
687
}
635
- struct dpp_global_config cfg = {0 };
636
- int ret ;
637
688
638
689
os_bzero (& s_dpp_ctx , sizeof (s_dpp_ctx ));
639
- s_dpp_ctx .dpp_event_cb = cb ;
640
-
690
+ struct dpp_global_config cfg = {0 };
641
691
cfg .cb_ctx = & s_dpp_ctx ;
642
692
cfg .msg_ctx = & s_dpp_ctx ;
643
693
s_dpp_ctx .dpp_global = dpp_global_init (& cfg );
694
+ if (!s_dpp_ctx .dpp_global ) {
695
+ wpa_printf (MSG_ERROR , "DPP: failed to allocate memory for dpp_global" );
696
+ ret = ESP_ERR_NO_MEM ;
697
+ goto init_fail ;
698
+ }
699
+
700
+ s_dpp_api_lock = os_recursive_mutex_create ();
701
+ if (!s_dpp_api_lock ) {
702
+ wpa_printf (MSG_ERROR , "DPP: dpp_init: failed to create DPP API lock" );
703
+ ret = ESP_ERR_NO_MEM ;
704
+ goto init_fail ;
705
+ }
644
706
645
- s_dpp_stop_listening = false;
646
707
s_dpp_evt_queue = os_queue_create (3 , sizeof (dpp_event_t ));
708
+ if (!s_dpp_evt_queue ) {
709
+ wpa_printf (MSG_ERROR , "DPP: dpp_init: failed to create DPP API queue" );
710
+ ret = ESP_ERR_NO_MEM ;
711
+ goto init_fail ;
712
+ }
713
+
647
714
ret = os_task_create (esp_dpp_task , "dppT" , DPP_TASK_STACK_SIZE , NULL , 2 , & s_dpp_task_hdl );
648
715
if (ret != TRUE) {
649
716
wpa_printf (MSG_ERROR , "DPP: failed to create task" );
650
- return ESP_FAIL ;
717
+ ret = ESP_ERR_NO_MEM ;
718
+ goto init_fail ;
651
719
}
652
720
653
- s_dpp_api_lock = os_recursive_mutex_create ();
654
- if (!s_dpp_api_lock ) {
655
- esp_supp_dpp_deinit ();
656
- wpa_printf (MSG_ERROR , "DPP: dpp_init: failed to create DPP API lock" );
657
- return ESP_ERR_NO_MEM ;
658
- }
721
+ s_dpp_listen_in_progress = false;
722
+ s_dpp_ctx .dpp_event_cb = cb ;
659
723
660
724
esp_event_handler_register (WIFI_EVENT , WIFI_EVENT_ACTION_TX_STATUS ,
661
725
& offchan_event_handler , NULL );
@@ -665,25 +729,32 @@ esp_err_t esp_supp_dpp_init(esp_supp_dpp_event_cb_t cb)
665
729
wpa_printf (MSG_INFO , "esp_dpp_task prio:%d, stack:%d\n" , 2 , DPP_TASK_STACK_SIZE );
666
730
667
731
return ESP_OK ;
732
+ init_fail :
733
+ if (s_dpp_ctx .dpp_global ) {
734
+ dpp_global_deinit (s_dpp_ctx .dpp_global );
735
+ s_dpp_ctx .dpp_global = NULL ;
736
+ }
737
+ if (s_dpp_api_lock ) {
738
+ os_semphr_delete (s_dpp_api_lock );
739
+ s_dpp_api_lock = NULL ;
740
+ }
741
+ if (s_dpp_evt_queue ) {
742
+ os_queue_delete (s_dpp_evt_queue );
743
+ s_dpp_evt_queue = NULL ;
744
+ }
745
+ return ret ;
668
746
}
669
-
670
747
void esp_supp_dpp_deinit (void )
671
748
{
672
- struct dpp_bootstrap_params_t * params = & s_dpp_ctx .bootstrap_params ;
673
- if (params -> info ) {
674
- os_free (params -> info );
675
- params -> info = NULL ;
676
- }
677
749
678
750
esp_event_handler_unregister (WIFI_EVENT , WIFI_EVENT_ACTION_TX_STATUS ,
679
751
& offchan_event_handler );
680
752
esp_event_handler_unregister (WIFI_EVENT , WIFI_EVENT_ROC_DONE ,
681
753
& offchan_event_handler );
682
- s_dpp_auth_retries = 0 ;
683
754
if (s_dpp_ctx .dpp_global ) {
684
- dpp_global_deinit ( s_dpp_ctx . dpp_global );
685
- s_dpp_ctx . dpp_global = NULL ;
686
- esp_dpp_post_evt ( SIG_DPP_DEL_TASK , 0 );
755
+ if ( esp_dpp_post_evt ( SIG_DPP_DEL_TASK , 0 )) {
756
+ wpa_printf ( MSG_ERROR , "DPP Deinit Failed" ) ;
757
+ }
687
758
}
688
759
}
689
760
#endif
0 commit comments