cfg.c 80 KB

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