cfg.c 70 KB

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