drv_callbacks.c 33 KB

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