wireless.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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 <net/cfg80211.h>
  12. /**
  13. * enum ieee80211_band - supported frequency bands
  14. *
  15. * The bands are assigned this way because the supported
  16. * bitrates differ in these bands.
  17. *
  18. * @IEEE80211_BAND_2GHZ: 2.4GHz ISM band
  19. * @IEEE80211_BAND_5GHZ: around 5GHz band (4.9-5.7)
  20. */
  21. enum ieee80211_band {
  22. IEEE80211_BAND_2GHZ,
  23. IEEE80211_BAND_5GHZ,
  24. /* keep last */
  25. IEEE80211_NUM_BANDS
  26. };
  27. /**
  28. * enum ieee80211_channel_flags - channel flags
  29. *
  30. * Channel flags set by the regulatory control code.
  31. *
  32. * @IEEE80211_CHAN_DISABLED: This channel is disabled.
  33. * @IEEE80211_CHAN_PASSIVE_SCAN: Only passive scanning is permitted
  34. * on this channel.
  35. * @IEEE80211_CHAN_NO_IBSS: IBSS is not allowed on this channel.
  36. * @IEEE80211_CHAN_RADAR: Radar detection is required on this channel.
  37. * @IEEE80211_CHAN_NO_FAT_ABOVE: extension channel above this channel
  38. * is not permitted.
  39. * @IEEE80211_CHAN_NO_FAT_BELOW: extension channel below this channel
  40. * is not permitted.
  41. */
  42. enum ieee80211_channel_flags {
  43. IEEE80211_CHAN_DISABLED = 1<<0,
  44. IEEE80211_CHAN_PASSIVE_SCAN = 1<<1,
  45. IEEE80211_CHAN_NO_IBSS = 1<<2,
  46. IEEE80211_CHAN_RADAR = 1<<3,
  47. IEEE80211_CHAN_NO_FAT_ABOVE = 1<<4,
  48. IEEE80211_CHAN_NO_FAT_BELOW = 1<<5,
  49. };
  50. /**
  51. * struct ieee80211_channel - channel definition
  52. *
  53. * This structure describes a single channel for use
  54. * with cfg80211.
  55. *
  56. * @center_freq: center frequency in MHz
  57. * @max_bandwidth: maximum allowed bandwidth for this channel, in MHz
  58. * @hw_value: hardware-specific value for the channel
  59. * @flags: channel flags from &enum ieee80211_channel_flags.
  60. * @orig_flags: channel flags at registration time, used by regulatory
  61. * code to support devices with additional restrictions
  62. * @band: band this channel belongs to.
  63. * @max_antenna_gain: maximum antenna gain in dBi
  64. * @max_power: maximum transmission power (in dBm)
  65. * @orig_mag: internal use
  66. * @orig_mpwr: internal use
  67. */
  68. struct ieee80211_channel {
  69. enum ieee80211_band band;
  70. u16 center_freq;
  71. u8 max_bandwidth;
  72. u16 hw_value;
  73. u32 flags;
  74. int max_antenna_gain;
  75. int max_power;
  76. u32 orig_flags;
  77. int orig_mag, orig_mpwr;
  78. };
  79. /**
  80. * enum ieee80211_rate_flags - rate flags
  81. *
  82. * Hardware/specification flags for rates. These are structured
  83. * in a way that allows using the same bitrate structure for
  84. * different bands/PHY modes.
  85. *
  86. * @IEEE80211_RATE_SHORT_PREAMBLE: Hardware can send with short
  87. * preamble on this bitrate; only relevant in 2.4GHz band and
  88. * with CCK rates.
  89. * @IEEE80211_RATE_MANDATORY_A: This bitrate is a mandatory rate
  90. * when used with 802.11a (on the 5 GHz band); filled by the
  91. * core code when registering the wiphy.
  92. * @IEEE80211_RATE_MANDATORY_B: This bitrate is a mandatory rate
  93. * when used with 802.11b (on the 2.4 GHz band); filled by the
  94. * core code when registering the wiphy.
  95. * @IEEE80211_RATE_MANDATORY_G: This bitrate is a mandatory rate
  96. * when used with 802.11g (on the 2.4 GHz band); filled by the
  97. * core code when registering the wiphy.
  98. * @IEEE80211_RATE_ERP_G: This is an ERP rate in 802.11g mode.
  99. */
  100. enum ieee80211_rate_flags {
  101. IEEE80211_RATE_SHORT_PREAMBLE = 1<<0,
  102. IEEE80211_RATE_MANDATORY_A = 1<<1,
  103. IEEE80211_RATE_MANDATORY_B = 1<<2,
  104. IEEE80211_RATE_MANDATORY_G = 1<<3,
  105. IEEE80211_RATE_ERP_G = 1<<4,
  106. };
  107. /**
  108. * struct ieee80211_rate - bitrate definition
  109. *
  110. * This structure describes a bitrate that an 802.11 PHY can
  111. * operate with. The two values @hw_value and @hw_value_short
  112. * are only for driver use when pointers to this structure are
  113. * passed around.
  114. *
  115. * @flags: rate-specific flags
  116. * @bitrate: bitrate in units of 100 Kbps
  117. * @hw_value: driver/hardware value for this rate
  118. * @hw_value_short: driver/hardware value for this rate when
  119. * short preamble is used
  120. */
  121. struct ieee80211_rate {
  122. u32 flags;
  123. u16 bitrate;
  124. u16 hw_value, hw_value_short;
  125. };
  126. /**
  127. * struct ieee80211_ht_info - describing STA's HT capabilities
  128. *
  129. * This structure describes most essential parameters needed
  130. * to describe 802.11n HT capabilities for an STA.
  131. *
  132. * @ht_supported: is HT supported by STA, 0: no, 1: yes
  133. * @cap: HT capabilities map as described in 802.11n spec
  134. * @ampdu_factor: Maximum A-MPDU length factor
  135. * @ampdu_density: Minimum A-MPDU spacing
  136. * @supp_mcs_set: Supported MCS set as described in 802.11n spec
  137. */
  138. struct ieee80211_ht_info {
  139. u16 cap; /* use IEEE80211_HT_CAP_ */
  140. u8 ht_supported;
  141. u8 ampdu_factor;
  142. u8 ampdu_density;
  143. u8 supp_mcs_set[16];
  144. };
  145. /**
  146. * struct ieee80211_supported_band - frequency band definition
  147. *
  148. * This structure describes a frequency band a wiphy
  149. * is able to operate in.
  150. *
  151. * @channels: Array of channels the hardware can operate in
  152. * in this band.
  153. * @band: the band this structure represents
  154. * @n_channels: Number of channels in @channels
  155. * @bitrates: Array of bitrates the hardware can operate with
  156. * in this band. Must be sorted to give a valid "supported
  157. * rates" IE, i.e. CCK rates first, then OFDM.
  158. * @n_bitrates: Number of bitrates in @bitrates
  159. */
  160. struct ieee80211_supported_band {
  161. struct ieee80211_channel *channels;
  162. struct ieee80211_rate *bitrates;
  163. enum ieee80211_band band;
  164. int n_channels;
  165. int n_bitrates;
  166. struct ieee80211_ht_info ht_info;
  167. };
  168. /**
  169. * struct wiphy - wireless hardware description
  170. * @idx: the wiphy index assigned to this item
  171. * @class_dev: the class device representing /sys/class/ieee80211/<wiphy-name>
  172. * @reg_notifier: the driver's regulatory notification callback
  173. */
  174. struct wiphy {
  175. /* assign these fields before you register the wiphy */
  176. /* permanent MAC address */
  177. u8 perm_addr[ETH_ALEN];
  178. /* Supported interface modes, OR together BIT(NL80211_IFTYPE_...) */
  179. u16 interface_modes;
  180. /* If multiple wiphys are registered and you're handed e.g.
  181. * a regular netdev with assigned ieee80211_ptr, you won't
  182. * know whether it points to a wiphy your driver has registered
  183. * or not. Assign this to something global to your driver to
  184. * help determine whether you own this wiphy or not. */
  185. void *privid;
  186. struct ieee80211_supported_band *bands[IEEE80211_NUM_BANDS];
  187. /* Lets us get back the wiphy on the callback */
  188. int (*reg_notifier)(struct wiphy *wiphy, enum reg_set_by setby);
  189. /* fields below are read-only, assigned by cfg80211 */
  190. /* the item in /sys/class/ieee80211/ points to this,
  191. * you need use set_wiphy_dev() (see below) */
  192. struct device dev;
  193. /* dir in debugfs: ieee80211/<wiphyname> */
  194. struct dentry *debugfsdir;
  195. char priv[0] __attribute__((__aligned__(NETDEV_ALIGN)));
  196. };
  197. /** struct wireless_dev - wireless per-netdev state
  198. *
  199. * This structure must be allocated by the driver/stack
  200. * that uses the ieee80211_ptr field in struct net_device
  201. * (this is intentional so it can be allocated along with
  202. * the netdev.)
  203. *
  204. * @wiphy: pointer to hardware description
  205. * @iftype: interface type
  206. */
  207. struct wireless_dev {
  208. struct wiphy *wiphy;
  209. enum nl80211_iftype iftype;
  210. /* private to the generic wireless code */
  211. struct list_head list;
  212. struct net_device *netdev;
  213. };
  214. /**
  215. * wiphy_priv - return priv from wiphy
  216. */
  217. static inline void *wiphy_priv(struct wiphy *wiphy)
  218. {
  219. BUG_ON(!wiphy);
  220. return &wiphy->priv;
  221. }
  222. /**
  223. * set_wiphy_dev - set device pointer for wiphy
  224. */
  225. static inline void set_wiphy_dev(struct wiphy *wiphy, struct device *dev)
  226. {
  227. wiphy->dev.parent = dev;
  228. }
  229. /**
  230. * wiphy_dev - get wiphy dev pointer
  231. */
  232. static inline struct device *wiphy_dev(struct wiphy *wiphy)
  233. {
  234. return wiphy->dev.parent;
  235. }
  236. /**
  237. * wiphy_name - get wiphy name
  238. */
  239. static inline char *wiphy_name(struct wiphy *wiphy)
  240. {
  241. return wiphy->dev.bus_id;
  242. }
  243. /**
  244. * wdev_priv - return wiphy priv from wireless_dev
  245. */
  246. static inline void *wdev_priv(struct wireless_dev *wdev)
  247. {
  248. BUG_ON(!wdev);
  249. return wiphy_priv(wdev->wiphy);
  250. }
  251. /**
  252. * wiphy_new - create a new wiphy for use with cfg80211
  253. *
  254. * create a new wiphy and associate the given operations with it.
  255. * @sizeof_priv bytes are allocated for private use.
  256. *
  257. * the returned pointer must be assigned to each netdev's
  258. * ieee80211_ptr for proper operation.
  259. */
  260. struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv);
  261. /**
  262. * wiphy_register - register a wiphy with cfg80211
  263. *
  264. * register the given wiphy
  265. *
  266. * Returns a non-negative wiphy index or a negative error code.
  267. */
  268. extern int wiphy_register(struct wiphy *wiphy);
  269. /**
  270. * wiphy_unregister - deregister a wiphy from cfg80211
  271. *
  272. * unregister a device with the given priv pointer.
  273. * After this call, no more requests can be made with this priv
  274. * pointer, but the call may sleep to wait for an outstanding
  275. * request that is being handled.
  276. */
  277. extern void wiphy_unregister(struct wiphy *wiphy);
  278. /**
  279. * wiphy_free - free wiphy
  280. */
  281. extern void wiphy_free(struct wiphy *wiphy);
  282. /**
  283. * ieee80211_channel_to_frequency - convert channel number to frequency
  284. */
  285. extern int ieee80211_channel_to_frequency(int chan);
  286. /**
  287. * ieee80211_frequency_to_channel - convert frequency to channel number
  288. */
  289. extern int ieee80211_frequency_to_channel(int freq);
  290. /*
  291. * Name indirection necessary because the ieee80211 code also has
  292. * a function named "ieee80211_get_channel", so if you include
  293. * cfg80211's header file you get cfg80211's version, if you try
  294. * to include both header files you'll (rightfully!) get a symbol
  295. * clash.
  296. */
  297. extern struct ieee80211_channel *__ieee80211_get_channel(struct wiphy *wiphy,
  298. int freq);
  299. /**
  300. * ieee80211_get_channel - get channel struct from wiphy for specified frequency
  301. */
  302. static inline struct ieee80211_channel *
  303. ieee80211_get_channel(struct wiphy *wiphy, int freq)
  304. {
  305. return __ieee80211_get_channel(wiphy, freq);
  306. }
  307. /**
  308. * __regulatory_hint - hint to the wireless core a regulatory domain
  309. * @wiphy: if a driver is providing the hint this is the driver's very
  310. * own &struct wiphy
  311. * @alpha2: the ISO/IEC 3166 alpha2 being claimed the regulatory domain
  312. * should be in. If @rd is set this should be NULL
  313. * @rd: a complete regulatory domain, if passed the caller need not worry
  314. * about freeing it
  315. *
  316. * The Wireless subsystem can use this function to hint to the wireless core
  317. * what it believes should be the current regulatory domain by
  318. * giving it an ISO/IEC 3166 alpha2 country code it knows its regulatory
  319. * domain should be in or by providing a completely build regulatory domain.
  320. *
  321. * Returns -EALREADY if *a regulatory domain* has already been set. Note that
  322. * this could be by another driver. It is safe for drivers to continue if
  323. * -EALREADY is returned, if drivers are not capable of world roaming they
  324. * should not register more channels than they support. Right now we only
  325. * support listening to the first driver hint. If the driver is capable
  326. * of world roaming but wants to respect its own EEPROM mappings for
  327. * specific regulatory domains it should register the @reg_notifier callback
  328. * on the &struct wiphy. Returns 0 if the hint went through fine or through an
  329. * intersection operation. Otherwise a standard error code is returned.
  330. *
  331. */
  332. extern int __regulatory_hint(struct wiphy *wiphy, enum reg_set_by set_by,
  333. const char *alpha2, struct ieee80211_regdomain *rd);
  334. /**
  335. * regulatory_hint - driver hint to the wireless core a regulatory domain
  336. * @wiphy: the driver's very own &struct wiphy
  337. * @alpha2: the ISO/IEC 3166 alpha2 the driver claims its regulatory domain
  338. * should be in. If @rd is set this should be NULL. Note that if you
  339. * set this to NULL you should still set rd->alpha2 to some accepted
  340. * alpha2.
  341. * @rd: a complete regulatory domain provided by the driver. If passed
  342. * the driver does not need to worry about freeing it.
  343. *
  344. * Wireless drivers can use this function to hint to the wireless core
  345. * what it believes should be the current regulatory domain by
  346. * giving it an ISO/IEC 3166 alpha2 country code it knows its regulatory
  347. * domain should be in or by providing a completely build regulatory domain.
  348. * If the driver provides an ISO/IEC 3166 alpha2 userspace will be queried
  349. * for a regulatory domain structure for the respective country. If
  350. * a regulatory domain is build and passed you should set the alpha2
  351. * if possible, otherwise set it to the special value of "99" which tells
  352. * the wireless core it is unknown. If you pass a built regulatory domain
  353. * and we return non zero you are in charge of kfree()'ing the structure.
  354. *
  355. * See __regulatory_hint() documentation for possible return values.
  356. */
  357. extern int regulatory_hint(struct wiphy *wiphy,
  358. const char *alpha2, struct ieee80211_regdomain *rd);
  359. #endif /* __NET_WIRELESS_H */