2 * WPA Supplicant / privileged helper program
3 * Copyright (c) 2007-2009, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
18 #endif /* __linux__ */
24 #include "common/version.h"
25 #include "drivers/driver.h"
26 #include "l2_packet/l2_packet.h"
27 #include "common/privsep_commands.h"
28 #include "common/ieee802_11_defs.h"
31 struct wpa_priv_interface
{
32 struct wpa_priv_interface
*next
;
38 struct wpa_driver_ops
*driver
;
40 struct sockaddr_un drv_addr
;
43 /* TODO: add support for multiple l2 connections */
44 struct l2_packet_data
*l2
;
45 struct sockaddr_un l2_addr
;
49 static void wpa_priv_cmd_register(struct wpa_priv_interface
*iface
,
50 struct sockaddr_un
*from
)
52 if (iface
->drv_priv
) {
53 wpa_printf(MSG_DEBUG
, "Cleaning up forgotten driver instance");
54 if (iface
->driver
->deinit
)
55 iface
->driver
->deinit(iface
->drv_priv
);
56 iface
->drv_priv
= NULL
;
57 iface
->wpas_registered
= 0;
61 wpa_printf(MSG_DEBUG
, "Cleaning up forgotten l2_packet "
63 l2_packet_deinit(iface
->l2
);
67 if (iface
->driver
->init
== NULL
)
70 iface
->drv_priv
= iface
->driver
->init(iface
, iface
->ifname
);
71 if (iface
->drv_priv
== NULL
) {
72 wpa_printf(MSG_DEBUG
, "Failed to initialize driver wrapper");
76 wpa_printf(MSG_DEBUG
, "Driver wrapper '%s' initialized for interface "
77 "'%s'", iface
->driver_name
, iface
->ifname
);
79 os_memcpy(&iface
->drv_addr
, from
, sizeof(iface
->drv_addr
));
80 iface
->wpas_registered
= 1;
82 if (iface
->driver
->set_param
&&
83 iface
->driver
->set_param(iface
->drv_priv
, NULL
) < 0) {
84 wpa_printf(MSG_ERROR
, "Driver interface rejected param");
89 static void wpa_priv_cmd_unregister(struct wpa_priv_interface
*iface
,
90 struct sockaddr_un
*from
)
92 if (iface
->drv_priv
) {
93 if (iface
->driver
->deinit
)
94 iface
->driver
->deinit(iface
->drv_priv
);
95 iface
->drv_priv
= NULL
;
96 iface
->wpas_registered
= 0;
101 static void wpa_priv_cmd_scan(struct wpa_priv_interface
*iface
,
102 char *buf
, size_t len
)
104 struct wpa_driver_scan_params params
;
106 if (iface
->drv_priv
== NULL
)
109 os_memset(¶ms
, 0, sizeof(params
));
111 params
.ssids
[0].ssid
= (u8
*) buf
;
112 params
.ssids
[0].ssid_len
= len
;
113 params
.num_ssids
= 1;
116 if (iface
->driver
->scan2
)
117 iface
->driver
->scan2(iface
->drv_priv
, ¶ms
);
121 static void wpa_priv_get_scan_results2(struct wpa_priv_interface
*iface
,
122 struct sockaddr_un
*from
)
124 struct wpa_scan_results
*res
;
125 u8
*buf
= NULL
, *pos
, *end
;
129 res
= iface
->driver
->get_scan_results2(iface
->drv_priv
);
133 buf
= os_malloc(60000);
139 os_memcpy(pos
, &val
, sizeof(int));
142 for (i
= 0; i
< res
->num
; i
++) {
143 struct wpa_scan_res
*r
= res
->res
[i
];
144 val
= sizeof(*r
) + r
->ie_len
;
145 if (end
- pos
< (int) sizeof(int) + val
)
147 os_memcpy(pos
, &val
, sizeof(int));
149 os_memcpy(pos
, r
, val
);
153 sendto(iface
->fd
, buf
, pos
- buf
, 0, (struct sockaddr
*) from
,
157 wpa_scan_results_free(res
);
162 wpa_scan_results_free(res
);
163 sendto(iface
->fd
, "", 0, 0, (struct sockaddr
*) from
, sizeof(*from
));
167 static void wpa_priv_cmd_get_scan_results(struct wpa_priv_interface
*iface
,
168 struct sockaddr_un
*from
)
170 if (iface
->drv_priv
== NULL
)
173 if (iface
->driver
->get_scan_results2
)
174 wpa_priv_get_scan_results2(iface
, from
);
176 sendto(iface
->fd
, "", 0, 0, (struct sockaddr
*) from
,
181 static void wpa_priv_cmd_associate(struct wpa_priv_interface
*iface
,
182 void *buf
, size_t len
)
184 struct wpa_driver_associate_params params
;
185 struct privsep_cmd_associate
*assoc
;
189 if (iface
->drv_priv
== NULL
|| iface
->driver
->associate
== NULL
)
192 if (len
< sizeof(*assoc
)) {
193 wpa_printf(MSG_DEBUG
, "Invalid association request");
198 if (sizeof(*assoc
) + assoc
->wpa_ie_len
> len
) {
199 wpa_printf(MSG_DEBUG
, "Association request overflow");
203 os_memset(¶ms
, 0, sizeof(params
));
204 bssid
= assoc
->bssid
;
205 if (bssid
[0] | bssid
[1] | bssid
[2] | bssid
[3] | bssid
[4] | bssid
[5])
206 params
.bssid
= bssid
;
207 params
.ssid
= assoc
->ssid
;
208 if (assoc
->ssid_len
> 32)
210 params
.ssid_len
= assoc
->ssid_len
;
211 params
.freq
= assoc
->freq
;
212 if (assoc
->wpa_ie_len
) {
213 params
.wpa_ie
= (u8
*) (assoc
+ 1);
214 params
.wpa_ie_len
= assoc
->wpa_ie_len
;
216 params
.pairwise_suite
= assoc
->pairwise_suite
;
217 params
.group_suite
= assoc
->group_suite
;
218 params
.key_mgmt_suite
= assoc
->key_mgmt_suite
;
219 params
.auth_alg
= assoc
->auth_alg
;
220 params
.mode
= assoc
->mode
;
222 res
= iface
->driver
->associate(iface
->drv_priv
, ¶ms
);
223 wpa_printf(MSG_DEBUG
, "drv->associate: res=%d", res
);
227 static void wpa_priv_cmd_get_bssid(struct wpa_priv_interface
*iface
,
228 struct sockaddr_un
*from
)
232 if (iface
->drv_priv
== NULL
)
235 if (iface
->driver
->get_bssid
== NULL
||
236 iface
->driver
->get_bssid(iface
->drv_priv
, bssid
) < 0)
239 sendto(iface
->fd
, bssid
, ETH_ALEN
, 0, (struct sockaddr
*) from
,
244 sendto(iface
->fd
, "", 0, 0, (struct sockaddr
*) from
, sizeof(*from
));
248 static void wpa_priv_cmd_get_ssid(struct wpa_priv_interface
*iface
,
249 struct sockaddr_un
*from
)
251 u8 ssid
[sizeof(int) + 32];
254 if (iface
->drv_priv
== NULL
)
257 if (iface
->driver
->get_ssid
== NULL
)
260 res
= iface
->driver
->get_ssid(iface
->drv_priv
, &ssid
[sizeof(int)]);
261 if (res
< 0 || res
> 32)
263 os_memcpy(ssid
, &res
, sizeof(int));
265 sendto(iface
->fd
, ssid
, sizeof(ssid
), 0, (struct sockaddr
*) from
,
270 sendto(iface
->fd
, "", 0, 0, (struct sockaddr
*) from
, sizeof(*from
));
274 static void wpa_priv_cmd_set_key(struct wpa_priv_interface
*iface
,
275 void *buf
, size_t len
)
277 struct privsep_cmd_set_key
*params
;
280 if (iface
->drv_priv
== NULL
|| iface
->driver
->set_key
== NULL
)
283 if (len
!= sizeof(*params
)) {
284 wpa_printf(MSG_DEBUG
, "Invalid set_key request");
290 res
= iface
->driver
->set_key(iface
->ifname
, iface
->drv_priv
,
292 params
->addr
, params
->key_idx
,
294 params
->seq_len
? params
->seq
: NULL
,
296 params
->key_len
? params
->key
: NULL
,
298 wpa_printf(MSG_DEBUG
, "drv->set_key: res=%d", res
);
302 static void wpa_priv_cmd_get_capa(struct wpa_priv_interface
*iface
,
303 struct sockaddr_un
*from
)
305 struct wpa_driver_capa capa
;
307 if (iface
->drv_priv
== NULL
)
310 if (iface
->driver
->get_capa
== NULL
||
311 iface
->driver
->get_capa(iface
->drv_priv
, &capa
) < 0)
314 sendto(iface
->fd
, &capa
, sizeof(capa
), 0, (struct sockaddr
*) from
,
319 sendto(iface
->fd
, "", 0, 0, (struct sockaddr
*) from
, sizeof(*from
));
323 static void wpa_priv_l2_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
326 struct wpa_priv_interface
*iface
= ctx
;
330 io
[0].iov_base
= (u8
*) src_addr
;
331 io
[0].iov_len
= ETH_ALEN
;
332 io
[1].iov_base
= (u8
*) buf
;
335 os_memset(&msg
, 0, sizeof(msg
));
338 msg
.msg_name
= &iface
->l2_addr
;
339 msg
.msg_namelen
= sizeof(iface
->l2_addr
);
341 if (sendmsg(iface
->fd
, &msg
, 0) < 0) {
342 perror("sendmsg(l2 rx)");
347 static void wpa_priv_cmd_l2_register(struct wpa_priv_interface
*iface
,
348 struct sockaddr_un
*from
,
349 void *buf
, size_t len
)
352 u8 own_addr
[ETH_ALEN
];
356 if (len
!= 2 * sizeof(int)) {
357 wpa_printf(MSG_DEBUG
, "Invalid l2_register length %lu",
358 (unsigned long) len
);
363 if (proto
!= ETH_P_EAPOL
&& proto
!= ETH_P_RSN_PREAUTH
) {
364 wpa_printf(MSG_DEBUG
, "Refused l2_packet connection for "
365 "ethertype 0x%x", proto
);
370 wpa_printf(MSG_DEBUG
, "Cleaning up forgotten l2_packet "
372 l2_packet_deinit(iface
->l2
);
376 os_memcpy(&iface
->l2_addr
, from
, sizeof(iface
->l2_addr
));
378 iface
->l2
= l2_packet_init(iface
->ifname
, NULL
, proto
,
379 wpa_priv_l2_rx
, iface
, reg_cmd
[1]);
380 if (iface
->l2
== NULL
) {
381 wpa_printf(MSG_DEBUG
, "Failed to initialize l2_packet "
382 "instance for protocol %d", proto
);
386 if (l2_packet_get_own_addr(iface
->l2
, own_addr
) < 0) {
387 wpa_printf(MSG_DEBUG
, "Failed to get own address from "
389 l2_packet_deinit(iface
->l2
);
394 res
= sendto(iface
->fd
, own_addr
, ETH_ALEN
, 0,
395 (struct sockaddr
*) from
, sizeof(*from
));
396 wpa_printf(MSG_DEBUG
, "L2 registration: res=%d", res
);
400 static void wpa_priv_cmd_l2_unregister(struct wpa_priv_interface
*iface
,
401 struct sockaddr_un
*from
)
404 l2_packet_deinit(iface
->l2
);
410 static void wpa_priv_cmd_l2_notify_auth_start(struct wpa_priv_interface
*iface
,
411 struct sockaddr_un
*from
)
414 l2_packet_notify_auth_start(iface
->l2
);
418 static void wpa_priv_cmd_l2_send(struct wpa_priv_interface
*iface
,
419 struct sockaddr_un
*from
,
420 void *buf
, size_t len
)
426 if (iface
->l2
== NULL
)
429 if (len
< ETH_ALEN
+ 2) {
430 wpa_printf(MSG_DEBUG
, "Too short L2 send packet (len=%lu)",
431 (unsigned long) len
);
436 os_memcpy(&proto
, buf
+ ETH_ALEN
, 2);
438 if (proto
!= ETH_P_EAPOL
&& proto
!= ETH_P_RSN_PREAUTH
) {
439 wpa_printf(MSG_DEBUG
, "Refused l2_packet send for ethertype "
444 res
= l2_packet_send(iface
->l2
, dst_addr
, proto
, buf
+ ETH_ALEN
+ 2,
446 wpa_printf(MSG_DEBUG
, "L2 send: res=%d", res
);
450 static void wpa_priv_cmd_set_country(struct wpa_priv_interface
*iface
,
453 if (iface
->drv_priv
== NULL
|| iface
->driver
->set_country
== NULL
||
457 iface
->driver
->set_country(iface
->drv_priv
, buf
);
461 static void wpa_priv_receive(int sock
, void *eloop_ctx
, void *sock_ctx
)
463 struct wpa_priv_interface
*iface
= eloop_ctx
;
464 char buf
[2000], *pos
;
468 struct sockaddr_un from
;
469 socklen_t fromlen
= sizeof(from
);
471 res
= recvfrom(sock
, buf
, sizeof(buf
), 0, (struct sockaddr
*) &from
,
478 if (res
< (int) sizeof(int)) {
479 wpa_printf(MSG_DEBUG
, "Too short command (len=%d)", res
);
483 os_memcpy(&cmd
, buf
, sizeof(int));
484 wpa_printf(MSG_DEBUG
, "Command %d for interface %s",
486 cmd_buf
= &buf
[sizeof(int)];
487 cmd_len
= res
- sizeof(int);
490 case PRIVSEP_CMD_REGISTER
:
491 wpa_priv_cmd_register(iface
, &from
);
493 case PRIVSEP_CMD_UNREGISTER
:
494 wpa_priv_cmd_unregister(iface
, &from
);
496 case PRIVSEP_CMD_SCAN
:
497 wpa_priv_cmd_scan(iface
, cmd_buf
, cmd_len
);
499 case PRIVSEP_CMD_GET_SCAN_RESULTS
:
500 wpa_priv_cmd_get_scan_results(iface
, &from
);
502 case PRIVSEP_CMD_ASSOCIATE
:
503 wpa_priv_cmd_associate(iface
, cmd_buf
, cmd_len
);
505 case PRIVSEP_CMD_GET_BSSID
:
506 wpa_priv_cmd_get_bssid(iface
, &from
);
508 case PRIVSEP_CMD_GET_SSID
:
509 wpa_priv_cmd_get_ssid(iface
, &from
);
511 case PRIVSEP_CMD_SET_KEY
:
512 wpa_priv_cmd_set_key(iface
, cmd_buf
, cmd_len
);
514 case PRIVSEP_CMD_GET_CAPA
:
515 wpa_priv_cmd_get_capa(iface
, &from
);
517 case PRIVSEP_CMD_L2_REGISTER
:
518 wpa_priv_cmd_l2_register(iface
, &from
, cmd_buf
, cmd_len
);
520 case PRIVSEP_CMD_L2_UNREGISTER
:
521 wpa_priv_cmd_l2_unregister(iface
, &from
);
523 case PRIVSEP_CMD_L2_NOTIFY_AUTH_START
:
524 wpa_priv_cmd_l2_notify_auth_start(iface
, &from
);
526 case PRIVSEP_CMD_L2_SEND
:
527 wpa_priv_cmd_l2_send(iface
, &from
, cmd_buf
, cmd_len
);
529 case PRIVSEP_CMD_SET_COUNTRY
:
531 if (pos
+ cmd_len
>= buf
+ sizeof(buf
))
534 wpa_priv_cmd_set_country(iface
, pos
);
540 static void wpa_priv_interface_deinit(struct wpa_priv_interface
*iface
)
542 if (iface
->drv_priv
&& iface
->driver
->deinit
)
543 iface
->driver
->deinit(iface
->drv_priv
);
545 if (iface
->fd
>= 0) {
546 eloop_unregister_read_sock(iface
->fd
);
548 unlink(iface
->sock_name
);
552 l2_packet_deinit(iface
->l2
);
554 os_free(iface
->ifname
);
555 os_free(iface
->driver_name
);
556 os_free(iface
->sock_name
);
561 extern struct wpa_driver_ops
*wpa_drivers
[];
563 static struct wpa_priv_interface
*
564 wpa_priv_interface_init(const char *dir
, const char *params
)
566 struct wpa_priv_interface
*iface
;
569 struct sockaddr_un addr
;
572 pos
= os_strchr(params
, ':');
576 iface
= os_zalloc(sizeof(*iface
));
582 iface
->driver_name
= os_malloc(len
+ 1);
583 if (iface
->driver_name
== NULL
) {
584 wpa_priv_interface_deinit(iface
);
587 os_memcpy(iface
->driver_name
, params
, len
);
588 iface
->driver_name
[len
] = '\0';
590 for (i
= 0; wpa_drivers
[i
]; i
++) {
591 if (os_strcmp(iface
->driver_name
,
592 wpa_drivers
[i
]->name
) == 0) {
593 iface
->driver
= wpa_drivers
[i
];
597 if (iface
->driver
== NULL
) {
598 wpa_printf(MSG_ERROR
, "Unsupported driver '%s'",
600 wpa_priv_interface_deinit(iface
);
605 iface
->ifname
= os_strdup(pos
);
606 if (iface
->ifname
== NULL
) {
607 wpa_priv_interface_deinit(iface
);
611 len
= os_strlen(dir
) + 1 + os_strlen(iface
->ifname
);
612 iface
->sock_name
= os_malloc(len
+ 1);
613 if (iface
->sock_name
== NULL
) {
614 wpa_priv_interface_deinit(iface
);
618 os_snprintf(iface
->sock_name
, len
+ 1, "%s/%s", dir
, iface
->ifname
);
619 if (os_strlen(iface
->sock_name
) >= sizeof(addr
.sun_path
)) {
620 wpa_priv_interface_deinit(iface
);
624 iface
->fd
= socket(PF_UNIX
, SOCK_DGRAM
, 0);
626 perror("socket(PF_UNIX)");
627 wpa_priv_interface_deinit(iface
);
631 os_memset(&addr
, 0, sizeof(addr
));
632 addr
.sun_family
= AF_UNIX
;
633 os_strlcpy(addr
.sun_path
, iface
->sock_name
, sizeof(addr
.sun_path
));
635 if (bind(iface
->fd
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
636 wpa_printf(MSG_DEBUG
, "bind(PF_UNIX) failed: %s",
638 if (connect(iface
->fd
, (struct sockaddr
*) &addr
,
640 wpa_printf(MSG_DEBUG
, "Socket exists, but does not "
641 "allow connections - assuming it was "
642 "leftover from forced program termination");
643 if (unlink(iface
->sock_name
) < 0) {
644 perror("unlink[ctrl_iface]");
645 wpa_printf(MSG_ERROR
, "Could not unlink "
646 "existing ctrl_iface socket '%s'",
650 if (bind(iface
->fd
, (struct sockaddr
*) &addr
,
652 perror("bind(PF_UNIX)");
655 wpa_printf(MSG_DEBUG
, "Successfully replaced leftover "
656 "socket '%s'", iface
->sock_name
);
658 wpa_printf(MSG_INFO
, "Socket exists and seems to be "
659 "in use - cannot override it");
660 wpa_printf(MSG_INFO
, "Delete '%s' manually if it is "
661 "not used anymore", iface
->sock_name
);
666 if (chmod(iface
->sock_name
, S_IRWXU
| S_IRWXG
| S_IRWXO
) < 0) {
671 eloop_register_read_sock(iface
->fd
, wpa_priv_receive
, iface
, NULL
);
676 wpa_priv_interface_deinit(iface
);
681 static int wpa_priv_send_event(struct wpa_priv_interface
*iface
, int event
,
682 const void *data
, size_t data_len
)
687 io
[0].iov_base
= &event
;
688 io
[0].iov_len
= sizeof(event
);
689 io
[1].iov_base
= (u8
*) data
;
690 io
[1].iov_len
= data_len
;
692 os_memset(&msg
, 0, sizeof(msg
));
694 msg
.msg_iovlen
= data
? 2 : 1;
695 msg
.msg_name
= &iface
->drv_addr
;
696 msg
.msg_namelen
= sizeof(iface
->drv_addr
);
698 if (sendmsg(iface
->fd
, &msg
, 0) < 0) {
699 perror("sendmsg(wpas_socket)");
707 static void wpa_priv_send_assoc(struct wpa_priv_interface
*iface
, int event
,
708 union wpa_event_data
*data
)
710 size_t buflen
= 3 * sizeof(int);
715 buflen
+= data
->assoc_info
.req_ies_len
+
716 data
->assoc_info
.resp_ies_len
+
717 data
->assoc_info
.beacon_ies_len
;
720 buf
= os_malloc(buflen
);
726 if (data
&& data
->assoc_info
.req_ies
) {
727 len
= data
->assoc_info
.req_ies_len
;
728 os_memcpy(pos
, &len
, sizeof(int));
730 os_memcpy(pos
, data
->assoc_info
.req_ies
, len
);
734 os_memcpy(pos
, &len
, sizeof(int));
738 if (data
&& data
->assoc_info
.resp_ies
) {
739 len
= data
->assoc_info
.resp_ies_len
;
740 os_memcpy(pos
, &len
, sizeof(int));
742 os_memcpy(pos
, data
->assoc_info
.resp_ies
, len
);
746 os_memcpy(pos
, &len
, sizeof(int));
750 if (data
&& data
->assoc_info
.beacon_ies
) {
751 len
= data
->assoc_info
.beacon_ies_len
;
752 os_memcpy(pos
, &len
, sizeof(int));
754 os_memcpy(pos
, data
->assoc_info
.beacon_ies
, len
);
758 os_memcpy(pos
, &len
, sizeof(int));
762 wpa_priv_send_event(iface
, event
, buf
, buflen
);
768 static void wpa_priv_send_interface_status(struct wpa_priv_interface
*iface
,
769 union wpa_event_data
*data
)
779 ievent
= data
->interface_status
.ievent
;
780 maxlen
= sizeof(data
->interface_status
.ifname
);
781 ifname
= data
->interface_status
.ifname
;
782 for (len
= 0; len
< maxlen
&& ifname
[len
]; len
++)
785 buf
= os_malloc(sizeof(int) + len
);
789 os_memcpy(buf
, &ievent
, sizeof(int));
790 os_memcpy(buf
+ sizeof(int), ifname
, len
);
792 wpa_priv_send_event(iface
, PRIVSEP_EVENT_INTERFACE_STATUS
,
793 buf
, sizeof(int) + len
);
800 static void wpa_priv_send_ft_response(struct wpa_priv_interface
*iface
,
801 union wpa_event_data
*data
)
806 if (data
== NULL
|| data
->ft_ies
.ies
== NULL
)
809 len
= sizeof(int) + ETH_ALEN
+ data
->ft_ies
.ies_len
;
810 buf
= os_malloc(len
);
815 os_memcpy(pos
, &data
->ft_ies
.ft_action
, sizeof(int));
817 os_memcpy(pos
, data
->ft_ies
.target_ap
, ETH_ALEN
);
819 os_memcpy(pos
, data
->ft_ies
.ies
, data
->ft_ies
.ies_len
);
821 wpa_priv_send_event(iface
, PRIVSEP_EVENT_FT_RESPONSE
, buf
, len
);
828 void wpa_supplicant_event(void *ctx
, wpa_event_type event
,
829 union wpa_event_data
*data
)
831 struct wpa_priv_interface
*iface
= ctx
;
833 wpa_printf(MSG_DEBUG
, "%s - event=%d", __func__
, event
);
835 if (!iface
->wpas_registered
) {
836 wpa_printf(MSG_DEBUG
, "Driver event received, but "
837 "wpa_supplicant not registered");
843 wpa_priv_send_assoc(iface
, PRIVSEP_EVENT_ASSOC
, data
);
846 wpa_priv_send_event(iface
, PRIVSEP_EVENT_DISASSOC
, NULL
, 0);
848 case EVENT_ASSOCINFO
:
851 wpa_priv_send_assoc(iface
, PRIVSEP_EVENT_ASSOCINFO
, data
);
853 case EVENT_MICHAEL_MIC_FAILURE
:
856 wpa_priv_send_event(iface
, PRIVSEP_EVENT_MICHAEL_MIC_FAILURE
,
857 &data
->michael_mic_failure
.unicast
,
860 case EVENT_SCAN_RESULTS
:
861 wpa_priv_send_event(iface
, PRIVSEP_EVENT_SCAN_RESULTS
, NULL
,
864 case EVENT_INTERFACE_STATUS
:
865 wpa_priv_send_interface_status(iface
, data
);
867 case EVENT_PMKID_CANDIDATE
:
870 wpa_priv_send_event(iface
, PRIVSEP_EVENT_PMKID_CANDIDATE
,
871 &data
->pmkid_candidate
,
872 sizeof(struct pmkid_candidate
));
877 wpa_priv_send_event(iface
, PRIVSEP_EVENT_STKSTART
,
878 &data
->stkstart
.peer
, ETH_ALEN
);
880 case EVENT_FT_RESPONSE
:
881 wpa_priv_send_ft_response(iface
, data
);
884 wpa_printf(MSG_DEBUG
, "Unsupported driver event %d - TODO",
891 void wpa_supplicant_rx_eapol(void *ctx
, const u8
*src_addr
,
892 const u8
*buf
, size_t len
)
894 struct wpa_priv_interface
*iface
= ctx
;
897 int event
= PRIVSEP_EVENT_RX_EAPOL
;
899 wpa_printf(MSG_DEBUG
, "RX EAPOL from driver");
900 io
[0].iov_base
= &event
;
901 io
[0].iov_len
= sizeof(event
);
902 io
[1].iov_base
= (u8
*) src_addr
;
903 io
[1].iov_len
= ETH_ALEN
;
904 io
[2].iov_base
= (u8
*) buf
;
907 os_memset(&msg
, 0, sizeof(msg
));
910 msg
.msg_name
= &iface
->drv_addr
;
911 msg
.msg_namelen
= sizeof(iface
->drv_addr
);
913 if (sendmsg(iface
->fd
, &msg
, 0) < 0)
914 perror("sendmsg(wpas_socket)");
918 static void wpa_priv_terminate(int sig
, void *eloop_ctx
, void *signal_ctx
)
920 wpa_printf(MSG_DEBUG
, "wpa_priv termination requested");
925 static void wpa_priv_fd_workaround(void)
929 /* When started from pcmcia-cs scripts, wpa_supplicant might start with
930 * fd 0, 1, and 2 closed. This will cause some issues because many
931 * places in wpa_supplicant are still printing out to stdout. As a
932 * workaround, make sure that fd's 0, 1, and 2 are not used for other
934 for (i
= 0; i
< 3; i
++) {
935 s
= open("/dev/null", O_RDWR
);
941 #endif /* __linux__ */
945 static void usage(void)
947 printf("wpa_priv v" VERSION_STR
"\n"
948 "Copyright (c) 2007-2009, Jouni Malinen <j@w1.fi> and "
952 " wpa_priv [-Bdd] [-P<pid file>] <driver:ifname> "
953 "[driver:ifname ...]\n");
957 extern int wpa_debug_level
;
959 int main(int argc
, char *argv
[])
963 char *pid_file
= NULL
;
965 char *ctrl_dir
= "/var/run/wpa_priv";
966 struct wpa_priv_interface
*interfaces
= NULL
, *iface
;
968 if (os_program_init())
971 wpa_priv_fd_workaround();
974 c
= getopt(argc
, argv
, "Bc:dP:");
988 pid_file
= os_rel2abs_path(optarg
);
996 if (optind
>= argc
) {
1001 wpa_printf(MSG_DEBUG
, "wpa_priv control directory: '%s'", ctrl_dir
);
1004 wpa_printf(MSG_ERROR
, "Failed to initialize event loop");
1008 for (i
= optind
; i
< argc
; i
++) {
1009 wpa_printf(MSG_DEBUG
, "Adding driver:interface %s", argv
[i
]);
1010 iface
= wpa_priv_interface_init(ctrl_dir
, argv
[i
]);
1013 iface
->next
= interfaces
;
1017 if (daemonize
&& os_daemonize(pid_file
))
1020 eloop_register_signal_terminate(wpa_priv_terminate
, NULL
);
1028 struct wpa_priv_interface
*prev
= iface
;
1029 iface
= iface
->next
;
1030 wpa_priv_interface_deinit(prev
);
1035 os_daemonize_terminate(pid_file
);
1037 os_program_deinit();