Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

net80211.h 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. #ifndef _GPXE_NET80211_H
  2. #define _GPXE_NET80211_H
  3. #include <gpxe/process.h>
  4. #include <gpxe/ieee80211.h>
  5. #include <gpxe/iobuf.h>
  6. #include <gpxe/netdevice.h>
  7. #include <gpxe/rc80211.h>
  8. /** @file
  9. *
  10. * The gPXE 802.11 MAC layer.
  11. */
  12. /*
  13. * Major things NOT YET supported:
  14. * - any type of security
  15. * - 802.11n
  16. *
  17. * Major things that probably will NEVER be supported, barring a
  18. * compelling use case and/or corporate sponsorship:
  19. * - QoS
  20. * - 802.1X authentication ("WPA Enterprise")
  21. * - Contention-free periods
  22. * - "ad-hoc" networks (IBSS), monitor mode, host AP mode
  23. * - hidden networks on the 5GHz band due to regulatory issues
  24. * - spectrum management on the 5GHz band (TPC and DFS), as required
  25. * in some non-US regulatory domains
  26. * - Clause 14 PHYs (Frequency-Hopping Spread Spectrum on 2.4GHz)
  27. * and Clause 16 PHYs (infrared) - I'm not aware of any real-world
  28. * use of these.
  29. */
  30. FILE_LICENCE ( GPL2_OR_LATER );
  31. /* All 802.11 devices are handled using a generic "802.11 device"
  32. net_device, with a link in its `priv' field to a net80211_device
  33. which we use to handle 802.11-specific details. */
  34. /** @defgroup net80211_band RF bands on which an 802.11 device can transmit */
  35. /** @{ */
  36. /** The 2.4 GHz ISM band, unlicensed in most countries */
  37. #define NET80211_BAND_2GHZ (1 << 0)
  38. /** The band from 4.9 GHz to 5.7 GHz, which tends to be more restricted */
  39. #define NET80211_BAND_5GHZ (1 << 1)
  40. /** @} */
  41. /** @defgroup net80211_mode 802.11 operation modes supported by hardware */
  42. /** @{ */
  43. /** 802.11a: 54 Mbps operation using OFDM signaling on the 5GHz band */
  44. #define NET80211_MODE_A (1 << 0)
  45. /** 802.11b: 1-11 Mbps operation using DSSS/CCK signaling on the 2.4GHz band */
  46. #define NET80211_MODE_B (1 << 1)
  47. /** 802.11g: 54 Mbps operation using ERP/OFDM signaling on the 2.4GHz band */
  48. #define NET80211_MODE_G (1 << 2)
  49. /** 802.11n: High-rate operation using MIMO technology on 2.4GHz or 5GHz */
  50. #define NET80211_MODE_N (1 << 3)
  51. /** @} */
  52. /** @defgroup net80211_cfg Constants for the net80211 config callback */
  53. /** @{ */
  54. /** Channel choice (@c dev->channel) or regulatory parameters have changed */
  55. #define NET80211_CFG_CHANNEL (1 << 0)
  56. /** Requested transmission rate (@c dev->rate) has changed */
  57. #define NET80211_CFG_RATE (1 << 1)
  58. /** Association has been established with a new BSS (@c dev->bssid) */
  59. #define NET80211_CFG_ASSOC (1 << 2)
  60. /** Low-level link parameters (short preamble, protection, etc) have changed */
  61. #define NET80211_CFG_PHY_PARAMS (1 << 3)
  62. /** @} */
  63. /** An 802.11 security handshaking protocol */
  64. enum net80211_security_proto {
  65. /** No security handshaking
  66. *
  67. * This might be used with an open network or with WEP, as
  68. * WEP does not have a cryptographic handshaking phase.
  69. */
  70. NET80211_SECPROT_NONE = 0,
  71. /** Pre-shared key handshaking
  72. *
  73. * This implements the "WPA Personal" handshake. 802.1X
  74. * authentication is not performed -- the user supplies a
  75. * pre-shared key directly -- but there is a 4-way handshake
  76. * between client and AP to verify that both have the same key
  77. * without revealing the contents of that key.
  78. */
  79. NET80211_SECPROT_PSK = 1,
  80. /** Full EAP 802.1X handshaking
  81. *
  82. * This implements the "WPA Enterprise" handshake, connecting
  83. * to an 802.1X authentication server to provide credentials
  84. * and receive a pairwise master key (PMK), which is then used
  85. * in the same 4-way handshake as the PSK method.
  86. */
  87. NET80211_SECPROT_EAP = 2,
  88. };
  89. /** An 802.11 data encryption algorithm */
  90. enum net80211_crypto_alg {
  91. /** No security, an "Open" network */
  92. NET80211_CRYPT_NONE = 0,
  93. /** Network protected with WEP (awful RC4-based system)
  94. *
  95. * WEP uses a naive application of RC4, with a monotonically
  96. * increasing initialization vector that is prepended to the
  97. * key to initialize the RC4 keystream. It is highly insecure
  98. * and can be completely cracked or subverted using automated,
  99. * robust, freely available tools (aircrack-ng) in minutes.
  100. *
  101. * 40-bit and 104-bit WEP are differentiated only by the size
  102. * of the key. They may be advertised as 64-bit and 128-bit,
  103. * counting the non-random IV as part of the key bits.
  104. */
  105. NET80211_CRYPT_WEP = 1,
  106. /** Network protected with TKIP (better RC4-based system)
  107. *
  108. * Usually known by its trade name of WPA (Wi-Fi Protected
  109. * Access), TKIP implements a message integrity code (MIC)
  110. * called Michael, a timestamp counter for replay prevention,
  111. * and a key mixing function that together remove almost all
  112. * the security problems with WEP. Countermeasures are
  113. * implemented to prevent high data-rate attacks.
  114. *
  115. * There exists one known attack on TKIP, that allows one to
  116. * send between 7 and 15 arbitrary short data packets on a
  117. * QoS-enabled network given about an hour of data
  118. * gathering. Since gPXE does not support QoS for 802.11
  119. * networks, this is not a threat to us. The only other method
  120. * is a brute-force passphrase attack.
  121. */
  122. NET80211_CRYPT_TKIP = 2,
  123. /** Network protected with CCMP (AES-based system)
  124. *
  125. * Often called WPA2 in commerce, or RSNA (Robust Security
  126. * Network Architecture) in the 802.11 standard, CCMP is
  127. * highly secure and does not have any known attack vectors.
  128. * Since it is based on a block cipher, the statistical
  129. * correlation and "chopchop" attacks used with great success
  130. * against WEP and minor success against TKIP fail.
  131. */
  132. NET80211_CRYPT_CCMP = 3,
  133. };
  134. /** @defgroup net80211_state Bits for the 802.11 association state field */
  135. /** @{ */
  136. /** An error code indicating the failure mode, or 0 if successful */
  137. #define NET80211_STATUS_MASK 0x7F
  138. /** Whether the error code provided is a "reason" code, not a "status" code */
  139. #define NET80211_IS_REASON 0x80
  140. /** Whether we have found the network we will be associating with */
  141. #define NET80211_PROBED (1 << 8)
  142. /** Whether we have successfully authenticated with the network
  143. *
  144. * This usually has nothing to do with actual security; it is a
  145. * holdover from older 802.11 implementation ideas.
  146. */
  147. #define NET80211_AUTHENTICATED (1 << 9)
  148. /** Whether we have successfully associated with the network */
  149. #define NET80211_ASSOCIATED (1 << 10)
  150. /** Whether we have completed security handshaking with the network
  151. *
  152. * Once this is set, we can send data packets. For that reason this
  153. * bit is set even in cases where no security handshaking is
  154. * required.
  155. */
  156. #define NET80211_CRYPTO_SYNCED (1 << 11)
  157. /** Whether the auto-association task is running */
  158. #define NET80211_WORKING (1 << 12)
  159. /** Whether the auto-association task is waiting for a reply from the AP */
  160. #define NET80211_WAITING (1 << 13)
  161. /** Whether the auto-association task should be suppressed
  162. *
  163. * This is set by the `iwlist' command so that it can open the device
  164. * without starting another probe process that will interfere with its
  165. * own.
  166. */
  167. #define NET80211_NO_ASSOC (1 << 14)
  168. /** Whether this association was performed using a broadcast SSID
  169. *
  170. * If the user opened this device without netX/ssid set, the device's
  171. * SSID will be set to that of the network it chooses to associate
  172. * with, but the netX/ssid setting will remain blank. If we don't
  173. * remember that we started from no specified SSID, it will appear
  174. * every time settings are updated (e.g. after DHCP) that we need to
  175. * reassociate due to the difference between the set SSID and our own.
  176. */
  177. #define NET80211_AUTO_SSID (1 << 15)
  178. /** @} */
  179. /** @defgroup net80211_phy 802.11 physical layer flags */
  180. /** @{ */
  181. /** Whether to use RTS/CTS or CTS-to-self protection for transmissions
  182. *
  183. * Since the RTS or CTS is transmitted using 802.11b signaling, and
  184. * includes a field indicating the amount of time that will be used by
  185. * transmission of the following packet, this serves as an effective
  186. * protection mechanism to avoid 802.11b clients interfering with
  187. * 802.11g clients on mixed networks.
  188. */
  189. #define NET80211_PHY_USE_PROTECTION (1 << 1)
  190. /** Whether to use 802.11b short preamble operation
  191. *
  192. * Short-preamble operation can moderately increase throughput on
  193. * 802.11b networks operating between 2Mbps and 11Mbps. It is
  194. * irrelevant for 802.11g data rates, since they use a different
  195. * modulation scheme.
  196. */
  197. #define NET80211_PHY_USE_SHORT_PREAMBLE (1 << 2)
  198. /** Whether to use 802.11g short slot operation
  199. *
  200. * This affects a low-level timing parameter of 802.11g transmissions.
  201. */
  202. #define NET80211_PHY_USE_SHORT_SLOT (1 << 3)
  203. /** @} */
  204. /** The maximum number of TX rates we allow to be configured simultaneously */
  205. #define NET80211_MAX_RATES 16
  206. /** The maximum number of channels we allow to be configured simultaneously */
  207. #define NET80211_MAX_CHANNELS 32
  208. /** Seconds we'll wait to get all fragments of a packet */
  209. #define NET80211_FRAG_TIMEOUT 2
  210. /** The number of fragments we can receive at once
  211. *
  212. * The 802.11 standard requires that this be at least 3.
  213. */
  214. #define NET80211_NR_CONCURRENT_FRAGS 3
  215. /** Maximum TX power to allow (dBm), if we don't get a regulatory hint */
  216. #define NET80211_REG_TXPOWER 20
  217. struct net80211_device;
  218. /** Operations that must be implemented by an 802.11 driver */
  219. struct net80211_device_operations {
  220. /** Open 802.11 device
  221. *
  222. * @v dev 802.11 device
  223. * @ret rc Return status code
  224. *
  225. * This method should allocate RX I/O buffers and enable the
  226. * hardware to start transmitting and receiving packets on the
  227. * channels its net80211_register() call indicated it could
  228. * handle. It does not need to tune the antenna to receive
  229. * packets on any particular channel.
  230. */
  231. int ( * open ) ( struct net80211_device *dev );
  232. /** Close 802.11 network device
  233. *
  234. * @v dev 802.11 device
  235. *
  236. * This method should stop the flow of packets, and call
  237. * net80211_tx_complete() for any packets remaining in the
  238. * device's TX queue.
  239. */
  240. void ( * close ) ( struct net80211_device *dev );
  241. /** Transmit packet on 802.11 network device
  242. *
  243. * @v dev 802.11 device
  244. * @v iobuf I/O buffer
  245. * @ret rc Return status code
  246. *
  247. * This method should cause the hardware to initiate
  248. * transmission of the I/O buffer, using the channel and rate
  249. * most recently indicated by an appropriate call to the
  250. * @c config callback. The 802.11 layer guarantees that said
  251. * channel and rate will be the same as those currently
  252. * reflected in the fields of @a dev.
  253. *
  254. * If this method returns success, the I/O buffer remains
  255. * owned by the network layer's TX queue, and the driver must
  256. * eventually call net80211_tx_complete() to free the buffer
  257. * whether transmission succeeded or not. If this method
  258. * returns failure, it will be interpreted as "failure to
  259. * enqueue buffer" and the I/O buffer will be immediately
  260. * released.
  261. *
  262. * This method is guaranteed to be called only when the device
  263. * is open.
  264. */
  265. int ( * transmit ) ( struct net80211_device *dev,
  266. struct io_buffer *iobuf );
  267. /** Poll for completed and received packets
  268. *
  269. * @v dev 802.11 device
  270. *
  271. * This method should cause the hardware to check for
  272. * completed transmissions and received packets. Any received
  273. * packets should be delivered via net80211_rx(), and
  274. * completed transmissions should be indicated using
  275. * net80211_tx_complete().
  276. *
  277. * This method is guaranteed to be called only when the device
  278. * is open.
  279. */
  280. void ( * poll ) ( struct net80211_device *dev );
  281. /** Enable or disable interrupts
  282. *
  283. * @v dev 802.11 device
  284. * @v enable If TRUE, interrupts should be enabled
  285. */
  286. void ( * irq ) ( struct net80211_device *dev, int enable );
  287. /** Update hardware state to match 802.11 layer state
  288. *
  289. * @v dev 802.11 device
  290. * @v changed Set of flags indicating what may have changed
  291. * @ret rc Return status code
  292. *
  293. * This method should cause the hardware state to be
  294. * reinitialized from the state indicated in fields of
  295. * net80211_device, in the areas indicated by bits set in
  296. * @a changed. If the hardware is unable to do so, this method
  297. * may return an appropriate error indication.
  298. *
  299. * This method is guaranteed to be called only when the device
  300. * is open.
  301. */
  302. int ( * config ) ( struct net80211_device *dev, int changed );
  303. };
  304. /** An 802.11 RF channel. */
  305. struct net80211_channel
  306. {
  307. /** The band with which this channel is associated */
  308. u8 band;
  309. /** A channel number interpreted according to the band
  310. *
  311. * The 2.4GHz band uses channel numbers from 1-13 at 5MHz
  312. * intervals such that channel 1 is 2407 MHz; channel 14,
  313. * legal for use only in Japan, is defined separately as 2484
  314. * MHz. Adjacent channels will overlap, since 802.11
  315. * transmissions use a 20 MHz (4-channel) bandwidth. Most
  316. * commonly, channels 1, 6, and 11 are used.
  317. *
  318. * The 5GHz band uses channel numbers derived directly from
  319. * the frequency; channel 0 is 5000 MHz, and channels are
  320. * always spaced 5 MHz apart. Channel numbers over 180 are
  321. * relative to 4GHz instead of 5GHz, but these are rarely
  322. * seen. Most channels are not legal for use.
  323. */
  324. u8 channel_nr;
  325. /** The center frequency for this channel
  326. *
  327. * Currently a bandwidth of 20 MHz is assumed.
  328. */
  329. u16 center_freq;
  330. /** Maximum allowable transmit power, in dBm
  331. *
  332. * This should be interpreted as EIRP, the power supplied to
  333. * an ideal isotropic antenna in order to achieve the same
  334. * average signal intensity as the real hardware at a
  335. * particular distance.
  336. *
  337. * Currently no provision is made for directional antennas.
  338. */
  339. u8 maxpower;
  340. };
  341. /** Information on the capabilities of an 802.11 hardware device
  342. *
  343. * In its probe callback, an 802.11 driver must read hardware
  344. * registers to determine the appropriate contents of this structure,
  345. * fill it, and pass it to net80211_register() so that the 802.11
  346. * layer knows how to treat the hardware and what to advertise as
  347. * supported to access points.
  348. */
  349. struct net80211_hw_info
  350. {
  351. /** Default hardware MAC address.
  352. *
  353. * The user may change this by setting the @c netX/mac setting
  354. * before the driver's open function is called; in that case
  355. * the driver must set the hardware MAC address to the address
  356. * contained in the wrapping net_device's ll_addr field, or if
  357. * that is impossible, set that ll_addr field back to the
  358. * unchangeable hardware MAC address.
  359. */
  360. u8 hwaddr[ETH_ALEN];
  361. /** A bitwise OR of the 802.11x modes supported by this device */
  362. int modes;
  363. /** A bitwise OR of the bands on which this device can communicate */
  364. int bands;
  365. /** A set of flags indicating peculiarities of this device. */
  366. enum {
  367. /** Received frames include a frame check sequence. */
  368. NET80211_HW_RX_HAS_FCS = (1 << 1),
  369. /** Hardware doesn't support 2.4GHz short preambles
  370. *
  371. * This is only relevant for 802.11b operation above
  372. * 2Mbps. All 802.11g devices support short preambles.
  373. */
  374. NET80211_HW_NO_SHORT_PREAMBLE = (1 << 2),
  375. /** Hardware doesn't support 802.11g short slot operation */
  376. NET80211_HW_NO_SHORT_SLOT = (1 << 3),
  377. } flags;
  378. /** Signal strength information that can be provided by the device
  379. *
  380. * Signal strength is passed to net80211_rx(), primarily to
  381. * allow determination of the closest access point for a
  382. * multi-AP network. The units are provided for completeness
  383. * of status displays.
  384. */
  385. enum {
  386. /** No signal strength information supported */
  387. NET80211_SIGNAL_NONE = 0,
  388. /** Signal strength in arbitrary units */
  389. NET80211_SIGNAL_ARBITRARY,
  390. /** Signal strength in decibels relative to arbitrary base */
  391. NET80211_SIGNAL_DB,
  392. /** Signal strength in decibels relative to 1mW */
  393. NET80211_SIGNAL_DBM,
  394. } signal_type;
  395. /** Maximum signal in arbitrary cases
  396. *
  397. * If signal_type is NET80211_SIGNAL_ARBITRARY or
  398. * NET80211_SIGNAL_DB, the driver should report it on a scale
  399. * from 0 to signal_max.
  400. */
  401. unsigned signal_max;
  402. /** List of transmission rates supported by the card
  403. *
  404. * Rates should be in 100kbps increments (e.g. 11 Mbps would
  405. * be represented as the number 110).
  406. */
  407. u16 supported_rates[NET80211_MAX_RATES];
  408. /** Number of supported rates */
  409. int nr_supported_rates;
  410. /** Estimate of the time required to change channels, in microseconds
  411. *
  412. * If this is not known, a guess on the order of a few
  413. * milliseconds (value of 1000-5000) is reasonable.
  414. */
  415. unsigned channel_change_time;
  416. };
  417. /** Structure tracking received fragments for a packet
  418. *
  419. * We set up a fragment cache entry when we receive a packet marked as
  420. * fragment 0 with the "more fragments" bit set in its frame control
  421. * header. We are required by the 802.11 standard to track 3
  422. * fragmented packets arriving simultaneously; if we receive more we
  423. * may drop some. Upon receipt of a new fragment-0 packet, if no entry
  424. * is available or expired, we take over the most @e recent entry for
  425. * the new packet, since we don't want to starve old entries from ever
  426. * finishing at all. If we get a fragment after the zeroth with no
  427. * cache entry for its packet, we drop it.
  428. */
  429. struct net80211_frag_cache
  430. {
  431. /** Whether this cache entry is in use */
  432. u8 in_use;
  433. /** Sequence number of this MSDU (packet) */
  434. u16 seqnr;
  435. /** Timestamp from point at which first fragment was collected */
  436. u32 start_ticks;
  437. /** Buffers for each fragment */
  438. struct io_buffer *iob[16];
  439. };
  440. /** Interface to an 802.11 cryptographic algorithm
  441. *
  442. * Cryptographic algorithms define a net80211_crypto structure
  443. * statically, using a gPXE linker table to make it available to the
  444. * 802.11 layer. When the algorithm needs to be used, the 802.11 code
  445. * will allocate a copy of the static definition plus whatever space
  446. * the algorithm has requested for private state, and point
  447. * net80211_device::crypto at it.
  448. */
  449. struct net80211_crypto
  450. {
  451. /** The cryptographic algorithm implemented */
  452. enum net80211_crypto_alg algorithm;
  453. /** Initialize cryptographic algorithm using a given key
  454. *
  455. * @v crypto 802.11 cryptographic algorithm
  456. * @v key Pointer to key bytes
  457. * @v keylen Number of key bytes
  458. * @ret rc Return status code
  459. *
  460. * This method is passed the communication key provided by the
  461. * security handshake handler, which will already be in the
  462. * low-level form required.
  463. */
  464. int ( * initialize ) ( struct net80211_crypto *crypto, u8 *key,
  465. int keylen );
  466. /** Encrypt a frame using the cryptographic algorithm
  467. *
  468. * @v crypto 802.11 cryptographic algorithm
  469. * @v iob I/O buffer
  470. * @ret eiob Newly allocated I/O buffer with encrypted packet
  471. *
  472. * This method is called to encrypt a single frame. It is
  473. * guaranteed that initialize() will have completed
  474. * successfully before this method is called.
  475. *
  476. * The frame passed already has an 802.11 header prepended,
  477. * but the PROTECTED bit in the frame control field will not
  478. * be set; this method is responsible for setting it. The
  479. * returned I/O buffer should contain a complete copy of @a
  480. * iob, including the 802.11 header, but with the PROTECTED
  481. * bit set, the data encrypted, and whatever encryption
  482. * headers/trailers are necessary added.
  483. *
  484. * This method should never free the passed I/O buffer.
  485. *
  486. * Return NULL if the packet could not be encrypted, due to
  487. * memory limitations or otherwise.
  488. */
  489. struct io_buffer * ( * encrypt ) ( struct net80211_crypto *crypto,
  490. struct io_buffer *iob );
  491. /** Decrypt a frame using the cryptographic algorithm
  492. *
  493. * @v crypto 802.11 cryptographic algorithm
  494. * @v eiob Encrypted I/O buffer
  495. * @ret iob Newly allocated I/O buffer with decrypted packet
  496. *
  497. * This method is called to decrypt a single frame. It is
  498. * guaranteed that initialize() will have completed
  499. * successfully before this method is called.
  500. *
  501. * Decryption follows the reverse of the pattern used for
  502. * encryption: this method must copy the 802.11 header into
  503. * the returned packet, decrypt the data stream, remove any
  504. * encryption header or trailer, and clear the PROTECTED bit
  505. * in the frame control header.
  506. *
  507. * This method should never free the passed I/O buffer.
  508. *
  509. * Return NULL if memory was not available for decryption, if
  510. * a consistency or integrity check on the decrypted frame
  511. * failed, or if the decrypted frame should not be processed
  512. * by the network stack for any other reason.
  513. */
  514. struct io_buffer * ( * decrypt ) ( struct net80211_crypto *crypto,
  515. struct io_buffer *iob );
  516. /** Length of private data requested to be allocated */
  517. int priv_len;
  518. /** Private data for the algorithm to store key and state info */
  519. void *priv;
  520. };
  521. struct net80211_probe_ctx;
  522. struct net80211_assoc_ctx;
  523. /** Structure encapsulating the complete state of an 802.11 device
  524. *
  525. * An 802.11 device is always wrapped by a network device, and this
  526. * network device is always pointed to by the @a netdev field. In
  527. * general, operations should never be performed by 802.11 code using
  528. * netdev functions directly. It is usually the case that the 802.11
  529. * layer might need to do some processing or bookkeeping on top of
  530. * what the netdevice code will do.
  531. */
  532. struct net80211_device
  533. {
  534. /** The net_device that wraps us. */
  535. struct net_device *netdev;
  536. /** List of 802.11 devices. */
  537. struct list_head list;
  538. /** 802.11 device operations */
  539. struct net80211_device_operations *op;
  540. /** Driver private data */
  541. void *priv;
  542. /** Information about the hardware, provided to net80211_register() */
  543. struct net80211_hw_info *hw;
  544. /* ---------- Channel and rate fields ---------- */
  545. /** A list of all possible channels we might use */
  546. struct net80211_channel channels[NET80211_MAX_CHANNELS];
  547. /** The number of channels in the channels array */
  548. u8 nr_channels;
  549. /** The channel currently in use, as an index into the channels array */
  550. u8 channel;
  551. /** A list of all possible TX rates we might use
  552. *
  553. * Rates are in units of 100 kbps.
  554. */
  555. u16 rates[NET80211_MAX_RATES];
  556. /** The number of transmission rates in the rates array */
  557. u8 nr_rates;
  558. /** The rate currently in use, as an index into the rates array */
  559. u8 rate;
  560. /** The rate to use for RTS/CTS transmissions
  561. *
  562. * This is always the fastest basic rate that is not faster
  563. * than the data rate in use. Also an index into the rates array.
  564. */
  565. u8 rtscts_rate;
  566. /** Bitmask of basic rates
  567. *
  568. * If bit N is set in this value, with the LSB considered to
  569. * be bit 0, then rate N in the rates array is a "basic" rate.
  570. *
  571. * We don't decide which rates are "basic"; our AP does, and
  572. * we respect its wishes. We need to be able to identify basic
  573. * rates in order to calculate the duration of a CTS packet
  574. * used for 802.11 g/b interoperability.
  575. */
  576. u32 basic_rates;
  577. /* ---------- Association fields ---------- */
  578. /** The asynchronous association process.
  579. *
  580. * When an 802.11 netdev is opened, or when the user changes
  581. * the SSID setting on an open 802.11 device, an
  582. * autoassociation task is started by net80211_autoassocate()
  583. * to associate with the new best network. The association is
  584. * asynchronous, but no packets can be transmitted until it is
  585. * complete. If it is successful, the wrapping net_device is
  586. * set as "link up". If it fails, @c assoc_rc will be set with
  587. * an error indication.
  588. */
  589. struct process proc_assoc;
  590. /** Network with which we are associating
  591. *
  592. * This will be NULL when we are not actively in the process
  593. * of associating with a network we have already successfully
  594. * probed for.
  595. */
  596. struct net80211_wlan *associating;
  597. /** Context for the association process
  598. *
  599. * This is a probe_ctx if the @c PROBED flag is not set in @c
  600. * state, and an assoc_ctx otherwise.
  601. */
  602. union {
  603. struct net80211_probe_ctx *probe;
  604. struct net80211_assoc_ctx *assoc;
  605. } ctx;
  606. /** State of our association to the network
  607. *
  608. * Since the association process happens asynchronously, it's
  609. * necessary to have some channel of communication so the
  610. * driver can say "I got an association reply and we're OK" or
  611. * similar. This variable provides that link. It is a bitmask
  612. * of any of NET80211_PROBED, NET80211_AUTHENTICATED,
  613. * NET80211_ASSOCIATED, NET80211_CRYPTO_SYNCED to indicate how
  614. * far along in associating we are; NET80211_WORKING if the
  615. * association task is running; and NET80211_WAITING if a
  616. * packet has been sent that we're waiting for a reply to. We
  617. * can only be crypto-synced if we're associated, we can
  618. * only be associated if we're authenticated, we can only be
  619. * authenticated if we've probed.
  620. *
  621. * If an association process fails (that is, we receive a
  622. * packet with an error indication), the error code is copied
  623. * into bits 6-0 of this variable and bit 7 is set to specify
  624. * what type of error code it is. An AP can provide either a
  625. * "status code" (0-51 are defined) explaining why it refused
  626. * an association immediately, or a "reason code" (0-45 are
  627. * defined) explaining why it canceled an association after it
  628. * had originally OK'ed it. Status and reason codes serve
  629. * similar functions, but they use separate error message
  630. * tables. A gPXE-formatted return status code (negative) is
  631. * placed in @c assoc_rc.
  632. *
  633. * If the failure to associate is indicated by a status code,
  634. * the NET80211_IS_REASON bit will be clear; if it is
  635. * indicated by a reason code, the bit will be set. If we were
  636. * successful, both zero status and zero reason mean success,
  637. * so there is no ambiguity.
  638. *
  639. * To prevent association when opening the device, user code
  640. * can set the NET80211_NO_ASSOC bit. The final bit in this
  641. * variable, NET80211_AUTO_SSID, is used to remember whether
  642. * we picked our SSID through automated probing as opposed to
  643. * user specification; the distinction becomes relevant in the
  644. * settings applicator.
  645. */
  646. u16 state;
  647. /** Return status code associated with @c state */
  648. int assoc_rc;
  649. /* ---------- Parameters of currently associated network ---------- */
  650. /** 802.11 cryptographic algorithm for our current network
  651. *
  652. * For an open network, this will be set to NULL.
  653. */
  654. struct net80211_crypto *crypto;
  655. /** MAC address of the access point most recently associated */
  656. u8 bssid[ETH_ALEN];
  657. /** SSID of the access point we are or will be associated with
  658. *
  659. * Although the SSID field in 802.11 packets is generally not
  660. * NUL-terminated, here and in net80211_wlan we add a NUL for
  661. * convenience.
  662. */
  663. char essid[IEEE80211_MAX_SSID_LEN+1];
  664. /** Association ID given to us by the AP */
  665. u16 aid;
  666. /** TSFT value for last beacon received, microseconds */
  667. u64 last_beacon_timestamp;
  668. /** Time between AP sending beacons, microseconds */
  669. u32 tx_beacon_interval;
  670. /** Smoothed average time between beacons, microseconds */
  671. u32 rx_beacon_interval;
  672. /* ---------- Physical layer information ---------- */
  673. /** Physical layer options
  674. *
  675. * These control the use of CTS protection, short preambles,
  676. * and short-slot operation.
  677. */
  678. int phy_flags;
  679. /** Signal strength of last received packet */
  680. int last_signal;
  681. /** Rate control state */
  682. struct rc80211_ctx *rctl;
  683. /* ---------- Packet handling state ---------- */
  684. /** Fragment reassembly state */
  685. struct net80211_frag_cache frags[NET80211_NR_CONCURRENT_FRAGS];
  686. /** The sequence number of the last packet we sent */
  687. u16 last_tx_seqnr;
  688. /** Packet duplication elimination state
  689. *
  690. * We are only required to handle immediate duplicates for
  691. * each direct sender, and since we can only have one direct
  692. * sender (the AP), we need only keep the sequence control
  693. * field from the most recent packet we've received. Thus,
  694. * this field stores the last sequence control field we've
  695. * received for a packet from the AP.
  696. */
  697. u16 last_rx_seq;
  698. /** RX management packet queue
  699. *
  700. * Sometimes we want to keep probe, beacon, and action packets
  701. * that we receive, such as when we're scanning for networks.
  702. * Ordinarily we drop them because they are sent at a large
  703. * volume (ten beacons per second per AP, broadcast) and we
  704. * have no need of them except when we're scanning.
  705. *
  706. * When keep_mgmt is TRUE, received probe, beacon, and action
  707. * management packets will be stored in this queue.
  708. */
  709. struct list_head mgmt_queue;
  710. /** RX management packet info queue
  711. *
  712. * We need to keep track of the signal strength for management
  713. * packets we're keeping, because that provides the only way
  714. * to distinguish between multiple APs for the same network.
  715. * Since we can't extend io_buffer to store signal, this field
  716. * heads a linked list of "RX packet info" structures that
  717. * contain that signal strength field. Its entries always
  718. * parallel the entries in mgmt_queue, because the two queues
  719. * are always added to or removed from in parallel.
  720. */
  721. struct list_head mgmt_info_queue;
  722. /** Whether to store management packets
  723. *
  724. * Received beacon, probe, and action packets will be added to
  725. * mgmt_queue (and their signal strengths added to
  726. * mgmt_info_queue) only when this variable is TRUE. It should
  727. * be set by net80211_keep_mgmt() (which returns the old
  728. * value) only when calling code is prepared to poll the
  729. * management queue frequently, because packets will otherwise
  730. * pile up and exhaust memory.
  731. */
  732. int keep_mgmt;
  733. };
  734. /** Structure representing a probed network.
  735. *
  736. * This is returned from the net80211_probe_finish functions and
  737. * passed to the low-level association functions. At least essid,
  738. * bssid, channel, beacon, and security must be filled in if you want
  739. * to build this structure manually.
  740. */
  741. struct net80211_wlan
  742. {
  743. /** The human-readable ESSID (network name)
  744. *
  745. * Although the 802.11 SSID field is generally not
  746. * NUL-terminated, the gPXE code adds an extra NUL (and
  747. * expects one in this structure) for convenience.
  748. */
  749. char essid[IEEE80211_MAX_SSID_LEN+1];
  750. /** MAC address of the strongest-signal access point for this ESSID */
  751. u8 bssid[ETH_ALEN];
  752. /** Signal strength of beacon frame from that access point */
  753. int signal;
  754. /** The channel on which that access point communicates
  755. *
  756. * This is a raw channel number (net80211_channel::channel_nr),
  757. * so that it will not be affected by reconfiguration of the
  758. * device channels array.
  759. */
  760. int channel;
  761. /** The complete beacon or probe-response frame received */
  762. struct io_buffer *beacon;
  763. /** Security handshaking method used on the network */
  764. enum net80211_security_proto handshaking;
  765. /** Cryptographic algorithm used on the network */
  766. enum net80211_crypto_alg crypto;
  767. /** Link to allow chaining multiple structures into a list to
  768. be returned from net80211_probe_finish_all(). */
  769. struct list_head list;
  770. };
  771. /**
  772. * @defgroup net80211_probe 802.11 network location API
  773. * @{
  774. */
  775. int net80211_prepare_probe ( struct net80211_device *dev, int band,
  776. int active );
  777. struct net80211_probe_ctx * net80211_probe_start ( struct net80211_device *dev,
  778. const char *essid,
  779. int active );
  780. int net80211_probe_step ( struct net80211_probe_ctx *ctx );
  781. struct net80211_wlan *
  782. net80211_probe_finish_best ( struct net80211_probe_ctx *ctx );
  783. struct list_head *net80211_probe_finish_all ( struct net80211_probe_ctx *ctx );
  784. void net80211_free_wlan ( struct net80211_wlan *wlan );
  785. void net80211_free_wlanlist ( struct list_head *list );
  786. /** @} */
  787. /**
  788. * @defgroup net80211_mgmt 802.11 network management API
  789. * @{
  790. */
  791. struct net80211_device * net80211_get ( struct net_device *netdev );
  792. void net80211_autoassociate ( struct net80211_device *dev );
  793. int net80211_change_channel ( struct net80211_device *dev, int channel );
  794. void net80211_set_rate_idx ( struct net80211_device *dev, int rate );
  795. int net80211_keep_mgmt ( struct net80211_device *dev, int enable );
  796. struct io_buffer * net80211_mgmt_dequeue ( struct net80211_device *dev,
  797. int *signal );
  798. int net80211_tx_mgmt ( struct net80211_device *dev, u16 fc,
  799. u8 bssid[ETH_ALEN], struct io_buffer *iob );
  800. /** @} */
  801. /**
  802. * @defgroup net80211_assoc 802.11 network association API
  803. * @{
  804. */
  805. int net80211_prepare_assoc ( struct net80211_device *dev,
  806. struct net80211_wlan *wlan );
  807. int net80211_send_auth ( struct net80211_device *dev,
  808. struct net80211_wlan *wlan, int method );
  809. int net80211_send_assoc ( struct net80211_device *dev,
  810. struct net80211_wlan *wlan );
  811. /** @} */
  812. /**
  813. * @defgroup net80211_driver 802.11 driver interface API
  814. * @{
  815. */
  816. struct net80211_device *net80211_alloc ( size_t priv_size );
  817. int net80211_register ( struct net80211_device *dev,
  818. struct net80211_device_operations *ops,
  819. struct net80211_hw_info *hw );
  820. void net80211_rx ( struct net80211_device *dev, struct io_buffer *iob,
  821. int signal, u16 rate );
  822. void net80211_rx_err ( struct net80211_device *dev,
  823. struct io_buffer *iob, int rc );
  824. void net80211_tx_complete ( struct net80211_device *dev,
  825. struct io_buffer *iob, int retries, int rc );
  826. void net80211_unregister ( struct net80211_device *dev );
  827. void net80211_free ( struct net80211_device *dev );
  828. /** @} */
  829. #endif