drv_callbacks.c 31 KB

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