drv_callbacks.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284
  1. /*
  2. * hostapd / Callback functions for driver wrappers
  3. * Copyright (c) 2002-2013, 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 "utils/eloop.h"
  11. #include "radius/radius.h"
  12. #include "drivers/driver.h"
  13. #include "common/ieee802_11_defs.h"
  14. #include "common/ieee802_11_common.h"
  15. #include "common/wpa_ctrl.h"
  16. #include "crypto/random.h"
  17. #include "p2p/p2p.h"
  18. #include "wps/wps.h"
  19. #include "wnm_ap.h"
  20. #include "hostapd.h"
  21. #include "ieee802_11.h"
  22. #include "sta_info.h"
  23. #include "accounting.h"
  24. #include "tkip_countermeasures.h"
  25. #include "ieee802_1x.h"
  26. #include "wpa_auth.h"
  27. #include "wps_hostapd.h"
  28. #include "ap_drv_ops.h"
  29. #include "ap_config.h"
  30. #include "hw_features.h"
  31. #include "dfs.h"
  32. #include "beacon.h"
  33. int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
  34. const u8 *req_ies, size_t req_ies_len, int reassoc)
  35. {
  36. struct sta_info *sta;
  37. int new_assoc, res;
  38. struct ieee802_11_elems elems;
  39. const u8 *ie;
  40. size_t ielen;
  41. #ifdef CONFIG_IEEE80211R
  42. u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
  43. u8 *p = buf;
  44. #endif /* CONFIG_IEEE80211R */
  45. u16 reason = WLAN_REASON_UNSPECIFIED;
  46. u16 status = WLAN_STATUS_SUCCESS;
  47. const u8 *p2p_dev_addr = NULL;
  48. if (addr == NULL) {
  49. /*
  50. * This could potentially happen with unexpected event from the
  51. * driver wrapper. This was seen at least in one case where the
  52. * driver ended up being set to station mode while hostapd was
  53. * running, so better make sure we stop processing such an
  54. * event here.
  55. */
  56. wpa_printf(MSG_DEBUG, "hostapd_notif_assoc: Skip event with "
  57. "no address");
  58. return -1;
  59. }
  60. random_add_randomness(addr, ETH_ALEN);
  61. hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
  62. HOSTAPD_LEVEL_INFO, "associated");
  63. ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0);
  64. if (elems.wps_ie) {
  65. ie = elems.wps_ie - 2;
  66. ielen = elems.wps_ie_len + 2;
  67. wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq");
  68. } else if (elems.rsn_ie) {
  69. ie = elems.rsn_ie - 2;
  70. ielen = elems.rsn_ie_len + 2;
  71. wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq");
  72. } else if (elems.wpa_ie) {
  73. ie = elems.wpa_ie - 2;
  74. ielen = elems.wpa_ie_len + 2;
  75. wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq");
  76. #ifdef CONFIG_HS20
  77. } else if (elems.osen) {
  78. ie = elems.osen - 2;
  79. ielen = elems.osen_len + 2;
  80. wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq");
  81. #endif /* CONFIG_HS20 */
  82. } else {
  83. ie = NULL;
  84. ielen = 0;
  85. wpa_printf(MSG_DEBUG, "STA did not include WPS/RSN/WPA IE in "
  86. "(Re)AssocReq");
  87. }
  88. sta = ap_get_sta(hapd, addr);
  89. if (sta) {
  90. ap_sta_no_session_timeout(hapd, sta);
  91. accounting_sta_stop(hapd, sta);
  92. /*
  93. * Make sure that the previously registered inactivity timer
  94. * will not remove the STA immediately.
  95. */
  96. sta->timeout_next = STA_NULLFUNC;
  97. } else {
  98. sta = ap_sta_add(hapd, addr);
  99. if (sta == NULL) {
  100. hostapd_drv_sta_disassoc(hapd, addr,
  101. WLAN_REASON_DISASSOC_AP_BUSY);
  102. return -1;
  103. }
  104. }
  105. sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
  106. #ifdef CONFIG_P2P
  107. if (elems.p2p) {
  108. wpabuf_free(sta->p2p_ie);
  109. sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
  110. P2P_IE_VENDOR_TYPE);
  111. if (sta->p2p_ie)
  112. p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
  113. }
  114. #endif /* CONFIG_P2P */
  115. #ifdef CONFIG_IEEE80211N
  116. #ifdef NEED_AP_MLME
  117. if (elems.ht_capabilities &&
  118. (hapd->iface->conf->ht_capab &
  119. HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
  120. struct ieee80211_ht_capabilities *ht_cap =
  121. (struct ieee80211_ht_capabilities *)
  122. elems.ht_capabilities;
  123. if (le_to_host16(ht_cap->ht_capabilities_info) &
  124. HT_CAP_INFO_40MHZ_INTOLERANT)
  125. ht40_intolerant_add(hapd->iface, sta);
  126. }
  127. #endif /* NEED_AP_MLME */
  128. #endif /* CONFIG_IEEE80211N */
  129. #ifdef CONFIG_INTERWORKING
  130. if (elems.ext_capab && elems.ext_capab_len > 4) {
  131. if (elems.ext_capab[4] & 0x01)
  132. sta->qos_map_enabled = 1;
  133. }
  134. #endif /* CONFIG_INTERWORKING */
  135. #ifdef CONFIG_HS20
  136. wpabuf_free(sta->hs20_ie);
  137. if (elems.hs20 && elems.hs20_len > 4) {
  138. sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
  139. elems.hs20_len - 4);
  140. } else
  141. sta->hs20_ie = NULL;
  142. #endif /* CONFIG_HS20 */
  143. if (hapd->conf->wpa) {
  144. if (ie == NULL || ielen == 0) {
  145. #ifdef CONFIG_WPS
  146. if (hapd->conf->wps_state) {
  147. wpa_printf(MSG_DEBUG, "STA did not include "
  148. "WPA/RSN IE in (Re)Association "
  149. "Request - possible WPS use");
  150. sta->flags |= WLAN_STA_MAYBE_WPS;
  151. goto skip_wpa_check;
  152. }
  153. #endif /* CONFIG_WPS */
  154. wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
  155. return -1;
  156. }
  157. #ifdef CONFIG_WPS
  158. if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
  159. os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
  160. struct wpabuf *wps;
  161. sta->flags |= WLAN_STA_WPS;
  162. wps = ieee802_11_vendor_ie_concat(ie, ielen,
  163. WPS_IE_VENDOR_TYPE);
  164. if (wps) {
  165. if (wps_is_20(wps)) {
  166. wpa_printf(MSG_DEBUG, "WPS: STA "
  167. "supports WPS 2.0");
  168. sta->flags |= WLAN_STA_WPS2;
  169. }
  170. wpabuf_free(wps);
  171. }
  172. goto skip_wpa_check;
  173. }
  174. #endif /* CONFIG_WPS */
  175. if (sta->wpa_sm == NULL)
  176. sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
  177. sta->addr,
  178. p2p_dev_addr);
  179. if (sta->wpa_sm == NULL) {
  180. wpa_printf(MSG_ERROR, "Failed to initialize WPA state "
  181. "machine");
  182. return -1;
  183. }
  184. res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
  185. ie, ielen,
  186. elems.mdie, elems.mdie_len);
  187. if (res != WPA_IE_OK) {
  188. wpa_printf(MSG_DEBUG, "WPA/RSN information element "
  189. "rejected? (res %u)", res);
  190. wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
  191. if (res == WPA_INVALID_GROUP) {
  192. reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
  193. status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
  194. } else if (res == WPA_INVALID_PAIRWISE) {
  195. reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
  196. status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
  197. } else if (res == WPA_INVALID_AKMP) {
  198. reason = WLAN_REASON_AKMP_NOT_VALID;
  199. status = WLAN_STATUS_AKMP_NOT_VALID;
  200. }
  201. #ifdef CONFIG_IEEE80211W
  202. else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) {
  203. reason = WLAN_REASON_INVALID_IE;
  204. status = WLAN_STATUS_INVALID_IE;
  205. } else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) {
  206. reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
  207. status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
  208. }
  209. #endif /* CONFIG_IEEE80211W */
  210. else {
  211. reason = WLAN_REASON_INVALID_IE;
  212. status = WLAN_STATUS_INVALID_IE;
  213. }
  214. goto fail;
  215. }
  216. #ifdef CONFIG_IEEE80211W
  217. if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
  218. sta->sa_query_count > 0)
  219. ap_check_sa_query_timeout(hapd, sta);
  220. if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
  221. (sta->auth_alg != WLAN_AUTH_FT)) {
  222. /*
  223. * STA has already been associated with MFP and SA
  224. * Query timeout has not been reached. Reject the
  225. * association attempt temporarily and start SA Query,
  226. * if one is not pending.
  227. */
  228. if (sta->sa_query_count == 0)
  229. ap_sta_start_sa_query(hapd, sta);
  230. #ifdef CONFIG_IEEE80211R
  231. status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
  232. p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
  233. hostapd_sta_assoc(hapd, addr, reassoc, status, buf,
  234. p - buf);
  235. #endif /* CONFIG_IEEE80211R */
  236. return 0;
  237. }
  238. if (wpa_auth_uses_mfp(sta->wpa_sm))
  239. sta->flags |= WLAN_STA_MFP;
  240. else
  241. sta->flags &= ~WLAN_STA_MFP;
  242. #endif /* CONFIG_IEEE80211W */
  243. #ifdef CONFIG_IEEE80211R
  244. if (sta->auth_alg == WLAN_AUTH_FT) {
  245. status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies,
  246. req_ies_len);
  247. if (status != WLAN_STATUS_SUCCESS) {
  248. if (status == WLAN_STATUS_INVALID_PMKID)
  249. reason = WLAN_REASON_INVALID_IE;
  250. if (status == WLAN_STATUS_INVALID_MDIE)
  251. reason = WLAN_REASON_INVALID_IE;
  252. if (status == WLAN_STATUS_INVALID_FTIE)
  253. reason = WLAN_REASON_INVALID_IE;
  254. goto fail;
  255. }
  256. }
  257. #endif /* CONFIG_IEEE80211R */
  258. } else if (hapd->conf->wps_state) {
  259. #ifdef CONFIG_WPS
  260. struct wpabuf *wps;
  261. if (req_ies)
  262. wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
  263. WPS_IE_VENDOR_TYPE);
  264. else
  265. wps = NULL;
  266. #ifdef CONFIG_WPS_STRICT
  267. if (wps && wps_validate_assoc_req(wps) < 0) {
  268. reason = WLAN_REASON_INVALID_IE;
  269. status = WLAN_STATUS_INVALID_IE;
  270. wpabuf_free(wps);
  271. goto fail;
  272. }
  273. #endif /* CONFIG_WPS_STRICT */
  274. if (wps) {
  275. sta->flags |= WLAN_STA_WPS;
  276. if (wps_is_20(wps)) {
  277. wpa_printf(MSG_DEBUG, "WPS: STA supports "
  278. "WPS 2.0");
  279. sta->flags |= WLAN_STA_WPS2;
  280. }
  281. } else
  282. sta->flags |= WLAN_STA_MAYBE_WPS;
  283. wpabuf_free(wps);
  284. #endif /* CONFIG_WPS */
  285. #ifdef CONFIG_HS20
  286. } else if (hapd->conf->osen) {
  287. if (elems.osen == NULL) {
  288. hostapd_logger(
  289. hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  290. HOSTAPD_LEVEL_INFO,
  291. "No HS 2.0 OSEN element in association request");
  292. return WLAN_STATUS_INVALID_IE;
  293. }
  294. wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
  295. if (sta->wpa_sm == NULL)
  296. sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
  297. sta->addr, NULL);
  298. if (sta->wpa_sm == NULL) {
  299. wpa_printf(MSG_WARNING, "Failed to initialize WPA "
  300. "state machine");
  301. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  302. }
  303. if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
  304. elems.osen - 2, elems.osen_len + 2) < 0)
  305. return WLAN_STATUS_INVALID_IE;
  306. #endif /* CONFIG_HS20 */
  307. }
  308. #ifdef CONFIG_WPS
  309. skip_wpa_check:
  310. #endif /* CONFIG_WPS */
  311. #ifdef CONFIG_IEEE80211R
  312. p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf),
  313. sta->auth_alg, req_ies, req_ies_len);
  314. hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
  315. if (sta->auth_alg == WLAN_AUTH_FT)
  316. ap_sta_set_authorized(hapd, sta, 1);
  317. #else /* CONFIG_IEEE80211R */
  318. /* Keep compiler silent about unused variables */
  319. if (status) {
  320. }
  321. #endif /* CONFIG_IEEE80211R */
  322. new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
  323. sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
  324. sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
  325. hostapd_set_sta_flags(hapd, sta);
  326. if (reassoc && (sta->auth_alg == WLAN_AUTH_FT))
  327. wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
  328. else
  329. wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
  330. hostapd_new_assoc_sta(hapd, sta, !new_assoc);
  331. ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
  332. #ifdef CONFIG_P2P
  333. if (req_ies) {
  334. p2p_group_notif_assoc(hapd->p2p_group, sta->addr,
  335. req_ies, req_ies_len);
  336. }
  337. #endif /* CONFIG_P2P */
  338. return 0;
  339. fail:
  340. #ifdef CONFIG_IEEE80211R
  341. hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
  342. #endif /* CONFIG_IEEE80211R */
  343. hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
  344. ap_free_sta(hapd, sta);
  345. return -1;
  346. }
  347. void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
  348. {
  349. struct sta_info *sta;
  350. if (addr == NULL) {
  351. /*
  352. * This could potentially happen with unexpected event from the
  353. * driver wrapper. This was seen at least in one case where the
  354. * driver ended up reporting a station mode event while hostapd
  355. * was running, so better make sure we stop processing such an
  356. * event here.
  357. */
  358. wpa_printf(MSG_DEBUG, "hostapd_notif_disassoc: Skip event "
  359. "with no address");
  360. return;
  361. }
  362. hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
  363. HOSTAPD_LEVEL_INFO, "disassociated");
  364. sta = ap_get_sta(hapd, addr);
  365. if (sta == NULL) {
  366. wpa_printf(MSG_DEBUG, "Disassociation notification for "
  367. "unknown STA " MACSTR, MAC2STR(addr));
  368. return;
  369. }
  370. ap_sta_set_authorized(hapd, sta, 0);
  371. sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
  372. wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
  373. sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
  374. ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
  375. ap_free_sta(hapd, sta);
  376. }
  377. void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr)
  378. {
  379. struct sta_info *sta = ap_get_sta(hapd, addr);
  380. if (!sta || !hapd->conf->disassoc_low_ack)
  381. return;
  382. hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
  383. HOSTAPD_LEVEL_INFO, "disconnected due to excessive "
  384. "missing ACKs");
  385. hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK);
  386. if (sta)
  387. ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK);
  388. }
  389. void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
  390. int offset, int width, int cf1, int cf2)
  391. {
  392. #ifdef NEED_AP_MLME
  393. int channel, chwidth, seg0_idx = 0, seg1_idx = 0, is_dfs;
  394. hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
  395. HOSTAPD_LEVEL_INFO,
  396. "driver had channel switch: freq=%d, ht=%d, offset=%d, width=%d (%s), cf1=%d, cf2=%d",
  397. freq, ht, offset, width, channel_width_to_string(width),
  398. cf1, cf2);
  399. hapd->iface->freq = freq;
  400. channel = hostapd_hw_get_channel(hapd, freq);
  401. if (!channel) {
  402. hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
  403. HOSTAPD_LEVEL_WARNING, "driver switched to "
  404. "bad channel!");
  405. return;
  406. }
  407. switch (width) {
  408. case CHAN_WIDTH_80:
  409. chwidth = VHT_CHANWIDTH_80MHZ;
  410. break;
  411. case CHAN_WIDTH_80P80:
  412. chwidth = VHT_CHANWIDTH_80P80MHZ;
  413. break;
  414. case CHAN_WIDTH_160:
  415. chwidth = VHT_CHANWIDTH_160MHZ;
  416. break;
  417. case CHAN_WIDTH_20_NOHT:
  418. case CHAN_WIDTH_20:
  419. case CHAN_WIDTH_40:
  420. default:
  421. chwidth = VHT_CHANWIDTH_USE_HT;
  422. break;
  423. }
  424. switch (hapd->iface->current_mode->mode) {
  425. case HOSTAPD_MODE_IEEE80211A:
  426. if (cf1 > 5000)
  427. seg0_idx = (cf1 - 5000) / 5;
  428. if (cf2 > 5000)
  429. seg1_idx = (cf2 - 5000) / 5;
  430. break;
  431. default:
  432. seg0_idx = hostapd_hw_get_channel(hapd, cf1);
  433. seg1_idx = hostapd_hw_get_channel(hapd, cf2);
  434. break;
  435. }
  436. hapd->iconf->channel = channel;
  437. hapd->iconf->ieee80211n = ht;
  438. if (!ht)
  439. hapd->iconf->ieee80211ac = 0;
  440. hapd->iconf->secondary_channel = offset;
  441. hapd->iconf->vht_oper_chwidth = chwidth;
  442. hapd->iconf->vht_oper_centr_freq_seg0_idx = seg0_idx;
  443. hapd->iconf->vht_oper_centr_freq_seg1_idx = seg1_idx;
  444. is_dfs = ieee80211_is_dfs(freq);
  445. if (hapd->csa_in_progress &&
  446. freq == hapd->cs_freq_params.freq) {
  447. hostapd_cleanup_cs_params(hapd);
  448. ieee802_11_set_beacon(hapd);
  449. wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
  450. "freq=%d dfs=%d", freq, is_dfs);
  451. } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) {
  452. wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
  453. "freq=%d dfs=%d", freq, is_dfs);
  454. }
  455. #endif /* NEED_AP_MLME */
  456. }
  457. void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
  458. const u8 *addr, int reason_code)
  459. {
  460. switch (reason_code) {
  461. case MAX_CLIENT_REACHED:
  462. wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR,
  463. MAC2STR(addr));
  464. break;
  465. case BLOCKED_CLIENT:
  466. wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR,
  467. MAC2STR(addr));
  468. break;
  469. }
  470. }
  471. #ifdef CONFIG_ACS
  472. static void hostapd_acs_channel_selected(struct hostapd_data *hapd,
  473. struct acs_selected_channels *acs_res)
  474. {
  475. int ret;
  476. if (hapd->iconf->channel) {
  477. wpa_printf(MSG_INFO, "ACS: Channel was already set to %d",
  478. hapd->iconf->channel);
  479. return;
  480. }
  481. hapd->iface->freq = hostapd_hw_get_freq(hapd, acs_res->pri_channel);
  482. if (!acs_res->pri_channel) {
  483. hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
  484. HOSTAPD_LEVEL_WARNING,
  485. "driver switched to bad channel");
  486. return;
  487. }
  488. hapd->iconf->channel = acs_res->pri_channel;
  489. hapd->iconf->acs = 1;
  490. if (acs_res->sec_channel == 0)
  491. hapd->iconf->secondary_channel = 0;
  492. else if (acs_res->sec_channel < acs_res->pri_channel)
  493. hapd->iconf->secondary_channel = -1;
  494. else if (acs_res->sec_channel > acs_res->pri_channel)
  495. hapd->iconf->secondary_channel = 1;
  496. else {
  497. wpa_printf(MSG_ERROR, "Invalid secondary channel!");
  498. return;
  499. }
  500. if (hapd->iface->conf->ieee80211ac) {
  501. /* set defaults for backwards compatibility */
  502. hapd->iconf->vht_oper_centr_freq_seg1_idx = 0;
  503. hapd->iconf->vht_oper_centr_freq_seg0_idx = 0;
  504. hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT;
  505. if (acs_res->ch_width == 80) {
  506. hapd->iconf->vht_oper_centr_freq_seg0_idx =
  507. acs_res->vht_seg0_center_ch;
  508. hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ;
  509. } else if (acs_res->ch_width == 160) {
  510. if (acs_res->vht_seg1_center_ch == 0) {
  511. hapd->iconf->vht_oper_centr_freq_seg0_idx =
  512. acs_res->vht_seg0_center_ch;
  513. hapd->iconf->vht_oper_chwidth =
  514. VHT_CHANWIDTH_160MHZ;
  515. } else {
  516. hapd->iconf->vht_oper_centr_freq_seg0_idx =
  517. acs_res->vht_seg0_center_ch;
  518. hapd->iconf->vht_oper_centr_freq_seg1_idx =
  519. acs_res->vht_seg1_center_ch;
  520. hapd->iconf->vht_oper_chwidth =
  521. VHT_CHANWIDTH_80P80MHZ;
  522. }
  523. }
  524. }
  525. ret = hostapd_acs_completed(hapd->iface, 0);
  526. if (ret) {
  527. wpa_printf(MSG_ERROR,
  528. "ACS: Possibly channel configuration is invalid");
  529. }
  530. }
  531. #endif /* CONFIG_ACS */
  532. int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
  533. const u8 *bssid, const u8 *ie, size_t ie_len,
  534. int ssi_signal)
  535. {
  536. size_t i;
  537. int ret = 0;
  538. if (sa == NULL || ie == NULL)
  539. return -1;
  540. random_add_randomness(sa, ETH_ALEN);
  541. for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
  542. if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
  543. sa, da, bssid, ie, ie_len,
  544. ssi_signal) > 0) {
  545. ret = 1;
  546. break;
  547. }
  548. }
  549. return ret;
  550. }
  551. #ifdef HOSTAPD
  552. #ifdef CONFIG_IEEE80211R
  553. static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
  554. const u8 *bssid,
  555. u16 auth_transaction, u16 status,
  556. const u8 *ies, size_t ies_len)
  557. {
  558. struct hostapd_data *hapd = ctx;
  559. struct sta_info *sta;
  560. sta = ap_get_sta(hapd, dst);
  561. if (sta == NULL)
  562. return;
  563. hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
  564. HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
  565. sta->flags |= WLAN_STA_AUTH;
  566. hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
  567. }
  568. #endif /* CONFIG_IEEE80211R */
  569. static void hostapd_notif_auth(struct hostapd_data *hapd,
  570. struct auth_info *rx_auth)
  571. {
  572. struct sta_info *sta;
  573. u16 status = WLAN_STATUS_SUCCESS;
  574. u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
  575. size_t resp_ies_len = 0;
  576. sta = ap_get_sta(hapd, rx_auth->peer);
  577. if (!sta) {
  578. sta = ap_sta_add(hapd, rx_auth->peer);
  579. if (sta == NULL) {
  580. status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
  581. goto fail;
  582. }
  583. }
  584. sta->flags &= ~WLAN_STA_PREAUTH;
  585. ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
  586. #ifdef CONFIG_IEEE80211R
  587. if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
  588. sta->auth_alg = WLAN_AUTH_FT;
  589. if (sta->wpa_sm == NULL)
  590. sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
  591. sta->addr, NULL);
  592. if (sta->wpa_sm == NULL) {
  593. wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
  594. "state machine");
  595. status = WLAN_STATUS_UNSPECIFIED_FAILURE;
  596. goto fail;
  597. }
  598. wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid,
  599. rx_auth->auth_transaction, rx_auth->ies,
  600. rx_auth->ies_len,
  601. hostapd_notify_auth_ft_finish, hapd);
  602. return;
  603. }
  604. #endif /* CONFIG_IEEE80211R */
  605. fail:
  606. hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
  607. status, resp_ies, resp_ies_len);
  608. }
  609. static void hostapd_action_rx(struct hostapd_data *hapd,
  610. struct rx_mgmt *drv_mgmt)
  611. {
  612. struct ieee80211_mgmt *mgmt;
  613. struct sta_info *sta;
  614. size_t plen __maybe_unused;
  615. u16 fc;
  616. if (drv_mgmt->frame_len < 24 + 1)
  617. return;
  618. plen = drv_mgmt->frame_len - 24 - 1;
  619. mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame;
  620. fc = le_to_host16(mgmt->frame_control);
  621. if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
  622. return; /* handled by the driver */
  623. wpa_printf(MSG_DEBUG, "RX_ACTION cat %d action plen %d",
  624. mgmt->u.action.category, (int) plen);
  625. sta = ap_get_sta(hapd, mgmt->sa);
  626. if (sta == NULL) {
  627. wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
  628. return;
  629. }
  630. #ifdef CONFIG_IEEE80211R
  631. if (mgmt->u.action.category == WLAN_ACTION_FT) {
  632. const u8 *payload = drv_mgmt->frame + 24 + 1;
  633. wpa_ft_action_rx(sta->wpa_sm, payload, plen);
  634. }
  635. #endif /* CONFIG_IEEE80211R */
  636. #ifdef CONFIG_IEEE80211W
  637. if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY && plen >= 4) {
  638. ieee802_11_sa_query_action(
  639. hapd, mgmt->sa,
  640. mgmt->u.action.u.sa_query_resp.action,
  641. mgmt->u.action.u.sa_query_resp.trans_id);
  642. }
  643. #endif /* CONFIG_IEEE80211W */
  644. #ifdef CONFIG_WNM
  645. if (mgmt->u.action.category == WLAN_ACTION_WNM) {
  646. ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len);
  647. }
  648. #endif /* CONFIG_WNM */
  649. }
  650. #ifdef NEED_AP_MLME
  651. #define HAPD_BROADCAST ((struct hostapd_data *) -1)
  652. static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
  653. const u8 *bssid)
  654. {
  655. size_t i;
  656. if (bssid == NULL)
  657. return NULL;
  658. if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
  659. bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
  660. return HAPD_BROADCAST;
  661. for (i = 0; i < iface->num_bss; i++) {
  662. if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0)
  663. return iface->bss[i];
  664. }
  665. return NULL;
  666. }
  667. static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
  668. const u8 *bssid, const u8 *addr,
  669. int wds)
  670. {
  671. hapd = get_hapd_bssid(hapd->iface, bssid);
  672. if (hapd == NULL || hapd == HAPD_BROADCAST)
  673. return;
  674. ieee802_11_rx_from_unknown(hapd, addr, wds);
  675. }
  676. static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
  677. {
  678. struct hostapd_iface *iface = hapd->iface;
  679. const struct ieee80211_hdr *hdr;
  680. const u8 *bssid;
  681. struct hostapd_frame_info fi;
  682. int ret;
  683. #ifdef CONFIG_TESTING_OPTIONS
  684. if (hapd->ext_mgmt_frame_handling) {
  685. size_t hex_len = 2 * rx_mgmt->frame_len + 1;
  686. char *hex = os_malloc(hex_len);
  687. if (hex) {
  688. wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame,
  689. rx_mgmt->frame_len);
  690. wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
  691. os_free(hex);
  692. }
  693. return 1;
  694. }
  695. #endif /* CONFIG_TESTING_OPTIONS */
  696. hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
  697. bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
  698. if (bssid == NULL)
  699. return 0;
  700. hapd = get_hapd_bssid(iface, bssid);
  701. if (hapd == NULL) {
  702. u16 fc;
  703. fc = le_to_host16(hdr->frame_control);
  704. /*
  705. * Drop frames to unknown BSSIDs except for Beacon frames which
  706. * could be used to update neighbor information.
  707. */
  708. if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
  709. WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
  710. hapd = iface->bss[0];
  711. else
  712. return 0;
  713. }
  714. os_memset(&fi, 0, sizeof(fi));
  715. fi.datarate = rx_mgmt->datarate;
  716. fi.ssi_signal = rx_mgmt->ssi_signal;
  717. if (hapd == HAPD_BROADCAST) {
  718. size_t i;
  719. ret = 0;
  720. for (i = 0; i < iface->num_bss; i++) {
  721. /* if bss is set, driver will call this function for
  722. * each bss individually. */
  723. if (rx_mgmt->drv_priv &&
  724. (iface->bss[i]->drv_priv != rx_mgmt->drv_priv))
  725. continue;
  726. if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
  727. rx_mgmt->frame_len, &fi) > 0)
  728. ret = 1;
  729. }
  730. } else
  731. ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len,
  732. &fi);
  733. random_add_randomness(&fi, sizeof(fi));
  734. return ret;
  735. }
  736. static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
  737. size_t len, u16 stype, int ok)
  738. {
  739. struct ieee80211_hdr *hdr;
  740. hdr = (struct ieee80211_hdr *) buf;
  741. hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len));
  742. if (hapd == NULL || hapd == HAPD_BROADCAST)
  743. return;
  744. ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
  745. }
  746. #endif /* NEED_AP_MLME */
  747. static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
  748. {
  749. struct sta_info *sta = ap_get_sta(hapd, addr);
  750. if (sta)
  751. return 0;
  752. wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
  753. " - adding a new STA", MAC2STR(addr));
  754. sta = ap_sta_add(hapd, addr);
  755. if (sta) {
  756. hostapd_new_assoc_sta(hapd, sta, 0);
  757. } else {
  758. wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
  759. MAC2STR(addr));
  760. return -1;
  761. }
  762. return 0;
  763. }
  764. static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
  765. const u8 *data, size_t data_len)
  766. {
  767. struct hostapd_iface *iface = hapd->iface;
  768. struct sta_info *sta;
  769. size_t j;
  770. for (j = 0; j < iface->num_bss; j++) {
  771. if ((sta = ap_get_sta(iface->bss[j], src))) {
  772. if (sta->flags & WLAN_STA_ASSOC) {
  773. hapd = iface->bss[j];
  774. break;
  775. }
  776. }
  777. }
  778. ieee802_1x_receive(hapd, src, data, data_len);
  779. }
  780. static struct hostapd_channel_data * hostapd_get_mode_channel(
  781. struct hostapd_iface *iface, unsigned int freq)
  782. {
  783. int i;
  784. struct hostapd_channel_data *chan;
  785. for (i = 0; i < iface->current_mode->num_channels; i++) {
  786. chan = &iface->current_mode->channels[i];
  787. if (!chan)
  788. return NULL;
  789. if ((unsigned int) chan->freq == freq)
  790. return chan;
  791. }
  792. return NULL;
  793. }
  794. static void hostapd_update_nf(struct hostapd_iface *iface,
  795. struct hostapd_channel_data *chan,
  796. struct freq_survey *survey)
  797. {
  798. if (!iface->chans_surveyed) {
  799. chan->min_nf = survey->nf;
  800. iface->lowest_nf = survey->nf;
  801. } else {
  802. if (dl_list_empty(&chan->survey_list))
  803. chan->min_nf = survey->nf;
  804. else if (survey->nf < chan->min_nf)
  805. chan->min_nf = survey->nf;
  806. if (survey->nf < iface->lowest_nf)
  807. iface->lowest_nf = survey->nf;
  808. }
  809. }
  810. static void hostapd_single_channel_get_survey(struct hostapd_iface *iface,
  811. struct survey_results *survey_res)
  812. {
  813. struct hostapd_channel_data *chan;
  814. struct freq_survey *survey;
  815. u64 divisor, dividend;
  816. survey = dl_list_first(&survey_res->survey_list, struct freq_survey,
  817. list);
  818. if (!survey || !survey->freq)
  819. return;
  820. chan = hostapd_get_mode_channel(iface, survey->freq);
  821. if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED)
  822. return;
  823. wpa_printf(MSG_DEBUG, "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
  824. survey->freq,
  825. (unsigned long int) survey->channel_time,
  826. (unsigned long int) survey->channel_time_busy);
  827. if (survey->channel_time > iface->last_channel_time &&
  828. survey->channel_time > survey->channel_time_busy) {
  829. dividend = survey->channel_time_busy -
  830. iface->last_channel_time_busy;
  831. divisor = survey->channel_time - iface->last_channel_time;
  832. iface->channel_utilization = dividend * 255 / divisor;
  833. wpa_printf(MSG_DEBUG, "Channel Utilization: %d",
  834. iface->channel_utilization);
  835. }
  836. iface->last_channel_time = survey->channel_time;
  837. iface->last_channel_time_busy = survey->channel_time_busy;
  838. }
  839. static void hostapd_event_get_survey(struct hostapd_data *hapd,
  840. struct survey_results *survey_results)
  841. {
  842. struct hostapd_iface *iface = hapd->iface;
  843. struct freq_survey *survey, *tmp;
  844. struct hostapd_channel_data *chan;
  845. if (dl_list_empty(&survey_results->survey_list)) {
  846. wpa_printf(MSG_DEBUG, "No survey data received");
  847. return;
  848. }
  849. if (survey_results->freq_filter) {
  850. hostapd_single_channel_get_survey(iface, survey_results);
  851. return;
  852. }
  853. dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
  854. struct freq_survey, list) {
  855. chan = hostapd_get_mode_channel(iface, survey->freq);
  856. if (!chan)
  857. continue;
  858. if (chan->flag & HOSTAPD_CHAN_DISABLED)
  859. continue;
  860. dl_list_del(&survey->list);
  861. dl_list_add_tail(&chan->survey_list, &survey->list);
  862. hostapd_update_nf(iface, chan, survey);
  863. iface->chans_surveyed++;
  864. }
  865. }
  866. #ifdef NEED_AP_MLME
  867. static void hostapd_event_iface_unavailable(struct hostapd_data *hapd)
  868. {
  869. wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped",
  870. hapd->conf->iface);
  871. if (hapd->csa_in_progress) {
  872. wpa_printf(MSG_INFO, "CSA failed (%s was stopped)",
  873. hapd->conf->iface);
  874. hostapd_switch_channel_fallback(hapd->iface,
  875. &hapd->cs_freq_params);
  876. }
  877. }
  878. static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
  879. struct dfs_event *radar)
  880. {
  881. wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
  882. hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled,
  883. radar->chan_offset, radar->chan_width,
  884. radar->cf1, radar->cf2);
  885. }
  886. static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
  887. struct dfs_event *radar)
  888. {
  889. wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
  890. hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled,
  891. radar->chan_offset, radar->chan_width,
  892. radar->cf1, radar->cf2);
  893. }
  894. static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd,
  895. struct dfs_event *radar)
  896. {
  897. wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
  898. hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled,
  899. radar->chan_offset, radar->chan_width,
  900. radar->cf1, radar->cf2);
  901. }
  902. static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
  903. struct dfs_event *radar)
  904. {
  905. wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
  906. hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled,
  907. radar->chan_offset, radar->chan_width,
  908. radar->cf1, radar->cf2);
  909. }
  910. static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
  911. struct dfs_event *radar)
  912. {
  913. wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq);
  914. hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled,
  915. radar->chan_offset, radar->chan_width,
  916. radar->cf1, radar->cf2);
  917. }
  918. #endif /* NEED_AP_MLME */
  919. void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
  920. union wpa_event_data *data)
  921. {
  922. struct hostapd_data *hapd = ctx;
  923. #ifndef CONFIG_NO_STDOUT_DEBUG
  924. int level = MSG_DEBUG;
  925. if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
  926. data->rx_mgmt.frame_len >= 24) {
  927. const struct ieee80211_hdr *hdr;
  928. u16 fc;
  929. hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
  930. fc = le_to_host16(hdr->frame_control);
  931. if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
  932. WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
  933. level = MSG_EXCESSIVE;
  934. if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
  935. WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
  936. level = MSG_EXCESSIVE;
  937. }
  938. wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
  939. event_to_string(event), event);
  940. #endif /* CONFIG_NO_STDOUT_DEBUG */
  941. switch (event) {
  942. case EVENT_MICHAEL_MIC_FAILURE:
  943. michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
  944. break;
  945. case EVENT_SCAN_RESULTS:
  946. if (hapd->iface->scan_cb)
  947. hapd->iface->scan_cb(hapd->iface);
  948. break;
  949. case EVENT_WPS_BUTTON_PUSHED:
  950. hostapd_wps_button_pushed(hapd, NULL);
  951. break;
  952. #ifdef NEED_AP_MLME
  953. case EVENT_TX_STATUS:
  954. switch (data->tx_status.type) {
  955. case WLAN_FC_TYPE_MGMT:
  956. hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
  957. data->tx_status.data_len,
  958. data->tx_status.stype,
  959. data->tx_status.ack);
  960. break;
  961. case WLAN_FC_TYPE_DATA:
  962. hostapd_tx_status(hapd, data->tx_status.dst,
  963. data->tx_status.data,
  964. data->tx_status.data_len,
  965. data->tx_status.ack);
  966. break;
  967. }
  968. break;
  969. case EVENT_EAPOL_TX_STATUS:
  970. hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
  971. data->eapol_tx_status.data,
  972. data->eapol_tx_status.data_len,
  973. data->eapol_tx_status.ack);
  974. break;
  975. case EVENT_DRIVER_CLIENT_POLL_OK:
  976. hostapd_client_poll_ok(hapd, data->client_poll.addr);
  977. break;
  978. case EVENT_RX_FROM_UNKNOWN:
  979. hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
  980. data->rx_from_unknown.addr,
  981. data->rx_from_unknown.wds);
  982. break;
  983. #endif /* NEED_AP_MLME */
  984. case EVENT_RX_MGMT:
  985. if (!data->rx_mgmt.frame)
  986. break;
  987. #ifdef NEED_AP_MLME
  988. if (hostapd_mgmt_rx(hapd, &data->rx_mgmt) > 0)
  989. break;
  990. #endif /* NEED_AP_MLME */
  991. hostapd_action_rx(hapd, &data->rx_mgmt);
  992. break;
  993. case EVENT_RX_PROBE_REQ:
  994. if (data->rx_probe_req.sa == NULL ||
  995. data->rx_probe_req.ie == NULL)
  996. break;
  997. hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
  998. data->rx_probe_req.da,
  999. data->rx_probe_req.bssid,
  1000. data->rx_probe_req.ie,
  1001. data->rx_probe_req.ie_len,
  1002. data->rx_probe_req.ssi_signal);
  1003. break;
  1004. case EVENT_NEW_STA:
  1005. hostapd_event_new_sta(hapd, data->new_sta.addr);
  1006. break;
  1007. case EVENT_EAPOL_RX:
  1008. hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
  1009. data->eapol_rx.data,
  1010. data->eapol_rx.data_len);
  1011. break;
  1012. case EVENT_ASSOC:
  1013. if (!data)
  1014. return;
  1015. hostapd_notif_assoc(hapd, data->assoc_info.addr,
  1016. data->assoc_info.req_ies,
  1017. data->assoc_info.req_ies_len,
  1018. data->assoc_info.reassoc);
  1019. break;
  1020. case EVENT_DISASSOC:
  1021. if (data)
  1022. hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
  1023. break;
  1024. case EVENT_DEAUTH:
  1025. if (data)
  1026. hostapd_notif_disassoc(hapd, data->deauth_info.addr);
  1027. break;
  1028. case EVENT_STATION_LOW_ACK:
  1029. if (!data)
  1030. break;
  1031. hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
  1032. break;
  1033. case EVENT_AUTH:
  1034. hostapd_notif_auth(hapd, &data->auth);
  1035. break;
  1036. case EVENT_CH_SWITCH:
  1037. if (!data)
  1038. break;
  1039. hostapd_event_ch_switch(hapd, data->ch_switch.freq,
  1040. data->ch_switch.ht_enabled,
  1041. data->ch_switch.ch_offset,
  1042. data->ch_switch.ch_width,
  1043. data->ch_switch.cf1,
  1044. data->ch_switch.cf2);
  1045. break;
  1046. case EVENT_CONNECT_FAILED_REASON:
  1047. if (!data)
  1048. break;
  1049. hostapd_event_connect_failed_reason(
  1050. hapd, data->connect_failed_reason.addr,
  1051. data->connect_failed_reason.code);
  1052. break;
  1053. case EVENT_SURVEY:
  1054. hostapd_event_get_survey(hapd, &data->survey_results);
  1055. break;
  1056. #ifdef NEED_AP_MLME
  1057. case EVENT_INTERFACE_UNAVAILABLE:
  1058. hostapd_event_iface_unavailable(hapd);
  1059. break;
  1060. case EVENT_DFS_RADAR_DETECTED:
  1061. if (!data)
  1062. break;
  1063. hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
  1064. break;
  1065. case EVENT_DFS_CAC_FINISHED:
  1066. if (!data)
  1067. break;
  1068. hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
  1069. break;
  1070. case EVENT_DFS_CAC_ABORTED:
  1071. if (!data)
  1072. break;
  1073. hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event);
  1074. break;
  1075. case EVENT_DFS_NOP_FINISHED:
  1076. if (!data)
  1077. break;
  1078. hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
  1079. break;
  1080. case EVENT_CHANNEL_LIST_CHANGED:
  1081. /* channel list changed (regulatory?), update channel list */
  1082. /* TODO: check this. hostapd_get_hw_features() initializes
  1083. * too much stuff. */
  1084. /* hostapd_get_hw_features(hapd->iface); */
  1085. hostapd_channel_list_updated(
  1086. hapd->iface, data->channel_list_changed.initiator);
  1087. break;
  1088. case EVENT_DFS_CAC_STARTED:
  1089. if (!data)
  1090. break;
  1091. hostapd_event_dfs_cac_started(hapd, &data->dfs_event);
  1092. break;
  1093. #endif /* NEED_AP_MLME */
  1094. case EVENT_INTERFACE_ENABLED:
  1095. wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED);
  1096. if (hapd->disabled && hapd->started) {
  1097. hapd->disabled = 0;
  1098. /*
  1099. * Try to re-enable interface if the driver stopped it
  1100. * when the interface got disabled.
  1101. */
  1102. wpa_auth_reconfig_group_keys(hapd->wpa_auth);
  1103. hapd->reenable_beacon = 1;
  1104. ieee802_11_set_beacon(hapd);
  1105. }
  1106. break;
  1107. case EVENT_INTERFACE_DISABLED:
  1108. hostapd_free_stas(hapd);
  1109. wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED);
  1110. hapd->disabled = 1;
  1111. break;
  1112. #ifdef CONFIG_ACS
  1113. case EVENT_ACS_CHANNEL_SELECTED:
  1114. hostapd_acs_channel_selected(hapd,
  1115. &data->acs_selected_channels);
  1116. break;
  1117. #endif /* CONFIG_ACS */
  1118. default:
  1119. wpa_printf(MSG_DEBUG, "Unknown event %d", event);
  1120. break;
  1121. }
  1122. }
  1123. #endif /* HOSTAPD */