cfg.c 93 KB

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