drv_callbacks.c 37 KB

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