cfg.c 85 KB

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