wireless.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. #ifndef __NET_WIRELESS_H
  2. #define __NET_WIRELESS_H
  3. /*
  4. * 802.11 device management
  5. *
  6. * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
  7. */
  8. #include <linux/netdevice.h>
  9. #include <linux/debugfs.h>
  10. #include <linux/list.h>
  11. #include <linux/ieee80211.h>
  12. #include <net/cfg80211.h>
  13. /**
  14. * enum ieee80211_band - supported frequency bands
  15. *
  16. * The bands are assigned this way because the supported
  17. * bitrates differ in these bands.
  18. *
  19. * @IEEE80211_BAND_2GHZ: 2.4GHz ISM band
  20. * @IEEE80211_BAND_5GHZ: around 5GHz band (4.9-5.7)
  21. */
  22. enum ieee80211_band {
  23. IEEE80211_BAND_2GHZ,
  24. IEEE80211_BAND_5GHZ,
  25. /* keep last */
  26. IEEE80211_NUM_BANDS
  27. };
  28. /**
  29. * enum ieee80211_channel_flags - channel flags
  30. *
  31. * Channel flags set by the regulatory control code.
  32. *
  33. * @IEEE80211_CHAN_DISABLED: This channel is disabled.
  34. * @IEEE80211_CHAN_PASSIVE_SCAN: Only passive scanning is permitted
  35. * on this channel.
  36. * @IEEE80211_CHAN_NO_IBSS: IBSS is not allowed on this channel.
  37. * @IEEE80211_CHAN_RADAR: Radar detection is required on this channel.
  38. * @IEEE80211_CHAN_NO_FAT_ABOVE: extension channel above this channel
  39. * is not permitted.
  40. * @IEEE80211_CHAN_NO_FAT_BELOW: extension channel below this channel
  41. * is not permitted.
  42. */
  43. enum ieee80211_channel_flags {
  44. IEEE80211_CHAN_DISABLED = 1<<0,
  45. IEEE80211_CHAN_PASSIVE_SCAN = 1<<1,
  46. IEEE80211_CHAN_NO_IBSS = 1<<2,
  47. IEEE80211_CHAN_RADAR = 1<<3,
  48. IEEE80211_CHAN_NO_FAT_ABOVE = 1<<4,
  49. IEEE80211_CHAN_NO_FAT_BELOW = 1<<5,
  50. };
  51. /**
  52. * struct ieee80211_channel - channel definition
  53. *
  54. * This structure describes a single channel for use
  55. * with cfg80211.
  56. *
  57. * @center_freq: center frequency in MHz
  58. * @max_bandwidth: maximum allowed bandwidth for this channel, in MHz
  59. * @hw_value: hardware-specific value for the channel
  60. * @flags: channel flags from &enum ieee80211_channel_flags.
  61. * @orig_flags: channel flags at registration time, used by regulatory
  62. * code to support devices with additional restrictions
  63. * @band: band this channel belongs to.
  64. * @max_antenna_gain: maximum antenna gain in dBi
  65. * @max_power: maximum transmission power (in dBm)
  66. * @beacon_found: helper to regulatory code to indicate when a beacon
  67. * has been found on this channel. Use regulatory_hint_found_beacon()
  68. * to enable this, this is is useful only on 5 GHz band.
  69. * @orig_mag: internal use
  70. * @orig_mpwr: internal use
  71. */
  72. struct ieee80211_channel {
  73. enum ieee80211_band band;
  74. u16 center_freq;
  75. u8 max_bandwidth;
  76. u16 hw_value;
  77. u32 flags;
  78. int max_antenna_gain;
  79. int max_power;
  80. bool beacon_found;
  81. u32 orig_flags;
  82. int orig_mag, orig_mpwr;
  83. };
  84. /**
  85. * enum ieee80211_rate_flags - rate flags
  86. *
  87. * Hardware/specification flags for rates. These are structured
  88. * in a way that allows using the same bitrate structure for
  89. * different bands/PHY modes.
  90. *
  91. * @IEEE80211_RATE_SHORT_PREAMBLE: Hardware can send with short
  92. * preamble on this bitrate; only relevant in 2.4GHz band and
  93. * with CCK rates.
  94. * @IEEE80211_RATE_MANDATORY_A: This bitrate is a mandatory rate
  95. * when used with 802.11a (on the 5 GHz band); filled by the
  96. * core code when registering the wiphy.
  97. * @IEEE80211_RATE_MANDATORY_B: This bitrate is a mandatory rate
  98. * when used with 802.11b (on the 2.4 GHz band); filled by the
  99. * core code when registering the wiphy.
  100. * @IEEE80211_RATE_MANDATORY_G: This bitrate is a mandatory rate
  101. * when used with 802.11g (on the 2.4 GHz band); filled by the
  102. * core code when registering the wiphy.
  103. * @IEEE80211_RATE_ERP_G: This is an ERP rate in 802.11g mode.
  104. */
  105. enum ieee80211_rate_flags {
  106. IEEE80211_RATE_SHORT_PREAMBLE = 1<<0,
  107. IEEE80211_RATE_MANDATORY_A = 1<<1,
  108. IEEE80211_RATE_MANDATORY_B = 1<<2,
  109. IEEE80211_RATE_MANDATORY_G = 1<<3,
  110. IEEE80211_RATE_ERP_G = 1<<4,
  111. };
  112. /**
  113. * struct ieee80211_rate - bitrate definition
  114. *
  115. * This structure describes a bitrate that an 802.11 PHY can
  116. * operate with. The two values @hw_value and @hw_value_short
  117. * are only for driver use when pointers to this structure are
  118. * passed around.
  119. *
  120. * @flags: rate-specific flags
  121. * @bitrate: bitrate in units of 100 Kbps
  122. * @hw_value: driver/hardware value for this rate
  123. * @hw_value_short: driver/hardware value for this rate when
  124. * short preamble is used
  125. */
  126. struct ieee80211_rate {
  127. u32 flags;
  128. u16 bitrate;
  129. u16 hw_value, hw_value_short;
  130. };
  131. /**
  132. * struct ieee80211_sta_ht_cap - STA's HT capabilities
  133. *
  134. * This structure describes most essential parameters needed
  135. * to describe 802.11n HT capabilities for an STA.
  136. *
  137. * @ht_supported: is HT supported by the STA
  138. * @cap: HT capabilities map as described in 802.11n spec
  139. * @ampdu_factor: Maximum A-MPDU length factor
  140. * @ampdu_density: Minimum A-MPDU spacing
  141. * @mcs: Supported MCS rates
  142. */
  143. struct ieee80211_sta_ht_cap {
  144. u16 cap; /* use IEEE80211_HT_CAP_ */
  145. bool ht_supported;
  146. u8 ampdu_factor;
  147. u8 ampdu_density;
  148. struct ieee80211_mcs_info mcs;
  149. };
  150. /**
  151. * struct ieee80211_supported_band - frequency band definition
  152. *
  153. * This structure describes a frequency band a wiphy
  154. * is able to operate in.
  155. *
  156. * @channels: Array of channels the hardware can operate in
  157. * in this band.
  158. * @band: the band this structure represents
  159. * @n_channels: Number of channels in @channels
  160. * @bitrates: Array of bitrates the hardware can operate with
  161. * in this band. Must be sorted to give a valid "supported
  162. * rates" IE, i.e. CCK rates first, then OFDM.
  163. * @n_bitrates: Number of bitrates in @bitrates
  164. */
  165. struct ieee80211_supported_band {
  166. struct ieee80211_channel *channels;
  167. struct ieee80211_rate *bitrates;
  168. enum ieee80211_band band;
  169. int n_channels;
  170. int n_bitrates;
  171. struct ieee80211_sta_ht_cap ht_cap;
  172. };
  173. /**
  174. * struct wiphy - wireless hardware description
  175. * @idx: the wiphy index assigned to this item
  176. * @class_dev: the class device representing /sys/class/ieee80211/<wiphy-name>
  177. * @custom_regulatory: tells us the driver for this device
  178. * has its own custom regulatory domain and cannot identify the
  179. * ISO / IEC 3166 alpha2 it belongs to. When this is enabled
  180. * we will disregard the first regulatory hint (when the
  181. * initiator is %REGDOM_SET_BY_CORE).
  182. * @strict_regulatory: tells us the driver for this device will ignore
  183. * regulatory domain settings until it gets its own regulatory domain
  184. * via its regulatory_hint(). After its gets its own regulatory domain
  185. * it will only allow further regulatory domain settings to further
  186. * enhance compliance. For example if channel 13 and 14 are disabled
  187. * by this regulatory domain no user regulatory domain can enable these
  188. * channels at a later time. This can be used for devices which do not
  189. * have calibration information gauranteed for frequencies or settings
  190. * outside of its regulatory domain.
  191. * @reg_notifier: the driver's regulatory notification callback
  192. * @regd: the driver's regulatory domain, if one was requested via
  193. * the regulatory_hint() API. This can be used by the driver
  194. * on the reg_notifier() if it chooses to ignore future
  195. * regulatory domain changes caused by other drivers.
  196. * @signal_type: signal type reported in &struct cfg80211_bss.
  197. * @cipher_suites: supported cipher suites
  198. * @n_cipher_suites: number of supported cipher suites
  199. */
  200. struct wiphy {
  201. /* assign these fields before you register the wiphy */
  202. /* permanent MAC address */
  203. u8 perm_addr[ETH_ALEN];
  204. /* Supported interface modes, OR together BIT(NL80211_IFTYPE_...) */
  205. u16 interface_modes;
  206. bool custom_regulatory;
  207. bool strict_regulatory;
  208. enum cfg80211_signal_type signal_type;
  209. int bss_priv_size;
  210. u8 max_scan_ssids;
  211. u16 max_scan_ie_len;
  212. int n_cipher_suites;
  213. const u32 *cipher_suites;
  214. /* If multiple wiphys are registered and you're handed e.g.
  215. * a regular netdev with assigned ieee80211_ptr, you won't
  216. * know whether it points to a wiphy your driver has registered
  217. * or not. Assign this to something global to your driver to
  218. * help determine whether you own this wiphy or not. */
  219. void *privid;
  220. struct ieee80211_supported_band *bands[IEEE80211_NUM_BANDS];
  221. /* Lets us get back the wiphy on the callback */
  222. int (*reg_notifier)(struct wiphy *wiphy,
  223. struct regulatory_request *request);
  224. /* fields below are read-only, assigned by cfg80211 */
  225. const struct ieee80211_regdomain *regd;
  226. /* the item in /sys/class/ieee80211/ points to this,
  227. * you need use set_wiphy_dev() (see below) */
  228. struct device dev;
  229. /* dir in debugfs: ieee80211/<wiphyname> */
  230. struct dentry *debugfsdir;
  231. char priv[0] __attribute__((__aligned__(NETDEV_ALIGN)));
  232. };
  233. /** struct wireless_dev - wireless per-netdev state
  234. *
  235. * This structure must be allocated by the driver/stack
  236. * that uses the ieee80211_ptr field in struct net_device
  237. * (this is intentional so it can be allocated along with
  238. * the netdev.)
  239. *
  240. * @wiphy: pointer to hardware description
  241. * @iftype: interface type
  242. * @list: (private)
  243. * @netdev (private)
  244. */
  245. struct wireless_dev {
  246. struct wiphy *wiphy;
  247. enum nl80211_iftype iftype;
  248. /* private to the generic wireless code */
  249. struct list_head list;
  250. struct net_device *netdev;
  251. /* currently used for IBSS - might be rearranged in the future */
  252. struct cfg80211_bss *current_bss;
  253. u8 bssid[ETH_ALEN];
  254. u8 ssid[IEEE80211_MAX_SSID_LEN];
  255. u8 ssid_len;
  256. #ifdef CONFIG_WIRELESS_EXT
  257. /* wext data */
  258. struct cfg80211_ibss_params wext;
  259. u8 wext_bssid[ETH_ALEN];
  260. #endif
  261. };
  262. /**
  263. * wiphy_priv - return priv from wiphy
  264. */
  265. static inline void *wiphy_priv(struct wiphy *wiphy)
  266. {
  267. BUG_ON(!wiphy);
  268. return &wiphy->priv;
  269. }
  270. /**
  271. * set_wiphy_dev - set device pointer for wiphy
  272. */
  273. static inline void set_wiphy_dev(struct wiphy *wiphy, struct device *dev)
  274. {
  275. wiphy->dev.parent = dev;
  276. }
  277. /**
  278. * wiphy_dev - get wiphy dev pointer
  279. */
  280. static inline struct device *wiphy_dev(struct wiphy *wiphy)
  281. {
  282. return wiphy->dev.parent;
  283. }
  284. /**
  285. * wiphy_name - get wiphy name
  286. */
  287. static inline const char *wiphy_name(struct wiphy *wiphy)
  288. {
  289. return dev_name(&wiphy->dev);
  290. }
  291. /**
  292. * wdev_priv - return wiphy priv from wireless_dev
  293. */
  294. static inline void *wdev_priv(struct wireless_dev *wdev)
  295. {
  296. BUG_ON(!wdev);
  297. return wiphy_priv(wdev->wiphy);
  298. }
  299. /**
  300. * wiphy_new - create a new wiphy for use with cfg80211
  301. *
  302. * create a new wiphy and associate the given operations with it.
  303. * @sizeof_priv bytes are allocated for private use.
  304. *
  305. * the returned pointer must be assigned to each netdev's
  306. * ieee80211_ptr for proper operation.
  307. */
  308. struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv);
  309. /**
  310. * wiphy_register - register a wiphy with cfg80211
  311. *
  312. * register the given wiphy
  313. *
  314. * Returns a non-negative wiphy index or a negative error code.
  315. */
  316. extern int wiphy_register(struct wiphy *wiphy);
  317. /**
  318. * wiphy_unregister - deregister a wiphy from cfg80211
  319. *
  320. * unregister a device with the given priv pointer.
  321. * After this call, no more requests can be made with this priv
  322. * pointer, but the call may sleep to wait for an outstanding
  323. * request that is being handled.
  324. */
  325. extern void wiphy_unregister(struct wiphy *wiphy);
  326. /**
  327. * wiphy_free - free wiphy
  328. */
  329. extern void wiphy_free(struct wiphy *wiphy);
  330. /**
  331. * ieee80211_channel_to_frequency - convert channel number to frequency
  332. */
  333. extern int ieee80211_channel_to_frequency(int chan);
  334. /**
  335. * ieee80211_frequency_to_channel - convert frequency to channel number
  336. */
  337. extern int ieee80211_frequency_to_channel(int freq);
  338. /*
  339. * Name indirection necessary because the ieee80211 code also has
  340. * a function named "ieee80211_get_channel", so if you include
  341. * cfg80211's header file you get cfg80211's version, if you try
  342. * to include both header files you'll (rightfully!) get a symbol
  343. * clash.
  344. */
  345. extern struct ieee80211_channel *__ieee80211_get_channel(struct wiphy *wiphy,
  346. int freq);
  347. /**
  348. * ieee80211_get_channel - get channel struct from wiphy for specified frequency
  349. */
  350. static inline struct ieee80211_channel *
  351. ieee80211_get_channel(struct wiphy *wiphy, int freq)
  352. {
  353. return __ieee80211_get_channel(wiphy, freq);
  354. }
  355. /**
  356. * ieee80211_get_response_rate - get basic rate for a given rate
  357. *
  358. * @sband: the band to look for rates in
  359. * @basic_rates: bitmap of basic rates
  360. * @bitrate: the bitrate for which to find the basic rate
  361. *
  362. * This function returns the basic rate corresponding to a given
  363. * bitrate, that is the next lower bitrate contained in the basic
  364. * rate map, which is, for this function, given as a bitmap of
  365. * indices of rates in the band's bitrate table.
  366. */
  367. struct ieee80211_rate *
  368. ieee80211_get_response_rate(struct ieee80211_supported_band *sband,
  369. u32 basic_rates, int bitrate);
  370. /**
  371. * regulatory_hint - driver hint to the wireless core a regulatory domain
  372. * @wiphy: the wireless device giving the hint (used only for reporting
  373. * conflicts)
  374. * @alpha2: the ISO/IEC 3166 alpha2 the driver claims its regulatory domain
  375. * should be in. If @rd is set this should be NULL. Note that if you
  376. * set this to NULL you should still set rd->alpha2 to some accepted
  377. * alpha2.
  378. *
  379. * Wireless drivers can use this function to hint to the wireless core
  380. * what it believes should be the current regulatory domain by
  381. * giving it an ISO/IEC 3166 alpha2 country code it knows its regulatory
  382. * domain should be in or by providing a completely build regulatory domain.
  383. * If the driver provides an ISO/IEC 3166 alpha2 userspace will be queried
  384. * for a regulatory domain structure for the respective country.
  385. *
  386. * The wiphy must have been registered to cfg80211 prior to this call.
  387. * For cfg80211 drivers this means you must first use wiphy_register(),
  388. * for mac80211 drivers you must first use ieee80211_register_hw().
  389. *
  390. * Drivers should check the return value, its possible you can get
  391. * an -ENOMEM.
  392. */
  393. extern int regulatory_hint(struct wiphy *wiphy, const char *alpha2);
  394. /**
  395. * regulatory_hint_11d - hints a country IE as a regulatory domain
  396. * @wiphy: the wireless device giving the hint (used only for reporting
  397. * conflicts)
  398. * @country_ie: pointer to the country IE
  399. * @country_ie_len: length of the country IE
  400. *
  401. * We will intersect the rd with the what CRDA tells us should apply
  402. * for the alpha2 this country IE belongs to, this prevents APs from
  403. * sending us incorrect or outdated information against a country.
  404. */
  405. extern void regulatory_hint_11d(struct wiphy *wiphy,
  406. u8 *country_ie,
  407. u8 country_ie_len);
  408. /**
  409. * wiphy_apply_custom_regulatory - apply a custom driver regulatory domain
  410. * @wiphy: the wireless device we want to process the regulatory domain on
  411. * @regd: the custom regulatory domain to use for this wiphy
  412. *
  413. * Drivers can sometimes have custom regulatory domains which do not apply
  414. * to a specific country. Drivers can use this to apply such custom regulatory
  415. * domains. This routine must be called prior to wiphy registration. The
  416. * custom regulatory domain will be trusted completely and as such previous
  417. * default channel settings will be disregarded. If no rule is found for a
  418. * channel on the regulatory domain the channel will be disabled.
  419. */
  420. extern void wiphy_apply_custom_regulatory(
  421. struct wiphy *wiphy,
  422. const struct ieee80211_regdomain *regd);
  423. /**
  424. * freq_reg_info - get regulatory information for the given frequency
  425. * @wiphy: the wiphy for which we want to process this rule for
  426. * @center_freq: Frequency in KHz for which we want regulatory information for
  427. * @bandwidth: the bandwidth requirement you have in KHz, if you do not have one
  428. * you can set this to 0. If this frequency is allowed we then set
  429. * this value to the maximum allowed bandwidth.
  430. * @reg_rule: the regulatory rule which we have for this frequency
  431. *
  432. * Use this function to get the regulatory rule for a specific frequency on
  433. * a given wireless device. If the device has a specific regulatory domain
  434. * it wants to follow we respect that unless a country IE has been received
  435. * and processed already.
  436. *
  437. * Returns 0 if it was able to find a valid regulatory rule which does
  438. * apply to the given center_freq otherwise it returns non-zero. It will
  439. * also return -ERANGE if we determine the given center_freq does not even have
  440. * a regulatory rule for a frequency range in the center_freq's band. See
  441. * freq_in_rule_band() for our current definition of a band -- this is purely
  442. * subjective and right now its 802.11 specific.
  443. */
  444. extern int freq_reg_info(struct wiphy *wiphy, u32 center_freq, u32 *bandwidth,
  445. const struct ieee80211_reg_rule **reg_rule);
  446. #endif /* __NET_WIRELESS_H */