cfg.c 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643
  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. struct ieee80211_sub_if_data *vlan;
  492. int ret;
  493. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  494. old = rtnl_dereference(sdata->u.ap.beacon);
  495. if (old)
  496. return -EALREADY;
  497. ret = ieee80211_config_beacon(sdata, params);
  498. if (ret)
  499. return ret;
  500. /*
  501. * Apply control port protocol, this allows us to
  502. * not encrypt dynamic WEP control frames.
  503. */
  504. sdata->control_port_protocol = params->crypto.control_port_ethertype;
  505. sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
  506. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
  507. vlan->control_port_protocol =
  508. params->crypto.control_port_ethertype;
  509. vlan->control_port_no_encrypt =
  510. params->crypto.control_port_no_encrypt;
  511. }
  512. return 0;
  513. }
  514. static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  515. struct beacon_parameters *params)
  516. {
  517. struct ieee80211_sub_if_data *sdata;
  518. struct beacon_data *old;
  519. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  520. old = rtnl_dereference(sdata->u.ap.beacon);
  521. if (!old)
  522. return -ENOENT;
  523. return ieee80211_config_beacon(sdata, params);
  524. }
  525. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  526. {
  527. struct ieee80211_sub_if_data *sdata;
  528. struct beacon_data *old;
  529. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  530. old = rtnl_dereference(sdata->u.ap.beacon);
  531. if (!old)
  532. return -ENOENT;
  533. RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
  534. synchronize_rcu();
  535. kfree(old);
  536. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  537. return 0;
  538. }
  539. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  540. struct iapp_layer2_update {
  541. u8 da[ETH_ALEN]; /* broadcast */
  542. u8 sa[ETH_ALEN]; /* STA addr */
  543. __be16 len; /* 6 */
  544. u8 dsap; /* 0 */
  545. u8 ssap; /* 0 */
  546. u8 control;
  547. u8 xid_info[3];
  548. } __packed;
  549. static void ieee80211_send_layer2_update(struct sta_info *sta)
  550. {
  551. struct iapp_layer2_update *msg;
  552. struct sk_buff *skb;
  553. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  554. * bridge devices */
  555. skb = dev_alloc_skb(sizeof(*msg));
  556. if (!skb)
  557. return;
  558. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  559. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  560. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  561. memset(msg->da, 0xff, ETH_ALEN);
  562. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  563. msg->len = htons(6);
  564. msg->dsap = 0;
  565. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  566. msg->control = 0xaf; /* XID response lsb.1111F101.
  567. * F=0 (no poll command; unsolicited frame) */
  568. msg->xid_info[0] = 0x81; /* XID format identifier */
  569. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  570. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  571. skb->dev = sta->sdata->dev;
  572. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  573. memset(skb->cb, 0, sizeof(skb->cb));
  574. netif_rx_ni(skb);
  575. }
  576. static void sta_apply_parameters(struct ieee80211_local *local,
  577. struct sta_info *sta,
  578. struct station_parameters *params)
  579. {
  580. u32 rates;
  581. int i, j;
  582. struct ieee80211_supported_band *sband;
  583. struct ieee80211_sub_if_data *sdata = sta->sdata;
  584. u32 mask, set;
  585. sband = local->hw.wiphy->bands[local->oper_channel->band];
  586. mask = params->sta_flags_mask;
  587. set = params->sta_flags_set;
  588. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  589. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  590. set_sta_flag(sta, WLAN_STA_AUTHORIZED);
  591. else
  592. clear_sta_flag(sta, WLAN_STA_AUTHORIZED);
  593. }
  594. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  595. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  596. set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  597. else
  598. clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  599. }
  600. if (mask & BIT(NL80211_STA_FLAG_WME)) {
  601. if (set & BIT(NL80211_STA_FLAG_WME)) {
  602. set_sta_flag(sta, WLAN_STA_WME);
  603. sta->sta.wme = true;
  604. } else {
  605. clear_sta_flag(sta, WLAN_STA_WME);
  606. sta->sta.wme = false;
  607. }
  608. }
  609. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  610. if (set & BIT(NL80211_STA_FLAG_MFP))
  611. set_sta_flag(sta, WLAN_STA_MFP);
  612. else
  613. clear_sta_flag(sta, WLAN_STA_MFP);
  614. }
  615. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
  616. if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
  617. set_sta_flag(sta, WLAN_STA_AUTH);
  618. else
  619. clear_sta_flag(sta, WLAN_STA_AUTH);
  620. }
  621. if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
  622. if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
  623. set_sta_flag(sta, WLAN_STA_TDLS_PEER);
  624. else
  625. clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
  626. }
  627. if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
  628. sta->sta.uapsd_queues = params->uapsd_queues;
  629. sta->sta.max_sp = params->max_sp;
  630. }
  631. /*
  632. * cfg80211 validates this (1-2007) and allows setting the AID
  633. * only when creating a new station entry
  634. */
  635. if (params->aid)
  636. sta->sta.aid = params->aid;
  637. /*
  638. * FIXME: updating the following information is racy when this
  639. * function is called from ieee80211_change_station().
  640. * However, all this information should be static so
  641. * maybe we should just reject attemps to change it.
  642. */
  643. if (params->listen_interval >= 0)
  644. sta->listen_interval = params->listen_interval;
  645. if (params->supported_rates) {
  646. rates = 0;
  647. for (i = 0; i < params->supported_rates_len; i++) {
  648. int rate = (params->supported_rates[i] & 0x7f) * 5;
  649. for (j = 0; j < sband->n_bitrates; j++) {
  650. if (sband->bitrates[j].bitrate == rate)
  651. rates |= BIT(j);
  652. }
  653. }
  654. sta->sta.supp_rates[local->oper_channel->band] = rates;
  655. }
  656. if (params->ht_capa)
  657. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  658. params->ht_capa,
  659. &sta->sta.ht_cap);
  660. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  661. #ifdef CONFIG_MAC80211_MESH
  662. if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED)
  663. switch (params->plink_state) {
  664. case NL80211_PLINK_LISTEN:
  665. case NL80211_PLINK_ESTAB:
  666. case NL80211_PLINK_BLOCKED:
  667. sta->plink_state = params->plink_state;
  668. break;
  669. default:
  670. /* nothing */
  671. break;
  672. }
  673. else
  674. switch (params->plink_action) {
  675. case PLINK_ACTION_OPEN:
  676. mesh_plink_open(sta);
  677. break;
  678. case PLINK_ACTION_BLOCK:
  679. mesh_plink_block(sta);
  680. break;
  681. }
  682. #endif
  683. }
  684. }
  685. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  686. u8 *mac, struct station_parameters *params)
  687. {
  688. struct ieee80211_local *local = wiphy_priv(wiphy);
  689. struct sta_info *sta;
  690. struct ieee80211_sub_if_data *sdata;
  691. int err;
  692. int layer2_update;
  693. if (params->vlan) {
  694. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  695. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  696. sdata->vif.type != NL80211_IFTYPE_AP)
  697. return -EINVAL;
  698. } else
  699. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  700. if (compare_ether_addr(mac, sdata->vif.addr) == 0)
  701. return -EINVAL;
  702. if (is_multicast_ether_addr(mac))
  703. return -EINVAL;
  704. /* Only TDLS-supporting stations can add TDLS peers */
  705. if ((params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
  706. !((wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
  707. sdata->vif.type == NL80211_IFTYPE_STATION))
  708. return -ENOTSUPP;
  709. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  710. if (!sta)
  711. return -ENOMEM;
  712. set_sta_flag(sta, WLAN_STA_AUTH);
  713. set_sta_flag(sta, WLAN_STA_ASSOC);
  714. sta_apply_parameters(local, sta, params);
  715. rate_control_rate_init(sta);
  716. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  717. sdata->vif.type == NL80211_IFTYPE_AP;
  718. err = sta_info_insert_rcu(sta);
  719. if (err) {
  720. rcu_read_unlock();
  721. return err;
  722. }
  723. if (layer2_update)
  724. ieee80211_send_layer2_update(sta);
  725. rcu_read_unlock();
  726. return 0;
  727. }
  728. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  729. u8 *mac)
  730. {
  731. struct ieee80211_local *local = wiphy_priv(wiphy);
  732. struct ieee80211_sub_if_data *sdata;
  733. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  734. if (mac)
  735. return sta_info_destroy_addr_bss(sdata, mac);
  736. sta_info_flush(local, sdata);
  737. return 0;
  738. }
  739. static int ieee80211_change_station(struct wiphy *wiphy,
  740. struct net_device *dev,
  741. u8 *mac,
  742. struct station_parameters *params)
  743. {
  744. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  745. struct ieee80211_local *local = wiphy_priv(wiphy);
  746. struct sta_info *sta;
  747. struct ieee80211_sub_if_data *vlansdata;
  748. rcu_read_lock();
  749. sta = sta_info_get_bss(sdata, mac);
  750. if (!sta) {
  751. rcu_read_unlock();
  752. return -ENOENT;
  753. }
  754. /* The TDLS bit cannot be toggled after the STA was added */
  755. if ((params->sta_flags_mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
  756. !!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) !=
  757. !!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
  758. rcu_read_unlock();
  759. return -EINVAL;
  760. }
  761. if (params->vlan && params->vlan != sta->sdata->dev) {
  762. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  763. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  764. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  765. rcu_read_unlock();
  766. return -EINVAL;
  767. }
  768. if (params->vlan->ieee80211_ptr->use_4addr) {
  769. if (vlansdata->u.vlan.sta) {
  770. rcu_read_unlock();
  771. return -EBUSY;
  772. }
  773. RCU_INIT_POINTER(vlansdata->u.vlan.sta, sta);
  774. }
  775. sta->sdata = vlansdata;
  776. ieee80211_send_layer2_update(sta);
  777. }
  778. sta_apply_parameters(local, sta, params);
  779. rcu_read_unlock();
  780. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  781. params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))
  782. ieee80211_recalc_ps(local, -1);
  783. return 0;
  784. }
  785. #ifdef CONFIG_MAC80211_MESH
  786. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  787. u8 *dst, u8 *next_hop)
  788. {
  789. struct ieee80211_sub_if_data *sdata;
  790. struct mesh_path *mpath;
  791. struct sta_info *sta;
  792. int err;
  793. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  794. rcu_read_lock();
  795. sta = sta_info_get(sdata, next_hop);
  796. if (!sta) {
  797. rcu_read_unlock();
  798. return -ENOENT;
  799. }
  800. err = mesh_path_add(dst, sdata);
  801. if (err) {
  802. rcu_read_unlock();
  803. return err;
  804. }
  805. mpath = mesh_path_lookup(dst, sdata);
  806. if (!mpath) {
  807. rcu_read_unlock();
  808. return -ENXIO;
  809. }
  810. mesh_path_fix_nexthop(mpath, sta);
  811. rcu_read_unlock();
  812. return 0;
  813. }
  814. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  815. u8 *dst)
  816. {
  817. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  818. if (dst)
  819. return mesh_path_del(dst, sdata);
  820. mesh_path_flush_by_iface(sdata);
  821. return 0;
  822. }
  823. static int ieee80211_change_mpath(struct wiphy *wiphy,
  824. struct net_device *dev,
  825. u8 *dst, u8 *next_hop)
  826. {
  827. struct ieee80211_sub_if_data *sdata;
  828. struct mesh_path *mpath;
  829. struct sta_info *sta;
  830. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  831. rcu_read_lock();
  832. sta = sta_info_get(sdata, next_hop);
  833. if (!sta) {
  834. rcu_read_unlock();
  835. return -ENOENT;
  836. }
  837. mpath = mesh_path_lookup(dst, sdata);
  838. if (!mpath) {
  839. rcu_read_unlock();
  840. return -ENOENT;
  841. }
  842. mesh_path_fix_nexthop(mpath, sta);
  843. rcu_read_unlock();
  844. return 0;
  845. }
  846. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  847. struct mpath_info *pinfo)
  848. {
  849. struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
  850. if (next_hop_sta)
  851. memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
  852. else
  853. memset(next_hop, 0, ETH_ALEN);
  854. pinfo->generation = mesh_paths_generation;
  855. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  856. MPATH_INFO_SN |
  857. MPATH_INFO_METRIC |
  858. MPATH_INFO_EXPTIME |
  859. MPATH_INFO_DISCOVERY_TIMEOUT |
  860. MPATH_INFO_DISCOVERY_RETRIES |
  861. MPATH_INFO_FLAGS;
  862. pinfo->frame_qlen = mpath->frame_queue.qlen;
  863. pinfo->sn = mpath->sn;
  864. pinfo->metric = mpath->metric;
  865. if (time_before(jiffies, mpath->exp_time))
  866. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  867. pinfo->discovery_timeout =
  868. jiffies_to_msecs(mpath->discovery_timeout);
  869. pinfo->discovery_retries = mpath->discovery_retries;
  870. pinfo->flags = 0;
  871. if (mpath->flags & MESH_PATH_ACTIVE)
  872. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  873. if (mpath->flags & MESH_PATH_RESOLVING)
  874. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  875. if (mpath->flags & MESH_PATH_SN_VALID)
  876. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  877. if (mpath->flags & MESH_PATH_FIXED)
  878. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  879. if (mpath->flags & MESH_PATH_RESOLVING)
  880. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  881. pinfo->flags = mpath->flags;
  882. }
  883. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  884. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  885. {
  886. struct ieee80211_sub_if_data *sdata;
  887. struct mesh_path *mpath;
  888. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  889. rcu_read_lock();
  890. mpath = mesh_path_lookup(dst, sdata);
  891. if (!mpath) {
  892. rcu_read_unlock();
  893. return -ENOENT;
  894. }
  895. memcpy(dst, mpath->dst, ETH_ALEN);
  896. mpath_set_pinfo(mpath, next_hop, pinfo);
  897. rcu_read_unlock();
  898. return 0;
  899. }
  900. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  901. int idx, u8 *dst, u8 *next_hop,
  902. struct mpath_info *pinfo)
  903. {
  904. struct ieee80211_sub_if_data *sdata;
  905. struct mesh_path *mpath;
  906. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  907. rcu_read_lock();
  908. mpath = mesh_path_lookup_by_idx(idx, sdata);
  909. if (!mpath) {
  910. rcu_read_unlock();
  911. return -ENOENT;
  912. }
  913. memcpy(dst, mpath->dst, ETH_ALEN);
  914. mpath_set_pinfo(mpath, next_hop, pinfo);
  915. rcu_read_unlock();
  916. return 0;
  917. }
  918. static int ieee80211_get_mesh_config(struct wiphy *wiphy,
  919. struct net_device *dev,
  920. struct mesh_config *conf)
  921. {
  922. struct ieee80211_sub_if_data *sdata;
  923. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  924. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  925. return 0;
  926. }
  927. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  928. {
  929. return (mask >> (parm-1)) & 0x1;
  930. }
  931. static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
  932. const struct mesh_setup *setup)
  933. {
  934. u8 *new_ie;
  935. const u8 *old_ie;
  936. /* allocate information elements */
  937. new_ie = NULL;
  938. old_ie = ifmsh->ie;
  939. if (setup->ie_len) {
  940. new_ie = kmemdup(setup->ie, setup->ie_len,
  941. GFP_KERNEL);
  942. if (!new_ie)
  943. return -ENOMEM;
  944. }
  945. ifmsh->ie_len = setup->ie_len;
  946. ifmsh->ie = new_ie;
  947. kfree(old_ie);
  948. /* now copy the rest of the setup parameters */
  949. ifmsh->mesh_id_len = setup->mesh_id_len;
  950. memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
  951. ifmsh->mesh_pp_id = setup->path_sel_proto;
  952. ifmsh->mesh_pm_id = setup->path_metric;
  953. ifmsh->security = IEEE80211_MESH_SEC_NONE;
  954. if (setup->is_authenticated)
  955. ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
  956. if (setup->is_secure)
  957. ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
  958. return 0;
  959. }
  960. static int ieee80211_update_mesh_config(struct wiphy *wiphy,
  961. struct net_device *dev, u32 mask,
  962. const struct mesh_config *nconf)
  963. {
  964. struct mesh_config *conf;
  965. struct ieee80211_sub_if_data *sdata;
  966. struct ieee80211_if_mesh *ifmsh;
  967. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  968. ifmsh = &sdata->u.mesh;
  969. /* Set the config options which we are interested in setting */
  970. conf = &(sdata->u.mesh.mshcfg);
  971. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  972. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  973. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  974. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  975. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  976. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  977. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  978. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  979. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  980. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  981. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  982. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  983. if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
  984. conf->dot11MeshTTL = nconf->element_ttl;
  985. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  986. conf->auto_open_plinks = nconf->auto_open_plinks;
  987. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  988. conf->dot11MeshHWMPmaxPREQretries =
  989. nconf->dot11MeshHWMPmaxPREQretries;
  990. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  991. conf->path_refresh_time = nconf->path_refresh_time;
  992. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  993. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  994. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  995. conf->dot11MeshHWMPactivePathTimeout =
  996. nconf->dot11MeshHWMPactivePathTimeout;
  997. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  998. conf->dot11MeshHWMPpreqMinInterval =
  999. nconf->dot11MeshHWMPpreqMinInterval;
  1000. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  1001. mask))
  1002. conf->dot11MeshHWMPnetDiameterTraversalTime =
  1003. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  1004. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  1005. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  1006. ieee80211_mesh_root_setup(ifmsh);
  1007. }
  1008. if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
  1009. /* our current gate announcement implementation rides on root
  1010. * announcements, so require this ifmsh to also be a root node
  1011. * */
  1012. if (nconf->dot11MeshGateAnnouncementProtocol &&
  1013. !conf->dot11MeshHWMPRootMode) {
  1014. conf->dot11MeshHWMPRootMode = 1;
  1015. ieee80211_mesh_root_setup(ifmsh);
  1016. }
  1017. conf->dot11MeshGateAnnouncementProtocol =
  1018. nconf->dot11MeshGateAnnouncementProtocol;
  1019. }
  1020. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask)) {
  1021. conf->dot11MeshHWMPRannInterval =
  1022. nconf->dot11MeshHWMPRannInterval;
  1023. }
  1024. return 0;
  1025. }
  1026. static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
  1027. const struct mesh_config *conf,
  1028. const struct mesh_setup *setup)
  1029. {
  1030. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1031. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1032. int err;
  1033. memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
  1034. err = copy_mesh_setup(ifmsh, setup);
  1035. if (err)
  1036. return err;
  1037. ieee80211_start_mesh(sdata);
  1038. return 0;
  1039. }
  1040. static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
  1041. {
  1042. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1043. ieee80211_stop_mesh(sdata);
  1044. return 0;
  1045. }
  1046. #endif
  1047. static int ieee80211_change_bss(struct wiphy *wiphy,
  1048. struct net_device *dev,
  1049. struct bss_parameters *params)
  1050. {
  1051. struct ieee80211_sub_if_data *sdata;
  1052. u32 changed = 0;
  1053. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1054. if (params->use_cts_prot >= 0) {
  1055. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  1056. changed |= BSS_CHANGED_ERP_CTS_PROT;
  1057. }
  1058. if (params->use_short_preamble >= 0) {
  1059. sdata->vif.bss_conf.use_short_preamble =
  1060. params->use_short_preamble;
  1061. changed |= BSS_CHANGED_ERP_PREAMBLE;
  1062. }
  1063. if (!sdata->vif.bss_conf.use_short_slot &&
  1064. sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
  1065. sdata->vif.bss_conf.use_short_slot = true;
  1066. changed |= BSS_CHANGED_ERP_SLOT;
  1067. }
  1068. if (params->use_short_slot_time >= 0) {
  1069. sdata->vif.bss_conf.use_short_slot =
  1070. params->use_short_slot_time;
  1071. changed |= BSS_CHANGED_ERP_SLOT;
  1072. }
  1073. if (params->basic_rates) {
  1074. int i, j;
  1075. u32 rates = 0;
  1076. struct ieee80211_local *local = wiphy_priv(wiphy);
  1077. struct ieee80211_supported_band *sband =
  1078. wiphy->bands[local->oper_channel->band];
  1079. for (i = 0; i < params->basic_rates_len; i++) {
  1080. int rate = (params->basic_rates[i] & 0x7f) * 5;
  1081. for (j = 0; j < sband->n_bitrates; j++) {
  1082. if (sband->bitrates[j].bitrate == rate)
  1083. rates |= BIT(j);
  1084. }
  1085. }
  1086. sdata->vif.bss_conf.basic_rates = rates;
  1087. changed |= BSS_CHANGED_BASIC_RATES;
  1088. }
  1089. if (params->ap_isolate >= 0) {
  1090. if (params->ap_isolate)
  1091. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1092. else
  1093. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1094. }
  1095. if (params->ht_opmode >= 0) {
  1096. sdata->vif.bss_conf.ht_operation_mode =
  1097. (u16) params->ht_opmode;
  1098. changed |= BSS_CHANGED_HT;
  1099. }
  1100. ieee80211_bss_info_change_notify(sdata, changed);
  1101. return 0;
  1102. }
  1103. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  1104. struct net_device *dev,
  1105. struct ieee80211_txq_params *params)
  1106. {
  1107. struct ieee80211_local *local = wiphy_priv(wiphy);
  1108. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1109. struct ieee80211_tx_queue_params p;
  1110. if (!local->ops->conf_tx)
  1111. return -EOPNOTSUPP;
  1112. memset(&p, 0, sizeof(p));
  1113. p.aifs = params->aifs;
  1114. p.cw_max = params->cwmax;
  1115. p.cw_min = params->cwmin;
  1116. p.txop = params->txop;
  1117. /*
  1118. * Setting tx queue params disables u-apsd because it's only
  1119. * called in master mode.
  1120. */
  1121. p.uapsd = false;
  1122. if (params->queue >= local->hw.queues)
  1123. return -EINVAL;
  1124. sdata->tx_conf[params->queue] = p;
  1125. if (drv_conf_tx(local, sdata, params->queue, &p)) {
  1126. wiphy_debug(local->hw.wiphy,
  1127. "failed to set TX queue parameters for queue %d\n",
  1128. params->queue);
  1129. return -EINVAL;
  1130. }
  1131. return 0;
  1132. }
  1133. static int ieee80211_set_channel(struct wiphy *wiphy,
  1134. struct net_device *netdev,
  1135. struct ieee80211_channel *chan,
  1136. enum nl80211_channel_type channel_type)
  1137. {
  1138. struct ieee80211_local *local = wiphy_priv(wiphy);
  1139. struct ieee80211_sub_if_data *sdata = NULL;
  1140. struct ieee80211_channel *old_oper;
  1141. enum nl80211_channel_type old_oper_type;
  1142. enum nl80211_channel_type old_vif_oper_type= NL80211_CHAN_NO_HT;
  1143. if (netdev)
  1144. sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
  1145. switch (ieee80211_get_channel_mode(local, NULL)) {
  1146. case CHAN_MODE_HOPPING:
  1147. return -EBUSY;
  1148. case CHAN_MODE_FIXED:
  1149. if (local->oper_channel != chan)
  1150. return -EBUSY;
  1151. if (!sdata && local->_oper_channel_type == channel_type)
  1152. return 0;
  1153. break;
  1154. case CHAN_MODE_UNDEFINED:
  1155. break;
  1156. }
  1157. if (sdata)
  1158. old_vif_oper_type = sdata->vif.bss_conf.channel_type;
  1159. old_oper_type = local->_oper_channel_type;
  1160. if (!ieee80211_set_channel_type(local, sdata, channel_type))
  1161. return -EBUSY;
  1162. old_oper = local->oper_channel;
  1163. local->oper_channel = chan;
  1164. /* Update driver if changes were actually made. */
  1165. if ((old_oper != local->oper_channel) ||
  1166. (old_oper_type != local->_oper_channel_type))
  1167. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  1168. if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR &&
  1169. old_vif_oper_type != sdata->vif.bss_conf.channel_type)
  1170. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
  1171. return 0;
  1172. }
  1173. #ifdef CONFIG_PM
  1174. static int ieee80211_suspend(struct wiphy *wiphy,
  1175. struct cfg80211_wowlan *wowlan)
  1176. {
  1177. return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
  1178. }
  1179. static int ieee80211_resume(struct wiphy *wiphy)
  1180. {
  1181. return __ieee80211_resume(wiphy_priv(wiphy));
  1182. }
  1183. #else
  1184. #define ieee80211_suspend NULL
  1185. #define ieee80211_resume NULL
  1186. #endif
  1187. static int ieee80211_scan(struct wiphy *wiphy,
  1188. struct net_device *dev,
  1189. struct cfg80211_scan_request *req)
  1190. {
  1191. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1192. switch (ieee80211_vif_type_p2p(&sdata->vif)) {
  1193. case NL80211_IFTYPE_STATION:
  1194. case NL80211_IFTYPE_ADHOC:
  1195. case NL80211_IFTYPE_MESH_POINT:
  1196. case NL80211_IFTYPE_P2P_CLIENT:
  1197. break;
  1198. case NL80211_IFTYPE_P2P_GO:
  1199. if (sdata->local->ops->hw_scan)
  1200. break;
  1201. /*
  1202. * FIXME: implement NoA while scanning in software,
  1203. * for now fall through to allow scanning only when
  1204. * beaconing hasn't been configured yet
  1205. */
  1206. case NL80211_IFTYPE_AP:
  1207. if (sdata->u.ap.beacon)
  1208. return -EOPNOTSUPP;
  1209. break;
  1210. default:
  1211. return -EOPNOTSUPP;
  1212. }
  1213. return ieee80211_request_scan(sdata, req);
  1214. }
  1215. static int
  1216. ieee80211_sched_scan_start(struct wiphy *wiphy,
  1217. struct net_device *dev,
  1218. struct cfg80211_sched_scan_request *req)
  1219. {
  1220. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1221. if (!sdata->local->ops->sched_scan_start)
  1222. return -EOPNOTSUPP;
  1223. return ieee80211_request_sched_scan_start(sdata, req);
  1224. }
  1225. static int
  1226. ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
  1227. {
  1228. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1229. if (!sdata->local->ops->sched_scan_stop)
  1230. return -EOPNOTSUPP;
  1231. return ieee80211_request_sched_scan_stop(sdata);
  1232. }
  1233. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  1234. struct cfg80211_auth_request *req)
  1235. {
  1236. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1237. }
  1238. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  1239. struct cfg80211_assoc_request *req)
  1240. {
  1241. struct ieee80211_local *local = wiphy_priv(wiphy);
  1242. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1243. switch (ieee80211_get_channel_mode(local, sdata)) {
  1244. case CHAN_MODE_HOPPING:
  1245. return -EBUSY;
  1246. case CHAN_MODE_FIXED:
  1247. if (local->oper_channel == req->bss->channel)
  1248. break;
  1249. return -EBUSY;
  1250. case CHAN_MODE_UNDEFINED:
  1251. break;
  1252. }
  1253. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1254. }
  1255. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1256. struct cfg80211_deauth_request *req,
  1257. void *cookie)
  1258. {
  1259. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
  1260. req, cookie);
  1261. }
  1262. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1263. struct cfg80211_disassoc_request *req,
  1264. void *cookie)
  1265. {
  1266. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
  1267. req, cookie);
  1268. }
  1269. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1270. struct cfg80211_ibss_params *params)
  1271. {
  1272. struct ieee80211_local *local = wiphy_priv(wiphy);
  1273. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1274. switch (ieee80211_get_channel_mode(local, sdata)) {
  1275. case CHAN_MODE_HOPPING:
  1276. return -EBUSY;
  1277. case CHAN_MODE_FIXED:
  1278. if (!params->channel_fixed)
  1279. return -EBUSY;
  1280. if (local->oper_channel == params->channel)
  1281. break;
  1282. return -EBUSY;
  1283. case CHAN_MODE_UNDEFINED:
  1284. break;
  1285. }
  1286. return ieee80211_ibss_join(sdata, params);
  1287. }
  1288. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1289. {
  1290. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1291. return ieee80211_ibss_leave(sdata);
  1292. }
  1293. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1294. {
  1295. struct ieee80211_local *local = wiphy_priv(wiphy);
  1296. int err;
  1297. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  1298. err = drv_set_frag_threshold(local, wiphy->frag_threshold);
  1299. if (err)
  1300. return err;
  1301. }
  1302. if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
  1303. err = drv_set_coverage_class(local, wiphy->coverage_class);
  1304. if (err)
  1305. return err;
  1306. }
  1307. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1308. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1309. if (err)
  1310. return err;
  1311. }
  1312. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1313. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1314. if (changed & WIPHY_PARAM_RETRY_LONG)
  1315. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1316. if (changed &
  1317. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1318. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1319. return 0;
  1320. }
  1321. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1322. enum nl80211_tx_power_setting type, int mbm)
  1323. {
  1324. struct ieee80211_local *local = wiphy_priv(wiphy);
  1325. struct ieee80211_channel *chan = local->hw.conf.channel;
  1326. u32 changes = 0;
  1327. switch (type) {
  1328. case NL80211_TX_POWER_AUTOMATIC:
  1329. local->user_power_level = -1;
  1330. break;
  1331. case NL80211_TX_POWER_LIMITED:
  1332. if (mbm < 0 || (mbm % 100))
  1333. return -EOPNOTSUPP;
  1334. local->user_power_level = MBM_TO_DBM(mbm);
  1335. break;
  1336. case NL80211_TX_POWER_FIXED:
  1337. if (mbm < 0 || (mbm % 100))
  1338. return -EOPNOTSUPP;
  1339. /* TODO: move to cfg80211 when it knows the channel */
  1340. if (MBM_TO_DBM(mbm) > chan->max_power)
  1341. return -EINVAL;
  1342. local->user_power_level = MBM_TO_DBM(mbm);
  1343. break;
  1344. }
  1345. ieee80211_hw_config(local, changes);
  1346. return 0;
  1347. }
  1348. static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
  1349. {
  1350. struct ieee80211_local *local = wiphy_priv(wiphy);
  1351. *dbm = local->hw.conf.power_level;
  1352. return 0;
  1353. }
  1354. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  1355. const u8 *addr)
  1356. {
  1357. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1358. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  1359. return 0;
  1360. }
  1361. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1362. {
  1363. struct ieee80211_local *local = wiphy_priv(wiphy);
  1364. drv_rfkill_poll(local);
  1365. }
  1366. #ifdef CONFIG_NL80211_TESTMODE
  1367. static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
  1368. {
  1369. struct ieee80211_local *local = wiphy_priv(wiphy);
  1370. if (!local->ops->testmode_cmd)
  1371. return -EOPNOTSUPP;
  1372. return local->ops->testmode_cmd(&local->hw, data, len);
  1373. }
  1374. static int ieee80211_testmode_dump(struct wiphy *wiphy,
  1375. struct sk_buff *skb,
  1376. struct netlink_callback *cb,
  1377. void *data, int len)
  1378. {
  1379. struct ieee80211_local *local = wiphy_priv(wiphy);
  1380. if (!local->ops->testmode_dump)
  1381. return -EOPNOTSUPP;
  1382. return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
  1383. }
  1384. #endif
  1385. int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
  1386. enum ieee80211_smps_mode smps_mode)
  1387. {
  1388. const u8 *ap;
  1389. enum ieee80211_smps_mode old_req;
  1390. int err;
  1391. lockdep_assert_held(&sdata->u.mgd.mtx);
  1392. old_req = sdata->u.mgd.req_smps;
  1393. sdata->u.mgd.req_smps = smps_mode;
  1394. if (old_req == smps_mode &&
  1395. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  1396. return 0;
  1397. /*
  1398. * If not associated, or current association is not an HT
  1399. * association, there's no need to send an action frame.
  1400. */
  1401. if (!sdata->u.mgd.associated ||
  1402. sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
  1403. mutex_lock(&sdata->local->iflist_mtx);
  1404. ieee80211_recalc_smps(sdata->local);
  1405. mutex_unlock(&sdata->local->iflist_mtx);
  1406. return 0;
  1407. }
  1408. ap = sdata->u.mgd.associated->bssid;
  1409. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  1410. if (sdata->u.mgd.powersave)
  1411. smps_mode = IEEE80211_SMPS_DYNAMIC;
  1412. else
  1413. smps_mode = IEEE80211_SMPS_OFF;
  1414. }
  1415. /* send SM PS frame to AP */
  1416. err = ieee80211_send_smps_action(sdata, smps_mode,
  1417. ap, ap);
  1418. if (err)
  1419. sdata->u.mgd.req_smps = old_req;
  1420. return err;
  1421. }
  1422. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1423. bool enabled, int timeout)
  1424. {
  1425. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1426. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1427. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1428. return -EOPNOTSUPP;
  1429. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  1430. return -EOPNOTSUPP;
  1431. if (enabled == sdata->u.mgd.powersave &&
  1432. timeout == local->dynamic_ps_forced_timeout)
  1433. return 0;
  1434. sdata->u.mgd.powersave = enabled;
  1435. local->dynamic_ps_forced_timeout = timeout;
  1436. /* no change, but if automatic follow powersave */
  1437. mutex_lock(&sdata->u.mgd.mtx);
  1438. __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
  1439. mutex_unlock(&sdata->u.mgd.mtx);
  1440. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  1441. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1442. ieee80211_recalc_ps(local, -1);
  1443. return 0;
  1444. }
  1445. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  1446. struct net_device *dev,
  1447. s32 rssi_thold, u32 rssi_hyst)
  1448. {
  1449. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1450. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1451. struct ieee80211_vif *vif = &sdata->vif;
  1452. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1453. if (rssi_thold == bss_conf->cqm_rssi_thold &&
  1454. rssi_hyst == bss_conf->cqm_rssi_hyst)
  1455. return 0;
  1456. bss_conf->cqm_rssi_thold = rssi_thold;
  1457. bss_conf->cqm_rssi_hyst = rssi_hyst;
  1458. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
  1459. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1460. return -EOPNOTSUPP;
  1461. return 0;
  1462. }
  1463. /* tell the driver upon association, unless already associated */
  1464. if (sdata->u.mgd.associated)
  1465. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  1466. return 0;
  1467. }
  1468. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  1469. struct net_device *dev,
  1470. const u8 *addr,
  1471. const struct cfg80211_bitrate_mask *mask)
  1472. {
  1473. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1474. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1475. int i, ret;
  1476. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
  1477. ret = drv_set_bitrate_mask(local, sdata, mask);
  1478. if (ret)
  1479. return ret;
  1480. }
  1481. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  1482. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  1483. return 0;
  1484. }
  1485. static int ieee80211_remain_on_channel_hw(struct ieee80211_local *local,
  1486. struct net_device *dev,
  1487. struct ieee80211_channel *chan,
  1488. enum nl80211_channel_type chantype,
  1489. unsigned int duration, u64 *cookie)
  1490. {
  1491. int ret;
  1492. u32 random_cookie;
  1493. lockdep_assert_held(&local->mtx);
  1494. if (local->hw_roc_cookie)
  1495. return -EBUSY;
  1496. /* must be nonzero */
  1497. random_cookie = random32() | 1;
  1498. *cookie = random_cookie;
  1499. local->hw_roc_dev = dev;
  1500. local->hw_roc_cookie = random_cookie;
  1501. local->hw_roc_channel = chan;
  1502. local->hw_roc_channel_type = chantype;
  1503. local->hw_roc_duration = duration;
  1504. ret = drv_remain_on_channel(local, chan, chantype, duration);
  1505. if (ret) {
  1506. local->hw_roc_channel = NULL;
  1507. local->hw_roc_cookie = 0;
  1508. }
  1509. return ret;
  1510. }
  1511. static int ieee80211_remain_on_channel(struct wiphy *wiphy,
  1512. struct net_device *dev,
  1513. struct ieee80211_channel *chan,
  1514. enum nl80211_channel_type channel_type,
  1515. unsigned int duration,
  1516. u64 *cookie)
  1517. {
  1518. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1519. struct ieee80211_local *local = sdata->local;
  1520. if (local->ops->remain_on_channel) {
  1521. int ret;
  1522. mutex_lock(&local->mtx);
  1523. ret = ieee80211_remain_on_channel_hw(local, dev,
  1524. chan, channel_type,
  1525. duration, cookie);
  1526. local->hw_roc_for_tx = false;
  1527. mutex_unlock(&local->mtx);
  1528. return ret;
  1529. }
  1530. return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
  1531. duration, cookie);
  1532. }
  1533. static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local *local,
  1534. u64 cookie)
  1535. {
  1536. int ret;
  1537. lockdep_assert_held(&local->mtx);
  1538. if (local->hw_roc_cookie != cookie)
  1539. return -ENOENT;
  1540. ret = drv_cancel_remain_on_channel(local);
  1541. if (ret)
  1542. return ret;
  1543. local->hw_roc_cookie = 0;
  1544. local->hw_roc_channel = NULL;
  1545. ieee80211_recalc_idle(local);
  1546. return 0;
  1547. }
  1548. static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
  1549. struct net_device *dev,
  1550. u64 cookie)
  1551. {
  1552. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1553. struct ieee80211_local *local = sdata->local;
  1554. if (local->ops->cancel_remain_on_channel) {
  1555. int ret;
  1556. mutex_lock(&local->mtx);
  1557. ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
  1558. mutex_unlock(&local->mtx);
  1559. return ret;
  1560. }
  1561. return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
  1562. }
  1563. static enum work_done_result
  1564. ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
  1565. {
  1566. /*
  1567. * Use the data embedded in the work struct for reporting
  1568. * here so if the driver mangled the SKB before dropping
  1569. * it (which is the only way we really should get here)
  1570. * then we don't report mangled data.
  1571. *
  1572. * If there was no wait time, then by the time we get here
  1573. * the driver will likely not have reported the status yet,
  1574. * so in that case userspace will have to deal with it.
  1575. */
  1576. if (wk->offchan_tx.wait && !wk->offchan_tx.status)
  1577. cfg80211_mgmt_tx_status(wk->sdata->dev,
  1578. (unsigned long) wk->offchan_tx.frame,
  1579. wk->ie, wk->ie_len, false, GFP_KERNEL);
  1580. return WORK_DONE_DESTROY;
  1581. }
  1582. static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
  1583. struct ieee80211_channel *chan, bool offchan,
  1584. enum nl80211_channel_type channel_type,
  1585. bool channel_type_valid, unsigned int wait,
  1586. const u8 *buf, size_t len, bool no_cck,
  1587. u64 *cookie)
  1588. {
  1589. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1590. struct ieee80211_local *local = sdata->local;
  1591. struct sk_buff *skb;
  1592. struct sta_info *sta;
  1593. struct ieee80211_work *wk;
  1594. const struct ieee80211_mgmt *mgmt = (void *)buf;
  1595. u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
  1596. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1597. bool is_offchan = false;
  1598. /* Check that we are on the requested channel for transmission */
  1599. if (chan != local->tmp_channel &&
  1600. chan != local->oper_channel)
  1601. is_offchan = true;
  1602. if (channel_type_valid &&
  1603. (channel_type != local->tmp_channel_type &&
  1604. channel_type != local->_oper_channel_type))
  1605. is_offchan = true;
  1606. if (chan == local->hw_roc_channel) {
  1607. /* TODO: check channel type? */
  1608. is_offchan = false;
  1609. flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
  1610. }
  1611. if (no_cck)
  1612. flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
  1613. if (is_offchan && !offchan)
  1614. return -EBUSY;
  1615. switch (sdata->vif.type) {
  1616. case NL80211_IFTYPE_ADHOC:
  1617. case NL80211_IFTYPE_AP:
  1618. case NL80211_IFTYPE_AP_VLAN:
  1619. case NL80211_IFTYPE_P2P_GO:
  1620. case NL80211_IFTYPE_MESH_POINT:
  1621. if (!ieee80211_is_action(mgmt->frame_control) ||
  1622. mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
  1623. break;
  1624. rcu_read_lock();
  1625. sta = sta_info_get(sdata, mgmt->da);
  1626. rcu_read_unlock();
  1627. if (!sta)
  1628. return -ENOLINK;
  1629. break;
  1630. case NL80211_IFTYPE_STATION:
  1631. case NL80211_IFTYPE_P2P_CLIENT:
  1632. break;
  1633. default:
  1634. return -EOPNOTSUPP;
  1635. }
  1636. skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
  1637. if (!skb)
  1638. return -ENOMEM;
  1639. skb_reserve(skb, local->hw.extra_tx_headroom);
  1640. memcpy(skb_put(skb, len), buf, len);
  1641. IEEE80211_SKB_CB(skb)->flags = flags;
  1642. skb->dev = sdata->dev;
  1643. *cookie = (unsigned long) skb;
  1644. if (is_offchan && local->ops->remain_on_channel) {
  1645. unsigned int duration;
  1646. int ret;
  1647. mutex_lock(&local->mtx);
  1648. /*
  1649. * If the duration is zero, then the driver
  1650. * wouldn't actually do anything. Set it to
  1651. * 100 for now.
  1652. *
  1653. * TODO: cancel the off-channel operation
  1654. * when we get the SKB's TX status and
  1655. * the wait time was zero before.
  1656. */
  1657. duration = 100;
  1658. if (wait)
  1659. duration = wait;
  1660. ret = ieee80211_remain_on_channel_hw(local, dev, chan,
  1661. channel_type,
  1662. duration, cookie);
  1663. if (ret) {
  1664. kfree_skb(skb);
  1665. mutex_unlock(&local->mtx);
  1666. return ret;
  1667. }
  1668. local->hw_roc_for_tx = true;
  1669. local->hw_roc_duration = wait;
  1670. /*
  1671. * queue up frame for transmission after
  1672. * ieee80211_ready_on_channel call
  1673. */
  1674. /* modify cookie to prevent API mismatches */
  1675. *cookie ^= 2;
  1676. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
  1677. local->hw_roc_skb = skb;
  1678. local->hw_roc_skb_for_status = skb;
  1679. mutex_unlock(&local->mtx);
  1680. return 0;
  1681. }
  1682. /*
  1683. * Can transmit right away if the channel was the
  1684. * right one and there's no wait involved... If a
  1685. * wait is involved, we might otherwise not be on
  1686. * the right channel for long enough!
  1687. */
  1688. if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
  1689. ieee80211_tx_skb(sdata, skb);
  1690. return 0;
  1691. }
  1692. wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL);
  1693. if (!wk) {
  1694. kfree_skb(skb);
  1695. return -ENOMEM;
  1696. }
  1697. wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
  1698. wk->chan = chan;
  1699. wk->chan_type = channel_type;
  1700. wk->sdata = sdata;
  1701. wk->done = ieee80211_offchan_tx_done;
  1702. wk->offchan_tx.frame = skb;
  1703. wk->offchan_tx.wait = wait;
  1704. wk->ie_len = len;
  1705. memcpy(wk->ie, buf, len);
  1706. ieee80211_add_work(wk);
  1707. return 0;
  1708. }
  1709. static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
  1710. struct net_device *dev,
  1711. u64 cookie)
  1712. {
  1713. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1714. struct ieee80211_local *local = sdata->local;
  1715. struct ieee80211_work *wk;
  1716. int ret = -ENOENT;
  1717. mutex_lock(&local->mtx);
  1718. if (local->ops->cancel_remain_on_channel) {
  1719. cookie ^= 2;
  1720. ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
  1721. if (ret == 0) {
  1722. kfree_skb(local->hw_roc_skb);
  1723. local->hw_roc_skb = NULL;
  1724. local->hw_roc_skb_for_status = NULL;
  1725. }
  1726. mutex_unlock(&local->mtx);
  1727. return ret;
  1728. }
  1729. list_for_each_entry(wk, &local->work_list, list) {
  1730. if (wk->sdata != sdata)
  1731. continue;
  1732. if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
  1733. continue;
  1734. if (cookie != (unsigned long) wk->offchan_tx.frame)
  1735. continue;
  1736. wk->timeout = jiffies;
  1737. ieee80211_queue_work(&local->hw, &local->work_work);
  1738. ret = 0;
  1739. break;
  1740. }
  1741. mutex_unlock(&local->mtx);
  1742. return ret;
  1743. }
  1744. static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
  1745. struct net_device *dev,
  1746. u16 frame_type, bool reg)
  1747. {
  1748. struct ieee80211_local *local = wiphy_priv(wiphy);
  1749. if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
  1750. return;
  1751. if (reg)
  1752. local->probe_req_reg++;
  1753. else
  1754. local->probe_req_reg--;
  1755. ieee80211_queue_work(&local->hw, &local->reconfig_filter);
  1756. }
  1757. static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  1758. {
  1759. struct ieee80211_local *local = wiphy_priv(wiphy);
  1760. if (local->started)
  1761. return -EOPNOTSUPP;
  1762. return drv_set_antenna(local, tx_ant, rx_ant);
  1763. }
  1764. static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
  1765. {
  1766. struct ieee80211_local *local = wiphy_priv(wiphy);
  1767. return drv_get_antenna(local, tx_ant, rx_ant);
  1768. }
  1769. static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
  1770. {
  1771. struct ieee80211_local *local = wiphy_priv(wiphy);
  1772. return drv_set_ringparam(local, tx, rx);
  1773. }
  1774. static void ieee80211_get_ringparam(struct wiphy *wiphy,
  1775. u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
  1776. {
  1777. struct ieee80211_local *local = wiphy_priv(wiphy);
  1778. drv_get_ringparam(local, tx, tx_max, rx, rx_max);
  1779. }
  1780. static int ieee80211_set_rekey_data(struct wiphy *wiphy,
  1781. struct net_device *dev,
  1782. struct cfg80211_gtk_rekey_data *data)
  1783. {
  1784. struct ieee80211_local *local = wiphy_priv(wiphy);
  1785. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1786. if (!local->ops->set_rekey_data)
  1787. return -EOPNOTSUPP;
  1788. drv_set_rekey_data(local, sdata, data);
  1789. return 0;
  1790. }
  1791. static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
  1792. {
  1793. u8 *pos = (void *)skb_put(skb, 7);
  1794. *pos++ = WLAN_EID_EXT_CAPABILITY;
  1795. *pos++ = 5; /* len */
  1796. *pos++ = 0x0;
  1797. *pos++ = 0x0;
  1798. *pos++ = 0x0;
  1799. *pos++ = 0x0;
  1800. *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
  1801. }
  1802. static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
  1803. {
  1804. struct ieee80211_local *local = sdata->local;
  1805. u16 capab;
  1806. capab = 0;
  1807. if (local->oper_channel->band != IEEE80211_BAND_2GHZ)
  1808. return capab;
  1809. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
  1810. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  1811. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
  1812. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  1813. return capab;
  1814. }
  1815. static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
  1816. u8 *peer, u8 *bssid)
  1817. {
  1818. struct ieee80211_tdls_lnkie *lnkid;
  1819. lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
  1820. lnkid->ie_type = WLAN_EID_LINK_ID;
  1821. lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
  1822. memcpy(lnkid->bssid, bssid, ETH_ALEN);
  1823. memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
  1824. memcpy(lnkid->resp_sta, peer, ETH_ALEN);
  1825. }
  1826. static int
  1827. ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
  1828. u8 *peer, u8 action_code, u8 dialog_token,
  1829. u16 status_code, struct sk_buff *skb)
  1830. {
  1831. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1832. struct ieee80211_tdls_data *tf;
  1833. tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
  1834. memcpy(tf->da, peer, ETH_ALEN);
  1835. memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
  1836. tf->ether_type = cpu_to_be16(ETH_P_TDLS);
  1837. tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
  1838. switch (action_code) {
  1839. case WLAN_TDLS_SETUP_REQUEST:
  1840. tf->category = WLAN_CATEGORY_TDLS;
  1841. tf->action_code = WLAN_TDLS_SETUP_REQUEST;
  1842. skb_put(skb, sizeof(tf->u.setup_req));
  1843. tf->u.setup_req.dialog_token = dialog_token;
  1844. tf->u.setup_req.capability =
  1845. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  1846. ieee80211_add_srates_ie(&sdata->vif, skb);
  1847. ieee80211_add_ext_srates_ie(&sdata->vif, skb);
  1848. ieee80211_tdls_add_ext_capab(skb);
  1849. break;
  1850. case WLAN_TDLS_SETUP_RESPONSE:
  1851. tf->category = WLAN_CATEGORY_TDLS;
  1852. tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
  1853. skb_put(skb, sizeof(tf->u.setup_resp));
  1854. tf->u.setup_resp.status_code = cpu_to_le16(status_code);
  1855. tf->u.setup_resp.dialog_token = dialog_token;
  1856. tf->u.setup_resp.capability =
  1857. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  1858. ieee80211_add_srates_ie(&sdata->vif, skb);
  1859. ieee80211_add_ext_srates_ie(&sdata->vif, skb);
  1860. ieee80211_tdls_add_ext_capab(skb);
  1861. break;
  1862. case WLAN_TDLS_SETUP_CONFIRM:
  1863. tf->category = WLAN_CATEGORY_TDLS;
  1864. tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
  1865. skb_put(skb, sizeof(tf->u.setup_cfm));
  1866. tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
  1867. tf->u.setup_cfm.dialog_token = dialog_token;
  1868. break;
  1869. case WLAN_TDLS_TEARDOWN:
  1870. tf->category = WLAN_CATEGORY_TDLS;
  1871. tf->action_code = WLAN_TDLS_TEARDOWN;
  1872. skb_put(skb, sizeof(tf->u.teardown));
  1873. tf->u.teardown.reason_code = cpu_to_le16(status_code);
  1874. break;
  1875. case WLAN_TDLS_DISCOVERY_REQUEST:
  1876. tf->category = WLAN_CATEGORY_TDLS;
  1877. tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
  1878. skb_put(skb, sizeof(tf->u.discover_req));
  1879. tf->u.discover_req.dialog_token = dialog_token;
  1880. break;
  1881. default:
  1882. return -EINVAL;
  1883. }
  1884. return 0;
  1885. }
  1886. static int
  1887. ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
  1888. u8 *peer, u8 action_code, u8 dialog_token,
  1889. u16 status_code, struct sk_buff *skb)
  1890. {
  1891. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1892. struct ieee80211_mgmt *mgmt;
  1893. mgmt = (void *)skb_put(skb, 24);
  1894. memset(mgmt, 0, 24);
  1895. memcpy(mgmt->da, peer, ETH_ALEN);
  1896. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  1897. memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
  1898. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1899. IEEE80211_STYPE_ACTION);
  1900. switch (action_code) {
  1901. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  1902. skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
  1903. mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
  1904. mgmt->u.action.u.tdls_discover_resp.action_code =
  1905. WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
  1906. mgmt->u.action.u.tdls_discover_resp.dialog_token =
  1907. dialog_token;
  1908. mgmt->u.action.u.tdls_discover_resp.capability =
  1909. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  1910. ieee80211_add_srates_ie(&sdata->vif, skb);
  1911. ieee80211_add_ext_srates_ie(&sdata->vif, skb);
  1912. ieee80211_tdls_add_ext_capab(skb);
  1913. break;
  1914. default:
  1915. return -EINVAL;
  1916. }
  1917. return 0;
  1918. }
  1919. static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1920. u8 *peer, u8 action_code, u8 dialog_token,
  1921. u16 status_code, const u8 *extra_ies,
  1922. size_t extra_ies_len)
  1923. {
  1924. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1925. struct ieee80211_local *local = sdata->local;
  1926. struct ieee80211_tx_info *info;
  1927. struct sk_buff *skb = NULL;
  1928. bool send_direct;
  1929. int ret;
  1930. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
  1931. return -ENOTSUPP;
  1932. /* make sure we are in managed mode, and associated */
  1933. if (sdata->vif.type != NL80211_IFTYPE_STATION ||
  1934. !sdata->u.mgd.associated)
  1935. return -EINVAL;
  1936. #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
  1937. printk(KERN_DEBUG "TDLS mgmt action %d peer %pM\n", action_code, peer);
  1938. #endif
  1939. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  1940. max(sizeof(struct ieee80211_mgmt),
  1941. sizeof(struct ieee80211_tdls_data)) +
  1942. 50 + /* supported rates */
  1943. 7 + /* ext capab */
  1944. extra_ies_len +
  1945. sizeof(struct ieee80211_tdls_lnkie));
  1946. if (!skb)
  1947. return -ENOMEM;
  1948. info = IEEE80211_SKB_CB(skb);
  1949. skb_reserve(skb, local->hw.extra_tx_headroom);
  1950. switch (action_code) {
  1951. case WLAN_TDLS_SETUP_REQUEST:
  1952. case WLAN_TDLS_SETUP_RESPONSE:
  1953. case WLAN_TDLS_SETUP_CONFIRM:
  1954. case WLAN_TDLS_TEARDOWN:
  1955. case WLAN_TDLS_DISCOVERY_REQUEST:
  1956. ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
  1957. action_code, dialog_token,
  1958. status_code, skb);
  1959. send_direct = false;
  1960. break;
  1961. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  1962. ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
  1963. dialog_token, status_code,
  1964. skb);
  1965. send_direct = true;
  1966. break;
  1967. default:
  1968. ret = -ENOTSUPP;
  1969. break;
  1970. }
  1971. if (ret < 0)
  1972. goto fail;
  1973. if (extra_ies_len)
  1974. memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
  1975. /* the TDLS link IE is always added last */
  1976. switch (action_code) {
  1977. case WLAN_TDLS_SETUP_REQUEST:
  1978. case WLAN_TDLS_SETUP_CONFIRM:
  1979. case WLAN_TDLS_TEARDOWN:
  1980. case WLAN_TDLS_DISCOVERY_REQUEST:
  1981. /* we are the initiator */
  1982. ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
  1983. sdata->u.mgd.bssid);
  1984. break;
  1985. case WLAN_TDLS_SETUP_RESPONSE:
  1986. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  1987. /* we are the responder */
  1988. ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
  1989. sdata->u.mgd.bssid);
  1990. break;
  1991. default:
  1992. ret = -ENOTSUPP;
  1993. goto fail;
  1994. }
  1995. if (send_direct) {
  1996. ieee80211_tx_skb(sdata, skb);
  1997. return 0;
  1998. }
  1999. /*
  2000. * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
  2001. * we should default to AC_VI.
  2002. */
  2003. switch (action_code) {
  2004. case WLAN_TDLS_SETUP_REQUEST:
  2005. case WLAN_TDLS_SETUP_RESPONSE:
  2006. skb_set_queue_mapping(skb, IEEE80211_AC_BK);
  2007. skb->priority = 2;
  2008. break;
  2009. default:
  2010. skb_set_queue_mapping(skb, IEEE80211_AC_VI);
  2011. skb->priority = 5;
  2012. break;
  2013. }
  2014. /* disable bottom halves when entering the Tx path */
  2015. local_bh_disable();
  2016. ret = ieee80211_subif_start_xmit(skb, dev);
  2017. local_bh_enable();
  2018. return ret;
  2019. fail:
  2020. dev_kfree_skb(skb);
  2021. return ret;
  2022. }
  2023. static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
  2024. u8 *peer, enum nl80211_tdls_operation oper)
  2025. {
  2026. struct sta_info *sta;
  2027. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2028. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
  2029. return -ENOTSUPP;
  2030. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2031. return -EINVAL;
  2032. #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
  2033. printk(KERN_DEBUG "TDLS oper %d peer %pM\n", oper, peer);
  2034. #endif
  2035. switch (oper) {
  2036. case NL80211_TDLS_ENABLE_LINK:
  2037. rcu_read_lock();
  2038. sta = sta_info_get(sdata, peer);
  2039. if (!sta) {
  2040. rcu_read_unlock();
  2041. return -ENOLINK;
  2042. }
  2043. set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
  2044. rcu_read_unlock();
  2045. break;
  2046. case NL80211_TDLS_DISABLE_LINK:
  2047. return sta_info_destroy_addr(sdata, peer);
  2048. case NL80211_TDLS_TEARDOWN:
  2049. case NL80211_TDLS_SETUP:
  2050. case NL80211_TDLS_DISCOVERY_REQ:
  2051. /* We don't support in-driver setup/teardown/discovery */
  2052. return -ENOTSUPP;
  2053. default:
  2054. return -ENOTSUPP;
  2055. }
  2056. return 0;
  2057. }
  2058. static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
  2059. const u8 *peer, u64 *cookie)
  2060. {
  2061. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2062. struct ieee80211_local *local = sdata->local;
  2063. struct ieee80211_qos_hdr *nullfunc;
  2064. struct sk_buff *skb;
  2065. int size = sizeof(*nullfunc);
  2066. __le16 fc;
  2067. bool qos;
  2068. struct ieee80211_tx_info *info;
  2069. struct sta_info *sta;
  2070. rcu_read_lock();
  2071. sta = sta_info_get(sdata, peer);
  2072. if (sta)
  2073. qos = test_sta_flag(sta, WLAN_STA_WME);
  2074. rcu_read_unlock();
  2075. if (!sta)
  2076. return -ENOLINK;
  2077. if (qos) {
  2078. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  2079. IEEE80211_STYPE_QOS_NULLFUNC |
  2080. IEEE80211_FCTL_FROMDS);
  2081. } else {
  2082. size -= 2;
  2083. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  2084. IEEE80211_STYPE_NULLFUNC |
  2085. IEEE80211_FCTL_FROMDS);
  2086. }
  2087. skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
  2088. if (!skb)
  2089. return -ENOMEM;
  2090. skb->dev = dev;
  2091. skb_reserve(skb, local->hw.extra_tx_headroom);
  2092. nullfunc = (void *) skb_put(skb, size);
  2093. nullfunc->frame_control = fc;
  2094. nullfunc->duration_id = 0;
  2095. memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
  2096. memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
  2097. memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
  2098. nullfunc->seq_ctrl = 0;
  2099. info = IEEE80211_SKB_CB(skb);
  2100. info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
  2101. IEEE80211_TX_INTFL_NL80211_FRAME_TX;
  2102. skb_set_queue_mapping(skb, IEEE80211_AC_VO);
  2103. skb->priority = 7;
  2104. if (qos)
  2105. nullfunc->qos_ctrl = cpu_to_le16(7);
  2106. local_bh_disable();
  2107. ieee80211_xmit(sdata, skb);
  2108. local_bh_enable();
  2109. *cookie = (unsigned long) skb;
  2110. return 0;
  2111. }
  2112. struct cfg80211_ops mac80211_config_ops = {
  2113. .add_virtual_intf = ieee80211_add_iface,
  2114. .del_virtual_intf = ieee80211_del_iface,
  2115. .change_virtual_intf = ieee80211_change_iface,
  2116. .add_key = ieee80211_add_key,
  2117. .del_key = ieee80211_del_key,
  2118. .get_key = ieee80211_get_key,
  2119. .set_default_key = ieee80211_config_default_key,
  2120. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  2121. .add_beacon = ieee80211_add_beacon,
  2122. .set_beacon = ieee80211_set_beacon,
  2123. .del_beacon = ieee80211_del_beacon,
  2124. .add_station = ieee80211_add_station,
  2125. .del_station = ieee80211_del_station,
  2126. .change_station = ieee80211_change_station,
  2127. .get_station = ieee80211_get_station,
  2128. .dump_station = ieee80211_dump_station,
  2129. .dump_survey = ieee80211_dump_survey,
  2130. #ifdef CONFIG_MAC80211_MESH
  2131. .add_mpath = ieee80211_add_mpath,
  2132. .del_mpath = ieee80211_del_mpath,
  2133. .change_mpath = ieee80211_change_mpath,
  2134. .get_mpath = ieee80211_get_mpath,
  2135. .dump_mpath = ieee80211_dump_mpath,
  2136. .update_mesh_config = ieee80211_update_mesh_config,
  2137. .get_mesh_config = ieee80211_get_mesh_config,
  2138. .join_mesh = ieee80211_join_mesh,
  2139. .leave_mesh = ieee80211_leave_mesh,
  2140. #endif
  2141. .change_bss = ieee80211_change_bss,
  2142. .set_txq_params = ieee80211_set_txq_params,
  2143. .set_channel = ieee80211_set_channel,
  2144. .suspend = ieee80211_suspend,
  2145. .resume = ieee80211_resume,
  2146. .scan = ieee80211_scan,
  2147. .sched_scan_start = ieee80211_sched_scan_start,
  2148. .sched_scan_stop = ieee80211_sched_scan_stop,
  2149. .auth = ieee80211_auth,
  2150. .assoc = ieee80211_assoc,
  2151. .deauth = ieee80211_deauth,
  2152. .disassoc = ieee80211_disassoc,
  2153. .join_ibss = ieee80211_join_ibss,
  2154. .leave_ibss = ieee80211_leave_ibss,
  2155. .set_wiphy_params = ieee80211_set_wiphy_params,
  2156. .set_tx_power = ieee80211_set_tx_power,
  2157. .get_tx_power = ieee80211_get_tx_power,
  2158. .set_wds_peer = ieee80211_set_wds_peer,
  2159. .rfkill_poll = ieee80211_rfkill_poll,
  2160. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  2161. CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
  2162. .set_power_mgmt = ieee80211_set_power_mgmt,
  2163. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  2164. .remain_on_channel = ieee80211_remain_on_channel,
  2165. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  2166. .mgmt_tx = ieee80211_mgmt_tx,
  2167. .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
  2168. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  2169. .mgmt_frame_register = ieee80211_mgmt_frame_register,
  2170. .set_antenna = ieee80211_set_antenna,
  2171. .get_antenna = ieee80211_get_antenna,
  2172. .set_ringparam = ieee80211_set_ringparam,
  2173. .get_ringparam = ieee80211_get_ringparam,
  2174. .set_rekey_data = ieee80211_set_rekey_data,
  2175. .tdls_oper = ieee80211_tdls_oper,
  2176. .tdls_mgmt = ieee80211_tdls_mgmt,
  2177. .probe_client = ieee80211_probe_client,
  2178. };