cfg.c 69 KB

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