Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 1 | /* |
AnjaneeDevi Kapparapu | 24b52ff | 2014-02-18 18:44:02 -0800 | [diff] [blame] | 2 | * Copyright (c) 2012-2013 The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 5 | * |
| 6 | * |
| 7 | * Permission to use, copy, modify, and/or distribute this software for |
| 8 | * any purpose with or without fee is hereby granted, provided that the |
| 9 | * above copyright notice and this permission notice appear in all |
| 10 | * copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 13 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 15 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 16 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 17 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 18 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 19 | * PERFORMANCE OF THIS SOFTWARE. |
Gopichand Nakkala | 9c070ad | 2013-01-08 21:16:34 -0800 | [diff] [blame] | 20 | */ |
AnjaneeDevi Kapparapu | 24b52ff | 2014-02-18 18:44:02 -0800 | [diff] [blame] | 21 | |
Gopichand Nakkala | 9c070ad | 2013-01-08 21:16:34 -0800 | [diff] [blame] | 22 | /* |
AnjaneeDevi Kapparapu | 24b52ff | 2014-02-18 18:44:02 -0800 | [diff] [blame] | 23 | * This file was originally distributed by Qualcomm Atheros, Inc. |
| 24 | * under proprietary terms before Copyright ownership was assigned |
| 25 | * to the Linux Foundation. |
| 26 | */ |
| 27 | |
| 28 | /* |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 29 | * File: $Header: //depot/software/projects/feature_branches/gen5_phase1/os/linux/classic/ap/apps/include/aniSsmEapol.h#1 $ |
| 30 | * Contains declarations of various utilities for EAPoL frame |
| 31 | * parsing and creation. |
| 32 | * range. |
| 33 | * Author: Mayank D. Upadhyay |
| 34 | * Date: 19-June-2002 |
| 35 | * History:- |
| 36 | * Date Modified by Modification Information |
| 37 | * ------------------------------------------------------ |
| 38 | * |
| 39 | */ |
| 40 | #ifndef _ANI_SSM_EAPOL_H_ |
| 41 | #define _ANI_SSM_EAPOL_H_ |
| 42 | |
| 43 | #include "vos_types.h" |
| 44 | #include "vos_trace.h" |
| 45 | #include "vos_packet.h" |
| 46 | #include <bapRsnAsfPacket.h> |
| 47 | |
| 48 | #define ANI_ETH_P_EAPOL 0x0003 |
| 49 | #define ANI_ETH_P_IP 0x0800 |
| 50 | |
| 51 | /** |
| 52 | * The EAPOL type field is one of the following: |
| 53 | */ |
| 54 | #define ANI_EAPOL_TYPE_PACKET 0 |
| 55 | #define ANI_EAPOL_TYPE_START 1 |
| 56 | #define ANI_EAPOL_TYPE_LOGOFF 2 |
| 57 | #define ANI_EAPOL_TYPE_KEY 3 |
| 58 | #define ANI_EAPOL_TYPE_ASF_ALERT 4 |
| 59 | |
| 60 | #define EAPOL_VERSION_1 0x01 |
| 61 | |
| 62 | #define EAPOL_RX_HEADER_SIZE 18 |
| 63 | #define EAPOL_TX_HEADER_SIZE 26 //include LLC_SNAP |
| 64 | #define SNAP_HEADER_SIZE 8 |
| 65 | |
| 66 | #define ANI_EAPOL_KEY_DESC_TYPE_LEGACY_RC4 1 |
| 67 | // JEZ20041012 This needs to be fixed. This needs to support BOTH |
| 68 | // the older WPA Key Descriptor type of 254 AS WELL AS the newer |
| 69 | // Key Descriptor type of 2 |
| 70 | #define ANI_EAPOL_KEY_DESC_TYPE_RSN 254 |
| 71 | //#define ANI_EAPOL_KEY_DESC_TYPE_RSN 2 |
| 72 | #define ANI_EAPOL_KEY_DESC_TYPE_RSN_NEW 2 |
| 73 | |
| 74 | #define ANI_EAPOL_KEY_RSN_REPLAY_CTR_SIZE 8 |
| 75 | #define ANI_EAPOL_KEY_RSN_NONCE_SIZE 32 |
| 76 | #define ANI_EAPOL_KEY_RSN_IV_SIZE 16 |
| 77 | #define ANI_EAPOL_KEY_RSN_RSC_SIZE 8 |
| 78 | #define ANI_EAPOL_KEY_RSN_ID_SIZE 8 |
| 79 | #define ANI_EAPOL_KEY_RSN_MIC_SIZE 16 |
| 80 | #define ANI_EAPOL_KEY_RSN_ENC_KEY_SIZE 16 |
| 81 | |
| 82 | #define ANI_EAPOL_KEY_DESC_VERS_RC4 1 |
| 83 | #define ANI_EAPOL_KEY_DESC_VERS_AES 2 |
| 84 | |
| 85 | #define ANI_EAPOL_KEY_RC4_REPLAY_CTR_SIZE 8 |
| 86 | #define ANI_EAPOL_KEY_RC4_IV_SIZE 16 |
| 87 | #define ANI_EAPOL_KET_RC4_SIGN_SIZE 16 |
| 88 | |
| 89 | #define ANI_SSM_IE_RSN_KEY_DATA_ENCAPS_ID 0xDD |
| 90 | #define ANI_SSM_IE_RSN_GROUP_KEY_DATA_ENCAPS_ID 1 |
| 91 | #define ANI_SSM_GROUP_KEY_KDE_TX_BIT 0x04 |
| 92 | |
| 93 | typedef struct sAniEapolLegacyRc4KeyDesc { |
| 94 | v_U16_t keyLen; |
| 95 | v_U8_t replayCounter[ANI_EAPOL_KEY_RC4_REPLAY_CTR_SIZE]; |
| 96 | v_U8_t keyIv[ANI_EAPOL_KEY_RC4_IV_SIZE]; |
| 97 | tANI_BOOLEAN unicastFlag; // The high order 1 bit of key-index |
| 98 | v_U8_t keyId; // The lower order 7 bits of key-index (but 0..3 based) |
| 99 | v_U8_t signature[ANI_EAPOL_KET_RC4_SIGN_SIZE]; |
| 100 | v_U8_t *key; |
| 101 | } tAniEapolLegacyRc4KeyDesc; |
| 102 | |
| 103 | typedef struct sAniRsnKeyInfo { |
| 104 | v_U32_t keyDescVers; |
| 105 | tANI_BOOLEAN unicastFlag; // Pair-wise key |
| 106 | v_U16_t keyId; |
| 107 | tANI_BOOLEAN installFlag; |
| 108 | tANI_BOOLEAN ackFlag; |
| 109 | tANI_BOOLEAN micFlag; |
| 110 | tANI_BOOLEAN secureFlag; |
| 111 | tANI_BOOLEAN errorFlag; |
| 112 | tANI_BOOLEAN requestFlag; |
| 113 | tANI_BOOLEAN encKeyDataFlag; // RSN only (Is 0 in WPA) |
| 114 | } tAniRsnKeyInfo; |
| 115 | |
| 116 | typedef struct sAniEapolRsnKeyDesc { |
| 117 | tAniRsnKeyInfo info; |
| 118 | v_U16_t keyLen; |
| 119 | v_U8_t replayCounter[ANI_EAPOL_KEY_RSN_REPLAY_CTR_SIZE]; |
| 120 | v_U8_t keyNonce[ANI_EAPOL_KEY_RSN_NONCE_SIZE]; |
| 121 | v_U8_t keyIv[ANI_EAPOL_KEY_RSN_IV_SIZE]; |
| 122 | v_U8_t keyRecvSeqCounter[ANI_EAPOL_KEY_RSN_RSC_SIZE]; |
| 123 | v_U8_t keyId[ANI_EAPOL_KEY_RSN_ID_SIZE]; |
| 124 | v_U8_t keyMic[ANI_EAPOL_KEY_RSN_MIC_SIZE]; |
| 125 | v_U16_t keyDataLen; |
| 126 | v_U8_t *keyData; |
| 127 | } tAniEapolRsnKeyDesc; |
| 128 | |
| 129 | /** |
| 130 | * aniEapolWriteStart |
| 131 | * |
| 132 | * FUNCTION: |
| 133 | * Writes an EAPOL-Start frame to the packet. It is only used by the |
| 134 | * supplicant. |
| 135 | * |
| 136 | * LOGIC: |
| 137 | * Prepend the appropriate EAPOL header to the packet. There is no |
| 138 | * EAPOL payload for this kind of frame. |
| 139 | * |
| 140 | * ASSUMPTIONS: |
| 141 | * The packet has enough space available for prepending the header. |
| 142 | * |
| 143 | * @param packet the packet to which the frame should be written |
| 144 | * @param dstMac the MAC address of the destination (authenticator) |
| 145 | * @param srcMac the MAC address of the source (supplicant) |
| 146 | * |
| 147 | * @return ANI_OK if the operation succeeds |
| 148 | */ |
| 149 | int |
| 150 | aniEapolWriteStart(tAniPacket *packet, |
| 151 | tAniMacAddr dstMac, |
| 152 | tAniMacAddr srcMac); |
| 153 | |
| 154 | /** |
| 155 | * aniEapolWriteEapPacket |
| 156 | * |
| 157 | * FUNCTION: |
| 158 | * Writes the EAPOL/EAP-Packet frame headers. It is used |
| 159 | * by both the authenticator and the supplicant. This creates an EAPOL |
| 160 | * frame that is carrying an EAP message as its payload. |
| 161 | * |
| 162 | * LOGIC: |
| 163 | * Prepend the appropriate EAPOL header to the packet. |
| 164 | * |
| 165 | * ASSUMPTIONS: |
| 166 | * The EAP message (ie., the payload) is already available in the |
| 167 | * packet and that the packet has enough space available for |
| 168 | * prepending the EAPOL header. |
| 169 | * |
| 170 | * @param packet the packet containing the EAP message |
| 171 | * @param dstMac the MAC address of the destination (authenticator) |
| 172 | * @param srcMac the MAC address of the source (supplicant) |
| 173 | * |
| 174 | * @return ANI_OK if the operation succeeds |
| 175 | */ |
| 176 | int |
| 177 | aniEapolWriteEapPacket(tAniPacket *eapPacket, |
| 178 | tAniMacAddr dstMac, |
| 179 | tAniMacAddr srcMac); |
| 180 | |
| 181 | /** |
| 182 | * aniEapolParse |
| 183 | * |
| 184 | * FUNCTION: |
| 185 | * Parses an EAPoL frame to the first level of headers (no EAP |
| 186 | * headers are parsed). |
| 187 | * |
| 188 | * NOTE: This is a non-destructive read, that is the |
| 189 | * headers are not stripped off the packet. However, any additional |
| 190 | * data at the end of the packet, beyond what the EAPoL headers encode |
| 191 | * will be stripped off. |
| 192 | * |
| 193 | * @param packet the packet containing the EAPoL frame to parse |
| 194 | * @param dstMac a pointer to set to the location of the destination |
| 195 | * MAC address |
| 196 | * @param srcMac a pointer to set to the location of the source |
| 197 | * MAC address |
| 198 | * @param type a pointer to set to the location of the EAPOL type |
| 199 | * field. |
| 200 | * |
| 201 | * @return the non-negative length of the EAPOL payload if the operation |
| 202 | * succeeds |
| 203 | */ |
| 204 | int |
| 205 | aniEapolParse(tAniPacket *packet, |
| 206 | v_U8_t **dstMac, |
| 207 | v_U8_t **srcMac, |
| 208 | v_U8_t **type); |
| 209 | |
| 210 | /** |
| 211 | * aniEapolWriteKey |
| 212 | * |
| 213 | * Writes out a complete EAPOL-Key frame. The key descriptor is |
| 214 | * appended to the packet and the EAPOL header is prepended to it. If |
| 215 | * a micKey is passed in, then a MIC is calculated and inserted into |
| 216 | * the frame. |
| 217 | * |
| 218 | * @param packet the packet to write to |
| 219 | * @param dstMac the destination MAC address |
| 220 | * @param srcMac the source MAC address |
| 221 | * @param descType the key descriptor type |
| 222 | * (ANI_EAPOL_KEY_DESC_TYPE_LEGACY_RC4 or |
| 223 | * ANI_EAPOL_KEY_DESC_TYPE_RSN). |
| 224 | * @param keyDescData the key descriptor data corresponding to the |
| 225 | * above descType. The signature field is ignored and will be |
| 226 | * generated in the packet. The key bytes are expected to be enctypted |
| 227 | * is they need to be encrypted. |
| 228 | * @param micKey the MIC key |
| 229 | * @param micKeyLen the number of bytes in the MIC key |
| 230 | * |
| 231 | * @return ANI_OK if the operation succeeds |
| 232 | * |
| 233 | */ |
| 234 | int |
| 235 | aniEapolWriteKey(v_U32_t cryptHandle, |
| 236 | tAniPacket *packet, |
| 237 | tAniMacAddr dstMac, |
| 238 | tAniMacAddr srcMac, |
| 239 | int descType, |
| 240 | void *keyDescData, |
| 241 | v_U8_t *micKey, |
| 242 | v_U32_t micKeyLen); |
| 243 | |
| 244 | /** |
| 245 | * aniEapolParseKey |
| 246 | * |
| 247 | * Parses and verifies a complete EAPOL-Key frame. The key descriptor |
| 248 | * type is returned and so is a newly allocated key descriptor structure |
| 249 | * that is appropriate for the type. |
| 250 | * |
| 251 | * NOTE: This is a non-destructive read. That is, the packet headers |
| 252 | * will be unchanged at the end of this read operation. This is so |
| 253 | * that a followup MIC check may be done on the complete packet. If |
| 254 | * the packet parsing fails, the packet headers are not guaranteed to |
| 255 | * be unchanged. |
| 256 | * |
| 257 | * @param packet the packet to read from. Note that the frame is not |
| 258 | * expected to contain any additional padding at the end other than |
| 259 | * the exact number of key bytes. (The aniEapolParse function will |
| 260 | * ensure this.) |
| 261 | * @param descType is set to the key descriptor type |
| 262 | * (ANI_EAPOL_KEY_DESC_TYPE_LEGACY_RC4 or |
| 263 | * ANI_EAPOL_KEY_DESC_TYPE_RSN). |
| 264 | * @param keyDescData is set to a newly allocated key descriptor |
| 265 | * corresponding to the above descType. The signature field is |
| 266 | * verified. The key bytes will be returned encrypted. It is the |
| 267 | * responsibility of the caller to free this structure and the data |
| 268 | * contained therein. |
| 269 | * |
| 270 | * @return ANI_OK if the operation succeeds |
| 271 | */ |
| 272 | int |
| 273 | aniEapolParseKey(tAniPacket *packet, |
| 274 | int *descType, |
| 275 | void **keyDescData); |
| 276 | |
| 277 | /** |
| 278 | * aniEapolKeyCheckMic |
| 279 | * |
| 280 | * @param eapolFrame the complete EAPOL-Key packet |
| 281 | * @param descType the key descriptor type |
| 282 | * @param keyDescData the key descriptor |
| 283 | * @param micKey the MIC key |
| 284 | * @param micKeyLen the number of bytes in the MIC key |
| 285 | * |
| 286 | * @return ANI_OK if the operation succeeds; ANI_E_MIC_FAILED if the |
| 287 | * MIC check fails. |
| 288 | */ |
| 289 | int |
| 290 | aniEapolKeyCheckMic(v_U32_t cryptHandle, |
| 291 | tAniPacket *eapolFrame, |
| 292 | int descType, |
| 293 | void *keyDescData, |
| 294 | v_U8_t *micKey, |
| 295 | v_U32_t micKeyLen); |
| 296 | |
| 297 | /** |
| 298 | * aniEapolKeyFreeDesc |
| 299 | * |
| 300 | * Frees the EAPOL key descriptor and the key bytes contained within it. |
| 301 | * |
| 302 | * @param descType the key descriptor type |
| 303 | * @param keyDescData the key descriptor |
| 304 | * |
| 305 | * @return ANI_OK if the operation succeeds |
| 306 | */ |
| 307 | int |
| 308 | aniEapolKeyFreeDesc(int descType, void *keyDescData); |
| 309 | |
| 310 | v_U8_t * |
| 311 | aniEapolType2Str(v_U8_t type); |
| 312 | |
| 313 | v_U8_t * |
| 314 | aniEapolHdr2Str(v_U8_t *hdr); |
| 315 | |
| 316 | /** |
| 317 | * aniEapolKeyLogDesc |
| 318 | * |
| 319 | * Logs information about the given EAPOL key desctiptor. |
| 320 | * |
| 321 | * @param descType the key descriptor type |
| 322 | * @param keyDescData the key descriptor |
| 323 | * |
| 324 | * @return ANI_OK if the operation succeeds |
| 325 | */ |
| 326 | int |
| 327 | aniEapolKeyLogDesc(int descType, void *keyDescData); |
| 328 | |
| 329 | void bapRsnEapolHandler( v_PVOID_t pvFsm, tAniPacket *packet, v_BOOL_t fIsAuth ); |
| 330 | //Transfer from pVosPacket to tAniPacket. |
| 331 | int bapRsnFormPktFromVosPkt( tAniPacket **ppPacket, vos_pkt_t *pVosPacket ); |
| 332 | |
| 333 | #endif //_ANI_SSM_EAPOL_H_ |