2 * WPA Supplicant / privileged helper program
3 * Copyright (c) 2007-2009, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #endif /* __linux__ */
18 #include "common/version.h"
19 #include "drivers/driver.h"
20 #include "l2_packet/l2_packet.h"
21 #include "common/privsep_commands.h"
22 #include "common/ieee802_11_defs.h"
25 struct wpa_priv_interface
{
26 struct wpa_priv_interface
*next
;
32 struct wpa_driver_ops
*driver
;
34 struct sockaddr_un drv_addr
;
37 /* TODO: add support for multiple l2 connections */
38 struct l2_packet_data
*l2
;
39 struct sockaddr_un l2_addr
;
43 static void wpa_priv_cmd_register(struct wpa_priv_interface
*iface
,
44 struct sockaddr_un
*from
)
46 if (iface
->drv_priv
) {
47 wpa_printf(MSG_DEBUG
, "Cleaning up forgotten driver instance");
48 if (iface
->driver
->deinit
)
49 iface
->driver
->deinit(iface
->drv_priv
);
50 iface
->drv_priv
= NULL
;
51 iface
->wpas_registered
= 0;
55 wpa_printf(MSG_DEBUG
, "Cleaning up forgotten l2_packet "
57 l2_packet_deinit(iface
->l2
);
61 if (iface
->driver
->init
== NULL
)
64 iface
->drv_priv
= iface
->driver
->init(iface
, iface
->ifname
);
65 if (iface
->drv_priv
== NULL
) {
66 wpa_printf(MSG_DEBUG
, "Failed to initialize driver wrapper");
70 wpa_printf(MSG_DEBUG
, "Driver wrapper '%s' initialized for interface "
71 "'%s'", iface
->driver_name
, iface
->ifname
);
73 os_memcpy(&iface
->drv_addr
, from
, sizeof(iface
->drv_addr
));
74 iface
->wpas_registered
= 1;
76 if (iface
->driver
->set_param
&&
77 iface
->driver
->set_param(iface
->drv_priv
, NULL
) < 0) {
78 wpa_printf(MSG_ERROR
, "Driver interface rejected param");
83 static void wpa_priv_cmd_unregister(struct wpa_priv_interface
*iface
,
84 struct sockaddr_un
*from
)
86 if (iface
->drv_priv
) {
87 if (iface
->driver
->deinit
)
88 iface
->driver
->deinit(iface
->drv_priv
);
89 iface
->drv_priv
= NULL
;
90 iface
->wpas_registered
= 0;
95 static void wpa_priv_cmd_scan(struct wpa_priv_interface
*iface
,
96 char *buf
, size_t len
)
98 struct wpa_driver_scan_params params
;
100 if (iface
->drv_priv
== NULL
)
103 os_memset(¶ms
, 0, sizeof(params
));
105 params
.ssids
[0].ssid
= (u8
*) buf
;
106 params
.ssids
[0].ssid_len
= len
;
107 params
.num_ssids
= 1;
110 if (iface
->driver
->scan2
)
111 iface
->driver
->scan2(iface
->drv_priv
, ¶ms
);
115 static void wpa_priv_get_scan_results2(struct wpa_priv_interface
*iface
,
116 struct sockaddr_un
*from
)
118 struct wpa_scan_results
*res
;
119 u8
*buf
= NULL
, *pos
, *end
;
123 res
= iface
->driver
->get_scan_results2(iface
->drv_priv
);
127 buf
= os_malloc(60000);
133 os_memcpy(pos
, &val
, sizeof(int));
136 for (i
= 0; i
< res
->num
; i
++) {
137 struct wpa_scan_res
*r
= res
->res
[i
];
138 val
= sizeof(*r
) + r
->ie_len
;
139 if (end
- pos
< (int) sizeof(int) + val
)
141 os_memcpy(pos
, &val
, sizeof(int));
143 os_memcpy(pos
, r
, val
);
147 sendto(iface
->fd
, buf
, pos
- buf
, 0, (struct sockaddr
*) from
,
151 wpa_scan_results_free(res
);
156 wpa_scan_results_free(res
);
157 sendto(iface
->fd
, "", 0, 0, (struct sockaddr
*) from
, sizeof(*from
));
161 static void wpa_priv_cmd_get_scan_results(struct wpa_priv_interface
*iface
,
162 struct sockaddr_un
*from
)
164 if (iface
->drv_priv
== NULL
)
167 if (iface
->driver
->get_scan_results2
)
168 wpa_priv_get_scan_results2(iface
, from
);
170 sendto(iface
->fd
, "", 0, 0, (struct sockaddr
*) from
,
175 static void wpa_priv_cmd_associate(struct wpa_priv_interface
*iface
,
176 void *buf
, size_t len
)
178 struct wpa_driver_associate_params params
;
179 struct privsep_cmd_associate
*assoc
;
183 if (iface
->drv_priv
== NULL
|| iface
->driver
->associate
== NULL
)
186 if (len
< sizeof(*assoc
)) {
187 wpa_printf(MSG_DEBUG
, "Invalid association request");
192 if (sizeof(*assoc
) + assoc
->wpa_ie_len
> len
) {
193 wpa_printf(MSG_DEBUG
, "Association request overflow");
197 os_memset(¶ms
, 0, sizeof(params
));
198 bssid
= assoc
->bssid
;
199 if (bssid
[0] | bssid
[1] | bssid
[2] | bssid
[3] | bssid
[4] | bssid
[5])
200 params
.bssid
= bssid
;
201 params
.ssid
= assoc
->ssid
;
202 if (assoc
->ssid_len
> 32)
204 params
.ssid_len
= assoc
->ssid_len
;
205 params
.freq
= assoc
->freq
;
206 if (assoc
->wpa_ie_len
) {
207 params
.wpa_ie
= (u8
*) (assoc
+ 1);
208 params
.wpa_ie_len
= assoc
->wpa_ie_len
;
210 params
.pairwise_suite
= assoc
->pairwise_suite
;
211 params
.group_suite
= assoc
->group_suite
;
212 params
.key_mgmt_suite
= assoc
->key_mgmt_suite
;
213 params
.auth_alg
= assoc
->auth_alg
;
214 params
.mode
= assoc
->mode
;
216 res
= iface
->driver
->associate(iface
->drv_priv
, ¶ms
);
217 wpa_printf(MSG_DEBUG
, "drv->associate: res=%d", res
);
221 static void wpa_priv_cmd_get_bssid(struct wpa_priv_interface
*iface
,
222 struct sockaddr_un
*from
)
226 if (iface
->drv_priv
== NULL
)
229 if (iface
->driver
->get_bssid
== NULL
||
230 iface
->driver
->get_bssid(iface
->drv_priv
, bssid
) < 0)
233 sendto(iface
->fd
, bssid
, ETH_ALEN
, 0, (struct sockaddr
*) from
,
238 sendto(iface
->fd
, "", 0, 0, (struct sockaddr
*) from
, sizeof(*from
));
242 static void wpa_priv_cmd_get_ssid(struct wpa_priv_interface
*iface
,
243 struct sockaddr_un
*from
)
245 u8 ssid
[sizeof(int) + 32];
248 if (iface
->drv_priv
== NULL
)
251 if (iface
->driver
->get_ssid
== NULL
)
254 res
= iface
->driver
->get_ssid(iface
->drv_priv
, &ssid
[sizeof(int)]);
255 if (res
< 0 || res
> 32)
257 os_memcpy(ssid
, &res
, sizeof(int));
259 sendto(iface
->fd
, ssid
, sizeof(ssid
), 0, (struct sockaddr
*) from
,
264 sendto(iface
->fd
, "", 0, 0, (struct sockaddr
*) from
, sizeof(*from
));
268 static void wpa_priv_cmd_set_key(struct wpa_priv_interface
*iface
,
269 void *buf
, size_t len
)
271 struct privsep_cmd_set_key
*params
;
274 if (iface
->drv_priv
== NULL
|| iface
->driver
->set_key
== NULL
)
277 if (len
!= sizeof(*params
)) {
278 wpa_printf(MSG_DEBUG
, "Invalid set_key request");
284 res
= iface
->driver
->set_key(iface
->ifname
, iface
->drv_priv
,
286 params
->addr
, params
->key_idx
,
288 params
->seq_len
? params
->seq
: NULL
,
290 params
->key_len
? params
->key
: NULL
,
292 wpa_printf(MSG_DEBUG
, "drv->set_key: res=%d", res
);
296 static void wpa_priv_cmd_get_capa(struct wpa_priv_interface
*iface
,
297 struct sockaddr_un
*from
)
299 struct wpa_driver_capa capa
;
301 if (iface
->drv_priv
== NULL
)
304 if (iface
->driver
->get_capa
== NULL
||
305 iface
->driver
->get_capa(iface
->drv_priv
, &capa
) < 0)
308 sendto(iface
->fd
, &capa
, sizeof(capa
), 0, (struct sockaddr
*) from
,
313 sendto(iface
->fd
, "", 0, 0, (struct sockaddr
*) from
, sizeof(*from
));
317 static void wpa_priv_l2_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
320 struct wpa_priv_interface
*iface
= ctx
;
324 io
[0].iov_base
= (u8
*) src_addr
;
325 io
[0].iov_len
= ETH_ALEN
;
326 io
[1].iov_base
= (u8
*) buf
;
329 os_memset(&msg
, 0, sizeof(msg
));
332 msg
.msg_name
= &iface
->l2_addr
;
333 msg
.msg_namelen
= sizeof(iface
->l2_addr
);
335 if (sendmsg(iface
->fd
, &msg
, 0) < 0) {
336 perror("sendmsg(l2 rx)");
341 static void wpa_priv_cmd_l2_register(struct wpa_priv_interface
*iface
,
342 struct sockaddr_un
*from
,
343 void *buf
, size_t len
)
346 u8 own_addr
[ETH_ALEN
];
350 if (len
!= 2 * sizeof(int)) {
351 wpa_printf(MSG_DEBUG
, "Invalid l2_register length %lu",
352 (unsigned long) len
);
357 if (proto
!= ETH_P_EAPOL
&& proto
!= ETH_P_RSN_PREAUTH
) {
358 wpa_printf(MSG_DEBUG
, "Refused l2_packet connection for "
359 "ethertype 0x%x", proto
);
364 wpa_printf(MSG_DEBUG
, "Cleaning up forgotten l2_packet "
366 l2_packet_deinit(iface
->l2
);
370 os_memcpy(&iface
->l2_addr
, from
, sizeof(iface
->l2_addr
));
372 iface
->l2
= l2_packet_init(iface
->ifname
, NULL
, proto
,
373 wpa_priv_l2_rx
, iface
, reg_cmd
[1]);
374 if (iface
->l2
== NULL
) {
375 wpa_printf(MSG_DEBUG
, "Failed to initialize l2_packet "
376 "instance for protocol %d", proto
);
380 if (l2_packet_get_own_addr(iface
->l2
, own_addr
) < 0) {
381 wpa_printf(MSG_DEBUG
, "Failed to get own address from "
383 l2_packet_deinit(iface
->l2
);
388 res
= sendto(iface
->fd
, own_addr
, ETH_ALEN
, 0,
389 (struct sockaddr
*) from
, sizeof(*from
));
390 wpa_printf(MSG_DEBUG
, "L2 registration: res=%d", res
);
394 static void wpa_priv_cmd_l2_unregister(struct wpa_priv_interface
*iface
,
395 struct sockaddr_un
*from
)
398 l2_packet_deinit(iface
->l2
);
404 static void wpa_priv_cmd_l2_notify_auth_start(struct wpa_priv_interface
*iface
,
405 struct sockaddr_un
*from
)
408 l2_packet_notify_auth_start(iface
->l2
);
412 static void wpa_priv_cmd_l2_send(struct wpa_priv_interface
*iface
,
413 struct sockaddr_un
*from
,
414 void *buf
, size_t len
)
420 if (iface
->l2
== NULL
)
423 if (len
< ETH_ALEN
+ 2) {
424 wpa_printf(MSG_DEBUG
, "Too short L2 send packet (len=%lu)",
425 (unsigned long) len
);
430 os_memcpy(&proto
, buf
+ ETH_ALEN
, 2);
432 if (proto
!= ETH_P_EAPOL
&& proto
!= ETH_P_RSN_PREAUTH
) {
433 wpa_printf(MSG_DEBUG
, "Refused l2_packet send for ethertype "
438 res
= l2_packet_send(iface
->l2
, dst_addr
, proto
, buf
+ ETH_ALEN
+ 2,
440 wpa_printf(MSG_DEBUG
, "L2 send: res=%d", res
);
444 static void wpa_priv_cmd_set_country(struct wpa_priv_interface
*iface
,
447 if (iface
->drv_priv
== NULL
|| iface
->driver
->set_country
== NULL
||
451 iface
->driver
->set_country(iface
->drv_priv
, buf
);
455 static void wpa_priv_receive(int sock
, void *eloop_ctx
, void *sock_ctx
)
457 struct wpa_priv_interface
*iface
= eloop_ctx
;
458 char buf
[2000], *pos
;
462 struct sockaddr_un from
;
463 socklen_t fromlen
= sizeof(from
);
465 res
= recvfrom(sock
, buf
, sizeof(buf
), 0, (struct sockaddr
*) &from
,
472 if (res
< (int) sizeof(int)) {
473 wpa_printf(MSG_DEBUG
, "Too short command (len=%d)", res
);
477 os_memcpy(&cmd
, buf
, sizeof(int));
478 wpa_printf(MSG_DEBUG
, "Command %d for interface %s",
480 cmd_buf
= &buf
[sizeof(int)];
481 cmd_len
= res
- sizeof(int);
484 case PRIVSEP_CMD_REGISTER
:
485 wpa_priv_cmd_register(iface
, &from
);
487 case PRIVSEP_CMD_UNREGISTER
:
488 wpa_priv_cmd_unregister(iface
, &from
);
490 case PRIVSEP_CMD_SCAN
:
491 wpa_priv_cmd_scan(iface
, cmd_buf
, cmd_len
);
493 case PRIVSEP_CMD_GET_SCAN_RESULTS
:
494 wpa_priv_cmd_get_scan_results(iface
, &from
);
496 case PRIVSEP_CMD_ASSOCIATE
:
497 wpa_priv_cmd_associate(iface
, cmd_buf
, cmd_len
);
499 case PRIVSEP_CMD_GET_BSSID
:
500 wpa_priv_cmd_get_bssid(iface
, &from
);
502 case PRIVSEP_CMD_GET_SSID
:
503 wpa_priv_cmd_get_ssid(iface
, &from
);
505 case PRIVSEP_CMD_SET_KEY
:
506 wpa_priv_cmd_set_key(iface
, cmd_buf
, cmd_len
);
508 case PRIVSEP_CMD_GET_CAPA
:
509 wpa_priv_cmd_get_capa(iface
, &from
);
511 case PRIVSEP_CMD_L2_REGISTER
:
512 wpa_priv_cmd_l2_register(iface
, &from
, cmd_buf
, cmd_len
);
514 case PRIVSEP_CMD_L2_UNREGISTER
:
515 wpa_priv_cmd_l2_unregister(iface
, &from
);
517 case PRIVSEP_CMD_L2_NOTIFY_AUTH_START
:
518 wpa_priv_cmd_l2_notify_auth_start(iface
, &from
);
520 case PRIVSEP_CMD_L2_SEND
:
521 wpa_priv_cmd_l2_send(iface
, &from
, cmd_buf
, cmd_len
);
523 case PRIVSEP_CMD_SET_COUNTRY
:
525 if (pos
+ cmd_len
>= buf
+ sizeof(buf
))
528 wpa_priv_cmd_set_country(iface
, pos
);
534 static void wpa_priv_interface_deinit(struct wpa_priv_interface
*iface
)
536 if (iface
->drv_priv
&& iface
->driver
->deinit
)
537 iface
->driver
->deinit(iface
->drv_priv
);
539 if (iface
->fd
>= 0) {
540 eloop_unregister_read_sock(iface
->fd
);
542 unlink(iface
->sock_name
);
546 l2_packet_deinit(iface
->l2
);
548 os_free(iface
->ifname
);
549 os_free(iface
->driver_name
);
550 os_free(iface
->sock_name
);
555 static struct wpa_priv_interface
*
556 wpa_priv_interface_init(const char *dir
, const char *params
)
558 struct wpa_priv_interface
*iface
;
561 struct sockaddr_un addr
;
564 pos
= os_strchr(params
, ':');
568 iface
= os_zalloc(sizeof(*iface
));
574 iface
->driver_name
= dup_binstr(params
, len
);
575 if (iface
->driver_name
== NULL
) {
576 wpa_priv_interface_deinit(iface
);
580 for (i
= 0; wpa_drivers
[i
]; i
++) {
581 if (os_strcmp(iface
->driver_name
,
582 wpa_drivers
[i
]->name
) == 0) {
583 iface
->driver
= wpa_drivers
[i
];
587 if (iface
->driver
== NULL
) {
588 wpa_printf(MSG_ERROR
, "Unsupported driver '%s'",
590 wpa_priv_interface_deinit(iface
);
595 iface
->ifname
= os_strdup(pos
);
596 if (iface
->ifname
== NULL
) {
597 wpa_priv_interface_deinit(iface
);
601 len
= os_strlen(dir
) + 1 + os_strlen(iface
->ifname
);
602 iface
->sock_name
= os_malloc(len
+ 1);
603 if (iface
->sock_name
== NULL
) {
604 wpa_priv_interface_deinit(iface
);
608 os_snprintf(iface
->sock_name
, len
+ 1, "%s/%s", dir
, iface
->ifname
);
609 if (os_strlen(iface
->sock_name
) >= sizeof(addr
.sun_path
)) {
610 wpa_priv_interface_deinit(iface
);
614 iface
->fd
= socket(PF_UNIX
, SOCK_DGRAM
, 0);
616 perror("socket(PF_UNIX)");
617 wpa_priv_interface_deinit(iface
);
621 os_memset(&addr
, 0, sizeof(addr
));
622 addr
.sun_family
= AF_UNIX
;
623 os_strlcpy(addr
.sun_path
, iface
->sock_name
, sizeof(addr
.sun_path
));
625 if (bind(iface
->fd
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
626 wpa_printf(MSG_DEBUG
, "bind(PF_UNIX) failed: %s",
628 if (connect(iface
->fd
, (struct sockaddr
*) &addr
,
630 wpa_printf(MSG_DEBUG
, "Socket exists, but does not "
631 "allow connections - assuming it was "
632 "leftover from forced program termination");
633 if (unlink(iface
->sock_name
) < 0) {
634 perror("unlink[ctrl_iface]");
635 wpa_printf(MSG_ERROR
, "Could not unlink "
636 "existing ctrl_iface socket '%s'",
640 if (bind(iface
->fd
, (struct sockaddr
*) &addr
,
642 perror("wpa-priv-iface-init: bind(PF_UNIX)");
645 wpa_printf(MSG_DEBUG
, "Successfully replaced leftover "
646 "socket '%s'", iface
->sock_name
);
648 wpa_printf(MSG_INFO
, "Socket exists and seems to be "
649 "in use - cannot override it");
650 wpa_printf(MSG_INFO
, "Delete '%s' manually if it is "
651 "not used anymore", iface
->sock_name
);
656 if (chmod(iface
->sock_name
, S_IRWXU
| S_IRWXG
| S_IRWXO
) < 0) {
661 eloop_register_read_sock(iface
->fd
, wpa_priv_receive
, iface
, NULL
);
666 wpa_priv_interface_deinit(iface
);
671 static int wpa_priv_send_event(struct wpa_priv_interface
*iface
, int event
,
672 const void *data
, size_t data_len
)
677 io
[0].iov_base
= &event
;
678 io
[0].iov_len
= sizeof(event
);
679 io
[1].iov_base
= (u8
*) data
;
680 io
[1].iov_len
= data_len
;
682 os_memset(&msg
, 0, sizeof(msg
));
684 msg
.msg_iovlen
= data
? 2 : 1;
685 msg
.msg_name
= &iface
->drv_addr
;
686 msg
.msg_namelen
= sizeof(iface
->drv_addr
);
688 if (sendmsg(iface
->fd
, &msg
, 0) < 0) {
689 perror("sendmsg(wpas_socket)");
697 static void wpa_priv_send_assoc(struct wpa_priv_interface
*iface
, int event
,
698 union wpa_event_data
*data
)
700 size_t buflen
= 3 * sizeof(int);
705 buflen
+= data
->assoc_info
.req_ies_len
+
706 data
->assoc_info
.resp_ies_len
+
707 data
->assoc_info
.beacon_ies_len
;
710 buf
= os_malloc(buflen
);
716 if (data
&& data
->assoc_info
.req_ies
) {
717 len
= data
->assoc_info
.req_ies_len
;
718 os_memcpy(pos
, &len
, sizeof(int));
720 os_memcpy(pos
, data
->assoc_info
.req_ies
, len
);
724 os_memcpy(pos
, &len
, sizeof(int));
728 if (data
&& data
->assoc_info
.resp_ies
) {
729 len
= data
->assoc_info
.resp_ies_len
;
730 os_memcpy(pos
, &len
, sizeof(int));
732 os_memcpy(pos
, data
->assoc_info
.resp_ies
, len
);
736 os_memcpy(pos
, &len
, sizeof(int));
740 if (data
&& data
->assoc_info
.beacon_ies
) {
741 len
= data
->assoc_info
.beacon_ies_len
;
742 os_memcpy(pos
, &len
, sizeof(int));
744 os_memcpy(pos
, data
->assoc_info
.beacon_ies
, len
);
748 os_memcpy(pos
, &len
, sizeof(int));
752 wpa_priv_send_event(iface
, event
, buf
, buflen
);
758 static void wpa_priv_send_interface_status(struct wpa_priv_interface
*iface
,
759 union wpa_event_data
*data
)
769 ievent
= data
->interface_status
.ievent
;
770 maxlen
= sizeof(data
->interface_status
.ifname
);
771 ifname
= data
->interface_status
.ifname
;
772 for (len
= 0; len
< maxlen
&& ifname
[len
]; len
++)
775 buf
= os_malloc(sizeof(int) + len
);
779 os_memcpy(buf
, &ievent
, sizeof(int));
780 os_memcpy(buf
+ sizeof(int), ifname
, len
);
782 wpa_priv_send_event(iface
, PRIVSEP_EVENT_INTERFACE_STATUS
,
783 buf
, sizeof(int) + len
);
790 static void wpa_priv_send_ft_response(struct wpa_priv_interface
*iface
,
791 union wpa_event_data
*data
)
796 if (data
== NULL
|| data
->ft_ies
.ies
== NULL
)
799 len
= sizeof(int) + ETH_ALEN
+ data
->ft_ies
.ies_len
;
800 buf
= os_malloc(len
);
805 os_memcpy(pos
, &data
->ft_ies
.ft_action
, sizeof(int));
807 os_memcpy(pos
, data
->ft_ies
.target_ap
, ETH_ALEN
);
809 os_memcpy(pos
, data
->ft_ies
.ies
, data
->ft_ies
.ies_len
);
811 wpa_priv_send_event(iface
, PRIVSEP_EVENT_FT_RESPONSE
, buf
, len
);
818 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
819 union wpa_event_data
*data
)
821 struct wpa_priv_interface
*iface
= ctx
;
823 wpa_printf(MSG_DEBUG
, "%s - event=%d", __func__
, event
);
825 if (!iface
->wpas_registered
) {
826 wpa_printf(MSG_DEBUG
, "Driver event received, but "
827 "wpa_supplicant not registered");
833 wpa_priv_send_assoc(iface
, PRIVSEP_EVENT_ASSOC
, data
);
836 wpa_priv_send_event(iface
, PRIVSEP_EVENT_DISASSOC
, NULL
, 0);
838 case EVENT_ASSOCINFO
:
841 wpa_priv_send_assoc(iface
, PRIVSEP_EVENT_ASSOCINFO
, data
);
843 case EVENT_MICHAEL_MIC_FAILURE
:
846 wpa_priv_send_event(iface
, PRIVSEP_EVENT_MICHAEL_MIC_FAILURE
,
847 &data
->michael_mic_failure
.unicast
,
850 case EVENT_SCAN_RESULTS
:
851 wpa_priv_send_event(iface
, PRIVSEP_EVENT_SCAN_RESULTS
, NULL
,
854 case EVENT_INTERFACE_STATUS
:
855 wpa_priv_send_interface_status(iface
, data
);
857 case EVENT_PMKID_CANDIDATE
:
860 wpa_priv_send_event(iface
, PRIVSEP_EVENT_PMKID_CANDIDATE
,
861 &data
->pmkid_candidate
,
862 sizeof(struct pmkid_candidate
));
867 wpa_priv_send_event(iface
, PRIVSEP_EVENT_STKSTART
,
868 &data
->stkstart
.peer
, ETH_ALEN
);
870 case EVENT_FT_RESPONSE
:
871 wpa_priv_send_ft_response(iface
, data
);
874 wpa_printf(MSG_DEBUG
, "Unsupported driver event %d - TODO",
881 void wpa_supplicant_rx_eapol(void *ctx
, const u8
*src_addr
,
882 const u8
*buf
, size_t len
)
884 struct wpa_priv_interface
*iface
= ctx
;
887 int event
= PRIVSEP_EVENT_RX_EAPOL
;
889 wpa_printf(MSG_DEBUG
, "RX EAPOL from driver");
890 io
[0].iov_base
= &event
;
891 io
[0].iov_len
= sizeof(event
);
892 io
[1].iov_base
= (u8
*) src_addr
;
893 io
[1].iov_len
= ETH_ALEN
;
894 io
[2].iov_base
= (u8
*) buf
;
897 os_memset(&msg
, 0, sizeof(msg
));
900 msg
.msg_name
= &iface
->drv_addr
;
901 msg
.msg_namelen
= sizeof(iface
->drv_addr
);
903 if (sendmsg(iface
->fd
, &msg
, 0) < 0)
904 perror("sendmsg(wpas_socket)");
908 static void wpa_priv_terminate(int sig
, void *signal_ctx
)
910 wpa_printf(MSG_DEBUG
, "wpa_priv termination requested");
915 static void wpa_priv_fd_workaround(void)
919 /* When started from pcmcia-cs scripts, wpa_supplicant might start with
920 * fd 0, 1, and 2 closed. This will cause some issues because many
921 * places in wpa_supplicant are still printing out to stdout. As a
922 * workaround, make sure that fd's 0, 1, and 2 are not used for other
924 for (i
= 0; i
< 3; i
++) {
925 s
= open("/dev/null", O_RDWR
);
931 #endif /* __linux__ */
935 static void usage(void)
937 printf("wpa_priv v" VERSION_STR
"\n"
938 "Copyright (c) 2007-2009, Jouni Malinen <j@w1.fi> and "
942 " wpa_priv [-Bdd] [-P<pid file>] <driver:ifname> "
943 "[driver:ifname ...]\n");
947 int main(int argc
, char *argv
[])
951 char *pid_file
= NULL
;
953 char *ctrl_dir
= "/var/run/wpa_priv";
954 struct wpa_priv_interface
*interfaces
= NULL
, *iface
;
956 if (os_program_init())
959 wpa_priv_fd_workaround();
962 c
= getopt(argc
, argv
, "Bc:dP:");
976 pid_file
= os_rel2abs_path(optarg
);
984 if (optind
>= argc
) {
989 wpa_printf(MSG_DEBUG
, "wpa_priv control directory: '%s'", ctrl_dir
);
992 wpa_printf(MSG_ERROR
, "Failed to initialize event loop");
996 for (i
= optind
; i
< argc
; i
++) {
997 wpa_printf(MSG_DEBUG
, "Adding driver:interface %s", argv
[i
]);
998 iface
= wpa_priv_interface_init(ctrl_dir
, argv
[i
]);
1001 iface
->next
= interfaces
;
1005 if (daemonize
&& os_daemonize(pid_file
))
1008 eloop_register_signal_terminate(wpa_priv_terminate
, NULL
);
1016 struct wpa_priv_interface
*prev
= iface
;
1017 iface
= iface
->next
;
1018 wpa_priv_interface_deinit(prev
);
1023 os_daemonize_terminate(pid_file
);
1025 os_program_deinit();