e6c1b20a614bcd52748529baff1bb078af879359
[obnox/wireshark/wip.git] / epan / crypt / airpdcap_int.h
1 /* airpcap_int.h
2  *
3  * $Id$
4  *
5  * Copyright (c) 2006 CACE Technologies, Davis (California)
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the project nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * Alternatively, this software may be distributed under the terms of the
21  * GNU General Public License ("GPL") version 2 as published by the Free
22  * Software Foundation.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  */
36
37 #ifndef _AIRPDCAP_INT_H
38 #define _AIRPDCAP_INT_H
39
40 /****************************************************************************/
41 /*      File includes                                                           */
42
43 #include "airpdcap_interop.h"
44
45 /****************************************************************************/
46
47 /****************************************************************************/
48 /* Definitions                                                                  */
49
50 /* IEEE 802.11 packet type values                                               */
51 #define AIRPDCAP_TYPE_MANAGEMENT                0
52 #define AIRPDCAP_TYPE_CONTROL                   1
53 #define AIRPDCAP_TYPE_DATA                      2
54
55 /* Min length of encrypted data (TKIP=25bytes, CCMP=21bytes)                    */
56 #define AIRPDCAP_CRYPTED_DATA_MINLEN    21
57
58 #define AIRPDCAP_TA_OFFSET      10
59
60 /*                                                                              */
61 /****************************************************************************/
62
63 /****************************************************************************/
64 /* Macro definitions                                                            */
65
66 /**
67  * Macros to get various bits of a 802.11 control frame
68  */
69 #define AIRPDCAP_TYPE(FrameControl_0)           (UINT8)((FrameControl_0 >> 2) & 0x3)
70 #define AIRPDCAP_SUBTYPE(FrameControl_0)        (UINT8)((FrameControl_0 >> 4) & 0xF)
71 #define AIRPDCAP_DS_BITS(FrameControl_1)        (UINT8)(FrameControl_1 & 0x3)
72 #define AIRPDCAP_TO_DS(FrameControl_1)          (UINT8)(FrameControl_1 & 0x1)
73 #define AIRPDCAP_FROM_DS(FrameControl_1)        (UINT8)((FrameControl_1 >> 1) & 0x1)
74 #define AIRPDCAP_WEP(FrameControl_1)            (UINT8)((FrameControl_1 >> 6) & 0x1)
75
76 /**
77  * Get the Key ID from the Initialization Vector (last byte)
78  */
79 #define AIRPDCAP_EXTIV(KeyID)   ((KeyID >> 5) & 0x1)
80
81 #define AIRPDCAP_KEY_INDEX(KeyID)       ((KeyID >> 6) & 0x3)  /** Used to determine TKIP group key from unicast (group = 1, unicast = 0) */
82
83 /* Macros to get various bits of an EAPOL frame                         */
84 #define AIRPDCAP_EAP_KEY_DESCR_VER(KeyInfo_1)   ((UCHAR)(KeyInfo_1 & 0x3))
85 #define AIRPDCAP_EAP_KEY(KeyInfo_1)             ((KeyInfo_1 >> 3) & 0x1)
86 #define AIRPDCAP_EAP_INST(KeyInfo_1)            ((KeyInfo_1 >> 6) & 0x1)
87 #define AIRPDCAP_EAP_ACK(KeyInfo_1)             ((KeyInfo_1 >> 7) & 0x1)
88 #define AIRPDCAP_EAP_MIC(KeyInfo_0)             (KeyInfo_0 & 0x1)
89 #define AIRPDCAP_EAP_SEC(KeyInfo_0)             ((KeyInfo_0 >> 1) & 0x1)
90
91 /****************************************************************************/
92
93 /****************************************************************************/
94 /* Structure definitions                                                        */
95
96 /*
97  * XXX - According to the thread at
98  * http://www.wireshark.org/lists/wireshark-dev/200612/msg00384.html we
99  * shouldn't have to worry about packing our structs, since the largest
100  * elements are 8 bits wide.
101  */
102 #ifdef _MSC_VER         /* MS Visual C++ */
103 #pragma pack(push)
104 #pragma pack(1)
105 #endif
106
107 /* Definition of IEEE 802.11 frame (without the address 4)                      */
108 typedef struct _AIRPDCAP_MAC_FRAME {
109         UCHAR   fc[2];
110         UCHAR   dur[2];
111         UCHAR   addr1[AIRPDCAP_MAC_LEN];
112         UCHAR   addr2[AIRPDCAP_MAC_LEN];
113         UCHAR   addr3[AIRPDCAP_MAC_LEN];
114         UCHAR   seq[2];
115 } AIRPDCAP_MAC_FRAME, *PAIRPDCAP_MAC_FRAME;
116
117 /* Definition of IEEE 802.11 frame (with the address 4)                 */
118 typedef struct _AIRPDCAP_MAC_FRAME_ADDR4 {
119         UCHAR   fc[2];
120         UCHAR   dur[2];
121         UCHAR   addr1[AIRPDCAP_MAC_LEN];
122         UCHAR   addr2[AIRPDCAP_MAC_LEN];
123         UCHAR   addr3[AIRPDCAP_MAC_LEN];
124         UCHAR   seq[2];
125         UCHAR   addr4[AIRPDCAP_MAC_LEN];
126 } AIRPDCAP_MAC_FRAME_ADDR4, *PAIRPDCAP_MAC_FRAME_ADDR4;
127
128 /* Definition of IEEE 802.11 frame (without the address 4, with QOS)            */
129 typedef struct _AIRPDCAP_MAC_FRAME_QOS {
130         UCHAR   fc[2];
131         UCHAR   dur[2];
132         UCHAR   addr1[AIRPDCAP_MAC_LEN];
133         UCHAR   addr2[AIRPDCAP_MAC_LEN];
134         UCHAR   addr3[AIRPDCAP_MAC_LEN];
135         UCHAR   seq[2];
136         UCHAR   qos[2];
137 } AIRPDCAP_MAC_FRAME_QOS, *PAIRPDCAP_MAC_FRAME_QOS;
138
139 /* Definition of IEEE 802.11 frame (with the address 4 and QOS)         */
140 typedef struct _AIRPDCAP_MAC_FRAME_ADDR4_QOS {
141         UCHAR   fc[2];
142         UCHAR   dur[2];
143         UCHAR   addr1[AIRPDCAP_MAC_LEN];
144         UCHAR   addr2[AIRPDCAP_MAC_LEN];
145         UCHAR   addr3[AIRPDCAP_MAC_LEN];
146         UCHAR   seq[2];
147         UCHAR   addr4[AIRPDCAP_MAC_LEN];
148         UCHAR   qos[2];
149 } AIRPDCAP_MAC_FRAME_ADDR4_QOS, *PAIRPDCAP_MAC_FRAME_ADDR4_QOS;
150
151 #ifdef _MSC_VER         /* MS Visual C++ */
152 #pragma pack(pop)
153 #endif
154
155 /******************************************************************************/
156
157 #endif