eapol.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /*
  2. * 802.1x EAPOL definitions
  3. *
  4. * See
  5. * IEEE Std 802.1X-2001
  6. * IEEE 802.1X RADIUS Usage Guidelines
  7. *
  8. * Portions of this code are copyright (c) 2020 Cypress Semiconductor Corporation
  9. *
  10. * Copyright (C) 1999-2020, Broadcom Corporation
  11. *
  12. * Unless you and Broadcom execute a separate written software license
  13. * agreement governing use of this software, this software is licensed to you
  14. * under the terms of the GNU General Public License version 2 (the "GPL"),
  15. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  16. * following added to such license:
  17. *
  18. * As a special exception, the copyright holders of this software give you
  19. * permission to link this software with independent modules, and to copy and
  20. * distribute the resulting executable under terms of your choice, provided that
  21. * you also meet, for each linked independent module, the terms and conditions of
  22. * the license of that module. An independent module is a module which is not
  23. * derived from this software. The special exception does not apply to any
  24. * modifications of the software.
  25. *
  26. * Notwithstanding the above, under no circumstances may you combine this
  27. * software in any way with any other Broadcom software provided under a license
  28. * other than the GPL, without Broadcom's express prior written consent.
  29. *
  30. *
  31. * <<Broadcom-WL-IPTag/Open:>>
  32. *
  33. * $Id: eapol.h 715555 2019-05-24 18:41:23Z $
  34. */
  35. #ifndef _eapol_h_
  36. #define _eapol_h_
  37. #ifndef _TYPEDEFS_H_
  38. #include <typedefs.h>
  39. #endif // endif
  40. /* This marks the start of a packed structure section. */
  41. #include <packed_section_start.h>
  42. #if !defined(BCMCRYPTO_COMPONENT)
  43. #include <bcmcrypto/aeskeywrap.h>
  44. #endif /* !BCMCRYPTO_COMPONENT */
  45. /* EAPOL for 802.3/Ethernet */
  46. typedef BWL_PRE_PACKED_STRUCT struct {
  47. struct ether_header eth; /* 802.3/Ethernet header */
  48. unsigned char version; /* EAPOL protocol version */
  49. unsigned char type; /* EAPOL type */
  50. unsigned short length; /* Length of body */
  51. unsigned char body[1]; /* Body (optional) */
  52. } BWL_POST_PACKED_STRUCT eapol_header_t;
  53. #define EAPOL_HEADER_LEN 18
  54. typedef struct {
  55. unsigned char version; /* EAPOL protocol version */
  56. unsigned char type; /* EAPOL type */
  57. unsigned short length; /* Length of body */
  58. } eapol_hdr_t;
  59. #define EAPOL_HDR_LEN 4u
  60. /* EAPOL version */
  61. #define WPA2_EAPOL_VERSION 2u
  62. #define WPA_EAPOL_VERSION 1u
  63. #define LEAP_EAPOL_VERSION 1u
  64. #define SES_EAPOL_VERSION 1u
  65. /* EAPOL types */
  66. #define EAP_PACKET 0
  67. #define EAPOL_START 1u
  68. #define EAPOL_LOGOFF 2u
  69. #define EAPOL_KEY 3u
  70. #define EAPOL_ASF 4u
  71. /* EAPOL-Key types */
  72. #define EAPOL_RC4_KEY 1u
  73. #define EAPOL_WPA2_KEY 2u /* 802.11i/WPA2 */
  74. #define EAPOL_WPA_KEY 254u /* WPA */
  75. /* RC4 EAPOL-Key header field sizes */
  76. #define EAPOL_KEY_REPLAY_LEN 8u
  77. #define EAPOL_KEY_IV_LEN 16u
  78. #define EAPOL_KEY_SIG_LEN 16u
  79. /* RC4 EAPOL-Key */
  80. typedef BWL_PRE_PACKED_STRUCT struct {
  81. unsigned char type; /* Key Descriptor Type */
  82. unsigned short length; /* Key Length (unaligned) */
  83. unsigned char replay[EAPOL_KEY_REPLAY_LEN]; /* Replay Counter */
  84. unsigned char iv[EAPOL_KEY_IV_LEN]; /* Key IV */
  85. unsigned char index; /* Key Flags & Index */
  86. unsigned char signature[EAPOL_KEY_SIG_LEN]; /* Key Signature */
  87. unsigned char key[1]; /* Key (optional) */
  88. } BWL_POST_PACKED_STRUCT eapol_key_header_t;
  89. #define EAPOL_KEY_HEADER_LEN 44u
  90. /* RC4 EAPOL-Key flags */
  91. #define EAPOL_KEY_FLAGS_MASK 0x80u
  92. #define EAPOL_KEY_BROADCAST 0u
  93. #define EAPOL_KEY_UNICAST 0x80u
  94. /* RC4 EAPOL-Key index */
  95. #define EAPOL_KEY_INDEX_MASK 0x7fu
  96. /* WPA/802.11i/WPA2 EAPOL-Key header field sizes */
  97. #define EAPOL_AKW_BLOCK_LEN 8
  98. #define EAPOL_WPA_KEY_REPLAY_LEN 8u
  99. #define EAPOL_WPA_KEY_NONCE_LEN 32u
  100. #define EAPOL_WPA_KEY_IV_LEN 16u
  101. #define EAPOL_WPA_KEY_RSC_LEN 8u
  102. #define EAPOL_WPA_KEY_ID_LEN 8u
  103. #define EAPOL_WPA_KEY_DATA_LEN (EAPOL_WPA_MAX_KEY_SIZE + EAPOL_AKW_BLOCK_LEN)
  104. #define EAPOL_WPA_MAX_KEY_SIZE 32u
  105. #define EAPOL_WPA_KEY_MAX_MIC_LEN 32u
  106. #define EAPOL_WPA_ENCR_KEY_MAX_LEN 64u
  107. #define EAPOL_WPA_TEMP_ENCR_KEY_MAX_LEN 32u
  108. #define EAPOL_WPA_PMK_MAX_LEN 64u
  109. #define EAPOL_WPA_PMK_SHA384_LEN 48u
  110. #define EAPOL_WPA_PMK_DEFAULT_LEN 32u
  111. #define EAPOL_WPA_KCK_DEFAULT_LEN 16u
  112. #define EAPOL_WPA_KCK_SHA384_LEN 24u
  113. #define EAPOL_WPA_KCK_MIC_DEFAULT_LEN 16u
  114. #define EAPOL_WPA_KCK_MIC_SHA384_LEN 24u
  115. #define EAPOL_WPA_ENCR_KEY_DEFAULT_LEN 16u
  116. #define EAPOL_WPA_KEK2_SHA256_LEN 16u
  117. #define EAPOL_WPA_KEK2_SHA384_LEN 32u
  118. #define EAPOL_WPA_KCK2_SHA256_LEN 16u
  119. #define EAPOL_WPA_KCK2_SHA384_LEN 24u
  120. #ifndef EAPOL_KEY_HDR_VER_V2
  121. #define EAPOL_WPA_KEY_MIC_LEN 16u /* deprecated */
  122. #define EAPOL_WPA_KEY_LEN 95u /* deprecated */
  123. #endif // endif
  124. #define EAPOL_PTK_KEY_MAX_LEN (EAPOL_WPA_KEY_MAX_MIC_LEN +\
  125. EAPOL_WPA_ENCR_KEY_MAX_LEN +\
  126. EAPOL_WPA_TEMP_ENCR_KEY_MAX_LEN +\
  127. EAPOL_WPA_KCK2_SHA384_LEN +\
  128. EAPOL_WPA_KEK2_SHA384_LEN)
  129. #ifndef EAPOL_KEY_HDR_VER_V2
  130. /* WPA EAPOL-Key : deprecated */
  131. typedef BWL_PRE_PACKED_STRUCT struct {
  132. unsigned char type; /* Key Descriptor Type */
  133. unsigned short key_info; /* Key Information (unaligned) */
  134. unsigned short key_len; /* Key Length (unaligned) */
  135. unsigned char replay[EAPOL_WPA_KEY_REPLAY_LEN]; /* Replay Counter */
  136. unsigned char nonce[EAPOL_WPA_KEY_NONCE_LEN]; /* Nonce */
  137. unsigned char iv[EAPOL_WPA_KEY_IV_LEN]; /* Key IV */
  138. unsigned char rsc[EAPOL_WPA_KEY_RSC_LEN]; /* Key RSC */
  139. unsigned char id[EAPOL_WPA_KEY_ID_LEN]; /* WPA:Key ID, 802.11i/WPA2: Reserved */
  140. unsigned char mic[EAPOL_WPA_KEY_MIC_LEN]; /* Key MIC */
  141. unsigned short data_len; /* Key Data Length */
  142. unsigned char data[EAPOL_WPA_KEY_DATA_LEN]; /* Key data */
  143. } BWL_POST_PACKED_STRUCT eapol_wpa_key_header_t;
  144. #else
  145. /* WPA EAPOL-Key : new structure to consider dynamic MIC length */
  146. typedef BWL_PRE_PACKED_STRUCT struct {
  147. unsigned char type; /* Key Descriptor Type */
  148. unsigned short key_info; /* Key Information (unaligned) */
  149. unsigned short key_len; /* Key Length (unaligned) */
  150. unsigned char replay[EAPOL_WPA_KEY_REPLAY_LEN]; /* Replay Counter */
  151. unsigned char nonce[EAPOL_WPA_KEY_NONCE_LEN]; /* Nonce */
  152. unsigned char iv[EAPOL_WPA_KEY_IV_LEN]; /* Key IV */
  153. unsigned char rsc[EAPOL_WPA_KEY_RSC_LEN]; /* Key RSC */
  154. unsigned char id[EAPOL_WPA_KEY_ID_LEN]; /* WPA:Key ID, 802.11i/WPA2: Reserved */
  155. } BWL_POST_PACKED_STRUCT eapol_wpa_key_header_v2_t;
  156. typedef eapol_wpa_key_header_v2_t eapol_wpa_key_header_t;
  157. #endif /* EAPOL_KEY_HDR_VER_V2 */
  158. #define EAPOL_WPA_KEY_DATA_LEN_SIZE 2u
  159. #ifdef EAPOL_KEY_HDR_VER_V2
  160. #define EAPOL_WPA_KEY_HDR_SIZE(mic_len) (sizeof(eapol_wpa_key_header_v2_t) \
  161. + mic_len + EAPOL_WPA_KEY_DATA_LEN_SIZE)
  162. /* WPA EAPOL-Key header macros to reach out mic/data_len/data field */
  163. #define EAPOL_WPA_KEY_HDR_MIC_PTR(pos) ((uint8 *)pos + sizeof(eapol_wpa_key_header_v2_t))
  164. #define EAPOL_WPA_KEY_HDR_DATA_LEN_PTR(pos, mic_len) \
  165. ((uint8 *)pos + sizeof(eapol_wpa_key_header_v2_t) + mic_len)
  166. #define EAPOL_WPA_KEY_HDR_DATA_PTR(pos, mic_len) \
  167. ((uint8 *)pos + EAPOL_WPA_KEY_HDR_SIZE(mic_len))
  168. #else
  169. #define EAPOL_WPA_KEY_HDR_SIZE(mic_len) EAPOL_WPA_KEY_LEN
  170. #define EAPOL_WPA_KEY_HDR_MIC_PTR(pos) ((uint8 *)&pos->mic)
  171. #define EAPOL_WPA_KEY_HDR_DATA_LEN_PTR(pos, mic_len) ((uint8 *)&pos->data_len)
  172. #define EAPOL_WPA_KEY_HDR_DATA_PTR(pos, mic_len) ((uint8 *)&pos->data)
  173. #endif /* EAPOL_KEY_HDR_VER_V2 */
  174. /* WPA/802.11i/WPA2 KEY KEY_INFO bits */
  175. #define WPA_KEY_DESC_OSEN 0x0
  176. #define WPA_KEY_DESC_V0 0x0
  177. #define WPA_KEY_DESC_V1 0x01
  178. #define WPA_KEY_DESC_V2 0x02
  179. #define WPA_KEY_DESC_V3 0x03
  180. #define WPA_KEY_PAIRWISE 0x08
  181. #define WPA_KEY_INSTALL 0x40
  182. #define WPA_KEY_ACK 0x80
  183. #define WPA_KEY_MIC 0x100
  184. #define WPA_KEY_SECURE 0x200
  185. #define WPA_KEY_ERROR 0x400
  186. #define WPA_KEY_REQ 0x800
  187. #define WPA_KEY_ENC_KEY_DATA 0x01000 /* Encrypted Key Data */
  188. #define WPA_KEY_SMK_MESSAGE 0x02000 /* SMK Message */
  189. #define WPA_KEY_DESC_VER(_ki) ((_ki) & 0x03u)
  190. #define WPA_KEY_DESC_V2_OR_V3 WPA_KEY_DESC_V2
  191. /* WPA-only KEY KEY_INFO bits */
  192. #define WPA_KEY_INDEX_0 0x00
  193. #define WPA_KEY_INDEX_1 0x10
  194. #define WPA_KEY_INDEX_2 0x20
  195. #define WPA_KEY_INDEX_3 0x30
  196. #define WPA_KEY_INDEX_MASK 0x30
  197. #define WPA_KEY_INDEX_SHIFT 0x04
  198. /* 802.11i/WPA2-only KEY KEY_INFO bits */
  199. #define WPA_KEY_ENCRYPTED_DATA 0x1000
  200. /* Key Data encapsulation */
  201. typedef BWL_PRE_PACKED_STRUCT struct {
  202. uint8 type;
  203. uint8 length;
  204. uint8 oui[3];
  205. uint8 subtype;
  206. uint8 data[1];
  207. } BWL_POST_PACKED_STRUCT eapol_wpa2_encap_data_t;
  208. #define EAPOL_WPA2_ENCAP_DATA_HDR_LEN 6
  209. #define WPA2_KEY_DATA_SUBTYPE_GTK 1
  210. #define WPA2_KEY_DATA_SUBTYPE_STAKEY 2
  211. #define WPA2_KEY_DATA_SUBTYPE_MAC 3
  212. #define WPA2_KEY_DATA_SUBTYPE_PMKID 4
  213. #define WPA2_KEY_DATA_SUBTYPE_IGTK 9
  214. /* GTK encapsulation */
  215. typedef BWL_PRE_PACKED_STRUCT struct {
  216. uint8 flags;
  217. uint8 reserved;
  218. uint8 gtk[EAPOL_WPA_MAX_KEY_SIZE];
  219. } BWL_POST_PACKED_STRUCT eapol_wpa2_key_gtk_encap_t;
  220. #define EAPOL_WPA2_KEY_GTK_ENCAP_HDR_LEN 2
  221. #define WPA2_GTK_INDEX_MASK 0x03
  222. #define WPA2_GTK_INDEX_SHIFT 0x00
  223. #define WPA2_GTK_TRANSMIT 0x04
  224. /* IGTK encapsulation */
  225. typedef BWL_PRE_PACKED_STRUCT struct {
  226. uint16 key_id;
  227. uint8 ipn[6];
  228. uint8 key[EAPOL_WPA_MAX_KEY_SIZE];
  229. } BWL_POST_PACKED_STRUCT eapol_wpa2_key_igtk_encap_t;
  230. #define EAPOL_WPA2_KEY_IGTK_ENCAP_HDR_LEN 8
  231. /* STAKey encapsulation */
  232. typedef BWL_PRE_PACKED_STRUCT struct {
  233. uint8 reserved[2];
  234. uint8 mac[ETHER_ADDR_LEN];
  235. uint8 stakey[EAPOL_WPA_MAX_KEY_SIZE];
  236. } BWL_POST_PACKED_STRUCT eapol_wpa2_key_stakey_encap_t;
  237. #define WPA2_KEY_DATA_PAD 0xdd
  238. /* This marks the end of a packed structure section. */
  239. #include <packed_section_end.h>
  240. #endif /* _eapol_h_ */