-rw-r--r-- | libopie2/opienet/802_11_user.h | 14 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 5 | ||||
-rw-r--r-- | libopie2/opienet/opcap.cpp | 31 | ||||
-rw-r--r-- | libopie2/opienet/opcap.h | 19 |
4 files changed, 67 insertions, 2 deletions
diff --git a/libopie2/opienet/802_11_user.h b/libopie2/opienet/802_11_user.h index f596bd8..cd98503 100644 --- a/libopie2/opienet/802_11_user.h +++ b/libopie2/opienet/802_11_user.h | |||
@@ -1,443 +1,457 @@ | |||
1 | #ifndef IEEE_802_11 | 1 | #ifndef IEEE_802_11 |
2 | #define IEEE_802_11 | 2 | #define IEEE_802_11 |
3 | 3 | ||
4 | enum ieee_802_11_link_status_failure_reason { | 4 | enum 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 nonAssociated station"},\ | 25 | {Class_3_from_NonAuth,0xff," Class 3 frame received from nonAssociated 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 | ||
34 | struct ieee_802_11_header { | 34 | struct 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 | ||
47 | struct ieee_802_3_header { | 47 | struct 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 | ||
58 | struct ieee_802_11_snap_header { | 58 | struct 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 | ||
69 | struct ieee_802_11_802_1H_header { | 69 | struct 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 | ||
79 | struct ieee_802_11_802_2_header { | 79 | struct 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 | } |
153 | struct ieee_802_11_frame_subtype_class { | 153 | struct 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 | ||
236 | struct ieee_802_11_mgmt_header { | 236 | struct 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 | ||
246 | struct ieee_802_11_data_header { | 246 | struct 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 | ||
258 | struct ieee_802_11_control_header { | 258 | struct ieee_802_11_control_header { |
259 | u_int16_tframe_control; | 259 | u_int16_tframe_control; |
260 | u_int16_tduration; | 260 | u_int16_tduration; |
261 | u_int8_tmac1[6]; | 261 | u_int8_tmac1[6]; |
262 | u_int8_tmac2[6]; | 262 | u_int8_tmac2[6]; |
263 | u_int8_tmac3[6]; | 263 | u_int8_tmac3[6]; |
264 | u_int16_tSeqCtl; | 264 | u_int16_tSeqCtl; |
265 | u_int8_tmac4[6]; | 265 | u_int8_tmac4[6]; |
266 | // u_int16_tgapLen; | 266 | // u_int16_tgapLen; |
267 | // u_int8_tgap[8]; | 267 | // u_int8_tgap[8]; |
268 | }; | 268 | }; |
269 | 269 | ||
270 | #define CAPABILITY_ESS(cap) ((cap) & 0x0001) | 270 | #define CAPABILITY_ESS(cap) ((cap) & 0x0001) |
271 | #define CAPABILITY_IBSS(cap) ((cap) & 0x0002) | 271 | #define CAPABILITY_IBSS(cap) ((cap) & 0x0002) |
272 | #define CAPABILITY_CFP(cap) ((cap) & 0x0004) | 272 | #define CAPABILITY_CFP(cap) ((cap) & 0x0004) |
273 | #define CAPABILITY_CFP_REQ(cap) ((cap) & 0x0008) | 273 | #define CAPABILITY_CFP_REQ(cap) ((cap) & 0x0008) |
274 | #define CAPABILITY_PRIVACY(cap) ((cap) & 0x0010) | 274 | #define CAPABILITY_PRIVACY(cap) ((cap) & 0x0010) |
275 | 275 | ||
276 | struct ssid_t { | 276 | struct ssid_t { |
277 | u_int8_telement_id; | 277 | u_int8_telement_id; |
278 | u_int8_tlength; | 278 | u_int8_tlength; |
279 | u_char ssid[33]; /* 32 + 1 for null */ | 279 | u_char ssid[33]; /* 32 + 1 for null */ |
280 | }; | 280 | }; |
281 | 281 | ||
282 | 282 | ||
283 | struct rates_t { | 283 | struct rates_t { |
284 | u_int8_telement_id; | 284 | u_int8_telement_id; |
285 | u_int8_tlength; | 285 | u_int8_tlength; |
286 | u_int8_trate[8]; | 286 | u_int8_trate[8]; |
287 | }; | 287 | }; |
288 | 288 | ||
289 | 289 | ||
290 | struct challenge_t { | 290 | struct challenge_t { |
291 | u_int8_telement_id; | 291 | u_int8_telement_id; |
292 | u_int8_tlength; | 292 | u_int8_tlength; |
293 | u_int8_ttext[254]; /* 1-253 + 1 for null */ | 293 | u_int8_ttext[254]; /* 1-253 + 1 for null */ |
294 | }; | 294 | }; |
295 | 295 | ||
296 | 296 | ||
297 | struct fh_t { | 297 | struct fh_t { |
298 | u_int8_telement_id; | 298 | u_int8_telement_id; |
299 | u_int8_tlength; | 299 | u_int8_tlength; |
300 | u_int16_tdwell_time; | 300 | u_int16_tdwell_time; |
301 | u_int8_thop_set; | 301 | u_int8_thop_set; |
302 | u_int8_t hop_pattern; | 302 | u_int8_t hop_pattern; |
303 | u_int8_thop_index; | 303 | u_int8_thop_index; |
304 | }; | 304 | }; |
305 | 305 | ||
306 | 306 | ||
307 | struct ds_t { | 307 | struct ds_t { |
308 | u_int8_telement_id; | 308 | u_int8_telement_id; |
309 | u_int8_tlength; | 309 | u_int8_tlength; |
310 | u_int8_tchannel; | 310 | u_int8_tchannel; |
311 | }; | 311 | }; |
312 | 312 | ||
313 | 313 | ||
314 | struct cf_t { | 314 | struct cf_t { |
315 | u_int8_telement_id; | 315 | u_int8_telement_id; |
316 | u_int8_tlength; | 316 | u_int8_tlength; |
317 | u_int8_tcount; | 317 | u_int8_tcount; |
318 | u_int8_tperiod; | 318 | u_int8_tperiod; |
319 | u_int16_tmax_duration; | 319 | u_int16_tmax_duration; |
320 | u_int16_tdur_remaing; | 320 | u_int16_tdur_remaing; |
321 | }; | 321 | }; |
322 | 322 | ||
323 | 323 | ||
324 | struct tim_t { | 324 | struct tim_t { |
325 | u_int8_telement_id; | 325 | u_int8_telement_id; |
326 | u_int8_tlength; | 326 | u_int8_tlength; |
327 | u_int8_tcount; | 327 | u_int8_tcount; |
328 | u_int8_tperiod; | 328 | u_int8_tperiod; |
329 | u_int8_tbitmap_control; | 329 | u_int8_tbitmap_control; |
330 | u_int8_tbitmap[251]; | 330 | u_int8_tbitmap[251]; |
331 | }; | 331 | }; |
332 | 332 | ||
333 | 333 | ||
334 | struct ibss_t { | 334 | struct ibss_t { |
335 | u_int8_telement_id; | 335 | u_int8_telement_id; |
336 | u_int8_tlength; | 336 | u_int8_tlength; |
337 | u_int16_tatim_window; | 337 | u_int16_tatim_window; |
338 | }; | 338 | }; |
339 | 339 | ||
340 | 340 | ||
341 | #define E_SSID 0 | 341 | #define E_SSID 0 |
342 | #define E_RATES 1 | 342 | #define E_RATES 1 |
343 | #define E_FH 2 | 343 | #define E_FH 2 |
344 | #define E_DS 3 | 344 | #define E_DS 3 |
345 | #define E_CF 4 | 345 | #define E_CF 4 |
346 | #define E_TIM 5 | 346 | #define E_TIM 5 |
347 | #define E_IBSS 6 | 347 | #define E_IBSS 6 |
348 | #define E_CHALLENGE 16 | 348 | #define E_CHALLENGE 16 |
349 | #define E_CISCO 133 | 349 | #define E_CISCO 133 |
350 | 350 | ||
351 | 351 | ||
352 | struct ieee_802_11_mgmt_body { | 352 | struct ieee_802_11_mgmt_body { |
353 | u_int8_t timestamp[8]; | 353 | u_int8_t timestamp[8]; |
354 | u_int16_t beacon_interval; | 354 | u_int16_t beacon_interval; |
355 | // u_int16_t listen_interval; | 355 | // u_int16_t listen_interval; |
356 | // u_int16_t status_code; | 356 | // u_int16_t status_code; |
357 | // u_int16_t aid; | 357 | // u_int16_t aid; |
358 | // u_char ap[6]; | 358 | // u_char ap[6]; |
359 | // u_int16_treason_code; | 359 | // u_int16_treason_code; |
360 | // u_int16_tauth_alg; | 360 | // u_int16_tauth_alg; |
361 | // u_int16_tauth_trans_seq_num; | 361 | // u_int16_tauth_trans_seq_num; |
362 | // struct challenge_t challenge; | 362 | // struct challenge_t challenge; |
363 | u_int16_t capability_info; | 363 | u_int16_t capability_info; |
364 | // struct ssid_tssid; | 364 | // struct ssid_tssid; |
365 | // struct rates_t rates; | 365 | // struct rates_t rates; |
366 | // struct ds_tds; | 366 | // struct ds_tds; |
367 | // struct cf_tcf; | 367 | // struct cf_tcf; |
368 | // struct fh_tfh; | 368 | // struct fh_tfh; |
369 | // struct tim_ttim; | 369 | // struct tim_ttim; |
370 | }; | 370 | }; |
371 | 371 | ||
372 | /* a 802.11 value */ | ||
373 | struct val_80211 { | ||
374 | unsigned int did; | ||
375 | unsigned short status, len; | ||
376 | unsigned int data; | ||
377 | }; | ||
378 | |||
379 | /* header attached during prism monitor mode */ | ||
380 | struct prism_hdr { | ||
381 | unsigned int msgcode, msglen; | ||
382 | char devname[16]; | ||
383 | struct val_80211 hosttime, mactime, channel, rssi, sq, signal, | ||
384 | noise, rate, istx, frmlen; | ||
385 | }; | ||
372 | 386 | ||
373 | struct ieee_802_11_data_body { | 387 | struct ieee_802_11_data_body { |
374 | //FIXME | 388 | //FIXME |
375 | }; | 389 | }; |
376 | 390 | ||
377 | struct ieee_802_11_control_body { | 391 | struct ieee_802_11_control_body { |
378 | //FIXME | 392 | //FIXME |
379 | }; | 393 | }; |
380 | 394 | ||
381 | struct ctrl_rts_t { | 395 | struct ctrl_rts_t { |
382 | u_int16_tfc; | 396 | u_int16_tfc; |
383 | u_int16_tduration; | 397 | u_int16_tduration; |
384 | u_int8_tra[6]; | 398 | u_int8_tra[6]; |
385 | u_int8_tta[6]; | 399 | u_int8_tta[6]; |
386 | u_int8_tfcs[4]; | 400 | u_int8_tfcs[4]; |
387 | }; | 401 | }; |
388 | 402 | ||
389 | #define CTRL_RTS_LEN(2+2+6+6+4) | 403 | #define CTRL_RTS_LEN(2+2+6+6+4) |
390 | 404 | ||
391 | struct ctrl_cts_t { | 405 | struct ctrl_cts_t { |
392 | u_int16_tfc; | 406 | u_int16_tfc; |
393 | u_int16_tduration; | 407 | u_int16_tduration; |
394 | u_int8_tra[6]; | 408 | u_int8_tra[6]; |
395 | u_int8_tfcs[4]; | 409 | u_int8_tfcs[4]; |
396 | }; | 410 | }; |
397 | 411 | ||
398 | #define CTRL_CTS_LEN(2+2+6+4) | 412 | #define CTRL_CTS_LEN(2+2+6+4) |
399 | 413 | ||
400 | struct ctrl_ack_t { | 414 | struct ctrl_ack_t { |
401 | u_int16_tfc; | 415 | u_int16_tfc; |
402 | u_int16_tduration; | 416 | u_int16_tduration; |
403 | u_int8_tra[6]; | 417 | u_int8_tra[6]; |
404 | u_int8_tfcs[4]; | 418 | u_int8_tfcs[4]; |
405 | }; | 419 | }; |
406 | 420 | ||
407 | #define CTRL_ACK_LEN(2+2+6+4) | 421 | #define CTRL_ACK_LEN(2+2+6+4) |
408 | 422 | ||
409 | struct ctrl_ps_poll_t { | 423 | struct ctrl_ps_poll_t { |
410 | u_int16_tfc; | 424 | u_int16_tfc; |
411 | u_int16_taid; | 425 | u_int16_taid; |
412 | u_int8_tbssid[6]; | 426 | u_int8_tbssid[6]; |
413 | u_int8_tta[6]; | 427 | u_int8_tta[6]; |
414 | u_int8_tfcs[4]; | 428 | u_int8_tfcs[4]; |
415 | }; | 429 | }; |
416 | 430 | ||
417 | #define CTRL_PS_POLL_LEN(2+2+6+6+4) | 431 | #define CTRL_PS_POLL_LEN(2+2+6+6+4) |
418 | 432 | ||
419 | struct ctrl_end_t { | 433 | struct ctrl_end_t { |
420 | u_int16_tfc; | 434 | u_int16_tfc; |
421 | u_int16_tduration; | 435 | u_int16_tduration; |
422 | u_int8_tra[6]; | 436 | u_int8_tra[6]; |
423 | u_int8_tbssid[6]; | 437 | u_int8_tbssid[6]; |
424 | u_int8_tfcs[4]; | 438 | u_int8_tfcs[4]; |
425 | }; | 439 | }; |
426 | 440 | ||
427 | #define CTRL_END_LEN(2+2+6+6+4) | 441 | #define CTRL_END_LEN(2+2+6+6+4) |
428 | 442 | ||
429 | struct ctrl_end_ack_t { | 443 | struct ctrl_end_ack_t { |
430 | u_int16_tfc; | 444 | u_int16_tfc; |
431 | u_int16_tduration; | 445 | u_int16_tduration; |
432 | u_int8_tra[6]; | 446 | u_int8_tra[6]; |
433 | u_int8_tbssid[6]; | 447 | u_int8_tbssid[6]; |
434 | u_int8_tfcs[4]; | 448 | u_int8_tfcs[4]; |
435 | }; | 449 | }; |
436 | 450 | ||
437 | #define CTRL_END_ACK_LEN(2+2+6+6+4) | 451 | #define CTRL_END_ACK_LEN(2+2+6+6+4) |
438 | 452 | ||
439 | #define IV_IV(iv)((iv) & 0xFFFFFF) | 453 | #define IV_IV(iv)((iv) & 0xFFFFFF) |
440 | #define IV_PAD(iv)(((iv) >> 24) & 0x3F) | 454 | #define IV_PAD(iv)(((iv) >> 24) & 0x3F) |
441 | #define IV_KEYID(iv)(((iv) >> 30) & 0x03) | 455 | #define IV_KEYID(iv)(((iv) >> 30) & 0x03) |
442 | 456 | ||
443 | #endif | 457 | #endif |
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index be2736a..95e7043 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -142,815 +142,816 @@ bool ONetwork::isWirelessInterface( const char* name ) const | |||
142 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); | 142 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); |
143 | return result != -1; | 143 | return result != -1; |
144 | } | 144 | } |
145 | 145 | ||
146 | /*====================================================================================== | 146 | /*====================================================================================== |
147 | * ONetworkInterface | 147 | * ONetworkInterface |
148 | *======================================================================================*/ | 148 | *======================================================================================*/ |
149 | 149 | ||
150 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) | 150 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) |
151 | :QObject( parent, name ), | 151 | :QObject( parent, name ), |
152 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) | 152 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) |
153 | { | 153 | { |
154 | qDebug( "ONetworkInterface::ONetworkInterface()" ); | 154 | qDebug( "ONetworkInterface::ONetworkInterface()" ); |
155 | init(); | 155 | init(); |
156 | } | 156 | } |
157 | 157 | ||
158 | 158 | ||
159 | struct ifreq& ONetworkInterface::ifr() const | 159 | struct ifreq& ONetworkInterface::ifr() const |
160 | { | 160 | { |
161 | return _ifr; | 161 | return _ifr; |
162 | } | 162 | } |
163 | 163 | ||
164 | 164 | ||
165 | void ONetworkInterface::init() | 165 | void ONetworkInterface::init() |
166 | { | 166 | { |
167 | qDebug( "ONetworkInterface::init()" ); | 167 | qDebug( "ONetworkInterface::init()" ); |
168 | 168 | ||
169 | memset( &_ifr, 0, sizeof( struct ifreq ) ); | 169 | memset( &_ifr, 0, sizeof( struct ifreq ) ); |
170 | 170 | ||
171 | if ( _sfd == -1 ) | 171 | if ( _sfd == -1 ) |
172 | { | 172 | { |
173 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); | 173 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); |
174 | return; | 174 | return; |
175 | } | 175 | } |
176 | } | 176 | } |
177 | 177 | ||
178 | 178 | ||
179 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const | 179 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const |
180 | { | 180 | { |
181 | int result = ::ioctl( _sfd, call, &ifreq ); | 181 | int result = ::ioctl( _sfd, call, &ifreq ); |
182 | if ( result == -1 ) | 182 | if ( result == -1 ) |
183 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); | 183 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); |
184 | else | 184 | else |
185 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call ); | 185 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call ); |
186 | return ( result != -1 ); | 186 | return ( result != -1 ); |
187 | } | 187 | } |
188 | 188 | ||
189 | 189 | ||
190 | bool ONetworkInterface::ioctl( int call ) const | 190 | bool ONetworkInterface::ioctl( int call ) const |
191 | { | 191 | { |
192 | strcpy( _ifr.ifr_name, name() ); | 192 | strcpy( _ifr.ifr_name, name() ); |
193 | return ioctl( call, _ifr ); | 193 | return ioctl( call, _ifr ); |
194 | } | 194 | } |
195 | 195 | ||
196 | 196 | ||
197 | bool ONetworkInterface::isLoopback() const | 197 | bool ONetworkInterface::isLoopback() const |
198 | { | 198 | { |
199 | ioctl( SIOCGIFFLAGS ); | 199 | ioctl( SIOCGIFFLAGS ); |
200 | return _ifr.ifr_flags & IFF_LOOPBACK; | 200 | return _ifr.ifr_flags & IFF_LOOPBACK; |
201 | } | 201 | } |
202 | 202 | ||
203 | 203 | ||
204 | bool ONetworkInterface::setUp( bool b ) | 204 | bool ONetworkInterface::setUp( bool b ) |
205 | { | 205 | { |
206 | ioctl( SIOCGIFFLAGS ); | 206 | ioctl( SIOCGIFFLAGS ); |
207 | if ( b ) _ifr.ifr_flags |= IFF_UP; | 207 | if ( b ) _ifr.ifr_flags |= IFF_UP; |
208 | else _ifr.ifr_flags &= (~IFF_UP); | 208 | else _ifr.ifr_flags &= (~IFF_UP); |
209 | return ioctl( SIOCSIFFLAGS ); | 209 | return ioctl( SIOCSIFFLAGS ); |
210 | } | 210 | } |
211 | 211 | ||
212 | 212 | ||
213 | bool ONetworkInterface::isUp() const | 213 | bool ONetworkInterface::isUp() const |
214 | { | 214 | { |
215 | ioctl( SIOCGIFFLAGS ); | 215 | ioctl( SIOCGIFFLAGS ); |
216 | return _ifr.ifr_flags & IFF_UP; | 216 | return _ifr.ifr_flags & IFF_UP; |
217 | } | 217 | } |
218 | 218 | ||
219 | 219 | ||
220 | void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) | 220 | void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) |
221 | { | 221 | { |
222 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 222 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
223 | sa->sin_family = AF_INET; | 223 | sa->sin_family = AF_INET; |
224 | sa->sin_port = 0; | 224 | sa->sin_port = 0; |
225 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | 225 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); |
226 | ioctl( SIOCSIFADDR ); | 226 | ioctl( SIOCSIFADDR ); |
227 | } | 227 | } |
228 | 228 | ||
229 | 229 | ||
230 | QString ONetworkInterface::ipV4Address() const | 230 | QString ONetworkInterface::ipV4Address() const |
231 | { | 231 | { |
232 | if ( ioctl( SIOCGIFADDR ) ) | 232 | if ( ioctl( SIOCGIFADDR ) ) |
233 | { | 233 | { |
234 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 234 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
235 | //FIXME: Use QHostAddress here | 235 | //FIXME: Use QHostAddress here |
236 | return QString( inet_ntoa( sa->sin_addr ) ); | 236 | return QString( inet_ntoa( sa->sin_addr ) ); |
237 | } | 237 | } |
238 | else | 238 | else |
239 | return "<unknown>"; | 239 | return "<unknown>"; |
240 | } | 240 | } |
241 | 241 | ||
242 | 242 | ||
243 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) | 243 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) |
244 | { | 244 | { |
245 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; | 245 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; |
246 | memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); | 246 | memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); |
247 | ioctl( SIOCSIFHWADDR ); | 247 | ioctl( SIOCSIFHWADDR ); |
248 | } | 248 | } |
249 | 249 | ||
250 | 250 | ||
251 | OMacAddress ONetworkInterface::macAddress() const | 251 | OMacAddress ONetworkInterface::macAddress() const |
252 | { | 252 | { |
253 | if ( ioctl( SIOCGIFHWADDR ) ) | 253 | if ( ioctl( SIOCGIFHWADDR ) ) |
254 | { | 254 | { |
255 | return OMacAddress( _ifr ); | 255 | return OMacAddress( _ifr ); |
256 | } | 256 | } |
257 | else | 257 | else |
258 | { | 258 | { |
259 | return OMacAddress::unknown; | 259 | return OMacAddress::unknown; |
260 | } | 260 | } |
261 | } | 261 | } |
262 | 262 | ||
263 | 263 | ||
264 | void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) | 264 | void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) |
265 | { | 265 | { |
266 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 266 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
267 | sa->sin_family = AF_INET; | 267 | sa->sin_family = AF_INET; |
268 | sa->sin_port = 0; | 268 | sa->sin_port = 0; |
269 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | 269 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); |
270 | ioctl( SIOCSIFNETMASK ); | 270 | ioctl( SIOCSIFNETMASK ); |
271 | } | 271 | } |
272 | 272 | ||
273 | 273 | ||
274 | QString ONetworkInterface::ipV4Netmask() const | 274 | QString ONetworkInterface::ipV4Netmask() const |
275 | { | 275 | { |
276 | if ( ioctl( SIOCGIFNETMASK ) ) | 276 | if ( ioctl( SIOCGIFNETMASK ) ) |
277 | { | 277 | { |
278 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 278 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
279 | //FIXME: Use QHostAddress here | 279 | //FIXME: Use QHostAddress here |
280 | return QString( inet_ntoa( sa->sin_addr ) ); | 280 | return QString( inet_ntoa( sa->sin_addr ) ); |
281 | } | 281 | } |
282 | else | 282 | else |
283 | return "<unknown>"; | 283 | return "<unknown>"; |
284 | } | 284 | } |
285 | 285 | ||
286 | 286 | ||
287 | int ONetworkInterface::dataLinkType() const | 287 | int ONetworkInterface::dataLinkType() const |
288 | { | 288 | { |
289 | if ( ioctl( SIOCGIFHWADDR ) ) | 289 | if ( ioctl( SIOCGIFHWADDR ) ) |
290 | { | 290 | { |
291 | return _ifr.ifr_hwaddr.sa_family; | 291 | return _ifr.ifr_hwaddr.sa_family; |
292 | } | 292 | } |
293 | else | 293 | else |
294 | { | 294 | { |
295 | return -1; | 295 | return -1; |
296 | } | 296 | } |
297 | } | 297 | } |
298 | 298 | ||
299 | 299 | ||
300 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) | 300 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) |
301 | { | 301 | { |
302 | _mon = m; | 302 | _mon = m; |
303 | qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); | 303 | qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); |
304 | } | 304 | } |
305 | 305 | ||
306 | 306 | ||
307 | OMonitoringInterface* ONetworkInterface::monitoring() const | 307 | OMonitoringInterface* ONetworkInterface::monitoring() const |
308 | { | 308 | { |
309 | return _mon; | 309 | return _mon; |
310 | } | 310 | } |
311 | 311 | ||
312 | 312 | ||
313 | ONetworkInterface::~ONetworkInterface() | 313 | ONetworkInterface::~ONetworkInterface() |
314 | { | 314 | { |
315 | qDebug( "ONetworkInterface::~ONetworkInterface()" ); | 315 | qDebug( "ONetworkInterface::~ONetworkInterface()" ); |
316 | if ( _sfd != -1 ) ::close( _sfd ); | 316 | if ( _sfd != -1 ) ::close( _sfd ); |
317 | } | 317 | } |
318 | 318 | ||
319 | 319 | ||
320 | bool ONetworkInterface::setPromiscuousMode( bool b ) | 320 | bool ONetworkInterface::setPromiscuousMode( bool b ) |
321 | { | 321 | { |
322 | ioctl( SIOCGIFFLAGS ); | 322 | ioctl( SIOCGIFFLAGS ); |
323 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; | 323 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; |
324 | else _ifr.ifr_flags &= (~IFF_PROMISC); | 324 | else _ifr.ifr_flags &= (~IFF_PROMISC); |
325 | return ioctl( SIOCSIFFLAGS ); | 325 | return ioctl( SIOCSIFFLAGS ); |
326 | } | 326 | } |
327 | 327 | ||
328 | 328 | ||
329 | bool ONetworkInterface::promiscuousMode() const | 329 | bool ONetworkInterface::promiscuousMode() const |
330 | { | 330 | { |
331 | ioctl( SIOCGIFFLAGS ); | 331 | ioctl( SIOCGIFFLAGS ); |
332 | return _ifr.ifr_flags & IFF_PROMISC; | 332 | return _ifr.ifr_flags & IFF_PROMISC; |
333 | } | 333 | } |
334 | 334 | ||
335 | 335 | ||
336 | bool ONetworkInterface::isWireless() const | 336 | bool ONetworkInterface::isWireless() const |
337 | { | 337 | { |
338 | return ioctl( SIOCGIWNAME ); | 338 | return ioctl( SIOCGIWNAME ); |
339 | } | 339 | } |
340 | 340 | ||
341 | 341 | ||
342 | /*====================================================================================== | 342 | /*====================================================================================== |
343 | * OChannelHopper | 343 | * OChannelHopper |
344 | *======================================================================================*/ | 344 | *======================================================================================*/ |
345 | 345 | ||
346 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) | 346 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) |
347 | :QObject( 0, "Mickey's funky hopper" ), | 347 | :QObject( 0, "Mickey's funky hopper" ), |
348 | _iface( iface ), _interval( 0 ), _tid( 0 ) | 348 | _iface( iface ), _interval( 0 ), _tid( 0 ) |
349 | { | 349 | { |
350 | int _maxChannel = iface->channels()+1; | 350 | int _maxChannel = iface->channels()+1; |
351 | // generate fancy hopping sequence honoring the device capabilities | 351 | // generate fancy hopping sequence honoring the device capabilities |
352 | if ( _maxChannel >= 1 ) _channels.append( 1 ); | 352 | if ( _maxChannel >= 1 ) _channels.append( 1 ); |
353 | if ( _maxChannel >= 7 ) _channels.append( 7 ); | 353 | if ( _maxChannel >= 7 ) _channels.append( 7 ); |
354 | if ( _maxChannel >= 13 ) _channels.append( 13 ); | 354 | if ( _maxChannel >= 13 ) _channels.append( 13 ); |
355 | if ( _maxChannel >= 2 ) _channels.append( 2 ); | 355 | if ( _maxChannel >= 2 ) _channels.append( 2 ); |
356 | if ( _maxChannel >= 8 ) _channels.append( 8 ); | 356 | if ( _maxChannel >= 8 ) _channels.append( 8 ); |
357 | if ( _maxChannel >= 3 ) _channels.append( 3 ); | 357 | if ( _maxChannel >= 3 ) _channels.append( 3 ); |
358 | if ( _maxChannel >= 14 ) _channels.append( 14 ); | 358 | if ( _maxChannel >= 14 ) _channels.append( 14 ); |
359 | if ( _maxChannel >= 9 ) _channels.append( 9 ); | 359 | if ( _maxChannel >= 9 ) _channels.append( 9 ); |
360 | if ( _maxChannel >= 4 ) _channels.append( 4 ); | 360 | if ( _maxChannel >= 4 ) _channels.append( 4 ); |
361 | if ( _maxChannel >= 10 ) _channels.append( 10 ); | 361 | if ( _maxChannel >= 10 ) _channels.append( 10 ); |
362 | if ( _maxChannel >= 5 ) _channels.append( 5 ); | 362 | if ( _maxChannel >= 5 ) _channels.append( 5 ); |
363 | if ( _maxChannel >= 11 ) _channels.append( 11 ); | 363 | if ( _maxChannel >= 11 ) _channels.append( 11 ); |
364 | if ( _maxChannel >= 6 ) _channels.append( 6 ); | 364 | if ( _maxChannel >= 6 ) _channels.append( 6 ); |
365 | if ( _maxChannel >= 12 ) _channels.append( 12 ); | 365 | if ( _maxChannel >= 12 ) _channels.append( 12 ); |
366 | _channel = _channels.begin(); | 366 | _channel = _channels.begin(); |
367 | 367 | ||
368 | } | 368 | } |
369 | 369 | ||
370 | 370 | ||
371 | OChannelHopper::~OChannelHopper() | 371 | OChannelHopper::~OChannelHopper() |
372 | { | 372 | { |
373 | } | 373 | } |
374 | 374 | ||
375 | 375 | ||
376 | bool OChannelHopper::isActive() const | 376 | bool OChannelHopper::isActive() const |
377 | { | 377 | { |
378 | return _tid; | 378 | return _tid; |
379 | } | 379 | } |
380 | 380 | ||
381 | 381 | ||
382 | int OChannelHopper::channel() const | 382 | int OChannelHopper::channel() const |
383 | { | 383 | { |
384 | return *_channel; | 384 | return *_channel; |
385 | } | 385 | } |
386 | 386 | ||
387 | 387 | ||
388 | void OChannelHopper::timerEvent( QTimerEvent* ) | 388 | void OChannelHopper::timerEvent( QTimerEvent* ) |
389 | { | 389 | { |
390 | _iface->setChannel( *_channel ); | 390 | _iface->setChannel( *_channel ); |
391 | emit( hopped( *_channel ) ); | 391 | emit( hopped( *_channel ) ); |
392 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", | 392 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", |
393 | *_channel, (const char*) _iface->name() ); | 393 | *_channel, (const char*) _iface->name() ); |
394 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); | 394 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); |
395 | } | 395 | } |
396 | 396 | ||
397 | 397 | ||
398 | void OChannelHopper::setInterval( int interval ) | 398 | void OChannelHopper::setInterval( int interval ) |
399 | { | 399 | { |
400 | if ( interval == _interval ) | 400 | if ( interval == _interval ) |
401 | return; | 401 | return; |
402 | 402 | ||
403 | if ( _interval ) | 403 | if ( _interval ) |
404 | killTimer( _tid ); | 404 | killTimer( _tid ); |
405 | 405 | ||
406 | _tid = 0; | 406 | _tid = 0; |
407 | _interval = interval; | 407 | _interval = interval; |
408 | 408 | ||
409 | if ( _interval ) | 409 | if ( _interval ) |
410 | { | 410 | { |
411 | _tid = startTimer( interval ); | 411 | _tid = startTimer( interval ); |
412 | } | 412 | } |
413 | } | 413 | } |
414 | 414 | ||
415 | 415 | ||
416 | int OChannelHopper::interval() const | 416 | int OChannelHopper::interval() const |
417 | { | 417 | { |
418 | return _interval; | 418 | return _interval; |
419 | } | 419 | } |
420 | 420 | ||
421 | 421 | ||
422 | /*====================================================================================== | 422 | /*====================================================================================== |
423 | * OWirelessNetworkInterface | 423 | * OWirelessNetworkInterface |
424 | *======================================================================================*/ | 424 | *======================================================================================*/ |
425 | 425 | ||
426 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) | 426 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) |
427 | :ONetworkInterface( parent, name ), _hopper( 0 ) | 427 | :ONetworkInterface( parent, name ), _hopper( 0 ) |
428 | { | 428 | { |
429 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); | 429 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); |
430 | init(); | 430 | init(); |
431 | } | 431 | } |
432 | 432 | ||
433 | 433 | ||
434 | OWirelessNetworkInterface::~OWirelessNetworkInterface() | 434 | OWirelessNetworkInterface::~OWirelessNetworkInterface() |
435 | { | 435 | { |
436 | } | 436 | } |
437 | 437 | ||
438 | 438 | ||
439 | struct iwreq& OWirelessNetworkInterface::iwr() const | 439 | struct iwreq& OWirelessNetworkInterface::iwr() const |
440 | { | 440 | { |
441 | return _iwr; | 441 | return _iwr; |
442 | } | 442 | } |
443 | 443 | ||
444 | 444 | ||
445 | void OWirelessNetworkInterface::init() | 445 | void OWirelessNetworkInterface::init() |
446 | { | 446 | { |
447 | qDebug( "OWirelessNetworkInterface::init()" ); | 447 | qDebug( "OWirelessNetworkInterface::init()" ); |
448 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 448 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
449 | buildChannelList(); | 449 | buildChannelList(); |
450 | buildPrivateList(); | 450 | buildPrivateList(); |
451 | } | 451 | } |
452 | 452 | ||
453 | 453 | ||
454 | QString OWirelessNetworkInterface::associatedAP() const | 454 | QString OWirelessNetworkInterface::associatedAP() const |
455 | { | 455 | { |
456 | //FIXME: use OMacAddress | 456 | //FIXME: use OMacAddress |
457 | QString mac; | 457 | QString mac; |
458 | 458 | ||
459 | if ( ioctl( SIOCGIWAP ) ) | 459 | if ( ioctl( SIOCGIWAP ) ) |
460 | { | 460 | { |
461 | mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 461 | mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", |
462 | _ifr.ifr_hwaddr.sa_data[0]&0xff, | 462 | _ifr.ifr_hwaddr.sa_data[0]&0xff, |
463 | _ifr.ifr_hwaddr.sa_data[1]&0xff, | 463 | _ifr.ifr_hwaddr.sa_data[1]&0xff, |
464 | _ifr.ifr_hwaddr.sa_data[2]&0xff, | 464 | _ifr.ifr_hwaddr.sa_data[2]&0xff, |
465 | _ifr.ifr_hwaddr.sa_data[3]&0xff, | 465 | _ifr.ifr_hwaddr.sa_data[3]&0xff, |
466 | _ifr.ifr_hwaddr.sa_data[4]&0xff, | 466 | _ifr.ifr_hwaddr.sa_data[4]&0xff, |
467 | _ifr.ifr_hwaddr.sa_data[5]&0xff ); | 467 | _ifr.ifr_hwaddr.sa_data[5]&0xff ); |
468 | } | 468 | } |
469 | else | 469 | else |
470 | { | 470 | { |
471 | mac = "<Unknown>"; | 471 | mac = "<Unknown>"; |
472 | } | 472 | } |
473 | return mac; | 473 | return mac; |
474 | } | 474 | } |
475 | 475 | ||
476 | 476 | ||
477 | void OWirelessNetworkInterface::buildChannelList() | 477 | void OWirelessNetworkInterface::buildChannelList() |
478 | { | 478 | { |
479 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck | 479 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck |
480 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete | 480 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete |
481 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". | 481 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". |
482 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate | 482 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate |
483 | //ML: _too much_ space. This is damn shitty crap *sigh* | 483 | //ML: _too much_ space. This is damn shitty crap *sigh* |
484 | //ML: We allocate a large memory region in RAM and check whether the | 484 | //ML: We allocate a large memory region in RAM and check whether the |
485 | //ML: driver pollutes this extra space. The complaint will be made on stdout, | 485 | //ML: driver pollutes this extra space. The complaint will be made on stdout, |
486 | //ML: so please forward this... | 486 | //ML: so please forward this... |
487 | 487 | ||
488 | struct iwreq wrq; | 488 | struct iwreq wrq; |
489 | int len = sizeof( struct iw_range )*2; | 489 | int len = sizeof( struct iw_range )*2; |
490 | char *buffer = (char*) malloc( len ); | 490 | char *buffer = (char*) malloc( len ); |
491 | //FIXME: Validate if we actually got the memory block | 491 | //FIXME: Validate if we actually got the memory block |
492 | memset( buffer, 0, len ); | 492 | memset( buffer, 0, len ); |
493 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); | 493 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); |
494 | wrq.u.data.pointer = (caddr_t) buffer; | 494 | wrq.u.data.pointer = (caddr_t) buffer; |
495 | wrq.u.data.length = sizeof( struct iw_range ); | 495 | wrq.u.data.length = sizeof( struct iw_range ); |
496 | wrq.u.data.flags = 0; | 496 | wrq.u.data.flags = 0; |
497 | 497 | ||
498 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) | 498 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) |
499 | { | 499 | { |
500 | qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); | 500 | qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); |
501 | _channels.insert( 2412, 1 ); // 2.412 GHz | 501 | _channels.insert( 2412, 1 ); // 2.412 GHz |
502 | _channels.insert( 2417, 2 ); // 2.417 GHz | 502 | _channels.insert( 2417, 2 ); // 2.417 GHz |
503 | _channels.insert( 2422, 3 ); // 2.422 GHz | 503 | _channels.insert( 2422, 3 ); // 2.422 GHz |
504 | _channels.insert( 2427, 4 ); // 2.427 GHz | 504 | _channels.insert( 2427, 4 ); // 2.427 GHz |
505 | _channels.insert( 2432, 5 ); // 2.432 GHz | 505 | _channels.insert( 2432, 5 ); // 2.432 GHz |
506 | _channels.insert( 2437, 6 ); // 2.437 GHz | 506 | _channels.insert( 2437, 6 ); // 2.437 GHz |
507 | _channels.insert( 2442, 7 ); // 2.442 GHz | 507 | _channels.insert( 2442, 7 ); // 2.442 GHz |
508 | _channels.insert( 2447, 8 ); // 2.447 GHz | 508 | _channels.insert( 2447, 8 ); // 2.447 GHz |
509 | _channels.insert( 2452, 9 ); // 2.452 GHz | 509 | _channels.insert( 2452, 9 ); // 2.452 GHz |
510 | _channels.insert( 2457, 10 ); // 2.457 GHz | 510 | _channels.insert( 2457, 10 ); // 2.457 GHz |
511 | _channels.insert( 2462, 11 ); // 2.462 GHz | 511 | _channels.insert( 2462, 11 ); // 2.462 GHz |
512 | } | 512 | } |
513 | else | 513 | else |
514 | { | 514 | { |
515 | // <check if the driver overwrites stuff> | 515 | // <check if the driver overwrites stuff> |
516 | int max = 0; | 516 | int max = 0; |
517 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) | 517 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) |
518 | if (buffer[r] != 0) | 518 | if (buffer[r] != 0) |
519 | max = r; | 519 | max = r; |
520 | if (max > 0) | 520 | if (max > 0) |
521 | { | 521 | { |
522 | qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" | 522 | qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" |
523 | "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); | 523 | "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); |
524 | } | 524 | } |
525 | // </check if the driver overwrites stuff> | 525 | // </check if the driver overwrites stuff> |
526 | 526 | ||
527 | struct iw_range range; | 527 | struct iw_range range; |
528 | memcpy( &range, buffer, sizeof range ); | 528 | memcpy( &range, buffer, sizeof range ); |
529 | 529 | ||
530 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); | 530 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); |
531 | for ( int i = 0; i < range.num_frequency; ++i ) | 531 | for ( int i = 0; i < range.num_frequency; ++i ) |
532 | { | 532 | { |
533 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); | 533 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); |
534 | _channels.insert( freq, i+1 ); | 534 | _channels.insert( freq, i+1 ); |
535 | } | 535 | } |
536 | } | 536 | } |
537 | 537 | ||
538 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); | 538 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); |
539 | free(buffer); | 539 | free(buffer); |
540 | } | 540 | } |
541 | 541 | ||
542 | 542 | ||
543 | void OWirelessNetworkInterface::buildPrivateList() | 543 | void OWirelessNetworkInterface::buildPrivateList() |
544 | { | 544 | { |
545 | qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); | 545 | qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); |
546 | 546 | ||
547 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; | 547 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; |
548 | 548 | ||
549 | _iwr.u.data.pointer = (char*) &priv; | 549 | _iwr.u.data.pointer = (char*) &priv; |
550 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself | 550 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself |
551 | _iwr.u.data.flags = 0; | 551 | _iwr.u.data.flags = 0; |
552 | 552 | ||
553 | if ( !wioctl( SIOCGIWPRIV ) ) | 553 | if ( !wioctl( SIOCGIWPRIV ) ) |
554 | { | 554 | { |
555 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); | 555 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); |
556 | return; | 556 | return; |
557 | } | 557 | } |
558 | 558 | ||
559 | for ( int i = 0; i < _iwr.u.data.length; ++i ) | 559 | for ( int i = 0; i < _iwr.u.data.length; ++i ) |
560 | { | 560 | { |
561 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); | 561 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); |
562 | } | 562 | } |
563 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); | 563 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); |
564 | } | 564 | } |
565 | 565 | ||
566 | 566 | ||
567 | int OWirelessNetworkInterface::channel() const | 567 | int OWirelessNetworkInterface::channel() const |
568 | { | 568 | { |
569 | //FIXME: When monitoring enabled, then use it | 569 | //FIXME: When monitoring enabled, then use it |
570 | //FIXME: to gather the current RF channel | 570 | //FIXME: to gather the current RF channel |
571 | //FIXME: Until then, get active channel from hopper. | 571 | //FIXME: Until then, get active channel from hopper. |
572 | if ( _hopper && _hopper->isActive() ) | 572 | if ( _hopper && _hopper->isActive() ) |
573 | return _hopper->channel(); | 573 | return _hopper->channel(); |
574 | 574 | ||
575 | if ( !wioctl( SIOCGIWFREQ ) ) | 575 | if ( !wioctl( SIOCGIWFREQ ) ) |
576 | { | 576 | { |
577 | return -1; | 577 | return -1; |
578 | } | 578 | } |
579 | else | 579 | else |
580 | { | 580 | { |
581 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; | 581 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; |
582 | } | 582 | } |
583 | } | 583 | } |
584 | 584 | ||
585 | 585 | ||
586 | void OWirelessNetworkInterface::setChannel( int c ) const | 586 | void OWirelessNetworkInterface::setChannel( int c ) const |
587 | { | 587 | { |
588 | if ( !_mon ) | 588 | if ( !_mon ) |
589 | { | 589 | { |
590 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 590 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
591 | _iwr.u.freq.m = c; | 591 | _iwr.u.freq.m = c; |
592 | _iwr.u.freq.e = 0; | 592 | _iwr.u.freq.e = 0; |
593 | wioctl( SIOCSIWFREQ ); | 593 | wioctl( SIOCSIWFREQ ); |
594 | } | 594 | } |
595 | else | 595 | else |
596 | { | 596 | { |
597 | _mon->setChannel( c ); | 597 | _mon->setChannel( c ); |
598 | } | 598 | } |
599 | } | 599 | } |
600 | 600 | ||
601 | 601 | ||
602 | double OWirelessNetworkInterface::frequency() const | 602 | double OWirelessNetworkInterface::frequency() const |
603 | { | 603 | { |
604 | if ( !wioctl( SIOCGIWFREQ ) ) | 604 | if ( !wioctl( SIOCGIWFREQ ) ) |
605 | { | 605 | { |
606 | return -1.0; | 606 | return -1.0; |
607 | } | 607 | } |
608 | else | 608 | else |
609 | { | 609 | { |
610 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; | 610 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; |
611 | } | 611 | } |
612 | } | 612 | } |
613 | 613 | ||
614 | 614 | ||
615 | int OWirelessNetworkInterface::channels() const | 615 | int OWirelessNetworkInterface::channels() const |
616 | { | 616 | { |
617 | return _channels.count(); | 617 | return _channels.count(); |
618 | } | 618 | } |
619 | 619 | ||
620 | 620 | ||
621 | void OWirelessNetworkInterface::setChannelHopping( int interval ) | 621 | void OWirelessNetworkInterface::setChannelHopping( int interval ) |
622 | { | 622 | { |
623 | if ( !_hopper ) _hopper = new OChannelHopper( this ); | 623 | if ( !_hopper ) _hopper = new OChannelHopper( this ); |
624 | _hopper->setInterval( interval ); | 624 | _hopper->setInterval( interval ); |
625 | //FIXME: When and by whom will the channel hopper be deleted? | 625 | //FIXME: When and by whom will the channel hopper be deleted? |
626 | //TODO: rely on QObject hierarchy | 626 | //TODO: rely on QObject hierarchy |
627 | } | 627 | } |
628 | 628 | ||
629 | 629 | ||
630 | int OWirelessNetworkInterface::channelHopping() const | 630 | int OWirelessNetworkInterface::channelHopping() const |
631 | { | 631 | { |
632 | return _hopper->interval(); | 632 | return _hopper->interval(); |
633 | } | 633 | } |
634 | 634 | ||
635 | 635 | ||
636 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const | 636 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const |
637 | { | 637 | { |
638 | return _hopper; | 638 | return _hopper; |
639 | } | 639 | } |
640 | 640 | ||
641 | 641 | ||
642 | void OWirelessNetworkInterface::setMonitorMode( bool b ) | 642 | void OWirelessNetworkInterface::setMonitorMode( bool b ) |
643 | { | 643 | { |
644 | if ( _mon ) | 644 | if ( _mon ) |
645 | _mon->setEnabled( b ); | 645 | _mon->setEnabled( b ); |
646 | else | 646 | else |
647 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); | 647 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); |
648 | } | 648 | } |
649 | 649 | ||
650 | 650 | ||
651 | bool OWirelessNetworkInterface::monitorMode() const | 651 | bool OWirelessNetworkInterface::monitorMode() const |
652 | { | 652 | { |
653 | qDebug( "dataLinkType = %d", dataLinkType() ); | 653 | qDebug( "dataLinkType = %d", dataLinkType() ); |
654 | return dataLinkType() == ARPHRD_IEEE80211; | 654 | return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); |
655 | // 802 is the header type for PRISM - Linux support for this is pending... | ||
655 | } | 656 | } |
656 | 657 | ||
657 | 658 | ||
658 | QString OWirelessNetworkInterface::nickName() const | 659 | QString OWirelessNetworkInterface::nickName() const |
659 | { | 660 | { |
660 | char str[IW_ESSID_MAX_SIZE]; | 661 | char str[IW_ESSID_MAX_SIZE]; |
661 | _iwr.u.data.pointer = &str[0]; | 662 | _iwr.u.data.pointer = &str[0]; |
662 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; | 663 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; |
663 | if ( !wioctl( SIOCGIWNICKN ) ) | 664 | if ( !wioctl( SIOCGIWNICKN ) ) |
664 | { | 665 | { |
665 | return "<unknown>"; | 666 | return "<unknown>"; |
666 | } | 667 | } |
667 | else | 668 | else |
668 | { | 669 | { |
669 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string | 670 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string |
670 | return str; | 671 | return str; |
671 | } | 672 | } |
672 | } | 673 | } |
673 | 674 | ||
674 | 675 | ||
675 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) | 676 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) |
676 | { | 677 | { |
677 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); | 678 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); |
678 | if ( !priv ) | 679 | if ( !priv ) |
679 | { | 680 | { |
680 | qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); | 681 | qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); |
681 | return; | 682 | return; |
682 | } | 683 | } |
683 | if ( priv->numberSetArgs() != numargs ) | 684 | if ( priv->numberSetArgs() != numargs ) |
684 | { | 685 | { |
685 | qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); | 686 | qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); |
686 | return; | 687 | return; |
687 | } | 688 | } |
688 | 689 | ||
689 | qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); | 690 | qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); |
690 | memset( &_iwr, 0, sizeof _iwr ); | 691 | memset( &_iwr, 0, sizeof _iwr ); |
691 | va_list argp; | 692 | va_list argp; |
692 | va_start( argp, numargs ); | 693 | va_start( argp, numargs ); |
693 | for ( int i = 0; i < numargs; ++i ) | 694 | for ( int i = 0; i < numargs; ++i ) |
694 | { | 695 | { |
695 | priv->setParameter( i, va_arg( argp, int ) ); | 696 | priv->setParameter( i, va_arg( argp, int ) ); |
696 | } | 697 | } |
697 | va_end( argp ); | 698 | va_end( argp ); |
698 | priv->invoke(); | 699 | priv->invoke(); |
699 | } | 700 | } |
700 | 701 | ||
701 | 702 | ||
702 | void OWirelessNetworkInterface::getPrivate( const QString& call ) | 703 | void OWirelessNetworkInterface::getPrivate( const QString& call ) |
703 | { | 704 | { |
704 | qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); | 705 | qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); |
705 | } | 706 | } |
706 | 707 | ||
707 | 708 | ||
708 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) | 709 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) |
709 | { | 710 | { |
710 | return child( (const char*) call ); | 711 | return child( (const char*) call ); |
711 | } | 712 | } |
712 | 713 | ||
713 | 714 | ||
714 | QString OWirelessNetworkInterface::SSID() const | 715 | QString OWirelessNetworkInterface::SSID() const |
715 | { | 716 | { |
716 | char str[IW_ESSID_MAX_SIZE]; | 717 | char str[IW_ESSID_MAX_SIZE]; |
717 | _iwr.u.essid.pointer = &str[0]; | 718 | _iwr.u.essid.pointer = &str[0]; |
718 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; | 719 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; |
719 | if ( !wioctl( SIOCGIWESSID ) ) | 720 | if ( !wioctl( SIOCGIWESSID ) ) |
720 | { | 721 | { |
721 | return "<unknown>"; | 722 | return "<unknown>"; |
722 | } | 723 | } |
723 | else | 724 | else |
724 | { | 725 | { |
725 | return str; | 726 | return str; |
726 | } | 727 | } |
727 | } | 728 | } |
728 | 729 | ||
729 | 730 | ||
730 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) | 731 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) |
731 | { | 732 | { |
732 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); | 733 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); |
733 | _iwr.u.essid.length = ssid.length(); | 734 | _iwr.u.essid.length = ssid.length(); |
734 | wioctl( SIOCSIWESSID ); | 735 | wioctl( SIOCSIWESSID ); |
735 | } | 736 | } |
736 | 737 | ||
737 | 738 | ||
738 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const | 739 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const |
739 | { | 740 | { |
740 | int result = ::ioctl( _sfd, call, &iwreq ); | 741 | int result = ::ioctl( _sfd, call, &iwreq ); |
741 | if ( result == -1 ) | 742 | if ( result == -1 ) |
742 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); | 743 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); |
743 | else | 744 | else |
744 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call ); | 745 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call ); |
745 | return ( result != -1 ); | 746 | return ( result != -1 ); |
746 | } | 747 | } |
747 | 748 | ||
748 | 749 | ||
749 | bool OWirelessNetworkInterface::wioctl( int call ) const | 750 | bool OWirelessNetworkInterface::wioctl( int call ) const |
750 | { | 751 | { |
751 | strcpy( _iwr.ifr_name, name() ); | 752 | strcpy( _iwr.ifr_name, name() ); |
752 | return wioctl( call, _iwr ); | 753 | return wioctl( call, _iwr ); |
753 | } | 754 | } |
754 | 755 | ||
755 | 756 | ||
756 | /*====================================================================================== | 757 | /*====================================================================================== |
757 | * OMonitoringInterface | 758 | * OMonitoringInterface |
758 | *======================================================================================*/ | 759 | *======================================================================================*/ |
759 | 760 | ||
760 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) | 761 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) |
761 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ) | 762 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ) |
762 | { | 763 | { |
763 | } | 764 | } |
764 | 765 | ||
765 | 766 | ||
766 | OMonitoringInterface::~OMonitoringInterface() | 767 | OMonitoringInterface::~OMonitoringInterface() |
767 | { | 768 | { |
768 | } | 769 | } |
769 | 770 | ||
770 | 771 | ||
771 | void OMonitoringInterface::setChannel( int c ) | 772 | void OMonitoringInterface::setChannel( int c ) |
772 | { | 773 | { |
773 | // use standard WE channel switching protocol | 774 | // use standard WE channel switching protocol |
774 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); | 775 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); |
775 | _if->_iwr.u.freq.m = c; | 776 | _if->_iwr.u.freq.m = c; |
776 | _if->_iwr.u.freq.e = 0; | 777 | _if->_iwr.u.freq.e = 0; |
777 | _if->wioctl( SIOCSIWFREQ ); | 778 | _if->wioctl( SIOCSIWFREQ ); |
778 | } | 779 | } |
779 | 780 | ||
780 | 781 | ||
781 | bool OMonitoringInterface::enabled() const | 782 | bool OMonitoringInterface::enabled() const |
782 | { | 783 | { |
783 | return _if->monitorMode(); | 784 | return _if->monitorMode(); |
784 | } | 785 | } |
785 | 786 | ||
786 | 787 | ||
787 | void OMonitoringInterface::setEnabled( bool b ) | 788 | void OMonitoringInterface::setEnabled( bool b ) |
788 | { | 789 | { |
789 | } | 790 | } |
790 | 791 | ||
791 | 792 | ||
792 | /*====================================================================================== | 793 | /*====================================================================================== |
793 | * OCiscoMonitoringInterface | 794 | * OCiscoMonitoringInterface |
794 | *======================================================================================*/ | 795 | *======================================================================================*/ |
795 | 796 | ||
796 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface ) | 797 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface ) |
797 | :OMonitoringInterface( iface ) | 798 | :OMonitoringInterface( iface ) |
798 | { | 799 | { |
799 | iface->setMonitoring( this ); | 800 | iface->setMonitoring( this ); |
800 | } | 801 | } |
801 | 802 | ||
802 | 803 | ||
803 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() | 804 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() |
804 | { | 805 | { |
805 | } | 806 | } |
806 | 807 | ||
807 | 808 | ||
808 | void OCiscoMonitoringInterface::setEnabled( bool b ) | 809 | void OCiscoMonitoringInterface::setEnabled( bool b ) |
809 | { | 810 | { |
810 | QString fname; | 811 | QString fname; |
811 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); | 812 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); |
812 | QFile f( fname ); | 813 | QFile f( fname ); |
813 | if ( !f.exists() ) return; | 814 | if ( !f.exists() ) return; |
814 | 815 | ||
815 | if ( f.open( IO_WriteOnly ) ) | 816 | if ( f.open( IO_WriteOnly ) ) |
816 | { | 817 | { |
817 | QTextStream s( &f ); | 818 | QTextStream s( &f ); |
818 | s << "Mode: r"; | 819 | s << "Mode: r"; |
819 | s << "Mode: y"; | 820 | s << "Mode: y"; |
820 | s << "XmitPower: 1"; | 821 | s << "XmitPower: 1"; |
821 | } | 822 | } |
822 | 823 | ||
823 | // flushing and closing will be done automatically when f goes out of scope | 824 | // flushing and closing will be done automatically when f goes out of scope |
824 | } | 825 | } |
825 | 826 | ||
826 | 827 | ||
827 | QString OCiscoMonitoringInterface::name() const | 828 | QString OCiscoMonitoringInterface::name() const |
828 | { | 829 | { |
829 | return "cisco"; | 830 | return "cisco"; |
830 | } | 831 | } |
831 | 832 | ||
832 | 833 | ||
833 | void OCiscoMonitoringInterface::setChannel( int ) | 834 | void OCiscoMonitoringInterface::setChannel( int ) |
834 | { | 835 | { |
835 | // cisco devices automatically switch channels when in monitor mode | 836 | // cisco devices automatically switch channels when in monitor mode |
836 | } | 837 | } |
837 | 838 | ||
838 | 839 | ||
839 | /*====================================================================================== | 840 | /*====================================================================================== |
840 | * OWlanNGMonitoringInterface | 841 | * OWlanNGMonitoringInterface |
841 | *======================================================================================*/ | 842 | *======================================================================================*/ |
842 | 843 | ||
843 | 844 | ||
844 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface ) | 845 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface ) |
845 | :OMonitoringInterface( iface ) | 846 | :OMonitoringInterface( iface ) |
846 | { | 847 | { |
847 | iface->setMonitoring( this ); | 848 | iface->setMonitoring( this ); |
848 | } | 849 | } |
849 | 850 | ||
850 | 851 | ||
851 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() | 852 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() |
852 | { | 853 | { |
853 | } | 854 | } |
854 | 855 | ||
855 | 856 | ||
856 | void OWlanNGMonitoringInterface::setEnabled( bool b ) | 857 | void OWlanNGMonitoringInterface::setEnabled( bool b ) |
857 | { | 858 | { |
858 | //FIXME: do nothing if its already in the same mode | 859 | //FIXME: do nothing if its already in the same mode |
859 | 860 | ||
860 | QString enable = b ? "true" : "false"; | 861 | QString enable = b ? "true" : "false"; |
861 | QString cmd; | 862 | QString cmd; |
862 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable ); | 863 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable ); |
863 | system( cmd ); | 864 | system( cmd ); |
864 | } | 865 | } |
865 | 866 | ||
866 | 867 | ||
867 | QString OWlanNGMonitoringInterface::name() const | 868 | QString OWlanNGMonitoringInterface::name() const |
868 | { | 869 | { |
869 | return "wlan-ng"; | 870 | return "wlan-ng"; |
870 | } | 871 | } |
871 | 872 | ||
872 | 873 | ||
873 | void OWlanNGMonitoringInterface::setChannel( int ) | 874 | void OWlanNGMonitoringInterface::setChannel( int ) |
874 | { | 875 | { |
875 | // wlan-ng devices automatically switch channels when in monitor mode | 876 | // wlan-ng devices automatically switch channels when in monitor mode |
876 | } | 877 | } |
877 | 878 | ||
878 | 879 | ||
879 | /*====================================================================================== | 880 | /*====================================================================================== |
880 | * OHostAPMonitoringInterface | 881 | * OHostAPMonitoringInterface |
881 | *======================================================================================*/ | 882 | *======================================================================================*/ |
882 | 883 | ||
883 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface ) | 884 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface ) |
884 | :OMonitoringInterface( iface ) | 885 | :OMonitoringInterface( iface ) |
885 | { | 886 | { |
886 | iface->setMonitoring( this ); | 887 | iface->setMonitoring( this ); |
887 | } | 888 | } |
888 | 889 | ||
889 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() | 890 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() |
890 | { | 891 | { |
891 | } | 892 | } |
892 | 893 | ||
893 | void OHostAPMonitoringInterface::setEnabled( bool b ) | 894 | void OHostAPMonitoringInterface::setEnabled( bool b ) |
894 | { | 895 | { |
895 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 | 896 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 |
896 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring | 897 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring |
897 | 898 | ||
898 | //TODO: check wireless extensions version on runtime and use | 899 | //TODO: check wireless extensions version on runtime and use |
899 | //TODO: SIOCSIWMODE( IW_MODE_MONITOR ) if running on WE >= 15 | 900 | //TODO: SIOCSIWMODE( IW_MODE_MONITOR ) if running on WE >= 15 |
900 | 901 | ||
901 | if ( b ) | 902 | if ( b ) |
902 | { | 903 | { |
903 | _if->setPrivate( "monitor", 1, 2 ); | 904 | _if->setPrivate( "monitor", 1, 2 ); |
904 | } | 905 | } |
905 | else | 906 | else |
906 | { | 907 | { |
907 | _if->setPrivate( "monitor", 1, 0 ); | 908 | _if->setPrivate( "monitor", 1, 0 ); |
908 | } | 909 | } |
909 | } | 910 | } |
910 | 911 | ||
911 | 912 | ||
912 | QString OHostAPMonitoringInterface::name() const | 913 | QString OHostAPMonitoringInterface::name() const |
913 | { | 914 | { |
914 | return "hostap"; | 915 | return "hostap"; |
915 | } | 916 | } |
916 | 917 | ||
917 | 918 | ||
918 | /*====================================================================================== | 919 | /*====================================================================================== |
919 | * OOrinocoNetworkInterface | 920 | * OOrinocoNetworkInterface |
920 | *======================================================================================*/ | 921 | *======================================================================================*/ |
921 | 922 | ||
922 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface ) | 923 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface ) |
923 | :OMonitoringInterface( iface ) | 924 | :OMonitoringInterface( iface ) |
924 | { | 925 | { |
925 | iface->setMonitoring( this ); | 926 | iface->setMonitoring( this ); |
926 | } | 927 | } |
927 | 928 | ||
928 | 929 | ||
929 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() | 930 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() |
930 | { | 931 | { |
931 | } | 932 | } |
932 | 933 | ||
933 | 934 | ||
934 | void OOrinocoMonitoringInterface::setChannel( int c ) | 935 | void OOrinocoMonitoringInterface::setChannel( int c ) |
935 | { | 936 | { |
936 | _if->setPrivate( "monitor", 2, 2, c ); | 937 | _if->setPrivate( "monitor", 2, 1, c ); |
937 | } | 938 | } |
938 | 939 | ||
939 | 940 | ||
940 | void OOrinocoMonitoringInterface::setEnabled( bool b ) | 941 | void OOrinocoMonitoringInterface::setEnabled( bool b ) |
941 | { | 942 | { |
942 | if ( b ) | 943 | if ( b ) |
943 | { | 944 | { |
944 | setChannel( 1 ); | 945 | setChannel( 1 ); |
945 | } | 946 | } |
946 | else | 947 | else |
947 | { | 948 | { |
948 | _if->setPrivate( "monitor", 2, 0, 0 ); | 949 | _if->setPrivate( "monitor", 2, 0, 0 ); |
949 | } | 950 | } |
950 | } | 951 | } |
951 | 952 | ||
952 | 953 | ||
953 | QString OOrinocoMonitoringInterface::name() const | 954 | QString OOrinocoMonitoringInterface::name() const |
954 | { | 955 | { |
955 | return "orinoco"; | 956 | return "orinoco"; |
956 | } | 957 | } |
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index e362883..675818e 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -1,830 +1,861 @@ | |||
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 | #include <qobjectlist.h> | 42 | #include <qobjectlist.h> |
43 | 43 | ||
44 | /*====================================================================================== | 44 | /*====================================================================================== |
45 | * OPacket | 45 | * OPacket |
46 | *======================================================================================*/ | 46 | *======================================================================================*/ |
47 | 47 | ||
48 | OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) | 48 | OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) |
49 | :QObject( parent, "Generic" ), _hdr( header ), _data( data ) | 49 | :QObject( parent, "Generic" ), _hdr( header ), _data( data ) |
50 | { | 50 | { |
51 | //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); | 51 | //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); |
52 | 52 | ||
53 | _end = (unsigned char*) data + header.len; | 53 | _end = (unsigned char*) data + header.len; |
54 | //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); | 54 | //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); |
55 | 55 | ||
56 | switch ( datalink ) | 56 | switch ( datalink ) |
57 | { | 57 | { |
58 | case DLT_EN10MB: | 58 | case DLT_EN10MB: |
59 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); | 59 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); |
60 | new OEthernetPacket( _end, (const struct ether_header*) data, this ); | 60 | new OEthernetPacket( _end, (const struct ether_header*) data, this ); |
61 | break; | 61 | break; |
62 | 62 | ||
63 | case DLT_IEEE802_11: | 63 | case DLT_IEEE802_11: |
64 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); | 64 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); |
65 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); | 65 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); |
66 | break; | 66 | break; |
67 | 67 | ||
68 | case DLT_PRISM_HEADER: | ||
69 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" ); | ||
70 | new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this ); | ||
71 | break; | ||
72 | |||
68 | default: | 73 | default: |
69 | qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink '%s'!", datalink ); | 74 | qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink '%s'!", datalink ); |
70 | } | 75 | } |
71 | } | 76 | } |
72 | 77 | ||
73 | 78 | ||
74 | OPacket::~OPacket() | 79 | OPacket::~OPacket() |
75 | { | 80 | { |
76 | } | 81 | } |
77 | 82 | ||
78 | 83 | ||
79 | timevalstruct OPacket::timeval() const | 84 | timevalstruct OPacket::timeval() const |
80 | { | 85 | { |
81 | return _hdr.ts; | 86 | return _hdr.ts; |
82 | } | 87 | } |
83 | 88 | ||
84 | 89 | ||
85 | int OPacket::caplen() const | 90 | int OPacket::caplen() const |
86 | { | 91 | { |
87 | return _hdr.caplen; | 92 | return _hdr.caplen; |
88 | } | 93 | } |
89 | 94 | ||
90 | 95 | ||
91 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) | 96 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) |
92 | { | 97 | { |
93 | if (!l) return; | 98 | if (!l) return; |
94 | QObject* o = l->first(); | 99 | QObject* o = l->first(); |
95 | while ( o ) | 100 | while ( o ) |
96 | { | 101 | { |
97 | stats[o->name()]++; | 102 | stats[o->name()]++; |
98 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); | 103 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); |
99 | o = l->next(); | 104 | o = l->next(); |
100 | } | 105 | } |
101 | } | 106 | } |
102 | 107 | ||
103 | 108 | ||
104 | QString OPacket::dump( int bpl ) const | 109 | QString OPacket::dump( int bpl ) const |
105 | { | 110 | { |
106 | static int index = 0; | 111 | static int index = 0; |
107 | index++; | 112 | index++; |
108 | int len = _hdr.caplen; | 113 | int len = _hdr.caplen; |
109 | QString str; | 114 | QString str; |
110 | str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); | 115 | str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); |
111 | str.append( "0000: " ); | 116 | str.append( "0000: " ); |
112 | QString tmp; | 117 | QString tmp; |
113 | QString bytes; | 118 | QString bytes; |
114 | QString chars; | 119 | QString chars; |
115 | 120 | ||
116 | for ( int i = 0; i < len; ++i ) | 121 | for ( int i = 0; i < len; ++i ) |
117 | { | 122 | { |
118 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); | 123 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); |
119 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); | 124 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); |
120 | else chars.append( '.' ); | 125 | else chars.append( '.' ); |
121 | 126 | ||
122 | if ( !((i+1) % bpl) ) | 127 | if ( !((i+1) % bpl) ) |
123 | { | 128 | { |
124 | str.append( bytes ); | 129 | str.append( bytes ); |
125 | str.append( ' ' ); | 130 | str.append( ' ' ); |
126 | str.append( chars ); | 131 | str.append( chars ); |
127 | str.append( '\n' ); | 132 | str.append( '\n' ); |
128 | tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); | 133 | tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); |
129 | bytes = ""; | 134 | bytes = ""; |
130 | chars = ""; | 135 | chars = ""; |
131 | } | 136 | } |
132 | 137 | ||
133 | } | 138 | } |
134 | if ( (len % bpl) ) | 139 | if ( (len % bpl) ) |
135 | { | 140 | { |
136 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); | 141 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); |
137 | str.append( chars ); | 142 | str.append( chars ); |
138 | } | 143 | } |
139 | str.append( '\n' ); | 144 | str.append( '\n' ); |
140 | return str; | 145 | return str; |
141 | } | 146 | } |
142 | 147 | ||
143 | 148 | ||
144 | int OPacket::len() const | 149 | int OPacket::len() const |
145 | { | 150 | { |
146 | return _hdr.len; | 151 | return _hdr.len; |
147 | } | 152 | } |
148 | 153 | ||
149 | 154 | ||
150 | /*====================================================================================== | 155 | /*====================================================================================== |
151 | * OEthernetPacket | 156 | * OEthernetPacket |
152 | *======================================================================================*/ | 157 | *======================================================================================*/ |
153 | 158 | ||
154 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) | 159 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) |
155 | :QObject( parent, "Ethernet" ), _ether( data ) | 160 | :QObject( parent, "Ethernet" ), _ether( data ) |
156 | 161 | ||
157 | { | 162 | { |
158 | 163 | ||
159 | qDebug( "Source = %s", (const char*) sourceAddress().toString() ); | 164 | qDebug( "Source = %s", (const char*) sourceAddress().toString() ); |
160 | qDebug( "Destination = %s", (const char*) destinationAddress().toString() ); | 165 | qDebug( "Destination = %s", (const char*) destinationAddress().toString() ); |
161 | 166 | ||
162 | if ( sourceAddress() == OMacAddress::broadcast ) | 167 | if ( sourceAddress() == OMacAddress::broadcast ) |
163 | qDebug( "Source is broadcast address" ); | 168 | qDebug( "Source is broadcast address" ); |
164 | if ( destinationAddress() == OMacAddress::broadcast ) | 169 | if ( destinationAddress() == OMacAddress::broadcast ) |
165 | qDebug( "Destination is broadcast address" ); | 170 | qDebug( "Destination is broadcast address" ); |
166 | 171 | ||
167 | switch ( type() ) | 172 | switch ( type() ) |
168 | { | 173 | { |
169 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 174 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
170 | case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; } | 175 | case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; } |
171 | case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } | 176 | case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } |
172 | default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" ); | 177 | default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" ); |
173 | } | 178 | } |
174 | 179 | ||
175 | } | 180 | } |
176 | 181 | ||
177 | 182 | ||
178 | OEthernetPacket::~OEthernetPacket() | 183 | OEthernetPacket::~OEthernetPacket() |
179 | { | 184 | { |
180 | } | 185 | } |
181 | 186 | ||
182 | 187 | ||
183 | OMacAddress OEthernetPacket::sourceAddress() const | 188 | OMacAddress OEthernetPacket::sourceAddress() const |
184 | { | 189 | { |
185 | return OMacAddress( _ether->ether_shost ); | 190 | return OMacAddress( _ether->ether_shost ); |
186 | } | 191 | } |
187 | 192 | ||
188 | 193 | ||
189 | OMacAddress OEthernetPacket::destinationAddress() const | 194 | OMacAddress OEthernetPacket::destinationAddress() const |
190 | { | 195 | { |
191 | return OMacAddress( _ether->ether_dhost ); | 196 | return OMacAddress( _ether->ether_dhost ); |
192 | } | 197 | } |
193 | 198 | ||
194 | int OEthernetPacket::type() const | 199 | int OEthernetPacket::type() const |
195 | { | 200 | { |
196 | return ntohs( _ether->ether_type ); | 201 | return ntohs( _ether->ether_type ); |
197 | } | 202 | } |
198 | 203 | ||
199 | 204 | ||
200 | /*====================================================================================== | 205 | /*====================================================================================== |
201 | * OIPPacket | 206 | * OIPPacket |
202 | *======================================================================================*/ | 207 | *======================================================================================*/ |
203 | 208 | ||
204 | 209 | ||
205 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) | 210 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) |
206 | :QObject( parent, "IP" ), _iphdr( data ) | 211 | :QObject( parent, "IP" ), _iphdr( data ) |
207 | 212 | ||
208 | { | 213 | { |
209 | qDebug( "OIPPacket::OIPPacket(): decoding IP header..." ); | 214 | qDebug( "OIPPacket::OIPPacket(): decoding IP header..." ); |
210 | 215 | ||
211 | //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) ); | 216 | //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) ); |
212 | //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) ); | 217 | //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) ); |
213 | 218 | ||
214 | qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() ); | 219 | qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() ); |
215 | qDebug( " toAddress: %s", (const char*) toIPAddress().toString() ); | 220 | qDebug( " toAddress: %s", (const char*) toIPAddress().toString() ); |
216 | 221 | ||
217 | switch ( protocol() ) | 222 | switch ( protocol() ) |
218 | { | 223 | { |
219 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; | 224 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; |
220 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; | 225 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; |
221 | default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() ); | 226 | default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() ); |
222 | } | 227 | } |
223 | 228 | ||
224 | } | 229 | } |
225 | 230 | ||
226 | OIPPacket::~OIPPacket() | 231 | OIPPacket::~OIPPacket() |
227 | { | 232 | { |
228 | } | 233 | } |
229 | 234 | ||
230 | 235 | ||
231 | QHostAddress OIPPacket::fromIPAddress() const | 236 | QHostAddress OIPPacket::fromIPAddress() const |
232 | { | 237 | { |
233 | return EXTRACT_32BITS( &_iphdr->saddr ); | 238 | return EXTRACT_32BITS( &_iphdr->saddr ); |
234 | } | 239 | } |
235 | 240 | ||
236 | 241 | ||
237 | QHostAddress OIPPacket::toIPAddress() const | 242 | QHostAddress OIPPacket::toIPAddress() const |
238 | { | 243 | { |
239 | return EXTRACT_32BITS( &_iphdr->saddr ); | 244 | return EXTRACT_32BITS( &_iphdr->saddr ); |
240 | } | 245 | } |
241 | 246 | ||
242 | 247 | ||
243 | int OIPPacket::tos() const | 248 | int OIPPacket::tos() const |
244 | { | 249 | { |
245 | return _iphdr->tos; | 250 | return _iphdr->tos; |
246 | } | 251 | } |
247 | 252 | ||
248 | 253 | ||
249 | int OIPPacket::len() const | 254 | int OIPPacket::len() const |
250 | { | 255 | { |
251 | return EXTRACT_16BITS( &_iphdr->tot_len ); | 256 | return EXTRACT_16BITS( &_iphdr->tot_len ); |
252 | } | 257 | } |
253 | 258 | ||
254 | 259 | ||
255 | int OIPPacket::id() const | 260 | int OIPPacket::id() const |
256 | { | 261 | { |
257 | return EXTRACT_16BITS( &_iphdr->id ); | 262 | return EXTRACT_16BITS( &_iphdr->id ); |
258 | } | 263 | } |
259 | 264 | ||
260 | 265 | ||
261 | int OIPPacket::offset() const | 266 | int OIPPacket::offset() const |
262 | { | 267 | { |
263 | return EXTRACT_16BITS( &_iphdr->frag_off ); | 268 | return EXTRACT_16BITS( &_iphdr->frag_off ); |
264 | } | 269 | } |
265 | 270 | ||
266 | 271 | ||
267 | int OIPPacket::ttl() const | 272 | int OIPPacket::ttl() const |
268 | { | 273 | { |
269 | return _iphdr->ttl; | 274 | return _iphdr->ttl; |
270 | } | 275 | } |
271 | 276 | ||
272 | 277 | ||
273 | int OIPPacket::protocol() const | 278 | int OIPPacket::protocol() const |
274 | { | 279 | { |
275 | return _iphdr->protocol; | 280 | return _iphdr->protocol; |
276 | } | 281 | } |
277 | 282 | ||
278 | 283 | ||
279 | int OIPPacket::checksum() const | 284 | int OIPPacket::checksum() const |
280 | { | 285 | { |
281 | return EXTRACT_16BITS( &_iphdr->check ); | 286 | return EXTRACT_16BITS( &_iphdr->check ); |
282 | } | 287 | } |
283 | 288 | ||
284 | /*====================================================================================== | 289 | /*====================================================================================== |
285 | * OUDPPacket | 290 | * OUDPPacket |
286 | *======================================================================================*/ | 291 | *======================================================================================*/ |
287 | 292 | ||
288 | 293 | ||
289 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) | 294 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) |
290 | :QObject( parent, "UDP" ), _udphdr( data ) | 295 | :QObject( parent, "UDP" ), _udphdr( data ) |
291 | 296 | ||
292 | { | 297 | { |
293 | qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." ); | 298 | qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." ); |
294 | } | 299 | } |
295 | 300 | ||
296 | OUDPPacket::~OUDPPacket() | 301 | OUDPPacket::~OUDPPacket() |
297 | { | 302 | { |
298 | } | 303 | } |
299 | 304 | ||
300 | 305 | ||
301 | /*====================================================================================== | 306 | /*====================================================================================== |
302 | * OTCPPacket | 307 | * OTCPPacket |
303 | *======================================================================================*/ | 308 | *======================================================================================*/ |
304 | 309 | ||
305 | 310 | ||
306 | OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) | 311 | OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) |
307 | :QObject( parent, "TCP" ), _tcphdr( data ) | 312 | :QObject( parent, "TCP" ), _tcphdr( data ) |
308 | 313 | ||
309 | { | 314 | { |
310 | qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." ); | 315 | qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." ); |
311 | } | 316 | } |
312 | 317 | ||
313 | OTCPPacket::~OTCPPacket() | 318 | OTCPPacket::~OTCPPacket() |
314 | { | 319 | { |
315 | } | 320 | } |
316 | 321 | ||
317 | 322 | ||
318 | /*====================================================================================== | 323 | /*====================================================================================== |
324 | * OPrismHeaderPacket | ||
325 | *======================================================================================*/ | ||
326 | |||
327 | |||
328 | OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) | ||
329 | :QObject( parent, "Prism" ), _header( data ) | ||
330 | |||
331 | { | ||
332 | qDebug( "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." ); | ||
333 | |||
334 | qDebug( "Signal Strength = %d", data->signal.data ); | ||
335 | |||
336 | new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); | ||
337 | } | ||
338 | |||
339 | OPrismHeaderPacket::~OPrismHeaderPacket() | ||
340 | { | ||
341 | } | ||
342 | |||
343 | |||
344 | unsigned int OPrismHeaderPacket::signalStrength() const | ||
345 | { | ||
346 | return _header->signal.data; | ||
347 | } | ||
348 | |||
349 | /*====================================================================================== | ||
319 | * OWaveLanPacket | 350 | * OWaveLanPacket |
320 | *======================================================================================*/ | 351 | *======================================================================================*/ |
321 | 352 | ||
322 | 353 | ||
323 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) | 354 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) |
324 | :QObject( parent, "802.11" ), _wlanhdr( data ) | 355 | :QObject( parent, "802.11" ), _wlanhdr( data ) |
325 | 356 | ||
326 | { | 357 | { |
327 | qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." ); | 358 | qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." ); |
328 | qDebug( "type: %0X", type() ); | 359 | qDebug( "type: %0X", type() ); |
329 | qDebug( "subType: %0X", subType() ); | 360 | qDebug( "subType: %0X", subType() ); |
330 | qDebug( "duration: %d", duration() ); | 361 | qDebug( "duration: %d", duration() ); |
331 | qDebug( "powermanagement: %d", usesPowerManagement() ); | 362 | qDebug( "powermanagement: %d", usesPowerManagement() ); |
332 | qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" ); | 363 | qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" ); |
333 | qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); | 364 | qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); |
334 | qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); | 365 | qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); |
335 | qDebug( "MAC3: %s", (const char*) macAddress3().toString() ); | 366 | qDebug( "MAC3: %s", (const char*) macAddress3().toString() ); |
336 | qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); | 367 | qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); |
337 | 368 | ||
338 | switch ( type() ) | 369 | switch ( type() ) |
339 | { | 370 | { |
340 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; | 371 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; |
341 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; | 372 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; |
342 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; | 373 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; |
343 | default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() ); | 374 | default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() ); |
344 | } | 375 | } |
345 | } | 376 | } |
346 | 377 | ||
347 | OWaveLanPacket::~OWaveLanPacket() | 378 | OWaveLanPacket::~OWaveLanPacket() |
348 | { | 379 | { |
349 | } | 380 | } |
350 | 381 | ||
351 | 382 | ||
352 | int OWaveLanPacket::duration() const | 383 | int OWaveLanPacket::duration() const |
353 | { | 384 | { |
354 | return _wlanhdr->duration; | 385 | return _wlanhdr->duration; |
355 | } | 386 | } |
356 | 387 | ||
357 | 388 | ||
358 | OMacAddress OWaveLanPacket::macAddress1() const | 389 | OMacAddress OWaveLanPacket::macAddress1() const |
359 | { | 390 | { |
360 | return OMacAddress( _wlanhdr->mac1 ); | 391 | return OMacAddress( _wlanhdr->mac1 ); |
361 | } | 392 | } |
362 | 393 | ||
363 | 394 | ||
364 | OMacAddress OWaveLanPacket::macAddress2() const | 395 | OMacAddress OWaveLanPacket::macAddress2() const |
365 | { | 396 | { |
366 | return OMacAddress( _wlanhdr->mac2 ); | 397 | return OMacAddress( _wlanhdr->mac2 ); |
367 | } | 398 | } |
368 | 399 | ||
369 | 400 | ||
370 | OMacAddress OWaveLanPacket::macAddress3() const | 401 | OMacAddress OWaveLanPacket::macAddress3() const |
371 | { | 402 | { |
372 | return OMacAddress( _wlanhdr->mac3 ); | 403 | return OMacAddress( _wlanhdr->mac3 ); |
373 | } | 404 | } |
374 | 405 | ||
375 | 406 | ||
376 | OMacAddress OWaveLanPacket::macAddress4() const | 407 | OMacAddress OWaveLanPacket::macAddress4() const |
377 | { | 408 | { |
378 | return OMacAddress( _wlanhdr->mac4 ); | 409 | return OMacAddress( _wlanhdr->mac4 ); |
379 | } | 410 | } |
380 | 411 | ||
381 | 412 | ||
382 | int OWaveLanPacket::subType() const | 413 | int OWaveLanPacket::subType() const |
383 | { | 414 | { |
384 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 415 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
385 | } | 416 | } |
386 | 417 | ||
387 | 418 | ||
388 | int OWaveLanPacket::type() const | 419 | int OWaveLanPacket::type() const |
389 | { | 420 | { |
390 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 421 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
391 | } | 422 | } |
392 | 423 | ||
393 | 424 | ||
394 | int OWaveLanPacket::version() const | 425 | int OWaveLanPacket::version() const |
395 | { | 426 | { |
396 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 427 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
397 | } | 428 | } |
398 | 429 | ||
399 | 430 | ||
400 | bool OWaveLanPacket::fromDS() const | 431 | bool OWaveLanPacket::fromDS() const |
401 | { | 432 | { |
402 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 433 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
403 | } | 434 | } |
404 | 435 | ||
405 | 436 | ||
406 | bool OWaveLanPacket::toDS() const | 437 | bool OWaveLanPacket::toDS() const |
407 | { | 438 | { |
408 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 439 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
409 | } | 440 | } |
410 | 441 | ||
411 | 442 | ||
412 | bool OWaveLanPacket::usesPowerManagement() const | 443 | bool OWaveLanPacket::usesPowerManagement() const |
413 | { | 444 | { |
414 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 445 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
415 | } | 446 | } |
416 | 447 | ||
417 | 448 | ||
418 | bool OWaveLanPacket::usesWep() const | 449 | bool OWaveLanPacket::usesWep() const |
419 | { | 450 | { |
420 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 451 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
421 | } | 452 | } |
422 | 453 | ||
423 | 454 | ||
424 | /*====================================================================================== | 455 | /*====================================================================================== |
425 | * OWaveLanManagementPacket | 456 | * OWaveLanManagementPacket |
426 | *======================================================================================*/ | 457 | *======================================================================================*/ |
427 | 458 | ||
428 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) | 459 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) |
429 | :QObject( parent, "802.11 Management" ), _header( data ), | 460 | :QObject( parent, "802.11 Management" ), _header( data ), |
430 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) | 461 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) |
431 | { | 462 | { |
432 | qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); | 463 | qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); |
433 | qDebug( "Detected subtype is '%s'", (const char*) managementType() ); | 464 | qDebug( "Detected subtype is '%s'", (const char*) managementType() ); |
434 | 465 | ||
435 | // grab tagged values | 466 | // grab tagged values |
436 | const unsigned char* ptr = (const unsigned char*) (_body+1); | 467 | const unsigned char* ptr = (const unsigned char*) (_body+1); |
437 | while (ptr < end) | 468 | while (ptr < end) |
438 | { | 469 | { |
439 | switch ( *ptr ) | 470 | switch ( *ptr ) |
440 | { | 471 | { |
441 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; | 472 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; |
442 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; | 473 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; |
443 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; | 474 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; |
444 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; | 475 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; |
445 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; | 476 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; |
446 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; | 477 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; |
447 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; | 478 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; |
448 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; | 479 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; |
449 | } | 480 | } |
450 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value | 481 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value |
451 | ptr+= 2; // skip tag ID and length | 482 | ptr+= 2; // skip tag ID and length |
452 | } | 483 | } |
453 | } | 484 | } |
454 | 485 | ||
455 | 486 | ||
456 | OWaveLanManagementPacket::~OWaveLanManagementPacket() | 487 | OWaveLanManagementPacket::~OWaveLanManagementPacket() |
457 | { | 488 | { |
458 | } | 489 | } |
459 | 490 | ||
460 | 491 | ||
461 | QString OWaveLanManagementPacket::managementType() const | 492 | QString OWaveLanManagementPacket::managementType() const |
462 | { | 493 | { |
463 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) | 494 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) |
464 | { | 495 | { |
465 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; | 496 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; |
466 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; | 497 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; |
467 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; | 498 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; |
468 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; | 499 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; |
469 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; | 500 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; |
470 | case ST_PROBE_RESPONSE: return "ProbeResponse"; break; | 501 | case ST_PROBE_RESPONSE: return "ProbeResponse"; break; |
471 | case ST_BEACON: return "Beacon"; break; | 502 | case ST_BEACON: return "Beacon"; break; |
472 | case ST_ATIM: return "Atim"; break; | 503 | case ST_ATIM: return "Atim"; break; |
473 | case ST_DISASSOC: return "Disassociation"; break; | 504 | case ST_DISASSOC: return "Disassociation"; break; |
474 | case ST_AUTH: return "Authentication"; break; | 505 | case ST_AUTH: return "Authentication"; break; |
475 | case ST_DEAUTH: return "Deathentication"; break; | 506 | case ST_DEAUTH: return "Deathentication"; break; |
476 | default: | 507 | default: |
477 | qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ); | 508 | qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ); |
478 | return "Unknown"; | 509 | return "Unknown"; |
479 | } | 510 | } |
480 | } | 511 | } |
481 | 512 | ||
482 | 513 | ||
483 | int OWaveLanManagementPacket::beaconInterval() const | 514 | int OWaveLanManagementPacket::beaconInterval() const |
484 | { | 515 | { |
485 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); | 516 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); |
486 | } | 517 | } |
487 | 518 | ||
488 | 519 | ||
489 | int OWaveLanManagementPacket::capabilities() const | 520 | int OWaveLanManagementPacket::capabilities() const |
490 | { | 521 | { |
491 | return EXTRACT_LE_16BITS( &_body->capability_info ); | 522 | return EXTRACT_LE_16BITS( &_body->capability_info ); |
492 | } | 523 | } |
493 | 524 | ||
494 | 525 | ||
495 | bool OWaveLanManagementPacket::canESS() const | 526 | bool OWaveLanManagementPacket::canESS() const |
496 | { | 527 | { |
497 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 528 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
498 | } | 529 | } |
499 | 530 | ||
500 | 531 | ||
501 | bool OWaveLanManagementPacket::canIBSS() const | 532 | bool OWaveLanManagementPacket::canIBSS() const |
502 | { | 533 | { |
503 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 534 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
504 | } | 535 | } |
505 | 536 | ||
506 | 537 | ||
507 | bool OWaveLanManagementPacket::canCFP() const | 538 | bool OWaveLanManagementPacket::canCFP() const |
508 | { | 539 | { |
509 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 540 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
510 | } | 541 | } |
511 | 542 | ||
512 | 543 | ||
513 | bool OWaveLanManagementPacket::canCFP_REQ() const | 544 | bool OWaveLanManagementPacket::canCFP_REQ() const |
514 | { | 545 | { |
515 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 546 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
516 | } | 547 | } |
517 | 548 | ||
518 | 549 | ||
519 | bool OWaveLanManagementPacket::canPrivacy() const | 550 | bool OWaveLanManagementPacket::canPrivacy() const |
520 | { | 551 | { |
521 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 552 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
522 | } | 553 | } |
523 | 554 | ||
524 | 555 | ||
525 | /*====================================================================================== | 556 | /*====================================================================================== |
526 | * OWaveLanManagementSSID | 557 | * OWaveLanManagementSSID |
527 | *======================================================================================*/ | 558 | *======================================================================================*/ |
528 | 559 | ||
529 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) | 560 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) |
530 | :QObject( parent, "802.11 SSID" ), _data( data ) | 561 | :QObject( parent, "802.11 SSID" ), _data( data ) |
531 | { | 562 | { |
532 | qDebug( "OWaveLanManagementSSID()" ); | 563 | qDebug( "OWaveLanManagementSSID()" ); |
533 | } | 564 | } |
534 | 565 | ||
535 | 566 | ||
536 | OWaveLanManagementSSID::~OWaveLanManagementSSID() | 567 | OWaveLanManagementSSID::~OWaveLanManagementSSID() |
537 | { | 568 | { |
538 | } | 569 | } |
539 | 570 | ||
540 | 571 | ||
541 | QString OWaveLanManagementSSID::ID() const | 572 | QString OWaveLanManagementSSID::ID() const |
542 | { | 573 | { |
543 | int length = _data->length; | 574 | int length = _data->length; |
544 | if ( length > 32 ) length = 32; | 575 | if ( length > 32 ) length = 32; |
545 | char essid[length+1]; | 576 | char essid[length+1]; |
546 | memcpy( &essid, &_data->ssid, length ); | 577 | memcpy( &essid, &_data->ssid, length ); |
547 | essid[length] = 0x0; | 578 | essid[length] = 0x0; |
548 | return essid; | 579 | return essid; |
549 | } | 580 | } |
550 | 581 | ||
551 | 582 | ||
552 | /*====================================================================================== | 583 | /*====================================================================================== |
553 | * OWaveLanManagementRates | 584 | * OWaveLanManagementRates |
554 | *======================================================================================*/ | 585 | *======================================================================================*/ |
555 | 586 | ||
556 | OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) | 587 | OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) |
557 | :QObject( parent, "802.11 Rates" ), _data( data ) | 588 | :QObject( parent, "802.11 Rates" ), _data( data ) |
558 | { | 589 | { |
559 | qDebug( "OWaveLanManagementRates()" ); | 590 | qDebug( "OWaveLanManagementRates()" ); |
560 | } | 591 | } |
561 | 592 | ||
562 | 593 | ||
563 | OWaveLanManagementRates::~OWaveLanManagementRates() | 594 | OWaveLanManagementRates::~OWaveLanManagementRates() |
564 | { | 595 | { |
565 | } | 596 | } |
566 | 597 | ||
567 | /*====================================================================================== | 598 | /*====================================================================================== |
568 | * OWaveLanManagementCF | 599 | * OWaveLanManagementCF |
569 | *======================================================================================*/ | 600 | *======================================================================================*/ |
570 | 601 | ||
571 | OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) | 602 | OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) |
572 | :QObject( parent, "802.11 CF" ), _data( data ) | 603 | :QObject( parent, "802.11 CF" ), _data( data ) |
573 | { | 604 | { |
574 | qDebug( "OWaveLanManagementCF()" ); | 605 | qDebug( "OWaveLanManagementCF()" ); |
575 | } | 606 | } |
576 | 607 | ||
577 | 608 | ||
578 | OWaveLanManagementCF::~OWaveLanManagementCF() | 609 | OWaveLanManagementCF::~OWaveLanManagementCF() |
579 | { | 610 | { |
580 | } | 611 | } |
581 | 612 | ||
582 | /*====================================================================================== | 613 | /*====================================================================================== |
583 | * OWaveLanManagementFH | 614 | * OWaveLanManagementFH |
584 | *======================================================================================*/ | 615 | *======================================================================================*/ |
585 | 616 | ||
586 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) | 617 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) |
587 | :QObject( parent, "802.11 FH" ), _data( data ) | 618 | :QObject( parent, "802.11 FH" ), _data( data ) |
588 | { | 619 | { |
589 | qDebug( "OWaveLanManagementFH()" ); | 620 | qDebug( "OWaveLanManagementFH()" ); |
590 | } | 621 | } |
591 | 622 | ||
592 | 623 | ||
593 | OWaveLanManagementFH::~OWaveLanManagementFH() | 624 | OWaveLanManagementFH::~OWaveLanManagementFH() |
594 | { | 625 | { |
595 | } | 626 | } |
596 | 627 | ||
597 | /*====================================================================================== | 628 | /*====================================================================================== |
598 | * OWaveLanManagementDS | 629 | * OWaveLanManagementDS |
599 | *======================================================================================*/ | 630 | *======================================================================================*/ |
600 | 631 | ||
601 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) | 632 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) |
602 | :QObject( parent, "802.11 DS" ), _data( data ) | 633 | :QObject( parent, "802.11 DS" ), _data( data ) |
603 | { | 634 | { |
604 | qDebug( "OWaveLanManagementDS()" ); | 635 | qDebug( "OWaveLanManagementDS()" ); |
605 | } | 636 | } |
606 | 637 | ||
607 | 638 | ||
608 | OWaveLanManagementDS::~OWaveLanManagementDS() | 639 | OWaveLanManagementDS::~OWaveLanManagementDS() |
609 | { | 640 | { |
610 | } | 641 | } |
611 | 642 | ||
612 | 643 | ||
613 | int OWaveLanManagementDS::channel() const | 644 | int OWaveLanManagementDS::channel() const |
614 | { | 645 | { |
615 | return _data->channel; | 646 | return _data->channel; |
616 | } | 647 | } |
617 | 648 | ||
618 | /*====================================================================================== | 649 | /*====================================================================================== |
619 | * OWaveLanManagementTim | 650 | * OWaveLanManagementTim |
620 | *======================================================================================*/ | 651 | *======================================================================================*/ |
621 | 652 | ||
622 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) | 653 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) |
623 | :QObject( parent, "802.11 Tim" ), _data( data ) | 654 | :QObject( parent, "802.11 Tim" ), _data( data ) |
624 | { | 655 | { |
625 | qDebug( "OWaveLanManagementTim()" ); | 656 | qDebug( "OWaveLanManagementTim()" ); |
626 | } | 657 | } |
627 | 658 | ||
628 | 659 | ||
629 | OWaveLanManagementTim::~OWaveLanManagementTim() | 660 | OWaveLanManagementTim::~OWaveLanManagementTim() |
630 | { | 661 | { |
631 | } | 662 | } |
632 | 663 | ||
633 | /*====================================================================================== | 664 | /*====================================================================================== |
634 | * OWaveLanManagementIBSS | 665 | * OWaveLanManagementIBSS |
635 | *======================================================================================*/ | 666 | *======================================================================================*/ |
636 | 667 | ||
637 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) | 668 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) |
638 | :QObject( parent, "802.11 IBSS" ), _data( data ) | 669 | :QObject( parent, "802.11 IBSS" ), _data( data ) |
639 | { | 670 | { |
640 | qDebug( "OWaveLanManagementIBSS()" ); | 671 | qDebug( "OWaveLanManagementIBSS()" ); |
641 | } | 672 | } |
642 | 673 | ||
643 | 674 | ||
644 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() | 675 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() |
645 | { | 676 | { |
646 | } | 677 | } |
647 | 678 | ||
648 | /*====================================================================================== | 679 | /*====================================================================================== |
649 | * OWaveLanManagementChallenge | 680 | * OWaveLanManagementChallenge |
650 | *======================================================================================*/ | 681 | *======================================================================================*/ |
651 | 682 | ||
652 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) | 683 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) |
653 | :QObject( parent, "802.11 Challenge" ), _data( data ) | 684 | :QObject( parent, "802.11 Challenge" ), _data( data ) |
654 | { | 685 | { |
655 | qDebug( "OWaveLanManagementChallenge()" ); | 686 | qDebug( "OWaveLanManagementChallenge()" ); |
656 | } | 687 | } |
657 | 688 | ||
658 | 689 | ||
659 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() | 690 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() |
660 | { | 691 | { |
661 | } | 692 | } |
662 | 693 | ||
663 | /*====================================================================================== | 694 | /*====================================================================================== |
664 | * OWaveLanDataPacket | 695 | * OWaveLanDataPacket |
665 | *======================================================================================*/ | 696 | *======================================================================================*/ |
666 | 697 | ||
667 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) | 698 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) |
668 | :QObject( parent, "802.11 Data" ), _header( data ) | 699 | :QObject( parent, "802.11 Data" ), _header( data ) |
669 | { | 700 | { |
670 | qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." ); | 701 | qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." ); |
671 | 702 | ||
672 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); | 703 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); |
673 | 704 | ||
674 | #warning The next line works for most cases, but can not be correct generally! | 705 | #warning The next line works for most cases, but can not be correct generally! |
675 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address | 706 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address |
676 | 707 | ||
677 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); | 708 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); |
678 | } | 709 | } |
679 | 710 | ||
680 | 711 | ||
681 | OWaveLanDataPacket::~OWaveLanDataPacket() | 712 | OWaveLanDataPacket::~OWaveLanDataPacket() |
682 | { | 713 | { |
683 | } | 714 | } |
684 | 715 | ||
685 | 716 | ||
686 | /*====================================================================================== | 717 | /*====================================================================================== |
687 | * OLLCPacket | 718 | * OLLCPacket |
688 | *======================================================================================*/ | 719 | *======================================================================================*/ |
689 | 720 | ||
690 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) | 721 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) |
691 | :QObject( parent, "802.11 LLC" ), _header( data ) | 722 | :QObject( parent, "802.11 LLC" ), _header( data ) |
692 | { | 723 | { |
693 | qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); | 724 | qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); |
694 | 725 | ||
695 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) | 726 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) |
696 | { | 727 | { |
697 | qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); | 728 | qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); |
698 | 729 | ||
699 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h | 730 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h |
700 | { | 731 | { |
701 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 732 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
702 | default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" ); | 733 | default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" ); |
703 | } | 734 | } |
704 | 735 | ||
705 | } | 736 | } |
706 | } | 737 | } |
707 | 738 | ||
708 | 739 | ||
709 | OLLCPacket::~OLLCPacket() | 740 | OLLCPacket::~OLLCPacket() |
710 | { | 741 | { |
711 | } | 742 | } |
712 | 743 | ||
713 | 744 | ||
714 | /*====================================================================================== | 745 | /*====================================================================================== |
715 | * OWaveLanControlPacket | 746 | * OWaveLanControlPacket |
716 | *======================================================================================*/ | 747 | *======================================================================================*/ |
717 | 748 | ||
718 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) | 749 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) |
719 | :QObject( parent, "802.11 Data" ), _header( data ) | 750 | :QObject( parent, "802.11 Data" ), _header( data ) |
720 | { | 751 | { |
721 | qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." ); | 752 | qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." ); |
722 | //TODO: Implement this | 753 | //TODO: Implement this |
723 | } | 754 | } |
724 | 755 | ||
725 | 756 | ||
726 | OWaveLanControlPacket::~OWaveLanControlPacket() | 757 | OWaveLanControlPacket::~OWaveLanControlPacket() |
727 | { | 758 | { |
728 | } | 759 | } |
729 | 760 | ||
730 | 761 | ||
731 | /*====================================================================================== | 762 | /*====================================================================================== |
732 | * OPacketCapturer | 763 | * OPacketCapturer |
733 | *======================================================================================*/ | 764 | *======================================================================================*/ |
734 | 765 | ||
735 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) | 766 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) |
736 | :QObject( parent, name ), _name( QString::null ), _open( false ), | 767 | :QObject( parent, name ), _name( QString::null ), _open( false ), |
737 | _pch( 0 ), _pcd( 0 ), _sn( 0 ) | 768 | _pch( 0 ), _pcd( 0 ), _sn( 0 ) |
738 | { | 769 | { |
739 | } | 770 | } |
740 | 771 | ||
741 | 772 | ||
742 | OPacketCapturer::~OPacketCapturer() | 773 | OPacketCapturer::~OPacketCapturer() |
743 | { | 774 | { |
744 | if ( _open ) | 775 | if ( _open ) |
745 | { | 776 | { |
746 | qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); | 777 | qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); |
747 | close(); | 778 | close(); |
748 | } | 779 | } |
749 | } | 780 | } |
750 | 781 | ||
751 | 782 | ||
752 | void OPacketCapturer::setBlocking( bool b ) | 783 | void OPacketCapturer::setBlocking( bool b ) |
753 | { | 784 | { |
754 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) | 785 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) |
755 | { | 786 | { |
756 | qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); | 787 | qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); |
757 | } | 788 | } |
758 | else | 789 | else |
759 | { | 790 | { |
760 | qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); | 791 | qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); |
761 | } | 792 | } |
762 | } | 793 | } |
763 | 794 | ||
764 | 795 | ||
765 | bool OPacketCapturer::blocking() const | 796 | bool OPacketCapturer::blocking() const |
766 | { | 797 | { |
767 | int b = pcap_getnonblock( _pch, _errbuf ); | 798 | int b = pcap_getnonblock( _pch, _errbuf ); |
768 | if ( b == -1 ) | 799 | if ( b == -1 ) |
769 | { | 800 | { |
770 | qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); | 801 | qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); |
771 | return -1; | 802 | return -1; |
772 | } | 803 | } |
773 | return !b; | 804 | return !b; |
774 | } | 805 | } |
775 | 806 | ||
776 | 807 | ||
777 | void OPacketCapturer::close() | 808 | void OPacketCapturer::close() |
778 | { | 809 | { |
779 | if ( _open ) | 810 | if ( _open ) |
780 | { | 811 | { |
781 | if ( _sn ) | 812 | if ( _sn ) |
782 | { | 813 | { |
783 | _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 814 | _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
784 | delete _sn; | 815 | delete _sn; |
785 | } | 816 | } |
786 | if ( _pcd ) | 817 | if ( _pcd ) |
787 | { | 818 | { |
788 | pcap_dump_close( _pcd ); | 819 | pcap_dump_close( _pcd ); |
789 | _pcd = 0; | 820 | _pcd = 0; |
790 | } | 821 | } |
791 | pcap_close( _pch ); | 822 | pcap_close( _pch ); |
792 | _open = false; | 823 | _open = false; |
793 | } | 824 | } |
794 | 825 | ||
795 | qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); | 826 | qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); |
796 | qDebug( "--------------------------------------------------" ); | 827 | qDebug( "--------------------------------------------------" ); |
797 | for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) | 828 | for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) |
798 | qDebug( "%s : %d", (const char*) it.key(), it.data() ); | 829 | qDebug( "%s : %d", (const char*) it.key(), it.data() ); |
799 | qDebug( "--------------------------------------------------" ); | 830 | qDebug( "--------------------------------------------------" ); |
800 | 831 | ||
801 | } | 832 | } |
802 | 833 | ||
803 | 834 | ||
804 | int OPacketCapturer::dataLink() const | 835 | int OPacketCapturer::dataLink() const |
805 | { | 836 | { |
806 | return pcap_datalink( _pch ); | 837 | return pcap_datalink( _pch ); |
807 | } | 838 | } |
808 | 839 | ||
809 | 840 | ||
810 | int OPacketCapturer::fileno() const | 841 | int OPacketCapturer::fileno() const |
811 | { | 842 | { |
812 | if ( _open ) | 843 | if ( _open ) |
813 | { | 844 | { |
814 | return pcap_fileno( _pch ); | 845 | return pcap_fileno( _pch ); |
815 | } | 846 | } |
816 | else | 847 | else |
817 | { | 848 | { |
818 | return -1; | 849 | return -1; |
819 | } | 850 | } |
820 | } | 851 | } |
821 | 852 | ||
822 | OPacket* OPacketCapturer::next() | 853 | OPacket* OPacketCapturer::next() |
823 | { | 854 | { |
824 | packetheaderstruct header; | 855 | packetheaderstruct header; |
825 | qDebug( "==> OPacketCapturer::next()" ); | 856 | qDebug( "==> OPacketCapturer::next()" ); |
826 | const unsigned char* pdata = pcap_next( _pch, &header ); | 857 | const unsigned char* pdata = pcap_next( _pch, &header ); |
827 | qDebug( "<== OPacketCapturer::next()" ); | 858 | qDebug( "<== OPacketCapturer::next()" ); |
828 | if ( _pcd ) | 859 | if ( _pcd ) |
829 | pcap_dump( (u_char*) _pcd, &header, pdata ); | 860 | pcap_dump( (u_char*) _pcd, &header, pdata ); |
830 | 861 | ||
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h index fe88e68..83f7115 100644 --- a/libopie2/opienet/opcap.h +++ b/libopie2/opienet/opcap.h | |||
@@ -1,550 +1,569 @@ | |||
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 */ |
38 | extern "C" // work around a bpf/pcap conflict in recent headers | 38 | extern "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 <qevent.h> | 49 | #include <qevent.h> |
50 | #include <qfile.h> | 50 | #include <qfile.h> |
51 | #include <qhostaddress.h> | 51 | #include <qhostaddress.h> |
52 | #include <qobject.h> | 52 | #include <qobject.h> |
53 | #include <qstring.h> | 53 | #include <qstring.h> |
54 | #include <qmap.h> | 54 | #include <qmap.h> |
55 | 55 | ||
56 | /* OPIE */ | 56 | /* OPIE */ |
57 | #include <opie2/onetutils.h> | 57 | #include <opie2/onetutils.h> |
58 | #include "802_11_user.h" | 58 | #include "802_11_user.h" |
59 | 59 | ||
60 | /* TYPEDEFS */ | 60 | /* TYPEDEFS */ |
61 | typedef struct timeval timevalstruct; | 61 | typedef struct timeval timevalstruct; |
62 | typedef struct pcap_pkthdr packetheaderstruct; | 62 | typedef struct pcap_pkthdr packetheaderstruct; |
63 | 63 | ||
64 | /* FORWARDS */ | 64 | /* FORWARDS */ |
65 | class OPacketCapturer; | 65 | class OPacketCapturer; |
66 | class QSocketNotifier; | 66 | class QSocketNotifier; |
67 | 67 | ||
68 | /*====================================================================================== | 68 | /*====================================================================================== |
69 | * OPacket - A frame on the wire | 69 | * OPacket - A frame on the wire |
70 | *======================================================================================*/ | 70 | *======================================================================================*/ |
71 | 71 | ||
72 | /** @brief A class representing a data frame on the wire. | 72 | /** @brief A class representing a data frame on the wire. |
73 | * | 73 | * |
74 | * The whole family of the packet classes are used when capturing frames from a network. | 74 | * The whole family of the packet classes are used when capturing frames from a network. |
75 | * Most standard network protocols in use share a common architecture, which mostly is | 75 | * Most standard network protocols in use share a common architecture, which mostly is |
76 | * a packet header and then the packet payload. In layered architectures, each lower layer | 76 | * a packet header and then the packet payload. In layered architectures, each lower layer |
77 | * encapsulates data from its upper layer - that is it | 77 | * encapsulates data from its upper layer - that is it |
78 | * treats the data from its upper layer as payload and prepends an own header to the packet, | 78 | * treats the data from its upper layer as payload and prepends an own header to the packet, |
79 | * which - again - is treated as the payload for the layer below. The figure below is an | 79 | * which - again - is treated as the payload for the layer below. The figure below is an |
80 | * example for how such a data frame is composed out of packets, e.g. when sending a mail. | 80 | * example for how such a data frame is composed out of packets, e.g. when sending a mail. |
81 | * | 81 | * |
82 | * <pre> | 82 | * <pre> |
83 | * | User Data | == Mail Data | 83 | * | User Data | == Mail Data |
84 | * | SMTP Header | User Data | == SMTP | 84 | * | SMTP Header | User Data | == SMTP |
85 | * | TCP Header | SMTP Header | User Data | == TCP | 85 | * | TCP Header | SMTP Header | User Data | == TCP |
86 | * | IP Header | TCP Header | SMTP Header | User Data | == IP | 86 | * | IP Header | TCP Header | SMTP Header | User Data | == IP |
87 | * | MAC Header | IP Header | TCP Header | SMTP Header | User Data | == MAC | 87 | * | MAC Header | IP Header | TCP Header | SMTP Header | User Data | == MAC |
88 | * | 88 | * |
89 | * </pre> | 89 | * </pre> |
90 | * | 90 | * |
91 | * The example is trimmed for simplicity, because the MAC (Medium Access Control) layer | 91 | * The example is trimmed for simplicity, because the MAC (Medium Access Control) layer |
92 | * also contains a few more levels of encapsulation. | 92 | * also contains a few more levels of encapsulation. |
93 | * Since the type of the payload is more or less independent from the encapsulating protocol, | 93 | * Since the type of the payload is more or less independent from the encapsulating protocol, |
94 | * the header must be inspected before attempting to decode the payload. Hence, the | 94 | * the header must be inspected before attempting to decode the payload. Hence, the |
95 | * encapsulation level varies and can't be deduced without actually looking into the packets. | 95 | * encapsulation level varies and can't be deduced without actually looking into the packets. |
96 | * | 96 | * |
97 | * For actually working with captured frames, it's useful to identify the packets via names and | 97 | * For actually working with captured frames, it's useful to identify the packets via names and |
98 | * insert them into a parent/child - relationship based on the encapsulation. This is why | 98 | * insert them into a parent/child - relationship based on the encapsulation. This is why |
99 | * all packet classes derive from QObject. The amount of overhead caused by the QObject is | 99 | * all packet classes derive from QObject. The amount of overhead caused by the QObject is |
100 | * not a problem in this case, because we're talking about a theoratical maximum of about | 100 | * not a problem in this case, because we're talking about a theoratical maximum of about |
101 | * 10 packets per captured frame. We need to stuff them into a searchable list anyway and the | 101 | * 10 packets per captured frame. We need to stuff them into a searchable list anyway and the |
102 | * QObject also cares about destroying the sub-, (child-) packets. | 102 | * QObject also cares about destroying the sub-, (child-) packets. |
103 | * | 103 | * |
104 | * This enables us to perform a simple look for packets of a certain type: | 104 | * This enables us to perform a simple look for packets of a certain type: |
105 | * @code | 105 | * @code |
106 | * OPacketCapturer* pcap = new OPacketCapturer(); | 106 | * OPacketCapturer* pcap = new OPacketCapturer(); |
107 | * pcap->open( "eth0" ); | 107 | * pcap->open( "eth0" ); |
108 | * OPacket* p = pcap->next(); | 108 | * OPacket* p = pcap->next(); |
109 | * OIPPacket* ip = (OIPPacket*) p->child( "IP" ); // returns 0, if no such child exists | 109 | * OIPPacket* ip = (OIPPacket*) p->child( "IP" ); // returns 0, if no such child exists |
110 | * odebug << "got ip packet from " << ip->fromIPAddress().toString() << " to " << ip->toIPAddress().toString() << oendl; | 110 | * odebug << "got ip packet from " << ip->fromIPAddress().toString() << " to " << ip->toIPAddress().toString() << oendl; |
111 | * | 111 | * |
112 | */ | 112 | */ |
113 | 113 | ||
114 | class OPacket : public QObject | 114 | class OPacket : public QObject |
115 | { | 115 | { |
116 | Q_OBJECT | 116 | Q_OBJECT |
117 | 117 | ||
118 | public: | 118 | public: |
119 | OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); | 119 | OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); |
120 | virtual ~OPacket(); | 120 | virtual ~OPacket(); |
121 | 121 | ||
122 | timevalstruct timeval() const; | 122 | timevalstruct timeval() const; |
123 | 123 | ||
124 | int caplen() const; | 124 | int caplen() const; |
125 | int len() const; | 125 | int len() const; |
126 | QString dump( int = 32 ) const; | 126 | QString dump( int = 32 ) const; |
127 | 127 | ||
128 | void updateStats( QMap<QString,int>&, QObjectList* ); | 128 | void updateStats( QMap<QString,int>&, QObjectList* ); |
129 | 129 | ||
130 | private: | 130 | private: |
131 | const packetheaderstruct _hdr; // pcap packet header | 131 | const packetheaderstruct _hdr; // pcap packet header |
132 | const unsigned char* _data; // pcap packet data | 132 | const unsigned char* _data; // pcap packet data |
133 | const unsigned char* _end; // end of pcap packet data | 133 | const unsigned char* _end; // end of pcap packet data |
134 | }; | 134 | }; |
135 | 135 | ||
136 | /*====================================================================================== | 136 | /*====================================================================================== |
137 | * OEthernetPacket - DLT_EN10MB frame | 137 | * OEthernetPacket - DLT_EN10MB frame |
138 | *======================================================================================*/ | 138 | *======================================================================================*/ |
139 | 139 | ||
140 | class OEthernetPacket : public QObject | 140 | class OEthernetPacket : public QObject |
141 | { | 141 | { |
142 | Q_OBJECT | 142 | Q_OBJECT |
143 | 143 | ||
144 | public: | 144 | public: |
145 | OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); | 145 | OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); |
146 | virtual ~OEthernetPacket(); | 146 | virtual ~OEthernetPacket(); |
147 | 147 | ||
148 | OMacAddress sourceAddress() const; | 148 | OMacAddress sourceAddress() const; |
149 | OMacAddress destinationAddress() const; | 149 | OMacAddress destinationAddress() const; |
150 | int type() const; | 150 | int type() const; |
151 | 151 | ||
152 | private: | 152 | private: |
153 | const struct ether_header* _ether; | 153 | const struct ether_header* _ether; |
154 | }; | 154 | }; |
155 | 155 | ||
156 | 156 | ||
157 | /*====================================================================================== | 157 | /*====================================================================================== |
158 | * OPrismHeaderPacket - DLT_PRISM_HEADER frame | ||
159 | *======================================================================================*/ | ||
160 | |||
161 | class OPrismHeaderPacket : public QObject | ||
162 | { | ||
163 | Q_OBJECT | ||
164 | |||
165 | public: | ||
166 | OPrismHeaderPacket( const unsigned char*, const struct prism_hdr*, QObject* parent = 0 ); | ||
167 | virtual ~OPrismHeaderPacket(); | ||
168 | |||
169 | unsigned int signalStrength() const; | ||
170 | |||
171 | private: | ||
172 | const struct prism_hdr* _header; | ||
173 | }; | ||
174 | |||
175 | |||
176 | /*====================================================================================== | ||
158 | * OWaveLanPacket - DLT_IEEE802_11 frame | 177 | * OWaveLanPacket - DLT_IEEE802_11 frame |
159 | *======================================================================================*/ | 178 | *======================================================================================*/ |
160 | 179 | ||
161 | class OWaveLanPacket : public QObject | 180 | class OWaveLanPacket : public QObject |
162 | { | 181 | { |
163 | Q_OBJECT | 182 | Q_OBJECT |
164 | 183 | ||
165 | public: | 184 | public: |
166 | OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); | 185 | OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); |
167 | virtual ~OWaveLanPacket(); | 186 | virtual ~OWaveLanPacket(); |
168 | 187 | ||
169 | int duration() const; | 188 | int duration() const; |
170 | bool fromDS() const; | 189 | bool fromDS() const; |
171 | bool toDS() const; | 190 | bool toDS() const; |
172 | virtual OMacAddress macAddress1() const; | 191 | virtual OMacAddress macAddress1() const; |
173 | virtual OMacAddress macAddress2() const; | 192 | virtual OMacAddress macAddress2() const; |
174 | virtual OMacAddress macAddress3() const; | 193 | virtual OMacAddress macAddress3() const; |
175 | virtual OMacAddress macAddress4() const; | 194 | virtual OMacAddress macAddress4() const; |
176 | bool usesPowerManagement() const; | 195 | bool usesPowerManagement() const; |
177 | int type() const; | 196 | int type() const; |
178 | int subType() const; | 197 | int subType() const; |
179 | int version() const; | 198 | int version() const; |
180 | bool usesWep() const; | 199 | bool usesWep() const; |
181 | 200 | ||
182 | private: | 201 | private: |
183 | const struct ieee_802_11_header* _wlanhdr; | 202 | const struct ieee_802_11_header* _wlanhdr; |
184 | }; | 203 | }; |
185 | 204 | ||
186 | 205 | ||
187 | /*====================================================================================== | 206 | /*====================================================================================== |
188 | * OWaveLanManagementPacket - type: management (T_MGMT) | 207 | * OWaveLanManagementPacket - type: management (T_MGMT) |
189 | *======================================================================================*/ | 208 | *======================================================================================*/ |
190 | 209 | ||
191 | class OWaveLanManagementPacket : public QObject | 210 | class OWaveLanManagementPacket : public QObject |
192 | { | 211 | { |
193 | Q_OBJECT | 212 | Q_OBJECT |
194 | 213 | ||
195 | public: | 214 | public: |
196 | OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); | 215 | OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); |
197 | virtual ~OWaveLanManagementPacket(); | 216 | virtual ~OWaveLanManagementPacket(); |
198 | 217 | ||
199 | QString managementType() const; | 218 | QString managementType() const; |
200 | 219 | ||
201 | int beaconInterval() const; | 220 | int beaconInterval() const; |
202 | int capabilities() const; // generic | 221 | int capabilities() const; // generic |
203 | 222 | ||
204 | bool canESS() const; | 223 | bool canESS() const; |
205 | bool canIBSS() const; | 224 | bool canIBSS() const; |
206 | bool canCFP() const; | 225 | bool canCFP() const; |
207 | bool canCFP_REQ() const; | 226 | bool canCFP_REQ() const; |
208 | bool canPrivacy() const; | 227 | bool canPrivacy() const; |
209 | 228 | ||
210 | private: | 229 | private: |
211 | const struct ieee_802_11_mgmt_header* _header; | 230 | const struct ieee_802_11_mgmt_header* _header; |
212 | const struct ieee_802_11_mgmt_body* _body; | 231 | const struct ieee_802_11_mgmt_body* _body; |
213 | }; | 232 | }; |
214 | 233 | ||
215 | 234 | ||
216 | /*====================================================================================== | 235 | /*====================================================================================== |
217 | * OWaveLanManagementSSID | 236 | * OWaveLanManagementSSID |
218 | *======================================================================================*/ | 237 | *======================================================================================*/ |
219 | 238 | ||
220 | class OWaveLanManagementSSID : public QObject | 239 | class OWaveLanManagementSSID : public QObject |
221 | { | 240 | { |
222 | Q_OBJECT | 241 | Q_OBJECT |
223 | 242 | ||
224 | public: | 243 | public: |
225 | OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 ); | 244 | OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 ); |
226 | virtual ~OWaveLanManagementSSID(); | 245 | virtual ~OWaveLanManagementSSID(); |
227 | 246 | ||
228 | QString ID() const; | 247 | QString ID() const; |
229 | 248 | ||
230 | private: | 249 | private: |
231 | const struct ssid_t* _data; | 250 | const struct ssid_t* _data; |
232 | }; | 251 | }; |
233 | 252 | ||
234 | /*====================================================================================== | 253 | /*====================================================================================== |
235 | * OWaveLanManagementRates | 254 | * OWaveLanManagementRates |
236 | *======================================================================================*/ | 255 | *======================================================================================*/ |
237 | 256 | ||
238 | class OWaveLanManagementRates : public QObject | 257 | class OWaveLanManagementRates : public QObject |
239 | { | 258 | { |
240 | Q_OBJECT | 259 | Q_OBJECT |
241 | 260 | ||
242 | public: | 261 | public: |
243 | OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); | 262 | OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); |
244 | virtual ~OWaveLanManagementRates(); | 263 | virtual ~OWaveLanManagementRates(); |
245 | 264 | ||
246 | private: | 265 | private: |
247 | const struct rates_t* _data; | 266 | const struct rates_t* _data; |
248 | }; | 267 | }; |
249 | 268 | ||
250 | /*====================================================================================== | 269 | /*====================================================================================== |
251 | * OWaveLanManagementCF | 270 | * OWaveLanManagementCF |
252 | *======================================================================================*/ | 271 | *======================================================================================*/ |
253 | 272 | ||
254 | class OWaveLanManagementCF : public QObject | 273 | class OWaveLanManagementCF : public QObject |
255 | { | 274 | { |
256 | Q_OBJECT | 275 | Q_OBJECT |
257 | 276 | ||
258 | public: | 277 | public: |
259 | OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); | 278 | OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); |
260 | virtual ~OWaveLanManagementCF(); | 279 | virtual ~OWaveLanManagementCF(); |
261 | 280 | ||
262 | private: | 281 | private: |
263 | const struct cf_t* _data; | 282 | const struct cf_t* _data; |
264 | }; | 283 | }; |
265 | 284 | ||
266 | /*====================================================================================== | 285 | /*====================================================================================== |
267 | * OWaveLanManagementFH | 286 | * OWaveLanManagementFH |
268 | *======================================================================================*/ | 287 | *======================================================================================*/ |
269 | 288 | ||
270 | class OWaveLanManagementFH : public QObject | 289 | class OWaveLanManagementFH : public QObject |
271 | { | 290 | { |
272 | Q_OBJECT | 291 | Q_OBJECT |
273 | 292 | ||
274 | public: | 293 | public: |
275 | OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 ); | 294 | OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 ); |
276 | virtual ~OWaveLanManagementFH(); | 295 | virtual ~OWaveLanManagementFH(); |
277 | 296 | ||
278 | private: | 297 | private: |
279 | const struct fh_t* _data; | 298 | const struct fh_t* _data; |
280 | }; | 299 | }; |
281 | 300 | ||
282 | /*====================================================================================== | 301 | /*====================================================================================== |
283 | * OWaveLanManagementDS | 302 | * OWaveLanManagementDS |
284 | *======================================================================================*/ | 303 | *======================================================================================*/ |
285 | 304 | ||
286 | class OWaveLanManagementDS : public QObject | 305 | class OWaveLanManagementDS : public QObject |
287 | { | 306 | { |
288 | Q_OBJECT | 307 | Q_OBJECT |
289 | 308 | ||
290 | public: | 309 | public: |
291 | OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); | 310 | OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); |
292 | virtual ~OWaveLanManagementDS(); | 311 | virtual ~OWaveLanManagementDS(); |
293 | 312 | ||
294 | int channel() const; | 313 | int channel() const; |
295 | 314 | ||
296 | private: | 315 | private: |
297 | const struct ds_t* _data; | 316 | const struct ds_t* _data; |
298 | }; | 317 | }; |
299 | 318 | ||
300 | /*====================================================================================== | 319 | /*====================================================================================== |
301 | * OWaveLanManagementTim | 320 | * OWaveLanManagementTim |
302 | *======================================================================================*/ | 321 | *======================================================================================*/ |
303 | 322 | ||
304 | class OWaveLanManagementTim : public QObject | 323 | class OWaveLanManagementTim : public QObject |
305 | { | 324 | { |
306 | Q_OBJECT | 325 | Q_OBJECT |
307 | 326 | ||
308 | public: | 327 | public: |
309 | OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); | 328 | OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); |
310 | virtual ~OWaveLanManagementTim(); | 329 | virtual ~OWaveLanManagementTim(); |
311 | 330 | ||
312 | private: | 331 | private: |
313 | const struct tim_t* _data; | 332 | const struct tim_t* _data; |
314 | }; | 333 | }; |
315 | 334 | ||
316 | /*====================================================================================== | 335 | /*====================================================================================== |
317 | * OWaveLanManagementIBSS | 336 | * OWaveLanManagementIBSS |
318 | *======================================================================================*/ | 337 | *======================================================================================*/ |
319 | 338 | ||
320 | class OWaveLanManagementIBSS : public QObject | 339 | class OWaveLanManagementIBSS : public QObject |
321 | { | 340 | { |
322 | Q_OBJECT | 341 | Q_OBJECT |
323 | 342 | ||
324 | public: | 343 | public: |
325 | OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); | 344 | OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); |
326 | virtual ~OWaveLanManagementIBSS(); | 345 | virtual ~OWaveLanManagementIBSS(); |
327 | 346 | ||
328 | private: | 347 | private: |
329 | const struct ibss_t* _data; | 348 | const struct ibss_t* _data; |
330 | }; | 349 | }; |
331 | 350 | ||
332 | /*====================================================================================== | 351 | /*====================================================================================== |
333 | * OWaveLanManagementChallenge | 352 | * OWaveLanManagementChallenge |
334 | *======================================================================================*/ | 353 | *======================================================================================*/ |
335 | 354 | ||
336 | // Qobject do we need that?? | 355 | // Qobject do we need that?? |
337 | class OWaveLanManagementChallenge : public QObject | 356 | class OWaveLanManagementChallenge : public QObject |
338 | { | 357 | { |
339 | Q_OBJECT | 358 | Q_OBJECT |
340 | 359 | ||
341 | public: | 360 | public: |
342 | OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); | 361 | OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); |
343 | virtual ~OWaveLanManagementChallenge(); | 362 | virtual ~OWaveLanManagementChallenge(); |
344 | 363 | ||
345 | private: | 364 | private: |
346 | const struct challenge_t* _data; | 365 | const struct challenge_t* _data; |
347 | }; | 366 | }; |
348 | 367 | ||
349 | /*====================================================================================== | 368 | /*====================================================================================== |
350 | * OWaveLanDataPacket - type: data (T_DATA) | 369 | * OWaveLanDataPacket - type: data (T_DATA) |
351 | *======================================================================================*/ | 370 | *======================================================================================*/ |
352 | // Qobject? | 371 | // Qobject? |
353 | class OWaveLanDataPacket : public QObject | 372 | class OWaveLanDataPacket : public QObject |
354 | { | 373 | { |
355 | Q_OBJECT | 374 | Q_OBJECT |
356 | 375 | ||
357 | public: | 376 | public: |
358 | OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); | 377 | OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); |
359 | virtual ~OWaveLanDataPacket(); | 378 | virtual ~OWaveLanDataPacket(); |
360 | 379 | ||
361 | private: | 380 | private: |
362 | const struct ieee_802_11_data_header* _header; | 381 | const struct ieee_802_11_data_header* _header; |
363 | }; | 382 | }; |
364 | 383 | ||
365 | /*====================================================================================== | 384 | /*====================================================================================== |
366 | * OWaveLanControlPacket - type: control (T_CTRL) | 385 | * OWaveLanControlPacket - type: control (T_CTRL) |
367 | *======================================================================================*/ | 386 | *======================================================================================*/ |
368 | 387 | ||
369 | class OWaveLanControlPacket : public QObject | 388 | class OWaveLanControlPacket : public QObject |
370 | { | 389 | { |
371 | Q_OBJECT | 390 | Q_OBJECT |
372 | 391 | ||
373 | public: | 392 | public: |
374 | OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); | 393 | OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); |
375 | virtual ~OWaveLanControlPacket(); | 394 | virtual ~OWaveLanControlPacket(); |
376 | 395 | ||
377 | private: | 396 | private: |
378 | const struct ieee_802_11_control_header* _header; | 397 | const struct ieee_802_11_control_header* _header; |
379 | }; | 398 | }; |
380 | 399 | ||
381 | /*====================================================================================== | 400 | /*====================================================================================== |
382 | * OLLCPacket - IEEE 802.2 Link Level Control | 401 | * OLLCPacket - IEEE 802.2 Link Level Control |
383 | *======================================================================================*/ | 402 | *======================================================================================*/ |
384 | 403 | ||
385 | class OLLCPacket : public QObject | 404 | class OLLCPacket : public QObject |
386 | { | 405 | { |
387 | Q_OBJECT | 406 | Q_OBJECT |
388 | 407 | ||
389 | public: | 408 | public: |
390 | OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); | 409 | OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); |
391 | virtual ~OLLCPacket(); | 410 | virtual ~OLLCPacket(); |
392 | 411 | ||
393 | private: | 412 | private: |
394 | const struct ieee_802_11_802_2_header* _header; | 413 | const struct ieee_802_11_802_2_header* _header; |
395 | }; | 414 | }; |
396 | 415 | ||
397 | /*====================================================================================== | 416 | /*====================================================================================== |
398 | * OIPPacket | 417 | * OIPPacket |
399 | *======================================================================================*/ | 418 | *======================================================================================*/ |
400 | 419 | ||
401 | class OIPPacket : public QObject | 420 | class OIPPacket : public QObject |
402 | { | 421 | { |
403 | Q_OBJECT | 422 | Q_OBJECT |
404 | 423 | ||
405 | public: | 424 | public: |
406 | OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); | 425 | OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); |
407 | virtual ~OIPPacket(); | 426 | virtual ~OIPPacket(); |
408 | 427 | ||
409 | QHostAddress fromIPAddress() const; | 428 | QHostAddress fromIPAddress() const; |
410 | QHostAddress toIPAddress() const; | 429 | QHostAddress toIPAddress() const; |
411 | 430 | ||
412 | int tos() const; | 431 | int tos() const; |
413 | int len() const; | 432 | int len() const; |
414 | int id() const; | 433 | int id() const; |
415 | int offset() const; | 434 | int offset() const; |
416 | int ttl() const; | 435 | int ttl() const; |
417 | int protocol() const; | 436 | int protocol() const; |
418 | int checksum() const; | 437 | int checksum() const; |
419 | 438 | ||
420 | private: | 439 | private: |
421 | const struct iphdr* _iphdr; | 440 | const struct iphdr* _iphdr; |
422 | }; | 441 | }; |
423 | 442 | ||
424 | /*====================================================================================== | 443 | /*====================================================================================== |
425 | * OUDPPacket | 444 | * OUDPPacket |
426 | *======================================================================================*/ | 445 | *======================================================================================*/ |
427 | 446 | ||
428 | class OUDPPacket : public QObject | 447 | class OUDPPacket : public QObject |
429 | { | 448 | { |
430 | Q_OBJECT | 449 | Q_OBJECT |
431 | 450 | ||
432 | public: | 451 | public: |
433 | OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); | 452 | OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); |
434 | virtual ~OUDPPacket(); | 453 | virtual ~OUDPPacket(); |
435 | 454 | ||
436 | int fromPort() const; | 455 | int fromPort() const; |
437 | int toPort() const; | 456 | int toPort() const; |
438 | 457 | ||
439 | private: | 458 | private: |
440 | const struct udphdr* _udphdr; | 459 | const struct udphdr* _udphdr; |
441 | }; | 460 | }; |
442 | 461 | ||
443 | /*====================================================================================== | 462 | /*====================================================================================== |
444 | * OTCPPacket | 463 | * OTCPPacket |
445 | *======================================================================================*/ | 464 | *======================================================================================*/ |
446 | 465 | ||
447 | class OTCPPacket : public QObject | 466 | class OTCPPacket : public QObject |
448 | { | 467 | { |
449 | Q_OBJECT | 468 | Q_OBJECT |
450 | 469 | ||
451 | public: | 470 | public: |
452 | OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); | 471 | OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); |
453 | virtual ~OTCPPacket(); | 472 | virtual ~OTCPPacket(); |
454 | 473 | ||
455 | int fromPort() const; | 474 | int fromPort() const; |
456 | int toPort() const; | 475 | int toPort() const; |
457 | 476 | ||
458 | private: | 477 | private: |
459 | const struct tcphdr* _tcphdr; | 478 | const struct tcphdr* _tcphdr; |
460 | }; | 479 | }; |
461 | 480 | ||
462 | 481 | ||
463 | /*====================================================================================== | 482 | /*====================================================================================== |
464 | * OPacketCapturer | 483 | * OPacketCapturer |
465 | *======================================================================================*/ | 484 | *======================================================================================*/ |
466 | 485 | ||
467 | /** | 486 | /** |
468 | * @brief A class based wrapper for network packet capturing. | 487 | * @brief A class based wrapper for network packet capturing. |
469 | * | 488 | * |
470 | * This class is the base of a high-level interface to the well known packet capturing | 489 | * This class is the base of a high-level interface to the well known packet capturing |
471 | * library libpcap. ... | 490 | * library libpcap. ... |
472 | */ | 491 | */ |
473 | class OPacketCapturer : public QObject | 492 | class OPacketCapturer : public QObject |
474 | { | 493 | { |
475 | Q_OBJECT | 494 | Q_OBJECT |
476 | 495 | ||
477 | public: | 496 | public: |
478 | /** | 497 | /** |
479 | * Constructor. | 498 | * Constructor. |
480 | */ | 499 | */ |
481 | OPacketCapturer( QObject* parent = 0, const char* name = 0 ); | 500 | OPacketCapturer( QObject* parent = 0, const char* name = 0 ); |
482 | /** | 501 | /** |
483 | * Destructor. | 502 | * Destructor. |
484 | */ | 503 | */ |
485 | ~OPacketCapturer(); | 504 | ~OPacketCapturer(); |
486 | /** | 505 | /** |
487 | * Setting the packet capturer to use blocking IO calls can be useful when | 506 | * Setting the packet capturer to use blocking IO calls can be useful when |
488 | * not using the socket notifier, e.g. without an application object. | 507 | * not using the socket notifier, e.g. without an application object. |
489 | */ | 508 | */ |
490 | void setBlocking( bool ); | 509 | void setBlocking( bool ); |
491 | /** | 510 | /** |
492 | * @returns true if the packet capturer uses blocking IO calls. | 511 | * @returns true if the packet capturer uses blocking IO calls. |
493 | */ | 512 | */ |
494 | bool blocking() const; | 513 | bool blocking() const; |
495 | /** | 514 | /** |
496 | * Closes the packet capturer. This is automatically done in the destructor. | 515 | * Closes the packet capturer. This is automatically done in the destructor. |
497 | */ | 516 | */ |
498 | void close(); | 517 | void close(); |
499 | /** | 518 | /** |
500 | * @returns the data link type. | 519 | * @returns the data link type. |
501 | * @see <pcap.h> for possible values. | 520 | * @see <pcap.h> for possible values. |
502 | */ | 521 | */ |
503 | int dataLink() const; | 522 | int dataLink() const; |
504 | /** | 523 | /** |
505 | * @returns the filedescriptor of the packet capturer. This is only useful, if | 524 | * @returns the filedescriptor of the packet capturer. This is only useful, if |
506 | * not using the socket notifier, e.g. without an application object. | 525 | * not using the socket notifier, e.g. without an application object. |
507 | */ | 526 | */ |
508 | int fileno() const; | 527 | int fileno() const; |
509 | /** | 528 | /** |
510 | * @returns the next @ref OPacket from the packet capturer. | 529 | * @returns the next @ref OPacket from the packet capturer. |
511 | * @note If blocking mode is true then this call might block. | 530 | * @note If blocking mode is true then this call might block. |
512 | */ | 531 | */ |
513 | OPacket* next(); | 532 | OPacket* next(); |
514 | /** | 533 | /** |
515 | * Open the packet capturer to capture packets in live-mode from @a interface. | 534 | * Open the packet capturer to capture packets in live-mode from @a interface. |
516 | * If a @a filename is given, all captured packets are output to a tcpdump-compatible capture file. | 535 | * If a @a filename is given, all captured packets are output to a tcpdump-compatible capture file. |
517 | */ | 536 | */ |
518 | bool open( const QString& interface, const QString& filename = QString::null ); | 537 | bool open( const QString& interface, const QString& filename = QString::null ); |
519 | /** | 538 | /** |
520 | * Open the packet capturer to capture packets in offline-mode from @a file. | 539 | * Open the packet capturer to capture packets in offline-mode from @a file. |
521 | */ | 540 | */ |
522 | bool open( const QFile& file ); | 541 | bool open( const QFile& file ); |
523 | /** | 542 | /** |
524 | * @returns true if the packet capturer is open | 543 | * @returns true if the packet capturer is open |
525 | */ | 544 | */ |
526 | bool isOpen() const; | 545 | bool isOpen() const; |
527 | 546 | ||
528 | const QMap<QString,int>& statistics() const; | 547 | const QMap<QString,int>& statistics() const; |
529 | 548 | ||
530 | signals: | 549 | signals: |
531 | /** | 550 | /** |
532 | * This signal is emitted, when a packet has been received. | 551 | * This signal is emitted, when a packet has been received. |
533 | */ | 552 | */ |
534 | void receivedPacket( OPacket* ); | 553 | void receivedPacket( OPacket* ); |
535 | 554 | ||
536 | protected slots: | 555 | protected slots: |
537 | void readyToReceive(); | 556 | void readyToReceive(); |
538 | 557 | ||
539 | protected: | 558 | protected: |
540 | QString _name; // devicename | 559 | QString _name; // devicename |
541 | bool _open; // check this before doing pcap calls | 560 | bool _open; // check this before doing pcap calls |
542 | pcap_t* _pch; // pcap library handle | 561 | pcap_t* _pch; // pcap library handle |
543 | pcap_dumper_t* _pcd; // pcap dumper handle | 562 | pcap_dumper_t* _pcd; // pcap dumper handle |
544 | QSocketNotifier* _sn; // socket notifier for main loop | 563 | QSocketNotifier* _sn; // socket notifier for main loop |
545 | mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap | 564 | mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap |
546 | QMap<QString, int> _stats; // statistics; | 565 | QMap<QString, int> _stats; // statistics; |
547 | }; | 566 | }; |
548 | 567 | ||
549 | #endif // OPCAP_H | 568 | #endif // OPCAP_H |
550 | 569 | ||