ibss_rsn.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /*
  2. * wpa_supplicant - IBSS RSN
  3. * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "includes.h"
  9. #include "common.h"
  10. #include "l2_packet/l2_packet.h"
  11. #include "rsn_supp/wpa.h"
  12. #include "rsn_supp/wpa_ie.h"
  13. #include "ap/wpa_auth.h"
  14. #include "wpa_supplicant_i.h"
  15. #include "driver_i.h"
  16. #include "ibss_rsn.h"
  17. static struct ibss_rsn_peer * ibss_rsn_get_peer(struct ibss_rsn *ibss_rsn,
  18. const u8 *addr)
  19. {
  20. struct ibss_rsn_peer *peer;
  21. for (peer = ibss_rsn->peers; peer; peer = peer->next)
  22. if (os_memcmp(addr, peer->addr, ETH_ALEN) == 0)
  23. break;
  24. return peer;
  25. }
  26. static void ibss_rsn_free(struct ibss_rsn_peer *peer)
  27. {
  28. wpa_auth_sta_deinit(peer->auth);
  29. wpa_sm_deinit(peer->supp);
  30. os_free(peer);
  31. }
  32. static void supp_set_state(void *ctx, enum wpa_states state)
  33. {
  34. struct ibss_rsn_peer *peer = ctx;
  35. peer->supp_state = state;
  36. }
  37. static enum wpa_states supp_get_state(void *ctx)
  38. {
  39. struct ibss_rsn_peer *peer = ctx;
  40. return peer->supp_state;
  41. }
  42. static int supp_ether_send(void *ctx, const u8 *dest, u16 proto, const u8 *buf,
  43. size_t len)
  44. {
  45. struct ibss_rsn_peer *peer = ctx;
  46. struct wpa_supplicant *wpa_s = peer->ibss_rsn->wpa_s;
  47. wpa_printf(MSG_DEBUG, "SUPP: %s(dest=" MACSTR " proto=0x%04x "
  48. "len=%lu)",
  49. __func__, MAC2STR(dest), proto, (unsigned long) len);
  50. if (wpa_s->l2)
  51. return l2_packet_send(wpa_s->l2, dest, proto, buf, len);
  52. return wpa_drv_send_eapol(wpa_s, dest, proto, buf, len);
  53. }
  54. static u8 * supp_alloc_eapol(void *ctx, u8 type, const void *data,
  55. u16 data_len, size_t *msg_len, void **data_pos)
  56. {
  57. struct ieee802_1x_hdr *hdr;
  58. wpa_printf(MSG_DEBUG, "SUPP: %s(type=%d data_len=%d)",
  59. __func__, type, data_len);
  60. *msg_len = sizeof(*hdr) + data_len;
  61. hdr = os_malloc(*msg_len);
  62. if (hdr == NULL)
  63. return NULL;
  64. hdr->version = 2;
  65. hdr->type = type;
  66. hdr->length = host_to_be16(data_len);
  67. if (data)
  68. os_memcpy(hdr + 1, data, data_len);
  69. else
  70. os_memset(hdr + 1, 0, data_len);
  71. if (data_pos)
  72. *data_pos = hdr + 1;
  73. return (u8 *) hdr;
  74. }
  75. static int supp_get_beacon_ie(void *ctx)
  76. {
  77. struct ibss_rsn_peer *peer = ctx;
  78. wpa_printf(MSG_DEBUG, "SUPP: %s", __func__);
  79. /* TODO: get correct RSN IE */
  80. return wpa_sm_set_ap_rsn_ie(peer->supp,
  81. (u8 *) "\x30\x14\x01\x00"
  82. "\x00\x0f\xac\x04"
  83. "\x01\x00\x00\x0f\xac\x04"
  84. "\x01\x00\x00\x0f\xac\x02"
  85. "\x00\x00", 22);
  86. }
  87. static int supp_set_key(void *ctx, enum wpa_alg alg,
  88. const u8 *addr, int key_idx, int set_tx,
  89. const u8 *seq, size_t seq_len,
  90. const u8 *key, size_t key_len)
  91. {
  92. struct ibss_rsn_peer *peer = ctx;
  93. wpa_printf(MSG_DEBUG, "SUPP: %s(alg=%d addr=" MACSTR " key_idx=%d "
  94. "set_tx=%d)",
  95. __func__, alg, MAC2STR(addr), key_idx, set_tx);
  96. wpa_hexdump(MSG_DEBUG, "SUPP: set_key - seq", seq, seq_len);
  97. wpa_hexdump_key(MSG_DEBUG, "SUPP: set_key - key", key, key_len);
  98. if (key_idx == 0) {
  99. /*
  100. * In IBSS RSN, the pairwise key from the 4-way handshake
  101. * initiated by the peer with highest MAC address is used.
  102. */
  103. if (os_memcmp(peer->ibss_rsn->wpa_s->own_addr, peer->addr,
  104. ETH_ALEN) > 0) {
  105. wpa_printf(MSG_DEBUG, "SUPP: Do not use this PTK");
  106. return 0;
  107. }
  108. }
  109. if (is_broadcast_ether_addr(addr))
  110. addr = peer->addr;
  111. return wpa_drv_set_key(peer->ibss_rsn->wpa_s, alg, addr, key_idx,
  112. set_tx, seq, seq_len, key, key_len);
  113. }
  114. static void * supp_get_network_ctx(void *ctx)
  115. {
  116. struct ibss_rsn_peer *peer = ctx;
  117. return wpa_supplicant_get_ssid(peer->ibss_rsn->wpa_s);
  118. }
  119. static int supp_mlme_setprotection(void *ctx, const u8 *addr,
  120. int protection_type, int key_type)
  121. {
  122. wpa_printf(MSG_DEBUG, "SUPP: %s(addr=" MACSTR " protection_type=%d "
  123. "key_type=%d)",
  124. __func__, MAC2STR(addr), protection_type, key_type);
  125. return 0;
  126. }
  127. static void supp_cancel_auth_timeout(void *ctx)
  128. {
  129. wpa_printf(MSG_DEBUG, "SUPP: %s", __func__);
  130. }
  131. static void supp_deauthenticate(void * ctx, int reason_code)
  132. {
  133. wpa_printf(MSG_DEBUG, "SUPP: %s (TODO)", __func__);
  134. }
  135. static int ibss_rsn_supp_init(struct ibss_rsn_peer *peer, const u8 *own_addr,
  136. const u8 *psk)
  137. {
  138. struct wpa_sm_ctx *ctx = os_zalloc(sizeof(*ctx));
  139. if (ctx == NULL)
  140. return -1;
  141. ctx->ctx = peer;
  142. ctx->msg_ctx = peer->ibss_rsn->wpa_s;
  143. ctx->set_state = supp_set_state;
  144. ctx->get_state = supp_get_state;
  145. ctx->ether_send = supp_ether_send;
  146. ctx->get_beacon_ie = supp_get_beacon_ie;
  147. ctx->alloc_eapol = supp_alloc_eapol;
  148. ctx->set_key = supp_set_key;
  149. ctx->get_network_ctx = supp_get_network_ctx;
  150. ctx->mlme_setprotection = supp_mlme_setprotection;
  151. ctx->cancel_auth_timeout = supp_cancel_auth_timeout;
  152. ctx->deauthenticate = supp_deauthenticate;
  153. peer->supp = wpa_sm_init(ctx);
  154. if (peer->supp == NULL) {
  155. wpa_printf(MSG_DEBUG, "SUPP: wpa_sm_init() failed");
  156. return -1;
  157. }
  158. wpa_sm_set_own_addr(peer->supp, own_addr);
  159. wpa_sm_set_param(peer->supp, WPA_PARAM_RSN_ENABLED, 1);
  160. wpa_sm_set_param(peer->supp, WPA_PARAM_PROTO, WPA_PROTO_RSN);
  161. wpa_sm_set_param(peer->supp, WPA_PARAM_PAIRWISE, WPA_CIPHER_CCMP);
  162. wpa_sm_set_param(peer->supp, WPA_PARAM_GROUP, WPA_CIPHER_CCMP);
  163. wpa_sm_set_param(peer->supp, WPA_PARAM_KEY_MGMT, WPA_KEY_MGMT_PSK);
  164. wpa_sm_set_pmk(peer->supp, psk, PMK_LEN);
  165. peer->supp_ie_len = sizeof(peer->supp_ie);
  166. if (wpa_sm_set_assoc_wpa_ie_default(peer->supp, peer->supp_ie,
  167. &peer->supp_ie_len) < 0) {
  168. wpa_printf(MSG_DEBUG, "SUPP: wpa_sm_set_assoc_wpa_ie_default()"
  169. " failed");
  170. return -1;
  171. }
  172. wpa_sm_notify_assoc(peer->supp, peer->addr);
  173. return 0;
  174. }
  175. static void auth_logger(void *ctx, const u8 *addr, logger_level level,
  176. const char *txt)
  177. {
  178. if (addr)
  179. wpa_printf(MSG_DEBUG, "AUTH: " MACSTR " - %s",
  180. MAC2STR(addr), txt);
  181. else
  182. wpa_printf(MSG_DEBUG, "AUTH: %s", txt);
  183. }
  184. static const u8 * auth_get_psk(void *ctx, const u8 *addr, const u8 *prev_psk)
  185. {
  186. struct ibss_rsn *ibss_rsn = ctx;
  187. wpa_printf(MSG_DEBUG, "AUTH: %s (addr=" MACSTR " prev_psk=%p)",
  188. __func__, MAC2STR(addr), prev_psk);
  189. if (prev_psk)
  190. return NULL;
  191. return ibss_rsn->psk;
  192. }
  193. static int auth_send_eapol(void *ctx, const u8 *addr, const u8 *data,
  194. size_t data_len, int encrypt)
  195. {
  196. struct ibss_rsn *ibss_rsn = ctx;
  197. struct wpa_supplicant *wpa_s = ibss_rsn->wpa_s;
  198. wpa_printf(MSG_DEBUG, "AUTH: %s(addr=" MACSTR " data_len=%lu "
  199. "encrypt=%d)",
  200. __func__, MAC2STR(addr), (unsigned long) data_len, encrypt);
  201. if (wpa_s->l2)
  202. return l2_packet_send(wpa_s->l2, addr, ETH_P_EAPOL, data,
  203. data_len);
  204. return wpa_drv_send_eapol(wpa_s, addr, ETH_P_EAPOL, data, data_len);
  205. }
  206. static int auth_set_key(void *ctx, int vlan_id, enum wpa_alg alg,
  207. const u8 *addr, int idx, u8 *key, size_t key_len)
  208. {
  209. struct ibss_rsn *ibss_rsn = ctx;
  210. u8 seq[6];
  211. os_memset(seq, 0, sizeof(seq));
  212. if (addr) {
  213. wpa_printf(MSG_DEBUG, "AUTH: %s(alg=%d addr=" MACSTR
  214. " key_idx=%d)",
  215. __func__, alg, MAC2STR(addr), idx);
  216. } else {
  217. wpa_printf(MSG_DEBUG, "AUTH: %s(alg=%d key_idx=%d)",
  218. __func__, alg, idx);
  219. }
  220. wpa_hexdump_key(MSG_DEBUG, "AUTH: set_key - key", key, key_len);
  221. if (idx == 0) {
  222. /*
  223. * In IBSS RSN, the pairwise key from the 4-way handshake
  224. * initiated by the peer with highest MAC address is used.
  225. */
  226. if (addr == NULL ||
  227. os_memcmp(ibss_rsn->wpa_s->own_addr, addr, ETH_ALEN) < 0) {
  228. wpa_printf(MSG_DEBUG, "AUTH: Do not use this PTK");
  229. return 0;
  230. }
  231. }
  232. return wpa_drv_set_key(ibss_rsn->wpa_s, alg, addr, idx,
  233. 1, seq, 6, key, key_len);
  234. }
  235. static void ibss_rsn_disconnect(void *ctx, const u8 *addr, u16 reason)
  236. {
  237. struct ibss_rsn *ibss_rsn = ctx;
  238. wpa_drv_sta_deauth(ibss_rsn->wpa_s, addr, reason);
  239. }
  240. static int auth_for_each_sta(void *ctx, int (*cb)(struct wpa_state_machine *sm,
  241. void *ctx),
  242. void *cb_ctx)
  243. {
  244. struct ibss_rsn *ibss_rsn = ctx;
  245. struct ibss_rsn_peer *peer;
  246. wpa_printf(MSG_DEBUG, "AUTH: for_each_sta");
  247. for (peer = ibss_rsn->peers; peer; peer = peer->next) {
  248. if (peer->auth && cb(peer->auth, cb_ctx))
  249. return 1;
  250. }
  251. return 0;
  252. }
  253. static void ibss_set_sta_authorized(struct ibss_rsn *ibss_rsn,
  254. struct ibss_rsn_peer *peer, int authorized)
  255. {
  256. int res;
  257. if (authorized) {
  258. res = wpa_drv_sta_set_flags(ibss_rsn->wpa_s, peer->addr,
  259. WPA_STA_AUTHORIZED,
  260. WPA_STA_AUTHORIZED, ~0);
  261. wpa_printf(MSG_DEBUG, "AUTH: " MACSTR " authorizing port",
  262. MAC2STR(peer->addr));
  263. } else {
  264. res = wpa_drv_sta_set_flags(ibss_rsn->wpa_s, peer->addr,
  265. 0, 0, ~WPA_STA_AUTHORIZED);
  266. wpa_printf(MSG_DEBUG, "AUTH: " MACSTR " unauthorizing port",
  267. MAC2STR(peer->addr));
  268. }
  269. if (res && errno != ENOENT) {
  270. wpa_printf(MSG_DEBUG, "Could not set station " MACSTR " flags "
  271. "for kernel driver (errno=%d)",
  272. MAC2STR(peer->addr), errno);
  273. }
  274. }
  275. static void auth_set_eapol(void *ctx, const u8 *addr,
  276. wpa_eapol_variable var, int value)
  277. {
  278. struct ibss_rsn *ibss_rsn = ctx;
  279. struct ibss_rsn_peer *peer = ibss_rsn_get_peer(ibss_rsn, addr);
  280. if (peer == NULL)
  281. return;
  282. switch (var) {
  283. case WPA_EAPOL_authorized:
  284. ibss_set_sta_authorized(ibss_rsn, peer, value);
  285. break;
  286. default:
  287. /* do not handle any other event */
  288. wpa_printf(MSG_DEBUG, "AUTH: eapol event not handled %d", var);
  289. break;
  290. }
  291. }
  292. static int ibss_rsn_auth_init_group(struct ibss_rsn *ibss_rsn,
  293. const u8 *own_addr)
  294. {
  295. struct wpa_auth_config conf;
  296. struct wpa_auth_callbacks cb;
  297. wpa_printf(MSG_DEBUG, "AUTH: Initializing group state machine");
  298. os_memset(&conf, 0, sizeof(conf));
  299. conf.wpa = 2;
  300. conf.wpa_key_mgmt = WPA_KEY_MGMT_PSK;
  301. conf.wpa_pairwise = WPA_CIPHER_CCMP;
  302. conf.rsn_pairwise = WPA_CIPHER_CCMP;
  303. conf.wpa_group = WPA_CIPHER_CCMP;
  304. conf.eapol_version = 2;
  305. conf.wpa_group_rekey = 600;
  306. os_memset(&cb, 0, sizeof(cb));
  307. cb.ctx = ibss_rsn;
  308. cb.logger = auth_logger;
  309. cb.set_eapol = auth_set_eapol;
  310. cb.send_eapol = auth_send_eapol;
  311. cb.get_psk = auth_get_psk;
  312. cb.set_key = auth_set_key;
  313. cb.for_each_sta = auth_for_each_sta;
  314. cb.disconnect = ibss_rsn_disconnect;
  315. ibss_rsn->auth_group = wpa_init(own_addr, &conf, &cb);
  316. if (ibss_rsn->auth_group == NULL) {
  317. wpa_printf(MSG_DEBUG, "AUTH: wpa_init() failed");
  318. return -1;
  319. }
  320. wpa_init_keys(ibss_rsn->auth_group);
  321. return 0;
  322. }
  323. static int ibss_rsn_auth_init(struct ibss_rsn *ibss_rsn,
  324. struct ibss_rsn_peer *peer)
  325. {
  326. peer->auth = wpa_auth_sta_init(ibss_rsn->auth_group, peer->addr);
  327. if (peer->auth == NULL) {
  328. wpa_printf(MSG_DEBUG, "AUTH: wpa_auth_sta_init() failed");
  329. return -1;
  330. }
  331. /* TODO: get peer RSN IE with Probe Request */
  332. if (wpa_validate_wpa_ie(ibss_rsn->auth_group, peer->auth,
  333. (u8 *) "\x30\x14\x01\x00"
  334. "\x00\x0f\xac\x04"
  335. "\x01\x00\x00\x0f\xac\x04"
  336. "\x01\x00\x00\x0f\xac\x02"
  337. "\x00\x00", 22, NULL, 0) !=
  338. WPA_IE_OK) {
  339. wpa_printf(MSG_DEBUG, "AUTH: wpa_validate_wpa_ie() failed");
  340. return -1;
  341. }
  342. if (wpa_auth_sm_event(peer->auth, WPA_ASSOC))
  343. return -1;
  344. if (wpa_auth_sta_associated(ibss_rsn->auth_group, peer->auth))
  345. return -1;
  346. return 0;
  347. }
  348. int ibss_rsn_start(struct ibss_rsn *ibss_rsn, const u8 *addr)
  349. {
  350. struct ibss_rsn_peer *peer;
  351. if (ibss_rsn == NULL)
  352. return -1;
  353. if (ibss_rsn_get_peer(ibss_rsn, addr)) {
  354. wpa_printf(MSG_DEBUG, "RSN: IBSS Authenticator and Supplicant "
  355. "for peer " MACSTR " already running",
  356. MAC2STR(addr));
  357. return 0;
  358. }
  359. wpa_printf(MSG_DEBUG, "RSN: Starting IBSS Authenticator and "
  360. "Supplicant for peer " MACSTR, MAC2STR(addr));
  361. peer = os_zalloc(sizeof(*peer));
  362. if (peer == NULL)
  363. return -1;
  364. peer->ibss_rsn = ibss_rsn;
  365. os_memcpy(peer->addr, addr, ETH_ALEN);
  366. if (ibss_rsn_supp_init(peer, ibss_rsn->wpa_s->own_addr, ibss_rsn->psk)
  367. < 0) {
  368. ibss_rsn_free(peer);
  369. return -1;
  370. }
  371. if (ibss_rsn_auth_init(ibss_rsn, peer) < 0) {
  372. ibss_rsn_free(peer);
  373. return -1;
  374. }
  375. peer->next = ibss_rsn->peers;
  376. ibss_rsn->peers = peer;
  377. return 0;
  378. }
  379. void ibss_rsn_stop(struct ibss_rsn *ibss_rsn, const u8 *peermac)
  380. {
  381. struct ibss_rsn_peer *peer, *prev;
  382. if (ibss_rsn == NULL)
  383. return;
  384. if (peermac == NULL) {
  385. /* remove all peers */
  386. wpa_printf(MSG_DEBUG, "%s: Remove all peers", __func__);
  387. peer = ibss_rsn->peers;
  388. while (peer) {
  389. prev = peer;
  390. peer = peer->next;
  391. ibss_rsn_free(prev);
  392. ibss_rsn->peers = peer;
  393. }
  394. } else {
  395. /* remove specific peer */
  396. wpa_printf(MSG_DEBUG, "%s: Remove specific peer " MACSTR,
  397. __func__, MAC2STR(peermac));
  398. for (prev = NULL, peer = ibss_rsn->peers; peer != NULL;
  399. prev = peer, peer = peer->next) {
  400. if (os_memcmp(peermac, peer->addr, ETH_ALEN) == 0) {
  401. if (prev == NULL)
  402. ibss_rsn->peers = peer->next;
  403. else
  404. prev->next = peer->next;
  405. ibss_rsn_free(peer);
  406. wpa_printf(MSG_DEBUG, "%s: Successfully "
  407. "removed a specific peer",
  408. __func__);
  409. break;
  410. }
  411. }
  412. }
  413. }
  414. struct ibss_rsn * ibss_rsn_init(struct wpa_supplicant *wpa_s)
  415. {
  416. struct ibss_rsn *ibss_rsn;
  417. ibss_rsn = os_zalloc(sizeof(*ibss_rsn));
  418. if (ibss_rsn == NULL)
  419. return NULL;
  420. ibss_rsn->wpa_s = wpa_s;
  421. if (ibss_rsn_auth_init_group(ibss_rsn, wpa_s->own_addr) < 0) {
  422. ibss_rsn_deinit(ibss_rsn);
  423. return NULL;
  424. }
  425. return ibss_rsn;
  426. }
  427. void ibss_rsn_deinit(struct ibss_rsn *ibss_rsn)
  428. {
  429. struct ibss_rsn_peer *peer, *prev;
  430. if (ibss_rsn == NULL)
  431. return;
  432. peer = ibss_rsn->peers;
  433. while (peer) {
  434. prev = peer;
  435. peer = peer->next;
  436. ibss_rsn_free(prev);
  437. }
  438. wpa_deinit(ibss_rsn->auth_group);
  439. os_free(ibss_rsn);
  440. }
  441. static int ibss_rsn_eapol_dst_supp(const u8 *buf, size_t len)
  442. {
  443. const struct ieee802_1x_hdr *hdr;
  444. const struct wpa_eapol_key *key;
  445. u16 key_info;
  446. size_t plen;
  447. /* TODO: Support other EAPOL packets than just EAPOL-Key */
  448. if (len < sizeof(*hdr) + sizeof(*key))
  449. return -1;
  450. hdr = (const struct ieee802_1x_hdr *) buf;
  451. key = (const struct wpa_eapol_key *) (hdr + 1);
  452. plen = be_to_host16(hdr->length);
  453. if (hdr->version < EAPOL_VERSION) {
  454. /* TODO: backwards compatibility */
  455. }
  456. if (hdr->type != IEEE802_1X_TYPE_EAPOL_KEY) {
  457. wpa_printf(MSG_DEBUG, "RSN: EAPOL frame (type %u) discarded, "
  458. "not a Key frame", hdr->type);
  459. return -1;
  460. }
  461. if (plen > len - sizeof(*hdr) || plen < sizeof(*key)) {
  462. wpa_printf(MSG_DEBUG, "RSN: EAPOL frame payload size %lu "
  463. "invalid (frame size %lu)",
  464. (unsigned long) plen, (unsigned long) len);
  465. return -1;
  466. }
  467. if (key->type != EAPOL_KEY_TYPE_RSN) {
  468. wpa_printf(MSG_DEBUG, "RSN: EAPOL-Key type (%d) unknown, "
  469. "discarded", key->type);
  470. return -1;
  471. }
  472. key_info = WPA_GET_BE16(key->key_info);
  473. return !!(key_info & WPA_KEY_INFO_ACK);
  474. }
  475. static int ibss_rsn_process_rx_eapol(struct ibss_rsn *ibss_rsn,
  476. struct ibss_rsn_peer *peer,
  477. const u8 *buf, size_t len)
  478. {
  479. int supp;
  480. u8 *tmp;
  481. supp = ibss_rsn_eapol_dst_supp(buf, len);
  482. if (supp < 0)
  483. return -1;
  484. tmp = os_malloc(len);
  485. if (tmp == NULL)
  486. return -1;
  487. os_memcpy(tmp, buf, len);
  488. if (supp) {
  489. wpa_printf(MSG_DEBUG, "RSN: IBSS RX EAPOL for Supplicant");
  490. wpa_sm_rx_eapol(peer->supp, peer->addr, tmp, len);
  491. } else {
  492. wpa_printf(MSG_DEBUG, "RSN: IBSS RX EAPOL for Authenticator");
  493. wpa_receive(ibss_rsn->auth_group, peer->auth, tmp, len);
  494. }
  495. os_free(tmp);
  496. return 1;
  497. }
  498. int ibss_rsn_rx_eapol(struct ibss_rsn *ibss_rsn, const u8 *src_addr,
  499. const u8 *buf, size_t len)
  500. {
  501. struct ibss_rsn_peer *peer;
  502. if (ibss_rsn == NULL)
  503. return -1;
  504. peer = ibss_rsn_get_peer(ibss_rsn, src_addr);
  505. if (peer)
  506. return ibss_rsn_process_rx_eapol(ibss_rsn, peer, buf, len);
  507. if (ibss_rsn_eapol_dst_supp(buf, len) > 0) {
  508. /*
  509. * Create new IBSS peer based on an EAPOL message from the peer
  510. * Authenticator.
  511. */
  512. if (ibss_rsn_start(ibss_rsn, src_addr) < 0)
  513. return -1;
  514. return ibss_rsn_process_rx_eapol(ibss_rsn, ibss_rsn->peers,
  515. buf, len);
  516. }
  517. return 0;
  518. }
  519. void ibss_rsn_set_psk(struct ibss_rsn *ibss_rsn, const u8 *psk)
  520. {
  521. if (ibss_rsn == NULL)
  522. return;
  523. os_memcpy(ibss_rsn->psk, psk, PMK_LEN);
  524. }