@@ -11,6 +11,7 @@ LOG_MODULE_REGISTER(wifi_supplicant, CONFIG_WIFI_NM_WPA_SUPPLICANT_LOG_LEVEL);
11
11
#include <zephyr/kernel.h>
12
12
#include <zephyr/init.h>
13
13
#include <poll.h>
14
+ #include <zephyr/zvfs/eventfd.h>
14
15
15
16
#if !defined(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE ) && !defined(CONFIG_MBEDTLS_ENABLE_HEAP )
16
17
#include <mbedtls/platform.h>
@@ -44,6 +45,7 @@ static K_THREAD_STACK_DEFINE(iface_wq_stack, CONFIG_WIFI_NM_WPA_SUPPLICANT_WQ_ST
44
45
#include "fst/fst.h"
45
46
#include "includes.h"
46
47
#include "wpa_cli_zephyr.h"
48
+ #include "ctrl_iface_zephyr.h"
47
49
#ifdef CONFIG_WIFI_NM_HOSTAPD_AP
48
50
#include "hostapd.h"
49
51
#include "hapd_main.h"
@@ -109,7 +111,8 @@ struct supplicant_context {
109
111
struct net_mgmt_event_callback cb ;
110
112
struct net_if * iface ;
111
113
char if_name [CONFIG_NET_INTERFACE_NAME_LEN + 1 ];
112
- int event_socketpair [2 ];
114
+ struct k_fifo fifo ;
115
+ int sock ;
113
116
struct k_work iface_work ;
114
117
struct k_work_q iface_wq ;
115
118
int (* iface_handler )(struct supplicant_context * ctx , struct net_if * iface );
@@ -139,39 +142,25 @@ struct k_work_q *get_workq(void)
139
142
return & get_default_context ()-> iface_wq ;
140
143
}
141
144
145
+ /* found in hostap/wpa_supplicant/ctrl_iface_zephyr.c */
146
+ extern int send_data (struct k_fifo * fifo , int sock , const char * buf , size_t len , int flags );
147
+
142
148
int zephyr_wifi_send_event (const struct wpa_supplicant_event_msg * msg )
143
149
{
144
150
struct supplicant_context * ctx ;
145
- struct pollfd fds [1 ];
146
151
int ret ;
147
152
148
153
/* TODO: Fix this to get the correct container */
149
154
ctx = get_default_context ();
150
155
151
- if (ctx -> event_socketpair [ 1 ] < 0 ) {
156
+ if (ctx -> sock < 0 ) {
152
157
ret = - ENOENT ;
153
158
goto out ;
154
159
}
155
160
156
- fds [0 ].fd = ctx -> event_socketpair [0 ];
157
- fds [0 ].events = POLLOUT ;
158
- fds [0 ].revents = 0 ;
159
-
160
- ret = zsock_poll (fds , 1 , WRITE_TIMEOUT );
161
- if (ret < 0 ) {
162
- ret = - errno ;
163
- LOG_ERR ("Cannot write event (%d)" , ret );
164
- goto out ;
165
- }
166
-
167
- ret = zsock_send (ctx -> event_socketpair [1 ], msg , sizeof (* msg ), 0 );
168
- if (ret < 0 ) {
169
- ret = - errno ;
170
- LOG_WRN ("Event send failed (%d)" , ret );
171
- goto out ;
172
- }
173
-
174
- if (ret != sizeof (* msg )) {
161
+ ret = send_data (& ctx -> fifo , ctx -> sock ,
162
+ (const char * )msg , sizeof (* msg ), 0 );
163
+ if (ret != 0 ) {
175
164
ret = - EMSGSIZE ;
176
165
LOG_WRN ("Event partial send (%d)" , ret );
177
166
goto out ;
@@ -562,84 +551,105 @@ static int setup_interface_monitoring(struct supplicant_context *ctx, struct net
562
551
static void event_socket_handler (int sock , void * eloop_ctx , void * user_data )
563
552
{
564
553
struct supplicant_context * ctx = user_data ;
565
- struct wpa_supplicant_event_msg msg ;
566
- int ret ;
554
+ struct wpa_supplicant_event_msg event_msg ;
555
+ struct zephyr_msg * msg ;
556
+ zvfs_eventfd_t value ;
567
557
568
558
ARG_UNUSED (eloop_ctx );
569
- ARG_UNUSED (ctx );
570
559
571
- ret = zsock_recv (sock , & msg , sizeof (msg ), 0 );
572
- if (ret < 0 ) {
573
- LOG_ERR ("Failed to recv the message (%d)" , - errno );
574
- return ;
575
- }
560
+ do {
561
+ zvfs_eventfd_read (sock , & value );
576
562
577
- if ( ret != sizeof ( msg )) {
578
- LOG_ERR ( "Received incomplete message: got: %d, expected:%d" ,
579
- ret , sizeof ( msg ) );
580
- return ;
581
- }
563
+ msg = k_fifo_get ( & ctx -> fifo , K_NO_WAIT );
564
+ if ( msg == NULL ) {
565
+ LOG_ERR ( "fifo(event): %s" , "empty" );
566
+ return ;
567
+ }
582
568
583
- LOG_DBG ("Passing message %d to wpa_supplicant" , msg .event );
569
+ if (msg -> data == NULL ) {
570
+ LOG_ERR ("fifo(event): %s" , "no data" );
571
+ goto out ;
572
+ }
584
573
585
- if (msg .global ) {
586
- wpa_supplicant_event_global (msg .ctx , msg .event , msg .data );
574
+ if (msg -> len != sizeof (event_msg )) {
575
+ LOG_ERR ("Received incomplete message: got: %d, expected:%d" ,
576
+ msg -> len , sizeof (event_msg ));
577
+ goto out ;
578
+ }
579
+
580
+ memcpy (& event_msg , msg -> data , sizeof (event_msg ));
581
+
582
+ LOG_DBG ("Passing message %d to wpa_supplicant" , event_msg .event );
583
+
584
+ if (event_msg .global ) {
585
+ wpa_supplicant_event_global (event_msg .ctx , event_msg .event ,
586
+ event_msg .data );
587
587
#ifdef CONFIG_WIFI_NM_HOSTAPD_AP
588
- } else if (msg .hostapd ) {
589
- hostapd_event (msg .ctx , msg .event , msg .data );
588
+ } else if (event_msg .hostapd ) {
589
+ hostapd_event (event_msg .ctx , event_msg .event , event_msg .data );
590
590
#endif
591
- } else {
592
- wpa_supplicant_event (msg .ctx , msg .event , msg .data );
593
- }
594
-
595
- if (msg .data ) {
596
- union wpa_event_data * data = msg .data ;
597
-
598
- /* Free up deep copied data */
599
- if (msg .event == EVENT_AUTH ) {
600
- os_free ((char * )data -> auth .ies );
601
- } else if (msg .event == EVENT_RX_MGMT ) {
602
- os_free ((char * )data -> rx_mgmt .frame );
603
- } else if (msg .event == EVENT_TX_STATUS ) {
604
- os_free ((char * )data -> tx_status .data );
605
- } else if (msg .event == EVENT_ASSOC ) {
606
- os_free ((char * )data -> assoc_info .addr );
607
- os_free ((char * )data -> assoc_info .req_ies );
608
- os_free ((char * )data -> assoc_info .resp_ies );
609
- os_free ((char * )data -> assoc_info .resp_frame );
610
- } else if (msg .event == EVENT_ASSOC_REJECT ) {
611
- os_free ((char * )data -> assoc_reject .bssid );
612
- os_free ((char * )data -> assoc_reject .resp_ies );
613
- } else if (msg .event == EVENT_DEAUTH ) {
614
- os_free ((char * )data -> deauth_info .addr );
615
- os_free ((char * )data -> deauth_info .ie );
616
- } else if (msg .event == EVENT_DISASSOC ) {
617
- os_free ((char * )data -> disassoc_info .addr );
618
- os_free ((char * )data -> disassoc_info .ie );
619
- } else if (msg .event == EVENT_UNPROT_DEAUTH ) {
620
- os_free ((char * )data -> unprot_deauth .sa );
621
- os_free ((char * )data -> unprot_deauth .da );
622
- } else if (msg .event == EVENT_UNPROT_DISASSOC ) {
623
- os_free ((char * )data -> unprot_disassoc .sa );
624
- os_free ((char * )data -> unprot_disassoc .da );
591
+ } else {
592
+ wpa_supplicant_event (event_msg .ctx , event_msg .event , event_msg .data );
625
593
}
626
594
627
- os_free (msg .data );
628
- }
595
+ if (event_msg .data ) {
596
+ union wpa_event_data * data = event_msg .data ;
597
+
598
+ /* Free up deep copied data */
599
+ if (event_msg .event == EVENT_AUTH ) {
600
+ os_free ((char * )data -> auth .ies );
601
+ } else if (event_msg .event == EVENT_RX_MGMT ) {
602
+ os_free ((char * )data -> rx_mgmt .frame );
603
+ } else if (event_msg .event == EVENT_TX_STATUS ) {
604
+ os_free ((char * )data -> tx_status .data );
605
+ } else if (event_msg .event == EVENT_ASSOC ) {
606
+ os_free ((char * )data -> assoc_info .addr );
607
+ os_free ((char * )data -> assoc_info .req_ies );
608
+ os_free ((char * )data -> assoc_info .resp_ies );
609
+ os_free ((char * )data -> assoc_info .resp_frame );
610
+ } else if (event_msg .event == EVENT_ASSOC_REJECT ) {
611
+ os_free ((char * )data -> assoc_reject .bssid );
612
+ os_free ((char * )data -> assoc_reject .resp_ies );
613
+ } else if (event_msg .event == EVENT_DEAUTH ) {
614
+ os_free ((char * )data -> deauth_info .addr );
615
+ os_free ((char * )data -> deauth_info .ie );
616
+ } else if (event_msg .event == EVENT_DISASSOC ) {
617
+ os_free ((char * )data -> disassoc_info .addr );
618
+ os_free ((char * )data -> disassoc_info .ie );
619
+ } else if (event_msg .event == EVENT_UNPROT_DEAUTH ) {
620
+ os_free ((char * )data -> unprot_deauth .sa );
621
+ os_free ((char * )data -> unprot_deauth .da );
622
+ } else if (event_msg .event == EVENT_UNPROT_DISASSOC ) {
623
+ os_free ((char * )data -> unprot_disassoc .sa );
624
+ os_free ((char * )data -> unprot_disassoc .da );
625
+ }
626
+
627
+ os_free (event_msg .data );
628
+ }
629
+
630
+ out :
631
+ os_free (msg -> data );
632
+ os_free (msg );
633
+
634
+ } while (!k_fifo_is_empty (& ctx -> fifo ));
629
635
}
630
636
631
637
static int register_supplicant_event_socket (struct supplicant_context * ctx )
632
638
{
633
639
int ret ;
634
640
635
- ret = socketpair ( AF_UNIX , SOCK_STREAM , 0 , ctx -> event_socketpair );
641
+ ret = zvfs_eventfd ( 0 , ZVFS_EFD_NONBLOCK );
636
642
if (ret < 0 ) {
637
643
ret = - errno ;
638
644
LOG_ERR ("Failed to initialize socket (%d)" , ret );
639
645
return ret ;
640
646
}
641
647
642
- eloop_register_read_sock (ctx -> event_socketpair [0 ], event_socket_handler , NULL , ctx );
648
+ ctx -> sock = ret ;
649
+
650
+ k_fifo_init (& ctx -> fifo );
651
+
652
+ eloop_register_read_sock (ctx -> sock , event_socket_handler , NULL , ctx );
643
653
644
654
return 0 ;
645
655
}
@@ -707,7 +717,7 @@ static void handler(void)
707
717
708
718
supplicant_generate_state_event (ctx -> if_name , NET_EVENT_SUPPLICANT_CMD_NOT_READY , 0 );
709
719
710
- eloop_unregister_read_sock (ctx -> event_socketpair [ 0 ] );
720
+ eloop_unregister_read_sock (ctx -> sock );
711
721
712
722
zephyr_global_wpa_ctrl_deinit ();
713
723
@@ -716,8 +726,7 @@ static void handler(void)
716
726
out :
717
727
wpa_supplicant_deinit (ctx -> supplicant );
718
728
719
- zsock_close (ctx -> event_socketpair [0 ]);
720
- zsock_close (ctx -> event_socketpair [1 ]);
729
+ close (ctx -> sock );
721
730
722
731
err :
723
732
os_free (params .pid_file );
0 commit comments