mlme.c 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709
  1. /*
  2. * BSS client mode implementation
  3. * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
  4. * Copyright 2004, Instant802 Networks, Inc.
  5. * Copyright 2005, Devicescape Software, Inc.
  6. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  7. * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/delay.h>
  14. #include <linux/if_ether.h>
  15. #include <linux/skbuff.h>
  16. #include <linux/if_arp.h>
  17. #include <linux/wireless.h>
  18. #include <linux/random.h>
  19. #include <linux/etherdevice.h>
  20. #include <linux/rtnetlink.h>
  21. #include <net/iw_handler.h>
  22. #include <net/mac80211.h>
  23. #include <asm/unaligned.h>
  24. #include "ieee80211_i.h"
  25. #include "rate.h"
  26. #include "led.h"
  27. #define IEEE80211_ASSOC_SCANS_MAX_TRIES 2
  28. #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
  29. #define IEEE80211_AUTH_MAX_TRIES 3
  30. #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
  31. #define IEEE80211_ASSOC_MAX_TRIES 3
  32. #define IEEE80211_MONITORING_INTERVAL (2 * HZ)
  33. #define IEEE80211_PROBE_INTERVAL (60 * HZ)
  34. #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
  35. #define IEEE80211_SCAN_INTERVAL (2 * HZ)
  36. #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
  37. #define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ)
  38. #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
  39. #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
  40. #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
  41. /* utils */
  42. static int ecw2cw(int ecw)
  43. {
  44. return (1 << ecw) - 1;
  45. }
  46. static u8 *ieee80211_bss_get_ie(struct ieee80211_bss *bss, u8 ie)
  47. {
  48. u8 *end, *pos;
  49. pos = bss->ies;
  50. if (pos == NULL)
  51. return NULL;
  52. end = pos + bss->ies_len;
  53. while (pos + 1 < end) {
  54. if (pos + 2 + pos[1] > end)
  55. break;
  56. if (pos[0] == ie)
  57. return pos;
  58. pos += 2 + pos[1];
  59. }
  60. return NULL;
  61. }
  62. static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
  63. struct ieee80211_supported_band *sband,
  64. u64 *rates)
  65. {
  66. int i, j, count;
  67. *rates = 0;
  68. count = 0;
  69. for (i = 0; i < bss->supp_rates_len; i++) {
  70. int rate = (bss->supp_rates[i] & 0x7F) * 5;
  71. for (j = 0; j < sband->n_bitrates; j++)
  72. if (sband->bitrates[j].bitrate == rate) {
  73. *rates |= BIT(j);
  74. count++;
  75. break;
  76. }
  77. }
  78. return count;
  79. }
  80. /* also used by mesh code */
  81. u64 ieee80211_sta_get_rates(struct ieee80211_local *local,
  82. struct ieee802_11_elems *elems,
  83. enum ieee80211_band band)
  84. {
  85. struct ieee80211_supported_band *sband;
  86. struct ieee80211_rate *bitrates;
  87. size_t num_rates;
  88. u64 supp_rates;
  89. int i, j;
  90. sband = local->hw.wiphy->bands[band];
  91. if (!sband) {
  92. WARN_ON(1);
  93. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  94. }
  95. bitrates = sband->bitrates;
  96. num_rates = sband->n_bitrates;
  97. supp_rates = 0;
  98. for (i = 0; i < elems->supp_rates_len +
  99. elems->ext_supp_rates_len; i++) {
  100. u8 rate = 0;
  101. int own_rate;
  102. if (i < elems->supp_rates_len)
  103. rate = elems->supp_rates[i];
  104. else if (elems->ext_supp_rates)
  105. rate = elems->ext_supp_rates
  106. [i - elems->supp_rates_len];
  107. own_rate = 5 * (rate & 0x7f);
  108. for (j = 0; j < num_rates; j++)
  109. if (bitrates[j].bitrate == own_rate)
  110. supp_rates |= BIT(j);
  111. }
  112. return supp_rates;
  113. }
  114. /* frame sending functions */
  115. /* also used by scanning code */
  116. void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
  117. u8 *ssid, size_t ssid_len)
  118. {
  119. struct ieee80211_local *local = sdata->local;
  120. struct ieee80211_supported_band *sband;
  121. struct sk_buff *skb;
  122. struct ieee80211_mgmt *mgmt;
  123. u8 *pos, *supp_rates, *esupp_rates = NULL;
  124. int i;
  125. skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200);
  126. if (!skb) {
  127. printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
  128. "request\n", sdata->dev->name);
  129. return;
  130. }
  131. skb_reserve(skb, local->hw.extra_tx_headroom);
  132. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  133. memset(mgmt, 0, 24);
  134. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  135. IEEE80211_STYPE_PROBE_REQ);
  136. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  137. if (dst) {
  138. memcpy(mgmt->da, dst, ETH_ALEN);
  139. memcpy(mgmt->bssid, dst, ETH_ALEN);
  140. } else {
  141. memset(mgmt->da, 0xff, ETH_ALEN);
  142. memset(mgmt->bssid, 0xff, ETH_ALEN);
  143. }
  144. pos = skb_put(skb, 2 + ssid_len);
  145. *pos++ = WLAN_EID_SSID;
  146. *pos++ = ssid_len;
  147. memcpy(pos, ssid, ssid_len);
  148. supp_rates = skb_put(skb, 2);
  149. supp_rates[0] = WLAN_EID_SUPP_RATES;
  150. supp_rates[1] = 0;
  151. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  152. for (i = 0; i < sband->n_bitrates; i++) {
  153. struct ieee80211_rate *rate = &sband->bitrates[i];
  154. if (esupp_rates) {
  155. pos = skb_put(skb, 1);
  156. esupp_rates[1]++;
  157. } else if (supp_rates[1] == 8) {
  158. esupp_rates = skb_put(skb, 3);
  159. esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES;
  160. esupp_rates[1] = 1;
  161. pos = &esupp_rates[2];
  162. } else {
  163. pos = skb_put(skb, 1);
  164. supp_rates[1]++;
  165. }
  166. *pos = rate->bitrate / 5;
  167. }
  168. ieee80211_tx_skb(sdata, skb, 0);
  169. }
  170. static void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
  171. struct ieee80211_if_sta *ifsta,
  172. int transaction, u8 *extra, size_t extra_len,
  173. int encrypt)
  174. {
  175. struct ieee80211_local *local = sdata->local;
  176. struct sk_buff *skb;
  177. struct ieee80211_mgmt *mgmt;
  178. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  179. sizeof(*mgmt) + 6 + extra_len);
  180. if (!skb) {
  181. printk(KERN_DEBUG "%s: failed to allocate buffer for auth "
  182. "frame\n", sdata->dev->name);
  183. return;
  184. }
  185. skb_reserve(skb, local->hw.extra_tx_headroom);
  186. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
  187. memset(mgmt, 0, 24 + 6);
  188. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  189. IEEE80211_STYPE_AUTH);
  190. if (encrypt)
  191. mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  192. memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
  193. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  194. memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
  195. mgmt->u.auth.auth_alg = cpu_to_le16(ifsta->auth_alg);
  196. mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
  197. ifsta->auth_transaction = transaction + 1;
  198. mgmt->u.auth.status_code = cpu_to_le16(0);
  199. if (extra)
  200. memcpy(skb_put(skb, extra_len), extra, extra_len);
  201. ieee80211_tx_skb(sdata, skb, encrypt);
  202. }
  203. static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
  204. struct ieee80211_if_sta *ifsta)
  205. {
  206. struct ieee80211_local *local = sdata->local;
  207. struct sk_buff *skb;
  208. struct ieee80211_mgmt *mgmt;
  209. u8 *pos, *ies, *ht_ie;
  210. int i, len, count, rates_len, supp_rates_len;
  211. u16 capab;
  212. struct ieee80211_bss *bss;
  213. int wmm = 0;
  214. struct ieee80211_supported_band *sband;
  215. u64 rates = 0;
  216. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  217. sizeof(*mgmt) + 200 + ifsta->extra_ie_len +
  218. ifsta->ssid_len);
  219. if (!skb) {
  220. printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
  221. "frame\n", sdata->dev->name);
  222. return;
  223. }
  224. skb_reserve(skb, local->hw.extra_tx_headroom);
  225. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  226. capab = ifsta->capab;
  227. if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
  228. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
  229. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  230. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
  231. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  232. }
  233. bss = ieee80211_rx_bss_get(local, ifsta->bssid,
  234. local->hw.conf.channel->center_freq,
  235. ifsta->ssid, ifsta->ssid_len);
  236. if (bss) {
  237. if (bss->capability & WLAN_CAPABILITY_PRIVACY)
  238. capab |= WLAN_CAPABILITY_PRIVACY;
  239. if (bss->wmm_used)
  240. wmm = 1;
  241. /* get all rates supported by the device and the AP as
  242. * some APs don't like getting a superset of their rates
  243. * in the association request (e.g. D-Link DAP 1353 in
  244. * b-only mode) */
  245. rates_len = ieee80211_compatible_rates(bss, sband, &rates);
  246. if ((bss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
  247. (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
  248. capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
  249. ieee80211_rx_bss_put(local, bss);
  250. } else {
  251. rates = ~0;
  252. rates_len = sband->n_bitrates;
  253. }
  254. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  255. memset(mgmt, 0, 24);
  256. memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
  257. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  258. memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
  259. if (ifsta->flags & IEEE80211_STA_PREV_BSSID_SET) {
  260. skb_put(skb, 10);
  261. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  262. IEEE80211_STYPE_REASSOC_REQ);
  263. mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
  264. mgmt->u.reassoc_req.listen_interval =
  265. cpu_to_le16(local->hw.conf.listen_interval);
  266. memcpy(mgmt->u.reassoc_req.current_ap, ifsta->prev_bssid,
  267. ETH_ALEN);
  268. } else {
  269. skb_put(skb, 4);
  270. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  271. IEEE80211_STYPE_ASSOC_REQ);
  272. mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
  273. mgmt->u.assoc_req.listen_interval =
  274. cpu_to_le16(local->hw.conf.listen_interval);
  275. }
  276. /* SSID */
  277. ies = pos = skb_put(skb, 2 + ifsta->ssid_len);
  278. *pos++ = WLAN_EID_SSID;
  279. *pos++ = ifsta->ssid_len;
  280. memcpy(pos, ifsta->ssid, ifsta->ssid_len);
  281. /* add all rates which were marked to be used above */
  282. supp_rates_len = rates_len;
  283. if (supp_rates_len > 8)
  284. supp_rates_len = 8;
  285. len = sband->n_bitrates;
  286. pos = skb_put(skb, supp_rates_len + 2);
  287. *pos++ = WLAN_EID_SUPP_RATES;
  288. *pos++ = supp_rates_len;
  289. count = 0;
  290. for (i = 0; i < sband->n_bitrates; i++) {
  291. if (BIT(i) & rates) {
  292. int rate = sband->bitrates[i].bitrate;
  293. *pos++ = (u8) (rate / 5);
  294. if (++count == 8)
  295. break;
  296. }
  297. }
  298. if (rates_len > count) {
  299. pos = skb_put(skb, rates_len - count + 2);
  300. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  301. *pos++ = rates_len - count;
  302. for (i++; i < sband->n_bitrates; i++) {
  303. if (BIT(i) & rates) {
  304. int rate = sband->bitrates[i].bitrate;
  305. *pos++ = (u8) (rate / 5);
  306. }
  307. }
  308. }
  309. if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
  310. /* 1. power capabilities */
  311. pos = skb_put(skb, 4);
  312. *pos++ = WLAN_EID_PWR_CAPABILITY;
  313. *pos++ = 2;
  314. *pos++ = 0; /* min tx power */
  315. *pos++ = local->hw.conf.channel->max_power; /* max tx power */
  316. /* 2. supported channels */
  317. /* TODO: get this in reg domain format */
  318. pos = skb_put(skb, 2 * sband->n_channels + 2);
  319. *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
  320. *pos++ = 2 * sband->n_channels;
  321. for (i = 0; i < sband->n_channels; i++) {
  322. *pos++ = ieee80211_frequency_to_channel(
  323. sband->channels[i].center_freq);
  324. *pos++ = 1; /* one channel in the subband*/
  325. }
  326. }
  327. if (ifsta->extra_ie) {
  328. pos = skb_put(skb, ifsta->extra_ie_len);
  329. memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len);
  330. }
  331. if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
  332. pos = skb_put(skb, 9);
  333. *pos++ = WLAN_EID_VENDOR_SPECIFIC;
  334. *pos++ = 7; /* len */
  335. *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
  336. *pos++ = 0x50;
  337. *pos++ = 0xf2;
  338. *pos++ = 2; /* WME */
  339. *pos++ = 0; /* WME info */
  340. *pos++ = 1; /* WME ver */
  341. *pos++ = 0;
  342. }
  343. /* wmm support is a must to HT */
  344. /*
  345. * IEEE802.11n does not allow TKIP/WEP as pairwise
  346. * ciphers in HT mode. We still associate in non-ht
  347. * mode (11a/b/g) if any one of these ciphers is
  348. * configured as pairwise.
  349. */
  350. if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED) &&
  351. sband->ht_cap.ht_supported &&
  352. (ht_ie = ieee80211_bss_get_ie(bss, WLAN_EID_HT_INFORMATION)) &&
  353. ht_ie[1] >= sizeof(struct ieee80211_ht_info) &&
  354. (!(ifsta->flags & IEEE80211_STA_TKIP_WEP_USED))) {
  355. struct ieee80211_ht_info *ht_info =
  356. (struct ieee80211_ht_info *)(ht_ie + 2);
  357. u16 cap = sband->ht_cap.cap;
  358. __le16 tmp;
  359. u32 flags = local->hw.conf.channel->flags;
  360. switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
  361. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  362. if (flags & IEEE80211_CHAN_NO_FAT_ABOVE) {
  363. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  364. cap &= ~IEEE80211_HT_CAP_SGI_40;
  365. }
  366. break;
  367. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  368. if (flags & IEEE80211_CHAN_NO_FAT_BELOW) {
  369. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  370. cap &= ~IEEE80211_HT_CAP_SGI_40;
  371. }
  372. break;
  373. }
  374. tmp = cpu_to_le16(cap);
  375. pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
  376. *pos++ = WLAN_EID_HT_CAPABILITY;
  377. *pos++ = sizeof(struct ieee80211_ht_cap);
  378. memset(pos, 0, sizeof(struct ieee80211_ht_cap));
  379. memcpy(pos, &tmp, sizeof(u16));
  380. pos += sizeof(u16);
  381. /* TODO: needs a define here for << 2 */
  382. *pos++ = sband->ht_cap.ampdu_factor |
  383. (sband->ht_cap.ampdu_density << 2);
  384. memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
  385. }
  386. kfree(ifsta->assocreq_ies);
  387. ifsta->assocreq_ies_len = (skb->data + skb->len) - ies;
  388. ifsta->assocreq_ies = kmalloc(ifsta->assocreq_ies_len, GFP_KERNEL);
  389. if (ifsta->assocreq_ies)
  390. memcpy(ifsta->assocreq_ies, ies, ifsta->assocreq_ies_len);
  391. ieee80211_tx_skb(sdata, skb, 0);
  392. }
  393. static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
  394. u16 stype, u16 reason)
  395. {
  396. struct ieee80211_local *local = sdata->local;
  397. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  398. struct sk_buff *skb;
  399. struct ieee80211_mgmt *mgmt;
  400. skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
  401. if (!skb) {
  402. printk(KERN_DEBUG "%s: failed to allocate buffer for "
  403. "deauth/disassoc frame\n", sdata->dev->name);
  404. return;
  405. }
  406. skb_reserve(skb, local->hw.extra_tx_headroom);
  407. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  408. memset(mgmt, 0, 24);
  409. memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
  410. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  411. memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
  412. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
  413. skb_put(skb, 2);
  414. /* u.deauth.reason_code == u.disassoc.reason_code */
  415. mgmt->u.deauth.reason_code = cpu_to_le16(reason);
  416. ieee80211_tx_skb(sdata, skb, 0);
  417. }
  418. /* MLME */
  419. static void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
  420. struct ieee80211_bss *bss)
  421. {
  422. struct ieee80211_local *local = sdata->local;
  423. int i, have_higher_than_11mbit = 0;
  424. /* cf. IEEE 802.11 9.2.12 */
  425. for (i = 0; i < bss->supp_rates_len; i++)
  426. if ((bss->supp_rates[i] & 0x7f) * 5 > 110)
  427. have_higher_than_11mbit = 1;
  428. if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
  429. have_higher_than_11mbit)
  430. sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
  431. else
  432. sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
  433. ieee80211_set_wmm_default(sdata);
  434. }
  435. static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
  436. struct ieee80211_if_sta *ifsta,
  437. u8 *wmm_param, size_t wmm_param_len)
  438. {
  439. struct ieee80211_tx_queue_params params;
  440. size_t left;
  441. int count;
  442. u8 *pos;
  443. if (!(ifsta->flags & IEEE80211_STA_WMM_ENABLED))
  444. return;
  445. if (!wmm_param)
  446. return;
  447. if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
  448. return;
  449. count = wmm_param[6] & 0x0f;
  450. if (count == ifsta->wmm_last_param_set)
  451. return;
  452. ifsta->wmm_last_param_set = count;
  453. pos = wmm_param + 8;
  454. left = wmm_param_len - 8;
  455. memset(&params, 0, sizeof(params));
  456. if (!local->ops->conf_tx)
  457. return;
  458. local->wmm_acm = 0;
  459. for (; left >= 4; left -= 4, pos += 4) {
  460. int aci = (pos[0] >> 5) & 0x03;
  461. int acm = (pos[0] >> 4) & 0x01;
  462. int queue;
  463. switch (aci) {
  464. case 1:
  465. queue = 3;
  466. if (acm)
  467. local->wmm_acm |= BIT(0) | BIT(3);
  468. break;
  469. case 2:
  470. queue = 1;
  471. if (acm)
  472. local->wmm_acm |= BIT(4) | BIT(5);
  473. break;
  474. case 3:
  475. queue = 0;
  476. if (acm)
  477. local->wmm_acm |= BIT(6) | BIT(7);
  478. break;
  479. case 0:
  480. default:
  481. queue = 2;
  482. if (acm)
  483. local->wmm_acm |= BIT(1) | BIT(2);
  484. break;
  485. }
  486. params.aifs = pos[0] & 0x0f;
  487. params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
  488. params.cw_min = ecw2cw(pos[1] & 0x0f);
  489. params.txop = get_unaligned_le16(pos + 2);
  490. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  491. printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
  492. "cWmin=%d cWmax=%d txop=%d\n",
  493. local->mdev->name, queue, aci, acm, params.aifs, params.cw_min,
  494. params.cw_max, params.txop);
  495. #endif
  496. /* TODO: handle ACM (block TX, fallback to next lowest allowed
  497. * AC for now) */
  498. if (local->ops->conf_tx(local_to_hw(local), queue, &params)) {
  499. printk(KERN_DEBUG "%s: failed to set TX queue "
  500. "parameters for queue %d\n", local->mdev->name, queue);
  501. }
  502. }
  503. }
  504. static bool check_tim(struct ieee802_11_elems *elems, u16 aid, bool *is_mc)
  505. {
  506. u8 mask;
  507. u8 index, indexn1, indexn2;
  508. struct ieee80211_tim_ie *tim = (struct ieee80211_tim_ie *) elems->tim;
  509. aid &= 0x3fff;
  510. index = aid / 8;
  511. mask = 1 << (aid & 7);
  512. if (tim->bitmap_ctrl & 0x01)
  513. *is_mc = true;
  514. indexn1 = tim->bitmap_ctrl & 0xfe;
  515. indexn2 = elems->tim_len + indexn1 - 4;
  516. if (index < indexn1 || index > indexn2)
  517. return false;
  518. index -= indexn1;
  519. return !!(tim->virtual_map[index] & mask);
  520. }
  521. static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
  522. u16 capab, bool erp_valid, u8 erp)
  523. {
  524. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  525. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  526. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  527. #endif
  528. u32 changed = 0;
  529. bool use_protection;
  530. bool use_short_preamble;
  531. bool use_short_slot;
  532. if (erp_valid) {
  533. use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
  534. use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
  535. } else {
  536. use_protection = false;
  537. use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
  538. }
  539. use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
  540. if (use_protection != bss_conf->use_cts_prot) {
  541. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  542. if (net_ratelimit()) {
  543. printk(KERN_DEBUG "%s: CTS protection %s (BSSID=%pM)\n",
  544. sdata->dev->name,
  545. use_protection ? "enabled" : "disabled",
  546. ifsta->bssid);
  547. }
  548. #endif
  549. bss_conf->use_cts_prot = use_protection;
  550. changed |= BSS_CHANGED_ERP_CTS_PROT;
  551. }
  552. if (use_short_preamble != bss_conf->use_short_preamble) {
  553. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  554. if (net_ratelimit()) {
  555. printk(KERN_DEBUG "%s: switched to %s barker preamble"
  556. " (BSSID=%pM)\n",
  557. sdata->dev->name,
  558. use_short_preamble ? "short" : "long",
  559. ifsta->bssid);
  560. }
  561. #endif
  562. bss_conf->use_short_preamble = use_short_preamble;
  563. changed |= BSS_CHANGED_ERP_PREAMBLE;
  564. }
  565. if (use_short_slot != bss_conf->use_short_slot) {
  566. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  567. if (net_ratelimit()) {
  568. printk(KERN_DEBUG "%s: switched to %s slot time"
  569. " (BSSID=%pM)\n",
  570. sdata->dev->name,
  571. use_short_slot ? "short" : "long",
  572. ifsta->bssid);
  573. }
  574. #endif
  575. bss_conf->use_short_slot = use_short_slot;
  576. changed |= BSS_CHANGED_ERP_SLOT;
  577. }
  578. return changed;
  579. }
  580. static void ieee80211_sta_send_apinfo(struct ieee80211_sub_if_data *sdata,
  581. struct ieee80211_if_sta *ifsta)
  582. {
  583. union iwreq_data wrqu;
  584. memset(&wrqu, 0, sizeof(wrqu));
  585. if (ifsta->flags & IEEE80211_STA_ASSOCIATED)
  586. memcpy(wrqu.ap_addr.sa_data, sdata->u.sta.bssid, ETH_ALEN);
  587. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  588. wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL);
  589. }
  590. static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata,
  591. struct ieee80211_if_sta *ifsta)
  592. {
  593. char *buf;
  594. size_t len;
  595. int i;
  596. union iwreq_data wrqu;
  597. if (!ifsta->assocreq_ies && !ifsta->assocresp_ies)
  598. return;
  599. buf = kmalloc(50 + 2 * (ifsta->assocreq_ies_len +
  600. ifsta->assocresp_ies_len), GFP_KERNEL);
  601. if (!buf)
  602. return;
  603. len = sprintf(buf, "ASSOCINFO(");
  604. if (ifsta->assocreq_ies) {
  605. len += sprintf(buf + len, "ReqIEs=");
  606. for (i = 0; i < ifsta->assocreq_ies_len; i++) {
  607. len += sprintf(buf + len, "%02x",
  608. ifsta->assocreq_ies[i]);
  609. }
  610. }
  611. if (ifsta->assocresp_ies) {
  612. if (ifsta->assocreq_ies)
  613. len += sprintf(buf + len, " ");
  614. len += sprintf(buf + len, "RespIEs=");
  615. for (i = 0; i < ifsta->assocresp_ies_len; i++) {
  616. len += sprintf(buf + len, "%02x",
  617. ifsta->assocresp_ies[i]);
  618. }
  619. }
  620. len += sprintf(buf + len, ")");
  621. if (len > IW_CUSTOM_MAX) {
  622. len = sprintf(buf, "ASSOCRESPIE=");
  623. for (i = 0; i < ifsta->assocresp_ies_len; i++) {
  624. len += sprintf(buf + len, "%02x",
  625. ifsta->assocresp_ies[i]);
  626. }
  627. }
  628. if (len <= IW_CUSTOM_MAX) {
  629. memset(&wrqu, 0, sizeof(wrqu));
  630. wrqu.data.length = len;
  631. wireless_send_event(sdata->dev, IWEVCUSTOM, &wrqu, buf);
  632. }
  633. kfree(buf);
  634. }
  635. static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
  636. struct ieee80211_if_sta *ifsta,
  637. u32 bss_info_changed)
  638. {
  639. struct ieee80211_local *local = sdata->local;
  640. struct ieee80211_conf *conf = &local_to_hw(local)->conf;
  641. struct ieee80211_bss *bss;
  642. bss_info_changed |= BSS_CHANGED_ASSOC;
  643. ifsta->flags |= IEEE80211_STA_ASSOCIATED;
  644. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  645. return;
  646. bss = ieee80211_rx_bss_get(local, ifsta->bssid,
  647. conf->channel->center_freq,
  648. ifsta->ssid, ifsta->ssid_len);
  649. if (bss) {
  650. /* set timing information */
  651. sdata->vif.bss_conf.beacon_int = bss->beacon_int;
  652. sdata->vif.bss_conf.timestamp = bss->timestamp;
  653. sdata->vif.bss_conf.dtim_period = bss->dtim_period;
  654. bss_info_changed |= ieee80211_handle_bss_capability(sdata,
  655. bss->capability, bss->has_erp_value, bss->erp_value);
  656. ieee80211_rx_bss_put(local, bss);
  657. }
  658. ifsta->flags |= IEEE80211_STA_PREV_BSSID_SET;
  659. memcpy(ifsta->prev_bssid, sdata->u.sta.bssid, ETH_ALEN);
  660. ieee80211_sta_send_associnfo(sdata, ifsta);
  661. ifsta->last_probe = jiffies;
  662. ieee80211_led_assoc(local, 1);
  663. sdata->vif.bss_conf.assoc = 1;
  664. /*
  665. * For now just always ask the driver to update the basic rateset
  666. * when we have associated, we aren't checking whether it actually
  667. * changed or not.
  668. */
  669. bss_info_changed |= BSS_CHANGED_BASIC_RATES;
  670. ieee80211_bss_info_change_notify(sdata, bss_info_changed);
  671. if (local->powersave &&
  672. !(local->hw.flags & IEEE80211_HW_NO_STACK_DYNAMIC_PS)) {
  673. if (local->dynamic_ps_timeout > 0)
  674. mod_timer(&local->dynamic_ps_timer, jiffies +
  675. msecs_to_jiffies(local->dynamic_ps_timeout));
  676. else {
  677. ieee80211_send_nullfunc(local, sdata, 1);
  678. conf->flags |= IEEE80211_CONF_PS;
  679. ieee80211_hw_config(local,
  680. IEEE80211_CONF_CHANGE_PS);
  681. }
  682. }
  683. netif_tx_start_all_queues(sdata->dev);
  684. netif_carrier_on(sdata->dev);
  685. ieee80211_sta_send_apinfo(sdata, ifsta);
  686. }
  687. static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata,
  688. struct ieee80211_if_sta *ifsta)
  689. {
  690. ifsta->direct_probe_tries++;
  691. if (ifsta->direct_probe_tries > IEEE80211_AUTH_MAX_TRIES) {
  692. printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n",
  693. sdata->dev->name, ifsta->bssid);
  694. ifsta->state = IEEE80211_STA_MLME_DISABLED;
  695. ieee80211_sta_send_apinfo(sdata, ifsta);
  696. return;
  697. }
  698. printk(KERN_DEBUG "%s: direct probe to AP %pM try %d\n",
  699. sdata->dev->name, ifsta->bssid,
  700. ifsta->direct_probe_tries);
  701. ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE;
  702. set_bit(IEEE80211_STA_REQ_DIRECT_PROBE, &ifsta->request);
  703. /* Direct probe is sent to broadcast address as some APs
  704. * will not answer to direct packet in unassociated state.
  705. */
  706. ieee80211_send_probe_req(sdata, NULL,
  707. ifsta->ssid, ifsta->ssid_len);
  708. mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
  709. }
  710. static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata,
  711. struct ieee80211_if_sta *ifsta)
  712. {
  713. ifsta->auth_tries++;
  714. if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
  715. printk(KERN_DEBUG "%s: authentication with AP %pM"
  716. " timed out\n",
  717. sdata->dev->name, ifsta->bssid);
  718. ifsta->state = IEEE80211_STA_MLME_DISABLED;
  719. ieee80211_sta_send_apinfo(sdata, ifsta);
  720. return;
  721. }
  722. ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE;
  723. printk(KERN_DEBUG "%s: authenticate with AP %pM\n",
  724. sdata->dev->name, ifsta->bssid);
  725. ieee80211_send_auth(sdata, ifsta, 1, NULL, 0, 0);
  726. mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
  727. }
  728. /*
  729. * The disassoc 'reason' argument can be either our own reason
  730. * if self disconnected or a reason code from the AP.
  731. */
  732. static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
  733. struct ieee80211_if_sta *ifsta, bool deauth,
  734. bool self_disconnected, u16 reason)
  735. {
  736. struct ieee80211_local *local = sdata->local;
  737. struct sta_info *sta;
  738. u32 changed = 0, config_changed = 0;
  739. rcu_read_lock();
  740. sta = sta_info_get(local, ifsta->bssid);
  741. if (!sta) {
  742. rcu_read_unlock();
  743. return;
  744. }
  745. if (deauth) {
  746. ifsta->direct_probe_tries = 0;
  747. ifsta->auth_tries = 0;
  748. }
  749. ifsta->assoc_scan_tries = 0;
  750. ifsta->assoc_tries = 0;
  751. netif_tx_stop_all_queues(sdata->dev);
  752. netif_carrier_off(sdata->dev);
  753. ieee80211_sta_tear_down_BA_sessions(sdata, sta->sta.addr);
  754. if (self_disconnected) {
  755. if (deauth)
  756. ieee80211_send_deauth_disassoc(sdata,
  757. IEEE80211_STYPE_DEAUTH, reason);
  758. else
  759. ieee80211_send_deauth_disassoc(sdata,
  760. IEEE80211_STYPE_DISASSOC, reason);
  761. }
  762. ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
  763. changed |= ieee80211_reset_erp_info(sdata);
  764. ieee80211_led_assoc(local, 0);
  765. changed |= BSS_CHANGED_ASSOC;
  766. sdata->vif.bss_conf.assoc = false;
  767. ieee80211_sta_send_apinfo(sdata, ifsta);
  768. if (self_disconnected || reason == WLAN_REASON_DISASSOC_STA_HAS_LEFT)
  769. ifsta->state = IEEE80211_STA_MLME_DISABLED;
  770. rcu_read_unlock();
  771. local->oper_channel_type = NL80211_CHAN_NO_HT;
  772. config_changed |= IEEE80211_CONF_CHANGE_HT;
  773. del_timer_sync(&local->dynamic_ps_timer);
  774. cancel_work_sync(&local->dynamic_ps_enable_work);
  775. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  776. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  777. config_changed |= IEEE80211_CONF_CHANGE_PS;
  778. }
  779. ieee80211_hw_config(local, config_changed);
  780. ieee80211_bss_info_change_notify(sdata, changed);
  781. rcu_read_lock();
  782. sta = sta_info_get(local, ifsta->bssid);
  783. if (!sta) {
  784. rcu_read_unlock();
  785. return;
  786. }
  787. sta_info_unlink(&sta);
  788. rcu_read_unlock();
  789. sta_info_destroy(sta);
  790. }
  791. static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data *sdata)
  792. {
  793. if (!sdata || !sdata->default_key ||
  794. sdata->default_key->conf.alg != ALG_WEP)
  795. return 0;
  796. return 1;
  797. }
  798. static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata,
  799. struct ieee80211_if_sta *ifsta)
  800. {
  801. struct ieee80211_local *local = sdata->local;
  802. struct ieee80211_bss *bss;
  803. int bss_privacy;
  804. int wep_privacy;
  805. int privacy_invoked;
  806. if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL))
  807. return 0;
  808. bss = ieee80211_rx_bss_get(local, ifsta->bssid,
  809. local->hw.conf.channel->center_freq,
  810. ifsta->ssid, ifsta->ssid_len);
  811. if (!bss)
  812. return 0;
  813. bss_privacy = !!(bss->capability & WLAN_CAPABILITY_PRIVACY);
  814. wep_privacy = !!ieee80211_sta_wep_configured(sdata);
  815. privacy_invoked = !!(ifsta->flags & IEEE80211_STA_PRIVACY_INVOKED);
  816. ieee80211_rx_bss_put(local, bss);
  817. if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
  818. return 0;
  819. return 1;
  820. }
  821. static void ieee80211_associate(struct ieee80211_sub_if_data *sdata,
  822. struct ieee80211_if_sta *ifsta)
  823. {
  824. ifsta->assoc_tries++;
  825. if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
  826. printk(KERN_DEBUG "%s: association with AP %pM"
  827. " timed out\n",
  828. sdata->dev->name, ifsta->bssid);
  829. ifsta->state = IEEE80211_STA_MLME_DISABLED;
  830. ieee80211_sta_send_apinfo(sdata, ifsta);
  831. return;
  832. }
  833. ifsta->state = IEEE80211_STA_MLME_ASSOCIATE;
  834. printk(KERN_DEBUG "%s: associate with AP %pM\n",
  835. sdata->dev->name, ifsta->bssid);
  836. if (ieee80211_privacy_mismatch(sdata, ifsta)) {
  837. printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
  838. "mixed-cell disabled - abort association\n", sdata->dev->name);
  839. ifsta->state = IEEE80211_STA_MLME_DISABLED;
  840. return;
  841. }
  842. ieee80211_send_assoc(sdata, ifsta);
  843. mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
  844. }
  845. static void ieee80211_associated(struct ieee80211_sub_if_data *sdata,
  846. struct ieee80211_if_sta *ifsta)
  847. {
  848. struct ieee80211_local *local = sdata->local;
  849. struct sta_info *sta;
  850. int disassoc;
  851. /* TODO: start monitoring current AP signal quality and number of
  852. * missed beacons. Scan other channels every now and then and search
  853. * for better APs. */
  854. /* TODO: remove expired BSSes */
  855. ifsta->state = IEEE80211_STA_MLME_ASSOCIATED;
  856. rcu_read_lock();
  857. sta = sta_info_get(local, ifsta->bssid);
  858. if (!sta) {
  859. printk(KERN_DEBUG "%s: No STA entry for own AP %pM\n",
  860. sdata->dev->name, ifsta->bssid);
  861. disassoc = 1;
  862. } else {
  863. disassoc = 0;
  864. if (time_after(jiffies,
  865. sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
  866. if (ifsta->flags & IEEE80211_STA_PROBEREQ_POLL) {
  867. printk(KERN_DEBUG "%s: No ProbeResp from "
  868. "current AP %pM - assume out of "
  869. "range\n",
  870. sdata->dev->name, ifsta->bssid);
  871. disassoc = 1;
  872. } else
  873. ieee80211_send_probe_req(sdata, ifsta->bssid,
  874. ifsta->ssid,
  875. ifsta->ssid_len);
  876. ifsta->flags ^= IEEE80211_STA_PROBEREQ_POLL;
  877. } else {
  878. ifsta->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
  879. if (time_after(jiffies, ifsta->last_probe +
  880. IEEE80211_PROBE_INTERVAL)) {
  881. ifsta->last_probe = jiffies;
  882. ieee80211_send_probe_req(sdata, ifsta->bssid,
  883. ifsta->ssid,
  884. ifsta->ssid_len);
  885. }
  886. }
  887. }
  888. rcu_read_unlock();
  889. if (disassoc)
  890. ieee80211_set_disassoc(sdata, ifsta, true, true,
  891. WLAN_REASON_PREV_AUTH_NOT_VALID);
  892. else
  893. mod_timer(&ifsta->timer, jiffies +
  894. IEEE80211_MONITORING_INTERVAL);
  895. }
  896. static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata,
  897. struct ieee80211_if_sta *ifsta)
  898. {
  899. printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name);
  900. ifsta->flags |= IEEE80211_STA_AUTHENTICATED;
  901. ieee80211_associate(sdata, ifsta);
  902. }
  903. static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
  904. struct ieee80211_if_sta *ifsta,
  905. struct ieee80211_mgmt *mgmt,
  906. size_t len)
  907. {
  908. u8 *pos;
  909. struct ieee802_11_elems elems;
  910. pos = mgmt->u.auth.variable;
  911. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
  912. if (!elems.challenge)
  913. return;
  914. ieee80211_send_auth(sdata, ifsta, 3, elems.challenge - 2,
  915. elems.challenge_len + 2, 1);
  916. }
  917. static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
  918. struct ieee80211_if_sta *ifsta,
  919. struct ieee80211_mgmt *mgmt,
  920. size_t len)
  921. {
  922. u16 auth_alg, auth_transaction, status_code;
  923. if (ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE &&
  924. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  925. return;
  926. if (len < 24 + 6)
  927. return;
  928. if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  929. memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0)
  930. return;
  931. if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  932. memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
  933. return;
  934. auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
  935. auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
  936. status_code = le16_to_cpu(mgmt->u.auth.status_code);
  937. if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  938. /*
  939. * IEEE 802.11 standard does not require authentication in IBSS
  940. * networks and most implementations do not seem to use it.
  941. * However, try to reply to authentication attempts if someone
  942. * has actually implemented this.
  943. */
  944. if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1)
  945. return;
  946. ieee80211_send_auth(sdata, ifsta, 2, NULL, 0, 0);
  947. }
  948. if (auth_alg != ifsta->auth_alg ||
  949. auth_transaction != ifsta->auth_transaction)
  950. return;
  951. if (status_code != WLAN_STATUS_SUCCESS) {
  952. if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
  953. u8 algs[3];
  954. const int num_algs = ARRAY_SIZE(algs);
  955. int i, pos;
  956. algs[0] = algs[1] = algs[2] = 0xff;
  957. if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
  958. algs[0] = WLAN_AUTH_OPEN;
  959. if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
  960. algs[1] = WLAN_AUTH_SHARED_KEY;
  961. if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
  962. algs[2] = WLAN_AUTH_LEAP;
  963. if (ifsta->auth_alg == WLAN_AUTH_OPEN)
  964. pos = 0;
  965. else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY)
  966. pos = 1;
  967. else
  968. pos = 2;
  969. for (i = 0; i < num_algs; i++) {
  970. pos++;
  971. if (pos >= num_algs)
  972. pos = 0;
  973. if (algs[pos] == ifsta->auth_alg ||
  974. algs[pos] == 0xff)
  975. continue;
  976. if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
  977. !ieee80211_sta_wep_configured(sdata))
  978. continue;
  979. ifsta->auth_alg = algs[pos];
  980. break;
  981. }
  982. }
  983. return;
  984. }
  985. switch (ifsta->auth_alg) {
  986. case WLAN_AUTH_OPEN:
  987. case WLAN_AUTH_LEAP:
  988. ieee80211_auth_completed(sdata, ifsta);
  989. break;
  990. case WLAN_AUTH_SHARED_KEY:
  991. if (ifsta->auth_transaction == 4)
  992. ieee80211_auth_completed(sdata, ifsta);
  993. else
  994. ieee80211_auth_challenge(sdata, ifsta, mgmt, len);
  995. break;
  996. }
  997. }
  998. static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
  999. struct ieee80211_if_sta *ifsta,
  1000. struct ieee80211_mgmt *mgmt,
  1001. size_t len)
  1002. {
  1003. u16 reason_code;
  1004. if (len < 24 + 2)
  1005. return;
  1006. if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN))
  1007. return;
  1008. reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
  1009. if (ifsta->flags & IEEE80211_STA_AUTHENTICATED)
  1010. printk(KERN_DEBUG "%s: deauthenticated (Reason: %u)\n",
  1011. sdata->dev->name, reason_code);
  1012. if (ifsta->state == IEEE80211_STA_MLME_AUTHENTICATE ||
  1013. ifsta->state == IEEE80211_STA_MLME_ASSOCIATE ||
  1014. ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) {
  1015. ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE;
  1016. mod_timer(&ifsta->timer, jiffies +
  1017. IEEE80211_RETRY_AUTH_INTERVAL);
  1018. }
  1019. ieee80211_set_disassoc(sdata, ifsta, true, false, 0);
  1020. ifsta->flags &= ~IEEE80211_STA_AUTHENTICATED;
  1021. }
  1022. static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
  1023. struct ieee80211_if_sta *ifsta,
  1024. struct ieee80211_mgmt *mgmt,
  1025. size_t len)
  1026. {
  1027. u16 reason_code;
  1028. if (len < 24 + 2)
  1029. return;
  1030. if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN))
  1031. return;
  1032. reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
  1033. if (ifsta->flags & IEEE80211_STA_ASSOCIATED)
  1034. printk(KERN_DEBUG "%s: disassociated (Reason: %u)\n",
  1035. sdata->dev->name, reason_code);
  1036. if (ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) {
  1037. ifsta->state = IEEE80211_STA_MLME_ASSOCIATE;
  1038. mod_timer(&ifsta->timer, jiffies +
  1039. IEEE80211_RETRY_AUTH_INTERVAL);
  1040. }
  1041. ieee80211_set_disassoc(sdata, ifsta, false, false, reason_code);
  1042. }
  1043. static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
  1044. struct ieee80211_if_sta *ifsta,
  1045. struct ieee80211_mgmt *mgmt,
  1046. size_t len,
  1047. int reassoc)
  1048. {
  1049. struct ieee80211_local *local = sdata->local;
  1050. struct ieee80211_supported_band *sband;
  1051. struct sta_info *sta;
  1052. u64 rates, basic_rates;
  1053. u16 capab_info, status_code, aid;
  1054. struct ieee802_11_elems elems;
  1055. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  1056. u8 *pos;
  1057. u32 changed = 0;
  1058. int i, j;
  1059. bool have_higher_than_11mbit = false, newsta = false;
  1060. u16 ap_ht_cap_flags;
  1061. /* AssocResp and ReassocResp have identical structure, so process both
  1062. * of them in this function. */
  1063. if (ifsta->state != IEEE80211_STA_MLME_ASSOCIATE)
  1064. return;
  1065. if (len < 24 + 6)
  1066. return;
  1067. if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0)
  1068. return;
  1069. capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
  1070. status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
  1071. aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
  1072. printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x "
  1073. "status=%d aid=%d)\n",
  1074. sdata->dev->name, reassoc ? "Rea" : "A", mgmt->sa,
  1075. capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
  1076. if (status_code != WLAN_STATUS_SUCCESS) {
  1077. printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
  1078. sdata->dev->name, status_code);
  1079. /* if this was a reassociation, ensure we try a "full"
  1080. * association next time. This works around some broken APs
  1081. * which do not correctly reject reassociation requests. */
  1082. ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
  1083. return;
  1084. }
  1085. if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
  1086. printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
  1087. "set\n", sdata->dev->name, aid);
  1088. aid &= ~(BIT(15) | BIT(14));
  1089. pos = mgmt->u.assoc_resp.variable;
  1090. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
  1091. if (!elems.supp_rates) {
  1092. printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
  1093. sdata->dev->name);
  1094. return;
  1095. }
  1096. printk(KERN_DEBUG "%s: associated\n", sdata->dev->name);
  1097. ifsta->aid = aid;
  1098. ifsta->ap_capab = capab_info;
  1099. kfree(ifsta->assocresp_ies);
  1100. ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt);
  1101. ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_KERNEL);
  1102. if (ifsta->assocresp_ies)
  1103. memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len);
  1104. rcu_read_lock();
  1105. /* Add STA entry for the AP */
  1106. sta = sta_info_get(local, ifsta->bssid);
  1107. if (!sta) {
  1108. struct ieee80211_bss *bss;
  1109. newsta = true;
  1110. sta = sta_info_alloc(sdata, ifsta->bssid, GFP_ATOMIC);
  1111. if (!sta) {
  1112. printk(KERN_DEBUG "%s: failed to alloc STA entry for"
  1113. " the AP\n", sdata->dev->name);
  1114. rcu_read_unlock();
  1115. return;
  1116. }
  1117. bss = ieee80211_rx_bss_get(local, ifsta->bssid,
  1118. local->hw.conf.channel->center_freq,
  1119. ifsta->ssid, ifsta->ssid_len);
  1120. if (bss) {
  1121. sta->last_signal = bss->signal;
  1122. sta->last_qual = bss->qual;
  1123. sta->last_noise = bss->noise;
  1124. ieee80211_rx_bss_put(local, bss);
  1125. }
  1126. /* update new sta with its last rx activity */
  1127. sta->last_rx = jiffies;
  1128. }
  1129. /*
  1130. * FIXME: Do we really need to update the sta_info's information here?
  1131. * We already know about the AP (we found it in our list) so it
  1132. * should already be filled with the right info, no?
  1133. * As is stands, all this is racy because typically we assume
  1134. * the information that is filled in here (except flags) doesn't
  1135. * change while a STA structure is alive. As such, it should move
  1136. * to between the sta_info_alloc() and sta_info_insert() above.
  1137. */
  1138. set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
  1139. WLAN_STA_AUTHORIZED);
  1140. rates = 0;
  1141. basic_rates = 0;
  1142. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1143. for (i = 0; i < elems.supp_rates_len; i++) {
  1144. int rate = (elems.supp_rates[i] & 0x7f) * 5;
  1145. bool is_basic = !!(elems.supp_rates[i] & 0x80);
  1146. if (rate > 110)
  1147. have_higher_than_11mbit = true;
  1148. for (j = 0; j < sband->n_bitrates; j++) {
  1149. if (sband->bitrates[j].bitrate == rate) {
  1150. rates |= BIT(j);
  1151. if (is_basic)
  1152. basic_rates |= BIT(j);
  1153. break;
  1154. }
  1155. }
  1156. }
  1157. for (i = 0; i < elems.ext_supp_rates_len; i++) {
  1158. int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
  1159. bool is_basic = !!(elems.supp_rates[i] & 0x80);
  1160. if (rate > 110)
  1161. have_higher_than_11mbit = true;
  1162. for (j = 0; j < sband->n_bitrates; j++) {
  1163. if (sband->bitrates[j].bitrate == rate) {
  1164. rates |= BIT(j);
  1165. if (is_basic)
  1166. basic_rates |= BIT(j);
  1167. break;
  1168. }
  1169. }
  1170. }
  1171. sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
  1172. sdata->vif.bss_conf.basic_rates = basic_rates;
  1173. /* cf. IEEE 802.11 9.2.12 */
  1174. if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
  1175. have_higher_than_11mbit)
  1176. sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
  1177. else
  1178. sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
  1179. if (elems.ht_cap_elem)
  1180. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  1181. elems.ht_cap_elem, &sta->sta.ht_cap);
  1182. ap_ht_cap_flags = sta->sta.ht_cap.cap;
  1183. rate_control_rate_init(sta);
  1184. if (elems.wmm_param)
  1185. set_sta_flags(sta, WLAN_STA_WME);
  1186. if (newsta) {
  1187. int err = sta_info_insert(sta);
  1188. if (err) {
  1189. printk(KERN_DEBUG "%s: failed to insert STA entry for"
  1190. " the AP (error %d)\n", sdata->dev->name, err);
  1191. rcu_read_unlock();
  1192. return;
  1193. }
  1194. }
  1195. rcu_read_unlock();
  1196. if (elems.wmm_param)
  1197. ieee80211_sta_wmm_params(local, ifsta, elems.wmm_param,
  1198. elems.wmm_param_len);
  1199. if (elems.ht_info_elem && elems.wmm_param &&
  1200. (ifsta->flags & IEEE80211_STA_WMM_ENABLED))
  1201. changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
  1202. ap_ht_cap_flags);
  1203. /* set AID and assoc capability,
  1204. * ieee80211_set_associated() will tell the driver */
  1205. bss_conf->aid = aid;
  1206. bss_conf->assoc_capability = capab_info;
  1207. ieee80211_set_associated(sdata, ifsta, changed);
  1208. ieee80211_associated(sdata, ifsta);
  1209. }
  1210. static int ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
  1211. struct ieee80211_if_sta *ifsta,
  1212. struct ieee80211_bss *bss)
  1213. {
  1214. struct ieee80211_local *local = sdata->local;
  1215. int res, rates, i, j;
  1216. struct sk_buff *skb;
  1217. struct ieee80211_mgmt *mgmt;
  1218. u8 *pos;
  1219. struct ieee80211_supported_band *sband;
  1220. union iwreq_data wrqu;
  1221. skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
  1222. if (!skb) {
  1223. printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
  1224. "response\n", sdata->dev->name);
  1225. return -ENOMEM;
  1226. }
  1227. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1228. /* Remove possible STA entries from other IBSS networks. */
  1229. sta_info_flush_delayed(sdata);
  1230. if (local->ops->reset_tsf) {
  1231. /* Reset own TSF to allow time synchronization work. */
  1232. local->ops->reset_tsf(local_to_hw(local));
  1233. }
  1234. memcpy(ifsta->bssid, bss->bssid, ETH_ALEN);
  1235. res = ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID);
  1236. if (res)
  1237. return res;
  1238. local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
  1239. sdata->drop_unencrypted = bss->capability &
  1240. WLAN_CAPABILITY_PRIVACY ? 1 : 0;
  1241. res = ieee80211_set_freq(sdata, bss->freq);
  1242. if (res)
  1243. return res;
  1244. /* Build IBSS probe response */
  1245. skb_reserve(skb, local->hw.extra_tx_headroom);
  1246. mgmt = (struct ieee80211_mgmt *)
  1247. skb_put(skb, 24 + sizeof(mgmt->u.beacon));
  1248. memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
  1249. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1250. IEEE80211_STYPE_PROBE_RESP);
  1251. memset(mgmt->da, 0xff, ETH_ALEN);
  1252. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  1253. memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
  1254. mgmt->u.beacon.beacon_int =
  1255. cpu_to_le16(local->hw.conf.beacon_int);
  1256. mgmt->u.beacon.timestamp = cpu_to_le64(bss->timestamp);
  1257. mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
  1258. pos = skb_put(skb, 2 + ifsta->ssid_len);
  1259. *pos++ = WLAN_EID_SSID;
  1260. *pos++ = ifsta->ssid_len;
  1261. memcpy(pos, ifsta->ssid, ifsta->ssid_len);
  1262. rates = bss->supp_rates_len;
  1263. if (rates > 8)
  1264. rates = 8;
  1265. pos = skb_put(skb, 2 + rates);
  1266. *pos++ = WLAN_EID_SUPP_RATES;
  1267. *pos++ = rates;
  1268. memcpy(pos, bss->supp_rates, rates);
  1269. if (bss->band == IEEE80211_BAND_2GHZ) {
  1270. pos = skb_put(skb, 2 + 1);
  1271. *pos++ = WLAN_EID_DS_PARAMS;
  1272. *pos++ = 1;
  1273. *pos++ = ieee80211_frequency_to_channel(bss->freq);
  1274. }
  1275. pos = skb_put(skb, 2 + 2);
  1276. *pos++ = WLAN_EID_IBSS_PARAMS;
  1277. *pos++ = 2;
  1278. /* FIX: set ATIM window based on scan results */
  1279. *pos++ = 0;
  1280. *pos++ = 0;
  1281. if (bss->supp_rates_len > 8) {
  1282. rates = bss->supp_rates_len - 8;
  1283. pos = skb_put(skb, 2 + rates);
  1284. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  1285. *pos++ = rates;
  1286. memcpy(pos, &bss->supp_rates[8], rates);
  1287. }
  1288. ifsta->probe_resp = skb;
  1289. ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
  1290. rates = 0;
  1291. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1292. for (i = 0; i < bss->supp_rates_len; i++) {
  1293. int bitrate = (bss->supp_rates[i] & 0x7f) * 5;
  1294. for (j = 0; j < sband->n_bitrates; j++)
  1295. if (sband->bitrates[j].bitrate == bitrate)
  1296. rates |= BIT(j);
  1297. }
  1298. ifsta->supp_rates_bits[local->hw.conf.channel->band] = rates;
  1299. ieee80211_sta_def_wmm_params(sdata, bss);
  1300. ifsta->state = IEEE80211_STA_MLME_IBSS_JOINED;
  1301. mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
  1302. ieee80211_led_assoc(local, true);
  1303. memset(&wrqu, 0, sizeof(wrqu));
  1304. memcpy(wrqu.ap_addr.sa_data, bss->bssid, ETH_ALEN);
  1305. wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL);
  1306. return res;
  1307. }
  1308. static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
  1309. struct ieee80211_mgmt *mgmt,
  1310. size_t len,
  1311. struct ieee80211_rx_status *rx_status,
  1312. struct ieee802_11_elems *elems,
  1313. bool beacon)
  1314. {
  1315. struct ieee80211_local *local = sdata->local;
  1316. int freq;
  1317. struct ieee80211_bss *bss;
  1318. struct sta_info *sta;
  1319. struct ieee80211_channel *channel;
  1320. u64 beacon_timestamp, rx_timestamp;
  1321. u64 supp_rates = 0;
  1322. enum ieee80211_band band = rx_status->band;
  1323. if (elems->ds_params && elems->ds_params_len == 1)
  1324. freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
  1325. else
  1326. freq = rx_status->freq;
  1327. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  1328. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  1329. return;
  1330. if (sdata->vif.type == NL80211_IFTYPE_ADHOC && elems->supp_rates &&
  1331. memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0) {
  1332. supp_rates = ieee80211_sta_get_rates(local, elems, band);
  1333. rcu_read_lock();
  1334. sta = sta_info_get(local, mgmt->sa);
  1335. if (sta) {
  1336. u64 prev_rates;
  1337. prev_rates = sta->sta.supp_rates[band];
  1338. /* make sure mandatory rates are always added */
  1339. sta->sta.supp_rates[band] = supp_rates |
  1340. ieee80211_mandatory_rates(local, band);
  1341. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  1342. if (sta->sta.supp_rates[band] != prev_rates)
  1343. printk(KERN_DEBUG "%s: updated supp_rates set "
  1344. "for %pM based on beacon info (0x%llx | "
  1345. "0x%llx -> 0x%llx)\n",
  1346. sdata->dev->name,
  1347. sta->sta.addr,
  1348. (unsigned long long) prev_rates,
  1349. (unsigned long long) supp_rates,
  1350. (unsigned long long) sta->sta.supp_rates[band]);
  1351. #endif
  1352. } else {
  1353. ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa, supp_rates);
  1354. }
  1355. rcu_read_unlock();
  1356. }
  1357. bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
  1358. freq, beacon);
  1359. if (!bss)
  1360. return;
  1361. if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
  1362. (memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0)) {
  1363. struct ieee80211_channel_sw_ie *sw_elem =
  1364. (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
  1365. ieee80211_process_chanswitch(sdata, sw_elem, bss);
  1366. }
  1367. /* was just updated in ieee80211_bss_info_update */
  1368. beacon_timestamp = bss->timestamp;
  1369. /*
  1370. * In STA mode, the remaining parameters should not be overridden
  1371. * by beacons because they're not necessarily accurate there.
  1372. */
  1373. if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  1374. bss->last_probe_resp && beacon) {
  1375. ieee80211_rx_bss_put(local, bss);
  1376. return;
  1377. }
  1378. /* check if we need to merge IBSS */
  1379. if (sdata->vif.type == NL80211_IFTYPE_ADHOC && beacon &&
  1380. (!(sdata->u.sta.flags & IEEE80211_STA_BSSID_SET)) &&
  1381. bss->capability & WLAN_CAPABILITY_IBSS &&
  1382. bss->freq == local->oper_channel->center_freq &&
  1383. elems->ssid_len == sdata->u.sta.ssid_len &&
  1384. memcmp(elems->ssid, sdata->u.sta.ssid,
  1385. sdata->u.sta.ssid_len) == 0) {
  1386. if (rx_status->flag & RX_FLAG_TSFT) {
  1387. /* in order for correct IBSS merging we need mactime
  1388. *
  1389. * since mactime is defined as the time the first data
  1390. * symbol of the frame hits the PHY, and the timestamp
  1391. * of the beacon is defined as "the time that the data
  1392. * symbol containing the first bit of the timestamp is
  1393. * transmitted to the PHY plus the transmitting STA’s
  1394. * delays through its local PHY from the MAC-PHY
  1395. * interface to its interface with the WM"
  1396. * (802.11 11.1.2) - equals the time this bit arrives at
  1397. * the receiver - we have to take into account the
  1398. * offset between the two.
  1399. * e.g: at 1 MBit that means mactime is 192 usec earlier
  1400. * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
  1401. */
  1402. int rate;
  1403. if (rx_status->flag & RX_FLAG_HT) {
  1404. rate = 65; /* TODO: HT rates */
  1405. } else {
  1406. rate = local->hw.wiphy->bands[band]->
  1407. bitrates[rx_status->rate_idx].bitrate;
  1408. }
  1409. rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate);
  1410. } else if (local && local->ops && local->ops->get_tsf)
  1411. /* second best option: get current TSF */
  1412. rx_timestamp = local->ops->get_tsf(local_to_hw(local));
  1413. else
  1414. /* can't merge without knowing the TSF */
  1415. rx_timestamp = -1LLU;
  1416. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  1417. printk(KERN_DEBUG "RX beacon SA=%pM BSSID="
  1418. "%pM TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
  1419. mgmt->sa, mgmt->bssid,
  1420. (unsigned long long)rx_timestamp,
  1421. (unsigned long long)beacon_timestamp,
  1422. (unsigned long long)(rx_timestamp - beacon_timestamp),
  1423. jiffies);
  1424. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  1425. if (beacon_timestamp > rx_timestamp) {
  1426. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  1427. printk(KERN_DEBUG "%s: beacon TSF higher than "
  1428. "local TSF - IBSS merge with BSSID %pM\n",
  1429. sdata->dev->name, mgmt->bssid);
  1430. #endif
  1431. ieee80211_sta_join_ibss(sdata, &sdata->u.sta, bss);
  1432. ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa, supp_rates);
  1433. }
  1434. }
  1435. ieee80211_rx_bss_put(local, bss);
  1436. }
  1437. static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
  1438. struct ieee80211_mgmt *mgmt,
  1439. size_t len,
  1440. struct ieee80211_rx_status *rx_status)
  1441. {
  1442. size_t baselen;
  1443. struct ieee802_11_elems elems;
  1444. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  1445. if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
  1446. return; /* ignore ProbeResp to foreign address */
  1447. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  1448. if (baselen > len)
  1449. return;
  1450. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  1451. &elems);
  1452. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
  1453. /* direct probe may be part of the association flow */
  1454. if (test_and_clear_bit(IEEE80211_STA_REQ_DIRECT_PROBE,
  1455. &ifsta->request)) {
  1456. printk(KERN_DEBUG "%s direct probe responded\n",
  1457. sdata->dev->name);
  1458. ieee80211_authenticate(sdata, ifsta);
  1459. }
  1460. }
  1461. static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
  1462. struct ieee80211_mgmt *mgmt,
  1463. size_t len,
  1464. struct ieee80211_rx_status *rx_status)
  1465. {
  1466. struct ieee80211_if_sta *ifsta;
  1467. size_t baselen;
  1468. struct ieee802_11_elems elems;
  1469. struct ieee80211_local *local = sdata->local;
  1470. u32 changed = 0;
  1471. bool erp_valid, directed_tim, is_mc = false;
  1472. u8 erp_value = 0;
  1473. /* Process beacon from the current BSS */
  1474. baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
  1475. if (baselen > len)
  1476. return;
  1477. ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
  1478. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true);
  1479. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1480. return;
  1481. ifsta = &sdata->u.sta;
  1482. if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED) ||
  1483. memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
  1484. return;
  1485. if (rx_status->freq != local->hw.conf.channel->center_freq)
  1486. return;
  1487. ieee80211_sta_wmm_params(local, ifsta, elems.wmm_param,
  1488. elems.wmm_param_len);
  1489. if (!(local->hw.flags & IEEE80211_HW_NO_STACK_DYNAMIC_PS)) {
  1490. directed_tim = check_tim(&elems, ifsta->aid, &is_mc);
  1491. if (directed_tim || is_mc) {
  1492. if (local->hw.conf.flags && IEEE80211_CONF_PS) {
  1493. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  1494. ieee80211_hw_config(local,
  1495. IEEE80211_CONF_CHANGE_PS);
  1496. ieee80211_send_nullfunc(local, sdata, 0);
  1497. }
  1498. }
  1499. }
  1500. if (elems.erp_info && elems.erp_info_len >= 1) {
  1501. erp_valid = true;
  1502. erp_value = elems.erp_info[0];
  1503. } else {
  1504. erp_valid = false;
  1505. }
  1506. changed |= ieee80211_handle_bss_capability(sdata,
  1507. le16_to_cpu(mgmt->u.beacon.capab_info),
  1508. erp_valid, erp_value);
  1509. if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param) {
  1510. struct sta_info *sta;
  1511. struct ieee80211_supported_band *sband;
  1512. u16 ap_ht_cap_flags;
  1513. rcu_read_lock();
  1514. sta = sta_info_get(local, ifsta->bssid);
  1515. if (!sta) {
  1516. rcu_read_unlock();
  1517. return;
  1518. }
  1519. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1520. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  1521. elems.ht_cap_elem, &sta->sta.ht_cap);
  1522. ap_ht_cap_flags = sta->sta.ht_cap.cap;
  1523. rcu_read_unlock();
  1524. changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
  1525. ap_ht_cap_flags);
  1526. }
  1527. if (elems.country_elem) {
  1528. /* Note we are only reviewing this on beacons
  1529. * for the BSSID we are associated to */
  1530. regulatory_hint_11d(local->hw.wiphy,
  1531. elems.country_elem, elems.country_elem_len);
  1532. }
  1533. ieee80211_bss_info_change_notify(sdata, changed);
  1534. }
  1535. static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
  1536. struct ieee80211_if_sta *ifsta,
  1537. struct ieee80211_mgmt *mgmt,
  1538. size_t len,
  1539. struct ieee80211_rx_status *rx_status)
  1540. {
  1541. struct ieee80211_local *local = sdata->local;
  1542. int tx_last_beacon;
  1543. struct sk_buff *skb;
  1544. struct ieee80211_mgmt *resp;
  1545. u8 *pos, *end;
  1546. if (sdata->vif.type != NL80211_IFTYPE_ADHOC ||
  1547. ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED ||
  1548. len < 24 + 2 || !ifsta->probe_resp)
  1549. return;
  1550. if (local->ops->tx_last_beacon)
  1551. tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local));
  1552. else
  1553. tx_last_beacon = 1;
  1554. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  1555. printk(KERN_DEBUG "%s: RX ProbeReq SA=%pM DA=%pM BSSID=%pM"
  1556. " (tx_last_beacon=%d)\n",
  1557. sdata->dev->name, mgmt->sa, mgmt->da,
  1558. mgmt->bssid, tx_last_beacon);
  1559. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  1560. if (!tx_last_beacon)
  1561. return;
  1562. if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 &&
  1563. memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0)
  1564. return;
  1565. end = ((u8 *) mgmt) + len;
  1566. pos = mgmt->u.probe_req.variable;
  1567. if (pos[0] != WLAN_EID_SSID ||
  1568. pos + 2 + pos[1] > end) {
  1569. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  1570. printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq "
  1571. "from %pM\n",
  1572. sdata->dev->name, mgmt->sa);
  1573. #endif
  1574. return;
  1575. }
  1576. if (pos[1] != 0 &&
  1577. (pos[1] != ifsta->ssid_len ||
  1578. memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) {
  1579. /* Ignore ProbeReq for foreign SSID */
  1580. return;
  1581. }
  1582. /* Reply with ProbeResp */
  1583. skb = skb_copy(ifsta->probe_resp, GFP_KERNEL);
  1584. if (!skb)
  1585. return;
  1586. resp = (struct ieee80211_mgmt *) skb->data;
  1587. memcpy(resp->da, mgmt->sa, ETH_ALEN);
  1588. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  1589. printk(KERN_DEBUG "%s: Sending ProbeResp to %pM\n",
  1590. sdata->dev->name, resp->da);
  1591. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  1592. ieee80211_tx_skb(sdata, skb, 0);
  1593. }
  1594. void ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
  1595. struct ieee80211_rx_status *rx_status)
  1596. {
  1597. struct ieee80211_local *local = sdata->local;
  1598. struct ieee80211_if_sta *ifsta;
  1599. struct ieee80211_mgmt *mgmt;
  1600. u16 fc;
  1601. if (skb->len < 24)
  1602. goto fail;
  1603. ifsta = &sdata->u.sta;
  1604. mgmt = (struct ieee80211_mgmt *) skb->data;
  1605. fc = le16_to_cpu(mgmt->frame_control);
  1606. switch (fc & IEEE80211_FCTL_STYPE) {
  1607. case IEEE80211_STYPE_PROBE_REQ:
  1608. case IEEE80211_STYPE_PROBE_RESP:
  1609. case IEEE80211_STYPE_BEACON:
  1610. memcpy(skb->cb, rx_status, sizeof(*rx_status));
  1611. case IEEE80211_STYPE_AUTH:
  1612. case IEEE80211_STYPE_ASSOC_RESP:
  1613. case IEEE80211_STYPE_REASSOC_RESP:
  1614. case IEEE80211_STYPE_DEAUTH:
  1615. case IEEE80211_STYPE_DISASSOC:
  1616. skb_queue_tail(&ifsta->skb_queue, skb);
  1617. queue_work(local->hw.workqueue, &ifsta->work);
  1618. return;
  1619. }
  1620. fail:
  1621. kfree_skb(skb);
  1622. }
  1623. static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  1624. struct sk_buff *skb)
  1625. {
  1626. struct ieee80211_rx_status *rx_status;
  1627. struct ieee80211_if_sta *ifsta;
  1628. struct ieee80211_mgmt *mgmt;
  1629. u16 fc;
  1630. ifsta = &sdata->u.sta;
  1631. rx_status = (struct ieee80211_rx_status *) skb->cb;
  1632. mgmt = (struct ieee80211_mgmt *) skb->data;
  1633. fc = le16_to_cpu(mgmt->frame_control);
  1634. switch (fc & IEEE80211_FCTL_STYPE) {
  1635. case IEEE80211_STYPE_PROBE_REQ:
  1636. ieee80211_rx_mgmt_probe_req(sdata, ifsta, mgmt, skb->len,
  1637. rx_status);
  1638. break;
  1639. case IEEE80211_STYPE_PROBE_RESP:
  1640. ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len, rx_status);
  1641. break;
  1642. case IEEE80211_STYPE_BEACON:
  1643. ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
  1644. break;
  1645. case IEEE80211_STYPE_AUTH:
  1646. ieee80211_rx_mgmt_auth(sdata, ifsta, mgmt, skb->len);
  1647. break;
  1648. case IEEE80211_STYPE_ASSOC_RESP:
  1649. ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 0);
  1650. break;
  1651. case IEEE80211_STYPE_REASSOC_RESP:
  1652. ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 1);
  1653. break;
  1654. case IEEE80211_STYPE_DEAUTH:
  1655. ieee80211_rx_mgmt_deauth(sdata, ifsta, mgmt, skb->len);
  1656. break;
  1657. case IEEE80211_STYPE_DISASSOC:
  1658. ieee80211_rx_mgmt_disassoc(sdata, ifsta, mgmt, skb->len);
  1659. break;
  1660. }
  1661. kfree_skb(skb);
  1662. }
  1663. static int ieee80211_sta_active_ibss(struct ieee80211_sub_if_data *sdata)
  1664. {
  1665. struct ieee80211_local *local = sdata->local;
  1666. int active = 0;
  1667. struct sta_info *sta;
  1668. rcu_read_lock();
  1669. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  1670. if (sta->sdata == sdata &&
  1671. time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL,
  1672. jiffies)) {
  1673. active++;
  1674. break;
  1675. }
  1676. }
  1677. rcu_read_unlock();
  1678. return active;
  1679. }
  1680. static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata,
  1681. struct ieee80211_if_sta *ifsta)
  1682. {
  1683. mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
  1684. ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT);
  1685. if (ieee80211_sta_active_ibss(sdata))
  1686. return;
  1687. if ((sdata->u.sta.flags & IEEE80211_STA_BSSID_SET) &&
  1688. (!(sdata->u.sta.flags & IEEE80211_STA_AUTO_CHANNEL_SEL)))
  1689. return;
  1690. printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
  1691. "IBSS networks with same SSID (merge)\n", sdata->dev->name);
  1692. ieee80211_request_scan(sdata, ifsta->ssid, ifsta->ssid_len);
  1693. }
  1694. static void ieee80211_sta_timer(unsigned long data)
  1695. {
  1696. struct ieee80211_sub_if_data *sdata =
  1697. (struct ieee80211_sub_if_data *) data;
  1698. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  1699. struct ieee80211_local *local = sdata->local;
  1700. set_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
  1701. queue_work(local->hw.workqueue, &ifsta->work);
  1702. }
  1703. static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata,
  1704. struct ieee80211_if_sta *ifsta)
  1705. {
  1706. struct ieee80211_local *local = sdata->local;
  1707. if (local->ops->reset_tsf) {
  1708. /* Reset own TSF to allow time synchronization work. */
  1709. local->ops->reset_tsf(local_to_hw(local));
  1710. }
  1711. ifsta->wmm_last_param_set = -1; /* allow any WMM update */
  1712. if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
  1713. ifsta->auth_alg = WLAN_AUTH_OPEN;
  1714. else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
  1715. ifsta->auth_alg = WLAN_AUTH_SHARED_KEY;
  1716. else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
  1717. ifsta->auth_alg = WLAN_AUTH_LEAP;
  1718. else
  1719. ifsta->auth_alg = WLAN_AUTH_OPEN;
  1720. ifsta->auth_transaction = -1;
  1721. ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
  1722. ifsta->assoc_scan_tries = 0;
  1723. ifsta->direct_probe_tries = 0;
  1724. ifsta->auth_tries = 0;
  1725. ifsta->assoc_tries = 0;
  1726. netif_tx_stop_all_queues(sdata->dev);
  1727. netif_carrier_off(sdata->dev);
  1728. }
  1729. static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta,
  1730. const char *ssid, int ssid_len)
  1731. {
  1732. int tmp, hidden_ssid;
  1733. if (ssid_len == ifsta->ssid_len &&
  1734. !memcmp(ifsta->ssid, ssid, ssid_len))
  1735. return 1;
  1736. if (ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL)
  1737. return 0;
  1738. hidden_ssid = 1;
  1739. tmp = ssid_len;
  1740. while (tmp--) {
  1741. if (ssid[tmp] != '\0') {
  1742. hidden_ssid = 0;
  1743. break;
  1744. }
  1745. }
  1746. if (hidden_ssid && (ifsta->ssid_len == ssid_len || ssid_len == 0))
  1747. return 1;
  1748. if (ssid_len == 1 && ssid[0] == ' ')
  1749. return 1;
  1750. return 0;
  1751. }
  1752. static int ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata,
  1753. struct ieee80211_if_sta *ifsta)
  1754. {
  1755. struct ieee80211_local *local = sdata->local;
  1756. struct ieee80211_bss *bss;
  1757. struct ieee80211_supported_band *sband;
  1758. u8 bssid[ETH_ALEN], *pos;
  1759. int i;
  1760. int ret;
  1761. #if 0
  1762. /* Easier testing, use fixed BSSID. */
  1763. memset(bssid, 0xfe, ETH_ALEN);
  1764. #else
  1765. /* Generate random, not broadcast, locally administered BSSID. Mix in
  1766. * own MAC address to make sure that devices that do not have proper
  1767. * random number generator get different BSSID. */
  1768. get_random_bytes(bssid, ETH_ALEN);
  1769. for (i = 0; i < ETH_ALEN; i++)
  1770. bssid[i] ^= sdata->dev->dev_addr[i];
  1771. bssid[0] &= ~0x01;
  1772. bssid[0] |= 0x02;
  1773. #endif
  1774. printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %pM\n",
  1775. sdata->dev->name, bssid);
  1776. bss = ieee80211_rx_bss_add(local, bssid,
  1777. local->hw.conf.channel->center_freq,
  1778. sdata->u.sta.ssid, sdata->u.sta.ssid_len);
  1779. if (!bss)
  1780. return -ENOMEM;
  1781. bss->band = local->hw.conf.channel->band;
  1782. sband = local->hw.wiphy->bands[bss->band];
  1783. if (local->hw.conf.beacon_int == 0)
  1784. local->hw.conf.beacon_int = 100;
  1785. bss->beacon_int = local->hw.conf.beacon_int;
  1786. bss->last_update = jiffies;
  1787. bss->capability = WLAN_CAPABILITY_IBSS;
  1788. if (sdata->default_key)
  1789. bss->capability |= WLAN_CAPABILITY_PRIVACY;
  1790. else
  1791. sdata->drop_unencrypted = 0;
  1792. bss->supp_rates_len = sband->n_bitrates;
  1793. pos = bss->supp_rates;
  1794. for (i = 0; i < sband->n_bitrates; i++) {
  1795. int rate = sband->bitrates[i].bitrate;
  1796. *pos++ = (u8) (rate / 5);
  1797. }
  1798. ret = ieee80211_sta_join_ibss(sdata, ifsta, bss);
  1799. ieee80211_rx_bss_put(local, bss);
  1800. return ret;
  1801. }
  1802. static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata,
  1803. struct ieee80211_if_sta *ifsta)
  1804. {
  1805. struct ieee80211_local *local = sdata->local;
  1806. struct ieee80211_bss *bss;
  1807. int found = 0;
  1808. u8 bssid[ETH_ALEN];
  1809. int active_ibss;
  1810. if (ifsta->ssid_len == 0)
  1811. return -EINVAL;
  1812. active_ibss = ieee80211_sta_active_ibss(sdata);
  1813. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  1814. printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n",
  1815. sdata->dev->name, active_ibss);
  1816. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  1817. spin_lock_bh(&local->bss_lock);
  1818. list_for_each_entry(bss, &local->bss_list, list) {
  1819. if (ifsta->ssid_len != bss->ssid_len ||
  1820. memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0
  1821. || !(bss->capability & WLAN_CAPABILITY_IBSS))
  1822. continue;
  1823. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  1824. printk(KERN_DEBUG " bssid=%pM found\n", bss->bssid);
  1825. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  1826. memcpy(bssid, bss->bssid, ETH_ALEN);
  1827. found = 1;
  1828. if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0)
  1829. break;
  1830. }
  1831. spin_unlock_bh(&local->bss_lock);
  1832. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  1833. if (found)
  1834. printk(KERN_DEBUG " sta_find_ibss: selected %pM current "
  1835. "%pM\n", bssid, ifsta->bssid);
  1836. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  1837. if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) {
  1838. int ret;
  1839. int search_freq;
  1840. if (ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL)
  1841. search_freq = bss->freq;
  1842. else
  1843. search_freq = local->hw.conf.channel->center_freq;
  1844. bss = ieee80211_rx_bss_get(local, bssid, search_freq,
  1845. ifsta->ssid, ifsta->ssid_len);
  1846. if (!bss)
  1847. goto dont_join;
  1848. printk(KERN_DEBUG "%s: Selected IBSS BSSID %pM"
  1849. " based on configured SSID\n",
  1850. sdata->dev->name, bssid);
  1851. ret = ieee80211_sta_join_ibss(sdata, ifsta, bss);
  1852. ieee80211_rx_bss_put(local, bss);
  1853. return ret;
  1854. }
  1855. dont_join:
  1856. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  1857. printk(KERN_DEBUG " did not try to join ibss\n");
  1858. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  1859. /* Selected IBSS not found in current scan results - try to scan */
  1860. if (ifsta->state == IEEE80211_STA_MLME_IBSS_JOINED &&
  1861. !ieee80211_sta_active_ibss(sdata)) {
  1862. mod_timer(&ifsta->timer, jiffies +
  1863. IEEE80211_IBSS_MERGE_INTERVAL);
  1864. } else if (time_after(jiffies, local->last_scan_completed +
  1865. IEEE80211_SCAN_INTERVAL)) {
  1866. printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
  1867. "join\n", sdata->dev->name);
  1868. return ieee80211_request_scan(sdata, ifsta->ssid,
  1869. ifsta->ssid_len);
  1870. } else if (ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED) {
  1871. int interval = IEEE80211_SCAN_INTERVAL;
  1872. if (time_after(jiffies, ifsta->ibss_join_req +
  1873. IEEE80211_IBSS_JOIN_TIMEOUT)) {
  1874. if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) &&
  1875. (!(local->oper_channel->flags &
  1876. IEEE80211_CHAN_NO_IBSS)))
  1877. return ieee80211_sta_create_ibss(sdata, ifsta);
  1878. if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) {
  1879. printk(KERN_DEBUG "%s: IBSS not allowed on"
  1880. " %d MHz\n", sdata->dev->name,
  1881. local->hw.conf.channel->center_freq);
  1882. }
  1883. /* No IBSS found - decrease scan interval and continue
  1884. * scanning. */
  1885. interval = IEEE80211_SCAN_INTERVAL_SLOW;
  1886. }
  1887. ifsta->state = IEEE80211_STA_MLME_IBSS_SEARCH;
  1888. mod_timer(&ifsta->timer, jiffies + interval);
  1889. return 0;
  1890. }
  1891. return 0;
  1892. }
  1893. static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata,
  1894. struct ieee80211_if_sta *ifsta)
  1895. {
  1896. struct ieee80211_local *local = sdata->local;
  1897. struct ieee80211_bss *bss, *selected = NULL;
  1898. int top_rssi = 0, freq;
  1899. spin_lock_bh(&local->bss_lock);
  1900. freq = local->oper_channel->center_freq;
  1901. list_for_each_entry(bss, &local->bss_list, list) {
  1902. if (!(bss->capability & WLAN_CAPABILITY_ESS))
  1903. continue;
  1904. if ((ifsta->flags & (IEEE80211_STA_AUTO_SSID_SEL |
  1905. IEEE80211_STA_AUTO_BSSID_SEL |
  1906. IEEE80211_STA_AUTO_CHANNEL_SEL)) &&
  1907. (!!(bss->capability & WLAN_CAPABILITY_PRIVACY) ^
  1908. !!sdata->default_key))
  1909. continue;
  1910. if (!(ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) &&
  1911. bss->freq != freq)
  1912. continue;
  1913. if (!(ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) &&
  1914. memcmp(bss->bssid, ifsta->bssid, ETH_ALEN))
  1915. continue;
  1916. if (!(ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) &&
  1917. !ieee80211_sta_match_ssid(ifsta, bss->ssid, bss->ssid_len))
  1918. continue;
  1919. if (!selected || top_rssi < bss->signal) {
  1920. selected = bss;
  1921. top_rssi = bss->signal;
  1922. }
  1923. }
  1924. if (selected)
  1925. atomic_inc(&selected->users);
  1926. spin_unlock_bh(&local->bss_lock);
  1927. if (selected) {
  1928. ieee80211_set_freq(sdata, selected->freq);
  1929. if (!(ifsta->flags & IEEE80211_STA_SSID_SET))
  1930. ieee80211_sta_set_ssid(sdata, selected->ssid,
  1931. selected->ssid_len);
  1932. ieee80211_sta_set_bssid(sdata, selected->bssid);
  1933. ieee80211_sta_def_wmm_params(sdata, selected);
  1934. /* Send out direct probe if no probe resp was received or
  1935. * the one we have is outdated
  1936. */
  1937. if (!selected->last_probe_resp ||
  1938. time_after(jiffies, selected->last_probe_resp
  1939. + IEEE80211_SCAN_RESULT_EXPIRE))
  1940. ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE;
  1941. else
  1942. ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE;
  1943. ieee80211_rx_bss_put(local, selected);
  1944. ieee80211_sta_reset_auth(sdata, ifsta);
  1945. return 0;
  1946. } else {
  1947. if (ifsta->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) {
  1948. ifsta->assoc_scan_tries++;
  1949. if (ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL)
  1950. ieee80211_start_scan(sdata, NULL, 0);
  1951. else
  1952. ieee80211_start_scan(sdata, ifsta->ssid,
  1953. ifsta->ssid_len);
  1954. ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE;
  1955. set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
  1956. } else
  1957. ifsta->state = IEEE80211_STA_MLME_DISABLED;
  1958. }
  1959. return -1;
  1960. }
  1961. static void ieee80211_sta_work(struct work_struct *work)
  1962. {
  1963. struct ieee80211_sub_if_data *sdata =
  1964. container_of(work, struct ieee80211_sub_if_data, u.sta.work);
  1965. struct ieee80211_local *local = sdata->local;
  1966. struct ieee80211_if_sta *ifsta;
  1967. struct sk_buff *skb;
  1968. if (!netif_running(sdata->dev))
  1969. return;
  1970. if (local->sw_scanning || local->hw_scanning)
  1971. return;
  1972. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION &&
  1973. sdata->vif.type != NL80211_IFTYPE_ADHOC))
  1974. return;
  1975. ifsta = &sdata->u.sta;
  1976. while ((skb = skb_dequeue(&ifsta->skb_queue)))
  1977. ieee80211_sta_rx_queued_mgmt(sdata, skb);
  1978. if (ifsta->state != IEEE80211_STA_MLME_DIRECT_PROBE &&
  1979. ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE &&
  1980. ifsta->state != IEEE80211_STA_MLME_ASSOCIATE &&
  1981. test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) {
  1982. ieee80211_start_scan(sdata, ifsta->scan_ssid,
  1983. ifsta->scan_ssid_len);
  1984. return;
  1985. }
  1986. if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request)) {
  1987. if (ieee80211_sta_config_auth(sdata, ifsta))
  1988. return;
  1989. clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
  1990. } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request))
  1991. return;
  1992. switch (ifsta->state) {
  1993. case IEEE80211_STA_MLME_DISABLED:
  1994. break;
  1995. case IEEE80211_STA_MLME_DIRECT_PROBE:
  1996. ieee80211_direct_probe(sdata, ifsta);
  1997. break;
  1998. case IEEE80211_STA_MLME_AUTHENTICATE:
  1999. ieee80211_authenticate(sdata, ifsta);
  2000. break;
  2001. case IEEE80211_STA_MLME_ASSOCIATE:
  2002. ieee80211_associate(sdata, ifsta);
  2003. break;
  2004. case IEEE80211_STA_MLME_ASSOCIATED:
  2005. ieee80211_associated(sdata, ifsta);
  2006. break;
  2007. case IEEE80211_STA_MLME_IBSS_SEARCH:
  2008. ieee80211_sta_find_ibss(sdata, ifsta);
  2009. break;
  2010. case IEEE80211_STA_MLME_IBSS_JOINED:
  2011. ieee80211_sta_merge_ibss(sdata, ifsta);
  2012. break;
  2013. default:
  2014. WARN_ON(1);
  2015. break;
  2016. }
  2017. if (ieee80211_privacy_mismatch(sdata, ifsta)) {
  2018. printk(KERN_DEBUG "%s: privacy configuration mismatch and "
  2019. "mixed-cell disabled - disassociate\n", sdata->dev->name);
  2020. ieee80211_set_disassoc(sdata, ifsta, false, true,
  2021. WLAN_REASON_UNSPECIFIED);
  2022. }
  2023. }
  2024. static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
  2025. {
  2026. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  2027. queue_work(sdata->local->hw.workqueue,
  2028. &sdata->u.sta.work);
  2029. }
  2030. /* interface setup */
  2031. void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
  2032. {
  2033. struct ieee80211_if_sta *ifsta;
  2034. ifsta = &sdata->u.sta;
  2035. INIT_WORK(&ifsta->work, ieee80211_sta_work);
  2036. INIT_WORK(&ifsta->chswitch_work, ieee80211_chswitch_work);
  2037. setup_timer(&ifsta->timer, ieee80211_sta_timer,
  2038. (unsigned long) sdata);
  2039. setup_timer(&ifsta->chswitch_timer, ieee80211_chswitch_timer,
  2040. (unsigned long) sdata);
  2041. skb_queue_head_init(&ifsta->skb_queue);
  2042. ifsta->capab = WLAN_CAPABILITY_ESS;
  2043. ifsta->auth_algs = IEEE80211_AUTH_ALG_OPEN |
  2044. IEEE80211_AUTH_ALG_SHARED_KEY;
  2045. ifsta->flags |= IEEE80211_STA_CREATE_IBSS |
  2046. IEEE80211_STA_AUTO_BSSID_SEL |
  2047. IEEE80211_STA_AUTO_CHANNEL_SEL;
  2048. if (ieee80211_num_regular_queues(&sdata->local->hw) >= 4)
  2049. ifsta->flags |= IEEE80211_STA_WMM_ENABLED;
  2050. }
  2051. /*
  2052. * Add a new IBSS station, will also be called by the RX code when,
  2053. * in IBSS mode, receiving a frame from a yet-unknown station, hence
  2054. * must be callable in atomic context.
  2055. */
  2056. struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
  2057. u8 *bssid,u8 *addr, u64 supp_rates)
  2058. {
  2059. struct ieee80211_local *local = sdata->local;
  2060. struct sta_info *sta;
  2061. int band = local->hw.conf.channel->band;
  2062. /* TODO: Could consider removing the least recently used entry and
  2063. * allow new one to be added. */
  2064. if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
  2065. if (net_ratelimit()) {
  2066. printk(KERN_DEBUG "%s: No room for a new IBSS STA "
  2067. "entry %pM\n", sdata->dev->name, addr);
  2068. }
  2069. return NULL;
  2070. }
  2071. if (compare_ether_addr(bssid, sdata->u.sta.bssid))
  2072. return NULL;
  2073. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  2074. printk(KERN_DEBUG "%s: Adding new IBSS station %pM (dev=%s)\n",
  2075. wiphy_name(local->hw.wiphy), addr, sdata->dev->name);
  2076. #endif
  2077. sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
  2078. if (!sta)
  2079. return NULL;
  2080. set_sta_flags(sta, WLAN_STA_AUTHORIZED);
  2081. /* make sure mandatory rates are always added */
  2082. sta->sta.supp_rates[band] = supp_rates |
  2083. ieee80211_mandatory_rates(local, band);
  2084. rate_control_rate_init(sta);
  2085. if (sta_info_insert(sta))
  2086. return NULL;
  2087. return sta;
  2088. }
  2089. /* configuration hooks */
  2090. void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata,
  2091. struct ieee80211_if_sta *ifsta)
  2092. {
  2093. struct ieee80211_local *local = sdata->local;
  2094. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2095. return;
  2096. if ((ifsta->flags & (IEEE80211_STA_BSSID_SET |
  2097. IEEE80211_STA_AUTO_BSSID_SEL)) &&
  2098. (ifsta->flags & (IEEE80211_STA_SSID_SET |
  2099. IEEE80211_STA_AUTO_SSID_SEL))) {
  2100. if (ifsta->state == IEEE80211_STA_MLME_ASSOCIATED)
  2101. ieee80211_set_disassoc(sdata, ifsta, true, true,
  2102. WLAN_REASON_DEAUTH_LEAVING);
  2103. set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
  2104. queue_work(local->hw.workqueue, &ifsta->work);
  2105. }
  2106. }
  2107. int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len)
  2108. {
  2109. struct ieee80211_if_sta *ifsta;
  2110. if (len > IEEE80211_MAX_SSID_LEN)
  2111. return -EINVAL;
  2112. ifsta = &sdata->u.sta;
  2113. if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0) {
  2114. memset(ifsta->ssid, 0, sizeof(ifsta->ssid));
  2115. memcpy(ifsta->ssid, ssid, len);
  2116. ifsta->ssid_len = len;
  2117. ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
  2118. }
  2119. if (len)
  2120. ifsta->flags |= IEEE80211_STA_SSID_SET;
  2121. else
  2122. ifsta->flags &= ~IEEE80211_STA_SSID_SET;
  2123. if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
  2124. !(ifsta->flags & IEEE80211_STA_BSSID_SET)) {
  2125. ifsta->ibss_join_req = jiffies;
  2126. ifsta->state = IEEE80211_STA_MLME_IBSS_SEARCH;
  2127. return ieee80211_sta_find_ibss(sdata, ifsta);
  2128. }
  2129. return 0;
  2130. }
  2131. int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len)
  2132. {
  2133. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  2134. memcpy(ssid, ifsta->ssid, ifsta->ssid_len);
  2135. *len = ifsta->ssid_len;
  2136. return 0;
  2137. }
  2138. int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid)
  2139. {
  2140. struct ieee80211_if_sta *ifsta;
  2141. int res;
  2142. bool valid;
  2143. ifsta = &sdata->u.sta;
  2144. valid = is_valid_ether_addr(bssid);
  2145. if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) {
  2146. if(valid)
  2147. memcpy(ifsta->bssid, bssid, ETH_ALEN);
  2148. else
  2149. memset(ifsta->bssid, 0, ETH_ALEN);
  2150. res = 0;
  2151. /*
  2152. * Hack! See also ieee80211_sta_set_ssid.
  2153. */
  2154. if (netif_running(sdata->dev))
  2155. res = ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID);
  2156. if (res) {
  2157. printk(KERN_DEBUG "%s: Failed to config new BSSID to "
  2158. "the low-level driver\n", sdata->dev->name);
  2159. return res;
  2160. }
  2161. }
  2162. if (valid)
  2163. ifsta->flags |= IEEE80211_STA_BSSID_SET;
  2164. else
  2165. ifsta->flags &= ~IEEE80211_STA_BSSID_SET;
  2166. return 0;
  2167. }
  2168. int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata, char *ie, size_t len)
  2169. {
  2170. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  2171. kfree(ifsta->extra_ie);
  2172. if (len == 0) {
  2173. ifsta->extra_ie = NULL;
  2174. ifsta->extra_ie_len = 0;
  2175. return 0;
  2176. }
  2177. ifsta->extra_ie = kmalloc(len, GFP_KERNEL);
  2178. if (!ifsta->extra_ie) {
  2179. ifsta->extra_ie_len = 0;
  2180. return -ENOMEM;
  2181. }
  2182. memcpy(ifsta->extra_ie, ie, len);
  2183. ifsta->extra_ie_len = len;
  2184. return 0;
  2185. }
  2186. int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason)
  2187. {
  2188. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  2189. printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
  2190. sdata->dev->name, reason);
  2191. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  2192. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  2193. return -EINVAL;
  2194. ieee80211_set_disassoc(sdata, ifsta, true, true, reason);
  2195. return 0;
  2196. }
  2197. int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason)
  2198. {
  2199. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  2200. printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
  2201. sdata->dev->name, reason);
  2202. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2203. return -EINVAL;
  2204. if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED))
  2205. return -1;
  2206. ieee80211_set_disassoc(sdata, ifsta, false, true, reason);
  2207. return 0;
  2208. }
  2209. /* scan finished notification */
  2210. void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
  2211. {
  2212. struct ieee80211_sub_if_data *sdata = local->scan_sdata;
  2213. struct ieee80211_if_sta *ifsta;
  2214. if (sdata && sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  2215. ifsta = &sdata->u.sta;
  2216. if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) ||
  2217. (!(ifsta->state == IEEE80211_STA_MLME_IBSS_JOINED) &&
  2218. !ieee80211_sta_active_ibss(sdata)))
  2219. ieee80211_sta_find_ibss(sdata, ifsta);
  2220. }
  2221. /* Restart STA timers */
  2222. rcu_read_lock();
  2223. list_for_each_entry_rcu(sdata, &local->interfaces, list)
  2224. ieee80211_restart_sta_timer(sdata);
  2225. rcu_read_unlock();
  2226. }
  2227. void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
  2228. {
  2229. struct ieee80211_local *local =
  2230. container_of(work, struct ieee80211_local,
  2231. dynamic_ps_disable_work);
  2232. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  2233. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  2234. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  2235. }
  2236. ieee80211_wake_queues_by_reason(&local->hw,
  2237. IEEE80211_QUEUE_STOP_REASON_PS);
  2238. }
  2239. void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
  2240. {
  2241. struct ieee80211_local *local =
  2242. container_of(work, struct ieee80211_local,
  2243. dynamic_ps_enable_work);
  2244. struct ieee80211_sub_if_data *sdata = local->scan_sdata;
  2245. if (local->hw.conf.flags & IEEE80211_CONF_PS)
  2246. return;
  2247. ieee80211_send_nullfunc(local, sdata, 1);
  2248. local->hw.conf.flags |= IEEE80211_CONF_PS;
  2249. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  2250. }
  2251. void ieee80211_dynamic_ps_timer(unsigned long data)
  2252. {
  2253. struct ieee80211_local *local = (void *) data;
  2254. queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work);
  2255. }