cfg.c 92 KB

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