ieee802_11.c 119 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269
  1. /*
  2. * hostapd / IEEE 802.11 Management
  3. * Copyright (c) 2002-2017, 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. #include "taxonomy.h"
  45. #include "fils_hlp.h"
  46. #include "dpp_hostapd.h"
  47. #include "gas_query_ap.h"
  48. #ifdef CONFIG_FILS
  49. static struct wpabuf *
  50. prepare_auth_resp_fils(struct hostapd_data *hapd,
  51. struct sta_info *sta, u16 *resp,
  52. struct rsn_pmksa_cache_entry *pmksa,
  53. struct wpabuf *erp_resp,
  54. const u8 *msk, size_t msk_len,
  55. int *is_pub);
  56. #endif /* CONFIG_FILS */
  57. u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
  58. {
  59. u8 *pos = eid;
  60. int i, num, count;
  61. if (hapd->iface->current_rates == NULL)
  62. return eid;
  63. *pos++ = WLAN_EID_SUPP_RATES;
  64. num = hapd->iface->num_rates;
  65. if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
  66. num++;
  67. if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
  68. num++;
  69. if (num > 8) {
  70. /* rest of the rates are encoded in Extended supported
  71. * rates element */
  72. num = 8;
  73. }
  74. *pos++ = num;
  75. for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
  76. i++) {
  77. count++;
  78. *pos = hapd->iface->current_rates[i].rate / 5;
  79. if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
  80. *pos |= 0x80;
  81. pos++;
  82. }
  83. if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) {
  84. count++;
  85. *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
  86. }
  87. if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) {
  88. count++;
  89. *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
  90. }
  91. return pos;
  92. }
  93. u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
  94. {
  95. u8 *pos = eid;
  96. int i, num, count;
  97. if (hapd->iface->current_rates == NULL)
  98. return eid;
  99. num = hapd->iface->num_rates;
  100. if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
  101. num++;
  102. if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
  103. num++;
  104. if (num <= 8)
  105. return eid;
  106. num -= 8;
  107. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  108. *pos++ = num;
  109. for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
  110. i++) {
  111. count++;
  112. if (count <= 8)
  113. continue; /* already in SuppRates IE */
  114. *pos = hapd->iface->current_rates[i].rate / 5;
  115. if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
  116. *pos |= 0x80;
  117. pos++;
  118. }
  119. if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
  120. count++;
  121. if (count > 8)
  122. *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
  123. }
  124. if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
  125. count++;
  126. if (count > 8)
  127. *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
  128. }
  129. return pos;
  130. }
  131. u16 hostapd_own_capab_info(struct hostapd_data *hapd)
  132. {
  133. int capab = WLAN_CAPABILITY_ESS;
  134. int privacy;
  135. int dfs;
  136. int i;
  137. /* Check if any of configured channels require DFS */
  138. dfs = hostapd_is_dfs_required(hapd->iface);
  139. if (dfs < 0) {
  140. wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
  141. dfs);
  142. dfs = 0;
  143. }
  144. if (hapd->iface->num_sta_no_short_preamble == 0 &&
  145. hapd->iconf->preamble == SHORT_PREAMBLE)
  146. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  147. privacy = hapd->conf->ssid.wep.keys_set;
  148. if (hapd->conf->ieee802_1x &&
  149. (hapd->conf->default_wep_key_len ||
  150. hapd->conf->individual_wep_key_len))
  151. privacy = 1;
  152. if (hapd->conf->wpa)
  153. privacy = 1;
  154. #ifdef CONFIG_HS20
  155. if (hapd->conf->osen)
  156. privacy = 1;
  157. #endif /* CONFIG_HS20 */
  158. if (privacy)
  159. capab |= WLAN_CAPABILITY_PRIVACY;
  160. if (hapd->iface->current_mode &&
  161. hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
  162. hapd->iface->num_sta_no_short_slot_time == 0)
  163. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  164. /*
  165. * Currently, Spectrum Management capability bit is set when directly
  166. * requested in configuration by spectrum_mgmt_required or when AP is
  167. * running on DFS channel.
  168. * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
  169. */
  170. if (hapd->iface->current_mode &&
  171. hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
  172. (hapd->iconf->spectrum_mgmt_required || dfs))
  173. capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
  174. for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) {
  175. if (hapd->conf->radio_measurements[i]) {
  176. capab |= IEEE80211_CAP_RRM;
  177. break;
  178. }
  179. }
  180. return capab;
  181. }
  182. #ifndef CONFIG_NO_RC4
  183. static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
  184. u16 auth_transaction, const u8 *challenge,
  185. int iswep)
  186. {
  187. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  188. HOSTAPD_LEVEL_DEBUG,
  189. "authentication (shared key, transaction %d)",
  190. auth_transaction);
  191. if (auth_transaction == 1) {
  192. if (!sta->challenge) {
  193. /* Generate a pseudo-random challenge */
  194. u8 key[8];
  195. sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
  196. if (sta->challenge == NULL)
  197. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  198. if (os_get_random(key, sizeof(key)) < 0) {
  199. os_free(sta->challenge);
  200. sta->challenge = NULL;
  201. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  202. }
  203. rc4_skip(key, sizeof(key), 0,
  204. sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
  205. }
  206. return 0;
  207. }
  208. if (auth_transaction != 3)
  209. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  210. /* Transaction 3 */
  211. if (!iswep || !sta->challenge || !challenge ||
  212. os_memcmp_const(sta->challenge, challenge,
  213. WLAN_AUTH_CHALLENGE_LEN)) {
  214. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  215. HOSTAPD_LEVEL_INFO,
  216. "shared key authentication - invalid "
  217. "challenge-response");
  218. return WLAN_STATUS_CHALLENGE_FAIL;
  219. }
  220. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  221. HOSTAPD_LEVEL_DEBUG,
  222. "authentication OK (shared key)");
  223. sta->flags |= WLAN_STA_AUTH;
  224. wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
  225. os_free(sta->challenge);
  226. sta->challenge = NULL;
  227. return 0;
  228. }
  229. #endif /* CONFIG_NO_RC4 */
  230. static int send_auth_reply(struct hostapd_data *hapd,
  231. const u8 *dst, const u8 *bssid,
  232. u16 auth_alg, u16 auth_transaction, u16 resp,
  233. const u8 *ies, size_t ies_len)
  234. {
  235. struct ieee80211_mgmt *reply;
  236. u8 *buf;
  237. size_t rlen;
  238. int reply_res = WLAN_STATUS_UNSPECIFIED_FAILURE;
  239. rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
  240. buf = os_zalloc(rlen);
  241. if (buf == NULL)
  242. return -1;
  243. reply = (struct ieee80211_mgmt *) buf;
  244. reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  245. WLAN_FC_STYPE_AUTH);
  246. os_memcpy(reply->da, dst, ETH_ALEN);
  247. os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
  248. os_memcpy(reply->bssid, bssid, ETH_ALEN);
  249. reply->u.auth.auth_alg = host_to_le16(auth_alg);
  250. reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
  251. reply->u.auth.status_code = host_to_le16(resp);
  252. if (ies && ies_len)
  253. os_memcpy(reply->u.auth.variable, ies, ies_len);
  254. wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
  255. " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
  256. MAC2STR(dst), auth_alg, auth_transaction,
  257. resp, (unsigned long) ies_len);
  258. if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
  259. wpa_printf(MSG_INFO, "send_auth_reply: send failed");
  260. else
  261. reply_res = WLAN_STATUS_SUCCESS;
  262. os_free(buf);
  263. return reply_res;
  264. }
  265. #ifdef CONFIG_IEEE80211R_AP
  266. static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
  267. u16 auth_transaction, u16 status,
  268. const u8 *ies, size_t ies_len)
  269. {
  270. struct hostapd_data *hapd = ctx;
  271. struct sta_info *sta;
  272. int reply_res;
  273. reply_res = send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT,
  274. auth_transaction, status, ies, ies_len);
  275. sta = ap_get_sta(hapd, dst);
  276. if (sta == NULL)
  277. return;
  278. if (sta->added_unassoc && (reply_res != WLAN_STATUS_SUCCESS ||
  279. status != WLAN_STATUS_SUCCESS)) {
  280. hostapd_drv_sta_remove(hapd, sta->addr);
  281. sta->added_unassoc = 0;
  282. return;
  283. }
  284. if (status != WLAN_STATUS_SUCCESS)
  285. return;
  286. hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
  287. HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
  288. sta->flags |= WLAN_STA_AUTH;
  289. mlme_authenticate_indication(hapd, sta);
  290. }
  291. #endif /* CONFIG_IEEE80211R_AP */
  292. #ifdef CONFIG_SAE
  293. #define dot11RSNASAESync 5 /* attempts */
  294. static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd,
  295. struct sta_info *sta, int update)
  296. {
  297. struct wpabuf *buf;
  298. if (hapd->conf->ssid.wpa_passphrase == NULL) {
  299. wpa_printf(MSG_DEBUG, "SAE: No password available");
  300. return NULL;
  301. }
  302. if (update &&
  303. sae_prepare_commit(hapd->own_addr, sta->addr,
  304. (u8 *) hapd->conf->ssid.wpa_passphrase,
  305. os_strlen(hapd->conf->ssid.wpa_passphrase),
  306. sta->sae) < 0) {
  307. wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
  308. return NULL;
  309. }
  310. buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
  311. if (buf == NULL)
  312. return NULL;
  313. sae_write_commit(sta->sae, buf, sta->sae->tmp ?
  314. sta->sae->tmp->anti_clogging_token : NULL);
  315. return buf;
  316. }
  317. static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
  318. struct sta_info *sta)
  319. {
  320. struct wpabuf *buf;
  321. buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
  322. if (buf == NULL)
  323. return NULL;
  324. sae_write_confirm(sta->sae, buf);
  325. return buf;
  326. }
  327. static int auth_sae_send_commit(struct hostapd_data *hapd,
  328. struct sta_info *sta,
  329. const u8 *bssid, int update)
  330. {
  331. struct wpabuf *data;
  332. int reply_res;
  333. data = auth_build_sae_commit(hapd, sta, update);
  334. if (data == NULL)
  335. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  336. reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 1,
  337. WLAN_STATUS_SUCCESS, wpabuf_head(data),
  338. wpabuf_len(data));
  339. wpabuf_free(data);
  340. return reply_res;
  341. }
  342. static int auth_sae_send_confirm(struct hostapd_data *hapd,
  343. struct sta_info *sta,
  344. const u8 *bssid)
  345. {
  346. struct wpabuf *data;
  347. int reply_res;
  348. data = auth_build_sae_confirm(hapd, sta);
  349. if (data == NULL)
  350. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  351. reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 2,
  352. WLAN_STATUS_SUCCESS, wpabuf_head(data),
  353. wpabuf_len(data));
  354. wpabuf_free(data);
  355. return reply_res;
  356. }
  357. static int use_sae_anti_clogging(struct hostapd_data *hapd)
  358. {
  359. struct sta_info *sta;
  360. unsigned int open = 0;
  361. if (hapd->conf->sae_anti_clogging_threshold == 0)
  362. return 1;
  363. for (sta = hapd->sta_list; sta; sta = sta->next) {
  364. if (!sta->sae)
  365. continue;
  366. if (sta->sae->state != SAE_COMMITTED &&
  367. sta->sae->state != SAE_CONFIRMED)
  368. continue;
  369. open++;
  370. if (open >= hapd->conf->sae_anti_clogging_threshold)
  371. return 1;
  372. }
  373. return 0;
  374. }
  375. static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
  376. const u8 *token, size_t token_len)
  377. {
  378. u8 mac[SHA256_MAC_LEN];
  379. if (token_len != SHA256_MAC_LEN)
  380. return -1;
  381. if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
  382. addr, ETH_ALEN, mac) < 0 ||
  383. os_memcmp_const(token, mac, SHA256_MAC_LEN) != 0)
  384. return -1;
  385. return 0;
  386. }
  387. static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
  388. int group, const u8 *addr)
  389. {
  390. struct wpabuf *buf;
  391. u8 *token;
  392. struct os_reltime now;
  393. os_get_reltime(&now);
  394. if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
  395. os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) {
  396. if (random_get_bytes(hapd->sae_token_key,
  397. sizeof(hapd->sae_token_key)) < 0)
  398. return NULL;
  399. wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
  400. hapd->sae_token_key, sizeof(hapd->sae_token_key));
  401. hapd->last_sae_token_key_update = now;
  402. }
  403. buf = wpabuf_alloc(sizeof(le16) + SHA256_MAC_LEN);
  404. if (buf == NULL)
  405. return NULL;
  406. wpabuf_put_le16(buf, group); /* Finite Cyclic Group */
  407. token = wpabuf_put(buf, SHA256_MAC_LEN);
  408. hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
  409. addr, ETH_ALEN, token);
  410. return buf;
  411. }
  412. static int sae_check_big_sync(struct sta_info *sta)
  413. {
  414. if (sta->sae->sync > dot11RSNASAESync) {
  415. sta->sae->state = SAE_NOTHING;
  416. sta->sae->sync = 0;
  417. return -1;
  418. }
  419. return 0;
  420. }
  421. static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data)
  422. {
  423. struct hostapd_data *hapd = eloop_ctx;
  424. struct sta_info *sta = eloop_data;
  425. int ret;
  426. if (sae_check_big_sync(sta))
  427. return;
  428. sta->sae->sync++;
  429. wpa_printf(MSG_DEBUG, "SAE: Auth SAE retransmit timer for " MACSTR
  430. " (sync=%d state=%d)",
  431. MAC2STR(sta->addr), sta->sae->sync, sta->sae->state);
  432. switch (sta->sae->state) {
  433. case SAE_COMMITTED:
  434. ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
  435. eloop_register_timeout(0,
  436. hapd->dot11RSNASAERetransPeriod * 1000,
  437. auth_sae_retransmit_timer, hapd, sta);
  438. break;
  439. case SAE_CONFIRMED:
  440. ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr);
  441. eloop_register_timeout(0,
  442. hapd->dot11RSNASAERetransPeriod * 1000,
  443. auth_sae_retransmit_timer, hapd, sta);
  444. break;
  445. default:
  446. ret = -1;
  447. break;
  448. }
  449. if (ret != WLAN_STATUS_SUCCESS)
  450. wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret);
  451. }
  452. void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta)
  453. {
  454. eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
  455. }
  456. static void sae_set_retransmit_timer(struct hostapd_data *hapd,
  457. struct sta_info *sta)
  458. {
  459. if (!(hapd->conf->mesh & MESH_ENABLED))
  460. return;
  461. eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
  462. eloop_register_timeout(0, hapd->dot11RSNASAERetransPeriod * 1000,
  463. auth_sae_retransmit_timer, hapd, sta);
  464. }
  465. void sae_accept_sta(struct hostapd_data *hapd, struct sta_info *sta)
  466. {
  467. sta->flags |= WLAN_STA_AUTH;
  468. sta->auth_alg = WLAN_AUTH_SAE;
  469. mlme_authenticate_indication(hapd, sta);
  470. wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
  471. sta->sae->state = SAE_ACCEPTED;
  472. wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr,
  473. sta->sae->pmk, sta->sae->pmkid);
  474. }
  475. static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta,
  476. const u8 *bssid, u8 auth_transaction)
  477. {
  478. int ret;
  479. if (auth_transaction != 1 && auth_transaction != 2)
  480. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  481. switch (sta->sae->state) {
  482. case SAE_NOTHING:
  483. if (auth_transaction == 1) {
  484. ret = auth_sae_send_commit(hapd, sta, bssid, 1);
  485. if (ret)
  486. return ret;
  487. sta->sae->state = SAE_COMMITTED;
  488. if (sae_process_commit(sta->sae) < 0)
  489. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  490. /*
  491. * In mesh case, both Commit and Confirm can be sent
  492. * immediately. In infrastructure BSS, only a single
  493. * Authentication frame (Commit) is expected from the AP
  494. * here and the second one (Confirm) will be sent once
  495. * the STA has sent its second Authentication frame
  496. * (Confirm).
  497. */
  498. if (hapd->conf->mesh & MESH_ENABLED) {
  499. /*
  500. * Send both Commit and Confirm immediately
  501. * based on SAE finite state machine
  502. * Nothing -> Confirm transition.
  503. */
  504. ret = auth_sae_send_confirm(hapd, sta, bssid);
  505. if (ret)
  506. return ret;
  507. sta->sae->state = SAE_CONFIRMED;
  508. } else {
  509. /*
  510. * For infrastructure BSS, send only the Commit
  511. * message now to get alternating sequence of
  512. * Authentication frames between the AP and STA.
  513. * Confirm will be sent in
  514. * Committed -> Confirmed/Accepted transition
  515. * when receiving Confirm from STA.
  516. */
  517. }
  518. sta->sae->sync = 0;
  519. sae_set_retransmit_timer(hapd, sta);
  520. } else {
  521. hostapd_logger(hapd, sta->addr,
  522. HOSTAPD_MODULE_IEEE80211,
  523. HOSTAPD_LEVEL_DEBUG,
  524. "SAE confirm before commit");
  525. }
  526. break;
  527. case SAE_COMMITTED:
  528. sae_clear_retransmit_timer(hapd, sta);
  529. if (auth_transaction == 1) {
  530. if (sae_process_commit(sta->sae) < 0)
  531. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  532. ret = auth_sae_send_confirm(hapd, sta, bssid);
  533. if (ret)
  534. return ret;
  535. sta->sae->state = SAE_CONFIRMED;
  536. sta->sae->sync = 0;
  537. sae_set_retransmit_timer(hapd, sta);
  538. } else if (hapd->conf->mesh & MESH_ENABLED) {
  539. /*
  540. * In mesh case, follow SAE finite state machine and
  541. * send Commit now, if sync count allows.
  542. */
  543. if (sae_check_big_sync(sta))
  544. return WLAN_STATUS_SUCCESS;
  545. sta->sae->sync++;
  546. ret = auth_sae_send_commit(hapd, sta, bssid, 0);
  547. if (ret)
  548. return ret;
  549. sae_set_retransmit_timer(hapd, sta);
  550. } else {
  551. /*
  552. * For instructure BSS, send the postponed Confirm from
  553. * Nothing -> Confirmed transition that was reduced to
  554. * Nothing -> Committed above.
  555. */
  556. ret = auth_sae_send_confirm(hapd, sta, bssid);
  557. if (ret)
  558. return ret;
  559. sta->sae->state = SAE_CONFIRMED;
  560. /*
  561. * Since this was triggered on Confirm RX, run another
  562. * step to get to Accepted without waiting for
  563. * additional events.
  564. */
  565. return sae_sm_step(hapd, sta, bssid, auth_transaction);
  566. }
  567. break;
  568. case SAE_CONFIRMED:
  569. sae_clear_retransmit_timer(hapd, sta);
  570. if (auth_transaction == 1) {
  571. if (sae_check_big_sync(sta))
  572. return WLAN_STATUS_SUCCESS;
  573. sta->sae->sync++;
  574. ret = auth_sae_send_commit(hapd, sta, bssid, 1);
  575. if (ret)
  576. return ret;
  577. if (sae_process_commit(sta->sae) < 0)
  578. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  579. ret = auth_sae_send_confirm(hapd, sta, bssid);
  580. if (ret)
  581. return ret;
  582. sae_set_retransmit_timer(hapd, sta);
  583. } else {
  584. sae_accept_sta(hapd, sta);
  585. }
  586. break;
  587. case SAE_ACCEPTED:
  588. if (auth_transaction == 1) {
  589. wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR
  590. ") doing reauthentication",
  591. MAC2STR(sta->addr));
  592. ap_free_sta(hapd, sta);
  593. wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
  594. } else {
  595. if (sae_check_big_sync(sta))
  596. return WLAN_STATUS_SUCCESS;
  597. sta->sae->sync++;
  598. ret = auth_sae_send_confirm(hapd, sta, bssid);
  599. sae_clear_temp_data(sta->sae);
  600. if (ret)
  601. return ret;
  602. }
  603. break;
  604. default:
  605. wpa_printf(MSG_ERROR, "SAE: invalid state %d",
  606. sta->sae->state);
  607. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  608. }
  609. return WLAN_STATUS_SUCCESS;
  610. }
  611. static void sae_pick_next_group(struct hostapd_data *hapd, struct sta_info *sta)
  612. {
  613. struct sae_data *sae = sta->sae;
  614. int i, *groups = hapd->conf->sae_groups;
  615. if (sae->state != SAE_COMMITTED)
  616. return;
  617. wpa_printf(MSG_DEBUG, "SAE: Previously selected group: %d", sae->group);
  618. for (i = 0; groups && groups[i] > 0; i++) {
  619. if (sae->group == groups[i])
  620. break;
  621. }
  622. if (!groups || groups[i] <= 0) {
  623. wpa_printf(MSG_DEBUG,
  624. "SAE: Previously selected group not found from the current configuration");
  625. return;
  626. }
  627. for (;;) {
  628. i++;
  629. if (groups[i] <= 0) {
  630. wpa_printf(MSG_DEBUG,
  631. "SAE: No alternative group enabled");
  632. return;
  633. }
  634. if (sae_set_group(sae, groups[i]) < 0)
  635. continue;
  636. break;
  637. }
  638. wpa_printf(MSG_DEBUG, "SAE: Selected new group: %d", groups[i]);
  639. }
  640. static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
  641. const struct ieee80211_mgmt *mgmt, size_t len,
  642. u16 auth_transaction, u16 status_code)
  643. {
  644. int resp = WLAN_STATUS_SUCCESS;
  645. struct wpabuf *data = NULL;
  646. #ifdef CONFIG_TESTING_OPTIONS
  647. if (hapd->conf->sae_reflection_attack && auth_transaction == 1) {
  648. const u8 *pos, *end;
  649. wpa_printf(MSG_DEBUG, "SAE: TESTING - reflection attack");
  650. pos = mgmt->u.auth.variable;
  651. end = ((const u8 *) mgmt) + len;
  652. send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
  653. auth_transaction, resp, pos, end - pos);
  654. goto remove_sta;
  655. }
  656. if (hapd->conf->sae_commit_override && auth_transaction == 1) {
  657. wpa_printf(MSG_DEBUG, "SAE: TESTING - commit override");
  658. send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
  659. auth_transaction, resp,
  660. wpabuf_head(hapd->conf->sae_commit_override),
  661. wpabuf_len(hapd->conf->sae_commit_override));
  662. goto remove_sta;
  663. }
  664. #endif /* CONFIG_TESTING_OPTIONS */
  665. if (!sta->sae) {
  666. if (auth_transaction != 1 ||
  667. status_code != WLAN_STATUS_SUCCESS) {
  668. resp = -1;
  669. goto remove_sta;
  670. }
  671. sta->sae = os_zalloc(sizeof(*sta->sae));
  672. if (!sta->sae) {
  673. resp = -1;
  674. goto remove_sta;
  675. }
  676. sta->sae->state = SAE_NOTHING;
  677. sta->sae->sync = 0;
  678. }
  679. if (sta->mesh_sae_pmksa_caching) {
  680. wpa_printf(MSG_DEBUG,
  681. "SAE: Cancel use of mesh PMKSA caching because peer starts SAE authentication");
  682. wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
  683. sta->mesh_sae_pmksa_caching = 0;
  684. }
  685. if (auth_transaction == 1) {
  686. const u8 *token = NULL, *pos, *end;
  687. size_t token_len = 0;
  688. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  689. HOSTAPD_LEVEL_DEBUG,
  690. "start SAE authentication (RX commit, status=%u)",
  691. status_code);
  692. if ((hapd->conf->mesh & MESH_ENABLED) &&
  693. status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ &&
  694. sta->sae->tmp) {
  695. pos = mgmt->u.auth.variable;
  696. end = ((const u8 *) mgmt) + len;
  697. if (pos + sizeof(le16) > end) {
  698. wpa_printf(MSG_ERROR,
  699. "SAE: Too short anti-clogging token request");
  700. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  701. goto reply;
  702. }
  703. resp = sae_group_allowed(sta->sae,
  704. hapd->conf->sae_groups,
  705. WPA_GET_LE16(pos));
  706. if (resp != WLAN_STATUS_SUCCESS) {
  707. wpa_printf(MSG_ERROR,
  708. "SAE: Invalid group in anti-clogging token request");
  709. goto reply;
  710. }
  711. pos += sizeof(le16);
  712. wpabuf_free(sta->sae->tmp->anti_clogging_token);
  713. sta->sae->tmp->anti_clogging_token =
  714. wpabuf_alloc_copy(pos, end - pos);
  715. if (sta->sae->tmp->anti_clogging_token == NULL) {
  716. wpa_printf(MSG_ERROR,
  717. "SAE: Failed to alloc for anti-clogging token");
  718. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  719. goto remove_sta;
  720. }
  721. /*
  722. * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
  723. * is 76, a new Commit Message shall be constructed
  724. * with the Anti-Clogging Token from the received
  725. * Authentication frame, and the commit-scalar and
  726. * COMMIT-ELEMENT previously sent.
  727. */
  728. resp = auth_sae_send_commit(hapd, sta, mgmt->bssid, 0);
  729. if (resp != WLAN_STATUS_SUCCESS) {
  730. wpa_printf(MSG_ERROR,
  731. "SAE: Failed to send commit message");
  732. goto remove_sta;
  733. }
  734. sta->sae->state = SAE_COMMITTED;
  735. sta->sae->sync = 0;
  736. sae_set_retransmit_timer(hapd, sta);
  737. return;
  738. }
  739. if ((hapd->conf->mesh & MESH_ENABLED) &&
  740. status_code ==
  741. WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
  742. sta->sae->tmp) {
  743. wpa_printf(MSG_DEBUG,
  744. "SAE: Peer did not accept our SAE group");
  745. sae_pick_next_group(hapd, sta);
  746. goto remove_sta;
  747. }
  748. if (status_code != WLAN_STATUS_SUCCESS)
  749. goto remove_sta;
  750. resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
  751. ((const u8 *) mgmt) + len -
  752. mgmt->u.auth.variable, &token,
  753. &token_len, hapd->conf->sae_groups);
  754. if (resp == SAE_SILENTLY_DISCARD) {
  755. wpa_printf(MSG_DEBUG,
  756. "SAE: Drop commit message from " MACSTR " due to reflection attack",
  757. MAC2STR(sta->addr));
  758. goto remove_sta;
  759. }
  760. if (token && check_sae_token(hapd, sta->addr, token, token_len)
  761. < 0) {
  762. wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
  763. "incorrect token from " MACSTR,
  764. MAC2STR(sta->addr));
  765. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  766. goto remove_sta;
  767. }
  768. if (resp != WLAN_STATUS_SUCCESS)
  769. goto reply;
  770. if (!token && use_sae_anti_clogging(hapd)) {
  771. wpa_printf(MSG_DEBUG,
  772. "SAE: Request anti-clogging token from "
  773. MACSTR, MAC2STR(sta->addr));
  774. data = auth_build_token_req(hapd, sta->sae->group,
  775. sta->addr);
  776. resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
  777. if (hapd->conf->mesh & MESH_ENABLED)
  778. sta->sae->state = SAE_NOTHING;
  779. goto reply;
  780. }
  781. resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
  782. } else if (auth_transaction == 2) {
  783. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  784. HOSTAPD_LEVEL_DEBUG,
  785. "SAE authentication (RX confirm, status=%u)",
  786. status_code);
  787. if (status_code != WLAN_STATUS_SUCCESS)
  788. goto remove_sta;
  789. if (sta->sae->state >= SAE_CONFIRMED ||
  790. !(hapd->conf->mesh & MESH_ENABLED)) {
  791. if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
  792. ((u8 *) mgmt) + len -
  793. mgmt->u.auth.variable) < 0) {
  794. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  795. goto reply;
  796. }
  797. }
  798. resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
  799. } else {
  800. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  801. HOSTAPD_LEVEL_DEBUG,
  802. "unexpected SAE authentication transaction %u (status=%u)",
  803. auth_transaction, status_code);
  804. if (status_code != WLAN_STATUS_SUCCESS)
  805. goto remove_sta;
  806. resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
  807. }
  808. reply:
  809. if (resp != WLAN_STATUS_SUCCESS) {
  810. send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
  811. auth_transaction, resp,
  812. data ? wpabuf_head(data) : (u8 *) "",
  813. data ? wpabuf_len(data) : 0);
  814. }
  815. remove_sta:
  816. if (sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
  817. status_code != WLAN_STATUS_SUCCESS)) {
  818. hostapd_drv_sta_remove(hapd, sta->addr);
  819. sta->added_unassoc = 0;
  820. }
  821. wpabuf_free(data);
  822. }
  823. /**
  824. * auth_sae_init_committed - Send COMMIT and start SAE in committed state
  825. * @hapd: BSS data for the device initiating the authentication
  826. * @sta: the peer to which commit authentication frame is sent
  827. *
  828. * This function implements Init event handling (IEEE Std 802.11-2012,
  829. * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
  830. * sta->sae structure should be initialized appropriately via a call to
  831. * sae_prepare_commit().
  832. */
  833. int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta)
  834. {
  835. int ret;
  836. if (!sta->sae || !sta->sae->tmp)
  837. return -1;
  838. if (sta->sae->state != SAE_NOTHING)
  839. return -1;
  840. ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
  841. if (ret)
  842. return -1;
  843. sta->sae->state = SAE_COMMITTED;
  844. sta->sae->sync = 0;
  845. sae_set_retransmit_timer(hapd, sta);
  846. return 0;
  847. }
  848. #endif /* CONFIG_SAE */
  849. static u16 wpa_res_to_status_code(int res)
  850. {
  851. if (res == WPA_INVALID_GROUP)
  852. return WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
  853. if (res == WPA_INVALID_PAIRWISE)
  854. return WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
  855. if (res == WPA_INVALID_AKMP)
  856. return WLAN_STATUS_AKMP_NOT_VALID;
  857. if (res == WPA_ALLOC_FAIL)
  858. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  859. #ifdef CONFIG_IEEE80211W
  860. if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
  861. return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
  862. if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
  863. return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
  864. #endif /* CONFIG_IEEE80211W */
  865. if (res == WPA_INVALID_MDIE)
  866. return WLAN_STATUS_INVALID_MDIE;
  867. if (res == WPA_INVALID_PMKID)
  868. return WLAN_STATUS_INVALID_PMKID;
  869. if (res != WPA_IE_OK)
  870. return WLAN_STATUS_INVALID_IE;
  871. return WLAN_STATUS_SUCCESS;
  872. }
  873. #ifdef CONFIG_FILS
  874. static void handle_auth_fils_finish(struct hostapd_data *hapd,
  875. struct sta_info *sta, u16 resp,
  876. struct wpabuf *data, int pub);
  877. void handle_auth_fils(struct hostapd_data *hapd, struct sta_info *sta,
  878. const u8 *pos, size_t len, u16 auth_alg,
  879. u16 auth_transaction, u16 status_code,
  880. void (*cb)(struct hostapd_data *hapd,
  881. struct sta_info *sta, u16 resp,
  882. struct wpabuf *data, int pub))
  883. {
  884. u16 resp = WLAN_STATUS_SUCCESS;
  885. const u8 *end;
  886. struct ieee802_11_elems elems;
  887. int res;
  888. struct wpa_ie_data rsn;
  889. struct rsn_pmksa_cache_entry *pmksa = NULL;
  890. if (auth_transaction != 1 || status_code != WLAN_STATUS_SUCCESS)
  891. return;
  892. end = pos + len;
  893. wpa_hexdump(MSG_DEBUG, "FILS: Authentication frame fields",
  894. pos, end - pos);
  895. /* TODO: FILS PK */
  896. #ifdef CONFIG_FILS_SK_PFS
  897. if (auth_alg == WLAN_AUTH_FILS_SK_PFS) {
  898. u16 group;
  899. struct wpabuf *pub;
  900. size_t elem_len;
  901. /* Using FILS PFS */
  902. /* Finite Cyclic Group */
  903. if (end - pos < 2) {
  904. wpa_printf(MSG_DEBUG,
  905. "FILS: No room for Finite Cyclic Group");
  906. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  907. goto fail;
  908. }
  909. group = WPA_GET_LE16(pos);
  910. pos += 2;
  911. if (group != hapd->conf->fils_dh_group) {
  912. wpa_printf(MSG_DEBUG,
  913. "FILS: Unsupported Finite Cyclic Group: %u (expected %u)",
  914. group, hapd->conf->fils_dh_group);
  915. resp = WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
  916. goto fail;
  917. }
  918. crypto_ecdh_deinit(sta->fils_ecdh);
  919. sta->fils_ecdh = crypto_ecdh_init(group);
  920. if (!sta->fils_ecdh) {
  921. wpa_printf(MSG_INFO,
  922. "FILS: Could not initialize ECDH with group %d",
  923. group);
  924. resp = WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
  925. goto fail;
  926. }
  927. pub = crypto_ecdh_get_pubkey(sta->fils_ecdh, 1);
  928. if (!pub) {
  929. wpa_printf(MSG_DEBUG,
  930. "FILS: Failed to derive ECDH public key");
  931. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  932. goto fail;
  933. }
  934. elem_len = wpabuf_len(pub);
  935. wpabuf_free(pub);
  936. /* Element */
  937. if ((size_t) (end - pos) < elem_len) {
  938. wpa_printf(MSG_DEBUG, "FILS: No room for Element");
  939. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  940. goto fail;
  941. }
  942. wpabuf_free(sta->fils_g_sta);
  943. sta->fils_g_sta = wpabuf_alloc_copy(pos, elem_len);
  944. wpabuf_clear_free(sta->fils_dh_ss);
  945. sta->fils_dh_ss = crypto_ecdh_set_peerkey(sta->fils_ecdh, 1,
  946. pos, elem_len);
  947. if (!sta->fils_dh_ss) {
  948. wpa_printf(MSG_DEBUG, "FILS: ECDH operation failed");
  949. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  950. goto fail;
  951. }
  952. wpa_hexdump_buf_key(MSG_DEBUG, "FILS: DH_SS", sta->fils_dh_ss);
  953. pos += elem_len;
  954. } else {
  955. crypto_ecdh_deinit(sta->fils_ecdh);
  956. sta->fils_ecdh = NULL;
  957. wpabuf_clear_free(sta->fils_dh_ss);
  958. sta->fils_dh_ss = NULL;
  959. }
  960. #endif /* CONFIG_FILS_SK_PFS */
  961. wpa_hexdump(MSG_DEBUG, "FILS: Remaining IEs", pos, end - pos);
  962. if (ieee802_11_parse_elems(pos, end - pos, &elems, 1) == ParseFailed) {
  963. wpa_printf(MSG_DEBUG, "FILS: Could not parse elements");
  964. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  965. goto fail;
  966. }
  967. /* RSNE */
  968. wpa_hexdump(MSG_DEBUG, "FILS: RSN element",
  969. elems.rsn_ie, elems.rsn_ie_len);
  970. if (!elems.rsn_ie ||
  971. wpa_parse_wpa_ie_rsn(elems.rsn_ie - 2, elems.rsn_ie_len + 2,
  972. &rsn) < 0) {
  973. wpa_printf(MSG_DEBUG, "FILS: No valid RSN element");
  974. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  975. goto fail;
  976. }
  977. if (!sta->wpa_sm)
  978. sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, sta->addr,
  979. NULL);
  980. if (!sta->wpa_sm) {
  981. wpa_printf(MSG_DEBUG,
  982. "FILS: Failed to initialize RSN state machine");
  983. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  984. goto fail;
  985. }
  986. res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
  987. elems.rsn_ie - 2, elems.rsn_ie_len + 2,
  988. elems.mdie, elems.mdie_len, NULL, 0);
  989. resp = wpa_res_to_status_code(res);
  990. if (resp != WLAN_STATUS_SUCCESS)
  991. goto fail;
  992. if (!elems.fils_nonce) {
  993. wpa_printf(MSG_DEBUG, "FILS: No FILS Nonce field");
  994. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  995. goto fail;
  996. }
  997. wpa_hexdump(MSG_DEBUG, "FILS: SNonce", elems.fils_nonce,
  998. FILS_NONCE_LEN);
  999. os_memcpy(sta->fils_snonce, elems.fils_nonce, FILS_NONCE_LEN);
  1000. /* PMKID List */
  1001. if (rsn.pmkid && rsn.num_pmkid > 0) {
  1002. u8 num;
  1003. const u8 *pmkid;
  1004. wpa_hexdump(MSG_DEBUG, "FILS: PMKID List",
  1005. rsn.pmkid, rsn.num_pmkid * PMKID_LEN);
  1006. pmkid = rsn.pmkid;
  1007. num = rsn.num_pmkid;
  1008. while (num) {
  1009. wpa_hexdump(MSG_DEBUG, "FILS: PMKID", pmkid, PMKID_LEN);
  1010. pmksa = wpa_auth_pmksa_get(hapd->wpa_auth, sta->addr,
  1011. pmkid);
  1012. if (pmksa)
  1013. break;
  1014. pmksa = wpa_auth_pmksa_get_fils_cache_id(hapd->wpa_auth,
  1015. sta->addr,
  1016. pmkid);
  1017. if (pmksa)
  1018. break;
  1019. pmkid += PMKID_LEN;
  1020. num--;
  1021. }
  1022. }
  1023. if (pmksa && wpa_auth_sta_key_mgmt(sta->wpa_sm) != pmksa->akmp) {
  1024. wpa_printf(MSG_DEBUG,
  1025. "FILS: Matching PMKSA cache entry has different AKMP (0x%x != 0x%x) - ignore",
  1026. wpa_auth_sta_key_mgmt(sta->wpa_sm), pmksa->akmp);
  1027. pmksa = NULL;
  1028. }
  1029. if (pmksa)
  1030. wpa_printf(MSG_DEBUG, "FILS: Found matching PMKSA cache entry");
  1031. /* FILS Session */
  1032. if (!elems.fils_session) {
  1033. wpa_printf(MSG_DEBUG, "FILS: No FILS Session element");
  1034. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1035. goto fail;
  1036. }
  1037. wpa_hexdump(MSG_DEBUG, "FILS: FILS Session", elems.fils_session,
  1038. FILS_SESSION_LEN);
  1039. os_memcpy(sta->fils_session, elems.fils_session, FILS_SESSION_LEN);
  1040. /* FILS Wrapped Data */
  1041. if (elems.fils_wrapped_data) {
  1042. wpa_hexdump(MSG_DEBUG, "FILS: Wrapped Data",
  1043. elems.fils_wrapped_data,
  1044. elems.fils_wrapped_data_len);
  1045. if (!pmksa) {
  1046. #ifndef CONFIG_NO_RADIUS
  1047. if (!sta->eapol_sm) {
  1048. sta->eapol_sm =
  1049. ieee802_1x_alloc_eapol_sm(hapd, sta);
  1050. }
  1051. wpa_printf(MSG_DEBUG,
  1052. "FILS: Forward EAP-Initiate/Re-auth to authentication server");
  1053. ieee802_1x_encapsulate_radius(
  1054. hapd, sta, elems.fils_wrapped_data,
  1055. elems.fils_wrapped_data_len);
  1056. sta->fils_pending_cb = cb;
  1057. wpa_printf(MSG_DEBUG,
  1058. "FILS: Will send Authentication frame once the response from authentication server is available");
  1059. sta->flags |= WLAN_STA_PENDING_FILS_ERP;
  1060. /* Calculate pending PMKID here so that we do not need
  1061. * to maintain a copy of the EAP-Initiate/Reauth
  1062. * message. */
  1063. if (fils_pmkid_erp(wpa_auth_sta_key_mgmt(sta->wpa_sm),
  1064. elems.fils_wrapped_data,
  1065. elems.fils_wrapped_data_len,
  1066. sta->fils_erp_pmkid) == 0)
  1067. sta->fils_erp_pmkid_set = 1;
  1068. return;
  1069. #else /* CONFIG_NO_RADIUS */
  1070. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1071. goto fail;
  1072. #endif /* CONFIG_NO_RADIUS */
  1073. }
  1074. }
  1075. fail:
  1076. if (cb) {
  1077. struct wpabuf *data;
  1078. int pub = 0;
  1079. data = prepare_auth_resp_fils(hapd, sta, &resp, pmksa, NULL,
  1080. NULL, 0, &pub);
  1081. if (!data) {
  1082. wpa_printf(MSG_DEBUG,
  1083. "%s: prepare_auth_resp_fils() returned failure",
  1084. __func__);
  1085. }
  1086. cb(hapd, sta, resp, data, pub);
  1087. }
  1088. }
  1089. static struct wpabuf *
  1090. prepare_auth_resp_fils(struct hostapd_data *hapd,
  1091. struct sta_info *sta, u16 *resp,
  1092. struct rsn_pmksa_cache_entry *pmksa,
  1093. struct wpabuf *erp_resp,
  1094. const u8 *msk, size_t msk_len,
  1095. int *is_pub)
  1096. {
  1097. u8 fils_nonce[FILS_NONCE_LEN];
  1098. size_t ielen;
  1099. struct wpabuf *data = NULL;
  1100. const u8 *ie;
  1101. u8 *ie_buf = NULL;
  1102. const u8 *pmk = NULL;
  1103. size_t pmk_len = 0;
  1104. u8 pmk_buf[PMK_LEN_MAX];
  1105. struct wpabuf *pub = NULL;
  1106. if (*resp != WLAN_STATUS_SUCCESS)
  1107. goto fail;
  1108. ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
  1109. if (!ie) {
  1110. *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1111. goto fail;
  1112. }
  1113. if (pmksa) {
  1114. /* Add PMKID of the selected PMKSA into RSNE */
  1115. ie_buf = os_malloc(ielen + 2 + 2 + PMKID_LEN);
  1116. if (!ie_buf) {
  1117. *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1118. goto fail;
  1119. }
  1120. os_memcpy(ie_buf, ie, ielen);
  1121. if (wpa_insert_pmkid(ie_buf, &ielen, pmksa->pmkid) < 0) {
  1122. *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1123. goto fail;
  1124. }
  1125. ie = ie_buf;
  1126. }
  1127. if (random_get_bytes(fils_nonce, FILS_NONCE_LEN) < 0) {
  1128. *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1129. goto fail;
  1130. }
  1131. wpa_hexdump(MSG_DEBUG, "RSN: Generated FILS Nonce",
  1132. fils_nonce, FILS_NONCE_LEN);
  1133. #ifdef CONFIG_FILS_SK_PFS
  1134. if (sta->fils_dh_ss && sta->fils_ecdh) {
  1135. pub = crypto_ecdh_get_pubkey(sta->fils_ecdh, 1);
  1136. if (!pub) {
  1137. *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1138. goto fail;
  1139. }
  1140. }
  1141. #endif /* CONFIG_FILS_SK_PFS */
  1142. data = wpabuf_alloc(1000 + ielen + (pub ? wpabuf_len(pub) : 0));
  1143. if (!data) {
  1144. *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1145. goto fail;
  1146. }
  1147. /* TODO: FILS PK */
  1148. #ifdef CONFIG_FILS_SK_PFS
  1149. if (pub) {
  1150. /* Finite Cyclic Group */
  1151. wpabuf_put_le16(data, hapd->conf->fils_dh_group);
  1152. /* Element */
  1153. wpabuf_put_buf(data, pub);
  1154. }
  1155. #endif /* CONFIG_FILS_SK_PFS */
  1156. /* RSNE */
  1157. wpabuf_put_data(data, ie, ielen);
  1158. /* MDE when using FILS+FT (already included in ie,ielen with RSNE) */
  1159. #ifdef CONFIG_IEEE80211R_AP
  1160. if (wpa_key_mgmt_ft(wpa_auth_sta_key_mgmt(sta->wpa_sm))) {
  1161. /* FTE[R1KH-ID,R0KH-ID] when using FILS+FT */
  1162. int res;
  1163. res = wpa_auth_write_fte(hapd->wpa_auth, wpabuf_put(data, 0),
  1164. wpabuf_tailroom(data));
  1165. if (res < 0) {
  1166. *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1167. goto fail;
  1168. }
  1169. wpabuf_put(data, res);
  1170. }
  1171. #endif /* CONFIG_IEEE80211R_AP */
  1172. /* FILS Nonce */
  1173. wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */
  1174. wpabuf_put_u8(data, 1 + FILS_NONCE_LEN); /* Length */
  1175. /* Element ID Extension */
  1176. wpabuf_put_u8(data, WLAN_EID_EXT_FILS_NONCE);
  1177. wpabuf_put_data(data, fils_nonce, FILS_NONCE_LEN);
  1178. /* FILS Session */
  1179. wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */
  1180. wpabuf_put_u8(data, 1 + FILS_SESSION_LEN); /* Length */
  1181. /* Element ID Extension */
  1182. wpabuf_put_u8(data, WLAN_EID_EXT_FILS_SESSION);
  1183. wpabuf_put_data(data, sta->fils_session, FILS_SESSION_LEN);
  1184. /* FILS Wrapped Data */
  1185. if (!pmksa && erp_resp) {
  1186. wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */
  1187. wpabuf_put_u8(data, 1 + wpabuf_len(erp_resp)); /* Length */
  1188. /* Element ID Extension */
  1189. wpabuf_put_u8(data, WLAN_EID_EXT_FILS_WRAPPED_DATA);
  1190. wpabuf_put_buf(data, erp_resp);
  1191. if (fils_rmsk_to_pmk(wpa_auth_sta_key_mgmt(sta->wpa_sm),
  1192. msk, msk_len, sta->fils_snonce, fils_nonce,
  1193. sta->fils_dh_ss ?
  1194. wpabuf_head(sta->fils_dh_ss) : NULL,
  1195. sta->fils_dh_ss ?
  1196. wpabuf_len(sta->fils_dh_ss) : 0,
  1197. pmk_buf, &pmk_len)) {
  1198. wpa_printf(MSG_DEBUG, "FILS: Failed to derive PMK");
  1199. *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1200. wpabuf_free(data);
  1201. data = NULL;
  1202. goto fail;
  1203. }
  1204. pmk = pmk_buf;
  1205. if (sta->fils_erp_pmkid_set) {
  1206. /* TODO: get PMKLifetime from WPA parameters */
  1207. unsigned int dot11RSNAConfigPMKLifetime = 43200;
  1208. sta->fils_erp_pmkid_set = 0;
  1209. if (wpa_auth_pmksa_add2(
  1210. hapd->wpa_auth, sta->addr,
  1211. pmk, pmk_len,
  1212. sta->fils_erp_pmkid,
  1213. sta->session_timeout_set ?
  1214. sta->session_timeout :
  1215. dot11RSNAConfigPMKLifetime,
  1216. wpa_auth_sta_key_mgmt(sta->wpa_sm)) < 0) {
  1217. wpa_printf(MSG_ERROR,
  1218. "FILS: Failed to add PMKSA cache entry based on ERP");
  1219. }
  1220. }
  1221. } else if (pmksa) {
  1222. pmk = pmksa->pmk;
  1223. pmk_len = pmksa->pmk_len;
  1224. }
  1225. if (!pmk) {
  1226. wpa_printf(MSG_DEBUG, "FILS: No PMK available");
  1227. *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1228. wpabuf_free(data);
  1229. data = NULL;
  1230. goto fail;
  1231. }
  1232. if (fils_auth_pmk_to_ptk(sta->wpa_sm, pmk, pmk_len,
  1233. sta->fils_snonce, fils_nonce,
  1234. sta->fils_g_sta, pub) < 0) {
  1235. *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1236. wpabuf_free(data);
  1237. data = NULL;
  1238. goto fail;
  1239. }
  1240. fail:
  1241. if (is_pub)
  1242. *is_pub = pub != NULL;
  1243. os_free(ie_buf);
  1244. wpabuf_free(pub);
  1245. wpabuf_clear_free(sta->fils_dh_ss);
  1246. sta->fils_dh_ss = NULL;
  1247. #ifdef CONFIG_FILS_SK_PFS
  1248. crypto_ecdh_deinit(sta->fils_ecdh);
  1249. sta->fils_ecdh = NULL;
  1250. #endif /* CONFIG_FILS_SK_PFS */
  1251. return data;
  1252. }
  1253. static void handle_auth_fils_finish(struct hostapd_data *hapd,
  1254. struct sta_info *sta, u16 resp,
  1255. struct wpabuf *data, int pub)
  1256. {
  1257. u16 auth_alg;
  1258. auth_alg = (pub ||
  1259. resp == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) ?
  1260. WLAN_AUTH_FILS_SK_PFS : WLAN_AUTH_FILS_SK;
  1261. send_auth_reply(hapd, sta->addr, hapd->own_addr, auth_alg, 2, resp,
  1262. data ? wpabuf_head(data) : (u8 *) "",
  1263. data ? wpabuf_len(data) : 0);
  1264. wpabuf_free(data);
  1265. if (resp == WLAN_STATUS_SUCCESS) {
  1266. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1267. HOSTAPD_LEVEL_DEBUG,
  1268. "authentication OK (FILS)");
  1269. sta->flags |= WLAN_STA_AUTH;
  1270. wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
  1271. sta->auth_alg = pub ? WLAN_AUTH_FILS_SK_PFS : WLAN_AUTH_FILS_SK;
  1272. mlme_authenticate_indication(hapd, sta);
  1273. }
  1274. }
  1275. void ieee802_11_finish_fils_auth(struct hostapd_data *hapd,
  1276. struct sta_info *sta, int success,
  1277. struct wpabuf *erp_resp,
  1278. const u8 *msk, size_t msk_len)
  1279. {
  1280. struct wpabuf *data;
  1281. int pub = 0;
  1282. u16 resp;
  1283. sta->flags &= ~WLAN_STA_PENDING_FILS_ERP;
  1284. if (!sta->fils_pending_cb)
  1285. return;
  1286. resp = success ? WLAN_STATUS_SUCCESS : WLAN_STATUS_UNSPECIFIED_FAILURE;
  1287. data = prepare_auth_resp_fils(hapd, sta, &resp, NULL, erp_resp,
  1288. msk, msk_len, &pub);
  1289. if (!data) {
  1290. wpa_printf(MSG_DEBUG,
  1291. "%s: prepare_auth_resp_fils() returned failure",
  1292. __func__);
  1293. }
  1294. sta->fils_pending_cb(hapd, sta, resp, data, pub);
  1295. }
  1296. #endif /* CONFIG_FILS */
  1297. static int
  1298. ieee802_11_allowed_address(struct hostapd_data *hapd, const u8 *addr,
  1299. const u8 *msg, size_t len, u32 *session_timeout,
  1300. u32 *acct_interim_interval,
  1301. struct vlan_description *vlan_id,
  1302. struct hostapd_sta_wpa_psk_short **psk,
  1303. char **identity, char **radius_cui)
  1304. {
  1305. int res;
  1306. os_memset(vlan_id, 0, sizeof(*vlan_id));
  1307. res = hostapd_allowed_address(hapd, addr, msg, len,
  1308. session_timeout, acct_interim_interval,
  1309. vlan_id, psk, identity, radius_cui);
  1310. if (res == HOSTAPD_ACL_REJECT) {
  1311. wpa_printf(MSG_INFO,
  1312. "Station " MACSTR " not allowed to authenticate",
  1313. MAC2STR(addr));
  1314. return HOSTAPD_ACL_REJECT;
  1315. }
  1316. if (res == HOSTAPD_ACL_PENDING) {
  1317. wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
  1318. " waiting for an external authentication",
  1319. MAC2STR(addr));
  1320. /* Authentication code will re-send the authentication frame
  1321. * after it has received (and cached) information from the
  1322. * external source. */
  1323. return HOSTAPD_ACL_PENDING;
  1324. }
  1325. return res;
  1326. }
  1327. static int
  1328. ieee802_11_set_radius_info(struct hostapd_data *hapd, struct sta_info *sta,
  1329. int res, u32 session_timeout,
  1330. u32 acct_interim_interval,
  1331. struct vlan_description *vlan_id,
  1332. struct hostapd_sta_wpa_psk_short **psk,
  1333. char **identity, char **radius_cui)
  1334. {
  1335. if (vlan_id->notempty &&
  1336. !hostapd_vlan_valid(hapd->conf->vlan, vlan_id)) {
  1337. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
  1338. HOSTAPD_LEVEL_INFO,
  1339. "Invalid VLAN %d%s received from RADIUS server",
  1340. vlan_id->untagged,
  1341. vlan_id->tagged[0] ? "+" : "");
  1342. return -1;
  1343. }
  1344. if (ap_sta_set_vlan(hapd, sta, vlan_id) < 0)
  1345. return -1;
  1346. if (sta->vlan_id)
  1347. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
  1348. HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
  1349. hostapd_free_psk_list(sta->psk);
  1350. if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
  1351. sta->psk = *psk;
  1352. *psk = NULL;
  1353. } else {
  1354. sta->psk = NULL;
  1355. }
  1356. sta->identity = *identity;
  1357. *identity = NULL;
  1358. sta->radius_cui = *radius_cui;
  1359. *radius_cui = NULL;
  1360. if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
  1361. sta->acct_interim_interval = acct_interim_interval;
  1362. if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
  1363. ap_sta_session_timeout(hapd, sta, session_timeout);
  1364. else
  1365. ap_sta_no_session_timeout(hapd, sta);
  1366. return 0;
  1367. }
  1368. static void handle_auth(struct hostapd_data *hapd,
  1369. const struct ieee80211_mgmt *mgmt, size_t len)
  1370. {
  1371. u16 auth_alg, auth_transaction, status_code;
  1372. u16 resp = WLAN_STATUS_SUCCESS;
  1373. struct sta_info *sta = NULL;
  1374. int res, reply_res;
  1375. u16 fc;
  1376. const u8 *challenge = NULL;
  1377. u32 session_timeout, acct_interim_interval;
  1378. struct vlan_description vlan_id;
  1379. struct hostapd_sta_wpa_psk_short *psk = NULL;
  1380. u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
  1381. size_t resp_ies_len = 0;
  1382. char *identity = NULL;
  1383. char *radius_cui = NULL;
  1384. u16 seq_ctrl;
  1385. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
  1386. wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
  1387. (unsigned long) len);
  1388. return;
  1389. }
  1390. #ifdef CONFIG_TESTING_OPTIONS
  1391. if (hapd->iconf->ignore_auth_probability > 0.0 &&
  1392. drand48() < hapd->iconf->ignore_auth_probability) {
  1393. wpa_printf(MSG_INFO,
  1394. "TESTING: ignoring auth frame from " MACSTR,
  1395. MAC2STR(mgmt->sa));
  1396. return;
  1397. }
  1398. #endif /* CONFIG_TESTING_OPTIONS */
  1399. auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
  1400. auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
  1401. status_code = le_to_host16(mgmt->u.auth.status_code);
  1402. fc = le_to_host16(mgmt->frame_control);
  1403. seq_ctrl = le_to_host16(mgmt->seq_ctrl);
  1404. if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
  1405. 2 + WLAN_AUTH_CHALLENGE_LEN &&
  1406. mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
  1407. mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
  1408. challenge = &mgmt->u.auth.variable[2];
  1409. wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
  1410. "auth_transaction=%d status_code=%d wep=%d%s "
  1411. "seq_ctrl=0x%x%s",
  1412. MAC2STR(mgmt->sa), auth_alg, auth_transaction,
  1413. status_code, !!(fc & WLAN_FC_ISWEP),
  1414. challenge ? " challenge" : "",
  1415. seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
  1416. #ifdef CONFIG_NO_RC4
  1417. if (auth_alg == WLAN_AUTH_SHARED_KEY) {
  1418. wpa_printf(MSG_INFO,
  1419. "Unsupported authentication algorithm (%d)",
  1420. auth_alg);
  1421. resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
  1422. goto fail;
  1423. }
  1424. #endif /* CONFIG_NO_RC4 */
  1425. if (hapd->tkip_countermeasures) {
  1426. resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
  1427. goto fail;
  1428. }
  1429. if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
  1430. auth_alg == WLAN_AUTH_OPEN) ||
  1431. #ifdef CONFIG_IEEE80211R_AP
  1432. (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
  1433. auth_alg == WLAN_AUTH_FT) ||
  1434. #endif /* CONFIG_IEEE80211R_AP */
  1435. #ifdef CONFIG_SAE
  1436. (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
  1437. auth_alg == WLAN_AUTH_SAE) ||
  1438. #endif /* CONFIG_SAE */
  1439. #ifdef CONFIG_FILS
  1440. (hapd->conf->wpa && wpa_key_mgmt_fils(hapd->conf->wpa_key_mgmt) &&
  1441. auth_alg == WLAN_AUTH_FILS_SK) ||
  1442. (hapd->conf->wpa && wpa_key_mgmt_fils(hapd->conf->wpa_key_mgmt) &&
  1443. hapd->conf->fils_dh_group &&
  1444. auth_alg == WLAN_AUTH_FILS_SK_PFS) ||
  1445. #endif /* CONFIG_FILS */
  1446. ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
  1447. auth_alg == WLAN_AUTH_SHARED_KEY))) {
  1448. wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
  1449. auth_alg);
  1450. resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
  1451. goto fail;
  1452. }
  1453. if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
  1454. (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
  1455. wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
  1456. auth_transaction);
  1457. resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
  1458. goto fail;
  1459. }
  1460. if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
  1461. wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
  1462. MAC2STR(mgmt->sa));
  1463. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1464. goto fail;
  1465. }
  1466. if (hapd->conf->no_auth_if_seen_on) {
  1467. struct hostapd_data *other;
  1468. other = sta_track_seen_on(hapd->iface, mgmt->sa,
  1469. hapd->conf->no_auth_if_seen_on);
  1470. if (other) {
  1471. u8 *pos;
  1472. u32 info;
  1473. u8 op_class, channel, phytype;
  1474. wpa_printf(MSG_DEBUG, "%s: Reject authentication from "
  1475. MACSTR " since STA has been seen on %s",
  1476. hapd->conf->iface, MAC2STR(mgmt->sa),
  1477. hapd->conf->no_auth_if_seen_on);
  1478. resp = WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION;
  1479. pos = &resp_ies[0];
  1480. *pos++ = WLAN_EID_NEIGHBOR_REPORT;
  1481. *pos++ = 13;
  1482. os_memcpy(pos, other->own_addr, ETH_ALEN);
  1483. pos += ETH_ALEN;
  1484. info = 0; /* TODO: BSSID Information */
  1485. WPA_PUT_LE32(pos, info);
  1486. pos += 4;
  1487. if (other->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD)
  1488. phytype = 8; /* dmg */
  1489. else if (other->iconf->ieee80211ac)
  1490. phytype = 9; /* vht */
  1491. else if (other->iconf->ieee80211n)
  1492. phytype = 7; /* ht */
  1493. else if (other->iconf->hw_mode ==
  1494. HOSTAPD_MODE_IEEE80211A)
  1495. phytype = 4; /* ofdm */
  1496. else if (other->iconf->hw_mode ==
  1497. HOSTAPD_MODE_IEEE80211G)
  1498. phytype = 6; /* erp */
  1499. else
  1500. phytype = 5; /* hrdsss */
  1501. if (ieee80211_freq_to_channel_ext(
  1502. hostapd_hw_get_freq(other,
  1503. other->iconf->channel),
  1504. other->iconf->secondary_channel,
  1505. other->iconf->ieee80211ac,
  1506. &op_class, &channel) == NUM_HOSTAPD_MODES) {
  1507. op_class = 0;
  1508. channel = other->iconf->channel;
  1509. }
  1510. *pos++ = op_class;
  1511. *pos++ = channel;
  1512. *pos++ = phytype;
  1513. resp_ies_len = pos - &resp_ies[0];
  1514. goto fail;
  1515. }
  1516. }
  1517. res = ieee802_11_allowed_address(
  1518. hapd, mgmt->sa, (const u8 *) mgmt, len, &session_timeout,
  1519. &acct_interim_interval, &vlan_id, &psk, &identity, &radius_cui);
  1520. if (res == HOSTAPD_ACL_REJECT) {
  1521. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1522. goto fail;
  1523. }
  1524. if (res == HOSTAPD_ACL_PENDING)
  1525. return;
  1526. sta = ap_get_sta(hapd, mgmt->sa);
  1527. if (sta) {
  1528. sta->flags &= ~WLAN_STA_PENDING_FILS_ERP;
  1529. if ((fc & WLAN_FC_RETRY) &&
  1530. sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
  1531. sta->last_seq_ctrl == seq_ctrl &&
  1532. sta->last_subtype == WLAN_FC_STYPE_AUTH) {
  1533. hostapd_logger(hapd, sta->addr,
  1534. HOSTAPD_MODULE_IEEE80211,
  1535. HOSTAPD_LEVEL_DEBUG,
  1536. "Drop repeated authentication frame seq_ctrl=0x%x",
  1537. seq_ctrl);
  1538. return;
  1539. }
  1540. #ifdef CONFIG_MESH
  1541. if ((hapd->conf->mesh & MESH_ENABLED) &&
  1542. sta->plink_state == PLINK_BLOCKED) {
  1543. wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
  1544. " is blocked - drop Authentication frame",
  1545. MAC2STR(mgmt->sa));
  1546. return;
  1547. }
  1548. #endif /* CONFIG_MESH */
  1549. } else {
  1550. #ifdef CONFIG_MESH
  1551. if (hapd->conf->mesh & MESH_ENABLED) {
  1552. /* if the mesh peer is not available, we don't do auth.
  1553. */
  1554. wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
  1555. " not yet known - drop Authentication frame",
  1556. MAC2STR(mgmt->sa));
  1557. /*
  1558. * Save a copy of the frame so that it can be processed
  1559. * if a new peer entry is added shortly after this.
  1560. */
  1561. wpabuf_free(hapd->mesh_pending_auth);
  1562. hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len);
  1563. os_get_reltime(&hapd->mesh_pending_auth_time);
  1564. return;
  1565. }
  1566. #endif /* CONFIG_MESH */
  1567. sta = ap_sta_add(hapd, mgmt->sa);
  1568. if (!sta) {
  1569. resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
  1570. goto fail;
  1571. }
  1572. }
  1573. sta->last_seq_ctrl = seq_ctrl;
  1574. sta->last_subtype = WLAN_FC_STYPE_AUTH;
  1575. res = ieee802_11_set_radius_info(
  1576. hapd, sta, res, session_timeout, acct_interim_interval,
  1577. &vlan_id, &psk, &identity, &radius_cui);
  1578. if (res) {
  1579. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1580. goto fail;
  1581. }
  1582. sta->flags &= ~WLAN_STA_PREAUTH;
  1583. ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
  1584. /*
  1585. * If the driver supports full AP client state, add a station to the
  1586. * driver before sending authentication reply to make sure the driver
  1587. * has resources, and not to go through the entire authentication and
  1588. * association handshake, and fail it at the end.
  1589. *
  1590. * If this is not the first transaction, in a multi-step authentication
  1591. * algorithm, the station already exists in the driver
  1592. * (sta->added_unassoc = 1) so skip it.
  1593. *
  1594. * In mesh mode, the station was already added to the driver when the
  1595. * NEW_PEER_CANDIDATE event is received.
  1596. *
  1597. * If PMF was negotiated for the existing association, skip this to
  1598. * avoid dropping the STA entry and the associated keys. This is needed
  1599. * to allow the original connection work until the attempt can complete
  1600. * (re)association, so that unprotected Authentication frame cannot be
  1601. * used to bypass PMF protection.
  1602. */
  1603. if (FULL_AP_CLIENT_STATE_SUPP(hapd->iface->drv_flags) &&
  1604. (!(sta->flags & WLAN_STA_MFP) || !ap_sta_is_authorized(sta)) &&
  1605. !(hapd->conf->mesh & MESH_ENABLED) &&
  1606. !(sta->added_unassoc)) {
  1607. /*
  1608. * If a station that is already associated to the AP, is trying
  1609. * to authenticate again, remove the STA entry, in order to make
  1610. * sure the STA PS state gets cleared and configuration gets
  1611. * updated. To handle this, station's added_unassoc flag is
  1612. * cleared once the station has completed association.
  1613. */
  1614. hostapd_drv_sta_remove(hapd, sta->addr);
  1615. sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_AUTH |
  1616. WLAN_STA_AUTHORIZED);
  1617. if (hostapd_sta_add(hapd, sta->addr, 0, 0, NULL, 0, 0,
  1618. NULL, NULL, sta->flags, 0, 0, 0, 0)) {
  1619. hostapd_logger(hapd, sta->addr,
  1620. HOSTAPD_MODULE_IEEE80211,
  1621. HOSTAPD_LEVEL_NOTICE,
  1622. "Could not add STA to kernel driver");
  1623. resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
  1624. goto fail;
  1625. }
  1626. sta->added_unassoc = 1;
  1627. }
  1628. switch (auth_alg) {
  1629. case WLAN_AUTH_OPEN:
  1630. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1631. HOSTAPD_LEVEL_DEBUG,
  1632. "authentication OK (open system)");
  1633. sta->flags |= WLAN_STA_AUTH;
  1634. wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
  1635. sta->auth_alg = WLAN_AUTH_OPEN;
  1636. mlme_authenticate_indication(hapd, sta);
  1637. break;
  1638. #ifndef CONFIG_NO_RC4
  1639. case WLAN_AUTH_SHARED_KEY:
  1640. resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
  1641. fc & WLAN_FC_ISWEP);
  1642. sta->auth_alg = WLAN_AUTH_SHARED_KEY;
  1643. mlme_authenticate_indication(hapd, sta);
  1644. if (sta->challenge && auth_transaction == 1) {
  1645. resp_ies[0] = WLAN_EID_CHALLENGE;
  1646. resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
  1647. os_memcpy(resp_ies + 2, sta->challenge,
  1648. WLAN_AUTH_CHALLENGE_LEN);
  1649. resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
  1650. }
  1651. break;
  1652. #endif /* CONFIG_NO_RC4 */
  1653. #ifdef CONFIG_IEEE80211R_AP
  1654. case WLAN_AUTH_FT:
  1655. sta->auth_alg = WLAN_AUTH_FT;
  1656. if (sta->wpa_sm == NULL)
  1657. sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
  1658. sta->addr, NULL);
  1659. if (sta->wpa_sm == NULL) {
  1660. wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
  1661. "state machine");
  1662. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1663. goto fail;
  1664. }
  1665. wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
  1666. auth_transaction, mgmt->u.auth.variable,
  1667. len - IEEE80211_HDRLEN -
  1668. sizeof(mgmt->u.auth),
  1669. handle_auth_ft_finish, hapd);
  1670. /* handle_auth_ft_finish() callback will complete auth. */
  1671. return;
  1672. #endif /* CONFIG_IEEE80211R_AP */
  1673. #ifdef CONFIG_SAE
  1674. case WLAN_AUTH_SAE:
  1675. #ifdef CONFIG_MESH
  1676. if (status_code == WLAN_STATUS_SUCCESS &&
  1677. hapd->conf->mesh & MESH_ENABLED) {
  1678. if (sta->wpa_sm == NULL)
  1679. sta->wpa_sm =
  1680. wpa_auth_sta_init(hapd->wpa_auth,
  1681. sta->addr, NULL);
  1682. if (sta->wpa_sm == NULL) {
  1683. wpa_printf(MSG_DEBUG,
  1684. "SAE: Failed to initialize WPA state machine");
  1685. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1686. goto fail;
  1687. }
  1688. }
  1689. #endif /* CONFIG_MESH */
  1690. handle_auth_sae(hapd, sta, mgmt, len, auth_transaction,
  1691. status_code);
  1692. return;
  1693. #endif /* CONFIG_SAE */
  1694. #ifdef CONFIG_FILS
  1695. case WLAN_AUTH_FILS_SK:
  1696. case WLAN_AUTH_FILS_SK_PFS:
  1697. handle_auth_fils(hapd, sta, mgmt->u.auth.variable,
  1698. len - IEEE80211_HDRLEN - sizeof(mgmt->u.auth),
  1699. auth_alg, auth_transaction, status_code,
  1700. handle_auth_fils_finish);
  1701. return;
  1702. #endif /* CONFIG_FILS */
  1703. }
  1704. fail:
  1705. os_free(identity);
  1706. os_free(radius_cui);
  1707. hostapd_free_psk_list(psk);
  1708. reply_res = send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
  1709. auth_transaction + 1, resp, resp_ies,
  1710. resp_ies_len);
  1711. if (sta && sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
  1712. reply_res != WLAN_STATUS_SUCCESS)) {
  1713. hostapd_drv_sta_remove(hapd, sta->addr);
  1714. sta->added_unassoc = 0;
  1715. }
  1716. }
  1717. int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
  1718. {
  1719. int i, j = 32, aid;
  1720. /* get a unique AID */
  1721. if (sta->aid > 0) {
  1722. wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
  1723. return 0;
  1724. }
  1725. if (TEST_FAIL())
  1726. return -1;
  1727. for (i = 0; i < AID_WORDS; i++) {
  1728. if (hapd->sta_aid[i] == (u32) -1)
  1729. continue;
  1730. for (j = 0; j < 32; j++) {
  1731. if (!(hapd->sta_aid[i] & BIT(j)))
  1732. break;
  1733. }
  1734. if (j < 32)
  1735. break;
  1736. }
  1737. if (j == 32)
  1738. return -1;
  1739. aid = i * 32 + j + 1;
  1740. if (aid > 2007)
  1741. return -1;
  1742. sta->aid = aid;
  1743. hapd->sta_aid[i] |= BIT(j);
  1744. wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
  1745. return 0;
  1746. }
  1747. static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
  1748. const u8 *ssid_ie, size_t ssid_ie_len)
  1749. {
  1750. if (ssid_ie == NULL)
  1751. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1752. if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
  1753. os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
  1754. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1755. HOSTAPD_LEVEL_INFO,
  1756. "Station tried to associate with unknown SSID "
  1757. "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
  1758. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1759. }
  1760. return WLAN_STATUS_SUCCESS;
  1761. }
  1762. static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
  1763. const u8 *wmm_ie, size_t wmm_ie_len)
  1764. {
  1765. sta->flags &= ~WLAN_STA_WMM;
  1766. sta->qosinfo = 0;
  1767. if (wmm_ie && hapd->conf->wmm_enabled) {
  1768. struct wmm_information_element *wmm;
  1769. if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
  1770. hostapd_logger(hapd, sta->addr,
  1771. HOSTAPD_MODULE_WPA,
  1772. HOSTAPD_LEVEL_DEBUG,
  1773. "invalid WMM element in association "
  1774. "request");
  1775. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1776. }
  1777. sta->flags |= WLAN_STA_WMM;
  1778. wmm = (struct wmm_information_element *) wmm_ie;
  1779. sta->qosinfo = wmm->qos_info;
  1780. }
  1781. return WLAN_STATUS_SUCCESS;
  1782. }
  1783. static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
  1784. struct ieee802_11_elems *elems)
  1785. {
  1786. /* Supported rates not used in IEEE 802.11ad/DMG */
  1787. if (hapd->iface->current_mode &&
  1788. hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD)
  1789. return WLAN_STATUS_SUCCESS;
  1790. if (!elems->supp_rates) {
  1791. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1792. HOSTAPD_LEVEL_DEBUG,
  1793. "No supported rates element in AssocReq");
  1794. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1795. }
  1796. if (elems->supp_rates_len + elems->ext_supp_rates_len >
  1797. sizeof(sta->supported_rates)) {
  1798. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1799. HOSTAPD_LEVEL_DEBUG,
  1800. "Invalid supported rates element length %d+%d",
  1801. elems->supp_rates_len,
  1802. elems->ext_supp_rates_len);
  1803. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1804. }
  1805. sta->supported_rates_len = merge_byte_arrays(
  1806. sta->supported_rates, sizeof(sta->supported_rates),
  1807. elems->supp_rates, elems->supp_rates_len,
  1808. elems->ext_supp_rates, elems->ext_supp_rates_len);
  1809. return WLAN_STATUS_SUCCESS;
  1810. }
  1811. static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
  1812. const u8 *ext_capab_ie, size_t ext_capab_ie_len)
  1813. {
  1814. #ifdef CONFIG_INTERWORKING
  1815. /* check for QoS Map support */
  1816. if (ext_capab_ie_len >= 5) {
  1817. if (ext_capab_ie[4] & 0x01)
  1818. sta->qos_map_enabled = 1;
  1819. }
  1820. #endif /* CONFIG_INTERWORKING */
  1821. if (ext_capab_ie_len > 0)
  1822. sta->ecsa_supported = !!(ext_capab_ie[0] & BIT(2));
  1823. return WLAN_STATUS_SUCCESS;
  1824. }
  1825. #ifdef CONFIG_OWE
  1826. static u16 owe_process_assoc_req(struct sta_info *sta, const u8 *owe_dh,
  1827. u8 owe_dh_len)
  1828. {
  1829. struct wpabuf *secret, *pub, *hkey;
  1830. int res;
  1831. u8 prk[SHA256_MAC_LEN], pmkid[SHA256_MAC_LEN];
  1832. const char *info = "OWE Key Generation";
  1833. const u8 *addr[2];
  1834. size_t len[2];
  1835. if (WPA_GET_LE16(owe_dh) != OWE_DH_GROUP)
  1836. return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
  1837. crypto_ecdh_deinit(sta->owe_ecdh);
  1838. sta->owe_ecdh = crypto_ecdh_init(OWE_DH_GROUP);
  1839. if (!sta->owe_ecdh)
  1840. return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
  1841. secret = crypto_ecdh_set_peerkey(sta->owe_ecdh, 0, owe_dh + 2,
  1842. owe_dh_len - 2);
  1843. if (!secret) {
  1844. wpa_printf(MSG_DEBUG, "OWE: Invalid peer DH public key");
  1845. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1846. }
  1847. wpa_hexdump_buf_key(MSG_DEBUG, "OWE: DH shared secret", secret);
  1848. /* prk = HKDF-extract(C | A | group, z) */
  1849. pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0);
  1850. if (!pub) {
  1851. wpabuf_clear_free(secret);
  1852. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1853. }
  1854. /* PMKID = Truncate-128(Hash(C | A)) */
  1855. addr[0] = owe_dh + 2;
  1856. len[0] = owe_dh_len - 2;
  1857. addr[1] = wpabuf_head(pub);
  1858. len[1] = wpabuf_len(pub);
  1859. res = sha256_vector(2, addr, len, pmkid);
  1860. if (res < 0) {
  1861. wpabuf_free(pub);
  1862. wpabuf_clear_free(secret);
  1863. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1864. }
  1865. hkey = wpabuf_alloc(owe_dh_len - 2 + wpabuf_len(pub) + 2);
  1866. if (!hkey) {
  1867. wpabuf_free(pub);
  1868. wpabuf_clear_free(secret);
  1869. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1870. }
  1871. wpabuf_put_data(hkey, owe_dh + 2, owe_dh_len - 2); /* C */
  1872. wpabuf_put_buf(hkey, pub); /* A */
  1873. wpabuf_free(pub);
  1874. wpabuf_put_le16(hkey, OWE_DH_GROUP); /* group */
  1875. res = hmac_sha256(wpabuf_head(hkey), wpabuf_len(hkey),
  1876. wpabuf_head(secret), wpabuf_len(secret), prk);
  1877. wpabuf_clear_free(hkey);
  1878. wpabuf_clear_free(secret);
  1879. if (res < 0)
  1880. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1881. wpa_hexdump_key(MSG_DEBUG, "OWE: prk", prk, SHA256_MAC_LEN);
  1882. /* PMK = HKDF-expand(prk, "OWE Key Generation", n) */
  1883. os_free(sta->owe_pmk);
  1884. sta->owe_pmk = os_malloc(PMK_LEN);
  1885. if (!sta->owe_pmk) {
  1886. os_memset(prk, 0, SHA256_MAC_LEN);
  1887. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1888. }
  1889. res = hmac_sha256_kdf(prk, SHA256_MAC_LEN, NULL, (const u8 *) info,
  1890. os_strlen(info), sta->owe_pmk, PMK_LEN);
  1891. os_memset(prk, 0, SHA256_MAC_LEN);
  1892. if (res < 0) {
  1893. os_free(sta->owe_pmk);
  1894. sta->owe_pmk = NULL;
  1895. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1896. }
  1897. wpa_hexdump_key(MSG_DEBUG, "OWE: PMK", sta->owe_pmk, PMK_LEN);
  1898. wpa_hexdump(MSG_DEBUG, "OWE: PMKID", pmkid, PMKID_LEN);
  1899. /* TODO: Add PMKSA cache entry */
  1900. return WLAN_STATUS_SUCCESS;
  1901. }
  1902. #endif /* CONFIG_OWE */
  1903. static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
  1904. const u8 *ies, size_t ies_len, int reassoc)
  1905. {
  1906. struct ieee802_11_elems elems;
  1907. u16 resp;
  1908. const u8 *wpa_ie;
  1909. size_t wpa_ie_len;
  1910. const u8 *p2p_dev_addr = NULL;
  1911. if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
  1912. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1913. HOSTAPD_LEVEL_INFO, "Station sent an invalid "
  1914. "association request");
  1915. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  1916. }
  1917. resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
  1918. if (resp != WLAN_STATUS_SUCCESS)
  1919. return resp;
  1920. resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
  1921. if (resp != WLAN_STATUS_SUCCESS)
  1922. return resp;
  1923. resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
  1924. if (resp != WLAN_STATUS_SUCCESS)
  1925. return resp;
  1926. resp = copy_supp_rates(hapd, sta, &elems);
  1927. if (resp != WLAN_STATUS_SUCCESS)
  1928. return resp;
  1929. #ifdef CONFIG_IEEE80211N
  1930. resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities);
  1931. if (resp != WLAN_STATUS_SUCCESS)
  1932. return resp;
  1933. if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
  1934. !(sta->flags & WLAN_STA_HT)) {
  1935. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1936. HOSTAPD_LEVEL_INFO, "Station does not support "
  1937. "mandatory HT PHY - reject association");
  1938. return WLAN_STATUS_ASSOC_DENIED_NO_HT;
  1939. }
  1940. #endif /* CONFIG_IEEE80211N */
  1941. #ifdef CONFIG_IEEE80211AC
  1942. if (hapd->iconf->ieee80211ac) {
  1943. resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities);
  1944. if (resp != WLAN_STATUS_SUCCESS)
  1945. return resp;
  1946. resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
  1947. if (resp != WLAN_STATUS_SUCCESS)
  1948. return resp;
  1949. }
  1950. if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
  1951. !(sta->flags & WLAN_STA_VHT)) {
  1952. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1953. HOSTAPD_LEVEL_INFO, "Station does not support "
  1954. "mandatory VHT PHY - reject association");
  1955. return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
  1956. }
  1957. if (hapd->conf->vendor_vht && !elems.vht_capabilities) {
  1958. resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht,
  1959. elems.vendor_vht_len);
  1960. if (resp != WLAN_STATUS_SUCCESS)
  1961. return resp;
  1962. }
  1963. #endif /* CONFIG_IEEE80211AC */
  1964. #ifdef CONFIG_P2P
  1965. if (elems.p2p) {
  1966. wpabuf_free(sta->p2p_ie);
  1967. sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
  1968. P2P_IE_VENDOR_TYPE);
  1969. if (sta->p2p_ie)
  1970. p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
  1971. } else {
  1972. wpabuf_free(sta->p2p_ie);
  1973. sta->p2p_ie = NULL;
  1974. }
  1975. #endif /* CONFIG_P2P */
  1976. if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
  1977. wpa_ie = elems.rsn_ie;
  1978. wpa_ie_len = elems.rsn_ie_len;
  1979. } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
  1980. elems.wpa_ie) {
  1981. wpa_ie = elems.wpa_ie;
  1982. wpa_ie_len = elems.wpa_ie_len;
  1983. } else {
  1984. wpa_ie = NULL;
  1985. wpa_ie_len = 0;
  1986. }
  1987. #ifdef CONFIG_WPS
  1988. sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
  1989. if (hapd->conf->wps_state && elems.wps_ie) {
  1990. wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
  1991. "Request - assume WPS is used");
  1992. sta->flags |= WLAN_STA_WPS;
  1993. wpabuf_free(sta->wps_ie);
  1994. sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
  1995. WPS_IE_VENDOR_TYPE);
  1996. if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
  1997. wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
  1998. sta->flags |= WLAN_STA_WPS2;
  1999. }
  2000. wpa_ie = NULL;
  2001. wpa_ie_len = 0;
  2002. if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
  2003. wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
  2004. "(Re)Association Request - reject");
  2005. return WLAN_STATUS_INVALID_IE;
  2006. }
  2007. } else if (hapd->conf->wps_state && wpa_ie == NULL) {
  2008. wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
  2009. "(Re)Association Request - possible WPS use");
  2010. sta->flags |= WLAN_STA_MAYBE_WPS;
  2011. } else
  2012. #endif /* CONFIG_WPS */
  2013. if (hapd->conf->wpa && wpa_ie == NULL) {
  2014. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  2015. HOSTAPD_LEVEL_INFO,
  2016. "No WPA/RSN IE in association request");
  2017. return WLAN_STATUS_INVALID_IE;
  2018. }
  2019. if (hapd->conf->wpa && wpa_ie) {
  2020. int res;
  2021. wpa_ie -= 2;
  2022. wpa_ie_len += 2;
  2023. if (sta->wpa_sm == NULL)
  2024. sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
  2025. sta->addr,
  2026. p2p_dev_addr);
  2027. if (sta->wpa_sm == NULL) {
  2028. wpa_printf(MSG_WARNING, "Failed to initialize WPA "
  2029. "state machine");
  2030. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  2031. }
  2032. res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
  2033. wpa_ie, wpa_ie_len,
  2034. elems.mdie, elems.mdie_len,
  2035. elems.owe_dh, elems.owe_dh_len);
  2036. resp = wpa_res_to_status_code(res);
  2037. if (resp != WLAN_STATUS_SUCCESS)
  2038. return resp;
  2039. #ifdef CONFIG_IEEE80211W
  2040. if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
  2041. sta->sa_query_count > 0)
  2042. ap_check_sa_query_timeout(hapd, sta);
  2043. if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
  2044. (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
  2045. /*
  2046. * STA has already been associated with MFP and SA
  2047. * Query timeout has not been reached. Reject the
  2048. * association attempt temporarily and start SA Query,
  2049. * if one is not pending.
  2050. */
  2051. if (sta->sa_query_count == 0)
  2052. ap_sta_start_sa_query(hapd, sta);
  2053. return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
  2054. }
  2055. if (wpa_auth_uses_mfp(sta->wpa_sm))
  2056. sta->flags |= WLAN_STA_MFP;
  2057. else
  2058. sta->flags &= ~WLAN_STA_MFP;
  2059. #endif /* CONFIG_IEEE80211W */
  2060. #ifdef CONFIG_IEEE80211R_AP
  2061. if (sta->auth_alg == WLAN_AUTH_FT) {
  2062. if (!reassoc) {
  2063. wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
  2064. "to use association (not "
  2065. "re-association) with FT auth_alg",
  2066. MAC2STR(sta->addr));
  2067. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  2068. }
  2069. resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
  2070. ies_len);
  2071. if (resp != WLAN_STATUS_SUCCESS)
  2072. return resp;
  2073. }
  2074. #endif /* CONFIG_IEEE80211R_AP */
  2075. #ifdef CONFIG_SAE
  2076. if (wpa_auth_uses_sae(sta->wpa_sm) &&
  2077. sta->auth_alg == WLAN_AUTH_OPEN) {
  2078. struct rsn_pmksa_cache_entry *sa;
  2079. sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
  2080. if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) {
  2081. wpa_printf(MSG_DEBUG,
  2082. "SAE: No PMKSA cache entry found for "
  2083. MACSTR, MAC2STR(sta->addr));
  2084. return WLAN_STATUS_INVALID_PMKID;
  2085. }
  2086. wpa_printf(MSG_DEBUG, "SAE: " MACSTR
  2087. " using PMKSA caching", MAC2STR(sta->addr));
  2088. } else if (wpa_auth_uses_sae(sta->wpa_sm) &&
  2089. sta->auth_alg != WLAN_AUTH_SAE &&
  2090. !(sta->auth_alg == WLAN_AUTH_FT &&
  2091. wpa_auth_uses_ft_sae(sta->wpa_sm))) {
  2092. wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
  2093. "SAE AKM after non-SAE auth_alg %u",
  2094. MAC2STR(sta->addr), sta->auth_alg);
  2095. return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
  2096. }
  2097. #endif /* CONFIG_SAE */
  2098. #ifdef CONFIG_OWE
  2099. if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
  2100. wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE &&
  2101. elems.owe_dh) {
  2102. resp = owe_process_assoc_req(sta, elems.owe_dh,
  2103. elems.owe_dh_len);
  2104. if (resp != WLAN_STATUS_SUCCESS)
  2105. return resp;
  2106. }
  2107. #endif /* CONFIG_OWE */
  2108. #ifdef CONFIG_IEEE80211N
  2109. if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
  2110. wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
  2111. hostapd_logger(hapd, sta->addr,
  2112. HOSTAPD_MODULE_IEEE80211,
  2113. HOSTAPD_LEVEL_INFO,
  2114. "Station tried to use TKIP with HT "
  2115. "association");
  2116. return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
  2117. }
  2118. #endif /* CONFIG_IEEE80211N */
  2119. #ifdef CONFIG_HS20
  2120. } else if (hapd->conf->osen) {
  2121. if (elems.osen == NULL) {
  2122. hostapd_logger(
  2123. hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  2124. HOSTAPD_LEVEL_INFO,
  2125. "No HS 2.0 OSEN element in association request");
  2126. return WLAN_STATUS_INVALID_IE;
  2127. }
  2128. wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
  2129. if (sta->wpa_sm == NULL)
  2130. sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
  2131. sta->addr, NULL);
  2132. if (sta->wpa_sm == NULL) {
  2133. wpa_printf(MSG_WARNING, "Failed to initialize WPA "
  2134. "state machine");
  2135. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  2136. }
  2137. if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
  2138. elems.osen - 2, elems.osen_len + 2) < 0)
  2139. return WLAN_STATUS_INVALID_IE;
  2140. #endif /* CONFIG_HS20 */
  2141. } else
  2142. wpa_auth_sta_no_wpa(sta->wpa_sm);
  2143. #ifdef CONFIG_P2P
  2144. p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
  2145. #endif /* CONFIG_P2P */
  2146. #ifdef CONFIG_HS20
  2147. wpabuf_free(sta->hs20_ie);
  2148. if (elems.hs20 && elems.hs20_len > 4) {
  2149. sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
  2150. elems.hs20_len - 4);
  2151. } else
  2152. sta->hs20_ie = NULL;
  2153. #endif /* CONFIG_HS20 */
  2154. #ifdef CONFIG_FST
  2155. wpabuf_free(sta->mb_ies);
  2156. if (hapd->iface->fst)
  2157. sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
  2158. else
  2159. sta->mb_ies = NULL;
  2160. #endif /* CONFIG_FST */
  2161. #ifdef CONFIG_MBO
  2162. mbo_ap_check_sta_assoc(hapd, sta, &elems);
  2163. if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
  2164. elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
  2165. hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
  2166. wpa_printf(MSG_INFO,
  2167. "MBO: Reject WPA2 association without PMF");
  2168. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  2169. }
  2170. #endif /* CONFIG_MBO */
  2171. ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
  2172. elems.supp_op_classes_len);
  2173. if ((sta->capability & WLAN_CAPABILITY_RADIO_MEASUREMENT) &&
  2174. elems.rrm_enabled &&
  2175. elems.rrm_enabled_len >= sizeof(sta->rrm_enabled_capa))
  2176. os_memcpy(sta->rrm_enabled_capa, elems.rrm_enabled,
  2177. sizeof(sta->rrm_enabled_capa));
  2178. return WLAN_STATUS_SUCCESS;
  2179. }
  2180. static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
  2181. u16 reason_code)
  2182. {
  2183. int send_len;
  2184. struct ieee80211_mgmt reply;
  2185. os_memset(&reply, 0, sizeof(reply));
  2186. reply.frame_control =
  2187. IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
  2188. os_memcpy(reply.da, addr, ETH_ALEN);
  2189. os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
  2190. os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
  2191. send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
  2192. reply.u.deauth.reason_code = host_to_le16(reason_code);
  2193. if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
  2194. wpa_printf(MSG_INFO, "Failed to send deauth: %s",
  2195. strerror(errno));
  2196. }
  2197. static int add_associated_sta(struct hostapd_data *hapd,
  2198. struct sta_info *sta)
  2199. {
  2200. struct ieee80211_ht_capabilities ht_cap;
  2201. struct ieee80211_vht_capabilities vht_cap;
  2202. /*
  2203. * Remove the STA entry to ensure the STA PS state gets cleared and
  2204. * configuration gets updated. This is relevant for cases, such as
  2205. * FT-over-the-DS, where a station re-associates back to the same AP but
  2206. * skips the authentication flow, or if working with a driver that
  2207. * does not support full AP client state.
  2208. */
  2209. if (!sta->added_unassoc)
  2210. hostapd_drv_sta_remove(hapd, sta->addr);
  2211. #ifdef CONFIG_IEEE80211N
  2212. if (sta->flags & WLAN_STA_HT)
  2213. hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
  2214. #endif /* CONFIG_IEEE80211N */
  2215. #ifdef CONFIG_IEEE80211AC
  2216. if (sta->flags & WLAN_STA_VHT)
  2217. hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
  2218. #endif /* CONFIG_IEEE80211AC */
  2219. /*
  2220. * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags
  2221. * will be set when the ACK frame for the (Re)Association Response frame
  2222. * is processed (TX status driver event).
  2223. */
  2224. if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
  2225. sta->supported_rates, sta->supported_rates_len,
  2226. sta->listen_interval,
  2227. sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
  2228. sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
  2229. sta->flags | WLAN_STA_ASSOC, sta->qosinfo,
  2230. sta->vht_opmode, sta->p2p_ie ? 1 : 0,
  2231. sta->added_unassoc)) {
  2232. hostapd_logger(hapd, sta->addr,
  2233. HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_NOTICE,
  2234. "Could not %s STA to kernel driver",
  2235. sta->added_unassoc ? "set" : "add");
  2236. if (sta->added_unassoc) {
  2237. hostapd_drv_sta_remove(hapd, sta->addr);
  2238. sta->added_unassoc = 0;
  2239. }
  2240. return -1;
  2241. }
  2242. sta->added_unassoc = 0;
  2243. return 0;
  2244. }
  2245. static u16 send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
  2246. const u8 *addr, u16 status_code, int reassoc,
  2247. const u8 *ies, size_t ies_len)
  2248. {
  2249. int send_len;
  2250. u8 *buf;
  2251. size_t buflen;
  2252. struct ieee80211_mgmt *reply;
  2253. u8 *p;
  2254. u16 res = WLAN_STATUS_SUCCESS;
  2255. buflen = sizeof(struct ieee80211_mgmt) + 1024;
  2256. #ifdef CONFIG_FILS
  2257. if (sta && sta->fils_hlp_resp)
  2258. buflen += wpabuf_len(sta->fils_hlp_resp);
  2259. #endif /* CONFIG_FILS */
  2260. #ifdef CONFIG_OWE
  2261. if (sta && (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE))
  2262. buflen += 50;
  2263. #endif /* CONFIG_OWE */
  2264. buf = os_zalloc(buflen);
  2265. if (!buf) {
  2266. res = WLAN_STATUS_UNSPECIFIED_FAILURE;
  2267. goto done;
  2268. }
  2269. reply = (struct ieee80211_mgmt *) buf;
  2270. reply->frame_control =
  2271. IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  2272. (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
  2273. WLAN_FC_STYPE_ASSOC_RESP));
  2274. os_memcpy(reply->da, addr, ETH_ALEN);
  2275. os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
  2276. os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
  2277. send_len = IEEE80211_HDRLEN;
  2278. send_len += sizeof(reply->u.assoc_resp);
  2279. reply->u.assoc_resp.capab_info =
  2280. host_to_le16(hostapd_own_capab_info(hapd));
  2281. reply->u.assoc_resp.status_code = host_to_le16(status_code);
  2282. reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0) |
  2283. BIT(14) | BIT(15));
  2284. /* Supported rates */
  2285. p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
  2286. /* Extended supported rates */
  2287. p = hostapd_eid_ext_supp_rates(hapd, p);
  2288. #ifdef CONFIG_IEEE80211R_AP
  2289. if (sta && status_code == WLAN_STATUS_SUCCESS) {
  2290. /* IEEE 802.11r: Mobility Domain Information, Fast BSS
  2291. * Transition Information, RSN, [RIC Response] */
  2292. p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
  2293. buf + buflen - p,
  2294. sta->auth_alg, ies, ies_len);
  2295. }
  2296. #endif /* CONFIG_IEEE80211R_AP */
  2297. #ifdef CONFIG_IEEE80211W
  2298. if (sta && status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
  2299. p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
  2300. #endif /* CONFIG_IEEE80211W */
  2301. #ifdef CONFIG_IEEE80211N
  2302. p = hostapd_eid_ht_capabilities(hapd, p);
  2303. p = hostapd_eid_ht_operation(hapd, p);
  2304. #endif /* CONFIG_IEEE80211N */
  2305. #ifdef CONFIG_IEEE80211AC
  2306. if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
  2307. u32 nsts = 0, sta_nsts;
  2308. if (sta && hapd->conf->use_sta_nsts && sta->vht_capabilities) {
  2309. struct ieee80211_vht_capabilities *capa;
  2310. nsts = (hapd->iface->conf->vht_capab >>
  2311. VHT_CAP_BEAMFORMEE_STS_OFFSET) & 7;
  2312. capa = sta->vht_capabilities;
  2313. sta_nsts = (le_to_host32(capa->vht_capabilities_info) >>
  2314. VHT_CAP_BEAMFORMEE_STS_OFFSET) & 7;
  2315. if (nsts < sta_nsts)
  2316. nsts = 0;
  2317. else
  2318. nsts = sta_nsts;
  2319. }
  2320. p = hostapd_eid_vht_capabilities(hapd, p, nsts);
  2321. p = hostapd_eid_vht_operation(hapd, p);
  2322. }
  2323. #endif /* CONFIG_IEEE80211AC */
  2324. p = hostapd_eid_ext_capab(hapd, p);
  2325. p = hostapd_eid_bss_max_idle_period(hapd, p);
  2326. if (sta && sta->qos_map_enabled)
  2327. p = hostapd_eid_qos_map_set(hapd, p);
  2328. #ifdef CONFIG_FST
  2329. if (hapd->iface->fst_ies) {
  2330. os_memcpy(p, wpabuf_head(hapd->iface->fst_ies),
  2331. wpabuf_len(hapd->iface->fst_ies));
  2332. p += wpabuf_len(hapd->iface->fst_ies);
  2333. }
  2334. #endif /* CONFIG_FST */
  2335. #ifdef CONFIG_IEEE80211AC
  2336. if (sta && hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT))
  2337. p = hostapd_eid_vendor_vht(hapd, p);
  2338. #endif /* CONFIG_IEEE80211AC */
  2339. if (sta && (sta->flags & WLAN_STA_WMM))
  2340. p = hostapd_eid_wmm(hapd, p);
  2341. #ifdef CONFIG_WPS
  2342. if (sta &&
  2343. ((sta->flags & WLAN_STA_WPS) ||
  2344. ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa))) {
  2345. struct wpabuf *wps = wps_build_assoc_resp_ie();
  2346. if (wps) {
  2347. os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
  2348. p += wpabuf_len(wps);
  2349. wpabuf_free(wps);
  2350. }
  2351. }
  2352. #endif /* CONFIG_WPS */
  2353. #ifdef CONFIG_P2P
  2354. if (sta && sta->p2p_ie && hapd->p2p_group) {
  2355. struct wpabuf *p2p_resp_ie;
  2356. enum p2p_status_code status;
  2357. switch (status_code) {
  2358. case WLAN_STATUS_SUCCESS:
  2359. status = P2P_SC_SUCCESS;
  2360. break;
  2361. case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
  2362. status = P2P_SC_FAIL_LIMIT_REACHED;
  2363. break;
  2364. default:
  2365. status = P2P_SC_FAIL_INVALID_PARAMS;
  2366. break;
  2367. }
  2368. p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
  2369. if (p2p_resp_ie) {
  2370. os_memcpy(p, wpabuf_head(p2p_resp_ie),
  2371. wpabuf_len(p2p_resp_ie));
  2372. p += wpabuf_len(p2p_resp_ie);
  2373. wpabuf_free(p2p_resp_ie);
  2374. }
  2375. }
  2376. #endif /* CONFIG_P2P */
  2377. #ifdef CONFIG_P2P_MANAGER
  2378. if (hapd->conf->p2p & P2P_MANAGE)
  2379. p = hostapd_eid_p2p_manage(hapd, p);
  2380. #endif /* CONFIG_P2P_MANAGER */
  2381. p = hostapd_eid_mbo(hapd, p, buf + buflen - p);
  2382. if (hapd->conf->assocresp_elements &&
  2383. (size_t) (buf + buflen - p) >=
  2384. wpabuf_len(hapd->conf->assocresp_elements)) {
  2385. os_memcpy(p, wpabuf_head(hapd->conf->assocresp_elements),
  2386. wpabuf_len(hapd->conf->assocresp_elements));
  2387. p += wpabuf_len(hapd->conf->assocresp_elements);
  2388. }
  2389. send_len += p - reply->u.assoc_resp.variable;
  2390. #ifdef CONFIG_FILS
  2391. if (sta &&
  2392. (sta->auth_alg == WLAN_AUTH_FILS_SK ||
  2393. sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
  2394. sta->auth_alg == WLAN_AUTH_FILS_PK) &&
  2395. status_code == WLAN_STATUS_SUCCESS) {
  2396. struct ieee802_11_elems elems;
  2397. if (ieee802_11_parse_elems(ies, ies_len, &elems, 0) ==
  2398. ParseFailed || !elems.fils_session) {
  2399. res = WLAN_STATUS_UNSPECIFIED_FAILURE;
  2400. goto done;
  2401. }
  2402. /* FILS Session */
  2403. *p++ = WLAN_EID_EXTENSION; /* Element ID */
  2404. *p++ = 1 + FILS_SESSION_LEN; /* Length */
  2405. *p++ = WLAN_EID_EXT_FILS_SESSION; /* Element ID Extension */
  2406. os_memcpy(p, elems.fils_session, FILS_SESSION_LEN);
  2407. send_len += 2 + 1 + FILS_SESSION_LEN;
  2408. send_len = fils_encrypt_assoc(sta->wpa_sm, buf, send_len,
  2409. buflen, sta->fils_hlp_resp);
  2410. if (send_len < 0) {
  2411. res = WLAN_STATUS_UNSPECIFIED_FAILURE;
  2412. goto done;
  2413. }
  2414. }
  2415. #endif /* CONFIG_FILS */
  2416. #ifdef CONFIG_OWE
  2417. if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
  2418. sta && sta->owe_ecdh &&
  2419. wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE) {
  2420. struct wpabuf *pub;
  2421. pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0);
  2422. if (!pub) {
  2423. res = WLAN_STATUS_UNSPECIFIED_FAILURE;
  2424. goto done;
  2425. }
  2426. /* OWE Diffie-Hellman Parameter element */
  2427. *p++ = WLAN_EID_EXTENSION; /* Element ID */
  2428. *p++ = 1 + 2 + wpabuf_len(pub); /* Length */
  2429. *p++ = WLAN_EID_EXT_OWE_DH_PARAM; /* Element ID Extension */
  2430. WPA_PUT_LE16(p, OWE_DH_GROUP);
  2431. p += 2;
  2432. os_memcpy(p, wpabuf_head(pub), wpabuf_len(pub));
  2433. p += wpabuf_len(pub);
  2434. send_len += 3 + 2 + wpabuf_len(pub);
  2435. wpabuf_free(pub);
  2436. }
  2437. #endif /* CONFIG_OWE */
  2438. if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0) {
  2439. wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
  2440. strerror(errno));
  2441. res = WLAN_STATUS_UNSPECIFIED_FAILURE;
  2442. }
  2443. done:
  2444. os_free(buf);
  2445. return res;
  2446. }
  2447. #ifdef CONFIG_FILS
  2448. void fils_hlp_finish_assoc(struct hostapd_data *hapd, struct sta_info *sta)
  2449. {
  2450. u16 reply_res;
  2451. wpa_printf(MSG_DEBUG, "FILS: Finish association with " MACSTR,
  2452. MAC2STR(sta->addr));
  2453. eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
  2454. if (!sta->fils_pending_assoc_req)
  2455. return;
  2456. reply_res = send_assoc_resp(hapd, sta, sta->addr, WLAN_STATUS_SUCCESS,
  2457. sta->fils_pending_assoc_is_reassoc,
  2458. sta->fils_pending_assoc_req,
  2459. sta->fils_pending_assoc_req_len);
  2460. os_free(sta->fils_pending_assoc_req);
  2461. sta->fils_pending_assoc_req = NULL;
  2462. sta->fils_pending_assoc_req_len = 0;
  2463. wpabuf_free(sta->fils_hlp_resp);
  2464. sta->fils_hlp_resp = NULL;
  2465. wpabuf_free(sta->hlp_dhcp_discover);
  2466. sta->hlp_dhcp_discover = NULL;
  2467. /*
  2468. * Remove the station in case tranmission of a success response fails
  2469. * (the STA was added associated to the driver) or if the station was
  2470. * previously added unassociated.
  2471. */
  2472. if (reply_res != WLAN_STATUS_SUCCESS || sta->added_unassoc) {
  2473. hostapd_drv_sta_remove(hapd, sta->addr);
  2474. sta->added_unassoc = 0;
  2475. }
  2476. }
  2477. void fils_hlp_timeout(void *eloop_ctx, void *eloop_data)
  2478. {
  2479. struct hostapd_data *hapd = eloop_ctx;
  2480. struct sta_info *sta = eloop_data;
  2481. wpa_printf(MSG_DEBUG,
  2482. "FILS: HLP response timeout - continue with association response for "
  2483. MACSTR, MAC2STR(sta->addr));
  2484. if (sta->fils_drv_assoc_finish)
  2485. hostapd_notify_assoc_fils_finish(hapd, sta);
  2486. else
  2487. fils_hlp_finish_assoc(hapd, sta);
  2488. }
  2489. #endif /* CONFIG_FILS */
  2490. static void handle_assoc(struct hostapd_data *hapd,
  2491. const struct ieee80211_mgmt *mgmt, size_t len,
  2492. int reassoc)
  2493. {
  2494. u16 capab_info, listen_interval, seq_ctrl, fc;
  2495. u16 resp = WLAN_STATUS_SUCCESS, reply_res;
  2496. const u8 *pos;
  2497. int left, i;
  2498. struct sta_info *sta;
  2499. u8 *tmp = NULL;
  2500. struct hostapd_sta_wpa_psk_short *psk = NULL;
  2501. char *identity = NULL;
  2502. char *radius_cui = NULL;
  2503. #ifdef CONFIG_FILS
  2504. int delay_assoc = 0;
  2505. #endif /* CONFIG_FILS */
  2506. if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
  2507. sizeof(mgmt->u.assoc_req))) {
  2508. wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
  2509. reassoc, (unsigned long) len);
  2510. return;
  2511. }
  2512. #ifdef CONFIG_TESTING_OPTIONS
  2513. if (reassoc) {
  2514. if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
  2515. drand48() < hapd->iconf->ignore_reassoc_probability) {
  2516. wpa_printf(MSG_INFO,
  2517. "TESTING: ignoring reassoc request from "
  2518. MACSTR, MAC2STR(mgmt->sa));
  2519. return;
  2520. }
  2521. } else {
  2522. if (hapd->iconf->ignore_assoc_probability > 0.0 &&
  2523. drand48() < hapd->iconf->ignore_assoc_probability) {
  2524. wpa_printf(MSG_INFO,
  2525. "TESTING: ignoring assoc request from "
  2526. MACSTR, MAC2STR(mgmt->sa));
  2527. return;
  2528. }
  2529. }
  2530. #endif /* CONFIG_TESTING_OPTIONS */
  2531. fc = le_to_host16(mgmt->frame_control);
  2532. seq_ctrl = le_to_host16(mgmt->seq_ctrl);
  2533. if (reassoc) {
  2534. capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
  2535. listen_interval = le_to_host16(
  2536. mgmt->u.reassoc_req.listen_interval);
  2537. wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
  2538. " capab_info=0x%02x listen_interval=%d current_ap="
  2539. MACSTR " seq_ctrl=0x%x%s",
  2540. MAC2STR(mgmt->sa), capab_info, listen_interval,
  2541. MAC2STR(mgmt->u.reassoc_req.current_ap),
  2542. seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
  2543. left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
  2544. pos = mgmt->u.reassoc_req.variable;
  2545. } else {
  2546. capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
  2547. listen_interval = le_to_host16(
  2548. mgmt->u.assoc_req.listen_interval);
  2549. wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
  2550. " capab_info=0x%02x listen_interval=%d "
  2551. "seq_ctrl=0x%x%s",
  2552. MAC2STR(mgmt->sa), capab_info, listen_interval,
  2553. seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
  2554. left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
  2555. pos = mgmt->u.assoc_req.variable;
  2556. }
  2557. sta = ap_get_sta(hapd, mgmt->sa);
  2558. #ifdef CONFIG_IEEE80211R_AP
  2559. if (sta && sta->auth_alg == WLAN_AUTH_FT &&
  2560. (sta->flags & WLAN_STA_AUTH) == 0) {
  2561. wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
  2562. "prior to authentication since it is using "
  2563. "over-the-DS FT", MAC2STR(mgmt->sa));
  2564. /*
  2565. * Mark station as authenticated, to avoid adding station
  2566. * entry in the driver as associated and not authenticated
  2567. */
  2568. sta->flags |= WLAN_STA_AUTH;
  2569. } else
  2570. #endif /* CONFIG_IEEE80211R_AP */
  2571. if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
  2572. if (hapd->iface->current_mode &&
  2573. hapd->iface->current_mode->mode ==
  2574. HOSTAPD_MODE_IEEE80211AD) {
  2575. int acl_res;
  2576. u32 session_timeout, acct_interim_interval;
  2577. struct vlan_description vlan_id;
  2578. acl_res = ieee802_11_allowed_address(
  2579. hapd, mgmt->sa, (const u8 *) mgmt, len,
  2580. &session_timeout, &acct_interim_interval,
  2581. &vlan_id, &psk, &identity, &radius_cui);
  2582. if (acl_res == HOSTAPD_ACL_REJECT) {
  2583. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  2584. goto fail;
  2585. }
  2586. if (acl_res == HOSTAPD_ACL_PENDING)
  2587. return;
  2588. /* DMG/IEEE 802.11ad does not use authentication.
  2589. * Allocate sta entry upon association. */
  2590. sta = ap_sta_add(hapd, mgmt->sa);
  2591. if (!sta) {
  2592. hostapd_logger(hapd, mgmt->sa,
  2593. HOSTAPD_MODULE_IEEE80211,
  2594. HOSTAPD_LEVEL_INFO,
  2595. "Failed to add STA");
  2596. resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
  2597. goto fail;
  2598. }
  2599. acl_res = ieee802_11_set_radius_info(
  2600. hapd, sta, acl_res, session_timeout,
  2601. acct_interim_interval, &vlan_id, &psk,
  2602. &identity, &radius_cui);
  2603. if (acl_res) {
  2604. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  2605. goto fail;
  2606. }
  2607. hostapd_logger(hapd, sta->addr,
  2608. HOSTAPD_MODULE_IEEE80211,
  2609. HOSTAPD_LEVEL_DEBUG,
  2610. "Skip authentication for DMG/IEEE 802.11ad");
  2611. sta->flags |= WLAN_STA_AUTH;
  2612. wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
  2613. sta->auth_alg = WLAN_AUTH_OPEN;
  2614. } else {
  2615. hostapd_logger(hapd, mgmt->sa,
  2616. HOSTAPD_MODULE_IEEE80211,
  2617. HOSTAPD_LEVEL_INFO,
  2618. "Station tried to associate before authentication (aid=%d flags=0x%x)",
  2619. sta ? sta->aid : -1,
  2620. sta ? sta->flags : 0);
  2621. send_deauth(hapd, mgmt->sa,
  2622. WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
  2623. return;
  2624. }
  2625. }
  2626. if ((fc & WLAN_FC_RETRY) &&
  2627. sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
  2628. sta->last_seq_ctrl == seq_ctrl &&
  2629. sta->last_subtype == (reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
  2630. WLAN_FC_STYPE_ASSOC_REQ)) {
  2631. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  2632. HOSTAPD_LEVEL_DEBUG,
  2633. "Drop repeated association frame seq_ctrl=0x%x",
  2634. seq_ctrl);
  2635. return;
  2636. }
  2637. sta->last_seq_ctrl = seq_ctrl;
  2638. sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
  2639. WLAN_FC_STYPE_ASSOC_REQ;
  2640. if (hapd->tkip_countermeasures) {
  2641. resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
  2642. goto fail;
  2643. }
  2644. if (listen_interval > hapd->conf->max_listen_interval) {
  2645. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  2646. HOSTAPD_LEVEL_DEBUG,
  2647. "Too large Listen Interval (%d)",
  2648. listen_interval);
  2649. resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
  2650. goto fail;
  2651. }
  2652. #ifdef CONFIG_MBO
  2653. if (hapd->conf->mbo_enabled && hapd->mbo_assoc_disallow) {
  2654. resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
  2655. goto fail;
  2656. }
  2657. #endif /* CONFIG_MBO */
  2658. /*
  2659. * sta->capability is used in check_assoc_ies() for RRM enabled
  2660. * capability element.
  2661. */
  2662. sta->capability = capab_info;
  2663. #ifdef CONFIG_FILS
  2664. if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
  2665. sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
  2666. sta->auth_alg == WLAN_AUTH_FILS_PK) {
  2667. /* The end of the payload is encrypted. Need to decrypt it
  2668. * before parsing. */
  2669. tmp = os_memdup(pos, left);
  2670. if (!tmp) {
  2671. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  2672. goto fail;
  2673. }
  2674. left = fils_decrypt_assoc(sta->wpa_sm, sta->fils_session, mgmt,
  2675. len, tmp, left);
  2676. if (left < 0) {
  2677. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  2678. goto fail;
  2679. }
  2680. pos = tmp;
  2681. }
  2682. #endif /* CONFIG_FILS */
  2683. /* followed by SSID and Supported rates; and HT capabilities if 802.11n
  2684. * is used */
  2685. resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
  2686. if (resp != WLAN_STATUS_SUCCESS)
  2687. goto fail;
  2688. if (hostapd_get_aid(hapd, sta) < 0) {
  2689. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  2690. HOSTAPD_LEVEL_INFO, "No room for more AIDs");
  2691. resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
  2692. goto fail;
  2693. }
  2694. sta->listen_interval = listen_interval;
  2695. if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
  2696. sta->flags |= WLAN_STA_NONERP;
  2697. for (i = 0; i < sta->supported_rates_len; i++) {
  2698. if ((sta->supported_rates[i] & 0x7f) > 22) {
  2699. sta->flags &= ~WLAN_STA_NONERP;
  2700. break;
  2701. }
  2702. }
  2703. if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
  2704. sta->nonerp_set = 1;
  2705. hapd->iface->num_sta_non_erp++;
  2706. if (hapd->iface->num_sta_non_erp == 1)
  2707. ieee802_11_set_beacons(hapd->iface);
  2708. }
  2709. if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
  2710. !sta->no_short_slot_time_set) {
  2711. sta->no_short_slot_time_set = 1;
  2712. hapd->iface->num_sta_no_short_slot_time++;
  2713. if (hapd->iface->current_mode->mode ==
  2714. HOSTAPD_MODE_IEEE80211G &&
  2715. hapd->iface->num_sta_no_short_slot_time == 1)
  2716. ieee802_11_set_beacons(hapd->iface);
  2717. }
  2718. if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  2719. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  2720. else
  2721. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  2722. if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
  2723. !sta->no_short_preamble_set) {
  2724. sta->no_short_preamble_set = 1;
  2725. hapd->iface->num_sta_no_short_preamble++;
  2726. if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
  2727. && hapd->iface->num_sta_no_short_preamble == 1)
  2728. ieee802_11_set_beacons(hapd->iface);
  2729. }
  2730. #ifdef CONFIG_IEEE80211N
  2731. update_ht_state(hapd, sta);
  2732. #endif /* CONFIG_IEEE80211N */
  2733. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  2734. HOSTAPD_LEVEL_DEBUG,
  2735. "association OK (aid %d)", sta->aid);
  2736. /* Station will be marked associated, after it acknowledges AssocResp
  2737. */
  2738. sta->flags |= WLAN_STA_ASSOC_REQ_OK;
  2739. #ifdef CONFIG_IEEE80211W
  2740. if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
  2741. wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
  2742. "SA Query procedure", reassoc ? "re" : "");
  2743. /* TODO: Send a protected Disassociate frame to the STA using
  2744. * the old key and Reason Code "Previous Authentication no
  2745. * longer valid". Make sure this is only sent protected since
  2746. * unprotected frame would be received by the STA that is now
  2747. * trying to associate.
  2748. */
  2749. }
  2750. #endif /* CONFIG_IEEE80211W */
  2751. /* Make sure that the previously registered inactivity timer will not
  2752. * remove the STA immediately. */
  2753. sta->timeout_next = STA_NULLFUNC;
  2754. #ifdef CONFIG_TAXONOMY
  2755. taxonomy_sta_info_assoc_req(hapd, sta, pos, left);
  2756. #endif /* CONFIG_TAXONOMY */
  2757. sta->pending_wds_enable = 0;
  2758. #ifdef CONFIG_FILS
  2759. if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
  2760. sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
  2761. sta->auth_alg == WLAN_AUTH_FILS_PK) {
  2762. if (fils_process_hlp(hapd, sta, pos, left) > 0)
  2763. delay_assoc = 1;
  2764. }
  2765. #endif /* CONFIG_FILS */
  2766. fail:
  2767. os_free(identity);
  2768. os_free(radius_cui);
  2769. hostapd_free_psk_list(psk);
  2770. /*
  2771. * In case of a successful response, add the station to the driver.
  2772. * Otherwise, the kernel may ignore Data frames before we process the
  2773. * ACK frame (TX status). In case of a failure, this station will be
  2774. * removed.
  2775. *
  2776. * Note that this is not compliant with the IEEE 802.11 standard that
  2777. * states that a non-AP station should transition into the
  2778. * authenticated/associated state only after the station acknowledges
  2779. * the (Re)Association Response frame. However, still do this as:
  2780. *
  2781. * 1. In case the station does not acknowledge the (Re)Association
  2782. * Response frame, it will be removed.
  2783. * 2. Data frames will be dropped in the kernel until the station is
  2784. * set into authorized state, and there are no significant known
  2785. * issues with processing other non-Data Class 3 frames during this
  2786. * window.
  2787. */
  2788. if (resp == WLAN_STATUS_SUCCESS && sta && add_associated_sta(hapd, sta))
  2789. resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
  2790. #ifdef CONFIG_FILS
  2791. if (sta) {
  2792. eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
  2793. os_free(sta->fils_pending_assoc_req);
  2794. sta->fils_pending_assoc_req = NULL;
  2795. sta->fils_pending_assoc_req_len = 0;
  2796. wpabuf_free(sta->fils_hlp_resp);
  2797. sta->fils_hlp_resp = NULL;
  2798. }
  2799. if (sta && delay_assoc && resp == WLAN_STATUS_SUCCESS) {
  2800. sta->fils_pending_assoc_req = tmp;
  2801. sta->fils_pending_assoc_req_len = left;
  2802. sta->fils_pending_assoc_is_reassoc = reassoc;
  2803. sta->fils_drv_assoc_finish = 0;
  2804. wpa_printf(MSG_DEBUG,
  2805. "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
  2806. MACSTR, MAC2STR(sta->addr));
  2807. eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
  2808. eloop_register_timeout(0, hapd->conf->fils_hlp_wait_time * 1024,
  2809. fils_hlp_timeout, hapd, sta);
  2810. return;
  2811. }
  2812. #endif /* CONFIG_FILS */
  2813. reply_res = send_assoc_resp(hapd, sta, mgmt->sa, resp, reassoc, pos,
  2814. left);
  2815. os_free(tmp);
  2816. /*
  2817. * Remove the station in case tranmission of a success response fails
  2818. * (the STA was added associated to the driver) or if the station was
  2819. * previously added unassociated.
  2820. */
  2821. if (sta && ((reply_res != WLAN_STATUS_SUCCESS &&
  2822. resp == WLAN_STATUS_SUCCESS) || sta->added_unassoc)) {
  2823. hostapd_drv_sta_remove(hapd, sta->addr);
  2824. sta->added_unassoc = 0;
  2825. }
  2826. }
  2827. static void handle_disassoc(struct hostapd_data *hapd,
  2828. const struct ieee80211_mgmt *mgmt, size_t len)
  2829. {
  2830. struct sta_info *sta;
  2831. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
  2832. wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
  2833. (unsigned long) len);
  2834. return;
  2835. }
  2836. wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
  2837. MAC2STR(mgmt->sa),
  2838. le_to_host16(mgmt->u.disassoc.reason_code));
  2839. sta = ap_get_sta(hapd, mgmt->sa);
  2840. if (sta == NULL) {
  2841. wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
  2842. MAC2STR(mgmt->sa));
  2843. return;
  2844. }
  2845. ap_sta_set_authorized(hapd, sta, 0);
  2846. sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
  2847. sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
  2848. wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
  2849. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  2850. HOSTAPD_LEVEL_INFO, "disassociated");
  2851. sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
  2852. ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
  2853. /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
  2854. * authenticated. */
  2855. accounting_sta_stop(hapd, sta);
  2856. ieee802_1x_free_station(hapd, sta);
  2857. if (sta->ipaddr)
  2858. hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
  2859. ap_sta_ip6addr_del(hapd, sta);
  2860. hostapd_drv_sta_remove(hapd, sta->addr);
  2861. sta->added_unassoc = 0;
  2862. if (sta->timeout_next == STA_NULLFUNC ||
  2863. sta->timeout_next == STA_DISASSOC) {
  2864. sta->timeout_next = STA_DEAUTH;
  2865. eloop_cancel_timeout(ap_handle_timer, hapd, sta);
  2866. eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
  2867. hapd, sta);
  2868. }
  2869. mlme_disassociate_indication(
  2870. hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
  2871. /* DMG/IEEE 802.11ad does not use deauthication. Deallocate sta upon
  2872. * disassociation. */
  2873. if (hapd->iface->current_mode &&
  2874. hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
  2875. sta->flags &= ~WLAN_STA_AUTH;
  2876. wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
  2877. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  2878. HOSTAPD_LEVEL_DEBUG, "deauthenticated");
  2879. ap_free_sta(hapd, sta);
  2880. }
  2881. }
  2882. static void handle_deauth(struct hostapd_data *hapd,
  2883. const struct ieee80211_mgmt *mgmt, size_t len)
  2884. {
  2885. struct sta_info *sta;
  2886. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
  2887. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
  2888. "payload (len=%lu)", (unsigned long) len);
  2889. return;
  2890. }
  2891. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
  2892. " reason_code=%d",
  2893. MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
  2894. sta = ap_get_sta(hapd, mgmt->sa);
  2895. if (sta == NULL) {
  2896. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
  2897. "to deauthenticate, but it is not authenticated",
  2898. MAC2STR(mgmt->sa));
  2899. return;
  2900. }
  2901. ap_sta_set_authorized(hapd, sta, 0);
  2902. sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
  2903. sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
  2904. WLAN_STA_ASSOC_REQ_OK);
  2905. wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
  2906. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  2907. HOSTAPD_LEVEL_DEBUG, "deauthenticated");
  2908. mlme_deauthenticate_indication(
  2909. hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
  2910. sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
  2911. ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
  2912. ap_free_sta(hapd, sta);
  2913. }
  2914. static void handle_beacon(struct hostapd_data *hapd,
  2915. const struct ieee80211_mgmt *mgmt, size_t len,
  2916. struct hostapd_frame_info *fi)
  2917. {
  2918. struct ieee802_11_elems elems;
  2919. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
  2920. wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
  2921. (unsigned long) len);
  2922. return;
  2923. }
  2924. (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
  2925. len - (IEEE80211_HDRLEN +
  2926. sizeof(mgmt->u.beacon)), &elems,
  2927. 0);
  2928. ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
  2929. }
  2930. #ifdef CONFIG_IEEE80211W
  2931. static int hostapd_sa_query_action(struct hostapd_data *hapd,
  2932. const struct ieee80211_mgmt *mgmt,
  2933. size_t len)
  2934. {
  2935. const u8 *end;
  2936. end = mgmt->u.action.u.sa_query_resp.trans_id +
  2937. WLAN_SA_QUERY_TR_ID_LEN;
  2938. if (((u8 *) mgmt) + len < end) {
  2939. wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
  2940. "frame (len=%lu)", (unsigned long) len);
  2941. return 0;
  2942. }
  2943. ieee802_11_sa_query_action(hapd, mgmt->sa,
  2944. mgmt->u.action.u.sa_query_resp.action,
  2945. mgmt->u.action.u.sa_query_resp.trans_id);
  2946. return 1;
  2947. }
  2948. static int robust_action_frame(u8 category)
  2949. {
  2950. return category != WLAN_ACTION_PUBLIC &&
  2951. category != WLAN_ACTION_HT;
  2952. }
  2953. #endif /* CONFIG_IEEE80211W */
  2954. static int handle_action(struct hostapd_data *hapd,
  2955. const struct ieee80211_mgmt *mgmt, size_t len)
  2956. {
  2957. struct sta_info *sta;
  2958. sta = ap_get_sta(hapd, mgmt->sa);
  2959. if (len < IEEE80211_HDRLEN + 1) {
  2960. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  2961. HOSTAPD_LEVEL_DEBUG,
  2962. "handle_action - too short payload (len=%lu)",
  2963. (unsigned long) len);
  2964. return 0;
  2965. }
  2966. if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
  2967. (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
  2968. wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
  2969. "frame (category=%u) from unassociated STA " MACSTR,
  2970. mgmt->u.action.category, MAC2STR(mgmt->sa));
  2971. return 0;
  2972. }
  2973. #ifdef CONFIG_IEEE80211W
  2974. if (sta && (sta->flags & WLAN_STA_MFP) &&
  2975. !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
  2976. robust_action_frame(mgmt->u.action.category)) {
  2977. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  2978. HOSTAPD_LEVEL_DEBUG,
  2979. "Dropped unprotected Robust Action frame from "
  2980. "an MFP STA");
  2981. return 0;
  2982. }
  2983. #endif /* CONFIG_IEEE80211W */
  2984. if (sta) {
  2985. u16 fc = le_to_host16(mgmt->frame_control);
  2986. u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
  2987. if ((fc & WLAN_FC_RETRY) &&
  2988. sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
  2989. sta->last_seq_ctrl == seq_ctrl &&
  2990. sta->last_subtype == WLAN_FC_STYPE_ACTION) {
  2991. hostapd_logger(hapd, sta->addr,
  2992. HOSTAPD_MODULE_IEEE80211,
  2993. HOSTAPD_LEVEL_DEBUG,
  2994. "Drop repeated action frame seq_ctrl=0x%x",
  2995. seq_ctrl);
  2996. return 1;
  2997. }
  2998. sta->last_seq_ctrl = seq_ctrl;
  2999. sta->last_subtype = WLAN_FC_STYPE_ACTION;
  3000. }
  3001. switch (mgmt->u.action.category) {
  3002. #ifdef CONFIG_IEEE80211R_AP
  3003. case WLAN_ACTION_FT:
  3004. if (!sta ||
  3005. wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
  3006. len - IEEE80211_HDRLEN))
  3007. break;
  3008. return 1;
  3009. #endif /* CONFIG_IEEE80211R_AP */
  3010. case WLAN_ACTION_WMM:
  3011. hostapd_wmm_action(hapd, mgmt, len);
  3012. return 1;
  3013. #ifdef CONFIG_IEEE80211W
  3014. case WLAN_ACTION_SA_QUERY:
  3015. return hostapd_sa_query_action(hapd, mgmt, len);
  3016. #endif /* CONFIG_IEEE80211W */
  3017. #ifdef CONFIG_WNM_AP
  3018. case WLAN_ACTION_WNM:
  3019. ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
  3020. return 1;
  3021. #endif /* CONFIG_WNM_AP */
  3022. #ifdef CONFIG_FST
  3023. case WLAN_ACTION_FST:
  3024. if (hapd->iface->fst)
  3025. fst_rx_action(hapd->iface->fst, mgmt, len);
  3026. else
  3027. wpa_printf(MSG_DEBUG,
  3028. "FST: Ignore FST Action frame - no FST attached");
  3029. return 1;
  3030. #endif /* CONFIG_FST */
  3031. case WLAN_ACTION_PUBLIC:
  3032. case WLAN_ACTION_PROTECTED_DUAL:
  3033. #ifdef CONFIG_IEEE80211N
  3034. if (len >= IEEE80211_HDRLEN + 2 &&
  3035. mgmt->u.action.u.public_action.action ==
  3036. WLAN_PA_20_40_BSS_COEX) {
  3037. wpa_printf(MSG_DEBUG,
  3038. "HT20/40 coex mgmt frame received from STA "
  3039. MACSTR, MAC2STR(mgmt->sa));
  3040. hostapd_2040_coex_action(hapd, mgmt, len);
  3041. return 1;
  3042. }
  3043. #endif /* CONFIG_IEEE80211N */
  3044. #ifdef CONFIG_DPP
  3045. if (len >= IEEE80211_HDRLEN + 6 &&
  3046. mgmt->u.action.u.vs_public_action.action ==
  3047. WLAN_PA_VENDOR_SPECIFIC &&
  3048. WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
  3049. OUI_WFA &&
  3050. mgmt->u.action.u.vs_public_action.variable[0] ==
  3051. DPP_OUI_TYPE) {
  3052. const u8 *pos, *end;
  3053. pos = &mgmt->u.action.u.vs_public_action.variable[1];
  3054. end = ((const u8 *) mgmt) + len;
  3055. hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos,
  3056. hapd->iface->freq);
  3057. return 1;
  3058. }
  3059. if (len >= IEEE80211_HDRLEN + 2 &&
  3060. (mgmt->u.action.u.public_action.action ==
  3061. WLAN_PA_GAS_INITIAL_RESP ||
  3062. mgmt->u.action.u.public_action.action ==
  3063. WLAN_PA_GAS_COMEBACK_RESP)) {
  3064. const u8 *pos, *end;
  3065. pos = &mgmt->u.action.u.public_action.action;
  3066. end = ((const u8 *) mgmt) + len;
  3067. gas_query_ap_rx(hapd->gas, mgmt->sa,
  3068. mgmt->u.action.category,
  3069. pos, end - pos, hapd->iface->freq);
  3070. return 1;
  3071. }
  3072. #endif /* CONFIG_DPP */
  3073. if (hapd->public_action_cb) {
  3074. hapd->public_action_cb(hapd->public_action_cb_ctx,
  3075. (u8 *) mgmt, len,
  3076. hapd->iface->freq);
  3077. }
  3078. if (hapd->public_action_cb2) {
  3079. hapd->public_action_cb2(hapd->public_action_cb2_ctx,
  3080. (u8 *) mgmt, len,
  3081. hapd->iface->freq);
  3082. }
  3083. if (hapd->public_action_cb || hapd->public_action_cb2)
  3084. return 1;
  3085. break;
  3086. case WLAN_ACTION_VENDOR_SPECIFIC:
  3087. if (hapd->vendor_action_cb) {
  3088. if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
  3089. (u8 *) mgmt, len,
  3090. hapd->iface->freq) == 0)
  3091. return 1;
  3092. }
  3093. break;
  3094. case WLAN_ACTION_RADIO_MEASUREMENT:
  3095. hostapd_handle_radio_measurement(hapd, (const u8 *) mgmt, len);
  3096. return 1;
  3097. }
  3098. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  3099. HOSTAPD_LEVEL_DEBUG,
  3100. "handle_action - unknown action category %d or invalid "
  3101. "frame",
  3102. mgmt->u.action.category);
  3103. if (!is_multicast_ether_addr(mgmt->da) &&
  3104. !(mgmt->u.action.category & 0x80) &&
  3105. !is_multicast_ether_addr(mgmt->sa)) {
  3106. struct ieee80211_mgmt *resp;
  3107. /*
  3108. * IEEE 802.11-REVma/D9.0 - 7.3.1.11
  3109. * Return the Action frame to the source without change
  3110. * except that MSB of the Category set to 1.
  3111. */
  3112. wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
  3113. "frame back to sender");
  3114. resp = os_memdup(mgmt, len);
  3115. if (resp == NULL)
  3116. return 0;
  3117. os_memcpy(resp->da, resp->sa, ETH_ALEN);
  3118. os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
  3119. os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
  3120. resp->u.action.category |= 0x80;
  3121. if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
  3122. wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
  3123. "Action frame");
  3124. }
  3125. os_free(resp);
  3126. }
  3127. return 1;
  3128. }
  3129. /**
  3130. * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
  3131. * @hapd: hostapd BSS data structure (the BSS to which the management frame was
  3132. * sent to)
  3133. * @buf: management frame data (starting from IEEE 802.11 header)
  3134. * @len: length of frame data in octets
  3135. * @fi: meta data about received frame (signal level, etc.)
  3136. *
  3137. * Process all incoming IEEE 802.11 management frames. This will be called for
  3138. * each frame received from the kernel driver through wlan#ap interface. In
  3139. * addition, it can be called to re-inserted pending frames (e.g., when using
  3140. * external RADIUS server as an MAC ACL).
  3141. */
  3142. int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
  3143. struct hostapd_frame_info *fi)
  3144. {
  3145. struct ieee80211_mgmt *mgmt;
  3146. u16 fc, stype;
  3147. int ret = 0;
  3148. if (len < 24)
  3149. return 0;
  3150. mgmt = (struct ieee80211_mgmt *) buf;
  3151. fc = le_to_host16(mgmt->frame_control);
  3152. stype = WLAN_FC_GET_STYPE(fc);
  3153. if (stype == WLAN_FC_STYPE_BEACON) {
  3154. handle_beacon(hapd, mgmt, len, fi);
  3155. return 1;
  3156. }
  3157. if (!is_broadcast_ether_addr(mgmt->bssid) &&
  3158. #ifdef CONFIG_P2P
  3159. /* Invitation responses can be sent with the peer MAC as BSSID */
  3160. !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
  3161. stype == WLAN_FC_STYPE_ACTION) &&
  3162. #endif /* CONFIG_P2P */
  3163. #ifdef CONFIG_MESH
  3164. !(hapd->conf->mesh & MESH_ENABLED) &&
  3165. #endif /* CONFIG_MESH */
  3166. os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
  3167. wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
  3168. MAC2STR(mgmt->bssid));
  3169. return 0;
  3170. }
  3171. if (stype == WLAN_FC_STYPE_PROBE_REQ) {
  3172. handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
  3173. return 1;
  3174. }
  3175. if ((!is_broadcast_ether_addr(mgmt->da) ||
  3176. stype != WLAN_FC_STYPE_ACTION) &&
  3177. os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
  3178. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  3179. HOSTAPD_LEVEL_DEBUG,
  3180. "MGMT: DA=" MACSTR " not our address",
  3181. MAC2STR(mgmt->da));
  3182. return 0;
  3183. }
  3184. if (hapd->iconf->track_sta_max_num)
  3185. sta_track_add(hapd->iface, mgmt->sa, fi->ssi_signal);
  3186. switch (stype) {
  3187. case WLAN_FC_STYPE_AUTH:
  3188. wpa_printf(MSG_DEBUG, "mgmt::auth");
  3189. handle_auth(hapd, mgmt, len);
  3190. ret = 1;
  3191. break;
  3192. case WLAN_FC_STYPE_ASSOC_REQ:
  3193. wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
  3194. handle_assoc(hapd, mgmt, len, 0);
  3195. ret = 1;
  3196. break;
  3197. case WLAN_FC_STYPE_REASSOC_REQ:
  3198. wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
  3199. handle_assoc(hapd, mgmt, len, 1);
  3200. ret = 1;
  3201. break;
  3202. case WLAN_FC_STYPE_DISASSOC:
  3203. wpa_printf(MSG_DEBUG, "mgmt::disassoc");
  3204. handle_disassoc(hapd, mgmt, len);
  3205. ret = 1;
  3206. break;
  3207. case WLAN_FC_STYPE_DEAUTH:
  3208. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
  3209. handle_deauth(hapd, mgmt, len);
  3210. ret = 1;
  3211. break;
  3212. case WLAN_FC_STYPE_ACTION:
  3213. wpa_printf(MSG_DEBUG, "mgmt::action");
  3214. ret = handle_action(hapd, mgmt, len);
  3215. break;
  3216. default:
  3217. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  3218. HOSTAPD_LEVEL_DEBUG,
  3219. "unknown mgmt frame subtype %d", stype);
  3220. break;
  3221. }
  3222. return ret;
  3223. }
  3224. static void handle_auth_cb(struct hostapd_data *hapd,
  3225. const struct ieee80211_mgmt *mgmt,
  3226. size_t len, int ok)
  3227. {
  3228. u16 auth_alg, auth_transaction, status_code;
  3229. struct sta_info *sta;
  3230. sta = ap_get_sta(hapd, mgmt->da);
  3231. if (!sta) {
  3232. wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
  3233. MAC2STR(mgmt->da));
  3234. return;
  3235. }
  3236. auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
  3237. auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
  3238. status_code = le_to_host16(mgmt->u.auth.status_code);
  3239. if (!ok) {
  3240. hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
  3241. HOSTAPD_LEVEL_NOTICE,
  3242. "did not acknowledge authentication response");
  3243. goto fail;
  3244. }
  3245. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
  3246. wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
  3247. (unsigned long) len);
  3248. goto fail;
  3249. }
  3250. if (status_code == WLAN_STATUS_SUCCESS &&
  3251. ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
  3252. (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
  3253. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  3254. HOSTAPD_LEVEL_INFO, "authenticated");
  3255. sta->flags |= WLAN_STA_AUTH;
  3256. if (sta->added_unassoc)
  3257. hostapd_set_sta_flags(hapd, sta);
  3258. return;
  3259. }
  3260. fail:
  3261. if (status_code != WLAN_STATUS_SUCCESS && sta->added_unassoc) {
  3262. hostapd_drv_sta_remove(hapd, sta->addr);
  3263. sta->added_unassoc = 0;
  3264. }
  3265. }
  3266. static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
  3267. struct sta_info *sta,
  3268. char *ifname_wds)
  3269. {
  3270. int i;
  3271. struct hostapd_ssid *ssid = &hapd->conf->ssid;
  3272. if (hapd->conf->ieee802_1x || hapd->conf->wpa)
  3273. return;
  3274. for (i = 0; i < 4; i++) {
  3275. if (ssid->wep.key[i] &&
  3276. hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
  3277. i == ssid->wep.idx, NULL, 0,
  3278. ssid->wep.key[i], ssid->wep.len[i])) {
  3279. wpa_printf(MSG_WARNING,
  3280. "Could not set WEP keys for WDS interface; %s",
  3281. ifname_wds);
  3282. break;
  3283. }
  3284. }
  3285. }
  3286. static void handle_assoc_cb(struct hostapd_data *hapd,
  3287. const struct ieee80211_mgmt *mgmt,
  3288. size_t len, int reassoc, int ok)
  3289. {
  3290. u16 status;
  3291. struct sta_info *sta;
  3292. int new_assoc = 1;
  3293. sta = ap_get_sta(hapd, mgmt->da);
  3294. if (!sta) {
  3295. wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
  3296. MAC2STR(mgmt->da));
  3297. return;
  3298. }
  3299. if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
  3300. sizeof(mgmt->u.assoc_resp))) {
  3301. wpa_printf(MSG_INFO,
  3302. "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
  3303. reassoc, (unsigned long) len);
  3304. hostapd_drv_sta_remove(hapd, sta->addr);
  3305. return;
  3306. }
  3307. if (reassoc)
  3308. status = le_to_host16(mgmt->u.reassoc_resp.status_code);
  3309. else
  3310. status = le_to_host16(mgmt->u.assoc_resp.status_code);
  3311. if (!ok) {
  3312. hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
  3313. HOSTAPD_LEVEL_DEBUG,
  3314. "did not acknowledge association response");
  3315. sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
  3316. /* The STA is added only in case of SUCCESS */
  3317. if (status == WLAN_STATUS_SUCCESS)
  3318. hostapd_drv_sta_remove(hapd, sta->addr);
  3319. return;
  3320. }
  3321. if (status != WLAN_STATUS_SUCCESS)
  3322. return;
  3323. /* Stop previous accounting session, if one is started, and allocate
  3324. * new session id for the new session. */
  3325. accounting_sta_stop(hapd, sta);
  3326. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  3327. HOSTAPD_LEVEL_INFO,
  3328. "associated (aid %d)",
  3329. sta->aid);
  3330. if (sta->flags & WLAN_STA_ASSOC)
  3331. new_assoc = 0;
  3332. sta->flags |= WLAN_STA_ASSOC;
  3333. sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
  3334. if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa &&
  3335. !hapd->conf->osen) ||
  3336. sta->auth_alg == WLAN_AUTH_FILS_SK ||
  3337. sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
  3338. sta->auth_alg == WLAN_AUTH_FILS_PK ||
  3339. sta->auth_alg == WLAN_AUTH_FT) {
  3340. /*
  3341. * Open, static WEP, FT protocol, or FILS; no separate
  3342. * authorization step.
  3343. */
  3344. ap_sta_set_authorized(hapd, sta, 1);
  3345. }
  3346. if (reassoc)
  3347. mlme_reassociate_indication(hapd, sta);
  3348. else
  3349. mlme_associate_indication(hapd, sta);
  3350. #ifdef CONFIG_IEEE80211W
  3351. sta->sa_query_timed_out = 0;
  3352. #endif /* CONFIG_IEEE80211W */
  3353. if (sta->eapol_sm == NULL) {
  3354. /*
  3355. * This STA does not use RADIUS server for EAP authentication,
  3356. * so bind it to the selected VLAN interface now, since the
  3357. * interface selection is not going to change anymore.
  3358. */
  3359. if (ap_sta_bind_vlan(hapd, sta) < 0)
  3360. return;
  3361. } else if (sta->vlan_id) {
  3362. /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
  3363. if (ap_sta_bind_vlan(hapd, sta) < 0)
  3364. return;
  3365. }
  3366. hostapd_set_sta_flags(hapd, sta);
  3367. if (!(sta->flags & WLAN_STA_WDS) && sta->pending_wds_enable) {
  3368. wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for STA "
  3369. MACSTR " based on pending request",
  3370. MAC2STR(sta->addr));
  3371. sta->pending_wds_enable = 0;
  3372. sta->flags |= WLAN_STA_WDS;
  3373. }
  3374. if (sta->flags & WLAN_STA_WDS) {
  3375. int ret;
  3376. char ifname_wds[IFNAMSIZ + 1];
  3377. wpa_printf(MSG_DEBUG, "Reenable 4-address WDS mode for STA "
  3378. MACSTR " (aid %u)",
  3379. MAC2STR(sta->addr), sta->aid);
  3380. ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
  3381. sta->aid, 1);
  3382. if (!ret)
  3383. hostapd_set_wds_encryption(hapd, sta, ifname_wds);
  3384. }
  3385. if (sta->auth_alg == WLAN_AUTH_FT)
  3386. wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
  3387. else
  3388. wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
  3389. hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
  3390. ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
  3391. #ifdef CONFIG_FILS
  3392. if ((sta->auth_alg == WLAN_AUTH_FILS_SK ||
  3393. sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
  3394. sta->auth_alg == WLAN_AUTH_FILS_PK) &&
  3395. fils_set_tk(sta->wpa_sm) < 0) {
  3396. wpa_printf(MSG_DEBUG, "FILS: TK configuration failed");
  3397. ap_sta_disconnect(hapd, sta, sta->addr,
  3398. WLAN_REASON_UNSPECIFIED);
  3399. return;
  3400. }
  3401. #endif /* CONFIG_FILS */
  3402. if (sta->pending_eapol_rx) {
  3403. struct os_reltime now, age;
  3404. os_get_reltime(&now);
  3405. os_reltime_sub(&now, &sta->pending_eapol_rx->rx_time, &age);
  3406. if (age.sec == 0 && age.usec < 200000) {
  3407. wpa_printf(MSG_DEBUG,
  3408. "Process pending EAPOL frame that was received from " MACSTR " just before association notification",
  3409. MAC2STR(sta->addr));
  3410. ieee802_1x_receive(
  3411. hapd, mgmt->da,
  3412. wpabuf_head(sta->pending_eapol_rx->buf),
  3413. wpabuf_len(sta->pending_eapol_rx->buf));
  3414. }
  3415. wpabuf_free(sta->pending_eapol_rx->buf);
  3416. os_free(sta->pending_eapol_rx);
  3417. sta->pending_eapol_rx = NULL;
  3418. }
  3419. }
  3420. static void handle_deauth_cb(struct hostapd_data *hapd,
  3421. const struct ieee80211_mgmt *mgmt,
  3422. size_t len, int ok)
  3423. {
  3424. struct sta_info *sta;
  3425. if (is_multicast_ether_addr(mgmt->da))
  3426. return;
  3427. sta = ap_get_sta(hapd, mgmt->da);
  3428. if (!sta) {
  3429. wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
  3430. " not found", MAC2STR(mgmt->da));
  3431. return;
  3432. }
  3433. if (ok)
  3434. wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
  3435. MAC2STR(sta->addr));
  3436. else
  3437. wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
  3438. "deauth", MAC2STR(sta->addr));
  3439. ap_sta_deauth_cb(hapd, sta);
  3440. }
  3441. static void handle_disassoc_cb(struct hostapd_data *hapd,
  3442. const struct ieee80211_mgmt *mgmt,
  3443. size_t len, int ok)
  3444. {
  3445. struct sta_info *sta;
  3446. if (is_multicast_ether_addr(mgmt->da))
  3447. return;
  3448. sta = ap_get_sta(hapd, mgmt->da);
  3449. if (!sta) {
  3450. wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
  3451. " not found", MAC2STR(mgmt->da));
  3452. return;
  3453. }
  3454. if (ok)
  3455. wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
  3456. MAC2STR(sta->addr));
  3457. else
  3458. wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
  3459. "disassoc", MAC2STR(sta->addr));
  3460. ap_sta_disassoc_cb(hapd, sta);
  3461. }
  3462. static void handle_action_cb(struct hostapd_data *hapd,
  3463. const struct ieee80211_mgmt *mgmt,
  3464. size_t len, int ok)
  3465. {
  3466. struct sta_info *sta;
  3467. const struct rrm_measurement_report_element *report;
  3468. if (is_multicast_ether_addr(mgmt->da))
  3469. return;
  3470. #ifdef CONFIG_DPP
  3471. if (len >= IEEE80211_HDRLEN + 6 &&
  3472. mgmt->u.action.category == WLAN_ACTION_PUBLIC &&
  3473. mgmt->u.action.u.vs_public_action.action ==
  3474. WLAN_PA_VENDOR_SPECIFIC &&
  3475. WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
  3476. OUI_WFA &&
  3477. mgmt->u.action.u.vs_public_action.variable[0] ==
  3478. DPP_OUI_TYPE) {
  3479. const u8 *pos, *end;
  3480. pos = &mgmt->u.action.u.vs_public_action.variable[1];
  3481. end = ((const u8 *) mgmt) + len;
  3482. hostapd_dpp_tx_status(hapd, mgmt->da, pos, end - pos, ok);
  3483. return;
  3484. }
  3485. if (len >= IEEE80211_HDRLEN + 2 &&
  3486. mgmt->u.action.category == WLAN_ACTION_PUBLIC &&
  3487. (mgmt->u.action.u.public_action.action ==
  3488. WLAN_PA_GAS_INITIAL_REQ ||
  3489. mgmt->u.action.u.public_action.action ==
  3490. WLAN_PA_GAS_COMEBACK_REQ)) {
  3491. const u8 *pos, *end;
  3492. pos = mgmt->u.action.u.public_action.variable;
  3493. end = ((const u8 *) mgmt) + len;
  3494. gas_query_ap_tx_status(hapd->gas, mgmt->da, pos, end - pos, ok);
  3495. return;
  3496. }
  3497. #endif /* CONFIG_DPP */
  3498. sta = ap_get_sta(hapd, mgmt->da);
  3499. if (!sta) {
  3500. wpa_printf(MSG_DEBUG, "handle_action_cb: STA " MACSTR
  3501. " not found", MAC2STR(mgmt->da));
  3502. return;
  3503. }
  3504. if (len < 24 + 5 + sizeof(*report))
  3505. return;
  3506. report = (const struct rrm_measurement_report_element *)
  3507. &mgmt->u.action.u.rrm.variable[2];
  3508. if (mgmt->u.action.category == WLAN_ACTION_RADIO_MEASUREMENT &&
  3509. mgmt->u.action.u.rrm.action == WLAN_RRM_RADIO_MEASUREMENT_REQUEST &&
  3510. report->eid == WLAN_EID_MEASURE_REQUEST &&
  3511. report->len >= 3 &&
  3512. report->type == MEASURE_TYPE_BEACON)
  3513. hostapd_rrm_beacon_req_tx_status(hapd, mgmt, len, ok);
  3514. }
  3515. /**
  3516. * ieee802_11_mgmt_cb - Process management frame TX status callback
  3517. * @hapd: hostapd BSS data structure (the BSS from which the management frame
  3518. * was sent from)
  3519. * @buf: management frame data (starting from IEEE 802.11 header)
  3520. * @len: length of frame data in octets
  3521. * @stype: management frame subtype from frame control field
  3522. * @ok: Whether the frame was ACK'ed
  3523. */
  3524. void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
  3525. u16 stype, int ok)
  3526. {
  3527. const struct ieee80211_mgmt *mgmt;
  3528. mgmt = (const struct ieee80211_mgmt *) buf;
  3529. #ifdef CONFIG_TESTING_OPTIONS
  3530. if (hapd->ext_mgmt_frame_handling) {
  3531. wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
  3532. stype, ok);
  3533. return;
  3534. }
  3535. #endif /* CONFIG_TESTING_OPTIONS */
  3536. switch (stype) {
  3537. case WLAN_FC_STYPE_AUTH:
  3538. wpa_printf(MSG_DEBUG, "mgmt::auth cb");
  3539. handle_auth_cb(hapd, mgmt, len, ok);
  3540. break;
  3541. case WLAN_FC_STYPE_ASSOC_RESP:
  3542. wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
  3543. handle_assoc_cb(hapd, mgmt, len, 0, ok);
  3544. break;
  3545. case WLAN_FC_STYPE_REASSOC_RESP:
  3546. wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
  3547. handle_assoc_cb(hapd, mgmt, len, 1, ok);
  3548. break;
  3549. case WLAN_FC_STYPE_PROBE_RESP:
  3550. wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb ok=%d", ok);
  3551. break;
  3552. case WLAN_FC_STYPE_DEAUTH:
  3553. wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
  3554. handle_deauth_cb(hapd, mgmt, len, ok);
  3555. break;
  3556. case WLAN_FC_STYPE_DISASSOC:
  3557. wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
  3558. handle_disassoc_cb(hapd, mgmt, len, ok);
  3559. break;
  3560. case WLAN_FC_STYPE_ACTION:
  3561. wpa_printf(MSG_DEBUG, "mgmt::action cb ok=%d", ok);
  3562. handle_action_cb(hapd, mgmt, len, ok);
  3563. break;
  3564. default:
  3565. wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
  3566. break;
  3567. }
  3568. }
  3569. int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
  3570. {
  3571. /* TODO */
  3572. return 0;
  3573. }
  3574. int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
  3575. char *buf, size_t buflen)
  3576. {
  3577. /* TODO */
  3578. return 0;
  3579. }
  3580. void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
  3581. const u8 *buf, size_t len, int ack)
  3582. {
  3583. struct sta_info *sta;
  3584. struct hostapd_iface *iface = hapd->iface;
  3585. sta = ap_get_sta(hapd, addr);
  3586. if (sta == NULL && iface->num_bss > 1) {
  3587. size_t j;
  3588. for (j = 0; j < iface->num_bss; j++) {
  3589. hapd = iface->bss[j];
  3590. sta = ap_get_sta(hapd, addr);
  3591. if (sta)
  3592. break;
  3593. }
  3594. }
  3595. if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
  3596. return;
  3597. if (sta->flags & WLAN_STA_PENDING_POLL) {
  3598. wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
  3599. "activity poll", MAC2STR(sta->addr),
  3600. ack ? "ACKed" : "did not ACK");
  3601. if (ack)
  3602. sta->flags &= ~WLAN_STA_PENDING_POLL;
  3603. }
  3604. ieee802_1x_tx_status(hapd, sta, buf, len, ack);
  3605. }
  3606. void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
  3607. const u8 *data, size_t len, int ack)
  3608. {
  3609. struct sta_info *sta;
  3610. struct hostapd_iface *iface = hapd->iface;
  3611. sta = ap_get_sta(hapd, dst);
  3612. if (sta == NULL && iface->num_bss > 1) {
  3613. size_t j;
  3614. for (j = 0; j < iface->num_bss; j++) {
  3615. hapd = iface->bss[j];
  3616. sta = ap_get_sta(hapd, dst);
  3617. if (sta)
  3618. break;
  3619. }
  3620. }
  3621. if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
  3622. wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
  3623. MACSTR " that is not currently associated",
  3624. MAC2STR(dst));
  3625. return;
  3626. }
  3627. ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
  3628. }
  3629. void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
  3630. {
  3631. struct sta_info *sta;
  3632. struct hostapd_iface *iface = hapd->iface;
  3633. sta = ap_get_sta(hapd, addr);
  3634. if (sta == NULL && iface->num_bss > 1) {
  3635. size_t j;
  3636. for (j = 0; j < iface->num_bss; j++) {
  3637. hapd = iface->bss[j];
  3638. sta = ap_get_sta(hapd, addr);
  3639. if (sta)
  3640. break;
  3641. }
  3642. }
  3643. if (sta == NULL)
  3644. return;
  3645. wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POLL_OK MACSTR,
  3646. MAC2STR(sta->addr));
  3647. if (!(sta->flags & WLAN_STA_PENDING_POLL))
  3648. return;
  3649. wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
  3650. "activity poll", MAC2STR(sta->addr));
  3651. sta->flags &= ~WLAN_STA_PENDING_POLL;
  3652. }
  3653. void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
  3654. int wds)
  3655. {
  3656. struct sta_info *sta;
  3657. sta = ap_get_sta(hapd, src);
  3658. if (sta &&
  3659. ((sta->flags & WLAN_STA_ASSOC) ||
  3660. ((sta->flags & WLAN_STA_ASSOC_REQ_OK) && wds))) {
  3661. if (!hapd->conf->wds_sta)
  3662. return;
  3663. if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK)) ==
  3664. WLAN_STA_ASSOC_REQ_OK) {
  3665. wpa_printf(MSG_DEBUG,
  3666. "Postpone 4-address WDS mode enabling for STA "
  3667. MACSTR " since TX status for AssocResp is not yet known",
  3668. MAC2STR(sta->addr));
  3669. sta->pending_wds_enable = 1;
  3670. return;
  3671. }
  3672. if (wds && !(sta->flags & WLAN_STA_WDS)) {
  3673. int ret;
  3674. char ifname_wds[IFNAMSIZ + 1];
  3675. wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
  3676. "STA " MACSTR " (aid %u)",
  3677. MAC2STR(sta->addr), sta->aid);
  3678. sta->flags |= WLAN_STA_WDS;
  3679. ret = hostapd_set_wds_sta(hapd, ifname_wds,
  3680. sta->addr, sta->aid, 1);
  3681. if (!ret)
  3682. hostapd_set_wds_encryption(hapd, sta,
  3683. ifname_wds);
  3684. }
  3685. return;
  3686. }
  3687. wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
  3688. MACSTR, MAC2STR(src));
  3689. if (is_multicast_ether_addr(src)) {
  3690. /* Broadcast bit set in SA?! Ignore the frame silently. */
  3691. return;
  3692. }
  3693. if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
  3694. wpa_printf(MSG_DEBUG, "Association Response to the STA has "
  3695. "already been sent, but no TX status yet known - "
  3696. "ignore Class 3 frame issue with " MACSTR,
  3697. MAC2STR(src));
  3698. return;
  3699. }
  3700. if (sta && (sta->flags & WLAN_STA_AUTH))
  3701. hostapd_drv_sta_disassoc(
  3702. hapd, src,
  3703. WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
  3704. else
  3705. hostapd_drv_sta_deauth(
  3706. hapd, src,
  3707. WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
  3708. }
  3709. #endif /* CONFIG_NATIVE_WINDOWS */