cfg.c 41 KB

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