@@ -66,7 +66,30 @@ static esp_err_t dpp_api_unlock(void)
6666 return ESP_OK ;
6767}
6868
69- static uint8_t esp_dpp_deinit_auth (void )
69+ static void dpp_event_handler (void * arg , esp_event_base_t event_base ,
70+ int32_t event_id , void * event_data )
71+ {
72+ if (!s_dpp_ctx .dpp_event_cb ) {
73+ return ;
74+ }
75+ switch (event_id ) {
76+ case WIFI_EVENT_DPP_URI_READY :
77+ wifi_event_dpp_uri_ready_t * event = (wifi_event_dpp_uri_ready_t * ) event_data ;
78+ s_dpp_ctx .dpp_event_cb (ESP_SUPP_DPP_URI_READY , (void * )(event -> uri ));
79+ break ;
80+ case WIFI_EVENT_DPP_CFG_RECVD :
81+ s_dpp_ctx .dpp_event_cb (ESP_SUPP_DPP_CFG_RECVD , (wifi_config_t * )event_data );
82+ break ;
83+ case WIFI_EVENT_DPP_FAILED :
84+ s_dpp_ctx .dpp_event_cb (ESP_SUPP_DPP_FAIL , (void * )event_data );
85+ break ;
86+ default :
87+ break ;
88+ }
89+ return ;
90+ }
91+
92+ static uint8_t dpp_deinit_auth (void )
7093{
7194 if (s_dpp_ctx .dpp_auth ) {
7295 dpp_auth_deinit (s_dpp_ctx .dpp_auth );
@@ -89,13 +112,23 @@ static int listen_stop_handler(void *data, void *user_ctx)
89112 return 0 ;
90113}
91114
92- static void esp_dpp_call_cb ( esp_supp_dpp_event_t evt , void * data )
115+ static void dpp_stop ( void )
93116{
94117 if (s_dpp_ctx .dpp_auth ) {
95- esp_dpp_deinit_auth ();
118+ dpp_deinit_auth ();
96119 listen_stop_handler (NULL , NULL );
97120 }
98- s_dpp_ctx .dpp_event_cb (evt , data );
121+ }
122+
123+ static void dpp_abort_with_failure (uint32_t failure_reason )
124+ {
125+ /* Stop DPP*/
126+ dpp_stop ();
127+
128+ /* Send event to APP */
129+ wifi_event_dpp_failed_t event = {0 };
130+ event .failure_reason = failure_reason ;
131+ esp_event_post (WIFI_EVENT , WIFI_EVENT_DPP_FAILED , & event , sizeof (event ), OS_BLOCK );
99132}
100133
101134static void esp_dpp_auth_conf_wait_timeout (void * eloop_ctx , void * timeout_ctx )
@@ -106,7 +139,7 @@ static void esp_dpp_auth_conf_wait_timeout(void *eloop_ctx, void *timeout_ctx)
106139
107140 wpa_printf (MSG_INFO ,
108141 "DPP: Terminate authentication exchange due to Auth Confirm timeout" );
109- esp_dpp_call_cb ( ESP_SUPP_DPP_FAIL , ( void * ) ESP_ERR_DPP_AUTH_TIMEOUT );
142+ dpp_abort_with_failure ( ESP_ERR_DPP_AUTH_TIMEOUT );
110143}
111144
112145esp_err_t esp_dpp_send_action_frame (uint8_t * dest_mac , const uint8_t * buf , uint32_t len ,
@@ -132,7 +165,7 @@ esp_err_t esp_dpp_send_action_frame(uint8_t *dest_mac, const uint8_t *buf, uint3
132165
133166 if (ESP_OK != esp_wifi_action_tx_req (req )) {
134167 wpa_printf (MSG_ERROR , "DPP: Failed to perform offchannel operation" );
135- esp_dpp_call_cb ( ESP_SUPP_DPP_FAIL , ( void * ) ESP_ERR_DPP_TX_FAILURE );
168+ dpp_abort_with_failure ( ESP_ERR_DPP_TX_FAILURE );
136169 os_free (req );
137170 return ESP_FAIL ;
138171 }
@@ -234,7 +267,7 @@ static void gas_query_timeout(void *eloop_data, void *user_ctx)
234267 wpabuf_free (auth -> conf_req );
235268 auth -> conf_req = NULL ;
236269 }
237- esp_dpp_call_cb ( ESP_SUPP_DPP_FAIL , ( void * ) ESP_ERR_DPP_CONF_TIMEOUT );
270+ dpp_abort_with_failure ( ESP_ERR_DPP_CONF_TIMEOUT );
238271}
239272
240273static int gas_query_req_tx (struct dpp_authentication * auth )
@@ -247,7 +280,7 @@ static int gas_query_req_tx(struct dpp_authentication *auth)
247280 supp_op_classes );
248281 if (!buf ) {
249282 wpa_printf (MSG_ERROR , "DPP: No configuration request data available" );
250- esp_dpp_call_cb ( ESP_SUPP_DPP_FAIL , ( void * ) ESP_ERR_DPP_FAILURE );
283+ dpp_abort_with_failure ( ESP_ERR_DPP_FAILURE );
251284 return ESP_FAIL ;
252285 }
253286
@@ -298,7 +331,12 @@ static int esp_dpp_handle_config_obj(struct dpp_authentication *auth,
298331 if (atomic_load (& s_dpp_listen_in_progress )) {
299332 listen_stop_handler (NULL , NULL );
300333 }
301- esp_dpp_call_cb (ESP_SUPP_DPP_CFG_RECVD , wifi_cfg );
334+ /* deinit AUTH since authentication is done */
335+ dpp_deinit_auth ();
336+
337+ wifi_event_dpp_config_received_t event = {0 };
338+ event .wifi_cfg = s_dpp_ctx .wifi_cfg ;
339+ esp_event_post (WIFI_EVENT , WIFI_EVENT_DPP_CFG_RECVD , & event , sizeof (event ), OS_BLOCK );
302340
303341 return 0 ;
304342}
@@ -573,7 +611,7 @@ static void esp_dpp_rx_action(void *data, void *user_ctx)
573611 os_free (rx_param );
574612
575613 if (ret != ESP_OK ) {
576- esp_dpp_call_cb ( ESP_SUPP_DPP_FAIL , ( void * ) ESP_ERR_DPP_FAILURE );
614+ dpp_abort_with_failure ( ESP_ERR_DPP_FAILURE );
577615 }
578616}
579617
@@ -609,6 +647,7 @@ static void esp_dpp_bootstrap_gen(void *data, void *user_ctx)
609647{
610648 char * command = data ;
611649 const char * uri ;
650+ uint32_t len ;
612651
613652 s_dpp_ctx .id = dpp_bootstrap_gen (s_dpp_ctx .dpp_global , command );
614653
@@ -621,7 +660,17 @@ static void esp_dpp_bootstrap_gen(void *data, void *user_ctx)
621660 }
622661 uri = dpp_bootstrap_get_uri (s_dpp_ctx .dpp_global , s_dpp_ctx .id );
623662
624- esp_dpp_call_cb (ESP_SUPP_DPP_URI_READY , (void * )uri );
663+ wifi_event_dpp_uri_ready_t * event ;
664+ len = sizeof (* event ) + os_strlen (uri ) + 1 ;
665+ event = os_malloc (len );
666+ if (!event ) {
667+ return ;
668+ }
669+ event -> uri_len = os_strlen (uri );
670+ os_memcpy (event -> uri , uri , event -> uri_len );
671+ event -> uri [event -> uri_len ++ ] = '\0' ;
672+ esp_event_post (WIFI_EVENT , WIFI_EVENT_DPP_URI_READY , event , len , OS_BLOCK );
673+ os_free (event );
625674 os_free (command );
626675 dpp_api_lock ();
627676 s_dpp_ctx .bootstrap_done = true;
@@ -641,6 +690,14 @@ static int esp_dpp_deinit(void *data, void *user_ctx)
641690 esp_event_handler_unregister (WIFI_EVENT , WIFI_EVENT_ROC_DONE ,
642691 & roc_status_handler );
643692
693+ if (s_dpp_ctx .dpp_event_cb ) {
694+ esp_event_handler_unregister (WIFI_EVENT , WIFI_EVENT_DPP_URI_READY ,
695+ & dpp_event_handler );
696+ esp_event_handler_unregister (WIFI_EVENT , WIFI_EVENT_DPP_CFG_RECVD ,
697+ & dpp_event_handler );
698+ esp_event_handler_unregister (WIFI_EVENT , WIFI_EVENT_DPP_FAILED ,
699+ & dpp_event_handler );
700+ }
644701 if (params -> info ) {
645702 os_free (params -> info );
646703 params -> info = NULL ;
@@ -656,6 +713,7 @@ static int esp_dpp_deinit(void *data, void *user_ctx)
656713 }
657714 s_dpp_ctx .dpp_init_done = false;
658715 s_dpp_ctx .bootstrap_done = false;
716+ s_dpp_ctx .dpp_event_cb = NULL ;
659717
660718 return 0 ;
661719}
@@ -701,7 +759,7 @@ static void esp_dpp_auth_resp_retry(void *eloop_ctx, void *timeout_ctx)
701759 auth -> auth_resp_tries ++ ;
702760 if (auth -> auth_resp_tries >= max_tries ) {
703761 wpa_printf (MSG_INFO , "DPP: No confirm received from initiator - stopping exchange" );
704- esp_dpp_call_cb ( ESP_SUPP_DPP_FAIL , ( void * ) ESP_ERR_DPP_TX_FAILURE );
762+ dpp_abort_with_failure ( ESP_ERR_DPP_TX_FAILURE );
705763 return ;
706764 }
707765
@@ -727,7 +785,7 @@ static void tx_status_handler(void *arg, esp_event_base_t event_base,
727785 return ;
728786 }
729787 if (!auth ) {
730- esp_dpp_call_cb ( ESP_SUPP_DPP_FAIL , ( void * ) ESP_ERR_DPP_FAILURE );
788+ dpp_abort_with_failure ( ESP_ERR_DPP_FAILURE );
731789 return ;
732790 }
733791 if (auth -> waiting_auth_conf ) {
@@ -744,7 +802,7 @@ static void tx_status_handler(void *arg, esp_event_base_t event_base,
744802 if (evt -> status ) {
745803 /* failed to send gas query frame, retry logic needed? */
746804 wpa_printf (MSG_WARNING , "DPP: failed to send GAS query frame" );
747- esp_dpp_call_cb ( ESP_SUPP_DPP_FAIL , ( void * ) ESP_ERR_DPP_TX_FAILURE );
805+ dpp_abort_with_failure ( ESP_ERR_DPP_TX_FAILURE );
748806 } else {
749807 eloop_cancel_timeout (gas_query_timeout , NULL , auth );
750808 eloop_register_timeout (ESP_GAS_TIMEOUT_SECS , 0 , gas_query_timeout , NULL , auth );
@@ -990,6 +1048,14 @@ static int esp_dpp_init(void *eloop_data, void *user_ctx)
9901048 atomic_store (& s_dpp_listen_in_progress , false);
9911049 s_dpp_ctx .dpp_event_cb = cb ;
9921050
1051+ if (cb ) {
1052+ esp_event_handler_register (WIFI_EVENT , WIFI_EVENT_DPP_URI_READY ,
1053+ & dpp_event_handler , NULL );
1054+ esp_event_handler_register (WIFI_EVENT , WIFI_EVENT_DPP_CFG_RECVD ,
1055+ & dpp_event_handler , NULL );
1056+ esp_event_handler_register (WIFI_EVENT , WIFI_EVENT_DPP_FAILED ,
1057+ & dpp_event_handler , NULL );
1058+ }
9931059 esp_event_handler_register (WIFI_EVENT , WIFI_EVENT_ACTION_TX_STATUS ,
9941060 & tx_status_handler , NULL );
9951061 esp_event_handler_register (WIFI_EVENT , WIFI_EVENT_ROC_DONE ,
0 commit comments