ieee802_11.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201
  1. /*
  2. * hostapd / IEEE 802.11 Management
  3. * Copyright (c) 2002-2012, 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. #ifndef CONFIG_NATIVE_WINDOWS
  10. #include "utils/common.h"
  11. #include "utils/eloop.h"
  12. #include "crypto/crypto.h"
  13. #include "crypto/sha256.h"
  14. #include "crypto/random.h"
  15. #include "drivers/driver.h"
  16. #include "common/ieee802_11_defs.h"
  17. #include "common/ieee802_11_common.h"
  18. #include "common/wpa_ctrl.h"
  19. #include "common/sae.h"
  20. #include "radius/radius.h"
  21. #include "radius/radius_client.h"
  22. #include "p2p/p2p.h"
  23. #include "wps/wps.h"
  24. #include "hostapd.h"
  25. #include "beacon.h"
  26. #include "ieee802_11_auth.h"
  27. #include "sta_info.h"
  28. #include "ieee802_1x.h"
  29. #include "wpa_auth.h"
  30. #include "wmm.h"
  31. #include "ap_list.h"
  32. #include "accounting.h"
  33. #include "ap_config.h"
  34. #include "ap_mlme.h"
  35. #include "p2p_hostapd.h"
  36. #include "ap_drv_ops.h"
  37. #include "wnm_ap.h"
  38. #include "ieee802_11.h"
  39. u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
  40. {
  41. u8 *pos = eid;
  42. int i, num, count;
  43. if (hapd->iface->current_rates == NULL)
  44. return eid;
  45. *pos++ = WLAN_EID_SUPP_RATES;
  46. num = hapd->iface->num_rates;
  47. if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
  48. num++;
  49. if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
  50. num++;
  51. if (num > 8) {
  52. /* rest of the rates are encoded in Extended supported
  53. * rates element */
  54. num = 8;
  55. }
  56. *pos++ = num;
  57. count = 0;
  58. for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
  59. i++) {
  60. count++;
  61. *pos = hapd->iface->current_rates[i].rate / 5;
  62. if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
  63. *pos |= 0x80;
  64. pos++;
  65. }
  66. if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) {
  67. count++;
  68. *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
  69. }
  70. if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) {
  71. count++;
  72. *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
  73. }
  74. return pos;
  75. }
  76. u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
  77. {
  78. u8 *pos = eid;
  79. int i, num, count;
  80. if (hapd->iface->current_rates == NULL)
  81. return eid;
  82. num = hapd->iface->num_rates;
  83. if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
  84. num++;
  85. if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
  86. num++;
  87. if (num <= 8)
  88. return eid;
  89. num -= 8;
  90. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  91. *pos++ = num;
  92. count = 0;
  93. for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
  94. i++) {
  95. count++;
  96. if (count <= 8)
  97. continue; /* already in SuppRates IE */
  98. *pos = hapd->iface->current_rates[i].rate / 5;
  99. if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
  100. *pos |= 0x80;
  101. pos++;
  102. }
  103. if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
  104. count++;
  105. if (count > 8)
  106. *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
  107. }
  108. if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
  109. count++;
  110. if (count > 8)
  111. *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
  112. }
  113. return pos;
  114. }
  115. u16 hostapd_own_capab_info(struct hostapd_data *hapd, struct sta_info *sta,
  116. int probe)
  117. {
  118. int capab = WLAN_CAPABILITY_ESS;
  119. int privacy;
  120. if (hapd->iface->num_sta_no_short_preamble == 0 &&
  121. hapd->iconf->preamble == SHORT_PREAMBLE)
  122. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  123. privacy = hapd->conf->ssid.wep.keys_set;
  124. if (hapd->conf->ieee802_1x &&
  125. (hapd->conf->default_wep_key_len ||
  126. hapd->conf->individual_wep_key_len))
  127. privacy = 1;
  128. if (hapd->conf->wpa)
  129. privacy = 1;
  130. if (sta) {
  131. int policy, def_klen;
  132. if (probe && sta->ssid_probe) {
  133. policy = sta->ssid_probe->security_policy;
  134. def_klen = sta->ssid_probe->wep.default_len;
  135. } else {
  136. policy = sta->ssid->security_policy;
  137. def_klen = sta->ssid->wep.default_len;
  138. }
  139. privacy = policy != SECURITY_PLAINTEXT;
  140. if (policy == SECURITY_IEEE_802_1X && def_klen == 0)
  141. privacy = 0;
  142. }
  143. if (privacy)
  144. capab |= WLAN_CAPABILITY_PRIVACY;
  145. if (hapd->iface->current_mode &&
  146. hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
  147. hapd->iface->num_sta_no_short_slot_time == 0)
  148. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  149. return capab;
  150. }
  151. void ieee802_11_print_ssid(char *buf, const u8 *ssid, u8 len)
  152. {
  153. int i;
  154. if (len > HOSTAPD_MAX_SSID_LEN)
  155. len = HOSTAPD_MAX_SSID_LEN;
  156. for (i = 0; i < len; i++) {
  157. if (ssid[i] >= 32 && ssid[i] < 127)
  158. buf[i] = ssid[i];
  159. else
  160. buf[i] = '.';
  161. }
  162. buf[len] = '\0';
  163. }
  164. static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
  165. u16 auth_transaction, const u8 *challenge,
  166. int iswep)
  167. {
  168. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  169. HOSTAPD_LEVEL_DEBUG,
  170. "authentication (shared key, transaction %d)",
  171. auth_transaction);
  172. if (auth_transaction == 1) {
  173. if (!sta->challenge) {
  174. /* Generate a pseudo-random challenge */
  175. u8 key[8];
  176. struct os_time now;
  177. int r;
  178. sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
  179. if (sta->challenge == NULL)
  180. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  181. os_get_time(&now);
  182. r = os_random();
  183. os_memcpy(key, &now.sec, 4);
  184. os_memcpy(key + 4, &r, 4);
  185. rc4_skip(key, sizeof(key), 0,
  186. sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
  187. }
  188. return 0;
  189. }
  190. if (auth_transaction != 3)
  191. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  192. /* Transaction 3 */
  193. if (!iswep || !sta->challenge || !challenge ||
  194. os_memcmp(sta->challenge, challenge, WLAN_AUTH_CHALLENGE_LEN)) {
  195. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  196. HOSTAPD_LEVEL_INFO,
  197. "shared key authentication - invalid "
  198. "challenge-response");
  199. return WLAN_STATUS_CHALLENGE_FAIL;
  200. }
  201. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  202. HOSTAPD_LEVEL_DEBUG,
  203. "authentication OK (shared key)");
  204. #ifdef IEEE80211_REQUIRE_AUTH_ACK
  205. /* Station will be marked authenticated if it ACKs the
  206. * authentication reply. */
  207. #else
  208. sta->flags |= WLAN_STA_AUTH;
  209. wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
  210. #endif
  211. os_free(sta->challenge);
  212. sta->challenge = NULL;
  213. return 0;
  214. }
  215. static void send_auth_reply(struct hostapd_data *hapd,
  216. const u8 *dst, const u8 *bssid,
  217. u16 auth_alg, u16 auth_transaction, u16 resp,
  218. const u8 *ies, size_t ies_len)
  219. {
  220. struct ieee80211_mgmt *reply;
  221. u8 *buf;
  222. size_t rlen;
  223. rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
  224. buf = os_zalloc(rlen);
  225. if (buf == NULL)
  226. return;
  227. reply = (struct ieee80211_mgmt *) buf;
  228. reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  229. WLAN_FC_STYPE_AUTH);
  230. os_memcpy(reply->da, dst, ETH_ALEN);
  231. os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
  232. os_memcpy(reply->bssid, bssid, ETH_ALEN);
  233. reply->u.auth.auth_alg = host_to_le16(auth_alg);
  234. reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
  235. reply->u.auth.status_code = host_to_le16(resp);
  236. if (ies && ies_len)
  237. os_memcpy(reply->u.auth.variable, ies, ies_len);
  238. wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
  239. " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
  240. MAC2STR(dst), auth_alg, auth_transaction,
  241. resp, (unsigned long) ies_len);
  242. if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
  243. perror("send_auth_reply: send");
  244. os_free(buf);
  245. }
  246. #ifdef CONFIG_IEEE80211R
  247. static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
  248. u16 auth_transaction, u16 status,
  249. const u8 *ies, size_t ies_len)
  250. {
  251. struct hostapd_data *hapd = ctx;
  252. struct sta_info *sta;
  253. send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
  254. status, ies, ies_len);
  255. if (status != WLAN_STATUS_SUCCESS)
  256. return;
  257. sta = ap_get_sta(hapd, dst);
  258. if (sta == NULL)
  259. return;
  260. hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
  261. HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
  262. sta->flags |= WLAN_STA_AUTH;
  263. mlme_authenticate_indication(hapd, sta);
  264. }
  265. #endif /* CONFIG_IEEE80211R */
  266. #ifdef CONFIG_SAE
  267. static struct wpabuf * auth_process_sae_commit(struct hostapd_data *hapd,
  268. struct sta_info *sta)
  269. {
  270. struct wpabuf *buf;
  271. if (hapd->conf->ssid.wpa_passphrase == NULL) {
  272. wpa_printf(MSG_DEBUG, "SAE: No password available");
  273. return NULL;
  274. }
  275. if (sae_prepare_commit(hapd->own_addr, sta->addr,
  276. (u8 *) hapd->conf->ssid.wpa_passphrase,
  277. os_strlen(hapd->conf->ssid.wpa_passphrase),
  278. sta->sae) < 0) {
  279. wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
  280. return NULL;
  281. }
  282. if (sae_process_commit(sta->sae) < 0) {
  283. wpa_printf(MSG_DEBUG, "SAE: Failed to process peer commit");
  284. return NULL;
  285. }
  286. buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
  287. if (buf == NULL)
  288. return NULL;
  289. sae_write_commit(sta->sae, buf, NULL);
  290. return buf;
  291. }
  292. static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
  293. struct sta_info *sta)
  294. {
  295. struct wpabuf *buf;
  296. buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
  297. if (buf == NULL)
  298. return NULL;
  299. sae_write_confirm(sta->sae, buf);
  300. return buf;
  301. }
  302. static int use_sae_anti_clogging(struct hostapd_data *hapd)
  303. {
  304. struct sta_info *sta;
  305. unsigned int open = 0;
  306. if (hapd->conf->sae_anti_clogging_threshold == 0)
  307. return 1;
  308. for (sta = hapd->sta_list; sta; sta = sta->next) {
  309. if (!sta->sae)
  310. continue;
  311. if (sta->sae->state != SAE_COMMITTED &&
  312. sta->sae->state != SAE_CONFIRMED)
  313. continue;
  314. open++;
  315. if (open >= hapd->conf->sae_anti_clogging_threshold)
  316. return 1;
  317. }
  318. return 0;
  319. }
  320. static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
  321. const u8 *token, size_t token_len)
  322. {
  323. u8 mac[SHA256_MAC_LEN];
  324. if (token_len != SHA256_MAC_LEN)
  325. return -1;
  326. if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
  327. addr, ETH_ALEN, mac) < 0 ||
  328. os_memcmp(token, mac, SHA256_MAC_LEN) != 0)
  329. return -1;
  330. return 0;
  331. }
  332. static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
  333. const u8 *addr)
  334. {
  335. struct wpabuf *buf;
  336. u8 *token;
  337. struct os_time t;
  338. os_get_time(&t);
  339. if (hapd->last_sae_token_key_update == 0 ||
  340. t.sec > hapd->last_sae_token_key_update + 60) {
  341. if (random_get_bytes(hapd->sae_token_key,
  342. sizeof(hapd->sae_token_key)) < 0)
  343. return NULL;
  344. wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
  345. hapd->sae_token_key, sizeof(hapd->sae_token_key));
  346. hapd->last_sae_token_key_update = t.sec;
  347. }
  348. buf = wpabuf_alloc(SHA256_MAC_LEN);
  349. if (buf == NULL)
  350. return NULL;
  351. token = wpabuf_put(buf, SHA256_MAC_LEN);
  352. hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
  353. addr, ETH_ALEN, token);
  354. return buf;
  355. }
  356. static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
  357. const struct ieee80211_mgmt *mgmt, size_t len,
  358. u8 auth_transaction)
  359. {
  360. u16 resp = WLAN_STATUS_SUCCESS;
  361. struct wpabuf *data = NULL;
  362. if (!sta->sae) {
  363. if (auth_transaction != 1)
  364. return;
  365. sta->sae = os_zalloc(sizeof(*sta->sae));
  366. if (sta->sae == NULL)
  367. return;
  368. sta->sae->state = SAE_NOTHING;
  369. }
  370. if (auth_transaction == 1) {
  371. const u8 *token = NULL;
  372. size_t token_len = 0;
  373. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  374. HOSTAPD_LEVEL_DEBUG,
  375. "start SAE authentication (RX commit)");
  376. resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
  377. ((const u8 *) mgmt) + len -
  378. mgmt->u.auth.variable, &token,
  379. &token_len, hapd->conf->sae_groups);
  380. if (token && check_sae_token(hapd, sta->addr, token, token_len)
  381. < 0) {
  382. wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
  383. "incorrect token from " MACSTR,
  384. MAC2STR(sta->addr));
  385. return;
  386. }
  387. if (resp == WLAN_STATUS_SUCCESS) {
  388. if (!token && use_sae_anti_clogging(hapd)) {
  389. wpa_printf(MSG_DEBUG, "SAE: Request anti-"
  390. "clogging token from " MACSTR,
  391. MAC2STR(sta->addr));
  392. data = auth_build_token_req(hapd, sta->addr);
  393. resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
  394. } else {
  395. data = auth_process_sae_commit(hapd, sta);
  396. if (data == NULL)
  397. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  398. else
  399. sta->sae->state = SAE_COMMITTED;
  400. }
  401. }
  402. } else if (auth_transaction == 2) {
  403. if (sta->sae->state != SAE_COMMITTED) {
  404. hostapd_logger(hapd, sta->addr,
  405. HOSTAPD_MODULE_IEEE80211,
  406. HOSTAPD_LEVEL_DEBUG,
  407. "SAE confirm before commit");
  408. resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
  409. }
  410. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  411. HOSTAPD_LEVEL_DEBUG,
  412. "SAE authentication (RX confirm)");
  413. if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
  414. ((u8 *) mgmt) + len -
  415. mgmt->u.auth.variable) < 0) {
  416. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  417. } else {
  418. resp = WLAN_STATUS_SUCCESS;
  419. sta->flags |= WLAN_STA_AUTH;
  420. wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
  421. sta->auth_alg = WLAN_AUTH_SAE;
  422. mlme_authenticate_indication(hapd, sta);
  423. data = auth_build_sae_confirm(hapd, sta);
  424. if (data == NULL)
  425. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  426. else {
  427. sta->sae->state = SAE_ACCEPTED;
  428. sae_clear_temp_data(sta->sae);
  429. }
  430. }
  431. } else {
  432. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  433. HOSTAPD_LEVEL_DEBUG,
  434. "unexpected SAE authentication transaction %u",
  435. auth_transaction);
  436. resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
  437. }
  438. sta->auth_alg = WLAN_AUTH_SAE;
  439. send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
  440. auth_transaction, resp,
  441. data ? wpabuf_head(data) : (u8 *) "",
  442. data ? wpabuf_len(data) : 0);
  443. wpabuf_free(data);
  444. }
  445. #endif /* CONFIG_SAE */
  446. static void handle_auth(struct hostapd_data *hapd,
  447. const struct ieee80211_mgmt *mgmt, size_t len)
  448. {
  449. u16 auth_alg, auth_transaction, status_code;
  450. u16 resp = WLAN_STATUS_SUCCESS;
  451. struct sta_info *sta = NULL;
  452. int res;
  453. u16 fc;
  454. const u8 *challenge = NULL;
  455. u32 session_timeout, acct_interim_interval;
  456. int vlan_id = 0;
  457. struct hostapd_sta_wpa_psk_short *psk = NULL;
  458. u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
  459. size_t resp_ies_len = 0;
  460. char *identity = NULL;
  461. char *radius_cui = NULL;
  462. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
  463. printf("handle_auth - too short payload (len=%lu)\n",
  464. (unsigned long) len);
  465. return;
  466. }
  467. #ifdef CONFIG_TESTING_OPTIONS
  468. if (hapd->iconf->ignore_auth_probability > 0.0d &&
  469. drand48() < hapd->iconf->ignore_auth_probability) {
  470. wpa_printf(MSG_INFO,
  471. "TESTING: ignoring auth frame from " MACSTR,
  472. MAC2STR(mgmt->sa));
  473. return;
  474. }
  475. #endif /* CONFIG_TESTING_OPTIONS */
  476. auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
  477. auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
  478. status_code = le_to_host16(mgmt->u.auth.status_code);
  479. fc = le_to_host16(mgmt->frame_control);
  480. if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
  481. 2 + WLAN_AUTH_CHALLENGE_LEN &&
  482. mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
  483. mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
  484. challenge = &mgmt->u.auth.variable[2];
  485. wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
  486. "auth_transaction=%d status_code=%d wep=%d%s",
  487. MAC2STR(mgmt->sa), auth_alg, auth_transaction,
  488. status_code, !!(fc & WLAN_FC_ISWEP),
  489. challenge ? " challenge" : "");
  490. if (hapd->tkip_countermeasures) {
  491. resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
  492. goto fail;
  493. }
  494. if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
  495. auth_alg == WLAN_AUTH_OPEN) ||
  496. #ifdef CONFIG_IEEE80211R
  497. (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
  498. auth_alg == WLAN_AUTH_FT) ||
  499. #endif /* CONFIG_IEEE80211R */
  500. #ifdef CONFIG_SAE
  501. (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
  502. auth_alg == WLAN_AUTH_SAE) ||
  503. #endif /* CONFIG_SAE */
  504. ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
  505. auth_alg == WLAN_AUTH_SHARED_KEY))) {
  506. printf("Unsupported authentication algorithm (%d)\n",
  507. auth_alg);
  508. resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
  509. goto fail;
  510. }
  511. if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
  512. (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
  513. printf("Unknown authentication transaction number (%d)\n",
  514. auth_transaction);
  515. resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
  516. goto fail;
  517. }
  518. if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
  519. printf("Station " MACSTR " not allowed to authenticate.\n",
  520. MAC2STR(mgmt->sa));
  521. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  522. goto fail;
  523. }
  524. res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
  525. &session_timeout,
  526. &acct_interim_interval, &vlan_id,
  527. &psk, &identity, &radius_cui);
  528. if (res == HOSTAPD_ACL_REJECT) {
  529. printf("Station " MACSTR " not allowed to authenticate.\n",
  530. MAC2STR(mgmt->sa));
  531. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  532. goto fail;
  533. }
  534. if (res == HOSTAPD_ACL_PENDING) {
  535. wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
  536. " waiting for an external authentication",
  537. MAC2STR(mgmt->sa));
  538. /* Authentication code will re-send the authentication frame
  539. * after it has received (and cached) information from the
  540. * external source. */
  541. return;
  542. }
  543. sta = ap_sta_add(hapd, mgmt->sa);
  544. if (!sta) {
  545. resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
  546. goto fail;
  547. }
  548. if (vlan_id > 0) {
  549. if (hostapd_get_vlan_id_ifname(hapd->conf->vlan,
  550. vlan_id) == NULL) {
  551. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
  552. HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
  553. "%d received from RADIUS server",
  554. vlan_id);
  555. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  556. goto fail;
  557. }
  558. sta->vlan_id = vlan_id;
  559. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
  560. HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
  561. }
  562. hostapd_free_psk_list(sta->psk);
  563. if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
  564. sta->psk = psk;
  565. psk = NULL;
  566. } else {
  567. sta->psk = NULL;
  568. }
  569. sta->identity = identity;
  570. identity = NULL;
  571. sta->radius_cui = radius_cui;
  572. radius_cui = NULL;
  573. sta->flags &= ~WLAN_STA_PREAUTH;
  574. ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
  575. if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
  576. sta->acct_interim_interval = acct_interim_interval;
  577. if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
  578. ap_sta_session_timeout(hapd, sta, session_timeout);
  579. else
  580. ap_sta_no_session_timeout(hapd, sta);
  581. switch (auth_alg) {
  582. case WLAN_AUTH_OPEN:
  583. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  584. HOSTAPD_LEVEL_DEBUG,
  585. "authentication OK (open system)");
  586. #ifdef IEEE80211_REQUIRE_AUTH_ACK
  587. /* Station will be marked authenticated if it ACKs the
  588. * authentication reply. */
  589. #else
  590. sta->flags |= WLAN_STA_AUTH;
  591. wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
  592. sta->auth_alg = WLAN_AUTH_OPEN;
  593. mlme_authenticate_indication(hapd, sta);
  594. #endif
  595. break;
  596. case WLAN_AUTH_SHARED_KEY:
  597. resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
  598. fc & WLAN_FC_ISWEP);
  599. sta->auth_alg = WLAN_AUTH_SHARED_KEY;
  600. mlme_authenticate_indication(hapd, sta);
  601. if (sta->challenge && auth_transaction == 1) {
  602. resp_ies[0] = WLAN_EID_CHALLENGE;
  603. resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
  604. os_memcpy(resp_ies + 2, sta->challenge,
  605. WLAN_AUTH_CHALLENGE_LEN);
  606. resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
  607. }
  608. break;
  609. #ifdef CONFIG_IEEE80211R
  610. case WLAN_AUTH_FT:
  611. sta->auth_alg = WLAN_AUTH_FT;
  612. if (sta->wpa_sm == NULL)
  613. sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
  614. sta->addr);
  615. if (sta->wpa_sm == NULL) {
  616. wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
  617. "state machine");
  618. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  619. goto fail;
  620. }
  621. wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
  622. auth_transaction, mgmt->u.auth.variable,
  623. len - IEEE80211_HDRLEN -
  624. sizeof(mgmt->u.auth),
  625. handle_auth_ft_finish, hapd);
  626. /* handle_auth_ft_finish() callback will complete auth. */
  627. return;
  628. #endif /* CONFIG_IEEE80211R */
  629. #ifdef CONFIG_SAE
  630. case WLAN_AUTH_SAE:
  631. handle_auth_sae(hapd, sta, mgmt, len, auth_transaction);
  632. return;
  633. #endif /* CONFIG_SAE */
  634. }
  635. fail:
  636. os_free(identity);
  637. os_free(radius_cui);
  638. hostapd_free_psk_list(psk);
  639. send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
  640. auth_transaction + 1, resp, resp_ies, resp_ies_len);
  641. }
  642. static int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
  643. {
  644. int i, j = 32, aid;
  645. /* get a unique AID */
  646. if (sta->aid > 0) {
  647. wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
  648. return 0;
  649. }
  650. for (i = 0; i < AID_WORDS; i++) {
  651. if (hapd->sta_aid[i] == (u32) -1)
  652. continue;
  653. for (j = 0; j < 32; j++) {
  654. if (!(hapd->sta_aid[i] & BIT(j)))
  655. break;
  656. }
  657. if (j < 32)
  658. break;
  659. }
  660. if (j == 32)
  661. return -1;
  662. aid = i * 32 + j + 1;
  663. if (aid > 2007)
  664. return -1;
  665. sta->aid = aid;
  666. hapd->sta_aid[i] |= BIT(j);
  667. wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
  668. return 0;
  669. }
  670. static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
  671. const u8 *ssid_ie, size_t ssid_ie_len)
  672. {
  673. if (ssid_ie == NULL)
  674. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  675. if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
  676. os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
  677. char ssid_txt[33];
  678. ieee802_11_print_ssid(ssid_txt, ssid_ie, ssid_ie_len);
  679. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  680. HOSTAPD_LEVEL_INFO,
  681. "Station tried to associate with unknown SSID "
  682. "'%s'", ssid_txt);
  683. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  684. }
  685. return WLAN_STATUS_SUCCESS;
  686. }
  687. static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
  688. const u8 *wmm_ie, size_t wmm_ie_len)
  689. {
  690. sta->flags &= ~WLAN_STA_WMM;
  691. sta->qosinfo = 0;
  692. if (wmm_ie && hapd->conf->wmm_enabled) {
  693. struct wmm_information_element *wmm;
  694. if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
  695. hostapd_logger(hapd, sta->addr,
  696. HOSTAPD_MODULE_WPA,
  697. HOSTAPD_LEVEL_DEBUG,
  698. "invalid WMM element in association "
  699. "request");
  700. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  701. }
  702. sta->flags |= WLAN_STA_WMM;
  703. wmm = (struct wmm_information_element *) wmm_ie;
  704. sta->qosinfo = wmm->qos_info;
  705. }
  706. return WLAN_STATUS_SUCCESS;
  707. }
  708. static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
  709. struct ieee802_11_elems *elems)
  710. {
  711. if (!elems->supp_rates) {
  712. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  713. HOSTAPD_LEVEL_DEBUG,
  714. "No supported rates element in AssocReq");
  715. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  716. }
  717. if (elems->supp_rates_len + elems->ext_supp_rates_len >
  718. sizeof(sta->supported_rates)) {
  719. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  720. HOSTAPD_LEVEL_DEBUG,
  721. "Invalid supported rates element length %d+%d",
  722. elems->supp_rates_len,
  723. elems->ext_supp_rates_len);
  724. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  725. }
  726. sta->supported_rates_len = merge_byte_arrays(
  727. sta->supported_rates, sizeof(sta->supported_rates),
  728. elems->supp_rates, elems->supp_rates_len,
  729. elems->ext_supp_rates, elems->ext_supp_rates_len);
  730. return WLAN_STATUS_SUCCESS;
  731. }
  732. static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
  733. const u8 *ies, size_t ies_len, int reassoc)
  734. {
  735. struct ieee802_11_elems elems;
  736. u16 resp;
  737. const u8 *wpa_ie;
  738. size_t wpa_ie_len;
  739. if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
  740. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  741. HOSTAPD_LEVEL_INFO, "Station sent an invalid "
  742. "association request");
  743. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  744. }
  745. resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
  746. if (resp != WLAN_STATUS_SUCCESS)
  747. return resp;
  748. resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
  749. if (resp != WLAN_STATUS_SUCCESS)
  750. return resp;
  751. resp = copy_supp_rates(hapd, sta, &elems);
  752. if (resp != WLAN_STATUS_SUCCESS)
  753. return resp;
  754. #ifdef CONFIG_IEEE80211N
  755. resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities,
  756. elems.ht_capabilities_len);
  757. if (resp != WLAN_STATUS_SUCCESS)
  758. return resp;
  759. if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
  760. !(sta->flags & WLAN_STA_HT)) {
  761. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  762. HOSTAPD_LEVEL_INFO, "Station does not support "
  763. "mandatory HT PHY - reject association");
  764. return WLAN_STATUS_ASSOC_DENIED_NO_HT;
  765. }
  766. #endif /* CONFIG_IEEE80211N */
  767. #ifdef CONFIG_IEEE80211AC
  768. resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities,
  769. elems.vht_capabilities_len);
  770. if (resp != WLAN_STATUS_SUCCESS)
  771. return resp;
  772. if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
  773. !(sta->flags & WLAN_STA_VHT)) {
  774. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  775. HOSTAPD_LEVEL_INFO, "Station does not support "
  776. "mandatory VHT PHY - reject association");
  777. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  778. }
  779. #endif /* CONFIG_IEEE80211AC */
  780. if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
  781. wpa_ie = elems.rsn_ie;
  782. wpa_ie_len = elems.rsn_ie_len;
  783. } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
  784. elems.wpa_ie) {
  785. wpa_ie = elems.wpa_ie;
  786. wpa_ie_len = elems.wpa_ie_len;
  787. } else {
  788. wpa_ie = NULL;
  789. wpa_ie_len = 0;
  790. }
  791. #ifdef CONFIG_WPS
  792. sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
  793. if (hapd->conf->wps_state && elems.wps_ie) {
  794. wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
  795. "Request - assume WPS is used");
  796. sta->flags |= WLAN_STA_WPS;
  797. wpabuf_free(sta->wps_ie);
  798. sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
  799. WPS_IE_VENDOR_TYPE);
  800. if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
  801. wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
  802. sta->flags |= WLAN_STA_WPS2;
  803. }
  804. wpa_ie = NULL;
  805. wpa_ie_len = 0;
  806. if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
  807. wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
  808. "(Re)Association Request - reject");
  809. return WLAN_STATUS_INVALID_IE;
  810. }
  811. } else if (hapd->conf->wps_state && wpa_ie == NULL) {
  812. wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
  813. "(Re)Association Request - possible WPS use");
  814. sta->flags |= WLAN_STA_MAYBE_WPS;
  815. } else
  816. #endif /* CONFIG_WPS */
  817. if (hapd->conf->wpa && wpa_ie == NULL) {
  818. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  819. HOSTAPD_LEVEL_INFO,
  820. "No WPA/RSN IE in association request");
  821. return WLAN_STATUS_INVALID_IE;
  822. }
  823. if (hapd->conf->wpa && wpa_ie) {
  824. int res;
  825. wpa_ie -= 2;
  826. wpa_ie_len += 2;
  827. if (sta->wpa_sm == NULL)
  828. sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
  829. sta->addr);
  830. if (sta->wpa_sm == NULL) {
  831. wpa_printf(MSG_WARNING, "Failed to initialize WPA "
  832. "state machine");
  833. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  834. }
  835. res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
  836. wpa_ie, wpa_ie_len,
  837. elems.mdie, elems.mdie_len);
  838. if (res == WPA_INVALID_GROUP)
  839. resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
  840. else if (res == WPA_INVALID_PAIRWISE)
  841. resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
  842. else if (res == WPA_INVALID_AKMP)
  843. resp = WLAN_STATUS_AKMP_NOT_VALID;
  844. else if (res == WPA_ALLOC_FAIL)
  845. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  846. #ifdef CONFIG_IEEE80211W
  847. else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
  848. resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
  849. else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
  850. resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
  851. #endif /* CONFIG_IEEE80211W */
  852. else if (res == WPA_INVALID_MDIE)
  853. resp = WLAN_STATUS_INVALID_MDIE;
  854. else if (res != WPA_IE_OK)
  855. resp = WLAN_STATUS_INVALID_IE;
  856. if (resp != WLAN_STATUS_SUCCESS)
  857. return resp;
  858. #ifdef CONFIG_IEEE80211W
  859. if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
  860. sta->sa_query_count > 0)
  861. ap_check_sa_query_timeout(hapd, sta);
  862. if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
  863. (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
  864. /*
  865. * STA has already been associated with MFP and SA
  866. * Query timeout has not been reached. Reject the
  867. * association attempt temporarily and start SA Query,
  868. * if one is not pending.
  869. */
  870. if (sta->sa_query_count == 0)
  871. ap_sta_start_sa_query(hapd, sta);
  872. return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
  873. }
  874. if (wpa_auth_uses_mfp(sta->wpa_sm))
  875. sta->flags |= WLAN_STA_MFP;
  876. else
  877. sta->flags &= ~WLAN_STA_MFP;
  878. #endif /* CONFIG_IEEE80211W */
  879. #ifdef CONFIG_IEEE80211R
  880. if (sta->auth_alg == WLAN_AUTH_FT) {
  881. if (!reassoc) {
  882. wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
  883. "to use association (not "
  884. "re-association) with FT auth_alg",
  885. MAC2STR(sta->addr));
  886. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  887. }
  888. resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
  889. ies_len);
  890. if (resp != WLAN_STATUS_SUCCESS)
  891. return resp;
  892. }
  893. #endif /* CONFIG_IEEE80211R */
  894. #ifdef CONFIG_SAE
  895. if (wpa_auth_uses_sae(sta->wpa_sm) &&
  896. sta->auth_alg != WLAN_AUTH_SAE) {
  897. wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
  898. "SAE AKM after non-SAE auth_alg %u",
  899. MAC2STR(sta->addr), sta->auth_alg);
  900. return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
  901. }
  902. #endif /* CONFIG_SAE */
  903. #ifdef CONFIG_IEEE80211N
  904. if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
  905. wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
  906. hostapd_logger(hapd, sta->addr,
  907. HOSTAPD_MODULE_IEEE80211,
  908. HOSTAPD_LEVEL_INFO,
  909. "Station tried to use TKIP with HT "
  910. "association");
  911. return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
  912. }
  913. #endif /* CONFIG_IEEE80211N */
  914. } else
  915. wpa_auth_sta_no_wpa(sta->wpa_sm);
  916. #ifdef CONFIG_P2P
  917. if (elems.p2p) {
  918. wpabuf_free(sta->p2p_ie);
  919. sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
  920. P2P_IE_VENDOR_TYPE);
  921. } else {
  922. wpabuf_free(sta->p2p_ie);
  923. sta->p2p_ie = NULL;
  924. }
  925. p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
  926. #endif /* CONFIG_P2P */
  927. #ifdef CONFIG_HS20
  928. wpabuf_free(sta->hs20_ie);
  929. if (elems.hs20 && elems.hs20_len > 4) {
  930. sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
  931. elems.hs20_len - 4);
  932. } else
  933. sta->hs20_ie = NULL;
  934. #endif /* CONFIG_HS20 */
  935. return WLAN_STATUS_SUCCESS;
  936. }
  937. static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
  938. u16 reason_code)
  939. {
  940. int send_len;
  941. struct ieee80211_mgmt reply;
  942. os_memset(&reply, 0, sizeof(reply));
  943. reply.frame_control =
  944. IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
  945. os_memcpy(reply.da, addr, ETH_ALEN);
  946. os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
  947. os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
  948. send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
  949. reply.u.deauth.reason_code = host_to_le16(reason_code);
  950. if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
  951. wpa_printf(MSG_INFO, "Failed to send deauth: %s",
  952. strerror(errno));
  953. }
  954. static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
  955. u16 status_code, int reassoc, const u8 *ies,
  956. size_t ies_len)
  957. {
  958. int send_len;
  959. u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
  960. struct ieee80211_mgmt *reply;
  961. u8 *p;
  962. os_memset(buf, 0, sizeof(buf));
  963. reply = (struct ieee80211_mgmt *) buf;
  964. reply->frame_control =
  965. IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  966. (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
  967. WLAN_FC_STYPE_ASSOC_RESP));
  968. os_memcpy(reply->da, sta->addr, ETH_ALEN);
  969. os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
  970. os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
  971. send_len = IEEE80211_HDRLEN;
  972. send_len += sizeof(reply->u.assoc_resp);
  973. reply->u.assoc_resp.capab_info =
  974. host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
  975. reply->u.assoc_resp.status_code = host_to_le16(status_code);
  976. reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0)
  977. | BIT(14) | BIT(15));
  978. /* Supported rates */
  979. p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
  980. /* Extended supported rates */
  981. p = hostapd_eid_ext_supp_rates(hapd, p);
  982. #ifdef CONFIG_IEEE80211R
  983. if (status_code == WLAN_STATUS_SUCCESS) {
  984. /* IEEE 802.11r: Mobility Domain Information, Fast BSS
  985. * Transition Information, RSN, [RIC Response] */
  986. p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
  987. buf + sizeof(buf) - p,
  988. sta->auth_alg, ies, ies_len);
  989. }
  990. #endif /* CONFIG_IEEE80211R */
  991. #ifdef CONFIG_IEEE80211W
  992. if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
  993. p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
  994. #endif /* CONFIG_IEEE80211W */
  995. #ifdef CONFIG_IEEE80211N
  996. p = hostapd_eid_ht_capabilities(hapd, p);
  997. p = hostapd_eid_ht_operation(hapd, p);
  998. #endif /* CONFIG_IEEE80211N */
  999. #ifdef CONFIG_IEEE80211AC
  1000. p = hostapd_eid_vht_capabilities(hapd, p);
  1001. p = hostapd_eid_vht_operation(hapd, p);
  1002. #endif /* CONFIG_IEEE80211AC */
  1003. p = hostapd_eid_ext_capab(hapd, p);
  1004. p = hostapd_eid_bss_max_idle_period(hapd, p);
  1005. if (sta->flags & WLAN_STA_WMM)
  1006. p = hostapd_eid_wmm(hapd, p);
  1007. #ifdef CONFIG_WPS
  1008. if ((sta->flags & WLAN_STA_WPS) ||
  1009. ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
  1010. struct wpabuf *wps = wps_build_assoc_resp_ie();
  1011. if (wps) {
  1012. os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
  1013. p += wpabuf_len(wps);
  1014. wpabuf_free(wps);
  1015. }
  1016. }
  1017. #endif /* CONFIG_WPS */
  1018. #ifdef CONFIG_P2P
  1019. if (sta->p2p_ie) {
  1020. struct wpabuf *p2p_resp_ie;
  1021. enum p2p_status_code status;
  1022. switch (status_code) {
  1023. case WLAN_STATUS_SUCCESS:
  1024. status = P2P_SC_SUCCESS;
  1025. break;
  1026. case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
  1027. status = P2P_SC_FAIL_LIMIT_REACHED;
  1028. break;
  1029. default:
  1030. status = P2P_SC_FAIL_INVALID_PARAMS;
  1031. break;
  1032. }
  1033. p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
  1034. if (p2p_resp_ie) {
  1035. os_memcpy(p, wpabuf_head(p2p_resp_ie),
  1036. wpabuf_len(p2p_resp_ie));
  1037. p += wpabuf_len(p2p_resp_ie);
  1038. wpabuf_free(p2p_resp_ie);
  1039. }
  1040. }
  1041. #endif /* CONFIG_P2P */
  1042. #ifdef CONFIG_P2P_MANAGER
  1043. if (hapd->conf->p2p & P2P_MANAGE)
  1044. p = hostapd_eid_p2p_manage(hapd, p);
  1045. #endif /* CONFIG_P2P_MANAGER */
  1046. send_len += p - reply->u.assoc_resp.variable;
  1047. if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0)
  1048. wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
  1049. strerror(errno));
  1050. }
  1051. static void handle_assoc(struct hostapd_data *hapd,
  1052. const struct ieee80211_mgmt *mgmt, size_t len,
  1053. int reassoc)
  1054. {
  1055. u16 capab_info, listen_interval;
  1056. u16 resp = WLAN_STATUS_SUCCESS;
  1057. const u8 *pos;
  1058. int left, i;
  1059. struct sta_info *sta;
  1060. if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
  1061. sizeof(mgmt->u.assoc_req))) {
  1062. printf("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
  1063. "\n", reassoc, (unsigned long) len);
  1064. return;
  1065. }
  1066. #ifdef CONFIG_TESTING_OPTIONS
  1067. if (reassoc) {
  1068. if (hapd->iconf->ignore_reassoc_probability > 0.0d &&
  1069. drand48() < hapd->iconf->ignore_reassoc_probability) {
  1070. wpa_printf(MSG_INFO,
  1071. "TESTING: ignoring reassoc request from "
  1072. MACSTR, MAC2STR(mgmt->sa));
  1073. return;
  1074. }
  1075. } else {
  1076. if (hapd->iconf->ignore_assoc_probability > 0.0d &&
  1077. drand48() < hapd->iconf->ignore_assoc_probability) {
  1078. wpa_printf(MSG_INFO,
  1079. "TESTING: ignoring assoc request from "
  1080. MACSTR, MAC2STR(mgmt->sa));
  1081. return;
  1082. }
  1083. }
  1084. #endif /* CONFIG_TESTING_OPTIONS */
  1085. if (reassoc) {
  1086. capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
  1087. listen_interval = le_to_host16(
  1088. mgmt->u.reassoc_req.listen_interval);
  1089. wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
  1090. " capab_info=0x%02x listen_interval=%d current_ap="
  1091. MACSTR,
  1092. MAC2STR(mgmt->sa), capab_info, listen_interval,
  1093. MAC2STR(mgmt->u.reassoc_req.current_ap));
  1094. left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
  1095. pos = mgmt->u.reassoc_req.variable;
  1096. } else {
  1097. capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
  1098. listen_interval = le_to_host16(
  1099. mgmt->u.assoc_req.listen_interval);
  1100. wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
  1101. " capab_info=0x%02x listen_interval=%d",
  1102. MAC2STR(mgmt->sa), capab_info, listen_interval);
  1103. left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
  1104. pos = mgmt->u.assoc_req.variable;
  1105. }
  1106. sta = ap_get_sta(hapd, mgmt->sa);
  1107. #ifdef CONFIG_IEEE80211R
  1108. if (sta && sta->auth_alg == WLAN_AUTH_FT &&
  1109. (sta->flags & WLAN_STA_AUTH) == 0) {
  1110. wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
  1111. "prior to authentication since it is using "
  1112. "over-the-DS FT", MAC2STR(mgmt->sa));
  1113. } else
  1114. #endif /* CONFIG_IEEE80211R */
  1115. if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
  1116. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1117. HOSTAPD_LEVEL_INFO, "Station tried to "
  1118. "associate before authentication "
  1119. "(aid=%d flags=0x%x)",
  1120. sta ? sta->aid : -1,
  1121. sta ? sta->flags : 0);
  1122. send_deauth(hapd, mgmt->sa,
  1123. WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
  1124. return;
  1125. }
  1126. if (hapd->tkip_countermeasures) {
  1127. resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
  1128. goto fail;
  1129. }
  1130. if (listen_interval > hapd->conf->max_listen_interval) {
  1131. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1132. HOSTAPD_LEVEL_DEBUG,
  1133. "Too large Listen Interval (%d)",
  1134. listen_interval);
  1135. resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
  1136. goto fail;
  1137. }
  1138. /* followed by SSID and Supported rates; and HT capabilities if 802.11n
  1139. * is used */
  1140. resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
  1141. if (resp != WLAN_STATUS_SUCCESS)
  1142. goto fail;
  1143. if (hostapd_get_aid(hapd, sta) < 0) {
  1144. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1145. HOSTAPD_LEVEL_INFO, "No room for more AIDs");
  1146. resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
  1147. goto fail;
  1148. }
  1149. sta->capability = capab_info;
  1150. sta->listen_interval = listen_interval;
  1151. if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
  1152. sta->flags |= WLAN_STA_NONERP;
  1153. for (i = 0; i < sta->supported_rates_len; i++) {
  1154. if ((sta->supported_rates[i] & 0x7f) > 22) {
  1155. sta->flags &= ~WLAN_STA_NONERP;
  1156. break;
  1157. }
  1158. }
  1159. if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
  1160. sta->nonerp_set = 1;
  1161. hapd->iface->num_sta_non_erp++;
  1162. if (hapd->iface->num_sta_non_erp == 1)
  1163. ieee802_11_set_beacons(hapd->iface);
  1164. }
  1165. if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
  1166. !sta->no_short_slot_time_set) {
  1167. sta->no_short_slot_time_set = 1;
  1168. hapd->iface->num_sta_no_short_slot_time++;
  1169. if (hapd->iface->current_mode->mode ==
  1170. HOSTAPD_MODE_IEEE80211G &&
  1171. hapd->iface->num_sta_no_short_slot_time == 1)
  1172. ieee802_11_set_beacons(hapd->iface);
  1173. }
  1174. if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  1175. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  1176. else
  1177. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  1178. if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
  1179. !sta->no_short_preamble_set) {
  1180. sta->no_short_preamble_set = 1;
  1181. hapd->iface->num_sta_no_short_preamble++;
  1182. if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
  1183. && hapd->iface->num_sta_no_short_preamble == 1)
  1184. ieee802_11_set_beacons(hapd->iface);
  1185. }
  1186. #ifdef CONFIG_IEEE80211N
  1187. update_ht_state(hapd, sta);
  1188. #endif /* CONFIG_IEEE80211N */
  1189. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1190. HOSTAPD_LEVEL_DEBUG,
  1191. "association OK (aid %d)", sta->aid);
  1192. /* Station will be marked associated, after it acknowledges AssocResp
  1193. */
  1194. sta->flags |= WLAN_STA_ASSOC_REQ_OK;
  1195. #ifdef CONFIG_IEEE80211W
  1196. if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
  1197. wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
  1198. "SA Query procedure", reassoc ? "re" : "");
  1199. /* TODO: Send a protected Disassociate frame to the STA using
  1200. * the old key and Reason Code "Previous Authentication no
  1201. * longer valid". Make sure this is only sent protected since
  1202. * unprotected frame would be received by the STA that is now
  1203. * trying to associate.
  1204. */
  1205. }
  1206. #endif /* CONFIG_IEEE80211W */
  1207. if (reassoc) {
  1208. os_memcpy(sta->previous_ap, mgmt->u.reassoc_req.current_ap,
  1209. ETH_ALEN);
  1210. }
  1211. if (sta->last_assoc_req)
  1212. os_free(sta->last_assoc_req);
  1213. sta->last_assoc_req = os_malloc(len);
  1214. if (sta->last_assoc_req)
  1215. os_memcpy(sta->last_assoc_req, mgmt, len);
  1216. /* Make sure that the previously registered inactivity timer will not
  1217. * remove the STA immediately. */
  1218. sta->timeout_next = STA_NULLFUNC;
  1219. fail:
  1220. send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
  1221. }
  1222. static void handle_disassoc(struct hostapd_data *hapd,
  1223. const struct ieee80211_mgmt *mgmt, size_t len)
  1224. {
  1225. struct sta_info *sta;
  1226. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
  1227. printf("handle_disassoc - too short payload (len=%lu)\n",
  1228. (unsigned long) len);
  1229. return;
  1230. }
  1231. wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
  1232. MAC2STR(mgmt->sa),
  1233. le_to_host16(mgmt->u.disassoc.reason_code));
  1234. sta = ap_get_sta(hapd, mgmt->sa);
  1235. if (sta == NULL) {
  1236. printf("Station " MACSTR " trying to disassociate, but it "
  1237. "is not associated.\n", MAC2STR(mgmt->sa));
  1238. return;
  1239. }
  1240. ap_sta_set_authorized(hapd, sta, 0);
  1241. sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
  1242. wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
  1243. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1244. HOSTAPD_LEVEL_INFO, "disassociated");
  1245. sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
  1246. ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
  1247. /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
  1248. * authenticated. */
  1249. accounting_sta_stop(hapd, sta);
  1250. ieee802_1x_free_station(sta);
  1251. hostapd_drv_sta_remove(hapd, sta->addr);
  1252. if (sta->timeout_next == STA_NULLFUNC ||
  1253. sta->timeout_next == STA_DISASSOC) {
  1254. sta->timeout_next = STA_DEAUTH;
  1255. eloop_cancel_timeout(ap_handle_timer, hapd, sta);
  1256. eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
  1257. hapd, sta);
  1258. }
  1259. mlme_disassociate_indication(
  1260. hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
  1261. }
  1262. static void handle_deauth(struct hostapd_data *hapd,
  1263. const struct ieee80211_mgmt *mgmt, size_t len)
  1264. {
  1265. struct sta_info *sta;
  1266. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
  1267. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
  1268. "payload (len=%lu)", (unsigned long) len);
  1269. return;
  1270. }
  1271. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
  1272. " reason_code=%d",
  1273. MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
  1274. sta = ap_get_sta(hapd, mgmt->sa);
  1275. if (sta == NULL) {
  1276. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
  1277. "to deauthenticate, but it is not authenticated",
  1278. MAC2STR(mgmt->sa));
  1279. return;
  1280. }
  1281. ap_sta_set_authorized(hapd, sta, 0);
  1282. sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
  1283. WLAN_STA_ASSOC_REQ_OK);
  1284. wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
  1285. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1286. HOSTAPD_LEVEL_DEBUG, "deauthenticated");
  1287. mlme_deauthenticate_indication(
  1288. hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
  1289. sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
  1290. ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
  1291. ap_free_sta(hapd, sta);
  1292. }
  1293. static void handle_beacon(struct hostapd_data *hapd,
  1294. const struct ieee80211_mgmt *mgmt, size_t len,
  1295. struct hostapd_frame_info *fi)
  1296. {
  1297. struct ieee802_11_elems elems;
  1298. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
  1299. printf("handle_beacon - too short payload (len=%lu)\n",
  1300. (unsigned long) len);
  1301. return;
  1302. }
  1303. (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
  1304. len - (IEEE80211_HDRLEN +
  1305. sizeof(mgmt->u.beacon)), &elems,
  1306. 0);
  1307. ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
  1308. }
  1309. #ifdef CONFIG_IEEE80211W
  1310. static void hostapd_sa_query_action(struct hostapd_data *hapd,
  1311. const struct ieee80211_mgmt *mgmt,
  1312. size_t len)
  1313. {
  1314. const u8 *end;
  1315. end = mgmt->u.action.u.sa_query_resp.trans_id +
  1316. WLAN_SA_QUERY_TR_ID_LEN;
  1317. if (((u8 *) mgmt) + len < end) {
  1318. wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
  1319. "frame (len=%lu)", (unsigned long) len);
  1320. return;
  1321. }
  1322. ieee802_11_sa_query_action(hapd, mgmt->sa,
  1323. mgmt->u.action.u.sa_query_resp.action,
  1324. mgmt->u.action.u.sa_query_resp.trans_id);
  1325. }
  1326. static int robust_action_frame(u8 category)
  1327. {
  1328. return category != WLAN_ACTION_PUBLIC &&
  1329. category != WLAN_ACTION_HT;
  1330. }
  1331. #endif /* CONFIG_IEEE80211W */
  1332. #ifdef CONFIG_WNM
  1333. static void hostapd_wnm_action(struct hostapd_data *hapd, struct sta_info *sta,
  1334. const struct ieee80211_mgmt *mgmt,
  1335. size_t len)
  1336. {
  1337. struct rx_action action;
  1338. if (len < IEEE80211_HDRLEN + 2)
  1339. return;
  1340. os_memset(&action, 0, sizeof(action));
  1341. action.da = mgmt->da;
  1342. action.sa = mgmt->sa;
  1343. action.bssid = mgmt->bssid;
  1344. action.category = mgmt->u.action.category;
  1345. action.data = (const u8 *) &mgmt->u.action.u.wnm_sleep_req.action;
  1346. action.len = len - IEEE80211_HDRLEN - 1;
  1347. action.freq = hapd->iface->freq;
  1348. ieee802_11_rx_wnm_action_ap(hapd, &action);
  1349. }
  1350. #endif /* CONFIG_WNM */
  1351. static void handle_action(struct hostapd_data *hapd,
  1352. const struct ieee80211_mgmt *mgmt, size_t len)
  1353. {
  1354. struct sta_info *sta;
  1355. sta = ap_get_sta(hapd, mgmt->sa);
  1356. if (len < IEEE80211_HDRLEN + 1) {
  1357. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1358. HOSTAPD_LEVEL_DEBUG,
  1359. "handle_action - too short payload (len=%lu)",
  1360. (unsigned long) len);
  1361. return;
  1362. }
  1363. if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
  1364. (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
  1365. wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
  1366. "frame (category=%u) from unassociated STA " MACSTR,
  1367. MAC2STR(mgmt->sa), mgmt->u.action.category);
  1368. return;
  1369. }
  1370. #ifdef CONFIG_IEEE80211W
  1371. if (sta && (sta->flags & WLAN_STA_MFP) &&
  1372. !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP) &&
  1373. robust_action_frame(mgmt->u.action.category))) {
  1374. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1375. HOSTAPD_LEVEL_DEBUG,
  1376. "Dropped unprotected Robust Action frame from "
  1377. "an MFP STA");
  1378. return;
  1379. }
  1380. #endif /* CONFIG_IEEE80211W */
  1381. switch (mgmt->u.action.category) {
  1382. #ifdef CONFIG_IEEE80211R
  1383. case WLAN_ACTION_FT:
  1384. if (wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
  1385. len - IEEE80211_HDRLEN))
  1386. break;
  1387. return;
  1388. #endif /* CONFIG_IEEE80211R */
  1389. case WLAN_ACTION_WMM:
  1390. hostapd_wmm_action(hapd, mgmt, len);
  1391. return;
  1392. #ifdef CONFIG_IEEE80211W
  1393. case WLAN_ACTION_SA_QUERY:
  1394. hostapd_sa_query_action(hapd, mgmt, len);
  1395. return;
  1396. #endif /* CONFIG_IEEE80211W */
  1397. #ifdef CONFIG_WNM
  1398. case WLAN_ACTION_WNM:
  1399. hostapd_wnm_action(hapd, sta, mgmt, len);
  1400. return;
  1401. #endif /* CONFIG_WNM */
  1402. case WLAN_ACTION_PUBLIC:
  1403. if (hapd->public_action_cb) {
  1404. hapd->public_action_cb(hapd->public_action_cb_ctx,
  1405. (u8 *) mgmt, len,
  1406. hapd->iface->freq);
  1407. }
  1408. if (hapd->public_action_cb2) {
  1409. hapd->public_action_cb2(hapd->public_action_cb2_ctx,
  1410. (u8 *) mgmt, len,
  1411. hapd->iface->freq);
  1412. }
  1413. if (hapd->public_action_cb || hapd->public_action_cb2)
  1414. return;
  1415. break;
  1416. case WLAN_ACTION_VENDOR_SPECIFIC:
  1417. if (hapd->vendor_action_cb) {
  1418. if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
  1419. (u8 *) mgmt, len,
  1420. hapd->iface->freq) == 0)
  1421. return;
  1422. }
  1423. break;
  1424. }
  1425. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1426. HOSTAPD_LEVEL_DEBUG,
  1427. "handle_action - unknown action category %d or invalid "
  1428. "frame",
  1429. mgmt->u.action.category);
  1430. if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
  1431. !(mgmt->sa[0] & 0x01)) {
  1432. struct ieee80211_mgmt *resp;
  1433. /*
  1434. * IEEE 802.11-REVma/D9.0 - 7.3.1.11
  1435. * Return the Action frame to the source without change
  1436. * except that MSB of the Category set to 1.
  1437. */
  1438. wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
  1439. "frame back to sender");
  1440. resp = os_malloc(len);
  1441. if (resp == NULL)
  1442. return;
  1443. os_memcpy(resp, mgmt, len);
  1444. os_memcpy(resp->da, resp->sa, ETH_ALEN);
  1445. os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
  1446. os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
  1447. resp->u.action.category |= 0x80;
  1448. if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
  1449. wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
  1450. "Action frame");
  1451. }
  1452. os_free(resp);
  1453. }
  1454. }
  1455. /**
  1456. * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
  1457. * @hapd: hostapd BSS data structure (the BSS to which the management frame was
  1458. * sent to)
  1459. * @buf: management frame data (starting from IEEE 802.11 header)
  1460. * @len: length of frame data in octets
  1461. * @fi: meta data about received frame (signal level, etc.)
  1462. *
  1463. * Process all incoming IEEE 802.11 management frames. This will be called for
  1464. * each frame received from the kernel driver through wlan#ap interface. In
  1465. * addition, it can be called to re-inserted pending frames (e.g., when using
  1466. * external RADIUS server as an MAC ACL).
  1467. */
  1468. void ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
  1469. struct hostapd_frame_info *fi)
  1470. {
  1471. struct ieee80211_mgmt *mgmt;
  1472. int broadcast;
  1473. u16 fc, stype;
  1474. if (len < 24)
  1475. return;
  1476. mgmt = (struct ieee80211_mgmt *) buf;
  1477. fc = le_to_host16(mgmt->frame_control);
  1478. stype = WLAN_FC_GET_STYPE(fc);
  1479. if (stype == WLAN_FC_STYPE_BEACON) {
  1480. handle_beacon(hapd, mgmt, len, fi);
  1481. return;
  1482. }
  1483. broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
  1484. mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
  1485. mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
  1486. if (!broadcast &&
  1487. #ifdef CONFIG_P2P
  1488. /* Invitation responses can be sent with the peer MAC as BSSID */
  1489. !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
  1490. stype == WLAN_FC_STYPE_ACTION) &&
  1491. #endif /* CONFIG_P2P */
  1492. os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
  1493. printf("MGMT: BSSID=" MACSTR " not our address\n",
  1494. MAC2STR(mgmt->bssid));
  1495. return;
  1496. }
  1497. if (stype == WLAN_FC_STYPE_PROBE_REQ) {
  1498. handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
  1499. return;
  1500. }
  1501. if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
  1502. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1503. HOSTAPD_LEVEL_DEBUG,
  1504. "MGMT: DA=" MACSTR " not our address",
  1505. MAC2STR(mgmt->da));
  1506. return;
  1507. }
  1508. switch (stype) {
  1509. case WLAN_FC_STYPE_AUTH:
  1510. wpa_printf(MSG_DEBUG, "mgmt::auth");
  1511. handle_auth(hapd, mgmt, len);
  1512. break;
  1513. case WLAN_FC_STYPE_ASSOC_REQ:
  1514. wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
  1515. handle_assoc(hapd, mgmt, len, 0);
  1516. break;
  1517. case WLAN_FC_STYPE_REASSOC_REQ:
  1518. wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
  1519. handle_assoc(hapd, mgmt, len, 1);
  1520. break;
  1521. case WLAN_FC_STYPE_DISASSOC:
  1522. wpa_printf(MSG_DEBUG, "mgmt::disassoc");
  1523. handle_disassoc(hapd, mgmt, len);
  1524. break;
  1525. case WLAN_FC_STYPE_DEAUTH:
  1526. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
  1527. handle_deauth(hapd, mgmt, len);
  1528. break;
  1529. case WLAN_FC_STYPE_ACTION:
  1530. wpa_printf(MSG_DEBUG, "mgmt::action");
  1531. handle_action(hapd, mgmt, len);
  1532. break;
  1533. default:
  1534. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1535. HOSTAPD_LEVEL_DEBUG,
  1536. "unknown mgmt frame subtype %d", stype);
  1537. break;
  1538. }
  1539. }
  1540. static void handle_auth_cb(struct hostapd_data *hapd,
  1541. const struct ieee80211_mgmt *mgmt,
  1542. size_t len, int ok)
  1543. {
  1544. u16 auth_alg, auth_transaction, status_code;
  1545. struct sta_info *sta;
  1546. if (!ok) {
  1547. hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
  1548. HOSTAPD_LEVEL_NOTICE,
  1549. "did not acknowledge authentication response");
  1550. return;
  1551. }
  1552. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
  1553. printf("handle_auth_cb - too short payload (len=%lu)\n",
  1554. (unsigned long) len);
  1555. return;
  1556. }
  1557. auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
  1558. auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
  1559. status_code = le_to_host16(mgmt->u.auth.status_code);
  1560. sta = ap_get_sta(hapd, mgmt->da);
  1561. if (!sta) {
  1562. printf("handle_auth_cb: STA " MACSTR " not found\n",
  1563. MAC2STR(mgmt->da));
  1564. return;
  1565. }
  1566. if (status_code == WLAN_STATUS_SUCCESS &&
  1567. ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
  1568. (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
  1569. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1570. HOSTAPD_LEVEL_INFO, "authenticated");
  1571. sta->flags |= WLAN_STA_AUTH;
  1572. }
  1573. }
  1574. static void handle_assoc_cb(struct hostapd_data *hapd,
  1575. const struct ieee80211_mgmt *mgmt,
  1576. size_t len, int reassoc, int ok)
  1577. {
  1578. u16 status;
  1579. struct sta_info *sta;
  1580. int new_assoc = 1;
  1581. struct ieee80211_ht_capabilities ht_cap;
  1582. struct ieee80211_vht_capabilities vht_cap;
  1583. if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
  1584. sizeof(mgmt->u.assoc_resp))) {
  1585. printf("handle_assoc_cb(reassoc=%d) - too short payload "
  1586. "(len=%lu)\n", reassoc, (unsigned long) len);
  1587. return;
  1588. }
  1589. sta = ap_get_sta(hapd, mgmt->da);
  1590. if (!sta) {
  1591. printf("handle_assoc_cb: STA " MACSTR " not found\n",
  1592. MAC2STR(mgmt->da));
  1593. return;
  1594. }
  1595. if (!ok) {
  1596. hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
  1597. HOSTAPD_LEVEL_DEBUG,
  1598. "did not acknowledge association response");
  1599. sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
  1600. return;
  1601. }
  1602. if (reassoc)
  1603. status = le_to_host16(mgmt->u.reassoc_resp.status_code);
  1604. else
  1605. status = le_to_host16(mgmt->u.assoc_resp.status_code);
  1606. if (status != WLAN_STATUS_SUCCESS)
  1607. goto fail;
  1608. /* Stop previous accounting session, if one is started, and allocate
  1609. * new session id for the new session. */
  1610. accounting_sta_stop(hapd, sta);
  1611. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1612. HOSTAPD_LEVEL_INFO,
  1613. "associated (aid %d)",
  1614. sta->aid);
  1615. if (sta->flags & WLAN_STA_ASSOC)
  1616. new_assoc = 0;
  1617. sta->flags |= WLAN_STA_ASSOC;
  1618. if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
  1619. sta->auth_alg == WLAN_AUTH_FT) {
  1620. /*
  1621. * Open, static WEP, or FT protocol; no separate authorization
  1622. * step.
  1623. */
  1624. ap_sta_set_authorized(hapd, sta, 1);
  1625. }
  1626. if (reassoc)
  1627. mlme_reassociate_indication(hapd, sta);
  1628. else
  1629. mlme_associate_indication(hapd, sta);
  1630. #ifdef CONFIG_IEEE80211W
  1631. sta->sa_query_timed_out = 0;
  1632. #endif /* CONFIG_IEEE80211W */
  1633. /*
  1634. * Remove the STA entry in order to make sure the STA PS state gets
  1635. * cleared and configuration gets updated in case of reassociation back
  1636. * to the same AP.
  1637. */
  1638. hostapd_drv_sta_remove(hapd, sta->addr);
  1639. #ifdef CONFIG_IEEE80211N
  1640. if (sta->flags & WLAN_STA_HT)
  1641. hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
  1642. #endif /* CONFIG_IEEE80211N */
  1643. #ifdef CONFIG_IEEE80211AC
  1644. if (sta->flags & WLAN_STA_VHT)
  1645. hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
  1646. #endif /* CONFIG_IEEE80211AC */
  1647. if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
  1648. sta->supported_rates, sta->supported_rates_len,
  1649. sta->listen_interval,
  1650. sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
  1651. sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
  1652. sta->flags, sta->qosinfo)) {
  1653. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1654. HOSTAPD_LEVEL_NOTICE,
  1655. "Could not add STA to kernel driver");
  1656. ap_sta_disconnect(hapd, sta, sta->addr,
  1657. WLAN_REASON_DISASSOC_AP_BUSY);
  1658. goto fail;
  1659. }
  1660. if (sta->flags & WLAN_STA_WDS)
  1661. hostapd_set_wds_sta(hapd, sta->addr, sta->aid, 1);
  1662. if (sta->eapol_sm == NULL) {
  1663. /*
  1664. * This STA does not use RADIUS server for EAP authentication,
  1665. * so bind it to the selected VLAN interface now, since the
  1666. * interface selection is not going to change anymore.
  1667. */
  1668. if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
  1669. goto fail;
  1670. } else if (sta->vlan_id) {
  1671. /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
  1672. if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
  1673. goto fail;
  1674. }
  1675. hostapd_set_sta_flags(hapd, sta);
  1676. if (sta->auth_alg == WLAN_AUTH_FT)
  1677. wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
  1678. else
  1679. wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
  1680. hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
  1681. ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
  1682. fail:
  1683. /* Copy of the association request is not needed anymore */
  1684. if (sta->last_assoc_req) {
  1685. os_free(sta->last_assoc_req);
  1686. sta->last_assoc_req = NULL;
  1687. }
  1688. }
  1689. static void handle_deauth_cb(struct hostapd_data *hapd,
  1690. const struct ieee80211_mgmt *mgmt,
  1691. size_t len, int ok)
  1692. {
  1693. struct sta_info *sta;
  1694. if (mgmt->da[0] & 0x01)
  1695. return;
  1696. sta = ap_get_sta(hapd, mgmt->da);
  1697. if (!sta) {
  1698. wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
  1699. " not found", MAC2STR(mgmt->da));
  1700. return;
  1701. }
  1702. if (ok)
  1703. wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
  1704. MAC2STR(sta->addr));
  1705. else
  1706. wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
  1707. "deauth", MAC2STR(sta->addr));
  1708. ap_sta_deauth_cb(hapd, sta);
  1709. }
  1710. static void handle_disassoc_cb(struct hostapd_data *hapd,
  1711. const struct ieee80211_mgmt *mgmt,
  1712. size_t len, int ok)
  1713. {
  1714. struct sta_info *sta;
  1715. if (mgmt->da[0] & 0x01)
  1716. return;
  1717. sta = ap_get_sta(hapd, mgmt->da);
  1718. if (!sta) {
  1719. wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
  1720. " not found", MAC2STR(mgmt->da));
  1721. return;
  1722. }
  1723. if (ok)
  1724. wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
  1725. MAC2STR(sta->addr));
  1726. else
  1727. wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
  1728. "disassoc", MAC2STR(sta->addr));
  1729. ap_sta_disassoc_cb(hapd, sta);
  1730. }
  1731. /**
  1732. * ieee802_11_mgmt_cb - Process management frame TX status callback
  1733. * @hapd: hostapd BSS data structure (the BSS from which the management frame
  1734. * was sent from)
  1735. * @buf: management frame data (starting from IEEE 802.11 header)
  1736. * @len: length of frame data in octets
  1737. * @stype: management frame subtype from frame control field
  1738. * @ok: Whether the frame was ACK'ed
  1739. */
  1740. void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
  1741. u16 stype, int ok)
  1742. {
  1743. const struct ieee80211_mgmt *mgmt;
  1744. mgmt = (const struct ieee80211_mgmt *) buf;
  1745. switch (stype) {
  1746. case WLAN_FC_STYPE_AUTH:
  1747. wpa_printf(MSG_DEBUG, "mgmt::auth cb");
  1748. handle_auth_cb(hapd, mgmt, len, ok);
  1749. break;
  1750. case WLAN_FC_STYPE_ASSOC_RESP:
  1751. wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
  1752. handle_assoc_cb(hapd, mgmt, len, 0, ok);
  1753. break;
  1754. case WLAN_FC_STYPE_REASSOC_RESP:
  1755. wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
  1756. handle_assoc_cb(hapd, mgmt, len, 1, ok);
  1757. break;
  1758. case WLAN_FC_STYPE_PROBE_RESP:
  1759. wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
  1760. break;
  1761. case WLAN_FC_STYPE_DEAUTH:
  1762. wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
  1763. handle_deauth_cb(hapd, mgmt, len, ok);
  1764. break;
  1765. case WLAN_FC_STYPE_DISASSOC:
  1766. wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
  1767. handle_disassoc_cb(hapd, mgmt, len, ok);
  1768. break;
  1769. case WLAN_FC_STYPE_ACTION:
  1770. wpa_printf(MSG_DEBUG, "mgmt::action cb");
  1771. break;
  1772. default:
  1773. printf("unknown mgmt cb frame subtype %d\n", stype);
  1774. break;
  1775. }
  1776. }
  1777. int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
  1778. {
  1779. /* TODO */
  1780. return 0;
  1781. }
  1782. int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
  1783. char *buf, size_t buflen)
  1784. {
  1785. /* TODO */
  1786. return 0;
  1787. }
  1788. void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
  1789. const u8 *buf, size_t len, int ack)
  1790. {
  1791. struct sta_info *sta;
  1792. struct hostapd_iface *iface = hapd->iface;
  1793. sta = ap_get_sta(hapd, addr);
  1794. if (sta == NULL && iface->num_bss > 1) {
  1795. size_t j;
  1796. for (j = 0; j < iface->num_bss; j++) {
  1797. hapd = iface->bss[j];
  1798. sta = ap_get_sta(hapd, addr);
  1799. if (sta)
  1800. break;
  1801. }
  1802. }
  1803. if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
  1804. return;
  1805. if (sta->flags & WLAN_STA_PENDING_POLL) {
  1806. wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
  1807. "activity poll", MAC2STR(sta->addr),
  1808. ack ? "ACKed" : "did not ACK");
  1809. if (ack)
  1810. sta->flags &= ~WLAN_STA_PENDING_POLL;
  1811. }
  1812. ieee802_1x_tx_status(hapd, sta, buf, len, ack);
  1813. }
  1814. void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
  1815. const u8 *data, size_t len, int ack)
  1816. {
  1817. struct sta_info *sta;
  1818. struct hostapd_iface *iface = hapd->iface;
  1819. sta = ap_get_sta(hapd, dst);
  1820. if (sta == NULL && iface->num_bss > 1) {
  1821. size_t j;
  1822. for (j = 0; j < iface->num_bss; j++) {
  1823. hapd = iface->bss[j];
  1824. sta = ap_get_sta(hapd, dst);
  1825. if (sta)
  1826. break;
  1827. }
  1828. }
  1829. if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
  1830. wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
  1831. MACSTR " that is not currently associated",
  1832. MAC2STR(dst));
  1833. return;
  1834. }
  1835. ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
  1836. }
  1837. void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
  1838. {
  1839. struct sta_info *sta;
  1840. struct hostapd_iface *iface = hapd->iface;
  1841. sta = ap_get_sta(hapd, addr);
  1842. if (sta == NULL && iface->num_bss > 1) {
  1843. size_t j;
  1844. for (j = 0; j < iface->num_bss; j++) {
  1845. hapd = iface->bss[j];
  1846. sta = ap_get_sta(hapd, addr);
  1847. if (sta)
  1848. break;
  1849. }
  1850. }
  1851. if (sta == NULL)
  1852. return;
  1853. if (!(sta->flags & WLAN_STA_PENDING_POLL))
  1854. return;
  1855. wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
  1856. "activity poll", MAC2STR(sta->addr));
  1857. sta->flags &= ~WLAN_STA_PENDING_POLL;
  1858. }
  1859. void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
  1860. int wds)
  1861. {
  1862. struct sta_info *sta;
  1863. sta = ap_get_sta(hapd, src);
  1864. if (sta && (sta->flags & WLAN_STA_ASSOC)) {
  1865. if (!hapd->conf->wds_sta)
  1866. return;
  1867. if (wds && !(sta->flags & WLAN_STA_WDS)) {
  1868. wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
  1869. "STA " MACSTR " (aid %u)",
  1870. MAC2STR(sta->addr), sta->aid);
  1871. sta->flags |= WLAN_STA_WDS;
  1872. hostapd_set_wds_sta(hapd, sta->addr, sta->aid, 1);
  1873. }
  1874. return;
  1875. }
  1876. wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
  1877. MACSTR, MAC2STR(src));
  1878. if (src[0] & 0x01) {
  1879. /* Broadcast bit set in SA?! Ignore the frame silently. */
  1880. return;
  1881. }
  1882. if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
  1883. wpa_printf(MSG_DEBUG, "Association Response to the STA has "
  1884. "already been sent, but no TX status yet known - "
  1885. "ignore Class 3 frame issue with " MACSTR,
  1886. MAC2STR(src));
  1887. return;
  1888. }
  1889. if (sta && (sta->flags & WLAN_STA_AUTH))
  1890. hostapd_drv_sta_disassoc(
  1891. hapd, src,
  1892. WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
  1893. else
  1894. hostapd_drv_sta_deauth(
  1895. hapd, src,
  1896. WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
  1897. }
  1898. #endif /* CONFIG_NATIVE_WINDOWS */