cfg.c 86 KB

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