cfg.c 71 KB

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