cfg.c 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556
  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 net_device *ieee80211_add_iface(struct wiphy *wiphy, char *name,
  22. enum nl80211_iftype type,
  23. u32 *flags,
  24. struct vif_params *params)
  25. {
  26. struct ieee80211_local *local = wiphy_priv(wiphy);
  27. struct net_device *dev;
  28. struct ieee80211_sub_if_data *sdata;
  29. int err;
  30. err = ieee80211_if_add(local, name, &dev, type, params);
  31. if (err)
  32. return ERR_PTR(err);
  33. if (type == NL80211_IFTYPE_MONITOR && flags) {
  34. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  35. sdata->u.mntr_flags = *flags;
  36. }
  37. return dev;
  38. }
  39. static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
  40. {
  41. ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
  42. return 0;
  43. }
  44. static int ieee80211_change_iface(struct wiphy *wiphy,
  45. struct net_device *dev,
  46. enum nl80211_iftype type, u32 *flags,
  47. struct vif_params *params)
  48. {
  49. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  50. int ret;
  51. ret = ieee80211_if_change_type(sdata, type);
  52. if (ret)
  53. return ret;
  54. if (type == NL80211_IFTYPE_AP_VLAN &&
  55. params && params->use_4addr == 0)
  56. RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
  57. else if (type == NL80211_IFTYPE_STATION &&
  58. params && params->use_4addr >= 0)
  59. sdata->u.mgd.use_4addr = params->use_4addr;
  60. if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
  61. struct ieee80211_local *local = sdata->local;
  62. if (ieee80211_sdata_running(sdata)) {
  63. /*
  64. * Prohibit MONITOR_FLAG_COOK_FRAMES to be
  65. * changed while the interface is up.
  66. * Else we would need to add a lot of cruft
  67. * to update everything:
  68. * cooked_mntrs, monitor and all fif_* counters
  69. * reconfigure hardware
  70. */
  71. if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
  72. (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
  73. return -EBUSY;
  74. ieee80211_adjust_monitor_flags(sdata, -1);
  75. sdata->u.mntr_flags = *flags;
  76. ieee80211_adjust_monitor_flags(sdata, 1);
  77. ieee80211_configure_filter(local);
  78. } else {
  79. /*
  80. * Because the interface is down, ieee80211_do_stop
  81. * and ieee80211_do_open take care of "everything"
  82. * mentioned in the comment above.
  83. */
  84. sdata->u.mntr_flags = *flags;
  85. }
  86. }
  87. return 0;
  88. }
  89. static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
  90. u8 key_idx, bool pairwise, const u8 *mac_addr,
  91. struct key_params *params)
  92. {
  93. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  94. struct sta_info *sta = NULL;
  95. struct ieee80211_key *key;
  96. int err;
  97. if (!ieee80211_sdata_running(sdata))
  98. return -ENETDOWN;
  99. /* reject WEP and TKIP keys if WEP failed to initialize */
  100. switch (params->cipher) {
  101. case WLAN_CIPHER_SUITE_WEP40:
  102. case WLAN_CIPHER_SUITE_TKIP:
  103. case WLAN_CIPHER_SUITE_WEP104:
  104. if (IS_ERR(sdata->local->wep_tx_tfm))
  105. return -EINVAL;
  106. break;
  107. default:
  108. break;
  109. }
  110. key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
  111. params->key, params->seq_len, params->seq);
  112. if (IS_ERR(key))
  113. return PTR_ERR(key);
  114. if (pairwise)
  115. key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
  116. mutex_lock(&sdata->local->sta_mtx);
  117. if (mac_addr) {
  118. if (ieee80211_vif_is_mesh(&sdata->vif))
  119. sta = sta_info_get(sdata, mac_addr);
  120. else
  121. sta = sta_info_get_bss(sdata, mac_addr);
  122. if (!sta) {
  123. ieee80211_key_free(sdata->local, key);
  124. err = -ENOENT;
  125. goto out_unlock;
  126. }
  127. }
  128. err = ieee80211_key_link(key, sdata, sta);
  129. if (err)
  130. ieee80211_key_free(sdata->local, key);
  131. out_unlock:
  132. mutex_unlock(&sdata->local->sta_mtx);
  133. return err;
  134. }
  135. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  136. u8 key_idx, bool pairwise, const u8 *mac_addr)
  137. {
  138. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  139. struct ieee80211_local *local = sdata->local;
  140. struct sta_info *sta;
  141. struct ieee80211_key *key = NULL;
  142. int ret;
  143. mutex_lock(&local->sta_mtx);
  144. mutex_lock(&local->key_mtx);
  145. if (mac_addr) {
  146. ret = -ENOENT;
  147. sta = sta_info_get_bss(sdata, mac_addr);
  148. if (!sta)
  149. goto out_unlock;
  150. if (pairwise)
  151. key = key_mtx_dereference(local, sta->ptk);
  152. else
  153. key = key_mtx_dereference(local, sta->gtk[key_idx]);
  154. } else
  155. key = key_mtx_dereference(local, sdata->keys[key_idx]);
  156. if (!key) {
  157. ret = -ENOENT;
  158. goto out_unlock;
  159. }
  160. __ieee80211_key_free(key);
  161. ret = 0;
  162. out_unlock:
  163. mutex_unlock(&local->key_mtx);
  164. mutex_unlock(&local->sta_mtx);
  165. return ret;
  166. }
  167. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  168. u8 key_idx, bool pairwise, const u8 *mac_addr,
  169. void *cookie,
  170. void (*callback)(void *cookie,
  171. struct key_params *params))
  172. {
  173. struct ieee80211_sub_if_data *sdata;
  174. struct sta_info *sta = NULL;
  175. u8 seq[6] = {0};
  176. struct key_params params;
  177. struct ieee80211_key *key = NULL;
  178. u64 pn64;
  179. u32 iv32;
  180. u16 iv16;
  181. int err = -ENOENT;
  182. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  183. rcu_read_lock();
  184. if (mac_addr) {
  185. sta = sta_info_get_bss(sdata, mac_addr);
  186. if (!sta)
  187. goto out;
  188. if (pairwise)
  189. key = rcu_dereference(sta->ptk);
  190. else if (key_idx < NUM_DEFAULT_KEYS)
  191. key = rcu_dereference(sta->gtk[key_idx]);
  192. } else
  193. key = rcu_dereference(sdata->keys[key_idx]);
  194. if (!key)
  195. goto out;
  196. memset(&params, 0, sizeof(params));
  197. params.cipher = key->conf.cipher;
  198. switch (key->conf.cipher) {
  199. case WLAN_CIPHER_SUITE_TKIP:
  200. iv32 = key->u.tkip.tx.iv32;
  201. iv16 = key->u.tkip.tx.iv16;
  202. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
  203. drv_get_tkip_seq(sdata->local,
  204. key->conf.hw_key_idx,
  205. &iv32, &iv16);
  206. seq[0] = iv16 & 0xff;
  207. seq[1] = (iv16 >> 8) & 0xff;
  208. seq[2] = iv32 & 0xff;
  209. seq[3] = (iv32 >> 8) & 0xff;
  210. seq[4] = (iv32 >> 16) & 0xff;
  211. seq[5] = (iv32 >> 24) & 0xff;
  212. params.seq = seq;
  213. params.seq_len = 6;
  214. break;
  215. case WLAN_CIPHER_SUITE_CCMP:
  216. pn64 = atomic64_read(&key->u.ccmp.tx_pn);
  217. seq[0] = pn64;
  218. seq[1] = pn64 >> 8;
  219. seq[2] = pn64 >> 16;
  220. seq[3] = pn64 >> 24;
  221. seq[4] = pn64 >> 32;
  222. seq[5] = pn64 >> 40;
  223. params.seq = seq;
  224. params.seq_len = 6;
  225. break;
  226. case WLAN_CIPHER_SUITE_AES_CMAC:
  227. pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
  228. seq[0] = pn64;
  229. seq[1] = pn64 >> 8;
  230. seq[2] = pn64 >> 16;
  231. seq[3] = pn64 >> 24;
  232. seq[4] = pn64 >> 32;
  233. seq[5] = pn64 >> 40;
  234. params.seq = seq;
  235. params.seq_len = 6;
  236. break;
  237. }
  238. params.key = key->conf.key;
  239. params.key_len = key->conf.keylen;
  240. callback(cookie, &params);
  241. err = 0;
  242. out:
  243. rcu_read_unlock();
  244. return err;
  245. }
  246. static int ieee80211_config_default_key(struct wiphy *wiphy,
  247. struct net_device *dev,
  248. u8 key_idx, bool uni,
  249. bool multi)
  250. {
  251. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  252. ieee80211_set_default_key(sdata, key_idx, uni, multi);
  253. return 0;
  254. }
  255. static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
  256. struct net_device *dev,
  257. u8 key_idx)
  258. {
  259. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  260. ieee80211_set_default_mgmt_key(sdata, key_idx);
  261. return 0;
  262. }
  263. static void rate_idx_to_bitrate(struct rate_info *rate, struct sta_info *sta, int idx)
  264. {
  265. if (!(rate->flags & RATE_INFO_FLAGS_MCS)) {
  266. struct ieee80211_supported_band *sband;
  267. sband = sta->local->hw.wiphy->bands[
  268. sta->local->hw.conf.channel->band];
  269. rate->legacy = sband->bitrates[idx].bitrate;
  270. } else
  271. rate->mcs = idx;
  272. }
  273. static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  274. {
  275. struct ieee80211_sub_if_data *sdata = sta->sdata;
  276. struct timespec uptime;
  277. sinfo->generation = sdata->local->sta_generation;
  278. sinfo->filled = STATION_INFO_INACTIVE_TIME |
  279. STATION_INFO_RX_BYTES |
  280. STATION_INFO_TX_BYTES |
  281. STATION_INFO_RX_PACKETS |
  282. STATION_INFO_TX_PACKETS |
  283. STATION_INFO_TX_RETRIES |
  284. STATION_INFO_TX_FAILED |
  285. STATION_INFO_TX_BITRATE |
  286. STATION_INFO_RX_BITRATE |
  287. STATION_INFO_RX_DROP_MISC |
  288. STATION_INFO_BSS_PARAM |
  289. STATION_INFO_CONNECTED_TIME |
  290. STATION_INFO_STA_FLAGS;
  291. do_posix_clock_monotonic_gettime(&uptime);
  292. sinfo->connected_time = uptime.tv_sec - sta->last_connected;
  293. sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
  294. sinfo->rx_bytes = sta->rx_bytes;
  295. sinfo->tx_bytes = sta->tx_bytes;
  296. sinfo->rx_packets = sta->rx_packets;
  297. sinfo->tx_packets = sta->tx_packets;
  298. sinfo->tx_retries = sta->tx_retry_count;
  299. sinfo->tx_failed = sta->tx_retry_failed;
  300. sinfo->rx_dropped_misc = sta->rx_dropped;
  301. if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
  302. (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
  303. sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
  304. sinfo->signal = (s8)sta->last_signal;
  305. sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
  306. }
  307. sinfo->txrate.flags = 0;
  308. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
  309. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  310. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  311. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  312. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
  313. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  314. rate_idx_to_bitrate(&sinfo->txrate, sta, sta->last_tx_rate.idx);
  315. sinfo->rxrate.flags = 0;
  316. if (sta->last_rx_rate_flag & RX_FLAG_HT)
  317. sinfo->rxrate.flags |= RATE_INFO_FLAGS_MCS;
  318. if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
  319. sinfo->rxrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  320. if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
  321. sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  322. rate_idx_to_bitrate(&sinfo->rxrate, sta, sta->last_rx_rate_idx);
  323. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  324. #ifdef CONFIG_MAC80211_MESH
  325. sinfo->filled |= STATION_INFO_LLID |
  326. STATION_INFO_PLID |
  327. STATION_INFO_PLINK_STATE;
  328. sinfo->llid = le16_to_cpu(sta->llid);
  329. sinfo->plid = le16_to_cpu(sta->plid);
  330. sinfo->plink_state = sta->plink_state;
  331. #endif
  332. }
  333. sinfo->bss_param.flags = 0;
  334. if (sdata->vif.bss_conf.use_cts_prot)
  335. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
  336. if (sdata->vif.bss_conf.use_short_preamble)
  337. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
  338. if (sdata->vif.bss_conf.use_short_slot)
  339. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
  340. sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
  341. sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
  342. sinfo->sta_flags.set = 0;
  343. sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
  344. BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
  345. BIT(NL80211_STA_FLAG_WME) |
  346. BIT(NL80211_STA_FLAG_MFP) |
  347. BIT(NL80211_STA_FLAG_AUTHENTICATED);
  348. if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  349. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
  350. if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
  351. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
  352. if (test_sta_flag(sta, WLAN_STA_WME))
  353. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
  354. if (test_sta_flag(sta, WLAN_STA_MFP))
  355. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
  356. if (test_sta_flag(sta, WLAN_STA_AUTH))
  357. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
  358. }
  359. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  360. int idx, u8 *mac, struct station_info *sinfo)
  361. {
  362. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  363. struct sta_info *sta;
  364. int ret = -ENOENT;
  365. rcu_read_lock();
  366. sta = sta_info_get_by_idx(sdata, idx);
  367. if (sta) {
  368. ret = 0;
  369. memcpy(mac, sta->sta.addr, ETH_ALEN);
  370. sta_set_sinfo(sta, sinfo);
  371. }
  372. rcu_read_unlock();
  373. return ret;
  374. }
  375. static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  376. int idx, struct survey_info *survey)
  377. {
  378. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  379. return drv_get_survey(local, idx, survey);
  380. }
  381. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  382. u8 *mac, struct station_info *sinfo)
  383. {
  384. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  385. struct sta_info *sta;
  386. int ret = -ENOENT;
  387. rcu_read_lock();
  388. sta = sta_info_get_bss(sdata, mac);
  389. if (sta) {
  390. ret = 0;
  391. sta_set_sinfo(sta, sinfo);
  392. }
  393. rcu_read_unlock();
  394. return ret;
  395. }
  396. static void ieee80211_config_ap_ssid(struct ieee80211_sub_if_data *sdata,
  397. struct beacon_parameters *params)
  398. {
  399. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  400. bss_conf->ssid_len = params->ssid_len;
  401. if (params->ssid_len)
  402. memcpy(bss_conf->ssid, params->ssid, params->ssid_len);
  403. bss_conf->hidden_ssid =
  404. (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
  405. }
  406. /*
  407. * This handles both adding a beacon and setting new beacon info
  408. */
  409. static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
  410. struct beacon_parameters *params)
  411. {
  412. struct beacon_data *new, *old;
  413. int new_head_len, new_tail_len;
  414. int size;
  415. int err = -EINVAL;
  416. old = rtnl_dereference(sdata->u.ap.beacon);
  417. /* head must not be zero-length */
  418. if (params->head && !params->head_len)
  419. return -EINVAL;
  420. /*
  421. * This is a kludge. beacon interval should really be part
  422. * of the beacon information.
  423. */
  424. if (params->interval &&
  425. (sdata->vif.bss_conf.beacon_int != params->interval)) {
  426. sdata->vif.bss_conf.beacon_int = params->interval;
  427. ieee80211_bss_info_change_notify(sdata,
  428. BSS_CHANGED_BEACON_INT);
  429. }
  430. /* Need to have a beacon head if we don't have one yet */
  431. if (!params->head && !old)
  432. return err;
  433. /* sorry, no way to start beaconing without dtim period */
  434. if (!params->dtim_period && !old)
  435. return err;
  436. /* new or old head? */
  437. if (params->head)
  438. new_head_len = params->head_len;
  439. else
  440. new_head_len = old->head_len;
  441. /* new or old tail? */
  442. if (params->tail || !old)
  443. /* params->tail_len will be zero for !params->tail */
  444. new_tail_len = params->tail_len;
  445. else
  446. new_tail_len = old->tail_len;
  447. size = sizeof(*new) + new_head_len + new_tail_len;
  448. new = kzalloc(size, GFP_KERNEL);
  449. if (!new)
  450. return -ENOMEM;
  451. /* start filling the new info now */
  452. /* new or old dtim period? */
  453. if (params->dtim_period)
  454. new->dtim_period = params->dtim_period;
  455. else
  456. new->dtim_period = old->dtim_period;
  457. /*
  458. * pointers go into the block we allocated,
  459. * memory is | beacon_data | head | tail |
  460. */
  461. new->head = ((u8 *) new) + sizeof(*new);
  462. new->tail = new->head + new_head_len;
  463. new->head_len = new_head_len;
  464. new->tail_len = new_tail_len;
  465. /* copy in head */
  466. if (params->head)
  467. memcpy(new->head, params->head, new_head_len);
  468. else
  469. memcpy(new->head, old->head, new_head_len);
  470. /* copy in optional tail */
  471. if (params->tail)
  472. memcpy(new->tail, params->tail, new_tail_len);
  473. else
  474. if (old)
  475. memcpy(new->tail, old->tail, new_tail_len);
  476. sdata->vif.bss_conf.dtim_period = new->dtim_period;
  477. RCU_INIT_POINTER(sdata->u.ap.beacon, new);
  478. synchronize_rcu();
  479. kfree(old);
  480. ieee80211_config_ap_ssid(sdata, params);
  481. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
  482. BSS_CHANGED_BEACON |
  483. BSS_CHANGED_SSID);
  484. return 0;
  485. }
  486. static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
  487. struct beacon_parameters *params)
  488. {
  489. struct ieee80211_sub_if_data *sdata;
  490. struct beacon_data *old;
  491. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  492. old = rtnl_dereference(sdata->u.ap.beacon);
  493. if (old)
  494. return -EALREADY;
  495. return ieee80211_config_beacon(sdata, params);
  496. }
  497. static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  498. struct beacon_parameters *params)
  499. {
  500. struct ieee80211_sub_if_data *sdata;
  501. struct beacon_data *old;
  502. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  503. old = rtnl_dereference(sdata->u.ap.beacon);
  504. if (!old)
  505. return -ENOENT;
  506. return ieee80211_config_beacon(sdata, params);
  507. }
  508. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  509. {
  510. struct ieee80211_sub_if_data *sdata;
  511. struct beacon_data *old;
  512. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  513. old = rtnl_dereference(sdata->u.ap.beacon);
  514. if (!old)
  515. return -ENOENT;
  516. RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
  517. synchronize_rcu();
  518. kfree(old);
  519. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  520. return 0;
  521. }
  522. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  523. struct iapp_layer2_update {
  524. u8 da[ETH_ALEN]; /* broadcast */
  525. u8 sa[ETH_ALEN]; /* STA addr */
  526. __be16 len; /* 6 */
  527. u8 dsap; /* 0 */
  528. u8 ssap; /* 0 */
  529. u8 control;
  530. u8 xid_info[3];
  531. } __packed;
  532. static void ieee80211_send_layer2_update(struct sta_info *sta)
  533. {
  534. struct iapp_layer2_update *msg;
  535. struct sk_buff *skb;
  536. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  537. * bridge devices */
  538. skb = dev_alloc_skb(sizeof(*msg));
  539. if (!skb)
  540. return;
  541. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  542. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  543. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  544. memset(msg->da, 0xff, ETH_ALEN);
  545. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  546. msg->len = htons(6);
  547. msg->dsap = 0;
  548. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  549. msg->control = 0xaf; /* XID response lsb.1111F101.
  550. * F=0 (no poll command; unsolicited frame) */
  551. msg->xid_info[0] = 0x81; /* XID format identifier */
  552. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  553. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  554. skb->dev = sta->sdata->dev;
  555. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  556. memset(skb->cb, 0, sizeof(skb->cb));
  557. netif_rx_ni(skb);
  558. }
  559. static void sta_apply_parameters(struct ieee80211_local *local,
  560. struct sta_info *sta,
  561. struct station_parameters *params)
  562. {
  563. u32 rates;
  564. int i, j;
  565. struct ieee80211_supported_band *sband;
  566. struct ieee80211_sub_if_data *sdata = sta->sdata;
  567. u32 mask, set;
  568. sband = local->hw.wiphy->bands[local->oper_channel->band];
  569. mask = params->sta_flags_mask;
  570. set = params->sta_flags_set;
  571. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  572. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  573. set_sta_flag(sta, WLAN_STA_AUTHORIZED);
  574. else
  575. clear_sta_flag(sta, WLAN_STA_AUTHORIZED);
  576. }
  577. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  578. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  579. set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  580. else
  581. clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  582. }
  583. if (mask & BIT(NL80211_STA_FLAG_WME)) {
  584. if (set & BIT(NL80211_STA_FLAG_WME)) {
  585. set_sta_flag(sta, WLAN_STA_WME);
  586. sta->sta.wme = true;
  587. } else {
  588. clear_sta_flag(sta, WLAN_STA_WME);
  589. sta->sta.wme = false;
  590. }
  591. }
  592. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  593. if (set & BIT(NL80211_STA_FLAG_MFP))
  594. set_sta_flag(sta, WLAN_STA_MFP);
  595. else
  596. clear_sta_flag(sta, WLAN_STA_MFP);
  597. }
  598. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
  599. if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
  600. set_sta_flag(sta, WLAN_STA_AUTH);
  601. else
  602. clear_sta_flag(sta, WLAN_STA_AUTH);
  603. }
  604. if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
  605. if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
  606. set_sta_flag(sta, WLAN_STA_TDLS_PEER);
  607. else
  608. clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
  609. }
  610. if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
  611. sta->sta.uapsd_queues = params->uapsd_queues;
  612. sta->sta.max_sp = params->max_sp;
  613. }
  614. /*
  615. * cfg80211 validates this (1-2007) and allows setting the AID
  616. * only when creating a new station entry
  617. */
  618. if (params->aid)
  619. sta->sta.aid = params->aid;
  620. /*
  621. * FIXME: updating the following information is racy when this
  622. * function is called from ieee80211_change_station().
  623. * However, all this information should be static so
  624. * maybe we should just reject attemps to change it.
  625. */
  626. if (params->listen_interval >= 0)
  627. sta->listen_interval = params->listen_interval;
  628. if (params->supported_rates) {
  629. rates = 0;
  630. for (i = 0; i < params->supported_rates_len; i++) {
  631. int rate = (params->supported_rates[i] & 0x7f) * 5;
  632. for (j = 0; j < sband->n_bitrates; j++) {
  633. if (sband->bitrates[j].bitrate == rate)
  634. rates |= BIT(j);
  635. }
  636. }
  637. sta->sta.supp_rates[local->oper_channel->band] = rates;
  638. }
  639. if (params->ht_capa)
  640. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  641. params->ht_capa,
  642. &sta->sta.ht_cap);
  643. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  644. #ifdef CONFIG_MAC80211_MESH
  645. if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED)
  646. switch (params->plink_state) {
  647. case NL80211_PLINK_LISTEN:
  648. case NL80211_PLINK_ESTAB:
  649. case NL80211_PLINK_BLOCKED:
  650. sta->plink_state = params->plink_state;
  651. break;
  652. default:
  653. /* nothing */
  654. break;
  655. }
  656. else
  657. switch (params->plink_action) {
  658. case PLINK_ACTION_OPEN:
  659. mesh_plink_open(sta);
  660. break;
  661. case PLINK_ACTION_BLOCK:
  662. mesh_plink_block(sta);
  663. break;
  664. }
  665. #endif
  666. }
  667. }
  668. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  669. u8 *mac, struct station_parameters *params)
  670. {
  671. struct ieee80211_local *local = wiphy_priv(wiphy);
  672. struct sta_info *sta;
  673. struct ieee80211_sub_if_data *sdata;
  674. int err;
  675. int layer2_update;
  676. if (params->vlan) {
  677. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  678. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  679. sdata->vif.type != NL80211_IFTYPE_AP)
  680. return -EINVAL;
  681. } else
  682. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  683. if (compare_ether_addr(mac, sdata->vif.addr) == 0)
  684. return -EINVAL;
  685. if (is_multicast_ether_addr(mac))
  686. return -EINVAL;
  687. /* Only TDLS-supporting stations can add TDLS peers */
  688. if ((params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
  689. !((wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
  690. sdata->vif.type == NL80211_IFTYPE_STATION))
  691. return -ENOTSUPP;
  692. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  693. if (!sta)
  694. return -ENOMEM;
  695. set_sta_flag(sta, WLAN_STA_AUTH);
  696. set_sta_flag(sta, WLAN_STA_ASSOC);
  697. sta_apply_parameters(local, sta, params);
  698. rate_control_rate_init(sta);
  699. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  700. sdata->vif.type == NL80211_IFTYPE_AP;
  701. err = sta_info_insert_rcu(sta);
  702. if (err) {
  703. rcu_read_unlock();
  704. return err;
  705. }
  706. if (layer2_update)
  707. ieee80211_send_layer2_update(sta);
  708. rcu_read_unlock();
  709. return 0;
  710. }
  711. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  712. u8 *mac)
  713. {
  714. struct ieee80211_local *local = wiphy_priv(wiphy);
  715. struct ieee80211_sub_if_data *sdata;
  716. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  717. if (mac)
  718. return sta_info_destroy_addr_bss(sdata, mac);
  719. sta_info_flush(local, sdata);
  720. return 0;
  721. }
  722. static int ieee80211_change_station(struct wiphy *wiphy,
  723. struct net_device *dev,
  724. u8 *mac,
  725. struct station_parameters *params)
  726. {
  727. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  728. struct ieee80211_local *local = wiphy_priv(wiphy);
  729. struct sta_info *sta;
  730. struct ieee80211_sub_if_data *vlansdata;
  731. rcu_read_lock();
  732. sta = sta_info_get_bss(sdata, mac);
  733. if (!sta) {
  734. rcu_read_unlock();
  735. return -ENOENT;
  736. }
  737. /* The TDLS bit cannot be toggled after the STA was added */
  738. if ((params->sta_flags_mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
  739. !!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) !=
  740. !!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
  741. rcu_read_unlock();
  742. return -EINVAL;
  743. }
  744. if (params->vlan && params->vlan != sta->sdata->dev) {
  745. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  746. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  747. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  748. rcu_read_unlock();
  749. return -EINVAL;
  750. }
  751. if (params->vlan->ieee80211_ptr->use_4addr) {
  752. if (vlansdata->u.vlan.sta) {
  753. rcu_read_unlock();
  754. return -EBUSY;
  755. }
  756. RCU_INIT_POINTER(vlansdata->u.vlan.sta, sta);
  757. }
  758. sta->sdata = vlansdata;
  759. ieee80211_send_layer2_update(sta);
  760. }
  761. sta_apply_parameters(local, sta, params);
  762. rcu_read_unlock();
  763. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  764. params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))
  765. ieee80211_recalc_ps(local, -1);
  766. return 0;
  767. }
  768. #ifdef CONFIG_MAC80211_MESH
  769. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  770. u8 *dst, u8 *next_hop)
  771. {
  772. struct ieee80211_sub_if_data *sdata;
  773. struct mesh_path *mpath;
  774. struct sta_info *sta;
  775. int err;
  776. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  777. rcu_read_lock();
  778. sta = sta_info_get(sdata, next_hop);
  779. if (!sta) {
  780. rcu_read_unlock();
  781. return -ENOENT;
  782. }
  783. err = mesh_path_add(dst, sdata);
  784. if (err) {
  785. rcu_read_unlock();
  786. return err;
  787. }
  788. mpath = mesh_path_lookup(dst, sdata);
  789. if (!mpath) {
  790. rcu_read_unlock();
  791. return -ENXIO;
  792. }
  793. mesh_path_fix_nexthop(mpath, sta);
  794. rcu_read_unlock();
  795. return 0;
  796. }
  797. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  798. u8 *dst)
  799. {
  800. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  801. if (dst)
  802. return mesh_path_del(dst, sdata);
  803. mesh_path_flush_by_iface(sdata);
  804. return 0;
  805. }
  806. static int ieee80211_change_mpath(struct wiphy *wiphy,
  807. struct net_device *dev,
  808. u8 *dst, u8 *next_hop)
  809. {
  810. struct ieee80211_sub_if_data *sdata;
  811. struct mesh_path *mpath;
  812. struct sta_info *sta;
  813. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  814. rcu_read_lock();
  815. sta = sta_info_get(sdata, next_hop);
  816. if (!sta) {
  817. rcu_read_unlock();
  818. return -ENOENT;
  819. }
  820. mpath = mesh_path_lookup(dst, sdata);
  821. if (!mpath) {
  822. rcu_read_unlock();
  823. return -ENOENT;
  824. }
  825. mesh_path_fix_nexthop(mpath, sta);
  826. rcu_read_unlock();
  827. return 0;
  828. }
  829. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  830. struct mpath_info *pinfo)
  831. {
  832. struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
  833. if (next_hop_sta)
  834. memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
  835. else
  836. memset(next_hop, 0, ETH_ALEN);
  837. pinfo->generation = mesh_paths_generation;
  838. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  839. MPATH_INFO_SN |
  840. MPATH_INFO_METRIC |
  841. MPATH_INFO_EXPTIME |
  842. MPATH_INFO_DISCOVERY_TIMEOUT |
  843. MPATH_INFO_DISCOVERY_RETRIES |
  844. MPATH_INFO_FLAGS;
  845. pinfo->frame_qlen = mpath->frame_queue.qlen;
  846. pinfo->sn = mpath->sn;
  847. pinfo->metric = mpath->metric;
  848. if (time_before(jiffies, mpath->exp_time))
  849. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  850. pinfo->discovery_timeout =
  851. jiffies_to_msecs(mpath->discovery_timeout);
  852. pinfo->discovery_retries = mpath->discovery_retries;
  853. pinfo->flags = 0;
  854. if (mpath->flags & MESH_PATH_ACTIVE)
  855. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  856. if (mpath->flags & MESH_PATH_RESOLVING)
  857. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  858. if (mpath->flags & MESH_PATH_SN_VALID)
  859. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  860. if (mpath->flags & MESH_PATH_FIXED)
  861. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  862. if (mpath->flags & MESH_PATH_RESOLVING)
  863. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  864. pinfo->flags = mpath->flags;
  865. }
  866. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  867. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  868. {
  869. struct ieee80211_sub_if_data *sdata;
  870. struct mesh_path *mpath;
  871. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  872. rcu_read_lock();
  873. mpath = mesh_path_lookup(dst, sdata);
  874. if (!mpath) {
  875. rcu_read_unlock();
  876. return -ENOENT;
  877. }
  878. memcpy(dst, mpath->dst, ETH_ALEN);
  879. mpath_set_pinfo(mpath, next_hop, pinfo);
  880. rcu_read_unlock();
  881. return 0;
  882. }
  883. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  884. int idx, u8 *dst, u8 *next_hop,
  885. struct mpath_info *pinfo)
  886. {
  887. struct ieee80211_sub_if_data *sdata;
  888. struct mesh_path *mpath;
  889. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  890. rcu_read_lock();
  891. mpath = mesh_path_lookup_by_idx(idx, sdata);
  892. if (!mpath) {
  893. rcu_read_unlock();
  894. return -ENOENT;
  895. }
  896. memcpy(dst, mpath->dst, ETH_ALEN);
  897. mpath_set_pinfo(mpath, next_hop, pinfo);
  898. rcu_read_unlock();
  899. return 0;
  900. }
  901. static int ieee80211_get_mesh_config(struct wiphy *wiphy,
  902. struct net_device *dev,
  903. struct mesh_config *conf)
  904. {
  905. struct ieee80211_sub_if_data *sdata;
  906. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  907. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  908. return 0;
  909. }
  910. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  911. {
  912. return (mask >> (parm-1)) & 0x1;
  913. }
  914. static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
  915. const struct mesh_setup *setup)
  916. {
  917. u8 *new_ie;
  918. const u8 *old_ie;
  919. /* allocate information elements */
  920. new_ie = NULL;
  921. old_ie = ifmsh->ie;
  922. if (setup->ie_len) {
  923. new_ie = kmemdup(setup->ie, setup->ie_len,
  924. GFP_KERNEL);
  925. if (!new_ie)
  926. return -ENOMEM;
  927. }
  928. ifmsh->ie_len = setup->ie_len;
  929. ifmsh->ie = new_ie;
  930. kfree(old_ie);
  931. /* now copy the rest of the setup parameters */
  932. ifmsh->mesh_id_len = setup->mesh_id_len;
  933. memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
  934. ifmsh->mesh_pp_id = setup->path_sel_proto;
  935. ifmsh->mesh_pm_id = setup->path_metric;
  936. ifmsh->security = IEEE80211_MESH_SEC_NONE;
  937. if (setup->is_authenticated)
  938. ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
  939. if (setup->is_secure)
  940. ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
  941. return 0;
  942. }
  943. static int ieee80211_update_mesh_config(struct wiphy *wiphy,
  944. struct net_device *dev, u32 mask,
  945. const struct mesh_config *nconf)
  946. {
  947. struct mesh_config *conf;
  948. struct ieee80211_sub_if_data *sdata;
  949. struct ieee80211_if_mesh *ifmsh;
  950. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  951. ifmsh = &sdata->u.mesh;
  952. /* Set the config options which we are interested in setting */
  953. conf = &(sdata->u.mesh.mshcfg);
  954. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  955. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  956. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  957. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  958. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  959. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  960. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  961. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  962. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  963. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  964. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  965. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  966. if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
  967. conf->dot11MeshTTL = nconf->element_ttl;
  968. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  969. conf->auto_open_plinks = nconf->auto_open_plinks;
  970. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  971. conf->dot11MeshHWMPmaxPREQretries =
  972. nconf->dot11MeshHWMPmaxPREQretries;
  973. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  974. conf->path_refresh_time = nconf->path_refresh_time;
  975. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  976. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  977. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  978. conf->dot11MeshHWMPactivePathTimeout =
  979. nconf->dot11MeshHWMPactivePathTimeout;
  980. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  981. conf->dot11MeshHWMPpreqMinInterval =
  982. nconf->dot11MeshHWMPpreqMinInterval;
  983. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  984. mask))
  985. conf->dot11MeshHWMPnetDiameterTraversalTime =
  986. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  987. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  988. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  989. ieee80211_mesh_root_setup(ifmsh);
  990. }
  991. if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
  992. /* our current gate announcement implementation rides on root
  993. * announcements, so require this ifmsh to also be a root node
  994. * */
  995. if (nconf->dot11MeshGateAnnouncementProtocol &&
  996. !conf->dot11MeshHWMPRootMode) {
  997. conf->dot11MeshHWMPRootMode = 1;
  998. ieee80211_mesh_root_setup(ifmsh);
  999. }
  1000. conf->dot11MeshGateAnnouncementProtocol =
  1001. nconf->dot11MeshGateAnnouncementProtocol;
  1002. }
  1003. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask)) {
  1004. conf->dot11MeshHWMPRannInterval =
  1005. nconf->dot11MeshHWMPRannInterval;
  1006. }
  1007. return 0;
  1008. }
  1009. static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
  1010. const struct mesh_config *conf,
  1011. const struct mesh_setup *setup)
  1012. {
  1013. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1014. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1015. int err;
  1016. memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
  1017. err = copy_mesh_setup(ifmsh, setup);
  1018. if (err)
  1019. return err;
  1020. ieee80211_start_mesh(sdata);
  1021. return 0;
  1022. }
  1023. static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
  1024. {
  1025. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1026. ieee80211_stop_mesh(sdata);
  1027. return 0;
  1028. }
  1029. #endif
  1030. static int ieee80211_change_bss(struct wiphy *wiphy,
  1031. struct net_device *dev,
  1032. struct bss_parameters *params)
  1033. {
  1034. struct ieee80211_sub_if_data *sdata;
  1035. u32 changed = 0;
  1036. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1037. if (params->use_cts_prot >= 0) {
  1038. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  1039. changed |= BSS_CHANGED_ERP_CTS_PROT;
  1040. }
  1041. if (params->use_short_preamble >= 0) {
  1042. sdata->vif.bss_conf.use_short_preamble =
  1043. params->use_short_preamble;
  1044. changed |= BSS_CHANGED_ERP_PREAMBLE;
  1045. }
  1046. if (!sdata->vif.bss_conf.use_short_slot &&
  1047. sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
  1048. sdata->vif.bss_conf.use_short_slot = true;
  1049. changed |= BSS_CHANGED_ERP_SLOT;
  1050. }
  1051. if (params->use_short_slot_time >= 0) {
  1052. sdata->vif.bss_conf.use_short_slot =
  1053. params->use_short_slot_time;
  1054. changed |= BSS_CHANGED_ERP_SLOT;
  1055. }
  1056. if (params->basic_rates) {
  1057. int i, j;
  1058. u32 rates = 0;
  1059. struct ieee80211_local *local = wiphy_priv(wiphy);
  1060. struct ieee80211_supported_band *sband =
  1061. wiphy->bands[local->oper_channel->band];
  1062. for (i = 0; i < params->basic_rates_len; i++) {
  1063. int rate = (params->basic_rates[i] & 0x7f) * 5;
  1064. for (j = 0; j < sband->n_bitrates; j++) {
  1065. if (sband->bitrates[j].bitrate == rate)
  1066. rates |= BIT(j);
  1067. }
  1068. }
  1069. sdata->vif.bss_conf.basic_rates = rates;
  1070. changed |= BSS_CHANGED_BASIC_RATES;
  1071. }
  1072. if (params->ap_isolate >= 0) {
  1073. if (params->ap_isolate)
  1074. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1075. else
  1076. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1077. }
  1078. if (params->ht_opmode >= 0) {
  1079. sdata->vif.bss_conf.ht_operation_mode =
  1080. (u16) params->ht_opmode;
  1081. changed |= BSS_CHANGED_HT;
  1082. }
  1083. ieee80211_bss_info_change_notify(sdata, changed);
  1084. return 0;
  1085. }
  1086. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  1087. struct net_device *dev,
  1088. struct ieee80211_txq_params *params)
  1089. {
  1090. struct ieee80211_local *local = wiphy_priv(wiphy);
  1091. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1092. struct ieee80211_tx_queue_params p;
  1093. if (!local->ops->conf_tx)
  1094. return -EOPNOTSUPP;
  1095. memset(&p, 0, sizeof(p));
  1096. p.aifs = params->aifs;
  1097. p.cw_max = params->cwmax;
  1098. p.cw_min = params->cwmin;
  1099. p.txop = params->txop;
  1100. /*
  1101. * Setting tx queue params disables u-apsd because it's only
  1102. * called in master mode.
  1103. */
  1104. p.uapsd = false;
  1105. if (params->queue >= local->hw.queues)
  1106. return -EINVAL;
  1107. sdata->tx_conf[params->queue] = p;
  1108. if (drv_conf_tx(local, sdata, params->queue, &p)) {
  1109. wiphy_debug(local->hw.wiphy,
  1110. "failed to set TX queue parameters for queue %d\n",
  1111. params->queue);
  1112. return -EINVAL;
  1113. }
  1114. return 0;
  1115. }
  1116. static int ieee80211_set_channel(struct wiphy *wiphy,
  1117. struct net_device *netdev,
  1118. struct ieee80211_channel *chan,
  1119. enum nl80211_channel_type channel_type)
  1120. {
  1121. struct ieee80211_local *local = wiphy_priv(wiphy);
  1122. struct ieee80211_sub_if_data *sdata = NULL;
  1123. struct ieee80211_channel *old_oper;
  1124. enum nl80211_channel_type old_oper_type;
  1125. enum nl80211_channel_type old_vif_oper_type= NL80211_CHAN_NO_HT;
  1126. if (netdev)
  1127. sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
  1128. switch (ieee80211_get_channel_mode(local, NULL)) {
  1129. case CHAN_MODE_HOPPING:
  1130. return -EBUSY;
  1131. case CHAN_MODE_FIXED:
  1132. if (local->oper_channel != chan)
  1133. return -EBUSY;
  1134. if (!sdata && local->_oper_channel_type == channel_type)
  1135. return 0;
  1136. break;
  1137. case CHAN_MODE_UNDEFINED:
  1138. break;
  1139. }
  1140. if (sdata)
  1141. old_vif_oper_type = sdata->vif.bss_conf.channel_type;
  1142. old_oper_type = local->_oper_channel_type;
  1143. if (!ieee80211_set_channel_type(local, sdata, channel_type))
  1144. return -EBUSY;
  1145. old_oper = local->oper_channel;
  1146. local->oper_channel = chan;
  1147. /* Update driver if changes were actually made. */
  1148. if ((old_oper != local->oper_channel) ||
  1149. (old_oper_type != local->_oper_channel_type))
  1150. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  1151. if ((sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR) &&
  1152. old_vif_oper_type != sdata->vif.bss_conf.channel_type)
  1153. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
  1154. return 0;
  1155. }
  1156. #ifdef CONFIG_PM
  1157. static int ieee80211_suspend(struct wiphy *wiphy,
  1158. struct cfg80211_wowlan *wowlan)
  1159. {
  1160. return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
  1161. }
  1162. static int ieee80211_resume(struct wiphy *wiphy)
  1163. {
  1164. return __ieee80211_resume(wiphy_priv(wiphy));
  1165. }
  1166. #else
  1167. #define ieee80211_suspend NULL
  1168. #define ieee80211_resume NULL
  1169. #endif
  1170. static int ieee80211_scan(struct wiphy *wiphy,
  1171. struct net_device *dev,
  1172. struct cfg80211_scan_request *req)
  1173. {
  1174. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1175. switch (ieee80211_vif_type_p2p(&sdata->vif)) {
  1176. case NL80211_IFTYPE_STATION:
  1177. case NL80211_IFTYPE_ADHOC:
  1178. case NL80211_IFTYPE_MESH_POINT:
  1179. case NL80211_IFTYPE_P2P_CLIENT:
  1180. break;
  1181. case NL80211_IFTYPE_P2P_GO:
  1182. if (sdata->local->ops->hw_scan)
  1183. break;
  1184. /*
  1185. * FIXME: implement NoA while scanning in software,
  1186. * for now fall through to allow scanning only when
  1187. * beaconing hasn't been configured yet
  1188. */
  1189. case NL80211_IFTYPE_AP:
  1190. if (sdata->u.ap.beacon)
  1191. return -EOPNOTSUPP;
  1192. break;
  1193. default:
  1194. return -EOPNOTSUPP;
  1195. }
  1196. return ieee80211_request_scan(sdata, req);
  1197. }
  1198. static int
  1199. ieee80211_sched_scan_start(struct wiphy *wiphy,
  1200. struct net_device *dev,
  1201. struct cfg80211_sched_scan_request *req)
  1202. {
  1203. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1204. if (!sdata->local->ops->sched_scan_start)
  1205. return -EOPNOTSUPP;
  1206. return ieee80211_request_sched_scan_start(sdata, req);
  1207. }
  1208. static int
  1209. ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
  1210. {
  1211. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1212. if (!sdata->local->ops->sched_scan_stop)
  1213. return -EOPNOTSUPP;
  1214. return ieee80211_request_sched_scan_stop(sdata);
  1215. }
  1216. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  1217. struct cfg80211_auth_request *req)
  1218. {
  1219. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1220. }
  1221. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  1222. struct cfg80211_assoc_request *req)
  1223. {
  1224. struct ieee80211_local *local = wiphy_priv(wiphy);
  1225. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1226. switch (ieee80211_get_channel_mode(local, sdata)) {
  1227. case CHAN_MODE_HOPPING:
  1228. return -EBUSY;
  1229. case CHAN_MODE_FIXED:
  1230. if (local->oper_channel == req->bss->channel)
  1231. break;
  1232. return -EBUSY;
  1233. case CHAN_MODE_UNDEFINED:
  1234. break;
  1235. }
  1236. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1237. }
  1238. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1239. struct cfg80211_deauth_request *req,
  1240. void *cookie)
  1241. {
  1242. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
  1243. req, cookie);
  1244. }
  1245. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1246. struct cfg80211_disassoc_request *req,
  1247. void *cookie)
  1248. {
  1249. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
  1250. req, cookie);
  1251. }
  1252. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1253. struct cfg80211_ibss_params *params)
  1254. {
  1255. struct ieee80211_local *local = wiphy_priv(wiphy);
  1256. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1257. switch (ieee80211_get_channel_mode(local, sdata)) {
  1258. case CHAN_MODE_HOPPING:
  1259. return -EBUSY;
  1260. case CHAN_MODE_FIXED:
  1261. if (!params->channel_fixed)
  1262. return -EBUSY;
  1263. if (local->oper_channel == params->channel)
  1264. break;
  1265. return -EBUSY;
  1266. case CHAN_MODE_UNDEFINED:
  1267. break;
  1268. }
  1269. return ieee80211_ibss_join(sdata, params);
  1270. }
  1271. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1272. {
  1273. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1274. return ieee80211_ibss_leave(sdata);
  1275. }
  1276. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1277. {
  1278. struct ieee80211_local *local = wiphy_priv(wiphy);
  1279. int err;
  1280. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  1281. err = drv_set_frag_threshold(local, wiphy->frag_threshold);
  1282. if (err)
  1283. return err;
  1284. }
  1285. if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
  1286. err = drv_set_coverage_class(local, wiphy->coverage_class);
  1287. if (err)
  1288. return err;
  1289. }
  1290. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1291. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1292. if (err)
  1293. return err;
  1294. }
  1295. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1296. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1297. if (changed & WIPHY_PARAM_RETRY_LONG)
  1298. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1299. if (changed &
  1300. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1301. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1302. return 0;
  1303. }
  1304. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1305. enum nl80211_tx_power_setting type, int mbm)
  1306. {
  1307. struct ieee80211_local *local = wiphy_priv(wiphy);
  1308. struct ieee80211_channel *chan = local->hw.conf.channel;
  1309. u32 changes = 0;
  1310. switch (type) {
  1311. case NL80211_TX_POWER_AUTOMATIC:
  1312. local->user_power_level = -1;
  1313. break;
  1314. case NL80211_TX_POWER_LIMITED:
  1315. if (mbm < 0 || (mbm % 100))
  1316. return -EOPNOTSUPP;
  1317. local->user_power_level = MBM_TO_DBM(mbm);
  1318. break;
  1319. case NL80211_TX_POWER_FIXED:
  1320. if (mbm < 0 || (mbm % 100))
  1321. return -EOPNOTSUPP;
  1322. /* TODO: move to cfg80211 when it knows the channel */
  1323. if (MBM_TO_DBM(mbm) > chan->max_power)
  1324. return -EINVAL;
  1325. local->user_power_level = MBM_TO_DBM(mbm);
  1326. break;
  1327. }
  1328. ieee80211_hw_config(local, changes);
  1329. return 0;
  1330. }
  1331. static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
  1332. {
  1333. struct ieee80211_local *local = wiphy_priv(wiphy);
  1334. *dbm = local->hw.conf.power_level;
  1335. return 0;
  1336. }
  1337. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  1338. const u8 *addr)
  1339. {
  1340. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1341. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  1342. return 0;
  1343. }
  1344. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1345. {
  1346. struct ieee80211_local *local = wiphy_priv(wiphy);
  1347. drv_rfkill_poll(local);
  1348. }
  1349. #ifdef CONFIG_NL80211_TESTMODE
  1350. static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
  1351. {
  1352. struct ieee80211_local *local = wiphy_priv(wiphy);
  1353. if (!local->ops->testmode_cmd)
  1354. return -EOPNOTSUPP;
  1355. return local->ops->testmode_cmd(&local->hw, data, len);
  1356. }
  1357. static int ieee80211_testmode_dump(struct wiphy *wiphy,
  1358. struct sk_buff *skb,
  1359. struct netlink_callback *cb,
  1360. void *data, int len)
  1361. {
  1362. struct ieee80211_local *local = wiphy_priv(wiphy);
  1363. if (!local->ops->testmode_dump)
  1364. return -EOPNOTSUPP;
  1365. return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
  1366. }
  1367. #endif
  1368. int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
  1369. enum ieee80211_smps_mode smps_mode)
  1370. {
  1371. const u8 *ap;
  1372. enum ieee80211_smps_mode old_req;
  1373. int err;
  1374. lockdep_assert_held(&sdata->u.mgd.mtx);
  1375. old_req = sdata->u.mgd.req_smps;
  1376. sdata->u.mgd.req_smps = smps_mode;
  1377. if (old_req == smps_mode &&
  1378. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  1379. return 0;
  1380. /*
  1381. * If not associated, or current association is not an HT
  1382. * association, there's no need to send an action frame.
  1383. */
  1384. if (!sdata->u.mgd.associated ||
  1385. sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
  1386. mutex_lock(&sdata->local->iflist_mtx);
  1387. ieee80211_recalc_smps(sdata->local);
  1388. mutex_unlock(&sdata->local->iflist_mtx);
  1389. return 0;
  1390. }
  1391. ap = sdata->u.mgd.associated->bssid;
  1392. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  1393. if (sdata->u.mgd.powersave)
  1394. smps_mode = IEEE80211_SMPS_DYNAMIC;
  1395. else
  1396. smps_mode = IEEE80211_SMPS_OFF;
  1397. }
  1398. /* send SM PS frame to AP */
  1399. err = ieee80211_send_smps_action(sdata, smps_mode,
  1400. ap, ap);
  1401. if (err)
  1402. sdata->u.mgd.req_smps = old_req;
  1403. return err;
  1404. }
  1405. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1406. bool enabled, int timeout)
  1407. {
  1408. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1409. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1410. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1411. return -EOPNOTSUPP;
  1412. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  1413. return -EOPNOTSUPP;
  1414. if (enabled == sdata->u.mgd.powersave &&
  1415. timeout == local->dynamic_ps_forced_timeout)
  1416. return 0;
  1417. sdata->u.mgd.powersave = enabled;
  1418. local->dynamic_ps_forced_timeout = timeout;
  1419. /* no change, but if automatic follow powersave */
  1420. mutex_lock(&sdata->u.mgd.mtx);
  1421. __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
  1422. mutex_unlock(&sdata->u.mgd.mtx);
  1423. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  1424. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1425. ieee80211_recalc_ps(local, -1);
  1426. return 0;
  1427. }
  1428. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  1429. struct net_device *dev,
  1430. s32 rssi_thold, u32 rssi_hyst)
  1431. {
  1432. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1433. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1434. struct ieee80211_vif *vif = &sdata->vif;
  1435. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1436. if (rssi_thold == bss_conf->cqm_rssi_thold &&
  1437. rssi_hyst == bss_conf->cqm_rssi_hyst)
  1438. return 0;
  1439. bss_conf->cqm_rssi_thold = rssi_thold;
  1440. bss_conf->cqm_rssi_hyst = rssi_hyst;
  1441. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
  1442. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1443. return -EOPNOTSUPP;
  1444. return 0;
  1445. }
  1446. /* tell the driver upon association, unless already associated */
  1447. if (sdata->u.mgd.associated)
  1448. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  1449. return 0;
  1450. }
  1451. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  1452. struct net_device *dev,
  1453. const u8 *addr,
  1454. const struct cfg80211_bitrate_mask *mask)
  1455. {
  1456. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1457. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1458. int i, ret;
  1459. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
  1460. ret = drv_set_bitrate_mask(local, sdata, mask);
  1461. if (ret)
  1462. return ret;
  1463. }
  1464. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  1465. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  1466. return 0;
  1467. }
  1468. static int ieee80211_remain_on_channel_hw(struct ieee80211_local *local,
  1469. struct net_device *dev,
  1470. struct ieee80211_channel *chan,
  1471. enum nl80211_channel_type chantype,
  1472. unsigned int duration, u64 *cookie)
  1473. {
  1474. int ret;
  1475. u32 random_cookie;
  1476. lockdep_assert_held(&local->mtx);
  1477. if (local->hw_roc_cookie)
  1478. return -EBUSY;
  1479. /* must be nonzero */
  1480. random_cookie = random32() | 1;
  1481. *cookie = random_cookie;
  1482. local->hw_roc_dev = dev;
  1483. local->hw_roc_cookie = random_cookie;
  1484. local->hw_roc_channel = chan;
  1485. local->hw_roc_channel_type = chantype;
  1486. local->hw_roc_duration = duration;
  1487. ret = drv_remain_on_channel(local, chan, chantype, duration);
  1488. if (ret) {
  1489. local->hw_roc_channel = NULL;
  1490. local->hw_roc_cookie = 0;
  1491. }
  1492. return ret;
  1493. }
  1494. static int ieee80211_remain_on_channel(struct wiphy *wiphy,
  1495. struct net_device *dev,
  1496. struct ieee80211_channel *chan,
  1497. enum nl80211_channel_type channel_type,
  1498. unsigned int duration,
  1499. u64 *cookie)
  1500. {
  1501. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1502. struct ieee80211_local *local = sdata->local;
  1503. if (local->ops->remain_on_channel) {
  1504. int ret;
  1505. mutex_lock(&local->mtx);
  1506. ret = ieee80211_remain_on_channel_hw(local, dev,
  1507. chan, channel_type,
  1508. duration, cookie);
  1509. local->hw_roc_for_tx = false;
  1510. mutex_unlock(&local->mtx);
  1511. return ret;
  1512. }
  1513. return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
  1514. duration, cookie);
  1515. }
  1516. static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local *local,
  1517. u64 cookie)
  1518. {
  1519. int ret;
  1520. lockdep_assert_held(&local->mtx);
  1521. if (local->hw_roc_cookie != cookie)
  1522. return -ENOENT;
  1523. ret = drv_cancel_remain_on_channel(local);
  1524. if (ret)
  1525. return ret;
  1526. local->hw_roc_cookie = 0;
  1527. local->hw_roc_channel = NULL;
  1528. ieee80211_recalc_idle(local);
  1529. return 0;
  1530. }
  1531. static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
  1532. struct net_device *dev,
  1533. u64 cookie)
  1534. {
  1535. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1536. struct ieee80211_local *local = sdata->local;
  1537. if (local->ops->cancel_remain_on_channel) {
  1538. int ret;
  1539. mutex_lock(&local->mtx);
  1540. ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
  1541. mutex_unlock(&local->mtx);
  1542. return ret;
  1543. }
  1544. return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
  1545. }
  1546. static enum work_done_result
  1547. ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
  1548. {
  1549. /*
  1550. * Use the data embedded in the work struct for reporting
  1551. * here so if the driver mangled the SKB before dropping
  1552. * it (which is the only way we really should get here)
  1553. * then we don't report mangled data.
  1554. *
  1555. * If there was no wait time, then by the time we get here
  1556. * the driver will likely not have reported the status yet,
  1557. * so in that case userspace will have to deal with it.
  1558. */
  1559. if (wk->offchan_tx.wait && !wk->offchan_tx.status)
  1560. cfg80211_mgmt_tx_status(wk->sdata->dev,
  1561. (unsigned long) wk->offchan_tx.frame,
  1562. wk->ie, wk->ie_len, false, GFP_KERNEL);
  1563. return WORK_DONE_DESTROY;
  1564. }
  1565. static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
  1566. struct ieee80211_channel *chan, bool offchan,
  1567. enum nl80211_channel_type channel_type,
  1568. bool channel_type_valid, unsigned int wait,
  1569. const u8 *buf, size_t len, bool no_cck,
  1570. u64 *cookie)
  1571. {
  1572. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1573. struct ieee80211_local *local = sdata->local;
  1574. struct sk_buff *skb;
  1575. struct sta_info *sta;
  1576. struct ieee80211_work *wk;
  1577. const struct ieee80211_mgmt *mgmt = (void *)buf;
  1578. u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
  1579. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1580. bool is_offchan = false;
  1581. /* Check that we are on the requested channel for transmission */
  1582. if (chan != local->tmp_channel &&
  1583. chan != local->oper_channel)
  1584. is_offchan = true;
  1585. if (channel_type_valid &&
  1586. (channel_type != local->tmp_channel_type &&
  1587. channel_type != local->_oper_channel_type))
  1588. is_offchan = true;
  1589. if (chan == local->hw_roc_channel) {
  1590. /* TODO: check channel type? */
  1591. is_offchan = false;
  1592. flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
  1593. }
  1594. if (no_cck)
  1595. flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
  1596. if (is_offchan && !offchan)
  1597. return -EBUSY;
  1598. switch (sdata->vif.type) {
  1599. case NL80211_IFTYPE_ADHOC:
  1600. case NL80211_IFTYPE_AP:
  1601. case NL80211_IFTYPE_AP_VLAN:
  1602. case NL80211_IFTYPE_P2P_GO:
  1603. case NL80211_IFTYPE_MESH_POINT:
  1604. if (!ieee80211_is_action(mgmt->frame_control) ||
  1605. mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
  1606. break;
  1607. rcu_read_lock();
  1608. sta = sta_info_get(sdata, mgmt->da);
  1609. rcu_read_unlock();
  1610. if (!sta)
  1611. return -ENOLINK;
  1612. break;
  1613. case NL80211_IFTYPE_STATION:
  1614. case NL80211_IFTYPE_P2P_CLIENT:
  1615. break;
  1616. default:
  1617. return -EOPNOTSUPP;
  1618. }
  1619. skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
  1620. if (!skb)
  1621. return -ENOMEM;
  1622. skb_reserve(skb, local->hw.extra_tx_headroom);
  1623. memcpy(skb_put(skb, len), buf, len);
  1624. IEEE80211_SKB_CB(skb)->flags = flags;
  1625. skb->dev = sdata->dev;
  1626. *cookie = (unsigned long) skb;
  1627. if (is_offchan && local->ops->remain_on_channel) {
  1628. unsigned int duration;
  1629. int ret;
  1630. mutex_lock(&local->mtx);
  1631. /*
  1632. * If the duration is zero, then the driver
  1633. * wouldn't actually do anything. Set it to
  1634. * 100 for now.
  1635. *
  1636. * TODO: cancel the off-channel operation
  1637. * when we get the SKB's TX status and
  1638. * the wait time was zero before.
  1639. */
  1640. duration = 100;
  1641. if (wait)
  1642. duration = wait;
  1643. ret = ieee80211_remain_on_channel_hw(local, dev, chan,
  1644. channel_type,
  1645. duration, cookie);
  1646. if (ret) {
  1647. kfree_skb(skb);
  1648. mutex_unlock(&local->mtx);
  1649. return ret;
  1650. }
  1651. local->hw_roc_for_tx = true;
  1652. local->hw_roc_duration = wait;
  1653. /*
  1654. * queue up frame for transmission after
  1655. * ieee80211_ready_on_channel call
  1656. */
  1657. /* modify cookie to prevent API mismatches */
  1658. *cookie ^= 2;
  1659. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
  1660. local->hw_roc_skb = skb;
  1661. local->hw_roc_skb_for_status = skb;
  1662. mutex_unlock(&local->mtx);
  1663. return 0;
  1664. }
  1665. /*
  1666. * Can transmit right away if the channel was the
  1667. * right one and there's no wait involved... If a
  1668. * wait is involved, we might otherwise not be on
  1669. * the right channel for long enough!
  1670. */
  1671. if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
  1672. ieee80211_tx_skb(sdata, skb);
  1673. return 0;
  1674. }
  1675. wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL);
  1676. if (!wk) {
  1677. kfree_skb(skb);
  1678. return -ENOMEM;
  1679. }
  1680. wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
  1681. wk->chan = chan;
  1682. wk->chan_type = channel_type;
  1683. wk->sdata = sdata;
  1684. wk->done = ieee80211_offchan_tx_done;
  1685. wk->offchan_tx.frame = skb;
  1686. wk->offchan_tx.wait = wait;
  1687. wk->ie_len = len;
  1688. memcpy(wk->ie, buf, len);
  1689. ieee80211_add_work(wk);
  1690. return 0;
  1691. }
  1692. static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
  1693. struct net_device *dev,
  1694. u64 cookie)
  1695. {
  1696. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1697. struct ieee80211_local *local = sdata->local;
  1698. struct ieee80211_work *wk;
  1699. int ret = -ENOENT;
  1700. mutex_lock(&local->mtx);
  1701. if (local->ops->cancel_remain_on_channel) {
  1702. cookie ^= 2;
  1703. ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
  1704. if (ret == 0) {
  1705. kfree_skb(local->hw_roc_skb);
  1706. local->hw_roc_skb = NULL;
  1707. local->hw_roc_skb_for_status = NULL;
  1708. }
  1709. mutex_unlock(&local->mtx);
  1710. return ret;
  1711. }
  1712. list_for_each_entry(wk, &local->work_list, list) {
  1713. if (wk->sdata != sdata)
  1714. continue;
  1715. if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
  1716. continue;
  1717. if (cookie != (unsigned long) wk->offchan_tx.frame)
  1718. continue;
  1719. wk->timeout = jiffies;
  1720. ieee80211_queue_work(&local->hw, &local->work_work);
  1721. ret = 0;
  1722. break;
  1723. }
  1724. mutex_unlock(&local->mtx);
  1725. return ret;
  1726. }
  1727. static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
  1728. struct net_device *dev,
  1729. u16 frame_type, bool reg)
  1730. {
  1731. struct ieee80211_local *local = wiphy_priv(wiphy);
  1732. if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
  1733. return;
  1734. if (reg)
  1735. local->probe_req_reg++;
  1736. else
  1737. local->probe_req_reg--;
  1738. ieee80211_queue_work(&local->hw, &local->reconfig_filter);
  1739. }
  1740. static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  1741. {
  1742. struct ieee80211_local *local = wiphy_priv(wiphy);
  1743. if (local->started)
  1744. return -EOPNOTSUPP;
  1745. return drv_set_antenna(local, tx_ant, rx_ant);
  1746. }
  1747. static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
  1748. {
  1749. struct ieee80211_local *local = wiphy_priv(wiphy);
  1750. return drv_get_antenna(local, tx_ant, rx_ant);
  1751. }
  1752. static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
  1753. {
  1754. struct ieee80211_local *local = wiphy_priv(wiphy);
  1755. return drv_set_ringparam(local, tx, rx);
  1756. }
  1757. static void ieee80211_get_ringparam(struct wiphy *wiphy,
  1758. u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
  1759. {
  1760. struct ieee80211_local *local = wiphy_priv(wiphy);
  1761. drv_get_ringparam(local, tx, tx_max, rx, rx_max);
  1762. }
  1763. static int ieee80211_set_rekey_data(struct wiphy *wiphy,
  1764. struct net_device *dev,
  1765. struct cfg80211_gtk_rekey_data *data)
  1766. {
  1767. struct ieee80211_local *local = wiphy_priv(wiphy);
  1768. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1769. if (!local->ops->set_rekey_data)
  1770. return -EOPNOTSUPP;
  1771. drv_set_rekey_data(local, sdata, data);
  1772. return 0;
  1773. }
  1774. static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
  1775. {
  1776. u8 *pos = (void *)skb_put(skb, 7);
  1777. *pos++ = WLAN_EID_EXT_CAPABILITY;
  1778. *pos++ = 5; /* len */
  1779. *pos++ = 0x0;
  1780. *pos++ = 0x0;
  1781. *pos++ = 0x0;
  1782. *pos++ = 0x0;
  1783. *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
  1784. }
  1785. static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
  1786. {
  1787. struct ieee80211_local *local = sdata->local;
  1788. u16 capab;
  1789. capab = 0;
  1790. if (local->oper_channel->band != IEEE80211_BAND_2GHZ)
  1791. return capab;
  1792. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
  1793. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  1794. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
  1795. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  1796. return capab;
  1797. }
  1798. static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
  1799. u8 *peer, u8 *bssid)
  1800. {
  1801. struct ieee80211_tdls_lnkie *lnkid;
  1802. lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
  1803. lnkid->ie_type = WLAN_EID_LINK_ID;
  1804. lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
  1805. memcpy(lnkid->bssid, bssid, ETH_ALEN);
  1806. memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
  1807. memcpy(lnkid->resp_sta, peer, ETH_ALEN);
  1808. }
  1809. static int
  1810. ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
  1811. u8 *peer, u8 action_code, u8 dialog_token,
  1812. u16 status_code, struct sk_buff *skb)
  1813. {
  1814. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1815. struct ieee80211_tdls_data *tf;
  1816. tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
  1817. memcpy(tf->da, peer, ETH_ALEN);
  1818. memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
  1819. tf->ether_type = cpu_to_be16(ETH_P_TDLS);
  1820. tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
  1821. switch (action_code) {
  1822. case WLAN_TDLS_SETUP_REQUEST:
  1823. tf->category = WLAN_CATEGORY_TDLS;
  1824. tf->action_code = WLAN_TDLS_SETUP_REQUEST;
  1825. skb_put(skb, sizeof(tf->u.setup_req));
  1826. tf->u.setup_req.dialog_token = dialog_token;
  1827. tf->u.setup_req.capability =
  1828. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  1829. ieee80211_add_srates_ie(&sdata->vif, skb);
  1830. ieee80211_add_ext_srates_ie(&sdata->vif, skb);
  1831. ieee80211_tdls_add_ext_capab(skb);
  1832. break;
  1833. case WLAN_TDLS_SETUP_RESPONSE:
  1834. tf->category = WLAN_CATEGORY_TDLS;
  1835. tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
  1836. skb_put(skb, sizeof(tf->u.setup_resp));
  1837. tf->u.setup_resp.status_code = cpu_to_le16(status_code);
  1838. tf->u.setup_resp.dialog_token = dialog_token;
  1839. tf->u.setup_resp.capability =
  1840. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  1841. ieee80211_add_srates_ie(&sdata->vif, skb);
  1842. ieee80211_add_ext_srates_ie(&sdata->vif, skb);
  1843. ieee80211_tdls_add_ext_capab(skb);
  1844. break;
  1845. case WLAN_TDLS_SETUP_CONFIRM:
  1846. tf->category = WLAN_CATEGORY_TDLS;
  1847. tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
  1848. skb_put(skb, sizeof(tf->u.setup_cfm));
  1849. tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
  1850. tf->u.setup_cfm.dialog_token = dialog_token;
  1851. break;
  1852. case WLAN_TDLS_TEARDOWN:
  1853. tf->category = WLAN_CATEGORY_TDLS;
  1854. tf->action_code = WLAN_TDLS_TEARDOWN;
  1855. skb_put(skb, sizeof(tf->u.teardown));
  1856. tf->u.teardown.reason_code = cpu_to_le16(status_code);
  1857. break;
  1858. case WLAN_TDLS_DISCOVERY_REQUEST:
  1859. tf->category = WLAN_CATEGORY_TDLS;
  1860. tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
  1861. skb_put(skb, sizeof(tf->u.discover_req));
  1862. tf->u.discover_req.dialog_token = dialog_token;
  1863. break;
  1864. default:
  1865. return -EINVAL;
  1866. }
  1867. return 0;
  1868. }
  1869. static int
  1870. ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
  1871. u8 *peer, u8 action_code, u8 dialog_token,
  1872. u16 status_code, struct sk_buff *skb)
  1873. {
  1874. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1875. struct ieee80211_mgmt *mgmt;
  1876. mgmt = (void *)skb_put(skb, 24);
  1877. memset(mgmt, 0, 24);
  1878. memcpy(mgmt->da, peer, ETH_ALEN);
  1879. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  1880. memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
  1881. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1882. IEEE80211_STYPE_ACTION);
  1883. switch (action_code) {
  1884. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  1885. skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
  1886. mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
  1887. mgmt->u.action.u.tdls_discover_resp.action_code =
  1888. WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
  1889. mgmt->u.action.u.tdls_discover_resp.dialog_token =
  1890. dialog_token;
  1891. mgmt->u.action.u.tdls_discover_resp.capability =
  1892. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  1893. ieee80211_add_srates_ie(&sdata->vif, skb);
  1894. ieee80211_add_ext_srates_ie(&sdata->vif, skb);
  1895. ieee80211_tdls_add_ext_capab(skb);
  1896. break;
  1897. default:
  1898. return -EINVAL;
  1899. }
  1900. return 0;
  1901. }
  1902. static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1903. u8 *peer, u8 action_code, u8 dialog_token,
  1904. u16 status_code, const u8 *extra_ies,
  1905. size_t extra_ies_len)
  1906. {
  1907. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1908. struct ieee80211_local *local = sdata->local;
  1909. struct ieee80211_tx_info *info;
  1910. struct sk_buff *skb = NULL;
  1911. bool send_direct;
  1912. int ret;
  1913. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
  1914. return -ENOTSUPP;
  1915. /* make sure we are in managed mode, and associated */
  1916. if (sdata->vif.type != NL80211_IFTYPE_STATION ||
  1917. !sdata->u.mgd.associated)
  1918. return -EINVAL;
  1919. #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
  1920. printk(KERN_DEBUG "TDLS mgmt action %d peer %pM\n", action_code, peer);
  1921. #endif
  1922. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  1923. max(sizeof(struct ieee80211_mgmt),
  1924. sizeof(struct ieee80211_tdls_data)) +
  1925. 50 + /* supported rates */
  1926. 7 + /* ext capab */
  1927. extra_ies_len +
  1928. sizeof(struct ieee80211_tdls_lnkie));
  1929. if (!skb)
  1930. return -ENOMEM;
  1931. info = IEEE80211_SKB_CB(skb);
  1932. skb_reserve(skb, local->hw.extra_tx_headroom);
  1933. switch (action_code) {
  1934. case WLAN_TDLS_SETUP_REQUEST:
  1935. case WLAN_TDLS_SETUP_RESPONSE:
  1936. case WLAN_TDLS_SETUP_CONFIRM:
  1937. case WLAN_TDLS_TEARDOWN:
  1938. case WLAN_TDLS_DISCOVERY_REQUEST:
  1939. ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
  1940. action_code, dialog_token,
  1941. status_code, skb);
  1942. send_direct = false;
  1943. break;
  1944. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  1945. ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
  1946. dialog_token, status_code,
  1947. skb);
  1948. send_direct = true;
  1949. break;
  1950. default:
  1951. ret = -ENOTSUPP;
  1952. break;
  1953. }
  1954. if (ret < 0)
  1955. goto fail;
  1956. if (extra_ies_len)
  1957. memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
  1958. /* the TDLS link IE is always added last */
  1959. switch (action_code) {
  1960. case WLAN_TDLS_SETUP_REQUEST:
  1961. case WLAN_TDLS_SETUP_CONFIRM:
  1962. case WLAN_TDLS_TEARDOWN:
  1963. case WLAN_TDLS_DISCOVERY_REQUEST:
  1964. /* we are the initiator */
  1965. ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
  1966. sdata->u.mgd.bssid);
  1967. break;
  1968. case WLAN_TDLS_SETUP_RESPONSE:
  1969. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  1970. /* we are the responder */
  1971. ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
  1972. sdata->u.mgd.bssid);
  1973. break;
  1974. default:
  1975. ret = -ENOTSUPP;
  1976. goto fail;
  1977. }
  1978. if (send_direct) {
  1979. ieee80211_tx_skb(sdata, skb);
  1980. return 0;
  1981. }
  1982. /*
  1983. * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
  1984. * we should default to AC_VI.
  1985. */
  1986. switch (action_code) {
  1987. case WLAN_TDLS_SETUP_REQUEST:
  1988. case WLAN_TDLS_SETUP_RESPONSE:
  1989. skb_set_queue_mapping(skb, IEEE80211_AC_BK);
  1990. skb->priority = 2;
  1991. break;
  1992. default:
  1993. skb_set_queue_mapping(skb, IEEE80211_AC_VI);
  1994. skb->priority = 5;
  1995. break;
  1996. }
  1997. /* disable bottom halves when entering the Tx path */
  1998. local_bh_disable();
  1999. ret = ieee80211_subif_start_xmit(skb, dev);
  2000. local_bh_enable();
  2001. return ret;
  2002. fail:
  2003. dev_kfree_skb(skb);
  2004. return ret;
  2005. }
  2006. static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
  2007. u8 *peer, enum nl80211_tdls_operation oper)
  2008. {
  2009. struct sta_info *sta;
  2010. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2011. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
  2012. return -ENOTSUPP;
  2013. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2014. return -EINVAL;
  2015. #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
  2016. printk(KERN_DEBUG "TDLS oper %d peer %pM\n", oper, peer);
  2017. #endif
  2018. switch (oper) {
  2019. case NL80211_TDLS_ENABLE_LINK:
  2020. rcu_read_lock();
  2021. sta = sta_info_get(sdata, peer);
  2022. if (!sta) {
  2023. rcu_read_unlock();
  2024. return -ENOLINK;
  2025. }
  2026. set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
  2027. rcu_read_unlock();
  2028. break;
  2029. case NL80211_TDLS_DISABLE_LINK:
  2030. return sta_info_destroy_addr(sdata, peer);
  2031. case NL80211_TDLS_TEARDOWN:
  2032. case NL80211_TDLS_SETUP:
  2033. case NL80211_TDLS_DISCOVERY_REQ:
  2034. /* We don't support in-driver setup/teardown/discovery */
  2035. return -ENOTSUPP;
  2036. default:
  2037. return -ENOTSUPP;
  2038. }
  2039. return 0;
  2040. }
  2041. struct cfg80211_ops mac80211_config_ops = {
  2042. .add_virtual_intf = ieee80211_add_iface,
  2043. .del_virtual_intf = ieee80211_del_iface,
  2044. .change_virtual_intf = ieee80211_change_iface,
  2045. .add_key = ieee80211_add_key,
  2046. .del_key = ieee80211_del_key,
  2047. .get_key = ieee80211_get_key,
  2048. .set_default_key = ieee80211_config_default_key,
  2049. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  2050. .add_beacon = ieee80211_add_beacon,
  2051. .set_beacon = ieee80211_set_beacon,
  2052. .del_beacon = ieee80211_del_beacon,
  2053. .add_station = ieee80211_add_station,
  2054. .del_station = ieee80211_del_station,
  2055. .change_station = ieee80211_change_station,
  2056. .get_station = ieee80211_get_station,
  2057. .dump_station = ieee80211_dump_station,
  2058. .dump_survey = ieee80211_dump_survey,
  2059. #ifdef CONFIG_MAC80211_MESH
  2060. .add_mpath = ieee80211_add_mpath,
  2061. .del_mpath = ieee80211_del_mpath,
  2062. .change_mpath = ieee80211_change_mpath,
  2063. .get_mpath = ieee80211_get_mpath,
  2064. .dump_mpath = ieee80211_dump_mpath,
  2065. .update_mesh_config = ieee80211_update_mesh_config,
  2066. .get_mesh_config = ieee80211_get_mesh_config,
  2067. .join_mesh = ieee80211_join_mesh,
  2068. .leave_mesh = ieee80211_leave_mesh,
  2069. #endif
  2070. .change_bss = ieee80211_change_bss,
  2071. .set_txq_params = ieee80211_set_txq_params,
  2072. .set_channel = ieee80211_set_channel,
  2073. .suspend = ieee80211_suspend,
  2074. .resume = ieee80211_resume,
  2075. .scan = ieee80211_scan,
  2076. .sched_scan_start = ieee80211_sched_scan_start,
  2077. .sched_scan_stop = ieee80211_sched_scan_stop,
  2078. .auth = ieee80211_auth,
  2079. .assoc = ieee80211_assoc,
  2080. .deauth = ieee80211_deauth,
  2081. .disassoc = ieee80211_disassoc,
  2082. .join_ibss = ieee80211_join_ibss,
  2083. .leave_ibss = ieee80211_leave_ibss,
  2084. .set_wiphy_params = ieee80211_set_wiphy_params,
  2085. .set_tx_power = ieee80211_set_tx_power,
  2086. .get_tx_power = ieee80211_get_tx_power,
  2087. .set_wds_peer = ieee80211_set_wds_peer,
  2088. .rfkill_poll = ieee80211_rfkill_poll,
  2089. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  2090. CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
  2091. .set_power_mgmt = ieee80211_set_power_mgmt,
  2092. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  2093. .remain_on_channel = ieee80211_remain_on_channel,
  2094. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  2095. .mgmt_tx = ieee80211_mgmt_tx,
  2096. .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
  2097. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  2098. .mgmt_frame_register = ieee80211_mgmt_frame_register,
  2099. .set_antenna = ieee80211_set_antenna,
  2100. .get_antenna = ieee80211_get_antenna,
  2101. .set_ringparam = ieee80211_set_ringparam,
  2102. .get_ringparam = ieee80211_get_ringparam,
  2103. .set_rekey_data = ieee80211_set_rekey_data,
  2104. .tdls_oper = ieee80211_tdls_oper,
  2105. .tdls_mgmt = ieee80211_tdls_mgmt,
  2106. };