drv_callbacks.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  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, i;
  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. if (!hapd->iface->current_mode) {
  482. for (i = 0; i < hapd->iface->num_hw_features; i++) {
  483. struct hostapd_hw_modes *mode =
  484. &hapd->iface->hw_features[i];
  485. if (mode->mode == acs_res->hw_mode) {
  486. hapd->iface->current_mode = mode;
  487. break;
  488. }
  489. }
  490. if (!hapd->iface->current_mode) {
  491. hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
  492. HOSTAPD_LEVEL_WARNING,
  493. "driver selected to bad hw_mode");
  494. return;
  495. }
  496. }
  497. hapd->iface->freq = hostapd_hw_get_freq(hapd, acs_res->pri_channel);
  498. if (!acs_res->pri_channel) {
  499. hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
  500. HOSTAPD_LEVEL_WARNING,
  501. "driver switched to bad channel");
  502. return;
  503. }
  504. hapd->iconf->channel = acs_res->pri_channel;
  505. hapd->iconf->acs = 1;
  506. if (acs_res->sec_channel == 0)
  507. hapd->iconf->secondary_channel = 0;
  508. else if (acs_res->sec_channel < acs_res->pri_channel)
  509. hapd->iconf->secondary_channel = -1;
  510. else if (acs_res->sec_channel > acs_res->pri_channel)
  511. hapd->iconf->secondary_channel = 1;
  512. else {
  513. wpa_printf(MSG_ERROR, "Invalid secondary channel!");
  514. return;
  515. }
  516. if (hapd->iface->conf->ieee80211ac) {
  517. /* set defaults for backwards compatibility */
  518. hapd->iconf->vht_oper_centr_freq_seg1_idx = 0;
  519. hapd->iconf->vht_oper_centr_freq_seg0_idx = 0;
  520. hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT;
  521. if (acs_res->ch_width == 80) {
  522. hapd->iconf->vht_oper_centr_freq_seg0_idx =
  523. acs_res->vht_seg0_center_ch;
  524. hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ;
  525. } else if (acs_res->ch_width == 160) {
  526. if (acs_res->vht_seg1_center_ch == 0) {
  527. hapd->iconf->vht_oper_centr_freq_seg0_idx =
  528. acs_res->vht_seg0_center_ch;
  529. hapd->iconf->vht_oper_chwidth =
  530. VHT_CHANWIDTH_160MHZ;
  531. } else {
  532. hapd->iconf->vht_oper_centr_freq_seg0_idx =
  533. acs_res->vht_seg0_center_ch;
  534. hapd->iconf->vht_oper_centr_freq_seg1_idx =
  535. acs_res->vht_seg1_center_ch;
  536. hapd->iconf->vht_oper_chwidth =
  537. VHT_CHANWIDTH_80P80MHZ;
  538. }
  539. }
  540. }
  541. ret = hostapd_acs_completed(hapd->iface, 0);
  542. if (ret) {
  543. wpa_printf(MSG_ERROR,
  544. "ACS: Possibly channel configuration is invalid");
  545. }
  546. }
  547. #endif /* CONFIG_ACS */
  548. int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
  549. const u8 *bssid, const u8 *ie, size_t ie_len,
  550. int ssi_signal)
  551. {
  552. size_t i;
  553. int ret = 0;
  554. if (sa == NULL || ie == NULL)
  555. return -1;
  556. random_add_randomness(sa, ETH_ALEN);
  557. for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
  558. if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
  559. sa, da, bssid, ie, ie_len,
  560. ssi_signal) > 0) {
  561. ret = 1;
  562. break;
  563. }
  564. }
  565. return ret;
  566. }
  567. #ifdef HOSTAPD
  568. #ifdef CONFIG_IEEE80211R
  569. static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
  570. const u8 *bssid,
  571. u16 auth_transaction, u16 status,
  572. const u8 *ies, size_t ies_len)
  573. {
  574. struct hostapd_data *hapd = ctx;
  575. struct sta_info *sta;
  576. sta = ap_get_sta(hapd, dst);
  577. if (sta == NULL)
  578. return;
  579. hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
  580. HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
  581. sta->flags |= WLAN_STA_AUTH;
  582. hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
  583. }
  584. #endif /* CONFIG_IEEE80211R */
  585. static void hostapd_notif_auth(struct hostapd_data *hapd,
  586. struct auth_info *rx_auth)
  587. {
  588. struct sta_info *sta;
  589. u16 status = WLAN_STATUS_SUCCESS;
  590. u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
  591. size_t resp_ies_len = 0;
  592. sta = ap_get_sta(hapd, rx_auth->peer);
  593. if (!sta) {
  594. sta = ap_sta_add(hapd, rx_auth->peer);
  595. if (sta == NULL) {
  596. status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
  597. goto fail;
  598. }
  599. }
  600. sta->flags &= ~WLAN_STA_PREAUTH;
  601. ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
  602. #ifdef CONFIG_IEEE80211R
  603. if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
  604. sta->auth_alg = WLAN_AUTH_FT;
  605. if (sta->wpa_sm == NULL)
  606. sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
  607. sta->addr, NULL);
  608. if (sta->wpa_sm == NULL) {
  609. wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
  610. "state machine");
  611. status = WLAN_STATUS_UNSPECIFIED_FAILURE;
  612. goto fail;
  613. }
  614. wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid,
  615. rx_auth->auth_transaction, rx_auth->ies,
  616. rx_auth->ies_len,
  617. hostapd_notify_auth_ft_finish, hapd);
  618. return;
  619. }
  620. #endif /* CONFIG_IEEE80211R */
  621. fail:
  622. hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
  623. status, resp_ies, resp_ies_len);
  624. }
  625. static void hostapd_action_rx(struct hostapd_data *hapd,
  626. struct rx_mgmt *drv_mgmt)
  627. {
  628. struct ieee80211_mgmt *mgmt;
  629. struct sta_info *sta;
  630. size_t plen __maybe_unused;
  631. u16 fc;
  632. if (drv_mgmt->frame_len < 24 + 1)
  633. return;
  634. plen = drv_mgmt->frame_len - 24 - 1;
  635. mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame;
  636. fc = le_to_host16(mgmt->frame_control);
  637. if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
  638. return; /* handled by the driver */
  639. wpa_printf(MSG_DEBUG, "RX_ACTION cat %d action plen %d",
  640. mgmt->u.action.category, (int) plen);
  641. sta = ap_get_sta(hapd, mgmt->sa);
  642. if (sta == NULL) {
  643. wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
  644. return;
  645. }
  646. #ifdef CONFIG_IEEE80211R
  647. if (mgmt->u.action.category == WLAN_ACTION_FT) {
  648. const u8 *payload = drv_mgmt->frame + 24 + 1;
  649. wpa_ft_action_rx(sta->wpa_sm, payload, plen);
  650. }
  651. #endif /* CONFIG_IEEE80211R */
  652. #ifdef CONFIG_IEEE80211W
  653. if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY && plen >= 4) {
  654. ieee802_11_sa_query_action(
  655. hapd, mgmt->sa,
  656. mgmt->u.action.u.sa_query_resp.action,
  657. mgmt->u.action.u.sa_query_resp.trans_id);
  658. }
  659. #endif /* CONFIG_IEEE80211W */
  660. #ifdef CONFIG_WNM
  661. if (mgmt->u.action.category == WLAN_ACTION_WNM) {
  662. ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len);
  663. }
  664. #endif /* CONFIG_WNM */
  665. }
  666. #ifdef NEED_AP_MLME
  667. #define HAPD_BROADCAST ((struct hostapd_data *) -1)
  668. static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
  669. const u8 *bssid)
  670. {
  671. size_t i;
  672. if (bssid == NULL)
  673. return NULL;
  674. if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
  675. bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
  676. return HAPD_BROADCAST;
  677. for (i = 0; i < iface->num_bss; i++) {
  678. if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0)
  679. return iface->bss[i];
  680. }
  681. return NULL;
  682. }
  683. static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
  684. const u8 *bssid, const u8 *addr,
  685. int wds)
  686. {
  687. hapd = get_hapd_bssid(hapd->iface, bssid);
  688. if (hapd == NULL || hapd == HAPD_BROADCAST)
  689. return;
  690. ieee802_11_rx_from_unknown(hapd, addr, wds);
  691. }
  692. static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
  693. {
  694. struct hostapd_iface *iface = hapd->iface;
  695. const struct ieee80211_hdr *hdr;
  696. const u8 *bssid;
  697. struct hostapd_frame_info fi;
  698. int ret;
  699. #ifdef CONFIG_TESTING_OPTIONS
  700. if (hapd->ext_mgmt_frame_handling) {
  701. size_t hex_len = 2 * rx_mgmt->frame_len + 1;
  702. char *hex = os_malloc(hex_len);
  703. if (hex) {
  704. wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame,
  705. rx_mgmt->frame_len);
  706. wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
  707. os_free(hex);
  708. }
  709. return 1;
  710. }
  711. #endif /* CONFIG_TESTING_OPTIONS */
  712. hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
  713. bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
  714. if (bssid == NULL)
  715. return 0;
  716. hapd = get_hapd_bssid(iface, bssid);
  717. if (hapd == NULL) {
  718. u16 fc;
  719. fc = le_to_host16(hdr->frame_control);
  720. /*
  721. * Drop frames to unknown BSSIDs except for Beacon frames which
  722. * could be used to update neighbor information.
  723. */
  724. if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
  725. WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
  726. hapd = iface->bss[0];
  727. else
  728. return 0;
  729. }
  730. os_memset(&fi, 0, sizeof(fi));
  731. fi.datarate = rx_mgmt->datarate;
  732. fi.ssi_signal = rx_mgmt->ssi_signal;
  733. if (hapd == HAPD_BROADCAST) {
  734. size_t i;
  735. ret = 0;
  736. for (i = 0; i < iface->num_bss; i++) {
  737. /* if bss is set, driver will call this function for
  738. * each bss individually. */
  739. if (rx_mgmt->drv_priv &&
  740. (iface->bss[i]->drv_priv != rx_mgmt->drv_priv))
  741. continue;
  742. if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
  743. rx_mgmt->frame_len, &fi) > 0)
  744. ret = 1;
  745. }
  746. } else
  747. ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len,
  748. &fi);
  749. random_add_randomness(&fi, sizeof(fi));
  750. return ret;
  751. }
  752. static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
  753. size_t len, u16 stype, int ok)
  754. {
  755. struct ieee80211_hdr *hdr;
  756. hdr = (struct ieee80211_hdr *) buf;
  757. hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len));
  758. if (hapd == NULL || hapd == HAPD_BROADCAST)
  759. return;
  760. ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
  761. }
  762. #endif /* NEED_AP_MLME */
  763. static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
  764. {
  765. struct sta_info *sta = ap_get_sta(hapd, addr);
  766. if (sta)
  767. return 0;
  768. wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
  769. " - adding a new STA", MAC2STR(addr));
  770. sta = ap_sta_add(hapd, addr);
  771. if (sta) {
  772. hostapd_new_assoc_sta(hapd, sta, 0);
  773. } else {
  774. wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
  775. MAC2STR(addr));
  776. return -1;
  777. }
  778. return 0;
  779. }
  780. static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
  781. const u8 *data, size_t data_len)
  782. {
  783. struct hostapd_iface *iface = hapd->iface;
  784. struct sta_info *sta;
  785. size_t j;
  786. for (j = 0; j < iface->num_bss; j++) {
  787. if ((sta = ap_get_sta(iface->bss[j], src))) {
  788. if (sta->flags & WLAN_STA_ASSOC) {
  789. hapd = iface->bss[j];
  790. break;
  791. }
  792. }
  793. }
  794. ieee802_1x_receive(hapd, src, data, data_len);
  795. }
  796. static struct hostapd_channel_data * hostapd_get_mode_channel(
  797. struct hostapd_iface *iface, unsigned int freq)
  798. {
  799. int i;
  800. struct hostapd_channel_data *chan;
  801. for (i = 0; i < iface->current_mode->num_channels; i++) {
  802. chan = &iface->current_mode->channels[i];
  803. if (!chan)
  804. return NULL;
  805. if ((unsigned int) chan->freq == freq)
  806. return chan;
  807. }
  808. return NULL;
  809. }
  810. static void hostapd_update_nf(struct hostapd_iface *iface,
  811. struct hostapd_channel_data *chan,
  812. struct freq_survey *survey)
  813. {
  814. if (!iface->chans_surveyed) {
  815. chan->min_nf = survey->nf;
  816. iface->lowest_nf = survey->nf;
  817. } else {
  818. if (dl_list_empty(&chan->survey_list))
  819. chan->min_nf = survey->nf;
  820. else if (survey->nf < chan->min_nf)
  821. chan->min_nf = survey->nf;
  822. if (survey->nf < iface->lowest_nf)
  823. iface->lowest_nf = survey->nf;
  824. }
  825. }
  826. static void hostapd_single_channel_get_survey(struct hostapd_iface *iface,
  827. struct survey_results *survey_res)
  828. {
  829. struct hostapd_channel_data *chan;
  830. struct freq_survey *survey;
  831. u64 divisor, dividend;
  832. survey = dl_list_first(&survey_res->survey_list, struct freq_survey,
  833. list);
  834. if (!survey || !survey->freq)
  835. return;
  836. chan = hostapd_get_mode_channel(iface, survey->freq);
  837. if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED)
  838. return;
  839. wpa_printf(MSG_DEBUG, "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
  840. survey->freq,
  841. (unsigned long int) survey->channel_time,
  842. (unsigned long int) survey->channel_time_busy);
  843. if (survey->channel_time > iface->last_channel_time &&
  844. survey->channel_time > survey->channel_time_busy) {
  845. dividend = survey->channel_time_busy -
  846. iface->last_channel_time_busy;
  847. divisor = survey->channel_time - iface->last_channel_time;
  848. iface->channel_utilization = dividend * 255 / divisor;
  849. wpa_printf(MSG_DEBUG, "Channel Utilization: %d",
  850. iface->channel_utilization);
  851. }
  852. iface->last_channel_time = survey->channel_time;
  853. iface->last_channel_time_busy = survey->channel_time_busy;
  854. }
  855. static void hostapd_event_get_survey(struct hostapd_data *hapd,
  856. struct survey_results *survey_results)
  857. {
  858. struct hostapd_iface *iface = hapd->iface;
  859. struct freq_survey *survey, *tmp;
  860. struct hostapd_channel_data *chan;
  861. if (dl_list_empty(&survey_results->survey_list)) {
  862. wpa_printf(MSG_DEBUG, "No survey data received");
  863. return;
  864. }
  865. if (survey_results->freq_filter) {
  866. hostapd_single_channel_get_survey(iface, survey_results);
  867. return;
  868. }
  869. dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
  870. struct freq_survey, list) {
  871. chan = hostapd_get_mode_channel(iface, survey->freq);
  872. if (!chan)
  873. continue;
  874. if (chan->flag & HOSTAPD_CHAN_DISABLED)
  875. continue;
  876. dl_list_del(&survey->list);
  877. dl_list_add_tail(&chan->survey_list, &survey->list);
  878. hostapd_update_nf(iface, chan, survey);
  879. iface->chans_surveyed++;
  880. }
  881. }
  882. #ifdef NEED_AP_MLME
  883. static void hostapd_event_iface_unavailable(struct hostapd_data *hapd)
  884. {
  885. wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped",
  886. hapd->conf->iface);
  887. if (hapd->csa_in_progress) {
  888. wpa_printf(MSG_INFO, "CSA failed (%s was stopped)",
  889. hapd->conf->iface);
  890. hostapd_switch_channel_fallback(hapd->iface,
  891. &hapd->cs_freq_params);
  892. }
  893. }
  894. static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
  895. struct dfs_event *radar)
  896. {
  897. wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
  898. hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled,
  899. radar->chan_offset, radar->chan_width,
  900. radar->cf1, radar->cf2);
  901. }
  902. static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
  903. struct dfs_event *radar)
  904. {
  905. wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
  906. hostapd_dfs_complete_cac(hapd->iface, 1, 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_aborted(struct hostapd_data *hapd,
  911. struct dfs_event *radar)
  912. {
  913. wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
  914. hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled,
  915. radar->chan_offset, radar->chan_width,
  916. radar->cf1, radar->cf2);
  917. }
  918. static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
  919. struct dfs_event *radar)
  920. {
  921. wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
  922. hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled,
  923. radar->chan_offset, radar->chan_width,
  924. radar->cf1, radar->cf2);
  925. }
  926. static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
  927. struct dfs_event *radar)
  928. {
  929. wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq);
  930. hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled,
  931. radar->chan_offset, radar->chan_width,
  932. radar->cf1, radar->cf2);
  933. }
  934. #endif /* NEED_AP_MLME */
  935. void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
  936. union wpa_event_data *data)
  937. {
  938. struct hostapd_data *hapd = ctx;
  939. #ifndef CONFIG_NO_STDOUT_DEBUG
  940. int level = MSG_DEBUG;
  941. if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
  942. data->rx_mgmt.frame_len >= 24) {
  943. const struct ieee80211_hdr *hdr;
  944. u16 fc;
  945. hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
  946. fc = le_to_host16(hdr->frame_control);
  947. if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
  948. WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
  949. level = MSG_EXCESSIVE;
  950. if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
  951. WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
  952. level = MSG_EXCESSIVE;
  953. }
  954. wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
  955. event_to_string(event), event);
  956. #endif /* CONFIG_NO_STDOUT_DEBUG */
  957. switch (event) {
  958. case EVENT_MICHAEL_MIC_FAILURE:
  959. michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
  960. break;
  961. case EVENT_SCAN_RESULTS:
  962. if (hapd->iface->scan_cb)
  963. hapd->iface->scan_cb(hapd->iface);
  964. break;
  965. case EVENT_WPS_BUTTON_PUSHED:
  966. hostapd_wps_button_pushed(hapd, NULL);
  967. break;
  968. #ifdef NEED_AP_MLME
  969. case EVENT_TX_STATUS:
  970. switch (data->tx_status.type) {
  971. case WLAN_FC_TYPE_MGMT:
  972. hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
  973. data->tx_status.data_len,
  974. data->tx_status.stype,
  975. data->tx_status.ack);
  976. break;
  977. case WLAN_FC_TYPE_DATA:
  978. hostapd_tx_status(hapd, data->tx_status.dst,
  979. data->tx_status.data,
  980. data->tx_status.data_len,
  981. data->tx_status.ack);
  982. break;
  983. }
  984. break;
  985. case EVENT_EAPOL_TX_STATUS:
  986. hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
  987. data->eapol_tx_status.data,
  988. data->eapol_tx_status.data_len,
  989. data->eapol_tx_status.ack);
  990. break;
  991. case EVENT_DRIVER_CLIENT_POLL_OK:
  992. hostapd_client_poll_ok(hapd, data->client_poll.addr);
  993. break;
  994. case EVENT_RX_FROM_UNKNOWN:
  995. hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
  996. data->rx_from_unknown.addr,
  997. data->rx_from_unknown.wds);
  998. break;
  999. #endif /* NEED_AP_MLME */
  1000. case EVENT_RX_MGMT:
  1001. if (!data->rx_mgmt.frame)
  1002. break;
  1003. #ifdef NEED_AP_MLME
  1004. if (hostapd_mgmt_rx(hapd, &data->rx_mgmt) > 0)
  1005. break;
  1006. #endif /* NEED_AP_MLME */
  1007. hostapd_action_rx(hapd, &data->rx_mgmt);
  1008. break;
  1009. case EVENT_RX_PROBE_REQ:
  1010. if (data->rx_probe_req.sa == NULL ||
  1011. data->rx_probe_req.ie == NULL)
  1012. break;
  1013. hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
  1014. data->rx_probe_req.da,
  1015. data->rx_probe_req.bssid,
  1016. data->rx_probe_req.ie,
  1017. data->rx_probe_req.ie_len,
  1018. data->rx_probe_req.ssi_signal);
  1019. break;
  1020. case EVENT_NEW_STA:
  1021. hostapd_event_new_sta(hapd, data->new_sta.addr);
  1022. break;
  1023. case EVENT_EAPOL_RX:
  1024. hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
  1025. data->eapol_rx.data,
  1026. data->eapol_rx.data_len);
  1027. break;
  1028. case EVENT_ASSOC:
  1029. if (!data)
  1030. return;
  1031. hostapd_notif_assoc(hapd, data->assoc_info.addr,
  1032. data->assoc_info.req_ies,
  1033. data->assoc_info.req_ies_len,
  1034. data->assoc_info.reassoc);
  1035. break;
  1036. case EVENT_DISASSOC:
  1037. if (data)
  1038. hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
  1039. break;
  1040. case EVENT_DEAUTH:
  1041. if (data)
  1042. hostapd_notif_disassoc(hapd, data->deauth_info.addr);
  1043. break;
  1044. case EVENT_STATION_LOW_ACK:
  1045. if (!data)
  1046. break;
  1047. hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
  1048. break;
  1049. case EVENT_AUTH:
  1050. hostapd_notif_auth(hapd, &data->auth);
  1051. break;
  1052. case EVENT_CH_SWITCH:
  1053. if (!data)
  1054. break;
  1055. hostapd_event_ch_switch(hapd, data->ch_switch.freq,
  1056. data->ch_switch.ht_enabled,
  1057. data->ch_switch.ch_offset,
  1058. data->ch_switch.ch_width,
  1059. data->ch_switch.cf1,
  1060. data->ch_switch.cf2);
  1061. break;
  1062. case EVENT_CONNECT_FAILED_REASON:
  1063. if (!data)
  1064. break;
  1065. hostapd_event_connect_failed_reason(
  1066. hapd, data->connect_failed_reason.addr,
  1067. data->connect_failed_reason.code);
  1068. break;
  1069. case EVENT_SURVEY:
  1070. hostapd_event_get_survey(hapd, &data->survey_results);
  1071. break;
  1072. #ifdef NEED_AP_MLME
  1073. case EVENT_INTERFACE_UNAVAILABLE:
  1074. hostapd_event_iface_unavailable(hapd);
  1075. break;
  1076. case EVENT_DFS_RADAR_DETECTED:
  1077. if (!data)
  1078. break;
  1079. hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
  1080. break;
  1081. case EVENT_DFS_CAC_FINISHED:
  1082. if (!data)
  1083. break;
  1084. hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
  1085. break;
  1086. case EVENT_DFS_CAC_ABORTED:
  1087. if (!data)
  1088. break;
  1089. hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event);
  1090. break;
  1091. case EVENT_DFS_NOP_FINISHED:
  1092. if (!data)
  1093. break;
  1094. hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
  1095. break;
  1096. case EVENT_CHANNEL_LIST_CHANGED:
  1097. /* channel list changed (regulatory?), update channel list */
  1098. /* TODO: check this. hostapd_get_hw_features() initializes
  1099. * too much stuff. */
  1100. /* hostapd_get_hw_features(hapd->iface); */
  1101. hostapd_channel_list_updated(
  1102. hapd->iface, data->channel_list_changed.initiator);
  1103. break;
  1104. case EVENT_DFS_CAC_STARTED:
  1105. if (!data)
  1106. break;
  1107. hostapd_event_dfs_cac_started(hapd, &data->dfs_event);
  1108. break;
  1109. #endif /* NEED_AP_MLME */
  1110. case EVENT_INTERFACE_ENABLED:
  1111. wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED);
  1112. if (hapd->disabled && hapd->started) {
  1113. hapd->disabled = 0;
  1114. /*
  1115. * Try to re-enable interface if the driver stopped it
  1116. * when the interface got disabled.
  1117. */
  1118. wpa_auth_reconfig_group_keys(hapd->wpa_auth);
  1119. hapd->reenable_beacon = 1;
  1120. ieee802_11_set_beacon(hapd);
  1121. }
  1122. break;
  1123. case EVENT_INTERFACE_DISABLED:
  1124. hostapd_free_stas(hapd);
  1125. wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED);
  1126. hapd->disabled = 1;
  1127. break;
  1128. #ifdef CONFIG_ACS
  1129. case EVENT_ACS_CHANNEL_SELECTED:
  1130. hostapd_acs_channel_selected(hapd,
  1131. &data->acs_selected_channels);
  1132. break;
  1133. #endif /* CONFIG_ACS */
  1134. default:
  1135. wpa_printf(MSG_DEBUG, "Unknown event %d", event);
  1136. break;
  1137. }
  1138. }
  1139. #endif /* HOSTAPD */