cfg.c 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718
  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_NET_DIAM_TRVS_TIME,
  1047. mask))
  1048. conf->dot11MeshHWMPnetDiameterTraversalTime =
  1049. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  1050. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  1051. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  1052. ieee80211_mesh_root_setup(ifmsh);
  1053. }
  1054. if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
  1055. /* our current gate announcement implementation rides on root
  1056. * announcements, so require this ifmsh to also be a root node
  1057. * */
  1058. if (nconf->dot11MeshGateAnnouncementProtocol &&
  1059. !conf->dot11MeshHWMPRootMode) {
  1060. conf->dot11MeshHWMPRootMode = 1;
  1061. ieee80211_mesh_root_setup(ifmsh);
  1062. }
  1063. conf->dot11MeshGateAnnouncementProtocol =
  1064. nconf->dot11MeshGateAnnouncementProtocol;
  1065. }
  1066. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask)) {
  1067. conf->dot11MeshHWMPRannInterval =
  1068. nconf->dot11MeshHWMPRannInterval;
  1069. }
  1070. return 0;
  1071. }
  1072. static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
  1073. const struct mesh_config *conf,
  1074. const struct mesh_setup *setup)
  1075. {
  1076. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1077. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1078. int err;
  1079. memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
  1080. err = copy_mesh_setup(ifmsh, setup);
  1081. if (err)
  1082. return err;
  1083. ieee80211_start_mesh(sdata);
  1084. return 0;
  1085. }
  1086. static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
  1087. {
  1088. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1089. ieee80211_stop_mesh(sdata);
  1090. return 0;
  1091. }
  1092. #endif
  1093. static int ieee80211_change_bss(struct wiphy *wiphy,
  1094. struct net_device *dev,
  1095. struct bss_parameters *params)
  1096. {
  1097. struct ieee80211_sub_if_data *sdata;
  1098. u32 changed = 0;
  1099. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1100. if (params->use_cts_prot >= 0) {
  1101. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  1102. changed |= BSS_CHANGED_ERP_CTS_PROT;
  1103. }
  1104. if (params->use_short_preamble >= 0) {
  1105. sdata->vif.bss_conf.use_short_preamble =
  1106. params->use_short_preamble;
  1107. changed |= BSS_CHANGED_ERP_PREAMBLE;
  1108. }
  1109. if (!sdata->vif.bss_conf.use_short_slot &&
  1110. sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
  1111. sdata->vif.bss_conf.use_short_slot = true;
  1112. changed |= BSS_CHANGED_ERP_SLOT;
  1113. }
  1114. if (params->use_short_slot_time >= 0) {
  1115. sdata->vif.bss_conf.use_short_slot =
  1116. params->use_short_slot_time;
  1117. changed |= BSS_CHANGED_ERP_SLOT;
  1118. }
  1119. if (params->basic_rates) {
  1120. int i, j;
  1121. u32 rates = 0;
  1122. struct ieee80211_local *local = wiphy_priv(wiphy);
  1123. struct ieee80211_supported_band *sband =
  1124. wiphy->bands[local->oper_channel->band];
  1125. for (i = 0; i < params->basic_rates_len; i++) {
  1126. int rate = (params->basic_rates[i] & 0x7f) * 5;
  1127. for (j = 0; j < sband->n_bitrates; j++) {
  1128. if (sband->bitrates[j].bitrate == rate)
  1129. rates |= BIT(j);
  1130. }
  1131. }
  1132. sdata->vif.bss_conf.basic_rates = rates;
  1133. changed |= BSS_CHANGED_BASIC_RATES;
  1134. }
  1135. if (params->ap_isolate >= 0) {
  1136. if (params->ap_isolate)
  1137. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1138. else
  1139. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1140. }
  1141. if (params->ht_opmode >= 0) {
  1142. sdata->vif.bss_conf.ht_operation_mode =
  1143. (u16) params->ht_opmode;
  1144. changed |= BSS_CHANGED_HT;
  1145. }
  1146. ieee80211_bss_info_change_notify(sdata, changed);
  1147. return 0;
  1148. }
  1149. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  1150. struct net_device *dev,
  1151. struct ieee80211_txq_params *params)
  1152. {
  1153. struct ieee80211_local *local = wiphy_priv(wiphy);
  1154. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1155. struct ieee80211_tx_queue_params p;
  1156. if (!local->ops->conf_tx)
  1157. return -EOPNOTSUPP;
  1158. memset(&p, 0, sizeof(p));
  1159. p.aifs = params->aifs;
  1160. p.cw_max = params->cwmax;
  1161. p.cw_min = params->cwmin;
  1162. p.txop = params->txop;
  1163. /*
  1164. * Setting tx queue params disables u-apsd because it's only
  1165. * called in master mode.
  1166. */
  1167. p.uapsd = false;
  1168. if (params->queue >= local->hw.queues)
  1169. return -EINVAL;
  1170. sdata->tx_conf[params->queue] = p;
  1171. if (drv_conf_tx(local, sdata, params->queue, &p)) {
  1172. wiphy_debug(local->hw.wiphy,
  1173. "failed to set TX queue parameters for queue %d\n",
  1174. params->queue);
  1175. return -EINVAL;
  1176. }
  1177. return 0;
  1178. }
  1179. static int ieee80211_set_channel(struct wiphy *wiphy,
  1180. struct net_device *netdev,
  1181. struct ieee80211_channel *chan,
  1182. enum nl80211_channel_type channel_type)
  1183. {
  1184. struct ieee80211_local *local = wiphy_priv(wiphy);
  1185. struct ieee80211_sub_if_data *sdata = NULL;
  1186. struct ieee80211_channel *old_oper;
  1187. enum nl80211_channel_type old_oper_type;
  1188. enum nl80211_channel_type old_vif_oper_type= NL80211_CHAN_NO_HT;
  1189. if (netdev)
  1190. sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
  1191. switch (ieee80211_get_channel_mode(local, NULL)) {
  1192. case CHAN_MODE_HOPPING:
  1193. return -EBUSY;
  1194. case CHAN_MODE_FIXED:
  1195. if (local->oper_channel != chan)
  1196. return -EBUSY;
  1197. if (!sdata && local->_oper_channel_type == channel_type)
  1198. return 0;
  1199. break;
  1200. case CHAN_MODE_UNDEFINED:
  1201. break;
  1202. }
  1203. if (sdata)
  1204. old_vif_oper_type = sdata->vif.bss_conf.channel_type;
  1205. old_oper_type = local->_oper_channel_type;
  1206. if (!ieee80211_set_channel_type(local, sdata, channel_type))
  1207. return -EBUSY;
  1208. old_oper = local->oper_channel;
  1209. local->oper_channel = chan;
  1210. /* Update driver if changes were actually made. */
  1211. if ((old_oper != local->oper_channel) ||
  1212. (old_oper_type != local->_oper_channel_type))
  1213. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  1214. if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR &&
  1215. old_vif_oper_type != sdata->vif.bss_conf.channel_type)
  1216. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
  1217. return 0;
  1218. }
  1219. #ifdef CONFIG_PM
  1220. static int ieee80211_suspend(struct wiphy *wiphy,
  1221. struct cfg80211_wowlan *wowlan)
  1222. {
  1223. return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
  1224. }
  1225. static int ieee80211_resume(struct wiphy *wiphy)
  1226. {
  1227. return __ieee80211_resume(wiphy_priv(wiphy));
  1228. }
  1229. #else
  1230. #define ieee80211_suspend NULL
  1231. #define ieee80211_resume NULL
  1232. #endif
  1233. static int ieee80211_scan(struct wiphy *wiphy,
  1234. struct net_device *dev,
  1235. struct cfg80211_scan_request *req)
  1236. {
  1237. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1238. switch (ieee80211_vif_type_p2p(&sdata->vif)) {
  1239. case NL80211_IFTYPE_STATION:
  1240. case NL80211_IFTYPE_ADHOC:
  1241. case NL80211_IFTYPE_MESH_POINT:
  1242. case NL80211_IFTYPE_P2P_CLIENT:
  1243. break;
  1244. case NL80211_IFTYPE_P2P_GO:
  1245. if (sdata->local->ops->hw_scan)
  1246. break;
  1247. /*
  1248. * FIXME: implement NoA while scanning in software,
  1249. * for now fall through to allow scanning only when
  1250. * beaconing hasn't been configured yet
  1251. */
  1252. case NL80211_IFTYPE_AP:
  1253. if (sdata->u.ap.beacon)
  1254. return -EOPNOTSUPP;
  1255. break;
  1256. default:
  1257. return -EOPNOTSUPP;
  1258. }
  1259. return ieee80211_request_scan(sdata, req);
  1260. }
  1261. static int
  1262. ieee80211_sched_scan_start(struct wiphy *wiphy,
  1263. struct net_device *dev,
  1264. struct cfg80211_sched_scan_request *req)
  1265. {
  1266. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1267. if (!sdata->local->ops->sched_scan_start)
  1268. return -EOPNOTSUPP;
  1269. return ieee80211_request_sched_scan_start(sdata, req);
  1270. }
  1271. static int
  1272. ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
  1273. {
  1274. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1275. if (!sdata->local->ops->sched_scan_stop)
  1276. return -EOPNOTSUPP;
  1277. return ieee80211_request_sched_scan_stop(sdata);
  1278. }
  1279. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  1280. struct cfg80211_auth_request *req)
  1281. {
  1282. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1283. }
  1284. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  1285. struct cfg80211_assoc_request *req)
  1286. {
  1287. struct ieee80211_local *local = wiphy_priv(wiphy);
  1288. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1289. switch (ieee80211_get_channel_mode(local, sdata)) {
  1290. case CHAN_MODE_HOPPING:
  1291. return -EBUSY;
  1292. case CHAN_MODE_FIXED:
  1293. if (local->oper_channel == req->bss->channel)
  1294. break;
  1295. return -EBUSY;
  1296. case CHAN_MODE_UNDEFINED:
  1297. break;
  1298. }
  1299. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1300. }
  1301. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1302. struct cfg80211_deauth_request *req,
  1303. void *cookie)
  1304. {
  1305. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
  1306. req, cookie);
  1307. }
  1308. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1309. struct cfg80211_disassoc_request *req,
  1310. void *cookie)
  1311. {
  1312. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
  1313. req, cookie);
  1314. }
  1315. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1316. struct cfg80211_ibss_params *params)
  1317. {
  1318. struct ieee80211_local *local = wiphy_priv(wiphy);
  1319. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1320. switch (ieee80211_get_channel_mode(local, sdata)) {
  1321. case CHAN_MODE_HOPPING:
  1322. return -EBUSY;
  1323. case CHAN_MODE_FIXED:
  1324. if (!params->channel_fixed)
  1325. return -EBUSY;
  1326. if (local->oper_channel == params->channel)
  1327. break;
  1328. return -EBUSY;
  1329. case CHAN_MODE_UNDEFINED:
  1330. break;
  1331. }
  1332. return ieee80211_ibss_join(sdata, params);
  1333. }
  1334. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1335. {
  1336. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1337. return ieee80211_ibss_leave(sdata);
  1338. }
  1339. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1340. {
  1341. struct ieee80211_local *local = wiphy_priv(wiphy);
  1342. int err;
  1343. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  1344. err = drv_set_frag_threshold(local, wiphy->frag_threshold);
  1345. if (err)
  1346. return err;
  1347. }
  1348. if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
  1349. err = drv_set_coverage_class(local, wiphy->coverage_class);
  1350. if (err)
  1351. return err;
  1352. }
  1353. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1354. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1355. if (err)
  1356. return err;
  1357. }
  1358. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1359. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1360. if (changed & WIPHY_PARAM_RETRY_LONG)
  1361. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1362. if (changed &
  1363. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1364. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1365. return 0;
  1366. }
  1367. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1368. enum nl80211_tx_power_setting type, int mbm)
  1369. {
  1370. struct ieee80211_local *local = wiphy_priv(wiphy);
  1371. struct ieee80211_channel *chan = local->hw.conf.channel;
  1372. u32 changes = 0;
  1373. switch (type) {
  1374. case NL80211_TX_POWER_AUTOMATIC:
  1375. local->user_power_level = -1;
  1376. break;
  1377. case NL80211_TX_POWER_LIMITED:
  1378. if (mbm < 0 || (mbm % 100))
  1379. return -EOPNOTSUPP;
  1380. local->user_power_level = MBM_TO_DBM(mbm);
  1381. break;
  1382. case NL80211_TX_POWER_FIXED:
  1383. if (mbm < 0 || (mbm % 100))
  1384. return -EOPNOTSUPP;
  1385. /* TODO: move to cfg80211 when it knows the channel */
  1386. if (MBM_TO_DBM(mbm) > chan->max_power)
  1387. return -EINVAL;
  1388. local->user_power_level = MBM_TO_DBM(mbm);
  1389. break;
  1390. }
  1391. ieee80211_hw_config(local, changes);
  1392. return 0;
  1393. }
  1394. static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
  1395. {
  1396. struct ieee80211_local *local = wiphy_priv(wiphy);
  1397. *dbm = local->hw.conf.power_level;
  1398. return 0;
  1399. }
  1400. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  1401. const u8 *addr)
  1402. {
  1403. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1404. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  1405. return 0;
  1406. }
  1407. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1408. {
  1409. struct ieee80211_local *local = wiphy_priv(wiphy);
  1410. drv_rfkill_poll(local);
  1411. }
  1412. #ifdef CONFIG_NL80211_TESTMODE
  1413. static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
  1414. {
  1415. struct ieee80211_local *local = wiphy_priv(wiphy);
  1416. if (!local->ops->testmode_cmd)
  1417. return -EOPNOTSUPP;
  1418. return local->ops->testmode_cmd(&local->hw, data, len);
  1419. }
  1420. static int ieee80211_testmode_dump(struct wiphy *wiphy,
  1421. struct sk_buff *skb,
  1422. struct netlink_callback *cb,
  1423. void *data, int len)
  1424. {
  1425. struct ieee80211_local *local = wiphy_priv(wiphy);
  1426. if (!local->ops->testmode_dump)
  1427. return -EOPNOTSUPP;
  1428. return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
  1429. }
  1430. #endif
  1431. int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
  1432. enum ieee80211_smps_mode smps_mode)
  1433. {
  1434. const u8 *ap;
  1435. enum ieee80211_smps_mode old_req;
  1436. int err;
  1437. lockdep_assert_held(&sdata->u.mgd.mtx);
  1438. old_req = sdata->u.mgd.req_smps;
  1439. sdata->u.mgd.req_smps = smps_mode;
  1440. if (old_req == smps_mode &&
  1441. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  1442. return 0;
  1443. /*
  1444. * If not associated, or current association is not an HT
  1445. * association, there's no need to send an action frame.
  1446. */
  1447. if (!sdata->u.mgd.associated ||
  1448. sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
  1449. mutex_lock(&sdata->local->iflist_mtx);
  1450. ieee80211_recalc_smps(sdata->local);
  1451. mutex_unlock(&sdata->local->iflist_mtx);
  1452. return 0;
  1453. }
  1454. ap = sdata->u.mgd.associated->bssid;
  1455. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  1456. if (sdata->u.mgd.powersave)
  1457. smps_mode = IEEE80211_SMPS_DYNAMIC;
  1458. else
  1459. smps_mode = IEEE80211_SMPS_OFF;
  1460. }
  1461. /* send SM PS frame to AP */
  1462. err = ieee80211_send_smps_action(sdata, smps_mode,
  1463. ap, ap);
  1464. if (err)
  1465. sdata->u.mgd.req_smps = old_req;
  1466. return err;
  1467. }
  1468. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1469. bool enabled, int timeout)
  1470. {
  1471. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1472. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1473. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1474. return -EOPNOTSUPP;
  1475. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  1476. return -EOPNOTSUPP;
  1477. if (enabled == sdata->u.mgd.powersave &&
  1478. timeout == local->dynamic_ps_forced_timeout)
  1479. return 0;
  1480. sdata->u.mgd.powersave = enabled;
  1481. local->dynamic_ps_forced_timeout = timeout;
  1482. /* no change, but if automatic follow powersave */
  1483. mutex_lock(&sdata->u.mgd.mtx);
  1484. __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
  1485. mutex_unlock(&sdata->u.mgd.mtx);
  1486. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  1487. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1488. ieee80211_recalc_ps(local, -1);
  1489. return 0;
  1490. }
  1491. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  1492. struct net_device *dev,
  1493. s32 rssi_thold, u32 rssi_hyst)
  1494. {
  1495. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1496. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1497. struct ieee80211_vif *vif = &sdata->vif;
  1498. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1499. if (rssi_thold == bss_conf->cqm_rssi_thold &&
  1500. rssi_hyst == bss_conf->cqm_rssi_hyst)
  1501. return 0;
  1502. bss_conf->cqm_rssi_thold = rssi_thold;
  1503. bss_conf->cqm_rssi_hyst = rssi_hyst;
  1504. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
  1505. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1506. return -EOPNOTSUPP;
  1507. return 0;
  1508. }
  1509. /* tell the driver upon association, unless already associated */
  1510. if (sdata->u.mgd.associated)
  1511. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  1512. return 0;
  1513. }
  1514. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  1515. struct net_device *dev,
  1516. const u8 *addr,
  1517. const struct cfg80211_bitrate_mask *mask)
  1518. {
  1519. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1520. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1521. int i, ret;
  1522. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
  1523. ret = drv_set_bitrate_mask(local, sdata, mask);
  1524. if (ret)
  1525. return ret;
  1526. }
  1527. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  1528. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  1529. return 0;
  1530. }
  1531. static int ieee80211_remain_on_channel_hw(struct ieee80211_local *local,
  1532. struct net_device *dev,
  1533. struct ieee80211_channel *chan,
  1534. enum nl80211_channel_type chantype,
  1535. unsigned int duration, u64 *cookie)
  1536. {
  1537. int ret;
  1538. u32 random_cookie;
  1539. lockdep_assert_held(&local->mtx);
  1540. if (local->hw_roc_cookie)
  1541. return -EBUSY;
  1542. /* must be nonzero */
  1543. random_cookie = random32() | 1;
  1544. *cookie = random_cookie;
  1545. local->hw_roc_dev = dev;
  1546. local->hw_roc_cookie = random_cookie;
  1547. local->hw_roc_channel = chan;
  1548. local->hw_roc_channel_type = chantype;
  1549. local->hw_roc_duration = duration;
  1550. ret = drv_remain_on_channel(local, chan, chantype, duration);
  1551. if (ret) {
  1552. local->hw_roc_channel = NULL;
  1553. local->hw_roc_cookie = 0;
  1554. }
  1555. return ret;
  1556. }
  1557. static int ieee80211_remain_on_channel(struct wiphy *wiphy,
  1558. struct net_device *dev,
  1559. struct ieee80211_channel *chan,
  1560. enum nl80211_channel_type channel_type,
  1561. unsigned int duration,
  1562. u64 *cookie)
  1563. {
  1564. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1565. struct ieee80211_local *local = sdata->local;
  1566. if (local->ops->remain_on_channel) {
  1567. int ret;
  1568. mutex_lock(&local->mtx);
  1569. ret = ieee80211_remain_on_channel_hw(local, dev,
  1570. chan, channel_type,
  1571. duration, cookie);
  1572. local->hw_roc_for_tx = false;
  1573. mutex_unlock(&local->mtx);
  1574. return ret;
  1575. }
  1576. return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
  1577. duration, cookie);
  1578. }
  1579. static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local *local,
  1580. u64 cookie)
  1581. {
  1582. int ret;
  1583. lockdep_assert_held(&local->mtx);
  1584. if (local->hw_roc_cookie != cookie)
  1585. return -ENOENT;
  1586. ret = drv_cancel_remain_on_channel(local);
  1587. if (ret)
  1588. return ret;
  1589. local->hw_roc_cookie = 0;
  1590. local->hw_roc_channel = NULL;
  1591. ieee80211_recalc_idle(local);
  1592. return 0;
  1593. }
  1594. static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
  1595. struct net_device *dev,
  1596. u64 cookie)
  1597. {
  1598. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1599. struct ieee80211_local *local = sdata->local;
  1600. if (local->ops->cancel_remain_on_channel) {
  1601. int ret;
  1602. mutex_lock(&local->mtx);
  1603. ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
  1604. mutex_unlock(&local->mtx);
  1605. return ret;
  1606. }
  1607. return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
  1608. }
  1609. static enum work_done_result
  1610. ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
  1611. {
  1612. /*
  1613. * Use the data embedded in the work struct for reporting
  1614. * here so if the driver mangled the SKB before dropping
  1615. * it (which is the only way we really should get here)
  1616. * then we don't report mangled data.
  1617. *
  1618. * If there was no wait time, then by the time we get here
  1619. * the driver will likely not have reported the status yet,
  1620. * so in that case userspace will have to deal with it.
  1621. */
  1622. if (wk->offchan_tx.wait && !wk->offchan_tx.status)
  1623. cfg80211_mgmt_tx_status(wk->sdata->dev,
  1624. (unsigned long) wk->offchan_tx.frame,
  1625. wk->ie, wk->ie_len, false, GFP_KERNEL);
  1626. return WORK_DONE_DESTROY;
  1627. }
  1628. static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
  1629. struct ieee80211_channel *chan, bool offchan,
  1630. enum nl80211_channel_type channel_type,
  1631. bool channel_type_valid, unsigned int wait,
  1632. const u8 *buf, size_t len, bool no_cck,
  1633. bool dont_wait_for_ack, u64 *cookie)
  1634. {
  1635. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1636. struct ieee80211_local *local = sdata->local;
  1637. struct sk_buff *skb;
  1638. struct sta_info *sta;
  1639. struct ieee80211_work *wk;
  1640. const struct ieee80211_mgmt *mgmt = (void *)buf;
  1641. u32 flags;
  1642. bool is_offchan = false;
  1643. if (dont_wait_for_ack)
  1644. flags = IEEE80211_TX_CTL_NO_ACK;
  1645. else
  1646. flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
  1647. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1648. /* Check that we are on the requested channel for transmission */
  1649. if (chan != local->tmp_channel &&
  1650. chan != local->oper_channel)
  1651. is_offchan = true;
  1652. if (channel_type_valid &&
  1653. (channel_type != local->tmp_channel_type &&
  1654. channel_type != local->_oper_channel_type))
  1655. is_offchan = true;
  1656. if (chan == local->hw_roc_channel) {
  1657. /* TODO: check channel type? */
  1658. is_offchan = false;
  1659. flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
  1660. }
  1661. if (no_cck)
  1662. flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
  1663. if (is_offchan && !offchan)
  1664. return -EBUSY;
  1665. switch (sdata->vif.type) {
  1666. case NL80211_IFTYPE_ADHOC:
  1667. case NL80211_IFTYPE_AP:
  1668. case NL80211_IFTYPE_AP_VLAN:
  1669. case NL80211_IFTYPE_P2P_GO:
  1670. case NL80211_IFTYPE_MESH_POINT:
  1671. if (!ieee80211_is_action(mgmt->frame_control) ||
  1672. mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
  1673. break;
  1674. rcu_read_lock();
  1675. sta = sta_info_get(sdata, mgmt->da);
  1676. rcu_read_unlock();
  1677. if (!sta)
  1678. return -ENOLINK;
  1679. break;
  1680. case NL80211_IFTYPE_STATION:
  1681. case NL80211_IFTYPE_P2P_CLIENT:
  1682. break;
  1683. default:
  1684. return -EOPNOTSUPP;
  1685. }
  1686. skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
  1687. if (!skb)
  1688. return -ENOMEM;
  1689. skb_reserve(skb, local->hw.extra_tx_headroom);
  1690. memcpy(skb_put(skb, len), buf, len);
  1691. IEEE80211_SKB_CB(skb)->flags = flags;
  1692. skb->dev = sdata->dev;
  1693. *cookie = (unsigned long) skb;
  1694. if (is_offchan && local->ops->remain_on_channel) {
  1695. unsigned int duration;
  1696. int ret;
  1697. mutex_lock(&local->mtx);
  1698. /*
  1699. * If the duration is zero, then the driver
  1700. * wouldn't actually do anything. Set it to
  1701. * 100 for now.
  1702. *
  1703. * TODO: cancel the off-channel operation
  1704. * when we get the SKB's TX status and
  1705. * the wait time was zero before.
  1706. */
  1707. duration = 100;
  1708. if (wait)
  1709. duration = wait;
  1710. ret = ieee80211_remain_on_channel_hw(local, dev, chan,
  1711. channel_type,
  1712. duration, cookie);
  1713. if (ret) {
  1714. kfree_skb(skb);
  1715. mutex_unlock(&local->mtx);
  1716. return ret;
  1717. }
  1718. local->hw_roc_for_tx = true;
  1719. local->hw_roc_duration = wait;
  1720. /*
  1721. * queue up frame for transmission after
  1722. * ieee80211_ready_on_channel call
  1723. */
  1724. /* modify cookie to prevent API mismatches */
  1725. *cookie ^= 2;
  1726. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
  1727. local->hw_roc_skb = skb;
  1728. local->hw_roc_skb_for_status = skb;
  1729. mutex_unlock(&local->mtx);
  1730. return 0;
  1731. }
  1732. /*
  1733. * Can transmit right away if the channel was the
  1734. * right one and there's no wait involved... If a
  1735. * wait is involved, we might otherwise not be on
  1736. * the right channel for long enough!
  1737. */
  1738. if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
  1739. ieee80211_tx_skb(sdata, skb);
  1740. return 0;
  1741. }
  1742. wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL);
  1743. if (!wk) {
  1744. kfree_skb(skb);
  1745. return -ENOMEM;
  1746. }
  1747. wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
  1748. wk->chan = chan;
  1749. wk->chan_type = channel_type;
  1750. wk->sdata = sdata;
  1751. wk->done = ieee80211_offchan_tx_done;
  1752. wk->offchan_tx.frame = skb;
  1753. wk->offchan_tx.wait = wait;
  1754. wk->ie_len = len;
  1755. memcpy(wk->ie, buf, len);
  1756. ieee80211_add_work(wk);
  1757. return 0;
  1758. }
  1759. static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
  1760. struct net_device *dev,
  1761. u64 cookie)
  1762. {
  1763. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1764. struct ieee80211_local *local = sdata->local;
  1765. struct ieee80211_work *wk;
  1766. int ret = -ENOENT;
  1767. mutex_lock(&local->mtx);
  1768. if (local->ops->cancel_remain_on_channel) {
  1769. cookie ^= 2;
  1770. ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
  1771. if (ret == 0) {
  1772. kfree_skb(local->hw_roc_skb);
  1773. local->hw_roc_skb = NULL;
  1774. local->hw_roc_skb_for_status = NULL;
  1775. }
  1776. mutex_unlock(&local->mtx);
  1777. return ret;
  1778. }
  1779. list_for_each_entry(wk, &local->work_list, list) {
  1780. if (wk->sdata != sdata)
  1781. continue;
  1782. if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
  1783. continue;
  1784. if (cookie != (unsigned long) wk->offchan_tx.frame)
  1785. continue;
  1786. wk->timeout = jiffies;
  1787. ieee80211_queue_work(&local->hw, &local->work_work);
  1788. ret = 0;
  1789. break;
  1790. }
  1791. mutex_unlock(&local->mtx);
  1792. return ret;
  1793. }
  1794. static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
  1795. struct net_device *dev,
  1796. u16 frame_type, bool reg)
  1797. {
  1798. struct ieee80211_local *local = wiphy_priv(wiphy);
  1799. if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
  1800. return;
  1801. if (reg)
  1802. local->probe_req_reg++;
  1803. else
  1804. local->probe_req_reg--;
  1805. ieee80211_queue_work(&local->hw, &local->reconfig_filter);
  1806. }
  1807. static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  1808. {
  1809. struct ieee80211_local *local = wiphy_priv(wiphy);
  1810. if (local->started)
  1811. return -EOPNOTSUPP;
  1812. return drv_set_antenna(local, tx_ant, rx_ant);
  1813. }
  1814. static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
  1815. {
  1816. struct ieee80211_local *local = wiphy_priv(wiphy);
  1817. return drv_get_antenna(local, tx_ant, rx_ant);
  1818. }
  1819. static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
  1820. {
  1821. struct ieee80211_local *local = wiphy_priv(wiphy);
  1822. return drv_set_ringparam(local, tx, rx);
  1823. }
  1824. static void ieee80211_get_ringparam(struct wiphy *wiphy,
  1825. u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
  1826. {
  1827. struct ieee80211_local *local = wiphy_priv(wiphy);
  1828. drv_get_ringparam(local, tx, tx_max, rx, rx_max);
  1829. }
  1830. static int ieee80211_set_rekey_data(struct wiphy *wiphy,
  1831. struct net_device *dev,
  1832. struct cfg80211_gtk_rekey_data *data)
  1833. {
  1834. struct ieee80211_local *local = wiphy_priv(wiphy);
  1835. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1836. if (!local->ops->set_rekey_data)
  1837. return -EOPNOTSUPP;
  1838. drv_set_rekey_data(local, sdata, data);
  1839. return 0;
  1840. }
  1841. static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
  1842. {
  1843. u8 *pos = (void *)skb_put(skb, 7);
  1844. *pos++ = WLAN_EID_EXT_CAPABILITY;
  1845. *pos++ = 5; /* len */
  1846. *pos++ = 0x0;
  1847. *pos++ = 0x0;
  1848. *pos++ = 0x0;
  1849. *pos++ = 0x0;
  1850. *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
  1851. }
  1852. static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
  1853. {
  1854. struct ieee80211_local *local = sdata->local;
  1855. u16 capab;
  1856. capab = 0;
  1857. if (local->oper_channel->band != IEEE80211_BAND_2GHZ)
  1858. return capab;
  1859. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
  1860. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  1861. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
  1862. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  1863. return capab;
  1864. }
  1865. static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
  1866. u8 *peer, u8 *bssid)
  1867. {
  1868. struct ieee80211_tdls_lnkie *lnkid;
  1869. lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
  1870. lnkid->ie_type = WLAN_EID_LINK_ID;
  1871. lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
  1872. memcpy(lnkid->bssid, bssid, ETH_ALEN);
  1873. memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
  1874. memcpy(lnkid->resp_sta, peer, ETH_ALEN);
  1875. }
  1876. static int
  1877. ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
  1878. u8 *peer, u8 action_code, u8 dialog_token,
  1879. u16 status_code, struct sk_buff *skb)
  1880. {
  1881. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1882. struct ieee80211_tdls_data *tf;
  1883. tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
  1884. memcpy(tf->da, peer, ETH_ALEN);
  1885. memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
  1886. tf->ether_type = cpu_to_be16(ETH_P_TDLS);
  1887. tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
  1888. switch (action_code) {
  1889. case WLAN_TDLS_SETUP_REQUEST:
  1890. tf->category = WLAN_CATEGORY_TDLS;
  1891. tf->action_code = WLAN_TDLS_SETUP_REQUEST;
  1892. skb_put(skb, sizeof(tf->u.setup_req));
  1893. tf->u.setup_req.dialog_token = dialog_token;
  1894. tf->u.setup_req.capability =
  1895. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  1896. ieee80211_add_srates_ie(&sdata->vif, skb);
  1897. ieee80211_add_ext_srates_ie(&sdata->vif, skb);
  1898. ieee80211_tdls_add_ext_capab(skb);
  1899. break;
  1900. case WLAN_TDLS_SETUP_RESPONSE:
  1901. tf->category = WLAN_CATEGORY_TDLS;
  1902. tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
  1903. skb_put(skb, sizeof(tf->u.setup_resp));
  1904. tf->u.setup_resp.status_code = cpu_to_le16(status_code);
  1905. tf->u.setup_resp.dialog_token = dialog_token;
  1906. tf->u.setup_resp.capability =
  1907. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  1908. ieee80211_add_srates_ie(&sdata->vif, skb);
  1909. ieee80211_add_ext_srates_ie(&sdata->vif, skb);
  1910. ieee80211_tdls_add_ext_capab(skb);
  1911. break;
  1912. case WLAN_TDLS_SETUP_CONFIRM:
  1913. tf->category = WLAN_CATEGORY_TDLS;
  1914. tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
  1915. skb_put(skb, sizeof(tf->u.setup_cfm));
  1916. tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
  1917. tf->u.setup_cfm.dialog_token = dialog_token;
  1918. break;
  1919. case WLAN_TDLS_TEARDOWN:
  1920. tf->category = WLAN_CATEGORY_TDLS;
  1921. tf->action_code = WLAN_TDLS_TEARDOWN;
  1922. skb_put(skb, sizeof(tf->u.teardown));
  1923. tf->u.teardown.reason_code = cpu_to_le16(status_code);
  1924. break;
  1925. case WLAN_TDLS_DISCOVERY_REQUEST:
  1926. tf->category = WLAN_CATEGORY_TDLS;
  1927. tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
  1928. skb_put(skb, sizeof(tf->u.discover_req));
  1929. tf->u.discover_req.dialog_token = dialog_token;
  1930. break;
  1931. default:
  1932. return -EINVAL;
  1933. }
  1934. return 0;
  1935. }
  1936. static int
  1937. ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
  1938. u8 *peer, u8 action_code, u8 dialog_token,
  1939. u16 status_code, struct sk_buff *skb)
  1940. {
  1941. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1942. struct ieee80211_mgmt *mgmt;
  1943. mgmt = (void *)skb_put(skb, 24);
  1944. memset(mgmt, 0, 24);
  1945. memcpy(mgmt->da, peer, ETH_ALEN);
  1946. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  1947. memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
  1948. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1949. IEEE80211_STYPE_ACTION);
  1950. switch (action_code) {
  1951. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  1952. skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
  1953. mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
  1954. mgmt->u.action.u.tdls_discover_resp.action_code =
  1955. WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
  1956. mgmt->u.action.u.tdls_discover_resp.dialog_token =
  1957. dialog_token;
  1958. mgmt->u.action.u.tdls_discover_resp.capability =
  1959. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  1960. ieee80211_add_srates_ie(&sdata->vif, skb);
  1961. ieee80211_add_ext_srates_ie(&sdata->vif, skb);
  1962. ieee80211_tdls_add_ext_capab(skb);
  1963. break;
  1964. default:
  1965. return -EINVAL;
  1966. }
  1967. return 0;
  1968. }
  1969. static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1970. u8 *peer, u8 action_code, u8 dialog_token,
  1971. u16 status_code, const u8 *extra_ies,
  1972. size_t extra_ies_len)
  1973. {
  1974. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1975. struct ieee80211_local *local = sdata->local;
  1976. struct ieee80211_tx_info *info;
  1977. struct sk_buff *skb = NULL;
  1978. bool send_direct;
  1979. int ret;
  1980. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
  1981. return -ENOTSUPP;
  1982. /* make sure we are in managed mode, and associated */
  1983. if (sdata->vif.type != NL80211_IFTYPE_STATION ||
  1984. !sdata->u.mgd.associated)
  1985. return -EINVAL;
  1986. #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
  1987. printk(KERN_DEBUG "TDLS mgmt action %d peer %pM\n", action_code, peer);
  1988. #endif
  1989. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  1990. max(sizeof(struct ieee80211_mgmt),
  1991. sizeof(struct ieee80211_tdls_data)) +
  1992. 50 + /* supported rates */
  1993. 7 + /* ext capab */
  1994. extra_ies_len +
  1995. sizeof(struct ieee80211_tdls_lnkie));
  1996. if (!skb)
  1997. return -ENOMEM;
  1998. info = IEEE80211_SKB_CB(skb);
  1999. skb_reserve(skb, local->hw.extra_tx_headroom);
  2000. switch (action_code) {
  2001. case WLAN_TDLS_SETUP_REQUEST:
  2002. case WLAN_TDLS_SETUP_RESPONSE:
  2003. case WLAN_TDLS_SETUP_CONFIRM:
  2004. case WLAN_TDLS_TEARDOWN:
  2005. case WLAN_TDLS_DISCOVERY_REQUEST:
  2006. ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
  2007. action_code, dialog_token,
  2008. status_code, skb);
  2009. send_direct = false;
  2010. break;
  2011. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  2012. ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
  2013. dialog_token, status_code,
  2014. skb);
  2015. send_direct = true;
  2016. break;
  2017. default:
  2018. ret = -ENOTSUPP;
  2019. break;
  2020. }
  2021. if (ret < 0)
  2022. goto fail;
  2023. if (extra_ies_len)
  2024. memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
  2025. /* the TDLS link IE is always added last */
  2026. switch (action_code) {
  2027. case WLAN_TDLS_SETUP_REQUEST:
  2028. case WLAN_TDLS_SETUP_CONFIRM:
  2029. case WLAN_TDLS_TEARDOWN:
  2030. case WLAN_TDLS_DISCOVERY_REQUEST:
  2031. /* we are the initiator */
  2032. ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
  2033. sdata->u.mgd.bssid);
  2034. break;
  2035. case WLAN_TDLS_SETUP_RESPONSE:
  2036. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  2037. /* we are the responder */
  2038. ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
  2039. sdata->u.mgd.bssid);
  2040. break;
  2041. default:
  2042. ret = -ENOTSUPP;
  2043. goto fail;
  2044. }
  2045. if (send_direct) {
  2046. ieee80211_tx_skb(sdata, skb);
  2047. return 0;
  2048. }
  2049. /*
  2050. * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
  2051. * we should default to AC_VI.
  2052. */
  2053. switch (action_code) {
  2054. case WLAN_TDLS_SETUP_REQUEST:
  2055. case WLAN_TDLS_SETUP_RESPONSE:
  2056. skb_set_queue_mapping(skb, IEEE80211_AC_BK);
  2057. skb->priority = 2;
  2058. break;
  2059. default:
  2060. skb_set_queue_mapping(skb, IEEE80211_AC_VI);
  2061. skb->priority = 5;
  2062. break;
  2063. }
  2064. /* disable bottom halves when entering the Tx path */
  2065. local_bh_disable();
  2066. ret = ieee80211_subif_start_xmit(skb, dev);
  2067. local_bh_enable();
  2068. return ret;
  2069. fail:
  2070. dev_kfree_skb(skb);
  2071. return ret;
  2072. }
  2073. static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
  2074. u8 *peer, enum nl80211_tdls_operation oper)
  2075. {
  2076. struct sta_info *sta;
  2077. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2078. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
  2079. return -ENOTSUPP;
  2080. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2081. return -EINVAL;
  2082. #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
  2083. printk(KERN_DEBUG "TDLS oper %d peer %pM\n", oper, peer);
  2084. #endif
  2085. switch (oper) {
  2086. case NL80211_TDLS_ENABLE_LINK:
  2087. rcu_read_lock();
  2088. sta = sta_info_get(sdata, peer);
  2089. if (!sta) {
  2090. rcu_read_unlock();
  2091. return -ENOLINK;
  2092. }
  2093. set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
  2094. rcu_read_unlock();
  2095. break;
  2096. case NL80211_TDLS_DISABLE_LINK:
  2097. return sta_info_destroy_addr(sdata, peer);
  2098. case NL80211_TDLS_TEARDOWN:
  2099. case NL80211_TDLS_SETUP:
  2100. case NL80211_TDLS_DISCOVERY_REQ:
  2101. /* We don't support in-driver setup/teardown/discovery */
  2102. return -ENOTSUPP;
  2103. default:
  2104. return -ENOTSUPP;
  2105. }
  2106. return 0;
  2107. }
  2108. static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
  2109. const u8 *peer, u64 *cookie)
  2110. {
  2111. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2112. struct ieee80211_local *local = sdata->local;
  2113. struct ieee80211_qos_hdr *nullfunc;
  2114. struct sk_buff *skb;
  2115. int size = sizeof(*nullfunc);
  2116. __le16 fc;
  2117. bool qos;
  2118. struct ieee80211_tx_info *info;
  2119. struct sta_info *sta;
  2120. rcu_read_lock();
  2121. sta = sta_info_get(sdata, peer);
  2122. if (sta) {
  2123. qos = test_sta_flag(sta, WLAN_STA_WME);
  2124. rcu_read_unlock();
  2125. } else {
  2126. rcu_read_unlock();
  2127. return -ENOLINK;
  2128. }
  2129. if (qos) {
  2130. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  2131. IEEE80211_STYPE_QOS_NULLFUNC |
  2132. IEEE80211_FCTL_FROMDS);
  2133. } else {
  2134. size -= 2;
  2135. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  2136. IEEE80211_STYPE_NULLFUNC |
  2137. IEEE80211_FCTL_FROMDS);
  2138. }
  2139. skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
  2140. if (!skb)
  2141. return -ENOMEM;
  2142. skb->dev = dev;
  2143. skb_reserve(skb, local->hw.extra_tx_headroom);
  2144. nullfunc = (void *) skb_put(skb, size);
  2145. nullfunc->frame_control = fc;
  2146. nullfunc->duration_id = 0;
  2147. memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
  2148. memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
  2149. memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
  2150. nullfunc->seq_ctrl = 0;
  2151. info = IEEE80211_SKB_CB(skb);
  2152. info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
  2153. IEEE80211_TX_INTFL_NL80211_FRAME_TX;
  2154. skb_set_queue_mapping(skb, IEEE80211_AC_VO);
  2155. skb->priority = 7;
  2156. if (qos)
  2157. nullfunc->qos_ctrl = cpu_to_le16(7);
  2158. local_bh_disable();
  2159. ieee80211_xmit(sdata, skb);
  2160. local_bh_enable();
  2161. *cookie = (unsigned long) skb;
  2162. return 0;
  2163. }
  2164. static struct ieee80211_channel *
  2165. ieee80211_wiphy_get_channel(struct wiphy *wiphy)
  2166. {
  2167. struct ieee80211_local *local = wiphy_priv(wiphy);
  2168. return local->oper_channel;
  2169. }
  2170. struct cfg80211_ops mac80211_config_ops = {
  2171. .add_virtual_intf = ieee80211_add_iface,
  2172. .del_virtual_intf = ieee80211_del_iface,
  2173. .change_virtual_intf = ieee80211_change_iface,
  2174. .add_key = ieee80211_add_key,
  2175. .del_key = ieee80211_del_key,
  2176. .get_key = ieee80211_get_key,
  2177. .set_default_key = ieee80211_config_default_key,
  2178. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  2179. .add_beacon = ieee80211_add_beacon,
  2180. .set_beacon = ieee80211_set_beacon,
  2181. .del_beacon = ieee80211_del_beacon,
  2182. .add_station = ieee80211_add_station,
  2183. .del_station = ieee80211_del_station,
  2184. .change_station = ieee80211_change_station,
  2185. .get_station = ieee80211_get_station,
  2186. .dump_station = ieee80211_dump_station,
  2187. .dump_survey = ieee80211_dump_survey,
  2188. #ifdef CONFIG_MAC80211_MESH
  2189. .add_mpath = ieee80211_add_mpath,
  2190. .del_mpath = ieee80211_del_mpath,
  2191. .change_mpath = ieee80211_change_mpath,
  2192. .get_mpath = ieee80211_get_mpath,
  2193. .dump_mpath = ieee80211_dump_mpath,
  2194. .update_mesh_config = ieee80211_update_mesh_config,
  2195. .get_mesh_config = ieee80211_get_mesh_config,
  2196. .join_mesh = ieee80211_join_mesh,
  2197. .leave_mesh = ieee80211_leave_mesh,
  2198. #endif
  2199. .change_bss = ieee80211_change_bss,
  2200. .set_txq_params = ieee80211_set_txq_params,
  2201. .set_channel = ieee80211_set_channel,
  2202. .suspend = ieee80211_suspend,
  2203. .resume = ieee80211_resume,
  2204. .scan = ieee80211_scan,
  2205. .sched_scan_start = ieee80211_sched_scan_start,
  2206. .sched_scan_stop = ieee80211_sched_scan_stop,
  2207. .auth = ieee80211_auth,
  2208. .assoc = ieee80211_assoc,
  2209. .deauth = ieee80211_deauth,
  2210. .disassoc = ieee80211_disassoc,
  2211. .join_ibss = ieee80211_join_ibss,
  2212. .leave_ibss = ieee80211_leave_ibss,
  2213. .set_wiphy_params = ieee80211_set_wiphy_params,
  2214. .set_tx_power = ieee80211_set_tx_power,
  2215. .get_tx_power = ieee80211_get_tx_power,
  2216. .set_wds_peer = ieee80211_set_wds_peer,
  2217. .rfkill_poll = ieee80211_rfkill_poll,
  2218. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  2219. CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
  2220. .set_power_mgmt = ieee80211_set_power_mgmt,
  2221. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  2222. .remain_on_channel = ieee80211_remain_on_channel,
  2223. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  2224. .mgmt_tx = ieee80211_mgmt_tx,
  2225. .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
  2226. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  2227. .mgmt_frame_register = ieee80211_mgmt_frame_register,
  2228. .set_antenna = ieee80211_set_antenna,
  2229. .get_antenna = ieee80211_get_antenna,
  2230. .set_ringparam = ieee80211_set_ringparam,
  2231. .get_ringparam = ieee80211_get_ringparam,
  2232. .set_rekey_data = ieee80211_set_rekey_data,
  2233. .tdls_oper = ieee80211_tdls_oper,
  2234. .tdls_mgmt = ieee80211_tdls_mgmt,
  2235. .probe_client = ieee80211_probe_client,
  2236. .get_channel = ieee80211_wiphy_get_channel,
  2237. .set_noack_map = ieee80211_set_noack_map,
  2238. };