ieee802_11.c 115 KB

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