| @@ -1,1804 +1,1803 @@ | | | @@ -1,1804 +1,1803 @@ |
1 | /* | | 1 | /* |
2 | * WPA Supplicant - driver interaction with BSD net80211 layer | | 2 | * WPA Supplicant - driver interaction with BSD net80211 layer |
3 | * Copyright (c) 2004, Sam Leffler <sam@errno.com> | | 3 | * Copyright (c) 2004, Sam Leffler <sam@errno.com> |
4 | * Copyright (c) 2004, 2Wire, Inc | | 4 | * Copyright (c) 2004, 2Wire, Inc |
5 | * | | 5 | * |
6 | * This software may be distributed under the terms of the BSD license. | | 6 | * This software may be distributed under the terms of the BSD license. |
7 | * See README for more details. | | 7 | * See README for more details. |
8 | */ | | 8 | */ |
9 | | | 9 | |
10 | #include "includes.h" | | 10 | #include "includes.h" |
11 | #include <sys/ioctl.h> | | 11 | #include <sys/ioctl.h> |
12 | #include <sys/param.h> | | 12 | #include <sys/param.h> |
13 | | | 13 | |
14 | #include "common.h" | | 14 | #include "common.h" |
15 | #include "driver.h" | | 15 | #include "driver.h" |
16 | #include "eloop.h" | | 16 | #include "eloop.h" |
17 | | | 17 | |
18 | #include <net/if.h> | | 18 | #include <net/if.h> |
19 | #include <net/if_media.h> | | 19 | #include <net/if_media.h> |
20 | | | 20 | |
21 | #ifdef __NetBSD__ | | 21 | #ifdef __NetBSD__ |
22 | #include <net/if_ether.h> | | 22 | #include <net/if_ether.h> |
23 | #else | | 23 | #else |
24 | #include <net/ethernet.h> | | 24 | #include <net/ethernet.h> |
25 | #endif | | 25 | #endif |
26 | #include <net/route.h> | | 26 | #include <net/route.h> |
27 | | | 27 | |
28 | #ifdef __DragonFly__ | | 28 | #ifdef __DragonFly__ |
29 | #include <netproto/802_11/ieee80211_ioctl.h> | | 29 | #include <netproto/802_11/ieee80211_ioctl.h> |
30 | #include <netproto/802_11/ieee80211_dragonfly.h> | | 30 | #include <netproto/802_11/ieee80211_dragonfly.h> |
31 | #else /* __DragonFly__ */ | | 31 | #else /* __DragonFly__ */ |
32 | #ifdef __GLIBC__ | | 32 | #ifdef __GLIBC__ |
33 | #include <netinet/ether.h> | | 33 | #include <netinet/ether.h> |
34 | #endif /* __GLIBC__ */ | | 34 | #endif /* __GLIBC__ */ |
35 | #include <net80211/ieee80211.h> | | 35 | #include <net80211/ieee80211.h> |
36 | #include <net80211/ieee80211_ioctl.h> | | 36 | #include <net80211/ieee80211_ioctl.h> |
37 | #include <net80211/ieee80211_crypto.h> | | 37 | #include <net80211/ieee80211_crypto.h> |
38 | #endif /* __DragonFly__ || __GLIBC__ */ | | 38 | #endif /* __DragonFly__ || __GLIBC__ */ |
39 | #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) | | 39 | #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) |
40 | #include <net80211/ieee80211_freebsd.h> | | 40 | #include <net80211/ieee80211_freebsd.h> |
41 | #endif | | 41 | #endif |
42 | #if __NetBSD__ | | 42 | #if __NetBSD__ |
43 | #include <net80211/ieee80211_netbsd.h> | | 43 | #include <net80211/ieee80211_netbsd.h> |
44 | #endif | | 44 | #endif |
45 | | | 45 | |
46 | #include "common/ieee802_11_defs.h" | | 46 | #include "common/ieee802_11_defs.h" |
47 | #include "common/wpa_common.h" | | 47 | #include "common/wpa_common.h" |
48 | #include "l2_packet/l2_packet.h" | | 48 | #include "l2_packet/l2_packet.h" |
49 | | | 49 | |
50 | struct bsd_driver_global { | | 50 | struct bsd_driver_global { |
51 | void *ctx; | | 51 | void *ctx; |
52 | int sock; /* socket for 802.11 ioctls */ | | 52 | int sock; /* socket for 802.11 ioctls */ |
53 | int route; /* routing socket for events */ | | 53 | int route; /* routing socket for events */ |
54 | struct iovec event_iov[1]; | | 54 | struct iovec event_iov[1]; |
55 | struct dl_list ifaces; /* list of interfaces */ | | 55 | struct dl_list ifaces; /* list of interfaces */ |
56 | }; | | 56 | }; |
57 | | | 57 | |
58 | struct bsd_driver_data { | | 58 | struct bsd_driver_data { |
59 | struct dl_list list; | | 59 | struct dl_list list; |
60 | struct bsd_driver_global *global; | | 60 | struct bsd_driver_global *global; |
61 | struct hostapd_data *hapd; /* back pointer */ | | 61 | void *ctx; |
62 | | | 62 | |
63 | struct l2_packet_data *sock_xmit;/* raw packet xmit socket */ | | 63 | struct l2_packet_data *sock_xmit;/* raw packet xmit socket */ |
64 | char ifname[IFNAMSIZ+1]; /* interface name */ | | 64 | char ifname[IFNAMSIZ+1]; /* interface name */ |
65 | int flags; | | 65 | int flags; |
66 | unsigned int ifindex; /* interface index */ | | 66 | unsigned int ifindex; /* interface index */ |
67 | int if_removed; /* has the interface been removed? */ | | 67 | int if_removed; /* has the interface been removed? */ |
68 | void *ctx; | | | |
69 | struct wpa_driver_capa capa; /* driver capability */ | | 68 | struct wpa_driver_capa capa; /* driver capability */ |
70 | int is_ap; /* Access point mode */ | | 69 | int is_ap; /* Access point mode */ |
71 | int prev_roaming; /* roaming state to restore on deinit */ | | 70 | int prev_roaming; /* roaming state to restore on deinit */ |
72 | int prev_privacy; /* privacy state to restore on deinit */ | | 71 | int prev_privacy; /* privacy state to restore on deinit */ |
73 | int prev_wpa; /* wpa state to restore on deinit */ | | 72 | int prev_wpa; /* wpa state to restore on deinit */ |
74 | enum ieee80211_opmode opmode; /* operation mode */ | | 73 | enum ieee80211_opmode opmode; /* operation mode */ |
75 | }; | | 74 | }; |
76 | | | 75 | |
77 | /* Generic functions for hostapd and wpa_supplicant */ | | 76 | /* Generic functions for hostapd and wpa_supplicant */ |
78 | | | 77 | |
79 | #define IOVEC_BUFSIZ 256 | | 78 | #define IOVEC_BUFSIZ 256 |
80 | ssize_t | | 79 | ssize_t |
81 | recvmsg_realloc(int fd, struct msghdr *msg, int flags) | | 80 | recvmsg_realloc(int fd, struct msghdr *msg, int flags) |
82 | { | | 81 | { |
83 | struct iovec *iov; | | 82 | struct iovec *iov; |
84 | ssize_t slen; | | 83 | ssize_t slen; |
85 | size_t len; | | 84 | size_t len; |
86 | void *n; | | 85 | void *n; |
87 | | | 86 | |
88 | /* Assume we are reallocing the last iovec. */ | | 87 | /* Assume we are reallocing the last iovec. */ |
89 | iov = &msg->msg_iov[msg->msg_iovlen - 1]; | | 88 | iov = &msg->msg_iov[msg->msg_iovlen - 1]; |
90 | | | 89 | |
91 | for (;;) { | | 90 | for (;;) { |
92 | /* Passing MSG_TRUNC should return the actual size needed. */ | | 91 | /* Passing MSG_TRUNC should return the actual size needed. */ |
93 | slen = recvmsg(fd, msg, flags | MSG_PEEK | MSG_TRUNC); | | 92 | slen = recvmsg(fd, msg, flags | MSG_PEEK | MSG_TRUNC); |
94 | if (slen == -1) | | 93 | if (slen == -1) |
95 | return -1; | | 94 | return -1; |
96 | if (!(msg->msg_flags & MSG_TRUNC)) | | 95 | if (!(msg->msg_flags & MSG_TRUNC)) |
97 | break; | | 96 | break; |
98 | | | 97 | |
99 | len = (size_t)slen; | | 98 | len = (size_t)slen; |
100 | | | 99 | |
101 | /* Some kernels return the size of the receive buffer | | 100 | /* Some kernels return the size of the receive buffer |
102 | * on truncation, not the actual size needed. | | 101 | * on truncation, not the actual size needed. |
103 | * So grow the buffer and try again. */ | | 102 | * So grow the buffer and try again. */ |
104 | if (iov->iov_len == len) | | 103 | if (iov->iov_len == len) |
105 | len = roundup(len + 1, IOVEC_BUFSIZ); | | 104 | len = roundup(len + 1, IOVEC_BUFSIZ); |
106 | else if (iov->iov_len > len) | | 105 | else if (iov->iov_len > len) |
107 | break; | | 106 | break; |
108 | if ((n = realloc(iov->iov_base, len)) == NULL) | | 107 | if ((n = realloc(iov->iov_base, len)) == NULL) |
109 | return -1; | | 108 | return -1; |
110 | iov->iov_base = n; | | 109 | iov->iov_base = n; |
111 | iov->iov_len = len; | | 110 | iov->iov_len = len; |
112 | } | | 111 | } |
113 | | | 112 | |
114 | slen = recvmsg(fd, msg, flags); | | 113 | slen = recvmsg(fd, msg, flags); |
115 | if (slen != -1 && msg->msg_flags & MSG_TRUNC) { | | 114 | if (slen != -1 && msg->msg_flags & MSG_TRUNC) { |
116 | /* This should not be possible ... */ | | 115 | /* This should not be possible ... */ |
117 | errno = ENOBUFS; | | 116 | errno = ENOBUFS; |
118 | return -1; | | 117 | return -1; |
119 | } | | 118 | } |
120 | return slen; | | 119 | return slen; |
121 | } | | 120 | } |
122 | | | 121 | |
123 | static struct bsd_driver_data * | | 122 | static struct bsd_driver_data * |
124 | bsd_get_drvindex(void *priv, unsigned int ifindex) | | 123 | bsd_get_drvindex(void *priv, unsigned int ifindex) |
125 | { | | 124 | { |
126 | struct bsd_driver_global *global = priv; | | 125 | struct bsd_driver_global *global = priv; |
127 | struct bsd_driver_data *drv; | | 126 | struct bsd_driver_data *drv; |
128 | | | 127 | |
129 | dl_list_for_each(drv, &global->ifaces, struct bsd_driver_data, list) { | | 128 | dl_list_for_each(drv, &global->ifaces, struct bsd_driver_data, list) { |
130 | if (drv->ifindex == ifindex) | | 129 | if (drv->ifindex == ifindex) |
131 | return drv; | | 130 | return drv; |
132 | } | | 131 | } |
133 | return NULL; | | 132 | return NULL; |
134 | } | | 133 | } |
135 | | | 134 | |
136 | #ifndef HOSTAPD | | 135 | #ifndef HOSTAPD |
137 | static struct bsd_driver_data * | | 136 | static struct bsd_driver_data * |
138 | bsd_get_drvname(void *priv, const char *ifname) | | 137 | bsd_get_drvname(void *priv, const char *ifname) |
139 | { | | 138 | { |
140 | struct bsd_driver_global *global = priv; | | 139 | struct bsd_driver_global *global = priv; |
141 | struct bsd_driver_data *drv; | | 140 | struct bsd_driver_data *drv; |
142 | | | 141 | |
143 | dl_list_for_each(drv, &global->ifaces, struct bsd_driver_data, list) { | | 142 | dl_list_for_each(drv, &global->ifaces, struct bsd_driver_data, list) { |
144 | if (os_strcmp(drv->ifname, ifname) == 0) | | 143 | if (os_strcmp(drv->ifname, ifname) == 0) |
145 | return drv; | | 144 | return drv; |
146 | } | | 145 | } |
147 | return NULL; | | 146 | return NULL; |
148 | } | | 147 | } |
149 | #endif /* HOSTAPD */ | | 148 | #endif /* HOSTAPD */ |
150 | | | 149 | |
151 | static int | | 150 | static int |
152 | bsd_set80211(void *priv, int op, int val, const void *arg, int arg_len) | | 151 | bsd_set80211(void *priv, int op, int val, const void *arg, int arg_len) |
153 | { | | 152 | { |
154 | struct bsd_driver_data *drv = priv; | | 153 | struct bsd_driver_data *drv = priv; |
155 | struct ieee80211req ireq; | | 154 | struct ieee80211req ireq; |
156 | | | 155 | |
157 | if (drv->ifindex == 0 || drv->if_removed) | | 156 | if (drv->ifindex == 0 || drv->if_removed) |
158 | return -1; | | 157 | return -1; |
159 | | | 158 | |
160 | os_memset(&ireq, 0, sizeof(ireq)); | | 159 | os_memset(&ireq, 0, sizeof(ireq)); |
161 | os_strlcpy(ireq.i_name, drv->ifname, sizeof(ireq.i_name)); | | 160 | os_strlcpy(ireq.i_name, drv->ifname, sizeof(ireq.i_name)); |
162 | ireq.i_type = op; | | 161 | ireq.i_type = op; |
163 | ireq.i_val = val; | | 162 | ireq.i_val = val; |
164 | ireq.i_data = (void *) arg; | | 163 | ireq.i_data = (void *) arg; |
165 | ireq.i_len = arg_len; | | 164 | ireq.i_len = arg_len; |
166 | | | 165 | |
167 | if (ioctl(drv->global->sock, SIOCS80211, &ireq) < 0) { | | 166 | if (ioctl(drv->global->sock, SIOCS80211, &ireq) < 0) { |
168 | wpa_printf(MSG_ERROR, "ioctl[SIOCS80211, op=%u, val=%u, " | | 167 | wpa_printf(MSG_ERROR, "ioctl[SIOCS80211, op=%u, val=%u, " |
169 | "arg_len=%u]: %s", op, val, arg_len, | | 168 | "arg_len=%u]: %s", op, val, arg_len, |
170 | strerror(errno)); | | 169 | strerror(errno)); |
171 | return -1; | | 170 | return -1; |
172 | } | | 171 | } |
173 | return 0; | | 172 | return 0; |
174 | } | | 173 | } |
175 | | | 174 | |
176 | static int | | 175 | static int |
177 | bsd_get80211(void *priv, struct ieee80211req *ireq, int op, void *arg, | | 176 | bsd_get80211(void *priv, struct ieee80211req *ireq, int op, void *arg, |
178 | int arg_len) | | 177 | int arg_len) |
179 | { | | 178 | { |
180 | struct bsd_driver_data *drv = priv; | | 179 | struct bsd_driver_data *drv = priv; |
181 | | | 180 | |
182 | os_memset(ireq, 0, sizeof(*ireq)); | | 181 | os_memset(ireq, 0, sizeof(*ireq)); |
183 | os_strlcpy(ireq->i_name, drv->ifname, sizeof(ireq->i_name)); | | 182 | os_strlcpy(ireq->i_name, drv->ifname, sizeof(ireq->i_name)); |
184 | ireq->i_type = op; | | 183 | ireq->i_type = op; |
185 | ireq->i_len = arg_len; | | 184 | ireq->i_len = arg_len; |
186 | ireq->i_data = arg; | | 185 | ireq->i_data = arg; |
187 | | | 186 | |
188 | if (ioctl(drv->global->sock, SIOCG80211, ireq) < 0) { | | 187 | if (ioctl(drv->global->sock, SIOCG80211, ireq) < 0) { |
189 | wpa_printf(MSG_ERROR, "ioctl[SIOCS80211, op=%u, " | | 188 | wpa_printf(MSG_ERROR, "ioctl[SIOCS80211, op=%u, " |
190 | "arg_len=%u]: %s", op, arg_len, strerror(errno)); | | 189 | "arg_len=%u]: %s", op, arg_len, strerror(errno)); |
191 | return -1; | | 190 | return -1; |
192 | } | | 191 | } |
193 | return 0; | | 192 | return 0; |
194 | } | | 193 | } |
195 | | | 194 | |
196 | static int | | 195 | static int |
197 | get80211var(struct bsd_driver_data *drv, int op, void *arg, int arg_len) | | 196 | get80211var(struct bsd_driver_data *drv, int op, void *arg, int arg_len) |
198 | { | | 197 | { |
199 | struct ieee80211req ireq; | | 198 | struct ieee80211req ireq; |
200 | | | 199 | |
201 | if (bsd_get80211(drv, &ireq, op, arg, arg_len) < 0) | | 200 | if (bsd_get80211(drv, &ireq, op, arg, arg_len) < 0) |
202 | return -1; | | 201 | return -1; |
203 | return ireq.i_len; | | 202 | return ireq.i_len; |
204 | } | | 203 | } |
205 | | | 204 | |
206 | static int | | 205 | static int |
207 | set80211var(struct bsd_driver_data *drv, int op, const void *arg, int arg_len) | | 206 | set80211var(struct bsd_driver_data *drv, int op, const void *arg, int arg_len) |
208 | { | | 207 | { |
209 | return bsd_set80211(drv, op, 0, arg, arg_len); | | 208 | return bsd_set80211(drv, op, 0, arg, arg_len); |
210 | } | | 209 | } |
211 | | | 210 | |
212 | static int | | 211 | static int |
213 | set80211param(struct bsd_driver_data *drv, int op, int arg) | | 212 | set80211param(struct bsd_driver_data *drv, int op, int arg) |
214 | { | | 213 | { |
215 | return bsd_set80211(drv, op, arg, NULL, 0); | | 214 | return bsd_set80211(drv, op, arg, NULL, 0); |
216 | } | | 215 | } |
217 | | | 216 | |
218 | static int | | 217 | static int |
219 | bsd_get_ssid(void *priv, u8 *ssid, int len) | | 218 | bsd_get_ssid(void *priv, u8 *ssid, int len) |
220 | { | | 219 | { |
221 | struct bsd_driver_data *drv = priv; | | 220 | struct bsd_driver_data *drv = priv; |
222 | #ifdef SIOCG80211NWID | | 221 | #ifdef SIOCG80211NWID |
223 | struct ieee80211_nwid nwid; | | 222 | struct ieee80211_nwid nwid; |
224 | struct ifreq ifr; | | 223 | struct ifreq ifr; |
225 | | | 224 | |
226 | os_memset(&ifr, 0, sizeof(ifr)); | | 225 | os_memset(&ifr, 0, sizeof(ifr)); |
227 | os_strlcpy(ifr.ifr_name, drv->ifname, sizeof(ifr.ifr_name)); | | 226 | os_strlcpy(ifr.ifr_name, drv->ifname, sizeof(ifr.ifr_name)); |
228 | ifr.ifr_data = (void *)&nwid; | | 227 | ifr.ifr_data = (void *)&nwid; |
229 | if (ioctl(drv->global->sock, SIOCG80211NWID, &ifr) < 0 || | | 228 | if (ioctl(drv->global->sock, SIOCG80211NWID, &ifr) < 0 || |
230 | nwid.i_len > IEEE80211_NWID_LEN) | | 229 | nwid.i_len > IEEE80211_NWID_LEN) |
231 | return -1; | | 230 | return -1; |
232 | os_memcpy(ssid, nwid.i_nwid, nwid.i_len); | | 231 | os_memcpy(ssid, nwid.i_nwid, nwid.i_len); |
233 | return nwid.i_len; | | 232 | return nwid.i_len; |
234 | #else | | 233 | #else |
235 | return get80211var(drv, IEEE80211_IOC_SSID, ssid, IEEE80211_NWID_LEN); | | 234 | return get80211var(drv, IEEE80211_IOC_SSID, ssid, IEEE80211_NWID_LEN); |
236 | #endif | | 235 | #endif |
237 | } | | 236 | } |
238 | | | 237 | |
239 | static int | | 238 | static int |
240 | bsd_set_ssid(void *priv, const u8 *ssid, int ssid_len) | | 239 | bsd_set_ssid(void *priv, const u8 *ssid, int ssid_len) |
241 | { | | 240 | { |
242 | struct bsd_driver_data *drv = priv; | | 241 | struct bsd_driver_data *drv = priv; |
243 | #ifdef SIOCS80211NWID | | 242 | #ifdef SIOCS80211NWID |
244 | struct ieee80211_nwid nwid; | | 243 | struct ieee80211_nwid nwid; |
245 | struct ifreq ifr; | | 244 | struct ifreq ifr; |
246 | | | 245 | |
247 | os_memcpy(nwid.i_nwid, ssid, ssid_len); | | 246 | os_memcpy(nwid.i_nwid, ssid, ssid_len); |
248 | nwid.i_len = ssid_len; | | 247 | nwid.i_len = ssid_len; |
249 | os_memset(&ifr, 0, sizeof(ifr)); | | 248 | os_memset(&ifr, 0, sizeof(ifr)); |
250 | os_strlcpy(ifr.ifr_name, drv->ifname, sizeof(ifr.ifr_name)); | | 249 | os_strlcpy(ifr.ifr_name, drv->ifname, sizeof(ifr.ifr_name)); |
251 | ifr.ifr_data = (void *)&nwid; | | 250 | ifr.ifr_data = (void *)&nwid; |
252 | return ioctl(drv->global->sock, SIOCS80211NWID, &ifr); | | 251 | return ioctl(drv->global->sock, SIOCS80211NWID, &ifr); |
253 | #else | | 252 | #else |
254 | return set80211var(drv, IEEE80211_IOC_SSID, ssid, ssid_len); | | 253 | return set80211var(drv, IEEE80211_IOC_SSID, ssid, ssid_len); |
255 | #endif | | 254 | #endif |
256 | } | | 255 | } |
257 | | | 256 | |
258 | static int | | 257 | static int |
259 | bsd_get_if_media(void *priv) | | 258 | bsd_get_if_media(void *priv) |
260 | { | | 259 | { |
261 | struct bsd_driver_data *drv = priv; | | 260 | struct bsd_driver_data *drv = priv; |
262 | struct ifmediareq ifmr; | | 261 | struct ifmediareq ifmr; |
263 | | | 262 | |
264 | os_memset(&ifmr, 0, sizeof(ifmr)); | | 263 | os_memset(&ifmr, 0, sizeof(ifmr)); |
265 | os_strlcpy(ifmr.ifm_name, drv->ifname, sizeof(ifmr.ifm_name)); | | 264 | os_strlcpy(ifmr.ifm_name, drv->ifname, sizeof(ifmr.ifm_name)); |
266 | | | 265 | |
267 | if (ioctl(drv->global->sock, SIOCGIFMEDIA, &ifmr) < 0) { | | 266 | if (ioctl(drv->global->sock, SIOCGIFMEDIA, &ifmr) < 0) { |
268 | wpa_printf(MSG_ERROR, "%s: SIOCGIFMEDIA %s", __func__, | | 267 | wpa_printf(MSG_ERROR, "%s: SIOCGIFMEDIA %s", __func__, |
269 | strerror(errno)); | | 268 | strerror(errno)); |
270 | return -1; | | 269 | return -1; |
271 | } | | 270 | } |
272 | | | 271 | |
273 | return ifmr.ifm_current; | | 272 | return ifmr.ifm_current; |
274 | } | | 273 | } |
275 | | | 274 | |
276 | static int | | 275 | static int |
277 | bsd_set_if_media(void *priv, int media) | | 276 | bsd_set_if_media(void *priv, int media) |
278 | { | | 277 | { |
279 | struct bsd_driver_data *drv = priv; | | 278 | struct bsd_driver_data *drv = priv; |
280 | struct ifreq ifr; | | 279 | struct ifreq ifr; |
281 | | | 280 | |
282 | os_memset(&ifr, 0, sizeof(ifr)); | | 281 | os_memset(&ifr, 0, sizeof(ifr)); |
283 | os_strlcpy(ifr.ifr_name, drv->ifname, sizeof(ifr.ifr_name)); | | 282 | os_strlcpy(ifr.ifr_name, drv->ifname, sizeof(ifr.ifr_name)); |
284 | ifr.ifr_media = media; | | 283 | ifr.ifr_media = media; |
285 | | | 284 | |
286 | if (ioctl(drv->global->sock, SIOCSIFMEDIA, &ifr) < 0) { | | 285 | if (ioctl(drv->global->sock, SIOCSIFMEDIA, &ifr) < 0) { |
287 | wpa_printf(MSG_ERROR, "%s: SIOCSIFMEDIA %s", __func__, | | 286 | wpa_printf(MSG_ERROR, "%s: SIOCSIFMEDIA %s", __func__, |
288 | strerror(errno)); | | 287 | strerror(errno)); |
289 | return -1; | | 288 | return -1; |
290 | } | | 289 | } |
291 | | | 290 | |
292 | return 0; | | 291 | return 0; |
293 | } | | 292 | } |
294 | | | 293 | |
295 | static int | | 294 | static int |
296 | bsd_set_mediaopt(void *priv, uint32_t mask, uint32_t mode) | | 295 | bsd_set_mediaopt(void *priv, uint32_t mask, uint32_t mode) |
297 | { | | 296 | { |
298 | int media = bsd_get_if_media(priv); | | 297 | int media = bsd_get_if_media(priv); |
299 | | | 298 | |
300 | if (media < 0) | | 299 | if (media < 0) |
301 | return -1; | | 300 | return -1; |
302 | media &= ~mask; | | 301 | media &= ~mask; |
303 | media |= mode; | | 302 | media |= mode; |
304 | if (bsd_set_if_media(priv, media) < 0) | | 303 | if (bsd_set_if_media(priv, media) < 0) |
305 | return -1; | | 304 | return -1; |
306 | return 0; | | 305 | return 0; |
307 | } | | 306 | } |
308 | | | 307 | |
309 | static int | | 308 | static int |
310 | bsd_del_key(void *priv, const u8 *addr, int key_idx) | | 309 | bsd_del_key(void *priv, const u8 *addr, int key_idx) |
311 | { | | 310 | { |
312 | struct ieee80211req_del_key wk; | | 311 | struct ieee80211req_del_key wk; |
313 | | | 312 | |
314 | os_memset(&wk, 0, sizeof(wk)); | | 313 | os_memset(&wk, 0, sizeof(wk)); |
315 | if (addr == NULL) { | | 314 | if (addr == NULL) { |
316 | wpa_printf(MSG_DEBUG, "%s: key_idx=%d", __func__, key_idx); | | 315 | wpa_printf(MSG_DEBUG, "%s: key_idx=%d", __func__, key_idx); |
317 | wk.idk_keyix = key_idx; | | 316 | wk.idk_keyix = key_idx; |
318 | } else { | | 317 | } else { |
319 | wpa_printf(MSG_DEBUG, "%s: addr=" MACSTR, __func__, | | 318 | wpa_printf(MSG_DEBUG, "%s: addr=" MACSTR, __func__, |
320 | MAC2STR(addr)); | | 319 | MAC2STR(addr)); |
321 | os_memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN); | | 320 | os_memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN); |
322 | wk.idk_keyix = (u_int8_t) IEEE80211_KEYIX_NONE; /* XXX */ | | 321 | wk.idk_keyix = (u_int8_t) IEEE80211_KEYIX_NONE; /* XXX */ |
323 | } | | 322 | } |
324 | | | 323 | |
325 | return set80211var(priv, IEEE80211_IOC_DELKEY, &wk, sizeof(wk)); | | 324 | return set80211var(priv, IEEE80211_IOC_DELKEY, &wk, sizeof(wk)); |
326 | } | | 325 | } |
327 | | | 326 | |
328 | static int | | 327 | static int |
329 | bsd_send_mlme_param(void *priv, const u8 op, const u16 reason, const u8 *addr) | | 328 | bsd_send_mlme_param(void *priv, const u8 op, const u16 reason, const u8 *addr) |
330 | { | | 329 | { |
331 | struct ieee80211req_mlme mlme; | | 330 | struct ieee80211req_mlme mlme; |
332 | | | 331 | |
333 | os_memset(&mlme, 0, sizeof(mlme)); | | 332 | os_memset(&mlme, 0, sizeof(mlme)); |
334 | mlme.im_op = op; | | 333 | mlme.im_op = op; |
335 | mlme.im_reason = reason; | | 334 | mlme.im_reason = reason; |
336 | os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN); | | 335 | os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN); |
337 | wpa_printf(MSG_DEBUG, "%s: op=%d reason=%d addr=" MACSTR, __func__, | | 336 | wpa_printf(MSG_DEBUG, "%s: op=%d reason=%d addr=" MACSTR, __func__, |
338 | op, reason, MAC2STR(addr)); | | 337 | op, reason, MAC2STR(addr)); |
339 | return set80211var(priv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme)); | | 338 | return set80211var(priv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme)); |
340 | } | | 339 | } |
341 | | | 340 | |
342 | static int | | 341 | static int |
343 | bsd_ctrl_iface(void *priv, int enable) | | 342 | bsd_ctrl_iface(void *priv, int enable) |
344 | { | | 343 | { |
345 | struct bsd_driver_data *drv = priv; | | 344 | struct bsd_driver_data *drv = priv; |
346 | struct ifreq ifr; | | 345 | struct ifreq ifr; |
347 | | | 346 | |
348 | os_memset(&ifr, 0, sizeof(ifr)); | | 347 | os_memset(&ifr, 0, sizeof(ifr)); |
349 | os_strlcpy(ifr.ifr_name, drv->ifname, sizeof(ifr.ifr_name)); | | 348 | os_strlcpy(ifr.ifr_name, drv->ifname, sizeof(ifr.ifr_name)); |
350 | | | 349 | |
351 | if (ioctl(drv->global->sock, SIOCGIFFLAGS, &ifr) < 0) { | | 350 | if (ioctl(drv->global->sock, SIOCGIFFLAGS, &ifr) < 0) { |
352 | wpa_printf(MSG_ERROR, "ioctl[SIOCGIFFLAGS]: %s", | | 351 | wpa_printf(MSG_ERROR, "ioctl[SIOCGIFFLAGS]: %s", |
353 | strerror(errno)); | | 352 | strerror(errno)); |
354 | return -1; | | 353 | return -1; |
355 | } | | 354 | } |
356 | drv->flags = ifr.ifr_flags; | | 355 | drv->flags = ifr.ifr_flags; |
357 | | | 356 | |
358 | if (enable) { | | 357 | if (enable) { |
359 | if (ifr.ifr_flags & IFF_UP) | | 358 | if (ifr.ifr_flags & IFF_UP) |
360 | return 0; | | 359 | return 0; |
361 | ifr.ifr_flags |= IFF_UP; | | 360 | ifr.ifr_flags |= IFF_UP; |
362 | } else { | | 361 | } else { |
363 | if (!(ifr.ifr_flags & IFF_UP)) | | 362 | if (!(ifr.ifr_flags & IFF_UP)) |
364 | return 0; | | 363 | return 0; |
365 | ifr.ifr_flags &= ~IFF_UP; | | 364 | ifr.ifr_flags &= ~IFF_UP; |
366 | } | | 365 | } |
367 | | | 366 | |
368 | if (ioctl(drv->global->sock, SIOCSIFFLAGS, &ifr) < 0) { | | 367 | if (ioctl(drv->global->sock, SIOCSIFFLAGS, &ifr) < 0) { |
369 | wpa_printf(MSG_ERROR, "ioctl[SIOCSIFFLAGS]: %s", | | 368 | wpa_printf(MSG_ERROR, "ioctl[SIOCSIFFLAGS]: %s", |
370 | strerror(errno)); | | 369 | strerror(errno)); |
371 | return -1; | | 370 | return -1; |
372 | } | | 371 | } |
373 | | | 372 | |
374 | drv->flags = ifr.ifr_flags; | | 373 | drv->flags = ifr.ifr_flags; |
375 | return 0; | | 374 | return 0; |
376 | } | | 375 | } |
377 | | | 376 | |
378 | static int | | 377 | static int |
379 | bsd_set_key(const char *ifname, void *priv, enum wpa_alg alg, | | 378 | bsd_set_key(const char *ifname, void *priv, enum wpa_alg alg, |
380 | const unsigned char *addr, int key_idx, int set_tx, const u8 *seq, | | 379 | const unsigned char *addr, int key_idx, int set_tx, const u8 *seq, |
381 | size_t seq_len, const u8 *key, size_t key_len) | | 380 | size_t seq_len, const u8 *key, size_t key_len) |
382 | { | | 381 | { |
383 | struct ieee80211req_key wk; | | 382 | struct ieee80211req_key wk; |
384 | #ifdef IEEE80211_KEY_NOREPLAY | | 383 | #ifdef IEEE80211_KEY_NOREPLAY |
385 | struct bsd_driver_data *drv = priv; | | 384 | struct bsd_driver_data *drv = priv; |
386 | #endif /* IEEE80211_KEY_NOREPLAY */ | | 385 | #endif /* IEEE80211_KEY_NOREPLAY */ |
387 | | | 386 | |
388 | wpa_printf(MSG_DEBUG, "%s: alg=%d addr=%p key_idx=%d set_tx=%d " | | 387 | wpa_printf(MSG_DEBUG, "%s: alg=%d addr=%p key_idx=%d set_tx=%d " |
389 | "seq_len=%zu key_len=%zu", __func__, alg, addr, key_idx, | | 388 | "seq_len=%zu key_len=%zu", __func__, alg, addr, key_idx, |
390 | set_tx, seq_len, key_len); | | 389 | set_tx, seq_len, key_len); |
391 | | | 390 | |
392 | if (alg == WPA_ALG_NONE) { | | 391 | if (alg == WPA_ALG_NONE) { |
393 | #ifndef HOSTAPD | | 392 | #ifndef HOSTAPD |
394 | if (addr == NULL || is_broadcast_ether_addr(addr)) | | 393 | if (addr == NULL || is_broadcast_ether_addr(addr)) |
395 | return bsd_del_key(priv, NULL, key_idx); | | 394 | return bsd_del_key(priv, NULL, key_idx); |
396 | else | | 395 | else |
397 | #endif /* HOSTAPD */ | | 396 | #endif /* HOSTAPD */ |
398 | return bsd_del_key(priv, addr, key_idx); | | 397 | return bsd_del_key(priv, addr, key_idx); |
399 | } | | 398 | } |
400 | | | 399 | |
401 | os_memset(&wk, 0, sizeof(wk)); | | 400 | os_memset(&wk, 0, sizeof(wk)); |
402 | switch (alg) { | | 401 | switch (alg) { |
403 | case WPA_ALG_WEP: | | 402 | case WPA_ALG_WEP: |
404 | wk.ik_type = IEEE80211_CIPHER_WEP; | | 403 | wk.ik_type = IEEE80211_CIPHER_WEP; |
405 | break; | | 404 | break; |
406 | case WPA_ALG_TKIP: | | 405 | case WPA_ALG_TKIP: |
407 | wk.ik_type = IEEE80211_CIPHER_TKIP; | | 406 | wk.ik_type = IEEE80211_CIPHER_TKIP; |
408 | break; | | 407 | break; |
409 | case WPA_ALG_CCMP: | | 408 | case WPA_ALG_CCMP: |
410 | wk.ik_type = IEEE80211_CIPHER_AES_CCM; | | 409 | wk.ik_type = IEEE80211_CIPHER_AES_CCM; |
411 | break; | | 410 | break; |
412 | default: | | 411 | default: |
413 | wpa_printf(MSG_ERROR, "%s: unknown alg=%d", __func__, alg); | | 412 | wpa_printf(MSG_ERROR, "%s: unknown alg=%d", __func__, alg); |
414 | return -1; | | 413 | return -1; |
415 | } | | 414 | } |
416 | | | 415 | |
417 | wk.ik_flags = IEEE80211_KEY_RECV; | | 416 | wk.ik_flags = IEEE80211_KEY_RECV; |
418 | if (set_tx) | | 417 | if (set_tx) |
419 | wk.ik_flags |= IEEE80211_KEY_XMIT; | | 418 | wk.ik_flags |= IEEE80211_KEY_XMIT; |
420 | | | 419 | |
421 | if (addr == NULL) { | | 420 | if (addr == NULL) { |
422 | os_memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN); | | 421 | os_memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN); |
423 | wk.ik_keyix = key_idx; | | 422 | wk.ik_keyix = key_idx; |
424 | } else { | | 423 | } else { |
425 | os_memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN); | | 424 | os_memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN); |
426 | /* | | 425 | /* |
427 | * Deduce whether group/global or unicast key by checking | | 426 | * Deduce whether group/global or unicast key by checking |
428 | * the address (yech). Note also that we can only mark global | | 427 | * the address (yech). Note also that we can only mark global |
429 | * keys default; doing this for a unicast key is an error. | | 428 | * keys default; doing this for a unicast key is an error. |
430 | */ | | 429 | */ |
431 | if (is_broadcast_ether_addr(addr)) { | | 430 | if (is_broadcast_ether_addr(addr)) { |
432 | wk.ik_flags |= IEEE80211_KEY_GROUP; | | 431 | wk.ik_flags |= IEEE80211_KEY_GROUP; |
433 | wk.ik_keyix = key_idx; | | 432 | wk.ik_keyix = key_idx; |
434 | } else { | | 433 | } else { |
435 | wk.ik_keyix = key_idx == 0 ? IEEE80211_KEYIX_NONE : | | 434 | wk.ik_keyix = key_idx == 0 ? IEEE80211_KEYIX_NONE : |
436 | key_idx; | | 435 | key_idx; |
437 | } | | 436 | } |
438 | } | | 437 | } |
439 | if (wk.ik_keyix != IEEE80211_KEYIX_NONE && set_tx) | | 438 | if (wk.ik_keyix != IEEE80211_KEYIX_NONE && set_tx) |
440 | wk.ik_flags |= IEEE80211_KEY_DEFAULT; | | 439 | wk.ik_flags |= IEEE80211_KEY_DEFAULT; |
441 | #ifndef HOSTAPD | | 440 | #ifndef HOSTAPD |
442 | #ifdef IEEE80211_KEY_NOREPLAY | | 441 | #ifdef IEEE80211_KEY_NOREPLAY |
443 | /* | | 442 | /* |
444 | * Ignore replay failures in IBSS and AHDEMO mode. | | 443 | * Ignore replay failures in IBSS and AHDEMO mode. |
445 | */ | | 444 | */ |
446 | if (drv->opmode == IEEE80211_M_IBSS || | | 445 | if (drv->opmode == IEEE80211_M_IBSS || |
447 | drv->opmode == IEEE80211_M_AHDEMO) | | 446 | drv->opmode == IEEE80211_M_AHDEMO) |
448 | wk.ik_flags |= IEEE80211_KEY_NOREPLAY; | | 447 | wk.ik_flags |= IEEE80211_KEY_NOREPLAY; |
449 | #endif /* IEEE80211_KEY_NOREPLAY */ | | 448 | #endif /* IEEE80211_KEY_NOREPLAY */ |
450 | #endif /* HOSTAPD */ | | 449 | #endif /* HOSTAPD */ |
451 | wk.ik_keylen = key_len; | | 450 | wk.ik_keylen = key_len; |
452 | if (seq) { | | 451 | if (seq) { |
453 | #ifdef WORDS_BIGENDIAN | | 452 | #ifdef WORDS_BIGENDIAN |
454 | /* | | 453 | /* |
455 | * wk.ik_keyrsc is in host byte order (big endian), need to | | 454 | * wk.ik_keyrsc is in host byte order (big endian), need to |
456 | * swap it to match with the byte order used in WPA. | | 455 | * swap it to match with the byte order used in WPA. |
457 | */ | | 456 | */ |
458 | int i; | | 457 | int i; |
459 | u8 *keyrsc = (u8 *) &wk.ik_keyrsc; | | 458 | u8 *keyrsc = (u8 *) &wk.ik_keyrsc; |
460 | for (i = 0; i < seq_len; i++) | | 459 | for (i = 0; i < seq_len; i++) |
461 | keyrsc[WPA_KEY_RSC_LEN - i - 1] = seq[i]; | | 460 | keyrsc[WPA_KEY_RSC_LEN - i - 1] = seq[i]; |
462 | #else /* WORDS_BIGENDIAN */ | | 461 | #else /* WORDS_BIGENDIAN */ |
463 | os_memcpy(&wk.ik_keyrsc, seq, seq_len); | | 462 | os_memcpy(&wk.ik_keyrsc, seq, seq_len); |
464 | #endif /* WORDS_BIGENDIAN */ | | 463 | #endif /* WORDS_BIGENDIAN */ |
465 | } | | 464 | } |
466 | os_memcpy(wk.ik_keydata, key, key_len); | | 465 | os_memcpy(wk.ik_keydata, key, key_len); |
467 | | | 466 | |
468 | return set80211var(priv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk)); | | 467 | return set80211var(priv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk)); |
469 | } | | 468 | } |
470 | | | 469 | |
471 | static int | | 470 | static int |
472 | bsd_configure_wpa(void *priv, struct wpa_bss_params *params) | | 471 | bsd_configure_wpa(void *priv, struct wpa_bss_params *params) |
473 | { | | 472 | { |
474 | #ifndef IEEE80211_IOC_APPIE | | 473 | #ifndef IEEE80211_IOC_APPIE |
475 | static const char *ciphernames[] = | | 474 | static const char *ciphernames[] = |
476 | { "WEP", "TKIP", "AES-OCB", "AES-CCM", "CKIP", "NONE" }; | | 475 | { "WEP", "TKIP", "AES-OCB", "AES-CCM", "CKIP", "NONE" }; |
477 | int v; | | 476 | int v; |
478 | | | 477 | |
479 | switch (params->wpa_group) { | | 478 | switch (params->wpa_group) { |
480 | case WPA_CIPHER_CCMP: | | 479 | case WPA_CIPHER_CCMP: |
481 | v = IEEE80211_CIPHER_AES_CCM; | | 480 | v = IEEE80211_CIPHER_AES_CCM; |
482 | break; | | 481 | break; |
483 | case WPA_CIPHER_TKIP: | | 482 | case WPA_CIPHER_TKIP: |
484 | v = IEEE80211_CIPHER_TKIP; | | 483 | v = IEEE80211_CIPHER_TKIP; |
485 | break; | | 484 | break; |
486 | case WPA_CIPHER_WEP104: | | 485 | case WPA_CIPHER_WEP104: |
487 | v = IEEE80211_CIPHER_WEP; | | 486 | v = IEEE80211_CIPHER_WEP; |
488 | break; | | 487 | break; |
489 | case WPA_CIPHER_WEP40: | | 488 | case WPA_CIPHER_WEP40: |
490 | v = IEEE80211_CIPHER_WEP; | | 489 | v = IEEE80211_CIPHER_WEP; |
491 | break; | | 490 | break; |
492 | case WPA_CIPHER_NONE: | | 491 | case WPA_CIPHER_NONE: |
493 | v = IEEE80211_CIPHER_NONE; | | 492 | v = IEEE80211_CIPHER_NONE; |
494 | break; | | 493 | break; |
495 | default: | | 494 | default: |
496 | wpa_printf(MSG_INFO, "Unknown group key cipher %u", | | 495 | wpa_printf(MSG_INFO, "Unknown group key cipher %u", |
497 | params->wpa_group); | | 496 | params->wpa_group); |
498 | return -1; | | 497 | return -1; |
499 | } | | 498 | } |
500 | wpa_printf(MSG_DEBUG, "%s: group key cipher=%s (%u)", | | 499 | wpa_printf(MSG_DEBUG, "%s: group key cipher=%s (%u)", |
501 | __func__, ciphernames[v], v); | | 500 | __func__, ciphernames[v], v); |
502 | if (set80211param(priv, IEEE80211_IOC_MCASTCIPHER, v)) { | | 501 | if (set80211param(priv, IEEE80211_IOC_MCASTCIPHER, v)) { |
503 | wpa_printf(MSG_INFO, | | 502 | wpa_printf(MSG_INFO, |
504 | "Unable to set group key cipher to %u (%s)", | | 503 | "Unable to set group key cipher to %u (%s)", |
505 | v, ciphernames[v]); | | 504 | v, ciphernames[v]); |
506 | return -1; | | 505 | return -1; |
507 | } | | 506 | } |
508 | if (v == IEEE80211_CIPHER_WEP) { | | 507 | if (v == IEEE80211_CIPHER_WEP) { |
509 | /* key length is done only for specific ciphers */ | | 508 | /* key length is done only for specific ciphers */ |
510 | v = (params->wpa_group == WPA_CIPHER_WEP104 ? 13 : 5); | | 509 | v = (params->wpa_group == WPA_CIPHER_WEP104 ? 13 : 5); |
511 | if (set80211param(priv, IEEE80211_IOC_MCASTKEYLEN, v)) { | | 510 | if (set80211param(priv, IEEE80211_IOC_MCASTKEYLEN, v)) { |
512 | wpa_printf(MSG_INFO, | | 511 | wpa_printf(MSG_INFO, |
513 | "Unable to set group key length to %u", v); | | 512 | "Unable to set group key length to %u", v); |
514 | return -1; | | 513 | return -1; |
515 | } | | 514 | } |
516 | } | | 515 | } |
517 | | | 516 | |
518 | v = 0; | | 517 | v = 0; |
519 | if (params->wpa_pairwise & WPA_CIPHER_CCMP) | | 518 | if (params->wpa_pairwise & WPA_CIPHER_CCMP) |
520 | v |= 1<<IEEE80211_CIPHER_AES_CCM; | | 519 | v |= 1<<IEEE80211_CIPHER_AES_CCM; |
521 | if (params->wpa_pairwise & WPA_CIPHER_TKIP) | | 520 | if (params->wpa_pairwise & WPA_CIPHER_TKIP) |
522 | v |= 1<<IEEE80211_CIPHER_TKIP; | | 521 | v |= 1<<IEEE80211_CIPHER_TKIP; |
523 | if (params->wpa_pairwise & WPA_CIPHER_NONE) | | 522 | if (params->wpa_pairwise & WPA_CIPHER_NONE) |
524 | v |= 1<<IEEE80211_CIPHER_NONE; | | 523 | v |= 1<<IEEE80211_CIPHER_NONE; |
525 | wpa_printf(MSG_DEBUG, "%s: pairwise key ciphers=0x%x", __func__, v); | | 524 | wpa_printf(MSG_DEBUG, "%s: pairwise key ciphers=0x%x", __func__, v); |
526 | if (set80211param(priv, IEEE80211_IOC_UCASTCIPHERS, v)) { | | 525 | if (set80211param(priv, IEEE80211_IOC_UCASTCIPHERS, v)) { |
527 | wpa_printf(MSG_INFO, | | 526 | wpa_printf(MSG_INFO, |
528 | "Unable to set pairwise key ciphers to 0x%x", v); | | 527 | "Unable to set pairwise key ciphers to 0x%x", v); |
529 | return -1; | | 528 | return -1; |
530 | } | | 529 | } |
531 | | | 530 | |
532 | wpa_printf(MSG_DEBUG, "%s: key management algorithms=0x%x", | | 531 | wpa_printf(MSG_DEBUG, "%s: key management algorithms=0x%x", |
533 | __func__, params->wpa_key_mgmt); | | 532 | __func__, params->wpa_key_mgmt); |
534 | if (set80211param(priv, IEEE80211_IOC_KEYMGTALGS, | | 533 | if (set80211param(priv, IEEE80211_IOC_KEYMGTALGS, |
535 | params->wpa_key_mgmt)) { | | 534 | params->wpa_key_mgmt)) { |
536 | wpa_printf(MSG_INFO, | | 535 | wpa_printf(MSG_INFO, |
537 | "Unable to set key management algorithms to 0x%x", | | 536 | "Unable to set key management algorithms to 0x%x", |
538 | params->wpa_key_mgmt); | | 537 | params->wpa_key_mgmt); |
539 | return -1; | | 538 | return -1; |
540 | } | | 539 | } |
541 | | | 540 | |
542 | v = 0; | | 541 | v = 0; |
543 | if (params->rsn_preauth) | | 542 | if (params->rsn_preauth) |
544 | v |= BIT(0); | | 543 | v |= BIT(0); |
545 | wpa_printf(MSG_DEBUG, "%s: rsn capabilities=0x%x", | | 544 | wpa_printf(MSG_DEBUG, "%s: rsn capabilities=0x%x", |
546 | __func__, params->rsn_preauth); | | 545 | __func__, params->rsn_preauth); |
547 | if (set80211param(priv, IEEE80211_IOC_RSNCAPS, v)) { | | 546 | if (set80211param(priv, IEEE80211_IOC_RSNCAPS, v)) { |
548 | wpa_printf(MSG_INFO, "Unable to set RSN capabilities to 0x%x", | | 547 | wpa_printf(MSG_INFO, "Unable to set RSN capabilities to 0x%x", |
549 | v); | | 548 | v); |
550 | return -1; | | 549 | return -1; |
551 | } | | 550 | } |
552 | #endif /* IEEE80211_IOC_APPIE */ | | 551 | #endif /* IEEE80211_IOC_APPIE */ |
553 | | | 552 | |
554 | wpa_printf(MSG_DEBUG, "%s: enable WPA= 0x%x", __func__, params->wpa); | | 553 | wpa_printf(MSG_DEBUG, "%s: enable WPA= 0x%x", __func__, params->wpa); |
555 | if (set80211param(priv, IEEE80211_IOC_WPA, params->wpa)) { | | 554 | if (set80211param(priv, IEEE80211_IOC_WPA, params->wpa)) { |
556 | wpa_printf(MSG_INFO, "Unable to set WPA to %u", params->wpa); | | 555 | wpa_printf(MSG_INFO, "Unable to set WPA to %u", params->wpa); |
557 | return -1; | | 556 | return -1; |
558 | } | | 557 | } |
559 | return 0; | | 558 | return 0; |
560 | } | | 559 | } |
561 | | | 560 | |
562 | static int | | 561 | static int |
563 | bsd_set_ieee8021x(void *priv, struct wpa_bss_params *params) | | 562 | bsd_set_ieee8021x(void *priv, struct wpa_bss_params *params) |
564 | { | | 563 | { |
565 | wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, params->enabled); | | 564 | wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, params->enabled); |
566 | | | 565 | |
567 | if (!params->enabled) { | | 566 | if (!params->enabled) { |
568 | /* XXX restore state */ | | 567 | /* XXX restore state */ |
569 | return set80211param(priv, IEEE80211_IOC_AUTHMODE, | | 568 | return set80211param(priv, IEEE80211_IOC_AUTHMODE, |
570 | IEEE80211_AUTH_AUTO); | | 569 | IEEE80211_AUTH_AUTO); |
571 | } | | 570 | } |
572 | if (!params->wpa && !params->ieee802_1x) { | | 571 | if (!params->wpa && !params->ieee802_1x) { |
573 | wpa_printf(MSG_ERROR, "%s: No 802.1X or WPA enabled", | | 572 | wpa_printf(MSG_ERROR, "%s: No 802.1X or WPA enabled", |
574 | __func__); | | 573 | __func__); |
575 | return -1; | | 574 | return -1; |
576 | } | | 575 | } |
577 | if (params->wpa && bsd_configure_wpa(priv, params) != 0) { | | 576 | if (params->wpa && bsd_configure_wpa(priv, params) != 0) { |
578 | wpa_printf(MSG_ERROR, "%s: Failed to configure WPA state", | | 577 | wpa_printf(MSG_ERROR, "%s: Failed to configure WPA state", |
579 | __func__); | | 578 | __func__); |
580 | return -1; | | 579 | return -1; |
581 | } | | 580 | } |
582 | if (set80211param(priv, IEEE80211_IOC_AUTHMODE, | | 581 | if (set80211param(priv, IEEE80211_IOC_AUTHMODE, |
583 | (params->wpa ? IEEE80211_AUTH_WPA : IEEE80211_AUTH_8021X))) { | | 582 | (params->wpa ? IEEE80211_AUTH_WPA : IEEE80211_AUTH_8021X))) { |
584 | wpa_printf(MSG_ERROR, "%s: Failed to enable WPA/802.1X", | | 583 | wpa_printf(MSG_ERROR, "%s: Failed to enable WPA/802.1X", |
585 | __func__); | | 584 | __func__); |
586 | return -1; | | 585 | return -1; |
587 | } | | 586 | } |
588 | return bsd_ctrl_iface(priv, 1); | | 587 | return bsd_ctrl_iface(priv, 1); |
589 | } | | 588 | } |
590 | | | 589 | |
591 | static void | | 590 | static void |
592 | bsd_new_sta(void *priv, void *ctx, u8 addr[IEEE80211_ADDR_LEN]) | | 591 | bsd_new_sta(void *priv, void *ctx, u8 addr[IEEE80211_ADDR_LEN]) |
593 | { | | 592 | { |
594 | struct ieee80211req_wpaie ie; | | 593 | struct ieee80211req_wpaie ie; |
595 | int ielen = 0; | | 594 | int ielen = 0; |
596 | u8 *iebuf = NULL; | | 595 | u8 *iebuf = NULL; |
597 | | | 596 | |
598 | /* | | 597 | /* |
599 | * Fetch and validate any negotiated WPA/RSN parameters. | | 598 | * Fetch and validate any negotiated WPA/RSN parameters. |
600 | */ | | 599 | */ |
601 | memset(&ie, 0, sizeof(ie)); | | 600 | memset(&ie, 0, sizeof(ie)); |
602 | memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN); | | 601 | memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN); |
603 | if (get80211var(priv, IEEE80211_IOC_WPAIE, &ie, sizeof(ie)) < 0) { | | 602 | if (get80211var(priv, IEEE80211_IOC_WPAIE, &ie, sizeof(ie)) < 0) { |
604 | wpa_printf(MSG_INFO, | | 603 | wpa_printf(MSG_INFO, |
605 | "Failed to get WPA/RSN information element"); | | 604 | "Failed to get WPA/RSN information element"); |
606 | goto no_ie; | | 605 | goto no_ie; |
607 | } | | 606 | } |
608 | iebuf = ie.wpa_ie; | | 607 | iebuf = ie.wpa_ie; |
609 | ielen = ie.wpa_ie[1]; | | 608 | ielen = ie.wpa_ie[1]; |
610 | if (ielen == 0) | | 609 | if (ielen == 0) |
611 | iebuf = NULL; | | 610 | iebuf = NULL; |
612 | else | | 611 | else |
613 | ielen += 2; | | 612 | ielen += 2; |
614 | | | 613 | |
615 | no_ie: | | 614 | no_ie: |
616 | drv_event_assoc(ctx, addr, iebuf, ielen, 0); | | 615 | drv_event_assoc(ctx, addr, iebuf, ielen, 0); |
617 | } | | 616 | } |
618 | | | 617 | |
619 | static int | | 618 | static int |
620 | bsd_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len, | | 619 | bsd_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len, |
621 | int encrypt, const u8 *own_addr, u32 flags) | | 620 | int encrypt, const u8 *own_addr, u32 flags) |
622 | { | | 621 | { |
623 | struct bsd_driver_data *drv = priv; | | 622 | struct bsd_driver_data *drv = priv; |
624 | | | 623 | |
625 | wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", data, data_len); | | 624 | wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", data, data_len); |
626 | | | 625 | |
627 | return l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, data, | | 626 | return l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, data, |
628 | data_len); | | 627 | data_len); |
629 | } | | 628 | } |
630 | | | 629 | |
631 | static int | | 630 | static int |
632 | bsd_set_freq(void *priv, struct hostapd_freq_params *freq) | | 631 | bsd_set_freq(void *priv, struct hostapd_freq_params *freq) |
633 | { | | 632 | { |
634 | struct bsd_driver_data *drv = priv; | | 633 | struct bsd_driver_data *drv = priv; |
635 | #ifdef SIOCS80211CHANNEL | | 634 | #ifdef SIOCS80211CHANNEL |
636 | struct ieee80211chanreq creq; | | 635 | struct ieee80211chanreq creq; |
637 | #endif /* SIOCS80211CHANNEL */ | | 636 | #endif /* SIOCS80211CHANNEL */ |
638 | u32 mode; | | 637 | u32 mode; |
639 | int channel = freq->channel; | | 638 | int channel = freq->channel; |
640 | | | 639 | |
641 | if (channel < 14) { | | 640 | if (channel < 14) { |
642 | mode = | | 641 | mode = |
643 | #ifdef CONFIG_IEEE80211N | | 642 | #ifdef CONFIG_IEEE80211N |
644 | freq->ht_enabled ? IFM_IEEE80211_11NG : | | 643 | freq->ht_enabled ? IFM_IEEE80211_11NG : |
645 | #endif /* CONFIG_IEEE80211N */ | | 644 | #endif /* CONFIG_IEEE80211N */ |
646 | IFM_IEEE80211_11G; | | 645 | IFM_IEEE80211_11G; |
647 | } else if (channel == 14) { | | 646 | } else if (channel == 14) { |
648 | mode = IFM_IEEE80211_11B; | | 647 | mode = IFM_IEEE80211_11B; |
649 | } else { | | 648 | } else { |
650 | mode = | | 649 | mode = |
651 | #ifdef CONFIG_IEEE80211N | | 650 | #ifdef CONFIG_IEEE80211N |
652 | freq->ht_enabled ? IFM_IEEE80211_11NA : | | 651 | freq->ht_enabled ? IFM_IEEE80211_11NA : |
653 | #endif /* CONFIG_IEEE80211N */ | | 652 | #endif /* CONFIG_IEEE80211N */ |
654 | IFM_IEEE80211_11A; | | 653 | IFM_IEEE80211_11A; |
655 | } | | 654 | } |
656 | if (bsd_set_mediaopt(drv, IFM_MMASK, mode) < 0) { | | 655 | if (bsd_set_mediaopt(drv, IFM_MMASK, mode) < 0) { |
657 | wpa_printf(MSG_ERROR, "%s: failed to set modulation mode", | | 656 | wpa_printf(MSG_ERROR, "%s: failed to set modulation mode", |
658 | __func__); | | 657 | __func__); |
659 | return -1; | | 658 | return -1; |
660 | } | | 659 | } |
661 | | | 660 | |
662 | #ifdef SIOCS80211CHANNEL | | 661 | #ifdef SIOCS80211CHANNEL |
663 | os_memset(&creq, 0, sizeof(creq)); | | 662 | os_memset(&creq, 0, sizeof(creq)); |
664 | os_strlcpy(creq.i_name, drv->ifname, sizeof(creq.i_name)); | | 663 | os_strlcpy(creq.i_name, drv->ifname, sizeof(creq.i_name)); |
665 | creq.i_channel = (u_int16_t)channel; | | 664 | creq.i_channel = (u_int16_t)channel; |
666 | return ioctl(drv->global->sock, SIOCS80211CHANNEL, &creq); | | 665 | return ioctl(drv->global->sock, SIOCS80211CHANNEL, &creq); |
667 | #else /* SIOCS80211CHANNEL */ | | 666 | #else /* SIOCS80211CHANNEL */ |
668 | return set80211param(priv, IEEE80211_IOC_CHANNEL, channel); | | 667 | return set80211param(priv, IEEE80211_IOC_CHANNEL, channel); |
669 | #endif /* SIOCS80211CHANNEL */ | | 668 | #endif /* SIOCS80211CHANNEL */ |
670 | } | | 669 | } |
671 | | | 670 | |
672 | static int | | 671 | static int |
673 | bsd_set_opt_ie(void *priv, const u8 *ie, size_t ie_len) | | 672 | bsd_set_opt_ie(void *priv, const u8 *ie, size_t ie_len) |
674 | { | | 673 | { |
675 | #ifdef IEEE80211_IOC_APPIE | | 674 | #ifdef IEEE80211_IOC_APPIE |
676 | wpa_printf(MSG_DEBUG, "%s: set WPA+RSN ie (len %lu)", __func__, | | 675 | wpa_printf(MSG_DEBUG, "%s: set WPA+RSN ie (len %lu)", __func__, |
677 | (unsigned long)ie_len); | | 676 | (unsigned long)ie_len); |
678 | return bsd_set80211(priv, IEEE80211_IOC_APPIE, IEEE80211_APPIE_WPA, | | 677 | return bsd_set80211(priv, IEEE80211_IOC_APPIE, IEEE80211_APPIE_WPA, |
679 | ie, ie_len); | | 678 | ie, ie_len); |
680 | #endif /* IEEE80211_IOC_APPIE */ | | 679 | #endif /* IEEE80211_IOC_APPIE */ |
681 | return 0; | | 680 | return 0; |
682 | } | | 681 | } |
683 | | | 682 | |
684 | #ifdef HOSTAPD | | 683 | #ifdef HOSTAPD |
685 | | | 684 | |
686 | /* | | 685 | /* |
687 | * Avoid conflicts with hostapd definitions by undefining couple of defines | | 686 | * Avoid conflicts with hostapd definitions by undefining couple of defines |
688 | * from net80211 header files. | | 687 | * from net80211 header files. |
689 | */ | | 688 | */ |
690 | #undef RSN_VERSION | | 689 | #undef RSN_VERSION |
691 | #undef WPA_VERSION | | 690 | #undef WPA_VERSION |
692 | #undef WPA_OUI_TYPE | | 691 | #undef WPA_OUI_TYPE |
693 | | | 692 | |
694 | static int bsd_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, | | 693 | static int bsd_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
695 | int reason_code); | | 694 | int reason_code); |
696 | | | 695 | |
697 | static const char * | | 696 | static const char * |
698 | ether_sprintf(const u8 *addr) | | 697 | ether_sprintf(const u8 *addr) |
699 | { | | 698 | { |
700 | static char buf[sizeof(MACSTR)]; | | 699 | static char buf[sizeof(MACSTR)]; |
701 | | | 700 | |
702 | if (addr != NULL) | | 701 | if (addr != NULL) |
703 | snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr)); | | 702 | snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr)); |
704 | else | | 703 | else |
705 | snprintf(buf, sizeof(buf), MACSTR, 0,0,0,0,0,0); | | 704 | snprintf(buf, sizeof(buf), MACSTR, 0,0,0,0,0,0); |
706 | return buf; | | 705 | return buf; |
707 | } | | 706 | } |
708 | | | 707 | |
709 | static int | | 708 | static int |
710 | bsd_set_privacy(void *priv, int enabled) | | 709 | bsd_set_privacy(void *priv, int enabled) |
711 | { | | 710 | { |
712 | wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled); | | 711 | wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled); |
713 | | | 712 | |
714 | return set80211param(priv, IEEE80211_IOC_PRIVACY, enabled); | | 713 | return set80211param(priv, IEEE80211_IOC_PRIVACY, enabled); |
715 | } | | 714 | } |
716 | | | 715 | |
717 | static int | | 716 | static int |
718 | bsd_get_seqnum(const char *ifname, void *priv, const u8 *addr, int idx, | | 717 | bsd_get_seqnum(const char *ifname, void *priv, const u8 *addr, int idx, |
719 | u8 *seq) | | 718 | u8 *seq) |
720 | { | | 719 | { |
721 | struct ieee80211req_key wk; | | 720 | struct ieee80211req_key wk; |
722 | | | 721 | |
723 | wpa_printf(MSG_DEBUG, "%s: addr=%s idx=%d", | | 722 | wpa_printf(MSG_DEBUG, "%s: addr=%s idx=%d", |
724 | __func__, ether_sprintf(addr), idx); | | 723 | __func__, ether_sprintf(addr), idx); |
725 | | | 724 | |
726 | memset(&wk, 0, sizeof(wk)); | | 725 | memset(&wk, 0, sizeof(wk)); |
727 | if (addr == NULL) | | 726 | if (addr == NULL) |
728 | memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN); | | 727 | memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN); |
729 | else | | 728 | else |
730 | memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN); | | 729 | memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN); |
731 | wk.ik_keyix = idx; | | 730 | wk.ik_keyix = idx; |
732 | | | 731 | |
733 | if (get80211var(priv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk)) < 0) { | | 732 | if (get80211var(priv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk)) < 0) { |
734 | wpa_printf(MSG_INFO, "Failed to get encryption"); | | 733 | wpa_printf(MSG_INFO, "Failed to get encryption"); |
735 | return -1; | | 734 | return -1; |
736 | } | | 735 | } |
737 | | | 736 | |
738 | #ifdef WORDS_BIGENDIAN | | 737 | #ifdef WORDS_BIGENDIAN |
739 | { | | 738 | { |
740 | /* | | 739 | /* |
741 | * wk.ik_keytsc is in host byte order (big endian), need to | | 740 | * wk.ik_keytsc is in host byte order (big endian), need to |
742 | * swap it to match with the byte order used in WPA. | | 741 | * swap it to match with the byte order used in WPA. |
743 | */ | | 742 | */ |
744 | int i; | | 743 | int i; |
745 | u8 tmp[WPA_KEY_RSC_LEN]; | | 744 | u8 tmp[WPA_KEY_RSC_LEN]; |
746 | memcpy(tmp, &wk.ik_keytsc, sizeof(wk.ik_keytsc)); | | 745 | memcpy(tmp, &wk.ik_keytsc, sizeof(wk.ik_keytsc)); |
747 | for (i = 0; i < WPA_KEY_RSC_LEN; i++) { | | 746 | for (i = 0; i < WPA_KEY_RSC_LEN; i++) { |
748 | seq[i] = tmp[WPA_KEY_RSC_LEN - i - 1]; | | 747 | seq[i] = tmp[WPA_KEY_RSC_LEN - i - 1]; |
749 | } | | 748 | } |
750 | } | | 749 | } |
751 | #else /* WORDS_BIGENDIAN */ | | 750 | #else /* WORDS_BIGENDIAN */ |
752 | memcpy(seq, &wk.ik_keytsc, sizeof(wk.ik_keytsc)); | | 751 | memcpy(seq, &wk.ik_keytsc, sizeof(wk.ik_keytsc)); |
753 | #endif /* WORDS_BIGENDIAN */ | | 752 | #endif /* WORDS_BIGENDIAN */ |
754 | return 0; | | 753 | return 0; |
755 | } | | 754 | } |
756 | | | 755 | |
757 | | | 756 | |
758 | static int | | 757 | static int |
759 | bsd_flush(void *priv) | | 758 | bsd_flush(void *priv) |
760 | { | | 759 | { |
761 | u8 allsta[IEEE80211_ADDR_LEN]; | | 760 | u8 allsta[IEEE80211_ADDR_LEN]; |
762 | | | 761 | |
763 | memset(allsta, 0xff, IEEE80211_ADDR_LEN); | | 762 | memset(allsta, 0xff, IEEE80211_ADDR_LEN); |
764 | return bsd_sta_deauth(priv, NULL, allsta, IEEE80211_REASON_AUTH_LEAVE); | | 763 | return bsd_sta_deauth(priv, NULL, allsta, IEEE80211_REASON_AUTH_LEAVE); |
765 | } | | 764 | } |
766 | | | 765 | |
767 | | | 766 | |
768 | static int | | 767 | static int |
769 | bsd_read_sta_driver_data(void *priv, struct hostap_sta_driver_data *data, | | 768 | bsd_read_sta_driver_data(void *priv, struct hostap_sta_driver_data *data, |
770 | const u8 *addr) | | 769 | const u8 *addr) |
771 | { | | 770 | { |
772 | struct ieee80211req_sta_stats stats; | | 771 | struct ieee80211req_sta_stats stats; |
773 | | | 772 | |
774 | memcpy(stats.is_u.macaddr, addr, IEEE80211_ADDR_LEN); | | 773 | memcpy(stats.is_u.macaddr, addr, IEEE80211_ADDR_LEN); |
775 | if (get80211var(priv, IEEE80211_IOC_STA_STATS, &stats, sizeof(stats)) | | 774 | if (get80211var(priv, IEEE80211_IOC_STA_STATS, &stats, sizeof(stats)) |
776 | > 0) { | | 775 | > 0) { |
777 | /* XXX? do packets counts include non-data frames? */ | | 776 | /* XXX? do packets counts include non-data frames? */ |
778 | data->rx_packets = stats.is_stats.ns_rx_data; | | 777 | data->rx_packets = stats.is_stats.ns_rx_data; |
779 | data->rx_bytes = stats.is_stats.ns_rx_bytes; | | 778 | data->rx_bytes = stats.is_stats.ns_rx_bytes; |
780 | data->tx_packets = stats.is_stats.ns_tx_data; | | 779 | data->tx_packets = stats.is_stats.ns_tx_data; |
781 | data->tx_bytes = stats.is_stats.ns_tx_bytes; | | 780 | data->tx_bytes = stats.is_stats.ns_tx_bytes; |
782 | } | | 781 | } |
783 | return 0; | | 782 | return 0; |
784 | } | | 783 | } |
785 | | | 784 | |
786 | static int | | 785 | static int |
787 | bsd_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, int reason_code) | | 786 | bsd_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, int reason_code) |
788 | { | | 787 | { |
789 | return bsd_send_mlme_param(priv, IEEE80211_MLME_DEAUTH, reason_code, | | 788 | return bsd_send_mlme_param(priv, IEEE80211_MLME_DEAUTH, reason_code, |
790 | addr); | | 789 | addr); |
791 | } | | 790 | } |
792 | | | 791 | |
793 | static int | | 792 | static int |
794 | bsd_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, | | 793 | bsd_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
795 | int reason_code) | | 794 | int reason_code) |
796 | { | | 795 | { |
797 | return bsd_send_mlme_param(priv, IEEE80211_MLME_DISASSOC, reason_code, | | 796 | return bsd_send_mlme_param(priv, IEEE80211_MLME_DISASSOC, reason_code, |
798 | addr); | | 797 | addr); |
799 | } | | 798 | } |
800 | | | 799 | |
801 | static void | | 800 | static void |
802 | bsd_wireless_event_receive(int sock, void *ctx, void *sock_ctx) | | 801 | bsd_wireless_event_receive(int sock, void *ctx, void *sock_ctx) |
803 | { | | 802 | { |
804 | struct bsd_driver_global *global = sock_ctx; | | 803 | struct bsd_driver_global *global = sock_ctx; |
805 | struct bsd_driver_data *drv; | | 804 | struct bsd_driver_data *drv; |
806 | struct msghdr msg; | | 805 | struct msghdr msg; |
807 | struct if_announcemsghdr *ifan; | | 806 | struct if_announcemsghdr *ifan; |
808 | struct rt_msghdr *rtm; | | 807 | struct rt_msghdr *rtm; |
809 | struct ieee80211_michael_event *mic; | | 808 | struct ieee80211_michael_event *mic; |
810 | struct ieee80211_join_event *join; | | 809 | struct ieee80211_join_event *join; |
811 | struct ieee80211_leave_event *leave; | | 810 | struct ieee80211_leave_event *leave; |
812 | ssize_t n; | | 811 | ssize_t n; |
813 | union wpa_event_data data; | | 812 | union wpa_event_data data; |
814 | | | 813 | |
815 | memset(&msg, 0, sizeof(msg)); | | 814 | memset(&msg, 0, sizeof(msg)); |
816 | msg.msg_iov = global->event_iov; | | 815 | msg.msg_iov = global->event_iov; |
817 | msg.msg_iovlen = 1; | | 816 | msg.msg_iovlen = 1; |
818 | n = recvmsg_realloc(sock, &msg, 0); | | 817 | n = recvmsg_realloc(sock, &msg, 0); |
819 | if (n < 0) { | | 818 | if (n < 0) { |
820 | if (errno != EINTR && errno != EAGAIN) | | 819 | if (errno != EINTR && errno != EAGAIN) |
821 | wpa_printf(MSG_ERROR, "%s read() failed: %s", | | 820 | wpa_printf(MSG_ERROR, "%s read() failed: %s", |
822 | __func__, strerror(errno)); | | 821 | __func__, strerror(errno)); |
823 | return; | | 822 | return; |
824 | } | | 823 | } |
825 | | | 824 | |
826 | rtm = (struct rt_msghdr *) global->event_iov[0].iov_base; | | 825 | rtm = (struct rt_msghdr *) global->event_iov[0].iov_base; |
827 | if (rtm->rtm_version != RTM_VERSION) { | | 826 | if (rtm->rtm_version != RTM_VERSION) { |
828 | wpa_printf(MSG_DEBUG, "Invalid routing message version=%d", | | 827 | wpa_printf(MSG_DEBUG, "Invalid routing message version=%d", |
829 | rtm->rtm_version); | | 828 | rtm->rtm_version); |
830 | return; | | 829 | return; |
831 | } | | 830 | } |
832 | switch (rtm->rtm_type) { | | 831 | switch (rtm->rtm_type) { |
833 | case RTM_IEEE80211: | | 832 | case RTM_IEEE80211: |
834 | ifan = (struct if_announcemsghdr *) rtm; | | 833 | ifan = (struct if_announcemsghdr *) rtm; |
835 | drv = bsd_get_drvindex(global, ifan->ifan_index); | | 834 | drv = bsd_get_drvindex(global, ifan->ifan_index); |
836 | if (drv == NULL) | | 835 | if (drv == NULL) |
837 | return; | | 836 | return; |
838 | switch (ifan->ifan_what) { | | 837 | switch (ifan->ifan_what) { |
839 | case RTM_IEEE80211_ASSOC: | | 838 | case RTM_IEEE80211_ASSOC: |
840 | case RTM_IEEE80211_REASSOC: | | 839 | case RTM_IEEE80211_REASSOC: |
841 | case RTM_IEEE80211_DISASSOC: | | 840 | case RTM_IEEE80211_DISASSOC: |
842 | case RTM_IEEE80211_SCAN: | | 841 | case RTM_IEEE80211_SCAN: |
843 | break; | | 842 | break; |
844 | case RTM_IEEE80211_LEAVE: | | 843 | case RTM_IEEE80211_LEAVE: |
845 | leave = (struct ieee80211_leave_event *) &ifan[1]; | | 844 | leave = (struct ieee80211_leave_event *) &ifan[1]; |
846 | drv_event_disassoc(drv->hapd, leave->iev_addr); | | 845 | drv_event_disassoc(drv->ctx, leave->iev_addr); |
847 | break; | | 846 | break; |
848 | case RTM_IEEE80211_JOIN: | | 847 | case RTM_IEEE80211_JOIN: |
849 | #ifdef RTM_IEEE80211_REJOIN | | 848 | #ifdef RTM_IEEE80211_REJOIN |
850 | case RTM_IEEE80211_REJOIN: | | 849 | case RTM_IEEE80211_REJOIN: |
851 | #endif | | 850 | #endif |
852 | join = (struct ieee80211_join_event *) &ifan[1]; | | 851 | join = (struct ieee80211_join_event *) &ifan[1]; |
853 | bsd_new_sta(drv, drv->hapd, join->iev_addr); | | 852 | bsd_new_sta(drv, drv->ctx, join->iev_addr); |
854 | break; | | 853 | break; |
855 | case RTM_IEEE80211_REPLAY: | | 854 | case RTM_IEEE80211_REPLAY: |
856 | /* ignore */ | | 855 | /* ignore */ |
857 | break; | | 856 | break; |
858 | case RTM_IEEE80211_MICHAEL: | | 857 | case RTM_IEEE80211_MICHAEL: |
859 | mic = (struct ieee80211_michael_event *) &ifan[1]; | | 858 | mic = (struct ieee80211_michael_event *) &ifan[1]; |
860 | wpa_printf(MSG_DEBUG, | | 859 | wpa_printf(MSG_DEBUG, |
861 | "Michael MIC failure wireless event: " | | 860 | "Michael MIC failure wireless event: " |
862 | "keyix=%u src_addr=" MACSTR, mic->iev_keyix, | | 861 | "keyix=%u src_addr=" MACSTR, mic->iev_keyix, |
863 | MAC2STR(mic->iev_src)); | | 862 | MAC2STR(mic->iev_src)); |
864 | os_memset(&data, 0, sizeof(data)); | | 863 | os_memset(&data, 0, sizeof(data)); |
865 | data.michael_mic_failure.unicast = 1; | | 864 | data.michael_mic_failure.unicast = 1; |
866 | data.michael_mic_failure.src = mic->iev_src; | | 865 | data.michael_mic_failure.src = mic->iev_src; |
867 | wpa_supplicant_event(drv->hapd, | | 866 | wpa_supplicant_event(drv->ctx, |
868 | EVENT_MICHAEL_MIC_FAILURE, &data); | | 867 | EVENT_MICHAEL_MIC_FAILURE, &data); |
869 | break; | | 868 | break; |
870 | } | | 869 | } |
871 | break; | | 870 | break; |
872 | } | | 871 | } |
873 | } | | 872 | } |
874 | | | 873 | |
875 | static void | | 874 | static void |
876 | handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len) | | 875 | handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len) |
877 | { | | 876 | { |
878 | struct bsd_driver_data *drv = ctx; | | 877 | struct bsd_driver_data *drv = ctx; |
879 | drv_event_eapol_rx(drv->hapd, src_addr, buf, len); | | 878 | drv_event_eapol_rx(drv->ctx, src_addr, buf, len); |
880 | } | | 879 | } |
881 | | | 880 | |
882 | static void * | | 881 | static void * |
883 | bsd_init(struct hostapd_data *hapd, struct wpa_init_params *params) | | 882 | bsd_init(struct hostapd_data *hapd, struct wpa_init_params *params) |
884 | { | | 883 | { |
885 | struct bsd_driver_data *drv; | | 884 | struct bsd_driver_data *drv; |
886 | | | 885 | |
887 | drv = os_zalloc(sizeof(struct bsd_driver_data)); | | 886 | drv = os_zalloc(sizeof(struct bsd_driver_data)); |
888 | if (drv == NULL) { | | 887 | if (drv == NULL) { |
889 | wpa_printf(MSG_ERROR, "Could not allocate memory for bsd driver data"); | | 888 | wpa_printf(MSG_ERROR, "Could not allocate memory for bsd driver data"); |
890 | return NULL; | | 889 | return NULL; |
891 | } | | 890 | } |
892 | | | 891 | |
893 | drv->ifindex = if_nametoindex(params->ifname); | | 892 | drv->ifindex = if_nametoindex(params->ifname); |
894 | if (drv->ifindex == 0) { | | 893 | if (drv->ifindex == 0) { |
895 | wpa_printf(MSG_DEBUG, "%s: interface %s does not exist", | | 894 | wpa_printf(MSG_DEBUG, "%s: interface %s does not exist", |
896 | __func__, params->ifname); | | 895 | __func__, params->ifname); |
897 | goto bad; | | 896 | goto bad; |
898 | } | | 897 | } |
899 | | | 898 | |
900 | drv->hapd = hapd; | | 899 | drv->ctx = hapd; |
901 | drv->global = params->global_priv; | | 900 | drv->global = params->global_priv; |
902 | os_strlcpy(drv->ifname, params->ifname, sizeof(drv->ifname)); | | 901 | os_strlcpy(drv->ifname, params->ifname, sizeof(drv->ifname)); |
903 | | | 902 | |
904 | drv->sock_xmit = l2_packet_init(drv->ifname, NULL, ETH_P_EAPOL, | | 903 | drv->sock_xmit = l2_packet_init(drv->ifname, NULL, ETH_P_EAPOL, |
905 | handle_read, drv, 0); | | 904 | handle_read, drv, 0); |
906 | if (drv->sock_xmit == NULL) | | 905 | if (drv->sock_xmit == NULL) |
907 | goto bad; | | 906 | goto bad; |
908 | if (l2_packet_get_own_addr(drv->sock_xmit, params->own_addr)) | | 907 | if (l2_packet_get_own_addr(drv->sock_xmit, params->own_addr)) |
909 | goto bad; | | 908 | goto bad; |
910 | | | 909 | |
911 | /* mark down during setup */ | | 910 | /* mark down during setup */ |
912 | if (bsd_ctrl_iface(drv, 0) < 0) | | 911 | if (bsd_ctrl_iface(drv, 0) < 0) |
913 | goto bad; | | 912 | goto bad; |
914 | | | 913 | |
915 | if (bsd_set_mediaopt(drv, IFM_OMASK, IFM_IEEE80211_HOSTAP) < 0) { | | 914 | if (bsd_set_mediaopt(drv, IFM_OMASK, IFM_IEEE80211_HOSTAP) < 0) { |
916 | wpa_printf(MSG_ERROR, "%s: failed to set operation mode", | | 915 | wpa_printf(MSG_ERROR, "%s: failed to set operation mode", |
917 | __func__); | | 916 | __func__); |
918 | goto bad; | | 917 | goto bad; |
919 | } | | 918 | } |
920 | | | 919 | |
921 | dl_list_add(&drv->global->ifaces, &drv->list); | | 920 | dl_list_add(&drv->global->ifaces, &drv->list); |
922 | | | 921 | |
923 | return drv; | | 922 | return drv; |
924 | bad: | | 923 | bad: |
925 | if (drv->sock_xmit != NULL) | | 924 | if (drv->sock_xmit != NULL) |
926 | l2_packet_deinit(drv->sock_xmit); | | 925 | l2_packet_deinit(drv->sock_xmit); |
927 | os_free(drv); | | 926 | os_free(drv); |
928 | return NULL; | | 927 | return NULL; |
929 | } | | 928 | } |
930 | | | 929 | |
931 | | | 930 | |
932 | static void | | 931 | static void |
933 | bsd_deinit(void *priv) | | 932 | bsd_deinit(void *priv) |
934 | { | | 933 | { |
935 | struct bsd_driver_data *drv = priv; | | 934 | struct bsd_driver_data *drv = priv; |
936 | | | 935 | |
937 | if (drv->ifindex != 0) | | 936 | if (drv->ifindex != 0) |
938 | bsd_ctrl_iface(drv, 0); | | 937 | bsd_ctrl_iface(drv, 0); |
939 | if (drv->sock_xmit != NULL) | | 938 | if (drv->sock_xmit != NULL) |
940 | l2_packet_deinit(drv->sock_xmit); | | 939 | l2_packet_deinit(drv->sock_xmit); |
941 | os_free(drv); | | 940 | os_free(drv); |
942 | } | | 941 | } |
943 | | | 942 | |
944 | | | 943 | |
945 | static int | | 944 | static int |
946 | bsd_commit(void *priv) | | 945 | bsd_commit(void *priv) |
947 | { | | 946 | { |
948 | return bsd_ctrl_iface(priv, 1); | | 947 | return bsd_ctrl_iface(priv, 1); |
949 | } | | 948 | } |
950 | | | 949 | |
951 | | | 950 | |
952 | static int | | 951 | static int |
953 | bsd_set_sta_authorized(void *priv, const u8 *addr, | | 952 | bsd_set_sta_authorized(void *priv, const u8 *addr, |
954 | unsigned int total_flags, unsigned int flags_or, | | 953 | unsigned int total_flags, unsigned int flags_or, |
955 | unsigned int flags_and) | | 954 | unsigned int flags_and) |
956 | { | | 955 | { |
957 | int authorized = -1; | | 956 | int authorized = -1; |
958 | | | 957 | |
959 | /* For now, only support setting Authorized flag */ | | 958 | /* For now, only support setting Authorized flag */ |
960 | if (flags_or & WPA_STA_AUTHORIZED) | | 959 | if (flags_or & WPA_STA_AUTHORIZED) |
961 | authorized = 1; | | 960 | authorized = 1; |
962 | if (!(flags_and & WPA_STA_AUTHORIZED)) | | 961 | if (!(flags_and & WPA_STA_AUTHORIZED)) |
963 | authorized = 0; | | 962 | authorized = 0; |
964 | | | 963 | |
965 | if (authorized < 0) | | 964 | if (authorized < 0) |
966 | return 0; | | 965 | return 0; |
967 | | | 966 | |
968 | return bsd_send_mlme_param(priv, authorized ? | | 967 | return bsd_send_mlme_param(priv, authorized ? |
969 | IEEE80211_MLME_AUTHORIZE : | | 968 | IEEE80211_MLME_AUTHORIZE : |
970 | IEEE80211_MLME_UNAUTHORIZE, 0, addr); | | 969 | IEEE80211_MLME_UNAUTHORIZE, 0, addr); |
971 | } | | 970 | } |
972 | #else /* HOSTAPD */ | | 971 | #else /* HOSTAPD */ |
973 | | | 972 | |
974 | static int | | 973 | static int |
975 | get80211param(struct bsd_driver_data *drv, int op) | | 974 | get80211param(struct bsd_driver_data *drv, int op) |
976 | { | | 975 | { |
977 | struct ieee80211req ireq; | | 976 | struct ieee80211req ireq; |
978 | | | 977 | |
979 | if (bsd_get80211(drv, &ireq, op, NULL, 0) < 0) | | 978 | if (bsd_get80211(drv, &ireq, op, NULL, 0) < 0) |
980 | return -1; | | 979 | return -1; |
981 | return ireq.i_val; | | 980 | return ireq.i_val; |
982 | } | | 981 | } |
983 | | | 982 | |
984 | static int | | 983 | static int |
985 | wpa_driver_bsd_get_bssid(void *priv, u8 *bssid) | | 984 | wpa_driver_bsd_get_bssid(void *priv, u8 *bssid) |
986 | { | | 985 | { |
987 | struct bsd_driver_data *drv = priv; | | 986 | struct bsd_driver_data *drv = priv; |
988 | #ifdef SIOCG80211BSSID | | 987 | #ifdef SIOCG80211BSSID |
989 | struct ieee80211_bssid bs; | | 988 | struct ieee80211_bssid bs; |
990 | | | 989 | |
991 | os_strlcpy(bs.i_name, drv->ifname, sizeof(bs.i_name)); | | 990 | os_strlcpy(bs.i_name, drv->ifname, sizeof(bs.i_name)); |
992 | if (ioctl(drv->global->sock, SIOCG80211BSSID, &bs) < 0) | | 991 | if (ioctl(drv->global->sock, SIOCG80211BSSID, &bs) < 0) |
993 | return -1; | | 992 | return -1; |
994 | os_memcpy(bssid, bs.i_bssid, sizeof(bs.i_bssid)); | | 993 | os_memcpy(bssid, bs.i_bssid, sizeof(bs.i_bssid)); |
995 | return 0; | | 994 | return 0; |
996 | #else | | 995 | #else |
997 | return get80211var(drv, IEEE80211_IOC_BSSID, | | 996 | return get80211var(drv, IEEE80211_IOC_BSSID, |
998 | bssid, IEEE80211_ADDR_LEN) < 0 ? -1 : 0; | | 997 | bssid, IEEE80211_ADDR_LEN) < 0 ? -1 : 0; |
999 | #endif | | 998 | #endif |
1000 | } | | 999 | } |
1001 | | | 1000 | |
1002 | static int | | 1001 | static int |
1003 | wpa_driver_bsd_get_ssid(void *priv, u8 *ssid) | | 1002 | wpa_driver_bsd_get_ssid(void *priv, u8 *ssid) |
1004 | { | | 1003 | { |
1005 | struct bsd_driver_data *drv = priv; | | 1004 | struct bsd_driver_data *drv = priv; |
1006 | return bsd_get_ssid(drv, ssid, 0); | | 1005 | return bsd_get_ssid(drv, ssid, 0); |
1007 | } | | 1006 | } |
1008 | | | 1007 | |
1009 | static int | | 1008 | static int |
1010 | wpa_driver_bsd_set_wpa_ie(struct bsd_driver_data *drv, const u8 *wpa_ie, | | 1009 | wpa_driver_bsd_set_wpa_ie(struct bsd_driver_data *drv, const u8 *wpa_ie, |
1011 | size_t wpa_ie_len) | | 1010 | size_t wpa_ie_len) |
1012 | { | | 1011 | { |
1013 | #ifdef IEEE80211_IOC_APPIE | | 1012 | #ifdef IEEE80211_IOC_APPIE |
1014 | return bsd_set_opt_ie(drv, wpa_ie, wpa_ie_len); | | 1013 | return bsd_set_opt_ie(drv, wpa_ie, wpa_ie_len); |
1015 | #else /* IEEE80211_IOC_APPIE */ | | 1014 | #else /* IEEE80211_IOC_APPIE */ |
1016 | return set80211var(drv, IEEE80211_IOC_OPTIE, wpa_ie, wpa_ie_len); | | 1015 | return set80211var(drv, IEEE80211_IOC_OPTIE, wpa_ie, wpa_ie_len); |
1017 | #endif /* IEEE80211_IOC_APPIE */ | | 1016 | #endif /* IEEE80211_IOC_APPIE */ |
1018 | } | | 1017 | } |
1019 | | | 1018 | |
1020 | static int | | 1019 | static int |
1021 | wpa_driver_bsd_set_wpa_internal(void *priv, int wpa, int privacy) | | 1020 | wpa_driver_bsd_set_wpa_internal(void *priv, int wpa, int privacy) |
1022 | { | | 1021 | { |
1023 | int ret = 0; | | 1022 | int ret = 0; |
1024 | | | 1023 | |
1025 | wpa_printf(MSG_DEBUG, "%s: wpa=%d privacy=%d", | | 1024 | wpa_printf(MSG_DEBUG, "%s: wpa=%d privacy=%d", |
1026 | __func__, wpa, privacy); | | 1025 | __func__, wpa, privacy); |
1027 | | | 1026 | |
1028 | if (!wpa && wpa_driver_bsd_set_wpa_ie(priv, NULL, 0) < 0) | | 1027 | if (!wpa && wpa_driver_bsd_set_wpa_ie(priv, NULL, 0) < 0) |
1029 | ret = -1; | | 1028 | ret = -1; |
1030 | if (set80211param(priv, IEEE80211_IOC_PRIVACY, privacy) < 0) | | 1029 | if (set80211param(priv, IEEE80211_IOC_PRIVACY, privacy) < 0) |
1031 | ret = -1; | | 1030 | ret = -1; |
1032 | if (set80211param(priv, IEEE80211_IOC_WPA, wpa) < 0) | | 1031 | if (set80211param(priv, IEEE80211_IOC_WPA, wpa) < 0) |
1033 | ret = -1; | | 1032 | ret = -1; |
1034 | | | 1033 | |
1035 | return ret; | | 1034 | return ret; |
1036 | } | | 1035 | } |
1037 | | | 1036 | |
1038 | static int | | 1037 | static int |
1039 | wpa_driver_bsd_set_wpa(void *priv, int enabled) | | 1038 | wpa_driver_bsd_set_wpa(void *priv, int enabled) |
1040 | { | | 1039 | { |
1041 | wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled); | | 1040 | wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled); |
1042 | | | 1041 | |
1043 | return wpa_driver_bsd_set_wpa_internal(priv, enabled ? 3 : 0, enabled); | | 1042 | return wpa_driver_bsd_set_wpa_internal(priv, enabled ? 3 : 0, enabled); |
1044 | } | | 1043 | } |
1045 | | | 1044 | |
1046 | static int | | 1045 | static int |
1047 | wpa_driver_bsd_set_countermeasures(void *priv, int enabled) | | 1046 | wpa_driver_bsd_set_countermeasures(void *priv, int enabled) |
1048 | { | | 1047 | { |
1049 | wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled); | | 1048 | wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled); |
1050 | return set80211param(priv, IEEE80211_IOC_COUNTERMEASURES, enabled); | | 1049 | return set80211param(priv, IEEE80211_IOC_COUNTERMEASURES, enabled); |
1051 | } | | 1050 | } |
1052 | | | 1051 | |
1053 | | | 1052 | |
1054 | static int | | 1053 | static int |
1055 | wpa_driver_bsd_set_drop_unencrypted(void *priv, int enabled) | | 1054 | wpa_driver_bsd_set_drop_unencrypted(void *priv, int enabled) |
1056 | { | | 1055 | { |
1057 | wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled); | | 1056 | wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled); |
1058 | return set80211param(priv, IEEE80211_IOC_DROPUNENCRYPTED, enabled); | | 1057 | return set80211param(priv, IEEE80211_IOC_DROPUNENCRYPTED, enabled); |
1059 | } | | 1058 | } |
1060 | | | 1059 | |
1061 | static int | | 1060 | static int |
1062 | wpa_driver_bsd_deauthenticate(void *priv, const u8 *addr, int reason_code) | | 1061 | wpa_driver_bsd_deauthenticate(void *priv, const u8 *addr, int reason_code) |
1063 | { | | 1062 | { |
1064 | return bsd_send_mlme_param(priv, IEEE80211_MLME_DEAUTH, reason_code, | | 1063 | return bsd_send_mlme_param(priv, IEEE80211_MLME_DEAUTH, reason_code, |
1065 | addr); | | 1064 | addr); |
1066 | } | | 1065 | } |
1067 | | | 1066 | |
1068 | static int | | 1067 | static int |
1069 | wpa_driver_bsd_set_auth_alg(void *priv, int auth_alg) | | 1068 | wpa_driver_bsd_set_auth_alg(void *priv, int auth_alg) |
1070 | { | | 1069 | { |
1071 | int authmode; | | 1070 | int authmode; |
1072 | | | 1071 | |
1073 | if ((auth_alg & WPA_AUTH_ALG_OPEN) && | | 1072 | if ((auth_alg & WPA_AUTH_ALG_OPEN) && |
1074 | (auth_alg & WPA_AUTH_ALG_SHARED)) | | 1073 | (auth_alg & WPA_AUTH_ALG_SHARED)) |
1075 | authmode = IEEE80211_AUTH_AUTO; | | 1074 | authmode = IEEE80211_AUTH_AUTO; |
1076 | else if (auth_alg & WPA_AUTH_ALG_SHARED) | | 1075 | else if (auth_alg & WPA_AUTH_ALG_SHARED) |
1077 | authmode = IEEE80211_AUTH_SHARED; | | 1076 | authmode = IEEE80211_AUTH_SHARED; |
1078 | else | | 1077 | else |
1079 | authmode = IEEE80211_AUTH_OPEN; | | 1078 | authmode = IEEE80211_AUTH_OPEN; |
1080 | | | 1079 | |
1081 | return set80211param(priv, IEEE80211_IOC_AUTHMODE, authmode); | | 1080 | return set80211param(priv, IEEE80211_IOC_AUTHMODE, authmode); |
1082 | } | | 1081 | } |
1083 | | | 1082 | |
1084 | static void | | 1083 | static void |
1085 | handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len) | | 1084 | handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len) |
1086 | { | | 1085 | { |
1087 | struct bsd_driver_data *drv = ctx; | | 1086 | struct bsd_driver_data *drv = ctx; |
1088 | | | 1087 | |
1089 | drv_event_eapol_rx(drv->ctx, src_addr, buf, len); | | 1088 | drv_event_eapol_rx(drv->ctx, src_addr, buf, len); |
1090 | } | | 1089 | } |
1091 | | | 1090 | |
1092 | static int | | 1091 | static int |
1093 | wpa_driver_bsd_associate(void *priv, struct wpa_driver_associate_params *params) | | 1092 | wpa_driver_bsd_associate(void *priv, struct wpa_driver_associate_params *params) |
1094 | { | | 1093 | { |
1095 | struct bsd_driver_data *drv = priv; | | 1094 | struct bsd_driver_data *drv = priv; |
1096 | struct ieee80211req_mlme mlme; | | 1095 | struct ieee80211req_mlme mlme; |
1097 | u32 mode; | | 1096 | u32 mode; |
1098 | int privacy; | | 1097 | int privacy; |
1099 | int ret = 0; | | 1098 | int ret = 0; |
1100 | | | 1099 | |
1101 | wpa_printf(MSG_DEBUG, | | 1100 | wpa_printf(MSG_DEBUG, |
1102 | "%s: ssid '%.*s' wpa ie len %u pairwise %u group %u key mgmt %u" | | 1101 | "%s: ssid '%.*s' wpa ie len %u pairwise %u group %u key mgmt %u" |
1103 | , __func__ | | 1102 | , __func__ |
1104 | , (unsigned int) params->ssid_len, params->ssid | | 1103 | , (unsigned int) params->ssid_len, params->ssid |
1105 | , (unsigned int) params->wpa_ie_len | | 1104 | , (unsigned int) params->wpa_ie_len |
1106 | , params->pairwise_suite | | 1105 | , params->pairwise_suite |
1107 | , params->group_suite | | 1106 | , params->group_suite |
1108 | , params->key_mgmt_suite | | 1107 | , params->key_mgmt_suite |
1109 | ); | | 1108 | ); |
1110 | | | 1109 | |
1111 | switch (params->mode) { | | 1110 | switch (params->mode) { |
1112 | case IEEE80211_MODE_INFRA: | | 1111 | case IEEE80211_MODE_INFRA: |
1113 | mode = 0 /* STA */; | | 1112 | mode = 0 /* STA */; |
1114 | break; | | 1113 | break; |
1115 | case IEEE80211_MODE_IBSS: | | 1114 | case IEEE80211_MODE_IBSS: |
1116 | mode = IFM_IEEE80211_IBSS; | | 1115 | mode = IFM_IEEE80211_IBSS; |
1117 | break; | | 1116 | break; |
1118 | case IEEE80211_MODE_AP: | | 1117 | case IEEE80211_MODE_AP: |
1119 | mode = IFM_IEEE80211_HOSTAP; | | 1118 | mode = IFM_IEEE80211_HOSTAP; |
1120 | break; | | 1119 | break; |
1121 | default: | | 1120 | default: |
1122 | wpa_printf(MSG_ERROR, "%s: unknown operation mode", __func__); | | 1121 | wpa_printf(MSG_ERROR, "%s: unknown operation mode", __func__); |
1123 | return -1; | | 1122 | return -1; |
1124 | } | | 1123 | } |
1125 | if (bsd_set_mediaopt(drv, IFM_OMASK, mode) < 0) { | | 1124 | if (bsd_set_mediaopt(drv, IFM_OMASK, mode) < 0) { |
1126 | wpa_printf(MSG_ERROR, "%s: failed to set operation mode", | | 1125 | wpa_printf(MSG_ERROR, "%s: failed to set operation mode", |
1127 | __func__); | | 1126 | __func__); |
1128 | return -1; | | 1127 | return -1; |
1129 | } | | 1128 | } |
1130 | | | 1129 | |
1131 | if (params->mode == IEEE80211_MODE_AP) { | | 1130 | if (params->mode == IEEE80211_MODE_AP) { |
1132 | drv->sock_xmit = l2_packet_init(drv->ifname, NULL, ETH_P_EAPOL, | | 1131 | drv->sock_xmit = l2_packet_init(drv->ifname, NULL, ETH_P_EAPOL, |
1133 | handle_read, drv, 0); | | 1132 | handle_read, drv, 0); |
1134 | if (drv->sock_xmit == NULL) | | 1133 | if (drv->sock_xmit == NULL) |
1135 | return -1; | | 1134 | return -1; |
1136 | drv->is_ap = 1; | | 1135 | drv->is_ap = 1; |
1137 | return 0; | | 1136 | return 0; |
1138 | } | | 1137 | } |
1139 | | | 1138 | |
1140 | if (wpa_driver_bsd_set_drop_unencrypted(drv, params->drop_unencrypted) | | 1139 | if (wpa_driver_bsd_set_drop_unencrypted(drv, params->drop_unencrypted) |
1141 | < 0) | | 1140 | < 0) |
1142 | ret = -1; | | 1141 | ret = -1; |
1143 | if (wpa_driver_bsd_set_auth_alg(drv, params->auth_alg) < 0) | | 1142 | if (wpa_driver_bsd_set_auth_alg(drv, params->auth_alg) < 0) |
1144 | ret = -1; | | 1143 | ret = -1; |
1145 | /* XXX error handling is wrong but unclear what to do... */ | | 1144 | /* XXX error handling is wrong but unclear what to do... */ |
1146 | if (wpa_driver_bsd_set_wpa_ie(drv, params->wpa_ie, params->wpa_ie_len) < 0) | | 1145 | if (wpa_driver_bsd_set_wpa_ie(drv, params->wpa_ie, params->wpa_ie_len) < 0) |
1147 | return -1; | | 1146 | return -1; |
1148 | | | 1147 | |
1149 | privacy = !(params->pairwise_suite == WPA_CIPHER_NONE && | | 1148 | privacy = !(params->pairwise_suite == WPA_CIPHER_NONE && |
1150 | params->group_suite == WPA_CIPHER_NONE && | | 1149 | params->group_suite == WPA_CIPHER_NONE && |
1151 | params->key_mgmt_suite == WPA_KEY_MGMT_NONE && | | 1150 | params->key_mgmt_suite == WPA_KEY_MGMT_NONE && |
1152 | params->wpa_ie_len == 0); | | 1151 | params->wpa_ie_len == 0); |
1153 | wpa_printf(MSG_DEBUG, "%s: set PRIVACY %u", __func__, privacy); | | 1152 | wpa_printf(MSG_DEBUG, "%s: set PRIVACY %u", __func__, privacy); |
1154 | | | 1153 | |
1155 | if (set80211param(drv, IEEE80211_IOC_PRIVACY, privacy) < 0) | | 1154 | if (set80211param(drv, IEEE80211_IOC_PRIVACY, privacy) < 0) |
1156 | return -1; | | 1155 | return -1; |
1157 | | | 1156 | |
1158 | if (params->wpa_ie_len && | | 1157 | if (params->wpa_ie_len && |
1159 | set80211param(drv, IEEE80211_IOC_WPA, | | 1158 | set80211param(drv, IEEE80211_IOC_WPA, |
1160 | params->wpa_ie[0] == WLAN_EID_RSN ? 2 : 1) < 0) | | 1159 | params->wpa_ie[0] == WLAN_EID_RSN ? 2 : 1) < 0) |
1161 | return -1; | | 1160 | return -1; |
1162 | | | 1161 | |
1163 | os_memset(&mlme, 0, sizeof(mlme)); | | 1162 | os_memset(&mlme, 0, sizeof(mlme)); |
1164 | mlme.im_op = IEEE80211_MLME_ASSOC; | | 1163 | mlme.im_op = IEEE80211_MLME_ASSOC; |
1165 | if (params->ssid != NULL) | | 1164 | if (params->ssid != NULL) |
1166 | os_memcpy(mlme.im_ssid, params->ssid, params->ssid_len); | | 1165 | os_memcpy(mlme.im_ssid, params->ssid, params->ssid_len); |
1167 | mlme.im_ssid_len = params->ssid_len; | | 1166 | mlme.im_ssid_len = params->ssid_len; |
1168 | if (params->bssid != NULL) | | 1167 | if (params->bssid != NULL) |
1169 | os_memcpy(mlme.im_macaddr, params->bssid, IEEE80211_ADDR_LEN); | | 1168 | os_memcpy(mlme.im_macaddr, params->bssid, IEEE80211_ADDR_LEN); |
1170 | if (set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme)) < 0) | | 1169 | if (set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme)) < 0) |
1171 | return -1; | | 1170 | return -1; |
1172 | return ret; | | 1171 | return ret; |
1173 | } | | 1172 | } |
1174 | | | 1173 | |
1175 | static int | | 1174 | static int |
1176 | wpa_driver_bsd_scan(void *priv, struct wpa_driver_scan_params *params) | | 1175 | wpa_driver_bsd_scan(void *priv, struct wpa_driver_scan_params *params) |
1177 | { | | 1176 | { |
1178 | struct bsd_driver_data *drv = priv; | | 1177 | struct bsd_driver_data *drv = priv; |
1179 | #ifdef IEEE80211_IOC_SCAN_MAX_SSID | | 1178 | #ifdef IEEE80211_IOC_SCAN_MAX_SSID |
1180 | struct ieee80211_scan_req sr; | | 1179 | struct ieee80211_scan_req sr; |
1181 | int i; | | 1180 | int i; |
1182 | #endif /* IEEE80211_IOC_SCAN_MAX_SSID */ | | 1181 | #endif /* IEEE80211_IOC_SCAN_MAX_SSID */ |
1183 | | | 1182 | |
1184 | if (bsd_set_mediaopt(drv, IFM_OMASK, 0 /* STA */) < 0) { | | 1183 | if (bsd_set_mediaopt(drv, IFM_OMASK, 0 /* STA */) < 0) { |
1185 | wpa_printf(MSG_ERROR, "%s: failed to set operation mode", | | 1184 | wpa_printf(MSG_ERROR, "%s: failed to set operation mode", |
1186 | __func__); | | 1185 | __func__); |
1187 | return -1; | | 1186 | return -1; |
1188 | } | | 1187 | } |
1189 | | | 1188 | |
1190 | if (set80211param(drv, IEEE80211_IOC_ROAMING, | | 1189 | if (set80211param(drv, IEEE80211_IOC_ROAMING, |
1191 | IEEE80211_ROAMING_MANUAL) < 0) { | | 1190 | IEEE80211_ROAMING_MANUAL) < 0) { |
1192 | wpa_printf(MSG_ERROR, "%s: failed to set " | | 1191 | wpa_printf(MSG_ERROR, "%s: failed to set " |
1193 | "wpa_supplicant-based roaming: %s", __func__, | | 1192 | "wpa_supplicant-based roaming: %s", __func__, |
1194 | strerror(errno)); | | 1193 | strerror(errno)); |
1195 | return -1; | | 1194 | return -1; |
1196 | } | | 1195 | } |
1197 | | | 1196 | |
1198 | if (wpa_driver_bsd_set_wpa(drv, 1) < 0) { | | 1197 | if (wpa_driver_bsd_set_wpa(drv, 1) < 0) { |
1199 | wpa_printf(MSG_ERROR, "%s: failed to set wpa: %s", __func__, | | 1198 | wpa_printf(MSG_ERROR, "%s: failed to set wpa: %s", __func__, |
1200 | strerror(errno)); | | 1199 | strerror(errno)); |
1201 | return -1; | | 1200 | return -1; |
1202 | } | | 1201 | } |
1203 | | | 1202 | |
1204 | /* NB: interface must be marked UP to do a scan */ | | 1203 | /* NB: interface must be marked UP to do a scan */ |
1205 | if (bsd_ctrl_iface(drv, 1) < 0) | | 1204 | if (bsd_ctrl_iface(drv, 1) < 0) |
1206 | return -1; | | 1205 | return -1; |
1207 | | | 1206 | |
1208 | #ifdef IEEE80211_IOC_SCAN_MAX_SSID | | 1207 | #ifdef IEEE80211_IOC_SCAN_MAX_SSID |
1209 | os_memset(&sr, 0, sizeof(sr)); | | 1208 | os_memset(&sr, 0, sizeof(sr)); |
1210 | sr.sr_flags = IEEE80211_IOC_SCAN_ACTIVE | IEEE80211_IOC_SCAN_ONCE | | | 1209 | sr.sr_flags = IEEE80211_IOC_SCAN_ACTIVE | IEEE80211_IOC_SCAN_ONCE | |
1211 | IEEE80211_IOC_SCAN_NOJOIN; | | 1210 | IEEE80211_IOC_SCAN_NOJOIN; |
1212 | sr.sr_duration = IEEE80211_IOC_SCAN_FOREVER; | | 1211 | sr.sr_duration = IEEE80211_IOC_SCAN_FOREVER; |
1213 | if (params->num_ssids > 0) { | | 1212 | if (params->num_ssids > 0) { |
1214 | sr.sr_nssid = params->num_ssids; | | 1213 | sr.sr_nssid = params->num_ssids; |
1215 | #if 0 | | 1214 | #if 0 |
1216 | /* Boundary check is done by upper layer */ | | 1215 | /* Boundary check is done by upper layer */ |
1217 | if (sr.sr_nssid > IEEE80211_IOC_SCAN_MAX_SSID) | | 1216 | if (sr.sr_nssid > IEEE80211_IOC_SCAN_MAX_SSID) |
1218 | sr.sr_nssid = IEEE80211_IOC_SCAN_MAX_SSID; | | 1217 | sr.sr_nssid = IEEE80211_IOC_SCAN_MAX_SSID; |
1219 | #endif | | 1218 | #endif |
1220 | | | 1219 | |
1221 | /* NB: check scan cache first */ | | 1220 | /* NB: check scan cache first */ |
1222 | sr.sr_flags |= IEEE80211_IOC_SCAN_CHECK; | | 1221 | sr.sr_flags |= IEEE80211_IOC_SCAN_CHECK; |
1223 | } | | 1222 | } |
1224 | for (i = 0; i < sr.sr_nssid; i++) { | | 1223 | for (i = 0; i < sr.sr_nssid; i++) { |
1225 | sr.sr_ssid[i].len = params->ssids[i].ssid_len; | | 1224 | sr.sr_ssid[i].len = params->ssids[i].ssid_len; |
1226 | os_memcpy(sr.sr_ssid[i].ssid, params->ssids[i].ssid, | | 1225 | os_memcpy(sr.sr_ssid[i].ssid, params->ssids[i].ssid, |
1227 | sr.sr_ssid[i].len); | | 1226 | sr.sr_ssid[i].len); |
1228 | } | | 1227 | } |
1229 | | | 1228 | |
1230 | /* NB: net80211 delivers a scan complete event so no need to poll */ | | 1229 | /* NB: net80211 delivers a scan complete event so no need to poll */ |
1231 | return set80211var(drv, IEEE80211_IOC_SCAN_REQ, &sr, sizeof(sr)); | | 1230 | return set80211var(drv, IEEE80211_IOC_SCAN_REQ, &sr, sizeof(sr)); |
1232 | #else /* IEEE80211_IOC_SCAN_MAX_SSID */ | | 1231 | #else /* IEEE80211_IOC_SCAN_MAX_SSID */ |
1233 | /* set desired ssid before scan */ | | 1232 | /* set desired ssid before scan */ |
1234 | if (bsd_set_ssid(drv, params->ssids[0].ssid, | | 1233 | if (bsd_set_ssid(drv, params->ssids[0].ssid, |
1235 | params->ssids[0].ssid_len) < 0) | | 1234 | params->ssids[0].ssid_len) < 0) |
1236 | return -1; | | 1235 | return -1; |
1237 | | | 1236 | |
1238 | /* NB: net80211 delivers a scan complete event so no need to poll */ | | 1237 | /* NB: net80211 delivers a scan complete event so no need to poll */ |
1239 | return set80211param(drv, IEEE80211_IOC_SCAN_REQ, 0); | | 1238 | return set80211param(drv, IEEE80211_IOC_SCAN_REQ, 0); |
1240 | #endif /* IEEE80211_IOC_SCAN_MAX_SSID */ | | 1239 | #endif /* IEEE80211_IOC_SCAN_MAX_SSID */ |
1241 | } | | 1240 | } |
1242 | | | 1241 | |
1243 | static void | | 1242 | static void |
1244 | wpa_driver_bsd_event_receive(int sock, void *ctx, void *sock_ctx) | | 1243 | wpa_driver_bsd_event_receive(int sock, void *ctx, void *sock_ctx) |
1245 | { | | 1244 | { |
1246 | struct bsd_driver_global *global = sock_ctx; | | 1245 | struct bsd_driver_global *global = sock_ctx; |
1247 | struct bsd_driver_data *drv; | | 1246 | struct bsd_driver_data *drv; |
1248 | struct msghdr msg; | | 1247 | struct msghdr msg; |
1249 | struct if_announcemsghdr *ifan; | | 1248 | struct if_announcemsghdr *ifan; |
1250 | struct if_msghdr *ifm; | | 1249 | struct if_msghdr *ifm; |
1251 | struct rt_msghdr *rtm; | | 1250 | struct rt_msghdr *rtm; |
1252 | union wpa_event_data event; | | 1251 | union wpa_event_data event; |
1253 | struct ieee80211_michael_event *mic; | | 1252 | struct ieee80211_michael_event *mic; |
1254 | struct ieee80211_leave_event *leave; | | 1253 | struct ieee80211_leave_event *leave; |
1255 | struct ieee80211_join_event *join; | | 1254 | struct ieee80211_join_event *join; |
1256 | ssize_t n; | | 1255 | ssize_t n; |
1257 | | | 1256 | |
1258 | memset(&msg, 0, sizeof(msg)); | | 1257 | memset(&msg, 0, sizeof(msg)); |
1259 | msg.msg_iov = global->event_iov; | | 1258 | msg.msg_iov = global->event_iov; |
1260 | msg.msg_iovlen = 1; | | 1259 | msg.msg_iovlen = 1; |
1261 | n = recvmsg_realloc(sock, &msg, 0); | | 1260 | n = recvmsg_realloc(sock, &msg, 0); |
1262 | if (n < 0) { | | 1261 | if (n < 0) { |
1263 | if (errno != EINTR && errno != EAGAIN) | | 1262 | if (errno != EINTR && errno != EAGAIN) |
1264 | wpa_printf(MSG_ERROR, "%s read() failed: %s", | | 1263 | wpa_printf(MSG_ERROR, "%s read() failed: %s", |
1265 | __func__, strerror(errno)); | | 1264 | __func__, strerror(errno)); |
1266 | return; | | 1265 | return; |
1267 | } | | 1266 | } |
1268 | | | 1267 | |
1269 | rtm = (struct rt_msghdr *) global->event_iov[0].iov_base; | | 1268 | rtm = (struct rt_msghdr *) global->event_iov[0].iov_base; |
1270 | if (rtm->rtm_version != RTM_VERSION) { | | 1269 | if (rtm->rtm_version != RTM_VERSION) { |
1271 | wpa_printf(MSG_DEBUG, "Invalid routing message version=%d", | | 1270 | wpa_printf(MSG_DEBUG, "Invalid routing message version=%d", |
1272 | rtm->rtm_version); | | 1271 | rtm->rtm_version); |
1273 | return; | | 1272 | return; |
1274 | } | | 1273 | } |
1275 | os_memset(&event, 0, sizeof(event)); | | 1274 | os_memset(&event, 0, sizeof(event)); |
1276 | switch (rtm->rtm_type) { | | 1275 | switch (rtm->rtm_type) { |
1277 | case RTM_IFANNOUNCE: | | 1276 | case RTM_IFANNOUNCE: |
1278 | ifan = (struct if_announcemsghdr *) rtm; | | 1277 | ifan = (struct if_announcemsghdr *) rtm; |
1279 | switch (ifan->ifan_what) { | | 1278 | switch (ifan->ifan_what) { |
1280 | case IFAN_DEPARTURE: | | 1279 | case IFAN_DEPARTURE: |
1281 | drv = bsd_get_drvindex(global, ifan->ifan_index); | | 1280 | drv = bsd_get_drvindex(global, ifan->ifan_index); |
1282 | if (drv) | | 1281 | if (drv) |
1283 | drv->if_removed = 1; | | 1282 | drv->if_removed = 1; |
1284 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; | | 1283 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; |
1285 | break; | | 1284 | break; |
1286 | case IFAN_ARRIVAL: | | 1285 | case IFAN_ARRIVAL: |
1287 | drv = bsd_get_drvname(global, ifan->ifan_name); | | 1286 | drv = bsd_get_drvname(global, ifan->ifan_name); |
1288 | if (drv) { | | 1287 | if (drv) { |
1289 | drv->ifindex = ifan->ifan_index; | | 1288 | drv->ifindex = ifan->ifan_index; |
1290 | drv->if_removed = 0; | | 1289 | drv->if_removed = 0; |
1291 | } | | 1290 | } |
1292 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; | | 1291 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; |
1293 | break; | | 1292 | break; |
1294 | default: | | 1293 | default: |
1295 | wpa_printf(MSG_DEBUG, "RTM_IFANNOUNCE: unknown action"); | | 1294 | wpa_printf(MSG_DEBUG, "RTM_IFANNOUNCE: unknown action"); |
1296 | return; | | 1295 | return; |
1297 | } | | 1296 | } |
1298 | wpa_printf(MSG_DEBUG, "RTM_IFANNOUNCE: Interface '%s' %s", | | 1297 | wpa_printf(MSG_DEBUG, "RTM_IFANNOUNCE: Interface '%s' %s", |
1299 | ifan->ifan_name, | | 1298 | ifan->ifan_name, |
1300 | ifan->ifan_what == IFAN_DEPARTURE ? | | 1299 | ifan->ifan_what == IFAN_DEPARTURE ? |
1301 | "removed" : "added"); | | 1300 | "removed" : "added"); |
1302 | os_strlcpy(event.interface_status.ifname, ifan->ifan_name, | | 1301 | os_strlcpy(event.interface_status.ifname, ifan->ifan_name, |
1303 | sizeof(event.interface_status.ifname)); | | 1302 | sizeof(event.interface_status.ifname)); |
1304 | if (drv) { | | 1303 | if (drv) { |
1305 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, | | 1304 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, |
1306 | &event); | | 1305 | &event); |
1307 | /* | | 1306 | /* |
1308 | * Set ifindex to zero after sending the event as the | | 1307 | * Set ifindex to zero after sending the event as the |
1309 | * event might query the driver to ensure a match. | | 1308 | * event might query the driver to ensure a match. |
1310 | */ | | 1309 | */ |
1311 | if (ifan->ifan_what == IFAN_DEPARTURE) | | 1310 | if (ifan->ifan_what == IFAN_DEPARTURE) |
1312 | drv->ifindex = 0; | | 1311 | drv->ifindex = 0; |
1313 | } else { | | 1312 | } else { |
1314 | wpa_supplicant_event_global(global->ctx, | | 1313 | wpa_supplicant_event_global(global->ctx, |
1315 | EVENT_INTERFACE_STATUS, | | 1314 | EVENT_INTERFACE_STATUS, |
1316 | &event); | | 1315 | &event); |
1317 | } | | 1316 | } |
1318 | break; | | 1317 | break; |
1319 | case RTM_IEEE80211: | | 1318 | case RTM_IEEE80211: |
1320 | ifan = (struct if_announcemsghdr *) rtm; | | 1319 | ifan = (struct if_announcemsghdr *) rtm; |
1321 | drv = bsd_get_drvindex(global, ifan->ifan_index); | | 1320 | drv = bsd_get_drvindex(global, ifan->ifan_index); |
1322 | if (drv == NULL) | | 1321 | if (drv == NULL) |
1323 | return; | | 1322 | return; |
1324 | switch (ifan->ifan_what) { | | 1323 | switch (ifan->ifan_what) { |
1325 | case RTM_IEEE80211_ASSOC: | | 1324 | case RTM_IEEE80211_ASSOC: |
1326 | case RTM_IEEE80211_REASSOC: | | 1325 | case RTM_IEEE80211_REASSOC: |
1327 | if (drv->is_ap) | | 1326 | if (drv->is_ap) |
1328 | break; | | 1327 | break; |
1329 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC, NULL); | | 1328 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC, NULL); |
1330 | break; | | 1329 | break; |
1331 | case RTM_IEEE80211_DISASSOC: | | 1330 | case RTM_IEEE80211_DISASSOC: |
1332 | if (drv->is_ap) | | 1331 | if (drv->is_ap) |
1333 | break; | | 1332 | break; |
1334 | wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL); | | 1333 | wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL); |
1335 | break; | | 1334 | break; |
1336 | case RTM_IEEE80211_SCAN: | | 1335 | case RTM_IEEE80211_SCAN: |
1337 | if (drv->is_ap) | | 1336 | if (drv->is_ap) |
1338 | break; | | 1337 | break; |
1339 | wpa_supplicant_event(drv->ctx, EVENT_SCAN_RESULTS, | | 1338 | wpa_supplicant_event(drv->ctx, EVENT_SCAN_RESULTS, |
1340 | NULL); | | 1339 | NULL); |
1341 | break; | | 1340 | break; |
1342 | case RTM_IEEE80211_LEAVE: | | 1341 | case RTM_IEEE80211_LEAVE: |
1343 | leave = (struct ieee80211_leave_event *) &ifan[1]; | | 1342 | leave = (struct ieee80211_leave_event *) &ifan[1]; |
1344 | drv_event_disassoc(drv->ctx, leave->iev_addr); | | 1343 | drv_event_disassoc(drv->ctx, leave->iev_addr); |
1345 | break; | | 1344 | break; |
1346 | case RTM_IEEE80211_JOIN: | | 1345 | case RTM_IEEE80211_JOIN: |
1347 | #ifdef RTM_IEEE80211_REJOIN | | 1346 | #ifdef RTM_IEEE80211_REJOIN |
1348 | case RTM_IEEE80211_REJOIN: | | 1347 | case RTM_IEEE80211_REJOIN: |
1349 | #endif | | 1348 | #endif |
1350 | join = (struct ieee80211_join_event *) &ifan[1]; | | 1349 | join = (struct ieee80211_join_event *) &ifan[1]; |
1351 | bsd_new_sta(drv, drv->ctx, join->iev_addr); | | 1350 | bsd_new_sta(drv, drv->ctx, join->iev_addr); |
1352 | break; | | 1351 | break; |
1353 | case RTM_IEEE80211_REPLAY: | | 1352 | case RTM_IEEE80211_REPLAY: |
1354 | /* ignore */ | | 1353 | /* ignore */ |
1355 | break; | | 1354 | break; |
1356 | case RTM_IEEE80211_MICHAEL: | | 1355 | case RTM_IEEE80211_MICHAEL: |
1357 | mic = (struct ieee80211_michael_event *) &ifan[1]; | | 1356 | mic = (struct ieee80211_michael_event *) &ifan[1]; |
1358 | wpa_printf(MSG_DEBUG, | | 1357 | wpa_printf(MSG_DEBUG, |
1359 | "Michael MIC failure wireless event: " | | 1358 | "Michael MIC failure wireless event: " |
1360 | "keyix=%u src_addr=" MACSTR, mic->iev_keyix, | | 1359 | "keyix=%u src_addr=" MACSTR, mic->iev_keyix, |
1361 | MAC2STR(mic->iev_src)); | | 1360 | MAC2STR(mic->iev_src)); |
1362 | | | 1361 | |
1363 | os_memset(&event, 0, sizeof(event)); | | 1362 | os_memset(&event, 0, sizeof(event)); |
1364 | event.michael_mic_failure.unicast = | | 1363 | event.michael_mic_failure.unicast = |
1365 | !IEEE80211_IS_MULTICAST(mic->iev_dst); | | 1364 | !IEEE80211_IS_MULTICAST(mic->iev_dst); |
1366 | wpa_supplicant_event(drv->ctx, | | 1365 | wpa_supplicant_event(drv->ctx, |
1367 | EVENT_MICHAEL_MIC_FAILURE, &event); | | 1366 | EVENT_MICHAEL_MIC_FAILURE, &event); |
1368 | break; | | 1367 | break; |
1369 | } | | 1368 | } |
1370 | break; | | 1369 | break; |
1371 | case RTM_IFINFO: | | 1370 | case RTM_IFINFO: |
1372 | ifm = (struct if_msghdr *) rtm; | | 1371 | ifm = (struct if_msghdr *) rtm; |
1373 | drv = bsd_get_drvindex(global, ifm->ifm_index); | | 1372 | drv = bsd_get_drvindex(global, ifm->ifm_index); |
1374 | if (drv == NULL) | | 1373 | if (drv == NULL) |
1375 | return; | | 1374 | return; |
1376 | if ((ifm->ifm_flags & IFF_UP) == 0 && | | 1375 | if ((ifm->ifm_flags & IFF_UP) == 0 && |
1377 | (drv->flags & IFF_UP) != 0) { | | 1376 | (drv->flags & IFF_UP) != 0) { |
1378 | wpa_printf(MSG_DEBUG, "RTM_IFINFO: Interface '%s' DOWN", | | 1377 | wpa_printf(MSG_DEBUG, "RTM_IFINFO: Interface '%s' DOWN", |
1379 | drv->ifname); | | 1378 | drv->ifname); |
1380 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, | | 1379 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, |
1381 | NULL); | | 1380 | NULL); |
1382 | } else if ((ifm->ifm_flags & IFF_UP) != 0 && | | 1381 | } else if ((ifm->ifm_flags & IFF_UP) != 0 && |
1383 | (drv->flags & IFF_UP) == 0) { | | 1382 | (drv->flags & IFF_UP) == 0) { |
1384 | wpa_printf(MSG_DEBUG, "RTM_IFINFO: Interface '%s' UP", | | 1383 | wpa_printf(MSG_DEBUG, "RTM_IFINFO: Interface '%s' UP", |
1385 | drv->ifname); | | 1384 | drv->ifname); |
1386 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, | | 1385 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, |
1387 | NULL); | | 1386 | NULL); |
1388 | } | | 1387 | } |
1389 | drv->flags = ifm->ifm_flags; | | 1388 | drv->flags = ifm->ifm_flags; |
1390 | break; | | 1389 | break; |
1391 | } | | 1390 | } |
1392 | } | | 1391 | } |
1393 | | | 1392 | |
1394 | static void | | 1393 | static void |
1395 | wpa_driver_bsd_add_scan_entry(struct wpa_scan_results *res, | | 1394 | wpa_driver_bsd_add_scan_entry(struct wpa_scan_results *res, |
1396 | struct ieee80211req_scan_result *sr) | | 1395 | struct ieee80211req_scan_result *sr) |
1397 | { | | 1396 | { |
1398 | struct wpa_scan_res *result, **tmp; | | 1397 | struct wpa_scan_res *result, **tmp; |
1399 | size_t extra_len; | | 1398 | size_t extra_len; |
1400 | u8 *pos; | | 1399 | u8 *pos; |
1401 | | | 1400 | |
1402 | extra_len = 2 + sr->isr_ssid_len; | | 1401 | extra_len = 2 + sr->isr_ssid_len; |
1403 | extra_len += 2 + sr->isr_nrates; | | 1402 | extra_len += 2 + sr->isr_nrates; |
1404 | extra_len += 3; /* ERP IE */ | | 1403 | extra_len += 3; /* ERP IE */ |
1405 | extra_len += sr->isr_ie_len; | | 1404 | extra_len += sr->isr_ie_len; |
1406 | | | 1405 | |
1407 | result = os_zalloc(sizeof(*result) + extra_len); | | 1406 | result = os_zalloc(sizeof(*result) + extra_len); |
1408 | if (result == NULL) | | 1407 | if (result == NULL) |
1409 | return; | | 1408 | return; |
1410 | os_memcpy(result->bssid, sr->isr_bssid, ETH_ALEN); | | 1409 | os_memcpy(result->bssid, sr->isr_bssid, ETH_ALEN); |
1411 | result->freq = sr->isr_freq; | | 1410 | result->freq = sr->isr_freq; |
1412 | result->beacon_int = sr->isr_intval; | | 1411 | result->beacon_int = sr->isr_intval; |
1413 | result->caps = sr->isr_capinfo; | | 1412 | result->caps = sr->isr_capinfo; |
1414 | result->qual = sr->isr_rssi; | | 1413 | result->qual = sr->isr_rssi; |
1415 | result->noise = sr->isr_noise; | | 1414 | result->noise = sr->isr_noise; |
1416 | | | 1415 | |
1417 | #ifdef __FreeBSD__ | | 1416 | #ifdef __FreeBSD__ |
1418 | /* | | 1417 | /* |
1419 | * the rssi value reported by the kernel is in 0.5dB steps relative to | | 1418 | * the rssi value reported by the kernel is in 0.5dB steps relative to |
1420 | * the reported noise floor. see ieee80211_node.h for details. | | 1419 | * the reported noise floor. see ieee80211_node.h for details. |
1421 | */ | | 1420 | */ |
1422 | result->level = sr->isr_rssi / 2 + sr->isr_noise; | | 1421 | result->level = sr->isr_rssi / 2 + sr->isr_noise; |
1423 | #else | | 1422 | #else |
1424 | result->level = sr->isr_rssi; | | 1423 | result->level = sr->isr_rssi; |
1425 | #endif | | 1424 | #endif |
1426 | | | 1425 | |
1427 | pos = (u8 *)(result + 1); | | 1426 | pos = (u8 *)(result + 1); |
1428 | | | 1427 | |
1429 | *pos++ = WLAN_EID_SSID; | | 1428 | *pos++ = WLAN_EID_SSID; |
1430 | *pos++ = sr->isr_ssid_len; | | 1429 | *pos++ = sr->isr_ssid_len; |
1431 | os_memcpy(pos, sr + 1, sr->isr_ssid_len); | | 1430 | os_memcpy(pos, sr + 1, sr->isr_ssid_len); |
1432 | pos += sr->isr_ssid_len; | | 1431 | pos += sr->isr_ssid_len; |
1433 | | | 1432 | |
1434 | /* | | 1433 | /* |
1435 | * Deal all rates as supported rate. | | 1434 | * Deal all rates as supported rate. |
1436 | * Because net80211 doesn't report extended supported rate or not. | | 1435 | * Because net80211 doesn't report extended supported rate or not. |
1437 | */ | | 1436 | */ |
1438 | *pos++ = WLAN_EID_SUPP_RATES; | | 1437 | *pos++ = WLAN_EID_SUPP_RATES; |
1439 | *pos++ = sr->isr_nrates; | | 1438 | *pos++ = sr->isr_nrates; |
1440 | os_memcpy(pos, sr->isr_rates, sr->isr_nrates); | | 1439 | os_memcpy(pos, sr->isr_rates, sr->isr_nrates); |
1441 | pos += sr->isr_nrates; | | 1440 | pos += sr->isr_nrates; |
1442 | | | 1441 | |
1443 | *pos++ = WLAN_EID_ERP_INFO; | | 1442 | *pos++ = WLAN_EID_ERP_INFO; |
1444 | *pos++ = 1; | | 1443 | *pos++ = 1; |
1445 | *pos++ = sr->isr_erp; | | 1444 | *pos++ = sr->isr_erp; |
1446 | | | 1445 | |
1447 | #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) | | 1446 | #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) |
1448 | os_memcpy(pos, (u8 *)(sr + 1) + sr->isr_ssid_len + sr->isr_meshid_len, | | 1447 | os_memcpy(pos, (u8 *)(sr + 1) + sr->isr_ssid_len + sr->isr_meshid_len, |
1449 | sr->isr_ie_len); | | 1448 | sr->isr_ie_len); |
1450 | #else | | 1449 | #else |
1451 | os_memcpy(pos, (u8 *)(sr + 1) + sr->isr_ssid_len, sr->isr_ie_len); | | 1450 | os_memcpy(pos, (u8 *)(sr + 1) + sr->isr_ssid_len, sr->isr_ie_len); |
1452 | #endif | | 1451 | #endif |
1453 | pos += sr->isr_ie_len; | | 1452 | pos += sr->isr_ie_len; |
1454 | | | 1453 | |
1455 | result->ie_len = pos - (u8 *)(result + 1); | | 1454 | result->ie_len = pos - (u8 *)(result + 1); |
1456 | | | 1455 | |
1457 | tmp = os_realloc_array(res->res, res->num + 1, | | 1456 | tmp = os_realloc_array(res->res, res->num + 1, |
1458 | sizeof(struct wpa_scan_res *)); | | 1457 | sizeof(struct wpa_scan_res *)); |
1459 | if (tmp == NULL) { | | 1458 | if (tmp == NULL) { |
1460 | os_free(result); | | 1459 | os_free(result); |
1461 | return; | | 1460 | return; |
1462 | } | | 1461 | } |
1463 | tmp[res->num++] = result; | | 1462 | tmp[res->num++] = result; |
1464 | res->res = tmp; | | 1463 | res->res = tmp; |
1465 | } | | 1464 | } |
1466 | | | 1465 | |
1467 | struct wpa_scan_results * | | 1466 | struct wpa_scan_results * |
1468 | wpa_driver_bsd_get_scan_results2(void *priv) | | 1467 | wpa_driver_bsd_get_scan_results2(void *priv) |
1469 | { | | 1468 | { |
1470 | struct ieee80211req_scan_result *sr; | | 1469 | struct ieee80211req_scan_result *sr; |
1471 | struct wpa_scan_results *res; | | 1470 | struct wpa_scan_results *res; |
1472 | int len, rest; | | 1471 | int len, rest; |
1473 | uint8_t buf[24*1024], *pos; | | 1472 | uint8_t buf[24*1024], *pos; |
1474 | | | 1473 | |
1475 | len = get80211var(priv, IEEE80211_IOC_SCAN_RESULTS, buf, 24*1024); | | 1474 | len = get80211var(priv, IEEE80211_IOC_SCAN_RESULTS, buf, 24*1024); |
1476 | if (len < 0) | | 1475 | if (len < 0) |
1477 | return NULL; | | 1476 | return NULL; |
1478 | | | 1477 | |
1479 | res = os_zalloc(sizeof(*res)); | | 1478 | res = os_zalloc(sizeof(*res)); |
1480 | if (res == NULL) | | 1479 | if (res == NULL) |
1481 | return NULL; | | 1480 | return NULL; |
1482 | | | 1481 | |
1483 | pos = buf; | | 1482 | pos = buf; |
1484 | rest = len; | | 1483 | rest = len; |
1485 | while (rest >= sizeof(struct ieee80211req_scan_result)) { | | 1484 | while (rest >= sizeof(struct ieee80211req_scan_result)) { |
1486 | sr = (struct ieee80211req_scan_result *)pos; | | 1485 | sr = (struct ieee80211req_scan_result *)pos; |
1487 | wpa_driver_bsd_add_scan_entry(res, sr); | | 1486 | wpa_driver_bsd_add_scan_entry(res, sr); |
1488 | pos += sr->isr_len; | | 1487 | pos += sr->isr_len; |
1489 | rest -= sr->isr_len; | | 1488 | rest -= sr->isr_len; |
1490 | } | | 1489 | } |
1491 | | | 1490 | |
1492 | wpa_printf(MSG_DEBUG, "Received %d bytes of scan results (%lu BSSes)", | | 1491 | wpa_printf(MSG_DEBUG, "Received %d bytes of scan results (%lu BSSes)", |
1493 | len, (unsigned long)res->num); | | 1492 | len, (unsigned long)res->num); |
1494 | | | 1493 | |
1495 | return res; | | 1494 | return res; |
1496 | } | | 1495 | } |
1497 | | | 1496 | |
1498 | static int wpa_driver_bsd_capa(struct bsd_driver_data *drv) | | 1497 | static int wpa_driver_bsd_capa(struct bsd_driver_data *drv) |
1499 | { | | 1498 | { |
1500 | #ifdef IEEE80211_IOC_DEVCAPS | | 1499 | #ifdef IEEE80211_IOC_DEVCAPS |
1501 | /* kernel definitions copied from net80211/ieee80211_var.h */ | | 1500 | /* kernel definitions copied from net80211/ieee80211_var.h */ |
1502 | #define IEEE80211_CIPHER_WEP 0 | | 1501 | #define IEEE80211_CIPHER_WEP 0 |
1503 | #define IEEE80211_CIPHER_TKIP 1 | | 1502 | #define IEEE80211_CIPHER_TKIP 1 |
1504 | #define IEEE80211_CIPHER_AES_CCM 3 | | 1503 | #define IEEE80211_CIPHER_AES_CCM 3 |
1505 | #define IEEE80211_CRYPTO_WEP (1<<IEEE80211_CIPHER_WEP) | | 1504 | #define IEEE80211_CRYPTO_WEP (1<<IEEE80211_CIPHER_WEP) |
1506 | #define IEEE80211_CRYPTO_TKIP (1<<IEEE80211_CIPHER_TKIP) | | 1505 | #define IEEE80211_CRYPTO_TKIP (1<<IEEE80211_CIPHER_TKIP) |
1507 | #define IEEE80211_CRYPTO_AES_CCM (1<<IEEE80211_CIPHER_AES_CCM) | | 1506 | #define IEEE80211_CRYPTO_AES_CCM (1<<IEEE80211_CIPHER_AES_CCM) |
1508 | #define IEEE80211_C_HOSTAP 0x00000400 /* CAPABILITY: HOSTAP avail */ | | 1507 | #define IEEE80211_C_HOSTAP 0x00000400 /* CAPABILITY: HOSTAP avail */ |
1509 | #define IEEE80211_C_WPA1 0x00800000 /* CAPABILITY: WPA1 avail */ | | 1508 | #define IEEE80211_C_WPA1 0x00800000 /* CAPABILITY: WPA1 avail */ |
1510 | #define IEEE80211_C_WPA2 0x01000000 /* CAPABILITY: WPA2 avail */ | | 1509 | #define IEEE80211_C_WPA2 0x01000000 /* CAPABILITY: WPA2 avail */ |
1511 | struct ieee80211_devcaps_req devcaps; | | 1510 | struct ieee80211_devcaps_req devcaps; |
1512 | | | 1511 | |
1513 | if (get80211var(drv, IEEE80211_IOC_DEVCAPS, &devcaps, | | 1512 | if (get80211var(drv, IEEE80211_IOC_DEVCAPS, &devcaps, |
1514 | sizeof(devcaps)) < 0) { | | 1513 | sizeof(devcaps)) < 0) { |
1515 | wpa_printf(MSG_ERROR, "failed to IEEE80211_IOC_DEVCAPS: %s", | | 1514 | wpa_printf(MSG_ERROR, "failed to IEEE80211_IOC_DEVCAPS: %s", |
1516 | strerror(errno)); | | 1515 | strerror(errno)); |
1517 | return -1; | | 1516 | return -1; |
1518 | } | | 1517 | } |
1519 | | | 1518 | |
1520 | wpa_printf(MSG_DEBUG, "%s: drivercaps=0x%08x,cryptocaps=0x%08x", | | 1519 | wpa_printf(MSG_DEBUG, "%s: drivercaps=0x%08x,cryptocaps=0x%08x", |
1521 | __func__, devcaps.dc_drivercaps, devcaps.dc_cryptocaps); | | 1520 | __func__, devcaps.dc_drivercaps, devcaps.dc_cryptocaps); |
1522 | | | 1521 | |
1523 | if (devcaps.dc_drivercaps & IEEE80211_C_WPA1) | | 1522 | if (devcaps.dc_drivercaps & IEEE80211_C_WPA1) |
1524 | drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA | | | 1523 | drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA | |
1525 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK; | | 1524 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK; |
1526 | if (devcaps.dc_drivercaps & IEEE80211_C_WPA2) | | 1525 | if (devcaps.dc_drivercaps & IEEE80211_C_WPA2) |
1527 | drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | | | 1526 | drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | |
1528 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK; | | 1527 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK; |
1529 | | | 1528 | |
1530 | if (devcaps.dc_cryptocaps & IEEE80211_CRYPTO_WEP) | | 1529 | if (devcaps.dc_cryptocaps & IEEE80211_CRYPTO_WEP) |
1531 | drv->capa.enc |= WPA_DRIVER_CAPA_ENC_WEP40 | | | 1530 | drv->capa.enc |= WPA_DRIVER_CAPA_ENC_WEP40 | |
1532 | WPA_DRIVER_CAPA_ENC_WEP104; | | 1531 | WPA_DRIVER_CAPA_ENC_WEP104; |
1533 | if (devcaps.dc_cryptocaps & IEEE80211_CRYPTO_TKIP) | | 1532 | if (devcaps.dc_cryptocaps & IEEE80211_CRYPTO_TKIP) |
1534 | drv->capa.enc |= WPA_DRIVER_CAPA_ENC_TKIP; | | 1533 | drv->capa.enc |= WPA_DRIVER_CAPA_ENC_TKIP; |
1535 | if (devcaps.dc_cryptocaps & IEEE80211_CRYPTO_AES_CCM) | | 1534 | if (devcaps.dc_cryptocaps & IEEE80211_CRYPTO_AES_CCM) |
1536 | drv->capa.enc |= WPA_DRIVER_CAPA_ENC_CCMP; | | 1535 | drv->capa.enc |= WPA_DRIVER_CAPA_ENC_CCMP; |
1537 | | | 1536 | |
1538 | if (devcaps.dc_drivercaps & IEEE80211_C_HOSTAP) | | 1537 | if (devcaps.dc_drivercaps & IEEE80211_C_HOSTAP) |
1539 | drv->capa.flags |= WPA_DRIVER_FLAGS_AP; | | 1538 | drv->capa.flags |= WPA_DRIVER_FLAGS_AP; |
1540 | #undef IEEE80211_CIPHER_WEP | | 1539 | #undef IEEE80211_CIPHER_WEP |
1541 | #undef IEEE80211_CIPHER_TKIP | | 1540 | #undef IEEE80211_CIPHER_TKIP |
1542 | #undef IEEE80211_CIPHER_AES_CCM | | 1541 | #undef IEEE80211_CIPHER_AES_CCM |
1543 | #undef IEEE80211_CRYPTO_WEP | | 1542 | #undef IEEE80211_CRYPTO_WEP |
1544 | #undef IEEE80211_CRYPTO_TKIP | | 1543 | #undef IEEE80211_CRYPTO_TKIP |
1545 | #undef IEEE80211_CRYPTO_AES_CCM | | 1544 | #undef IEEE80211_CRYPTO_AES_CCM |
1546 | #undef IEEE80211_C_HOSTAP | | 1545 | #undef IEEE80211_C_HOSTAP |
1547 | #undef IEEE80211_C_WPA1 | | 1546 | #undef IEEE80211_C_WPA1 |
1548 | #undef IEEE80211_C_WPA2 | | 1547 | #undef IEEE80211_C_WPA2 |
1549 | #else /* IEEE80211_IOC_DEVCAPS */ | | 1548 | #else /* IEEE80211_IOC_DEVCAPS */ |
1550 | /* For now, assume TKIP, CCMP, WPA, WPA2 are supported */ | | 1549 | /* For now, assume TKIP, CCMP, WPA, WPA2 are supported */ |
1551 | drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA | | | 1550 | drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA | |
1552 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | | | 1551 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | |
1553 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | | | 1552 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | |
1554 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK; | | 1553 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK; |
1555 | drv->capa.enc = WPA_DRIVER_CAPA_ENC_WEP40 | | | 1554 | drv->capa.enc = WPA_DRIVER_CAPA_ENC_WEP40 | |
1556 | WPA_DRIVER_CAPA_ENC_WEP104 | | | 1555 | WPA_DRIVER_CAPA_ENC_WEP104 | |
1557 | WPA_DRIVER_CAPA_ENC_TKIP | | | 1556 | WPA_DRIVER_CAPA_ENC_TKIP | |
1558 | WPA_DRIVER_CAPA_ENC_CCMP; | | 1557 | WPA_DRIVER_CAPA_ENC_CCMP; |
1559 | drv->capa.flags |= WPA_DRIVER_FLAGS_AP; | | 1558 | drv->capa.flags |= WPA_DRIVER_FLAGS_AP; |
1560 | #endif /* IEEE80211_IOC_DEVCAPS */ | | 1559 | #endif /* IEEE80211_IOC_DEVCAPS */ |
1561 | #ifdef IEEE80211_IOC_SCAN_MAX_SSID | | 1560 | #ifdef IEEE80211_IOC_SCAN_MAX_SSID |
1562 | drv->capa.max_scan_ssids = IEEE80211_IOC_SCAN_MAX_SSID; | | 1561 | drv->capa.max_scan_ssids = IEEE80211_IOC_SCAN_MAX_SSID; |
1563 | #else /* IEEE80211_IOC_SCAN_MAX_SSID */ | | 1562 | #else /* IEEE80211_IOC_SCAN_MAX_SSID */ |
1564 | drv->capa.max_scan_ssids = 1; | | 1563 | drv->capa.max_scan_ssids = 1; |
1565 | #endif /* IEEE80211_IOC_SCAN_MAX_SSID */ | | 1564 | #endif /* IEEE80211_IOC_SCAN_MAX_SSID */ |
1566 | drv->capa.auth = WPA_DRIVER_AUTH_OPEN | | | 1565 | drv->capa.auth = WPA_DRIVER_AUTH_OPEN | |
1567 | WPA_DRIVER_AUTH_SHARED | | | 1566 | WPA_DRIVER_AUTH_SHARED | |
1568 | WPA_DRIVER_AUTH_LEAP; | | 1567 | WPA_DRIVER_AUTH_LEAP; |
1569 | return 0; | | 1568 | return 0; |
1570 | } | | 1569 | } |
1571 | | | 1570 | |
1572 | static enum ieee80211_opmode | | 1571 | static enum ieee80211_opmode |
1573 | get80211opmode(struct bsd_driver_data *drv) | | 1572 | get80211opmode(struct bsd_driver_data *drv) |
1574 | { | | 1573 | { |
1575 | struct ifmediareq ifmr; | | 1574 | struct ifmediareq ifmr; |
1576 | | | 1575 | |
1577 | (void) memset(&ifmr, 0, sizeof(ifmr)); | | 1576 | (void) memset(&ifmr, 0, sizeof(ifmr)); |
1578 | (void) os_strlcpy(ifmr.ifm_name, drv->ifname, sizeof(ifmr.ifm_name)); | | 1577 | (void) os_strlcpy(ifmr.ifm_name, drv->ifname, sizeof(ifmr.ifm_name)); |
1579 | | | 1578 | |
1580 | if (ioctl(drv->global->sock, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0) { | | 1579 | if (ioctl(drv->global->sock, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0) { |
1581 | if (ifmr.ifm_current & IFM_IEEE80211_ADHOC) { | | 1580 | if (ifmr.ifm_current & IFM_IEEE80211_ADHOC) { |
1582 | if (ifmr.ifm_current & IFM_FLAG0) | | 1581 | if (ifmr.ifm_current & IFM_FLAG0) |
1583 | return IEEE80211_M_AHDEMO; | | 1582 | return IEEE80211_M_AHDEMO; |
1584 | else | | 1583 | else |
1585 | return IEEE80211_M_IBSS; | | 1584 | return IEEE80211_M_IBSS; |
1586 | } | | 1585 | } |
1587 | if (ifmr.ifm_current & IFM_IEEE80211_HOSTAP) | | 1586 | if (ifmr.ifm_current & IFM_IEEE80211_HOSTAP) |
1588 | return IEEE80211_M_HOSTAP; | | 1587 | return IEEE80211_M_HOSTAP; |
1589 | if (ifmr.ifm_current & IFM_IEEE80211_MONITOR) | | 1588 | if (ifmr.ifm_current & IFM_IEEE80211_MONITOR) |
1590 | return IEEE80211_M_MONITOR; | | 1589 | return IEEE80211_M_MONITOR; |
1591 | #ifdef IEEE80211_M_MBSS | | 1590 | #ifdef IEEE80211_M_MBSS |
1592 | if (ifmr.ifm_current & IFM_IEEE80211_MBSS) | | 1591 | if (ifmr.ifm_current & IFM_IEEE80211_MBSS) |
1593 | return IEEE80211_M_MBSS; | | 1592 | return IEEE80211_M_MBSS; |
1594 | #endif /* IEEE80211_M_MBSS */ | | 1593 | #endif /* IEEE80211_M_MBSS */ |
1595 | } | | 1594 | } |
1596 | return IEEE80211_M_STA; | | 1595 | return IEEE80211_M_STA; |
1597 | } | | 1596 | } |
1598 | | | 1597 | |
1599 | static void * | | 1598 | static void * |
1600 | wpa_driver_bsd_init(void *ctx, const char *ifname, void *priv) | | 1599 | wpa_driver_bsd_init(void *ctx, const char *ifname, void *priv) |
1601 | { | | 1600 | { |
1602 | #define GETPARAM(drv, param, v) \ | | 1601 | #define GETPARAM(drv, param, v) \ |
1603 | (((v) = get80211param(drv, param)) != -1) | | 1602 | (((v) = get80211param(drv, param)) != -1) |
1604 | struct bsd_driver_data *drv; | | 1603 | struct bsd_driver_data *drv; |
1605 | | | 1604 | |
1606 | drv = os_zalloc(sizeof(*drv)); | | 1605 | drv = os_zalloc(sizeof(*drv)); |
1607 | if (drv == NULL) | | 1606 | if (drv == NULL) |
1608 | return NULL; | | 1607 | return NULL; |
1609 | | | 1608 | |
1610 | /* | | 1609 | /* |
1611 | * NB: We require the interface name be mappable to an index. | | 1610 | * NB: We require the interface name be mappable to an index. |
1612 | * This implies we do not support having wpa_supplicant | | 1611 | * This implies we do not support having wpa_supplicant |
1613 | * wait for an interface to appear. This seems ok; that | | 1612 | * wait for an interface to appear. This seems ok; that |
1614 | * doesn't belong here; it's really the job of devd. | | 1613 | * doesn't belong here; it's really the job of devd. |
1615 | */ | | 1614 | */ |
1616 | drv->ifindex = if_nametoindex(ifname); | | 1615 | drv->ifindex = if_nametoindex(ifname); |
1617 | if (drv->ifindex == 0) { | | 1616 | if (drv->ifindex == 0) { |
1618 | wpa_printf(MSG_DEBUG, "%s: interface %s does not exist", | | 1617 | wpa_printf(MSG_DEBUG, "%s: interface %s does not exist", |
1619 | __func__, ifname); | | 1618 | __func__, ifname); |
1620 | goto fail; | | 1619 | goto fail; |
1621 | } | | 1620 | } |
1622 | | | 1621 | |
1623 | drv->ctx = ctx; | | 1622 | drv->ctx = ctx; |
1624 | drv->global = priv; | | 1623 | drv->global = priv; |
1625 | os_strlcpy(drv->ifname, ifname, sizeof(drv->ifname)); | | 1624 | os_strlcpy(drv->ifname, ifname, sizeof(drv->ifname)); |
1626 | | | 1625 | |
1627 | if (!GETPARAM(drv, IEEE80211_IOC_ROAMING, drv->prev_roaming)) { | | 1626 | if (!GETPARAM(drv, IEEE80211_IOC_ROAMING, drv->prev_roaming)) { |
1628 | wpa_printf(MSG_DEBUG, "%s: failed to get roaming state: %s", | | 1627 | wpa_printf(MSG_DEBUG, "%s: failed to get roaming state: %s", |
1629 | __func__, strerror(errno)); | | 1628 | __func__, strerror(errno)); |
1630 | goto fail; | | 1629 | goto fail; |
1631 | } | | 1630 | } |
1632 | if (!GETPARAM(drv, IEEE80211_IOC_PRIVACY, drv->prev_privacy)) { | | 1631 | if (!GETPARAM(drv, IEEE80211_IOC_PRIVACY, drv->prev_privacy)) { |
1633 | wpa_printf(MSG_DEBUG, "%s: failed to get privacy state: %s", | | 1632 | wpa_printf(MSG_DEBUG, "%s: failed to get privacy state: %s", |
1634 | __func__, strerror(errno)); | | 1633 | __func__, strerror(errno)); |
1635 | goto fail; | | 1634 | goto fail; |
1636 | } | | 1635 | } |
1637 | if (!GETPARAM(drv, IEEE80211_IOC_WPA, drv->prev_wpa)) { | | 1636 | if (!GETPARAM(drv, IEEE80211_IOC_WPA, drv->prev_wpa)) { |
1638 | wpa_printf(MSG_DEBUG, "%s: failed to get wpa state: %s", | | 1637 | wpa_printf(MSG_DEBUG, "%s: failed to get wpa state: %s", |
1639 | __func__, strerror(errno)); | | 1638 | __func__, strerror(errno)); |
1640 | goto fail; | | 1639 | goto fail; |
1641 | } | | 1640 | } |
1642 | | | 1641 | |
1643 | if (wpa_driver_bsd_capa(drv)) | | 1642 | if (wpa_driver_bsd_capa(drv)) |
1644 | goto fail; | | 1643 | goto fail; |
1645 | | | 1644 | |
1646 | /* Down interface during setup. */ | | 1645 | /* Down interface during setup. */ |
1647 | if (bsd_ctrl_iface(drv, 0) < 0) | | 1646 | if (bsd_ctrl_iface(drv, 0) < 0) |
1648 | goto fail; | | 1647 | goto fail; |
1649 | | | 1648 | |
1650 | drv->opmode = get80211opmode(drv); | | 1649 | drv->opmode = get80211opmode(drv); |
1651 | dl_list_add(&drv->global->ifaces, &drv->list); | | 1650 | dl_list_add(&drv->global->ifaces, &drv->list); |
1652 | | | 1651 | |
1653 | return drv; | | 1652 | return drv; |
1654 | fail: | | 1653 | fail: |
1655 | os_free(drv); | | 1654 | os_free(drv); |
1656 | return NULL; | | 1655 | return NULL; |
1657 | #undef GETPARAM | | 1656 | #undef GETPARAM |
1658 | } | | 1657 | } |
1659 | | | 1658 | |
1660 | static void | | 1659 | static void |
1661 | wpa_driver_bsd_deinit(void *priv) | | 1660 | wpa_driver_bsd_deinit(void *priv) |
1662 | { | | 1661 | { |
1663 | struct bsd_driver_data *drv = priv; | | 1662 | struct bsd_driver_data *drv = priv; |
1664 | | | 1663 | |
1665 | if (drv->ifindex != 0 && !drv->if_removed) { | | 1664 | if (drv->ifindex != 0 && !drv->if_removed) { |
1666 | wpa_driver_bsd_set_wpa(drv, 0); | | 1665 | wpa_driver_bsd_set_wpa(drv, 0); |
1667 | | | 1666 | |
1668 | /* NB: mark interface down */ | | 1667 | /* NB: mark interface down */ |
1669 | bsd_ctrl_iface(drv, 0); | | 1668 | bsd_ctrl_iface(drv, 0); |
1670 | | | 1669 | |
1671 | wpa_driver_bsd_set_wpa_internal(drv, drv->prev_wpa, | | 1670 | wpa_driver_bsd_set_wpa_internal(drv, drv->prev_wpa, |
1672 | drv->prev_privacy); | | 1671 | drv->prev_privacy); |
1673 | | | 1672 | |
1674 | if (set80211param(drv, IEEE80211_IOC_ROAMING, drv->prev_roaming) | | 1673 | if (set80211param(drv, IEEE80211_IOC_ROAMING, drv->prev_roaming) |
1675 | < 0) | | 1674 | < 0) |
1676 | wpa_printf(MSG_DEBUG, | | 1675 | wpa_printf(MSG_DEBUG, |
1677 | "%s: failed to restore roaming state", | | 1676 | "%s: failed to restore roaming state", |
1678 | __func__); | | 1677 | __func__); |
1679 | } | | 1678 | } |
1680 | | | 1679 | |
1681 | if (drv->sock_xmit != NULL) | | 1680 | if (drv->sock_xmit != NULL) |
1682 | l2_packet_deinit(drv->sock_xmit); | | 1681 | l2_packet_deinit(drv->sock_xmit); |
1683 | dl_list_del(&drv->list); | | 1682 | dl_list_del(&drv->list); |
1684 | os_free(drv); | | 1683 | os_free(drv); |
1685 | } | | 1684 | } |
1686 | | | 1685 | |
1687 | static int | | 1686 | static int |
1688 | wpa_driver_bsd_get_capa(void *priv, struct wpa_driver_capa *capa) | | 1687 | wpa_driver_bsd_get_capa(void *priv, struct wpa_driver_capa *capa) |
1689 | { | | 1688 | { |
1690 | struct bsd_driver_data *drv = priv; | | 1689 | struct bsd_driver_data *drv = priv; |
1691 | | | 1690 | |
1692 | os_memcpy(capa, &drv->capa, sizeof(*capa)); | | 1691 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
1693 | return 0; | | 1692 | return 0; |
1694 | } | | 1693 | } |
1695 | #endif /* HOSTAPD */ | | 1694 | #endif /* HOSTAPD */ |
1696 | | | 1695 | |
1697 | static void * | | 1696 | static void * |
1698 | bsd_global_init(void *ctx) | | 1697 | bsd_global_init(void *ctx) |
1699 | { | | 1698 | { |
1700 | struct bsd_driver_global *global; | | 1699 | struct bsd_driver_global *global; |
1701 | #ifdef RO_MSGFILTER | | 1700 | #ifdef RO_MSGFILTER |
1702 | unsigned char msgfilter[] = { | | 1701 | unsigned char msgfilter[] = { |
1703 | RTM_IEEE80211, | | 1702 | RTM_IEEE80211, |
1704 | #ifndef HOSTAPD | | 1703 | #ifndef HOSTAPD |
1705 | RTM_IFINFO, RTM_IFANNOUNCE, | | 1704 | RTM_IFINFO, RTM_IFANNOUNCE, |
1706 | #endif | | 1705 | #endif |
1707 | }; | | 1706 | }; |
1708 | #endif | | 1707 | #endif |
1709 | | | 1708 | |
1710 | global = os_zalloc(sizeof(*global)); | | 1709 | global = os_zalloc(sizeof(*global)); |
1711 | if (global == NULL) | | 1710 | if (global == NULL) |
1712 | return NULL; | | 1711 | return NULL; |
1713 | | | 1712 | |
1714 | global->ctx = ctx; | | 1713 | global->ctx = ctx; |
1715 | dl_list_init(&global->ifaces); | | 1714 | dl_list_init(&global->ifaces); |
1716 | | | 1715 | |
1717 | global->sock = socket(PF_INET, SOCK_DGRAM, 0); | | 1716 | global->sock = socket(PF_INET, SOCK_DGRAM, 0); |
1718 | if (global->sock < 0) { | | 1717 | if (global->sock < 0) { |
1719 | wpa_printf(MSG_ERROR, "socket[PF_INET,SOCK_DGRAM]: %s", | | 1718 | wpa_printf(MSG_ERROR, "socket[PF_INET,SOCK_DGRAM]: %s", |
1720 | strerror(errno)); | | 1719 | strerror(errno)); |
1721 | goto fail1; | | 1720 | goto fail1; |
1722 | } | | 1721 | } |
1723 | | | 1722 | |
1724 | global->route = socket(PF_ROUTE, SOCK_RAW, 0); | | 1723 | global->route = socket(PF_ROUTE, SOCK_RAW, 0); |
1725 | if (global->route < 0) { | | 1724 | if (global->route < 0) { |
1726 | wpa_printf(MSG_ERROR, "socket[PF_ROUTE,SOCK_RAW]: %s", | | 1725 | wpa_printf(MSG_ERROR, "socket[PF_ROUTE,SOCK_RAW]: %s", |
1727 | strerror(errno)); | | 1726 | strerror(errno)); |
1728 | goto fail; | | 1727 | goto fail; |
1729 | } | | 1728 | } |
1730 | | | 1729 | |
1731 | #ifdef RO_MSGFILTER | | 1730 | #ifdef RO_MSGFILTER |
1732 | if (setsockopt(global->route, PF_ROUTE, RO_MSGFILTER, | | 1731 | if (setsockopt(global->route, PF_ROUTE, RO_MSGFILTER, |
1733 | &msgfilter, sizeof(msgfilter)) < 0) | | 1732 | &msgfilter, sizeof(msgfilter)) < 0) |
1734 | wpa_printf(MSG_ERROR, "setsockopt[PF_ROUTE,RO_MSGFILTER]: %s", | | 1733 | wpa_printf(MSG_ERROR, "setsockopt[PF_ROUTE,RO_MSGFILTER]: %s", |
1735 | strerror(errno)); | | 1734 | strerror(errno)); |
1736 | #endif | | 1735 | #endif |
1737 | | | 1736 | |
1738 | #ifdef HOSTAPD | | 1737 | #ifdef HOSTAPD |
1739 | eloop_register_read_sock(global->route, bsd_wireless_event_receive, | | 1738 | eloop_register_read_sock(global->route, bsd_wireless_event_receive, |
1740 | NULL, global); | | 1739 | NULL, global); |
1741 | | | 1740 | |
1742 | #else /* HOSTAPD */ | | 1741 | #else /* HOSTAPD */ |
1743 | eloop_register_read_sock(global->route, wpa_driver_bsd_event_receive, | | 1742 | eloop_register_read_sock(global->route, wpa_driver_bsd_event_receive, |
1744 | NULL, global); | | 1743 | NULL, global); |
1745 | #endif /* HOSTAPD */ | | 1744 | #endif /* HOSTAPD */ |
1746 | | | 1745 | |
1747 | return global; | | 1746 | return global; |
1748 | | | 1747 | |
1749 | fail: | | 1748 | fail: |
1750 | close(global->sock); | | 1749 | close(global->sock); |
1751 | fail1: | | 1750 | fail1: |
1752 | os_free(global); | | 1751 | os_free(global); |
1753 | return NULL; | | 1752 | return NULL; |
1754 | } | | 1753 | } |
1755 | | | 1754 | |
1756 | static void | | 1755 | static void |
1757 | bsd_global_deinit(void *priv) | | 1756 | bsd_global_deinit(void *priv) |
1758 | { | | 1757 | { |
1759 | struct bsd_driver_global *global = priv; | | 1758 | struct bsd_driver_global *global = priv; |
1760 | | | 1759 | |
1761 | eloop_unregister_read_sock(global->route); | | 1760 | eloop_unregister_read_sock(global->route); |
1762 | (void) close(global->route); | | 1761 | (void) close(global->route); |
1763 | (void) close(global->sock); | | 1762 | (void) close(global->sock); |
1764 | free(global->event_iov[0].iov_base); | | 1763 | free(global->event_iov[0].iov_base); |
1765 | os_free(global); | | 1764 | os_free(global); |
1766 | } | | 1765 | } |
1767 | | | 1766 | |
1768 | | | 1767 | |
1769 | const struct wpa_driver_ops wpa_driver_bsd_ops = { | | 1768 | const struct wpa_driver_ops wpa_driver_bsd_ops = { |
1770 | .name = "bsd", | | 1769 | .name = "bsd", |
1771 | .desc = "BSD 802.11 support", | | 1770 | .desc = "BSD 802.11 support", |
1772 | .global_init = bsd_global_init, | | 1771 | .global_init = bsd_global_init, |
1773 | .global_deinit = bsd_global_deinit, | | 1772 | .global_deinit = bsd_global_deinit, |
1774 | #ifdef HOSTAPD | | 1773 | #ifdef HOSTAPD |
1775 | .hapd_init = bsd_init, | | 1774 | .hapd_init = bsd_init, |
1776 | .hapd_deinit = bsd_deinit, | | 1775 | .hapd_deinit = bsd_deinit, |
1777 | .set_privacy = bsd_set_privacy, | | 1776 | .set_privacy = bsd_set_privacy, |
1778 | .get_seqnum = bsd_get_seqnum, | | 1777 | .get_seqnum = bsd_get_seqnum, |
1779 | .flush = bsd_flush, | | 1778 | .flush = bsd_flush, |
1780 | .read_sta_data = bsd_read_sta_driver_data, | | 1779 | .read_sta_data = bsd_read_sta_driver_data, |
1781 | .sta_disassoc = bsd_sta_disassoc, | | 1780 | .sta_disassoc = bsd_sta_disassoc, |
1782 | .sta_deauth = bsd_sta_deauth, | | 1781 | .sta_deauth = bsd_sta_deauth, |
1783 | .sta_set_flags = bsd_set_sta_authorized, | | 1782 | .sta_set_flags = bsd_set_sta_authorized, |
1784 | .commit = bsd_commit, | | 1783 | .commit = bsd_commit, |
1785 | #else /* HOSTAPD */ | | 1784 | #else /* HOSTAPD */ |
1786 | .init2 = wpa_driver_bsd_init, | | 1785 | .init2 = wpa_driver_bsd_init, |
1787 | .deinit = wpa_driver_bsd_deinit, | | 1786 | .deinit = wpa_driver_bsd_deinit, |
1788 | .get_bssid = wpa_driver_bsd_get_bssid, | | 1787 | .get_bssid = wpa_driver_bsd_get_bssid, |
1789 | .get_ssid = wpa_driver_bsd_get_ssid, | | 1788 | .get_ssid = wpa_driver_bsd_get_ssid, |
1790 | .set_countermeasures = wpa_driver_bsd_set_countermeasures, | | 1789 | .set_countermeasures = wpa_driver_bsd_set_countermeasures, |
1791 | .scan2 = wpa_driver_bsd_scan, | | 1790 | .scan2 = wpa_driver_bsd_scan, |
1792 | .get_scan_results2 = wpa_driver_bsd_get_scan_results2, | | 1791 | .get_scan_results2 = wpa_driver_bsd_get_scan_results2, |
1793 | .deauthenticate = wpa_driver_bsd_deauthenticate, | | 1792 | .deauthenticate = wpa_driver_bsd_deauthenticate, |
1794 | .associate = wpa_driver_bsd_associate, | | 1793 | .associate = wpa_driver_bsd_associate, |
1795 | .get_capa = wpa_driver_bsd_get_capa, | | 1794 | .get_capa = wpa_driver_bsd_get_capa, |
1796 | #endif /* HOSTAPD */ | | 1795 | #endif /* HOSTAPD */ |
1797 | .set_freq = bsd_set_freq, | | 1796 | .set_freq = bsd_set_freq, |
1798 | .set_key = bsd_set_key, | | 1797 | .set_key = bsd_set_key, |
1799 | .set_ieee8021x = bsd_set_ieee8021x, | | 1798 | .set_ieee8021x = bsd_set_ieee8021x, |
1800 | .hapd_set_ssid = bsd_set_ssid, | | 1799 | .hapd_set_ssid = bsd_set_ssid, |
1801 | .hapd_get_ssid = bsd_get_ssid, | | 1800 | .hapd_get_ssid = bsd_get_ssid, |
1802 | .hapd_send_eapol = bsd_send_eapol, | | 1801 | .hapd_send_eapol = bsd_send_eapol, |
1803 | .set_generic_elem = bsd_set_opt_ie, | | 1802 | .set_generic_elem = bsd_set_opt_ie, |
1804 | }; | | 1803 | }; |