cfg.c 41 KB

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