cfg.c 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069
  1. /*
  2. * mac80211 configuration hooks for cfg80211
  3. *
  4. * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
  5. *
  6. * This file is GPLv2 as found in COPYING.
  7. */
  8. #include <linux/ieee80211.h>
  9. #include <linux/nl80211.h>
  10. #include <linux/rtnetlink.h>
  11. #include <linux/slab.h>
  12. #include <net/net_namespace.h>
  13. #include <linux/rcupdate.h>
  14. #include <linux/if_ether.h>
  15. #include <net/cfg80211.h>
  16. #include "ieee80211_i.h"
  17. #include "driver-ops.h"
  18. #include "cfg.h"
  19. #include "rate.h"
  20. #include "mesh.h"
  21. static struct net_device *ieee80211_add_iface(struct wiphy *wiphy, char *name,
  22. enum nl80211_iftype type,
  23. u32 *flags,
  24. struct vif_params *params)
  25. {
  26. struct ieee80211_local *local = wiphy_priv(wiphy);
  27. struct net_device *dev;
  28. struct ieee80211_sub_if_data *sdata;
  29. int err;
  30. err = ieee80211_if_add(local, name, &dev, type, params);
  31. if (err)
  32. return ERR_PTR(err);
  33. if (type == NL80211_IFTYPE_MONITOR && flags) {
  34. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  35. sdata->u.mntr_flags = *flags;
  36. }
  37. return dev;
  38. }
  39. static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
  40. {
  41. ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
  42. return 0;
  43. }
  44. static int ieee80211_change_iface(struct wiphy *wiphy,
  45. struct net_device *dev,
  46. enum nl80211_iftype type, u32 *flags,
  47. struct vif_params *params)
  48. {
  49. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  50. int ret;
  51. ret = ieee80211_if_change_type(sdata, type);
  52. if (ret)
  53. return ret;
  54. if (type == NL80211_IFTYPE_AP_VLAN &&
  55. params && params->use_4addr == 0)
  56. RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
  57. else if (type == NL80211_IFTYPE_STATION &&
  58. params && params->use_4addr >= 0)
  59. sdata->u.mgd.use_4addr = params->use_4addr;
  60. if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
  61. struct ieee80211_local *local = sdata->local;
  62. if (ieee80211_sdata_running(sdata)) {
  63. /*
  64. * Prohibit MONITOR_FLAG_COOK_FRAMES to be
  65. * changed while the interface is up.
  66. * Else we would need to add a lot of cruft
  67. * to update everything:
  68. * cooked_mntrs, monitor and all fif_* counters
  69. * reconfigure hardware
  70. */
  71. if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
  72. (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
  73. return -EBUSY;
  74. ieee80211_adjust_monitor_flags(sdata, -1);
  75. sdata->u.mntr_flags = *flags;
  76. ieee80211_adjust_monitor_flags(sdata, 1);
  77. ieee80211_configure_filter(local);
  78. } else {
  79. /*
  80. * Because the interface is down, ieee80211_do_stop
  81. * and ieee80211_do_open take care of "everything"
  82. * mentioned in the comment above.
  83. */
  84. sdata->u.mntr_flags = *flags;
  85. }
  86. }
  87. return 0;
  88. }
  89. static int ieee80211_set_noack_map(struct wiphy *wiphy,
  90. struct net_device *dev,
  91. u16 noack_map)
  92. {
  93. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  94. sdata->noack_map = noack_map;
  95. return 0;
  96. }
  97. static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
  98. u8 key_idx, bool pairwise, const u8 *mac_addr,
  99. struct key_params *params)
  100. {
  101. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  102. struct sta_info *sta = NULL;
  103. struct ieee80211_key *key;
  104. int err;
  105. if (!ieee80211_sdata_running(sdata))
  106. return -ENETDOWN;
  107. /* reject WEP and TKIP keys if WEP failed to initialize */
  108. switch (params->cipher) {
  109. case WLAN_CIPHER_SUITE_WEP40:
  110. case WLAN_CIPHER_SUITE_TKIP:
  111. case WLAN_CIPHER_SUITE_WEP104:
  112. if (IS_ERR(sdata->local->wep_tx_tfm))
  113. return -EINVAL;
  114. break;
  115. default:
  116. break;
  117. }
  118. key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
  119. params->key, params->seq_len, params->seq);
  120. if (IS_ERR(key))
  121. return PTR_ERR(key);
  122. if (pairwise)
  123. key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
  124. mutex_lock(&sdata->local->sta_mtx);
  125. if (mac_addr) {
  126. if (ieee80211_vif_is_mesh(&sdata->vif))
  127. sta = sta_info_get(sdata, mac_addr);
  128. else
  129. sta = sta_info_get_bss(sdata, mac_addr);
  130. if (!sta) {
  131. ieee80211_key_free(sdata->local, key);
  132. err = -ENOENT;
  133. goto out_unlock;
  134. }
  135. }
  136. err = ieee80211_key_link(key, sdata, sta);
  137. if (err)
  138. ieee80211_key_free(sdata->local, key);
  139. out_unlock:
  140. mutex_unlock(&sdata->local->sta_mtx);
  141. return err;
  142. }
  143. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  144. u8 key_idx, bool pairwise, const u8 *mac_addr)
  145. {
  146. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  147. struct ieee80211_local *local = sdata->local;
  148. struct sta_info *sta;
  149. struct ieee80211_key *key = NULL;
  150. int ret;
  151. mutex_lock(&local->sta_mtx);
  152. mutex_lock(&local->key_mtx);
  153. if (mac_addr) {
  154. ret = -ENOENT;
  155. sta = sta_info_get_bss(sdata, mac_addr);
  156. if (!sta)
  157. goto out_unlock;
  158. if (pairwise)
  159. key = key_mtx_dereference(local, sta->ptk);
  160. else
  161. key = key_mtx_dereference(local, sta->gtk[key_idx]);
  162. } else
  163. key = key_mtx_dereference(local, sdata->keys[key_idx]);
  164. if (!key) {
  165. ret = -ENOENT;
  166. goto out_unlock;
  167. }
  168. __ieee80211_key_free(key);
  169. ret = 0;
  170. out_unlock:
  171. mutex_unlock(&local->key_mtx);
  172. mutex_unlock(&local->sta_mtx);
  173. return ret;
  174. }
  175. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  176. u8 key_idx, bool pairwise, const u8 *mac_addr,
  177. void *cookie,
  178. void (*callback)(void *cookie,
  179. struct key_params *params))
  180. {
  181. struct ieee80211_sub_if_data *sdata;
  182. struct sta_info *sta = NULL;
  183. u8 seq[6] = {0};
  184. struct key_params params;
  185. struct ieee80211_key *key = NULL;
  186. u64 pn64;
  187. u32 iv32;
  188. u16 iv16;
  189. int err = -ENOENT;
  190. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  191. rcu_read_lock();
  192. if (mac_addr) {
  193. sta = sta_info_get_bss(sdata, mac_addr);
  194. if (!sta)
  195. goto out;
  196. if (pairwise)
  197. key = rcu_dereference(sta->ptk);
  198. else if (key_idx < NUM_DEFAULT_KEYS)
  199. key = rcu_dereference(sta->gtk[key_idx]);
  200. } else
  201. key = rcu_dereference(sdata->keys[key_idx]);
  202. if (!key)
  203. goto out;
  204. memset(&params, 0, sizeof(params));
  205. params.cipher = key->conf.cipher;
  206. switch (key->conf.cipher) {
  207. case WLAN_CIPHER_SUITE_TKIP:
  208. iv32 = key->u.tkip.tx.iv32;
  209. iv16 = key->u.tkip.tx.iv16;
  210. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
  211. drv_get_tkip_seq(sdata->local,
  212. key->conf.hw_key_idx,
  213. &iv32, &iv16);
  214. seq[0] = iv16 & 0xff;
  215. seq[1] = (iv16 >> 8) & 0xff;
  216. seq[2] = iv32 & 0xff;
  217. seq[3] = (iv32 >> 8) & 0xff;
  218. seq[4] = (iv32 >> 16) & 0xff;
  219. seq[5] = (iv32 >> 24) & 0xff;
  220. params.seq = seq;
  221. params.seq_len = 6;
  222. break;
  223. case WLAN_CIPHER_SUITE_CCMP:
  224. pn64 = atomic64_read(&key->u.ccmp.tx_pn);
  225. seq[0] = pn64;
  226. seq[1] = pn64 >> 8;
  227. seq[2] = pn64 >> 16;
  228. seq[3] = pn64 >> 24;
  229. seq[4] = pn64 >> 32;
  230. seq[5] = pn64 >> 40;
  231. params.seq = seq;
  232. params.seq_len = 6;
  233. break;
  234. case WLAN_CIPHER_SUITE_AES_CMAC:
  235. pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
  236. seq[0] = pn64;
  237. seq[1] = pn64 >> 8;
  238. seq[2] = pn64 >> 16;
  239. seq[3] = pn64 >> 24;
  240. seq[4] = pn64 >> 32;
  241. seq[5] = pn64 >> 40;
  242. params.seq = seq;
  243. params.seq_len = 6;
  244. break;
  245. }
  246. params.key = key->conf.key;
  247. params.key_len = key->conf.keylen;
  248. callback(cookie, &params);
  249. err = 0;
  250. out:
  251. rcu_read_unlock();
  252. return err;
  253. }
  254. static int ieee80211_config_default_key(struct wiphy *wiphy,
  255. struct net_device *dev,
  256. u8 key_idx, bool uni,
  257. bool multi)
  258. {
  259. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  260. ieee80211_set_default_key(sdata, key_idx, uni, multi);
  261. return 0;
  262. }
  263. static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
  264. struct net_device *dev,
  265. u8 key_idx)
  266. {
  267. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  268. ieee80211_set_default_mgmt_key(sdata, key_idx);
  269. return 0;
  270. }
  271. static void rate_idx_to_bitrate(struct rate_info *rate, struct sta_info *sta, int idx)
  272. {
  273. if (!(rate->flags & RATE_INFO_FLAGS_MCS)) {
  274. struct ieee80211_supported_band *sband;
  275. sband = sta->local->hw.wiphy->bands[
  276. sta->local->hw.conf.channel->band];
  277. rate->legacy = sband->bitrates[idx].bitrate;
  278. } else
  279. rate->mcs = idx;
  280. }
  281. void sta_set_rate_info_tx(struct sta_info *sta,
  282. const struct ieee80211_tx_rate *rate,
  283. struct rate_info *rinfo)
  284. {
  285. rinfo->flags = 0;
  286. if (rate->flags & IEEE80211_TX_RC_MCS)
  287. rinfo->flags |= RATE_INFO_FLAGS_MCS;
  288. if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  289. rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  290. if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
  291. rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
  292. rate_idx_to_bitrate(rinfo, sta, rate->idx);
  293. }
  294. static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  295. {
  296. struct ieee80211_sub_if_data *sdata = sta->sdata;
  297. struct timespec uptime;
  298. sinfo->generation = sdata->local->sta_generation;
  299. sinfo->filled = STATION_INFO_INACTIVE_TIME |
  300. STATION_INFO_RX_BYTES |
  301. STATION_INFO_TX_BYTES |
  302. STATION_INFO_RX_PACKETS |
  303. STATION_INFO_TX_PACKETS |
  304. STATION_INFO_TX_RETRIES |
  305. STATION_INFO_TX_FAILED |
  306. STATION_INFO_TX_BITRATE |
  307. STATION_INFO_RX_BITRATE |
  308. STATION_INFO_RX_DROP_MISC |
  309. STATION_INFO_BSS_PARAM |
  310. STATION_INFO_CONNECTED_TIME |
  311. STATION_INFO_STA_FLAGS |
  312. STATION_INFO_BEACON_LOSS_COUNT;
  313. do_posix_clock_monotonic_gettime(&uptime);
  314. sinfo->connected_time = uptime.tv_sec - sta->last_connected;
  315. sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
  316. sinfo->rx_bytes = sta->rx_bytes;
  317. sinfo->tx_bytes = sta->tx_bytes;
  318. sinfo->rx_packets = sta->rx_packets;
  319. sinfo->tx_packets = sta->tx_packets;
  320. sinfo->tx_retries = sta->tx_retry_count;
  321. sinfo->tx_failed = sta->tx_retry_failed;
  322. sinfo->rx_dropped_misc = sta->rx_dropped;
  323. sinfo->beacon_loss_count = sta->beacon_loss_count;
  324. if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
  325. (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
  326. sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
  327. sinfo->signal = (s8)sta->last_signal;
  328. sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
  329. }
  330. sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
  331. sinfo->rxrate.flags = 0;
  332. if (sta->last_rx_rate_flag & RX_FLAG_HT)
  333. sinfo->rxrate.flags |= RATE_INFO_FLAGS_MCS;
  334. if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
  335. sinfo->rxrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  336. if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
  337. sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  338. rate_idx_to_bitrate(&sinfo->rxrate, sta, sta->last_rx_rate_idx);
  339. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  340. #ifdef CONFIG_MAC80211_MESH
  341. sinfo->filled |= STATION_INFO_LLID |
  342. STATION_INFO_PLID |
  343. STATION_INFO_PLINK_STATE;
  344. sinfo->llid = le16_to_cpu(sta->llid);
  345. sinfo->plid = le16_to_cpu(sta->plid);
  346. sinfo->plink_state = sta->plink_state;
  347. if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
  348. sinfo->filled |= STATION_INFO_T_OFFSET;
  349. sinfo->t_offset = sta->t_offset;
  350. }
  351. #endif
  352. }
  353. sinfo->bss_param.flags = 0;
  354. if (sdata->vif.bss_conf.use_cts_prot)
  355. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
  356. if (sdata->vif.bss_conf.use_short_preamble)
  357. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
  358. if (sdata->vif.bss_conf.use_short_slot)
  359. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
  360. sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
  361. sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
  362. sinfo->sta_flags.set = 0;
  363. sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
  364. BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
  365. BIT(NL80211_STA_FLAG_WME) |
  366. BIT(NL80211_STA_FLAG_MFP) |
  367. BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  368. BIT(NL80211_STA_FLAG_TDLS_PEER);
  369. if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  370. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
  371. if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
  372. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
  373. if (test_sta_flag(sta, WLAN_STA_WME))
  374. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
  375. if (test_sta_flag(sta, WLAN_STA_MFP))
  376. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
  377. if (test_sta_flag(sta, WLAN_STA_AUTH))
  378. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
  379. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
  380. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
  381. }
  382. static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
  383. "rx_packets", "rx_bytes", "wep_weak_iv_count",
  384. "rx_duplicates", "rx_fragments", "rx_dropped",
  385. "tx_packets", "tx_bytes", "tx_fragments",
  386. "tx_filtered", "tx_retry_failed", "tx_retries",
  387. "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
  388. "channel", "noise", "ch_time", "ch_time_busy",
  389. "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
  390. };
  391. #define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
  392. static int ieee80211_get_et_sset_count(struct wiphy *wiphy,
  393. struct net_device *dev,
  394. int sset)
  395. {
  396. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  397. int rv = 0;
  398. if (sset == ETH_SS_STATS)
  399. rv += STA_STATS_LEN;
  400. rv += drv_get_et_sset_count(sdata, sset);
  401. if (rv == 0)
  402. return -EOPNOTSUPP;
  403. return rv;
  404. }
  405. static void ieee80211_get_et_stats(struct wiphy *wiphy,
  406. struct net_device *dev,
  407. struct ethtool_stats *stats,
  408. u64 *data)
  409. {
  410. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  411. struct sta_info *sta;
  412. struct ieee80211_local *local = sdata->local;
  413. struct station_info sinfo;
  414. struct survey_info survey;
  415. int i, q;
  416. #define STA_STATS_SURVEY_LEN 7
  417. memset(data, 0, sizeof(u64) * STA_STATS_LEN);
  418. #define ADD_STA_STATS(sta) \
  419. do { \
  420. data[i++] += sta->rx_packets; \
  421. data[i++] += sta->rx_bytes; \
  422. data[i++] += sta->wep_weak_iv_count; \
  423. data[i++] += sta->num_duplicates; \
  424. data[i++] += sta->rx_fragments; \
  425. data[i++] += sta->rx_dropped; \
  426. \
  427. data[i++] += sta->tx_packets; \
  428. data[i++] += sta->tx_bytes; \
  429. data[i++] += sta->tx_fragments; \
  430. data[i++] += sta->tx_filtered_count; \
  431. data[i++] += sta->tx_retry_failed; \
  432. data[i++] += sta->tx_retry_count; \
  433. data[i++] += sta->beacon_loss_count; \
  434. } while (0)
  435. /* For Managed stations, find the single station based on BSSID
  436. * and use that. For interface types, iterate through all available
  437. * stations and add stats for any station that is assigned to this
  438. * network device.
  439. */
  440. rcu_read_lock();
  441. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  442. sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
  443. if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
  444. goto do_survey;
  445. i = 0;
  446. ADD_STA_STATS(sta);
  447. data[i++] = sta->sta_state;
  448. sinfo.filled = 0;
  449. sta_set_sinfo(sta, &sinfo);
  450. if (sinfo.filled & STATION_INFO_TX_BITRATE)
  451. data[i] = 100000 *
  452. cfg80211_calculate_bitrate(&sinfo.txrate);
  453. i++;
  454. if (sinfo.filled & STATION_INFO_RX_BITRATE)
  455. data[i] = 100000 *
  456. cfg80211_calculate_bitrate(&sinfo.rxrate);
  457. i++;
  458. if (sinfo.filled & STATION_INFO_SIGNAL_AVG)
  459. data[i] = (u8)sinfo.signal_avg;
  460. i++;
  461. } else {
  462. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  463. /* Make sure this station belongs to the proper dev */
  464. if (sta->sdata->dev != dev)
  465. continue;
  466. i = 0;
  467. ADD_STA_STATS(sta);
  468. }
  469. }
  470. do_survey:
  471. i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
  472. /* Get survey stats for current channel */
  473. q = 0;
  474. while (true) {
  475. survey.filled = 0;
  476. if (drv_get_survey(local, q, &survey) != 0) {
  477. survey.filled = 0;
  478. break;
  479. }
  480. if (survey.channel &&
  481. (local->oper_channel->center_freq ==
  482. survey.channel->center_freq))
  483. break;
  484. q++;
  485. }
  486. if (survey.filled)
  487. data[i++] = survey.channel->center_freq;
  488. else
  489. data[i++] = 0;
  490. if (survey.filled & SURVEY_INFO_NOISE_DBM)
  491. data[i++] = (u8)survey.noise;
  492. else
  493. data[i++] = -1LL;
  494. if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
  495. data[i++] = survey.channel_time;
  496. else
  497. data[i++] = -1LL;
  498. if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
  499. data[i++] = survey.channel_time_busy;
  500. else
  501. data[i++] = -1LL;
  502. if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
  503. data[i++] = survey.channel_time_ext_busy;
  504. else
  505. data[i++] = -1LL;
  506. if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
  507. data[i++] = survey.channel_time_rx;
  508. else
  509. data[i++] = -1LL;
  510. if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
  511. data[i++] = survey.channel_time_tx;
  512. else
  513. data[i++] = -1LL;
  514. rcu_read_unlock();
  515. if (WARN_ON(i != STA_STATS_LEN))
  516. return;
  517. drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
  518. }
  519. static void ieee80211_get_et_strings(struct wiphy *wiphy,
  520. struct net_device *dev,
  521. u32 sset, u8 *data)
  522. {
  523. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  524. int sz_sta_stats = 0;
  525. if (sset == ETH_SS_STATS) {
  526. sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
  527. memcpy(data, *ieee80211_gstrings_sta_stats, sz_sta_stats);
  528. }
  529. drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
  530. }
  531. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  532. int idx, u8 *mac, struct station_info *sinfo)
  533. {
  534. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  535. struct sta_info *sta;
  536. int ret = -ENOENT;
  537. rcu_read_lock();
  538. sta = sta_info_get_by_idx(sdata, idx);
  539. if (sta) {
  540. ret = 0;
  541. memcpy(mac, sta->sta.addr, ETH_ALEN);
  542. sta_set_sinfo(sta, sinfo);
  543. }
  544. rcu_read_unlock();
  545. return ret;
  546. }
  547. static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  548. int idx, struct survey_info *survey)
  549. {
  550. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  551. return drv_get_survey(local, idx, survey);
  552. }
  553. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  554. u8 *mac, struct station_info *sinfo)
  555. {
  556. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  557. struct sta_info *sta;
  558. int ret = -ENOENT;
  559. rcu_read_lock();
  560. sta = sta_info_get_bss(sdata, mac);
  561. if (sta) {
  562. ret = 0;
  563. sta_set_sinfo(sta, sinfo);
  564. }
  565. rcu_read_unlock();
  566. return ret;
  567. }
  568. static int ieee80211_set_channel(struct wiphy *wiphy,
  569. struct net_device *netdev,
  570. struct ieee80211_channel *chan,
  571. enum nl80211_channel_type channel_type)
  572. {
  573. struct ieee80211_local *local = wiphy_priv(wiphy);
  574. struct ieee80211_sub_if_data *sdata = NULL;
  575. if (netdev)
  576. sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
  577. switch (ieee80211_get_channel_mode(local, NULL)) {
  578. case CHAN_MODE_HOPPING:
  579. return -EBUSY;
  580. case CHAN_MODE_FIXED:
  581. if (local->oper_channel != chan ||
  582. (!sdata && local->_oper_channel_type != channel_type))
  583. return -EBUSY;
  584. if (!sdata && local->_oper_channel_type == channel_type)
  585. return 0;
  586. break;
  587. case CHAN_MODE_UNDEFINED:
  588. break;
  589. }
  590. if (!ieee80211_set_channel_type(local, sdata, channel_type))
  591. return -EBUSY;
  592. local->oper_channel = chan;
  593. /* auto-detects changes */
  594. ieee80211_hw_config(local, 0);
  595. return 0;
  596. }
  597. static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
  598. struct ieee80211_channel *chan,
  599. enum nl80211_channel_type channel_type)
  600. {
  601. return ieee80211_set_channel(wiphy, NULL, chan, channel_type);
  602. }
  603. static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
  604. const u8 *resp, size_t resp_len)
  605. {
  606. struct sk_buff *new, *old;
  607. if (!resp || !resp_len)
  608. return 1;
  609. old = rtnl_dereference(sdata->u.ap.probe_resp);
  610. new = dev_alloc_skb(resp_len);
  611. if (!new)
  612. return -ENOMEM;
  613. memcpy(skb_put(new, resp_len), resp, resp_len);
  614. rcu_assign_pointer(sdata->u.ap.probe_resp, new);
  615. if (old) {
  616. /* TODO: use call_rcu() */
  617. synchronize_rcu();
  618. dev_kfree_skb(old);
  619. }
  620. return 0;
  621. }
  622. static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
  623. struct cfg80211_beacon_data *params)
  624. {
  625. struct beacon_data *new, *old;
  626. int new_head_len, new_tail_len;
  627. int size, err;
  628. u32 changed = BSS_CHANGED_BEACON;
  629. old = rtnl_dereference(sdata->u.ap.beacon);
  630. /* Need to have a beacon head if we don't have one yet */
  631. if (!params->head && !old)
  632. return -EINVAL;
  633. /* new or old head? */
  634. if (params->head)
  635. new_head_len = params->head_len;
  636. else
  637. new_head_len = old->head_len;
  638. /* new or old tail? */
  639. if (params->tail || !old)
  640. /* params->tail_len will be zero for !params->tail */
  641. new_tail_len = params->tail_len;
  642. else
  643. new_tail_len = old->tail_len;
  644. size = sizeof(*new) + new_head_len + new_tail_len;
  645. new = kzalloc(size, GFP_KERNEL);
  646. if (!new)
  647. return -ENOMEM;
  648. /* start filling the new info now */
  649. /*
  650. * pointers go into the block we allocated,
  651. * memory is | beacon_data | head | tail |
  652. */
  653. new->head = ((u8 *) new) + sizeof(*new);
  654. new->tail = new->head + new_head_len;
  655. new->head_len = new_head_len;
  656. new->tail_len = new_tail_len;
  657. /* copy in head */
  658. if (params->head)
  659. memcpy(new->head, params->head, new_head_len);
  660. else
  661. memcpy(new->head, old->head, new_head_len);
  662. /* copy in optional tail */
  663. if (params->tail)
  664. memcpy(new->tail, params->tail, new_tail_len);
  665. else
  666. if (old)
  667. memcpy(new->tail, old->tail, new_tail_len);
  668. err = ieee80211_set_probe_resp(sdata, params->probe_resp,
  669. params->probe_resp_len);
  670. if (err < 0)
  671. return err;
  672. if (err == 0)
  673. changed |= BSS_CHANGED_AP_PROBE_RESP;
  674. rcu_assign_pointer(sdata->u.ap.beacon, new);
  675. if (old)
  676. kfree_rcu(old, rcu_head);
  677. return changed;
  678. }
  679. static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
  680. struct cfg80211_ap_settings *params)
  681. {
  682. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  683. struct beacon_data *old;
  684. struct ieee80211_sub_if_data *vlan;
  685. u32 changed = BSS_CHANGED_BEACON_INT |
  686. BSS_CHANGED_BEACON_ENABLED |
  687. BSS_CHANGED_BEACON |
  688. BSS_CHANGED_SSID;
  689. int err;
  690. old = rtnl_dereference(sdata->u.ap.beacon);
  691. if (old)
  692. return -EALREADY;
  693. err = ieee80211_set_channel(wiphy, dev, params->channel,
  694. params->channel_type);
  695. if (err)
  696. return err;
  697. /*
  698. * Apply control port protocol, this allows us to
  699. * not encrypt dynamic WEP control frames.
  700. */
  701. sdata->control_port_protocol = params->crypto.control_port_ethertype;
  702. sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
  703. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
  704. vlan->control_port_protocol =
  705. params->crypto.control_port_ethertype;
  706. vlan->control_port_no_encrypt =
  707. params->crypto.control_port_no_encrypt;
  708. }
  709. sdata->vif.bss_conf.beacon_int = params->beacon_interval;
  710. sdata->vif.bss_conf.dtim_period = params->dtim_period;
  711. sdata->vif.bss_conf.ssid_len = params->ssid_len;
  712. if (params->ssid_len)
  713. memcpy(sdata->vif.bss_conf.ssid, params->ssid,
  714. params->ssid_len);
  715. sdata->vif.bss_conf.hidden_ssid =
  716. (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
  717. err = ieee80211_assign_beacon(sdata, &params->beacon);
  718. if (err < 0)
  719. return err;
  720. changed |= err;
  721. ieee80211_bss_info_change_notify(sdata, changed);
  722. netif_carrier_on(dev);
  723. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
  724. netif_carrier_on(vlan->dev);
  725. return 0;
  726. }
  727. static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
  728. struct cfg80211_beacon_data *params)
  729. {
  730. struct ieee80211_sub_if_data *sdata;
  731. struct beacon_data *old;
  732. int err;
  733. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  734. old = rtnl_dereference(sdata->u.ap.beacon);
  735. if (!old)
  736. return -ENOENT;
  737. err = ieee80211_assign_beacon(sdata, params);
  738. if (err < 0)
  739. return err;
  740. ieee80211_bss_info_change_notify(sdata, err);
  741. return 0;
  742. }
  743. static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
  744. {
  745. struct ieee80211_sub_if_data *sdata, *vlan;
  746. struct beacon_data *old;
  747. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  748. old = rtnl_dereference(sdata->u.ap.beacon);
  749. if (!old)
  750. return -ENOENT;
  751. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
  752. netif_carrier_off(vlan->dev);
  753. netif_carrier_off(dev);
  754. RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
  755. kfree_rcu(old, rcu_head);
  756. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  757. return 0;
  758. }
  759. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  760. struct iapp_layer2_update {
  761. u8 da[ETH_ALEN]; /* broadcast */
  762. u8 sa[ETH_ALEN]; /* STA addr */
  763. __be16 len; /* 6 */
  764. u8 dsap; /* 0 */
  765. u8 ssap; /* 0 */
  766. u8 control;
  767. u8 xid_info[3];
  768. } __packed;
  769. static void ieee80211_send_layer2_update(struct sta_info *sta)
  770. {
  771. struct iapp_layer2_update *msg;
  772. struct sk_buff *skb;
  773. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  774. * bridge devices */
  775. skb = dev_alloc_skb(sizeof(*msg));
  776. if (!skb)
  777. return;
  778. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  779. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  780. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  781. memset(msg->da, 0xff, ETH_ALEN);
  782. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  783. msg->len = htons(6);
  784. msg->dsap = 0;
  785. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  786. msg->control = 0xaf; /* XID response lsb.1111F101.
  787. * F=0 (no poll command; unsolicited frame) */
  788. msg->xid_info[0] = 0x81; /* XID format identifier */
  789. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  790. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  791. skb->dev = sta->sdata->dev;
  792. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  793. memset(skb->cb, 0, sizeof(skb->cb));
  794. netif_rx_ni(skb);
  795. }
  796. static int sta_apply_parameters(struct ieee80211_local *local,
  797. struct sta_info *sta,
  798. struct station_parameters *params)
  799. {
  800. int ret = 0;
  801. u32 rates;
  802. int i, j;
  803. struct ieee80211_supported_band *sband;
  804. struct ieee80211_sub_if_data *sdata = sta->sdata;
  805. u32 mask, set;
  806. sband = local->hw.wiphy->bands[local->oper_channel->band];
  807. mask = params->sta_flags_mask;
  808. set = params->sta_flags_set;
  809. /*
  810. * In mesh mode, we can clear AUTHENTICATED flag but must
  811. * also make ASSOCIATED follow appropriately for the driver
  812. * API. See also below, after AUTHORIZED changes.
  813. */
  814. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
  815. /* cfg80211 should not allow this in non-mesh modes */
  816. if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
  817. return -EINVAL;
  818. if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  819. !test_sta_flag(sta, WLAN_STA_AUTH)) {
  820. ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
  821. if (ret)
  822. return ret;
  823. ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  824. if (ret)
  825. return ret;
  826. }
  827. }
  828. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  829. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  830. ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
  831. else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  832. ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  833. if (ret)
  834. return ret;
  835. }
  836. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
  837. /* cfg80211 should not allow this in non-mesh modes */
  838. if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
  839. return -EINVAL;
  840. if (!(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
  841. test_sta_flag(sta, WLAN_STA_AUTH)) {
  842. ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
  843. if (ret)
  844. return ret;
  845. ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
  846. if (ret)
  847. return ret;
  848. }
  849. }
  850. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  851. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  852. set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  853. else
  854. clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  855. }
  856. if (mask & BIT(NL80211_STA_FLAG_WME)) {
  857. if (set & BIT(NL80211_STA_FLAG_WME)) {
  858. set_sta_flag(sta, WLAN_STA_WME);
  859. sta->sta.wme = true;
  860. } else {
  861. clear_sta_flag(sta, WLAN_STA_WME);
  862. sta->sta.wme = false;
  863. }
  864. }
  865. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  866. if (set & BIT(NL80211_STA_FLAG_MFP))
  867. set_sta_flag(sta, WLAN_STA_MFP);
  868. else
  869. clear_sta_flag(sta, WLAN_STA_MFP);
  870. }
  871. if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
  872. if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
  873. set_sta_flag(sta, WLAN_STA_TDLS_PEER);
  874. else
  875. clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
  876. }
  877. if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
  878. sta->sta.uapsd_queues = params->uapsd_queues;
  879. sta->sta.max_sp = params->max_sp;
  880. }
  881. /*
  882. * cfg80211 validates this (1-2007) and allows setting the AID
  883. * only when creating a new station entry
  884. */
  885. if (params->aid)
  886. sta->sta.aid = params->aid;
  887. /*
  888. * FIXME: updating the following information is racy when this
  889. * function is called from ieee80211_change_station().
  890. * However, all this information should be static so
  891. * maybe we should just reject attemps to change it.
  892. */
  893. if (params->listen_interval >= 0)
  894. sta->listen_interval = params->listen_interval;
  895. if (params->supported_rates) {
  896. rates = 0;
  897. for (i = 0; i < params->supported_rates_len; i++) {
  898. int rate = (params->supported_rates[i] & 0x7f) * 5;
  899. for (j = 0; j < sband->n_bitrates; j++) {
  900. if (sband->bitrates[j].bitrate == rate)
  901. rates |= BIT(j);
  902. }
  903. }
  904. sta->sta.supp_rates[local->oper_channel->band] = rates;
  905. }
  906. if (params->ht_capa)
  907. ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
  908. params->ht_capa,
  909. &sta->sta.ht_cap);
  910. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  911. #ifdef CONFIG_MAC80211_MESH
  912. if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED)
  913. switch (params->plink_state) {
  914. case NL80211_PLINK_LISTEN:
  915. case NL80211_PLINK_ESTAB:
  916. case NL80211_PLINK_BLOCKED:
  917. sta->plink_state = params->plink_state;
  918. break;
  919. default:
  920. /* nothing */
  921. break;
  922. }
  923. else
  924. switch (params->plink_action) {
  925. case PLINK_ACTION_OPEN:
  926. mesh_plink_open(sta);
  927. break;
  928. case PLINK_ACTION_BLOCK:
  929. mesh_plink_block(sta);
  930. break;
  931. }
  932. #endif
  933. }
  934. return 0;
  935. }
  936. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  937. u8 *mac, struct station_parameters *params)
  938. {
  939. struct ieee80211_local *local = wiphy_priv(wiphy);
  940. struct sta_info *sta;
  941. struct ieee80211_sub_if_data *sdata;
  942. int err;
  943. int layer2_update;
  944. if (params->vlan) {
  945. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  946. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  947. sdata->vif.type != NL80211_IFTYPE_AP)
  948. return -EINVAL;
  949. } else
  950. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  951. if (ether_addr_equal(mac, sdata->vif.addr))
  952. return -EINVAL;
  953. if (is_multicast_ether_addr(mac))
  954. return -EINVAL;
  955. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  956. if (!sta)
  957. return -ENOMEM;
  958. sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
  959. sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
  960. err = sta_apply_parameters(local, sta, params);
  961. if (err) {
  962. sta_info_free(local, sta);
  963. return err;
  964. }
  965. /*
  966. * for TDLS, rate control should be initialized only when supported
  967. * rates are known.
  968. */
  969. if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
  970. rate_control_rate_init(sta);
  971. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  972. sdata->vif.type == NL80211_IFTYPE_AP;
  973. err = sta_info_insert_rcu(sta);
  974. if (err) {
  975. rcu_read_unlock();
  976. return err;
  977. }
  978. if (layer2_update)
  979. ieee80211_send_layer2_update(sta);
  980. rcu_read_unlock();
  981. return 0;
  982. }
  983. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  984. u8 *mac)
  985. {
  986. struct ieee80211_local *local = wiphy_priv(wiphy);
  987. struct ieee80211_sub_if_data *sdata;
  988. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  989. if (mac)
  990. return sta_info_destroy_addr_bss(sdata, mac);
  991. sta_info_flush(local, sdata);
  992. return 0;
  993. }
  994. static int ieee80211_change_station(struct wiphy *wiphy,
  995. struct net_device *dev,
  996. u8 *mac,
  997. struct station_parameters *params)
  998. {
  999. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1000. struct ieee80211_local *local = wiphy_priv(wiphy);
  1001. struct sta_info *sta;
  1002. struct ieee80211_sub_if_data *vlansdata;
  1003. int err;
  1004. mutex_lock(&local->sta_mtx);
  1005. sta = sta_info_get_bss(sdata, mac);
  1006. if (!sta) {
  1007. mutex_unlock(&local->sta_mtx);
  1008. return -ENOENT;
  1009. }
  1010. /* in station mode, supported rates are only valid with TDLS */
  1011. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  1012. params->supported_rates &&
  1013. !test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
  1014. mutex_unlock(&local->sta_mtx);
  1015. return -EINVAL;
  1016. }
  1017. if (params->vlan && params->vlan != sta->sdata->dev) {
  1018. bool prev_4addr = false;
  1019. bool new_4addr = false;
  1020. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  1021. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  1022. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  1023. mutex_unlock(&local->sta_mtx);
  1024. return -EINVAL;
  1025. }
  1026. if (params->vlan->ieee80211_ptr->use_4addr) {
  1027. if (vlansdata->u.vlan.sta) {
  1028. mutex_unlock(&local->sta_mtx);
  1029. return -EBUSY;
  1030. }
  1031. rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
  1032. new_4addr = true;
  1033. }
  1034. if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1035. sta->sdata->u.vlan.sta) {
  1036. rcu_assign_pointer(sta->sdata->u.vlan.sta, NULL);
  1037. prev_4addr = true;
  1038. }
  1039. sta->sdata = vlansdata;
  1040. if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
  1041. prev_4addr != new_4addr) {
  1042. if (new_4addr)
  1043. atomic_dec(&sta->sdata->bss->num_mcast_sta);
  1044. else
  1045. atomic_inc(&sta->sdata->bss->num_mcast_sta);
  1046. }
  1047. ieee80211_send_layer2_update(sta);
  1048. }
  1049. err = sta_apply_parameters(local, sta, params);
  1050. if (err) {
  1051. mutex_unlock(&local->sta_mtx);
  1052. return err;
  1053. }
  1054. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && params->supported_rates)
  1055. rate_control_rate_init(sta);
  1056. mutex_unlock(&local->sta_mtx);
  1057. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  1058. params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))
  1059. ieee80211_recalc_ps(local, -1);
  1060. return 0;
  1061. }
  1062. #ifdef CONFIG_MAC80211_MESH
  1063. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  1064. u8 *dst, u8 *next_hop)
  1065. {
  1066. struct ieee80211_sub_if_data *sdata;
  1067. struct mesh_path *mpath;
  1068. struct sta_info *sta;
  1069. int err;
  1070. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1071. rcu_read_lock();
  1072. sta = sta_info_get(sdata, next_hop);
  1073. if (!sta) {
  1074. rcu_read_unlock();
  1075. return -ENOENT;
  1076. }
  1077. err = mesh_path_add(dst, sdata);
  1078. if (err) {
  1079. rcu_read_unlock();
  1080. return err;
  1081. }
  1082. mpath = mesh_path_lookup(dst, sdata);
  1083. if (!mpath) {
  1084. rcu_read_unlock();
  1085. return -ENXIO;
  1086. }
  1087. mesh_path_fix_nexthop(mpath, sta);
  1088. rcu_read_unlock();
  1089. return 0;
  1090. }
  1091. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  1092. u8 *dst)
  1093. {
  1094. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1095. if (dst)
  1096. return mesh_path_del(dst, sdata);
  1097. mesh_path_flush_by_iface(sdata);
  1098. return 0;
  1099. }
  1100. static int ieee80211_change_mpath(struct wiphy *wiphy,
  1101. struct net_device *dev,
  1102. u8 *dst, u8 *next_hop)
  1103. {
  1104. struct ieee80211_sub_if_data *sdata;
  1105. struct mesh_path *mpath;
  1106. struct sta_info *sta;
  1107. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1108. rcu_read_lock();
  1109. sta = sta_info_get(sdata, next_hop);
  1110. if (!sta) {
  1111. rcu_read_unlock();
  1112. return -ENOENT;
  1113. }
  1114. mpath = mesh_path_lookup(dst, sdata);
  1115. if (!mpath) {
  1116. rcu_read_unlock();
  1117. return -ENOENT;
  1118. }
  1119. mesh_path_fix_nexthop(mpath, sta);
  1120. rcu_read_unlock();
  1121. return 0;
  1122. }
  1123. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  1124. struct mpath_info *pinfo)
  1125. {
  1126. struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
  1127. if (next_hop_sta)
  1128. memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
  1129. else
  1130. memset(next_hop, 0, ETH_ALEN);
  1131. pinfo->generation = mesh_paths_generation;
  1132. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  1133. MPATH_INFO_SN |
  1134. MPATH_INFO_METRIC |
  1135. MPATH_INFO_EXPTIME |
  1136. MPATH_INFO_DISCOVERY_TIMEOUT |
  1137. MPATH_INFO_DISCOVERY_RETRIES |
  1138. MPATH_INFO_FLAGS;
  1139. pinfo->frame_qlen = mpath->frame_queue.qlen;
  1140. pinfo->sn = mpath->sn;
  1141. pinfo->metric = mpath->metric;
  1142. if (time_before(jiffies, mpath->exp_time))
  1143. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  1144. pinfo->discovery_timeout =
  1145. jiffies_to_msecs(mpath->discovery_timeout);
  1146. pinfo->discovery_retries = mpath->discovery_retries;
  1147. pinfo->flags = 0;
  1148. if (mpath->flags & MESH_PATH_ACTIVE)
  1149. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  1150. if (mpath->flags & MESH_PATH_RESOLVING)
  1151. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  1152. if (mpath->flags & MESH_PATH_SN_VALID)
  1153. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  1154. if (mpath->flags & MESH_PATH_FIXED)
  1155. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  1156. if (mpath->flags & MESH_PATH_RESOLVING)
  1157. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  1158. pinfo->flags = mpath->flags;
  1159. }
  1160. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  1161. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  1162. {
  1163. struct ieee80211_sub_if_data *sdata;
  1164. struct mesh_path *mpath;
  1165. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1166. rcu_read_lock();
  1167. mpath = mesh_path_lookup(dst, sdata);
  1168. if (!mpath) {
  1169. rcu_read_unlock();
  1170. return -ENOENT;
  1171. }
  1172. memcpy(dst, mpath->dst, ETH_ALEN);
  1173. mpath_set_pinfo(mpath, next_hop, pinfo);
  1174. rcu_read_unlock();
  1175. return 0;
  1176. }
  1177. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  1178. int idx, u8 *dst, u8 *next_hop,
  1179. struct mpath_info *pinfo)
  1180. {
  1181. struct ieee80211_sub_if_data *sdata;
  1182. struct mesh_path *mpath;
  1183. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1184. rcu_read_lock();
  1185. mpath = mesh_path_lookup_by_idx(idx, sdata);
  1186. if (!mpath) {
  1187. rcu_read_unlock();
  1188. return -ENOENT;
  1189. }
  1190. memcpy(dst, mpath->dst, ETH_ALEN);
  1191. mpath_set_pinfo(mpath, next_hop, pinfo);
  1192. rcu_read_unlock();
  1193. return 0;
  1194. }
  1195. static int ieee80211_get_mesh_config(struct wiphy *wiphy,
  1196. struct net_device *dev,
  1197. struct mesh_config *conf)
  1198. {
  1199. struct ieee80211_sub_if_data *sdata;
  1200. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1201. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  1202. return 0;
  1203. }
  1204. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  1205. {
  1206. return (mask >> (parm-1)) & 0x1;
  1207. }
  1208. static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
  1209. const struct mesh_setup *setup)
  1210. {
  1211. u8 *new_ie;
  1212. const u8 *old_ie;
  1213. struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
  1214. struct ieee80211_sub_if_data, u.mesh);
  1215. /* allocate information elements */
  1216. new_ie = NULL;
  1217. old_ie = ifmsh->ie;
  1218. if (setup->ie_len) {
  1219. new_ie = kmemdup(setup->ie, setup->ie_len,
  1220. GFP_KERNEL);
  1221. if (!new_ie)
  1222. return -ENOMEM;
  1223. }
  1224. ifmsh->ie_len = setup->ie_len;
  1225. ifmsh->ie = new_ie;
  1226. kfree(old_ie);
  1227. /* now copy the rest of the setup parameters */
  1228. ifmsh->mesh_id_len = setup->mesh_id_len;
  1229. memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
  1230. ifmsh->mesh_sp_id = setup->sync_method;
  1231. ifmsh->mesh_pp_id = setup->path_sel_proto;
  1232. ifmsh->mesh_pm_id = setup->path_metric;
  1233. ifmsh->security = IEEE80211_MESH_SEC_NONE;
  1234. if (setup->is_authenticated)
  1235. ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
  1236. if (setup->is_secure)
  1237. ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
  1238. /* mcast rate setting in Mesh Node */
  1239. memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
  1240. sizeof(setup->mcast_rate));
  1241. return 0;
  1242. }
  1243. static int ieee80211_update_mesh_config(struct wiphy *wiphy,
  1244. struct net_device *dev, u32 mask,
  1245. const struct mesh_config *nconf)
  1246. {
  1247. struct mesh_config *conf;
  1248. struct ieee80211_sub_if_data *sdata;
  1249. struct ieee80211_if_mesh *ifmsh;
  1250. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1251. ifmsh = &sdata->u.mesh;
  1252. /* Set the config options which we are interested in setting */
  1253. conf = &(sdata->u.mesh.mshcfg);
  1254. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  1255. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  1256. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  1257. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  1258. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  1259. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  1260. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  1261. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  1262. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  1263. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  1264. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  1265. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  1266. if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
  1267. conf->element_ttl = nconf->element_ttl;
  1268. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  1269. conf->auto_open_plinks = nconf->auto_open_plinks;
  1270. if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
  1271. conf->dot11MeshNbrOffsetMaxNeighbor =
  1272. nconf->dot11MeshNbrOffsetMaxNeighbor;
  1273. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  1274. conf->dot11MeshHWMPmaxPREQretries =
  1275. nconf->dot11MeshHWMPmaxPREQretries;
  1276. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  1277. conf->path_refresh_time = nconf->path_refresh_time;
  1278. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  1279. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  1280. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  1281. conf->dot11MeshHWMPactivePathTimeout =
  1282. nconf->dot11MeshHWMPactivePathTimeout;
  1283. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  1284. conf->dot11MeshHWMPpreqMinInterval =
  1285. nconf->dot11MeshHWMPpreqMinInterval;
  1286. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
  1287. conf->dot11MeshHWMPperrMinInterval =
  1288. nconf->dot11MeshHWMPperrMinInterval;
  1289. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  1290. mask))
  1291. conf->dot11MeshHWMPnetDiameterTraversalTime =
  1292. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  1293. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  1294. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  1295. ieee80211_mesh_root_setup(ifmsh);
  1296. }
  1297. if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
  1298. /* our current gate announcement implementation rides on root
  1299. * announcements, so require this ifmsh to also be a root node
  1300. * */
  1301. if (nconf->dot11MeshGateAnnouncementProtocol &&
  1302. !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
  1303. conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
  1304. ieee80211_mesh_root_setup(ifmsh);
  1305. }
  1306. conf->dot11MeshGateAnnouncementProtocol =
  1307. nconf->dot11MeshGateAnnouncementProtocol;
  1308. }
  1309. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
  1310. conf->dot11MeshHWMPRannInterval =
  1311. nconf->dot11MeshHWMPRannInterval;
  1312. if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
  1313. conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
  1314. if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
  1315. /* our RSSI threshold implementation is supported only for
  1316. * devices that report signal in dBm.
  1317. */
  1318. if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
  1319. return -ENOTSUPP;
  1320. conf->rssi_threshold = nconf->rssi_threshold;
  1321. }
  1322. if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
  1323. conf->ht_opmode = nconf->ht_opmode;
  1324. sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
  1325. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
  1326. }
  1327. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
  1328. conf->dot11MeshHWMPactivePathToRootTimeout =
  1329. nconf->dot11MeshHWMPactivePathToRootTimeout;
  1330. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
  1331. conf->dot11MeshHWMProotInterval =
  1332. nconf->dot11MeshHWMProotInterval;
  1333. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
  1334. conf->dot11MeshHWMPconfirmationInterval =
  1335. nconf->dot11MeshHWMPconfirmationInterval;
  1336. return 0;
  1337. }
  1338. static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
  1339. const struct mesh_config *conf,
  1340. const struct mesh_setup *setup)
  1341. {
  1342. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1343. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1344. int err;
  1345. memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
  1346. err = copy_mesh_setup(ifmsh, setup);
  1347. if (err)
  1348. return err;
  1349. err = ieee80211_set_channel(wiphy, dev, setup->channel,
  1350. setup->channel_type);
  1351. if (err)
  1352. return err;
  1353. ieee80211_start_mesh(sdata);
  1354. return 0;
  1355. }
  1356. static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
  1357. {
  1358. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1359. ieee80211_stop_mesh(sdata);
  1360. return 0;
  1361. }
  1362. #endif
  1363. static int ieee80211_change_bss(struct wiphy *wiphy,
  1364. struct net_device *dev,
  1365. struct bss_parameters *params)
  1366. {
  1367. struct ieee80211_sub_if_data *sdata;
  1368. u32 changed = 0;
  1369. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1370. if (params->use_cts_prot >= 0) {
  1371. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  1372. changed |= BSS_CHANGED_ERP_CTS_PROT;
  1373. }
  1374. if (params->use_short_preamble >= 0) {
  1375. sdata->vif.bss_conf.use_short_preamble =
  1376. params->use_short_preamble;
  1377. changed |= BSS_CHANGED_ERP_PREAMBLE;
  1378. }
  1379. if (!sdata->vif.bss_conf.use_short_slot &&
  1380. sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
  1381. sdata->vif.bss_conf.use_short_slot = true;
  1382. changed |= BSS_CHANGED_ERP_SLOT;
  1383. }
  1384. if (params->use_short_slot_time >= 0) {
  1385. sdata->vif.bss_conf.use_short_slot =
  1386. params->use_short_slot_time;
  1387. changed |= BSS_CHANGED_ERP_SLOT;
  1388. }
  1389. if (params->basic_rates) {
  1390. int i, j;
  1391. u32 rates = 0;
  1392. struct ieee80211_local *local = wiphy_priv(wiphy);
  1393. struct ieee80211_supported_band *sband =
  1394. wiphy->bands[local->oper_channel->band];
  1395. for (i = 0; i < params->basic_rates_len; i++) {
  1396. int rate = (params->basic_rates[i] & 0x7f) * 5;
  1397. for (j = 0; j < sband->n_bitrates; j++) {
  1398. if (sband->bitrates[j].bitrate == rate)
  1399. rates |= BIT(j);
  1400. }
  1401. }
  1402. sdata->vif.bss_conf.basic_rates = rates;
  1403. changed |= BSS_CHANGED_BASIC_RATES;
  1404. }
  1405. if (params->ap_isolate >= 0) {
  1406. if (params->ap_isolate)
  1407. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1408. else
  1409. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1410. }
  1411. if (params->ht_opmode >= 0) {
  1412. sdata->vif.bss_conf.ht_operation_mode =
  1413. (u16) params->ht_opmode;
  1414. changed |= BSS_CHANGED_HT;
  1415. }
  1416. ieee80211_bss_info_change_notify(sdata, changed);
  1417. return 0;
  1418. }
  1419. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  1420. struct net_device *dev,
  1421. struct ieee80211_txq_params *params)
  1422. {
  1423. struct ieee80211_local *local = wiphy_priv(wiphy);
  1424. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1425. struct ieee80211_tx_queue_params p;
  1426. if (!local->ops->conf_tx)
  1427. return -EOPNOTSUPP;
  1428. if (local->hw.queues < IEEE80211_NUM_ACS)
  1429. return -EOPNOTSUPP;
  1430. memset(&p, 0, sizeof(p));
  1431. p.aifs = params->aifs;
  1432. p.cw_max = params->cwmax;
  1433. p.cw_min = params->cwmin;
  1434. p.txop = params->txop;
  1435. /*
  1436. * Setting tx queue params disables u-apsd because it's only
  1437. * called in master mode.
  1438. */
  1439. p.uapsd = false;
  1440. sdata->tx_conf[params->ac] = p;
  1441. if (drv_conf_tx(local, sdata, params->ac, &p)) {
  1442. wiphy_debug(local->hw.wiphy,
  1443. "failed to set TX queue parameters for AC %d\n",
  1444. params->ac);
  1445. return -EINVAL;
  1446. }
  1447. return 0;
  1448. }
  1449. #ifdef CONFIG_PM
  1450. static int ieee80211_suspend(struct wiphy *wiphy,
  1451. struct cfg80211_wowlan *wowlan)
  1452. {
  1453. return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
  1454. }
  1455. static int ieee80211_resume(struct wiphy *wiphy)
  1456. {
  1457. return __ieee80211_resume(wiphy_priv(wiphy));
  1458. }
  1459. #else
  1460. #define ieee80211_suspend NULL
  1461. #define ieee80211_resume NULL
  1462. #endif
  1463. static int ieee80211_scan(struct wiphy *wiphy,
  1464. struct net_device *dev,
  1465. struct cfg80211_scan_request *req)
  1466. {
  1467. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1468. switch (ieee80211_vif_type_p2p(&sdata->vif)) {
  1469. case NL80211_IFTYPE_STATION:
  1470. case NL80211_IFTYPE_ADHOC:
  1471. case NL80211_IFTYPE_MESH_POINT:
  1472. case NL80211_IFTYPE_P2P_CLIENT:
  1473. break;
  1474. case NL80211_IFTYPE_P2P_GO:
  1475. if (sdata->local->ops->hw_scan)
  1476. break;
  1477. /*
  1478. * FIXME: implement NoA while scanning in software,
  1479. * for now fall through to allow scanning only when
  1480. * beaconing hasn't been configured yet
  1481. */
  1482. case NL80211_IFTYPE_AP:
  1483. if (sdata->u.ap.beacon)
  1484. return -EOPNOTSUPP;
  1485. break;
  1486. default:
  1487. return -EOPNOTSUPP;
  1488. }
  1489. return ieee80211_request_scan(sdata, req);
  1490. }
  1491. static int
  1492. ieee80211_sched_scan_start(struct wiphy *wiphy,
  1493. struct net_device *dev,
  1494. struct cfg80211_sched_scan_request *req)
  1495. {
  1496. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1497. if (!sdata->local->ops->sched_scan_start)
  1498. return -EOPNOTSUPP;
  1499. return ieee80211_request_sched_scan_start(sdata, req);
  1500. }
  1501. static int
  1502. ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
  1503. {
  1504. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1505. if (!sdata->local->ops->sched_scan_stop)
  1506. return -EOPNOTSUPP;
  1507. return ieee80211_request_sched_scan_stop(sdata);
  1508. }
  1509. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  1510. struct cfg80211_auth_request *req)
  1511. {
  1512. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1513. }
  1514. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  1515. struct cfg80211_assoc_request *req)
  1516. {
  1517. struct ieee80211_local *local = wiphy_priv(wiphy);
  1518. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1519. switch (ieee80211_get_channel_mode(local, sdata)) {
  1520. case CHAN_MODE_HOPPING:
  1521. return -EBUSY;
  1522. case CHAN_MODE_FIXED:
  1523. if (local->oper_channel == req->bss->channel)
  1524. break;
  1525. return -EBUSY;
  1526. case CHAN_MODE_UNDEFINED:
  1527. break;
  1528. }
  1529. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1530. }
  1531. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1532. struct cfg80211_deauth_request *req)
  1533. {
  1534. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1535. }
  1536. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1537. struct cfg80211_disassoc_request *req)
  1538. {
  1539. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1540. }
  1541. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1542. struct cfg80211_ibss_params *params)
  1543. {
  1544. struct ieee80211_local *local = wiphy_priv(wiphy);
  1545. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1546. switch (ieee80211_get_channel_mode(local, sdata)) {
  1547. case CHAN_MODE_HOPPING:
  1548. return -EBUSY;
  1549. case CHAN_MODE_FIXED:
  1550. if (!params->channel_fixed)
  1551. return -EBUSY;
  1552. if (local->oper_channel == params->channel)
  1553. break;
  1554. return -EBUSY;
  1555. case CHAN_MODE_UNDEFINED:
  1556. break;
  1557. }
  1558. return ieee80211_ibss_join(sdata, params);
  1559. }
  1560. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1561. {
  1562. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1563. return ieee80211_ibss_leave(sdata);
  1564. }
  1565. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1566. {
  1567. struct ieee80211_local *local = wiphy_priv(wiphy);
  1568. int err;
  1569. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  1570. err = drv_set_frag_threshold(local, wiphy->frag_threshold);
  1571. if (err)
  1572. return err;
  1573. }
  1574. if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
  1575. err = drv_set_coverage_class(local, wiphy->coverage_class);
  1576. if (err)
  1577. return err;
  1578. }
  1579. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1580. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1581. if (err)
  1582. return err;
  1583. }
  1584. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1585. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1586. if (changed & WIPHY_PARAM_RETRY_LONG)
  1587. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1588. if (changed &
  1589. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1590. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1591. return 0;
  1592. }
  1593. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1594. enum nl80211_tx_power_setting type, int mbm)
  1595. {
  1596. struct ieee80211_local *local = wiphy_priv(wiphy);
  1597. struct ieee80211_channel *chan = local->hw.conf.channel;
  1598. u32 changes = 0;
  1599. switch (type) {
  1600. case NL80211_TX_POWER_AUTOMATIC:
  1601. local->user_power_level = -1;
  1602. break;
  1603. case NL80211_TX_POWER_LIMITED:
  1604. if (mbm < 0 || (mbm % 100))
  1605. return -EOPNOTSUPP;
  1606. local->user_power_level = MBM_TO_DBM(mbm);
  1607. break;
  1608. case NL80211_TX_POWER_FIXED:
  1609. if (mbm < 0 || (mbm % 100))
  1610. return -EOPNOTSUPP;
  1611. /* TODO: move to cfg80211 when it knows the channel */
  1612. if (MBM_TO_DBM(mbm) > chan->max_power)
  1613. return -EINVAL;
  1614. local->user_power_level = MBM_TO_DBM(mbm);
  1615. break;
  1616. }
  1617. ieee80211_hw_config(local, changes);
  1618. return 0;
  1619. }
  1620. static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
  1621. {
  1622. struct ieee80211_local *local = wiphy_priv(wiphy);
  1623. *dbm = local->hw.conf.power_level;
  1624. return 0;
  1625. }
  1626. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  1627. const u8 *addr)
  1628. {
  1629. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1630. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  1631. return 0;
  1632. }
  1633. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1634. {
  1635. struct ieee80211_local *local = wiphy_priv(wiphy);
  1636. drv_rfkill_poll(local);
  1637. }
  1638. #ifdef CONFIG_NL80211_TESTMODE
  1639. static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
  1640. {
  1641. struct ieee80211_local *local = wiphy_priv(wiphy);
  1642. if (!local->ops->testmode_cmd)
  1643. return -EOPNOTSUPP;
  1644. return local->ops->testmode_cmd(&local->hw, data, len);
  1645. }
  1646. static int ieee80211_testmode_dump(struct wiphy *wiphy,
  1647. struct sk_buff *skb,
  1648. struct netlink_callback *cb,
  1649. void *data, int len)
  1650. {
  1651. struct ieee80211_local *local = wiphy_priv(wiphy);
  1652. if (!local->ops->testmode_dump)
  1653. return -EOPNOTSUPP;
  1654. return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
  1655. }
  1656. #endif
  1657. int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
  1658. enum ieee80211_smps_mode smps_mode)
  1659. {
  1660. const u8 *ap;
  1661. enum ieee80211_smps_mode old_req;
  1662. int err;
  1663. lockdep_assert_held(&sdata->u.mgd.mtx);
  1664. old_req = sdata->u.mgd.req_smps;
  1665. sdata->u.mgd.req_smps = smps_mode;
  1666. if (old_req == smps_mode &&
  1667. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  1668. return 0;
  1669. /*
  1670. * If not associated, or current association is not an HT
  1671. * association, there's no need to send an action frame.
  1672. */
  1673. if (!sdata->u.mgd.associated ||
  1674. sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
  1675. mutex_lock(&sdata->local->iflist_mtx);
  1676. ieee80211_recalc_smps(sdata->local);
  1677. mutex_unlock(&sdata->local->iflist_mtx);
  1678. return 0;
  1679. }
  1680. ap = sdata->u.mgd.associated->bssid;
  1681. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  1682. if (sdata->u.mgd.powersave)
  1683. smps_mode = IEEE80211_SMPS_DYNAMIC;
  1684. else
  1685. smps_mode = IEEE80211_SMPS_OFF;
  1686. }
  1687. /* send SM PS frame to AP */
  1688. err = ieee80211_send_smps_action(sdata, smps_mode,
  1689. ap, ap);
  1690. if (err)
  1691. sdata->u.mgd.req_smps = old_req;
  1692. return err;
  1693. }
  1694. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1695. bool enabled, int timeout)
  1696. {
  1697. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1698. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1699. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1700. return -EOPNOTSUPP;
  1701. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  1702. return -EOPNOTSUPP;
  1703. if (enabled == sdata->u.mgd.powersave &&
  1704. timeout == local->dynamic_ps_forced_timeout)
  1705. return 0;
  1706. sdata->u.mgd.powersave = enabled;
  1707. local->dynamic_ps_forced_timeout = timeout;
  1708. /* no change, but if automatic follow powersave */
  1709. mutex_lock(&sdata->u.mgd.mtx);
  1710. __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
  1711. mutex_unlock(&sdata->u.mgd.mtx);
  1712. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  1713. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1714. ieee80211_recalc_ps(local, -1);
  1715. return 0;
  1716. }
  1717. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  1718. struct net_device *dev,
  1719. s32 rssi_thold, u32 rssi_hyst)
  1720. {
  1721. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1722. struct ieee80211_vif *vif = &sdata->vif;
  1723. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1724. if (rssi_thold == bss_conf->cqm_rssi_thold &&
  1725. rssi_hyst == bss_conf->cqm_rssi_hyst)
  1726. return 0;
  1727. bss_conf->cqm_rssi_thold = rssi_thold;
  1728. bss_conf->cqm_rssi_hyst = rssi_hyst;
  1729. /* tell the driver upon association, unless already associated */
  1730. if (sdata->u.mgd.associated &&
  1731. sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
  1732. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  1733. return 0;
  1734. }
  1735. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  1736. struct net_device *dev,
  1737. const u8 *addr,
  1738. const struct cfg80211_bitrate_mask *mask)
  1739. {
  1740. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1741. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1742. int i, ret;
  1743. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
  1744. ret = drv_set_bitrate_mask(local, sdata, mask);
  1745. if (ret)
  1746. return ret;
  1747. }
  1748. for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
  1749. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  1750. memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
  1751. sizeof(mask->control[i].mcs));
  1752. }
  1753. return 0;
  1754. }
  1755. static int ieee80211_start_roc_work(struct ieee80211_local *local,
  1756. struct ieee80211_sub_if_data *sdata,
  1757. struct ieee80211_channel *channel,
  1758. enum nl80211_channel_type channel_type,
  1759. unsigned int duration, u64 *cookie,
  1760. struct sk_buff *txskb)
  1761. {
  1762. struct ieee80211_roc_work *roc, *tmp;
  1763. bool queued = false;
  1764. int ret;
  1765. lockdep_assert_held(&local->mtx);
  1766. roc = kzalloc(sizeof(*roc), GFP_KERNEL);
  1767. if (!roc)
  1768. return -ENOMEM;
  1769. roc->chan = channel;
  1770. roc->chan_type = channel_type;
  1771. roc->duration = duration;
  1772. roc->req_duration = duration;
  1773. roc->frame = txskb;
  1774. roc->mgmt_tx_cookie = (unsigned long)txskb;
  1775. roc->sdata = sdata;
  1776. INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
  1777. INIT_LIST_HEAD(&roc->dependents);
  1778. /* if there's one pending or we're scanning, queue this one */
  1779. if (!list_empty(&local->roc_list) || local->scanning)
  1780. goto out_check_combine;
  1781. /* if not HW assist, just queue & schedule work */
  1782. if (!local->ops->remain_on_channel) {
  1783. ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
  1784. goto out_queue;
  1785. }
  1786. /* otherwise actually kick it off here (for error handling) */
  1787. /*
  1788. * If the duration is zero, then the driver
  1789. * wouldn't actually do anything. Set it to
  1790. * 10 for now.
  1791. *
  1792. * TODO: cancel the off-channel operation
  1793. * when we get the SKB's TX status and
  1794. * the wait time was zero before.
  1795. */
  1796. if (!duration)
  1797. duration = 10;
  1798. ret = drv_remain_on_channel(local, channel, channel_type, duration);
  1799. if (ret) {
  1800. kfree(roc);
  1801. return ret;
  1802. }
  1803. roc->started = true;
  1804. goto out_queue;
  1805. out_check_combine:
  1806. list_for_each_entry(tmp, &local->roc_list, list) {
  1807. if (tmp->chan != channel || tmp->chan_type != channel_type)
  1808. continue;
  1809. /*
  1810. * Extend this ROC if possible:
  1811. *
  1812. * If it hasn't started yet, just increase the duration
  1813. * and add the new one to the list of dependents.
  1814. */
  1815. if (!tmp->started) {
  1816. list_add_tail(&roc->list, &tmp->dependents);
  1817. tmp->duration = max(tmp->duration, roc->duration);
  1818. queued = true;
  1819. break;
  1820. }
  1821. /* If it has already started, it's more difficult ... */
  1822. if (local->ops->remain_on_channel) {
  1823. unsigned long j = jiffies;
  1824. /*
  1825. * In the offloaded ROC case, if it hasn't begun, add
  1826. * this new one to the dependent list to be handled
  1827. * when the the master one begins. If it has begun,
  1828. * check that there's still a minimum time left and
  1829. * if so, start this one, transmitting the frame, but
  1830. * add it to the list directly after this one with a
  1831. * a reduced time so we'll ask the driver to execute
  1832. * it right after finishing the previous one, in the
  1833. * hope that it'll also be executed right afterwards,
  1834. * effectively extending the old one.
  1835. * If there's no minimum time left, just add it to the
  1836. * normal list.
  1837. */
  1838. if (!tmp->hw_begun) {
  1839. list_add_tail(&roc->list, &tmp->dependents);
  1840. queued = true;
  1841. break;
  1842. }
  1843. if (time_before(j + IEEE80211_ROC_MIN_LEFT,
  1844. tmp->hw_start_time +
  1845. msecs_to_jiffies(tmp->duration))) {
  1846. int new_dur;
  1847. ieee80211_handle_roc_started(roc);
  1848. new_dur = roc->duration -
  1849. jiffies_to_msecs(tmp->hw_start_time +
  1850. msecs_to_jiffies(
  1851. tmp->duration) -
  1852. j);
  1853. if (new_dur > 0) {
  1854. /* add right after tmp */
  1855. list_add(&roc->list, &tmp->list);
  1856. } else {
  1857. list_add_tail(&roc->list,
  1858. &tmp->dependents);
  1859. }
  1860. queued = true;
  1861. }
  1862. } else if (del_timer_sync(&tmp->work.timer)) {
  1863. unsigned long new_end;
  1864. /*
  1865. * In the software ROC case, cancel the timer, if
  1866. * that fails then the finish work is already
  1867. * queued/pending and thus we queue the new ROC
  1868. * normally, if that succeeds then we can extend
  1869. * the timer duration and TX the frame (if any.)
  1870. */
  1871. list_add_tail(&roc->list, &tmp->dependents);
  1872. queued = true;
  1873. new_end = jiffies + msecs_to_jiffies(roc->duration);
  1874. /* ok, it was started & we canceled timer */
  1875. if (time_after(new_end, tmp->work.timer.expires))
  1876. mod_timer(&tmp->work.timer, new_end);
  1877. else
  1878. add_timer(&tmp->work.timer);
  1879. ieee80211_handle_roc_started(roc);
  1880. }
  1881. break;
  1882. }
  1883. out_queue:
  1884. if (!queued)
  1885. list_add_tail(&roc->list, &local->roc_list);
  1886. /*
  1887. * cookie is either the roc (for normal roc)
  1888. * or the SKB (for mgmt TX)
  1889. */
  1890. if (txskb)
  1891. *cookie = (unsigned long)txskb;
  1892. else
  1893. *cookie = (unsigned long)roc;
  1894. return 0;
  1895. }
  1896. static int ieee80211_remain_on_channel(struct wiphy *wiphy,
  1897. struct net_device *dev,
  1898. struct ieee80211_channel *chan,
  1899. enum nl80211_channel_type channel_type,
  1900. unsigned int duration,
  1901. u64 *cookie)
  1902. {
  1903. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1904. struct ieee80211_local *local = sdata->local;
  1905. int ret;
  1906. mutex_lock(&local->mtx);
  1907. ret = ieee80211_start_roc_work(local, sdata, chan, channel_type,
  1908. duration, cookie, NULL);
  1909. mutex_unlock(&local->mtx);
  1910. return ret;
  1911. }
  1912. static int ieee80211_cancel_roc(struct ieee80211_local *local,
  1913. u64 cookie, bool mgmt_tx)
  1914. {
  1915. struct ieee80211_roc_work *roc, *tmp, *found = NULL;
  1916. int ret;
  1917. mutex_lock(&local->mtx);
  1918. list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
  1919. struct ieee80211_roc_work *dep, *tmp2;
  1920. list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
  1921. if (!mgmt_tx && (unsigned long)dep != cookie)
  1922. continue;
  1923. else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
  1924. continue;
  1925. /* found dependent item -- just remove it */
  1926. list_del(&dep->list);
  1927. mutex_unlock(&local->mtx);
  1928. ieee80211_roc_notify_destroy(dep);
  1929. return 0;
  1930. }
  1931. if (!mgmt_tx && (unsigned long)roc != cookie)
  1932. continue;
  1933. else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
  1934. continue;
  1935. found = roc;
  1936. break;
  1937. }
  1938. if (!found) {
  1939. mutex_unlock(&local->mtx);
  1940. return -ENOENT;
  1941. }
  1942. /*
  1943. * We found the item to cancel, so do that. Note that it
  1944. * may have dependents, which we also cancel (and send
  1945. * the expired signal for.) Not doing so would be quite
  1946. * tricky here, but we may need to fix it later.
  1947. */
  1948. if (local->ops->remain_on_channel) {
  1949. if (found->started) {
  1950. ret = drv_cancel_remain_on_channel(local);
  1951. if (WARN_ON_ONCE(ret)) {
  1952. mutex_unlock(&local->mtx);
  1953. return ret;
  1954. }
  1955. }
  1956. list_del(&found->list);
  1957. if (found->started)
  1958. ieee80211_start_next_roc(local);
  1959. mutex_unlock(&local->mtx);
  1960. ieee80211_roc_notify_destroy(found);
  1961. } else {
  1962. /* work may be pending so use it all the time */
  1963. found->abort = true;
  1964. ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
  1965. mutex_unlock(&local->mtx);
  1966. /* work will clean up etc */
  1967. flush_delayed_work(&found->work);
  1968. }
  1969. return 0;
  1970. }
  1971. static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
  1972. struct net_device *dev,
  1973. u64 cookie)
  1974. {
  1975. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1976. struct ieee80211_local *local = sdata->local;
  1977. return ieee80211_cancel_roc(local, cookie, false);
  1978. }
  1979. static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
  1980. struct ieee80211_channel *chan, bool offchan,
  1981. enum nl80211_channel_type channel_type,
  1982. bool channel_type_valid, unsigned int wait,
  1983. const u8 *buf, size_t len, bool no_cck,
  1984. bool dont_wait_for_ack, u64 *cookie)
  1985. {
  1986. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1987. struct ieee80211_local *local = sdata->local;
  1988. struct sk_buff *skb;
  1989. struct sta_info *sta;
  1990. const struct ieee80211_mgmt *mgmt = (void *)buf;
  1991. bool need_offchan = false;
  1992. u32 flags;
  1993. int ret;
  1994. if (dont_wait_for_ack)
  1995. flags = IEEE80211_TX_CTL_NO_ACK;
  1996. else
  1997. flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
  1998. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1999. if (no_cck)
  2000. flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
  2001. switch (sdata->vif.type) {
  2002. case NL80211_IFTYPE_ADHOC:
  2003. if (!sdata->vif.bss_conf.ibss_joined)
  2004. need_offchan = true;
  2005. /* fall through */
  2006. #ifdef CONFIG_MAC80211_MESH
  2007. case NL80211_IFTYPE_MESH_POINT:
  2008. if (ieee80211_vif_is_mesh(&sdata->vif) &&
  2009. !sdata->u.mesh.mesh_id_len)
  2010. need_offchan = true;
  2011. /* fall through */
  2012. #endif
  2013. case NL80211_IFTYPE_AP:
  2014. case NL80211_IFTYPE_AP_VLAN:
  2015. case NL80211_IFTYPE_P2P_GO:
  2016. if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  2017. !ieee80211_vif_is_mesh(&sdata->vif) &&
  2018. !rcu_access_pointer(sdata->bss->beacon))
  2019. need_offchan = true;
  2020. if (!ieee80211_is_action(mgmt->frame_control) ||
  2021. mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
  2022. break;
  2023. rcu_read_lock();
  2024. sta = sta_info_get(sdata, mgmt->da);
  2025. rcu_read_unlock();
  2026. if (!sta)
  2027. return -ENOLINK;
  2028. break;
  2029. case NL80211_IFTYPE_STATION:
  2030. case NL80211_IFTYPE_P2P_CLIENT:
  2031. if (!sdata->u.mgd.associated)
  2032. need_offchan = true;
  2033. break;
  2034. default:
  2035. return -EOPNOTSUPP;
  2036. }
  2037. mutex_lock(&local->mtx);
  2038. /* Check if the operating channel is the requested channel */
  2039. if (!need_offchan) {
  2040. need_offchan = chan != local->oper_channel;
  2041. if (channel_type_valid &&
  2042. channel_type != local->_oper_channel_type)
  2043. need_offchan = true;
  2044. }
  2045. if (need_offchan && !offchan) {
  2046. ret = -EBUSY;
  2047. goto out_unlock;
  2048. }
  2049. skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
  2050. if (!skb) {
  2051. ret = -ENOMEM;
  2052. goto out_unlock;
  2053. }
  2054. skb_reserve(skb, local->hw.extra_tx_headroom);
  2055. memcpy(skb_put(skb, len), buf, len);
  2056. IEEE80211_SKB_CB(skb)->flags = flags;
  2057. skb->dev = sdata->dev;
  2058. if (!need_offchan) {
  2059. ieee80211_tx_skb(sdata, skb);
  2060. ret = 0;
  2061. goto out_unlock;
  2062. }
  2063. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
  2064. if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
  2065. IEEE80211_SKB_CB(skb)->hw_queue =
  2066. local->hw.offchannel_tx_hw_queue;
  2067. /* This will handle all kinds of coalescing and immediate TX */
  2068. ret = ieee80211_start_roc_work(local, sdata, chan, channel_type,
  2069. wait, cookie, skb);
  2070. if (ret)
  2071. kfree_skb(skb);
  2072. out_unlock:
  2073. mutex_unlock(&local->mtx);
  2074. return ret;
  2075. }
  2076. static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
  2077. struct net_device *dev,
  2078. u64 cookie)
  2079. {
  2080. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2081. struct ieee80211_local *local = sdata->local;
  2082. return ieee80211_cancel_roc(local, cookie, true);
  2083. }
  2084. static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
  2085. struct net_device *dev,
  2086. u16 frame_type, bool reg)
  2087. {
  2088. struct ieee80211_local *local = wiphy_priv(wiphy);
  2089. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2090. switch (frame_type) {
  2091. case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH:
  2092. if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  2093. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  2094. if (reg)
  2095. ifibss->auth_frame_registrations++;
  2096. else
  2097. ifibss->auth_frame_registrations--;
  2098. }
  2099. break;
  2100. case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
  2101. if (reg)
  2102. local->probe_req_reg++;
  2103. else
  2104. local->probe_req_reg--;
  2105. ieee80211_queue_work(&local->hw, &local->reconfig_filter);
  2106. break;
  2107. default:
  2108. break;
  2109. }
  2110. }
  2111. static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  2112. {
  2113. struct ieee80211_local *local = wiphy_priv(wiphy);
  2114. if (local->started)
  2115. return -EOPNOTSUPP;
  2116. return drv_set_antenna(local, tx_ant, rx_ant);
  2117. }
  2118. static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
  2119. {
  2120. struct ieee80211_local *local = wiphy_priv(wiphy);
  2121. return drv_get_antenna(local, tx_ant, rx_ant);
  2122. }
  2123. static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
  2124. {
  2125. struct ieee80211_local *local = wiphy_priv(wiphy);
  2126. return drv_set_ringparam(local, tx, rx);
  2127. }
  2128. static void ieee80211_get_ringparam(struct wiphy *wiphy,
  2129. u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
  2130. {
  2131. struct ieee80211_local *local = wiphy_priv(wiphy);
  2132. drv_get_ringparam(local, tx, tx_max, rx, rx_max);
  2133. }
  2134. static int ieee80211_set_rekey_data(struct wiphy *wiphy,
  2135. struct net_device *dev,
  2136. struct cfg80211_gtk_rekey_data *data)
  2137. {
  2138. struct ieee80211_local *local = wiphy_priv(wiphy);
  2139. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2140. if (!local->ops->set_rekey_data)
  2141. return -EOPNOTSUPP;
  2142. drv_set_rekey_data(local, sdata, data);
  2143. return 0;
  2144. }
  2145. static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
  2146. {
  2147. u8 *pos = (void *)skb_put(skb, 7);
  2148. *pos++ = WLAN_EID_EXT_CAPABILITY;
  2149. *pos++ = 5; /* len */
  2150. *pos++ = 0x0;
  2151. *pos++ = 0x0;
  2152. *pos++ = 0x0;
  2153. *pos++ = 0x0;
  2154. *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
  2155. }
  2156. static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
  2157. {
  2158. struct ieee80211_local *local = sdata->local;
  2159. u16 capab;
  2160. capab = 0;
  2161. if (local->oper_channel->band != IEEE80211_BAND_2GHZ)
  2162. return capab;
  2163. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
  2164. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  2165. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
  2166. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  2167. return capab;
  2168. }
  2169. static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
  2170. u8 *peer, u8 *bssid)
  2171. {
  2172. struct ieee80211_tdls_lnkie *lnkid;
  2173. lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
  2174. lnkid->ie_type = WLAN_EID_LINK_ID;
  2175. lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
  2176. memcpy(lnkid->bssid, bssid, ETH_ALEN);
  2177. memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
  2178. memcpy(lnkid->resp_sta, peer, ETH_ALEN);
  2179. }
  2180. static int
  2181. ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
  2182. u8 *peer, u8 action_code, u8 dialog_token,
  2183. u16 status_code, struct sk_buff *skb)
  2184. {
  2185. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2186. struct ieee80211_tdls_data *tf;
  2187. tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
  2188. memcpy(tf->da, peer, ETH_ALEN);
  2189. memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
  2190. tf->ether_type = cpu_to_be16(ETH_P_TDLS);
  2191. tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
  2192. switch (action_code) {
  2193. case WLAN_TDLS_SETUP_REQUEST:
  2194. tf->category = WLAN_CATEGORY_TDLS;
  2195. tf->action_code = WLAN_TDLS_SETUP_REQUEST;
  2196. skb_put(skb, sizeof(tf->u.setup_req));
  2197. tf->u.setup_req.dialog_token = dialog_token;
  2198. tf->u.setup_req.capability =
  2199. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  2200. ieee80211_add_srates_ie(&sdata->vif, skb, false);
  2201. ieee80211_add_ext_srates_ie(&sdata->vif, skb, false);
  2202. ieee80211_tdls_add_ext_capab(skb);
  2203. break;
  2204. case WLAN_TDLS_SETUP_RESPONSE:
  2205. tf->category = WLAN_CATEGORY_TDLS;
  2206. tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
  2207. skb_put(skb, sizeof(tf->u.setup_resp));
  2208. tf->u.setup_resp.status_code = cpu_to_le16(status_code);
  2209. tf->u.setup_resp.dialog_token = dialog_token;
  2210. tf->u.setup_resp.capability =
  2211. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  2212. ieee80211_add_srates_ie(&sdata->vif, skb, false);
  2213. ieee80211_add_ext_srates_ie(&sdata->vif, skb, false);
  2214. ieee80211_tdls_add_ext_capab(skb);
  2215. break;
  2216. case WLAN_TDLS_SETUP_CONFIRM:
  2217. tf->category = WLAN_CATEGORY_TDLS;
  2218. tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
  2219. skb_put(skb, sizeof(tf->u.setup_cfm));
  2220. tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
  2221. tf->u.setup_cfm.dialog_token = dialog_token;
  2222. break;
  2223. case WLAN_TDLS_TEARDOWN:
  2224. tf->category = WLAN_CATEGORY_TDLS;
  2225. tf->action_code = WLAN_TDLS_TEARDOWN;
  2226. skb_put(skb, sizeof(tf->u.teardown));
  2227. tf->u.teardown.reason_code = cpu_to_le16(status_code);
  2228. break;
  2229. case WLAN_TDLS_DISCOVERY_REQUEST:
  2230. tf->category = WLAN_CATEGORY_TDLS;
  2231. tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
  2232. skb_put(skb, sizeof(tf->u.discover_req));
  2233. tf->u.discover_req.dialog_token = dialog_token;
  2234. break;
  2235. default:
  2236. return -EINVAL;
  2237. }
  2238. return 0;
  2239. }
  2240. static int
  2241. ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
  2242. u8 *peer, u8 action_code, u8 dialog_token,
  2243. u16 status_code, struct sk_buff *skb)
  2244. {
  2245. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2246. struct ieee80211_mgmt *mgmt;
  2247. mgmt = (void *)skb_put(skb, 24);
  2248. memset(mgmt, 0, 24);
  2249. memcpy(mgmt->da, peer, ETH_ALEN);
  2250. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  2251. memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
  2252. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  2253. IEEE80211_STYPE_ACTION);
  2254. switch (action_code) {
  2255. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  2256. skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
  2257. mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
  2258. mgmt->u.action.u.tdls_discover_resp.action_code =
  2259. WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
  2260. mgmt->u.action.u.tdls_discover_resp.dialog_token =
  2261. dialog_token;
  2262. mgmt->u.action.u.tdls_discover_resp.capability =
  2263. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  2264. ieee80211_add_srates_ie(&sdata->vif, skb, false);
  2265. ieee80211_add_ext_srates_ie(&sdata->vif, skb, false);
  2266. ieee80211_tdls_add_ext_capab(skb);
  2267. break;
  2268. default:
  2269. return -EINVAL;
  2270. }
  2271. return 0;
  2272. }
  2273. static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
  2274. u8 *peer, u8 action_code, u8 dialog_token,
  2275. u16 status_code, const u8 *extra_ies,
  2276. size_t extra_ies_len)
  2277. {
  2278. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2279. struct ieee80211_local *local = sdata->local;
  2280. struct ieee80211_tx_info *info;
  2281. struct sk_buff *skb = NULL;
  2282. bool send_direct;
  2283. int ret;
  2284. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
  2285. return -ENOTSUPP;
  2286. /* make sure we are in managed mode, and associated */
  2287. if (sdata->vif.type != NL80211_IFTYPE_STATION ||
  2288. !sdata->u.mgd.associated)
  2289. return -EINVAL;
  2290. #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
  2291. pr_debug("TDLS mgmt action %d peer %pM\n", action_code, peer);
  2292. #endif
  2293. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  2294. max(sizeof(struct ieee80211_mgmt),
  2295. sizeof(struct ieee80211_tdls_data)) +
  2296. 50 + /* supported rates */
  2297. 7 + /* ext capab */
  2298. extra_ies_len +
  2299. sizeof(struct ieee80211_tdls_lnkie));
  2300. if (!skb)
  2301. return -ENOMEM;
  2302. info = IEEE80211_SKB_CB(skb);
  2303. skb_reserve(skb, local->hw.extra_tx_headroom);
  2304. switch (action_code) {
  2305. case WLAN_TDLS_SETUP_REQUEST:
  2306. case WLAN_TDLS_SETUP_RESPONSE:
  2307. case WLAN_TDLS_SETUP_CONFIRM:
  2308. case WLAN_TDLS_TEARDOWN:
  2309. case WLAN_TDLS_DISCOVERY_REQUEST:
  2310. ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
  2311. action_code, dialog_token,
  2312. status_code, skb);
  2313. send_direct = false;
  2314. break;
  2315. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  2316. ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
  2317. dialog_token, status_code,
  2318. skb);
  2319. send_direct = true;
  2320. break;
  2321. default:
  2322. ret = -ENOTSUPP;
  2323. break;
  2324. }
  2325. if (ret < 0)
  2326. goto fail;
  2327. if (extra_ies_len)
  2328. memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
  2329. /* the TDLS link IE is always added last */
  2330. switch (action_code) {
  2331. case WLAN_TDLS_SETUP_REQUEST:
  2332. case WLAN_TDLS_SETUP_CONFIRM:
  2333. case WLAN_TDLS_TEARDOWN:
  2334. case WLAN_TDLS_DISCOVERY_REQUEST:
  2335. /* we are the initiator */
  2336. ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
  2337. sdata->u.mgd.bssid);
  2338. break;
  2339. case WLAN_TDLS_SETUP_RESPONSE:
  2340. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  2341. /* we are the responder */
  2342. ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
  2343. sdata->u.mgd.bssid);
  2344. break;
  2345. default:
  2346. ret = -ENOTSUPP;
  2347. goto fail;
  2348. }
  2349. if (send_direct) {
  2350. ieee80211_tx_skb(sdata, skb);
  2351. return 0;
  2352. }
  2353. /*
  2354. * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
  2355. * we should default to AC_VI.
  2356. */
  2357. switch (action_code) {
  2358. case WLAN_TDLS_SETUP_REQUEST:
  2359. case WLAN_TDLS_SETUP_RESPONSE:
  2360. skb_set_queue_mapping(skb, IEEE80211_AC_BK);
  2361. skb->priority = 2;
  2362. break;
  2363. default:
  2364. skb_set_queue_mapping(skb, IEEE80211_AC_VI);
  2365. skb->priority = 5;
  2366. break;
  2367. }
  2368. /* disable bottom halves when entering the Tx path */
  2369. local_bh_disable();
  2370. ret = ieee80211_subif_start_xmit(skb, dev);
  2371. local_bh_enable();
  2372. return ret;
  2373. fail:
  2374. dev_kfree_skb(skb);
  2375. return ret;
  2376. }
  2377. static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
  2378. u8 *peer, enum nl80211_tdls_operation oper)
  2379. {
  2380. struct sta_info *sta;
  2381. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2382. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
  2383. return -ENOTSUPP;
  2384. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2385. return -EINVAL;
  2386. #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
  2387. pr_debug("TDLS oper %d peer %pM\n", oper, peer);
  2388. #endif
  2389. switch (oper) {
  2390. case NL80211_TDLS_ENABLE_LINK:
  2391. rcu_read_lock();
  2392. sta = sta_info_get(sdata, peer);
  2393. if (!sta) {
  2394. rcu_read_unlock();
  2395. return -ENOLINK;
  2396. }
  2397. set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
  2398. rcu_read_unlock();
  2399. break;
  2400. case NL80211_TDLS_DISABLE_LINK:
  2401. return sta_info_destroy_addr(sdata, peer);
  2402. case NL80211_TDLS_TEARDOWN:
  2403. case NL80211_TDLS_SETUP:
  2404. case NL80211_TDLS_DISCOVERY_REQ:
  2405. /* We don't support in-driver setup/teardown/discovery */
  2406. return -ENOTSUPP;
  2407. default:
  2408. return -ENOTSUPP;
  2409. }
  2410. return 0;
  2411. }
  2412. static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
  2413. const u8 *peer, u64 *cookie)
  2414. {
  2415. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2416. struct ieee80211_local *local = sdata->local;
  2417. struct ieee80211_qos_hdr *nullfunc;
  2418. struct sk_buff *skb;
  2419. int size = sizeof(*nullfunc);
  2420. __le16 fc;
  2421. bool qos;
  2422. struct ieee80211_tx_info *info;
  2423. struct sta_info *sta;
  2424. rcu_read_lock();
  2425. sta = sta_info_get(sdata, peer);
  2426. if (sta) {
  2427. qos = test_sta_flag(sta, WLAN_STA_WME);
  2428. rcu_read_unlock();
  2429. } else {
  2430. rcu_read_unlock();
  2431. return -ENOLINK;
  2432. }
  2433. if (qos) {
  2434. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  2435. IEEE80211_STYPE_QOS_NULLFUNC |
  2436. IEEE80211_FCTL_FROMDS);
  2437. } else {
  2438. size -= 2;
  2439. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  2440. IEEE80211_STYPE_NULLFUNC |
  2441. IEEE80211_FCTL_FROMDS);
  2442. }
  2443. skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
  2444. if (!skb)
  2445. return -ENOMEM;
  2446. skb->dev = dev;
  2447. skb_reserve(skb, local->hw.extra_tx_headroom);
  2448. nullfunc = (void *) skb_put(skb, size);
  2449. nullfunc->frame_control = fc;
  2450. nullfunc->duration_id = 0;
  2451. memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
  2452. memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
  2453. memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
  2454. nullfunc->seq_ctrl = 0;
  2455. info = IEEE80211_SKB_CB(skb);
  2456. info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
  2457. IEEE80211_TX_INTFL_NL80211_FRAME_TX;
  2458. skb_set_queue_mapping(skb, IEEE80211_AC_VO);
  2459. skb->priority = 7;
  2460. if (qos)
  2461. nullfunc->qos_ctrl = cpu_to_le16(7);
  2462. local_bh_disable();
  2463. ieee80211_xmit(sdata, skb);
  2464. local_bh_enable();
  2465. *cookie = (unsigned long) skb;
  2466. return 0;
  2467. }
  2468. static struct ieee80211_channel *
  2469. ieee80211_wiphy_get_channel(struct wiphy *wiphy,
  2470. enum nl80211_channel_type *type)
  2471. {
  2472. struct ieee80211_local *local = wiphy_priv(wiphy);
  2473. *type = local->_oper_channel_type;
  2474. return local->oper_channel;
  2475. }
  2476. #ifdef CONFIG_PM
  2477. static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
  2478. {
  2479. drv_set_wakeup(wiphy_priv(wiphy), enabled);
  2480. }
  2481. #endif
  2482. struct cfg80211_ops mac80211_config_ops = {
  2483. .add_virtual_intf = ieee80211_add_iface,
  2484. .del_virtual_intf = ieee80211_del_iface,
  2485. .change_virtual_intf = ieee80211_change_iface,
  2486. .add_key = ieee80211_add_key,
  2487. .del_key = ieee80211_del_key,
  2488. .get_key = ieee80211_get_key,
  2489. .set_default_key = ieee80211_config_default_key,
  2490. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  2491. .start_ap = ieee80211_start_ap,
  2492. .change_beacon = ieee80211_change_beacon,
  2493. .stop_ap = ieee80211_stop_ap,
  2494. .add_station = ieee80211_add_station,
  2495. .del_station = ieee80211_del_station,
  2496. .change_station = ieee80211_change_station,
  2497. .get_station = ieee80211_get_station,
  2498. .dump_station = ieee80211_dump_station,
  2499. .dump_survey = ieee80211_dump_survey,
  2500. #ifdef CONFIG_MAC80211_MESH
  2501. .add_mpath = ieee80211_add_mpath,
  2502. .del_mpath = ieee80211_del_mpath,
  2503. .change_mpath = ieee80211_change_mpath,
  2504. .get_mpath = ieee80211_get_mpath,
  2505. .dump_mpath = ieee80211_dump_mpath,
  2506. .update_mesh_config = ieee80211_update_mesh_config,
  2507. .get_mesh_config = ieee80211_get_mesh_config,
  2508. .join_mesh = ieee80211_join_mesh,
  2509. .leave_mesh = ieee80211_leave_mesh,
  2510. #endif
  2511. .change_bss = ieee80211_change_bss,
  2512. .set_txq_params = ieee80211_set_txq_params,
  2513. .set_monitor_channel = ieee80211_set_monitor_channel,
  2514. .suspend = ieee80211_suspend,
  2515. .resume = ieee80211_resume,
  2516. .scan = ieee80211_scan,
  2517. .sched_scan_start = ieee80211_sched_scan_start,
  2518. .sched_scan_stop = ieee80211_sched_scan_stop,
  2519. .auth = ieee80211_auth,
  2520. .assoc = ieee80211_assoc,
  2521. .deauth = ieee80211_deauth,
  2522. .disassoc = ieee80211_disassoc,
  2523. .join_ibss = ieee80211_join_ibss,
  2524. .leave_ibss = ieee80211_leave_ibss,
  2525. .set_wiphy_params = ieee80211_set_wiphy_params,
  2526. .set_tx_power = ieee80211_set_tx_power,
  2527. .get_tx_power = ieee80211_get_tx_power,
  2528. .set_wds_peer = ieee80211_set_wds_peer,
  2529. .rfkill_poll = ieee80211_rfkill_poll,
  2530. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  2531. CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
  2532. .set_power_mgmt = ieee80211_set_power_mgmt,
  2533. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  2534. .remain_on_channel = ieee80211_remain_on_channel,
  2535. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  2536. .mgmt_tx = ieee80211_mgmt_tx,
  2537. .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
  2538. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  2539. .mgmt_frame_register = ieee80211_mgmt_frame_register,
  2540. .set_antenna = ieee80211_set_antenna,
  2541. .get_antenna = ieee80211_get_antenna,
  2542. .set_ringparam = ieee80211_set_ringparam,
  2543. .get_ringparam = ieee80211_get_ringparam,
  2544. .set_rekey_data = ieee80211_set_rekey_data,
  2545. .tdls_oper = ieee80211_tdls_oper,
  2546. .tdls_mgmt = ieee80211_tdls_mgmt,
  2547. .probe_client = ieee80211_probe_client,
  2548. .get_channel = ieee80211_wiphy_get_channel,
  2549. .set_noack_map = ieee80211_set_noack_map,
  2550. #ifdef CONFIG_PM
  2551. .set_wakeup = ieee80211_set_wakeup,
  2552. #endif
  2553. .get_et_sset_count = ieee80211_get_et_sset_count,
  2554. .get_et_stats = ieee80211_get_et_stats,
  2555. .get_et_strings = ieee80211_get_et_strings,
  2556. };