cfg.c 40 KB

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