summaryrefslogtreecommitdiff
authormjm <mjm>2002-12-28 16:57:51 (UTC)
committer mjm <mjm>2002-12-28 16:57:51 (UTC)
commit6f71f59df05e634e59cd9ce44f785bd70429284a (patch) (unidiff)
tree54e11ac4a5e3c7d5d831de018b0f8734d6da783e
parentd6fb3096228e13a3de41b1c888a154c4f9ec3f16 (diff)
downloadopie-6f71f59df05e634e59cd9ce44f785bd70429284a.zip
opie-6f71f59df05e634e59cd9ce44f785bd70429284a.tar.gz
opie-6f71f59df05e634e59cd9ce44f785bd70429284a.tar.bz2
added memsets
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/sniff.cc5
1 files changed, 4 insertions, 1 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc b/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc
index 9b4e360..e516177 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc
+++ b/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc
@@ -1,317 +1,320 @@
1/* 1/*
2 * rfmon mode sniffer 2 * rfmon mode sniffer
3 * 3 *
4 * $Id$ 4 * $Id$
5 */ 5 */
6 6
7#include "sniff.hh" 7#include "sniff.hh"
8#include "ieee802_11.hh" 8#include "ieee802_11.hh"
9#include "extract.hh" 9#include "extract.hh"
10#include "wl_log.hh" 10#include "wl_log.hh"
11#include "wl_proto.hh" 11#include "wl_proto.hh"
12 12
13/* Main function, checks packets */ 13/* Main function, checks packets */
14void process_packets(const struct pcap_pkthdr *pkthdr, const unsigned char *packet, char *guihost, int guiport) 14void process_packets(const struct pcap_pkthdr *pkthdr, const unsigned char *packet, char *guihost, int guiport)
15{ 15{
16 unsigned int caplen = pkthdr->caplen; 16 unsigned int caplen = pkthdr->caplen;
17 unsigned int length = pkthdr->len; 17 unsigned int length = pkthdr->len;
18 u_int16_t fc; 18 u_int16_t fc;
19 unsigned int HEADER_LENGTH; 19 unsigned int HEADER_LENGTH;
20 20
21 /* pinfo holds all interresting information for us */ 21 /* pinfo holds all interresting information for us */
22 struct packetinfo pinfo; 22 struct packetinfo pinfo;
23 struct packetinfo *pinfoptr; 23 struct packetinfo *pinfoptr;
24 24
25 /* wl_network_t will finally be set and send to the ui */ 25 /* wl_network_t will finally be set and send to the ui */
26 wl_network_t wl_net; 26 wl_network_t wl_net;
27 27
28 pinfoptr=&pinfo; 28 pinfoptr=&pinfo;
29 29
30 pinfoptr->isvalid = 0; 30 pinfoptr->isvalid = 0;
31 pinfoptr->pktlen = pkthdr->len; 31 pinfoptr->pktlen = pkthdr->len;
32 32
33 if (caplen < IEEE802_11_FC_LEN) 33 if (caplen < IEEE802_11_FC_LEN)
34 { 34 {
35 /* This is a garbage packet, because is does not long enough 35 /* This is a garbage packet, because is does not long enough
36 to hold a 802.11b header */ 36 to hold a 802.11b header */
37 pinfoptr->isvalid = 0; 37 pinfoptr->isvalid = 0;
38 return; 38 return;
39 } 39 }
40 40
41 /* Gets the framecontrol bits (2bytes long) */ 41 /* Gets the framecontrol bits (2bytes long) */
42 fc = EXTRACT_LE_16BITS(packet); 42 fc = EXTRACT_LE_16BITS(packet);
43 43
44 HEADER_LENGTH = GetHeaderLength(fc); 44 HEADER_LENGTH = GetHeaderLength(fc);
45 45
46 if (caplen < HEADER_LENGTH) 46 if (caplen < HEADER_LENGTH)
47 { 47 {
48 /* This is a garbage packet, because it is not long enough 48 /* This is a garbage packet, because it is not long enough
49 to hold a correct header of its type */ 49 to hold a correct header of its type */
50 pinfoptr->isvalid = 0; 50 pinfoptr->isvalid = 0;
51 return; 51 return;
52 } 52 }
53 53
54 /* Decode 802.11b header out of the packet */ 54 /* Decode 802.11b header out of the packet */
55 if (decode_80211b_hdr(packet,pinfoptr) == 0) 55 if (decode_80211b_hdr(packet,pinfoptr) == 0)
56 { 56 {
57 /* Justification of the ofset to further process the packet */ 57 /* Justification of the ofset to further process the packet */
58 length -= HEADER_LENGTH; 58 length -= HEADER_LENGTH;
59 caplen -= HEADER_LENGTH; 59 caplen -= HEADER_LENGTH;
60 packet += HEADER_LENGTH; 60 packet += HEADER_LENGTH;
61 } 61 }
62 else /* Something is wrong,could not be a correct packet */ 62 else /* Something is wrong,could not be a correct packet */
63 return; 63 return;
64 64
65 switch (FC_TYPE(fc)) 65 switch (FC_TYPE(fc))
66 { 66 {
67 /* Is it a managemnet frame? */ 67 /* Is it a managemnet frame? */
68 case T_MGMT: 68 case T_MGMT:
69 switch (FC_SUBTYPE(fc)) 69 switch (FC_SUBTYPE(fc))
70 { 70 {
71 case ST_BEACON: 71 case ST_BEACON:
72 if (handle_beacon(fc, packet,pinfoptr) ==0) 72 if (handle_beacon(fc, packet,pinfoptr) ==0)
73 { 73 {
74 if (!strcmp(pinfoptr->desthwaddr,"ff:ff:ff:ff:ff:ff") == 0) 74 if (!strcmp(pinfoptr->desthwaddr,"ff:ff:ff:ff:ff:ff") == 0)
75 { 75 {
76 /* Every beacon must have the broadcast as destination 76 /* Every beacon must have the broadcast as destination
77 so it must be a shitti packet */ 77 so it must be a shitti packet */
78 pinfoptr->isvalid = 0; 78 pinfoptr->isvalid = 0;
79 return; 79 return;
80 } 80 }
81 81
82 if (pinfoptr->cap_ESS == pinfoptr->cap_IBSS) 82 if (pinfoptr->cap_ESS == pinfoptr->cap_IBSS)
83 { 83 {
84 /* Only one of both are possible, so must be 84 /* Only one of both are possible, so must be
85 a noise packet, if this comes up */ 85 a noise packet, if this comes up */
86 pinfoptr->isvalid = 0; 86 pinfoptr->isvalid = 0;
87 return; 87 return;
88 } 88 }
89 if (pinfoptr->channel < 1 || pinfoptr->channel > 14) 89 if (pinfoptr->channel < 1 || pinfoptr->channel > 14)
90 { 90 {
91 /* Only channels between 1 and 14 are possible 91 /* Only channels between 1 and 14 are possible
92 others must be noise packets */ 92 others must be noise packets */
93 pinfoptr->isvalid = 0; 93 pinfoptr->isvalid = 0;
94 return; 94 return;
95 } 95 }
96 96
97 /* Here should be the infos to the gui issued */ 97 /* Here should be the infos to the gui issued */
98 if (pinfoptr->cap_ESS == 1 &&pinfoptr->cap_IBSS ==0) 98 if (pinfoptr->cap_ESS == 1 &&pinfoptr->cap_IBSS ==0)
99 { 99 {
100 wl_loginfo("Found an access point"); 100 wl_loginfo("Found an access point");
101 wl_net.net_type=1; 101 wl_net.net_type=1;
102 } 102 }
103 else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 2) 103 else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 2)
104 { 104 {
105 wl_loginfo("Found an ad-hoc network"); 105 wl_loginfo("Found an ad-hoc network");
106 wl_net.net_type=2; 106 wl_net.net_type=2;
107 } 107 }
108 108
109 memset(wl_net.bssid, 0, sizeof(wl_net.bssid));
110
109 if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0) 111 if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0)
110 wl_loginfo("Net is a non-broadcasting network"); 112 wl_loginfo("Net is a non-broadcasting network");
111 else 113 else
112 wl_loginfo("SSID is: %s", pinfoptr->ssid); 114 wl_loginfo("SSID is: %s", pinfoptr->ssid);
113 115
114 wl_loginfo("SSID is: %s", pinfoptr->ssid); 116 wl_loginfo("SSID is: %s", pinfoptr->ssid);
115 memcpy(wl_net.bssid, pinfoptr->ssid, sizeof(wl_net.bssid)-1); 117 memcpy(wl_net.bssid, pinfoptr->ssid, sizeof(wl_net.bssid)-1);
116 118
117 wl_loginfo("SSID length is: %d", pinfoptr->ssid_len); 119 wl_loginfo("SSID length is: %d", pinfoptr->ssid_len);
118 wl_net.ssid_len=pinfoptr->ssid_len; 120 wl_net.ssid_len=pinfoptr->ssid_len;
119 121
120 wl_loginfo("Channel is: %d", pinfoptr->channel); 122 wl_loginfo("Channel is: %d", pinfoptr->channel);
121 wl_net.channel=pinfoptr->channel; 123 wl_net.channel=pinfoptr->channel;
122 wl_net.wep=pinfoptr->cap_WEP; 124 wl_net.wep=pinfoptr->cap_WEP;
123 125
124 wl_loginfo("Mac is: %s", pinfoptr->sndhwaddr); 126 wl_loginfo("Mac is: %s", pinfoptr->sndhwaddr);
125 memcpy(wl_net.mac, pinfoptr->sndhwaddr, sizeof(wl_net.mac)-1);; 127 memset(wl_net.mac, 0, sizeof(wl_net.mac));
128 memcpy(wl_net.mac, pinfoptr->sndhwaddr, sizeof(wl_net.mac)-1);
126 129
127 if(!send_network_found((char *)guihost, guiport, &wl_net)) 130 if(!send_network_found((char *)guihost, guiport, &wl_net))
128 { 131 {
129 wl_logerr("Error sending data to UI: %s", strerror(errno)); 132 wl_logerr("Error sending data to UI: %s", strerror(errno));
130 break; 133 break;
131 } 134 }
132 wl_loginfo("Sent network to GUI '%s:%d'", guihost, guiport); 135 wl_loginfo("Sent network to GUI '%s:%d'", guihost, guiport);
133 } 136 }
134 break; 137 break;
135 138
136 default: 139 default:
137 wl_logerr("Unknown IEEE802.11 frame subtype (%d)", FC_SUBTYPE(fc)); 140 wl_logerr("Unknown IEEE802.11 frame subtype (%d)", FC_SUBTYPE(fc));
138 break; 141 break;
139 } /* End of switch over different mgt frame types */ 142 } /* End of switch over different mgt frame types */
140 143
141 break; 144 break;
142 145
143 case T_CTRL: 146 case T_CTRL:
144 wl_loginfo("Received control frame, not implemented yet"); 147 wl_loginfo("Received control frame, not implemented yet");
145 break; 148 break;
146 149
147 case T_DATA: 150 case T_DATA:
148 wl_loginfo("Received date frame, not implemented yet"); 151 wl_loginfo("Received date frame, not implemented yet");
149 break; 152 break;
150 153
151 default: 154 default:
152 wl_logerr("Unknown IEEE802.11 frame type (%d)", FC_TYPE(fc)); 155 wl_logerr("Unknown IEEE802.11 frame type (%d)", FC_TYPE(fc));
153 break; 156 break;
154 } 157 }
155} 158}
156 159
157/* This decodes the 802.11b frame header out of the 802.11b packet 160/* This decodes the 802.11b frame header out of the 802.11b packet
158 all the infos is placed into the packetinfo structure */ 161 all the infos is placed into the packetinfo structure */
159int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo) 162int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo)
160{ 163{
161 const struct mgmt_header_t *mgthdr = (const struct mgmt_header_t *) p; 164 const struct mgmt_header_t *mgthdr = (const struct mgmt_header_t *) p;
162 ppinfo->fcsubtype = FC_SUBTYPE(mgthdr->fc); 165 ppinfo->fcsubtype = FC_SUBTYPE(mgthdr->fc);
163 166
164 /* Get the sender, bssid and dest mac address */ 167 /* Get the sender, bssid and dest mac address */
165 etheraddr_string(mgthdr->bssid,ppinfo->bssid); 168 etheraddr_string(mgthdr->bssid,ppinfo->bssid);
166 etheraddr_string(mgthdr->da,ppinfo->desthwaddr); 169 etheraddr_string(mgthdr->da,ppinfo->desthwaddr);
167 etheraddr_string(mgthdr->sa,ppinfo->sndhwaddr); 170 etheraddr_string(mgthdr->sa,ppinfo->sndhwaddr);
168 ppinfo->fc_wep = FC_WEP(mgthdr->fc); 171 ppinfo->fc_wep = FC_WEP(mgthdr->fc);
169 return 0; 172 return 0;
170} 173}
171 174
172 175
173void etheraddr_string(register const u_char *ep, char *text) 176void etheraddr_string(register const u_char *ep, char *text)
174{ 177{
175 static char hex[] = "0123456789abcdef"; 178 static char hex[] = "0123456789abcdef";
176 register unsigned int i, j; 179 register unsigned int i, j;
177 register char *cp; 180 register char *cp;
178 char buf[sizeof("00:00:00:00:00:00\0")]; 181 char buf[sizeof("00:00:00:00:00:00\0")];
179 cp = buf; 182 cp = buf;
180 if ((j = *ep >> 4) != 0) 183 if ((j = *ep >> 4) != 0)
181 { 184 {
182 *cp++ = hex[j]; 185 *cp++ = hex[j];
183 } 186 }
184 else 187 else
185 { 188 {
186 *cp++ = '0'; 189 *cp++ = '0';
187 } 190 }
188 *cp++ = hex[*ep++ & 0xf]; 191 *cp++ = hex[*ep++ & 0xf];
189 192
190 for (i = 5; (int)--i >= 0;) 193 for (i = 5; (int)--i >= 0;)
191 { 194 {
192 *cp++ = ':'; 195 *cp++ = ':';
193 if ((j = *ep >> 4) != 0) 196 if ((j = *ep >> 4) != 0)
194 { 197 {
195 *cp++ = hex[j]; 198 *cp++ = hex[j];
196 } 199 }
197 else 200 else
198 { 201 {
199 *cp++ = '0'; 202 *cp++ = '0';
200 } 203 }
201 204
202 *cp++ = hex[*ep++ & 0xf]; 205 *cp++ = hex[*ep++ & 0xf];
203 } 206 }
204 *cp = '\0'; 207 *cp = '\0';
205 strcpy(text,buf); 208 strcpy(text,buf);
206} 209}
207 210
208/* beacon handler */ 211/* beacon handler */
209int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) 212int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo)
210{ 213{
211 struct mgmt_body_t pbody; 214 struct mgmt_body_t pbody;
212 int offset = 0; 215 int offset = 0;
213 216
214 /* Get the static informations out of the packet */ 217 /* Get the static informations out of the packet */
215 memset(&pbody, 0, sizeof(pbody)); 218 memset(&pbody, 0, sizeof(pbody));
216 memcpy(&pbody.timestamp, p, 8); 219 memcpy(&pbody.timestamp, p, 8);
217 offset += 8; 220 offset += 8;
218 pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); 221 pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset);
219 offset += 2; 222 offset += 2;
220 pbody.capability_info = EXTRACT_LE_16BITS(p+offset); 223 pbody.capability_info = EXTRACT_LE_16BITS(p+offset);
221 offset += 2; 224 offset += 2;
222 225
223 /* Gets the different flags out of the capabilities */ 226 /* Gets the different flags out of the capabilities */
224 ppinfo->cap_ESS = CAPABILITY_ESS(pbody.capability_info); 227 ppinfo->cap_ESS = CAPABILITY_ESS(pbody.capability_info);
225 ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info); 228 ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info);
226 ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info); 229 ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info);
227 230
228 /* Gets the tagged elements out of the packets */ 231 /* Gets the tagged elements out of the packets */
229 while (offset + 1 < ppinfo->pktlen) 232 while (offset + 1 < ppinfo->pktlen)
230 { 233 {
231 switch (*(p + offset)) 234 switch (*(p + offset))
232 { 235 {
233 case E_SSID: 236 case E_SSID:
234 memcpy(&(pbody.ssid),p+offset,2); offset += 2; 237 memcpy(&(pbody.ssid),p+offset,2); offset += 2;
235 if (pbody.ssid.length > 0) 238 if (pbody.ssid.length > 0)
236 { 239 {
237 memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length; 240 memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length;
238 pbody.ssid.ssid[pbody.ssid.length]='\0'; 241 pbody.ssid.ssid[pbody.ssid.length]='\0';
239 if (strcmp((char *)pbody.ssid.ssid,"")==0) 242 if (strcmp((char *)pbody.ssid.ssid,"")==0)
240 memcpy(ppinfo->ssid, NONBROADCASTING, sizeof(ppinfo->ssid)); 243 memcpy(ppinfo->ssid, NONBROADCASTING, sizeof(ppinfo->ssid));
241 else 244 else
242 memcpy(ppinfo->ssid, pbody.ssid.ssid, sizeof(ppinfo->ssid)); 245 memcpy(ppinfo->ssid, pbody.ssid.ssid, sizeof(ppinfo->ssid));
243 ppinfo->ssid_len = pbody.ssid.length; 246 ppinfo->ssid_len = pbody.ssid.length;
244 } 247 }
245 break; 248 break;
246 249
247 case E_CHALLENGE: 250 case E_CHALLENGE:
248 memcpy(&(pbody.challenge),p+offset,2); offset += 2; 251 memcpy(&(pbody.challenge),p+offset,2); offset += 2;
249 if (pbody.challenge.length > 0) 252 if (pbody.challenge.length > 0)
250 { 253 {
251 memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length; 254 memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length;
252 pbody.challenge.text[pbody.challenge.length]='\0'; 255 pbody.challenge.text[pbody.challenge.length]='\0';
253 } 256 }
254 break; 257 break;
255 case E_RATES: 258 case E_RATES:
256 memcpy(&(pbody.rates),p+offset,2); offset += 2; 259 memcpy(&(pbody.rates),p+offset,2); offset += 2;
257 if (pbody.rates.length > 0) 260 if (pbody.rates.length > 0)
258 { 261 {
259 memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); offset += pbody.rates.length; 262 memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); offset += pbody.rates.length;
260 } 263 }
261 break; 264 break;
262 case E_DS: 265 case E_DS:
263 memcpy(&(pbody.ds),p+offset,3); offset +=3; 266 memcpy(&(pbody.ds),p+offset,3); offset +=3;
264 ppinfo->channel = pbody.ds.channel; 267 ppinfo->channel = pbody.ds.channel;
265 break; 268 break;
266 case E_CF: 269 case E_CF:
267 memcpy(&(pbody.cf),p+offset,8); offset +=8; 270 memcpy(&(pbody.cf),p+offset,8); offset +=8;
268 break; 271 break;
269 case E_TIM: 272 case E_TIM:
270 memcpy(&(pbody.tim),p+offset,2); offset +=2; 273 memcpy(&(pbody.tim),p+offset,2); offset +=2;
271 memcpy(&(pbody.tim.count),p+offset,3); offset +=3; 274 memcpy(&(pbody.tim.count),p+offset,3); offset +=3;
272 if ((pbody.tim.length -3) > 0) 275 if ((pbody.tim.length -3) > 0)
273 { 276 {
274 memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3)); 277 memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3));
275 offset += pbody.tim.length -3; 278 offset += pbody.tim.length -3;
276 } 279 }
277 break; 280 break;
278 default: 281 default:
279 282
280 offset+= *(p+offset+1) + 2; 283 offset+= *(p+offset+1) + 2;
281 break; 284 break;
282 } /* end of switch*/ 285 } /* end of switch*/
283 } /* end of for loop */ 286 } /* end of for loop */
284 return 0; 287 return 0;
285 288
286} /* End of handle_beacon */ 289} /* End of handle_beacon */
287 290
288 291
289int GetHeaderLength(u_int16_t fc) 292int GetHeaderLength(u_int16_t fc)
290{ 293{
291 int iLength=0; 294 int iLength=0;
292 295
293 switch (FC_TYPE(fc)) 296 switch (FC_TYPE(fc))
294 { 297 {
295 case T_MGMT: 298 case T_MGMT:
296 iLength = MGMT_HEADER_LEN; 299 iLength = MGMT_HEADER_LEN;
297 break; 300 break;
298 case T_CTRL: 301 case T_CTRL:
299 switch (FC_SUBTYPE(fc)) 302 switch (FC_SUBTYPE(fc))
300 { 303 {
301 case CTRL_PS_POLL: 304 case CTRL_PS_POLL:
302 iLength = CTRL_PS_POLL_LEN; 305 iLength = CTRL_PS_POLL_LEN;
303 break; 306 break;
304 case CTRL_RTS: 307 case CTRL_RTS:
305 iLength = CTRL_RTS_LEN; 308 iLength = CTRL_RTS_LEN;
306 break; 309 break;
307 case CTRL_CTS: 310 case CTRL_CTS:
308 iLength = CTRL_CTS_LEN; 311 iLength = CTRL_CTS_LEN;
309 break; 312 break;
310 case CTRL_ACK: 313 case CTRL_ACK:
311 iLength = CTRL_ACK_LEN; 314 iLength = CTRL_ACK_LEN;
312 break; 315 break;
313 case CTRL_CF_END: 316 case CTRL_CF_END:
314 iLength = CTRL_END_LEN; 317 iLength = CTRL_END_LEN;
315 break; 318 break;
316 case CTRL_END_ACK: 319 case CTRL_END_ACK:
317 iLength = CTRL_END_ACK_LEN; 320 iLength = CTRL_END_ACK_LEN;