From 303683c89f11b1918d90dc791a40730fac9e0239 Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Thu, 31 Aug 2017 04:04:41 +0200 Subject: [PATCH] mpdu: Refactor mpdu structs Refactor management frame structures to take into account optional presence of some parts of the header: * drop the single structure for management header and body since the body offset is variable. * add mmpdu_get_body to locate the start of frame body. * drop the union of different management frame type bodies. * prefix names specific to management frames with "mmpdu" instead of "mpdu" including any enums based on 802.11-2012 section 8.4. * move the FC field to the mmpdu_header structure. --- src/eapol.c | 22 +++---- src/mpdu.c | 90 +++++++++++++++------------ src/mpdu.h | 170 +++++++++++++++++++++++---------------------------- src/netdev.c | 35 +++++------ 4 files changed, 158 insertions(+), 159 deletions(-) diff --git a/src/eapol.c b/src/eapol.c index 8996a28b..0f58d5cf 100644 --- a/src/eapol.c +++ b/src/eapol.c @@ -845,7 +845,7 @@ static void eapol_timeout(struct l_timeout *timeout, void *user_data) l_timeout_remove(sm->timeout); sm->timeout = NULL; - handshake_failed(sm, MPDU_REASON_CODE_4WAY_HANDSHAKE_TIMEOUT); + handshake_failed(sm, MMPDU_REASON_CODE_4WAY_HANDSHAKE_TIMEOUT); } static void eapol_write(struct eapol_sm *sm, const struct eapol_frame *ef) @@ -983,7 +983,7 @@ static void eapol_handle_ptk_1_of_4(struct eapol_sm *sm, l_info("MIC calculation failed. " "Ensure Kernel Crypto is available."); l_free(step2); - handshake_failed(sm, MPDU_REASON_CODE_UNSPECIFIED); + handshake_failed(sm, MMPDU_REASON_CODE_UNSPECIFIED); return; } @@ -998,7 +998,7 @@ static void eapol_handle_ptk_1_of_4(struct eapol_sm *sm, return; error_unspecified: - handshake_failed(sm, MPDU_REASON_CODE_UNSPECIFIED); + handshake_failed(sm, MMPDU_REASON_CODE_UNSPECIFIED); } static const uint8_t *eapol_find_rsne(const uint8_t *data, size_t data_len, @@ -1063,7 +1063,7 @@ static void eapol_handle_ptk_3_of_4(struct eapol_sm *sm, uint8_t igtk_key_index; if (!eapol_verify_ptk_3_of_4(ek, sm->handshake->wpa_ie)) { - handshake_failed(sm, MPDU_REASON_CODE_UNSPECIFIED); + handshake_failed(sm, MMPDU_REASON_CODE_UNSPECIFIED); return; } @@ -1178,7 +1178,7 @@ static void eapol_handle_ptk_3_of_4(struct eapol_sm *sm, !(info1.pairwise_ciphers & override) || __builtin_popcount(override) != 1) { handshake_failed(sm, - MPDU_REASON_CODE_INVALID_PAIRWISE_CIPHER); + MMPDU_REASON_CODE_INVALID_PAIRWISE_CIPHER); return; } @@ -1194,7 +1194,7 @@ static void eapol_handle_ptk_3_of_4(struct eapol_sm *sm, decrypted_key_data_size, >k_len); if (!gtk || gtk_len < 8) { - handshake_failed(sm, MPDU_REASON_CODE_UNSPECIFIED); + handshake_failed(sm, MMPDU_REASON_CODE_UNSPECIFIED); return; } @@ -1211,7 +1211,7 @@ static void eapol_handle_ptk_3_of_4(struct eapol_sm *sm, decrypted_key_data_size, &igtk_len); if (!igtk || igtk_len < 8) { - handshake_failed(sm, MPDU_REASON_CODE_UNSPECIFIED); + handshake_failed(sm, MMPDU_REASON_CODE_UNSPECIFIED); return; } @@ -1260,7 +1260,7 @@ fail: return; error_ie_different: - handshake_failed(sm, MPDU_REASON_CODE_IE_DIFFERENT); + handshake_failed(sm, MMPDU_REASON_CODE_IE_DIFFERENT); } static void eapol_handle_gtk_1_of_2(struct eapol_sm *sm, @@ -1279,7 +1279,7 @@ static void eapol_handle_gtk_1_of_2(struct eapol_sm *sm, uint8_t igtk_key_index; if (!eapol_verify_gtk_1_of_2(ek, sm->handshake->wpa_ie)) { - handshake_failed(sm, MPDU_REASON_CODE_UNSPECIFIED); + handshake_failed(sm, MMPDU_REASON_CODE_UNSPECIFIED); return; } @@ -1497,7 +1497,7 @@ static void eapol_eap_complete_cb(enum eap_result result, void *user_data) sm->eap = NULL; if (result != EAP_RESULT_SUCCESS) - handshake_failed(sm, MPDU_REASON_CODE_IEEE8021X_FAILED); + handshake_failed(sm, MMPDU_REASON_CODE_IEEE8021X_FAILED); } /* This respresentes the eapResults message */ @@ -1552,7 +1552,7 @@ msk_short: l_error("EAP method's MSK too short for AKM suite %u", sm->handshake->akm_suite); - handshake_failed(sm, MPDU_REASON_CODE_IEEE8021X_FAILED); + handshake_failed(sm, MMPDU_REASON_CODE_IEEE8021X_FAILED); } static void eapol_eap_event_cb(unsigned int event, diff --git a/src/mpdu.c b/src/mpdu.c index acebd8a8..cdac4477 100644 --- a/src/mpdu.c +++ b/src/mpdu.c @@ -29,7 +29,8 @@ #include "ie.h" #include "mpdu.h" -static bool validate_mgmt_header(const struct mpdu *mpdu, int len, int *offset) +static bool validate_mgmt_header(const struct mmpdu_header *mpdu, + int len, int *offset) { /* Duration + Address1 + Address 2 + Address 3 + SeqCntrl */ if (len < *offset + 22) @@ -48,42 +49,43 @@ static bool validate_mgmt_header(const struct mpdu *mpdu, int len, int *offset) return true; } -static bool validate_on_ies_start_position_mgmt_mpdu(const struct mpdu *mpdu, - int len, int *offset, - int position) +static bool validate_on_ies_start_position_mmpdu( + const struct mmpdu_header *mpdu, + int len, int *offset, int position) { return *offset + position < len; } -static bool validate_atim_mgmt_mpdu(const struct mpdu *mpdu, - int len, int *offset) +static bool validate_atim_mmpdu(const struct mmpdu_header *mpdu, + int len, int *offset) { return *offset == len; } -static bool validate_disassociation_mgmt_mpdu(const struct mpdu *mpdu, +static bool validate_disassociation_mmpdu(const struct mmpdu_header *mpdu, int len, int *offset) { *offset += 2; return *offset <= len; } -static bool validate_authentication_mgmt_mpdu(const struct mpdu *mpdu, +static bool validate_authentication_mmpdu(const struct mmpdu_header *mpdu, int len, int *offset) { uint16_t transaction_sequence; + const struct mmpdu_authentication *body = (const void *) mpdu + *offset; if (len < *offset + 6) return false; *offset += 6; - switch (L_LE16_TO_CPU(mpdu->auth.algorithm)) { - case MPDU_AUTH_ALGO_OPEN_SYSTEM: + switch (L_LE16_TO_CPU(body->algorithm)) { + case MMPDU_AUTH_ALGO_OPEN_SYSTEM: return *offset <= len; - case MPDU_AUTH_ALGO_SHARED_KEY: + case MMPDU_AUTH_ALGO_SHARED_KEY: transaction_sequence = - L_LE16_TO_CPU(mpdu->auth.transaction_sequence); + L_LE16_TO_CPU(body->transaction_sequence); if (transaction_sequence < 2 || transaction_sequence > 3) return *offset == len; @@ -93,11 +95,10 @@ static bool validate_authentication_mgmt_mpdu(const struct mpdu *mpdu, *offset += 2; - if (mpdu->auth.shared_key_23.element_id != - IE_TYPE_CHALLENGE_TEXT) + if (body->shared_key_23.element_id != IE_TYPE_CHALLENGE_TEXT) return false; - *offset += mpdu->auth.shared_key_23.challenge_text_len; + *offset += body->shared_key_23.challenge_text_len; return *offset <= len; default: return false; @@ -106,51 +107,52 @@ static bool validate_authentication_mgmt_mpdu(const struct mpdu *mpdu, return false; } -static bool validate_deauthentication_mgmt_mpdu(const struct mpdu *mpdu, +static bool validate_deauthentication_mmpdu(const struct mmpdu_header *mpdu, int len, int *offset) { *offset += 2; return *offset <= len; } -static bool validate_mgmt_mpdu(const struct mpdu *mpdu, int len, int *offset) +static bool validate_mgmt_mpdu(const struct mmpdu_header *mpdu, int len, + int *offset) { if (!validate_mgmt_header(mpdu, len, offset)) return false; switch (mpdu->fc.subtype) { case MPDU_MANAGEMENT_SUBTYPE_ASSOCIATION_REQUEST: - return validate_on_ies_start_position_mgmt_mpdu(mpdu, len, + return validate_on_ies_start_position_mmpdu(mpdu, len, offset, 9); case MPDU_MANAGEMENT_SUBTYPE_ASSOCIATION_RESPONSE: - return validate_on_ies_start_position_mgmt_mpdu(mpdu, len, + return validate_on_ies_start_position_mmpdu(mpdu, len, offset, 9); case MPDU_MANAGEMENT_SUBTYPE_REASSOCIATION_REQUEST: - return validate_on_ies_start_position_mgmt_mpdu(mpdu, len, + return validate_on_ies_start_position_mmpdu(mpdu, len, offset, 15); case MPDU_MANAGEMENT_SUBTYPE_REASSOCIATION_RESPONSE: - return validate_on_ies_start_position_mgmt_mpdu(mpdu, len, + return validate_on_ies_start_position_mmpdu(mpdu, len, offset, 9); case MPDU_MANAGEMENT_SUBTYPE_PROBE_REQUEST: - return validate_on_ies_start_position_mgmt_mpdu(mpdu, len, + return validate_on_ies_start_position_mmpdu(mpdu, len, offset, 0); case MPDU_MANAGEMENT_SUBTYPE_PROBE_RESPONSE: - return validate_on_ies_start_position_mgmt_mpdu(mpdu, len, + return validate_on_ies_start_position_mmpdu(mpdu, len, offset, 5); case MPDU_MANAGEMENT_SUBTYPE_TIMING_ADVERTISEMENT: - return validate_on_ies_start_position_mgmt_mpdu(mpdu, len, + return validate_on_ies_start_position_mmpdu(mpdu, len, offset, 3); case MPDU_MANAGEMENT_SUBTYPE_BEACON: - return validate_on_ies_start_position_mgmt_mpdu(mpdu, len, + return validate_on_ies_start_position_mmpdu(mpdu, len, offset, 5); case MPDU_MANAGEMENT_SUBTYPE_ATIM: - return validate_atim_mgmt_mpdu(mpdu, len, offset); + return validate_atim_mmpdu(mpdu, len, offset); case MPDU_MANAGEMENT_SUBTYPE_DISASSOCIATION: - return validate_disassociation_mgmt_mpdu(mpdu, len, offset); + return validate_disassociation_mmpdu(mpdu, len, offset); case MPDU_MANAGEMENT_SUBTYPE_AUTHENTICATION: - return validate_authentication_mgmt_mpdu(mpdu, len, offset); + return validate_authentication_mmpdu(mpdu, len, offset); case MPDU_MANAGEMENT_SUBTYPE_DEAUTHENTICATION: - return validate_deauthentication_mgmt_mpdu(mpdu, len, offset); + return validate_deauthentication_mmpdu(mpdu, len, offset); default: return false; } @@ -158,10 +160,10 @@ static bool validate_mgmt_mpdu(const struct mpdu *mpdu, int len, int *offset) return true; } -const struct mpdu *mpdu_validate(const uint8_t *frame, int len) +const struct mmpdu_header *mpdu_validate(const uint8_t *frame, int len) { - const struct mpdu *mpdu; - bool valid; + const struct mpdu_fc *fc; + const struct mmpdu_header *mmpdu; int offset; if (!frame) @@ -171,15 +173,27 @@ const struct mpdu *mpdu_validate(const uint8_t *frame, int len) return NULL; offset = 2; - mpdu = (const struct mpdu *) frame; + fc = (const struct mpdu_fc *) frame; - switch (mpdu->fc.type) { + switch (fc->type) { case MPDU_TYPE_MANAGEMENT: - valid = validate_mgmt_mpdu(mpdu, len, &offset); - break; + mmpdu = (const struct mmpdu_header *) mmpdu; + + if (validate_mgmt_mpdu(mmpdu, len, &offset)) + return mmpdu; + + return NULL; default: return NULL; } - - return valid ? mpdu : NULL; +} + +static size_t mmpdu_header_len(const struct mmpdu_header *mmpdu) +{ + return mmpdu->fc.order == 0 ? 24 : 28; +} + +const void *mmpdu_body(const struct mmpdu_header *mmpdu) +{ + return ((const uint8_t *) mmpdu + mmpdu_header_len(mmpdu)); } diff --git a/src/mpdu.h b/src/mpdu.h index a243cec5..389b9b74 100644 --- a/src/mpdu.h +++ b/src/mpdu.h @@ -50,69 +50,69 @@ enum mpdu_management_subtype { }; /* 802.11, Section 8.4.1.1 Authentication Algorithm Number field */ -enum mpdu_authentication_algorithm_number { - MPDU_AUTH_ALGO_OPEN_SYSTEM = 0, - MPDU_AUTH_ALGO_SHARED_KEY, +enum mmpdu_authentication_algorithm_number { + MMPDU_AUTH_ALGO_OPEN_SYSTEM = 0, + MMPDU_AUTH_ALGO_SHARED_KEY, }; /* * 802.11-2012, Section 8.4.1.7: */ -enum mpdu_reason_code { - MPDU_REASON_CODE_UNSPECIFIED = 1, - MPDU_REASON_CODE_PREV_AUTH_NOT_VALID = 2, - MPDU_REASON_CODE_DEAUTH_LEAVING = 3, - MPDU_REASON_CODE_DISASSOC_DUE_TO_INACTIVITY = 4, - MPDU_REASON_CODE_DISASSOC_AP_BUSY = 5, - MPDU_REASON_CODE_CLASS2_FRAME_FROM_NONAUTH_STA = 6, - MPDU_REASON_CODE_CLASS3_FRAME_FROM_NONASSOC_STA = 7, - MPDU_REASON_CODE_DISASSOC_STA_HAS_LEFT = 8, - MPDU_REASON_CODE_STA_REQ_ASSOC_WITHOUT_AUTH = 9, +enum mmpdu_reason_code { + MMPDU_REASON_CODE_UNSPECIFIED = 1, + MMPDU_REASON_CODE_PREV_AUTH_NOT_VALID = 2, + MMPDU_REASON_CODE_DEAUTH_LEAVING = 3, + MMPDU_REASON_CODE_DISASSOC_DUE_TO_INACTIVITY = 4, + MMPDU_REASON_CODE_DISASSOC_AP_BUSY = 5, + MMPDU_REASON_CODE_CLASS2_FRAME_FROM_NONAUTH_STA = 6, + MMPDU_REASON_CODE_CLASS3_FRAME_FROM_NONASSOC_STA = 7, + MMPDU_REASON_CODE_DISASSOC_STA_HAS_LEFT = 8, + MMPDU_REASON_CODE_STA_REQ_ASSOC_WITHOUT_AUTH = 9, /* 802.11h */ - MPDU_REASON_CODE_DISASSOC_BAD_POWER = 10, - MPDU_REASON_CODE_DISASSOC_BAD_SUPP_CHAN = 11, + MMPDU_REASON_CODE_DISASSOC_BAD_POWER = 10, + MMPDU_REASON_CODE_DISASSOC_BAD_SUPP_CHAN = 11, /* 802.11i */ - MPDU_REASON_CODE_INVALID_IE = 13, - MPDU_REASON_CODE_MIC_FAILURE = 14, - MPDU_REASON_CODE_4WAY_HANDSHAKE_TIMEOUT = 15, - MPDU_REASON_CODE_GROUP_KEY_HANDSHAKE_TIMEOUT = 16, - MPDU_REASON_CODE_IE_DIFFERENT = 17, - MPDU_REASON_CODE_INVALID_GROUP_CIPHER = 18, - MPDU_REASON_CODE_INVALID_PAIRWISE_CIPHER = 19, - MPDU_REASON_CODE_INVALID_AKMP = 20, - MPDU_REASON_CODE_UNSUPP_RSN_VERSION = 21, - MPDU_REASON_CODE_INVALID_RSN_IE_CAP = 22, - MPDU_REASON_CODE_IEEE8021X_FAILED = 23, - MPDU_REASON_CODE_CIPHER_SUITE_REJECTED = 24, + MMPDU_REASON_CODE_INVALID_IE = 13, + MMPDU_REASON_CODE_MIC_FAILURE = 14, + MMPDU_REASON_CODE_4WAY_HANDSHAKE_TIMEOUT = 15, + MMPDU_REASON_CODE_GROUP_KEY_HANDSHAKE_TIMEOUT = 16, + MMPDU_REASON_CODE_IE_DIFFERENT = 17, + MMPDU_REASON_CODE_INVALID_GROUP_CIPHER = 18, + MMPDU_REASON_CODE_INVALID_PAIRWISE_CIPHER = 19, + MMPDU_REASON_CODE_INVALID_AKMP = 20, + MMPDU_REASON_CODE_UNSUPP_RSN_VERSION = 21, + MMPDU_REASON_CODE_INVALID_RSN_IE_CAP = 22, + MMPDU_REASON_CODE_IEEE8021X_FAILED = 23, + MMPDU_REASON_CODE_CIPHER_SUITE_REJECTED = 24, /* TDLS (802.11z) */ - MPDU_REASON_CODE_TDLS_TEARDOWN_UNREACHABLE = 25, - MPDU_REASON_CODE_TDLS_TEARDOWN_UNSPECIFIED = 26, + MMPDU_REASON_CODE_TDLS_TEARDOWN_UNREACHABLE = 25, + MMPDU_REASON_CODE_TDLS_TEARDOWN_UNSPECIFIED = 26, /* 802.11e */ - MPDU_REASON_CODE_DISASSOC_UNSPECIFIED_QOS = 32, - MPDU_REASON_CODE_DISASSOC_QAP_NO_BANDWIDTH = 33, - MPDU_REASON_CODE_DISASSOC_LOW_ACK = 34, - MPDU_REASON_CODE_DISASSOC_QAP_EXCEED_TXOP = 35, - MPDU_REASON_CODE_QSTA_LEAVE_QBSS = 36, - MPDU_REASON_CODE_QSTA_NOT_USE = 37, - MPDU_REASON_CODE_QSTA_REQUIRE_SETUP = 38, - MPDU_REASON_CODE_QSTA_TIMEOUT = 39, - MPDU_REASON_CODE_QSTA_CIPHER_NOT_SUPP = 45, + MMPDU_REASON_CODE_DISASSOC_UNSPECIFIED_QOS = 32, + MMPDU_REASON_CODE_DISASSOC_QAP_NO_BANDWIDTH = 33, + MMPDU_REASON_CODE_DISASSOC_LOW_ACK = 34, + MMPDU_REASON_CODE_DISASSOC_QAP_EXCEED_TXOP = 35, + MMPDU_REASON_CODE_QSTA_LEAVE_QBSS = 36, + MMPDU_REASON_CODE_QSTA_NOT_USE = 37, + MMPDU_REASON_CODE_QSTA_REQUIRE_SETUP = 38, + MMPDU_REASON_CODE_QSTA_TIMEOUT = 39, + MMPDU_REASON_CODE_QSTA_CIPHER_NOT_SUPP = 45, /* 802.11s */ - MPDU_REASON_CODE_MESH_PEER_CANCELED = 52, - MPDU_REASON_CODE_MESH_MAX_PEERS = 53, - MPDU_REASON_CODE_MESH_CONFIG = 54, - MPDU_REASON_CODE_MESH_CLOSE = 55, - MPDU_REASON_CODE_MESH_MAX_RETRIES = 56, - MPDU_REASON_CODE_MESH_CONFIRM_TIMEOUT = 57, - MPDU_REASON_CODE_MESH_INVALID_GTK = 58, - MPDU_REASON_CODE_MESH_INCONSISTENT_PARAM = 59, - MPDU_REASON_CODE_MESH_INVALID_SECURITY = 60, - MPDU_REASON_CODE_MESH_PATH_ERROR = 61, - MPDU_REASON_CODE_MESH_PATH_NOFORWARD = 62, - MPDU_REASON_CODE_MESH_PATH_DEST_UNREACHABLE = 63, - MPDU_REASON_CODE_MAC_EXISTS_IN_MBSS = 64, - MPDU_REASON_CODE_MESH_CHAN_REGULATORY = 65, - MPDU_REASON_CODE_MESH_CHAN = 66, + MMPDU_REASON_CODE_MESH_PEER_CANCELED = 52, + MMPDU_REASON_CODE_MESH_MAX_PEERS = 53, + MMPDU_REASON_CODE_MESH_CONFIG = 54, + MMPDU_REASON_CODE_MESH_CLOSE = 55, + MMPDU_REASON_CODE_MESH_MAX_RETRIES = 56, + MMPDU_REASON_CODE_MESH_CONFIRM_TIMEOUT = 57, + MMPDU_REASON_CODE_MESH_INVALID_GTK = 58, + MMPDU_REASON_CODE_MESH_INCONSISTENT_PARAM = 59, + MMPDU_REASON_CODE_MESH_INVALID_SECURITY = 60, + MMPDU_REASON_CODE_MESH_PATH_ERROR = 61, + MMPDU_REASON_CODE_MESH_PATH_NOFORWARD = 62, + MMPDU_REASON_CODE_MESH_PATH_DEST_UNREACHABLE = 63, + MMPDU_REASON_CODE_MAC_EXISTS_IN_MBSS = 64, + MMPDU_REASON_CODE_MESH_CHAN_REGULATORY = 65, + MMPDU_REASON_CODE_MESH_CHAN = 66, }; /* 802.11, Section 8.2.4.1.1, Figure 8-2 */ @@ -147,7 +147,8 @@ struct mpdu_fc { } __attribute__ ((packed)); /* 802.11, Section 8.3.3.1 */ -struct mpdu_mgmt_header { +struct mmpdu_header { + struct mpdu_fc fc; __le16 duration; unsigned char address_1[6]; unsigned char address_2[6]; @@ -165,11 +166,11 @@ struct mpdu_mgmt_header { __le32 ht_control; /* ToDo? */ } __attribute__ ((packed)); -#define MPDU_MGMT_SEQUENCE_NUMBER(v) \ +#define MPDU_SEQUENCE_NUMBER(v) \ (((v).sequence_number_high << 4) + ((v).sequence_number_low)) /* 802.11, Section 8.4.1.4 */ -struct mpdu_field_capability { +struct mmpdu_field_capability { #if defined(__LITTLE_ENDIAN_BITFIELD) bool ess:1; bool ibss:1; @@ -210,72 +211,72 @@ struct mpdu_field_capability { } __attribute__ ((packed)); /* 802.11, Section 8.3.3.5 */ -struct mpdu_association_request { - struct mpdu_field_capability capability; +struct mmpdu_association_request { + struct mmpdu_field_capability capability; __le16 listen_interval; uint8_t ies[0]; } __attribute__ ((packed)); /* 802.11, Section 8.3.3.6 */ -struct mpdu_association_response { - struct mpdu_field_capability capability; +struct mmpdu_association_response { + struct mmpdu_field_capability capability; __le16 status_code; __le16 aid; uint8_t ies[0]; } __attribute__ ((packed)); /* 802.11, Section 8.3.3.7 */ -struct mpdu_reassociation_request { - struct mpdu_field_capability capability; +struct mmpdu_reassociation_request { + struct mmpdu_field_capability capability; __le16 listen_interval; unsigned char current_ap_address[6]; uint8_t ies[0]; } __attribute__ ((packed)); /* 802.11, Section 8.3.3.8 */ -struct mpdu_reassociation_response { - struct mpdu_field_capability capability; +struct mmpdu_reassociation_response { + struct mmpdu_field_capability capability; __le16 status_code; __le16 aid; uint8_t ies[0]; } __attribute__ ((packed)); /* 802.11, Section 8.3.3.4 */ -struct mpdu_disassociation { +struct mmpdu_disassociation { __le16 reason_code; uint8_t ies[0]; } __attribute__ ((packed)); /* 802.11, Section 8.3.3.9 */ -struct mpdu_probe_request { +struct mmpdu_probe_request { uint8_t ies[0]; } __attribute__ ((packed)); /* 802.11, Section 8.3.3.10 */ -struct mpdu_probe_response { +struct mmpdu_probe_response { uint8_t timestamp; __le16 beacon_interval; - struct mpdu_field_capability capability; + struct mmpdu_field_capability capability; uint8_t ies[0]; } __attribute__ ((packed)); /* 802.11, Section 8.3.3.15 */ -struct mpdu_timing_advertisement { +struct mmpdu_timing_advertisement { uint8_t timestamp; - struct mpdu_field_capability capability; + struct mmpdu_field_capability capability; uint8_t ies[0]; } __attribute__ ((packed)); /* 802.11, Section 8.3.3.2 */ -struct mpdu_beacon { +struct mmpdu_beacon { uint8_t timestamp; __le16 beacon_interval; - struct mpdu_field_capability capability; + struct mmpdu_field_capability capability; uint8_t ies[0]; } __attribute__ ((packed)); /* 802.11, Section 8.3.3.11 */ -struct mpdu_authentication { +struct mmpdu_authentication { __le16 algorithm; __le16 transaction_sequence; __le16 status; @@ -291,27 +292,10 @@ struct mpdu_authentication { } __attribute__ ((packed)); /* 802.11, Section 8.3.3.12 */ -struct mpdu_deauthentication { +struct mmpdu_deauthentication { __le16 reason_code; uint8_t ies[0]; } __attribute__ ((packed)); -struct mpdu { - struct mpdu_fc fc; - struct mpdu_mgmt_header mgmt_hdr; - union { - struct mpdu_association_request assoc_req; - struct mpdu_association_response assoc_resp; - struct mpdu_reassociation_request reassoc_req; - struct mpdu_reassociation_response reassoc_resp; - struct mpdu_probe_request probe_req; - struct mpdu_probe_response probe_resp; - struct mpdu_timing_advertisement time_advert; - struct mpdu_beacon beacon; - struct mpdu_disassociation disassoc; - struct mpdu_authentication auth; - struct mpdu_deauthentication deauth; - }; -} __attribute__ ((packed)); - -const struct mpdu *mpdu_validate(const uint8_t *frame, int len); +const struct mmpdu_header *mpdu_validate(const uint8_t *frame, int len); +const void *mmpdu_body(const struct mmpdu_header *mpdu); diff --git a/src/netdev.c b/src/netdev.c index 86e96f7f..2b5c3d44 100644 --- a/src/netdev.c +++ b/src/netdev.c @@ -885,7 +885,8 @@ static void netdev_setting_keys_failed(struct netdev *netdev, netdev->group_management_new_key_cmd_id = 0; netdev->result = NETDEV_RESULT_KEY_SETTING_FAILED; - msg = netdev_build_cmd_disconnect(netdev, MPDU_REASON_CODE_UNSPECIFIED); + msg = netdev_build_cmd_disconnect(netdev, + MMPDU_REASON_CODE_UNSPECIFIED); netdev->disconnect_cmd_id = l_genl_family_send(nl80211, msg, netdev_connect_failed, netdev, NULL); @@ -906,7 +907,7 @@ static void netdev_set_station_cb(struct l_genl_msg *msg, void *user_data) if (err < 0) { l_error("Set Station failed for ifindex %d", netdev->index); netdev_setting_keys_failed(netdev, - MPDU_REASON_CODE_UNSPECIFIED); + MMPDU_REASON_CODE_UNSPECIFIED); return; } @@ -952,7 +953,7 @@ static void netdev_new_group_key_cb(struct l_genl_msg *msg, void *data) return; error: - netdev_setting_keys_failed(netdev, MPDU_REASON_CODE_UNSPECIFIED); + netdev_setting_keys_failed(netdev, MMPDU_REASON_CODE_UNSPECIFIED); } static void netdev_new_group_management_key_cb(struct l_genl_msg *msg, @@ -966,7 +967,7 @@ static void netdev_new_group_management_key_cb(struct l_genl_msg *msg, l_error("New Key for Group Mgmt failed for ifindex: %d", netdev->index); netdev_setting_keys_failed(netdev, - MPDU_REASON_CODE_UNSPECIFIED); + MMPDU_REASON_CODE_UNSPECIFIED); } } @@ -1010,7 +1011,7 @@ static void netdev_set_gtk(uint32_t ifindex, uint8_t key_index, if (crypto_cipher_key_len(cipher) != gtk_len) { l_error("Unexpected key length: %d", gtk_len); netdev_setting_keys_failed(netdev, - MPDU_REASON_CODE_INVALID_GROUP_CIPHER); + MMPDU_REASON_CODE_INVALID_GROUP_CIPHER); return; } @@ -1045,7 +1046,7 @@ static void netdev_set_gtk(uint32_t ifindex, uint8_t key_index, default: l_error("Unexpected cipher: %x", cipher); netdev_setting_keys_failed(netdev, - MPDU_REASON_CODE_INVALID_GROUP_CIPHER); + MMPDU_REASON_CODE_INVALID_GROUP_CIPHER); return; } @@ -1060,7 +1061,7 @@ static void netdev_set_gtk(uint32_t ifindex, uint8_t key_index, return; l_genl_msg_unref(msg); - netdev_setting_keys_failed(netdev, MPDU_REASON_CODE_UNSPECIFIED); + netdev_setting_keys_failed(netdev, MMPDU_REASON_CODE_UNSPECIFIED); } static void netdev_set_igtk(uint32_t ifindex, uint8_t key_index, @@ -1079,7 +1080,7 @@ static void netdev_set_igtk(uint32_t ifindex, uint8_t key_index, if (crypto_cipher_key_len(cipher) != igtk_len) { l_error("Unexpected key length: %d", igtk_len); netdev_setting_keys_failed(netdev, - MPDU_REASON_CODE_INVALID_GROUP_CIPHER); + MMPDU_REASON_CODE_INVALID_GROUP_CIPHER); return; } @@ -1090,7 +1091,7 @@ static void netdev_set_igtk(uint32_t ifindex, uint8_t key_index, default: l_error("Unexpected cipher: %x", cipher); netdev_setting_keys_failed(netdev, - MPDU_REASON_CODE_INVALID_GROUP_CIPHER); + MMPDU_REASON_CODE_INVALID_GROUP_CIPHER); return; } @@ -1106,7 +1107,7 @@ static void netdev_set_igtk(uint32_t ifindex, uint8_t key_index, return; l_genl_msg_unref(msg); - netdev_setting_keys_failed(netdev, MPDU_REASON_CODE_UNSPECIFIED); + netdev_setting_keys_failed(netdev, MMPDU_REASON_CODE_UNSPECIFIED); } static void netdev_set_pairwise_key_cb(struct l_genl_msg *msg, void *data) @@ -1120,7 +1121,7 @@ static void netdev_set_pairwise_key_cb(struct l_genl_msg *msg, void *data) l_error("Set Key for Pairwise Key failed for ifindex: %d", netdev->index); - netdev_setting_keys_failed(netdev, MPDU_REASON_CODE_UNSPECIFIED); + netdev_setting_keys_failed(netdev, MMPDU_REASON_CODE_UNSPECIFIED); } static struct l_genl_msg *netdev_build_cmd_set_key_pairwise( @@ -1154,7 +1155,7 @@ static void netdev_new_pairwise_key_cb(struct l_genl_msg *msg, void *data) l_error("New Key for Pairwise Key failed for ifindex: %d", netdev->index); - netdev_setting_keys_failed(netdev, MPDU_REASON_CODE_UNSPECIFIED); + netdev_setting_keys_failed(netdev, MMPDU_REASON_CODE_UNSPECIFIED); } static struct l_genl_msg *netdev_build_cmd_new_key_pairwise( @@ -1228,7 +1229,7 @@ static void netdev_set_tk(uint32_t ifindex, const uint8_t *aa, default: l_error("Unexpected cipher: %x", cipher); netdev_setting_keys_failed(netdev, - MPDU_REASON_CODE_INVALID_PAIRWISE_CIPHER); + MMPDU_REASON_CODE_INVALID_PAIRWISE_CIPHER); return; } @@ -1253,7 +1254,7 @@ static void netdev_set_tk(uint32_t ifindex, const uint8_t *aa, l_genl_msg_unref(msg); error: - netdev_setting_keys_failed(netdev, MPDU_REASON_CODE_UNSPECIFIED); + netdev_setting_keys_failed(netdev, MMPDU_REASON_CODE_UNSPECIFIED); } static void netdev_handshake_failed(uint32_t ifindex, @@ -1771,7 +1772,7 @@ static void netdev_cmd_ft_reassociate_cb(struct l_genl_msg *msg, netdev->result = NETDEV_RESULT_ASSOCIATION_FAILED; cmd_deauth = netdev_build_cmd_deauthenticate(netdev, - MPDU_REASON_CODE_UNSPECIFIED); + MMPDU_REASON_CODE_UNSPECIFIED); netdev->disconnect_cmd_id = l_genl_family_send(nl80211, cmd_deauth, netdev_connect_failed, @@ -2013,7 +2014,7 @@ auth_error: ft_error: netdev->result = NETDEV_RESULT_AUTHENTICATION_FAILED; cmd_deauth = netdev_build_cmd_deauthenticate(netdev, - MPDU_REASON_CODE_UNSPECIFIED); + MMPDU_REASON_CODE_UNSPECIFIED); netdev->disconnect_cmd_id = l_genl_family_send(nl80211, cmd_deauth, netdev_connect_failed, netdev, NULL); @@ -2296,7 +2297,7 @@ int netdev_disconnect(struct netdev *netdev, } disconnect = netdev_build_cmd_disconnect(netdev, - MPDU_REASON_CODE_DEAUTH_LEAVING); + MMPDU_REASON_CODE_DEAUTH_LEAVING); netdev->disconnect_cmd_id = l_genl_family_send(nl80211, disconnect, netdev_cmd_disconnect_cb, netdev, NULL);