cfg.c 93 KB

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