mlme.c 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188
  1. /*
  2. * WPA Supplicant - Client mode MLME
  3. * Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi>
  4. * Copyright (c) 2004, Instant802 Networks, Inc.
  5. * Copyright (c) 2005-2006, Devicescape Software, Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Alternatively, this software may be distributed under the terms of BSD
  12. * license.
  13. *
  14. * See README and COPYING for more details.
  15. */
  16. #include "includes.h"
  17. #include "common.h"
  18. #include "eloop.h"
  19. #include "config_ssid.h"
  20. #include "wpa_supplicant_i.h"
  21. #include "notify.h"
  22. #include "driver_i.h"
  23. #include "rsn_supp/wpa.h"
  24. #include "common/ieee802_11_defs.h"
  25. #include "common/ieee802_11_common.h"
  26. #include "mlme.h"
  27. /* Timeouts and intervals in milliseconds */
  28. #define IEEE80211_AUTH_TIMEOUT (200)
  29. #define IEEE80211_AUTH_MAX_TRIES 3
  30. #define IEEE80211_ASSOC_TIMEOUT (200)
  31. #define IEEE80211_ASSOC_MAX_TRIES 3
  32. #define IEEE80211_MONITORING_INTERVAL (2000)
  33. #define IEEE80211_PROBE_INTERVAL (60000)
  34. #define IEEE80211_RETRY_AUTH_INTERVAL (1000)
  35. #define IEEE80211_SCAN_INTERVAL (2000)
  36. #define IEEE80211_SCAN_INTERVAL_SLOW (15000)
  37. #define IEEE80211_IBSS_JOIN_TIMEOUT (20000)
  38. #define IEEE80211_PROBE_DELAY (33)
  39. #define IEEE80211_CHANNEL_TIME (33)
  40. #define IEEE80211_PASSIVE_CHANNEL_TIME (200)
  41. #define IEEE80211_SCAN_RESULT_EXPIRE (10000)
  42. #define IEEE80211_IBSS_MERGE_INTERVAL (30000)
  43. #define IEEE80211_IBSS_INACTIVITY_LIMIT (60000)
  44. #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
  45. #define IEEE80211_FC(type, stype) host_to_le16((type << 2) | (stype << 4))
  46. struct ieee80211_sta_bss {
  47. struct ieee80211_sta_bss *next;
  48. struct ieee80211_sta_bss *hnext;
  49. u8 bssid[ETH_ALEN];
  50. u8 ssid[MAX_SSID_LEN];
  51. size_t ssid_len;
  52. u16 capability; /* host byte order */
  53. int hw_mode;
  54. int channel;
  55. int freq;
  56. int rssi;
  57. u8 *ie;
  58. size_t ie_len;
  59. u8 *wpa_ie;
  60. size_t wpa_ie_len;
  61. u8 *rsn_ie;
  62. size_t rsn_ie_len;
  63. u8 *wmm_ie;
  64. size_t wmm_ie_len;
  65. u8 *mdie;
  66. size_t mdie_len;
  67. #define IEEE80211_MAX_SUPP_RATES 32
  68. u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
  69. size_t supp_rates_len;
  70. int beacon_int;
  71. u64 timestamp;
  72. int probe_resp;
  73. struct os_time last_update;
  74. };
  75. static void ieee80211_send_probe_req(struct wpa_supplicant *wpa_s,
  76. const u8 *dst,
  77. const u8 *ssid, size_t ssid_len);
  78. static struct ieee80211_sta_bss *
  79. ieee80211_bss_get(struct wpa_supplicant *wpa_s, const u8 *bssid);
  80. static int ieee80211_sta_find_ibss(struct wpa_supplicant *wpa_s);
  81. static int ieee80211_sta_wep_configured(struct wpa_supplicant *wpa_s);
  82. static void ieee80211_sta_timer(void *eloop_ctx, void *timeout_ctx);
  83. static void ieee80211_sta_scan_timer(void *eloop_ctx, void *timeout_ctx);
  84. static void ieee80211_build_tspec(struct wpabuf *buf);
  85. static int ieee80211_sta_set_channel(struct wpa_supplicant *wpa_s,
  86. hostapd_hw_mode phymode, int chan,
  87. int freq)
  88. {
  89. size_t i;
  90. struct hostapd_hw_modes *mode;
  91. for (i = 0; i < wpa_s->mlme.num_modes; i++) {
  92. mode = &wpa_s->mlme.modes[i];
  93. if (mode->mode == phymode) {
  94. wpa_s->mlme.curr_rates = mode->rates;
  95. wpa_s->mlme.num_curr_rates = mode->num_rates;
  96. break;
  97. }
  98. }
  99. return wpa_drv_set_channel(wpa_s, phymode, chan, freq);
  100. }
  101. static int ecw2cw(int ecw)
  102. {
  103. int cw = 1;
  104. while (ecw > 0) {
  105. cw <<= 1;
  106. ecw--;
  107. }
  108. return cw - 1;
  109. }
  110. static void ieee80211_sta_wmm_params(struct wpa_supplicant *wpa_s,
  111. u8 *wmm_param, size_t wmm_param_len)
  112. {
  113. size_t left;
  114. int count;
  115. u8 *pos;
  116. u8 wmm_acm;
  117. if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
  118. return;
  119. count = wmm_param[6] & 0x0f;
  120. if (count == wpa_s->mlme.wmm_last_param_set)
  121. return;
  122. wpa_s->mlme.wmm_last_param_set = count;
  123. pos = wmm_param + 8;
  124. left = wmm_param_len - 8;
  125. wmm_acm = 0;
  126. for (; left >= 4; left -= 4, pos += 4) {
  127. int aci = (pos[0] >> 5) & 0x03;
  128. int acm = (pos[0] >> 4) & 0x01;
  129. int aifs, cw_max, cw_min, burst_time;
  130. switch (aci) {
  131. case 1: /* AC_BK */
  132. if (acm)
  133. wmm_acm |= BIT(1) | BIT(2); /* BK/- */
  134. break;
  135. case 2: /* AC_VI */
  136. if (acm)
  137. wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
  138. break;
  139. case 3: /* AC_VO */
  140. if (acm)
  141. wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
  142. break;
  143. case 0: /* AC_BE */
  144. default:
  145. if (acm)
  146. wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
  147. break;
  148. }
  149. aifs = pos[0] & 0x0f;
  150. cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
  151. cw_min = ecw2cw(pos[1] & 0x0f);
  152. /* TXOP is in units of 32 usec; burst_time in 0.1 ms */
  153. burst_time = (pos[2] | (pos[3] << 8)) * 32 / 100;
  154. wpa_printf(MSG_DEBUG, "MLME: WMM aci=%d acm=%d aifs=%d "
  155. "cWmin=%d cWmax=%d burst=%d",
  156. aci, acm, aifs, cw_min, cw_max, burst_time);
  157. /* TODO: driver configuration */
  158. }
  159. }
  160. static void ieee80211_set_associated(struct wpa_supplicant *wpa_s, int assoc)
  161. {
  162. if (wpa_s->mlme.associated == assoc && !assoc)
  163. return;
  164. wpa_s->mlme.associated = assoc;
  165. if (assoc) {
  166. union wpa_event_data data;
  167. os_memset(&data, 0, sizeof(data));
  168. wpa_s->mlme.prev_bssid_set = 1;
  169. os_memcpy(wpa_s->mlme.prev_bssid, wpa_s->bssid, ETH_ALEN);
  170. data.assoc_info.req_ies = wpa_s->mlme.assocreq_ies;
  171. data.assoc_info.req_ies_len = wpa_s->mlme.assocreq_ies_len;
  172. data.assoc_info.resp_ies = wpa_s->mlme.assocresp_ies;
  173. data.assoc_info.resp_ies_len = wpa_s->mlme.assocresp_ies_len;
  174. wpa_supplicant_event(wpa_s, EVENT_ASSOC, &data);
  175. } else {
  176. wpa_supplicant_event(wpa_s, EVENT_DISASSOC, NULL);
  177. }
  178. os_get_time(&wpa_s->mlme.last_probe);
  179. }
  180. static int ieee80211_sta_tx(struct wpa_supplicant *wpa_s, const u8 *buf,
  181. size_t len)
  182. {
  183. return wpa_drv_send_mlme(wpa_s, buf, len);
  184. }
  185. static void ieee80211_send_auth(struct wpa_supplicant *wpa_s,
  186. int transaction, u8 *extra, size_t extra_len,
  187. int encrypt)
  188. {
  189. u8 *buf;
  190. size_t len;
  191. struct ieee80211_mgmt *mgmt;
  192. buf = os_malloc(sizeof(*mgmt) + 6 + extra_len);
  193. if (buf == NULL) {
  194. wpa_printf(MSG_DEBUG, "MLME: failed to allocate buffer for "
  195. "auth frame");
  196. return;
  197. }
  198. mgmt = (struct ieee80211_mgmt *) buf;
  199. len = 24 + 6;
  200. os_memset(mgmt, 0, 24 + 6);
  201. mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  202. WLAN_FC_STYPE_AUTH);
  203. if (encrypt)
  204. mgmt->frame_control |= host_to_le16(WLAN_FC_ISWEP);
  205. os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
  206. os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
  207. os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
  208. mgmt->u.auth.auth_alg = host_to_le16(wpa_s->mlme.auth_alg);
  209. mgmt->u.auth.auth_transaction = host_to_le16(transaction);
  210. wpa_s->mlme.auth_transaction = transaction + 1;
  211. mgmt->u.auth.status_code = host_to_le16(0);
  212. if (extra) {
  213. os_memcpy(buf + len, extra, extra_len);
  214. len += extra_len;
  215. }
  216. ieee80211_sta_tx(wpa_s, buf, len);
  217. os_free(buf);
  218. }
  219. static void ieee80211_reschedule_timer(struct wpa_supplicant *wpa_s, int ms)
  220. {
  221. eloop_cancel_timeout(ieee80211_sta_timer, wpa_s, NULL);
  222. eloop_register_timeout(ms / 1000, 1000 * (ms % 1000),
  223. ieee80211_sta_timer, wpa_s, NULL);
  224. }
  225. static void ieee80211_authenticate(struct wpa_supplicant *wpa_s)
  226. {
  227. u8 *extra;
  228. size_t extra_len;
  229. wpa_s->mlme.auth_tries++;
  230. if (wpa_s->mlme.auth_tries > IEEE80211_AUTH_MAX_TRIES) {
  231. wpa_printf(MSG_DEBUG, "MLME: authentication with AP " MACSTR
  232. " timed out", MAC2STR(wpa_s->bssid));
  233. return;
  234. }
  235. wpa_s->mlme.state = IEEE80211_AUTHENTICATE;
  236. wpa_printf(MSG_DEBUG, "MLME: authenticate with AP " MACSTR,
  237. MAC2STR(wpa_s->bssid));
  238. extra = NULL;
  239. extra_len = 0;
  240. #ifdef CONFIG_IEEE80211R
  241. if ((wpa_s->mlme.key_mgmt == KEY_MGMT_FT_802_1X ||
  242. wpa_s->mlme.key_mgmt == KEY_MGMT_FT_PSK) &&
  243. wpa_s->mlme.ft_ies) {
  244. struct ieee80211_sta_bss *bss;
  245. struct rsn_mdie *mdie = NULL;
  246. bss = ieee80211_bss_get(wpa_s, wpa_s->bssid);
  247. if (bss && bss->mdie_len >= 2 + sizeof(*mdie))
  248. mdie = (struct rsn_mdie *) (bss->mdie + 2);
  249. if (mdie &&
  250. os_memcmp(mdie->mobility_domain, wpa_s->mlme.current_md,
  251. MOBILITY_DOMAIN_ID_LEN) == 0) {
  252. wpa_printf(MSG_DEBUG, "MLME: Trying to use FT "
  253. "over-the-air");
  254. wpa_s->mlme.auth_alg = WLAN_AUTH_FT;
  255. extra = wpa_s->mlme.ft_ies;
  256. extra_len = wpa_s->mlme.ft_ies_len;
  257. }
  258. }
  259. #endif /* CONFIG_IEEE80211R */
  260. ieee80211_send_auth(wpa_s, 1, extra, extra_len, 0);
  261. ieee80211_reschedule_timer(wpa_s, IEEE80211_AUTH_TIMEOUT);
  262. }
  263. static void ieee80211_send_assoc(struct wpa_supplicant *wpa_s)
  264. {
  265. struct ieee80211_mgmt *mgmt;
  266. u8 *pos, *ies, *buf;
  267. int i, len;
  268. u16 capab;
  269. struct ieee80211_sta_bss *bss;
  270. int wmm = 0;
  271. size_t blen, buflen;
  272. if (wpa_s->mlme.curr_rates == NULL) {
  273. wpa_printf(MSG_DEBUG, "MLME: curr_rates not set for assoc");
  274. return;
  275. }
  276. buflen = sizeof(*mgmt) + 200 + wpa_s->mlme.extra_ie_len +
  277. wpa_s->mlme.ssid_len;
  278. #ifdef CONFIG_IEEE80211R
  279. if (wpa_s->mlme.ft_ies)
  280. buflen += wpa_s->mlme.ft_ies_len;
  281. #endif /* CONFIG_IEEE80211R */
  282. buf = os_malloc(buflen);
  283. if (buf == NULL) {
  284. wpa_printf(MSG_DEBUG, "MLME: failed to allocate buffer for "
  285. "assoc frame");
  286. return;
  287. }
  288. blen = 0;
  289. capab = wpa_s->mlme.capab;
  290. if (wpa_s->mlme.phymode == HOSTAPD_MODE_IEEE80211G) {
  291. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME |
  292. WLAN_CAPABILITY_SHORT_PREAMBLE;
  293. }
  294. bss = ieee80211_bss_get(wpa_s, wpa_s->bssid);
  295. if (bss) {
  296. if (bss->capability & WLAN_CAPABILITY_PRIVACY)
  297. capab |= WLAN_CAPABILITY_PRIVACY;
  298. if (bss->wmm_ie) {
  299. wmm = 1;
  300. }
  301. }
  302. mgmt = (struct ieee80211_mgmt *) buf;
  303. blen += 24;
  304. os_memset(mgmt, 0, 24);
  305. os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
  306. os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
  307. os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
  308. if (wpa_s->mlme.prev_bssid_set) {
  309. blen += 10;
  310. mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  311. WLAN_FC_STYPE_REASSOC_REQ);
  312. mgmt->u.reassoc_req.capab_info = host_to_le16(capab);
  313. mgmt->u.reassoc_req.listen_interval = host_to_le16(1);
  314. os_memcpy(mgmt->u.reassoc_req.current_ap,
  315. wpa_s->mlme.prev_bssid,
  316. ETH_ALEN);
  317. } else {
  318. blen += 4;
  319. mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  320. WLAN_FC_STYPE_ASSOC_REQ);
  321. mgmt->u.assoc_req.capab_info = host_to_le16(capab);
  322. mgmt->u.assoc_req.listen_interval = host_to_le16(1);
  323. }
  324. /* SSID */
  325. ies = pos = buf + blen;
  326. blen += 2 + wpa_s->mlme.ssid_len;
  327. *pos++ = WLAN_EID_SSID;
  328. *pos++ = wpa_s->mlme.ssid_len;
  329. os_memcpy(pos, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len);
  330. len = wpa_s->mlme.num_curr_rates;
  331. if (len > 8)
  332. len = 8;
  333. pos = buf + blen;
  334. blen += len + 2;
  335. *pos++ = WLAN_EID_SUPP_RATES;
  336. *pos++ = len;
  337. for (i = 0; i < len; i++)
  338. *pos++ = (u8) (wpa_s->mlme.curr_rates[i] / 5);
  339. if (wpa_s->mlme.num_curr_rates > len) {
  340. pos = buf + blen;
  341. blen += wpa_s->mlme.num_curr_rates - len + 2;
  342. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  343. *pos++ = wpa_s->mlme.num_curr_rates - len;
  344. for (i = len; i < wpa_s->mlme.num_curr_rates; i++)
  345. *pos++ = (u8) (wpa_s->mlme.curr_rates[i] / 5);
  346. }
  347. if (wpa_s->mlme.extra_ie && wpa_s->mlme.auth_alg != WLAN_AUTH_FT) {
  348. pos = buf + blen;
  349. blen += wpa_s->mlme.extra_ie_len;
  350. os_memcpy(pos, wpa_s->mlme.extra_ie, wpa_s->mlme.extra_ie_len);
  351. }
  352. #ifdef CONFIG_IEEE80211R
  353. if ((wpa_s->mlme.key_mgmt == KEY_MGMT_FT_802_1X ||
  354. wpa_s->mlme.key_mgmt == KEY_MGMT_FT_PSK) &&
  355. wpa_s->mlme.auth_alg != WLAN_AUTH_FT &&
  356. bss && bss->mdie &&
  357. bss->mdie_len >= 2 + sizeof(struct rsn_mdie) &&
  358. bss->mdie[1] >= sizeof(struct rsn_mdie)) {
  359. pos = buf + blen;
  360. blen += 2 + sizeof(struct rsn_mdie);
  361. *pos++ = WLAN_EID_MOBILITY_DOMAIN;
  362. *pos++ = sizeof(struct rsn_mdie);
  363. os_memcpy(pos, bss->mdie + 2, MOBILITY_DOMAIN_ID_LEN);
  364. pos += MOBILITY_DOMAIN_ID_LEN;
  365. *pos++ = 0; /* FIX: copy from the target AP's MDIE */
  366. }
  367. if ((wpa_s->mlme.key_mgmt == KEY_MGMT_FT_802_1X ||
  368. wpa_s->mlme.key_mgmt == KEY_MGMT_FT_PSK) &&
  369. wpa_s->mlme.auth_alg == WLAN_AUTH_FT && wpa_s->mlme.ft_ies) {
  370. pos = buf + blen;
  371. os_memcpy(pos, wpa_s->mlme.ft_ies, wpa_s->mlme.ft_ies_len);
  372. pos += wpa_s->mlme.ft_ies_len;
  373. blen += wpa_s->mlme.ft_ies_len;
  374. }
  375. #endif /* CONFIG_IEEE80211R */
  376. if (wmm && wpa_s->mlme.wmm_enabled) {
  377. pos = buf + blen;
  378. blen += 9;
  379. *pos++ = WLAN_EID_VENDOR_SPECIFIC;
  380. *pos++ = 7; /* len */
  381. *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
  382. *pos++ = 0x50;
  383. *pos++ = 0xf2;
  384. *pos++ = 2; /* WMM */
  385. *pos++ = 0; /* WMM info */
  386. *pos++ = 1; /* WMM ver */
  387. *pos++ = 0;
  388. }
  389. os_free(wpa_s->mlme.assocreq_ies);
  390. wpa_s->mlme.assocreq_ies_len = (buf + blen) - ies;
  391. wpa_s->mlme.assocreq_ies = os_malloc(wpa_s->mlme.assocreq_ies_len);
  392. if (wpa_s->mlme.assocreq_ies) {
  393. os_memcpy(wpa_s->mlme.assocreq_ies, ies,
  394. wpa_s->mlme.assocreq_ies_len);
  395. }
  396. ieee80211_sta_tx(wpa_s, buf, blen);
  397. os_free(buf);
  398. }
  399. static void ieee80211_send_deauth(struct wpa_supplicant *wpa_s, u16 reason)
  400. {
  401. u8 *buf;
  402. size_t len;
  403. struct ieee80211_mgmt *mgmt;
  404. buf = os_zalloc(sizeof(*mgmt));
  405. if (buf == NULL) {
  406. wpa_printf(MSG_DEBUG, "MLME: failed to allocate buffer for "
  407. "deauth frame");
  408. return;
  409. }
  410. mgmt = (struct ieee80211_mgmt *) buf;
  411. len = 24;
  412. os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
  413. os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
  414. os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
  415. mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  416. WLAN_FC_STYPE_DEAUTH);
  417. len += 2;
  418. mgmt->u.deauth.reason_code = host_to_le16(reason);
  419. ieee80211_sta_tx(wpa_s, buf, len);
  420. os_free(buf);
  421. }
  422. static void ieee80211_send_disassoc(struct wpa_supplicant *wpa_s, u16 reason)
  423. {
  424. u8 *buf;
  425. size_t len;
  426. struct ieee80211_mgmt *mgmt;
  427. buf = os_zalloc(sizeof(*mgmt));
  428. if (buf == NULL) {
  429. wpa_printf(MSG_DEBUG, "MLME: failed to allocate buffer for "
  430. "disassoc frame");
  431. return;
  432. }
  433. mgmt = (struct ieee80211_mgmt *) buf;
  434. len = 24;
  435. os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
  436. os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
  437. os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
  438. mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  439. WLAN_FC_STYPE_DISASSOC);
  440. len += 2;
  441. mgmt->u.disassoc.reason_code = host_to_le16(reason);
  442. ieee80211_sta_tx(wpa_s, buf, len);
  443. os_free(buf);
  444. }
  445. static int ieee80211_privacy_mismatch(struct wpa_supplicant *wpa_s)
  446. {
  447. struct ieee80211_sta_bss *bss;
  448. int res = 0;
  449. if (wpa_s->mlme.mixed_cell ||
  450. wpa_s->mlme.key_mgmt != KEY_MGMT_NONE)
  451. return 0;
  452. bss = ieee80211_bss_get(wpa_s, wpa_s->bssid);
  453. if (bss == NULL)
  454. return 0;
  455. if (ieee80211_sta_wep_configured(wpa_s) !=
  456. !!(bss->capability & WLAN_CAPABILITY_PRIVACY))
  457. res = 1;
  458. return res;
  459. }
  460. static void ieee80211_associate(struct wpa_supplicant *wpa_s)
  461. {
  462. wpa_s->mlme.assoc_tries++;
  463. if (wpa_s->mlme.assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
  464. wpa_printf(MSG_DEBUG, "MLME: association with AP " MACSTR
  465. " timed out", MAC2STR(wpa_s->bssid));
  466. return;
  467. }
  468. wpa_s->mlme.state = IEEE80211_ASSOCIATE;
  469. wpa_printf(MSG_DEBUG, "MLME: associate with AP " MACSTR,
  470. MAC2STR(wpa_s->bssid));
  471. if (ieee80211_privacy_mismatch(wpa_s)) {
  472. wpa_printf(MSG_DEBUG, "MLME: mismatch in privacy "
  473. "configuration and mixed-cell disabled - abort "
  474. "association");
  475. return;
  476. }
  477. ieee80211_send_assoc(wpa_s);
  478. ieee80211_reschedule_timer(wpa_s, IEEE80211_ASSOC_TIMEOUT);
  479. }
  480. static void ieee80211_associated(struct wpa_supplicant *wpa_s)
  481. {
  482. int disassoc;
  483. /* TODO: start monitoring current AP signal quality and number of
  484. * missed beacons. Scan other channels every now and then and search
  485. * for better APs. */
  486. /* TODO: remove expired BSSes */
  487. wpa_s->mlme.state = IEEE80211_ASSOCIATED;
  488. #if 0 /* FIX */
  489. sta = sta_info_get(local, wpa_s->bssid);
  490. if (sta == NULL) {
  491. wpa_printf(MSG_DEBUG "MLME: No STA entry for own AP " MACSTR,
  492. MAC2STR(wpa_s->bssid));
  493. disassoc = 1;
  494. } else {
  495. disassoc = 0;
  496. if (time_after(jiffies,
  497. sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
  498. if (wpa_s->mlme.probereq_poll) {
  499. wpa_printf(MSG_DEBUG "MLME: No ProbeResp from "
  500. "current AP " MACSTR " - assume "
  501. "out of range",
  502. MAC2STR(wpa_s->bssid));
  503. disassoc = 1;
  504. } else {
  505. ieee80211_send_probe_req(
  506. wpa_s->bssid,
  507. wpa_s->mlme.scan_ssid,
  508. wpa_s->mlme.scan_ssid_len);
  509. wpa_s->mlme.probereq_poll = 1;
  510. }
  511. } else {
  512. wpa_s->mlme.probereq_poll = 0;
  513. if (time_after(jiffies, wpa_s->mlme.last_probe +
  514. IEEE80211_PROBE_INTERVAL)) {
  515. wpa_s->mlme.last_probe = jiffies;
  516. ieee80211_send_probe_req(wpa_s->bssid,
  517. wpa_s->mlme.ssid,
  518. wpa_s->mlme.ssid_len);
  519. }
  520. }
  521. sta_info_release(local, sta);
  522. }
  523. #else
  524. disassoc = 0;
  525. #endif
  526. if (disassoc) {
  527. wpa_supplicant_event(wpa_s, EVENT_DISASSOC, NULL);
  528. ieee80211_reschedule_timer(wpa_s,
  529. IEEE80211_MONITORING_INTERVAL +
  530. 30000);
  531. } else {
  532. ieee80211_reschedule_timer(wpa_s,
  533. IEEE80211_MONITORING_INTERVAL);
  534. }
  535. }
  536. static void ieee80211_send_probe_req(struct wpa_supplicant *wpa_s,
  537. const u8 *dst,
  538. const u8 *ssid, size_t ssid_len)
  539. {
  540. u8 *buf;
  541. size_t len;
  542. struct ieee80211_mgmt *mgmt;
  543. u8 *pos, *supp_rates;
  544. u8 *esupp_rates = NULL;
  545. int i;
  546. buf = os_malloc(sizeof(*mgmt) + 200 + wpa_s->mlme.extra_probe_ie_len);
  547. if (buf == NULL) {
  548. wpa_printf(MSG_DEBUG, "MLME: failed to allocate buffer for "
  549. "probe request");
  550. return;
  551. }
  552. mgmt = (struct ieee80211_mgmt *) buf;
  553. len = 24;
  554. os_memset(mgmt, 0, 24);
  555. mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  556. WLAN_FC_STYPE_PROBE_REQ);
  557. os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
  558. if (dst) {
  559. os_memcpy(mgmt->da, dst, ETH_ALEN);
  560. os_memcpy(mgmt->bssid, dst, ETH_ALEN);
  561. } else {
  562. os_memset(mgmt->da, 0xff, ETH_ALEN);
  563. os_memset(mgmt->bssid, 0xff, ETH_ALEN);
  564. }
  565. pos = buf + len;
  566. len += 2 + ssid_len;
  567. *pos++ = WLAN_EID_SSID;
  568. *pos++ = ssid_len;
  569. os_memcpy(pos, ssid, ssid_len);
  570. supp_rates = buf + len;
  571. len += 2;
  572. supp_rates[0] = WLAN_EID_SUPP_RATES;
  573. supp_rates[1] = 0;
  574. for (i = 0; i < wpa_s->mlme.num_curr_rates; i++) {
  575. if (esupp_rates) {
  576. pos = buf + len;
  577. len++;
  578. esupp_rates[1]++;
  579. } else if (supp_rates[1] == 8) {
  580. esupp_rates = pos;
  581. esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES;
  582. esupp_rates[1] = 1;
  583. pos = &esupp_rates[2];
  584. len += 3;
  585. } else {
  586. pos = buf + len;
  587. len++;
  588. supp_rates[1]++;
  589. }
  590. *pos++ = wpa_s->mlme.curr_rates[i] / 5;
  591. }
  592. if (wpa_s->mlme.extra_probe_ie) {
  593. os_memcpy(pos, wpa_s->mlme.extra_probe_ie,
  594. wpa_s->mlme.extra_probe_ie_len);
  595. len += wpa_s->mlme.extra_probe_ie_len;
  596. }
  597. ieee80211_sta_tx(wpa_s, buf, len);
  598. os_free(buf);
  599. }
  600. static int ieee80211_sta_wep_configured(struct wpa_supplicant *wpa_s)
  601. {
  602. #if 0 /* FIX */
  603. if (sdata == NULL || sdata->default_key == NULL ||
  604. sdata->default_key->alg != ALG_WEP)
  605. return 0;
  606. return 1;
  607. #else
  608. return 0;
  609. #endif
  610. }
  611. static void ieee80211_auth_completed(struct wpa_supplicant *wpa_s)
  612. {
  613. wpa_printf(MSG_DEBUG, "MLME: authenticated");
  614. wpa_s->mlme.authenticated = 1;
  615. ieee80211_associate(wpa_s);
  616. }
  617. static void ieee80211_auth_challenge(struct wpa_supplicant *wpa_s,
  618. struct ieee80211_mgmt *mgmt,
  619. size_t len,
  620. struct ieee80211_rx_status *rx_status)
  621. {
  622. u8 *pos;
  623. struct ieee802_11_elems elems;
  624. wpa_printf(MSG_DEBUG, "MLME: replying to auth challenge");
  625. pos = mgmt->u.auth.variable;
  626. if (ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems, 0)
  627. == ParseFailed) {
  628. wpa_printf(MSG_DEBUG, "MLME: failed to parse Auth(challenge)");
  629. return;
  630. }
  631. if (elems.challenge == NULL) {
  632. wpa_printf(MSG_DEBUG, "MLME: no challenge IE in shared key "
  633. "auth frame");
  634. return;
  635. }
  636. ieee80211_send_auth(wpa_s, 3, elems.challenge - 2,
  637. elems.challenge_len + 2, 1);
  638. }
  639. static void ieee80211_rx_mgmt_auth(struct wpa_supplicant *wpa_s,
  640. struct ieee80211_mgmt *mgmt,
  641. size_t len,
  642. struct ieee80211_rx_status *rx_status)
  643. {
  644. struct wpa_ssid *ssid = wpa_s->current_ssid;
  645. u16 auth_alg, auth_transaction, status_code;
  646. int adhoc;
  647. adhoc = ssid && ssid->mode == 1;
  648. if (wpa_s->mlme.state != IEEE80211_AUTHENTICATE && !adhoc) {
  649. wpa_printf(MSG_DEBUG, "MLME: authentication frame received "
  650. "from " MACSTR ", but not in authenticate state - "
  651. "ignored", MAC2STR(mgmt->sa));
  652. return;
  653. }
  654. if (len < 24 + 6) {
  655. wpa_printf(MSG_DEBUG, "MLME: too short (%lu) authentication "
  656. "frame received from " MACSTR " - ignored",
  657. (unsigned long) len, MAC2STR(mgmt->sa));
  658. return;
  659. }
  660. if (!adhoc && os_memcmp(wpa_s->bssid, mgmt->sa, ETH_ALEN) != 0) {
  661. wpa_printf(MSG_DEBUG, "MLME: authentication frame received "
  662. "from unknown AP (SA=" MACSTR " BSSID=" MACSTR
  663. ") - ignored",
  664. MAC2STR(mgmt->sa), MAC2STR(mgmt->bssid));
  665. return;
  666. }
  667. if (adhoc && os_memcmp(wpa_s->bssid, mgmt->bssid, ETH_ALEN) != 0) {
  668. wpa_printf(MSG_DEBUG, "MLME: authentication frame received "
  669. "from unknown BSSID (SA=" MACSTR " BSSID=" MACSTR
  670. ") - ignored",
  671. MAC2STR(mgmt->sa), MAC2STR(mgmt->bssid));
  672. return;
  673. }
  674. auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
  675. auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
  676. status_code = le_to_host16(mgmt->u.auth.status_code);
  677. wpa_printf(MSG_DEBUG, "MLME: RX authentication from " MACSTR
  678. " (alg=%d transaction=%d status=%d)",
  679. MAC2STR(mgmt->sa), auth_alg, auth_transaction, status_code);
  680. if (adhoc) {
  681. /* IEEE 802.11 standard does not require authentication in IBSS
  682. * networks and most implementations do not seem to use it.
  683. * However, try to reply to authentication attempts if someone
  684. * has actually implemented this.
  685. * TODO: Could implement shared key authentication. */
  686. if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) {
  687. wpa_printf(MSG_DEBUG, "MLME: unexpected IBSS "
  688. "authentication frame (alg=%d "
  689. "transaction=%d)",
  690. auth_alg, auth_transaction);
  691. return;
  692. }
  693. ieee80211_send_auth(wpa_s, 2, NULL, 0, 0);
  694. }
  695. if (auth_alg != wpa_s->mlme.auth_alg ||
  696. auth_transaction != wpa_s->mlme.auth_transaction) {
  697. wpa_printf(MSG_DEBUG, "MLME: unexpected authentication frame "
  698. "(alg=%d transaction=%d)",
  699. auth_alg, auth_transaction);
  700. return;
  701. }
  702. if (status_code != WLAN_STATUS_SUCCESS) {
  703. wpa_printf(MSG_DEBUG, "MLME: AP denied authentication "
  704. "(auth_alg=%d code=%d)", wpa_s->mlme.auth_alg,
  705. status_code);
  706. if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
  707. const int num_algs = 3;
  708. u8 algs[num_algs];
  709. int i, pos;
  710. algs[0] = algs[1] = algs[2] = 0xff;
  711. if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_OPEN)
  712. algs[0] = WLAN_AUTH_OPEN;
  713. if (wpa_s->mlme.auth_algs &
  714. IEEE80211_AUTH_ALG_SHARED_KEY)
  715. algs[1] = WLAN_AUTH_SHARED_KEY;
  716. if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_LEAP)
  717. algs[2] = WLAN_AUTH_LEAP;
  718. if (wpa_s->mlme.auth_alg == WLAN_AUTH_OPEN)
  719. pos = 0;
  720. else if (wpa_s->mlme.auth_alg == WLAN_AUTH_SHARED_KEY)
  721. pos = 1;
  722. else
  723. pos = 2;
  724. for (i = 0; i < num_algs; i++) {
  725. pos++;
  726. if (pos >= num_algs)
  727. pos = 0;
  728. if (algs[pos] == wpa_s->mlme.auth_alg ||
  729. algs[pos] == 0xff)
  730. continue;
  731. if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
  732. !ieee80211_sta_wep_configured(wpa_s))
  733. continue;
  734. wpa_s->mlme.auth_alg = algs[pos];
  735. wpa_printf(MSG_DEBUG, "MLME: set auth_alg=%d "
  736. "for next try",
  737. wpa_s->mlme.auth_alg);
  738. break;
  739. }
  740. }
  741. return;
  742. }
  743. switch (wpa_s->mlme.auth_alg) {
  744. case WLAN_AUTH_OPEN:
  745. case WLAN_AUTH_LEAP:
  746. ieee80211_auth_completed(wpa_s);
  747. break;
  748. case WLAN_AUTH_SHARED_KEY:
  749. if (wpa_s->mlme.auth_transaction == 4)
  750. ieee80211_auth_completed(wpa_s);
  751. else
  752. ieee80211_auth_challenge(wpa_s, mgmt, len,
  753. rx_status);
  754. break;
  755. #ifdef CONFIG_IEEE80211R
  756. case WLAN_AUTH_FT:
  757. {
  758. union wpa_event_data data;
  759. struct wpabuf *ric = NULL;
  760. os_memset(&data, 0, sizeof(data));
  761. data.ft_ies.ies = mgmt->u.auth.variable;
  762. data.ft_ies.ies_len = len -
  763. (mgmt->u.auth.variable - (u8 *) mgmt);
  764. os_memcpy(data.ft_ies.target_ap, wpa_s->bssid, ETH_ALEN);
  765. if (os_strcmp(wpa_s->driver->name, "test") == 0 &&
  766. wpa_s->mlme.wmm_enabled) {
  767. ric = wpabuf_alloc(200);
  768. if (ric) {
  769. /* Build simple RIC-Request: RDIE | TSPEC */
  770. /* RIC Data (RDIE) */
  771. wpabuf_put_u8(ric, WLAN_EID_RIC_DATA);
  772. wpabuf_put_u8(ric, 4);
  773. wpabuf_put_u8(ric, 0); /* RDIE Identifier */
  774. wpabuf_put_u8(ric, 1); /* Resource Descriptor
  775. * Count */
  776. wpabuf_put_le16(ric, 0); /* Status Code */
  777. /* WMM TSPEC */
  778. ieee80211_build_tspec(ric);
  779. data.ft_ies.ric_ies = wpabuf_head(ric);
  780. data.ft_ies.ric_ies_len = wpabuf_len(ric);
  781. }
  782. }
  783. wpa_supplicant_event(wpa_s, EVENT_FT_RESPONSE, &data);
  784. wpabuf_free(ric);
  785. ieee80211_auth_completed(wpa_s);
  786. break;
  787. }
  788. #endif /* CONFIG_IEEE80211R */
  789. }
  790. }
  791. static void ieee80211_rx_mgmt_deauth(struct wpa_supplicant *wpa_s,
  792. struct ieee80211_mgmt *mgmt,
  793. size_t len,
  794. struct ieee80211_rx_status *rx_status)
  795. {
  796. u16 reason_code;
  797. if (len < 24 + 2) {
  798. wpa_printf(MSG_DEBUG, "MLME: too short (%lu) deauthentication "
  799. "frame received from " MACSTR " - ignored",
  800. (unsigned long) len, MAC2STR(mgmt->sa));
  801. return;
  802. }
  803. if (os_memcmp(wpa_s->bssid, mgmt->sa, ETH_ALEN) != 0) {
  804. wpa_printf(MSG_DEBUG, "MLME: deauthentication frame received "
  805. "from unknown AP (SA=" MACSTR " BSSID=" MACSTR
  806. ") - ignored",
  807. MAC2STR(mgmt->sa), MAC2STR(mgmt->bssid));
  808. return;
  809. }
  810. reason_code = le_to_host16(mgmt->u.deauth.reason_code);
  811. wpa_printf(MSG_DEBUG, "MLME: RX deauthentication from " MACSTR
  812. " (reason=%d)", MAC2STR(mgmt->sa), reason_code);
  813. if (wpa_s->mlme.authenticated)
  814. wpa_printf(MSG_DEBUG, "MLME: deauthenticated");
  815. if (wpa_s->mlme.state == IEEE80211_AUTHENTICATE ||
  816. wpa_s->mlme.state == IEEE80211_ASSOCIATE ||
  817. wpa_s->mlme.state == IEEE80211_ASSOCIATED) {
  818. wpa_s->mlme.state = IEEE80211_AUTHENTICATE;
  819. ieee80211_reschedule_timer(wpa_s,
  820. IEEE80211_RETRY_AUTH_INTERVAL);
  821. }
  822. ieee80211_set_associated(wpa_s, 0);
  823. wpa_s->mlme.authenticated = 0;
  824. }
  825. static void ieee80211_rx_mgmt_disassoc(struct wpa_supplicant *wpa_s,
  826. struct ieee80211_mgmt *mgmt,
  827. size_t len,
  828. struct ieee80211_rx_status *rx_status)
  829. {
  830. u16 reason_code;
  831. if (len < 24 + 2) {
  832. wpa_printf(MSG_DEBUG, "MLME: too short (%lu) disassociation "
  833. "frame received from " MACSTR " - ignored",
  834. (unsigned long) len, MAC2STR(mgmt->sa));
  835. return;
  836. }
  837. if (os_memcmp(wpa_s->bssid, mgmt->sa, ETH_ALEN) != 0) {
  838. wpa_printf(MSG_DEBUG, "MLME: disassociation frame received "
  839. "from unknown AP (SA=" MACSTR " BSSID=" MACSTR
  840. ") - ignored",
  841. MAC2STR(mgmt->sa), MAC2STR(mgmt->bssid));
  842. return;
  843. }
  844. reason_code = le_to_host16(mgmt->u.disassoc.reason_code);
  845. wpa_printf(MSG_DEBUG, "MLME: RX disassociation from " MACSTR
  846. " (reason=%d)", MAC2STR(mgmt->sa), reason_code);
  847. if (wpa_s->mlme.associated)
  848. wpa_printf(MSG_DEBUG, "MLME: disassociated");
  849. if (wpa_s->mlme.state == IEEE80211_ASSOCIATED) {
  850. wpa_s->mlme.state = IEEE80211_ASSOCIATE;
  851. ieee80211_reschedule_timer(wpa_s,
  852. IEEE80211_RETRY_AUTH_INTERVAL);
  853. }
  854. ieee80211_set_associated(wpa_s, 0);
  855. }
  856. static int ieee80211_ft_assoc_resp(struct wpa_supplicant *wpa_s,
  857. struct ieee802_11_elems *elems)
  858. {
  859. #ifdef CONFIG_IEEE80211R
  860. const u8 *mobility_domain = NULL;
  861. const u8 *r0kh_id = NULL;
  862. size_t r0kh_id_len = 0;
  863. const u8 *r1kh_id = NULL;
  864. struct rsn_ftie *hdr;
  865. const u8 *pos, *end;
  866. if (elems->mdie && elems->mdie_len >= MOBILITY_DOMAIN_ID_LEN)
  867. mobility_domain = elems->mdie;
  868. if (elems->ftie && elems->ftie_len >= sizeof(struct rsn_ftie)) {
  869. end = elems->ftie + elems->ftie_len;
  870. hdr = (struct rsn_ftie *) elems->ftie;
  871. pos = (const u8 *) (hdr + 1);
  872. while (pos + 1 < end) {
  873. if (pos + 2 + pos[1] > end)
  874. break;
  875. if (pos[0] == FTIE_SUBELEM_R1KH_ID &&
  876. pos[1] == FT_R1KH_ID_LEN)
  877. r1kh_id = pos + 2;
  878. else if (pos[0] == FTIE_SUBELEM_R0KH_ID &&
  879. pos[1] >= 1 && pos[1] <= FT_R0KH_ID_MAX_LEN) {
  880. r0kh_id = pos + 2;
  881. r0kh_id_len = pos[1];
  882. }
  883. pos += 2 + pos[1];
  884. }
  885. }
  886. return wpa_sm_set_ft_params(wpa_s->wpa, mobility_domain, r0kh_id,
  887. r0kh_id_len, r1kh_id);
  888. #else /* CONFIG_IEEE80211R */
  889. return 0;
  890. #endif /* CONFIG_IEEE80211R */
  891. }
  892. static void ieee80211_build_tspec(struct wpabuf *buf)
  893. {
  894. struct wmm_tspec_element *tspec;
  895. int tid, up;
  896. tspec = wpabuf_put(buf, sizeof(*tspec));
  897. tspec->eid = WLAN_EID_VENDOR_SPECIFIC;
  898. tspec->length = sizeof(*tspec) - 2;
  899. tspec->oui[0] = 0x00;
  900. tspec->oui[1] = 0x50;
  901. tspec->oui[2] = 0xf2;
  902. tspec->oui_type = 2;
  903. tspec->oui_subtype = 2;
  904. tspec->version = 1;
  905. tid = 1;
  906. up = 6; /* Voice */
  907. tspec->ts_info[0] = (tid << 1) |
  908. (WMM_TSPEC_DIRECTION_BI_DIRECTIONAL << 5) |
  909. BIT(7);
  910. tspec->ts_info[1] = up << 3;
  911. tspec->nominal_msdu_size = host_to_le16(1530);
  912. tspec->mean_data_rate = host_to_le32(128000); /* bits per second */
  913. tspec->minimum_phy_rate = host_to_le32(6000000);
  914. tspec->surplus_bandwidth_allowance = host_to_le16(0x3000); /* 150% */
  915. }
  916. static void ieee80211_tx_addts(struct wpa_supplicant *wpa_s)
  917. {
  918. struct wpabuf *buf;
  919. struct ieee80211_mgmt *mgmt;
  920. size_t alen;
  921. wpa_printf(MSG_DEBUG, "MLME: Send ADDTS Request for Voice TSPEC");
  922. mgmt = NULL;
  923. alen = mgmt->u.action.u.wmm_action.variable - (u8 *) mgmt;
  924. buf = wpabuf_alloc(alen + sizeof(struct wmm_tspec_element));
  925. if (buf == NULL)
  926. return;
  927. mgmt = wpabuf_put(buf, alen);
  928. os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
  929. os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
  930. os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
  931. mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  932. WLAN_FC_STYPE_ACTION);
  933. mgmt->u.action.category = WLAN_ACTION_WMM;
  934. mgmt->u.action.u.wmm_action.action_code = WMM_ACTION_CODE_ADDTS_REQ;
  935. mgmt->u.action.u.wmm_action.dialog_token = 1;
  936. mgmt->u.action.u.wmm_action.status_code = 0;
  937. ieee80211_build_tspec(buf);
  938. ieee80211_sta_tx(wpa_s, wpabuf_head(buf), wpabuf_len(buf));
  939. wpabuf_free(buf);
  940. }
  941. static void ieee80211_rx_mgmt_assoc_resp(struct wpa_supplicant *wpa_s,
  942. struct ieee80211_mgmt *mgmt,
  943. size_t len,
  944. struct ieee80211_rx_status *rx_status,
  945. int reassoc)
  946. {
  947. u8 rates[32];
  948. size_t rates_len;
  949. u16 capab_info, status_code, aid;
  950. struct ieee802_11_elems elems;
  951. u8 *pos;
  952. /* AssocResp and ReassocResp have identical structure, so process both
  953. * of them in this function. */
  954. if (wpa_s->mlme.state != IEEE80211_ASSOCIATE) {
  955. wpa_printf(MSG_DEBUG, "MLME: association frame received from "
  956. MACSTR ", but not in associate state - ignored",
  957. MAC2STR(mgmt->sa));
  958. return;
  959. }
  960. if (len < 24 + 6) {
  961. wpa_printf(MSG_DEBUG, "MLME: too short (%lu) association "
  962. "frame received from " MACSTR " - ignored",
  963. (unsigned long) len, MAC2STR(mgmt->sa));
  964. return;
  965. }
  966. if (os_memcmp(wpa_s->bssid, mgmt->sa, ETH_ALEN) != 0) {
  967. wpa_printf(MSG_DEBUG, "MLME: association frame received from "
  968. "unknown AP (SA=" MACSTR " BSSID=" MACSTR ") - "
  969. "ignored", MAC2STR(mgmt->sa), MAC2STR(mgmt->bssid));
  970. return;
  971. }
  972. capab_info = le_to_host16(mgmt->u.assoc_resp.capab_info);
  973. status_code = le_to_host16(mgmt->u.assoc_resp.status_code);
  974. aid = le_to_host16(mgmt->u.assoc_resp.aid);
  975. if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
  976. wpa_printf(MSG_DEBUG, "MLME: invalid aid value %d; bits 15:14 "
  977. "not set", aid);
  978. aid &= ~(BIT(15) | BIT(14));
  979. wpa_printf(MSG_DEBUG, "MLME: RX %sssocResp from " MACSTR
  980. " (capab=0x%x status=%d aid=%d)",
  981. reassoc ? "Rea" : "A", MAC2STR(mgmt->sa),
  982. capab_info, status_code, aid);
  983. pos = mgmt->u.assoc_resp.variable;
  984. if (ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems, 0)
  985. == ParseFailed) {
  986. wpa_printf(MSG_DEBUG, "MLME: failed to parse AssocResp");
  987. return;
  988. }
  989. if (status_code != WLAN_STATUS_SUCCESS) {
  990. wpa_printf(MSG_DEBUG, "MLME: AP denied association (code=%d)",
  991. status_code);
  992. #ifdef CONFIG_IEEE80211W
  993. if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
  994. elems.timeout_int && elems.timeout_int_len == 5 &&
  995. elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
  996. u32 tu, ms;
  997. tu = WPA_GET_LE32(elems.timeout_int + 1);
  998. ms = tu * 1024 / 1000;
  999. wpa_printf(MSG_DEBUG, "MLME: AP rejected association "
  1000. "temporarily; comeback duration %u TU "
  1001. "(%u ms)", tu, ms);
  1002. if (ms > IEEE80211_ASSOC_TIMEOUT) {
  1003. wpa_printf(MSG_DEBUG, "MLME: Update timer "
  1004. "based on comeback duration");
  1005. ieee80211_reschedule_timer(wpa_s, ms);
  1006. }
  1007. }
  1008. #endif /* CONFIG_IEEE80211W */
  1009. return;
  1010. }
  1011. if (elems.supp_rates == NULL) {
  1012. wpa_printf(MSG_DEBUG, "MLME: no SuppRates element in "
  1013. "AssocResp");
  1014. return;
  1015. }
  1016. if (wpa_s->mlme.auth_alg == WLAN_AUTH_FT) {
  1017. if (!reassoc) {
  1018. wpa_printf(MSG_DEBUG, "MLME: AP tried to use "
  1019. "association, not reassociation, response "
  1020. "with FT");
  1021. return;
  1022. }
  1023. if (wpa_ft_validate_reassoc_resp(
  1024. wpa_s->wpa, pos, len - (pos - (u8 *) mgmt),
  1025. mgmt->sa) < 0) {
  1026. wpa_printf(MSG_DEBUG, "MLME: FT validation of Reassoc"
  1027. "Resp failed");
  1028. return;
  1029. }
  1030. } else if (ieee80211_ft_assoc_resp(wpa_s, &elems) < 0)
  1031. return;
  1032. wpa_printf(MSG_DEBUG, "MLME: associated");
  1033. wpa_s->mlme.aid = aid;
  1034. wpa_s->mlme.ap_capab = capab_info;
  1035. os_free(wpa_s->mlme.assocresp_ies);
  1036. wpa_s->mlme.assocresp_ies_len = len - (pos - (u8 *) mgmt);
  1037. wpa_s->mlme.assocresp_ies = os_malloc(wpa_s->mlme.assocresp_ies_len);
  1038. if (wpa_s->mlme.assocresp_ies) {
  1039. os_memcpy(wpa_s->mlme.assocresp_ies, pos,
  1040. wpa_s->mlme.assocresp_ies_len);
  1041. }
  1042. ieee80211_set_associated(wpa_s, 1);
  1043. rates_len = elems.supp_rates_len;
  1044. if (rates_len > sizeof(rates))
  1045. rates_len = sizeof(rates);
  1046. os_memcpy(rates, elems.supp_rates, rates_len);
  1047. if (elems.ext_supp_rates) {
  1048. size_t _len = elems.ext_supp_rates_len;
  1049. if (_len > sizeof(rates) - rates_len)
  1050. _len = sizeof(rates) - rates_len;
  1051. os_memcpy(rates + rates_len, elems.ext_supp_rates, _len);
  1052. rates_len += _len;
  1053. }
  1054. if (wpa_drv_set_bssid(wpa_s, wpa_s->bssid) < 0) {
  1055. wpa_printf(MSG_DEBUG, "MLME: failed to set BSSID for the "
  1056. "netstack");
  1057. }
  1058. if (wpa_drv_set_ssid(wpa_s, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len) <
  1059. 0) {
  1060. wpa_printf(MSG_DEBUG, "MLME: failed to set SSID for the "
  1061. "netstack");
  1062. }
  1063. /* Remove STA entry before adding a new one just in case to avoid
  1064. * problems with existing configuration (e.g., keys). */
  1065. wpa_drv_mlme_remove_sta(wpa_s, wpa_s->bssid);
  1066. if (wpa_drv_mlme_add_sta(wpa_s, wpa_s->bssid, rates, rates_len) < 0) {
  1067. wpa_printf(MSG_DEBUG, "MLME: failed to add STA entry to the "
  1068. "netstack");
  1069. }
  1070. if (elems.wmm && wpa_s->mlme.wmm_enabled)
  1071. ieee80211_sta_wmm_params(wpa_s, elems.wmm, elems.wmm_len);
  1072. ieee80211_associated(wpa_s);
  1073. if (wpa_s->mlme.auth_alg != WLAN_AUTH_FT &&
  1074. os_strcmp(wpa_s->driver->name, "test") == 0 &&
  1075. elems.wmm && wpa_s->mlme.wmm_enabled) {
  1076. /* Test WMM-AC - send ADDTS for WMM TSPEC */
  1077. ieee80211_tx_addts(wpa_s);
  1078. }
  1079. }
  1080. /* Caller must hold local->sta_bss_lock */
  1081. static void __ieee80211_bss_hash_add(struct wpa_supplicant *wpa_s,
  1082. struct ieee80211_sta_bss *bss)
  1083. {
  1084. bss->hnext = wpa_s->mlme.sta_bss_hash[STA_HASH(bss->bssid)];
  1085. wpa_s->mlme.sta_bss_hash[STA_HASH(bss->bssid)] = bss;
  1086. }
  1087. /* Caller must hold local->sta_bss_lock */
  1088. static void __ieee80211_bss_hash_del(struct wpa_supplicant *wpa_s,
  1089. struct ieee80211_sta_bss *bss)
  1090. {
  1091. struct ieee80211_sta_bss *b, *prev = NULL;
  1092. b = wpa_s->mlme.sta_bss_hash[STA_HASH(bss->bssid)];
  1093. while (b) {
  1094. if (b == bss) {
  1095. if (prev == NULL) {
  1096. wpa_s->mlme.sta_bss_hash[STA_HASH(bss->bssid)]
  1097. = bss->hnext;
  1098. } else {
  1099. prev->hnext = bss->hnext;
  1100. }
  1101. break;
  1102. }
  1103. prev = b;
  1104. b = b->hnext;
  1105. }
  1106. }
  1107. static struct ieee80211_sta_bss *
  1108. ieee80211_bss_add(struct wpa_supplicant *wpa_s, const u8 *bssid)
  1109. {
  1110. struct ieee80211_sta_bss *bss;
  1111. bss = os_zalloc(sizeof(*bss));
  1112. if (bss == NULL)
  1113. return NULL;
  1114. os_memcpy(bss->bssid, bssid, ETH_ALEN);
  1115. /* TODO: order by RSSI? */
  1116. bss->next = wpa_s->mlme.sta_bss_list;
  1117. wpa_s->mlme.sta_bss_list = bss;
  1118. __ieee80211_bss_hash_add(wpa_s, bss);
  1119. return bss;
  1120. }
  1121. static struct ieee80211_sta_bss *
  1122. ieee80211_bss_get(struct wpa_supplicant *wpa_s, const u8 *bssid)
  1123. {
  1124. struct ieee80211_sta_bss *bss;
  1125. bss = wpa_s->mlme.sta_bss_hash[STA_HASH(bssid)];
  1126. while (bss) {
  1127. if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0)
  1128. break;
  1129. bss = bss->hnext;
  1130. }
  1131. return bss;
  1132. }
  1133. static void ieee80211_bss_free(struct wpa_supplicant *wpa_s,
  1134. struct ieee80211_sta_bss *bss)
  1135. {
  1136. __ieee80211_bss_hash_del(wpa_s, bss);
  1137. os_free(bss->ie);
  1138. os_free(bss->wpa_ie);
  1139. os_free(bss->rsn_ie);
  1140. os_free(bss->wmm_ie);
  1141. os_free(bss->mdie);
  1142. os_free(bss);
  1143. }
  1144. static void ieee80211_bss_list_deinit(struct wpa_supplicant *wpa_s)
  1145. {
  1146. struct ieee80211_sta_bss *bss, *prev;
  1147. bss = wpa_s->mlme.sta_bss_list;
  1148. wpa_s->mlme.sta_bss_list = NULL;
  1149. while (bss) {
  1150. prev = bss;
  1151. bss = bss->next;
  1152. ieee80211_bss_free(wpa_s, prev);
  1153. }
  1154. }
  1155. static void ieee80211_bss_info(struct wpa_supplicant *wpa_s,
  1156. struct ieee80211_mgmt *mgmt,
  1157. size_t len,
  1158. struct ieee80211_rx_status *rx_status,
  1159. int beacon)
  1160. {
  1161. struct ieee802_11_elems elems;
  1162. size_t baselen;
  1163. int channel, invalid = 0, clen;
  1164. struct ieee80211_sta_bss *bss;
  1165. u64 timestamp;
  1166. u8 *pos, *ie_pos;
  1167. size_t ie_len;
  1168. if (!beacon && os_memcmp(mgmt->da, wpa_s->own_addr, ETH_ALEN))
  1169. return; /* ignore ProbeResp to foreign address */
  1170. #if 0
  1171. wpa_printf(MSG_MSGDUMP, "MLME: RX %s from " MACSTR " to " MACSTR,
  1172. beacon ? "Beacon" : "Probe Response",
  1173. MAC2STR(mgmt->sa), MAC2STR(mgmt->da));
  1174. #endif
  1175. baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
  1176. if (baselen > len)
  1177. return;
  1178. pos = mgmt->u.beacon.timestamp;
  1179. timestamp = WPA_GET_LE64(pos);
  1180. #if 0 /* FIX */
  1181. if (local->conf.mode == IW_MODE_ADHOC && beacon &&
  1182. os_memcmp(mgmt->bssid, local->bssid, ETH_ALEN) == 0) {
  1183. #ifdef IEEE80211_IBSS_DEBUG
  1184. static unsigned long last_tsf_debug = 0;
  1185. u64 tsf;
  1186. if (local->hw->get_tsf)
  1187. tsf = local->hw->get_tsf(local->mdev);
  1188. else
  1189. tsf = -1LLU;
  1190. if (time_after(jiffies, last_tsf_debug + 5 * HZ)) {
  1191. wpa_printf(MSG_DEBUG, "RX beacon SA=" MACSTR " BSSID="
  1192. MACSTR " TSF=0x%llx BCN=0x%llx diff=%lld "
  1193. "@%ld",
  1194. MAC2STR(mgmt->sa), MAC2STR(mgmt->bssid),
  1195. tsf, timestamp, tsf - timestamp, jiffies);
  1196. last_tsf_debug = jiffies;
  1197. }
  1198. #endif /* IEEE80211_IBSS_DEBUG */
  1199. }
  1200. #endif
  1201. ie_pos = mgmt->u.beacon.variable;
  1202. ie_len = len - baselen;
  1203. if (ieee802_11_parse_elems(ie_pos, ie_len, &elems, 0) == ParseFailed)
  1204. invalid = 1;
  1205. #if 0 /* FIX */
  1206. if (local->conf.mode == IW_MODE_ADHOC && elems.supp_rates &&
  1207. os_memcmp(mgmt->bssid, local->bssid, ETH_ALEN) == 0 &&
  1208. (sta = sta_info_get(local, mgmt->sa))) {
  1209. struct ieee80211_rate *rates;
  1210. size_t num_rates;
  1211. u32 supp_rates, prev_rates;
  1212. int i, j, oper_mode;
  1213. rates = local->curr_rates;
  1214. num_rates = local->num_curr_rates;
  1215. oper_mode = wpa_s->mlme.sta_scanning ?
  1216. local->scan_oper_phymode : local->conf.phymode;
  1217. for (i = 0; i < local->hw->num_modes; i++) {
  1218. struct ieee80211_hw_modes *mode = &local->hw->modes[i];
  1219. if (oper_mode == mode->mode) {
  1220. rates = mode->rates;
  1221. num_rates = mode->num_rates;
  1222. break;
  1223. }
  1224. }
  1225. supp_rates = 0;
  1226. for (i = 0; i < elems.supp_rates_len +
  1227. elems.ext_supp_rates_len; i++) {
  1228. u8 rate = 0;
  1229. int own_rate;
  1230. if (i < elems.supp_rates_len)
  1231. rate = elems.supp_rates[i];
  1232. else if (elems.ext_supp_rates)
  1233. rate = elems.ext_supp_rates
  1234. [i - elems.supp_rates_len];
  1235. own_rate = 5 * (rate & 0x7f);
  1236. if (oper_mode == MODE_ATHEROS_TURBO)
  1237. own_rate *= 2;
  1238. for (j = 0; j < num_rates; j++)
  1239. if (rates[j].rate == own_rate)
  1240. supp_rates |= BIT(j);
  1241. }
  1242. prev_rates = sta->supp_rates;
  1243. sta->supp_rates &= supp_rates;
  1244. if (sta->supp_rates == 0) {
  1245. /* No matching rates - this should not really happen.
  1246. * Make sure that at least one rate is marked
  1247. * supported to avoid issues with TX rate ctrl. */
  1248. sta->supp_rates = wpa_s->mlme.supp_rates_bits;
  1249. }
  1250. if (sta->supp_rates != prev_rates) {
  1251. wpa_printf(MSG_DEBUG, "MLME: updated supp_rates set "
  1252. "for " MACSTR " based on beacon info "
  1253. "(0x%x & 0x%x -> 0x%x)",
  1254. MAC2STR(sta->addr), prev_rates,
  1255. supp_rates, sta->supp_rates);
  1256. }
  1257. sta_info_release(local, sta);
  1258. }
  1259. #endif
  1260. if (elems.ssid == NULL)
  1261. return;
  1262. if (elems.ds_params && elems.ds_params_len == 1)
  1263. channel = elems.ds_params[0];
  1264. else
  1265. channel = rx_status->channel;
  1266. bss = ieee80211_bss_get(wpa_s, mgmt->bssid);
  1267. if (bss == NULL) {
  1268. bss = ieee80211_bss_add(wpa_s, mgmt->bssid);
  1269. if (bss == NULL)
  1270. return;
  1271. } else {
  1272. #if 0
  1273. /* TODO: order by RSSI? */
  1274. spin_lock_bh(&local->sta_bss_lock);
  1275. list_move_tail(&bss->list, &local->sta_bss_list);
  1276. spin_unlock_bh(&local->sta_bss_lock);
  1277. #endif
  1278. }
  1279. if (bss->probe_resp && beacon) {
  1280. /* Do not allow beacon to override data from Probe Response. */
  1281. return;
  1282. }
  1283. bss->beacon_int = le_to_host16(mgmt->u.beacon.beacon_int);
  1284. bss->capability = le_to_host16(mgmt->u.beacon.capab_info);
  1285. if (bss->ie == NULL || bss->ie_len < ie_len) {
  1286. os_free(bss->ie);
  1287. bss->ie = os_malloc(ie_len);
  1288. }
  1289. if (bss->ie) {
  1290. os_memcpy(bss->ie, ie_pos, ie_len);
  1291. bss->ie_len = ie_len;
  1292. }
  1293. if (elems.ssid && elems.ssid_len <= MAX_SSID_LEN) {
  1294. os_memcpy(bss->ssid, elems.ssid, elems.ssid_len);
  1295. bss->ssid_len = elems.ssid_len;
  1296. }
  1297. bss->supp_rates_len = 0;
  1298. if (elems.supp_rates) {
  1299. clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
  1300. if (clen > elems.supp_rates_len)
  1301. clen = elems.supp_rates_len;
  1302. os_memcpy(&bss->supp_rates[bss->supp_rates_len],
  1303. elems.supp_rates, clen);
  1304. bss->supp_rates_len += clen;
  1305. }
  1306. if (elems.ext_supp_rates) {
  1307. clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
  1308. if (clen > elems.ext_supp_rates_len)
  1309. clen = elems.ext_supp_rates_len;
  1310. os_memcpy(&bss->supp_rates[bss->supp_rates_len],
  1311. elems.ext_supp_rates, clen);
  1312. bss->supp_rates_len += clen;
  1313. }
  1314. if (elems.wpa_ie &&
  1315. (bss->wpa_ie == NULL || bss->wpa_ie_len != elems.wpa_ie_len ||
  1316. os_memcmp(bss->wpa_ie, elems.wpa_ie, elems.wpa_ie_len))) {
  1317. os_free(bss->wpa_ie);
  1318. bss->wpa_ie = os_malloc(elems.wpa_ie_len + 2);
  1319. if (bss->wpa_ie) {
  1320. os_memcpy(bss->wpa_ie, elems.wpa_ie - 2,
  1321. elems.wpa_ie_len + 2);
  1322. bss->wpa_ie_len = elems.wpa_ie_len + 2;
  1323. } else
  1324. bss->wpa_ie_len = 0;
  1325. } else if (!elems.wpa_ie && bss->wpa_ie) {
  1326. os_free(bss->wpa_ie);
  1327. bss->wpa_ie = NULL;
  1328. bss->wpa_ie_len = 0;
  1329. }
  1330. if (elems.rsn_ie &&
  1331. (bss->rsn_ie == NULL || bss->rsn_ie_len != elems.rsn_ie_len ||
  1332. os_memcmp(bss->rsn_ie, elems.rsn_ie, elems.rsn_ie_len))) {
  1333. os_free(bss->rsn_ie);
  1334. bss->rsn_ie = os_malloc(elems.rsn_ie_len + 2);
  1335. if (bss->rsn_ie) {
  1336. os_memcpy(bss->rsn_ie, elems.rsn_ie - 2,
  1337. elems.rsn_ie_len + 2);
  1338. bss->rsn_ie_len = elems.rsn_ie_len + 2;
  1339. } else
  1340. bss->rsn_ie_len = 0;
  1341. } else if (!elems.rsn_ie && bss->rsn_ie) {
  1342. os_free(bss->rsn_ie);
  1343. bss->rsn_ie = NULL;
  1344. bss->rsn_ie_len = 0;
  1345. }
  1346. if (elems.wmm &&
  1347. (bss->wmm_ie == NULL || bss->wmm_ie_len != elems.wmm_len ||
  1348. os_memcmp(bss->wmm_ie, elems.wmm, elems.wmm_len))) {
  1349. os_free(bss->wmm_ie);
  1350. bss->wmm_ie = os_malloc(elems.wmm_len + 2);
  1351. if (bss->wmm_ie) {
  1352. os_memcpy(bss->wmm_ie, elems.wmm - 2,
  1353. elems.wmm_len + 2);
  1354. bss->wmm_ie_len = elems.wmm_len + 2;
  1355. } else
  1356. bss->wmm_ie_len = 0;
  1357. } else if (!elems.wmm && bss->wmm_ie) {
  1358. os_free(bss->wmm_ie);
  1359. bss->wmm_ie = NULL;
  1360. bss->wmm_ie_len = 0;
  1361. }
  1362. #ifdef CONFIG_IEEE80211R
  1363. if (elems.mdie &&
  1364. (bss->mdie == NULL || bss->mdie_len != elems.mdie_len ||
  1365. os_memcmp(bss->mdie, elems.mdie, elems.mdie_len))) {
  1366. os_free(bss->mdie);
  1367. bss->mdie = os_malloc(elems.mdie_len + 2);
  1368. if (bss->mdie) {
  1369. os_memcpy(bss->mdie, elems.mdie - 2,
  1370. elems.mdie_len + 2);
  1371. bss->mdie_len = elems.mdie_len + 2;
  1372. } else
  1373. bss->mdie_len = 0;
  1374. } else if (!elems.mdie && bss->mdie) {
  1375. os_free(bss->mdie);
  1376. bss->mdie = NULL;
  1377. bss->mdie_len = 0;
  1378. }
  1379. #endif /* CONFIG_IEEE80211R */
  1380. bss->hw_mode = wpa_s->mlme.phymode;
  1381. bss->channel = channel;
  1382. bss->freq = wpa_s->mlme.freq;
  1383. if (channel != wpa_s->mlme.channel &&
  1384. (wpa_s->mlme.phymode == HOSTAPD_MODE_IEEE80211G ||
  1385. wpa_s->mlme.phymode == HOSTAPD_MODE_IEEE80211B) &&
  1386. channel >= 1 && channel <= 14) {
  1387. static const int freq_list[] = {
  1388. 2412, 2417, 2422, 2427, 2432, 2437, 2442,
  1389. 2447, 2452, 2457, 2462, 2467, 2472, 2484
  1390. };
  1391. /* IEEE 802.11g/b mode can receive packets from neighboring
  1392. * channels, so map the channel into frequency. */
  1393. bss->freq = freq_list[channel - 1];
  1394. }
  1395. bss->timestamp = timestamp;
  1396. os_get_time(&bss->last_update);
  1397. bss->rssi = rx_status->ssi;
  1398. if (!beacon)
  1399. bss->probe_resp++;
  1400. }
  1401. static void ieee80211_rx_mgmt_probe_resp(struct wpa_supplicant *wpa_s,
  1402. struct ieee80211_mgmt *mgmt,
  1403. size_t len,
  1404. struct ieee80211_rx_status *rx_status)
  1405. {
  1406. ieee80211_bss_info(wpa_s, mgmt, len, rx_status, 0);
  1407. }
  1408. static void ieee80211_rx_mgmt_beacon(struct wpa_supplicant *wpa_s,
  1409. struct ieee80211_mgmt *mgmt,
  1410. size_t len,
  1411. struct ieee80211_rx_status *rx_status)
  1412. {
  1413. int use_protection;
  1414. size_t baselen;
  1415. struct ieee802_11_elems elems;
  1416. ieee80211_bss_info(wpa_s, mgmt, len, rx_status, 1);
  1417. if (!wpa_s->mlme.associated ||
  1418. os_memcmp(wpa_s->bssid, mgmt->bssid, ETH_ALEN) != 0)
  1419. return;
  1420. /* Process beacon from the current BSS */
  1421. baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
  1422. if (baselen > len)
  1423. return;
  1424. if (ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen,
  1425. &elems, 0) == ParseFailed)
  1426. return;
  1427. use_protection = 0;
  1428. if (elems.erp_info && elems.erp_info_len >= 1) {
  1429. use_protection =
  1430. (elems.erp_info[0] & ERP_INFO_USE_PROTECTION) != 0;
  1431. }
  1432. if (use_protection != !!wpa_s->mlme.use_protection) {
  1433. wpa_printf(MSG_DEBUG, "MLME: CTS protection %s (BSSID=" MACSTR
  1434. ")",
  1435. use_protection ? "enabled" : "disabled",
  1436. MAC2STR(wpa_s->bssid));
  1437. wpa_s->mlme.use_protection = use_protection ? 1 : 0;
  1438. wpa_s->mlme.cts_protect_erp_frames = use_protection;
  1439. }
  1440. if (elems.wmm && wpa_s->mlme.wmm_enabled) {
  1441. ieee80211_sta_wmm_params(wpa_s, elems.wmm,
  1442. elems.wmm_len);
  1443. }
  1444. }
  1445. static void ieee80211_rx_mgmt_probe_req(struct wpa_supplicant *wpa_s,
  1446. struct ieee80211_mgmt *mgmt,
  1447. size_t len,
  1448. struct ieee80211_rx_status *rx_status)
  1449. {
  1450. int tx_last_beacon, adhoc;
  1451. #if 0 /* FIX */
  1452. struct ieee80211_mgmt *resp;
  1453. #endif
  1454. u8 *pos, *end;
  1455. struct wpa_ssid *ssid = wpa_s->current_ssid;
  1456. adhoc = ssid && ssid->mode == 1;
  1457. if (!adhoc || wpa_s->mlme.state != IEEE80211_IBSS_JOINED ||
  1458. len < 24 + 2 || wpa_s->mlme.probe_resp == NULL)
  1459. return;
  1460. #if 0 /* FIX */
  1461. if (local->hw->tx_last_beacon)
  1462. tx_last_beacon = local->hw->tx_last_beacon(local->mdev);
  1463. else
  1464. #endif
  1465. tx_last_beacon = 1;
  1466. #ifdef IEEE80211_IBSS_DEBUG
  1467. wpa_printf(MSG_DEBUG, "MLME: RX ProbeReq SA=" MACSTR " DA=" MACSTR
  1468. " BSSID=" MACSTR " (tx_last_beacon=%d)",
  1469. MAC2STR(mgmt->sa), MAC2STR(mgmt->da),
  1470. MAC2STR(mgmt->bssid), tx_last_beacon);
  1471. #endif /* IEEE80211_IBSS_DEBUG */
  1472. if (!tx_last_beacon)
  1473. return;
  1474. if (os_memcmp(mgmt->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
  1475. os_memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0)
  1476. return;
  1477. end = ((u8 *) mgmt) + len;
  1478. pos = mgmt->u.probe_req.variable;
  1479. if (pos[0] != WLAN_EID_SSID ||
  1480. pos + 2 + pos[1] > end) {
  1481. wpa_printf(MSG_DEBUG, "MLME: Invalid SSID IE in ProbeReq from "
  1482. MACSTR, MAC2STR(mgmt->sa));
  1483. return;
  1484. }
  1485. if (pos[1] != 0 &&
  1486. (pos[1] != wpa_s->mlme.ssid_len ||
  1487. os_memcmp(pos + 2, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len) != 0))
  1488. {
  1489. /* Ignore ProbeReq for foreign SSID */
  1490. return;
  1491. }
  1492. #if 0 /* FIX */
  1493. /* Reply with ProbeResp */
  1494. skb = skb_copy(wpa_s->mlme.probe_resp, GFP_ATOMIC);
  1495. if (skb == NULL)
  1496. return;
  1497. resp = (struct ieee80211_mgmt *) skb->data;
  1498. os_memcpy(resp->da, mgmt->sa, ETH_ALEN);
  1499. #ifdef IEEE80211_IBSS_DEBUG
  1500. wpa_printf(MSG_DEBUG, "MLME: Sending ProbeResp to " MACSTR,
  1501. MAC2STR(resp->da));
  1502. #endif /* IEEE80211_IBSS_DEBUG */
  1503. ieee80211_sta_tx(wpa_s, skb, 0, 1);
  1504. #endif
  1505. }
  1506. #ifdef CONFIG_IEEE80211R
  1507. static void ieee80211_rx_mgmt_ft_action(struct wpa_supplicant *wpa_s,
  1508. struct ieee80211_mgmt *mgmt,
  1509. size_t len,
  1510. struct ieee80211_rx_status *rx_status)
  1511. {
  1512. union wpa_event_data data;
  1513. u16 status;
  1514. u8 *sta_addr, *target_ap_addr;
  1515. if (len < 24 + 1 + sizeof(mgmt->u.action.u.ft_action_resp)) {
  1516. wpa_printf(MSG_DEBUG, "MLME: Too short FT Action frame");
  1517. return;
  1518. }
  1519. /*
  1520. * Only FT Action Response is needed for now since reservation
  1521. * protocol is not supported.
  1522. */
  1523. if (mgmt->u.action.u.ft_action_resp.action != 2) {
  1524. wpa_printf(MSG_DEBUG, "MLME: Unexpected FT Action %d",
  1525. mgmt->u.action.u.ft_action_resp.action);
  1526. return;
  1527. }
  1528. status = le_to_host16(mgmt->u.action.u.ft_action_resp.status_code);
  1529. sta_addr = mgmt->u.action.u.ft_action_resp.sta_addr;
  1530. target_ap_addr = mgmt->u.action.u.ft_action_resp.target_ap_addr;
  1531. wpa_printf(MSG_DEBUG, "MLME: Received FT Action Response: STA " MACSTR
  1532. " TargetAP " MACSTR " Status Code %d",
  1533. MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
  1534. if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
  1535. wpa_printf(MSG_DEBUG, "MLME: Foreign STA Address " MACSTR
  1536. " in FT Action Response", MAC2STR(sta_addr));
  1537. return;
  1538. }
  1539. if (status) {
  1540. wpa_printf(MSG_DEBUG, "MLME: FT Action Response indicates "
  1541. "failure (status code %d)", status);
  1542. /* TODO: report error to FT code(?) */
  1543. return;
  1544. }
  1545. os_memset(&data, 0, sizeof(data));
  1546. data.ft_ies.ies = mgmt->u.action.u.ft_action_resp.variable;
  1547. data.ft_ies.ies_len = len - (mgmt->u.action.u.ft_action_resp.variable -
  1548. (u8 *) mgmt);
  1549. data.ft_ies.ft_action = 1;
  1550. os_memcpy(data.ft_ies.target_ap, target_ap_addr, ETH_ALEN);
  1551. wpa_supplicant_event(wpa_s, EVENT_FT_RESPONSE, &data);
  1552. /* TODO: should only re-associate, if EVENT_FT_RESPONSE was processed
  1553. * successfully */
  1554. wpa_s->mlme.prev_bssid_set = 1;
  1555. wpa_s->mlme.auth_alg = WLAN_AUTH_FT;
  1556. os_memcpy(wpa_s->mlme.prev_bssid, wpa_s->bssid, ETH_ALEN);
  1557. os_memcpy(wpa_s->bssid, target_ap_addr, ETH_ALEN);
  1558. ieee80211_associate(wpa_s);
  1559. }
  1560. #endif /* CONFIG_IEEE80211R */
  1561. #ifdef CONFIG_IEEE80211W
  1562. /* MLME-SAQuery.response */
  1563. static int ieee80211_sta_send_sa_query_resp(struct wpa_supplicant *wpa_s,
  1564. const u8 *addr, const u8 *trans_id)
  1565. {
  1566. struct ieee80211_mgmt *mgmt;
  1567. int res;
  1568. size_t len;
  1569. mgmt = os_zalloc(sizeof(*mgmt));
  1570. if (mgmt == NULL) {
  1571. wpa_printf(MSG_DEBUG, "MLME: Failed to allocate buffer for "
  1572. "SA Query action frame");
  1573. return -1;
  1574. }
  1575. len = 24;
  1576. os_memcpy(mgmt->da, addr, ETH_ALEN);
  1577. os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
  1578. os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
  1579. mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  1580. WLAN_FC_STYPE_ACTION);
  1581. mgmt->u.action.category = WLAN_ACTION_SA_QUERY;
  1582. mgmt->u.action.u.sa_query_resp.action = WLAN_SA_QUERY_RESPONSE;
  1583. os_memcpy(mgmt->u.action.u.sa_query_resp.trans_id, trans_id,
  1584. WLAN_SA_QUERY_TR_ID_LEN);
  1585. len += 1 + sizeof(mgmt->u.action.u.sa_query_resp);
  1586. res = ieee80211_sta_tx(wpa_s, (u8 *) mgmt, len);
  1587. os_free(mgmt);
  1588. return res;
  1589. }
  1590. static void ieee80211_rx_mgmt_sa_query_action(
  1591. struct wpa_supplicant *wpa_s, struct ieee80211_mgmt *mgmt, size_t len,
  1592. struct ieee80211_rx_status *rx_status)
  1593. {
  1594. if (len < 24 + 1 + sizeof(mgmt->u.action.u.sa_query_req)) {
  1595. wpa_printf(MSG_DEBUG, "MLME: Too short SA Query Action frame");
  1596. return;
  1597. }
  1598. if (mgmt->u.action.u.sa_query_req.action != WLAN_SA_QUERY_REQUEST) {
  1599. wpa_printf(MSG_DEBUG, "MLME: Unexpected SA Query Action %d",
  1600. mgmt->u.action.u.sa_query_req.action);
  1601. return;
  1602. }
  1603. if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) != 0) {
  1604. wpa_printf(MSG_DEBUG, "MLME: Ignore SA Query from unknown "
  1605. "source " MACSTR, MAC2STR(mgmt->sa));
  1606. return;
  1607. }
  1608. if (wpa_s->mlme.state == IEEE80211_ASSOCIATE) {
  1609. wpa_printf(MSG_DEBUG, "MLME: Ignore SA query request during "
  1610. "association process");
  1611. return;
  1612. }
  1613. wpa_printf(MSG_DEBUG, "MLME: Replying to SA Query request");
  1614. ieee80211_sta_send_sa_query_resp(wpa_s, mgmt->sa, mgmt->u.action.u.
  1615. sa_query_req.trans_id);
  1616. }
  1617. #endif /* CONFIG_IEEE80211W */
  1618. static void dump_tspec(struct wmm_tspec_element *tspec)
  1619. {
  1620. int up, psb, dir, tid;
  1621. u16 val;
  1622. up = (tspec->ts_info[1] >> 3) & 0x07;
  1623. psb = (tspec->ts_info[1] >> 2) & 0x01;
  1624. dir = (tspec->ts_info[0] >> 5) & 0x03;
  1625. tid = (tspec->ts_info[0] >> 1) & 0x0f;
  1626. wpa_printf(MSG_DEBUG, "WMM: TS Info: UP=%d PSB=%d Direction=%d TID=%d",
  1627. up, psb, dir, tid);
  1628. val = le_to_host16(tspec->nominal_msdu_size);
  1629. wpa_printf(MSG_DEBUG, "WMM: Nominal MSDU Size: %d%s",
  1630. val & 0x7fff, val & 0x8000 ? " (fixed)" : "");
  1631. wpa_printf(MSG_DEBUG, "WMM: Mean Data Rate: %u bps",
  1632. le_to_host32(tspec->mean_data_rate));
  1633. wpa_printf(MSG_DEBUG, "WMM: Minimum PHY Rate: %u bps",
  1634. le_to_host32(tspec->minimum_phy_rate));
  1635. val = le_to_host16(tspec->surplus_bandwidth_allowance);
  1636. wpa_printf(MSG_DEBUG, "WMM: Surplus Bandwidth Allowance: %u.%04u",
  1637. val >> 13, 10000 * (val & 0x1fff) / 0x2000);
  1638. val = le_to_host16(tspec->medium_time);
  1639. wpa_printf(MSG_DEBUG, "WMM: Medium Time: %u (= %u usec/sec)",
  1640. val, 32 * val);
  1641. }
  1642. static int is_wmm_tspec(const u8 *ie, size_t len)
  1643. {
  1644. const struct wmm_tspec_element *tspec;
  1645. if (len < sizeof(*tspec))
  1646. return 0;
  1647. tspec = (const struct wmm_tspec_element *) ie;
  1648. if (tspec->eid != WLAN_EID_VENDOR_SPECIFIC ||
  1649. tspec->length < sizeof(*tspec) - 2 ||
  1650. tspec->oui[0] != 0x00 || tspec->oui[1] != 0x50 ||
  1651. tspec->oui[2] != 0xf2 || tspec->oui_type != 2 ||
  1652. tspec->oui_subtype != 2 || tspec->version != 1)
  1653. return 0;
  1654. return 1;
  1655. }
  1656. static void ieee80211_rx_addts_resp(
  1657. struct wpa_supplicant *wpa_s, struct ieee80211_mgmt *mgmt, size_t len,
  1658. size_t var_len)
  1659. {
  1660. struct wmm_tspec_element *tspec;
  1661. wpa_printf(MSG_DEBUG, "WMM: Received ADDTS Response");
  1662. wpa_hexdump(MSG_MSGDUMP, "WMM: ADDTS Response IE(s)",
  1663. mgmt->u.action.u.wmm_action.variable, var_len);
  1664. if (!is_wmm_tspec(mgmt->u.action.u.wmm_action.variable, var_len))
  1665. return;
  1666. tspec = (struct wmm_tspec_element *)
  1667. mgmt->u.action.u.wmm_action.variable;
  1668. dump_tspec(tspec);
  1669. }
  1670. static void ieee80211_rx_delts(
  1671. struct wpa_supplicant *wpa_s, struct ieee80211_mgmt *mgmt, size_t len,
  1672. size_t var_len)
  1673. {
  1674. struct wmm_tspec_element *tspec;
  1675. wpa_printf(MSG_DEBUG, "WMM: Received DELTS");
  1676. wpa_hexdump(MSG_MSGDUMP, "WMM: DELTS IE(s)",
  1677. mgmt->u.action.u.wmm_action.variable, var_len);
  1678. if (!is_wmm_tspec(mgmt->u.action.u.wmm_action.variable, var_len))
  1679. return;
  1680. tspec = (struct wmm_tspec_element *)
  1681. mgmt->u.action.u.wmm_action.variable;
  1682. dump_tspec(tspec);
  1683. }
  1684. static void ieee80211_rx_mgmt_wmm_action(
  1685. struct wpa_supplicant *wpa_s, struct ieee80211_mgmt *mgmt, size_t len,
  1686. struct ieee80211_rx_status *rx_status)
  1687. {
  1688. size_t alen;
  1689. alen = mgmt->u.action.u.wmm_action.variable - (u8 *) mgmt;
  1690. if (len < alen) {
  1691. wpa_printf(MSG_DEBUG, "WMM: Received Action frame too short");
  1692. return;
  1693. }
  1694. wpa_printf(MSG_DEBUG, "WMM: Received Action frame: Action Code %d, "
  1695. "Dialog Token %d, Status Code %d",
  1696. mgmt->u.action.u.wmm_action.action_code,
  1697. mgmt->u.action.u.wmm_action.dialog_token,
  1698. mgmt->u.action.u.wmm_action.status_code);
  1699. switch (mgmt->u.action.u.wmm_action.action_code) {
  1700. case WMM_ACTION_CODE_ADDTS_RESP:
  1701. ieee80211_rx_addts_resp(wpa_s, mgmt, len, len - alen);
  1702. break;
  1703. case WMM_ACTION_CODE_DELTS:
  1704. ieee80211_rx_delts(wpa_s, mgmt, len, len - alen);
  1705. break;
  1706. default:
  1707. wpa_printf(MSG_DEBUG, "WMM: Unsupported Action Code %d",
  1708. mgmt->u.action.u.wmm_action.action_code);
  1709. break;
  1710. }
  1711. }
  1712. static void ieee80211_rx_mgmt_action(struct wpa_supplicant *wpa_s,
  1713. struct ieee80211_mgmt *mgmt,
  1714. size_t len,
  1715. struct ieee80211_rx_status *rx_status)
  1716. {
  1717. wpa_printf(MSG_DEBUG, "MLME: received Action frame");
  1718. if (len < 25)
  1719. return;
  1720. switch (mgmt->u.action.category) {
  1721. #ifdef CONFIG_IEEE80211R
  1722. case WLAN_ACTION_FT:
  1723. ieee80211_rx_mgmt_ft_action(wpa_s, mgmt, len, rx_status);
  1724. break;
  1725. #endif /* CONFIG_IEEE80211R */
  1726. #ifdef CONFIG_IEEE80211W
  1727. case WLAN_ACTION_SA_QUERY:
  1728. ieee80211_rx_mgmt_sa_query_action(wpa_s, mgmt, len, rx_status);
  1729. break;
  1730. #endif /* CONFIG_IEEE80211W */
  1731. case WLAN_ACTION_WMM:
  1732. ieee80211_rx_mgmt_wmm_action(wpa_s, mgmt, len, rx_status);
  1733. break;
  1734. default:
  1735. wpa_printf(MSG_DEBUG, "MLME: unknown Action Category %d",
  1736. mgmt->u.action.category);
  1737. break;
  1738. }
  1739. }
  1740. static void ieee80211_sta_rx_mgmt(struct wpa_supplicant *wpa_s,
  1741. const u8 *buf, size_t len,
  1742. struct ieee80211_rx_status *rx_status)
  1743. {
  1744. struct ieee80211_mgmt *mgmt;
  1745. u16 fc;
  1746. if (len < 24)
  1747. return;
  1748. mgmt = (struct ieee80211_mgmt *) buf;
  1749. fc = le_to_host16(mgmt->frame_control);
  1750. switch (WLAN_FC_GET_STYPE(fc)) {
  1751. case WLAN_FC_STYPE_PROBE_REQ:
  1752. ieee80211_rx_mgmt_probe_req(wpa_s, mgmt, len, rx_status);
  1753. break;
  1754. case WLAN_FC_STYPE_PROBE_RESP:
  1755. ieee80211_rx_mgmt_probe_resp(wpa_s, mgmt, len, rx_status);
  1756. break;
  1757. case WLAN_FC_STYPE_BEACON:
  1758. ieee80211_rx_mgmt_beacon(wpa_s, mgmt, len, rx_status);
  1759. break;
  1760. case WLAN_FC_STYPE_AUTH:
  1761. ieee80211_rx_mgmt_auth(wpa_s, mgmt, len, rx_status);
  1762. break;
  1763. case WLAN_FC_STYPE_ASSOC_RESP:
  1764. ieee80211_rx_mgmt_assoc_resp(wpa_s, mgmt, len, rx_status, 0);
  1765. break;
  1766. case WLAN_FC_STYPE_REASSOC_RESP:
  1767. ieee80211_rx_mgmt_assoc_resp(wpa_s, mgmt, len, rx_status, 1);
  1768. break;
  1769. case WLAN_FC_STYPE_DEAUTH:
  1770. ieee80211_rx_mgmt_deauth(wpa_s, mgmt, len, rx_status);
  1771. break;
  1772. case WLAN_FC_STYPE_DISASSOC:
  1773. ieee80211_rx_mgmt_disassoc(wpa_s, mgmt, len, rx_status);
  1774. break;
  1775. case WLAN_FC_STYPE_ACTION:
  1776. ieee80211_rx_mgmt_action(wpa_s, mgmt, len, rx_status);
  1777. break;
  1778. default:
  1779. wpa_printf(MSG_DEBUG, "MLME: received unknown management "
  1780. "frame - stype=%d", WLAN_FC_GET_STYPE(fc));
  1781. break;
  1782. }
  1783. }
  1784. static void ieee80211_sta_rx_scan(struct wpa_supplicant *wpa_s,
  1785. const u8 *buf, size_t len,
  1786. struct ieee80211_rx_status *rx_status)
  1787. {
  1788. struct ieee80211_mgmt *mgmt;
  1789. u16 fc;
  1790. if (len < 24)
  1791. return;
  1792. mgmt = (struct ieee80211_mgmt *) buf;
  1793. fc = le_to_host16(mgmt->frame_control);
  1794. if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT) {
  1795. if (WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) {
  1796. ieee80211_rx_mgmt_probe_resp(wpa_s, mgmt,
  1797. len, rx_status);
  1798. } else if (WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) {
  1799. ieee80211_rx_mgmt_beacon(wpa_s, mgmt, len, rx_status);
  1800. }
  1801. }
  1802. }
  1803. static int ieee80211_sta_active_ibss(struct wpa_supplicant *wpa_s)
  1804. {
  1805. int active = 0;
  1806. #if 0 /* FIX */
  1807. list_for_each(ptr, &local->sta_list) {
  1808. sta = list_entry(ptr, struct sta_info, list);
  1809. if (sta->dev == dev &&
  1810. time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL,
  1811. jiffies)) {
  1812. active++;
  1813. break;
  1814. }
  1815. }
  1816. #endif
  1817. return active;
  1818. }
  1819. static void ieee80211_sta_expire(struct wpa_supplicant *wpa_s)
  1820. {
  1821. #if 0 /* FIX */
  1822. list_for_each_safe(ptr, n, &local->sta_list) {
  1823. sta = list_entry(ptr, struct sta_info, list);
  1824. if (time_after(jiffies, sta->last_rx +
  1825. IEEE80211_IBSS_INACTIVITY_LIMIT)) {
  1826. wpa_printf(MSG_DEBUG, "MLME: expiring inactive STA "
  1827. MACSTR, MAC2STR(sta->addr));
  1828. sta_info_free(local, sta, 1);
  1829. }
  1830. }
  1831. #endif
  1832. }
  1833. static void ieee80211_sta_merge_ibss(struct wpa_supplicant *wpa_s)
  1834. {
  1835. ieee80211_reschedule_timer(wpa_s, IEEE80211_IBSS_MERGE_INTERVAL);
  1836. ieee80211_sta_expire(wpa_s);
  1837. if (ieee80211_sta_active_ibss(wpa_s))
  1838. return;
  1839. wpa_printf(MSG_DEBUG, "MLME: No active IBSS STAs - trying to scan for "
  1840. "other IBSS networks with same SSID (merge)");
  1841. ieee80211_sta_req_scan(wpa_s, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len);
  1842. }
  1843. static void ieee80211_sta_timer(void *eloop_ctx, void *timeout_ctx)
  1844. {
  1845. struct wpa_supplicant *wpa_s = eloop_ctx;
  1846. switch (wpa_s->mlme.state) {
  1847. case IEEE80211_DISABLED:
  1848. break;
  1849. case IEEE80211_AUTHENTICATE:
  1850. ieee80211_authenticate(wpa_s);
  1851. break;
  1852. case IEEE80211_ASSOCIATE:
  1853. ieee80211_associate(wpa_s);
  1854. break;
  1855. case IEEE80211_ASSOCIATED:
  1856. ieee80211_associated(wpa_s);
  1857. break;
  1858. case IEEE80211_IBSS_SEARCH:
  1859. ieee80211_sta_find_ibss(wpa_s);
  1860. break;
  1861. case IEEE80211_IBSS_JOINED:
  1862. ieee80211_sta_merge_ibss(wpa_s);
  1863. break;
  1864. default:
  1865. wpa_printf(MSG_DEBUG, "ieee80211_sta_timer: Unknown state %d",
  1866. wpa_s->mlme.state);
  1867. break;
  1868. }
  1869. if (ieee80211_privacy_mismatch(wpa_s)) {
  1870. wpa_printf(MSG_DEBUG, "MLME: privacy configuration mismatch "
  1871. "and mixed-cell disabled - disassociate");
  1872. ieee80211_send_disassoc(wpa_s, WLAN_REASON_UNSPECIFIED);
  1873. ieee80211_set_associated(wpa_s, 0);
  1874. }
  1875. }
  1876. static void ieee80211_sta_new_auth(struct wpa_supplicant *wpa_s)
  1877. {
  1878. struct wpa_ssid *ssid = wpa_s->current_ssid;
  1879. if (ssid && ssid->mode != 0)
  1880. return;
  1881. #if 0 /* FIX */
  1882. if (local->hw->reset_tsf) {
  1883. /* Reset own TSF to allow time synchronization work. */
  1884. local->hw->reset_tsf(local->mdev);
  1885. }
  1886. #endif
  1887. wpa_s->mlme.wmm_last_param_set = -1; /* allow any WMM update */
  1888. if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_OPEN)
  1889. wpa_s->mlme.auth_alg = WLAN_AUTH_OPEN;
  1890. else if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
  1891. wpa_s->mlme.auth_alg = WLAN_AUTH_SHARED_KEY;
  1892. else if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_LEAP)
  1893. wpa_s->mlme.auth_alg = WLAN_AUTH_LEAP;
  1894. else
  1895. wpa_s->mlme.auth_alg = WLAN_AUTH_OPEN;
  1896. wpa_printf(MSG_DEBUG, "MLME: Initial auth_alg=%d",
  1897. wpa_s->mlme.auth_alg);
  1898. wpa_s->mlme.auth_transaction = -1;
  1899. wpa_s->mlme.auth_tries = wpa_s->mlme.assoc_tries = 0;
  1900. ieee80211_authenticate(wpa_s);
  1901. }
  1902. static int ieee80211_ibss_allowed(struct wpa_supplicant *wpa_s)
  1903. {
  1904. #if 0 /* FIX */
  1905. int m, c;
  1906. for (m = 0; m < local->hw->num_modes; m++) {
  1907. struct ieee80211_hw_modes *mode = &local->hw->modes[m];
  1908. if (mode->mode != local->conf.phymode)
  1909. continue;
  1910. for (c = 0; c < mode->num_channels; c++) {
  1911. struct ieee80211_channel *chan = &mode->channels[c];
  1912. if (chan->flag & IEEE80211_CHAN_W_SCAN &&
  1913. chan->chan == local->conf.channel) {
  1914. if (chan->flag & IEEE80211_CHAN_W_IBSS)
  1915. return 1;
  1916. break;
  1917. }
  1918. }
  1919. }
  1920. #endif
  1921. return 0;
  1922. }
  1923. static int ieee80211_sta_join_ibss(struct wpa_supplicant *wpa_s,
  1924. struct ieee80211_sta_bss *bss)
  1925. {
  1926. int res = 0, rates, done = 0, bssid_changed;
  1927. struct ieee80211_mgmt *mgmt;
  1928. #if 0 /* FIX */
  1929. struct ieee80211_tx_control control;
  1930. struct ieee80211_rate *rate;
  1931. struct rate_control_extra extra;
  1932. #endif
  1933. u8 *pos, *buf;
  1934. size_t len;
  1935. /* Remove possible STA entries from other IBSS networks. */
  1936. #if 0 /* FIX */
  1937. sta_info_flush(local, NULL);
  1938. if (local->hw->reset_tsf) {
  1939. /* Reset own TSF to allow time synchronization work. */
  1940. local->hw->reset_tsf(local->mdev);
  1941. }
  1942. #endif
  1943. bssid_changed = os_memcmp(wpa_s->bssid, bss->bssid, ETH_ALEN);
  1944. os_memcpy(wpa_s->bssid, bss->bssid, ETH_ALEN);
  1945. if (bssid_changed)
  1946. wpas_notify_bssid_changed(wpa_s);
  1947. #if 0 /* FIX */
  1948. local->conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
  1949. sdata->drop_unencrypted = bss->capability &
  1950. host_to_le16(WLAN_CAPABILITY_PRIVACY) ? 1 : 0;
  1951. #endif
  1952. #if 0 /* FIX */
  1953. os_memset(&rq, 0, sizeof(rq));
  1954. rq.m = bss->freq * 100000;
  1955. rq.e = 1;
  1956. res = ieee80211_ioctl_siwfreq(wpa_s, NULL, &rq, NULL);
  1957. #endif
  1958. if (!ieee80211_ibss_allowed(wpa_s)) {
  1959. #if 0 /* FIX */
  1960. wpa_printf(MSG_DEBUG, "MLME: IBSS not allowed on channel %d "
  1961. "(%d MHz)", local->conf.channel,
  1962. local->conf.freq);
  1963. #endif
  1964. return -1;
  1965. }
  1966. /* Set beacon template based on scan results */
  1967. buf = os_malloc(400);
  1968. len = 0;
  1969. do {
  1970. if (buf == NULL)
  1971. break;
  1972. mgmt = (struct ieee80211_mgmt *) buf;
  1973. len += 24 + sizeof(mgmt->u.beacon);
  1974. os_memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
  1975. mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  1976. WLAN_FC_STYPE_BEACON);
  1977. os_memset(mgmt->da, 0xff, ETH_ALEN);
  1978. os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
  1979. os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
  1980. #if 0 /* FIX */
  1981. mgmt->u.beacon.beacon_int =
  1982. host_to_le16(local->conf.beacon_int);
  1983. #endif
  1984. mgmt->u.beacon.capab_info = host_to_le16(bss->capability);
  1985. pos = buf + len;
  1986. len += 2 + wpa_s->mlme.ssid_len;
  1987. *pos++ = WLAN_EID_SSID;
  1988. *pos++ = wpa_s->mlme.ssid_len;
  1989. os_memcpy(pos, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len);
  1990. rates = bss->supp_rates_len;
  1991. if (rates > 8)
  1992. rates = 8;
  1993. pos = buf + len;
  1994. len += 2 + rates;
  1995. *pos++ = WLAN_EID_SUPP_RATES;
  1996. *pos++ = rates;
  1997. os_memcpy(pos, bss->supp_rates, rates);
  1998. pos = buf + len;
  1999. len += 2 + 1;
  2000. *pos++ = WLAN_EID_DS_PARAMS;
  2001. *pos++ = 1;
  2002. *pos++ = bss->channel;
  2003. pos = buf + len;
  2004. len += 2 + 2;
  2005. *pos++ = WLAN_EID_IBSS_PARAMS;
  2006. *pos++ = 2;
  2007. /* FIX: set ATIM window based on scan results */
  2008. *pos++ = 0;
  2009. *pos++ = 0;
  2010. if (bss->supp_rates_len > 8) {
  2011. rates = bss->supp_rates_len - 8;
  2012. pos = buf + len;
  2013. len += 2 + rates;
  2014. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  2015. *pos++ = rates;
  2016. os_memcpy(pos, &bss->supp_rates[8], rates);
  2017. }
  2018. #if 0 /* FIX */
  2019. os_memset(&control, 0, sizeof(control));
  2020. control.pkt_type = PKT_PROBE_RESP;
  2021. os_memset(&extra, 0, sizeof(extra));
  2022. extra.endidx = local->num_curr_rates;
  2023. rate = rate_control_get_rate(wpa_s, skb, &extra);
  2024. if (rate == NULL) {
  2025. wpa_printf(MSG_DEBUG, "MLME: Failed to determine TX "
  2026. "rate for IBSS beacon");
  2027. break;
  2028. }
  2029. control.tx_rate = (wpa_s->mlme.short_preamble &&
  2030. (rate->flags & IEEE80211_RATE_PREAMBLE2)) ?
  2031. rate->val2 : rate->val;
  2032. control.antenna_sel = local->conf.antenna_sel;
  2033. control.power_level = local->conf.power_level;
  2034. control.no_ack = 1;
  2035. control.retry_limit = 1;
  2036. control.rts_cts_duration = 0;
  2037. #endif
  2038. #if 0 /* FIX */
  2039. wpa_s->mlme.probe_resp = skb_copy(skb, GFP_ATOMIC);
  2040. if (wpa_s->mlme.probe_resp) {
  2041. mgmt = (struct ieee80211_mgmt *)
  2042. wpa_s->mlme.probe_resp->data;
  2043. mgmt->frame_control =
  2044. IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  2045. WLAN_FC_STYPE_PROBE_RESP);
  2046. } else {
  2047. wpa_printf(MSG_DEBUG, "MLME: Could not allocate "
  2048. "ProbeResp template for IBSS");
  2049. }
  2050. if (local->hw->beacon_update &&
  2051. local->hw->beacon_update(wpa_s, skb, &control) == 0) {
  2052. wpa_printf(MSG_DEBUG, "MLME: Configured IBSS beacon "
  2053. "template based on scan results");
  2054. skb = NULL;
  2055. }
  2056. rates = 0;
  2057. for (i = 0; i < bss->supp_rates_len; i++) {
  2058. int rate = (bss->supp_rates[i] & 0x7f) * 5;
  2059. if (local->conf.phymode == MODE_ATHEROS_TURBO)
  2060. rate *= 2;
  2061. for (j = 0; j < local->num_curr_rates; j++)
  2062. if (local->curr_rates[j] == rate)
  2063. rates |= BIT(j);
  2064. }
  2065. wpa_s->mlme.supp_rates_bits = rates;
  2066. #endif
  2067. done = 1;
  2068. } while (0);
  2069. os_free(buf);
  2070. if (!done) {
  2071. wpa_printf(MSG_DEBUG, "MLME: Failed to configure IBSS beacon "
  2072. "template");
  2073. }
  2074. wpa_s->mlme.state = IEEE80211_IBSS_JOINED;
  2075. ieee80211_reschedule_timer(wpa_s, IEEE80211_IBSS_MERGE_INTERVAL);
  2076. return res;
  2077. }
  2078. #if 0 /* FIX */
  2079. static int ieee80211_sta_create_ibss(struct wpa_supplicant *wpa_s)
  2080. {
  2081. struct ieee80211_sta_bss *bss;
  2082. u8 bssid[ETH_ALEN], *pos;
  2083. int i;
  2084. #if 0
  2085. /* Easier testing, use fixed BSSID. */
  2086. os_memset(bssid, 0xfe, ETH_ALEN);
  2087. #else
  2088. /* Generate random, not broadcast, locally administered BSSID. Mix in
  2089. * own MAC address to make sure that devices that do not have proper
  2090. * random number generator get different BSSID. */
  2091. os_get_random(bssid, ETH_ALEN);
  2092. for (i = 0; i < ETH_ALEN; i++)
  2093. bssid[i] ^= wpa_s->own_addr[i];
  2094. bssid[0] &= ~0x01;
  2095. bssid[0] |= 0x02;
  2096. #endif
  2097. wpa_printf(MSG_DEBUG, "MLME: Creating new IBSS network, BSSID "
  2098. MACSTR "", MAC2STR(bssid));
  2099. bss = ieee80211_bss_add(wpa_s, bssid);
  2100. if (bss == NULL)
  2101. return -ENOMEM;
  2102. #if 0 /* FIX */
  2103. if (local->conf.beacon_int == 0)
  2104. local->conf.beacon_int = 100;
  2105. bss->beacon_int = local->conf.beacon_int;
  2106. bss->hw_mode = local->conf.phymode;
  2107. bss->channel = local->conf.channel;
  2108. bss->freq = local->conf.freq;
  2109. #endif
  2110. os_get_time(&bss->last_update);
  2111. bss->capability = host_to_le16(WLAN_CAPABILITY_IBSS);
  2112. #if 0 /* FIX */
  2113. if (sdata->default_key) {
  2114. bss->capability |= host_to_le16(WLAN_CAPABILITY_PRIVACY);
  2115. } else
  2116. sdata->drop_unencrypted = 0;
  2117. bss->supp_rates_len = local->num_curr_rates;
  2118. #endif
  2119. pos = bss->supp_rates;
  2120. #if 0 /* FIX */
  2121. for (i = 0; i < local->num_curr_rates; i++) {
  2122. int rate = local->curr_rates[i];
  2123. if (local->conf.phymode == MODE_ATHEROS_TURBO)
  2124. rate /= 2;
  2125. *pos++ = (u8) (rate / 5);
  2126. }
  2127. #endif
  2128. return ieee80211_sta_join_ibss(wpa_s, bss);
  2129. }
  2130. #endif
  2131. static int ieee80211_sta_find_ibss(struct wpa_supplicant *wpa_s)
  2132. {
  2133. struct ieee80211_sta_bss *bss;
  2134. int found = 0;
  2135. u8 bssid[ETH_ALEN];
  2136. int active_ibss;
  2137. struct os_time now;
  2138. if (wpa_s->mlme.ssid_len == 0)
  2139. return -EINVAL;
  2140. active_ibss = ieee80211_sta_active_ibss(wpa_s);
  2141. #ifdef IEEE80211_IBSS_DEBUG
  2142. wpa_printf(MSG_DEBUG, "MLME: sta_find_ibss (active_ibss=%d)",
  2143. active_ibss);
  2144. #endif /* IEEE80211_IBSS_DEBUG */
  2145. for (bss = wpa_s->mlme.sta_bss_list; bss; bss = bss->next) {
  2146. if (wpa_s->mlme.ssid_len != bss->ssid_len ||
  2147. os_memcmp(wpa_s->mlme.ssid, bss->ssid, bss->ssid_len) != 0
  2148. || !(bss->capability & WLAN_CAPABILITY_IBSS))
  2149. continue;
  2150. #ifdef IEEE80211_IBSS_DEBUG
  2151. wpa_printf(MSG_DEBUG, " bssid=" MACSTR " found",
  2152. MAC2STR(bss->bssid));
  2153. #endif /* IEEE80211_IBSS_DEBUG */
  2154. os_memcpy(bssid, bss->bssid, ETH_ALEN);
  2155. found = 1;
  2156. if (active_ibss ||
  2157. os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)
  2158. break;
  2159. }
  2160. #ifdef IEEE80211_IBSS_DEBUG
  2161. wpa_printf(MSG_DEBUG, " sta_find_ibss: selected " MACSTR " current "
  2162. MACSTR, MAC2STR(bssid), MAC2STR(wpa_s->bssid));
  2163. #endif /* IEEE80211_IBSS_DEBUG */
  2164. if (found && os_memcmp(wpa_s->bssid, bssid, ETH_ALEN) != 0 &&
  2165. (bss = ieee80211_bss_get(wpa_s, bssid))) {
  2166. wpa_printf(MSG_DEBUG, "MLME: Selected IBSS BSSID " MACSTR
  2167. " based on configured SSID",
  2168. MAC2STR(bssid));
  2169. return ieee80211_sta_join_ibss(wpa_s, bss);
  2170. }
  2171. #ifdef IEEE80211_IBSS_DEBUG
  2172. wpa_printf(MSG_DEBUG, " did not try to join ibss");
  2173. #endif /* IEEE80211_IBSS_DEBUG */
  2174. /* Selected IBSS not found in current scan results - try to scan */
  2175. os_get_time(&now);
  2176. #if 0 /* FIX */
  2177. if (wpa_s->mlme.state == IEEE80211_IBSS_JOINED &&
  2178. !ieee80211_sta_active_ibss(wpa_s)) {
  2179. ieee80211_reschedule_timer(wpa_s,
  2180. IEEE80211_IBSS_MERGE_INTERVAL);
  2181. } else if (time_after(jiffies, wpa_s->mlme.last_scan_completed +
  2182. IEEE80211_SCAN_INTERVAL)) {
  2183. wpa_printf(MSG_DEBUG, "MLME: Trigger new scan to find an IBSS "
  2184. "to join");
  2185. return ieee80211_sta_req_scan(wpa_s->mlme.ssid,
  2186. wpa_s->mlme.ssid_len);
  2187. } else if (wpa_s->mlme.state != IEEE80211_IBSS_JOINED) {
  2188. int interval = IEEE80211_SCAN_INTERVAL;
  2189. if (time_after(jiffies, wpa_s->mlme.ibss_join_req +
  2190. IEEE80211_IBSS_JOIN_TIMEOUT)) {
  2191. if (wpa_s->mlme.create_ibss &&
  2192. ieee80211_ibss_allowed(wpa_s))
  2193. return ieee80211_sta_create_ibss(wpa_s);
  2194. if (wpa_s->mlme.create_ibss) {
  2195. wpa_printf(MSG_DEBUG, "MLME: IBSS not allowed "
  2196. "on the configured channel %d "
  2197. "(%d MHz)",
  2198. local->conf.channel,
  2199. local->conf.freq);
  2200. }
  2201. /* No IBSS found - decrease scan interval and continue
  2202. * scanning. */
  2203. interval = IEEE80211_SCAN_INTERVAL_SLOW;
  2204. }
  2205. wpa_s->mlme.state = IEEE80211_IBSS_SEARCH;
  2206. ieee80211_reschedule_timer(wpa_s, interval);
  2207. return 0;
  2208. }
  2209. #endif
  2210. return 0;
  2211. }
  2212. int ieee80211_sta_get_ssid(struct wpa_supplicant *wpa_s, u8 *ssid,
  2213. size_t *len)
  2214. {
  2215. os_memcpy(ssid, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len);
  2216. *len = wpa_s->mlme.ssid_len;
  2217. return 0;
  2218. }
  2219. int ieee80211_sta_associate(struct wpa_supplicant *wpa_s,
  2220. struct wpa_driver_associate_params *params)
  2221. {
  2222. struct ieee80211_sta_bss *bss;
  2223. int bssid_changed;
  2224. wpa_s->mlme.bssid_set = 0;
  2225. wpa_s->mlme.freq = params->freq;
  2226. if (params->bssid) {
  2227. bssid_changed = os_memcmp(wpa_s->bssid, params->bssid,
  2228. ETH_ALEN);
  2229. os_memcpy(wpa_s->bssid, params->bssid, ETH_ALEN);
  2230. if (bssid_changed)
  2231. wpas_notify_bssid_changed(wpa_s);
  2232. if (!is_zero_ether_addr(params->bssid))
  2233. wpa_s->mlme.bssid_set = 1;
  2234. bss = ieee80211_bss_get(wpa_s, wpa_s->bssid);
  2235. if (bss) {
  2236. wpa_s->mlme.phymode = bss->hw_mode;
  2237. wpa_s->mlme.channel = bss->channel;
  2238. wpa_s->mlme.freq = bss->freq;
  2239. }
  2240. }
  2241. #if 0 /* FIX */
  2242. /* TODO: This should always be done for IBSS, even if IEEE80211_QOS is
  2243. * not defined. */
  2244. if (local->hw->conf_tx) {
  2245. struct ieee80211_tx_queue_params qparam;
  2246. int i;
  2247. os_memset(&qparam, 0, sizeof(qparam));
  2248. /* TODO: are these ok defaults for all hw_modes? */
  2249. qparam.aifs = 2;
  2250. qparam.cw_min =
  2251. local->conf.phymode == MODE_IEEE80211B ? 31 : 15;
  2252. qparam.cw_max = 1023;
  2253. qparam.burst_time = 0;
  2254. for (i = IEEE80211_TX_QUEUE_DATA0; i < NUM_TX_DATA_QUEUES; i++)
  2255. {
  2256. local->hw->conf_tx(wpa_s, i + IEEE80211_TX_QUEUE_DATA0,
  2257. &qparam);
  2258. }
  2259. /* IBSS uses different parameters for Beacon sending */
  2260. qparam.cw_min++;
  2261. qparam.cw_min *= 2;
  2262. qparam.cw_min--;
  2263. local->hw->conf_tx(wpa_s, IEEE80211_TX_QUEUE_BEACON, &qparam);
  2264. }
  2265. #endif
  2266. if (wpa_s->mlme.ssid_len != params->ssid_len ||
  2267. os_memcmp(wpa_s->mlme.ssid, params->ssid, params->ssid_len) != 0)
  2268. wpa_s->mlme.prev_bssid_set = 0;
  2269. os_memcpy(wpa_s->mlme.ssid, params->ssid, params->ssid_len);
  2270. os_memset(wpa_s->mlme.ssid + params->ssid_len, 0,
  2271. MAX_SSID_LEN - params->ssid_len);
  2272. wpa_s->mlme.ssid_len = params->ssid_len;
  2273. wpa_s->mlme.ssid_set = 1;
  2274. os_free(wpa_s->mlme.extra_ie);
  2275. if (params->wpa_ie == NULL || params->wpa_ie_len == 0) {
  2276. wpa_s->mlme.extra_ie = NULL;
  2277. wpa_s->mlme.extra_ie_len = 0;
  2278. } else {
  2279. wpa_s->mlme.extra_ie = os_malloc(params->wpa_ie_len);
  2280. if (wpa_s->mlme.extra_ie == NULL) {
  2281. wpa_s->mlme.extra_ie_len = 0;
  2282. return -1;
  2283. }
  2284. os_memcpy(wpa_s->mlme.extra_ie, params->wpa_ie,
  2285. params->wpa_ie_len);
  2286. wpa_s->mlme.extra_ie_len = params->wpa_ie_len;
  2287. }
  2288. wpa_s->mlme.key_mgmt = params->key_mgmt_suite;
  2289. ieee80211_sta_set_channel(wpa_s, wpa_s->mlme.phymode,
  2290. wpa_s->mlme.channel, wpa_s->mlme.freq);
  2291. if (params->mode == 1 && !wpa_s->mlme.bssid_set) {
  2292. os_get_time(&wpa_s->mlme.ibss_join_req);
  2293. wpa_s->mlme.state = IEEE80211_IBSS_SEARCH;
  2294. return ieee80211_sta_find_ibss(wpa_s);
  2295. }
  2296. if (wpa_s->mlme.bssid_set)
  2297. ieee80211_sta_new_auth(wpa_s);
  2298. return 0;
  2299. }
  2300. static void ieee80211_sta_save_oper_chan(struct wpa_supplicant *wpa_s)
  2301. {
  2302. wpa_s->mlme.scan_oper_channel = wpa_s->mlme.channel;
  2303. wpa_s->mlme.scan_oper_freq = wpa_s->mlme.freq;
  2304. wpa_s->mlme.scan_oper_phymode = wpa_s->mlme.phymode;
  2305. }
  2306. static int ieee80211_sta_restore_oper_chan(struct wpa_supplicant *wpa_s)
  2307. {
  2308. wpa_s->mlme.channel = wpa_s->mlme.scan_oper_channel;
  2309. wpa_s->mlme.freq = wpa_s->mlme.scan_oper_freq;
  2310. wpa_s->mlme.phymode = wpa_s->mlme.scan_oper_phymode;
  2311. if (wpa_s->mlme.freq == 0)
  2312. return 0;
  2313. return ieee80211_sta_set_channel(wpa_s, wpa_s->mlme.phymode,
  2314. wpa_s->mlme.channel,
  2315. wpa_s->mlme.freq);
  2316. }
  2317. static int ieee80211_active_scan(struct wpa_supplicant *wpa_s)
  2318. {
  2319. size_t m;
  2320. int c;
  2321. for (m = 0; m < wpa_s->mlme.num_modes; m++) {
  2322. struct hostapd_hw_modes *mode = &wpa_s->mlme.modes[m];
  2323. if ((int) mode->mode != (int) wpa_s->mlme.phymode)
  2324. continue;
  2325. for (c = 0; c < mode->num_channels; c++) {
  2326. struct hostapd_channel_data *chan = &mode->channels[c];
  2327. if (!(chan->flag & HOSTAPD_CHAN_DISABLED) &&
  2328. chan->chan == wpa_s->mlme.channel) {
  2329. if (!(chan->flag & HOSTAPD_CHAN_PASSIVE_SCAN))
  2330. return 1;
  2331. break;
  2332. }
  2333. }
  2334. }
  2335. return 0;
  2336. }
  2337. static void ieee80211_sta_scan_timer(void *eloop_ctx, void *timeout_ctx)
  2338. {
  2339. struct wpa_supplicant *wpa_s = eloop_ctx;
  2340. struct hostapd_hw_modes *mode;
  2341. struct hostapd_channel_data *chan;
  2342. int skip = 0;
  2343. int timeout = 0;
  2344. struct wpa_ssid *ssid = wpa_s->current_ssid;
  2345. int adhoc;
  2346. if (!wpa_s->mlme.sta_scanning || wpa_s->mlme.modes == NULL)
  2347. return;
  2348. adhoc = ssid && ssid->mode == 1;
  2349. switch (wpa_s->mlme.scan_state) {
  2350. case SCAN_SET_CHANNEL:
  2351. mode = &wpa_s->mlme.modes[wpa_s->mlme.scan_hw_mode_idx];
  2352. if (wpa_s->mlme.scan_hw_mode_idx >=
  2353. (int) wpa_s->mlme.num_modes ||
  2354. (wpa_s->mlme.scan_hw_mode_idx + 1 ==
  2355. (int) wpa_s->mlme.num_modes
  2356. && wpa_s->mlme.scan_channel_idx >= mode->num_channels)) {
  2357. if (ieee80211_sta_restore_oper_chan(wpa_s)) {
  2358. wpa_printf(MSG_DEBUG, "MLME: failed to "
  2359. "restore operational channel after "
  2360. "scan");
  2361. }
  2362. wpa_printf(MSG_DEBUG, "MLME: scan completed");
  2363. wpa_s->mlme.sta_scanning = 0;
  2364. os_get_time(&wpa_s->mlme.last_scan_completed);
  2365. wpa_supplicant_event(wpa_s, EVENT_SCAN_RESULTS, NULL);
  2366. if (adhoc) {
  2367. if (!wpa_s->mlme.bssid_set ||
  2368. (wpa_s->mlme.state ==
  2369. IEEE80211_IBSS_JOINED &&
  2370. !ieee80211_sta_active_ibss(wpa_s)))
  2371. ieee80211_sta_find_ibss(wpa_s);
  2372. }
  2373. return;
  2374. }
  2375. skip = !(wpa_s->mlme.hw_modes & (1 << mode->mode));
  2376. chan = &mode->channels[wpa_s->mlme.scan_channel_idx];
  2377. if ((chan->flag & HOSTAPD_CHAN_DISABLED) ||
  2378. (adhoc && (chan->flag & HOSTAPD_CHAN_NO_IBSS)) ||
  2379. (wpa_s->mlme.hw_modes & (1 << HOSTAPD_MODE_IEEE80211G) &&
  2380. mode->mode == HOSTAPD_MODE_IEEE80211B &&
  2381. wpa_s->mlme.scan_skip_11b))
  2382. skip = 1;
  2383. if (!skip) {
  2384. wpa_printf(MSG_MSGDUMP,
  2385. "MLME: scan channel %d (%d MHz)",
  2386. chan->chan, chan->freq);
  2387. wpa_s->mlme.channel = chan->chan;
  2388. wpa_s->mlme.freq = chan->freq;
  2389. wpa_s->mlme.phymode = mode->mode;
  2390. if (ieee80211_sta_set_channel(wpa_s, mode->mode,
  2391. chan->chan, chan->freq))
  2392. {
  2393. wpa_printf(MSG_DEBUG, "MLME: failed to set "
  2394. "channel %d (%d MHz) for scan",
  2395. chan->chan, chan->freq);
  2396. skip = 1;
  2397. }
  2398. }
  2399. wpa_s->mlme.scan_channel_idx++;
  2400. if (wpa_s->mlme.scan_channel_idx >=
  2401. wpa_s->mlme.modes[wpa_s->mlme.scan_hw_mode_idx].
  2402. num_channels) {
  2403. wpa_s->mlme.scan_hw_mode_idx++;
  2404. wpa_s->mlme.scan_channel_idx = 0;
  2405. }
  2406. if (skip) {
  2407. timeout = 0;
  2408. break;
  2409. }
  2410. timeout = IEEE80211_PROBE_DELAY;
  2411. wpa_s->mlme.scan_state = SCAN_SEND_PROBE;
  2412. break;
  2413. case SCAN_SEND_PROBE:
  2414. if (ieee80211_active_scan(wpa_s)) {
  2415. ieee80211_send_probe_req(wpa_s, NULL,
  2416. wpa_s->mlme.scan_ssid,
  2417. wpa_s->mlme.scan_ssid_len);
  2418. timeout = IEEE80211_CHANNEL_TIME;
  2419. } else {
  2420. timeout = IEEE80211_PASSIVE_CHANNEL_TIME;
  2421. }
  2422. wpa_s->mlme.scan_state = SCAN_SET_CHANNEL;
  2423. break;
  2424. }
  2425. eloop_register_timeout(timeout / 1000, 1000 * (timeout % 1000),
  2426. ieee80211_sta_scan_timer, wpa_s, NULL);
  2427. }
  2428. int ieee80211_sta_req_scan(struct wpa_supplicant *wpa_s, const u8 *ssid,
  2429. size_t ssid_len)
  2430. {
  2431. if (ssid_len > MAX_SSID_LEN)
  2432. return -1;
  2433. /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
  2434. * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
  2435. * BSSID: MACAddress
  2436. * SSID
  2437. * ScanType: ACTIVE, PASSIVE
  2438. * ProbeDelay: delay (in microseconds) to be used prior to transmitting
  2439. * a Probe frame during active scanning
  2440. * ChannelList
  2441. * MinChannelTime (>= ProbeDelay), in TU
  2442. * MaxChannelTime: (>= MinChannelTime), in TU
  2443. */
  2444. /* MLME-SCAN.confirm
  2445. * BSSDescriptionSet
  2446. * ResultCode: SUCCESS, INVALID_PARAMETERS
  2447. */
  2448. /* TODO: if assoc, move to power save mode for the duration of the
  2449. * scan */
  2450. if (wpa_s->mlme.sta_scanning)
  2451. return -1;
  2452. wpa_printf(MSG_DEBUG, "MLME: starting scan");
  2453. ieee80211_sta_save_oper_chan(wpa_s);
  2454. wpa_s->mlme.sta_scanning = 1;
  2455. /* TODO: stop TX queue? */
  2456. if (ssid) {
  2457. wpa_s->mlme.scan_ssid_len = ssid_len;
  2458. os_memcpy(wpa_s->mlme.scan_ssid, ssid, ssid_len);
  2459. } else
  2460. wpa_s->mlme.scan_ssid_len = 0;
  2461. wpa_s->mlme.scan_skip_11b = 1; /* FIX: clear this is 11g is not
  2462. * supported */
  2463. wpa_s->mlme.scan_state = SCAN_SET_CHANNEL;
  2464. wpa_s->mlme.scan_hw_mode_idx = 0;
  2465. wpa_s->mlme.scan_channel_idx = 0;
  2466. eloop_register_timeout(0, 1, ieee80211_sta_scan_timer, wpa_s, NULL);
  2467. return 0;
  2468. }
  2469. struct wpa_scan_results *
  2470. ieee80211_sta_get_scan_results(struct wpa_supplicant *wpa_s)
  2471. {
  2472. size_t ap_num = 0;
  2473. struct wpa_scan_results *res;
  2474. struct wpa_scan_res *r;
  2475. struct ieee80211_sta_bss *bss;
  2476. res = os_zalloc(sizeof(*res));
  2477. for (bss = wpa_s->mlme.sta_bss_list; bss; bss = bss->next)
  2478. ap_num++;
  2479. res->res = os_zalloc(ap_num * sizeof(struct wpa_scan_res *));
  2480. if (res->res == NULL) {
  2481. os_free(res);
  2482. return NULL;
  2483. }
  2484. for (bss = wpa_s->mlme.sta_bss_list; bss; bss = bss->next) {
  2485. r = os_zalloc(sizeof(*r) + bss->ie_len);
  2486. if (r == NULL)
  2487. break;
  2488. os_memcpy(r->bssid, bss->bssid, ETH_ALEN);
  2489. r->freq = bss->freq;
  2490. r->beacon_int = bss->beacon_int;
  2491. r->caps = bss->capability;
  2492. r->level = bss->rssi;
  2493. r->tsf = bss->timestamp;
  2494. if (bss->ie) {
  2495. r->ie_len = bss->ie_len;
  2496. os_memcpy(r + 1, bss->ie, bss->ie_len);
  2497. }
  2498. res->res[res->num++] = r;
  2499. }
  2500. return res;
  2501. }
  2502. #if 0 /* FIX */
  2503. struct sta_info * ieee80211_ibss_add_sta(struct wpa_supplicant *wpa_s,
  2504. struct sk_buff *skb, u8 *bssid,
  2505. u8 *addr)
  2506. {
  2507. struct ieee80211_local *local = dev->priv;
  2508. struct list_head *ptr;
  2509. struct sta_info *sta;
  2510. struct wpa_supplicant *sta_dev = NULL;
  2511. /* TODO: Could consider removing the least recently used entry and
  2512. * allow new one to be added. */
  2513. if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
  2514. if (net_ratelimit()) {
  2515. wpa_printf(MSG_DEBUG, "MLME: No room for a new IBSS "
  2516. "STA entry " MACSTR, MAC2STR(addr));
  2517. }
  2518. return NULL;
  2519. }
  2520. spin_lock_bh(&local->sub_if_lock);
  2521. list_for_each(ptr, &local->sub_if_list) {
  2522. sdata = list_entry(ptr, struct ieee80211_sub_if_data, list);
  2523. if (sdata->type == IEEE80211_SUB_IF_TYPE_STA &&
  2524. os_memcmp(bssid, sdata->u.sta.bssid, ETH_ALEN) == 0) {
  2525. sta_dev = sdata->dev;
  2526. break;
  2527. }
  2528. }
  2529. spin_unlock_bh(&local->sub_if_lock);
  2530. if (sta_dev == NULL)
  2531. return NULL;
  2532. wpa_printf(MSG_DEBUG, "MLME: Adding new IBSS station " MACSTR
  2533. " (dev=%s)", MAC2STR(addr), sta_dev->name);
  2534. sta = sta_info_add(wpa_s, addr);
  2535. if (sta == NULL) {
  2536. return NULL;
  2537. }
  2538. sta->dev = sta_dev;
  2539. sta->supp_rates = wpa_s->mlme.supp_rates_bits;
  2540. rate_control_rate_init(local, sta);
  2541. return sta; /* caller will call sta_info_release() */
  2542. }
  2543. #endif
  2544. int ieee80211_sta_deauthenticate(struct wpa_supplicant *wpa_s, u16 reason)
  2545. {
  2546. wpa_printf(MSG_DEBUG, "MLME: deauthenticate(reason=%d)", reason);
  2547. ieee80211_send_deauth(wpa_s, reason);
  2548. ieee80211_set_associated(wpa_s, 0);
  2549. return 0;
  2550. }
  2551. int ieee80211_sta_disassociate(struct wpa_supplicant *wpa_s, u16 reason)
  2552. {
  2553. wpa_printf(MSG_DEBUG, "MLME: disassociate(reason=%d)", reason);
  2554. if (!wpa_s->mlme.associated)
  2555. return -1;
  2556. ieee80211_send_disassoc(wpa_s, reason);
  2557. ieee80211_set_associated(wpa_s, 0);
  2558. return 0;
  2559. }
  2560. void ieee80211_sta_rx(struct wpa_supplicant *wpa_s, const u8 *buf, size_t len,
  2561. struct ieee80211_rx_status *rx_status)
  2562. {
  2563. struct ieee80211_mgmt *mgmt;
  2564. u16 fc;
  2565. const u8 *pos;
  2566. /* wpa_hexdump(MSG_MSGDUMP, "MLME: Received frame", buf, len); */
  2567. if (wpa_s->mlme.sta_scanning) {
  2568. ieee80211_sta_rx_scan(wpa_s, buf, len, rx_status);
  2569. return;
  2570. }
  2571. if (len < 24)
  2572. return;
  2573. mgmt = (struct ieee80211_mgmt *) buf;
  2574. fc = le_to_host16(mgmt->frame_control);
  2575. if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT)
  2576. ieee80211_sta_rx_mgmt(wpa_s, buf, len, rx_status);
  2577. else if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA) {
  2578. if ((fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) !=
  2579. WLAN_FC_FROMDS)
  2580. return;
  2581. /* mgmt->sa is actually BSSID for FromDS data frames */
  2582. if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) != 0)
  2583. return;
  2584. /* Skip IEEE 802.11 and LLC headers */
  2585. pos = buf + 24 + 6;
  2586. if (WPA_GET_BE16(pos) != ETH_P_EAPOL)
  2587. return;
  2588. pos += 2;
  2589. /* mgmt->bssid is actually BSSID for SA data frames */
  2590. wpa_supplicant_rx_eapol(wpa_s, mgmt->bssid,
  2591. pos, buf + len - pos);
  2592. }
  2593. }
  2594. void ieee80211_sta_free_hw_features(struct hostapd_hw_modes *hw_features,
  2595. size_t num_hw_features)
  2596. {
  2597. size_t i;
  2598. if (hw_features == NULL)
  2599. return;
  2600. for (i = 0; i < num_hw_features; i++) {
  2601. os_free(hw_features[i].channels);
  2602. os_free(hw_features[i].rates);
  2603. }
  2604. os_free(hw_features);
  2605. }
  2606. int ieee80211_sta_init(struct wpa_supplicant *wpa_s)
  2607. {
  2608. u16 num_modes, flags;
  2609. wpa_s->mlme.modes = wpa_drv_get_hw_feature_data(wpa_s, &num_modes,
  2610. &flags);
  2611. if (wpa_s->mlme.modes == NULL) {
  2612. wpa_printf(MSG_ERROR, "MLME: Failed to read supported "
  2613. "channels and rates from the driver");
  2614. return -1;
  2615. }
  2616. wpa_s->mlme.num_modes = num_modes;
  2617. wpa_s->mlme.hw_modes = 1 << HOSTAPD_MODE_IEEE80211A;
  2618. wpa_s->mlme.hw_modes |= 1 << HOSTAPD_MODE_IEEE80211B;
  2619. wpa_s->mlme.hw_modes |= 1 << HOSTAPD_MODE_IEEE80211G;
  2620. wpa_s->mlme.wmm_enabled = 1;
  2621. return 0;
  2622. }
  2623. void ieee80211_sta_deinit(struct wpa_supplicant *wpa_s)
  2624. {
  2625. eloop_cancel_timeout(ieee80211_sta_timer, wpa_s, NULL);
  2626. eloop_cancel_timeout(ieee80211_sta_scan_timer, wpa_s, NULL);
  2627. os_free(wpa_s->mlme.extra_ie);
  2628. wpa_s->mlme.extra_ie = NULL;
  2629. os_free(wpa_s->mlme.extra_probe_ie);
  2630. wpa_s->mlme.extra_probe_ie = NULL;
  2631. os_free(wpa_s->mlme.assocreq_ies);
  2632. wpa_s->mlme.assocreq_ies = NULL;
  2633. os_free(wpa_s->mlme.assocresp_ies);
  2634. wpa_s->mlme.assocresp_ies = NULL;
  2635. ieee80211_bss_list_deinit(wpa_s);
  2636. ieee80211_sta_free_hw_features(wpa_s->mlme.modes,
  2637. wpa_s->mlme.num_modes);
  2638. #ifdef CONFIG_IEEE80211R
  2639. os_free(wpa_s->mlme.ft_ies);
  2640. wpa_s->mlme.ft_ies = NULL;
  2641. wpa_s->mlme.ft_ies_len = 0;
  2642. #endif /* CONFIG_IEEE80211R */
  2643. }
  2644. #ifdef CONFIG_IEEE80211R
  2645. int ieee80211_sta_update_ft_ies(struct wpa_supplicant *wpa_s, const u8 *md,
  2646. const u8 *ies, size_t ies_len)
  2647. {
  2648. if (md == NULL) {
  2649. wpa_printf(MSG_DEBUG, "MLME: Clear FT mobility domain");
  2650. os_memset(wpa_s->mlme.current_md, 0, MOBILITY_DOMAIN_ID_LEN);
  2651. } else {
  2652. wpa_printf(MSG_DEBUG, "MLME: Update FT IEs for MD " MACSTR,
  2653. MAC2STR(md));
  2654. os_memcpy(wpa_s->mlme.current_md, md, MOBILITY_DOMAIN_ID_LEN);
  2655. }
  2656. wpa_hexdump(MSG_DEBUG, "MLME: FT IEs", ies, ies_len);
  2657. os_free(wpa_s->mlme.ft_ies);
  2658. wpa_s->mlme.ft_ies = os_malloc(ies_len);
  2659. if (wpa_s->mlme.ft_ies == NULL)
  2660. return -1;
  2661. os_memcpy(wpa_s->mlme.ft_ies, ies, ies_len);
  2662. wpa_s->mlme.ft_ies_len = ies_len;
  2663. return 0;
  2664. }
  2665. int ieee80211_sta_send_ft_action(struct wpa_supplicant *wpa_s, u8 action,
  2666. const u8 *target_ap,
  2667. const u8 *ies, size_t ies_len)
  2668. {
  2669. u8 *buf;
  2670. size_t len;
  2671. struct ieee80211_mgmt *mgmt;
  2672. int res;
  2673. /*
  2674. * Action frame payload:
  2675. * Category[1] = 6 (Fast BSS Transition)
  2676. * Action[1] = 1 (Fast BSS Transition Request)
  2677. * STA Address
  2678. * Target AP Address
  2679. * FT IEs
  2680. */
  2681. buf = os_zalloc(sizeof(*mgmt) + ies_len);
  2682. if (buf == NULL) {
  2683. wpa_printf(MSG_DEBUG, "MLME: Failed to allocate buffer for "
  2684. "FT action frame");
  2685. return -1;
  2686. }
  2687. mgmt = (struct ieee80211_mgmt *) buf;
  2688. len = 24;
  2689. os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
  2690. os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
  2691. os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
  2692. mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  2693. WLAN_FC_STYPE_ACTION);
  2694. mgmt->u.action.category = WLAN_ACTION_FT;
  2695. mgmt->u.action.u.ft_action_req.action = action;
  2696. os_memcpy(mgmt->u.action.u.ft_action_req.sta_addr, wpa_s->own_addr,
  2697. ETH_ALEN);
  2698. os_memcpy(mgmt->u.action.u.ft_action_req.target_ap_addr, target_ap,
  2699. ETH_ALEN);
  2700. os_memcpy(mgmt->u.action.u.ft_action_req.variable, ies, ies_len);
  2701. len += 1 + sizeof(mgmt->u.action.u.ft_action_req) + ies_len;
  2702. wpa_printf(MSG_DEBUG, "MLME: Send FT Action Frame: Action=%d "
  2703. "Target AP=" MACSTR " body_len=%lu",
  2704. action, MAC2STR(target_ap), (unsigned long) ies_len);
  2705. res = ieee80211_sta_tx(wpa_s, buf, len);
  2706. os_free(buf);
  2707. return res;
  2708. }
  2709. #endif /* CONFIG_IEEE80211R */
  2710. int ieee80211_sta_set_probe_req_ie(struct wpa_supplicant *wpa_s, const u8 *ies,
  2711. size_t ies_len)
  2712. {
  2713. os_free(wpa_s->mlme.extra_probe_ie);
  2714. wpa_s->mlme.extra_probe_ie = NULL;
  2715. wpa_s->mlme.extra_probe_ie_len = 0;
  2716. if (ies == NULL)
  2717. return 0;
  2718. wpa_s->mlme.extra_probe_ie = os_malloc(ies_len);
  2719. if (wpa_s->mlme.extra_probe_ie == NULL)
  2720. return -1;
  2721. os_memcpy(wpa_s->mlme.extra_probe_ie, ies, ies_len);
  2722. wpa_s->mlme.extra_probe_ie_len = ies_len;
  2723. return 0;
  2724. }