wpa_auth_glue.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /*
  2. * hostapd / WPA authenticator glue code
  3. * Copyright (c) 2002-2012, 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 "utils/includes.h"
  9. #include "utils/common.h"
  10. #include "common/ieee802_11_defs.h"
  11. #include "common/sae.h"
  12. #include "common/wpa_ctrl.h"
  13. #include "eapol_auth/eapol_auth_sm.h"
  14. #include "eapol_auth/eapol_auth_sm_i.h"
  15. #include "eap_server/eap.h"
  16. #include "l2_packet/l2_packet.h"
  17. #include "hostapd.h"
  18. #include "ieee802_1x.h"
  19. #include "preauth_auth.h"
  20. #include "sta_info.h"
  21. #include "tkip_countermeasures.h"
  22. #include "ap_drv_ops.h"
  23. #include "ap_config.h"
  24. #include "wpa_auth.h"
  25. #include "wpa_auth_glue.h"
  26. static void hostapd_wpa_auth_conf(struct hostapd_bss_config *conf,
  27. struct hostapd_config *iconf,
  28. struct wpa_auth_config *wconf)
  29. {
  30. os_memset(wconf, 0, sizeof(*wconf));
  31. wconf->wpa = conf->wpa;
  32. wconf->wpa_key_mgmt = conf->wpa_key_mgmt;
  33. wconf->wpa_pairwise = conf->wpa_pairwise;
  34. wconf->wpa_group = conf->wpa_group;
  35. wconf->wpa_group_rekey = conf->wpa_group_rekey;
  36. wconf->wpa_strict_rekey = conf->wpa_strict_rekey;
  37. wconf->wpa_gmk_rekey = conf->wpa_gmk_rekey;
  38. wconf->wpa_ptk_rekey = conf->wpa_ptk_rekey;
  39. wconf->rsn_pairwise = conf->rsn_pairwise;
  40. wconf->rsn_preauth = conf->rsn_preauth;
  41. wconf->eapol_version = conf->eapol_version;
  42. wconf->peerkey = conf->peerkey;
  43. wconf->wmm_enabled = conf->wmm_enabled;
  44. wconf->wmm_uapsd = conf->wmm_uapsd;
  45. wconf->disable_pmksa_caching = conf->disable_pmksa_caching;
  46. wconf->okc = conf->okc;
  47. #ifdef CONFIG_IEEE80211W
  48. wconf->ieee80211w = conf->ieee80211w;
  49. wconf->group_mgmt_cipher = conf->group_mgmt_cipher;
  50. #endif /* CONFIG_IEEE80211W */
  51. #ifdef CONFIG_IEEE80211R
  52. wconf->ssid_len = conf->ssid.ssid_len;
  53. if (wconf->ssid_len > SSID_MAX_LEN)
  54. wconf->ssid_len = SSID_MAX_LEN;
  55. os_memcpy(wconf->ssid, conf->ssid.ssid, wconf->ssid_len);
  56. os_memcpy(wconf->mobility_domain, conf->mobility_domain,
  57. MOBILITY_DOMAIN_ID_LEN);
  58. if (conf->nas_identifier &&
  59. os_strlen(conf->nas_identifier) <= FT_R0KH_ID_MAX_LEN) {
  60. wconf->r0_key_holder_len = os_strlen(conf->nas_identifier);
  61. os_memcpy(wconf->r0_key_holder, conf->nas_identifier,
  62. wconf->r0_key_holder_len);
  63. }
  64. os_memcpy(wconf->r1_key_holder, conf->r1_key_holder, FT_R1KH_ID_LEN);
  65. wconf->r0_key_lifetime = conf->r0_key_lifetime;
  66. wconf->reassociation_deadline = conf->reassociation_deadline;
  67. wconf->r0kh_list = conf->r0kh_list;
  68. wconf->r1kh_list = conf->r1kh_list;
  69. wconf->pmk_r1_push = conf->pmk_r1_push;
  70. wconf->ft_over_ds = conf->ft_over_ds;
  71. #endif /* CONFIG_IEEE80211R */
  72. #ifdef CONFIG_HS20
  73. wconf->disable_gtk = conf->disable_dgaf;
  74. if (conf->osen) {
  75. wconf->disable_gtk = 1;
  76. wconf->wpa = WPA_PROTO_OSEN;
  77. wconf->wpa_key_mgmt = WPA_KEY_MGMT_OSEN;
  78. wconf->wpa_pairwise = 0;
  79. wconf->wpa_group = WPA_CIPHER_CCMP;
  80. wconf->rsn_pairwise = WPA_CIPHER_CCMP;
  81. wconf->rsn_preauth = 0;
  82. wconf->disable_pmksa_caching = 1;
  83. #ifdef CONFIG_IEEE80211W
  84. wconf->ieee80211w = 1;
  85. #endif /* CONFIG_IEEE80211W */
  86. }
  87. #endif /* CONFIG_HS20 */
  88. #ifdef CONFIG_TESTING_OPTIONS
  89. wconf->corrupt_gtk_rekey_mic_probability =
  90. iconf->corrupt_gtk_rekey_mic_probability;
  91. if (conf->own_ie_override &&
  92. wpabuf_len(conf->own_ie_override) <= MAX_OWN_IE_OVERRIDE) {
  93. wconf->own_ie_override_len = wpabuf_len(conf->own_ie_override);
  94. os_memcpy(wconf->own_ie_override,
  95. wpabuf_head(conf->own_ie_override),
  96. wconf->own_ie_override_len);
  97. }
  98. #endif /* CONFIG_TESTING_OPTIONS */
  99. #ifdef CONFIG_P2P
  100. os_memcpy(wconf->ip_addr_go, conf->ip_addr_go, 4);
  101. os_memcpy(wconf->ip_addr_mask, conf->ip_addr_mask, 4);
  102. os_memcpy(wconf->ip_addr_start, conf->ip_addr_start, 4);
  103. os_memcpy(wconf->ip_addr_end, conf->ip_addr_end, 4);
  104. #endif /* CONFIG_P2P */
  105. }
  106. static void hostapd_wpa_auth_logger(void *ctx, const u8 *addr,
  107. logger_level level, const char *txt)
  108. {
  109. #ifndef CONFIG_NO_HOSTAPD_LOGGER
  110. struct hostapd_data *hapd = ctx;
  111. int hlevel;
  112. switch (level) {
  113. case LOGGER_WARNING:
  114. hlevel = HOSTAPD_LEVEL_WARNING;
  115. break;
  116. case LOGGER_INFO:
  117. hlevel = HOSTAPD_LEVEL_INFO;
  118. break;
  119. case LOGGER_DEBUG:
  120. default:
  121. hlevel = HOSTAPD_LEVEL_DEBUG;
  122. break;
  123. }
  124. hostapd_logger(hapd, addr, HOSTAPD_MODULE_WPA, hlevel, "%s", txt);
  125. #endif /* CONFIG_NO_HOSTAPD_LOGGER */
  126. }
  127. static void hostapd_wpa_auth_disconnect(void *ctx, const u8 *addr,
  128. u16 reason)
  129. {
  130. struct hostapd_data *hapd = ctx;
  131. wpa_printf(MSG_DEBUG, "%s: WPA authenticator requests disconnect: "
  132. "STA " MACSTR " reason %d",
  133. __func__, MAC2STR(addr), reason);
  134. ap_sta_disconnect(hapd, NULL, addr, reason);
  135. }
  136. static int hostapd_wpa_auth_mic_failure_report(void *ctx, const u8 *addr)
  137. {
  138. struct hostapd_data *hapd = ctx;
  139. return michael_mic_failure(hapd, addr, 0);
  140. }
  141. static void hostapd_wpa_auth_psk_failure_report(void *ctx, const u8 *addr)
  142. {
  143. struct hostapd_data *hapd = ctx;
  144. wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
  145. MAC2STR(addr));
  146. }
  147. static void hostapd_wpa_auth_set_eapol(void *ctx, const u8 *addr,
  148. wpa_eapol_variable var, int value)
  149. {
  150. struct hostapd_data *hapd = ctx;
  151. struct sta_info *sta = ap_get_sta(hapd, addr);
  152. if (sta == NULL)
  153. return;
  154. switch (var) {
  155. case WPA_EAPOL_portEnabled:
  156. ieee802_1x_notify_port_enabled(sta->eapol_sm, value);
  157. break;
  158. case WPA_EAPOL_portValid:
  159. ieee802_1x_notify_port_valid(sta->eapol_sm, value);
  160. break;
  161. case WPA_EAPOL_authorized:
  162. ieee802_1x_set_sta_authorized(hapd, sta, value);
  163. break;
  164. case WPA_EAPOL_portControl_Auto:
  165. if (sta->eapol_sm)
  166. sta->eapol_sm->portControl = Auto;
  167. break;
  168. case WPA_EAPOL_keyRun:
  169. if (sta->eapol_sm)
  170. sta->eapol_sm->keyRun = value ? TRUE : FALSE;
  171. break;
  172. case WPA_EAPOL_keyAvailable:
  173. if (sta->eapol_sm)
  174. sta->eapol_sm->eap_if->eapKeyAvailable =
  175. value ? TRUE : FALSE;
  176. break;
  177. case WPA_EAPOL_keyDone:
  178. if (sta->eapol_sm)
  179. sta->eapol_sm->keyDone = value ? TRUE : FALSE;
  180. break;
  181. case WPA_EAPOL_inc_EapolFramesTx:
  182. if (sta->eapol_sm)
  183. sta->eapol_sm->dot1xAuthEapolFramesTx++;
  184. break;
  185. }
  186. }
  187. static int hostapd_wpa_auth_get_eapol(void *ctx, const u8 *addr,
  188. wpa_eapol_variable var)
  189. {
  190. struct hostapd_data *hapd = ctx;
  191. struct sta_info *sta = ap_get_sta(hapd, addr);
  192. if (sta == NULL || sta->eapol_sm == NULL)
  193. return -1;
  194. switch (var) {
  195. case WPA_EAPOL_keyRun:
  196. return sta->eapol_sm->keyRun;
  197. case WPA_EAPOL_keyAvailable:
  198. return sta->eapol_sm->eap_if->eapKeyAvailable;
  199. default:
  200. return -1;
  201. }
  202. }
  203. static const u8 * hostapd_wpa_auth_get_psk(void *ctx, const u8 *addr,
  204. const u8 *p2p_dev_addr,
  205. const u8 *prev_psk)
  206. {
  207. struct hostapd_data *hapd = ctx;
  208. struct sta_info *sta = ap_get_sta(hapd, addr);
  209. const u8 *psk;
  210. #ifdef CONFIG_SAE
  211. if (sta && sta->auth_alg == WLAN_AUTH_SAE) {
  212. if (!sta->sae || prev_psk)
  213. return NULL;
  214. return sta->sae->pmk;
  215. }
  216. #endif /* CONFIG_SAE */
  217. psk = hostapd_get_psk(hapd->conf, addr, p2p_dev_addr, prev_psk);
  218. /*
  219. * This is about to iterate over all psks, prev_psk gives the last
  220. * returned psk which should not be returned again.
  221. * logic list (all hostapd_get_psk; all sta->psk)
  222. */
  223. if (sta && sta->psk && !psk) {
  224. struct hostapd_sta_wpa_psk_short *pos;
  225. psk = sta->psk->psk;
  226. for (pos = sta->psk; pos; pos = pos->next) {
  227. if (pos->psk == prev_psk) {
  228. psk = pos->next ? pos->next->psk : NULL;
  229. break;
  230. }
  231. }
  232. }
  233. return psk;
  234. }
  235. static int hostapd_wpa_auth_get_msk(void *ctx, const u8 *addr, u8 *msk,
  236. size_t *len)
  237. {
  238. struct hostapd_data *hapd = ctx;
  239. const u8 *key;
  240. size_t keylen;
  241. struct sta_info *sta;
  242. sta = ap_get_sta(hapd, addr);
  243. if (sta == NULL) {
  244. wpa_printf(MSG_DEBUG, "AUTH_GET_MSK: Cannot find STA");
  245. return -1;
  246. }
  247. key = ieee802_1x_get_key(sta->eapol_sm, &keylen);
  248. if (key == NULL) {
  249. wpa_printf(MSG_DEBUG, "AUTH_GET_MSK: Key is null, eapol_sm: %p",
  250. sta->eapol_sm);
  251. return -1;
  252. }
  253. if (keylen > *len)
  254. keylen = *len;
  255. os_memcpy(msk, key, keylen);
  256. *len = keylen;
  257. return 0;
  258. }
  259. static int hostapd_wpa_auth_set_key(void *ctx, int vlan_id, enum wpa_alg alg,
  260. const u8 *addr, int idx, u8 *key,
  261. size_t key_len)
  262. {
  263. struct hostapd_data *hapd = ctx;
  264. const char *ifname = hapd->conf->iface;
  265. if (vlan_id > 0) {
  266. ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan, vlan_id);
  267. if (ifname == NULL)
  268. return -1;
  269. }
  270. return hostapd_drv_set_key(ifname, hapd, alg, addr, idx, 1, NULL, 0,
  271. key, key_len);
  272. }
  273. static int hostapd_wpa_auth_get_seqnum(void *ctx, const u8 *addr, int idx,
  274. u8 *seq)
  275. {
  276. struct hostapd_data *hapd = ctx;
  277. return hostapd_get_seqnum(hapd->conf->iface, hapd, addr, idx, seq);
  278. }
  279. static int hostapd_wpa_auth_send_eapol(void *ctx, const u8 *addr,
  280. const u8 *data, size_t data_len,
  281. int encrypt)
  282. {
  283. struct hostapd_data *hapd = ctx;
  284. struct sta_info *sta;
  285. u32 flags = 0;
  286. #ifdef CONFIG_TESTING_OPTIONS
  287. if (hapd->ext_eapol_frame_io) {
  288. size_t hex_len = 2 * data_len + 1;
  289. char *hex = os_malloc(hex_len);
  290. if (hex == NULL)
  291. return -1;
  292. wpa_snprintf_hex(hex, hex_len, data, data_len);
  293. wpa_msg(hapd->msg_ctx, MSG_INFO, "EAPOL-TX " MACSTR " %s",
  294. MAC2STR(addr), hex);
  295. os_free(hex);
  296. return 0;
  297. }
  298. #endif /* CONFIG_TESTING_OPTIONS */
  299. sta = ap_get_sta(hapd, addr);
  300. if (sta)
  301. flags = hostapd_sta_flags_to_drv(sta->flags);
  302. return hostapd_drv_hapd_send_eapol(hapd, addr, data, data_len,
  303. encrypt, flags);
  304. }
  305. static int hostapd_wpa_auth_for_each_sta(
  306. void *ctx, int (*cb)(struct wpa_state_machine *sm, void *ctx),
  307. void *cb_ctx)
  308. {
  309. struct hostapd_data *hapd = ctx;
  310. struct sta_info *sta;
  311. for (sta = hapd->sta_list; sta; sta = sta->next) {
  312. if (sta->wpa_sm && cb(sta->wpa_sm, cb_ctx))
  313. return 1;
  314. }
  315. return 0;
  316. }
  317. struct wpa_auth_iface_iter_data {
  318. int (*cb)(struct wpa_authenticator *sm, void *ctx);
  319. void *cb_ctx;
  320. };
  321. static int wpa_auth_iface_iter(struct hostapd_iface *iface, void *ctx)
  322. {
  323. struct wpa_auth_iface_iter_data *data = ctx;
  324. size_t i;
  325. for (i = 0; i < iface->num_bss; i++) {
  326. if (iface->bss[i]->wpa_auth &&
  327. data->cb(iface->bss[i]->wpa_auth, data->cb_ctx))
  328. return 1;
  329. }
  330. return 0;
  331. }
  332. static int hostapd_wpa_auth_for_each_auth(
  333. void *ctx, int (*cb)(struct wpa_authenticator *sm, void *ctx),
  334. void *cb_ctx)
  335. {
  336. struct hostapd_data *hapd = ctx;
  337. struct wpa_auth_iface_iter_data data;
  338. if (hapd->iface->interfaces == NULL ||
  339. hapd->iface->interfaces->for_each_interface == NULL)
  340. return -1;
  341. data.cb = cb;
  342. data.cb_ctx = cb_ctx;
  343. return hapd->iface->interfaces->for_each_interface(
  344. hapd->iface->interfaces, wpa_auth_iface_iter, &data);
  345. }
  346. #ifdef CONFIG_IEEE80211R
  347. struct wpa_auth_ft_iface_iter_data {
  348. struct hostapd_data *src_hapd;
  349. const u8 *dst;
  350. const u8 *data;
  351. size_t data_len;
  352. };
  353. static int hostapd_wpa_auth_ft_iter(struct hostapd_iface *iface, void *ctx)
  354. {
  355. struct wpa_auth_ft_iface_iter_data *idata = ctx;
  356. struct hostapd_data *hapd;
  357. size_t j;
  358. for (j = 0; j < iface->num_bss; j++) {
  359. hapd = iface->bss[j];
  360. if (hapd == idata->src_hapd)
  361. continue;
  362. if (os_memcmp(hapd->own_addr, idata->dst, ETH_ALEN) == 0) {
  363. wpa_printf(MSG_DEBUG, "FT: Send RRB data directly to "
  364. "locally managed BSS " MACSTR "@%s -> "
  365. MACSTR "@%s",
  366. MAC2STR(idata->src_hapd->own_addr),
  367. idata->src_hapd->conf->iface,
  368. MAC2STR(hapd->own_addr), hapd->conf->iface);
  369. wpa_ft_rrb_rx(hapd->wpa_auth,
  370. idata->src_hapd->own_addr,
  371. idata->data, idata->data_len);
  372. return 1;
  373. }
  374. }
  375. return 0;
  376. }
  377. #endif /* CONFIG_IEEE80211R */
  378. static int hostapd_wpa_auth_send_ether(void *ctx, const u8 *dst, u16 proto,
  379. const u8 *data, size_t data_len)
  380. {
  381. struct hostapd_data *hapd = ctx;
  382. struct l2_ethhdr *buf;
  383. int ret;
  384. #ifdef CONFIG_TESTING_OPTIONS
  385. if (hapd->ext_eapol_frame_io && proto == ETH_P_EAPOL) {
  386. size_t hex_len = 2 * data_len + 1;
  387. char *hex = os_malloc(hex_len);
  388. if (hex == NULL)
  389. return -1;
  390. wpa_snprintf_hex(hex, hex_len, data, data_len);
  391. wpa_msg(hapd->msg_ctx, MSG_INFO, "EAPOL-TX " MACSTR " %s",
  392. MAC2STR(dst), hex);
  393. os_free(hex);
  394. return 0;
  395. }
  396. #endif /* CONFIG_TESTING_OPTIONS */
  397. #ifdef CONFIG_IEEE80211R
  398. if (proto == ETH_P_RRB && hapd->iface->interfaces &&
  399. hapd->iface->interfaces->for_each_interface) {
  400. int res;
  401. struct wpa_auth_ft_iface_iter_data idata;
  402. idata.src_hapd = hapd;
  403. idata.dst = dst;
  404. idata.data = data;
  405. idata.data_len = data_len;
  406. res = hapd->iface->interfaces->for_each_interface(
  407. hapd->iface->interfaces, hostapd_wpa_auth_ft_iter,
  408. &idata);
  409. if (res == 1)
  410. return data_len;
  411. }
  412. #endif /* CONFIG_IEEE80211R */
  413. if (hapd->driver && hapd->driver->send_ether)
  414. return hapd->driver->send_ether(hapd->drv_priv, dst,
  415. hapd->own_addr, proto,
  416. data, data_len);
  417. if (hapd->l2 == NULL)
  418. return -1;
  419. buf = os_malloc(sizeof(*buf) + data_len);
  420. if (buf == NULL)
  421. return -1;
  422. os_memcpy(buf->h_dest, dst, ETH_ALEN);
  423. os_memcpy(buf->h_source, hapd->own_addr, ETH_ALEN);
  424. buf->h_proto = host_to_be16(proto);
  425. os_memcpy(buf + 1, data, data_len);
  426. ret = l2_packet_send(hapd->l2, dst, proto, (u8 *) buf,
  427. sizeof(*buf) + data_len);
  428. os_free(buf);
  429. return ret;
  430. }
  431. #ifdef CONFIG_IEEE80211R
  432. static int hostapd_wpa_auth_send_ft_action(void *ctx, const u8 *dst,
  433. const u8 *data, size_t data_len)
  434. {
  435. struct hostapd_data *hapd = ctx;
  436. int res;
  437. struct ieee80211_mgmt *m;
  438. size_t mlen;
  439. struct sta_info *sta;
  440. sta = ap_get_sta(hapd, dst);
  441. if (sta == NULL || sta->wpa_sm == NULL)
  442. return -1;
  443. m = os_zalloc(sizeof(*m) + data_len);
  444. if (m == NULL)
  445. return -1;
  446. mlen = ((u8 *) &m->u - (u8 *) m) + data_len;
  447. m->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  448. WLAN_FC_STYPE_ACTION);
  449. os_memcpy(m->da, dst, ETH_ALEN);
  450. os_memcpy(m->sa, hapd->own_addr, ETH_ALEN);
  451. os_memcpy(m->bssid, hapd->own_addr, ETH_ALEN);
  452. os_memcpy(&m->u, data, data_len);
  453. res = hostapd_drv_send_mlme(hapd, (u8 *) m, mlen, 0);
  454. os_free(m);
  455. return res;
  456. }
  457. static struct wpa_state_machine *
  458. hostapd_wpa_auth_add_sta(void *ctx, const u8 *sta_addr)
  459. {
  460. struct hostapd_data *hapd = ctx;
  461. struct sta_info *sta;
  462. if (hostapd_add_sta_node(hapd, sta_addr, WLAN_AUTH_FT) < 0)
  463. return NULL;
  464. sta = ap_sta_add(hapd, sta_addr);
  465. if (sta == NULL)
  466. return NULL;
  467. if (sta->wpa_sm) {
  468. sta->auth_alg = WLAN_AUTH_FT;
  469. return sta->wpa_sm;
  470. }
  471. sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, sta->addr, NULL);
  472. if (sta->wpa_sm == NULL) {
  473. ap_free_sta(hapd, sta);
  474. return NULL;
  475. }
  476. sta->auth_alg = WLAN_AUTH_FT;
  477. return sta->wpa_sm;
  478. }
  479. static void hostapd_rrb_receive(void *ctx, const u8 *src_addr, const u8 *buf,
  480. size_t len)
  481. {
  482. struct hostapd_data *hapd = ctx;
  483. struct l2_ethhdr *ethhdr;
  484. if (len < sizeof(*ethhdr))
  485. return;
  486. ethhdr = (struct l2_ethhdr *) buf;
  487. wpa_printf(MSG_DEBUG, "FT: RRB received packet " MACSTR " -> "
  488. MACSTR, MAC2STR(ethhdr->h_source), MAC2STR(ethhdr->h_dest));
  489. wpa_ft_rrb_rx(hapd->wpa_auth, ethhdr->h_source, buf + sizeof(*ethhdr),
  490. len - sizeof(*ethhdr));
  491. }
  492. static int hostapd_wpa_auth_add_tspec(void *ctx, const u8 *sta_addr,
  493. u8 *tspec_ie, size_t tspec_ielen)
  494. {
  495. struct hostapd_data *hapd = ctx;
  496. return hostapd_add_tspec(hapd, sta_addr, tspec_ie, tspec_ielen);
  497. }
  498. #endif /* CONFIG_IEEE80211R */
  499. int hostapd_setup_wpa(struct hostapd_data *hapd)
  500. {
  501. struct wpa_auth_config _conf;
  502. struct wpa_auth_callbacks cb;
  503. const u8 *wpa_ie;
  504. size_t wpa_ie_len;
  505. hostapd_wpa_auth_conf(hapd->conf, hapd->iconf, &_conf);
  506. if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_EAPOL_TX_STATUS)
  507. _conf.tx_status = 1;
  508. if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_MLME)
  509. _conf.ap_mlme = 1;
  510. os_memset(&cb, 0, sizeof(cb));
  511. cb.ctx = hapd;
  512. cb.logger = hostapd_wpa_auth_logger;
  513. cb.disconnect = hostapd_wpa_auth_disconnect;
  514. cb.mic_failure_report = hostapd_wpa_auth_mic_failure_report;
  515. cb.psk_failure_report = hostapd_wpa_auth_psk_failure_report;
  516. cb.set_eapol = hostapd_wpa_auth_set_eapol;
  517. cb.get_eapol = hostapd_wpa_auth_get_eapol;
  518. cb.get_psk = hostapd_wpa_auth_get_psk;
  519. cb.get_msk = hostapd_wpa_auth_get_msk;
  520. cb.set_key = hostapd_wpa_auth_set_key;
  521. cb.get_seqnum = hostapd_wpa_auth_get_seqnum;
  522. cb.send_eapol = hostapd_wpa_auth_send_eapol;
  523. cb.for_each_sta = hostapd_wpa_auth_for_each_sta;
  524. cb.for_each_auth = hostapd_wpa_auth_for_each_auth;
  525. cb.send_ether = hostapd_wpa_auth_send_ether;
  526. #ifdef CONFIG_IEEE80211R
  527. cb.send_ft_action = hostapd_wpa_auth_send_ft_action;
  528. cb.add_sta = hostapd_wpa_auth_add_sta;
  529. cb.add_tspec = hostapd_wpa_auth_add_tspec;
  530. #endif /* CONFIG_IEEE80211R */
  531. hapd->wpa_auth = wpa_init(hapd->own_addr, &_conf, &cb);
  532. if (hapd->wpa_auth == NULL) {
  533. wpa_printf(MSG_ERROR, "WPA initialization failed.");
  534. return -1;
  535. }
  536. if (hostapd_set_privacy(hapd, 1)) {
  537. wpa_printf(MSG_ERROR, "Could not set PrivacyInvoked "
  538. "for interface %s", hapd->conf->iface);
  539. return -1;
  540. }
  541. wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
  542. if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len)) {
  543. wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
  544. "the kernel driver.");
  545. return -1;
  546. }
  547. if (rsn_preauth_iface_init(hapd)) {
  548. wpa_printf(MSG_ERROR, "Initialization of RSN "
  549. "pre-authentication failed.");
  550. return -1;
  551. }
  552. #ifdef CONFIG_IEEE80211R
  553. if (!hostapd_drv_none(hapd) && hapd->conf->ft_over_ds &&
  554. wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt)) {
  555. hapd->l2 = l2_packet_init(hapd->conf->bridge[0] ?
  556. hapd->conf->bridge :
  557. hapd->conf->iface, NULL, ETH_P_RRB,
  558. hostapd_rrb_receive, hapd, 1);
  559. if (hapd->l2 == NULL &&
  560. (hapd->driver == NULL ||
  561. hapd->driver->send_ether == NULL)) {
  562. wpa_printf(MSG_ERROR, "Failed to open l2_packet "
  563. "interface");
  564. return -1;
  565. }
  566. }
  567. #endif /* CONFIG_IEEE80211R */
  568. return 0;
  569. }
  570. void hostapd_reconfig_wpa(struct hostapd_data *hapd)
  571. {
  572. struct wpa_auth_config wpa_auth_conf;
  573. hostapd_wpa_auth_conf(hapd->conf, hapd->iconf, &wpa_auth_conf);
  574. wpa_reconfig(hapd->wpa_auth, &wpa_auth_conf);
  575. }
  576. void hostapd_deinit_wpa(struct hostapd_data *hapd)
  577. {
  578. ieee80211_tkip_countermeasures_deinit(hapd);
  579. rsn_preauth_iface_deinit(hapd);
  580. if (hapd->wpa_auth) {
  581. wpa_deinit(hapd->wpa_auth);
  582. hapd->wpa_auth = NULL;
  583. if (hapd->drv_priv && hostapd_set_privacy(hapd, 0)) {
  584. wpa_printf(MSG_DEBUG, "Could not disable "
  585. "PrivacyInvoked for interface %s",
  586. hapd->conf->iface);
  587. }
  588. if (hapd->drv_priv &&
  589. hostapd_set_generic_elem(hapd, (u8 *) "", 0)) {
  590. wpa_printf(MSG_DEBUG, "Could not remove generic "
  591. "information element from interface %s",
  592. hapd->conf->iface);
  593. }
  594. }
  595. ieee802_1x_deinit(hapd);
  596. #ifdef CONFIG_IEEE80211R
  597. l2_packet_deinit(hapd->l2);
  598. hapd->l2 = NULL;
  599. #endif /* CONFIG_IEEE80211R */
  600. }