cfg.c 41 KB

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