ibss_rsn.c revision 1.1.1.4 1 1.1 christos /*
2 1.1 christos * wpa_supplicant - IBSS RSN
3 1.1.1.4 christos * Copyright (c) 2009-2013, Jouni Malinen <j (at) w1.fi>
4 1.1 christos *
5 1.1.1.3 christos * This software may be distributed under the terms of the BSD license.
6 1.1.1.3 christos * See README for more details.
7 1.1 christos */
8 1.1 christos
9 1.1 christos #include "includes.h"
10 1.1 christos
11 1.1 christos #include "common.h"
12 1.1.1.4 christos #include "common/wpa_ctrl.h"
13 1.1.1.4 christos #include "utils/eloop.h"
14 1.1 christos #include "l2_packet/l2_packet.h"
15 1.1 christos #include "rsn_supp/wpa.h"
16 1.1 christos #include "rsn_supp/wpa_ie.h"
17 1.1 christos #include "ap/wpa_auth.h"
18 1.1 christos #include "wpa_supplicant_i.h"
19 1.1 christos #include "driver_i.h"
20 1.1.1.4 christos #include "common/ieee802_11_defs.h"
21 1.1 christos #include "ibss_rsn.h"
22 1.1 christos
23 1.1 christos
24 1.1.1.4 christos static void ibss_rsn_auth_timeout(void *eloop_ctx, void *timeout_ctx);
25 1.1.1.4 christos
26 1.1.1.4 christos
27 1.1.1.3 christos static struct ibss_rsn_peer * ibss_rsn_get_peer(struct ibss_rsn *ibss_rsn,
28 1.1.1.3 christos const u8 *addr)
29 1.1.1.3 christos {
30 1.1.1.3 christos struct ibss_rsn_peer *peer;
31 1.1.1.3 christos
32 1.1.1.3 christos for (peer = ibss_rsn->peers; peer; peer = peer->next)
33 1.1.1.3 christos if (os_memcmp(addr, peer->addr, ETH_ALEN) == 0)
34 1.1.1.3 christos break;
35 1.1.1.3 christos return peer;
36 1.1.1.3 christos }
37 1.1.1.3 christos
38 1.1.1.3 christos
39 1.1 christos static void ibss_rsn_free(struct ibss_rsn_peer *peer)
40 1.1 christos {
41 1.1.1.4 christos eloop_cancel_timeout(ibss_rsn_auth_timeout, peer, NULL);
42 1.1 christos wpa_auth_sta_deinit(peer->auth);
43 1.1 christos wpa_sm_deinit(peer->supp);
44 1.1 christos os_free(peer);
45 1.1 christos }
46 1.1 christos
47 1.1 christos
48 1.1 christos static void supp_set_state(void *ctx, enum wpa_states state)
49 1.1 christos {
50 1.1 christos struct ibss_rsn_peer *peer = ctx;
51 1.1 christos peer->supp_state = state;
52 1.1 christos }
53 1.1 christos
54 1.1 christos
55 1.1.1.2 christos static enum wpa_states supp_get_state(void *ctx)
56 1.1.1.2 christos {
57 1.1.1.2 christos struct ibss_rsn_peer *peer = ctx;
58 1.1.1.2 christos return peer->supp_state;
59 1.1.1.2 christos }
60 1.1.1.2 christos
61 1.1.1.2 christos
62 1.1 christos static int supp_ether_send(void *ctx, const u8 *dest, u16 proto, const u8 *buf,
63 1.1 christos size_t len)
64 1.1 christos {
65 1.1 christos struct ibss_rsn_peer *peer = ctx;
66 1.1 christos struct wpa_supplicant *wpa_s = peer->ibss_rsn->wpa_s;
67 1.1 christos
68 1.1 christos wpa_printf(MSG_DEBUG, "SUPP: %s(dest=" MACSTR " proto=0x%04x "
69 1.1 christos "len=%lu)",
70 1.1 christos __func__, MAC2STR(dest), proto, (unsigned long) len);
71 1.1 christos
72 1.1 christos if (wpa_s->l2)
73 1.1 christos return l2_packet_send(wpa_s->l2, dest, proto, buf, len);
74 1.1 christos
75 1.1 christos return wpa_drv_send_eapol(wpa_s, dest, proto, buf, len);
76 1.1 christos }
77 1.1 christos
78 1.1 christos
79 1.1 christos static u8 * supp_alloc_eapol(void *ctx, u8 type, const void *data,
80 1.1 christos u16 data_len, size_t *msg_len, void **data_pos)
81 1.1 christos {
82 1.1 christos struct ieee802_1x_hdr *hdr;
83 1.1 christos
84 1.1 christos wpa_printf(MSG_DEBUG, "SUPP: %s(type=%d data_len=%d)",
85 1.1 christos __func__, type, data_len);
86 1.1 christos
87 1.1 christos *msg_len = sizeof(*hdr) + data_len;
88 1.1 christos hdr = os_malloc(*msg_len);
89 1.1 christos if (hdr == NULL)
90 1.1 christos return NULL;
91 1.1 christos
92 1.1 christos hdr->version = 2;
93 1.1 christos hdr->type = type;
94 1.1 christos hdr->length = host_to_be16(data_len);
95 1.1 christos
96 1.1 christos if (data)
97 1.1 christos os_memcpy(hdr + 1, data, data_len);
98 1.1 christos else
99 1.1 christos os_memset(hdr + 1, 0, data_len);
100 1.1 christos
101 1.1 christos if (data_pos)
102 1.1 christos *data_pos = hdr + 1;
103 1.1 christos
104 1.1 christos return (u8 *) hdr;
105 1.1 christos }
106 1.1 christos
107 1.1 christos
108 1.1 christos static int supp_get_beacon_ie(void *ctx)
109 1.1 christos {
110 1.1 christos struct ibss_rsn_peer *peer = ctx;
111 1.1 christos
112 1.1 christos wpa_printf(MSG_DEBUG, "SUPP: %s", __func__);
113 1.1 christos /* TODO: get correct RSN IE */
114 1.1 christos return wpa_sm_set_ap_rsn_ie(peer->supp,
115 1.1 christos (u8 *) "\x30\x14\x01\x00"
116 1.1 christos "\x00\x0f\xac\x04"
117 1.1 christos "\x01\x00\x00\x0f\xac\x04"
118 1.1 christos "\x01\x00\x00\x0f\xac\x02"
119 1.1 christos "\x00\x00", 22);
120 1.1 christos }
121 1.1 christos
122 1.1 christos
123 1.1.1.4 christos static void ibss_check_rsn_completed(struct ibss_rsn_peer *peer)
124 1.1.1.4 christos {
125 1.1.1.4 christos struct wpa_supplicant *wpa_s = peer->ibss_rsn->wpa_s;
126 1.1.1.4 christos
127 1.1.1.4 christos if ((peer->authentication_status &
128 1.1.1.4 christos (IBSS_RSN_SET_PTK_SUPP | IBSS_RSN_SET_PTK_AUTH)) !=
129 1.1.1.4 christos (IBSS_RSN_SET_PTK_SUPP | IBSS_RSN_SET_PTK_AUTH))
130 1.1.1.4 christos return;
131 1.1.1.4 christos if (peer->authentication_status & IBSS_RSN_REPORTED_PTK)
132 1.1.1.4 christos return;
133 1.1.1.4 christos peer->authentication_status |= IBSS_RSN_REPORTED_PTK;
134 1.1.1.4 christos wpa_msg(wpa_s, MSG_INFO, IBSS_RSN_COMPLETED MACSTR,
135 1.1.1.4 christos MAC2STR(peer->addr));
136 1.1.1.4 christos }
137 1.1.1.4 christos
138 1.1.1.4 christos
139 1.1 christos static int supp_set_key(void *ctx, enum wpa_alg alg,
140 1.1 christos const u8 *addr, int key_idx, int set_tx,
141 1.1 christos const u8 *seq, size_t seq_len,
142 1.1 christos const u8 *key, size_t key_len)
143 1.1 christos {
144 1.1 christos struct ibss_rsn_peer *peer = ctx;
145 1.1 christos
146 1.1 christos wpa_printf(MSG_DEBUG, "SUPP: %s(alg=%d addr=" MACSTR " key_idx=%d "
147 1.1 christos "set_tx=%d)",
148 1.1 christos __func__, alg, MAC2STR(addr), key_idx, set_tx);
149 1.1 christos wpa_hexdump(MSG_DEBUG, "SUPP: set_key - seq", seq, seq_len);
150 1.1 christos wpa_hexdump_key(MSG_DEBUG, "SUPP: set_key - key", key, key_len);
151 1.1 christos
152 1.1 christos if (key_idx == 0) {
153 1.1.1.4 christos peer->authentication_status |= IBSS_RSN_SET_PTK_SUPP;
154 1.1.1.4 christos ibss_check_rsn_completed(peer);
155 1.1 christos /*
156 1.1 christos * In IBSS RSN, the pairwise key from the 4-way handshake
157 1.1 christos * initiated by the peer with highest MAC address is used.
158 1.1 christos */
159 1.1 christos if (os_memcmp(peer->ibss_rsn->wpa_s->own_addr, peer->addr,
160 1.1 christos ETH_ALEN) > 0) {
161 1.1 christos wpa_printf(MSG_DEBUG, "SUPP: Do not use this PTK");
162 1.1 christos return 0;
163 1.1 christos }
164 1.1 christos }
165 1.1 christos
166 1.1.1.2 christos if (is_broadcast_ether_addr(addr))
167 1.1.1.2 christos addr = peer->addr;
168 1.1 christos return wpa_drv_set_key(peer->ibss_rsn->wpa_s, alg, addr, key_idx,
169 1.1 christos set_tx, seq, seq_len, key, key_len);
170 1.1 christos }
171 1.1 christos
172 1.1 christos
173 1.1 christos static void * supp_get_network_ctx(void *ctx)
174 1.1 christos {
175 1.1 christos struct ibss_rsn_peer *peer = ctx;
176 1.1 christos return wpa_supplicant_get_ssid(peer->ibss_rsn->wpa_s);
177 1.1 christos }
178 1.1 christos
179 1.1 christos
180 1.1 christos static int supp_mlme_setprotection(void *ctx, const u8 *addr,
181 1.1 christos int protection_type, int key_type)
182 1.1 christos {
183 1.1 christos wpa_printf(MSG_DEBUG, "SUPP: %s(addr=" MACSTR " protection_type=%d "
184 1.1 christos "key_type=%d)",
185 1.1 christos __func__, MAC2STR(addr), protection_type, key_type);
186 1.1 christos return 0;
187 1.1 christos }
188 1.1 christos
189 1.1 christos
190 1.1 christos static void supp_cancel_auth_timeout(void *ctx)
191 1.1 christos {
192 1.1 christos wpa_printf(MSG_DEBUG, "SUPP: %s", __func__);
193 1.1 christos }
194 1.1 christos
195 1.1 christos
196 1.1.1.2 christos static void supp_deauthenticate(void * ctx, int reason_code)
197 1.1.1.2 christos {
198 1.1.1.2 christos wpa_printf(MSG_DEBUG, "SUPP: %s (TODO)", __func__);
199 1.1.1.2 christos }
200 1.1.1.2 christos
201 1.1.1.2 christos
202 1.1.1.3 christos static int ibss_rsn_supp_init(struct ibss_rsn_peer *peer, const u8 *own_addr,
203 1.1.1.3 christos const u8 *psk)
204 1.1 christos {
205 1.1 christos struct wpa_sm_ctx *ctx = os_zalloc(sizeof(*ctx));
206 1.1 christos if (ctx == NULL)
207 1.1 christos return -1;
208 1.1 christos
209 1.1 christos ctx->ctx = peer;
210 1.1 christos ctx->msg_ctx = peer->ibss_rsn->wpa_s;
211 1.1 christos ctx->set_state = supp_set_state;
212 1.1.1.2 christos ctx->get_state = supp_get_state;
213 1.1 christos ctx->ether_send = supp_ether_send;
214 1.1 christos ctx->get_beacon_ie = supp_get_beacon_ie;
215 1.1 christos ctx->alloc_eapol = supp_alloc_eapol;
216 1.1 christos ctx->set_key = supp_set_key;
217 1.1 christos ctx->get_network_ctx = supp_get_network_ctx;
218 1.1 christos ctx->mlme_setprotection = supp_mlme_setprotection;
219 1.1 christos ctx->cancel_auth_timeout = supp_cancel_auth_timeout;
220 1.1.1.2 christos ctx->deauthenticate = supp_deauthenticate;
221 1.1 christos peer->supp = wpa_sm_init(ctx);
222 1.1 christos if (peer->supp == NULL) {
223 1.1 christos wpa_printf(MSG_DEBUG, "SUPP: wpa_sm_init() failed");
224 1.1 christos return -1;
225 1.1 christos }
226 1.1 christos
227 1.1 christos wpa_sm_set_own_addr(peer->supp, own_addr);
228 1.1 christos wpa_sm_set_param(peer->supp, WPA_PARAM_RSN_ENABLED, 1);
229 1.1 christos wpa_sm_set_param(peer->supp, WPA_PARAM_PROTO, WPA_PROTO_RSN);
230 1.1 christos wpa_sm_set_param(peer->supp, WPA_PARAM_PAIRWISE, WPA_CIPHER_CCMP);
231 1.1 christos wpa_sm_set_param(peer->supp, WPA_PARAM_GROUP, WPA_CIPHER_CCMP);
232 1.1 christos wpa_sm_set_param(peer->supp, WPA_PARAM_KEY_MGMT, WPA_KEY_MGMT_PSK);
233 1.1 christos wpa_sm_set_pmk(peer->supp, psk, PMK_LEN);
234 1.1 christos
235 1.1 christos peer->supp_ie_len = sizeof(peer->supp_ie);
236 1.1 christos if (wpa_sm_set_assoc_wpa_ie_default(peer->supp, peer->supp_ie,
237 1.1 christos &peer->supp_ie_len) < 0) {
238 1.1 christos wpa_printf(MSG_DEBUG, "SUPP: wpa_sm_set_assoc_wpa_ie_default()"
239 1.1 christos " failed");
240 1.1 christos return -1;
241 1.1 christos }
242 1.1 christos
243 1.1 christos wpa_sm_notify_assoc(peer->supp, peer->addr);
244 1.1 christos
245 1.1 christos return 0;
246 1.1 christos }
247 1.1 christos
248 1.1 christos
249 1.1 christos static void auth_logger(void *ctx, const u8 *addr, logger_level level,
250 1.1 christos const char *txt)
251 1.1 christos {
252 1.1 christos if (addr)
253 1.1 christos wpa_printf(MSG_DEBUG, "AUTH: " MACSTR " - %s",
254 1.1 christos MAC2STR(addr), txt);
255 1.1 christos else
256 1.1 christos wpa_printf(MSG_DEBUG, "AUTH: %s", txt);
257 1.1 christos }
258 1.1 christos
259 1.1 christos
260 1.1.1.4 christos static const u8 * auth_get_psk(void *ctx, const u8 *addr,
261 1.1.1.4 christos const u8 *p2p_dev_addr, const u8 *prev_psk)
262 1.1 christos {
263 1.1 christos struct ibss_rsn *ibss_rsn = ctx;
264 1.1 christos wpa_printf(MSG_DEBUG, "AUTH: %s (addr=" MACSTR " prev_psk=%p)",
265 1.1 christos __func__, MAC2STR(addr), prev_psk);
266 1.1 christos if (prev_psk)
267 1.1 christos return NULL;
268 1.1 christos return ibss_rsn->psk;
269 1.1 christos }
270 1.1 christos
271 1.1 christos
272 1.1 christos static int auth_send_eapol(void *ctx, const u8 *addr, const u8 *data,
273 1.1 christos size_t data_len, int encrypt)
274 1.1 christos {
275 1.1 christos struct ibss_rsn *ibss_rsn = ctx;
276 1.1 christos struct wpa_supplicant *wpa_s = ibss_rsn->wpa_s;
277 1.1 christos
278 1.1 christos wpa_printf(MSG_DEBUG, "AUTH: %s(addr=" MACSTR " data_len=%lu "
279 1.1 christos "encrypt=%d)",
280 1.1 christos __func__, MAC2STR(addr), (unsigned long) data_len, encrypt);
281 1.1 christos
282 1.1 christos if (wpa_s->l2)
283 1.1 christos return l2_packet_send(wpa_s->l2, addr, ETH_P_EAPOL, data,
284 1.1 christos data_len);
285 1.1 christos
286 1.1 christos return wpa_drv_send_eapol(wpa_s, addr, ETH_P_EAPOL, data, data_len);
287 1.1 christos }
288 1.1 christos
289 1.1 christos
290 1.1 christos static int auth_set_key(void *ctx, int vlan_id, enum wpa_alg alg,
291 1.1 christos const u8 *addr, int idx, u8 *key, size_t key_len)
292 1.1 christos {
293 1.1 christos struct ibss_rsn *ibss_rsn = ctx;
294 1.1 christos u8 seq[6];
295 1.1 christos
296 1.1 christos os_memset(seq, 0, sizeof(seq));
297 1.1 christos
298 1.1 christos if (addr) {
299 1.1 christos wpa_printf(MSG_DEBUG, "AUTH: %s(alg=%d addr=" MACSTR
300 1.1 christos " key_idx=%d)",
301 1.1 christos __func__, alg, MAC2STR(addr), idx);
302 1.1 christos } else {
303 1.1 christos wpa_printf(MSG_DEBUG, "AUTH: %s(alg=%d key_idx=%d)",
304 1.1 christos __func__, alg, idx);
305 1.1 christos }
306 1.1 christos wpa_hexdump_key(MSG_DEBUG, "AUTH: set_key - key", key, key_len);
307 1.1 christos
308 1.1 christos if (idx == 0) {
309 1.1.1.4 christos if (addr) {
310 1.1.1.4 christos struct ibss_rsn_peer *peer;
311 1.1.1.4 christos peer = ibss_rsn_get_peer(ibss_rsn, addr);
312 1.1.1.4 christos if (peer) {
313 1.1.1.4 christos peer->authentication_status |=
314 1.1.1.4 christos IBSS_RSN_SET_PTK_AUTH;
315 1.1.1.4 christos ibss_check_rsn_completed(peer);
316 1.1.1.4 christos }
317 1.1.1.4 christos }
318 1.1 christos /*
319 1.1 christos * In IBSS RSN, the pairwise key from the 4-way handshake
320 1.1 christos * initiated by the peer with highest MAC address is used.
321 1.1 christos */
322 1.1 christos if (addr == NULL ||
323 1.1 christos os_memcmp(ibss_rsn->wpa_s->own_addr, addr, ETH_ALEN) < 0) {
324 1.1 christos wpa_printf(MSG_DEBUG, "AUTH: Do not use this PTK");
325 1.1 christos return 0;
326 1.1 christos }
327 1.1 christos }
328 1.1 christos
329 1.1 christos return wpa_drv_set_key(ibss_rsn->wpa_s, alg, addr, idx,
330 1.1 christos 1, seq, 6, key, key_len);
331 1.1 christos }
332 1.1 christos
333 1.1 christos
334 1.1.1.4 christos static void ibss_rsn_disconnect(void *ctx, const u8 *addr, u16 reason)
335 1.1.1.4 christos {
336 1.1.1.4 christos struct ibss_rsn *ibss_rsn = ctx;
337 1.1.1.4 christos wpa_drv_sta_deauth(ibss_rsn->wpa_s, addr, reason);
338 1.1.1.4 christos }
339 1.1.1.4 christos
340 1.1.1.4 christos
341 1.1.1.2 christos static int auth_for_each_sta(void *ctx, int (*cb)(struct wpa_state_machine *sm,
342 1.1.1.2 christos void *ctx),
343 1.1.1.2 christos void *cb_ctx)
344 1.1.1.2 christos {
345 1.1.1.2 christos struct ibss_rsn *ibss_rsn = ctx;
346 1.1.1.2 christos struct ibss_rsn_peer *peer;
347 1.1.1.2 christos
348 1.1.1.2 christos wpa_printf(MSG_DEBUG, "AUTH: for_each_sta");
349 1.1.1.2 christos
350 1.1.1.2 christos for (peer = ibss_rsn->peers; peer; peer = peer->next) {
351 1.1.1.2 christos if (peer->auth && cb(peer->auth, cb_ctx))
352 1.1.1.2 christos return 1;
353 1.1.1.2 christos }
354 1.1.1.2 christos
355 1.1.1.2 christos return 0;
356 1.1.1.2 christos }
357 1.1.1.2 christos
358 1.1.1.2 christos
359 1.1.1.3 christos static void ibss_set_sta_authorized(struct ibss_rsn *ibss_rsn,
360 1.1.1.3 christos struct ibss_rsn_peer *peer, int authorized)
361 1.1.1.3 christos {
362 1.1.1.3 christos int res;
363 1.1.1.3 christos
364 1.1.1.3 christos if (authorized) {
365 1.1.1.3 christos res = wpa_drv_sta_set_flags(ibss_rsn->wpa_s, peer->addr,
366 1.1.1.3 christos WPA_STA_AUTHORIZED,
367 1.1.1.3 christos WPA_STA_AUTHORIZED, ~0);
368 1.1.1.3 christos wpa_printf(MSG_DEBUG, "AUTH: " MACSTR " authorizing port",
369 1.1.1.3 christos MAC2STR(peer->addr));
370 1.1.1.3 christos } else {
371 1.1.1.3 christos res = wpa_drv_sta_set_flags(ibss_rsn->wpa_s, peer->addr,
372 1.1.1.3 christos 0, 0, ~WPA_STA_AUTHORIZED);
373 1.1.1.3 christos wpa_printf(MSG_DEBUG, "AUTH: " MACSTR " unauthorizing port",
374 1.1.1.3 christos MAC2STR(peer->addr));
375 1.1.1.3 christos }
376 1.1.1.3 christos
377 1.1.1.3 christos if (res && errno != ENOENT) {
378 1.1.1.3 christos wpa_printf(MSG_DEBUG, "Could not set station " MACSTR " flags "
379 1.1.1.3 christos "for kernel driver (errno=%d)",
380 1.1.1.3 christos MAC2STR(peer->addr), errno);
381 1.1.1.3 christos }
382 1.1.1.3 christos }
383 1.1.1.3 christos
384 1.1.1.3 christos
385 1.1.1.3 christos static void auth_set_eapol(void *ctx, const u8 *addr,
386 1.1.1.3 christos wpa_eapol_variable var, int value)
387 1.1.1.3 christos {
388 1.1.1.3 christos struct ibss_rsn *ibss_rsn = ctx;
389 1.1.1.3 christos struct ibss_rsn_peer *peer = ibss_rsn_get_peer(ibss_rsn, addr);
390 1.1.1.3 christos
391 1.1.1.3 christos if (peer == NULL)
392 1.1.1.3 christos return;
393 1.1.1.3 christos
394 1.1.1.3 christos switch (var) {
395 1.1.1.3 christos case WPA_EAPOL_authorized:
396 1.1.1.3 christos ibss_set_sta_authorized(ibss_rsn, peer, value);
397 1.1.1.3 christos break;
398 1.1.1.3 christos default:
399 1.1.1.3 christos /* do not handle any other event */
400 1.1.1.3 christos wpa_printf(MSG_DEBUG, "AUTH: eapol event not handled %d", var);
401 1.1.1.3 christos break;
402 1.1.1.3 christos }
403 1.1.1.3 christos }
404 1.1.1.3 christos
405 1.1.1.3 christos
406 1.1 christos static int ibss_rsn_auth_init_group(struct ibss_rsn *ibss_rsn,
407 1.1 christos const u8 *own_addr)
408 1.1 christos {
409 1.1 christos struct wpa_auth_config conf;
410 1.1 christos struct wpa_auth_callbacks cb;
411 1.1 christos
412 1.1 christos wpa_printf(MSG_DEBUG, "AUTH: Initializing group state machine");
413 1.1 christos
414 1.1 christos os_memset(&conf, 0, sizeof(conf));
415 1.1 christos conf.wpa = 2;
416 1.1 christos conf.wpa_key_mgmt = WPA_KEY_MGMT_PSK;
417 1.1 christos conf.wpa_pairwise = WPA_CIPHER_CCMP;
418 1.1 christos conf.rsn_pairwise = WPA_CIPHER_CCMP;
419 1.1 christos conf.wpa_group = WPA_CIPHER_CCMP;
420 1.1 christos conf.eapol_version = 2;
421 1.1.1.2 christos conf.wpa_group_rekey = 600;
422 1.1 christos
423 1.1 christos os_memset(&cb, 0, sizeof(cb));
424 1.1 christos cb.ctx = ibss_rsn;
425 1.1 christos cb.logger = auth_logger;
426 1.1.1.3 christos cb.set_eapol = auth_set_eapol;
427 1.1 christos cb.send_eapol = auth_send_eapol;
428 1.1 christos cb.get_psk = auth_get_psk;
429 1.1 christos cb.set_key = auth_set_key;
430 1.1.1.2 christos cb.for_each_sta = auth_for_each_sta;
431 1.1.1.4 christos cb.disconnect = ibss_rsn_disconnect;
432 1.1 christos
433 1.1 christos ibss_rsn->auth_group = wpa_init(own_addr, &conf, &cb);
434 1.1 christos if (ibss_rsn->auth_group == NULL) {
435 1.1 christos wpa_printf(MSG_DEBUG, "AUTH: wpa_init() failed");
436 1.1 christos return -1;
437 1.1 christos }
438 1.1 christos
439 1.1.1.2 christos wpa_init_keys(ibss_rsn->auth_group);
440 1.1.1.2 christos
441 1.1 christos return 0;
442 1.1 christos }
443 1.1 christos
444 1.1 christos
445 1.1 christos static int ibss_rsn_auth_init(struct ibss_rsn *ibss_rsn,
446 1.1 christos struct ibss_rsn_peer *peer)
447 1.1 christos {
448 1.1.1.4 christos peer->auth = wpa_auth_sta_init(ibss_rsn->auth_group, peer->addr, NULL);
449 1.1 christos if (peer->auth == NULL) {
450 1.1 christos wpa_printf(MSG_DEBUG, "AUTH: wpa_auth_sta_init() failed");
451 1.1 christos return -1;
452 1.1 christos }
453 1.1 christos
454 1.1 christos /* TODO: get peer RSN IE with Probe Request */
455 1.1 christos if (wpa_validate_wpa_ie(ibss_rsn->auth_group, peer->auth,
456 1.1 christos (u8 *) "\x30\x14\x01\x00"
457 1.1 christos "\x00\x0f\xac\x04"
458 1.1 christos "\x01\x00\x00\x0f\xac\x04"
459 1.1 christos "\x01\x00\x00\x0f\xac\x02"
460 1.1 christos "\x00\x00", 22, NULL, 0) !=
461 1.1 christos WPA_IE_OK) {
462 1.1 christos wpa_printf(MSG_DEBUG, "AUTH: wpa_validate_wpa_ie() failed");
463 1.1 christos return -1;
464 1.1 christos }
465 1.1 christos
466 1.1 christos if (wpa_auth_sm_event(peer->auth, WPA_ASSOC))
467 1.1 christos return -1;
468 1.1 christos
469 1.1 christos if (wpa_auth_sta_associated(ibss_rsn->auth_group, peer->auth))
470 1.1 christos return -1;
471 1.1 christos
472 1.1 christos return 0;
473 1.1 christos }
474 1.1 christos
475 1.1 christos
476 1.1.1.4 christos static int ibss_rsn_send_auth(struct ibss_rsn *ibss_rsn, const u8 *da, int seq)
477 1.1 christos {
478 1.1.1.4 christos struct ieee80211_mgmt auth;
479 1.1.1.4 christos const size_t auth_length = IEEE80211_HDRLEN + sizeof(auth.u.auth);
480 1.1.1.4 christos struct wpa_supplicant *wpa_s = ibss_rsn->wpa_s;
481 1.1 christos
482 1.1.1.4 christos if (wpa_s->driver->send_frame == NULL)
483 1.1.1.2 christos return -1;
484 1.1.1.2 christos
485 1.1.1.4 christos os_memset(&auth, 0, sizeof(auth));
486 1.1.1.4 christos
487 1.1.1.4 christos auth.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
488 1.1.1.4 christos WLAN_FC_STYPE_AUTH);
489 1.1.1.4 christos os_memcpy(auth.da, da, ETH_ALEN);
490 1.1.1.4 christos os_memcpy(auth.sa, wpa_s->own_addr, ETH_ALEN);
491 1.1.1.4 christos os_memcpy(auth.bssid, wpa_s->bssid, ETH_ALEN);
492 1.1.1.4 christos
493 1.1.1.4 christos auth.u.auth.auth_alg = host_to_le16(WLAN_AUTH_OPEN);
494 1.1.1.4 christos auth.u.auth.auth_transaction = host_to_le16(seq);
495 1.1.1.4 christos auth.u.auth.status_code = host_to_le16(WLAN_STATUS_SUCCESS);
496 1.1.1.4 christos
497 1.1.1.4 christos wpa_printf(MSG_DEBUG, "RSN: IBSS TX Auth frame (SEQ %d) to " MACSTR,
498 1.1.1.4 christos seq, MAC2STR(da));
499 1.1.1.4 christos
500 1.1.1.4 christos return wpa_s->driver->send_frame(wpa_s->drv_priv, (u8 *) &auth,
501 1.1.1.4 christos auth_length, 0);
502 1.1.1.4 christos }
503 1.1.1.4 christos
504 1.1.1.4 christos
505 1.1.1.4 christos static int ibss_rsn_is_auth_started(struct ibss_rsn_peer * peer)
506 1.1.1.4 christos {
507 1.1.1.4 christos return peer->authentication_status &
508 1.1.1.4 christos (IBSS_RSN_AUTH_BY_US | IBSS_RSN_AUTH_EAPOL_BY_US);
509 1.1.1.4 christos }
510 1.1.1.4 christos
511 1.1.1.4 christos
512 1.1.1.4 christos static struct ibss_rsn_peer *
513 1.1.1.4 christos ibss_rsn_peer_init(struct ibss_rsn *ibss_rsn, const u8 *addr)
514 1.1.1.4 christos {
515 1.1.1.4 christos struct ibss_rsn_peer *peer;
516 1.1.1.4 christos if (ibss_rsn == NULL)
517 1.1.1.4 christos return NULL;
518 1.1.1.4 christos
519 1.1.1.4 christos peer = ibss_rsn_get_peer(ibss_rsn, addr);
520 1.1.1.4 christos if (peer) {
521 1.1.1.4 christos wpa_printf(MSG_DEBUG, "RSN: IBSS Supplicant for peer "MACSTR
522 1.1.1.4 christos " already running", MAC2STR(addr));
523 1.1.1.4 christos return peer;
524 1.1.1.2 christos }
525 1.1.1.2 christos
526 1.1.1.4 christos wpa_printf(MSG_DEBUG, "RSN: Starting IBSS Supplicant for peer "MACSTR,
527 1.1.1.4 christos MAC2STR(addr));
528 1.1 christos
529 1.1 christos peer = os_zalloc(sizeof(*peer));
530 1.1.1.4 christos if (peer == NULL) {
531 1.1.1.4 christos wpa_printf(MSG_DEBUG, "RSN: Could not allocate memory.");
532 1.1.1.4 christos return NULL;
533 1.1.1.4 christos }
534 1.1 christos
535 1.1 christos peer->ibss_rsn = ibss_rsn;
536 1.1 christos os_memcpy(peer->addr, addr, ETH_ALEN);
537 1.1.1.4 christos peer->authentication_status = IBSS_RSN_AUTH_NOT_AUTHENTICATED;
538 1.1 christos
539 1.1.1.4 christos if (ibss_rsn_supp_init(peer, ibss_rsn->wpa_s->own_addr,
540 1.1.1.4 christos ibss_rsn->psk) < 0) {
541 1.1 christos ibss_rsn_free(peer);
542 1.1.1.4 christos return NULL;
543 1.1.1.4 christos }
544 1.1.1.4 christos
545 1.1.1.4 christos peer->next = ibss_rsn->peers;
546 1.1.1.4 christos ibss_rsn->peers = peer;
547 1.1.1.4 christos
548 1.1.1.4 christos return peer;
549 1.1.1.4 christos }
550 1.1.1.4 christos
551 1.1.1.4 christos
552 1.1.1.4 christos static void ibss_rsn_auth_timeout(void *eloop_ctx, void *timeout_ctx)
553 1.1.1.4 christos {
554 1.1.1.4 christos struct ibss_rsn_peer *peer = eloop_ctx;
555 1.1.1.4 christos
556 1.1.1.4 christos /*
557 1.1.1.4 christos * Assume peer does not support Authentication exchange or the frame was
558 1.1.1.4 christos * lost somewhere - start EAPOL Authenticator.
559 1.1.1.4 christos */
560 1.1.1.4 christos wpa_printf(MSG_DEBUG,
561 1.1.1.4 christos "RSN: Timeout on waiting Authentication frame response from "
562 1.1.1.4 christos MACSTR " - start authenticator", MAC2STR(peer->addr));
563 1.1.1.4 christos
564 1.1.1.4 christos peer->authentication_status |= IBSS_RSN_AUTH_BY_US;
565 1.1.1.4 christos ibss_rsn_auth_init(peer->ibss_rsn, peer);
566 1.1.1.4 christos }
567 1.1.1.4 christos
568 1.1.1.4 christos
569 1.1.1.4 christos int ibss_rsn_start(struct ibss_rsn *ibss_rsn, const u8 *addr)
570 1.1.1.4 christos {
571 1.1.1.4 christos struct ibss_rsn_peer *peer;
572 1.1.1.4 christos int res;
573 1.1.1.4 christos
574 1.1.1.4 christos /* if the peer already exists, exit immediately */
575 1.1.1.4 christos peer = ibss_rsn_get_peer(ibss_rsn, addr);
576 1.1.1.4 christos if (peer)
577 1.1.1.4 christos return 0;
578 1.1.1.4 christos
579 1.1.1.4 christos peer = ibss_rsn_peer_init(ibss_rsn, addr);
580 1.1.1.4 christos if (peer == NULL)
581 1.1 christos return -1;
582 1.1.1.4 christos
583 1.1.1.4 christos /* Open Authentication: send first Authentication frame */
584 1.1.1.4 christos res = ibss_rsn_send_auth(ibss_rsn, addr, 1);
585 1.1.1.4 christos if (res) {
586 1.1.1.4 christos /*
587 1.1.1.4 christos * The driver may not support Authentication frame exchange in
588 1.1.1.4 christos * IBSS. Ignore authentication and go through EAPOL exchange.
589 1.1.1.4 christos */
590 1.1.1.4 christos peer->authentication_status |= IBSS_RSN_AUTH_BY_US;
591 1.1.1.4 christos return ibss_rsn_auth_init(ibss_rsn, peer);
592 1.1.1.4 christos } else {
593 1.1.1.4 christos os_get_reltime(&peer->own_auth_tx);
594 1.1.1.4 christos eloop_register_timeout(1, 0, ibss_rsn_auth_timeout, peer, NULL);
595 1.1 christos }
596 1.1 christos
597 1.1.1.4 christos return 0;
598 1.1.1.4 christos }
599 1.1.1.4 christos
600 1.1.1.4 christos
601 1.1.1.4 christos static int ibss_rsn_peer_authenticated(struct ibss_rsn *ibss_rsn,
602 1.1.1.4 christos struct ibss_rsn_peer *peer, int reason)
603 1.1.1.4 christos {
604 1.1.1.4 christos int already_started;
605 1.1.1.4 christos
606 1.1.1.4 christos if (ibss_rsn == NULL || peer == NULL)
607 1.1 christos return -1;
608 1.1.1.4 christos
609 1.1.1.4 christos already_started = ibss_rsn_is_auth_started(peer);
610 1.1.1.4 christos peer->authentication_status |= reason;
611 1.1.1.4 christos
612 1.1.1.4 christos if (already_started) {
613 1.1.1.4 christos wpa_printf(MSG_DEBUG, "RSN: IBSS Authenticator already "
614 1.1.1.4 christos "started for peer " MACSTR, MAC2STR(peer->addr));
615 1.1.1.4 christos return 0;
616 1.1 christos }
617 1.1 christos
618 1.1.1.4 christos wpa_printf(MSG_DEBUG, "RSN: Starting IBSS Authenticator "
619 1.1.1.4 christos "for now-authenticated peer " MACSTR, MAC2STR(peer->addr));
620 1.1 christos
621 1.1.1.4 christos return ibss_rsn_auth_init(ibss_rsn, peer);
622 1.1 christos }
623 1.1 christos
624 1.1 christos
625 1.1.1.2 christos void ibss_rsn_stop(struct ibss_rsn *ibss_rsn, const u8 *peermac)
626 1.1.1.2 christos {
627 1.1.1.2 christos struct ibss_rsn_peer *peer, *prev;
628 1.1.1.2 christos
629 1.1.1.2 christos if (ibss_rsn == NULL)
630 1.1.1.2 christos return;
631 1.1.1.2 christos
632 1.1.1.2 christos if (peermac == NULL) {
633 1.1.1.2 christos /* remove all peers */
634 1.1.1.2 christos wpa_printf(MSG_DEBUG, "%s: Remove all peers", __func__);
635 1.1.1.2 christos peer = ibss_rsn->peers;
636 1.1.1.2 christos while (peer) {
637 1.1.1.2 christos prev = peer;
638 1.1.1.2 christos peer = peer->next;
639 1.1.1.2 christos ibss_rsn_free(prev);
640 1.1.1.2 christos ibss_rsn->peers = peer;
641 1.1.1.2 christos }
642 1.1.1.2 christos } else {
643 1.1.1.2 christos /* remove specific peer */
644 1.1.1.2 christos wpa_printf(MSG_DEBUG, "%s: Remove specific peer " MACSTR,
645 1.1.1.2 christos __func__, MAC2STR(peermac));
646 1.1.1.2 christos
647 1.1.1.2 christos for (prev = NULL, peer = ibss_rsn->peers; peer != NULL;
648 1.1.1.2 christos prev = peer, peer = peer->next) {
649 1.1.1.2 christos if (os_memcmp(peermac, peer->addr, ETH_ALEN) == 0) {
650 1.1.1.2 christos if (prev == NULL)
651 1.1.1.2 christos ibss_rsn->peers = peer->next;
652 1.1.1.2 christos else
653 1.1.1.2 christos prev->next = peer->next;
654 1.1.1.2 christos ibss_rsn_free(peer);
655 1.1.1.2 christos wpa_printf(MSG_DEBUG, "%s: Successfully "
656 1.1.1.2 christos "removed a specific peer",
657 1.1.1.2 christos __func__);
658 1.1.1.2 christos break;
659 1.1.1.2 christos }
660 1.1.1.2 christos }
661 1.1.1.2 christos }
662 1.1.1.2 christos }
663 1.1.1.2 christos
664 1.1.1.2 christos
665 1.1 christos struct ibss_rsn * ibss_rsn_init(struct wpa_supplicant *wpa_s)
666 1.1 christos {
667 1.1 christos struct ibss_rsn *ibss_rsn;
668 1.1 christos
669 1.1 christos ibss_rsn = os_zalloc(sizeof(*ibss_rsn));
670 1.1 christos if (ibss_rsn == NULL)
671 1.1 christos return NULL;
672 1.1 christos ibss_rsn->wpa_s = wpa_s;
673 1.1 christos
674 1.1 christos if (ibss_rsn_auth_init_group(ibss_rsn, wpa_s->own_addr) < 0) {
675 1.1 christos ibss_rsn_deinit(ibss_rsn);
676 1.1 christos return NULL;
677 1.1 christos }
678 1.1 christos
679 1.1 christos return ibss_rsn;
680 1.1 christos }
681 1.1 christos
682 1.1 christos
683 1.1 christos void ibss_rsn_deinit(struct ibss_rsn *ibss_rsn)
684 1.1 christos {
685 1.1 christos struct ibss_rsn_peer *peer, *prev;
686 1.1 christos
687 1.1 christos if (ibss_rsn == NULL)
688 1.1 christos return;
689 1.1 christos
690 1.1 christos peer = ibss_rsn->peers;
691 1.1 christos while (peer) {
692 1.1 christos prev = peer;
693 1.1 christos peer = peer->next;
694 1.1 christos ibss_rsn_free(prev);
695 1.1 christos }
696 1.1 christos
697 1.1 christos wpa_deinit(ibss_rsn->auth_group);
698 1.1 christos os_free(ibss_rsn);
699 1.1 christos
700 1.1 christos }
701 1.1 christos
702 1.1 christos
703 1.1 christos static int ibss_rsn_eapol_dst_supp(const u8 *buf, size_t len)
704 1.1 christos {
705 1.1 christos const struct ieee802_1x_hdr *hdr;
706 1.1 christos const struct wpa_eapol_key *key;
707 1.1 christos u16 key_info;
708 1.1 christos size_t plen;
709 1.1 christos
710 1.1 christos /* TODO: Support other EAPOL packets than just EAPOL-Key */
711 1.1 christos
712 1.1 christos if (len < sizeof(*hdr) + sizeof(*key))
713 1.1 christos return -1;
714 1.1 christos
715 1.1 christos hdr = (const struct ieee802_1x_hdr *) buf;
716 1.1 christos key = (const struct wpa_eapol_key *) (hdr + 1);
717 1.1 christos plen = be_to_host16(hdr->length);
718 1.1 christos
719 1.1 christos if (hdr->version < EAPOL_VERSION) {
720 1.1 christos /* TODO: backwards compatibility */
721 1.1 christos }
722 1.1 christos if (hdr->type != IEEE802_1X_TYPE_EAPOL_KEY) {
723 1.1 christos wpa_printf(MSG_DEBUG, "RSN: EAPOL frame (type %u) discarded, "
724 1.1 christos "not a Key frame", hdr->type);
725 1.1 christos return -1;
726 1.1 christos }
727 1.1 christos if (plen > len - sizeof(*hdr) || plen < sizeof(*key)) {
728 1.1 christos wpa_printf(MSG_DEBUG, "RSN: EAPOL frame payload size %lu "
729 1.1 christos "invalid (frame size %lu)",
730 1.1 christos (unsigned long) plen, (unsigned long) len);
731 1.1 christos return -1;
732 1.1 christos }
733 1.1 christos
734 1.1 christos if (key->type != EAPOL_KEY_TYPE_RSN) {
735 1.1 christos wpa_printf(MSG_DEBUG, "RSN: EAPOL-Key type (%d) unknown, "
736 1.1 christos "discarded", key->type);
737 1.1 christos return -1;
738 1.1 christos }
739 1.1 christos
740 1.1 christos key_info = WPA_GET_BE16(key->key_info);
741 1.1 christos
742 1.1 christos return !!(key_info & WPA_KEY_INFO_ACK);
743 1.1 christos }
744 1.1 christos
745 1.1 christos
746 1.1 christos static int ibss_rsn_process_rx_eapol(struct ibss_rsn *ibss_rsn,
747 1.1 christos struct ibss_rsn_peer *peer,
748 1.1 christos const u8 *buf, size_t len)
749 1.1 christos {
750 1.1 christos int supp;
751 1.1 christos u8 *tmp;
752 1.1 christos
753 1.1 christos supp = ibss_rsn_eapol_dst_supp(buf, len);
754 1.1 christos if (supp < 0)
755 1.1 christos return -1;
756 1.1 christos
757 1.1 christos tmp = os_malloc(len);
758 1.1 christos if (tmp == NULL)
759 1.1 christos return -1;
760 1.1 christos os_memcpy(tmp, buf, len);
761 1.1 christos if (supp) {
762 1.1.1.4 christos peer->authentication_status |= IBSS_RSN_AUTH_EAPOL_BY_PEER;
763 1.1.1.4 christos wpa_printf(MSG_DEBUG, "RSN: IBSS RX EAPOL for Supplicant from "
764 1.1.1.4 christos MACSTR, MAC2STR(peer->addr));
765 1.1 christos wpa_sm_rx_eapol(peer->supp, peer->addr, tmp, len);
766 1.1 christos } else {
767 1.1.1.4 christos if (ibss_rsn_is_auth_started(peer) == 0) {
768 1.1.1.4 christos wpa_printf(MSG_DEBUG, "RSN: IBSS EAPOL for "
769 1.1.1.4 christos "Authenticator dropped as " MACSTR " is not "
770 1.1.1.4 christos "authenticated", MAC2STR(peer->addr));
771 1.1.1.4 christos os_free(tmp);
772 1.1.1.4 christos return -1;
773 1.1.1.4 christos }
774 1.1.1.4 christos
775 1.1.1.4 christos wpa_printf(MSG_DEBUG, "RSN: IBSS RX EAPOL for Authenticator "
776 1.1.1.4 christos "from "MACSTR, MAC2STR(peer->addr));
777 1.1 christos wpa_receive(ibss_rsn->auth_group, peer->auth, tmp, len);
778 1.1 christos }
779 1.1 christos os_free(tmp);
780 1.1 christos
781 1.1 christos return 1;
782 1.1 christos }
783 1.1 christos
784 1.1 christos
785 1.1 christos int ibss_rsn_rx_eapol(struct ibss_rsn *ibss_rsn, const u8 *src_addr,
786 1.1 christos const u8 *buf, size_t len)
787 1.1 christos {
788 1.1 christos struct ibss_rsn_peer *peer;
789 1.1 christos
790 1.1.1.2 christos if (ibss_rsn == NULL)
791 1.1.1.2 christos return -1;
792 1.1.1.2 christos
793 1.1.1.3 christos peer = ibss_rsn_get_peer(ibss_rsn, src_addr);
794 1.1.1.3 christos if (peer)
795 1.1.1.3 christos return ibss_rsn_process_rx_eapol(ibss_rsn, peer, buf, len);
796 1.1 christos
797 1.1 christos if (ibss_rsn_eapol_dst_supp(buf, len) > 0) {
798 1.1 christos /*
799 1.1 christos * Create new IBSS peer based on an EAPOL message from the peer
800 1.1 christos * Authenticator.
801 1.1 christos */
802 1.1.1.4 christos peer = ibss_rsn_peer_init(ibss_rsn, src_addr);
803 1.1.1.4 christos if (peer == NULL)
804 1.1 christos return -1;
805 1.1.1.4 christos
806 1.1.1.4 christos /* assume the peer is authenticated already */
807 1.1.1.4 christos wpa_printf(MSG_DEBUG, "RSN: IBSS Not using IBSS Auth for peer "
808 1.1.1.4 christos MACSTR, MAC2STR(src_addr));
809 1.1.1.4 christos ibss_rsn_peer_authenticated(ibss_rsn, peer,
810 1.1.1.4 christos IBSS_RSN_AUTH_EAPOL_BY_US);
811 1.1.1.4 christos
812 1.1 christos return ibss_rsn_process_rx_eapol(ibss_rsn, ibss_rsn->peers,
813 1.1 christos buf, len);
814 1.1 christos }
815 1.1 christos
816 1.1 christos return 0;
817 1.1 christos }
818 1.1 christos
819 1.1 christos void ibss_rsn_set_psk(struct ibss_rsn *ibss_rsn, const u8 *psk)
820 1.1 christos {
821 1.1.1.2 christos if (ibss_rsn == NULL)
822 1.1.1.2 christos return;
823 1.1 christos os_memcpy(ibss_rsn->psk, psk, PMK_LEN);
824 1.1 christos }
825 1.1.1.4 christos
826 1.1.1.4 christos
827 1.1.1.4 christos static void ibss_rsn_handle_auth_1_of_2(struct ibss_rsn *ibss_rsn,
828 1.1.1.4 christos struct ibss_rsn_peer *peer,
829 1.1.1.4 christos const u8* addr)
830 1.1.1.4 christos {
831 1.1.1.4 christos wpa_printf(MSG_DEBUG, "RSN: IBSS RX Auth frame (SEQ 1) from " MACSTR,
832 1.1.1.4 christos MAC2STR(addr));
833 1.1.1.4 christos
834 1.1.1.4 christos if (peer &&
835 1.1.1.4 christos peer->authentication_status & IBSS_RSN_AUTH_EAPOL_BY_PEER) {
836 1.1.1.4 christos if (peer->own_auth_tx.sec) {
837 1.1.1.4 christos struct os_reltime now, diff;
838 1.1.1.4 christos os_get_reltime(&now);
839 1.1.1.4 christos os_reltime_sub(&now, &peer->own_auth_tx, &diff);
840 1.1.1.4 christos if (diff.sec == 0 && diff.usec < 500000) {
841 1.1.1.4 christos wpa_printf(MSG_DEBUG, "RSN: Skip IBSS reinit since only %u usec from own Auth frame TX",
842 1.1.1.4 christos (int) diff.usec);
843 1.1.1.4 christos goto skip_reinit;
844 1.1.1.4 christos }
845 1.1.1.4 christos }
846 1.1.1.4 christos /*
847 1.1.1.4 christos * A peer sent us an Authentication frame even though it already
848 1.1.1.4 christos * started an EAPOL session. We should reinit state machines
849 1.1.1.4 christos * here, but it's much more complicated than just deleting and
850 1.1.1.4 christos * recreating the state machine
851 1.1.1.4 christos */
852 1.1.1.4 christos wpa_printf(MSG_DEBUG, "RSN: IBSS Reinitializing station "
853 1.1.1.4 christos MACSTR, MAC2STR(addr));
854 1.1.1.4 christos
855 1.1.1.4 christos ibss_rsn_stop(ibss_rsn, addr);
856 1.1.1.4 christos peer = NULL;
857 1.1.1.4 christos }
858 1.1.1.4 christos
859 1.1.1.4 christos if (!peer) {
860 1.1.1.4 christos peer = ibss_rsn_peer_init(ibss_rsn, addr);
861 1.1.1.4 christos if (!peer)
862 1.1.1.4 christos return;
863 1.1.1.4 christos
864 1.1.1.4 christos wpa_printf(MSG_DEBUG, "RSN: IBSS Auth started by peer " MACSTR,
865 1.1.1.4 christos MAC2STR(addr));
866 1.1.1.4 christos }
867 1.1.1.4 christos
868 1.1.1.4 christos skip_reinit:
869 1.1.1.4 christos /* reply with an Authentication frame now, before sending an EAPOL */
870 1.1.1.4 christos ibss_rsn_send_auth(ibss_rsn, addr, 2);
871 1.1.1.4 christos /* no need to start another AUTH challenge in the other way.. */
872 1.1.1.4 christos ibss_rsn_peer_authenticated(ibss_rsn, peer, IBSS_RSN_AUTH_EAPOL_BY_US);
873 1.1.1.4 christos }
874 1.1.1.4 christos
875 1.1.1.4 christos
876 1.1.1.4 christos void ibss_rsn_handle_auth(struct ibss_rsn *ibss_rsn, const u8 *auth_frame,
877 1.1.1.4 christos size_t len)
878 1.1.1.4 christos {
879 1.1.1.4 christos const struct ieee80211_mgmt *header;
880 1.1.1.4 christos struct ibss_rsn_peer *peer;
881 1.1.1.4 christos size_t auth_length;
882 1.1.1.4 christos
883 1.1.1.4 christos header = (const struct ieee80211_mgmt *) auth_frame;
884 1.1.1.4 christos auth_length = IEEE80211_HDRLEN + sizeof(header->u.auth);
885 1.1.1.4 christos
886 1.1.1.4 christos if (ibss_rsn == NULL || len < auth_length)
887 1.1.1.4 christos return;
888 1.1.1.4 christos
889 1.1.1.4 christos if (le_to_host16(header->u.auth.auth_alg) != WLAN_AUTH_OPEN ||
890 1.1.1.4 christos le_to_host16(header->u.auth.status_code) != WLAN_STATUS_SUCCESS)
891 1.1.1.4 christos return;
892 1.1.1.4 christos
893 1.1.1.4 christos peer = ibss_rsn_get_peer(ibss_rsn, header->sa);
894 1.1.1.4 christos
895 1.1.1.4 christos switch (le_to_host16(header->u.auth.auth_transaction)) {
896 1.1.1.4 christos case 1:
897 1.1.1.4 christos ibss_rsn_handle_auth_1_of_2(ibss_rsn, peer, header->sa);
898 1.1.1.4 christos break;
899 1.1.1.4 christos case 2:
900 1.1.1.4 christos wpa_printf(MSG_DEBUG, "RSN: IBSS RX Auth frame (SEQ 2) from "
901 1.1.1.4 christos MACSTR, MAC2STR(header->sa));
902 1.1.1.4 christos if (!peer) {
903 1.1.1.4 christos wpa_printf(MSG_DEBUG, "RSN: Received Auth seq 2 from "
904 1.1.1.4 christos "unknown STA " MACSTR, MAC2STR(header->sa));
905 1.1.1.4 christos break;
906 1.1.1.4 christos }
907 1.1.1.4 christos
908 1.1.1.4 christos /* authentication has been completed */
909 1.1.1.4 christos eloop_cancel_timeout(ibss_rsn_auth_timeout, peer, NULL);
910 1.1.1.4 christos wpa_printf(MSG_DEBUG, "RSN: IBSS Auth completed with " MACSTR,
911 1.1.1.4 christos MAC2STR(header->sa));
912 1.1.1.4 christos ibss_rsn_peer_authenticated(ibss_rsn, peer,
913 1.1.1.4 christos IBSS_RSN_AUTH_BY_US);
914 1.1.1.4 christos break;
915 1.1.1.4 christos }
916 1.1.1.4 christos }
917