cfg.c 70 KB

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