ieee802_11.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263
  1. /*
  2. * hostapd / IEEE 802.11 Management
  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. #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. wpa_printf(MSG_INFO, "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. wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
  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. wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
  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. wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
  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. wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
  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. wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
  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_vlan_id_valid(hapd->conf->vlan, vlan_id)) {
  550. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
  551. HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
  552. "%d received from RADIUS server",
  553. vlan_id);
  554. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  555. goto fail;
  556. }
  557. sta->vlan_id = vlan_id;
  558. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
  559. HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
  560. }
  561. hostapd_free_psk_list(sta->psk);
  562. if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
  563. sta->psk = psk;
  564. psk = NULL;
  565. } else {
  566. sta->psk = NULL;
  567. }
  568. sta->identity = identity;
  569. identity = NULL;
  570. sta->radius_cui = radius_cui;
  571. radius_cui = NULL;
  572. sta->flags &= ~WLAN_STA_PREAUTH;
  573. ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
  574. if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
  575. sta->acct_interim_interval = acct_interim_interval;
  576. if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
  577. ap_sta_session_timeout(hapd, sta, session_timeout);
  578. else
  579. ap_sta_no_session_timeout(hapd, sta);
  580. switch (auth_alg) {
  581. case WLAN_AUTH_OPEN:
  582. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  583. HOSTAPD_LEVEL_DEBUG,
  584. "authentication OK (open system)");
  585. #ifdef IEEE80211_REQUIRE_AUTH_ACK
  586. /* Station will be marked authenticated if it ACKs the
  587. * authentication reply. */
  588. #else
  589. sta->flags |= WLAN_STA_AUTH;
  590. wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
  591. sta->auth_alg = WLAN_AUTH_OPEN;
  592. mlme_authenticate_indication(hapd, sta);
  593. #endif
  594. break;
  595. case WLAN_AUTH_SHARED_KEY:
  596. resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
  597. fc & WLAN_FC_ISWEP);
  598. sta->auth_alg = WLAN_AUTH_SHARED_KEY;
  599. mlme_authenticate_indication(hapd, sta);
  600. if (sta->challenge && auth_transaction == 1) {
  601. resp_ies[0] = WLAN_EID_CHALLENGE;
  602. resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
  603. os_memcpy(resp_ies + 2, sta->challenge,
  604. WLAN_AUTH_CHALLENGE_LEN);
  605. resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
  606. }
  607. break;
  608. #ifdef CONFIG_IEEE80211R
  609. case WLAN_AUTH_FT:
  610. sta->auth_alg = WLAN_AUTH_FT;
  611. if (sta->wpa_sm == NULL)
  612. sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
  613. sta->addr, NULL);
  614. if (sta->wpa_sm == NULL) {
  615. wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
  616. "state machine");
  617. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  618. goto fail;
  619. }
  620. wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
  621. auth_transaction, mgmt->u.auth.variable,
  622. len - IEEE80211_HDRLEN -
  623. sizeof(mgmt->u.auth),
  624. handle_auth_ft_finish, hapd);
  625. /* handle_auth_ft_finish() callback will complete auth. */
  626. return;
  627. #endif /* CONFIG_IEEE80211R */
  628. #ifdef CONFIG_SAE
  629. case WLAN_AUTH_SAE:
  630. handle_auth_sae(hapd, sta, mgmt, len, auth_transaction);
  631. return;
  632. #endif /* CONFIG_SAE */
  633. }
  634. fail:
  635. os_free(identity);
  636. os_free(radius_cui);
  637. hostapd_free_psk_list(psk);
  638. send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
  639. auth_transaction + 1, resp, resp_ies, resp_ies_len);
  640. }
  641. static int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
  642. {
  643. int i, j = 32, aid;
  644. /* get a unique AID */
  645. if (sta->aid > 0) {
  646. wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
  647. return 0;
  648. }
  649. for (i = 0; i < AID_WORDS; i++) {
  650. if (hapd->sta_aid[i] == (u32) -1)
  651. continue;
  652. for (j = 0; j < 32; j++) {
  653. if (!(hapd->sta_aid[i] & BIT(j)))
  654. break;
  655. }
  656. if (j < 32)
  657. break;
  658. }
  659. if (j == 32)
  660. return -1;
  661. aid = i * 32 + j + 1;
  662. if (aid > 2007)
  663. return -1;
  664. sta->aid = aid;
  665. hapd->sta_aid[i] |= BIT(j);
  666. wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
  667. return 0;
  668. }
  669. static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
  670. const u8 *ssid_ie, size_t ssid_ie_len)
  671. {
  672. if (ssid_ie == NULL)
  673. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  674. if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
  675. os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
  676. char ssid_txt[33];
  677. ieee802_11_print_ssid(ssid_txt, ssid_ie, ssid_ie_len);
  678. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  679. HOSTAPD_LEVEL_INFO,
  680. "Station tried to associate with unknown SSID "
  681. "'%s'", ssid_txt);
  682. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  683. }
  684. return WLAN_STATUS_SUCCESS;
  685. }
  686. static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
  687. const u8 *wmm_ie, size_t wmm_ie_len)
  688. {
  689. sta->flags &= ~WLAN_STA_WMM;
  690. sta->qosinfo = 0;
  691. if (wmm_ie && hapd->conf->wmm_enabled) {
  692. struct wmm_information_element *wmm;
  693. if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
  694. hostapd_logger(hapd, sta->addr,
  695. HOSTAPD_MODULE_WPA,
  696. HOSTAPD_LEVEL_DEBUG,
  697. "invalid WMM element in association "
  698. "request");
  699. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  700. }
  701. sta->flags |= WLAN_STA_WMM;
  702. wmm = (struct wmm_information_element *) wmm_ie;
  703. sta->qosinfo = wmm->qos_info;
  704. }
  705. return WLAN_STATUS_SUCCESS;
  706. }
  707. static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
  708. struct ieee802_11_elems *elems)
  709. {
  710. if (!elems->supp_rates) {
  711. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  712. HOSTAPD_LEVEL_DEBUG,
  713. "No supported rates element in AssocReq");
  714. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  715. }
  716. if (elems->supp_rates_len + elems->ext_supp_rates_len >
  717. sizeof(sta->supported_rates)) {
  718. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  719. HOSTAPD_LEVEL_DEBUG,
  720. "Invalid supported rates element length %d+%d",
  721. elems->supp_rates_len,
  722. elems->ext_supp_rates_len);
  723. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  724. }
  725. sta->supported_rates_len = merge_byte_arrays(
  726. sta->supported_rates, sizeof(sta->supported_rates),
  727. elems->supp_rates, elems->supp_rates_len,
  728. elems->ext_supp_rates, elems->ext_supp_rates_len);
  729. return WLAN_STATUS_SUCCESS;
  730. }
  731. static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
  732. const u8 *ext_capab_ie, size_t ext_capab_ie_len)
  733. {
  734. #ifdef CONFIG_INTERWORKING
  735. /* check for QoS Map support */
  736. if (ext_capab_ie_len >= 5) {
  737. if (ext_capab_ie[4] & 0x01)
  738. sta->qos_map_enabled = 1;
  739. }
  740. #endif /* CONFIG_INTERWORKING */
  741. return WLAN_STATUS_SUCCESS;
  742. }
  743. static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
  744. const u8 *ies, size_t ies_len, int reassoc)
  745. {
  746. struct ieee802_11_elems elems;
  747. u16 resp;
  748. const u8 *wpa_ie;
  749. size_t wpa_ie_len;
  750. const u8 *p2p_dev_addr = NULL;
  751. if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
  752. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  753. HOSTAPD_LEVEL_INFO, "Station sent an invalid "
  754. "association request");
  755. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  756. }
  757. resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
  758. if (resp != WLAN_STATUS_SUCCESS)
  759. return resp;
  760. resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
  761. if (resp != WLAN_STATUS_SUCCESS)
  762. return resp;
  763. resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
  764. if (resp != WLAN_STATUS_SUCCESS)
  765. return resp;
  766. resp = copy_supp_rates(hapd, sta, &elems);
  767. if (resp != WLAN_STATUS_SUCCESS)
  768. return resp;
  769. #ifdef CONFIG_IEEE80211N
  770. resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities,
  771. elems.ht_capabilities_len);
  772. if (resp != WLAN_STATUS_SUCCESS)
  773. return resp;
  774. if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
  775. !(sta->flags & WLAN_STA_HT)) {
  776. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  777. HOSTAPD_LEVEL_INFO, "Station does not support "
  778. "mandatory HT PHY - reject association");
  779. return WLAN_STATUS_ASSOC_DENIED_NO_HT;
  780. }
  781. #endif /* CONFIG_IEEE80211N */
  782. #ifdef CONFIG_IEEE80211AC
  783. resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities,
  784. elems.vht_capabilities_len);
  785. if (resp != WLAN_STATUS_SUCCESS)
  786. return resp;
  787. if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
  788. !(sta->flags & WLAN_STA_VHT)) {
  789. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  790. HOSTAPD_LEVEL_INFO, "Station does not support "
  791. "mandatory VHT PHY - reject association");
  792. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  793. }
  794. #endif /* CONFIG_IEEE80211AC */
  795. #ifdef CONFIG_P2P
  796. if (elems.p2p) {
  797. wpabuf_free(sta->p2p_ie);
  798. sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
  799. P2P_IE_VENDOR_TYPE);
  800. if (sta->p2p_ie)
  801. p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
  802. } else {
  803. wpabuf_free(sta->p2p_ie);
  804. sta->p2p_ie = NULL;
  805. }
  806. #endif /* CONFIG_P2P */
  807. if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
  808. wpa_ie = elems.rsn_ie;
  809. wpa_ie_len = elems.rsn_ie_len;
  810. } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
  811. elems.wpa_ie) {
  812. wpa_ie = elems.wpa_ie;
  813. wpa_ie_len = elems.wpa_ie_len;
  814. } else {
  815. wpa_ie = NULL;
  816. wpa_ie_len = 0;
  817. }
  818. #ifdef CONFIG_WPS
  819. sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
  820. if (hapd->conf->wps_state && elems.wps_ie) {
  821. wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
  822. "Request - assume WPS is used");
  823. sta->flags |= WLAN_STA_WPS;
  824. wpabuf_free(sta->wps_ie);
  825. sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
  826. WPS_IE_VENDOR_TYPE);
  827. if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
  828. wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
  829. sta->flags |= WLAN_STA_WPS2;
  830. }
  831. wpa_ie = NULL;
  832. wpa_ie_len = 0;
  833. if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
  834. wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
  835. "(Re)Association Request - reject");
  836. return WLAN_STATUS_INVALID_IE;
  837. }
  838. } else if (hapd->conf->wps_state && wpa_ie == NULL) {
  839. wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
  840. "(Re)Association Request - possible WPS use");
  841. sta->flags |= WLAN_STA_MAYBE_WPS;
  842. } else
  843. #endif /* CONFIG_WPS */
  844. if (hapd->conf->wpa && wpa_ie == NULL) {
  845. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  846. HOSTAPD_LEVEL_INFO,
  847. "No WPA/RSN IE in association request");
  848. return WLAN_STATUS_INVALID_IE;
  849. }
  850. if (hapd->conf->wpa && wpa_ie) {
  851. int res;
  852. wpa_ie -= 2;
  853. wpa_ie_len += 2;
  854. if (sta->wpa_sm == NULL)
  855. sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
  856. sta->addr,
  857. p2p_dev_addr);
  858. if (sta->wpa_sm == NULL) {
  859. wpa_printf(MSG_WARNING, "Failed to initialize WPA "
  860. "state machine");
  861. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  862. }
  863. res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
  864. wpa_ie, wpa_ie_len,
  865. elems.mdie, elems.mdie_len);
  866. if (res == WPA_INVALID_GROUP)
  867. resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
  868. else if (res == WPA_INVALID_PAIRWISE)
  869. resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
  870. else if (res == WPA_INVALID_AKMP)
  871. resp = WLAN_STATUS_AKMP_NOT_VALID;
  872. else if (res == WPA_ALLOC_FAIL)
  873. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  874. #ifdef CONFIG_IEEE80211W
  875. else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
  876. resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
  877. else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
  878. resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
  879. #endif /* CONFIG_IEEE80211W */
  880. else if (res == WPA_INVALID_MDIE)
  881. resp = WLAN_STATUS_INVALID_MDIE;
  882. else if (res != WPA_IE_OK)
  883. resp = WLAN_STATUS_INVALID_IE;
  884. if (resp != WLAN_STATUS_SUCCESS)
  885. return resp;
  886. #ifdef CONFIG_IEEE80211W
  887. if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
  888. sta->sa_query_count > 0)
  889. ap_check_sa_query_timeout(hapd, sta);
  890. if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
  891. (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
  892. /*
  893. * STA has already been associated with MFP and SA
  894. * Query timeout has not been reached. Reject the
  895. * association attempt temporarily and start SA Query,
  896. * if one is not pending.
  897. */
  898. if (sta->sa_query_count == 0)
  899. ap_sta_start_sa_query(hapd, sta);
  900. return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
  901. }
  902. if (wpa_auth_uses_mfp(sta->wpa_sm))
  903. sta->flags |= WLAN_STA_MFP;
  904. else
  905. sta->flags &= ~WLAN_STA_MFP;
  906. #endif /* CONFIG_IEEE80211W */
  907. #ifdef CONFIG_IEEE80211R
  908. if (sta->auth_alg == WLAN_AUTH_FT) {
  909. if (!reassoc) {
  910. wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
  911. "to use association (not "
  912. "re-association) with FT auth_alg",
  913. MAC2STR(sta->addr));
  914. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  915. }
  916. resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
  917. ies_len);
  918. if (resp != WLAN_STATUS_SUCCESS)
  919. return resp;
  920. }
  921. #endif /* CONFIG_IEEE80211R */
  922. #ifdef CONFIG_SAE
  923. if (wpa_auth_uses_sae(sta->wpa_sm) &&
  924. sta->auth_alg != WLAN_AUTH_SAE) {
  925. wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
  926. "SAE AKM after non-SAE auth_alg %u",
  927. MAC2STR(sta->addr), sta->auth_alg);
  928. return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
  929. }
  930. #endif /* CONFIG_SAE */
  931. #ifdef CONFIG_IEEE80211N
  932. if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
  933. wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
  934. hostapd_logger(hapd, sta->addr,
  935. HOSTAPD_MODULE_IEEE80211,
  936. HOSTAPD_LEVEL_INFO,
  937. "Station tried to use TKIP with HT "
  938. "association");
  939. return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
  940. }
  941. #endif /* CONFIG_IEEE80211N */
  942. } else
  943. wpa_auth_sta_no_wpa(sta->wpa_sm);
  944. #ifdef CONFIG_P2P
  945. p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
  946. #endif /* CONFIG_P2P */
  947. #ifdef CONFIG_HS20
  948. wpabuf_free(sta->hs20_ie);
  949. if (elems.hs20 && elems.hs20_len > 4) {
  950. sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
  951. elems.hs20_len - 4);
  952. } else
  953. sta->hs20_ie = NULL;
  954. #endif /* CONFIG_HS20 */
  955. return WLAN_STATUS_SUCCESS;
  956. }
  957. static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
  958. u16 reason_code)
  959. {
  960. int send_len;
  961. struct ieee80211_mgmt reply;
  962. os_memset(&reply, 0, sizeof(reply));
  963. reply.frame_control =
  964. IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
  965. os_memcpy(reply.da, addr, ETH_ALEN);
  966. os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
  967. os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
  968. send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
  969. reply.u.deauth.reason_code = host_to_le16(reason_code);
  970. if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
  971. wpa_printf(MSG_INFO, "Failed to send deauth: %s",
  972. strerror(errno));
  973. }
  974. static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
  975. u16 status_code, int reassoc, const u8 *ies,
  976. size_t ies_len)
  977. {
  978. int send_len;
  979. u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
  980. struct ieee80211_mgmt *reply;
  981. u8 *p;
  982. os_memset(buf, 0, sizeof(buf));
  983. reply = (struct ieee80211_mgmt *) buf;
  984. reply->frame_control =
  985. IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  986. (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
  987. WLAN_FC_STYPE_ASSOC_RESP));
  988. os_memcpy(reply->da, sta->addr, ETH_ALEN);
  989. os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
  990. os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
  991. send_len = IEEE80211_HDRLEN;
  992. send_len += sizeof(reply->u.assoc_resp);
  993. reply->u.assoc_resp.capab_info =
  994. host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
  995. reply->u.assoc_resp.status_code = host_to_le16(status_code);
  996. reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0)
  997. | BIT(14) | BIT(15));
  998. /* Supported rates */
  999. p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
  1000. /* Extended supported rates */
  1001. p = hostapd_eid_ext_supp_rates(hapd, p);
  1002. #ifdef CONFIG_IEEE80211R
  1003. if (status_code == WLAN_STATUS_SUCCESS) {
  1004. /* IEEE 802.11r: Mobility Domain Information, Fast BSS
  1005. * Transition Information, RSN, [RIC Response] */
  1006. p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
  1007. buf + sizeof(buf) - p,
  1008. sta->auth_alg, ies, ies_len);
  1009. }
  1010. #endif /* CONFIG_IEEE80211R */
  1011. #ifdef CONFIG_IEEE80211W
  1012. if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
  1013. p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
  1014. #endif /* CONFIG_IEEE80211W */
  1015. #ifdef CONFIG_IEEE80211N
  1016. p = hostapd_eid_ht_capabilities(hapd, p);
  1017. p = hostapd_eid_ht_operation(hapd, p);
  1018. #endif /* CONFIG_IEEE80211N */
  1019. #ifdef CONFIG_IEEE80211AC
  1020. p = hostapd_eid_vht_capabilities(hapd, p);
  1021. p = hostapd_eid_vht_operation(hapd, p);
  1022. #endif /* CONFIG_IEEE80211AC */
  1023. p = hostapd_eid_ext_capab(hapd, p);
  1024. p = hostapd_eid_bss_max_idle_period(hapd, p);
  1025. if (sta->qos_map_enabled)
  1026. p = hostapd_eid_qos_map_set(hapd, p);
  1027. if (sta->flags & WLAN_STA_WMM)
  1028. p = hostapd_eid_wmm(hapd, p);
  1029. #ifdef CONFIG_WPS
  1030. if ((sta->flags & WLAN_STA_WPS) ||
  1031. ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
  1032. struct wpabuf *wps = wps_build_assoc_resp_ie();
  1033. if (wps) {
  1034. os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
  1035. p += wpabuf_len(wps);
  1036. wpabuf_free(wps);
  1037. }
  1038. }
  1039. #endif /* CONFIG_WPS */
  1040. #ifdef CONFIG_P2P
  1041. if (sta->p2p_ie) {
  1042. struct wpabuf *p2p_resp_ie;
  1043. enum p2p_status_code status;
  1044. switch (status_code) {
  1045. case WLAN_STATUS_SUCCESS:
  1046. status = P2P_SC_SUCCESS;
  1047. break;
  1048. case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
  1049. status = P2P_SC_FAIL_LIMIT_REACHED;
  1050. break;
  1051. default:
  1052. status = P2P_SC_FAIL_INVALID_PARAMS;
  1053. break;
  1054. }
  1055. p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
  1056. if (p2p_resp_ie) {
  1057. os_memcpy(p, wpabuf_head(p2p_resp_ie),
  1058. wpabuf_len(p2p_resp_ie));
  1059. p += wpabuf_len(p2p_resp_ie);
  1060. wpabuf_free(p2p_resp_ie);
  1061. }
  1062. }
  1063. #endif /* CONFIG_P2P */
  1064. #ifdef CONFIG_P2P_MANAGER
  1065. if (hapd->conf->p2p & P2P_MANAGE)
  1066. p = hostapd_eid_p2p_manage(hapd, p);
  1067. #endif /* CONFIG_P2P_MANAGER */
  1068. send_len += p - reply->u.assoc_resp.variable;
  1069. if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0)
  1070. wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
  1071. strerror(errno));
  1072. }
  1073. static void handle_assoc(struct hostapd_data *hapd,
  1074. const struct ieee80211_mgmt *mgmt, size_t len,
  1075. int reassoc)
  1076. {
  1077. u16 capab_info, listen_interval;
  1078. u16 resp = WLAN_STATUS_SUCCESS;
  1079. const u8 *pos;
  1080. int left, i;
  1081. struct sta_info *sta;
  1082. if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
  1083. sizeof(mgmt->u.assoc_req))) {
  1084. wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
  1085. reassoc, (unsigned long) len);
  1086. return;
  1087. }
  1088. #ifdef CONFIG_TESTING_OPTIONS
  1089. if (reassoc) {
  1090. if (hapd->iconf->ignore_reassoc_probability > 0.0d &&
  1091. drand48() < hapd->iconf->ignore_reassoc_probability) {
  1092. wpa_printf(MSG_INFO,
  1093. "TESTING: ignoring reassoc request from "
  1094. MACSTR, MAC2STR(mgmt->sa));
  1095. return;
  1096. }
  1097. } else {
  1098. if (hapd->iconf->ignore_assoc_probability > 0.0d &&
  1099. drand48() < hapd->iconf->ignore_assoc_probability) {
  1100. wpa_printf(MSG_INFO,
  1101. "TESTING: ignoring assoc request from "
  1102. MACSTR, MAC2STR(mgmt->sa));
  1103. return;
  1104. }
  1105. }
  1106. #endif /* CONFIG_TESTING_OPTIONS */
  1107. if (reassoc) {
  1108. capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
  1109. listen_interval = le_to_host16(
  1110. mgmt->u.reassoc_req.listen_interval);
  1111. wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
  1112. " capab_info=0x%02x listen_interval=%d current_ap="
  1113. MACSTR,
  1114. MAC2STR(mgmt->sa), capab_info, listen_interval,
  1115. MAC2STR(mgmt->u.reassoc_req.current_ap));
  1116. left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
  1117. pos = mgmt->u.reassoc_req.variable;
  1118. } else {
  1119. capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
  1120. listen_interval = le_to_host16(
  1121. mgmt->u.assoc_req.listen_interval);
  1122. wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
  1123. " capab_info=0x%02x listen_interval=%d",
  1124. MAC2STR(mgmt->sa), capab_info, listen_interval);
  1125. left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
  1126. pos = mgmt->u.assoc_req.variable;
  1127. }
  1128. sta = ap_get_sta(hapd, mgmt->sa);
  1129. #ifdef CONFIG_IEEE80211R
  1130. if (sta && sta->auth_alg == WLAN_AUTH_FT &&
  1131. (sta->flags & WLAN_STA_AUTH) == 0) {
  1132. wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
  1133. "prior to authentication since it is using "
  1134. "over-the-DS FT", MAC2STR(mgmt->sa));
  1135. } else
  1136. #endif /* CONFIG_IEEE80211R */
  1137. if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
  1138. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1139. HOSTAPD_LEVEL_INFO, "Station tried to "
  1140. "associate before authentication "
  1141. "(aid=%d flags=0x%x)",
  1142. sta ? sta->aid : -1,
  1143. sta ? sta->flags : 0);
  1144. send_deauth(hapd, mgmt->sa,
  1145. WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
  1146. return;
  1147. }
  1148. if (hapd->tkip_countermeasures) {
  1149. resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
  1150. goto fail;
  1151. }
  1152. if (listen_interval > hapd->conf->max_listen_interval) {
  1153. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1154. HOSTAPD_LEVEL_DEBUG,
  1155. "Too large Listen Interval (%d)",
  1156. listen_interval);
  1157. resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
  1158. goto fail;
  1159. }
  1160. /* followed by SSID and Supported rates; and HT capabilities if 802.11n
  1161. * is used */
  1162. resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
  1163. if (resp != WLAN_STATUS_SUCCESS)
  1164. goto fail;
  1165. if (hostapd_get_aid(hapd, sta) < 0) {
  1166. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1167. HOSTAPD_LEVEL_INFO, "No room for more AIDs");
  1168. resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
  1169. goto fail;
  1170. }
  1171. sta->capability = capab_info;
  1172. sta->listen_interval = listen_interval;
  1173. if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
  1174. sta->flags |= WLAN_STA_NONERP;
  1175. for (i = 0; i < sta->supported_rates_len; i++) {
  1176. if ((sta->supported_rates[i] & 0x7f) > 22) {
  1177. sta->flags &= ~WLAN_STA_NONERP;
  1178. break;
  1179. }
  1180. }
  1181. if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
  1182. sta->nonerp_set = 1;
  1183. hapd->iface->num_sta_non_erp++;
  1184. if (hapd->iface->num_sta_non_erp == 1)
  1185. ieee802_11_set_beacons(hapd->iface);
  1186. }
  1187. if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
  1188. !sta->no_short_slot_time_set) {
  1189. sta->no_short_slot_time_set = 1;
  1190. hapd->iface->num_sta_no_short_slot_time++;
  1191. if (hapd->iface->current_mode->mode ==
  1192. HOSTAPD_MODE_IEEE80211G &&
  1193. hapd->iface->num_sta_no_short_slot_time == 1)
  1194. ieee802_11_set_beacons(hapd->iface);
  1195. }
  1196. if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  1197. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  1198. else
  1199. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  1200. if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
  1201. !sta->no_short_preamble_set) {
  1202. sta->no_short_preamble_set = 1;
  1203. hapd->iface->num_sta_no_short_preamble++;
  1204. if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
  1205. && hapd->iface->num_sta_no_short_preamble == 1)
  1206. ieee802_11_set_beacons(hapd->iface);
  1207. }
  1208. #ifdef CONFIG_IEEE80211N
  1209. update_ht_state(hapd, sta);
  1210. #endif /* CONFIG_IEEE80211N */
  1211. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1212. HOSTAPD_LEVEL_DEBUG,
  1213. "association OK (aid %d)", sta->aid);
  1214. /* Station will be marked associated, after it acknowledges AssocResp
  1215. */
  1216. sta->flags |= WLAN_STA_ASSOC_REQ_OK;
  1217. #ifdef CONFIG_IEEE80211W
  1218. if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
  1219. wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
  1220. "SA Query procedure", reassoc ? "re" : "");
  1221. /* TODO: Send a protected Disassociate frame to the STA using
  1222. * the old key and Reason Code "Previous Authentication no
  1223. * longer valid". Make sure this is only sent protected since
  1224. * unprotected frame would be received by the STA that is now
  1225. * trying to associate.
  1226. */
  1227. }
  1228. #endif /* CONFIG_IEEE80211W */
  1229. if (reassoc) {
  1230. os_memcpy(sta->previous_ap, mgmt->u.reassoc_req.current_ap,
  1231. ETH_ALEN);
  1232. }
  1233. if (sta->last_assoc_req)
  1234. os_free(sta->last_assoc_req);
  1235. sta->last_assoc_req = os_malloc(len);
  1236. if (sta->last_assoc_req)
  1237. os_memcpy(sta->last_assoc_req, mgmt, len);
  1238. /* Make sure that the previously registered inactivity timer will not
  1239. * remove the STA immediately. */
  1240. sta->timeout_next = STA_NULLFUNC;
  1241. fail:
  1242. send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
  1243. }
  1244. static void handle_disassoc(struct hostapd_data *hapd,
  1245. const struct ieee80211_mgmt *mgmt, size_t len)
  1246. {
  1247. struct sta_info *sta;
  1248. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
  1249. wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
  1250. (unsigned long) len);
  1251. return;
  1252. }
  1253. wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
  1254. MAC2STR(mgmt->sa),
  1255. le_to_host16(mgmt->u.disassoc.reason_code));
  1256. sta = ap_get_sta(hapd, mgmt->sa);
  1257. if (sta == NULL) {
  1258. wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
  1259. MAC2STR(mgmt->sa));
  1260. return;
  1261. }
  1262. ap_sta_set_authorized(hapd, sta, 0);
  1263. sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
  1264. wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
  1265. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1266. HOSTAPD_LEVEL_INFO, "disassociated");
  1267. sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
  1268. ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
  1269. /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
  1270. * authenticated. */
  1271. accounting_sta_stop(hapd, sta);
  1272. ieee802_1x_free_station(sta);
  1273. hostapd_drv_sta_remove(hapd, sta->addr);
  1274. if (sta->timeout_next == STA_NULLFUNC ||
  1275. sta->timeout_next == STA_DISASSOC) {
  1276. sta->timeout_next = STA_DEAUTH;
  1277. eloop_cancel_timeout(ap_handle_timer, hapd, sta);
  1278. eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
  1279. hapd, sta);
  1280. }
  1281. mlme_disassociate_indication(
  1282. hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
  1283. }
  1284. static void handle_deauth(struct hostapd_data *hapd,
  1285. const struct ieee80211_mgmt *mgmt, size_t len)
  1286. {
  1287. struct sta_info *sta;
  1288. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
  1289. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
  1290. "payload (len=%lu)", (unsigned long) len);
  1291. return;
  1292. }
  1293. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
  1294. " reason_code=%d",
  1295. MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
  1296. sta = ap_get_sta(hapd, mgmt->sa);
  1297. if (sta == NULL) {
  1298. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
  1299. "to deauthenticate, but it is not authenticated",
  1300. MAC2STR(mgmt->sa));
  1301. return;
  1302. }
  1303. ap_sta_set_authorized(hapd, sta, 0);
  1304. sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
  1305. WLAN_STA_ASSOC_REQ_OK);
  1306. wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
  1307. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1308. HOSTAPD_LEVEL_DEBUG, "deauthenticated");
  1309. mlme_deauthenticate_indication(
  1310. hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
  1311. sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
  1312. ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
  1313. ap_free_sta(hapd, sta);
  1314. }
  1315. static void handle_beacon(struct hostapd_data *hapd,
  1316. const struct ieee80211_mgmt *mgmt, size_t len,
  1317. struct hostapd_frame_info *fi)
  1318. {
  1319. struct ieee802_11_elems elems;
  1320. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
  1321. wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
  1322. (unsigned long) len);
  1323. return;
  1324. }
  1325. (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
  1326. len - (IEEE80211_HDRLEN +
  1327. sizeof(mgmt->u.beacon)), &elems,
  1328. 0);
  1329. ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
  1330. }
  1331. #ifdef CONFIG_IEEE80211W
  1332. static void hostapd_sa_query_action(struct hostapd_data *hapd,
  1333. const struct ieee80211_mgmt *mgmt,
  1334. size_t len)
  1335. {
  1336. const u8 *end;
  1337. end = mgmt->u.action.u.sa_query_resp.trans_id +
  1338. WLAN_SA_QUERY_TR_ID_LEN;
  1339. if (((u8 *) mgmt) + len < end) {
  1340. wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
  1341. "frame (len=%lu)", (unsigned long) len);
  1342. return;
  1343. }
  1344. ieee802_11_sa_query_action(hapd, mgmt->sa,
  1345. mgmt->u.action.u.sa_query_resp.action,
  1346. mgmt->u.action.u.sa_query_resp.trans_id);
  1347. }
  1348. static int robust_action_frame(u8 category)
  1349. {
  1350. return category != WLAN_ACTION_PUBLIC &&
  1351. category != WLAN_ACTION_HT;
  1352. }
  1353. #endif /* CONFIG_IEEE80211W */
  1354. #ifdef CONFIG_WNM
  1355. static void hostapd_wnm_action(struct hostapd_data *hapd, struct sta_info *sta,
  1356. const struct ieee80211_mgmt *mgmt,
  1357. size_t len)
  1358. {
  1359. struct rx_action action;
  1360. if (len < IEEE80211_HDRLEN + 2)
  1361. return;
  1362. os_memset(&action, 0, sizeof(action));
  1363. action.da = mgmt->da;
  1364. action.sa = mgmt->sa;
  1365. action.bssid = mgmt->bssid;
  1366. action.category = mgmt->u.action.category;
  1367. action.data = (const u8 *) &mgmt->u.action.u.wnm_sleep_req.action;
  1368. action.len = len - IEEE80211_HDRLEN - 1;
  1369. action.freq = hapd->iface->freq;
  1370. ieee802_11_rx_wnm_action_ap(hapd, &action);
  1371. }
  1372. #endif /* CONFIG_WNM */
  1373. static void handle_action(struct hostapd_data *hapd,
  1374. const struct ieee80211_mgmt *mgmt, size_t len)
  1375. {
  1376. struct sta_info *sta;
  1377. sta = ap_get_sta(hapd, mgmt->sa);
  1378. if (len < IEEE80211_HDRLEN + 1) {
  1379. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1380. HOSTAPD_LEVEL_DEBUG,
  1381. "handle_action - too short payload (len=%lu)",
  1382. (unsigned long) len);
  1383. return;
  1384. }
  1385. if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
  1386. (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
  1387. wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
  1388. "frame (category=%u) from unassociated STA " MACSTR,
  1389. MAC2STR(mgmt->sa), mgmt->u.action.category);
  1390. return;
  1391. }
  1392. #ifdef CONFIG_IEEE80211W
  1393. if (sta && (sta->flags & WLAN_STA_MFP) &&
  1394. !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP) &&
  1395. robust_action_frame(mgmt->u.action.category))) {
  1396. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1397. HOSTAPD_LEVEL_DEBUG,
  1398. "Dropped unprotected Robust Action frame from "
  1399. "an MFP STA");
  1400. return;
  1401. }
  1402. #endif /* CONFIG_IEEE80211W */
  1403. switch (mgmt->u.action.category) {
  1404. #ifdef CONFIG_IEEE80211R
  1405. case WLAN_ACTION_FT:
  1406. if (wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
  1407. len - IEEE80211_HDRLEN))
  1408. break;
  1409. return;
  1410. #endif /* CONFIG_IEEE80211R */
  1411. case WLAN_ACTION_WMM:
  1412. hostapd_wmm_action(hapd, mgmt, len);
  1413. return;
  1414. #ifdef CONFIG_IEEE80211W
  1415. case WLAN_ACTION_SA_QUERY:
  1416. hostapd_sa_query_action(hapd, mgmt, len);
  1417. return;
  1418. #endif /* CONFIG_IEEE80211W */
  1419. #ifdef CONFIG_WNM
  1420. case WLAN_ACTION_WNM:
  1421. hostapd_wnm_action(hapd, sta, mgmt, len);
  1422. return;
  1423. #endif /* CONFIG_WNM */
  1424. case WLAN_ACTION_PUBLIC:
  1425. if (hapd->public_action_cb) {
  1426. hapd->public_action_cb(hapd->public_action_cb_ctx,
  1427. (u8 *) mgmt, len,
  1428. hapd->iface->freq);
  1429. }
  1430. if (hapd->public_action_cb2) {
  1431. hapd->public_action_cb2(hapd->public_action_cb2_ctx,
  1432. (u8 *) mgmt, len,
  1433. hapd->iface->freq);
  1434. }
  1435. if (hapd->public_action_cb || hapd->public_action_cb2)
  1436. return;
  1437. break;
  1438. case WLAN_ACTION_VENDOR_SPECIFIC:
  1439. if (hapd->vendor_action_cb) {
  1440. if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
  1441. (u8 *) mgmt, len,
  1442. hapd->iface->freq) == 0)
  1443. return;
  1444. }
  1445. break;
  1446. }
  1447. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1448. HOSTAPD_LEVEL_DEBUG,
  1449. "handle_action - unknown action category %d or invalid "
  1450. "frame",
  1451. mgmt->u.action.category);
  1452. if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
  1453. !(mgmt->sa[0] & 0x01)) {
  1454. struct ieee80211_mgmt *resp;
  1455. /*
  1456. * IEEE 802.11-REVma/D9.0 - 7.3.1.11
  1457. * Return the Action frame to the source without change
  1458. * except that MSB of the Category set to 1.
  1459. */
  1460. wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
  1461. "frame back to sender");
  1462. resp = os_malloc(len);
  1463. if (resp == NULL)
  1464. return;
  1465. os_memcpy(resp, mgmt, len);
  1466. os_memcpy(resp->da, resp->sa, ETH_ALEN);
  1467. os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
  1468. os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
  1469. resp->u.action.category |= 0x80;
  1470. if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
  1471. wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
  1472. "Action frame");
  1473. }
  1474. os_free(resp);
  1475. }
  1476. }
  1477. /**
  1478. * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
  1479. * @hapd: hostapd BSS data structure (the BSS to which the management frame was
  1480. * sent to)
  1481. * @buf: management frame data (starting from IEEE 802.11 header)
  1482. * @len: length of frame data in octets
  1483. * @fi: meta data about received frame (signal level, etc.)
  1484. *
  1485. * Process all incoming IEEE 802.11 management frames. This will be called for
  1486. * each frame received from the kernel driver through wlan#ap interface. In
  1487. * addition, it can be called to re-inserted pending frames (e.g., when using
  1488. * external RADIUS server as an MAC ACL).
  1489. */
  1490. void ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
  1491. struct hostapd_frame_info *fi)
  1492. {
  1493. struct ieee80211_mgmt *mgmt;
  1494. int broadcast;
  1495. u16 fc, stype;
  1496. if (len < 24)
  1497. return;
  1498. mgmt = (struct ieee80211_mgmt *) buf;
  1499. fc = le_to_host16(mgmt->frame_control);
  1500. stype = WLAN_FC_GET_STYPE(fc);
  1501. if (stype == WLAN_FC_STYPE_BEACON) {
  1502. handle_beacon(hapd, mgmt, len, fi);
  1503. return;
  1504. }
  1505. broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
  1506. mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
  1507. mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
  1508. if (!broadcast &&
  1509. #ifdef CONFIG_P2P
  1510. /* Invitation responses can be sent with the peer MAC as BSSID */
  1511. !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
  1512. stype == WLAN_FC_STYPE_ACTION) &&
  1513. #endif /* CONFIG_P2P */
  1514. os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
  1515. wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
  1516. MAC2STR(mgmt->bssid));
  1517. return;
  1518. }
  1519. if (stype == WLAN_FC_STYPE_PROBE_REQ) {
  1520. handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
  1521. return;
  1522. }
  1523. if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
  1524. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1525. HOSTAPD_LEVEL_DEBUG,
  1526. "MGMT: DA=" MACSTR " not our address",
  1527. MAC2STR(mgmt->da));
  1528. return;
  1529. }
  1530. switch (stype) {
  1531. case WLAN_FC_STYPE_AUTH:
  1532. wpa_printf(MSG_DEBUG, "mgmt::auth");
  1533. handle_auth(hapd, mgmt, len);
  1534. break;
  1535. case WLAN_FC_STYPE_ASSOC_REQ:
  1536. wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
  1537. handle_assoc(hapd, mgmt, len, 0);
  1538. break;
  1539. case WLAN_FC_STYPE_REASSOC_REQ:
  1540. wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
  1541. handle_assoc(hapd, mgmt, len, 1);
  1542. break;
  1543. case WLAN_FC_STYPE_DISASSOC:
  1544. wpa_printf(MSG_DEBUG, "mgmt::disassoc");
  1545. handle_disassoc(hapd, mgmt, len);
  1546. break;
  1547. case WLAN_FC_STYPE_DEAUTH:
  1548. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
  1549. handle_deauth(hapd, mgmt, len);
  1550. break;
  1551. case WLAN_FC_STYPE_ACTION:
  1552. wpa_printf(MSG_DEBUG, "mgmt::action");
  1553. handle_action(hapd, mgmt, len);
  1554. break;
  1555. default:
  1556. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1557. HOSTAPD_LEVEL_DEBUG,
  1558. "unknown mgmt frame subtype %d", stype);
  1559. break;
  1560. }
  1561. }
  1562. static void handle_auth_cb(struct hostapd_data *hapd,
  1563. const struct ieee80211_mgmt *mgmt,
  1564. size_t len, int ok)
  1565. {
  1566. u16 auth_alg, auth_transaction, status_code;
  1567. struct sta_info *sta;
  1568. if (!ok) {
  1569. hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
  1570. HOSTAPD_LEVEL_NOTICE,
  1571. "did not acknowledge authentication response");
  1572. return;
  1573. }
  1574. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
  1575. wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
  1576. (unsigned long) len);
  1577. return;
  1578. }
  1579. auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
  1580. auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
  1581. status_code = le_to_host16(mgmt->u.auth.status_code);
  1582. sta = ap_get_sta(hapd, mgmt->da);
  1583. if (!sta) {
  1584. wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
  1585. MAC2STR(mgmt->da));
  1586. return;
  1587. }
  1588. if (status_code == WLAN_STATUS_SUCCESS &&
  1589. ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
  1590. (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
  1591. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1592. HOSTAPD_LEVEL_INFO, "authenticated");
  1593. sta->flags |= WLAN_STA_AUTH;
  1594. }
  1595. }
  1596. static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
  1597. struct sta_info *sta,
  1598. char *ifname_wds)
  1599. {
  1600. int i;
  1601. struct hostapd_ssid *ssid = sta->ssid;
  1602. if (hapd->conf->ieee802_1x || hapd->conf->wpa)
  1603. return;
  1604. for (i = 0; i < 4; i++) {
  1605. if (ssid->wep.key[i] &&
  1606. hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
  1607. i == ssid->wep.idx, NULL, 0,
  1608. ssid->wep.key[i], ssid->wep.len[i])) {
  1609. wpa_printf(MSG_WARNING,
  1610. "Could not set WEP keys for WDS interface; %s",
  1611. ifname_wds);
  1612. break;
  1613. }
  1614. }
  1615. }
  1616. static void handle_assoc_cb(struct hostapd_data *hapd,
  1617. const struct ieee80211_mgmt *mgmt,
  1618. size_t len, int reassoc, int ok)
  1619. {
  1620. u16 status;
  1621. struct sta_info *sta;
  1622. int new_assoc = 1;
  1623. struct ieee80211_ht_capabilities ht_cap;
  1624. struct ieee80211_vht_capabilities vht_cap;
  1625. if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
  1626. sizeof(mgmt->u.assoc_resp))) {
  1627. wpa_printf(MSG_INFO, "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
  1628. reassoc, (unsigned long) len);
  1629. return;
  1630. }
  1631. sta = ap_get_sta(hapd, mgmt->da);
  1632. if (!sta) {
  1633. wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
  1634. MAC2STR(mgmt->da));
  1635. return;
  1636. }
  1637. if (!ok) {
  1638. hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
  1639. HOSTAPD_LEVEL_DEBUG,
  1640. "did not acknowledge association response");
  1641. sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
  1642. return;
  1643. }
  1644. if (reassoc)
  1645. status = le_to_host16(mgmt->u.reassoc_resp.status_code);
  1646. else
  1647. status = le_to_host16(mgmt->u.assoc_resp.status_code);
  1648. if (status != WLAN_STATUS_SUCCESS)
  1649. goto fail;
  1650. /* Stop previous accounting session, if one is started, and allocate
  1651. * new session id for the new session. */
  1652. accounting_sta_stop(hapd, sta);
  1653. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1654. HOSTAPD_LEVEL_INFO,
  1655. "associated (aid %d)",
  1656. sta->aid);
  1657. if (sta->flags & WLAN_STA_ASSOC)
  1658. new_assoc = 0;
  1659. sta->flags |= WLAN_STA_ASSOC;
  1660. if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
  1661. sta->auth_alg == WLAN_AUTH_FT) {
  1662. /*
  1663. * Open, static WEP, or FT protocol; no separate authorization
  1664. * step.
  1665. */
  1666. ap_sta_set_authorized(hapd, sta, 1);
  1667. }
  1668. if (reassoc)
  1669. mlme_reassociate_indication(hapd, sta);
  1670. else
  1671. mlme_associate_indication(hapd, sta);
  1672. #ifdef CONFIG_IEEE80211W
  1673. sta->sa_query_timed_out = 0;
  1674. #endif /* CONFIG_IEEE80211W */
  1675. /*
  1676. * Remove the STA entry in order to make sure the STA PS state gets
  1677. * cleared and configuration gets updated in case of reassociation back
  1678. * to the same AP.
  1679. */
  1680. hostapd_drv_sta_remove(hapd, sta->addr);
  1681. #ifdef CONFIG_IEEE80211N
  1682. if (sta->flags & WLAN_STA_HT)
  1683. hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
  1684. #endif /* CONFIG_IEEE80211N */
  1685. #ifdef CONFIG_IEEE80211AC
  1686. if (sta->flags & WLAN_STA_VHT)
  1687. hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
  1688. #endif /* CONFIG_IEEE80211AC */
  1689. if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
  1690. sta->supported_rates, sta->supported_rates_len,
  1691. sta->listen_interval,
  1692. sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
  1693. sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
  1694. sta->flags, sta->qosinfo)) {
  1695. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1696. HOSTAPD_LEVEL_NOTICE,
  1697. "Could not add STA to kernel driver");
  1698. ap_sta_disconnect(hapd, sta, sta->addr,
  1699. WLAN_REASON_DISASSOC_AP_BUSY);
  1700. goto fail;
  1701. }
  1702. if (sta->flags & WLAN_STA_WDS) {
  1703. int ret;
  1704. char ifname_wds[IFNAMSIZ + 1];
  1705. ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
  1706. sta->aid, 1);
  1707. if (!ret)
  1708. hostapd_set_wds_encryption(hapd, sta, ifname_wds);
  1709. }
  1710. if (sta->eapol_sm == NULL) {
  1711. /*
  1712. * This STA does not use RADIUS server for EAP authentication,
  1713. * so bind it to the selected VLAN interface now, since the
  1714. * interface selection is not going to change anymore.
  1715. */
  1716. if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
  1717. goto fail;
  1718. } else if (sta->vlan_id) {
  1719. /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
  1720. if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
  1721. goto fail;
  1722. }
  1723. hostapd_set_sta_flags(hapd, sta);
  1724. if (sta->auth_alg == WLAN_AUTH_FT)
  1725. wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
  1726. else
  1727. wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
  1728. hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
  1729. ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
  1730. fail:
  1731. /* Copy of the association request is not needed anymore */
  1732. if (sta->last_assoc_req) {
  1733. os_free(sta->last_assoc_req);
  1734. sta->last_assoc_req = NULL;
  1735. }
  1736. }
  1737. static void handle_deauth_cb(struct hostapd_data *hapd,
  1738. const struct ieee80211_mgmt *mgmt,
  1739. size_t len, int ok)
  1740. {
  1741. struct sta_info *sta;
  1742. if (mgmt->da[0] & 0x01)
  1743. return;
  1744. sta = ap_get_sta(hapd, mgmt->da);
  1745. if (!sta) {
  1746. wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
  1747. " not found", MAC2STR(mgmt->da));
  1748. return;
  1749. }
  1750. if (ok)
  1751. wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
  1752. MAC2STR(sta->addr));
  1753. else
  1754. wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
  1755. "deauth", MAC2STR(sta->addr));
  1756. ap_sta_deauth_cb(hapd, sta);
  1757. }
  1758. static void handle_disassoc_cb(struct hostapd_data *hapd,
  1759. const struct ieee80211_mgmt *mgmt,
  1760. size_t len, int ok)
  1761. {
  1762. struct sta_info *sta;
  1763. if (mgmt->da[0] & 0x01)
  1764. return;
  1765. sta = ap_get_sta(hapd, mgmt->da);
  1766. if (!sta) {
  1767. wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
  1768. " not found", MAC2STR(mgmt->da));
  1769. return;
  1770. }
  1771. if (ok)
  1772. wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
  1773. MAC2STR(sta->addr));
  1774. else
  1775. wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
  1776. "disassoc", MAC2STR(sta->addr));
  1777. ap_sta_disassoc_cb(hapd, sta);
  1778. }
  1779. /**
  1780. * ieee802_11_mgmt_cb - Process management frame TX status callback
  1781. * @hapd: hostapd BSS data structure (the BSS from which the management frame
  1782. * was sent from)
  1783. * @buf: management frame data (starting from IEEE 802.11 header)
  1784. * @len: length of frame data in octets
  1785. * @stype: management frame subtype from frame control field
  1786. * @ok: Whether the frame was ACK'ed
  1787. */
  1788. void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
  1789. u16 stype, int ok)
  1790. {
  1791. const struct ieee80211_mgmt *mgmt;
  1792. mgmt = (const struct ieee80211_mgmt *) buf;
  1793. switch (stype) {
  1794. case WLAN_FC_STYPE_AUTH:
  1795. wpa_printf(MSG_DEBUG, "mgmt::auth cb");
  1796. handle_auth_cb(hapd, mgmt, len, ok);
  1797. break;
  1798. case WLAN_FC_STYPE_ASSOC_RESP:
  1799. wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
  1800. handle_assoc_cb(hapd, mgmt, len, 0, ok);
  1801. break;
  1802. case WLAN_FC_STYPE_REASSOC_RESP:
  1803. wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
  1804. handle_assoc_cb(hapd, mgmt, len, 1, ok);
  1805. break;
  1806. case WLAN_FC_STYPE_PROBE_RESP:
  1807. wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
  1808. break;
  1809. case WLAN_FC_STYPE_DEAUTH:
  1810. wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
  1811. handle_deauth_cb(hapd, mgmt, len, ok);
  1812. break;
  1813. case WLAN_FC_STYPE_DISASSOC:
  1814. wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
  1815. handle_disassoc_cb(hapd, mgmt, len, ok);
  1816. break;
  1817. case WLAN_FC_STYPE_ACTION:
  1818. wpa_printf(MSG_DEBUG, "mgmt::action cb");
  1819. break;
  1820. default:
  1821. wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
  1822. break;
  1823. }
  1824. }
  1825. int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
  1826. {
  1827. /* TODO */
  1828. return 0;
  1829. }
  1830. int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
  1831. char *buf, size_t buflen)
  1832. {
  1833. /* TODO */
  1834. return 0;
  1835. }
  1836. void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
  1837. const u8 *buf, size_t len, int ack)
  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 || !(sta->flags & WLAN_STA_ASSOC))
  1852. return;
  1853. if (sta->flags & WLAN_STA_PENDING_POLL) {
  1854. wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
  1855. "activity poll", MAC2STR(sta->addr),
  1856. ack ? "ACKed" : "did not ACK");
  1857. if (ack)
  1858. sta->flags &= ~WLAN_STA_PENDING_POLL;
  1859. }
  1860. ieee802_1x_tx_status(hapd, sta, buf, len, ack);
  1861. }
  1862. void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
  1863. const u8 *data, size_t len, int ack)
  1864. {
  1865. struct sta_info *sta;
  1866. struct hostapd_iface *iface = hapd->iface;
  1867. sta = ap_get_sta(hapd, dst);
  1868. if (sta == NULL && iface->num_bss > 1) {
  1869. size_t j;
  1870. for (j = 0; j < iface->num_bss; j++) {
  1871. hapd = iface->bss[j];
  1872. sta = ap_get_sta(hapd, dst);
  1873. if (sta)
  1874. break;
  1875. }
  1876. }
  1877. if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
  1878. wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
  1879. MACSTR " that is not currently associated",
  1880. MAC2STR(dst));
  1881. return;
  1882. }
  1883. ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
  1884. }
  1885. void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
  1886. {
  1887. struct sta_info *sta;
  1888. struct hostapd_iface *iface = hapd->iface;
  1889. sta = ap_get_sta(hapd, addr);
  1890. if (sta == NULL && iface->num_bss > 1) {
  1891. size_t j;
  1892. for (j = 0; j < iface->num_bss; j++) {
  1893. hapd = iface->bss[j];
  1894. sta = ap_get_sta(hapd, addr);
  1895. if (sta)
  1896. break;
  1897. }
  1898. }
  1899. if (sta == NULL)
  1900. return;
  1901. if (!(sta->flags & WLAN_STA_PENDING_POLL))
  1902. return;
  1903. wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
  1904. "activity poll", MAC2STR(sta->addr));
  1905. sta->flags &= ~WLAN_STA_PENDING_POLL;
  1906. }
  1907. void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
  1908. int wds)
  1909. {
  1910. struct sta_info *sta;
  1911. sta = ap_get_sta(hapd, src);
  1912. if (sta && (sta->flags & WLAN_STA_ASSOC)) {
  1913. if (!hapd->conf->wds_sta)
  1914. return;
  1915. if (wds && !(sta->flags & WLAN_STA_WDS)) {
  1916. int ret;
  1917. char ifname_wds[IFNAMSIZ + 1];
  1918. wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
  1919. "STA " MACSTR " (aid %u)",
  1920. MAC2STR(sta->addr), sta->aid);
  1921. sta->flags |= WLAN_STA_WDS;
  1922. ret = hostapd_set_wds_sta(hapd, ifname_wds,
  1923. sta->addr, sta->aid, 1);
  1924. if (!ret)
  1925. hostapd_set_wds_encryption(hapd, sta,
  1926. ifname_wds);
  1927. }
  1928. return;
  1929. }
  1930. wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
  1931. MACSTR, MAC2STR(src));
  1932. if (src[0] & 0x01) {
  1933. /* Broadcast bit set in SA?! Ignore the frame silently. */
  1934. return;
  1935. }
  1936. if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
  1937. wpa_printf(MSG_DEBUG, "Association Response to the STA has "
  1938. "already been sent, but no TX status yet known - "
  1939. "ignore Class 3 frame issue with " MACSTR,
  1940. MAC2STR(src));
  1941. return;
  1942. }
  1943. if (sta && (sta->flags & WLAN_STA_AUTH))
  1944. hostapd_drv_sta_disassoc(
  1945. hapd, src,
  1946. WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
  1947. else
  1948. hostapd_drv_sta_deauth(
  1949. hapd, src,
  1950. WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
  1951. }
  1952. #endif /* CONFIG_NATIVE_WINDOWS */