wpa_auth_glue.c 17 KB

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