summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-04-08 14:15:35 (UTC)
committer mickeyl <mickeyl>2003-04-08 14:15:35 (UTC)
commit1af4ae3d621d63c82f7d78efda05218a3457981f (patch) (unidiff)
tree99423ee25f8bf9d008d8e990725c4ecefc864ecd
parent77b1330ad7380ac87db4ab532acec7ae11c3bd3a (diff)
downloadopie-1af4ae3d621d63c82f7d78efda05218a3457981f.zip
opie-1af4ae3d621d63c82f7d78efda05218a3457981f.tar.gz
opie-1af4ae3d621d63c82f7d78efda05218a3457981f.tar.bz2
- add skeleton for the last missing parts in the 802.11 decoding framework
- fix huge memory leak in packet capturer - add more fine granular 802.11 subtype handling
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/802_11_user.h16
-rw-r--r--libopie2/opienet/opcap.cpp103
-rw-r--r--libopie2/opienet/opcap.h22
3 files changed, 108 insertions, 33 deletions
diff --git a/libopie2/opienet/802_11_user.h b/libopie2/opienet/802_11_user.h
index ffdcb93..f596bd8 100644
--- a/libopie2/opienet/802_11_user.h
+++ b/libopie2/opienet/802_11_user.h
@@ -1,427 +1,443 @@
1#ifndef IEEE_802_11 1#ifndef IEEE_802_11
2#define IEEE_802_11 2#define IEEE_802_11
3 3
4enum ieee_802_11_link_status_failure_reason { 4enum ieee_802_11_link_status_failure_reason {
5 reserved0, Unspecified=1, Previous_not_valid, 5 reserved0, Unspecified=1, Previous_not_valid,
6 Sender_Quits_ESS_or_IBSS, 6 Sender_Quits_ESS_or_IBSS,
7 Due_Inactivity, AP_Overload, 7 Due_Inactivity, AP_Overload,
8 Class_2_from_NonAuth, 8 Class_2_from_NonAuth,
9 Class_3_from_NonAuth, 9 Class_3_from_NonAuth,
10 Sender_Quits_BSS, 10 Sender_Quits_BSS,
11 Association_requester_not_authenticated, 11 Association_requester_not_authenticated,
12 Reserved10 12 Reserved10
13}; 13};
14 14
15 15
16#define IEEE_802_11_LINK_STATUS_FAILURE_REASON_STRINGS \ 16#define IEEE_802_11_LINK_STATUS_FAILURE_REASON_STRINGS \
17 {\ 17 {\
18 {reserved0, 0xff," Reserved reason "},\ 18 {reserved0, 0xff," Reserved reason "},\
19 {Unspecified, 0xff," Unspecified Reason "},\ 19 {Unspecified, 0xff," Unspecified Reason "},\
20 {Previous_not_valid,0xff," Previous Authentication no longer valid "},\ 20 {Previous_not_valid,0xff," Previous Authentication no longer valid "},\
21 {Sender_Quits_ESS_or_IBSS,0xff," Deauthenticated because sending station is leaving (has left) IBSS or ESS "},\ 21 {Sender_Quits_ESS_or_IBSS,0xff," Deauthenticated because sending station is leaving (has left) IBSS or ESS "},\
22 {Due_Inactivity,0xff," Disassociated due to inactivity "},\ 22 {Due_Inactivity,0xff," Disassociated due to inactivity "},\
23 {AP_Overload, 0xff," Disassociated because AP is unable to handle all currently associated stations "},\ 23 {AP_Overload, 0xff," Disassociated because AP is unable to handle all currently associated stations "},\
24 {Class_2_from_NonAuth,0xff," Class 2 frame received from non-Authenticated station"},\ 24 {Class_2_from_NonAuth,0xff," Class 2 frame received from non-Authenticated station"},\
25 {Class_3_from_NonAuth,0xff," Class 3 frame received from non­Associated station"},\ 25 {Class_3_from_NonAuth,0xff," Class 3 frame received from non­Associated station"},\
26 {Sender_Quits_BSS,0xff," Disassociated because sending station is leaving (has left) BSS"},\ 26 {Sender_Quits_BSS,0xff," Disassociated because sending station is leaving (has left) BSS"},\
27 {Association_requester_not_authenticated,0xff," Station requesting (Re)Association is not Authenticated with responding station"},\ 27 {Association_requester_not_authenticated,0xff," Station requesting (Re)Association is not Authenticated with responding station"},\
28 {Reserved10, 0xff," Reserved"},\ 28 {Reserved10, 0xff," Reserved"},\
29 {0,0,NULL}\ 29 {0,0,NULL}\
30}; 30};
31 31
32 32
33 33
34struct ieee_802_11_header { 34struct ieee_802_11_header {
35 u_int16_tframe_control;// needs to be subtyped 35 u_int16_tframe_control;// needs to be subtyped
36 u_int16_tduration; 36 u_int16_tduration;
37 u_int8_tmac1[6]; 37 u_int8_tmac1[6];
38 u_int8_tmac2[6]; 38 u_int8_tmac2[6];
39 u_int8_tmac3[6]; 39 u_int8_tmac3[6];
40 u_int16_tSeqCtl; 40 u_int16_tSeqCtl;
41 u_int8_tmac4[6]; 41 u_int8_tmac4[6];
42 // u_int16_tgapLen; 42 // u_int16_tgapLen;
43 // u_int8_tgap[8]; 43 // u_int8_tgap[8];
44}; 44};
45 45
46 46
47struct ieee_802_3_header { 47struct ieee_802_3_header {
48 48
49 u_int16_tstatus; 49 u_int16_tstatus;
50 u_int16_tpayload_length; 50 u_int16_tpayload_length;
51 u_int8_tdst_mac[6]; 51 u_int8_tdst_mac[6];
52 u_int8_tsrc_mac[6]; 52 u_int8_tsrc_mac[6];
53 53
54}; 54};
55 55
56#define P80211_OUI_LEN 3 56#define P80211_OUI_LEN 3
57 57
58struct ieee_802_11_snap_header { 58struct ieee_802_11_snap_header {
59 59
60 u_int8_t dsap; /* always 0xAA */ 60 u_int8_t dsap; /* always 0xAA */
61 u_int8_t ssap; /* always 0xAA */ 61 u_int8_t ssap; /* always 0xAA */
62 u_int8_t ctrl; /* always 0x03 */ 62 u_int8_t ctrl; /* always 0x03 */
63 u_int8_t oui[P80211_OUI_LEN]; /* organizational universal id */ 63 u_int8_t oui[P80211_OUI_LEN]; /* organizational universal id */
64 64
65} __attribute__ ((packed)); 65} __attribute__ ((packed));
66 66
67#define P80211_LLC_OUI_LEN 3 67#define P80211_LLC_OUI_LEN 3
68 68
69struct ieee_802_11_802_1H_header { 69struct ieee_802_11_802_1H_header {
70 70
71 u_int8_t dsap; 71 u_int8_t dsap;
72 u_int8_t ssap; /* always 0xAA */ 72 u_int8_t ssap; /* always 0xAA */
73 u_int8_t ctrl; /* always 0x03 */ 73 u_int8_t ctrl; /* always 0x03 */
74 u_int8_t oui[P80211_OUI_LEN]; /* organizational universal id */ 74 u_int8_t oui[P80211_OUI_LEN]; /* organizational universal id */
75 u_int16_t unknown1; /* packet type ID fields */ 75 u_int16_t unknown1; /* packet type ID fields */
76 u_int16_t unknown2; /* here is something like length in some cases */ 76 u_int16_t unknown2; /* here is something like length in some cases */
77} __attribute__ ((packed)); 77} __attribute__ ((packed));
78 78
79struct ieee_802_11_802_2_header { 79struct ieee_802_11_802_2_header {
80 80
81 u_int8_t dsap; 81 u_int8_t dsap;
82 u_int8_t ssap; /* always 0xAA */ 82 u_int8_t ssap; /* always 0xAA */
83 u_int8_t ctrl; /* always 0x03 */ 83 u_int8_t ctrl; /* always 0x03 */
84 u_int8_t oui[P80211_OUI_LEN]; /* organizational universal id */ 84 u_int8_t oui[P80211_OUI_LEN]; /* organizational universal id */
85 u_int16_t type; /* packet type ID field */ 85 u_int16_t type; /* packet type ID field */
86 86
87} __attribute__ ((packed)); 87} __attribute__ ((packed));
88 88
89 89
90 90
91// following is incoplete and may be incorrect and need reorganization 91// following is incoplete and may be incorrect and need reorganization
92 92
93 #define ieee_802_11_frame_type_Management0x00 93 #define ieee_802_11_frame_type_Management0x00
94 #define ieee_802_11_frame_type_Control 0x01 94 #define ieee_802_11_frame_type_Control 0x01
95 #define ieee_802_11_frame_type_Data 0x10 95 #define ieee_802_11_frame_type_Data 0x10
96 #define ieee_802_11_frame_type_Reserved 0x11 96 #define ieee_802_11_frame_type_Reserved 0x11
97 97
98 #define ieee_802_11_frame_subtype_Association_Req0x0 // Association Request 98 #define ieee_802_11_frame_subtype_Association_Req0x0 // Association Request
99 #define ieee_802_11_frame_subtype_Association_Resp0x1 // Association Response 99 #define ieee_802_11_frame_subtype_Association_Resp0x1 // Association Response
100 #define ieee_802_11_frame_subtype_Reassociation_Req0x2 // Reassociation Request 100 #define ieee_802_11_frame_subtype_Reassociation_Req0x2 // Reassociation Request
101 #define ieee_802_11_frame_subtype_Reassociation_Resp0x3 // Reassociation Response 101 #define ieee_802_11_frame_subtype_Reassociation_Resp0x3 // Reassociation Response
102 #define ieee_802_11_frame_subtype_Probe_Req 0x4 // Probe Request 102 #define ieee_802_11_frame_subtype_Probe_Req 0x4 // Probe Request
103 #define ieee_802_11_frame_subtype_Probe_Resp 0x5 // Probe Response 103 #define ieee_802_11_frame_subtype_Probe_Resp 0x5 // Probe Response
104 #define ieee_802_11_frame_subtype_Beacon 0x8 // Beacon 104 #define ieee_802_11_frame_subtype_Beacon 0x8 // Beacon
105 #define ieee_802_11_frame_subtype_ATIM 0x9 // ATIM 105 #define ieee_802_11_frame_subtype_ATIM 0x9 // ATIM
106 #define ieee_802_11_frame_subtype_Disassociation 0xA // Disassociation 106 #define ieee_802_11_frame_subtype_Disassociation 0xA // Disassociation
107 #define ieee_802_11_frame_subtype_Authentication 0xB // Authentication 107 #define ieee_802_11_frame_subtype_Authentication 0xB // Authentication
108 #define ieee_802_11_frame_subtype_Deauthentication 0xC // Deauthentication 108 #define ieee_802_11_frame_subtype_Deauthentication 0xC // Deauthentication
109 #define ieee_802_11_frame_subtype_PS_Poll 0xA // PS-Poll 109 #define ieee_802_11_frame_subtype_PS_Poll 0xA // PS-Poll
110 #define ieee_802_11_frame_subtype_RTS 0xB // RTS 110 #define ieee_802_11_frame_subtype_RTS 0xB // RTS
111 #define ieee_802_11_frame_subtype_CTS 0xC // CTS 111 #define ieee_802_11_frame_subtype_CTS 0xC // CTS
112 #define ieee_802_11_frame_subtype_ACK 0xD // ACK 112 #define ieee_802_11_frame_subtype_ACK 0xD // ACK
113 #define ieee_802_11_frame_subtype_CFEnd 0xE // CF-End 113 #define ieee_802_11_frame_subtype_CFEnd 0xE // CF-End
114 #define ieee_802_11_frame_subtype_CFEnd_CFAck 0xF // CF-End + CF-Ack 114 #define ieee_802_11_frame_subtype_CFEnd_CFAck 0xF // CF-End + CF-Ack
115 #define ieee_802_11_frame_subtype_Data 0x0 // Data 115 #define ieee_802_11_frame_subtype_Data 0x0 // Data
116 #define ieee_802_11_frame_subtype_Data_CFAck 0x1 // Data + CF-Ack 116 #define ieee_802_11_frame_subtype_Data_CFAck 0x1 // Data + CF-Ack
117 #define ieee_802_11_frame_subtype_Data_CF_Poll 0x2 // Data + CF-Poll 117 #define ieee_802_11_frame_subtype_Data_CF_Poll 0x2 // Data + CF-Poll
118 #define ieee_802_11_frame_subtype_Data_CF_AckCF_Poll 0x3 // Data + CF-Ack + CF-Poll 118 #define ieee_802_11_frame_subtype_Data_CF_AckCF_Poll 0x3 // Data + CF-Ack + CF-Poll
119 #define ieee_802_11_frame_subtype_NullFunction 0x4 // Null Function (no data) 119 #define ieee_802_11_frame_subtype_NullFunction 0x4 // Null Function (no data)
120 #define ieee_802_11_frame_subtype_CF_Ack 0x5 // CF-Ack (no data) 120 #define ieee_802_11_frame_subtype_CF_Ack 0x5 // CF-Ack (no data)
121 #define ieee_802_11_frame_subtype_CF_Poll 0x6 // CF-Poll (no data) 121 #define ieee_802_11_frame_subtype_CF_Poll 0x6 // CF-Poll (no data)
122 #define ieee_802_11_frame_subtype_CF_AckCF_Poll 0x7 // CF-Ack + CF-Poll (no data) 122 #define ieee_802_11_frame_subtype_CF_AckCF_Poll 0x7 // CF-Ack + CF-Poll (no data)
123 123
124 124
125#define ieee_802_11_frame_subtype_strings {\ 125#define ieee_802_11_frame_subtype_strings {\
126 { ieee_802_11_frame_subtype_Association_Req,0xF,"f Association Request"},\ 126 { ieee_802_11_frame_subtype_Association_Req,0xF,"f Association Request"},\
127 { ieee_802_11_frame_subtype_Association_Resp,0xF,"1 Association Response"},\ 127 { ieee_802_11_frame_subtype_Association_Resp,0xF,"1 Association Response"},\
128 { ieee_802_11_frame_subtype_Reassociation_Req,0xF,"2 Reassociation Request"},\ 128 { ieee_802_11_frame_subtype_Reassociation_Req,0xF,"2 Reassociation Request"},\
129 { ieee_802_11_frame_subtype_Reassociation_Resp,0xF,"3 Reassociation Response"},\ 129 { ieee_802_11_frame_subtype_Reassociation_Resp,0xF,"3 Reassociation Response"},\
130 { ieee_802_11_frame_subtype_Probe_Req ,0xF,"4 Probe Request"},\ 130 { ieee_802_11_frame_subtype_Probe_Req ,0xF,"4 Probe Request"},\
131 { ieee_802_11_frame_subtype_Probe_Resp ,0xF,"5 Probe Response"},\ 131 { ieee_802_11_frame_subtype_Probe_Resp ,0xF,"5 Probe Response"},\
132 { ieee_802_11_frame_subtype_Beacon ,0xF,"8 Beacon"},\ 132 { ieee_802_11_frame_subtype_Beacon ,0xF,"8 Beacon"},\
133 { ieee_802_11_frame_subtype_ATIM ,0xF,"9 ATIM"},\ 133 { ieee_802_11_frame_subtype_ATIM ,0xF,"9 ATIM"},\
134 { ieee_802_11_frame_subtype_Disassociation,0xF,"A Disassociation"},\ 134 { ieee_802_11_frame_subtype_Disassociation,0xF,"A Disassociation"},\
135 { ieee_802_11_frame_subtype_Authentication,0xF,"B Authentication"},\ 135 { ieee_802_11_frame_subtype_Authentication,0xF,"B Authentication"},\
136 { ieee_802_11_frame_subtype_Deauthentication,0xF,"C Deauthentication"},\ 136 { ieee_802_11_frame_subtype_Deauthentication,0xF,"C Deauthentication"},\
137 { ieee_802_11_frame_subtype_PS_Poll ,0xF,"A PS-Poll"},\ 137 { ieee_802_11_frame_subtype_PS_Poll ,0xF,"A PS-Poll"},\
138 { ieee_802_11_frame_subtype_RTS ,0xF,"B RTS"},\ 138 { ieee_802_11_frame_subtype_RTS ,0xF,"B RTS"},\
139 { ieee_802_11_frame_subtype_CTS ,0xF,"C CTS"},\ 139 { ieee_802_11_frame_subtype_CTS ,0xF,"C CTS"},\
140 { ieee_802_11_frame_subtype_ACK ,0xF,"D ACK"},\ 140 { ieee_802_11_frame_subtype_ACK ,0xF,"D ACK"},\
141 { ieee_802_11_frame_subtype_CFEnd ,0xF,"E CF-End"},\ 141 { ieee_802_11_frame_subtype_CFEnd ,0xF,"E CF-End"},\
142 { ieee_802_11_frame_subtype_CFEnd_CFAck ,0xF,"F CF-End + CF-Ack"},\ 142 { ieee_802_11_frame_subtype_CFEnd_CFAck ,0xF,"F CF-End + CF-Ack"},\
143 { ieee_802_11_frame_subtype_Data ,0xF,"0 Data"},\ 143 { ieee_802_11_frame_subtype_Data ,0xF,"0 Data"},\
144 { ieee_802_11_frame_subtype_Data_CFAck ,0xF,"1 Data + CF-Ack"},\ 144 { ieee_802_11_frame_subtype_Data_CFAck ,0xF,"1 Data + CF-Ack"},\
145 { ieee_802_11_frame_subtype_Data_CFPoll ,0xF,"2 Data + CF-Poll"},\ 145 { ieee_802_11_frame_subtype_Data_CFPoll ,0xF,"2 Data + CF-Poll"},\
146 { ieee_802_11_frame_subtype_Data_CFAck_CFPoll,0xF,"3 Data + CF-Ack + CF-Poll"},\ 146 { ieee_802_11_frame_subtype_Data_CFAck_CFPoll,0xF,"3 Data + CF-Ack + CF-Poll"},\
147 { ieee_802_11_frame_subtype_Null_Function ,0xF,"4 Null Function (no data)"},\ 147 { ieee_802_11_frame_subtype_Null_Function ,0xF,"4 Null Function (no data)"},\
148 { ieee_802_11_frame_subtype_CFAck , 0xF,"5 CF-Ack (no data)"},\ 148 { ieee_802_11_frame_subtype_CFAck , 0xF,"5 CF-Ack (no data)"},\
149 { ieee_802_11_frame_subtype_CFPoll , 0xF,"6 CF-Poll (no data)"},\ 149 { ieee_802_11_frame_subtype_CFPoll , 0xF,"6 CF-Poll (no data)"},\
150 { ieee_802_11_frame_subtype_CFAck_CFPoll,0xF,"y7 CF-Ack + CF-Poll (no data)"},\ 150 { ieee_802_11_frame_subtype_CFAck_CFPoll,0xF,"y7 CF-Ack + CF-Poll (no data)"},\
151 { 0,0,NULL}\ 151 { 0,0,NULL}\
152} 152}
153struct ieee_802_11_frame_subtype_class { 153struct ieee_802_11_frame_subtype_class {
154 u_int8_tsubtype; 154 u_int8_tsubtype;
155 u_int8_tmask; 155 u_int8_tmask;
156 u_int8_tklass; 156 u_int8_tklass;
157 u_int8_ttype; 157 u_int8_ttype;
158}; 158};
159#define ieee_802_11_frame_subtype_classes {\ 159#define ieee_802_11_frame_subtype_classes {\
160 { ieee_802_11_frame_subtype_Association_Req,0xF,2,ieee_802_11_frame_type_Management},\ 160 { ieee_802_11_frame_subtype_Association_Req,0xF,2,ieee_802_11_frame_type_Management},\
161 { ieee_802_11_frame_subtype_Association_Resp,0xF,2,ieee_802_11_frame_type_Management},\ 161 { ieee_802_11_frame_subtype_Association_Resp,0xF,2,ieee_802_11_frame_type_Management},\
162 { ieee_802_11_frame_subtype_Reassociation_Req,0xF,2,ieee_802_11_frame_type_Management},\ 162 { ieee_802_11_frame_subtype_Reassociation_Req,0xF,2,ieee_802_11_frame_type_Management},\
163 { ieee_802_11_frame_subtype_Reassociation_Resp,0xF,2,ieee_802_11_frame_type_Management},\ 163 { ieee_802_11_frame_subtype_Reassociation_Resp,0xF,2,ieee_802_11_frame_type_Management},\
164 { ieee_802_11_frame_subtype_Probe_Req ,0xF,1,ieee_802_11_frame_type_Management},\ 164 { ieee_802_11_frame_subtype_Probe_Req ,0xF,1,ieee_802_11_frame_type_Management},\
165 { ieee_802_11_frame_subtype_Probe_Resp ,0xF,1,ieee_802_11_frame_type_Management},\ 165 { ieee_802_11_frame_subtype_Probe_Resp ,0xF,1,ieee_802_11_frame_type_Management},\
166 { ieee_802_11_frame_subtype_Beacon ,0xF,1,ieee_802_11_frame_type_Management},\ 166 { ieee_802_11_frame_subtype_Beacon ,0xF,1,ieee_802_11_frame_type_Management},\
167 { ieee_802_11_frame_subtype_ATIM ,0xF,1,ieee_802_11_frame_type_Management},\ 167 { ieee_802_11_frame_subtype_ATIM ,0xF,1,ieee_802_11_frame_type_Management},\
168 { ieee_802_11_frame_subtype_Disassociation,0xF,2,ieee_802_11_frame_type_Management},\ 168 { ieee_802_11_frame_subtype_Disassociation,0xF,2,ieee_802_11_frame_type_Management},\
169 { ieee_802_11_frame_subtype_Authentication,0xF,1,ieee_802_11_frame_type_Management},\ 169 { ieee_802_11_frame_subtype_Authentication,0xF,1,ieee_802_11_frame_type_Management},\
170 { ieee_802_11_frame_subtype_Deauthentication,0xF,3,ieee_802_11_frame_type_Management},\ 170 { ieee_802_11_frame_subtype_Deauthentication,0xF,3,ieee_802_11_frame_type_Management},\
171 { ieee_802_11_frame_subtype_PS-Poll ,0xF,3,ieee_802_11_frame_type_Control},\ 171 { ieee_802_11_frame_subtype_PS-Poll ,0xF,3,ieee_802_11_frame_type_Control},\
172 { ieee_802_11_frame_subtype_RTS ,0xF,1,ieee_802_11_frame_type_Control},\ 172 { ieee_802_11_frame_subtype_RTS ,0xF,1,ieee_802_11_frame_type_Control},\
173 { ieee_802_11_frame_subtype_CTS ,0xF,1,ieee_802_11_frame_type_Control},\ 173 { ieee_802_11_frame_subtype_CTS ,0xF,1,ieee_802_11_frame_type_Control},\
174 { ieee_802_11_frame_subtype_ACK ,0xF,1,ieee_802_11_frame_type_Control},\ 174 { ieee_802_11_frame_subtype_ACK ,0xF,1,ieee_802_11_frame_type_Control},\
175 { ieee_802_11_frame_subtype_CFEnd ,0xF,1,ieee_802_11_frame_type_Control},\ 175 { ieee_802_11_frame_subtype_CFEnd ,0xF,1,ieee_802_11_frame_type_Control},\
176 { ieee_802_11_frame_subtype_CFEnd_CFAck ,0xF,1,ieee_802_11_frame_type_Control},\ 176 { ieee_802_11_frame_subtype_CFEnd_CFAck ,0xF,1,ieee_802_11_frame_type_Control},\
177 { ieee_802_11_frame_subtype_Data ,0xF,3,ieee_802_11_frame_type_Data},\ 177 { ieee_802_11_frame_subtype_Data ,0xF,3,ieee_802_11_frame_type_Data},\
178 { ieee_802_11_frame_subtype_Data_CFAck ,0xF,3,ieee_802_11_frame_type_Data},\ 178 { ieee_802_11_frame_subtype_Data_CFAck ,0xF,3,ieee_802_11_frame_type_Data},\
179 { ieee_802_11_frame_subtype_Data_CF_Poll 0xF,3,ieee_802_11_frame_type_Data},\ 179 { ieee_802_11_frame_subtype_Data_CF_Poll 0xF,3,ieee_802_11_frame_type_Data},\
180 { ieee_802_11_frame_subtype_Data_CF_AckCF_Poll,0xF,3,ieee_802_11_frame_type_Data},\ 180 { ieee_802_11_frame_subtype_Data_CF_AckCF_Poll,0xF,3,ieee_802_11_frame_type_Data},\
181 { ieee_802_11_frame_subtype_NullFunction 0xF,1,ieee_802_11_frame_type_Data},\ 181 { ieee_802_11_frame_subtype_NullFunction 0xF,1,ieee_802_11_frame_type_Data},\
182 { ieee_802_11_frame_subtype_CF_Ack , 0xF,1,ieee_802_11_frame_type_Data},\ 182 { ieee_802_11_frame_subtype_CF_Ack , 0xF,1,ieee_802_11_frame_type_Data},\
183 { ieee_802_11_frame_subtype_CF_Poll , 0xF,1,ieee_802_11_frame_type_Data},\ 183 { ieee_802_11_frame_subtype_CF_Poll , 0xF,1,ieee_802_11_frame_type_Data},\
184 { ieee_802_11_frame_subtype_CF_AckCF_Poll,0xF,1,ieee_802_11_frame_type_Data},\ 184 { ieee_802_11_frame_subtype_CF_AckCF_Poll,0xF,1,ieee_802_11_frame_type_Data},\
185 { 0,0,NULL}\ 185 { 0,0,NULL}\
186} 186}
187 187
188 #define IEEE802_11_FC_LEN2 188 #define IEEE802_11_FC_LEN2
189 189
190#define T_MGMT 0x0 /* management */ 190#define T_MGMT 0x0 /* management */
191#define T_CTRL 0x1 /* control */ 191#define T_CTRL 0x1 /* control */
192#define T_DATA 0x2 /* data */ 192#define T_DATA 0x2 /* data */
193#define T_RESV 0x3 /* reserved */ 193#define T_RESV 0x3 /* reserved */
194 194
195 #define ST_ASSOC_REQUEST 0x0 195 #define ST_ASSOC_REQUEST 0x0
196 #define ST_ASSOC_RESPONSE 0x1 196 #define ST_ASSOC_RESPONSE 0x1
197 #define ST_REASSOC_REQUEST 0x2 197 #define ST_REASSOC_REQUEST 0x2
198 #define ST_REASSOC_RESPONSE 0x3 198 #define ST_REASSOC_RESPONSE 0x3
199 #define ST_PROBE_REQUEST 0x4 199 #define ST_PROBE_REQUEST 0x4
200 #define ST_PROBE_RESPONSE 0x5 200 #define ST_PROBE_RESPONSE 0x5
201 /* RESERVED 0x6 */ 201 /* RESERVED 0x6 */
202 /* RESERVED 0x7 */ 202 /* RESERVED 0x7 */
203 #define ST_BEACON 0x8 203 #define ST_BEACON 0x8
204 #define ST_ATIM 0x9 204 #define ST_ATIM 0x9
205 #define ST_DISASSOC 0xA 205 #define ST_DISASSOC 0xA
206 #define ST_AUTH 0xB 206 #define ST_AUTH 0xB
207 #define ST_DEAUTH 0xC 207 #define ST_DEAUTH 0xC
208 /* RESERVED 0xD */ 208 /* RESERVED 0xD */
209 /* RESERVED 0xE */ 209 /* RESERVED 0xE */
210 /* RESERVED 0xF */ 210 /* RESERVED 0xF */
211 211
212 212
213 #define CTRL_PS_POLL0xA 213 #define CTRL_PS_POLL0xA
214 #define CTRL_RTS0xB 214 #define CTRL_RTS0xB
215 #define CTRL_CTS0xC 215 #define CTRL_CTS0xC
216 #define CTRL_ACK0xD 216 #define CTRL_ACK0xD
217 #define CTRL_CF_END0xE 217 #define CTRL_CF_END0xE
218 #define CTRL_END_ACK0xF 218 #define CTRL_END_ACK0xF
219 219
220/* 220/*
221 * Bits in the frame control field. 221 * Bits in the frame control field.
222 */ 222 */
223 #define FC_VERSION(fc) ((fc) & 0x3) 223 #define FC_VERSION(fc) ((fc) & 0x3)
224 #define FC_TYPE(fc) (((fc) >> 2) & 0x3) 224 #define FC_TYPE(fc) (((fc) >> 2) & 0x3)
225 #define FC_SUBTYPE(fc) (((fc) >> 4) & 0xF) 225 #define FC_SUBTYPE(fc) (((fc) >> 4) & 0xF)
226 #define FC_TO_DS(fc) ((fc) & 0x0100) 226 #define FC_TO_DS(fc) ((fc) & 0x0100)
227 #define FC_FROM_DS(fc) ((fc) & 0x0200) 227 #define FC_FROM_DS(fc) ((fc) & 0x0200)
228 #define FC_MORE_FLAG(fc)((fc) & 0x0400) 228 #define FC_MORE_FLAG(fc)((fc) & 0x0400)
229 #define FC_RETRY(fc) ((fc) & 0x0800) 229 #define FC_RETRY(fc) ((fc) & 0x0800)
230 #define FC_POWER_MGMT(fc)((fc) & 0x1000) 230 #define FC_POWER_MGMT(fc)((fc) & 0x1000)
231 #define FC_MORE_DATA(fc)((fc) & 0x2000) 231 #define FC_MORE_DATA(fc)((fc) & 0x2000)
232 #define FC_WEP(fc) ((fc) & 0x4000) 232 #define FC_WEP(fc) ((fc) & 0x4000)
233 #define FC_ORDER(fc) ((fc) & 0x8000) 233 #define FC_ORDER(fc) ((fc) & 0x8000)
234 234
235 235
236struct ieee_802_11_mgmt_header { 236struct ieee_802_11_mgmt_header {
237 u_int16_t fc; 237 u_int16_t fc;
238 u_int16_t duration; 238 u_int16_t duration;
239 u_int8_t da[6]; 239 u_int8_t da[6];
240 u_int8_t sa[6]; 240 u_int8_t sa[6];
241 u_int8_t bssid[6]; 241 u_int8_t bssid[6];
242 u_int16_t seq_ctrl; 242 u_int16_t seq_ctrl;
243}; 243};
244 244
245 245
246struct ieee_802_11_data_header { 246struct ieee_802_11_data_header {
247 u_int16_tframe_control; 247 u_int16_tframe_control;
248 u_int16_tduration; 248 u_int16_tduration;
249 u_int8_tmac1[6]; 249 u_int8_tmac1[6];
250 u_int8_tmac2[6]; 250 u_int8_tmac2[6];
251 u_int8_tmac3[6]; 251 u_int8_tmac3[6];
252 u_int16_tSeqCtl; 252 u_int16_tSeqCtl;
253 u_int8_tmac4[6]; 253 u_int8_tmac4[6];
254 // u_int16_tgapLen; 254 // u_int16_tgapLen;
255 // u_int8_tgap[8]; 255 // u_int8_tgap[8];
256}; 256};
257 257
258struct ieee_802_11_control_header {
259 u_int16_tframe_control;
260 u_int16_tduration;
261 u_int8_tmac1[6];
262 u_int8_tmac2[6];
263 u_int8_tmac3[6];
264 u_int16_tSeqCtl;
265 u_int8_tmac4[6];
266 // u_int16_tgapLen;
267 // u_int8_tgap[8];
268};
269
258#define CAPABILITY_ESS(cap) ((cap) & 0x0001) 270#define CAPABILITY_ESS(cap) ((cap) & 0x0001)
259#define CAPABILITY_IBSS(cap) ((cap) & 0x0002) 271#define CAPABILITY_IBSS(cap) ((cap) & 0x0002)
260#define CAPABILITY_CFP(cap) ((cap) & 0x0004) 272#define CAPABILITY_CFP(cap) ((cap) & 0x0004)
261#define CAPABILITY_CFP_REQ(cap) ((cap) & 0x0008) 273#define CAPABILITY_CFP_REQ(cap) ((cap) & 0x0008)
262#define CAPABILITY_PRIVACY(cap) ((cap) & 0x0010) 274#define CAPABILITY_PRIVACY(cap) ((cap) & 0x0010)
263 275
264struct ssid_t { 276struct ssid_t {
265 u_int8_telement_id; 277 u_int8_telement_id;
266 u_int8_tlength; 278 u_int8_tlength;
267 u_char ssid[33]; /* 32 + 1 for null */ 279 u_char ssid[33]; /* 32 + 1 for null */
268}; 280};
269 281
270 282
271struct rates_t { 283struct rates_t {
272 u_int8_telement_id; 284 u_int8_telement_id;
273 u_int8_tlength; 285 u_int8_tlength;
274 u_int8_trate[8]; 286 u_int8_trate[8];
275}; 287};
276 288
277 289
278struct challenge_t { 290struct challenge_t {
279 u_int8_telement_id; 291 u_int8_telement_id;
280 u_int8_tlength; 292 u_int8_tlength;
281 u_int8_ttext[254]; /* 1-253 + 1 for null */ 293 u_int8_ttext[254]; /* 1-253 + 1 for null */
282}; 294};
283 295
284 296
285struct fh_t { 297struct fh_t {
286 u_int8_telement_id; 298 u_int8_telement_id;
287 u_int8_tlength; 299 u_int8_tlength;
288 u_int16_tdwell_time; 300 u_int16_tdwell_time;
289 u_int8_thop_set; 301 u_int8_thop_set;
290 u_int8_t hop_pattern; 302 u_int8_t hop_pattern;
291 u_int8_thop_index; 303 u_int8_thop_index;
292}; 304};
293 305
294 306
295struct ds_t { 307struct ds_t {
296 u_int8_telement_id; 308 u_int8_telement_id;
297 u_int8_tlength; 309 u_int8_tlength;
298 u_int8_tchannel; 310 u_int8_tchannel;
299}; 311};
300 312
301 313
302struct cf_t { 314struct cf_t {
303 u_int8_telement_id; 315 u_int8_telement_id;
304 u_int8_tlength; 316 u_int8_tlength;
305 u_int8_tcount; 317 u_int8_tcount;
306 u_int8_tperiod; 318 u_int8_tperiod;
307 u_int16_tmax_duration; 319 u_int16_tmax_duration;
308 u_int16_tdur_remaing; 320 u_int16_tdur_remaing;
309}; 321};
310 322
311 323
312struct tim_t { 324struct tim_t {
313 u_int8_telement_id; 325 u_int8_telement_id;
314 u_int8_tlength; 326 u_int8_tlength;
315 u_int8_tcount; 327 u_int8_tcount;
316 u_int8_tperiod; 328 u_int8_tperiod;
317 u_int8_tbitmap_control; 329 u_int8_tbitmap_control;
318 u_int8_tbitmap[251]; 330 u_int8_tbitmap[251];
319}; 331};
320 332
321 333
322struct ibss_t { 334struct ibss_t {
323 u_int8_telement_id; 335 u_int8_telement_id;
324 u_int8_tlength; 336 u_int8_tlength;
325 u_int16_tatim_window; 337 u_int16_tatim_window;
326}; 338};
327 339
328 340
329#define E_SSID 0 341#define E_SSID 0
330#define E_RATES 1 342#define E_RATES 1
331#define E_FH 2 343#define E_FH 2
332#define E_DS 3 344#define E_DS 3
333#define E_CF 4 345#define E_CF 4
334#define E_TIM 5 346#define E_TIM 5
335#define E_IBSS 6 347#define E_IBSS 6
336#define E_CHALLENGE 16 348#define E_CHALLENGE 16
337#define E_CISCO 133 349#define E_CISCO 133
338 350
339 351
340struct ieee_802_11_mgmt_body { 352struct ieee_802_11_mgmt_body {
341 u_int8_t timestamp[8]; 353 u_int8_t timestamp[8];
342 u_int16_t beacon_interval; 354 u_int16_t beacon_interval;
343 // u_int16_t listen_interval; 355 // u_int16_t listen_interval;
344 // u_int16_t status_code; 356 // u_int16_t status_code;
345 // u_int16_t aid; 357 // u_int16_t aid;
346 // u_char ap[6]; 358 // u_char ap[6];
347 // u_int16_treason_code; 359 // u_int16_treason_code;
348 // u_int16_tauth_alg; 360 // u_int16_tauth_alg;
349 // u_int16_tauth_trans_seq_num; 361 // u_int16_tauth_trans_seq_num;
350// struct challenge_t challenge; 362// struct challenge_t challenge;
351 u_int16_t capability_info; 363 u_int16_t capability_info;
352 // struct ssid_tssid; 364 // struct ssid_tssid;
353 // struct rates_t rates; 365 // struct rates_t rates;
354 // struct ds_tds; 366 // struct ds_tds;
355 // struct cf_tcf; 367 // struct cf_tcf;
356 // struct fh_tfh; 368 // struct fh_tfh;
357 // struct tim_ttim; 369 // struct tim_ttim;
358}; 370};
359 371
360 372
361struct ieee_802_11_data_body { 373struct ieee_802_11_data_body {
362//FIXME 374//FIXME
363}; 375};
364 376
377struct ieee_802_11_control_body {
378//FIXME
379};
380
365struct ctrl_rts_t { 381struct ctrl_rts_t {
366 u_int16_tfc; 382 u_int16_tfc;
367 u_int16_tduration; 383 u_int16_tduration;
368 u_int8_tra[6]; 384 u_int8_tra[6];
369 u_int8_tta[6]; 385 u_int8_tta[6];
370 u_int8_tfcs[4]; 386 u_int8_tfcs[4];
371}; 387};
372 388
373 #define CTRL_RTS_LEN(2+2+6+6+4) 389 #define CTRL_RTS_LEN(2+2+6+6+4)
374 390
375struct ctrl_cts_t { 391struct ctrl_cts_t {
376 u_int16_tfc; 392 u_int16_tfc;
377 u_int16_tduration; 393 u_int16_tduration;
378 u_int8_tra[6]; 394 u_int8_tra[6];
379 u_int8_tfcs[4]; 395 u_int8_tfcs[4];
380}; 396};
381 397
382 #define CTRL_CTS_LEN(2+2+6+4) 398 #define CTRL_CTS_LEN(2+2+6+4)
383 399
384struct ctrl_ack_t { 400struct ctrl_ack_t {
385 u_int16_tfc; 401 u_int16_tfc;
386 u_int16_tduration; 402 u_int16_tduration;
387 u_int8_tra[6]; 403 u_int8_tra[6];
388 u_int8_tfcs[4]; 404 u_int8_tfcs[4];
389}; 405};
390 406
391 #define CTRL_ACK_LEN(2+2+6+4) 407 #define CTRL_ACK_LEN(2+2+6+4)
392 408
393struct ctrl_ps_poll_t { 409struct ctrl_ps_poll_t {
394 u_int16_tfc; 410 u_int16_tfc;
395 u_int16_taid; 411 u_int16_taid;
396 u_int8_tbssid[6]; 412 u_int8_tbssid[6];
397 u_int8_tta[6]; 413 u_int8_tta[6];
398 u_int8_tfcs[4]; 414 u_int8_tfcs[4];
399}; 415};
400 416
401 #define CTRL_PS_POLL_LEN(2+2+6+6+4) 417 #define CTRL_PS_POLL_LEN(2+2+6+6+4)
402 418
403struct ctrl_end_t { 419struct ctrl_end_t {
404 u_int16_tfc; 420 u_int16_tfc;
405 u_int16_tduration; 421 u_int16_tduration;
406 u_int8_tra[6]; 422 u_int8_tra[6];
407 u_int8_tbssid[6]; 423 u_int8_tbssid[6];
408 u_int8_tfcs[4]; 424 u_int8_tfcs[4];
409}; 425};
410 426
411 #define CTRL_END_LEN(2+2+6+6+4) 427 #define CTRL_END_LEN(2+2+6+6+4)
412 428
413struct ctrl_end_ack_t { 429struct ctrl_end_ack_t {
414 u_int16_tfc; 430 u_int16_tfc;
415 u_int16_tduration; 431 u_int16_tduration;
416 u_int8_tra[6]; 432 u_int8_tra[6];
417 u_int8_tbssid[6]; 433 u_int8_tbssid[6];
418 u_int8_tfcs[4]; 434 u_int8_tfcs[4];
419}; 435};
420 436
421 #define CTRL_END_ACK_LEN(2+2+6+6+4) 437 #define CTRL_END_ACK_LEN(2+2+6+6+4)
422 438
423 #define IV_IV(iv)((iv) & 0xFFFFFF) 439 #define IV_IV(iv)((iv) & 0xFFFFFF)
424 #define IV_PAD(iv)(((iv) >> 24) & 0x3F) 440 #define IV_PAD(iv)(((iv) >> 24) & 0x3F)
425 #define IV_KEYID(iv)(((iv) >> 30) & 0x03) 441 #define IV_KEYID(iv)(((iv) >> 30) & 0x03)
426 442
427#endif 443#endif
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 40aac2c..5c464cf 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -1,832 +1,875 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 by the Wellenreiter team: 3              Copyright (C) 2003 by the Wellenreiter team:
4 Martin J. Muench <mjm@remote-exploit.org> 4 Martin J. Muench <mjm@remote-exploit.org>
5 Max Moser <mmo@remote-exploit.org 5 Max Moser <mmo@remote-exploit.org
6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34/* OPIE */ 34/* OPIE */
35 35
36#include <opie2/opcap.h> 36#include <opie2/opcap.h>
37 37
38/* QT */ 38/* QT */
39 39
40#include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) 40#include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects)
41#include <qsocketnotifier.h> 41#include <qsocketnotifier.h>
42 42
43/*====================================================================================== 43/*======================================================================================
44 * OPacket 44 * OPacket
45 *======================================================================================*/ 45 *======================================================================================*/
46 46
47OPacket::OPacket( packetheaderstruct header, const unsigned char* data, QObject* parent ) 47OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent )
48 :QObject( parent, "Generic" ), _hdr( header ), _data( data ) 48 :QObject( parent, "Generic" ), _hdr( header ), _data( data )
49{ 49{
50 qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); 50 //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen );
51 51
52 _end = (unsigned char*) data + header.len; 52 _end = (unsigned char*) data + header.len;
53 qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); 53 //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end );
54 54
55 if ( packetCapturer()->dataLink() == DLT_EN10MB ) 55 switch ( datalink )
56 { 56 {
57 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); 57 case DLT_EN10MB:
58 new OEthernetPacket( _end, (const struct ether_header*) data, this ); 58 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" );
59 } 59 new OEthernetPacket( _end, (const struct ether_header*) data, this );
60 else 60 break;
61 { 61
62 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); 62 case DLT_IEEE802_11:
63 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); 63 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" );
64 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this );
65 break;
66
67 default:
68 qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink '%s'!", datalink );
64 } 69 }
65} 70}
66 71
67 72
68OPacket::~OPacket() 73OPacket::~OPacket()
69{ 74{
70} 75}
71 76
72 77
73OPacketCapturer* OPacket::packetCapturer() const
74{
75 return parent()->inherits( "OPacketCapturer" ) ? static_cast<OPacketCapturer*>( parent() ) : 0;
76}
77
78
79timevalstruct OPacket::timeval() const 78timevalstruct OPacket::timeval() const
80{ 79{
81 return _hdr.ts; 80 return _hdr.ts;
82} 81}
83 82
84 83
85int OPacket::caplen() const 84int OPacket::caplen() const
86{ 85{
87 return _hdr.caplen; 86 return _hdr.caplen;
88} 87}
89 88
90 89
91QString OPacket::dump( int bpl ) const 90QString OPacket::dump( int bpl ) const
92{ 91{
93 static int index = 0; 92 static int index = 0;
94 index++; 93 index++;
95 int len = _hdr.caplen; 94 int len = _hdr.caplen;
96 QString str; 95 QString str;
97 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); 96 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len );
98 str.append( "0000: " ); 97 str.append( "0000: " );
99 QString tmp; 98 QString tmp;
100 QString bytes; 99 QString bytes;
101 QString chars; 100 QString chars;
102 101
103 for ( int i = 0; i < len; ++i ) 102 for ( int i = 0; i < len; ++i )
104 { 103 {
105 tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); 104 tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp );
106 if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); 105 if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] );
107 else chars.append( '.' ); 106 else chars.append( '.' );
108 107
109 if ( !((i+1) % bpl) ) 108 if ( !((i+1) % bpl) )
110 { 109 {
111 str.append( bytes ); 110 str.append( bytes );
112 str.append( ' ' ); 111 str.append( ' ' );
113 str.append( chars ); 112 str.append( chars );
114 str.append( '\n' ); 113 str.append( '\n' );
115 tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); 114 tmp.sprintf( "%04X: ", i+1 ); str.append( tmp );
116 bytes = ""; 115 bytes = "";
117 chars = ""; 116 chars = "";
118 } 117 }
119 118
120 } 119 }
121 if ( (len % bpl) ) 120 if ( (len % bpl) )
122 { 121 {
123 str.append( bytes.leftJustify( 1 + 3*bpl ) ); 122 str.append( bytes.leftJustify( 1 + 3*bpl ) );
124 str.append( chars ); 123 str.append( chars );
125 } 124 }
126 str.append( '\n' ); 125 str.append( '\n' );
127 return str; 126 return str;
128} 127}
129 128
130 129
131 130
132int OPacket::len() const 131int OPacket::len() const
133{ 132{
134 return _hdr.len; 133 return _hdr.len;
135} 134}
136 135
137/*====================================================================================== 136/*======================================================================================
138 * OEthernetPacket 137 * OEthernetPacket
139 *======================================================================================*/ 138 *======================================================================================*/
140 139
141OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) 140OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent )
142 :QObject( parent, "Ethernet" ), _ether( data ) 141 :QObject( parent, "Ethernet" ), _ether( data )
143 142
144{ 143{
145 144
146 qDebug( "Source = %s", (const char*) sourceAddress().toString() ); 145 qDebug( "Source = %s", (const char*) sourceAddress().toString() );
147 qDebug( "Destination = %s", (const char*) destinationAddress().toString() ); 146 qDebug( "Destination = %s", (const char*) destinationAddress().toString() );
148 147
149 if ( sourceAddress() == OMacAddress::broadcast ) 148 if ( sourceAddress() == OMacAddress::broadcast )
150 qDebug( "Source is broadcast address" ); 149 qDebug( "Source is broadcast address" );
151 if ( destinationAddress() == OMacAddress::broadcast ) 150 if ( destinationAddress() == OMacAddress::broadcast )
152 qDebug( "Destination is broadcast address" ); 151 qDebug( "Destination is broadcast address" );
153 152
154 switch ( type() ) 153 switch ( type() )
155 { 154 {
156 case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; 155 case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
157 case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; } 156 case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; }
158 case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } 157 case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; }
159 default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" ); 158 default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" );
160 } 159 }
161 160
162} 161}
163 162
164 163
165OEthernetPacket::~OEthernetPacket() 164OEthernetPacket::~OEthernetPacket()
166{ 165{
167} 166}
168 167
169 168
170OMacAddress OEthernetPacket::sourceAddress() const 169OMacAddress OEthernetPacket::sourceAddress() const
171{ 170{
172 return OMacAddress( _ether->ether_shost ); 171 return OMacAddress( _ether->ether_shost );
173} 172}
174 173
175 174
176OMacAddress OEthernetPacket::destinationAddress() const 175OMacAddress OEthernetPacket::destinationAddress() const
177{ 176{
178 return OMacAddress( _ether->ether_dhost ); 177 return OMacAddress( _ether->ether_dhost );
179} 178}
180 179
181int OEthernetPacket::type() const 180int OEthernetPacket::type() const
182{ 181{
183 return ntohs( _ether->ether_type ); 182 return ntohs( _ether->ether_type );
184} 183}
185 184
186 185
187/*====================================================================================== 186/*======================================================================================
188 * OIPPacket 187 * OIPPacket
189 *======================================================================================*/ 188 *======================================================================================*/
190 189
191 190
192OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) 191OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent )
193 :QObject( parent, "IP" ), _iphdr( data ) 192 :QObject( parent, "IP" ), _iphdr( data )
194 193
195{ 194{
196 qDebug( "OIPPacket::OIPPacket(): decoding IP header..." ); 195 qDebug( "OIPPacket::OIPPacket(): decoding IP header..." );
197 196
198 //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) ); 197 //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) );
199 //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) ); 198 //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) );
200 199
201 qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() ); 200 qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() );
202 qDebug( " toAddress: %s", (const char*) toIPAddress().toString() ); 201 qDebug( " toAddress: %s", (const char*) toIPAddress().toString() );
203 202
204 switch ( protocol() ) 203 switch ( protocol() )
205 { 204 {
206 case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; 205 case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break;
207 case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; 206 case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break;
208 default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() ); 207 default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() );
209 } 208 }
210 209
211} 210}
212 211
213OIPPacket::~OIPPacket() 212OIPPacket::~OIPPacket()
214{ 213{
215} 214}
216 215
217 216
218QHostAddress OIPPacket::fromIPAddress() const 217QHostAddress OIPPacket::fromIPAddress() const
219{ 218{
220 return EXTRACT_32BITS( &_iphdr->saddr ); 219 return EXTRACT_32BITS( &_iphdr->saddr );
221} 220}
222 221
223 222
224QHostAddress OIPPacket::toIPAddress() const 223QHostAddress OIPPacket::toIPAddress() const
225{ 224{
226 return EXTRACT_32BITS( &_iphdr->saddr ); 225 return EXTRACT_32BITS( &_iphdr->saddr );
227} 226}
228 227
229 228
230int OIPPacket::tos() const 229int OIPPacket::tos() const
231{ 230{
232 return _iphdr->tos; 231 return _iphdr->tos;
233} 232}
234 233
235 234
236int OIPPacket::len() const 235int OIPPacket::len() const
237{ 236{
238 return EXTRACT_16BITS( &_iphdr->tot_len ); 237 return EXTRACT_16BITS( &_iphdr->tot_len );
239} 238}
240 239
241 240
242int OIPPacket::id() const 241int OIPPacket::id() const
243{ 242{
244 return EXTRACT_16BITS( &_iphdr->id ); 243 return EXTRACT_16BITS( &_iphdr->id );
245} 244}
246 245
247 246
248int OIPPacket::offset() const 247int OIPPacket::offset() const
249{ 248{
250 return EXTRACT_16BITS( &_iphdr->frag_off ); 249 return EXTRACT_16BITS( &_iphdr->frag_off );
251} 250}
252 251
253 252
254int OIPPacket::ttl() const 253int OIPPacket::ttl() const
255{ 254{
256 return _iphdr->ttl; 255 return _iphdr->ttl;
257} 256}
258 257
259 258
260int OIPPacket::protocol() const 259int OIPPacket::protocol() const
261{ 260{
262 return _iphdr->protocol; 261 return _iphdr->protocol;
263} 262}
264 263
265 264
266int OIPPacket::checksum() const 265int OIPPacket::checksum() const
267{ 266{
268 return EXTRACT_16BITS( &_iphdr->check ); 267 return EXTRACT_16BITS( &_iphdr->check );
269} 268}
270 269
271/*====================================================================================== 270/*======================================================================================
272 * OUDPPacket 271 * OUDPPacket
273 *======================================================================================*/ 272 *======================================================================================*/
274 273
275 274
276OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) 275OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent )
277 :QObject( parent, "UDP" ), _udphdr( data ) 276 :QObject( parent, "UDP" ), _udphdr( data )
278 277
279{ 278{
280 qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." ); 279 qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." );
281} 280}
282 281
283OUDPPacket::~OUDPPacket() 282OUDPPacket::~OUDPPacket()
284{ 283{
285} 284}
286 285
287 286
288/*====================================================================================== 287/*======================================================================================
289 * OTCPPacket 288 * OTCPPacket
290 *======================================================================================*/ 289 *======================================================================================*/
291 290
292 291
293OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) 292OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent )
294 :QObject( parent, "TCP" ), _tcphdr( data ) 293 :QObject( parent, "TCP" ), _tcphdr( data )
295 294
296{ 295{
297 qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." ); 296 qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." );
298} 297}
299 298
300OTCPPacket::~OTCPPacket() 299OTCPPacket::~OTCPPacket()
301{ 300{
302} 301}
303 302
304 303
305/*====================================================================================== 304/*======================================================================================
306 * OWaveLanPacket 305 * OWaveLanPacket
307 *======================================================================================*/ 306 *======================================================================================*/
308 307
309 308
310OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) 309OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent )
311 :QObject( parent, "802.11" ), _wlanhdr( data ) 310 :QObject( parent, "802.11" ), _wlanhdr( data )
312 311
313{ 312{
314 qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." ); 313 qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." );
315 qDebug( "type: %0X", type() ); 314 qDebug( "type: %0X", type() );
316 qDebug( "subType: %0X", subType() ); 315 qDebug( "subType: %0X", subType() );
317 qDebug( "duration: %d", duration() ); 316 qDebug( "duration: %d", duration() );
318 qDebug( "powermanagement: %d", usesPowerManagement() ); 317 qDebug( "powermanagement: %d", usesPowerManagement() );
319 qDebug( "wep: %d", usesWep() ); 318 qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" );
320 qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); 319 qDebug( "MAC1: %s", (const char*) macAddress1().toString() );
321 qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); 320 qDebug( "MAC2: %s", (const char*) macAddress2().toString() );
322 qDebug( "MAC3: %s", (const char*) macAddress3().toString() ); 321 qDebug( "MAC3: %s", (const char*) macAddress3().toString() );
323 qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); 322 qDebug( "MAC4: %s", (const char*) macAddress4().toString() );
324 323
325 switch ( type() ) 324 switch ( type() )
326 { 325 {
327 case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; 326 case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break;
328 case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; 327 case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break;
329 //case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_ctrl_header*) data, this ); break; 328 case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break;
330 default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown type!" ); 329 default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() );
331 } 330 }
332} 331}
333 332
334OWaveLanPacket::~OWaveLanPacket() 333OWaveLanPacket::~OWaveLanPacket()
335{ 334{
336} 335}
337 336
338 337
339int OWaveLanPacket::duration() const 338int OWaveLanPacket::duration() const
340{ 339{
341 return _wlanhdr->duration; 340 return _wlanhdr->duration;
342} 341}
343 342
344 343
345OMacAddress OWaveLanPacket::macAddress1() const 344OMacAddress OWaveLanPacket::macAddress1() const
346{ 345{
347 return OMacAddress( _wlanhdr->mac1 ); 346 return OMacAddress( _wlanhdr->mac1 );
348} 347}
349 348
350 349
351OMacAddress OWaveLanPacket::macAddress2() const 350OMacAddress OWaveLanPacket::macAddress2() const
352{ 351{
353 return OMacAddress( _wlanhdr->mac2 ); 352 return OMacAddress( _wlanhdr->mac2 );
354} 353}
355 354
356 355
357OMacAddress OWaveLanPacket::macAddress3() const 356OMacAddress OWaveLanPacket::macAddress3() const
358{ 357{
359 return OMacAddress( _wlanhdr->mac3 ); 358 return OMacAddress( _wlanhdr->mac3 );
360} 359}
361 360
362 361
363OMacAddress OWaveLanPacket::macAddress4() const 362OMacAddress OWaveLanPacket::macAddress4() const
364{ 363{
365 return OMacAddress( _wlanhdr->mac4 ); 364 return OMacAddress( _wlanhdr->mac4 );
366} 365}
367 366
368 367
369int OWaveLanPacket::subType() const 368int OWaveLanPacket::subType() const
370{ 369{
371 return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 370 return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
372} 371}
373 372
374 373
375int OWaveLanPacket::type() const 374int OWaveLanPacket::type() const
376{ 375{
377 return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 376 return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
378} 377}
379 378
380 379
381int OWaveLanPacket::version() const 380int OWaveLanPacket::version() const
382{ 381{
383 return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 382 return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
384} 383}
385 384
386 385
387bool OWaveLanPacket::fromDS() const 386bool OWaveLanPacket::fromDS() const
388{ 387{
389 return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 388 return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
390} 389}
391 390
392 391
393bool OWaveLanPacket::toDS() const 392bool OWaveLanPacket::toDS() const
394{ 393{
395 return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 394 return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
396} 395}
397 396
398 397
399bool OWaveLanPacket::usesPowerManagement() const 398bool OWaveLanPacket::usesPowerManagement() const
400{ 399{
401 return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 400 return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
402} 401}
403 402
404 403
405bool OWaveLanPacket::usesWep() const 404bool OWaveLanPacket::usesWep() const
406{ 405{
407 return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 406 return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
408} 407}
409 408
410 409
411/*====================================================================================== 410/*======================================================================================
412 * OWaveLanManagementPacket 411 * OWaveLanManagementPacket
413 *======================================================================================*/ 412 *======================================================================================*/
414 413
415OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) 414OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent )
416 :QObject( parent, "802.11 Management" ), _header( data ), 415 :QObject( parent, "802.11 Management" ), _header( data ),
417 _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) 416 _body( (const struct ieee_802_11_mgmt_body*) (data+1) )
418{ 417{
419 qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); 418 qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." );
420 419 qDebug( "Detected subtype is '%s'", (const char*) managementType() );
421 switch ( ((OWaveLanPacket*) this->parent() )->subType() )
422 {
423 case ST_BEACON:
424 {
425 // nice, received a beacon...
426 }
427 }
428 420
429 // grab tagged values 421 // grab tagged values
430 const unsigned char* ptr = (const unsigned char*) (_body+1); 422 const unsigned char* ptr = (const unsigned char*) (_body+1);
431 while (ptr < end) 423 while (ptr < end)
432 { 424 {
433 switch ( *ptr ) 425 switch ( *ptr )
434 { 426 {
435 case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; 427 case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break;
436 case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; 428 case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break;
437 case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; 429 case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break;
438 case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; 430 case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break;
439 case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; 431 case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break;
440 case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; 432 case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break;
441 case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; 433 case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break;
442 case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; 434 case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break;
443 } 435 }
444 ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value 436 ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value
445 ptr+= 2; // skip tag ID and length 437 ptr+= 2; // skip tag ID and length
446 } 438 }
447} 439}
448 440
449 441
450OWaveLanManagementPacket::~OWaveLanManagementPacket() 442OWaveLanManagementPacket::~OWaveLanManagementPacket()
451{ 443{
452} 444}
453 445
454 446
447QString OWaveLanManagementPacket::managementType() const
448{
449 switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) )
450 {
451 case ST_ASSOC_REQUEST: return "AssociationRequest"; break;
452 case ST_ASSOC_RESPONSE: return "AssociationResponse"; break;
453 case ST_REASSOC_REQUEST: return "ReassociationRequest"; break;
454 case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break;
455 case ST_PROBE_REQUEST: return "ProbeRequest"; break;
456 case ST_PROBE_RESPONSE: return "ProbeResponse"; break;
457 case ST_BEACON: return "Beacon"; break;
458 case ST_ATIM: return "Atim"; break;
459 case ST_DISASSOC: return "Disassociation"; break;
460 case ST_AUTH: return "Authentication"; break;
461 case ST_DEAUTH: return "Deathentication"; break;
462 default:
463 qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) );
464 return "Unknown";
465 }
466}
467
468
455int OWaveLanManagementPacket::beaconInterval() const 469int OWaveLanManagementPacket::beaconInterval() const
456{ 470{
457 return EXTRACT_LE_16BITS( &_body->beacon_interval ); 471 return EXTRACT_LE_16BITS( &_body->beacon_interval );
458} 472}
459 473
460 474
461int OWaveLanManagementPacket::capabilities() const 475int OWaveLanManagementPacket::capabilities() const
462{ 476{
463 return EXTRACT_LE_16BITS( &_body->capability_info ); 477 return EXTRACT_LE_16BITS( &_body->capability_info );
464} 478}
465 479
466 480
467bool OWaveLanManagementPacket::canESS() const 481bool OWaveLanManagementPacket::canESS() const
468{ 482{
469 return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); 483 return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) );
470} 484}
471 485
472 486
473bool OWaveLanManagementPacket::canIBSS() const 487bool OWaveLanManagementPacket::canIBSS() const
474{ 488{
475 return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); 489 return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) );
476} 490}
477 491
478 492
479bool OWaveLanManagementPacket::canCFP() const 493bool OWaveLanManagementPacket::canCFP() const
480{ 494{
481 return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); 495 return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) );
482} 496}
483 497
484 498
485bool OWaveLanManagementPacket::canCFP_REQ() const 499bool OWaveLanManagementPacket::canCFP_REQ() const
486{ 500{
487 return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); 501 return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) );
488} 502}
489 503
490 504
491bool OWaveLanManagementPacket::canPrivacy() const 505bool OWaveLanManagementPacket::canPrivacy() const
492{ 506{
493 return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); 507 return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) );
494} 508}
495 509
496 510
497/*====================================================================================== 511/*======================================================================================
498 * OWaveLanManagementSSID 512 * OWaveLanManagementSSID
499 *======================================================================================*/ 513 *======================================================================================*/
500 514
501OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) 515OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent )
502 :QObject( parent, "802.11 SSID" ), _data( data ) 516 :QObject( parent, "802.11 SSID" ), _data( data )
503{ 517{
504 qDebug( "OWaveLanManagementSSID()" ); 518 qDebug( "OWaveLanManagementSSID()" );
505} 519}
506 520
507 521
508OWaveLanManagementSSID::~OWaveLanManagementSSID() 522OWaveLanManagementSSID::~OWaveLanManagementSSID()
509{ 523{
510} 524}
511 525
512 526
513QString OWaveLanManagementSSID::ID() const 527QString OWaveLanManagementSSID::ID() const
514{ 528{
515 int length = _data->length; 529 int length = _data->length;
516 if ( length > 32 ) length = 32; 530 if ( length > 32 ) length = 32;
517 char essid[length+1]; 531 char essid[length+1];
518 memcpy( &essid, &_data->ssid, length ); 532 memcpy( &essid, &_data->ssid, length );
519 essid[length] = 0x0; 533 essid[length] = 0x0;
520 return essid; 534 return essid;
521} 535}
522 536
523 537
524/*====================================================================================== 538/*======================================================================================
525 * OWaveLanManagementRates 539 * OWaveLanManagementRates
526 *======================================================================================*/ 540 *======================================================================================*/
527 541
528OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) 542OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent )
529 :QObject( parent, "802.11 Rates" ), _data( data ) 543 :QObject( parent, "802.11 Rates" ), _data( data )
530{ 544{
531 qDebug( "OWaveLanManagementRates()" ); 545 qDebug( "OWaveLanManagementRates()" );
532} 546}
533 547
534 548
535OWaveLanManagementRates::~OWaveLanManagementRates() 549OWaveLanManagementRates::~OWaveLanManagementRates()
536{ 550{
537} 551}
538 552
539/*====================================================================================== 553/*======================================================================================
540 * OWaveLanManagementCF 554 * OWaveLanManagementCF
541 *======================================================================================*/ 555 *======================================================================================*/
542 556
543OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) 557OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent )
544 :QObject( parent, "802.11 CF" ), _data( data ) 558 :QObject( parent, "802.11 CF" ), _data( data )
545{ 559{
546 qDebug( "OWaveLanManagementCF()" ); 560 qDebug( "OWaveLanManagementCF()" );
547} 561}
548 562
549 563
550OWaveLanManagementCF::~OWaveLanManagementCF() 564OWaveLanManagementCF::~OWaveLanManagementCF()
551{ 565{
552} 566}
553 567
554/*====================================================================================== 568/*======================================================================================
555 * OWaveLanManagementFH 569 * OWaveLanManagementFH
556 *======================================================================================*/ 570 *======================================================================================*/
557 571
558OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) 572OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent )
559 :QObject( parent, "802.11 FH" ), _data( data ) 573 :QObject( parent, "802.11 FH" ), _data( data )
560{ 574{
561 qDebug( "OWaveLanManagementFH()" ); 575 qDebug( "OWaveLanManagementFH()" );
562} 576}
563 577
564 578
565OWaveLanManagementFH::~OWaveLanManagementFH() 579OWaveLanManagementFH::~OWaveLanManagementFH()
566{ 580{
567} 581}
568 582
569/*====================================================================================== 583/*======================================================================================
570 * OWaveLanManagementDS 584 * OWaveLanManagementDS
571 *======================================================================================*/ 585 *======================================================================================*/
572 586
573OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) 587OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent )
574 :QObject( parent, "802.11 DS" ), _data( data ) 588 :QObject( parent, "802.11 DS" ), _data( data )
575{ 589{
576 qDebug( "OWaveLanManagementDS()" ); 590 qDebug( "OWaveLanManagementDS()" );
577} 591}
578 592
579 593
580OWaveLanManagementDS::~OWaveLanManagementDS() 594OWaveLanManagementDS::~OWaveLanManagementDS()
581{ 595{
582} 596}
583 597
584 598
585int OWaveLanManagementDS::channel() const 599int OWaveLanManagementDS::channel() const
586{ 600{
587 return _data->channel; 601 return _data->channel;
588} 602}
589 603
590/*====================================================================================== 604/*======================================================================================
591 * OWaveLanManagementTim 605 * OWaveLanManagementTim
592 *======================================================================================*/ 606 *======================================================================================*/
593 607
594OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) 608OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent )
595 :QObject( parent, "802.11 Tim" ), _data( data ) 609 :QObject( parent, "802.11 Tim" ), _data( data )
596{ 610{
597 qDebug( "OWaveLanManagementTim()" ); 611 qDebug( "OWaveLanManagementTim()" );
598} 612}
599 613
600 614
601OWaveLanManagementTim::~OWaveLanManagementTim() 615OWaveLanManagementTim::~OWaveLanManagementTim()
602{ 616{
603} 617}
604 618
605/*====================================================================================== 619/*======================================================================================
606 * OWaveLanManagementIBSS 620 * OWaveLanManagementIBSS
607 *======================================================================================*/ 621 *======================================================================================*/
608 622
609OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) 623OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent )
610 :QObject( parent, "802.11 IBSS" ), _data( data ) 624 :QObject( parent, "802.11 IBSS" ), _data( data )
611{ 625{
612 qDebug( "OWaveLanManagementIBSS()" ); 626 qDebug( "OWaveLanManagementIBSS()" );
613} 627}
614 628
615 629
616OWaveLanManagementIBSS::~OWaveLanManagementIBSS() 630OWaveLanManagementIBSS::~OWaveLanManagementIBSS()
617{ 631{
618} 632}
619 633
620/*====================================================================================== 634/*======================================================================================
621 * OWaveLanManagementChallenge 635 * OWaveLanManagementChallenge
622 *======================================================================================*/ 636 *======================================================================================*/
623 637
624OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) 638OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent )
625 :QObject( parent, "802.11 Challenge" ), _data( data ) 639 :QObject( parent, "802.11 Challenge" ), _data( data )
626{ 640{
627 qDebug( "OWaveLanManagementChallenge()" ); 641 qDebug( "OWaveLanManagementChallenge()" );
628} 642}
629 643
630 644
631OWaveLanManagementChallenge::~OWaveLanManagementChallenge() 645OWaveLanManagementChallenge::~OWaveLanManagementChallenge()
632{ 646{
633} 647}
634 648
635/*====================================================================================== 649/*======================================================================================
636 * OWaveLanDataPacket 650 * OWaveLanDataPacket
637 *======================================================================================*/ 651 *======================================================================================*/
638 652
639OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) 653OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent )
640 :QObject( parent, "802.11 Data" ), _header( data ) 654 :QObject( parent, "802.11 Data" ), _header( data )
641{ 655{
642 qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." ); 656 qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." );
643 657
644 const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); 658 const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header );
645 659
646 #warning The next line works for most cases, but can not be correct generally! 660 #warning The next line works for most cases, but can not be correct generally!
647 if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address 661 if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address
648 662
649 new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); 663 new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this );
650} 664}
651 665
652 666
653OWaveLanDataPacket::~OWaveLanDataPacket() 667OWaveLanDataPacket::~OWaveLanDataPacket()
654{ 668{
655} 669}
656 670
657 671
658/*====================================================================================== 672/*======================================================================================
659 * OLLCPacket 673 * OLLCPacket
660 *======================================================================================*/ 674 *======================================================================================*/
661 675
662OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) 676OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent )
663 :QObject( parent, "802.11 LLC" ), _header( data ) 677 :QObject( parent, "802.11 LLC" ), _header( data )
664{ 678{
665 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); 679 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." );
666 680
667 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) 681 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) )
668 { 682 {
669 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); 683 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) );
670 684
671 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h 685 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h
672 { 686 {
673 case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; 687 case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
674 default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" ); 688 default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" );
675 } 689 }
676 690
677 } 691 }
678} 692}
679 693
680 694
681OLLCPacket::~OLLCPacket() 695OLLCPacket::~OLLCPacket()
682{ 696{
683} 697}
684 698
699
700/*======================================================================================
701 * OWaveLanControlPacket
702 *======================================================================================*/
703
704OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent )
705 :QObject( parent, "802.11 Data" ), _header( data )
706{
707 qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." );
708 //TODO: Implement this
709}
710
711
712OWaveLanControlPacket::~OWaveLanControlPacket()
713{
714}
715
716
685/*====================================================================================== 717/*======================================================================================
686 * OPacketCapturer 718 * OPacketCapturer
687 *======================================================================================*/ 719 *======================================================================================*/
688 720
689OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) 721OPacketCapturer::OPacketCapturer( QObject* parent, const char* name )
690 :QObject( parent, name ), _name( QString::null ), _open( false ), 722 :QObject( parent, name ), _name( QString::null ), _open( false ),
691 _pch( 0 ), _sn( 0 ) 723 _pch( 0 ), _sn( 0 )
692{ 724{
693} 725}
694 726
695 727
696OPacketCapturer::~OPacketCapturer() 728OPacketCapturer::~OPacketCapturer()
697{ 729{
698 if ( _open ) 730 if ( _open )
699 { 731 {
700 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); 732 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." );
701 close(); 733 close();
702 } 734 }
703} 735}
704 736
705 737
706void OPacketCapturer::setBlocking( bool b ) 738void OPacketCapturer::setBlocking( bool b )
707{ 739{
708 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) 740 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 )
709 { 741 {
710 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); 742 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." );
711 } 743 }
712 else 744 else
713 { 745 {
714 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); 746 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf );
715 } 747 }
716} 748}
717 749
718 750
719bool OPacketCapturer::blocking() const 751bool OPacketCapturer::blocking() const
720{ 752{
721 int b = pcap_getnonblock( _pch, _errbuf ); 753 int b = pcap_getnonblock( _pch, _errbuf );
722 if ( b == -1 ) 754 if ( b == -1 )
723 { 755 {
724 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); 756 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf );
725 return -1; 757 return -1;
726 } 758 }
727 return !b; 759 return !b;
728} 760}
729 761
730 762
731void OPacketCapturer::close() 763void OPacketCapturer::close()
732{ 764{
733 if ( _open ) 765 if ( _open )
734 { 766 {
735 if ( _sn ) 767 if ( _sn )
736 { 768 {
737 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 769 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
738 delete _sn; 770 delete _sn;
739 } 771 }
740 pcap_close( _pch ); 772 pcap_close( _pch );
741 _open = false; 773 _open = false;
742 } 774 }
743} 775}
744 776
745 777
746int OPacketCapturer::dataLink() const 778int OPacketCapturer::dataLink() const
747{ 779{
748 return pcap_datalink( _pch ); 780 return pcap_datalink( _pch );
749} 781}
750 782
751 783
752int OPacketCapturer::fileno() const 784int OPacketCapturer::fileno() const
753{ 785{
754 if ( _open ) 786 if ( _open )
755 { 787 {
756 return pcap_fileno( _pch ); 788 return pcap_fileno( _pch );
757 } 789 }
758 else 790 else
759 { 791 {
760 return -1; 792 return -1;
761 } 793 }
762} 794}
763 795
764 796
765OPacket* OPacketCapturer::next() 797OPacket* OPacketCapturer::next()
766{ 798{
767 packetheaderstruct header; 799 packetheaderstruct header;
768 qDebug( "==> OPacketCapturer::next()" ); 800 qDebug( "==> OPacketCapturer::next()" );
769 const unsigned char* pdata = pcap_next( _pch, &header ); 801 const unsigned char* pdata = pcap_next( _pch, &header );
770 qDebug( "<== OPacketCapturer::next()" ); 802 qDebug( "<== OPacketCapturer::next()" );
771 803
772 if ( header.len ) 804 if ( header.len )
773 return new OPacket( header, pdata, this ); 805 {
806 return new OPacket( dataLink(), header, pdata, 0 );
807 // packets shouldn't be inserted in the QObject child-parent hierarchy,
808 // because due to memory constraints they will be deleted as soon
809 // as possible - that is right after they have been processed
810 // by emit() [ see below ]
811 }
774 else 812 else
813 {
775 return 0; 814 return 0;
815 }
776} 816}
777 817
778 818
779bool OPacketCapturer::open( const QString& name ) 819bool OPacketCapturer::open( const QString& name )
780{ 820{
781 if ( _open ) 821 if ( _open )
782 { 822 {
783 if ( name == _name ) // ignore opening an already openend device 823 if ( name == _name ) // ignore opening an already openend device
784 { 824 {
785 return true; 825 return true;
786 } 826 }
787 else // close the last opened device 827 else // close the last opened device
788 { 828 {
789 close(); 829 close();
790 } 830 }
791 } 831 }
792 832
793 _name = name; 833 _name = name;
794 834
795 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); 835 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] );
796 836
797 if ( handle ) 837 if ( handle )
798 { 838 {
799 qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); 839 qDebug( "OPacketCapturer::open(): libpcap opened successfully." );
800 _pch = handle; 840 _pch = handle;
801 _open = true; 841 _open = true;
802 842
803 // in case we have an application object, create a socket notifier 843 // in case we have an application object, create a socket notifier
804 if ( qApp ) 844 if ( qApp )
805 { 845 {
806 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); 846 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
807 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 847 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
808 } 848 }
809 849
810 return true; 850 return true;
811 } 851 }
812 else 852 else
813 { 853 {
814 qDebug( "OPacketCapturer::open(): can't open libpcap: %s", _errbuf ); 854 qDebug( "OPacketCapturer::open(): can't open libpcap: %s", _errbuf );
815 return false; 855 return false;
816 } 856 }
817 857
818} 858}
819 859
820 860
821bool OPacketCapturer::isOpen() const 861bool OPacketCapturer::isOpen() const
822{ 862{
823 return _open; 863 return _open;
824} 864}
825 865
826 866
827void OPacketCapturer::readyToReceive() 867void OPacketCapturer::readyToReceive()
828{ 868{
829 qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(...)'" ); 869 qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(...)'" );
830 emit receivedPacket( next() ); 870 OPacket* p = next();
871 emit receivedPacket( p );
872 // emit is synchronous - packet has been dealt with, now it's safe to delete
873 delete p;
831} 874}
832 875
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h
index 04d22ff..ddef278 100644
--- a/libopie2/opienet/opcap.h
+++ b/libopie2/opienet/opcap.h
@@ -1,436 +1,452 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 by the Wellenreiter team: 3              Copyright (C) 2003 by the Wellenreiter team:
4 Martin J. Muench <mjm@remote-exploit.org> 4 Martin J. Muench <mjm@remote-exploit.org>
5 Max Moser <mmo@remote-exploit.org 5 Max Moser <mmo@remote-exploit.org
6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#ifndef OPCAP_H 34#ifndef OPCAP_H
35#define OPCAP_H 35#define OPCAP_H
36 36
37/* LINUX */ 37/* LINUX */
38extern "C" // work around a bpf/pcap conflict in recent headers 38extern "C" // work around a bpf/pcap conflict in recent headers
39{ 39{
40 #include <pcap.h> 40 #include <pcap.h>
41} 41}
42#include <netinet/ether.h> 42#include <netinet/ether.h>
43#include <netinet/ip.h> 43#include <netinet/ip.h>
44#include <netinet/udp.h> 44#include <netinet/udp.h>
45#include <netinet/tcp.h> 45#include <netinet/tcp.h>
46#include <time.h> 46#include <time.h>
47 47
48/* QT */ 48/* QT */
49#include <qhostaddress.h> 49#include <qhostaddress.h>
50#include <qobject.h> 50#include <qobject.h>
51#include <qstring.h> 51#include <qstring.h>
52 52
53/* OPIE */ 53/* OPIE */
54#include <opie2/onetutils.h> 54#include <opie2/onetutils.h>
55#include "802_11_user.h" 55#include "802_11_user.h"
56 56
57/* TYPEDEFS */ 57/* TYPEDEFS */
58typedef struct timeval timevalstruct; 58typedef struct timeval timevalstruct;
59typedef struct pcap_pkthdr packetheaderstruct; 59typedef struct pcap_pkthdr packetheaderstruct;
60 60
61/* FORWARDS */ 61/* FORWARDS */
62class OPacketCapturer; 62class OPacketCapturer;
63class QSocketNotifier; 63class QSocketNotifier;
64 64
65/*====================================================================================== 65/*======================================================================================
66 * OPacket - A frame on the wire 66 * OPacket - A frame on the wire
67 *======================================================================================*/ 67 *======================================================================================*/
68 68
69class OPacket : public QObject 69class OPacket : public QObject
70{ 70{
71 Q_OBJECT 71 Q_OBJECT
72 72
73 public: 73 public:
74 OPacket( packetheaderstruct, const unsigned char*, QObject* parent ); 74 OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent );
75 virtual ~OPacket(); 75 virtual ~OPacket();
76 76
77 timevalstruct timeval() const; 77 timevalstruct timeval() const;
78 78
79 OPacketCapturer* packetCapturer() const;
80
81 int caplen() const; 79 int caplen() const;
82 int len() const; 80 int len() const;
83 QString dump( int = 32 ) const; 81 QString dump( int = 32 ) const;
84 82
85 private: 83 private:
86 const packetheaderstruct _hdr; // pcap packet header 84 const packetheaderstruct _hdr; // pcap packet header
87 const unsigned char* _data; // pcap packet data 85 const unsigned char* _data; // pcap packet data
88 const unsigned char* _end; // end of pcap packet data 86 const unsigned char* _end; // end of pcap packet data
89}; 87};
90 88
91/*====================================================================================== 89/*======================================================================================
92 * OEthernetPacket - DLT_EN10MB frame 90 * OEthernetPacket - DLT_EN10MB frame
93 *======================================================================================*/ 91 *======================================================================================*/
94 92
95class OEthernetPacket : public QObject 93class OEthernetPacket : public QObject
96{ 94{
97 Q_OBJECT 95 Q_OBJECT
98 96
99 public: 97 public:
100 OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); 98 OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 );
101 virtual ~OEthernetPacket(); 99 virtual ~OEthernetPacket();
102 100
103 OMacAddress sourceAddress() const; 101 OMacAddress sourceAddress() const;
104 OMacAddress destinationAddress() const; 102 OMacAddress destinationAddress() const;
105 int type() const; 103 int type() const;
106 104
107 private: 105 private:
108 const struct ether_header* _ether; 106 const struct ether_header* _ether;
109}; 107};
110 108
111 109
112/*====================================================================================== 110/*======================================================================================
113 * OWaveLanPacket - DLT_IEEE802_11 frame 111 * OWaveLanPacket - DLT_IEEE802_11 frame
114 *======================================================================================*/ 112 *======================================================================================*/
115 113
116class OWaveLanPacket : public QObject 114class OWaveLanPacket : public QObject
117{ 115{
118 Q_OBJECT 116 Q_OBJECT
119 117
120 public: 118 public:
121 OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); 119 OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 );
122 virtual ~OWaveLanPacket(); 120 virtual ~OWaveLanPacket();
123 121
124 int duration() const; 122 int duration() const;
125 bool fromDS() const; 123 bool fromDS() const;
126 bool toDS() const; 124 bool toDS() const;
127 virtual OMacAddress macAddress1() const; 125 virtual OMacAddress macAddress1() const;
128 virtual OMacAddress macAddress2() const; 126 virtual OMacAddress macAddress2() const;
129 virtual OMacAddress macAddress3() const; 127 virtual OMacAddress macAddress3() const;
130 virtual OMacAddress macAddress4() const; 128 virtual OMacAddress macAddress4() const;
131 bool usesPowerManagement() const; 129 bool usesPowerManagement() const;
132 int type() const; 130 int type() const;
133 int subType() const; 131 int subType() const;
134 int version() const; 132 int version() const;
135 bool usesWep() const; 133 bool usesWep() const;
136 134
137 private: 135 private:
138 const struct ieee_802_11_header* _wlanhdr; 136 const struct ieee_802_11_header* _wlanhdr;
139}; 137};
140 138
141 139
142/*====================================================================================== 140/*======================================================================================
143 * OWaveLanManagementPacket - type: management (T_MGMT) 141 * OWaveLanManagementPacket - type: management (T_MGMT)
144 *======================================================================================*/ 142 *======================================================================================*/
145 143
146class OWaveLanManagementPacket : public QObject 144class OWaveLanManagementPacket : public QObject
147{ 145{
148 Q_OBJECT 146 Q_OBJECT
149 147
150 public: 148 public:
151 OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); 149 OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 );
152 virtual ~OWaveLanManagementPacket(); 150 virtual ~OWaveLanManagementPacket();
153 151
152 QString managementType() const;
153
154 int beaconInterval() const; 154 int beaconInterval() const;
155 int capabilities() const; // generic 155 int capabilities() const; // generic
156 156
157 bool canESS() const; 157 bool canESS() const;
158 bool canIBSS() const; 158 bool canIBSS() const;
159 bool canCFP() const; 159 bool canCFP() const;
160 bool canCFP_REQ() const; 160 bool canCFP_REQ() const;
161 bool canPrivacy() const; 161 bool canPrivacy() const;
162 162
163 private: 163 private:
164 const struct ieee_802_11_mgmt_header* _header; 164 const struct ieee_802_11_mgmt_header* _header;
165 const struct ieee_802_11_mgmt_body* _body; 165 const struct ieee_802_11_mgmt_body* _body;
166}; 166};
167 167
168 168
169/*====================================================================================== 169/*======================================================================================
170 * OWaveLanManagementSSID 170 * OWaveLanManagementSSID
171 *======================================================================================*/ 171 *======================================================================================*/
172 172
173class OWaveLanManagementSSID : public QObject 173class OWaveLanManagementSSID : public QObject
174{ 174{
175 Q_OBJECT 175 Q_OBJECT
176 176
177 public: 177 public:
178 OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 ); 178 OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 );
179 virtual ~OWaveLanManagementSSID(); 179 virtual ~OWaveLanManagementSSID();
180 180
181 QString ID() const; 181 QString ID() const;
182 182
183 private: 183 private:
184 const struct ssid_t* _data; 184 const struct ssid_t* _data;
185}; 185};
186 186
187/*====================================================================================== 187/*======================================================================================
188 * OWaveLanManagementRates 188 * OWaveLanManagementRates
189 *======================================================================================*/ 189 *======================================================================================*/
190 190
191class OWaveLanManagementRates : public QObject 191class OWaveLanManagementRates : public QObject
192{ 192{
193 Q_OBJECT 193 Q_OBJECT
194 194
195 public: 195 public:
196 OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); 196 OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 );
197 virtual ~OWaveLanManagementRates(); 197 virtual ~OWaveLanManagementRates();
198 198
199 private: 199 private:
200 const struct rates_t* _data; 200 const struct rates_t* _data;
201}; 201};
202 202
203/*====================================================================================== 203/*======================================================================================
204 * OWaveLanManagementCF 204 * OWaveLanManagementCF
205 *======================================================================================*/ 205 *======================================================================================*/
206 206
207class OWaveLanManagementCF : public QObject 207class OWaveLanManagementCF : public QObject
208{ 208{
209 Q_OBJECT 209 Q_OBJECT
210 210
211 public: 211 public:
212 OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); 212 OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 );
213 virtual ~OWaveLanManagementCF(); 213 virtual ~OWaveLanManagementCF();
214 214
215 private: 215 private:
216 const struct cf_t* _data; 216 const struct cf_t* _data;
217}; 217};
218 218
219/*====================================================================================== 219/*======================================================================================
220 * OWaveLanManagementFH 220 * OWaveLanManagementFH
221 *======================================================================================*/ 221 *======================================================================================*/
222 222
223class OWaveLanManagementFH : public QObject 223class OWaveLanManagementFH : public QObject
224{ 224{
225 Q_OBJECT 225 Q_OBJECT
226 226
227 public: 227 public:
228 OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 ); 228 OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 );
229 virtual ~OWaveLanManagementFH(); 229 virtual ~OWaveLanManagementFH();
230 230
231 private: 231 private:
232 const struct fh_t* _data; 232 const struct fh_t* _data;
233}; 233};
234 234
235/*====================================================================================== 235/*======================================================================================
236 * OWaveLanManagementDS 236 * OWaveLanManagementDS
237 *======================================================================================*/ 237 *======================================================================================*/
238 238
239class OWaveLanManagementDS : public QObject 239class OWaveLanManagementDS : public QObject
240{ 240{
241 Q_OBJECT 241 Q_OBJECT
242 242
243 public: 243 public:
244 OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); 244 OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 );
245 virtual ~OWaveLanManagementDS(); 245 virtual ~OWaveLanManagementDS();
246 246
247 int channel() const; 247 int channel() const;
248 248
249 private: 249 private:
250 const struct ds_t* _data; 250 const struct ds_t* _data;
251}; 251};
252 252
253/*====================================================================================== 253/*======================================================================================
254 * OWaveLanManagementTim 254 * OWaveLanManagementTim
255 *======================================================================================*/ 255 *======================================================================================*/
256 256
257class OWaveLanManagementTim : public QObject 257class OWaveLanManagementTim : public QObject
258{ 258{
259 Q_OBJECT 259 Q_OBJECT
260 260
261 public: 261 public:
262 OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); 262 OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 );
263 virtual ~OWaveLanManagementTim(); 263 virtual ~OWaveLanManagementTim();
264 264
265 private: 265 private:
266 const struct tim_t* _data; 266 const struct tim_t* _data;
267}; 267};
268 268
269/*====================================================================================== 269/*======================================================================================
270 * OWaveLanManagementIBSS 270 * OWaveLanManagementIBSS
271 *======================================================================================*/ 271 *======================================================================================*/
272 272
273class OWaveLanManagementIBSS : public QObject 273class OWaveLanManagementIBSS : public QObject
274{ 274{
275 Q_OBJECT 275 Q_OBJECT
276 276
277 public: 277 public:
278 OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); 278 OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 );
279 virtual ~OWaveLanManagementIBSS(); 279 virtual ~OWaveLanManagementIBSS();
280 280
281 private: 281 private:
282 const struct ibss_t* _data; 282 const struct ibss_t* _data;
283}; 283};
284 284
285/*====================================================================================== 285/*======================================================================================
286 * OWaveLanManagementChallenge 286 * OWaveLanManagementChallenge
287 *======================================================================================*/ 287 *======================================================================================*/
288 288
289class OWaveLanManagementChallenge : public QObject 289class OWaveLanManagementChallenge : public QObject
290{ 290{
291 Q_OBJECT 291 Q_OBJECT
292 292
293 public: 293 public:
294 OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); 294 OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 );
295 virtual ~OWaveLanManagementChallenge(); 295 virtual ~OWaveLanManagementChallenge();
296 296
297 private: 297 private:
298 const struct challenge_t* _data; 298 const struct challenge_t* _data;
299}; 299};
300 300
301/*====================================================================================== 301/*======================================================================================
302 * OWaveLanDataPacket - type: data (T_DATA) 302 * OWaveLanDataPacket - type: data (T_DATA)
303 *======================================================================================*/ 303 *======================================================================================*/
304 304
305class OWaveLanDataPacket : public QObject 305class OWaveLanDataPacket : public QObject
306{ 306{
307 Q_OBJECT 307 Q_OBJECT
308 308
309 public: 309 public:
310 OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); 310 OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 );
311 virtual ~OWaveLanDataPacket(); 311 virtual ~OWaveLanDataPacket();
312 312
313 private: 313 private:
314 const struct ieee_802_11_data_header* _header; 314 const struct ieee_802_11_data_header* _header;
315}; 315};
316 316
317/*====================================================================================== 317/*======================================================================================
318 * OWaveLanControlPacket - type: control (T_CTRL)
319 *======================================================================================*/
320
321class OWaveLanControlPacket : public QObject
322{
323 Q_OBJECT
324
325 public:
326 OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 );
327 virtual ~OWaveLanControlPacket();
328
329 private:
330 const struct ieee_802_11_control_header* _header;
331};
332
333/*======================================================================================
318 * OLLCPacket - IEEE 802.2 Link Level Control 334 * OLLCPacket - IEEE 802.2 Link Level Control
319 *======================================================================================*/ 335 *======================================================================================*/
320 336
321class OLLCPacket : public QObject 337class OLLCPacket : public QObject
322{ 338{
323 Q_OBJECT 339 Q_OBJECT
324 340
325 public: 341 public:
326 OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); 342 OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 );
327 virtual ~OLLCPacket(); 343 virtual ~OLLCPacket();
328 344
329 private: 345 private:
330 const struct ieee_802_11_802_2_header* _header; 346 const struct ieee_802_11_802_2_header* _header;
331}; 347};
332 348
333/*====================================================================================== 349/*======================================================================================
334 * OIPPacket 350 * OIPPacket
335 *======================================================================================*/ 351 *======================================================================================*/
336 352
337class OIPPacket : public QObject 353class OIPPacket : public QObject
338{ 354{
339 Q_OBJECT 355 Q_OBJECT
340 356
341 public: 357 public:
342 OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); 358 OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 );
343 virtual ~OIPPacket(); 359 virtual ~OIPPacket();
344 360
345 QHostAddress fromIPAddress() const; 361 QHostAddress fromIPAddress() const;
346 QHostAddress toIPAddress() const; 362 QHostAddress toIPAddress() const;
347 363
348 int tos() const; 364 int tos() const;
349 int len() const; 365 int len() const;
350 int id() const; 366 int id() const;
351 int offset() const; 367 int offset() const;
352 int ttl() const; 368 int ttl() const;
353 int protocol() const; 369 int protocol() const;
354 int checksum() const; 370 int checksum() const;
355 371
356 private: 372 private:
357 const struct iphdr* _iphdr; 373 const struct iphdr* _iphdr;
358}; 374};
359 375
360/*====================================================================================== 376/*======================================================================================
361 * OUDPPacket 377 * OUDPPacket
362 *======================================================================================*/ 378 *======================================================================================*/
363 379
364class OUDPPacket : public QObject 380class OUDPPacket : public QObject
365{ 381{
366 Q_OBJECT 382 Q_OBJECT
367 383
368 public: 384 public:
369 OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); 385 OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 );
370 virtual ~OUDPPacket(); 386 virtual ~OUDPPacket();
371 387
372 int fromPort() const; 388 int fromPort() const;
373 int toPort() const; 389 int toPort() const;
374 390
375 private: 391 private:
376 const struct udphdr* _udphdr; 392 const struct udphdr* _udphdr;
377}; 393};
378 394
379/*====================================================================================== 395/*======================================================================================
380 * OTCPPacket 396 * OTCPPacket
381 *======================================================================================*/ 397 *======================================================================================*/
382 398
383class OTCPPacket : public QObject 399class OTCPPacket : public QObject
384{ 400{
385 Q_OBJECT 401 Q_OBJECT
386 402
387 public: 403 public:
388 OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); 404 OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 );
389 virtual ~OTCPPacket(); 405 virtual ~OTCPPacket();
390 406
391 int fromPort() const; 407 int fromPort() const;
392 int toPort() const; 408 int toPort() const;
393 409
394 private: 410 private:
395 const struct tcphdr* _tcphdr; 411 const struct tcphdr* _tcphdr;
396}; 412};
397 413
398 414
399/*====================================================================================== 415/*======================================================================================
400 * OPacketCapturer 416 * OPacketCapturer
401 *======================================================================================*/ 417 *======================================================================================*/
402 418
403class OPacketCapturer : public QObject 419class OPacketCapturer : public QObject
404{ 420{
405 Q_OBJECT 421 Q_OBJECT
406 422
407 public: 423 public:
408 OPacketCapturer( QObject* parent = 0, const char* name = 0 ); 424 OPacketCapturer( QObject* parent = 0, const char* name = 0 );
409 ~OPacketCapturer(); 425 ~OPacketCapturer();
410 426
411 void setBlocking( bool ); 427 void setBlocking( bool );
412 bool blocking() const; 428 bool blocking() const;
413 429
414 void close(); 430 void close();
415 int dataLink() const; 431 int dataLink() const;
416 int fileno() const; 432 int fileno() const;
417 OPacket* next(); 433 OPacket* next();
418 bool open( const QString& name ); 434 bool open( const QString& name );
419 bool isOpen() const; 435 bool isOpen() const;
420 436
421 signals: 437 signals:
422 void receivedPacket( OPacket* ); 438 void receivedPacket( OPacket* );
423 439
424 protected slots: 440 protected slots:
425 void readyToReceive(); 441 void readyToReceive();
426 442
427 protected: 443 protected:
428 QString _name; // devicename 444 QString _name; // devicename
429 bool _open; // check this before doing pcap calls 445 bool _open; // check this before doing pcap calls
430 pcap_t* _pch; // pcap library handle 446 pcap_t* _pch; // pcap library handle
431 QSocketNotifier* _sn; // socket notifier for main loop 447 QSocketNotifier* _sn; // socket notifier for main loop
432 mutable char _errbuf[PCAP_ERRBUF_SIZE]; 448 mutable char _errbuf[PCAP_ERRBUF_SIZE];
433}; 449};
434 450
435#endif // OPCAP_H 451#endif // OPCAP_H
436 452