wireless.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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. * @orig_mag: internal use
  67. * @orig_mpwr: internal use
  68. */
  69. struct ieee80211_channel {
  70. enum ieee80211_band band;
  71. u16 center_freq;
  72. u8 max_bandwidth;
  73. u16 hw_value;
  74. u32 flags;
  75. int max_antenna_gain;
  76. int max_power;
  77. u32 orig_flags;
  78. int orig_mag, orig_mpwr;
  79. };
  80. /**
  81. * enum ieee80211_rate_flags - rate flags
  82. *
  83. * Hardware/specification flags for rates. These are structured
  84. * in a way that allows using the same bitrate structure for
  85. * different bands/PHY modes.
  86. *
  87. * @IEEE80211_RATE_SHORT_PREAMBLE: Hardware can send with short
  88. * preamble on this bitrate; only relevant in 2.4GHz band and
  89. * with CCK rates.
  90. * @IEEE80211_RATE_MANDATORY_A: This bitrate is a mandatory rate
  91. * when used with 802.11a (on the 5 GHz band); filled by the
  92. * core code when registering the wiphy.
  93. * @IEEE80211_RATE_MANDATORY_B: This bitrate is a mandatory rate
  94. * when used with 802.11b (on the 2.4 GHz band); filled by the
  95. * core code when registering the wiphy.
  96. * @IEEE80211_RATE_MANDATORY_G: This bitrate is a mandatory rate
  97. * when used with 802.11g (on the 2.4 GHz band); filled by the
  98. * core code when registering the wiphy.
  99. * @IEEE80211_RATE_ERP_G: This is an ERP rate in 802.11g mode.
  100. */
  101. enum ieee80211_rate_flags {
  102. IEEE80211_RATE_SHORT_PREAMBLE = 1<<0,
  103. IEEE80211_RATE_MANDATORY_A = 1<<1,
  104. IEEE80211_RATE_MANDATORY_B = 1<<2,
  105. IEEE80211_RATE_MANDATORY_G = 1<<3,
  106. IEEE80211_RATE_ERP_G = 1<<4,
  107. };
  108. /**
  109. * struct ieee80211_rate - bitrate definition
  110. *
  111. * This structure describes a bitrate that an 802.11 PHY can
  112. * operate with. The two values @hw_value and @hw_value_short
  113. * are only for driver use when pointers to this structure are
  114. * passed around.
  115. *
  116. * @flags: rate-specific flags
  117. * @bitrate: bitrate in units of 100 Kbps
  118. * @hw_value: driver/hardware value for this rate
  119. * @hw_value_short: driver/hardware value for this rate when
  120. * short preamble is used
  121. */
  122. struct ieee80211_rate {
  123. u32 flags;
  124. u16 bitrate;
  125. u16 hw_value, hw_value_short;
  126. };
  127. /**
  128. * struct ieee80211_sta_ht_cap - STA's HT capabilities
  129. *
  130. * This structure describes most essential parameters needed
  131. * to describe 802.11n HT capabilities for an STA.
  132. *
  133. * @ht_supported: is HT supported by the STA
  134. * @cap: HT capabilities map as described in 802.11n spec
  135. * @ampdu_factor: Maximum A-MPDU length factor
  136. * @ampdu_density: Minimum A-MPDU spacing
  137. * @mcs: Supported MCS rates
  138. */
  139. struct ieee80211_sta_ht_cap {
  140. u16 cap; /* use IEEE80211_HT_CAP_ */
  141. bool ht_supported;
  142. u8 ampdu_factor;
  143. u8 ampdu_density;
  144. struct ieee80211_mcs_info mcs;
  145. };
  146. /**
  147. * struct ieee80211_supported_band - frequency band definition
  148. *
  149. * This structure describes a frequency band a wiphy
  150. * is able to operate in.
  151. *
  152. * @channels: Array of channels the hardware can operate in
  153. * in this band.
  154. * @band: the band this structure represents
  155. * @n_channels: Number of channels in @channels
  156. * @bitrates: Array of bitrates the hardware can operate with
  157. * in this band. Must be sorted to give a valid "supported
  158. * rates" IE, i.e. CCK rates first, then OFDM.
  159. * @n_bitrates: Number of bitrates in @bitrates
  160. */
  161. struct ieee80211_supported_band {
  162. struct ieee80211_channel *channels;
  163. struct ieee80211_rate *bitrates;
  164. enum ieee80211_band band;
  165. int n_channels;
  166. int n_bitrates;
  167. struct ieee80211_sta_ht_cap ht_cap;
  168. };
  169. /**
  170. * struct wiphy - wireless hardware description
  171. * @idx: the wiphy index assigned to this item
  172. * @class_dev: the class device representing /sys/class/ieee80211/<wiphy-name>
  173. * @fw_handles_regulatory: tells us the firmware for this device
  174. * has its own regulatory solution and cannot identify the
  175. * ISO / IEC 3166 alpha2 it belongs to. When this is enabled
  176. * we will disregard the first regulatory hint (when the
  177. * initiator is %REGDOM_SET_BY_CORE).
  178. * @reg_notifier: the driver's regulatory notification callback
  179. */
  180. struct wiphy {
  181. /* assign these fields before you register the wiphy */
  182. /* permanent MAC address */
  183. u8 perm_addr[ETH_ALEN];
  184. /* Supported interface modes, OR together BIT(NL80211_IFTYPE_...) */
  185. u16 interface_modes;
  186. bool fw_handles_regulatory;
  187. /* If multiple wiphys are registered and you're handed e.g.
  188. * a regular netdev with assigned ieee80211_ptr, you won't
  189. * know whether it points to a wiphy your driver has registered
  190. * or not. Assign this to something global to your driver to
  191. * help determine whether you own this wiphy or not. */
  192. void *privid;
  193. struct ieee80211_supported_band *bands[IEEE80211_NUM_BANDS];
  194. /* Lets us get back the wiphy on the callback */
  195. int (*reg_notifier)(struct wiphy *wiphy, enum reg_set_by setby);
  196. /* fields below are read-only, assigned by cfg80211 */
  197. /* the item in /sys/class/ieee80211/ points to this,
  198. * you need use set_wiphy_dev() (see below) */
  199. struct device dev;
  200. /* dir in debugfs: ieee80211/<wiphyname> */
  201. struct dentry *debugfsdir;
  202. char priv[0] __attribute__((__aligned__(NETDEV_ALIGN)));
  203. };
  204. /** struct wireless_dev - wireless per-netdev state
  205. *
  206. * This structure must be allocated by the driver/stack
  207. * that uses the ieee80211_ptr field in struct net_device
  208. * (this is intentional so it can be allocated along with
  209. * the netdev.)
  210. *
  211. * @wiphy: pointer to hardware description
  212. * @iftype: interface type
  213. */
  214. struct wireless_dev {
  215. struct wiphy *wiphy;
  216. enum nl80211_iftype iftype;
  217. /* private to the generic wireless code */
  218. struct list_head list;
  219. struct net_device *netdev;
  220. };
  221. /**
  222. * wiphy_priv - return priv from wiphy
  223. */
  224. static inline void *wiphy_priv(struct wiphy *wiphy)
  225. {
  226. BUG_ON(!wiphy);
  227. return &wiphy->priv;
  228. }
  229. /**
  230. * set_wiphy_dev - set device pointer for wiphy
  231. */
  232. static inline void set_wiphy_dev(struct wiphy *wiphy, struct device *dev)
  233. {
  234. wiphy->dev.parent = dev;
  235. }
  236. /**
  237. * wiphy_dev - get wiphy dev pointer
  238. */
  239. static inline struct device *wiphy_dev(struct wiphy *wiphy)
  240. {
  241. return wiphy->dev.parent;
  242. }
  243. /**
  244. * wiphy_name - get wiphy name
  245. */
  246. static inline const char *wiphy_name(struct wiphy *wiphy)
  247. {
  248. return dev_name(&wiphy->dev);
  249. }
  250. /**
  251. * wdev_priv - return wiphy priv from wireless_dev
  252. */
  253. static inline void *wdev_priv(struct wireless_dev *wdev)
  254. {
  255. BUG_ON(!wdev);
  256. return wiphy_priv(wdev->wiphy);
  257. }
  258. /**
  259. * wiphy_new - create a new wiphy for use with cfg80211
  260. *
  261. * create a new wiphy and associate the given operations with it.
  262. * @sizeof_priv bytes are allocated for private use.
  263. *
  264. * the returned pointer must be assigned to each netdev's
  265. * ieee80211_ptr for proper operation.
  266. */
  267. struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv);
  268. /**
  269. * wiphy_register - register a wiphy with cfg80211
  270. *
  271. * register the given wiphy
  272. *
  273. * Returns a non-negative wiphy index or a negative error code.
  274. */
  275. extern int wiphy_register(struct wiphy *wiphy);
  276. /**
  277. * wiphy_unregister - deregister a wiphy from cfg80211
  278. *
  279. * unregister a device with the given priv pointer.
  280. * After this call, no more requests can be made with this priv
  281. * pointer, but the call may sleep to wait for an outstanding
  282. * request that is being handled.
  283. */
  284. extern void wiphy_unregister(struct wiphy *wiphy);
  285. /**
  286. * wiphy_free - free wiphy
  287. */
  288. extern void wiphy_free(struct wiphy *wiphy);
  289. /**
  290. * ieee80211_channel_to_frequency - convert channel number to frequency
  291. */
  292. extern int ieee80211_channel_to_frequency(int chan);
  293. /**
  294. * ieee80211_frequency_to_channel - convert frequency to channel number
  295. */
  296. extern int ieee80211_frequency_to_channel(int freq);
  297. /*
  298. * Name indirection necessary because the ieee80211 code also has
  299. * a function named "ieee80211_get_channel", so if you include
  300. * cfg80211's header file you get cfg80211's version, if you try
  301. * to include both header files you'll (rightfully!) get a symbol
  302. * clash.
  303. */
  304. extern struct ieee80211_channel *__ieee80211_get_channel(struct wiphy *wiphy,
  305. int freq);
  306. /**
  307. * ieee80211_get_channel - get channel struct from wiphy for specified frequency
  308. */
  309. static inline struct ieee80211_channel *
  310. ieee80211_get_channel(struct wiphy *wiphy, int freq)
  311. {
  312. return __ieee80211_get_channel(wiphy, freq);
  313. }
  314. /**
  315. * ieee80211_get_response_rate - get basic rate for a given rate
  316. *
  317. * @sband: the band to look for rates in
  318. * @basic_rates: bitmap of basic rates
  319. * @bitrate: the bitrate for which to find the basic rate
  320. *
  321. * This function returns the basic rate corresponding to a given
  322. * bitrate, that is the next lower bitrate contained in the basic
  323. * rate map, which is, for this function, given as a bitmap of
  324. * indices of rates in the band's bitrate table.
  325. */
  326. struct ieee80211_rate *
  327. ieee80211_get_response_rate(struct ieee80211_supported_band *sband,
  328. u64 basic_rates, int bitrate);
  329. /**
  330. * regulatory_hint - driver hint to the wireless core a regulatory domain
  331. * @wiphy: the wireless device giving the hint (used only for reporting
  332. * conflicts)
  333. * @alpha2: the ISO/IEC 3166 alpha2 the driver claims its regulatory domain
  334. * should be in. If @rd is set this should be NULL. Note that if you
  335. * set this to NULL you should still set rd->alpha2 to some accepted
  336. * alpha2.
  337. *
  338. * Wireless drivers can use this function to hint to the wireless core
  339. * what it believes should be the current regulatory domain by
  340. * giving it an ISO/IEC 3166 alpha2 country code it knows its regulatory
  341. * domain should be in or by providing a completely build regulatory domain.
  342. * If the driver provides an ISO/IEC 3166 alpha2 userspace will be queried
  343. * for a regulatory domain structure for the respective country.
  344. */
  345. extern void regulatory_hint(struct wiphy *wiphy, const char *alpha2);
  346. /**
  347. * regulatory_hint_11d - hints a country IE as a regulatory domain
  348. * @wiphy: the wireless device giving the hint (used only for reporting
  349. * conflicts)
  350. * @country_ie: pointer to the country IE
  351. * @country_ie_len: length of the country IE
  352. *
  353. * We will intersect the rd with the what CRDA tells us should apply
  354. * for the alpha2 this country IE belongs to, this prevents APs from
  355. * sending us incorrect or outdated information against a country.
  356. */
  357. extern void regulatory_hint_11d(struct wiphy *wiphy,
  358. u8 *country_ie,
  359. u8 country_ie_len);
  360. #endif /* __NET_WIRELESS_H */