Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
eapol_helper.h
00001 /* 00002 * Copyright (c) 2018-2019, Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #ifndef EAPOL_HELPER_H_ 00019 #define EAPOL_HELPER_H_ 00020 00021 #define EAPOL_PROTOCOL_VERSION 3 00022 #define EAPOL_EAP_TYPE 0 00023 #define EAPOL_KEY_TYPE 3 00024 #define EAPOL_KEY_NONCE_LEN 32 00025 #define EAPOL_KEY_MIC_LEN 16 00026 #define EAPOL_KEY_LEN 16 00027 00028 #define EAPOL_BASE_LENGTH 4 //Protocol version 1 byte, Packet type 1 byte, packet length 2 byte 00029 00030 #define EAPOL_KEY_FRAME_BASE_SIZE 95 00031 00032 struct eap_header_t; 00033 00034 typedef struct eapol_key_information { 00035 unsigned description_version: 3; 00036 bool pairwise_key: 1; 00037 bool install: 1; 00038 bool key_ack: 1; 00039 bool key_mic: 1; 00040 bool secured_key_frame: 1; 00041 bool error: 1; 00042 bool request: 1; 00043 bool encrypted_key_data: 1; 00044 bool smk_handshake: 1; 00045 } eapol_key_information_t; 00046 00047 typedef struct eapol_key_frame { 00048 uint8_t key_description; 00049 eapol_key_information_t key_information; 00050 uint16_t key_length; 00051 uint64_t replay_counter; 00052 uint8_t *key_nonce; /*< Write operation: NULL memset are by 0, otherwise write data */ 00053 uint8_t *key_iv; /*< Write operation: NULL memset are by 0, otherwise write data */ 00054 uint8_t *key_rsc; /*< Write operation: NULL memset are by 0, otherwise write data */ 00055 uint8_t *key_mic; /*< Write operation: NULL memset are by 0, otherwise write data */ 00056 uint16_t key_data_length; 00057 uint8_t *key_data; 00058 } eapol_key_frame_t; 00059 00060 typedef struct eapol_pdu { 00061 uint8_t packet_type; /*< EAPOL_EAP_TYPE or EAPOL_KEY_TYPE */ 00062 uint16_t packet_length; /*< EAPOL Total length includin full packet body and data */ 00063 uint8_t *packet_body; /*< Data pointer to packet body*/ 00064 union { 00065 eapol_key_frame_t key; 00066 struct eap_header eap; 00067 } msg; 00068 } eapol_pdu_t; 00069 00070 #define EAPOL_RSN_KEY_DESCRIPTION 2 00071 #define KEY_DESCRIPTION_HMAC_MD5_MIC_ARC4_ENC 1 00072 #define KEY_DESCRIPTION_HMAC_SHA1_MIC_AES_ENC 2 00073 #define KEY_DESCRIPTION_AES_128_CMAC_MIC_AES_ENC 3 00074 00075 /** 00076 * Helper macro to get full message length 00077 */ 00078 #define eapol_pdu_total_length(x) (x->packet_length + EAPOL_BASE_LENGTH) 00079 00080 /** 00081 * Helper macro to message start 00082 */ 00083 #define eapol_pdu_msg_start(x) (x->packet_body - EAPOL_BASE_LENGTH) 00084 00085 /** 00086 * Parse EAPOL message to EAPOL-pdu frame 00087 * 00088 * \return true when message is valid and supported otherwise return false 00089 */ 00090 bool eapol_parse_pdu_header(uint8_t *ptr, uint16_t data_length, eapol_pdu_t *eapol_pdu); 00091 00092 uint8_t *eapol_write_pdu_frame(uint8_t *ptr, eapol_pdu_t *eapol_pdu); 00093 00094 uint16_t eapol_pdu_eap_frame_init(eapol_pdu_t *eapol_pdu, uint8_t eap_code, uint8_t id_seq, uint8_t type, uint16_t data_length, uint8_t *data_ptr); 00095 00096 uint16_t eapol_pdu_key_frame_init(eapol_pdu_t *eapol_pdu, uint16_t data_length, uint8_t *data_ptr); 00097 00098 void eapol_write_key_packet_mic(uint8_t *eapol_pdu, uint8_t *mic); 00099 00100 #define KEY_INFO_INSTALL 0x01 00101 #define KEY_INFO_KEY_ACK 0x02 00102 #define KEY_INFO_KEY_MIC 0x04 00103 #define KEY_INFO_SECURED_KEY_FRAME 0x08 00104 00105 /** 00106 * eapol_pdu_key_mask_get gets masked EAPOL-Key message bits 00107 * 00108 * \param eapol_pdu EAPOL PDU 00109 * 00110 * \return mask 00111 */ 00112 uint8_t eapol_pdu_key_mask_get(eapol_pdu_t *eapol_pdu); 00113 00114 #endif /* EAPOL_HELPER_H_ */
Generated on Tue Jul 12 2022 13:54:17 by
