wireless.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. * @hw_value: hardware-specific value for the channel
  58. * @flags: channel flags from &enum ieee80211_channel_flags.
  59. * @orig_flags: channel flags at registration time, used by regulatory
  60. * code to support devices with additional restrictions
  61. * @band: band this channel belongs to.
  62. * @max_antenna_gain: maximum antenna gain in dBi
  63. * @max_power: maximum transmission power (in dBm)
  64. * @orig_mag: internal use
  65. * @orig_mpwr: internal use
  66. */
  67. struct ieee80211_channel {
  68. enum ieee80211_band band;
  69. u16 center_freq;
  70. u16 hw_value;
  71. u32 flags;
  72. int max_antenna_gain;
  73. int max_power;
  74. u32 orig_flags;
  75. int orig_mag, orig_mpwr;
  76. };
  77. /**
  78. * enum ieee80211_rate_flags - rate flags
  79. *
  80. * Hardware/specification flags for rates. These are structured
  81. * in a way that allows using the same bitrate structure for
  82. * different bands/PHY modes.
  83. *
  84. * @IEEE80211_RATE_SHORT_PREAMBLE: Hardware can send with short
  85. * preamble on this bitrate; only relevant in 2.4GHz band and
  86. * with CCK rates.
  87. * @IEEE80211_RATE_MANDATORY_A: This bitrate is a mandatory rate
  88. * when used with 802.11a (on the 5 GHz band); filled by the
  89. * core code when registering the wiphy.
  90. * @IEEE80211_RATE_MANDATORY_B: This bitrate is a mandatory rate
  91. * when used with 802.11b (on the 2.4 GHz band); filled by the
  92. * core code when registering the wiphy.
  93. * @IEEE80211_RATE_MANDATORY_G: This bitrate is a mandatory rate
  94. * when used with 802.11g (on the 2.4 GHz band); filled by the
  95. * core code when registering the wiphy.
  96. * @IEEE80211_RATE_ERP_G: This is an ERP rate in 802.11g mode.
  97. */
  98. enum ieee80211_rate_flags {
  99. IEEE80211_RATE_SHORT_PREAMBLE = 1<<0,
  100. IEEE80211_RATE_MANDATORY_A = 1<<1,
  101. IEEE80211_RATE_MANDATORY_B = 1<<2,
  102. IEEE80211_RATE_MANDATORY_G = 1<<3,
  103. IEEE80211_RATE_ERP_G = 1<<4,
  104. };
  105. /**
  106. * struct ieee80211_rate - bitrate definition
  107. *
  108. * This structure describes a bitrate that an 802.11 PHY can
  109. * operate with. The two values @hw_value and @hw_value_short
  110. * are only for driver use when pointers to this structure are
  111. * passed around.
  112. *
  113. * @flags: rate-specific flags
  114. * @bitrate: bitrate in units of 100 Kbps
  115. * @hw_value: driver/hardware value for this rate
  116. * @hw_value_short: driver/hardware value for this rate when
  117. * short preamble is used
  118. */
  119. struct ieee80211_rate {
  120. u32 flags;
  121. u16 bitrate;
  122. u16 hw_value, hw_value_short;
  123. };
  124. /**
  125. * struct ieee80211_ht_info - describing STA's HT capabilities
  126. *
  127. * This structure describes most essential parameters needed
  128. * to describe 802.11n HT capabilities for an STA.
  129. *
  130. * @ht_supported: is HT supported by STA, 0: no, 1: yes
  131. * @cap: HT capabilities map as described in 802.11n spec
  132. * @ampdu_factor: Maximum A-MPDU length factor
  133. * @ampdu_density: Minimum A-MPDU spacing
  134. * @supp_mcs_set: Supported MCS set as described in 802.11n spec
  135. */
  136. struct ieee80211_ht_info {
  137. u16 cap; /* use IEEE80211_HT_CAP_ */
  138. u8 ht_supported;
  139. u8 ampdu_factor;
  140. u8 ampdu_density;
  141. u8 supp_mcs_set[16];
  142. };
  143. /**
  144. * struct ieee80211_supported_band - frequency band definition
  145. *
  146. * This structure describes a frequency band a wiphy
  147. * is able to operate in.
  148. *
  149. * @channels: Array of channels the hardware can operate in
  150. * in this band.
  151. * @band: the band this structure represents
  152. * @n_channels: Number of channels in @channels
  153. * @bitrates: Array of bitrates the hardware can operate with
  154. * in this band. Must be sorted to give a valid "supported
  155. * rates" IE, i.e. CCK rates first, then OFDM.
  156. * @n_bitrates: Number of bitrates in @bitrates
  157. */
  158. struct ieee80211_supported_band {
  159. struct ieee80211_channel *channels;
  160. struct ieee80211_rate *bitrates;
  161. enum ieee80211_band band;
  162. int n_channels;
  163. int n_bitrates;
  164. struct ieee80211_ht_info ht_info;
  165. };
  166. /**
  167. * struct wiphy - wireless hardware description
  168. * @idx: the wiphy index assigned to this item
  169. * @class_dev: the class device representing /sys/class/ieee80211/<wiphy-name>
  170. */
  171. struct wiphy {
  172. /* assign these fields before you register the wiphy */
  173. /* permanent MAC address */
  174. u8 perm_addr[ETH_ALEN];
  175. /* If multiple wiphys are registered and you're handed e.g.
  176. * a regular netdev with assigned ieee80211_ptr, you won't
  177. * know whether it points to a wiphy your driver has registered
  178. * or not. Assign this to something global to your driver to
  179. * help determine whether you own this wiphy or not. */
  180. void *privid;
  181. struct ieee80211_supported_band *bands[IEEE80211_NUM_BANDS];
  182. /* fields below are read-only, assigned by cfg80211 */
  183. /* the item in /sys/class/ieee80211/ points to this,
  184. * you need use set_wiphy_dev() (see below) */
  185. struct device dev;
  186. /* dir in debugfs: ieee80211/<wiphyname> */
  187. struct dentry *debugfsdir;
  188. char priv[0] __attribute__((__aligned__(NETDEV_ALIGN)));
  189. };
  190. /** struct wireless_dev - wireless per-netdev state
  191. *
  192. * This structure must be allocated by the driver/stack
  193. * that uses the ieee80211_ptr field in struct net_device
  194. * (this is intentional so it can be allocated along with
  195. * the netdev.)
  196. *
  197. * @wiphy: pointer to hardware description
  198. */
  199. struct wireless_dev {
  200. struct wiphy *wiphy;
  201. /* private to the generic wireless code */
  202. struct list_head list;
  203. struct net_device *netdev;
  204. };
  205. /**
  206. * wiphy_priv - return priv from wiphy
  207. */
  208. static inline void *wiphy_priv(struct wiphy *wiphy)
  209. {
  210. BUG_ON(!wiphy);
  211. return &wiphy->priv;
  212. }
  213. /**
  214. * set_wiphy_dev - set device pointer for wiphy
  215. */
  216. static inline void set_wiphy_dev(struct wiphy *wiphy, struct device *dev)
  217. {
  218. wiphy->dev.parent = dev;
  219. }
  220. /**
  221. * wiphy_dev - get wiphy dev pointer
  222. */
  223. static inline struct device *wiphy_dev(struct wiphy *wiphy)
  224. {
  225. return wiphy->dev.parent;
  226. }
  227. /**
  228. * wiphy_name - get wiphy name
  229. */
  230. static inline char *wiphy_name(struct wiphy *wiphy)
  231. {
  232. return wiphy->dev.bus_id;
  233. }
  234. /**
  235. * wdev_priv - return wiphy priv from wireless_dev
  236. */
  237. static inline void *wdev_priv(struct wireless_dev *wdev)
  238. {
  239. BUG_ON(!wdev);
  240. return wiphy_priv(wdev->wiphy);
  241. }
  242. /**
  243. * wiphy_new - create a new wiphy for use with cfg80211
  244. *
  245. * create a new wiphy and associate the given operations with it.
  246. * @sizeof_priv bytes are allocated for private use.
  247. *
  248. * the returned pointer must be assigned to each netdev's
  249. * ieee80211_ptr for proper operation.
  250. */
  251. struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv);
  252. /**
  253. * wiphy_register - register a wiphy with cfg80211
  254. *
  255. * register the given wiphy
  256. *
  257. * Returns a non-negative wiphy index or a negative error code.
  258. */
  259. extern int wiphy_register(struct wiphy *wiphy);
  260. /**
  261. * wiphy_unregister - deregister a wiphy from cfg80211
  262. *
  263. * unregister a device with the given priv pointer.
  264. * After this call, no more requests can be made with this priv
  265. * pointer, but the call may sleep to wait for an outstanding
  266. * request that is being handled.
  267. */
  268. extern void wiphy_unregister(struct wiphy *wiphy);
  269. /**
  270. * wiphy_free - free wiphy
  271. */
  272. extern void wiphy_free(struct wiphy *wiphy);
  273. /**
  274. * ieee80211_channel_to_frequency - convert channel number to frequency
  275. */
  276. extern int ieee80211_channel_to_frequency(int chan);
  277. /**
  278. * ieee80211_frequency_to_channel - convert frequency to channel number
  279. */
  280. extern int ieee80211_frequency_to_channel(int freq);
  281. /*
  282. * Name indirection necessary because the ieee80211 code also has
  283. * a function named "ieee80211_get_channel", so if you include
  284. * cfg80211's header file you get cfg80211's version, if you try
  285. * to include both header files you'll (rightfully!) get a symbol
  286. * clash.
  287. */
  288. extern struct ieee80211_channel *__ieee80211_get_channel(struct wiphy *wiphy,
  289. int freq);
  290. /**
  291. * ieee80211_get_channel - get channel struct from wiphy for specified frequency
  292. */
  293. static inline struct ieee80211_channel *
  294. ieee80211_get_channel(struct wiphy *wiphy, int freq)
  295. {
  296. return __ieee80211_get_channel(wiphy, freq);
  297. }
  298. #endif /* __NET_WIRELESS_H */