mlme.c 85 KB

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