cfg.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016
  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 <net/cfg80211.h>
  15. #include "ieee80211_i.h"
  16. #include "driver-ops.h"
  17. #include "cfg.h"
  18. #include "rate.h"
  19. #include "mesh.h"
  20. static struct net_device *ieee80211_add_iface(struct wiphy *wiphy, char *name,
  21. enum nl80211_iftype type,
  22. u32 *flags,
  23. struct vif_params *params)
  24. {
  25. struct ieee80211_local *local = wiphy_priv(wiphy);
  26. struct net_device *dev;
  27. struct ieee80211_sub_if_data *sdata;
  28. int err;
  29. err = ieee80211_if_add(local, name, &dev, type, params);
  30. if (err)
  31. return ERR_PTR(err);
  32. if (type == NL80211_IFTYPE_MONITOR && flags) {
  33. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  34. sdata->u.mntr_flags = *flags;
  35. }
  36. return dev;
  37. }
  38. static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
  39. {
  40. ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
  41. return 0;
  42. }
  43. static int ieee80211_change_iface(struct wiphy *wiphy,
  44. struct net_device *dev,
  45. enum nl80211_iftype type, u32 *flags,
  46. struct vif_params *params)
  47. {
  48. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  49. int ret;
  50. ret = ieee80211_if_change_type(sdata, type);
  51. if (ret)
  52. return ret;
  53. if (type == NL80211_IFTYPE_AP_VLAN &&
  54. params && params->use_4addr == 0)
  55. rcu_assign_pointer(sdata->u.vlan.sta, NULL);
  56. else if (type == NL80211_IFTYPE_STATION &&
  57. params && params->use_4addr >= 0)
  58. sdata->u.mgd.use_4addr = params->use_4addr;
  59. if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
  60. struct ieee80211_local *local = sdata->local;
  61. if (ieee80211_sdata_running(sdata)) {
  62. /*
  63. * Prohibit MONITOR_FLAG_COOK_FRAMES to be
  64. * changed while the interface is up.
  65. * Else we would need to add a lot of cruft
  66. * to update everything:
  67. * cooked_mntrs, monitor and all fif_* counters
  68. * reconfigure hardware
  69. */
  70. if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
  71. (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
  72. return -EBUSY;
  73. ieee80211_adjust_monitor_flags(sdata, -1);
  74. sdata->u.mntr_flags = *flags;
  75. ieee80211_adjust_monitor_flags(sdata, 1);
  76. ieee80211_configure_filter(local);
  77. } else {
  78. /*
  79. * Because the interface is down, ieee80211_do_stop
  80. * and ieee80211_do_open take care of "everything"
  81. * mentioned in the comment above.
  82. */
  83. sdata->u.mntr_flags = *flags;
  84. }
  85. }
  86. return 0;
  87. }
  88. static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
  89. u8 key_idx, bool pairwise, const u8 *mac_addr,
  90. struct key_params *params)
  91. {
  92. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  93. struct sta_info *sta = NULL;
  94. struct ieee80211_key *key;
  95. int err;
  96. if (!ieee80211_sdata_running(sdata))
  97. return -ENETDOWN;
  98. /* reject WEP and TKIP keys if WEP failed to initialize */
  99. switch (params->cipher) {
  100. case WLAN_CIPHER_SUITE_WEP40:
  101. case WLAN_CIPHER_SUITE_TKIP:
  102. case WLAN_CIPHER_SUITE_WEP104:
  103. if (IS_ERR(sdata->local->wep_tx_tfm))
  104. return -EINVAL;
  105. break;
  106. default:
  107. break;
  108. }
  109. key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
  110. params->key, params->seq_len, params->seq);
  111. if (IS_ERR(key))
  112. return PTR_ERR(key);
  113. if (pairwise)
  114. key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
  115. mutex_lock(&sdata->local->sta_mtx);
  116. if (mac_addr) {
  117. sta = sta_info_get_bss(sdata, mac_addr);
  118. if (!sta) {
  119. ieee80211_key_free(sdata->local, key);
  120. err = -ENOENT;
  121. goto out_unlock;
  122. }
  123. }
  124. err = ieee80211_key_link(key, sdata, sta);
  125. if (err)
  126. ieee80211_key_free(sdata->local, key);
  127. out_unlock:
  128. mutex_unlock(&sdata->local->sta_mtx);
  129. return err;
  130. }
  131. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  132. u8 key_idx, bool pairwise, const u8 *mac_addr)
  133. {
  134. struct ieee80211_sub_if_data *sdata;
  135. struct sta_info *sta;
  136. int ret;
  137. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  138. mutex_lock(&sdata->local->sta_mtx);
  139. if (mac_addr) {
  140. ret = -ENOENT;
  141. sta = sta_info_get_bss(sdata, mac_addr);
  142. if (!sta)
  143. goto out_unlock;
  144. if (pairwise) {
  145. if (sta->ptk) {
  146. ieee80211_key_free(sdata->local, sta->ptk);
  147. ret = 0;
  148. }
  149. } else {
  150. if (sta->gtk[key_idx]) {
  151. ieee80211_key_free(sdata->local,
  152. sta->gtk[key_idx]);
  153. ret = 0;
  154. }
  155. }
  156. goto out_unlock;
  157. }
  158. if (!sdata->keys[key_idx]) {
  159. ret = -ENOENT;
  160. goto out_unlock;
  161. }
  162. ieee80211_key_free(sdata->local, sdata->keys[key_idx]);
  163. WARN_ON(sdata->keys[key_idx]);
  164. ret = 0;
  165. out_unlock:
  166. mutex_unlock(&sdata->local->sta_mtx);
  167. return ret;
  168. }
  169. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  170. u8 key_idx, bool pairwise, const u8 *mac_addr,
  171. void *cookie,
  172. void (*callback)(void *cookie,
  173. struct key_params *params))
  174. {
  175. struct ieee80211_sub_if_data *sdata;
  176. struct sta_info *sta = NULL;
  177. u8 seq[6] = {0};
  178. struct key_params params;
  179. struct ieee80211_key *key = NULL;
  180. u32 iv32;
  181. u16 iv16;
  182. int err = -ENOENT;
  183. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  184. rcu_read_lock();
  185. if (mac_addr) {
  186. sta = sta_info_get_bss(sdata, mac_addr);
  187. if (!sta)
  188. goto out;
  189. if (pairwise)
  190. key = sta->ptk;
  191. else if (key_idx < NUM_DEFAULT_KEYS)
  192. key = sta->gtk[key_idx];
  193. } else
  194. key = sdata->keys[key_idx];
  195. if (!key)
  196. goto out;
  197. memset(&params, 0, sizeof(params));
  198. params.cipher = key->conf.cipher;
  199. switch (key->conf.cipher) {
  200. case WLAN_CIPHER_SUITE_TKIP:
  201. iv32 = key->u.tkip.tx.iv32;
  202. iv16 = key->u.tkip.tx.iv16;
  203. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
  204. drv_get_tkip_seq(sdata->local,
  205. key->conf.hw_key_idx,
  206. &iv32, &iv16);
  207. seq[0] = iv16 & 0xff;
  208. seq[1] = (iv16 >> 8) & 0xff;
  209. seq[2] = iv32 & 0xff;
  210. seq[3] = (iv32 >> 8) & 0xff;
  211. seq[4] = (iv32 >> 16) & 0xff;
  212. seq[5] = (iv32 >> 24) & 0xff;
  213. params.seq = seq;
  214. params.seq_len = 6;
  215. break;
  216. case WLAN_CIPHER_SUITE_CCMP:
  217. seq[0] = key->u.ccmp.tx_pn[5];
  218. seq[1] = key->u.ccmp.tx_pn[4];
  219. seq[2] = key->u.ccmp.tx_pn[3];
  220. seq[3] = key->u.ccmp.tx_pn[2];
  221. seq[4] = key->u.ccmp.tx_pn[1];
  222. seq[5] = key->u.ccmp.tx_pn[0];
  223. params.seq = seq;
  224. params.seq_len = 6;
  225. break;
  226. case WLAN_CIPHER_SUITE_AES_CMAC:
  227. seq[0] = key->u.aes_cmac.tx_pn[5];
  228. seq[1] = key->u.aes_cmac.tx_pn[4];
  229. seq[2] = key->u.aes_cmac.tx_pn[3];
  230. seq[3] = key->u.aes_cmac.tx_pn[2];
  231. seq[4] = key->u.aes_cmac.tx_pn[1];
  232. seq[5] = key->u.aes_cmac.tx_pn[0];
  233. params.seq = seq;
  234. params.seq_len = 6;
  235. break;
  236. }
  237. params.key = key->conf.key;
  238. params.key_len = key->conf.keylen;
  239. callback(cookie, &params);
  240. err = 0;
  241. out:
  242. rcu_read_unlock();
  243. return err;
  244. }
  245. static int ieee80211_config_default_key(struct wiphy *wiphy,
  246. struct net_device *dev,
  247. u8 key_idx, bool uni,
  248. bool multi)
  249. {
  250. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  251. ieee80211_set_default_key(sdata, key_idx, uni, multi);
  252. return 0;
  253. }
  254. static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
  255. struct net_device *dev,
  256. u8 key_idx)
  257. {
  258. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  259. ieee80211_set_default_mgmt_key(sdata, key_idx);
  260. return 0;
  261. }
  262. static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  263. {
  264. struct ieee80211_sub_if_data *sdata = sta->sdata;
  265. sinfo->generation = sdata->local->sta_generation;
  266. sinfo->filled = STATION_INFO_INACTIVE_TIME |
  267. STATION_INFO_RX_BYTES |
  268. STATION_INFO_TX_BYTES |
  269. STATION_INFO_RX_PACKETS |
  270. STATION_INFO_TX_PACKETS |
  271. STATION_INFO_TX_RETRIES |
  272. STATION_INFO_TX_FAILED |
  273. STATION_INFO_TX_BITRATE |
  274. STATION_INFO_RX_DROP_MISC;
  275. sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
  276. sinfo->rx_bytes = sta->rx_bytes;
  277. sinfo->tx_bytes = sta->tx_bytes;
  278. sinfo->rx_packets = sta->rx_packets;
  279. sinfo->tx_packets = sta->tx_packets;
  280. sinfo->tx_retries = sta->tx_retry_count;
  281. sinfo->tx_failed = sta->tx_retry_failed;
  282. sinfo->rx_dropped_misc = sta->rx_dropped;
  283. if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
  284. (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
  285. sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
  286. sinfo->signal = (s8)sta->last_signal;
  287. sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
  288. }
  289. sinfo->txrate.flags = 0;
  290. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
  291. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  292. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  293. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  294. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
  295. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  296. if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
  297. struct ieee80211_supported_band *sband;
  298. sband = sta->local->hw.wiphy->bands[
  299. sta->local->hw.conf.channel->band];
  300. sinfo->txrate.legacy =
  301. sband->bitrates[sta->last_tx_rate.idx].bitrate;
  302. } else
  303. sinfo->txrate.mcs = sta->last_tx_rate.idx;
  304. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  305. #ifdef CONFIG_MAC80211_MESH
  306. sinfo->filled |= STATION_INFO_LLID |
  307. STATION_INFO_PLID |
  308. STATION_INFO_PLINK_STATE;
  309. sinfo->llid = le16_to_cpu(sta->llid);
  310. sinfo->plid = le16_to_cpu(sta->plid);
  311. sinfo->plink_state = sta->plink_state;
  312. #endif
  313. }
  314. }
  315. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  316. int idx, u8 *mac, struct station_info *sinfo)
  317. {
  318. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  319. struct sta_info *sta;
  320. int ret = -ENOENT;
  321. rcu_read_lock();
  322. sta = sta_info_get_by_idx(sdata, idx);
  323. if (sta) {
  324. ret = 0;
  325. memcpy(mac, sta->sta.addr, ETH_ALEN);
  326. sta_set_sinfo(sta, sinfo);
  327. }
  328. rcu_read_unlock();
  329. return ret;
  330. }
  331. static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  332. int idx, struct survey_info *survey)
  333. {
  334. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  335. return drv_get_survey(local, idx, survey);
  336. }
  337. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  338. u8 *mac, struct station_info *sinfo)
  339. {
  340. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  341. struct sta_info *sta;
  342. int ret = -ENOENT;
  343. rcu_read_lock();
  344. sta = sta_info_get_bss(sdata, mac);
  345. if (sta) {
  346. ret = 0;
  347. sta_set_sinfo(sta, sinfo);
  348. }
  349. rcu_read_unlock();
  350. return ret;
  351. }
  352. /*
  353. * This handles both adding a beacon and setting new beacon info
  354. */
  355. static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
  356. struct beacon_parameters *params)
  357. {
  358. struct beacon_data *new, *old;
  359. int new_head_len, new_tail_len;
  360. int size;
  361. int err = -EINVAL;
  362. old = sdata->u.ap.beacon;
  363. /* head must not be zero-length */
  364. if (params->head && !params->head_len)
  365. return -EINVAL;
  366. /*
  367. * This is a kludge. beacon interval should really be part
  368. * of the beacon information.
  369. */
  370. if (params->interval &&
  371. (sdata->vif.bss_conf.beacon_int != params->interval)) {
  372. sdata->vif.bss_conf.beacon_int = params->interval;
  373. ieee80211_bss_info_change_notify(sdata,
  374. BSS_CHANGED_BEACON_INT);
  375. }
  376. /* Need to have a beacon head if we don't have one yet */
  377. if (!params->head && !old)
  378. return err;
  379. /* sorry, no way to start beaconing without dtim period */
  380. if (!params->dtim_period && !old)
  381. return err;
  382. /* new or old head? */
  383. if (params->head)
  384. new_head_len = params->head_len;
  385. else
  386. new_head_len = old->head_len;
  387. /* new or old tail? */
  388. if (params->tail || !old)
  389. /* params->tail_len will be zero for !params->tail */
  390. new_tail_len = params->tail_len;
  391. else
  392. new_tail_len = old->tail_len;
  393. size = sizeof(*new) + new_head_len + new_tail_len;
  394. new = kzalloc(size, GFP_KERNEL);
  395. if (!new)
  396. return -ENOMEM;
  397. /* start filling the new info now */
  398. /* new or old dtim period? */
  399. if (params->dtim_period)
  400. new->dtim_period = params->dtim_period;
  401. else
  402. new->dtim_period = old->dtim_period;
  403. /*
  404. * pointers go into the block we allocated,
  405. * memory is | beacon_data | head | tail |
  406. */
  407. new->head = ((u8 *) new) + sizeof(*new);
  408. new->tail = new->head + new_head_len;
  409. new->head_len = new_head_len;
  410. new->tail_len = new_tail_len;
  411. /* copy in head */
  412. if (params->head)
  413. memcpy(new->head, params->head, new_head_len);
  414. else
  415. memcpy(new->head, old->head, new_head_len);
  416. /* copy in optional tail */
  417. if (params->tail)
  418. memcpy(new->tail, params->tail, new_tail_len);
  419. else
  420. if (old)
  421. memcpy(new->tail, old->tail, new_tail_len);
  422. sdata->vif.bss_conf.dtim_period = new->dtim_period;
  423. rcu_assign_pointer(sdata->u.ap.beacon, new);
  424. synchronize_rcu();
  425. kfree(old);
  426. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
  427. BSS_CHANGED_BEACON);
  428. return 0;
  429. }
  430. static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
  431. struct beacon_parameters *params)
  432. {
  433. struct ieee80211_sub_if_data *sdata;
  434. struct beacon_data *old;
  435. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  436. old = sdata->u.ap.beacon;
  437. if (old)
  438. return -EALREADY;
  439. return ieee80211_config_beacon(sdata, params);
  440. }
  441. static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  442. struct beacon_parameters *params)
  443. {
  444. struct ieee80211_sub_if_data *sdata;
  445. struct beacon_data *old;
  446. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  447. old = sdata->u.ap.beacon;
  448. if (!old)
  449. return -ENOENT;
  450. return ieee80211_config_beacon(sdata, params);
  451. }
  452. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  453. {
  454. struct ieee80211_sub_if_data *sdata;
  455. struct beacon_data *old;
  456. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  457. old = sdata->u.ap.beacon;
  458. if (!old)
  459. return -ENOENT;
  460. rcu_assign_pointer(sdata->u.ap.beacon, NULL);
  461. synchronize_rcu();
  462. kfree(old);
  463. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  464. return 0;
  465. }
  466. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  467. struct iapp_layer2_update {
  468. u8 da[ETH_ALEN]; /* broadcast */
  469. u8 sa[ETH_ALEN]; /* STA addr */
  470. __be16 len; /* 6 */
  471. u8 dsap; /* 0 */
  472. u8 ssap; /* 0 */
  473. u8 control;
  474. u8 xid_info[3];
  475. } __packed;
  476. static void ieee80211_send_layer2_update(struct sta_info *sta)
  477. {
  478. struct iapp_layer2_update *msg;
  479. struct sk_buff *skb;
  480. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  481. * bridge devices */
  482. skb = dev_alloc_skb(sizeof(*msg));
  483. if (!skb)
  484. return;
  485. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  486. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  487. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  488. memset(msg->da, 0xff, ETH_ALEN);
  489. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  490. msg->len = htons(6);
  491. msg->dsap = 0;
  492. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  493. msg->control = 0xaf; /* XID response lsb.1111F101.
  494. * F=0 (no poll command; unsolicited frame) */
  495. msg->xid_info[0] = 0x81; /* XID format identifier */
  496. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  497. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  498. skb->dev = sta->sdata->dev;
  499. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  500. memset(skb->cb, 0, sizeof(skb->cb));
  501. netif_rx_ni(skb);
  502. }
  503. static void sta_apply_parameters(struct ieee80211_local *local,
  504. struct sta_info *sta,
  505. struct station_parameters *params)
  506. {
  507. unsigned long flags;
  508. u32 rates;
  509. int i, j;
  510. struct ieee80211_supported_band *sband;
  511. struct ieee80211_sub_if_data *sdata = sta->sdata;
  512. u32 mask, set;
  513. sband = local->hw.wiphy->bands[local->oper_channel->band];
  514. spin_lock_irqsave(&sta->flaglock, flags);
  515. mask = params->sta_flags_mask;
  516. set = params->sta_flags_set;
  517. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  518. sta->flags &= ~WLAN_STA_AUTHORIZED;
  519. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  520. sta->flags |= WLAN_STA_AUTHORIZED;
  521. }
  522. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  523. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  524. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  525. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  526. }
  527. if (mask & BIT(NL80211_STA_FLAG_WME)) {
  528. sta->flags &= ~WLAN_STA_WME;
  529. if (set & BIT(NL80211_STA_FLAG_WME))
  530. sta->flags |= WLAN_STA_WME;
  531. }
  532. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  533. sta->flags &= ~WLAN_STA_MFP;
  534. if (set & BIT(NL80211_STA_FLAG_MFP))
  535. sta->flags |= WLAN_STA_MFP;
  536. }
  537. spin_unlock_irqrestore(&sta->flaglock, flags);
  538. /*
  539. * cfg80211 validates this (1-2007) and allows setting the AID
  540. * only when creating a new station entry
  541. */
  542. if (params->aid)
  543. sta->sta.aid = params->aid;
  544. /*
  545. * FIXME: updating the following information is racy when this
  546. * function is called from ieee80211_change_station().
  547. * However, all this information should be static so
  548. * maybe we should just reject attemps to change it.
  549. */
  550. if (params->listen_interval >= 0)
  551. sta->listen_interval = params->listen_interval;
  552. if (params->supported_rates) {
  553. rates = 0;
  554. for (i = 0; i < params->supported_rates_len; i++) {
  555. int rate = (params->supported_rates[i] & 0x7f) * 5;
  556. for (j = 0; j < sband->n_bitrates; j++) {
  557. if (sband->bitrates[j].bitrate == rate)
  558. rates |= BIT(j);
  559. }
  560. }
  561. sta->sta.supp_rates[local->oper_channel->band] = rates;
  562. }
  563. if (params->ht_capa)
  564. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  565. params->ht_capa,
  566. &sta->sta.ht_cap);
  567. if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
  568. switch (params->plink_action) {
  569. case PLINK_ACTION_OPEN:
  570. mesh_plink_open(sta);
  571. break;
  572. case PLINK_ACTION_BLOCK:
  573. mesh_plink_block(sta);
  574. break;
  575. }
  576. }
  577. }
  578. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  579. u8 *mac, struct station_parameters *params)
  580. {
  581. struct ieee80211_local *local = wiphy_priv(wiphy);
  582. struct sta_info *sta;
  583. struct ieee80211_sub_if_data *sdata;
  584. int err;
  585. int layer2_update;
  586. if (params->vlan) {
  587. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  588. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  589. sdata->vif.type != NL80211_IFTYPE_AP)
  590. return -EINVAL;
  591. } else
  592. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  593. if (compare_ether_addr(mac, sdata->vif.addr) == 0)
  594. return -EINVAL;
  595. if (is_multicast_ether_addr(mac))
  596. return -EINVAL;
  597. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  598. if (!sta)
  599. return -ENOMEM;
  600. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  601. sta_apply_parameters(local, sta, params);
  602. rate_control_rate_init(sta);
  603. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  604. sdata->vif.type == NL80211_IFTYPE_AP;
  605. err = sta_info_insert_rcu(sta);
  606. if (err) {
  607. rcu_read_unlock();
  608. return err;
  609. }
  610. if (layer2_update)
  611. ieee80211_send_layer2_update(sta);
  612. rcu_read_unlock();
  613. return 0;
  614. }
  615. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  616. u8 *mac)
  617. {
  618. struct ieee80211_local *local = wiphy_priv(wiphy);
  619. struct ieee80211_sub_if_data *sdata;
  620. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  621. if (mac)
  622. return sta_info_destroy_addr_bss(sdata, mac);
  623. sta_info_flush(local, sdata);
  624. return 0;
  625. }
  626. static int ieee80211_change_station(struct wiphy *wiphy,
  627. struct net_device *dev,
  628. u8 *mac,
  629. struct station_parameters *params)
  630. {
  631. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  632. struct ieee80211_local *local = wiphy_priv(wiphy);
  633. struct sta_info *sta;
  634. struct ieee80211_sub_if_data *vlansdata;
  635. rcu_read_lock();
  636. sta = sta_info_get_bss(sdata, mac);
  637. if (!sta) {
  638. rcu_read_unlock();
  639. return -ENOENT;
  640. }
  641. if (params->vlan && params->vlan != sta->sdata->dev) {
  642. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  643. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  644. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  645. rcu_read_unlock();
  646. return -EINVAL;
  647. }
  648. if (params->vlan->ieee80211_ptr->use_4addr) {
  649. if (vlansdata->u.vlan.sta) {
  650. rcu_read_unlock();
  651. return -EBUSY;
  652. }
  653. rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
  654. }
  655. sta->sdata = vlansdata;
  656. ieee80211_send_layer2_update(sta);
  657. }
  658. sta_apply_parameters(local, sta, params);
  659. rcu_read_unlock();
  660. return 0;
  661. }
  662. #ifdef CONFIG_MAC80211_MESH
  663. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  664. u8 *dst, u8 *next_hop)
  665. {
  666. struct ieee80211_sub_if_data *sdata;
  667. struct mesh_path *mpath;
  668. struct sta_info *sta;
  669. int err;
  670. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  671. rcu_read_lock();
  672. sta = sta_info_get(sdata, next_hop);
  673. if (!sta) {
  674. rcu_read_unlock();
  675. return -ENOENT;
  676. }
  677. err = mesh_path_add(dst, sdata);
  678. if (err) {
  679. rcu_read_unlock();
  680. return err;
  681. }
  682. mpath = mesh_path_lookup(dst, sdata);
  683. if (!mpath) {
  684. rcu_read_unlock();
  685. return -ENXIO;
  686. }
  687. mesh_path_fix_nexthop(mpath, sta);
  688. rcu_read_unlock();
  689. return 0;
  690. }
  691. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  692. u8 *dst)
  693. {
  694. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  695. if (dst)
  696. return mesh_path_del(dst, sdata);
  697. mesh_path_flush(sdata);
  698. return 0;
  699. }
  700. static int ieee80211_change_mpath(struct wiphy *wiphy,
  701. struct net_device *dev,
  702. u8 *dst, u8 *next_hop)
  703. {
  704. struct ieee80211_sub_if_data *sdata;
  705. struct mesh_path *mpath;
  706. struct sta_info *sta;
  707. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  708. rcu_read_lock();
  709. sta = sta_info_get(sdata, next_hop);
  710. if (!sta) {
  711. rcu_read_unlock();
  712. return -ENOENT;
  713. }
  714. mpath = mesh_path_lookup(dst, sdata);
  715. if (!mpath) {
  716. rcu_read_unlock();
  717. return -ENOENT;
  718. }
  719. mesh_path_fix_nexthop(mpath, sta);
  720. rcu_read_unlock();
  721. return 0;
  722. }
  723. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  724. struct mpath_info *pinfo)
  725. {
  726. if (mpath->next_hop)
  727. memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
  728. else
  729. memset(next_hop, 0, ETH_ALEN);
  730. pinfo->generation = mesh_paths_generation;
  731. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  732. MPATH_INFO_SN |
  733. MPATH_INFO_METRIC |
  734. MPATH_INFO_EXPTIME |
  735. MPATH_INFO_DISCOVERY_TIMEOUT |
  736. MPATH_INFO_DISCOVERY_RETRIES |
  737. MPATH_INFO_FLAGS;
  738. pinfo->frame_qlen = mpath->frame_queue.qlen;
  739. pinfo->sn = mpath->sn;
  740. pinfo->metric = mpath->metric;
  741. if (time_before(jiffies, mpath->exp_time))
  742. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  743. pinfo->discovery_timeout =
  744. jiffies_to_msecs(mpath->discovery_timeout);
  745. pinfo->discovery_retries = mpath->discovery_retries;
  746. pinfo->flags = 0;
  747. if (mpath->flags & MESH_PATH_ACTIVE)
  748. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  749. if (mpath->flags & MESH_PATH_RESOLVING)
  750. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  751. if (mpath->flags & MESH_PATH_SN_VALID)
  752. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  753. if (mpath->flags & MESH_PATH_FIXED)
  754. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  755. if (mpath->flags & MESH_PATH_RESOLVING)
  756. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  757. pinfo->flags = mpath->flags;
  758. }
  759. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  760. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  761. {
  762. struct ieee80211_sub_if_data *sdata;
  763. struct mesh_path *mpath;
  764. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  765. rcu_read_lock();
  766. mpath = mesh_path_lookup(dst, sdata);
  767. if (!mpath) {
  768. rcu_read_unlock();
  769. return -ENOENT;
  770. }
  771. memcpy(dst, mpath->dst, ETH_ALEN);
  772. mpath_set_pinfo(mpath, next_hop, pinfo);
  773. rcu_read_unlock();
  774. return 0;
  775. }
  776. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  777. int idx, u8 *dst, u8 *next_hop,
  778. struct mpath_info *pinfo)
  779. {
  780. struct ieee80211_sub_if_data *sdata;
  781. struct mesh_path *mpath;
  782. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  783. rcu_read_lock();
  784. mpath = mesh_path_lookup_by_idx(idx, sdata);
  785. if (!mpath) {
  786. rcu_read_unlock();
  787. return -ENOENT;
  788. }
  789. memcpy(dst, mpath->dst, ETH_ALEN);
  790. mpath_set_pinfo(mpath, next_hop, pinfo);
  791. rcu_read_unlock();
  792. return 0;
  793. }
  794. static int ieee80211_get_mesh_config(struct wiphy *wiphy,
  795. struct net_device *dev,
  796. struct mesh_config *conf)
  797. {
  798. struct ieee80211_sub_if_data *sdata;
  799. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  800. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  801. return 0;
  802. }
  803. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  804. {
  805. return (mask >> (parm-1)) & 0x1;
  806. }
  807. static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
  808. const struct mesh_setup *setup)
  809. {
  810. u8 *new_ie;
  811. const u8 *old_ie;
  812. /* first allocate the new vendor information element */
  813. new_ie = NULL;
  814. old_ie = ifmsh->vendor_ie;
  815. ifmsh->vendor_ie_len = setup->vendor_ie_len;
  816. if (setup->vendor_ie_len) {
  817. new_ie = kmemdup(setup->vendor_ie, setup->vendor_ie_len,
  818. GFP_KERNEL);
  819. if (!new_ie)
  820. return -ENOMEM;
  821. }
  822. /* now copy the rest of the setup parameters */
  823. ifmsh->mesh_id_len = setup->mesh_id_len;
  824. memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
  825. ifmsh->mesh_pp_id = setup->path_sel_proto;
  826. ifmsh->mesh_pm_id = setup->path_metric;
  827. ifmsh->vendor_ie = new_ie;
  828. kfree(old_ie);
  829. return 0;
  830. }
  831. static int ieee80211_update_mesh_config(struct wiphy *wiphy,
  832. struct net_device *dev, u32 mask,
  833. const struct mesh_config *nconf)
  834. {
  835. struct mesh_config *conf;
  836. struct ieee80211_sub_if_data *sdata;
  837. struct ieee80211_if_mesh *ifmsh;
  838. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  839. ifmsh = &sdata->u.mesh;
  840. /* Set the config options which we are interested in setting */
  841. conf = &(sdata->u.mesh.mshcfg);
  842. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  843. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  844. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  845. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  846. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  847. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  848. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  849. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  850. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  851. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  852. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  853. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  854. if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
  855. conf->dot11MeshTTL = nconf->element_ttl;
  856. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  857. conf->auto_open_plinks = nconf->auto_open_plinks;
  858. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  859. conf->dot11MeshHWMPmaxPREQretries =
  860. nconf->dot11MeshHWMPmaxPREQretries;
  861. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  862. conf->path_refresh_time = nconf->path_refresh_time;
  863. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  864. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  865. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  866. conf->dot11MeshHWMPactivePathTimeout =
  867. nconf->dot11MeshHWMPactivePathTimeout;
  868. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  869. conf->dot11MeshHWMPpreqMinInterval =
  870. nconf->dot11MeshHWMPpreqMinInterval;
  871. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  872. mask))
  873. conf->dot11MeshHWMPnetDiameterTraversalTime =
  874. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  875. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  876. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  877. ieee80211_mesh_root_setup(ifmsh);
  878. }
  879. return 0;
  880. }
  881. static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
  882. const struct mesh_config *conf,
  883. const struct mesh_setup *setup)
  884. {
  885. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  886. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  887. int err;
  888. memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
  889. err = copy_mesh_setup(ifmsh, setup);
  890. if (err)
  891. return err;
  892. ieee80211_start_mesh(sdata);
  893. return 0;
  894. }
  895. static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
  896. {
  897. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  898. ieee80211_stop_mesh(sdata);
  899. return 0;
  900. }
  901. #endif
  902. static int ieee80211_change_bss(struct wiphy *wiphy,
  903. struct net_device *dev,
  904. struct bss_parameters *params)
  905. {
  906. struct ieee80211_sub_if_data *sdata;
  907. u32 changed = 0;
  908. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  909. if (params->use_cts_prot >= 0) {
  910. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  911. changed |= BSS_CHANGED_ERP_CTS_PROT;
  912. }
  913. if (params->use_short_preamble >= 0) {
  914. sdata->vif.bss_conf.use_short_preamble =
  915. params->use_short_preamble;
  916. changed |= BSS_CHANGED_ERP_PREAMBLE;
  917. }
  918. if (!sdata->vif.bss_conf.use_short_slot &&
  919. sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
  920. sdata->vif.bss_conf.use_short_slot = true;
  921. changed |= BSS_CHANGED_ERP_SLOT;
  922. }
  923. if (params->use_short_slot_time >= 0) {
  924. sdata->vif.bss_conf.use_short_slot =
  925. params->use_short_slot_time;
  926. changed |= BSS_CHANGED_ERP_SLOT;
  927. }
  928. if (params->basic_rates) {
  929. int i, j;
  930. u32 rates = 0;
  931. struct ieee80211_local *local = wiphy_priv(wiphy);
  932. struct ieee80211_supported_band *sband =
  933. wiphy->bands[local->oper_channel->band];
  934. for (i = 0; i < params->basic_rates_len; i++) {
  935. int rate = (params->basic_rates[i] & 0x7f) * 5;
  936. for (j = 0; j < sband->n_bitrates; j++) {
  937. if (sband->bitrates[j].bitrate == rate)
  938. rates |= BIT(j);
  939. }
  940. }
  941. sdata->vif.bss_conf.basic_rates = rates;
  942. changed |= BSS_CHANGED_BASIC_RATES;
  943. }
  944. if (params->ap_isolate >= 0) {
  945. if (params->ap_isolate)
  946. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  947. else
  948. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  949. }
  950. if (params->ht_opmode >= 0) {
  951. sdata->vif.bss_conf.ht_operation_mode =
  952. (u16) params->ht_opmode;
  953. changed |= BSS_CHANGED_HT;
  954. }
  955. ieee80211_bss_info_change_notify(sdata, changed);
  956. return 0;
  957. }
  958. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  959. struct ieee80211_txq_params *params)
  960. {
  961. struct ieee80211_local *local = wiphy_priv(wiphy);
  962. struct ieee80211_tx_queue_params p;
  963. if (!local->ops->conf_tx)
  964. return -EOPNOTSUPP;
  965. memset(&p, 0, sizeof(p));
  966. p.aifs = params->aifs;
  967. p.cw_max = params->cwmax;
  968. p.cw_min = params->cwmin;
  969. p.txop = params->txop;
  970. /*
  971. * Setting tx queue params disables u-apsd because it's only
  972. * called in master mode.
  973. */
  974. p.uapsd = false;
  975. if (drv_conf_tx(local, params->queue, &p)) {
  976. wiphy_debug(local->hw.wiphy,
  977. "failed to set TX queue parameters for queue %d\n",
  978. params->queue);
  979. return -EINVAL;
  980. }
  981. return 0;
  982. }
  983. static int ieee80211_set_channel(struct wiphy *wiphy,
  984. struct net_device *netdev,
  985. struct ieee80211_channel *chan,
  986. enum nl80211_channel_type channel_type)
  987. {
  988. struct ieee80211_local *local = wiphy_priv(wiphy);
  989. struct ieee80211_sub_if_data *sdata = NULL;
  990. struct ieee80211_channel *old_oper;
  991. enum nl80211_channel_type old_oper_type;
  992. enum nl80211_channel_type old_vif_oper_type= NL80211_CHAN_NO_HT;
  993. if (netdev)
  994. sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
  995. switch (ieee80211_get_channel_mode(local, NULL)) {
  996. case CHAN_MODE_HOPPING:
  997. return -EBUSY;
  998. case CHAN_MODE_FIXED:
  999. if (local->oper_channel != chan)
  1000. return -EBUSY;
  1001. if (!sdata && local->_oper_channel_type == channel_type)
  1002. return 0;
  1003. break;
  1004. case CHAN_MODE_UNDEFINED:
  1005. break;
  1006. }
  1007. if (sdata)
  1008. old_vif_oper_type = sdata->vif.bss_conf.channel_type;
  1009. old_oper_type = local->_oper_channel_type;
  1010. if (!ieee80211_set_channel_type(local, sdata, channel_type))
  1011. return -EBUSY;
  1012. old_oper = local->oper_channel;
  1013. local->oper_channel = chan;
  1014. /* Update driver if changes were actually made. */
  1015. if ((old_oper != local->oper_channel) ||
  1016. (old_oper_type != local->_oper_channel_type))
  1017. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  1018. if ((sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR) &&
  1019. old_vif_oper_type != sdata->vif.bss_conf.channel_type)
  1020. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
  1021. return 0;
  1022. }
  1023. #ifdef CONFIG_PM
  1024. static int ieee80211_suspend(struct wiphy *wiphy)
  1025. {
  1026. return __ieee80211_suspend(wiphy_priv(wiphy));
  1027. }
  1028. static int ieee80211_resume(struct wiphy *wiphy)
  1029. {
  1030. return __ieee80211_resume(wiphy_priv(wiphy));
  1031. }
  1032. #else
  1033. #define ieee80211_suspend NULL
  1034. #define ieee80211_resume NULL
  1035. #endif
  1036. static int ieee80211_scan(struct wiphy *wiphy,
  1037. struct net_device *dev,
  1038. struct cfg80211_scan_request *req)
  1039. {
  1040. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1041. switch (ieee80211_vif_type_p2p(&sdata->vif)) {
  1042. case NL80211_IFTYPE_STATION:
  1043. case NL80211_IFTYPE_ADHOC:
  1044. case NL80211_IFTYPE_MESH_POINT:
  1045. case NL80211_IFTYPE_P2P_CLIENT:
  1046. break;
  1047. case NL80211_IFTYPE_P2P_GO:
  1048. if (sdata->local->ops->hw_scan)
  1049. break;
  1050. /*
  1051. * FIXME: implement NoA while scanning in software,
  1052. * for now fall through to allow scanning only when
  1053. * beaconing hasn't been configured yet
  1054. */
  1055. case NL80211_IFTYPE_AP:
  1056. if (sdata->u.ap.beacon)
  1057. return -EOPNOTSUPP;
  1058. break;
  1059. default:
  1060. return -EOPNOTSUPP;
  1061. }
  1062. return ieee80211_request_scan(sdata, req);
  1063. }
  1064. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  1065. struct cfg80211_auth_request *req)
  1066. {
  1067. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1068. }
  1069. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  1070. struct cfg80211_assoc_request *req)
  1071. {
  1072. struct ieee80211_local *local = wiphy_priv(wiphy);
  1073. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1074. switch (ieee80211_get_channel_mode(local, sdata)) {
  1075. case CHAN_MODE_HOPPING:
  1076. return -EBUSY;
  1077. case CHAN_MODE_FIXED:
  1078. if (local->oper_channel == req->bss->channel)
  1079. break;
  1080. return -EBUSY;
  1081. case CHAN_MODE_UNDEFINED:
  1082. break;
  1083. }
  1084. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1085. }
  1086. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1087. struct cfg80211_deauth_request *req,
  1088. void *cookie)
  1089. {
  1090. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
  1091. req, cookie);
  1092. }
  1093. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1094. struct cfg80211_disassoc_request *req,
  1095. void *cookie)
  1096. {
  1097. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
  1098. req, cookie);
  1099. }
  1100. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1101. struct cfg80211_ibss_params *params)
  1102. {
  1103. struct ieee80211_local *local = wiphy_priv(wiphy);
  1104. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1105. switch (ieee80211_get_channel_mode(local, sdata)) {
  1106. case CHAN_MODE_HOPPING:
  1107. return -EBUSY;
  1108. case CHAN_MODE_FIXED:
  1109. if (!params->channel_fixed)
  1110. return -EBUSY;
  1111. if (local->oper_channel == params->channel)
  1112. break;
  1113. return -EBUSY;
  1114. case CHAN_MODE_UNDEFINED:
  1115. break;
  1116. }
  1117. return ieee80211_ibss_join(sdata, params);
  1118. }
  1119. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1120. {
  1121. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1122. return ieee80211_ibss_leave(sdata);
  1123. }
  1124. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1125. {
  1126. struct ieee80211_local *local = wiphy_priv(wiphy);
  1127. int err;
  1128. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  1129. err = drv_set_frag_threshold(local, wiphy->frag_threshold);
  1130. if (err)
  1131. return err;
  1132. }
  1133. if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
  1134. err = drv_set_coverage_class(local, wiphy->coverage_class);
  1135. if (err)
  1136. return err;
  1137. }
  1138. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1139. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1140. if (err)
  1141. return err;
  1142. }
  1143. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1144. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1145. if (changed & WIPHY_PARAM_RETRY_LONG)
  1146. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1147. if (changed &
  1148. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1149. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1150. return 0;
  1151. }
  1152. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1153. enum nl80211_tx_power_setting type, int mbm)
  1154. {
  1155. struct ieee80211_local *local = wiphy_priv(wiphy);
  1156. struct ieee80211_channel *chan = local->hw.conf.channel;
  1157. u32 changes = 0;
  1158. switch (type) {
  1159. case NL80211_TX_POWER_AUTOMATIC:
  1160. local->user_power_level = -1;
  1161. break;
  1162. case NL80211_TX_POWER_LIMITED:
  1163. if (mbm < 0 || (mbm % 100))
  1164. return -EOPNOTSUPP;
  1165. local->user_power_level = MBM_TO_DBM(mbm);
  1166. break;
  1167. case NL80211_TX_POWER_FIXED:
  1168. if (mbm < 0 || (mbm % 100))
  1169. return -EOPNOTSUPP;
  1170. /* TODO: move to cfg80211 when it knows the channel */
  1171. if (MBM_TO_DBM(mbm) > chan->max_power)
  1172. return -EINVAL;
  1173. local->user_power_level = MBM_TO_DBM(mbm);
  1174. break;
  1175. }
  1176. ieee80211_hw_config(local, changes);
  1177. return 0;
  1178. }
  1179. static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
  1180. {
  1181. struct ieee80211_local *local = wiphy_priv(wiphy);
  1182. *dbm = local->hw.conf.power_level;
  1183. return 0;
  1184. }
  1185. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  1186. const u8 *addr)
  1187. {
  1188. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1189. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  1190. return 0;
  1191. }
  1192. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1193. {
  1194. struct ieee80211_local *local = wiphy_priv(wiphy);
  1195. drv_rfkill_poll(local);
  1196. }
  1197. #ifdef CONFIG_NL80211_TESTMODE
  1198. static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
  1199. {
  1200. struct ieee80211_local *local = wiphy_priv(wiphy);
  1201. if (!local->ops->testmode_cmd)
  1202. return -EOPNOTSUPP;
  1203. return local->ops->testmode_cmd(&local->hw, data, len);
  1204. }
  1205. #endif
  1206. int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
  1207. enum ieee80211_smps_mode smps_mode)
  1208. {
  1209. const u8 *ap;
  1210. enum ieee80211_smps_mode old_req;
  1211. int err;
  1212. old_req = sdata->u.mgd.req_smps;
  1213. sdata->u.mgd.req_smps = smps_mode;
  1214. if (old_req == smps_mode &&
  1215. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  1216. return 0;
  1217. /*
  1218. * If not associated, or current association is not an HT
  1219. * association, there's no need to send an action frame.
  1220. */
  1221. if (!sdata->u.mgd.associated ||
  1222. sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
  1223. mutex_lock(&sdata->local->iflist_mtx);
  1224. ieee80211_recalc_smps(sdata->local);
  1225. mutex_unlock(&sdata->local->iflist_mtx);
  1226. return 0;
  1227. }
  1228. ap = sdata->u.mgd.associated->bssid;
  1229. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  1230. if (sdata->u.mgd.powersave)
  1231. smps_mode = IEEE80211_SMPS_DYNAMIC;
  1232. else
  1233. smps_mode = IEEE80211_SMPS_OFF;
  1234. }
  1235. /* send SM PS frame to AP */
  1236. err = ieee80211_send_smps_action(sdata, smps_mode,
  1237. ap, ap);
  1238. if (err)
  1239. sdata->u.mgd.req_smps = old_req;
  1240. return err;
  1241. }
  1242. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1243. bool enabled, int timeout)
  1244. {
  1245. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1246. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1247. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1248. return -EOPNOTSUPP;
  1249. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  1250. return -EOPNOTSUPP;
  1251. if (enabled == sdata->u.mgd.powersave &&
  1252. timeout == local->dynamic_ps_forced_timeout)
  1253. return 0;
  1254. sdata->u.mgd.powersave = enabled;
  1255. local->dynamic_ps_forced_timeout = timeout;
  1256. /* no change, but if automatic follow powersave */
  1257. mutex_lock(&sdata->u.mgd.mtx);
  1258. __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
  1259. mutex_unlock(&sdata->u.mgd.mtx);
  1260. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  1261. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1262. ieee80211_recalc_ps(local, -1);
  1263. return 0;
  1264. }
  1265. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  1266. struct net_device *dev,
  1267. s32 rssi_thold, u32 rssi_hyst)
  1268. {
  1269. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1270. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1271. struct ieee80211_vif *vif = &sdata->vif;
  1272. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1273. if (rssi_thold == bss_conf->cqm_rssi_thold &&
  1274. rssi_hyst == bss_conf->cqm_rssi_hyst)
  1275. return 0;
  1276. bss_conf->cqm_rssi_thold = rssi_thold;
  1277. bss_conf->cqm_rssi_hyst = rssi_hyst;
  1278. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
  1279. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1280. return -EOPNOTSUPP;
  1281. return 0;
  1282. }
  1283. /* tell the driver upon association, unless already associated */
  1284. if (sdata->u.mgd.associated)
  1285. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  1286. return 0;
  1287. }
  1288. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  1289. struct net_device *dev,
  1290. const u8 *addr,
  1291. const struct cfg80211_bitrate_mask *mask)
  1292. {
  1293. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1294. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1295. int i;
  1296. /*
  1297. * This _could_ be supported by providing a hook for
  1298. * drivers for this function, but at this point it
  1299. * doesn't seem worth bothering.
  1300. */
  1301. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
  1302. return -EOPNOTSUPP;
  1303. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  1304. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  1305. return 0;
  1306. }
  1307. static int ieee80211_remain_on_channel_hw(struct ieee80211_local *local,
  1308. struct net_device *dev,
  1309. struct ieee80211_channel *chan,
  1310. enum nl80211_channel_type chantype,
  1311. unsigned int duration, u64 *cookie)
  1312. {
  1313. int ret;
  1314. u32 random_cookie;
  1315. lockdep_assert_held(&local->mtx);
  1316. if (local->hw_roc_cookie)
  1317. return -EBUSY;
  1318. /* must be nonzero */
  1319. random_cookie = random32() | 1;
  1320. *cookie = random_cookie;
  1321. local->hw_roc_dev = dev;
  1322. local->hw_roc_cookie = random_cookie;
  1323. local->hw_roc_channel = chan;
  1324. local->hw_roc_channel_type = chantype;
  1325. local->hw_roc_duration = duration;
  1326. ret = drv_remain_on_channel(local, chan, chantype, duration);
  1327. if (ret) {
  1328. local->hw_roc_channel = NULL;
  1329. local->hw_roc_cookie = 0;
  1330. }
  1331. return ret;
  1332. }
  1333. static int ieee80211_remain_on_channel(struct wiphy *wiphy,
  1334. struct net_device *dev,
  1335. struct ieee80211_channel *chan,
  1336. enum nl80211_channel_type channel_type,
  1337. unsigned int duration,
  1338. u64 *cookie)
  1339. {
  1340. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1341. struct ieee80211_local *local = sdata->local;
  1342. if (local->ops->remain_on_channel) {
  1343. int ret;
  1344. mutex_lock(&local->mtx);
  1345. ret = ieee80211_remain_on_channel_hw(local, dev,
  1346. chan, channel_type,
  1347. duration, cookie);
  1348. local->hw_roc_for_tx = false;
  1349. mutex_unlock(&local->mtx);
  1350. return ret;
  1351. }
  1352. return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
  1353. duration, cookie);
  1354. }
  1355. static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local *local,
  1356. u64 cookie)
  1357. {
  1358. int ret;
  1359. lockdep_assert_held(&local->mtx);
  1360. if (local->hw_roc_cookie != cookie)
  1361. return -ENOENT;
  1362. ret = drv_cancel_remain_on_channel(local);
  1363. if (ret)
  1364. return ret;
  1365. local->hw_roc_cookie = 0;
  1366. local->hw_roc_channel = NULL;
  1367. ieee80211_recalc_idle(local);
  1368. return 0;
  1369. }
  1370. static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
  1371. struct net_device *dev,
  1372. u64 cookie)
  1373. {
  1374. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1375. struct ieee80211_local *local = sdata->local;
  1376. if (local->ops->cancel_remain_on_channel) {
  1377. int ret;
  1378. mutex_lock(&local->mtx);
  1379. ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
  1380. mutex_unlock(&local->mtx);
  1381. return ret;
  1382. }
  1383. return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
  1384. }
  1385. static enum work_done_result
  1386. ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
  1387. {
  1388. /*
  1389. * Use the data embedded in the work struct for reporting
  1390. * here so if the driver mangled the SKB before dropping
  1391. * it (which is the only way we really should get here)
  1392. * then we don't report mangled data.
  1393. *
  1394. * If there was no wait time, then by the time we get here
  1395. * the driver will likely not have reported the status yet,
  1396. * so in that case userspace will have to deal with it.
  1397. */
  1398. if (wk->offchan_tx.wait && wk->offchan_tx.frame)
  1399. cfg80211_mgmt_tx_status(wk->sdata->dev,
  1400. (unsigned long) wk->offchan_tx.frame,
  1401. wk->ie, wk->ie_len, false, GFP_KERNEL);
  1402. return WORK_DONE_DESTROY;
  1403. }
  1404. static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
  1405. struct ieee80211_channel *chan, bool offchan,
  1406. enum nl80211_channel_type channel_type,
  1407. bool channel_type_valid, unsigned int wait,
  1408. const u8 *buf, size_t len, u64 *cookie)
  1409. {
  1410. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1411. struct ieee80211_local *local = sdata->local;
  1412. struct sk_buff *skb;
  1413. struct sta_info *sta;
  1414. struct ieee80211_work *wk;
  1415. const struct ieee80211_mgmt *mgmt = (void *)buf;
  1416. u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
  1417. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1418. bool is_offchan = false;
  1419. /* Check that we are on the requested channel for transmission */
  1420. if (chan != local->tmp_channel &&
  1421. chan != local->oper_channel)
  1422. is_offchan = true;
  1423. if (channel_type_valid &&
  1424. (channel_type != local->tmp_channel_type &&
  1425. channel_type != local->_oper_channel_type))
  1426. is_offchan = true;
  1427. if (chan == local->hw_roc_channel) {
  1428. /* TODO: check channel type? */
  1429. is_offchan = false;
  1430. flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
  1431. }
  1432. if (is_offchan && !offchan)
  1433. return -EBUSY;
  1434. switch (sdata->vif.type) {
  1435. case NL80211_IFTYPE_ADHOC:
  1436. case NL80211_IFTYPE_AP:
  1437. case NL80211_IFTYPE_AP_VLAN:
  1438. case NL80211_IFTYPE_P2P_GO:
  1439. case NL80211_IFTYPE_MESH_POINT:
  1440. if (!ieee80211_is_action(mgmt->frame_control) ||
  1441. mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
  1442. break;
  1443. rcu_read_lock();
  1444. sta = sta_info_get(sdata, mgmt->da);
  1445. rcu_read_unlock();
  1446. if (!sta)
  1447. return -ENOLINK;
  1448. break;
  1449. case NL80211_IFTYPE_STATION:
  1450. case NL80211_IFTYPE_P2P_CLIENT:
  1451. break;
  1452. default:
  1453. return -EOPNOTSUPP;
  1454. }
  1455. skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
  1456. if (!skb)
  1457. return -ENOMEM;
  1458. skb_reserve(skb, local->hw.extra_tx_headroom);
  1459. memcpy(skb_put(skb, len), buf, len);
  1460. IEEE80211_SKB_CB(skb)->flags = flags;
  1461. skb->dev = sdata->dev;
  1462. *cookie = (unsigned long) skb;
  1463. if (is_offchan && local->ops->remain_on_channel) {
  1464. unsigned int duration;
  1465. int ret;
  1466. mutex_lock(&local->mtx);
  1467. /*
  1468. * If the duration is zero, then the driver
  1469. * wouldn't actually do anything. Set it to
  1470. * 100 for now.
  1471. *
  1472. * TODO: cancel the off-channel operation
  1473. * when we get the SKB's TX status and
  1474. * the wait time was zero before.
  1475. */
  1476. duration = 100;
  1477. if (wait)
  1478. duration = wait;
  1479. ret = ieee80211_remain_on_channel_hw(local, dev, chan,
  1480. channel_type,
  1481. duration, cookie);
  1482. if (ret) {
  1483. kfree_skb(skb);
  1484. mutex_unlock(&local->mtx);
  1485. return ret;
  1486. }
  1487. local->hw_roc_for_tx = true;
  1488. local->hw_roc_duration = wait;
  1489. /*
  1490. * queue up frame for transmission after
  1491. * ieee80211_ready_on_channel call
  1492. */
  1493. /* modify cookie to prevent API mismatches */
  1494. *cookie ^= 2;
  1495. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
  1496. local->hw_roc_skb = skb;
  1497. local->hw_roc_skb_for_status = skb;
  1498. mutex_unlock(&local->mtx);
  1499. return 0;
  1500. }
  1501. /*
  1502. * Can transmit right away if the channel was the
  1503. * right one and there's no wait involved... If a
  1504. * wait is involved, we might otherwise not be on
  1505. * the right channel for long enough!
  1506. */
  1507. if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
  1508. ieee80211_tx_skb(sdata, skb);
  1509. return 0;
  1510. }
  1511. wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL);
  1512. if (!wk) {
  1513. kfree_skb(skb);
  1514. return -ENOMEM;
  1515. }
  1516. wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
  1517. wk->chan = chan;
  1518. wk->chan_type = channel_type;
  1519. wk->sdata = sdata;
  1520. wk->done = ieee80211_offchan_tx_done;
  1521. wk->offchan_tx.frame = skb;
  1522. wk->offchan_tx.wait = wait;
  1523. wk->ie_len = len;
  1524. memcpy(wk->ie, buf, len);
  1525. ieee80211_add_work(wk);
  1526. return 0;
  1527. }
  1528. static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
  1529. struct net_device *dev,
  1530. u64 cookie)
  1531. {
  1532. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1533. struct ieee80211_local *local = sdata->local;
  1534. struct ieee80211_work *wk;
  1535. int ret = -ENOENT;
  1536. mutex_lock(&local->mtx);
  1537. if (local->ops->cancel_remain_on_channel) {
  1538. cookie ^= 2;
  1539. ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
  1540. if (ret == 0) {
  1541. kfree_skb(local->hw_roc_skb);
  1542. local->hw_roc_skb = NULL;
  1543. local->hw_roc_skb_for_status = NULL;
  1544. }
  1545. mutex_unlock(&local->mtx);
  1546. return ret;
  1547. }
  1548. list_for_each_entry(wk, &local->work_list, list) {
  1549. if (wk->sdata != sdata)
  1550. continue;
  1551. if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
  1552. continue;
  1553. if (cookie != (unsigned long) wk->offchan_tx.frame)
  1554. continue;
  1555. wk->timeout = jiffies;
  1556. ieee80211_queue_work(&local->hw, &local->work_work);
  1557. ret = 0;
  1558. break;
  1559. }
  1560. mutex_unlock(&local->mtx);
  1561. return ret;
  1562. }
  1563. static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
  1564. struct net_device *dev,
  1565. u16 frame_type, bool reg)
  1566. {
  1567. struct ieee80211_local *local = wiphy_priv(wiphy);
  1568. if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
  1569. return;
  1570. if (reg)
  1571. local->probe_req_reg++;
  1572. else
  1573. local->probe_req_reg--;
  1574. ieee80211_queue_work(&local->hw, &local->reconfig_filter);
  1575. }
  1576. static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  1577. {
  1578. struct ieee80211_local *local = wiphy_priv(wiphy);
  1579. if (local->started)
  1580. return -EOPNOTSUPP;
  1581. return drv_set_antenna(local, tx_ant, rx_ant);
  1582. }
  1583. static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
  1584. {
  1585. struct ieee80211_local *local = wiphy_priv(wiphy);
  1586. return drv_get_antenna(local, tx_ant, rx_ant);
  1587. }
  1588. struct cfg80211_ops mac80211_config_ops = {
  1589. .add_virtual_intf = ieee80211_add_iface,
  1590. .del_virtual_intf = ieee80211_del_iface,
  1591. .change_virtual_intf = ieee80211_change_iface,
  1592. .add_key = ieee80211_add_key,
  1593. .del_key = ieee80211_del_key,
  1594. .get_key = ieee80211_get_key,
  1595. .set_default_key = ieee80211_config_default_key,
  1596. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  1597. .add_beacon = ieee80211_add_beacon,
  1598. .set_beacon = ieee80211_set_beacon,
  1599. .del_beacon = ieee80211_del_beacon,
  1600. .add_station = ieee80211_add_station,
  1601. .del_station = ieee80211_del_station,
  1602. .change_station = ieee80211_change_station,
  1603. .get_station = ieee80211_get_station,
  1604. .dump_station = ieee80211_dump_station,
  1605. .dump_survey = ieee80211_dump_survey,
  1606. #ifdef CONFIG_MAC80211_MESH
  1607. .add_mpath = ieee80211_add_mpath,
  1608. .del_mpath = ieee80211_del_mpath,
  1609. .change_mpath = ieee80211_change_mpath,
  1610. .get_mpath = ieee80211_get_mpath,
  1611. .dump_mpath = ieee80211_dump_mpath,
  1612. .update_mesh_config = ieee80211_update_mesh_config,
  1613. .get_mesh_config = ieee80211_get_mesh_config,
  1614. .join_mesh = ieee80211_join_mesh,
  1615. .leave_mesh = ieee80211_leave_mesh,
  1616. #endif
  1617. .change_bss = ieee80211_change_bss,
  1618. .set_txq_params = ieee80211_set_txq_params,
  1619. .set_channel = ieee80211_set_channel,
  1620. .suspend = ieee80211_suspend,
  1621. .resume = ieee80211_resume,
  1622. .scan = ieee80211_scan,
  1623. .auth = ieee80211_auth,
  1624. .assoc = ieee80211_assoc,
  1625. .deauth = ieee80211_deauth,
  1626. .disassoc = ieee80211_disassoc,
  1627. .join_ibss = ieee80211_join_ibss,
  1628. .leave_ibss = ieee80211_leave_ibss,
  1629. .set_wiphy_params = ieee80211_set_wiphy_params,
  1630. .set_tx_power = ieee80211_set_tx_power,
  1631. .get_tx_power = ieee80211_get_tx_power,
  1632. .set_wds_peer = ieee80211_set_wds_peer,
  1633. .rfkill_poll = ieee80211_rfkill_poll,
  1634. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  1635. .set_power_mgmt = ieee80211_set_power_mgmt,
  1636. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  1637. .remain_on_channel = ieee80211_remain_on_channel,
  1638. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  1639. .mgmt_tx = ieee80211_mgmt_tx,
  1640. .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
  1641. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  1642. .mgmt_frame_register = ieee80211_mgmt_frame_register,
  1643. .set_antenna = ieee80211_set_antenna,
  1644. .get_antenna = ieee80211_get_antenna,
  1645. };