ieee802_11.c 88 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162
  1. /*
  2. * hostapd / IEEE 802.11 Management
  3. * Copyright (c) 2002-2014, 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 "common/ieee802_11_defs.h"
  16. #include "common/ieee802_11_common.h"
  17. #include "common/wpa_ctrl.h"
  18. #include "common/sae.h"
  19. #include "radius/radius.h"
  20. #include "radius/radius_client.h"
  21. #include "p2p/p2p.h"
  22. #include "wps/wps.h"
  23. #include "fst/fst.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 "pmksa_cache_auth.h"
  31. #include "wmm.h"
  32. #include "ap_list.h"
  33. #include "accounting.h"
  34. #include "ap_config.h"
  35. #include "ap_mlme.h"
  36. #include "p2p_hostapd.h"
  37. #include "ap_drv_ops.h"
  38. #include "wnm_ap.h"
  39. #include "hw_features.h"
  40. #include "ieee802_11.h"
  41. #include "dfs.h"
  42. #include "mbo_ap.h"
  43. #include "rrm.h"
  44. u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
  45. {
  46. u8 *pos = eid;
  47. int i, num, count;
  48. if (hapd->iface->current_rates == NULL)
  49. return eid;
  50. *pos++ = WLAN_EID_SUPP_RATES;
  51. num = hapd->iface->num_rates;
  52. if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
  53. num++;
  54. if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
  55. num++;
  56. if (num > 8) {
  57. /* rest of the rates are encoded in Extended supported
  58. * rates element */
  59. num = 8;
  60. }
  61. *pos++ = num;
  62. for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
  63. i++) {
  64. count++;
  65. *pos = hapd->iface->current_rates[i].rate / 5;
  66. if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
  67. *pos |= 0x80;
  68. pos++;
  69. }
  70. if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) {
  71. count++;
  72. *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
  73. }
  74. if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) {
  75. count++;
  76. *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
  77. }
  78. return pos;
  79. }
  80. u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
  81. {
  82. u8 *pos = eid;
  83. int i, num, count;
  84. if (hapd->iface->current_rates == NULL)
  85. return eid;
  86. num = hapd->iface->num_rates;
  87. if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
  88. num++;
  89. if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
  90. num++;
  91. if (num <= 8)
  92. return eid;
  93. num -= 8;
  94. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  95. *pos++ = num;
  96. for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
  97. i++) {
  98. count++;
  99. if (count <= 8)
  100. continue; /* already in SuppRates IE */
  101. *pos = hapd->iface->current_rates[i].rate / 5;
  102. if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
  103. *pos |= 0x80;
  104. pos++;
  105. }
  106. if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
  107. count++;
  108. if (count > 8)
  109. *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
  110. }
  111. if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
  112. count++;
  113. if (count > 8)
  114. *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
  115. }
  116. return pos;
  117. }
  118. u16 hostapd_own_capab_info(struct hostapd_data *hapd)
  119. {
  120. int capab = WLAN_CAPABILITY_ESS;
  121. int privacy;
  122. int dfs;
  123. int i;
  124. /* Check if any of configured channels require DFS */
  125. dfs = hostapd_is_dfs_required(hapd->iface);
  126. if (dfs < 0) {
  127. wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
  128. dfs);
  129. dfs = 0;
  130. }
  131. if (hapd->iface->num_sta_no_short_preamble == 0 &&
  132. hapd->iconf->preamble == SHORT_PREAMBLE)
  133. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  134. privacy = hapd->conf->ssid.wep.keys_set;
  135. if (hapd->conf->ieee802_1x &&
  136. (hapd->conf->default_wep_key_len ||
  137. hapd->conf->individual_wep_key_len))
  138. privacy = 1;
  139. if (hapd->conf->wpa)
  140. privacy = 1;
  141. #ifdef CONFIG_HS20
  142. if (hapd->conf->osen)
  143. privacy = 1;
  144. #endif /* CONFIG_HS20 */
  145. if (privacy)
  146. capab |= WLAN_CAPABILITY_PRIVACY;
  147. if (hapd->iface->current_mode &&
  148. hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
  149. hapd->iface->num_sta_no_short_slot_time == 0)
  150. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  151. /*
  152. * Currently, Spectrum Management capability bit is set when directly
  153. * requested in configuration by spectrum_mgmt_required or when AP is
  154. * running on DFS channel.
  155. * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
  156. */
  157. if (hapd->iface->current_mode &&
  158. hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
  159. (hapd->iconf->spectrum_mgmt_required || dfs))
  160. capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
  161. for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) {
  162. if (hapd->conf->radio_measurements[i]) {
  163. capab |= IEEE80211_CAP_RRM;
  164. break;
  165. }
  166. }
  167. return capab;
  168. }
  169. #ifndef CONFIG_NO_RC4
  170. static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
  171. u16 auth_transaction, const u8 *challenge,
  172. int iswep)
  173. {
  174. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  175. HOSTAPD_LEVEL_DEBUG,
  176. "authentication (shared key, transaction %d)",
  177. auth_transaction);
  178. if (auth_transaction == 1) {
  179. if (!sta->challenge) {
  180. /* Generate a pseudo-random challenge */
  181. u8 key[8];
  182. sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
  183. if (sta->challenge == NULL)
  184. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  185. if (os_get_random(key, sizeof(key)) < 0) {
  186. os_free(sta->challenge);
  187. sta->challenge = NULL;
  188. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  189. }
  190. rc4_skip(key, sizeof(key), 0,
  191. sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
  192. }
  193. return 0;
  194. }
  195. if (auth_transaction != 3)
  196. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  197. /* Transaction 3 */
  198. if (!iswep || !sta->challenge || !challenge ||
  199. os_memcmp_const(sta->challenge, challenge,
  200. WLAN_AUTH_CHALLENGE_LEN)) {
  201. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  202. HOSTAPD_LEVEL_INFO,
  203. "shared key authentication - invalid "
  204. "challenge-response");
  205. return WLAN_STATUS_CHALLENGE_FAIL;
  206. }
  207. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  208. HOSTAPD_LEVEL_DEBUG,
  209. "authentication OK (shared key)");
  210. sta->flags |= WLAN_STA_AUTH;
  211. wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
  212. os_free(sta->challenge);
  213. sta->challenge = NULL;
  214. return 0;
  215. }
  216. #endif /* CONFIG_NO_RC4 */
  217. static int send_auth_reply(struct hostapd_data *hapd,
  218. const u8 *dst, const u8 *bssid,
  219. u16 auth_alg, u16 auth_transaction, u16 resp,
  220. const u8 *ies, size_t ies_len)
  221. {
  222. struct ieee80211_mgmt *reply;
  223. u8 *buf;
  224. size_t rlen;
  225. int reply_res = WLAN_STATUS_UNSPECIFIED_FAILURE;
  226. rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
  227. buf = os_zalloc(rlen);
  228. if (buf == NULL)
  229. return -1;
  230. reply = (struct ieee80211_mgmt *) buf;
  231. reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  232. WLAN_FC_STYPE_AUTH);
  233. os_memcpy(reply->da, dst, ETH_ALEN);
  234. os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
  235. os_memcpy(reply->bssid, bssid, ETH_ALEN);
  236. reply->u.auth.auth_alg = host_to_le16(auth_alg);
  237. reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
  238. reply->u.auth.status_code = host_to_le16(resp);
  239. if (ies && ies_len)
  240. os_memcpy(reply->u.auth.variable, ies, ies_len);
  241. wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
  242. " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
  243. MAC2STR(dst), auth_alg, auth_transaction,
  244. resp, (unsigned long) ies_len);
  245. if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
  246. wpa_printf(MSG_INFO, "send_auth_reply: send failed");
  247. else
  248. reply_res = WLAN_STATUS_SUCCESS;
  249. os_free(buf);
  250. return reply_res;
  251. }
  252. #ifdef CONFIG_IEEE80211R
  253. static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
  254. u16 auth_transaction, u16 status,
  255. const u8 *ies, size_t ies_len)
  256. {
  257. struct hostapd_data *hapd = ctx;
  258. struct sta_info *sta;
  259. int reply_res;
  260. reply_res = send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT,
  261. auth_transaction, status, ies, ies_len);
  262. sta = ap_get_sta(hapd, dst);
  263. if (sta == NULL)
  264. return;
  265. if (sta->added_unassoc && (reply_res != WLAN_STATUS_SUCCESS ||
  266. status != WLAN_STATUS_SUCCESS)) {
  267. hostapd_drv_sta_remove(hapd, sta->addr);
  268. sta->added_unassoc = 0;
  269. return;
  270. }
  271. if (status != WLAN_STATUS_SUCCESS)
  272. return;
  273. hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
  274. HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
  275. sta->flags |= WLAN_STA_AUTH;
  276. mlme_authenticate_indication(hapd, sta);
  277. }
  278. #endif /* CONFIG_IEEE80211R */
  279. #ifdef CONFIG_SAE
  280. #define dot11RSNASAESync 5 /* attempts */
  281. static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd,
  282. struct sta_info *sta, int update)
  283. {
  284. struct wpabuf *buf;
  285. if (hapd->conf->ssid.wpa_passphrase == NULL) {
  286. wpa_printf(MSG_DEBUG, "SAE: No password available");
  287. return NULL;
  288. }
  289. if (update &&
  290. sae_prepare_commit(hapd->own_addr, sta->addr,
  291. (u8 *) hapd->conf->ssid.wpa_passphrase,
  292. os_strlen(hapd->conf->ssid.wpa_passphrase),
  293. sta->sae) < 0) {
  294. wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
  295. return NULL;
  296. }
  297. buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
  298. if (buf == NULL)
  299. return NULL;
  300. sae_write_commit(sta->sae, buf, sta->sae->tmp ?
  301. sta->sae->tmp->anti_clogging_token : NULL);
  302. return buf;
  303. }
  304. static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
  305. struct sta_info *sta)
  306. {
  307. struct wpabuf *buf;
  308. buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
  309. if (buf == NULL)
  310. return NULL;
  311. sae_write_confirm(sta->sae, buf);
  312. return buf;
  313. }
  314. static int auth_sae_send_commit(struct hostapd_data *hapd,
  315. struct sta_info *sta,
  316. const u8 *bssid, int update)
  317. {
  318. struct wpabuf *data;
  319. int reply_res;
  320. data = auth_build_sae_commit(hapd, sta, update);
  321. if (data == NULL)
  322. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  323. reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 1,
  324. WLAN_STATUS_SUCCESS, wpabuf_head(data),
  325. wpabuf_len(data));
  326. wpabuf_free(data);
  327. return reply_res;
  328. }
  329. static int auth_sae_send_confirm(struct hostapd_data *hapd,
  330. struct sta_info *sta,
  331. const u8 *bssid)
  332. {
  333. struct wpabuf *data;
  334. int reply_res;
  335. data = auth_build_sae_confirm(hapd, sta);
  336. if (data == NULL)
  337. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  338. reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 2,
  339. WLAN_STATUS_SUCCESS, wpabuf_head(data),
  340. wpabuf_len(data));
  341. wpabuf_free(data);
  342. return reply_res;
  343. }
  344. static int use_sae_anti_clogging(struct hostapd_data *hapd)
  345. {
  346. struct sta_info *sta;
  347. unsigned int open = 0;
  348. if (hapd->conf->sae_anti_clogging_threshold == 0)
  349. return 1;
  350. for (sta = hapd->sta_list; sta; sta = sta->next) {
  351. if (!sta->sae)
  352. continue;
  353. if (sta->sae->state != SAE_COMMITTED &&
  354. sta->sae->state != SAE_CONFIRMED)
  355. continue;
  356. open++;
  357. if (open >= hapd->conf->sae_anti_clogging_threshold)
  358. return 1;
  359. }
  360. return 0;
  361. }
  362. static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
  363. const u8 *token, size_t token_len)
  364. {
  365. u8 mac[SHA256_MAC_LEN];
  366. if (token_len != SHA256_MAC_LEN)
  367. return -1;
  368. if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
  369. addr, ETH_ALEN, mac) < 0 ||
  370. os_memcmp_const(token, mac, SHA256_MAC_LEN) != 0)
  371. return -1;
  372. return 0;
  373. }
  374. static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
  375. int group, const u8 *addr)
  376. {
  377. struct wpabuf *buf;
  378. u8 *token;
  379. struct os_reltime now;
  380. os_get_reltime(&now);
  381. if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
  382. os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) {
  383. if (random_get_bytes(hapd->sae_token_key,
  384. sizeof(hapd->sae_token_key)) < 0)
  385. return NULL;
  386. wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
  387. hapd->sae_token_key, sizeof(hapd->sae_token_key));
  388. hapd->last_sae_token_key_update = now;
  389. }
  390. buf = wpabuf_alloc(sizeof(le16) + SHA256_MAC_LEN);
  391. if (buf == NULL)
  392. return NULL;
  393. wpabuf_put_le16(buf, group); /* Finite Cyclic Group */
  394. token = wpabuf_put(buf, SHA256_MAC_LEN);
  395. hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
  396. addr, ETH_ALEN, token);
  397. return buf;
  398. }
  399. static int sae_check_big_sync(struct sta_info *sta)
  400. {
  401. if (sta->sae->sync > dot11RSNASAESync) {
  402. sta->sae->state = SAE_NOTHING;
  403. sta->sae->sync = 0;
  404. return -1;
  405. }
  406. return 0;
  407. }
  408. static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data)
  409. {
  410. struct hostapd_data *hapd = eloop_ctx;
  411. struct sta_info *sta = eloop_data;
  412. int ret;
  413. if (sae_check_big_sync(sta))
  414. return;
  415. sta->sae->sync++;
  416. wpa_printf(MSG_DEBUG, "SAE: Auth SAE retransmit timer for " MACSTR
  417. " (sync=%d state=%d)",
  418. MAC2STR(sta->addr), sta->sae->sync, sta->sae->state);
  419. switch (sta->sae->state) {
  420. case SAE_COMMITTED:
  421. ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
  422. eloop_register_timeout(0,
  423. hapd->dot11RSNASAERetransPeriod * 1000,
  424. auth_sae_retransmit_timer, hapd, sta);
  425. break;
  426. case SAE_CONFIRMED:
  427. ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr);
  428. eloop_register_timeout(0,
  429. hapd->dot11RSNASAERetransPeriod * 1000,
  430. auth_sae_retransmit_timer, hapd, sta);
  431. break;
  432. default:
  433. ret = -1;
  434. break;
  435. }
  436. if (ret != WLAN_STATUS_SUCCESS)
  437. wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret);
  438. }
  439. void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta)
  440. {
  441. eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
  442. }
  443. static void sae_set_retransmit_timer(struct hostapd_data *hapd,
  444. struct sta_info *sta)
  445. {
  446. if (!(hapd->conf->mesh & MESH_ENABLED))
  447. return;
  448. eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
  449. eloop_register_timeout(0, hapd->dot11RSNASAERetransPeriod * 1000,
  450. auth_sae_retransmit_timer, hapd, sta);
  451. }
  452. void sae_accept_sta(struct hostapd_data *hapd, struct sta_info *sta)
  453. {
  454. sta->flags |= WLAN_STA_AUTH;
  455. sta->auth_alg = WLAN_AUTH_SAE;
  456. mlme_authenticate_indication(hapd, sta);
  457. wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
  458. sta->sae->state = SAE_ACCEPTED;
  459. wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr,
  460. sta->sae->pmk, sta->sae->pmkid);
  461. }
  462. static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta,
  463. const u8 *bssid, u8 auth_transaction)
  464. {
  465. int ret;
  466. if (auth_transaction != 1 && auth_transaction != 2)
  467. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  468. switch (sta->sae->state) {
  469. case SAE_NOTHING:
  470. if (auth_transaction == 1) {
  471. ret = auth_sae_send_commit(hapd, sta, bssid, 1);
  472. if (ret)
  473. return ret;
  474. sta->sae->state = SAE_COMMITTED;
  475. if (sae_process_commit(sta->sae) < 0)
  476. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  477. /*
  478. * In mesh case, both Commit and Confirm can be sent
  479. * immediately. In infrastructure BSS, only a single
  480. * Authentication frame (Commit) is expected from the AP
  481. * here and the second one (Confirm) will be sent once
  482. * the STA has sent its second Authentication frame
  483. * (Confirm).
  484. */
  485. if (hapd->conf->mesh & MESH_ENABLED) {
  486. /*
  487. * Send both Commit and Confirm immediately
  488. * based on SAE finite state machine
  489. * Nothing -> Confirm transition.
  490. */
  491. ret = auth_sae_send_confirm(hapd, sta, bssid);
  492. if (ret)
  493. return ret;
  494. sta->sae->state = SAE_CONFIRMED;
  495. } else {
  496. /*
  497. * For infrastructure BSS, send only the Commit
  498. * message now to get alternating sequence of
  499. * Authentication frames between the AP and STA.
  500. * Confirm will be sent in
  501. * Commited -> Confirmed/Accepted transition
  502. * when receiving Confirm from STA.
  503. */
  504. }
  505. sta->sae->sync = 0;
  506. sae_set_retransmit_timer(hapd, sta);
  507. } else {
  508. hostapd_logger(hapd, sta->addr,
  509. HOSTAPD_MODULE_IEEE80211,
  510. HOSTAPD_LEVEL_DEBUG,
  511. "SAE confirm before commit");
  512. }
  513. break;
  514. case SAE_COMMITTED:
  515. sae_clear_retransmit_timer(hapd, sta);
  516. if (auth_transaction == 1) {
  517. if (sae_process_commit(sta->sae) < 0)
  518. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  519. ret = auth_sae_send_confirm(hapd, sta, bssid);
  520. if (ret)
  521. return ret;
  522. sta->sae->state = SAE_CONFIRMED;
  523. sta->sae->sync = 0;
  524. sae_set_retransmit_timer(hapd, sta);
  525. } else if (hapd->conf->mesh & MESH_ENABLED) {
  526. /*
  527. * In mesh case, follow SAE finite state machine and
  528. * send Commit now, if sync count allows.
  529. */
  530. if (sae_check_big_sync(sta))
  531. return WLAN_STATUS_SUCCESS;
  532. sta->sae->sync++;
  533. ret = auth_sae_send_commit(hapd, sta, bssid, 0);
  534. if (ret)
  535. return ret;
  536. sae_set_retransmit_timer(hapd, sta);
  537. } else {
  538. /*
  539. * For instructure BSS, send the postponed Confirm from
  540. * Nothing -> Confirmed transition that was reduced to
  541. * Nothing -> Committed above.
  542. */
  543. ret = auth_sae_send_confirm(hapd, sta, bssid);
  544. if (ret)
  545. return ret;
  546. sta->sae->state = SAE_CONFIRMED;
  547. /*
  548. * Since this was triggered on Confirm RX, run another
  549. * step to get to Accepted without waiting for
  550. * additional events.
  551. */
  552. return sae_sm_step(hapd, sta, bssid, auth_transaction);
  553. }
  554. break;
  555. case SAE_CONFIRMED:
  556. sae_clear_retransmit_timer(hapd, sta);
  557. if (auth_transaction == 1) {
  558. if (sae_check_big_sync(sta))
  559. return WLAN_STATUS_SUCCESS;
  560. sta->sae->sync++;
  561. ret = auth_sae_send_commit(hapd, sta, bssid, 1);
  562. if (ret)
  563. return ret;
  564. if (sae_process_commit(sta->sae) < 0)
  565. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  566. ret = auth_sae_send_confirm(hapd, sta, bssid);
  567. if (ret)
  568. return ret;
  569. sae_set_retransmit_timer(hapd, sta);
  570. } else {
  571. sae_accept_sta(hapd, sta);
  572. }
  573. break;
  574. case SAE_ACCEPTED:
  575. if (auth_transaction == 1) {
  576. wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR
  577. ") doing reauthentication",
  578. MAC2STR(sta->addr));
  579. ap_free_sta(hapd, sta);
  580. wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
  581. } else {
  582. if (sae_check_big_sync(sta))
  583. return WLAN_STATUS_SUCCESS;
  584. sta->sae->sync++;
  585. ret = auth_sae_send_confirm(hapd, sta, bssid);
  586. sae_clear_temp_data(sta->sae);
  587. if (ret)
  588. return ret;
  589. }
  590. break;
  591. default:
  592. wpa_printf(MSG_ERROR, "SAE: invalid state %d",
  593. sta->sae->state);
  594. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  595. }
  596. return WLAN_STATUS_SUCCESS;
  597. }
  598. static void sae_pick_next_group(struct hostapd_data *hapd, struct sta_info *sta)
  599. {
  600. struct sae_data *sae = sta->sae;
  601. int i, *groups = hapd->conf->sae_groups;
  602. if (sae->state != SAE_COMMITTED)
  603. return;
  604. wpa_printf(MSG_DEBUG, "SAE: Previously selected group: %d", sae->group);
  605. for (i = 0; groups && groups[i] > 0; i++) {
  606. if (sae->group == groups[i])
  607. break;
  608. }
  609. if (!groups || groups[i] <= 0) {
  610. wpa_printf(MSG_DEBUG,
  611. "SAE: Previously selected group not found from the current configuration");
  612. return;
  613. }
  614. for (;;) {
  615. i++;
  616. if (groups[i] <= 0) {
  617. wpa_printf(MSG_DEBUG,
  618. "SAE: No alternative group enabled");
  619. return;
  620. }
  621. if (sae_set_group(sae, groups[i]) < 0)
  622. continue;
  623. break;
  624. }
  625. wpa_printf(MSG_DEBUG, "SAE: Selected new group: %d", groups[i]);
  626. }
  627. static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
  628. const struct ieee80211_mgmt *mgmt, size_t len,
  629. u16 auth_transaction, u16 status_code)
  630. {
  631. int resp = WLAN_STATUS_SUCCESS;
  632. struct wpabuf *data = NULL;
  633. if (!sta->sae) {
  634. if (auth_transaction != 1 ||
  635. status_code != WLAN_STATUS_SUCCESS) {
  636. resp = -1;
  637. goto remove_sta;
  638. }
  639. sta->sae = os_zalloc(sizeof(*sta->sae));
  640. if (!sta->sae) {
  641. resp = -1;
  642. goto remove_sta;
  643. }
  644. sta->sae->state = SAE_NOTHING;
  645. sta->sae->sync = 0;
  646. }
  647. if (sta->mesh_sae_pmksa_caching) {
  648. wpa_printf(MSG_DEBUG,
  649. "SAE: Cancel use of mesh PMKSA caching because peer starts SAE authentication");
  650. wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
  651. sta->mesh_sae_pmksa_caching = 0;
  652. }
  653. if (auth_transaction == 1) {
  654. const u8 *token = NULL, *pos, *end;
  655. size_t token_len = 0;
  656. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  657. HOSTAPD_LEVEL_DEBUG,
  658. "start SAE authentication (RX commit, status=%u)",
  659. status_code);
  660. if ((hapd->conf->mesh & MESH_ENABLED) &&
  661. status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ &&
  662. sta->sae->tmp) {
  663. pos = mgmt->u.auth.variable;
  664. end = ((const u8 *) mgmt) + len;
  665. if (pos + sizeof(le16) > end) {
  666. wpa_printf(MSG_ERROR,
  667. "SAE: Too short anti-clogging token request");
  668. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  669. goto reply;
  670. }
  671. resp = sae_group_allowed(sta->sae,
  672. hapd->conf->sae_groups,
  673. WPA_GET_LE16(pos));
  674. if (resp != WLAN_STATUS_SUCCESS) {
  675. wpa_printf(MSG_ERROR,
  676. "SAE: Invalid group in anti-clogging token request");
  677. goto reply;
  678. }
  679. pos += sizeof(le16);
  680. wpabuf_free(sta->sae->tmp->anti_clogging_token);
  681. sta->sae->tmp->anti_clogging_token =
  682. wpabuf_alloc_copy(pos, end - pos);
  683. if (sta->sae->tmp->anti_clogging_token == NULL) {
  684. wpa_printf(MSG_ERROR,
  685. "SAE: Failed to alloc for anti-clogging token");
  686. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  687. goto remove_sta;
  688. }
  689. /*
  690. * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
  691. * is 76, a new Commit Message shall be constructed
  692. * with the Anti-Clogging Token from the received
  693. * Authentication frame, and the commit-scalar and
  694. * COMMIT-ELEMENT previously sent.
  695. */
  696. resp = auth_sae_send_commit(hapd, sta, mgmt->bssid, 0);
  697. if (resp != WLAN_STATUS_SUCCESS) {
  698. wpa_printf(MSG_ERROR,
  699. "SAE: Failed to send commit message");
  700. goto remove_sta;
  701. }
  702. sta->sae->state = SAE_COMMITTED;
  703. sta->sae->sync = 0;
  704. sae_set_retransmit_timer(hapd, sta);
  705. return;
  706. }
  707. if ((hapd->conf->mesh & MESH_ENABLED) &&
  708. status_code ==
  709. WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
  710. sta->sae->tmp) {
  711. wpa_printf(MSG_DEBUG,
  712. "SAE: Peer did not accept our SAE group");
  713. sae_pick_next_group(hapd, sta);
  714. goto remove_sta;
  715. }
  716. if (status_code != WLAN_STATUS_SUCCESS)
  717. goto remove_sta;
  718. resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
  719. ((const u8 *) mgmt) + len -
  720. mgmt->u.auth.variable, &token,
  721. &token_len, hapd->conf->sae_groups);
  722. if (resp == SAE_SILENTLY_DISCARD) {
  723. wpa_printf(MSG_DEBUG,
  724. "SAE: Drop commit message from " MACSTR " due to reflection attack",
  725. MAC2STR(sta->addr));
  726. goto remove_sta;
  727. }
  728. if (token && check_sae_token(hapd, sta->addr, token, token_len)
  729. < 0) {
  730. wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
  731. "incorrect token from " MACSTR,
  732. MAC2STR(sta->addr));
  733. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  734. goto remove_sta;
  735. }
  736. if (resp != WLAN_STATUS_SUCCESS)
  737. goto reply;
  738. if (!token && use_sae_anti_clogging(hapd)) {
  739. wpa_printf(MSG_DEBUG,
  740. "SAE: Request anti-clogging token from "
  741. MACSTR, MAC2STR(sta->addr));
  742. data = auth_build_token_req(hapd, sta->sae->group,
  743. sta->addr);
  744. resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
  745. if (hapd->conf->mesh & MESH_ENABLED)
  746. sta->sae->state = SAE_NOTHING;
  747. goto reply;
  748. }
  749. resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
  750. } else if (auth_transaction == 2) {
  751. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  752. HOSTAPD_LEVEL_DEBUG,
  753. "SAE authentication (RX confirm, status=%u)",
  754. status_code);
  755. if (status_code != WLAN_STATUS_SUCCESS)
  756. goto remove_sta;
  757. if (sta->sae->state >= SAE_CONFIRMED ||
  758. !(hapd->conf->mesh & MESH_ENABLED)) {
  759. if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
  760. ((u8 *) mgmt) + len -
  761. mgmt->u.auth.variable) < 0) {
  762. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  763. goto reply;
  764. }
  765. }
  766. resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
  767. } else {
  768. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  769. HOSTAPD_LEVEL_DEBUG,
  770. "unexpected SAE authentication transaction %u (status=%u)",
  771. auth_transaction, status_code);
  772. if (status_code != WLAN_STATUS_SUCCESS)
  773. goto remove_sta;
  774. resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
  775. }
  776. reply:
  777. if (resp != WLAN_STATUS_SUCCESS) {
  778. send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
  779. auth_transaction, resp,
  780. data ? wpabuf_head(data) : (u8 *) "",
  781. data ? wpabuf_len(data) : 0);
  782. }
  783. remove_sta:
  784. if (sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
  785. status_code != WLAN_STATUS_SUCCESS)) {
  786. hostapd_drv_sta_remove(hapd, sta->addr);
  787. sta->added_unassoc = 0;
  788. }
  789. wpabuf_free(data);
  790. }
  791. /**
  792. * auth_sae_init_committed - Send COMMIT and start SAE in committed state
  793. * @hapd: BSS data for the device initiating the authentication
  794. * @sta: the peer to which commit authentication frame is sent
  795. *
  796. * This function implements Init event handling (IEEE Std 802.11-2012,
  797. * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
  798. * sta->sae structure should be initialized appropriately via a call to
  799. * sae_prepare_commit().
  800. */
  801. int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta)
  802. {
  803. int ret;
  804. if (!sta->sae || !sta->sae->tmp)
  805. return -1;
  806. if (sta->sae->state != SAE_NOTHING)
  807. return -1;
  808. ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
  809. if (ret)
  810. return -1;
  811. sta->sae->state = SAE_COMMITTED;
  812. sta->sae->sync = 0;
  813. sae_set_retransmit_timer(hapd, sta);
  814. return 0;
  815. }
  816. #endif /* CONFIG_SAE */
  817. static void handle_auth(struct hostapd_data *hapd,
  818. const struct ieee80211_mgmt *mgmt, size_t len)
  819. {
  820. u16 auth_alg, auth_transaction, status_code;
  821. u16 resp = WLAN_STATUS_SUCCESS;
  822. struct sta_info *sta = NULL;
  823. int res, reply_res;
  824. u16 fc;
  825. const u8 *challenge = NULL;
  826. u32 session_timeout, acct_interim_interval;
  827. struct vlan_description vlan_id;
  828. struct hostapd_sta_wpa_psk_short *psk = NULL;
  829. u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
  830. size_t resp_ies_len = 0;
  831. char *identity = NULL;
  832. char *radius_cui = NULL;
  833. u16 seq_ctrl;
  834. os_memset(&vlan_id, 0, sizeof(vlan_id));
  835. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
  836. wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
  837. (unsigned long) len);
  838. return;
  839. }
  840. #ifdef CONFIG_TESTING_OPTIONS
  841. if (hapd->iconf->ignore_auth_probability > 0.0 &&
  842. drand48() < hapd->iconf->ignore_auth_probability) {
  843. wpa_printf(MSG_INFO,
  844. "TESTING: ignoring auth frame from " MACSTR,
  845. MAC2STR(mgmt->sa));
  846. return;
  847. }
  848. #endif /* CONFIG_TESTING_OPTIONS */
  849. auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
  850. auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
  851. status_code = le_to_host16(mgmt->u.auth.status_code);
  852. fc = le_to_host16(mgmt->frame_control);
  853. seq_ctrl = le_to_host16(mgmt->seq_ctrl);
  854. if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
  855. 2 + WLAN_AUTH_CHALLENGE_LEN &&
  856. mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
  857. mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
  858. challenge = &mgmt->u.auth.variable[2];
  859. wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
  860. "auth_transaction=%d status_code=%d wep=%d%s "
  861. "seq_ctrl=0x%x%s",
  862. MAC2STR(mgmt->sa), auth_alg, auth_transaction,
  863. status_code, !!(fc & WLAN_FC_ISWEP),
  864. challenge ? " challenge" : "",
  865. seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
  866. #ifdef CONFIG_NO_RC4
  867. if (auth_alg == WLAN_AUTH_SHARED_KEY) {
  868. wpa_printf(MSG_INFO,
  869. "Unsupported authentication algorithm (%d)",
  870. auth_alg);
  871. resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
  872. goto fail;
  873. }
  874. #endif /* CONFIG_NO_RC4 */
  875. if (hapd->tkip_countermeasures) {
  876. resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
  877. goto fail;
  878. }
  879. if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
  880. auth_alg == WLAN_AUTH_OPEN) ||
  881. #ifdef CONFIG_IEEE80211R
  882. (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
  883. auth_alg == WLAN_AUTH_FT) ||
  884. #endif /* CONFIG_IEEE80211R */
  885. #ifdef CONFIG_SAE
  886. (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
  887. auth_alg == WLAN_AUTH_SAE) ||
  888. #endif /* CONFIG_SAE */
  889. ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
  890. auth_alg == WLAN_AUTH_SHARED_KEY))) {
  891. wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
  892. auth_alg);
  893. resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
  894. goto fail;
  895. }
  896. if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
  897. (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
  898. wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
  899. auth_transaction);
  900. resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
  901. goto fail;
  902. }
  903. if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
  904. wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
  905. MAC2STR(mgmt->sa));
  906. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  907. goto fail;
  908. }
  909. if (hapd->conf->no_auth_if_seen_on) {
  910. struct hostapd_data *other;
  911. other = sta_track_seen_on(hapd->iface, mgmt->sa,
  912. hapd->conf->no_auth_if_seen_on);
  913. if (other) {
  914. u8 *pos;
  915. u32 info;
  916. u8 op_class, channel, phytype;
  917. wpa_printf(MSG_DEBUG, "%s: Reject authentication from "
  918. MACSTR " since STA has been seen on %s",
  919. hapd->conf->iface, MAC2STR(mgmt->sa),
  920. hapd->conf->no_auth_if_seen_on);
  921. resp = WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION;
  922. pos = &resp_ies[0];
  923. *pos++ = WLAN_EID_NEIGHBOR_REPORT;
  924. *pos++ = 13;
  925. os_memcpy(pos, other->own_addr, ETH_ALEN);
  926. pos += ETH_ALEN;
  927. info = 0; /* TODO: BSSID Information */
  928. WPA_PUT_LE32(pos, info);
  929. pos += 4;
  930. if (other->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD)
  931. phytype = 8; /* dmg */
  932. else if (other->iconf->ieee80211ac)
  933. phytype = 9; /* vht */
  934. else if (other->iconf->ieee80211n)
  935. phytype = 7; /* ht */
  936. else if (other->iconf->hw_mode ==
  937. HOSTAPD_MODE_IEEE80211A)
  938. phytype = 4; /* ofdm */
  939. else if (other->iconf->hw_mode ==
  940. HOSTAPD_MODE_IEEE80211G)
  941. phytype = 6; /* erp */
  942. else
  943. phytype = 5; /* hrdsss */
  944. if (ieee80211_freq_to_channel_ext(
  945. hostapd_hw_get_freq(other,
  946. other->iconf->channel),
  947. other->iconf->secondary_channel,
  948. other->iconf->ieee80211ac,
  949. &op_class, &channel) == NUM_HOSTAPD_MODES) {
  950. op_class = 0;
  951. channel = other->iconf->channel;
  952. }
  953. *pos++ = op_class;
  954. *pos++ = channel;
  955. *pos++ = phytype;
  956. resp_ies_len = pos - &resp_ies[0];
  957. goto fail;
  958. }
  959. }
  960. res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
  961. &session_timeout,
  962. &acct_interim_interval, &vlan_id,
  963. &psk, &identity, &radius_cui);
  964. if (res == HOSTAPD_ACL_REJECT) {
  965. wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
  966. MAC2STR(mgmt->sa));
  967. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  968. goto fail;
  969. }
  970. if (res == HOSTAPD_ACL_PENDING) {
  971. wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
  972. " waiting for an external authentication",
  973. MAC2STR(mgmt->sa));
  974. /* Authentication code will re-send the authentication frame
  975. * after it has received (and cached) information from the
  976. * external source. */
  977. return;
  978. }
  979. sta = ap_get_sta(hapd, mgmt->sa);
  980. if (sta) {
  981. if ((fc & WLAN_FC_RETRY) &&
  982. sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
  983. sta->last_seq_ctrl == seq_ctrl &&
  984. sta->last_subtype == WLAN_FC_STYPE_AUTH) {
  985. hostapd_logger(hapd, sta->addr,
  986. HOSTAPD_MODULE_IEEE80211,
  987. HOSTAPD_LEVEL_DEBUG,
  988. "Drop repeated authentication frame seq_ctrl=0x%x",
  989. seq_ctrl);
  990. return;
  991. }
  992. #ifdef CONFIG_MESH
  993. if ((hapd->conf->mesh & MESH_ENABLED) &&
  994. sta->plink_state == PLINK_BLOCKED) {
  995. wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
  996. " is blocked - drop Authentication frame",
  997. MAC2STR(mgmt->sa));
  998. return;
  999. }
  1000. #endif /* CONFIG_MESH */
  1001. } else {
  1002. #ifdef CONFIG_MESH
  1003. if (hapd->conf->mesh & MESH_ENABLED) {
  1004. /* if the mesh peer is not available, we don't do auth.
  1005. */
  1006. wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
  1007. " not yet known - drop Authentication frame",
  1008. MAC2STR(mgmt->sa));
  1009. /*
  1010. * Save a copy of the frame so that it can be processed
  1011. * if a new peer entry is added shortly after this.
  1012. */
  1013. wpabuf_free(hapd->mesh_pending_auth);
  1014. hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len);
  1015. os_get_reltime(&hapd->mesh_pending_auth_time);
  1016. return;
  1017. }
  1018. #endif /* CONFIG_MESH */
  1019. sta = ap_sta_add(hapd, mgmt->sa);
  1020. if (!sta) {
  1021. resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
  1022. goto fail;
  1023. }
  1024. }
  1025. sta->last_seq_ctrl = seq_ctrl;
  1026. sta->last_subtype = WLAN_FC_STYPE_AUTH;
  1027. if (vlan_id.notempty &&
  1028. !hostapd_vlan_valid(hapd->conf->vlan, &vlan_id)) {
  1029. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
  1030. HOSTAPD_LEVEL_INFO,
  1031. "Invalid VLAN %d%s received from RADIUS server",
  1032. vlan_id.untagged,
  1033. vlan_id.tagged[0] ? "+" : "");
  1034. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1035. goto fail;
  1036. }
  1037. if (ap_sta_set_vlan(hapd, sta, &vlan_id) < 0) {
  1038. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1039. goto fail;
  1040. }
  1041. if (sta->vlan_id)
  1042. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
  1043. HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
  1044. hostapd_free_psk_list(sta->psk);
  1045. if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
  1046. sta->psk = psk;
  1047. psk = NULL;
  1048. } else {
  1049. sta->psk = NULL;
  1050. }
  1051. sta->identity = identity;
  1052. identity = NULL;
  1053. sta->radius_cui = radius_cui;
  1054. radius_cui = NULL;
  1055. sta->flags &= ~WLAN_STA_PREAUTH;
  1056. ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
  1057. if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
  1058. sta->acct_interim_interval = acct_interim_interval;
  1059. if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
  1060. ap_sta_session_timeout(hapd, sta, session_timeout);
  1061. else
  1062. ap_sta_no_session_timeout(hapd, sta);
  1063. /*
  1064. * If the driver supports full AP client state, add a station to the
  1065. * driver before sending authentication reply to make sure the driver
  1066. * has resources, and not to go through the entire authentication and
  1067. * association handshake, and fail it at the end.
  1068. *
  1069. * If this is not the first transaction, in a multi-step authentication
  1070. * algorithm, the station already exists in the driver
  1071. * (sta->added_unassoc = 1) so skip it.
  1072. *
  1073. * In mesh mode, the station was already added to the driver when the
  1074. * NEW_PEER_CANDIDATE event is received.
  1075. */
  1076. if (FULL_AP_CLIENT_STATE_SUPP(hapd->iface->drv_flags) &&
  1077. !(hapd->conf->mesh & MESH_ENABLED) &&
  1078. !(sta->added_unassoc)) {
  1079. /*
  1080. * If a station that is already associated to the AP, is trying
  1081. * to authenticate again, remove the STA entry, in order to make
  1082. * sure the STA PS state gets cleared and configuration gets
  1083. * updated. To handle this, station's added_unassoc flag is
  1084. * cleared once the station has completed association.
  1085. */
  1086. hostapd_drv_sta_remove(hapd, sta->addr);
  1087. sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_AUTH |
  1088. WLAN_STA_AUTHORIZED);
  1089. if (hostapd_sta_add(hapd, sta->addr, 0, 0, NULL, 0, 0,
  1090. NULL, NULL, sta->flags, 0, 0, 0, 0)) {
  1091. hostapd_logger(hapd, sta->addr,
  1092. HOSTAPD_MODULE_IEEE80211,
  1093. HOSTAPD_LEVEL_NOTICE,
  1094. "Could not add STA to kernel driver");
  1095. resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
  1096. goto fail;
  1097. }
  1098. sta->added_unassoc = 1;
  1099. }
  1100. switch (auth_alg) {
  1101. case WLAN_AUTH_OPEN:
  1102. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1103. HOSTAPD_LEVEL_DEBUG,
  1104. "authentication OK (open system)");
  1105. sta->flags |= WLAN_STA_AUTH;
  1106. wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
  1107. sta->auth_alg = WLAN_AUTH_OPEN;
  1108. mlme_authenticate_indication(hapd, sta);
  1109. break;
  1110. #ifndef CONFIG_NO_RC4
  1111. case WLAN_AUTH_SHARED_KEY:
  1112. resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
  1113. fc & WLAN_FC_ISWEP);
  1114. sta->auth_alg = WLAN_AUTH_SHARED_KEY;
  1115. mlme_authenticate_indication(hapd, sta);
  1116. if (sta->challenge && auth_transaction == 1) {
  1117. resp_ies[0] = WLAN_EID_CHALLENGE;
  1118. resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
  1119. os_memcpy(resp_ies + 2, sta->challenge,
  1120. WLAN_AUTH_CHALLENGE_LEN);
  1121. resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
  1122. }
  1123. break;
  1124. #endif /* CONFIG_NO_RC4 */
  1125. #ifdef CONFIG_IEEE80211R
  1126. case WLAN_AUTH_FT:
  1127. sta->auth_alg = WLAN_AUTH_FT;
  1128. if (sta->wpa_sm == NULL)
  1129. sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
  1130. sta->addr, NULL);
  1131. if (sta->wpa_sm == NULL) {
  1132. wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
  1133. "state machine");
  1134. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1135. goto fail;
  1136. }
  1137. wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
  1138. auth_transaction, mgmt->u.auth.variable,
  1139. len - IEEE80211_HDRLEN -
  1140. sizeof(mgmt->u.auth),
  1141. handle_auth_ft_finish, hapd);
  1142. /* handle_auth_ft_finish() callback will complete auth. */
  1143. return;
  1144. #endif /* CONFIG_IEEE80211R */
  1145. #ifdef CONFIG_SAE
  1146. case WLAN_AUTH_SAE:
  1147. #ifdef CONFIG_MESH
  1148. if (status_code == WLAN_STATUS_SUCCESS &&
  1149. hapd->conf->mesh & MESH_ENABLED) {
  1150. if (sta->wpa_sm == NULL)
  1151. sta->wpa_sm =
  1152. wpa_auth_sta_init(hapd->wpa_auth,
  1153. sta->addr, NULL);
  1154. if (sta->wpa_sm == NULL) {
  1155. wpa_printf(MSG_DEBUG,
  1156. "SAE: Failed to initialize WPA state machine");
  1157. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1158. goto fail;
  1159. }
  1160. }
  1161. #endif /* CONFIG_MESH */
  1162. handle_auth_sae(hapd, sta, mgmt, len, auth_transaction,
  1163. status_code);
  1164. return;
  1165. #endif /* CONFIG_SAE */
  1166. }
  1167. fail:
  1168. os_free(identity);
  1169. os_free(radius_cui);
  1170. hostapd_free_psk_list(psk);
  1171. reply_res = send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
  1172. auth_transaction + 1, resp, resp_ies,
  1173. resp_ies_len);
  1174. if (sta && sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
  1175. reply_res != WLAN_STATUS_SUCCESS)) {
  1176. hostapd_drv_sta_remove(hapd, sta->addr);
  1177. sta->added_unassoc = 0;
  1178. }
  1179. }
  1180. int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
  1181. {
  1182. int i, j = 32, aid;
  1183. /* get a unique AID */
  1184. if (sta->aid > 0) {
  1185. wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
  1186. return 0;
  1187. }
  1188. if (TEST_FAIL())
  1189. return -1;
  1190. for (i = 0; i < AID_WORDS; i++) {
  1191. if (hapd->sta_aid[i] == (u32) -1)
  1192. continue;
  1193. for (j = 0; j < 32; j++) {
  1194. if (!(hapd->sta_aid[i] & BIT(j)))
  1195. break;
  1196. }
  1197. if (j < 32)
  1198. break;
  1199. }
  1200. if (j == 32)
  1201. return -1;
  1202. aid = i * 32 + j + 1;
  1203. if (aid > 2007)
  1204. return -1;
  1205. sta->aid = aid;
  1206. hapd->sta_aid[i] |= BIT(j);
  1207. wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
  1208. return 0;
  1209. }
  1210. static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
  1211. const u8 *ssid_ie, size_t ssid_ie_len)
  1212. {
  1213. if (ssid_ie == NULL)
  1214. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1215. if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
  1216. os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
  1217. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1218. HOSTAPD_LEVEL_INFO,
  1219. "Station tried to associate with unknown SSID "
  1220. "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
  1221. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1222. }
  1223. return WLAN_STATUS_SUCCESS;
  1224. }
  1225. static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
  1226. const u8 *wmm_ie, size_t wmm_ie_len)
  1227. {
  1228. sta->flags &= ~WLAN_STA_WMM;
  1229. sta->qosinfo = 0;
  1230. if (wmm_ie && hapd->conf->wmm_enabled) {
  1231. struct wmm_information_element *wmm;
  1232. if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
  1233. hostapd_logger(hapd, sta->addr,
  1234. HOSTAPD_MODULE_WPA,
  1235. HOSTAPD_LEVEL_DEBUG,
  1236. "invalid WMM element in association "
  1237. "request");
  1238. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1239. }
  1240. sta->flags |= WLAN_STA_WMM;
  1241. wmm = (struct wmm_information_element *) wmm_ie;
  1242. sta->qosinfo = wmm->qos_info;
  1243. }
  1244. return WLAN_STATUS_SUCCESS;
  1245. }
  1246. static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
  1247. struct ieee802_11_elems *elems)
  1248. {
  1249. if (!elems->supp_rates) {
  1250. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1251. HOSTAPD_LEVEL_DEBUG,
  1252. "No supported rates element in AssocReq");
  1253. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1254. }
  1255. if (elems->supp_rates_len + elems->ext_supp_rates_len >
  1256. sizeof(sta->supported_rates)) {
  1257. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1258. HOSTAPD_LEVEL_DEBUG,
  1259. "Invalid supported rates element length %d+%d",
  1260. elems->supp_rates_len,
  1261. elems->ext_supp_rates_len);
  1262. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1263. }
  1264. sta->supported_rates_len = merge_byte_arrays(
  1265. sta->supported_rates, sizeof(sta->supported_rates),
  1266. elems->supp_rates, elems->supp_rates_len,
  1267. elems->ext_supp_rates, elems->ext_supp_rates_len);
  1268. return WLAN_STATUS_SUCCESS;
  1269. }
  1270. static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
  1271. const u8 *ext_capab_ie, size_t ext_capab_ie_len)
  1272. {
  1273. #ifdef CONFIG_INTERWORKING
  1274. /* check for QoS Map support */
  1275. if (ext_capab_ie_len >= 5) {
  1276. if (ext_capab_ie[4] & 0x01)
  1277. sta->qos_map_enabled = 1;
  1278. }
  1279. #endif /* CONFIG_INTERWORKING */
  1280. if (ext_capab_ie_len > 0)
  1281. sta->ecsa_supported = !!(ext_capab_ie[0] & BIT(2));
  1282. return WLAN_STATUS_SUCCESS;
  1283. }
  1284. static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
  1285. const u8 *ies, size_t ies_len, int reassoc)
  1286. {
  1287. struct ieee802_11_elems elems;
  1288. u16 resp;
  1289. const u8 *wpa_ie;
  1290. size_t wpa_ie_len;
  1291. const u8 *p2p_dev_addr = NULL;
  1292. if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
  1293. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1294. HOSTAPD_LEVEL_INFO, "Station sent an invalid "
  1295. "association request");
  1296. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1297. }
  1298. resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
  1299. if (resp != WLAN_STATUS_SUCCESS)
  1300. return resp;
  1301. resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
  1302. if (resp != WLAN_STATUS_SUCCESS)
  1303. return resp;
  1304. resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
  1305. if (resp != WLAN_STATUS_SUCCESS)
  1306. return resp;
  1307. resp = copy_supp_rates(hapd, sta, &elems);
  1308. if (resp != WLAN_STATUS_SUCCESS)
  1309. return resp;
  1310. #ifdef CONFIG_IEEE80211N
  1311. resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities);
  1312. if (resp != WLAN_STATUS_SUCCESS)
  1313. return resp;
  1314. if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
  1315. !(sta->flags & WLAN_STA_HT)) {
  1316. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1317. HOSTAPD_LEVEL_INFO, "Station does not support "
  1318. "mandatory HT PHY - reject association");
  1319. return WLAN_STATUS_ASSOC_DENIED_NO_HT;
  1320. }
  1321. #endif /* CONFIG_IEEE80211N */
  1322. #ifdef CONFIG_IEEE80211AC
  1323. if (hapd->iconf->ieee80211ac) {
  1324. resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities);
  1325. if (resp != WLAN_STATUS_SUCCESS)
  1326. return resp;
  1327. resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
  1328. if (resp != WLAN_STATUS_SUCCESS)
  1329. return resp;
  1330. }
  1331. if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
  1332. !(sta->flags & WLAN_STA_VHT)) {
  1333. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1334. HOSTAPD_LEVEL_INFO, "Station does not support "
  1335. "mandatory VHT PHY - reject association");
  1336. return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
  1337. }
  1338. if (hapd->conf->vendor_vht && !elems.vht_capabilities) {
  1339. resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht,
  1340. elems.vendor_vht_len);
  1341. if (resp != WLAN_STATUS_SUCCESS)
  1342. return resp;
  1343. }
  1344. #endif /* CONFIG_IEEE80211AC */
  1345. #ifdef CONFIG_P2P
  1346. if (elems.p2p) {
  1347. wpabuf_free(sta->p2p_ie);
  1348. sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
  1349. P2P_IE_VENDOR_TYPE);
  1350. if (sta->p2p_ie)
  1351. p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
  1352. } else {
  1353. wpabuf_free(sta->p2p_ie);
  1354. sta->p2p_ie = NULL;
  1355. }
  1356. #endif /* CONFIG_P2P */
  1357. if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
  1358. wpa_ie = elems.rsn_ie;
  1359. wpa_ie_len = elems.rsn_ie_len;
  1360. } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
  1361. elems.wpa_ie) {
  1362. wpa_ie = elems.wpa_ie;
  1363. wpa_ie_len = elems.wpa_ie_len;
  1364. } else {
  1365. wpa_ie = NULL;
  1366. wpa_ie_len = 0;
  1367. }
  1368. #ifdef CONFIG_WPS
  1369. sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
  1370. if (hapd->conf->wps_state && elems.wps_ie) {
  1371. wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
  1372. "Request - assume WPS is used");
  1373. sta->flags |= WLAN_STA_WPS;
  1374. wpabuf_free(sta->wps_ie);
  1375. sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
  1376. WPS_IE_VENDOR_TYPE);
  1377. if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
  1378. wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
  1379. sta->flags |= WLAN_STA_WPS2;
  1380. }
  1381. wpa_ie = NULL;
  1382. wpa_ie_len = 0;
  1383. if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
  1384. wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
  1385. "(Re)Association Request - reject");
  1386. return WLAN_STATUS_INVALID_IE;
  1387. }
  1388. } else if (hapd->conf->wps_state && wpa_ie == NULL) {
  1389. wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
  1390. "(Re)Association Request - possible WPS use");
  1391. sta->flags |= WLAN_STA_MAYBE_WPS;
  1392. } else
  1393. #endif /* CONFIG_WPS */
  1394. if (hapd->conf->wpa && wpa_ie == NULL) {
  1395. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1396. HOSTAPD_LEVEL_INFO,
  1397. "No WPA/RSN IE in association request");
  1398. return WLAN_STATUS_INVALID_IE;
  1399. }
  1400. if (hapd->conf->wpa && wpa_ie) {
  1401. int res;
  1402. wpa_ie -= 2;
  1403. wpa_ie_len += 2;
  1404. if (sta->wpa_sm == NULL)
  1405. sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
  1406. sta->addr,
  1407. p2p_dev_addr);
  1408. if (sta->wpa_sm == NULL) {
  1409. wpa_printf(MSG_WARNING, "Failed to initialize WPA "
  1410. "state machine");
  1411. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1412. }
  1413. res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
  1414. wpa_ie, wpa_ie_len,
  1415. elems.mdie, elems.mdie_len);
  1416. if (res == WPA_INVALID_GROUP)
  1417. resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
  1418. else if (res == WPA_INVALID_PAIRWISE)
  1419. resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
  1420. else if (res == WPA_INVALID_AKMP)
  1421. resp = WLAN_STATUS_AKMP_NOT_VALID;
  1422. else if (res == WPA_ALLOC_FAIL)
  1423. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1424. #ifdef CONFIG_IEEE80211W
  1425. else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
  1426. resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
  1427. else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
  1428. resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
  1429. #endif /* CONFIG_IEEE80211W */
  1430. else if (res == WPA_INVALID_MDIE)
  1431. resp = WLAN_STATUS_INVALID_MDIE;
  1432. else if (res != WPA_IE_OK)
  1433. resp = WLAN_STATUS_INVALID_IE;
  1434. if (resp != WLAN_STATUS_SUCCESS)
  1435. return resp;
  1436. #ifdef CONFIG_IEEE80211W
  1437. if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
  1438. sta->sa_query_count > 0)
  1439. ap_check_sa_query_timeout(hapd, sta);
  1440. if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
  1441. (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
  1442. /*
  1443. * STA has already been associated with MFP and SA
  1444. * Query timeout has not been reached. Reject the
  1445. * association attempt temporarily and start SA Query,
  1446. * if one is not pending.
  1447. */
  1448. if (sta->sa_query_count == 0)
  1449. ap_sta_start_sa_query(hapd, sta);
  1450. return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
  1451. }
  1452. if (wpa_auth_uses_mfp(sta->wpa_sm))
  1453. sta->flags |= WLAN_STA_MFP;
  1454. else
  1455. sta->flags &= ~WLAN_STA_MFP;
  1456. #endif /* CONFIG_IEEE80211W */
  1457. #ifdef CONFIG_IEEE80211R
  1458. if (sta->auth_alg == WLAN_AUTH_FT) {
  1459. if (!reassoc) {
  1460. wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
  1461. "to use association (not "
  1462. "re-association) with FT auth_alg",
  1463. MAC2STR(sta->addr));
  1464. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1465. }
  1466. resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
  1467. ies_len);
  1468. if (resp != WLAN_STATUS_SUCCESS)
  1469. return resp;
  1470. }
  1471. #endif /* CONFIG_IEEE80211R */
  1472. #ifdef CONFIG_SAE
  1473. if (wpa_auth_uses_sae(sta->wpa_sm) &&
  1474. sta->auth_alg == WLAN_AUTH_OPEN) {
  1475. struct rsn_pmksa_cache_entry *sa;
  1476. sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
  1477. if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) {
  1478. wpa_printf(MSG_DEBUG,
  1479. "SAE: No PMKSA cache entry found for "
  1480. MACSTR, MAC2STR(sta->addr));
  1481. return WLAN_STATUS_INVALID_PMKID;
  1482. }
  1483. wpa_printf(MSG_DEBUG, "SAE: " MACSTR
  1484. " using PMKSA caching", MAC2STR(sta->addr));
  1485. } else if (wpa_auth_uses_sae(sta->wpa_sm) &&
  1486. sta->auth_alg != WLAN_AUTH_SAE &&
  1487. !(sta->auth_alg == WLAN_AUTH_FT &&
  1488. wpa_auth_uses_ft_sae(sta->wpa_sm))) {
  1489. wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
  1490. "SAE AKM after non-SAE auth_alg %u",
  1491. MAC2STR(sta->addr), sta->auth_alg);
  1492. return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
  1493. }
  1494. #endif /* CONFIG_SAE */
  1495. #ifdef CONFIG_IEEE80211N
  1496. if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
  1497. wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
  1498. hostapd_logger(hapd, sta->addr,
  1499. HOSTAPD_MODULE_IEEE80211,
  1500. HOSTAPD_LEVEL_INFO,
  1501. "Station tried to use TKIP with HT "
  1502. "association");
  1503. return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
  1504. }
  1505. #endif /* CONFIG_IEEE80211N */
  1506. #ifdef CONFIG_HS20
  1507. } else if (hapd->conf->osen) {
  1508. if (elems.osen == NULL) {
  1509. hostapd_logger(
  1510. hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1511. HOSTAPD_LEVEL_INFO,
  1512. "No HS 2.0 OSEN element in association request");
  1513. return WLAN_STATUS_INVALID_IE;
  1514. }
  1515. wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
  1516. if (sta->wpa_sm == NULL)
  1517. sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
  1518. sta->addr, NULL);
  1519. if (sta->wpa_sm == NULL) {
  1520. wpa_printf(MSG_WARNING, "Failed to initialize WPA "
  1521. "state machine");
  1522. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1523. }
  1524. if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
  1525. elems.osen - 2, elems.osen_len + 2) < 0)
  1526. return WLAN_STATUS_INVALID_IE;
  1527. #endif /* CONFIG_HS20 */
  1528. } else
  1529. wpa_auth_sta_no_wpa(sta->wpa_sm);
  1530. #ifdef CONFIG_P2P
  1531. p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
  1532. #endif /* CONFIG_P2P */
  1533. #ifdef CONFIG_HS20
  1534. wpabuf_free(sta->hs20_ie);
  1535. if (elems.hs20 && elems.hs20_len > 4) {
  1536. sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
  1537. elems.hs20_len - 4);
  1538. } else
  1539. sta->hs20_ie = NULL;
  1540. #endif /* CONFIG_HS20 */
  1541. #ifdef CONFIG_FST
  1542. wpabuf_free(sta->mb_ies);
  1543. if (hapd->iface->fst)
  1544. sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
  1545. else
  1546. sta->mb_ies = NULL;
  1547. #endif /* CONFIG_FST */
  1548. #ifdef CONFIG_MBO
  1549. mbo_ap_check_sta_assoc(hapd, sta, &elems);
  1550. if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
  1551. elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
  1552. hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
  1553. wpa_printf(MSG_INFO,
  1554. "MBO: Reject WPA2 association without PMF");
  1555. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1556. }
  1557. #endif /* CONFIG_MBO */
  1558. ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
  1559. elems.supp_op_classes_len);
  1560. if ((sta->capability & WLAN_CAPABILITY_RADIO_MEASUREMENT) &&
  1561. elems.rrm_enabled &&
  1562. elems.rrm_enabled_len >= sizeof(sta->rrm_enabled_capa))
  1563. os_memcpy(sta->rrm_enabled_capa, elems.rrm_enabled,
  1564. sizeof(sta->rrm_enabled_capa));
  1565. return WLAN_STATUS_SUCCESS;
  1566. }
  1567. static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
  1568. u16 reason_code)
  1569. {
  1570. int send_len;
  1571. struct ieee80211_mgmt reply;
  1572. os_memset(&reply, 0, sizeof(reply));
  1573. reply.frame_control =
  1574. IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
  1575. os_memcpy(reply.da, addr, ETH_ALEN);
  1576. os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
  1577. os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
  1578. send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
  1579. reply.u.deauth.reason_code = host_to_le16(reason_code);
  1580. if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
  1581. wpa_printf(MSG_INFO, "Failed to send deauth: %s",
  1582. strerror(errno));
  1583. }
  1584. static int add_associated_sta(struct hostapd_data *hapd,
  1585. struct sta_info *sta)
  1586. {
  1587. struct ieee80211_ht_capabilities ht_cap;
  1588. struct ieee80211_vht_capabilities vht_cap;
  1589. /*
  1590. * Remove the STA entry to ensure the STA PS state gets cleared and
  1591. * configuration gets updated. This is relevant for cases, such as
  1592. * FT-over-the-DS, where a station re-associates back to the same AP but
  1593. * skips the authentication flow, or if working with a driver that
  1594. * does not support full AP client state.
  1595. */
  1596. if (!sta->added_unassoc)
  1597. hostapd_drv_sta_remove(hapd, sta->addr);
  1598. #ifdef CONFIG_IEEE80211N
  1599. if (sta->flags & WLAN_STA_HT)
  1600. hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
  1601. #endif /* CONFIG_IEEE80211N */
  1602. #ifdef CONFIG_IEEE80211AC
  1603. if (sta->flags & WLAN_STA_VHT)
  1604. hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
  1605. #endif /* CONFIG_IEEE80211AC */
  1606. /*
  1607. * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags
  1608. * will be set when the ACK frame for the (Re)Association Response frame
  1609. * is processed (TX status driver event).
  1610. */
  1611. if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
  1612. sta->supported_rates, sta->supported_rates_len,
  1613. sta->listen_interval,
  1614. sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
  1615. sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
  1616. sta->flags | WLAN_STA_ASSOC, sta->qosinfo,
  1617. sta->vht_opmode, sta->p2p_ie ? 1 : 0,
  1618. sta->added_unassoc)) {
  1619. hostapd_logger(hapd, sta->addr,
  1620. HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_NOTICE,
  1621. "Could not %s STA to kernel driver",
  1622. sta->added_unassoc ? "set" : "add");
  1623. if (sta->added_unassoc) {
  1624. hostapd_drv_sta_remove(hapd, sta->addr);
  1625. sta->added_unassoc = 0;
  1626. }
  1627. return -1;
  1628. }
  1629. sta->added_unassoc = 0;
  1630. return 0;
  1631. }
  1632. static u16 send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
  1633. u16 status_code, int reassoc, const u8 *ies,
  1634. size_t ies_len)
  1635. {
  1636. int send_len;
  1637. u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
  1638. struct ieee80211_mgmt *reply;
  1639. u8 *p;
  1640. os_memset(buf, 0, sizeof(buf));
  1641. reply = (struct ieee80211_mgmt *) buf;
  1642. reply->frame_control =
  1643. IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  1644. (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
  1645. WLAN_FC_STYPE_ASSOC_RESP));
  1646. os_memcpy(reply->da, sta->addr, ETH_ALEN);
  1647. os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
  1648. os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
  1649. send_len = IEEE80211_HDRLEN;
  1650. send_len += sizeof(reply->u.assoc_resp);
  1651. reply->u.assoc_resp.capab_info =
  1652. host_to_le16(hostapd_own_capab_info(hapd));
  1653. reply->u.assoc_resp.status_code = host_to_le16(status_code);
  1654. reply->u.assoc_resp.aid = host_to_le16(sta->aid | BIT(14) | BIT(15));
  1655. /* Supported rates */
  1656. p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
  1657. /* Extended supported rates */
  1658. p = hostapd_eid_ext_supp_rates(hapd, p);
  1659. #ifdef CONFIG_IEEE80211R
  1660. if (status_code == WLAN_STATUS_SUCCESS) {
  1661. /* IEEE 802.11r: Mobility Domain Information, Fast BSS
  1662. * Transition Information, RSN, [RIC Response] */
  1663. p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
  1664. buf + sizeof(buf) - p,
  1665. sta->auth_alg, ies, ies_len);
  1666. }
  1667. #endif /* CONFIG_IEEE80211R */
  1668. #ifdef CONFIG_IEEE80211W
  1669. if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
  1670. p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
  1671. #endif /* CONFIG_IEEE80211W */
  1672. #ifdef CONFIG_IEEE80211N
  1673. p = hostapd_eid_ht_capabilities(hapd, p);
  1674. p = hostapd_eid_ht_operation(hapd, p);
  1675. #endif /* CONFIG_IEEE80211N */
  1676. #ifdef CONFIG_IEEE80211AC
  1677. if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
  1678. p = hostapd_eid_vht_capabilities(hapd, p);
  1679. p = hostapd_eid_vht_operation(hapd, p);
  1680. }
  1681. #endif /* CONFIG_IEEE80211AC */
  1682. p = hostapd_eid_ext_capab(hapd, p);
  1683. p = hostapd_eid_bss_max_idle_period(hapd, p);
  1684. if (sta->qos_map_enabled)
  1685. p = hostapd_eid_qos_map_set(hapd, p);
  1686. #ifdef CONFIG_FST
  1687. if (hapd->iface->fst_ies) {
  1688. os_memcpy(p, wpabuf_head(hapd->iface->fst_ies),
  1689. wpabuf_len(hapd->iface->fst_ies));
  1690. p += wpabuf_len(hapd->iface->fst_ies);
  1691. }
  1692. #endif /* CONFIG_FST */
  1693. #ifdef CONFIG_IEEE80211AC
  1694. if (hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT))
  1695. p = hostapd_eid_vendor_vht(hapd, p);
  1696. #endif /* CONFIG_IEEE80211AC */
  1697. if (sta->flags & WLAN_STA_WMM)
  1698. p = hostapd_eid_wmm(hapd, p);
  1699. #ifdef CONFIG_WPS
  1700. if ((sta->flags & WLAN_STA_WPS) ||
  1701. ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
  1702. struct wpabuf *wps = wps_build_assoc_resp_ie();
  1703. if (wps) {
  1704. os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
  1705. p += wpabuf_len(wps);
  1706. wpabuf_free(wps);
  1707. }
  1708. }
  1709. #endif /* CONFIG_WPS */
  1710. #ifdef CONFIG_P2P
  1711. if (sta->p2p_ie && hapd->p2p_group) {
  1712. struct wpabuf *p2p_resp_ie;
  1713. enum p2p_status_code status;
  1714. switch (status_code) {
  1715. case WLAN_STATUS_SUCCESS:
  1716. status = P2P_SC_SUCCESS;
  1717. break;
  1718. case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
  1719. status = P2P_SC_FAIL_LIMIT_REACHED;
  1720. break;
  1721. default:
  1722. status = P2P_SC_FAIL_INVALID_PARAMS;
  1723. break;
  1724. }
  1725. p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
  1726. if (p2p_resp_ie) {
  1727. os_memcpy(p, wpabuf_head(p2p_resp_ie),
  1728. wpabuf_len(p2p_resp_ie));
  1729. p += wpabuf_len(p2p_resp_ie);
  1730. wpabuf_free(p2p_resp_ie);
  1731. }
  1732. }
  1733. #endif /* CONFIG_P2P */
  1734. #ifdef CONFIG_P2P_MANAGER
  1735. if (hapd->conf->p2p & P2P_MANAGE)
  1736. p = hostapd_eid_p2p_manage(hapd, p);
  1737. #endif /* CONFIG_P2P_MANAGER */
  1738. p = hostapd_eid_mbo(hapd, p, buf + sizeof(buf) - p);
  1739. if (hapd->conf->assocresp_elements &&
  1740. (size_t) (buf + sizeof(buf) - p) >=
  1741. wpabuf_len(hapd->conf->assocresp_elements)) {
  1742. os_memcpy(p, wpabuf_head(hapd->conf->assocresp_elements),
  1743. wpabuf_len(hapd->conf->assocresp_elements));
  1744. p += wpabuf_len(hapd->conf->assocresp_elements);
  1745. }
  1746. send_len += p - reply->u.assoc_resp.variable;
  1747. if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0) {
  1748. wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
  1749. strerror(errno));
  1750. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1751. }
  1752. return WLAN_STATUS_SUCCESS;
  1753. }
  1754. static void handle_assoc(struct hostapd_data *hapd,
  1755. const struct ieee80211_mgmt *mgmt, size_t len,
  1756. int reassoc)
  1757. {
  1758. u16 capab_info, listen_interval, seq_ctrl, fc;
  1759. u16 resp = WLAN_STATUS_SUCCESS, reply_res;
  1760. const u8 *pos;
  1761. int left, i;
  1762. struct sta_info *sta;
  1763. if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
  1764. sizeof(mgmt->u.assoc_req))) {
  1765. wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
  1766. reassoc, (unsigned long) len);
  1767. return;
  1768. }
  1769. #ifdef CONFIG_TESTING_OPTIONS
  1770. if (reassoc) {
  1771. if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
  1772. drand48() < hapd->iconf->ignore_reassoc_probability) {
  1773. wpa_printf(MSG_INFO,
  1774. "TESTING: ignoring reassoc request from "
  1775. MACSTR, MAC2STR(mgmt->sa));
  1776. return;
  1777. }
  1778. } else {
  1779. if (hapd->iconf->ignore_assoc_probability > 0.0 &&
  1780. drand48() < hapd->iconf->ignore_assoc_probability) {
  1781. wpa_printf(MSG_INFO,
  1782. "TESTING: ignoring assoc request from "
  1783. MACSTR, MAC2STR(mgmt->sa));
  1784. return;
  1785. }
  1786. }
  1787. #endif /* CONFIG_TESTING_OPTIONS */
  1788. fc = le_to_host16(mgmt->frame_control);
  1789. seq_ctrl = le_to_host16(mgmt->seq_ctrl);
  1790. if (reassoc) {
  1791. capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
  1792. listen_interval = le_to_host16(
  1793. mgmt->u.reassoc_req.listen_interval);
  1794. wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
  1795. " capab_info=0x%02x listen_interval=%d current_ap="
  1796. MACSTR " seq_ctrl=0x%x%s",
  1797. MAC2STR(mgmt->sa), capab_info, listen_interval,
  1798. MAC2STR(mgmt->u.reassoc_req.current_ap),
  1799. seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
  1800. left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
  1801. pos = mgmt->u.reassoc_req.variable;
  1802. } else {
  1803. capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
  1804. listen_interval = le_to_host16(
  1805. mgmt->u.assoc_req.listen_interval);
  1806. wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
  1807. " capab_info=0x%02x listen_interval=%d "
  1808. "seq_ctrl=0x%x%s",
  1809. MAC2STR(mgmt->sa), capab_info, listen_interval,
  1810. seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
  1811. left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
  1812. pos = mgmt->u.assoc_req.variable;
  1813. }
  1814. sta = ap_get_sta(hapd, mgmt->sa);
  1815. #ifdef CONFIG_IEEE80211R
  1816. if (sta && sta->auth_alg == WLAN_AUTH_FT &&
  1817. (sta->flags & WLAN_STA_AUTH) == 0) {
  1818. wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
  1819. "prior to authentication since it is using "
  1820. "over-the-DS FT", MAC2STR(mgmt->sa));
  1821. /*
  1822. * Mark station as authenticated, to avoid adding station
  1823. * entry in the driver as associated and not authenticated
  1824. */
  1825. sta->flags |= WLAN_STA_AUTH;
  1826. } else
  1827. #endif /* CONFIG_IEEE80211R */
  1828. if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
  1829. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1830. HOSTAPD_LEVEL_INFO, "Station tried to "
  1831. "associate before authentication "
  1832. "(aid=%d flags=0x%x)",
  1833. sta ? sta->aid : -1,
  1834. sta ? sta->flags : 0);
  1835. send_deauth(hapd, mgmt->sa,
  1836. WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
  1837. return;
  1838. }
  1839. if ((fc & WLAN_FC_RETRY) &&
  1840. sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
  1841. sta->last_seq_ctrl == seq_ctrl &&
  1842. sta->last_subtype == reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
  1843. WLAN_FC_STYPE_ASSOC_REQ) {
  1844. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1845. HOSTAPD_LEVEL_DEBUG,
  1846. "Drop repeated association frame seq_ctrl=0x%x",
  1847. seq_ctrl);
  1848. return;
  1849. }
  1850. sta->last_seq_ctrl = seq_ctrl;
  1851. sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
  1852. WLAN_FC_STYPE_ASSOC_REQ;
  1853. if (hapd->tkip_countermeasures) {
  1854. resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
  1855. goto fail;
  1856. }
  1857. if (listen_interval > hapd->conf->max_listen_interval) {
  1858. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1859. HOSTAPD_LEVEL_DEBUG,
  1860. "Too large Listen Interval (%d)",
  1861. listen_interval);
  1862. resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
  1863. goto fail;
  1864. }
  1865. #ifdef CONFIG_MBO
  1866. if (hapd->conf->mbo_enabled && hapd->mbo_assoc_disallow) {
  1867. resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
  1868. goto fail;
  1869. }
  1870. #endif /* CONFIG_MBO */
  1871. /*
  1872. * sta->capability is used in check_assoc_ies() for RRM enabled
  1873. * capability element.
  1874. */
  1875. sta->capability = capab_info;
  1876. /* followed by SSID and Supported rates; and HT capabilities if 802.11n
  1877. * is used */
  1878. resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
  1879. if (resp != WLAN_STATUS_SUCCESS)
  1880. goto fail;
  1881. if (hostapd_get_aid(hapd, sta) < 0) {
  1882. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1883. HOSTAPD_LEVEL_INFO, "No room for more AIDs");
  1884. resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
  1885. goto fail;
  1886. }
  1887. sta->listen_interval = listen_interval;
  1888. if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
  1889. sta->flags |= WLAN_STA_NONERP;
  1890. for (i = 0; i < sta->supported_rates_len; i++) {
  1891. if ((sta->supported_rates[i] & 0x7f) > 22) {
  1892. sta->flags &= ~WLAN_STA_NONERP;
  1893. break;
  1894. }
  1895. }
  1896. if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
  1897. sta->nonerp_set = 1;
  1898. hapd->iface->num_sta_non_erp++;
  1899. if (hapd->iface->num_sta_non_erp == 1)
  1900. ieee802_11_set_beacons(hapd->iface);
  1901. }
  1902. if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
  1903. !sta->no_short_slot_time_set) {
  1904. sta->no_short_slot_time_set = 1;
  1905. hapd->iface->num_sta_no_short_slot_time++;
  1906. if (hapd->iface->current_mode->mode ==
  1907. HOSTAPD_MODE_IEEE80211G &&
  1908. hapd->iface->num_sta_no_short_slot_time == 1)
  1909. ieee802_11_set_beacons(hapd->iface);
  1910. }
  1911. if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  1912. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  1913. else
  1914. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  1915. if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
  1916. !sta->no_short_preamble_set) {
  1917. sta->no_short_preamble_set = 1;
  1918. hapd->iface->num_sta_no_short_preamble++;
  1919. if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
  1920. && hapd->iface->num_sta_no_short_preamble == 1)
  1921. ieee802_11_set_beacons(hapd->iface);
  1922. }
  1923. #ifdef CONFIG_IEEE80211N
  1924. update_ht_state(hapd, sta);
  1925. #endif /* CONFIG_IEEE80211N */
  1926. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1927. HOSTAPD_LEVEL_DEBUG,
  1928. "association OK (aid %d)", sta->aid);
  1929. /* Station will be marked associated, after it acknowledges AssocResp
  1930. */
  1931. sta->flags |= WLAN_STA_ASSOC_REQ_OK;
  1932. #ifdef CONFIG_IEEE80211W
  1933. if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
  1934. wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
  1935. "SA Query procedure", reassoc ? "re" : "");
  1936. /* TODO: Send a protected Disassociate frame to the STA using
  1937. * the old key and Reason Code "Previous Authentication no
  1938. * longer valid". Make sure this is only sent protected since
  1939. * unprotected frame would be received by the STA that is now
  1940. * trying to associate.
  1941. */
  1942. }
  1943. #endif /* CONFIG_IEEE80211W */
  1944. /* Make sure that the previously registered inactivity timer will not
  1945. * remove the STA immediately. */
  1946. sta->timeout_next = STA_NULLFUNC;
  1947. fail:
  1948. /*
  1949. * In case of a successful response, add the station to the driver.
  1950. * Otherwise, the kernel may ignore Data frames before we process the
  1951. * ACK frame (TX status). In case of a failure, this station will be
  1952. * removed.
  1953. *
  1954. * Note that this is not compliant with the IEEE 802.11 standard that
  1955. * states that a non-AP station should transition into the
  1956. * authenticated/associated state only after the station acknowledges
  1957. * the (Re)Association Response frame. However, still do this as:
  1958. *
  1959. * 1. In case the station does not acknowledge the (Re)Association
  1960. * Response frame, it will be removed.
  1961. * 2. Data frames will be dropped in the kernel until the station is
  1962. * set into authorized state, and there are no significant known
  1963. * issues with processing other non-Data Class 3 frames during this
  1964. * window.
  1965. */
  1966. if (resp == WLAN_STATUS_SUCCESS && add_associated_sta(hapd, sta))
  1967. resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
  1968. reply_res = send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
  1969. /*
  1970. * Remove the station in case tranmission of a success response fails
  1971. * (the STA was added associated to the driver) or if the station was
  1972. * previously added unassociated.
  1973. */
  1974. if ((reply_res != WLAN_STATUS_SUCCESS &&
  1975. resp == WLAN_STATUS_SUCCESS) || sta->added_unassoc) {
  1976. hostapd_drv_sta_remove(hapd, sta->addr);
  1977. sta->added_unassoc = 0;
  1978. }
  1979. }
  1980. static void handle_disassoc(struct hostapd_data *hapd,
  1981. const struct ieee80211_mgmt *mgmt, size_t len)
  1982. {
  1983. struct sta_info *sta;
  1984. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
  1985. wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
  1986. (unsigned long) len);
  1987. return;
  1988. }
  1989. wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
  1990. MAC2STR(mgmt->sa),
  1991. le_to_host16(mgmt->u.disassoc.reason_code));
  1992. sta = ap_get_sta(hapd, mgmt->sa);
  1993. if (sta == NULL) {
  1994. wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
  1995. MAC2STR(mgmt->sa));
  1996. return;
  1997. }
  1998. ap_sta_set_authorized(hapd, sta, 0);
  1999. sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
  2000. sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
  2001. wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
  2002. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  2003. HOSTAPD_LEVEL_INFO, "disassociated");
  2004. sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
  2005. ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
  2006. /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
  2007. * authenticated. */
  2008. accounting_sta_stop(hapd, sta);
  2009. ieee802_1x_free_station(hapd, sta);
  2010. if (sta->ipaddr)
  2011. hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
  2012. ap_sta_ip6addr_del(hapd, sta);
  2013. hostapd_drv_sta_remove(hapd, sta->addr);
  2014. sta->added_unassoc = 0;
  2015. if (sta->timeout_next == STA_NULLFUNC ||
  2016. sta->timeout_next == STA_DISASSOC) {
  2017. sta->timeout_next = STA_DEAUTH;
  2018. eloop_cancel_timeout(ap_handle_timer, hapd, sta);
  2019. eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
  2020. hapd, sta);
  2021. }
  2022. mlme_disassociate_indication(
  2023. hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
  2024. }
  2025. static void handle_deauth(struct hostapd_data *hapd,
  2026. const struct ieee80211_mgmt *mgmt, size_t len)
  2027. {
  2028. struct sta_info *sta;
  2029. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
  2030. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
  2031. "payload (len=%lu)", (unsigned long) len);
  2032. return;
  2033. }
  2034. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
  2035. " reason_code=%d",
  2036. MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
  2037. sta = ap_get_sta(hapd, mgmt->sa);
  2038. if (sta == NULL) {
  2039. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
  2040. "to deauthenticate, but it is not authenticated",
  2041. MAC2STR(mgmt->sa));
  2042. return;
  2043. }
  2044. ap_sta_set_authorized(hapd, sta, 0);
  2045. sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
  2046. sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
  2047. WLAN_STA_ASSOC_REQ_OK);
  2048. wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
  2049. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  2050. HOSTAPD_LEVEL_DEBUG, "deauthenticated");
  2051. mlme_deauthenticate_indication(
  2052. hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
  2053. sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
  2054. ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
  2055. ap_free_sta(hapd, sta);
  2056. }
  2057. static void handle_beacon(struct hostapd_data *hapd,
  2058. const struct ieee80211_mgmt *mgmt, size_t len,
  2059. struct hostapd_frame_info *fi)
  2060. {
  2061. struct ieee802_11_elems elems;
  2062. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
  2063. wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
  2064. (unsigned long) len);
  2065. return;
  2066. }
  2067. (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
  2068. len - (IEEE80211_HDRLEN +
  2069. sizeof(mgmt->u.beacon)), &elems,
  2070. 0);
  2071. ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
  2072. }
  2073. #ifdef CONFIG_IEEE80211W
  2074. static int hostapd_sa_query_action(struct hostapd_data *hapd,
  2075. const struct ieee80211_mgmt *mgmt,
  2076. size_t len)
  2077. {
  2078. const u8 *end;
  2079. end = mgmt->u.action.u.sa_query_resp.trans_id +
  2080. WLAN_SA_QUERY_TR_ID_LEN;
  2081. if (((u8 *) mgmt) + len < end) {
  2082. wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
  2083. "frame (len=%lu)", (unsigned long) len);
  2084. return 0;
  2085. }
  2086. ieee802_11_sa_query_action(hapd, mgmt->sa,
  2087. mgmt->u.action.u.sa_query_resp.action,
  2088. mgmt->u.action.u.sa_query_resp.trans_id);
  2089. return 1;
  2090. }
  2091. static int robust_action_frame(u8 category)
  2092. {
  2093. return category != WLAN_ACTION_PUBLIC &&
  2094. category != WLAN_ACTION_HT;
  2095. }
  2096. #endif /* CONFIG_IEEE80211W */
  2097. static int handle_action(struct hostapd_data *hapd,
  2098. const struct ieee80211_mgmt *mgmt, size_t len)
  2099. {
  2100. struct sta_info *sta;
  2101. sta = ap_get_sta(hapd, mgmt->sa);
  2102. if (len < IEEE80211_HDRLEN + 1) {
  2103. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  2104. HOSTAPD_LEVEL_DEBUG,
  2105. "handle_action - too short payload (len=%lu)",
  2106. (unsigned long) len);
  2107. return 0;
  2108. }
  2109. if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
  2110. (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
  2111. wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
  2112. "frame (category=%u) from unassociated STA " MACSTR,
  2113. MAC2STR(mgmt->sa), mgmt->u.action.category);
  2114. return 0;
  2115. }
  2116. #ifdef CONFIG_IEEE80211W
  2117. if (sta && (sta->flags & WLAN_STA_MFP) &&
  2118. !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
  2119. robust_action_frame(mgmt->u.action.category)) {
  2120. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  2121. HOSTAPD_LEVEL_DEBUG,
  2122. "Dropped unprotected Robust Action frame from "
  2123. "an MFP STA");
  2124. return 0;
  2125. }
  2126. #endif /* CONFIG_IEEE80211W */
  2127. if (sta) {
  2128. u16 fc = le_to_host16(mgmt->frame_control);
  2129. u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
  2130. if ((fc & WLAN_FC_RETRY) &&
  2131. sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
  2132. sta->last_seq_ctrl == seq_ctrl &&
  2133. sta->last_subtype == WLAN_FC_STYPE_ACTION) {
  2134. hostapd_logger(hapd, sta->addr,
  2135. HOSTAPD_MODULE_IEEE80211,
  2136. HOSTAPD_LEVEL_DEBUG,
  2137. "Drop repeated action frame seq_ctrl=0x%x",
  2138. seq_ctrl);
  2139. return 1;
  2140. }
  2141. sta->last_seq_ctrl = seq_ctrl;
  2142. sta->last_subtype = WLAN_FC_STYPE_ACTION;
  2143. }
  2144. switch (mgmt->u.action.category) {
  2145. #ifdef CONFIG_IEEE80211R
  2146. case WLAN_ACTION_FT:
  2147. if (!sta ||
  2148. wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
  2149. len - IEEE80211_HDRLEN))
  2150. break;
  2151. return 1;
  2152. #endif /* CONFIG_IEEE80211R */
  2153. case WLAN_ACTION_WMM:
  2154. hostapd_wmm_action(hapd, mgmt, len);
  2155. return 1;
  2156. #ifdef CONFIG_IEEE80211W
  2157. case WLAN_ACTION_SA_QUERY:
  2158. return hostapd_sa_query_action(hapd, mgmt, len);
  2159. #endif /* CONFIG_IEEE80211W */
  2160. #ifdef CONFIG_WNM
  2161. case WLAN_ACTION_WNM:
  2162. ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
  2163. return 1;
  2164. #endif /* CONFIG_WNM */
  2165. #ifdef CONFIG_FST
  2166. case WLAN_ACTION_FST:
  2167. if (hapd->iface->fst)
  2168. fst_rx_action(hapd->iface->fst, mgmt, len);
  2169. else
  2170. wpa_printf(MSG_DEBUG,
  2171. "FST: Ignore FST Action frame - no FST attached");
  2172. return 1;
  2173. #endif /* CONFIG_FST */
  2174. case WLAN_ACTION_PUBLIC:
  2175. case WLAN_ACTION_PROTECTED_DUAL:
  2176. #ifdef CONFIG_IEEE80211N
  2177. if (len >= IEEE80211_HDRLEN + 2 &&
  2178. mgmt->u.action.u.public_action.action ==
  2179. WLAN_PA_20_40_BSS_COEX) {
  2180. wpa_printf(MSG_DEBUG,
  2181. "HT20/40 coex mgmt frame received from STA "
  2182. MACSTR, MAC2STR(mgmt->sa));
  2183. hostapd_2040_coex_action(hapd, mgmt, len);
  2184. }
  2185. #endif /* CONFIG_IEEE80211N */
  2186. if (hapd->public_action_cb) {
  2187. hapd->public_action_cb(hapd->public_action_cb_ctx,
  2188. (u8 *) mgmt, len,
  2189. hapd->iface->freq);
  2190. }
  2191. if (hapd->public_action_cb2) {
  2192. hapd->public_action_cb2(hapd->public_action_cb2_ctx,
  2193. (u8 *) mgmt, len,
  2194. hapd->iface->freq);
  2195. }
  2196. if (hapd->public_action_cb || hapd->public_action_cb2)
  2197. return 1;
  2198. break;
  2199. case WLAN_ACTION_VENDOR_SPECIFIC:
  2200. if (hapd->vendor_action_cb) {
  2201. if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
  2202. (u8 *) mgmt, len,
  2203. hapd->iface->freq) == 0)
  2204. return 1;
  2205. }
  2206. break;
  2207. case WLAN_ACTION_RADIO_MEASUREMENT:
  2208. hostapd_handle_radio_measurement(hapd, (const u8 *) mgmt, len);
  2209. return 1;
  2210. }
  2211. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  2212. HOSTAPD_LEVEL_DEBUG,
  2213. "handle_action - unknown action category %d or invalid "
  2214. "frame",
  2215. mgmt->u.action.category);
  2216. if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
  2217. !(mgmt->sa[0] & 0x01)) {
  2218. struct ieee80211_mgmt *resp;
  2219. /*
  2220. * IEEE 802.11-REVma/D9.0 - 7.3.1.11
  2221. * Return the Action frame to the source without change
  2222. * except that MSB of the Category set to 1.
  2223. */
  2224. wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
  2225. "frame back to sender");
  2226. resp = os_malloc(len);
  2227. if (resp == NULL)
  2228. return 0;
  2229. os_memcpy(resp, mgmt, len);
  2230. os_memcpy(resp->da, resp->sa, ETH_ALEN);
  2231. os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
  2232. os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
  2233. resp->u.action.category |= 0x80;
  2234. if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
  2235. wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
  2236. "Action frame");
  2237. }
  2238. os_free(resp);
  2239. }
  2240. return 1;
  2241. }
  2242. /**
  2243. * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
  2244. * @hapd: hostapd BSS data structure (the BSS to which the management frame was
  2245. * sent to)
  2246. * @buf: management frame data (starting from IEEE 802.11 header)
  2247. * @len: length of frame data in octets
  2248. * @fi: meta data about received frame (signal level, etc.)
  2249. *
  2250. * Process all incoming IEEE 802.11 management frames. This will be called for
  2251. * each frame received from the kernel driver through wlan#ap interface. In
  2252. * addition, it can be called to re-inserted pending frames (e.g., when using
  2253. * external RADIUS server as an MAC ACL).
  2254. */
  2255. int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
  2256. struct hostapd_frame_info *fi)
  2257. {
  2258. struct ieee80211_mgmt *mgmt;
  2259. int broadcast;
  2260. u16 fc, stype;
  2261. int ret = 0;
  2262. if (len < 24)
  2263. return 0;
  2264. mgmt = (struct ieee80211_mgmt *) buf;
  2265. fc = le_to_host16(mgmt->frame_control);
  2266. stype = WLAN_FC_GET_STYPE(fc);
  2267. if (stype == WLAN_FC_STYPE_BEACON) {
  2268. handle_beacon(hapd, mgmt, len, fi);
  2269. return 1;
  2270. }
  2271. broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
  2272. mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
  2273. mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
  2274. if (!broadcast &&
  2275. #ifdef CONFIG_P2P
  2276. /* Invitation responses can be sent with the peer MAC as BSSID */
  2277. !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
  2278. stype == WLAN_FC_STYPE_ACTION) &&
  2279. #endif /* CONFIG_P2P */
  2280. #ifdef CONFIG_MESH
  2281. !(hapd->conf->mesh & MESH_ENABLED) &&
  2282. #endif /* CONFIG_MESH */
  2283. os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
  2284. wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
  2285. MAC2STR(mgmt->bssid));
  2286. return 0;
  2287. }
  2288. if (stype == WLAN_FC_STYPE_PROBE_REQ) {
  2289. handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
  2290. return 1;
  2291. }
  2292. if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
  2293. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  2294. HOSTAPD_LEVEL_DEBUG,
  2295. "MGMT: DA=" MACSTR " not our address",
  2296. MAC2STR(mgmt->da));
  2297. return 0;
  2298. }
  2299. if (hapd->iconf->track_sta_max_num)
  2300. sta_track_add(hapd->iface, mgmt->sa);
  2301. switch (stype) {
  2302. case WLAN_FC_STYPE_AUTH:
  2303. wpa_printf(MSG_DEBUG, "mgmt::auth");
  2304. handle_auth(hapd, mgmt, len);
  2305. ret = 1;
  2306. break;
  2307. case WLAN_FC_STYPE_ASSOC_REQ:
  2308. wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
  2309. handle_assoc(hapd, mgmt, len, 0);
  2310. ret = 1;
  2311. break;
  2312. case WLAN_FC_STYPE_REASSOC_REQ:
  2313. wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
  2314. handle_assoc(hapd, mgmt, len, 1);
  2315. ret = 1;
  2316. break;
  2317. case WLAN_FC_STYPE_DISASSOC:
  2318. wpa_printf(MSG_DEBUG, "mgmt::disassoc");
  2319. handle_disassoc(hapd, mgmt, len);
  2320. ret = 1;
  2321. break;
  2322. case WLAN_FC_STYPE_DEAUTH:
  2323. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
  2324. handle_deauth(hapd, mgmt, len);
  2325. ret = 1;
  2326. break;
  2327. case WLAN_FC_STYPE_ACTION:
  2328. wpa_printf(MSG_DEBUG, "mgmt::action");
  2329. ret = handle_action(hapd, mgmt, len);
  2330. break;
  2331. default:
  2332. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  2333. HOSTAPD_LEVEL_DEBUG,
  2334. "unknown mgmt frame subtype %d", stype);
  2335. break;
  2336. }
  2337. return ret;
  2338. }
  2339. static void handle_auth_cb(struct hostapd_data *hapd,
  2340. const struct ieee80211_mgmt *mgmt,
  2341. size_t len, int ok)
  2342. {
  2343. u16 auth_alg, auth_transaction, status_code;
  2344. struct sta_info *sta;
  2345. sta = ap_get_sta(hapd, mgmt->da);
  2346. if (!sta) {
  2347. wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
  2348. MAC2STR(mgmt->da));
  2349. return;
  2350. }
  2351. auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
  2352. auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
  2353. status_code = le_to_host16(mgmt->u.auth.status_code);
  2354. if (!ok) {
  2355. hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
  2356. HOSTAPD_LEVEL_NOTICE,
  2357. "did not acknowledge authentication response");
  2358. goto fail;
  2359. }
  2360. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
  2361. wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
  2362. (unsigned long) len);
  2363. goto fail;
  2364. }
  2365. if (status_code == WLAN_STATUS_SUCCESS &&
  2366. ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
  2367. (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
  2368. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  2369. HOSTAPD_LEVEL_INFO, "authenticated");
  2370. sta->flags |= WLAN_STA_AUTH;
  2371. if (sta->added_unassoc)
  2372. hostapd_set_sta_flags(hapd, sta);
  2373. return;
  2374. }
  2375. fail:
  2376. if (status_code != WLAN_STATUS_SUCCESS && sta->added_unassoc) {
  2377. hostapd_drv_sta_remove(hapd, sta->addr);
  2378. sta->added_unassoc = 0;
  2379. }
  2380. }
  2381. static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
  2382. struct sta_info *sta,
  2383. char *ifname_wds)
  2384. {
  2385. int i;
  2386. struct hostapd_ssid *ssid = &hapd->conf->ssid;
  2387. if (hapd->conf->ieee802_1x || hapd->conf->wpa)
  2388. return;
  2389. for (i = 0; i < 4; i++) {
  2390. if (ssid->wep.key[i] &&
  2391. hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
  2392. i == ssid->wep.idx, NULL, 0,
  2393. ssid->wep.key[i], ssid->wep.len[i])) {
  2394. wpa_printf(MSG_WARNING,
  2395. "Could not set WEP keys for WDS interface; %s",
  2396. ifname_wds);
  2397. break;
  2398. }
  2399. }
  2400. }
  2401. static void handle_assoc_cb(struct hostapd_data *hapd,
  2402. const struct ieee80211_mgmt *mgmt,
  2403. size_t len, int reassoc, int ok)
  2404. {
  2405. u16 status;
  2406. struct sta_info *sta;
  2407. int new_assoc = 1;
  2408. sta = ap_get_sta(hapd, mgmt->da);
  2409. if (!sta) {
  2410. wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
  2411. MAC2STR(mgmt->da));
  2412. return;
  2413. }
  2414. if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
  2415. sizeof(mgmt->u.assoc_resp))) {
  2416. wpa_printf(MSG_INFO,
  2417. "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
  2418. reassoc, (unsigned long) len);
  2419. hostapd_drv_sta_remove(hapd, sta->addr);
  2420. return;
  2421. }
  2422. if (reassoc)
  2423. status = le_to_host16(mgmt->u.reassoc_resp.status_code);
  2424. else
  2425. status = le_to_host16(mgmt->u.assoc_resp.status_code);
  2426. if (!ok) {
  2427. hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
  2428. HOSTAPD_LEVEL_DEBUG,
  2429. "did not acknowledge association response");
  2430. sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
  2431. /* The STA is added only in case of SUCCESS */
  2432. if (status == WLAN_STATUS_SUCCESS)
  2433. hostapd_drv_sta_remove(hapd, sta->addr);
  2434. return;
  2435. }
  2436. if (status != WLAN_STATUS_SUCCESS)
  2437. return;
  2438. /* Stop previous accounting session, if one is started, and allocate
  2439. * new session id for the new session. */
  2440. accounting_sta_stop(hapd, sta);
  2441. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  2442. HOSTAPD_LEVEL_INFO,
  2443. "associated (aid %d)",
  2444. sta->aid);
  2445. if (sta->flags & WLAN_STA_ASSOC)
  2446. new_assoc = 0;
  2447. sta->flags |= WLAN_STA_ASSOC;
  2448. sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
  2449. if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) ||
  2450. sta->auth_alg == WLAN_AUTH_FT) {
  2451. /*
  2452. * Open, static WEP, or FT protocol; no separate authorization
  2453. * step.
  2454. */
  2455. ap_sta_set_authorized(hapd, sta, 1);
  2456. }
  2457. if (reassoc)
  2458. mlme_reassociate_indication(hapd, sta);
  2459. else
  2460. mlme_associate_indication(hapd, sta);
  2461. #ifdef CONFIG_IEEE80211W
  2462. sta->sa_query_timed_out = 0;
  2463. #endif /* CONFIG_IEEE80211W */
  2464. if (sta->flags & WLAN_STA_WDS) {
  2465. int ret;
  2466. char ifname_wds[IFNAMSIZ + 1];
  2467. ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
  2468. sta->aid, 1);
  2469. if (!ret)
  2470. hostapd_set_wds_encryption(hapd, sta, ifname_wds);
  2471. }
  2472. if (sta->eapol_sm == NULL) {
  2473. /*
  2474. * This STA does not use RADIUS server for EAP authentication,
  2475. * so bind it to the selected VLAN interface now, since the
  2476. * interface selection is not going to change anymore.
  2477. */
  2478. if (ap_sta_bind_vlan(hapd, sta) < 0)
  2479. return;
  2480. } else if (sta->vlan_id) {
  2481. /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
  2482. if (ap_sta_bind_vlan(hapd, sta) < 0)
  2483. return;
  2484. }
  2485. hostapd_set_sta_flags(hapd, sta);
  2486. if (sta->auth_alg == WLAN_AUTH_FT)
  2487. wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
  2488. else
  2489. wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
  2490. hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
  2491. ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
  2492. if (sta->pending_eapol_rx) {
  2493. struct os_reltime now, age;
  2494. os_get_reltime(&now);
  2495. os_reltime_sub(&now, &sta->pending_eapol_rx->rx_time, &age);
  2496. if (age.sec == 0 && age.usec < 200000) {
  2497. wpa_printf(MSG_DEBUG,
  2498. "Process pending EAPOL frame that was received from " MACSTR " just before association notification",
  2499. MAC2STR(sta->addr));
  2500. ieee802_1x_receive(
  2501. hapd, mgmt->da,
  2502. wpabuf_head(sta->pending_eapol_rx->buf),
  2503. wpabuf_len(sta->pending_eapol_rx->buf));
  2504. }
  2505. wpabuf_free(sta->pending_eapol_rx->buf);
  2506. os_free(sta->pending_eapol_rx);
  2507. sta->pending_eapol_rx = NULL;
  2508. }
  2509. }
  2510. static void handle_deauth_cb(struct hostapd_data *hapd,
  2511. const struct ieee80211_mgmt *mgmt,
  2512. size_t len, int ok)
  2513. {
  2514. struct sta_info *sta;
  2515. if (mgmt->da[0] & 0x01)
  2516. return;
  2517. sta = ap_get_sta(hapd, mgmt->da);
  2518. if (!sta) {
  2519. wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
  2520. " not found", MAC2STR(mgmt->da));
  2521. return;
  2522. }
  2523. if (ok)
  2524. wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
  2525. MAC2STR(sta->addr));
  2526. else
  2527. wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
  2528. "deauth", MAC2STR(sta->addr));
  2529. ap_sta_deauth_cb(hapd, sta);
  2530. }
  2531. static void handle_disassoc_cb(struct hostapd_data *hapd,
  2532. const struct ieee80211_mgmt *mgmt,
  2533. size_t len, int ok)
  2534. {
  2535. struct sta_info *sta;
  2536. if (mgmt->da[0] & 0x01)
  2537. return;
  2538. sta = ap_get_sta(hapd, mgmt->da);
  2539. if (!sta) {
  2540. wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
  2541. " not found", MAC2STR(mgmt->da));
  2542. return;
  2543. }
  2544. if (ok)
  2545. wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
  2546. MAC2STR(sta->addr));
  2547. else
  2548. wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
  2549. "disassoc", MAC2STR(sta->addr));
  2550. ap_sta_disassoc_cb(hapd, sta);
  2551. }
  2552. /**
  2553. * ieee802_11_mgmt_cb - Process management frame TX status callback
  2554. * @hapd: hostapd BSS data structure (the BSS from which the management frame
  2555. * was sent from)
  2556. * @buf: management frame data (starting from IEEE 802.11 header)
  2557. * @len: length of frame data in octets
  2558. * @stype: management frame subtype from frame control field
  2559. * @ok: Whether the frame was ACK'ed
  2560. */
  2561. void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
  2562. u16 stype, int ok)
  2563. {
  2564. const struct ieee80211_mgmt *mgmt;
  2565. mgmt = (const struct ieee80211_mgmt *) buf;
  2566. #ifdef CONFIG_TESTING_OPTIONS
  2567. if (hapd->ext_mgmt_frame_handling) {
  2568. wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
  2569. stype, ok);
  2570. return;
  2571. }
  2572. #endif /* CONFIG_TESTING_OPTIONS */
  2573. switch (stype) {
  2574. case WLAN_FC_STYPE_AUTH:
  2575. wpa_printf(MSG_DEBUG, "mgmt::auth cb");
  2576. handle_auth_cb(hapd, mgmt, len, ok);
  2577. break;
  2578. case WLAN_FC_STYPE_ASSOC_RESP:
  2579. wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
  2580. handle_assoc_cb(hapd, mgmt, len, 0, ok);
  2581. break;
  2582. case WLAN_FC_STYPE_REASSOC_RESP:
  2583. wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
  2584. handle_assoc_cb(hapd, mgmt, len, 1, ok);
  2585. break;
  2586. case WLAN_FC_STYPE_PROBE_RESP:
  2587. wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb ok=%d", ok);
  2588. break;
  2589. case WLAN_FC_STYPE_DEAUTH:
  2590. wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
  2591. handle_deauth_cb(hapd, mgmt, len, ok);
  2592. break;
  2593. case WLAN_FC_STYPE_DISASSOC:
  2594. wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
  2595. handle_disassoc_cb(hapd, mgmt, len, ok);
  2596. break;
  2597. case WLAN_FC_STYPE_ACTION:
  2598. wpa_printf(MSG_DEBUG, "mgmt::action cb ok=%d", ok);
  2599. break;
  2600. default:
  2601. wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
  2602. break;
  2603. }
  2604. }
  2605. int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
  2606. {
  2607. /* TODO */
  2608. return 0;
  2609. }
  2610. int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
  2611. char *buf, size_t buflen)
  2612. {
  2613. /* TODO */
  2614. return 0;
  2615. }
  2616. void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
  2617. const u8 *buf, size_t len, int ack)
  2618. {
  2619. struct sta_info *sta;
  2620. struct hostapd_iface *iface = hapd->iface;
  2621. sta = ap_get_sta(hapd, addr);
  2622. if (sta == NULL && iface->num_bss > 1) {
  2623. size_t j;
  2624. for (j = 0; j < iface->num_bss; j++) {
  2625. hapd = iface->bss[j];
  2626. sta = ap_get_sta(hapd, addr);
  2627. if (sta)
  2628. break;
  2629. }
  2630. }
  2631. if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
  2632. return;
  2633. if (sta->flags & WLAN_STA_PENDING_POLL) {
  2634. wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
  2635. "activity poll", MAC2STR(sta->addr),
  2636. ack ? "ACKed" : "did not ACK");
  2637. if (ack)
  2638. sta->flags &= ~WLAN_STA_PENDING_POLL;
  2639. }
  2640. ieee802_1x_tx_status(hapd, sta, buf, len, ack);
  2641. }
  2642. void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
  2643. const u8 *data, size_t len, int ack)
  2644. {
  2645. struct sta_info *sta;
  2646. struct hostapd_iface *iface = hapd->iface;
  2647. sta = ap_get_sta(hapd, dst);
  2648. if (sta == NULL && iface->num_bss > 1) {
  2649. size_t j;
  2650. for (j = 0; j < iface->num_bss; j++) {
  2651. hapd = iface->bss[j];
  2652. sta = ap_get_sta(hapd, dst);
  2653. if (sta)
  2654. break;
  2655. }
  2656. }
  2657. if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
  2658. wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
  2659. MACSTR " that is not currently associated",
  2660. MAC2STR(dst));
  2661. return;
  2662. }
  2663. ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
  2664. }
  2665. void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
  2666. {
  2667. struct sta_info *sta;
  2668. struct hostapd_iface *iface = hapd->iface;
  2669. sta = ap_get_sta(hapd, addr);
  2670. if (sta == NULL && iface->num_bss > 1) {
  2671. size_t j;
  2672. for (j = 0; j < iface->num_bss; j++) {
  2673. hapd = iface->bss[j];
  2674. sta = ap_get_sta(hapd, addr);
  2675. if (sta)
  2676. break;
  2677. }
  2678. }
  2679. if (sta == NULL)
  2680. return;
  2681. wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POLL_OK MACSTR,
  2682. MAC2STR(sta->addr));
  2683. if (!(sta->flags & WLAN_STA_PENDING_POLL))
  2684. return;
  2685. wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
  2686. "activity poll", MAC2STR(sta->addr));
  2687. sta->flags &= ~WLAN_STA_PENDING_POLL;
  2688. }
  2689. void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
  2690. int wds)
  2691. {
  2692. struct sta_info *sta;
  2693. sta = ap_get_sta(hapd, src);
  2694. if (sta && (sta->flags & WLAN_STA_ASSOC)) {
  2695. if (!hapd->conf->wds_sta)
  2696. return;
  2697. if (wds && !(sta->flags & WLAN_STA_WDS)) {
  2698. int ret;
  2699. char ifname_wds[IFNAMSIZ + 1];
  2700. wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
  2701. "STA " MACSTR " (aid %u)",
  2702. MAC2STR(sta->addr), sta->aid);
  2703. sta->flags |= WLAN_STA_WDS;
  2704. ret = hostapd_set_wds_sta(hapd, ifname_wds,
  2705. sta->addr, sta->aid, 1);
  2706. if (!ret)
  2707. hostapd_set_wds_encryption(hapd, sta,
  2708. ifname_wds);
  2709. }
  2710. return;
  2711. }
  2712. wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
  2713. MACSTR, MAC2STR(src));
  2714. if (src[0] & 0x01) {
  2715. /* Broadcast bit set in SA?! Ignore the frame silently. */
  2716. return;
  2717. }
  2718. if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
  2719. wpa_printf(MSG_DEBUG, "Association Response to the STA has "
  2720. "already been sent, but no TX status yet known - "
  2721. "ignore Class 3 frame issue with " MACSTR,
  2722. MAC2STR(src));
  2723. return;
  2724. }
  2725. if (sta && (sta->flags & WLAN_STA_AUTH))
  2726. hostapd_drv_sta_disassoc(
  2727. hapd, src,
  2728. WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
  2729. else
  2730. hostapd_drv_sta_deauth(
  2731. hapd, src,
  2732. WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
  2733. }
  2734. #endif /* CONFIG_NATIVE_WINDOWS */