cfg.c 55 KB

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