eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

eapolutil.h (3555B)


      1 /*
      2  *
      3  *  Wireless daemon for Linux
      4  *
      5  *  Copyright (C) 2013-2019  Intel Corporation. All rights reserved.
      6  *
      7  *  This library is free software; you can redistribute it and/or
      8  *  modify it under the terms of the GNU Lesser General Public
      9  *  License as published by the Free Software Foundation; either
     10  *  version 2.1 of the License, or (at your option) any later version.
     11  *
     12  *  This library is distributed in the hope that it will be useful,
     13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  *  Lesser General Public License for more details.
     16  *
     17  *  You should have received a copy of the GNU Lesser General Public
     18  *  License along with this library; if not, write to the Free Software
     19  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     20  *
     21  */
     22 
     23 #include <stdint.h>
     24 #include <stdbool.h>
     25 #include <asm/byteorder.h>
     26 #include <linux/types.h>
     27 
     28 enum ie_rsn_akm_suite;
     29 enum ie_rsn_cipher_suite;
     30 
     31 enum eapol_protocol_version {
     32 	EAPOL_PROTOCOL_VERSION_2001	= 1,
     33 	EAPOL_PROTOCOL_VERSION_2004	= 2,
     34 	EAPOL_PROTOCOL_VERSION_2010	= 3,
     35 };
     36 
     37 /*
     38  * 802.1X-2010: Table 11-5-Descriptor Type value assignments
     39  * The WPA key type of 254 comes from somewhere else.  Seems it is a legacy
     40  * value that might still be used by older implementations
     41  */
     42 enum eapol_descriptor_type {
     43 	EAPOL_DESCRIPTOR_TYPE_RC4	= 1,
     44 	EAPOL_DESCRIPTOR_TYPE_80211	= 2,
     45 	EAPOL_DESCRIPTOR_TYPE_WPA	= 254,
     46 };
     47 
     48 enum eapol_key_descriptor_version {
     49 	EAPOL_KEY_DESCRIPTOR_VERSION_AKM_DEFINED	= 0,
     50 	EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4	= 1,
     51 	EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES	= 2,
     52 	EAPOL_KEY_DESCRIPTOR_VERSION_AES_128_CMAC_AES	= 3,
     53 };
     54 
     55 struct eapol_header {
     56 	uint8_t protocol_version;
     57 	uint8_t packet_type;
     58 	__be16 packet_len;
     59 } __attribute__ ((packed));
     60 
     61 struct eapol_frame {
     62 	struct eapol_header header;
     63 	uint8_t data[];
     64 } __attribute__ ((packed));
     65 
     66 /* gets pointer to MIC */
     67 #define EAPOL_KEY_MIC(ek) ((ek)->key_data)
     68 
     69 /* get key data length */
     70 #define EAPOL_KEY_DATA_LEN(ek, mic_len) l_get_be16((ek)->key_data + (mic_len))
     71 
     72 /* gets pointer to key data */
     73 #define EAPOL_KEY_DATA(ek, mic_len) ((ek)->key_data + (mic_len) + 2)
     74 
     75 /* gets frame length (not including key data) */
     76 #define EAPOL_FRAME_LEN(mic_len) (sizeof(struct eapol_key) + (mic_len) + 2)
     77 
     78 struct eapol_key {
     79 	struct eapol_header header;
     80 	uint8_t descriptor_type;
     81 #if defined(__LITTLE_ENDIAN_BITFIELD)
     82 	bool key_mic:1;
     83 	bool secure:1;
     84 	bool error:1;
     85 	bool request:1;
     86 	bool encrypted_key_data:1;
     87 	bool smk_message:1;
     88 	uint8_t reserved2:2;
     89 	uint8_t key_descriptor_version:3;
     90 	bool key_type:1;
     91 	uint8_t wpa_key_id:2; /* Bits 4-5 reserved in RSN, Key ID in WPA */
     92 	bool install:1;
     93 	bool key_ack:1;
     94 #elif defined (__BIG_ENDIAN_BITFIELD)
     95 	uint8_t reserved2:2;
     96 	bool smk_message:1;
     97 	bool encrypted_key_data:1;
     98 	bool request:1;
     99 	bool error:1;
    100 	bool secure:1;
    101 	bool key_mic:1;
    102 	bool key_ack:1;
    103 	bool install:1;
    104 	uint8_t wpa_key_id:2; /* Bits 4-5 reserved in RSN, Key ID in WPA */
    105 	bool key_type:1;
    106 	uint8_t key_descriptor_version:3;
    107 #else
    108 #error  "Please fix <asm/byteorder.h>"
    109 #endif
    110 
    111 	__be16 key_length;
    112 	__be64 key_replay_counter;
    113 	uint8_t key_nonce[32];
    114 	uint8_t eapol_key_iv[16];
    115 	uint8_t key_rsc[8];
    116 	uint8_t reserved[8];
    117 	uint8_t key_data[];
    118 } __attribute__ ((packed));
    119 
    120 const struct eapol_key *eapol_key_validate(const uint8_t *frame, size_t len,
    121 						size_t mic_len);
    122 int eapol_key_descriptor_version_from_akm(enum ie_rsn_akm_suite akm,
    123 					enum ie_rsn_cipher_suite pairwise,
    124 					uint8_t *out_version);