drv_callbacks.c 35 KB

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