wireless.h 8.9 KB

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