mlme.c 84 KB

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