summaryrefslogtreecommitdiff
path: root/noncore
Unidiff
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/Makefile2
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc97
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh34
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/extract.hh59
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/ieee802_11.hh250
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/sniff.cc303
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/sniff.hh64
7 files changed, 808 insertions, 1 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/Makefile b/noncore/net/wellenreiter/libwellenreiter/source/Makefile
index 05a5bd3..3670d96 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/Makefile
+++ b/noncore/net/wellenreiter/libwellenreiter/source/Makefile
@@ -2,7 +2,7 @@
2 2
3INCLUDES = 3INCLUDES =
4LIBRARIES = 4LIBRARIES =
5LIBOBJ = sock.o log.o 5LIBOBJ = proto.o sock.o log.o cardmode.o sniff.o
6CXX = g++ -Wall -pedantic -g $(INCLUDES) -DDEBUG 6CXX = g++ -Wall -pedantic -g $(INCLUDES) -DDEBUG
7 7
8 static:libwellenreiter.a 8 static:libwellenreiter.a
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
new file mode 100644
index 0000000..62c2940
--- a/dev/null
+++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
@@ -0,0 +1,97 @@
1/*
2 * Set card modes for sniffing
3 *
4 * $Id$
5 */
6
7#include "cardmode.hh"
8
9/* main card into monitor function */
10int card_into_monitormode (void *orighandle, char *device, int cardtype)
11{
12 int datalink; /* used for getting the pcap datalink type */
13 char CiscoRFMON[35] = "/proc/driver/aironet/";
14 FILE *CISCO_CONFIG_FILE;
15 char errbuf[PCAP_ERRBUF_SIZE];
16 pcap_t *handle;
17
18 handle = (pcap_t *)orighandle;
19
20 /* Checks if we have a device to sniff on */
21 if(device == NULL)
22 {
23 wl_logerr("No device given");
24 return 0;
25 }
26
27 /* Setting the prmiscous and up flag to the interface */
28 if (!card_set_promisc_up(device))
29 {
30 wl_logerr("Cannot set interface to promisc mode: %s", strerror(errno));
31 return 0;
32 }
33 wl_loginfo("Interface set to promisc mode");
34
35 /* Check the cardtype and executes the commands to go into monitor mode */
36 if (cardtype == CARD_TYPE_CISCO)
37 {
38 /* bring the sniffer into rfmon mode */
39 snprintf(CiscoRFMON, sizeof(CiscoRFMON), DEFAULT_PATH, device);
40 if((CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w")) == NULL)
41 {
42 wl_logerr("Cannot open config file: %s", strerror(errno));
43 return 0;
44 }
45 fputs ("Mode: r",CISCO_CONFIG_FILE);
46 fputs ("Mode: y",CISCO_CONFIG_FILE);
47 fputs ("XmitPower: 1",CISCO_CONFIG_FILE);
48 fclose(CISCO_CONFIG_FILE);
49 }
50 else if (cardtype == CARD_TYPE_NG)
51 {
52 char wlanngcmd[62];
53 snprintf(wlanngcmd, sizeof(wlanngcmd), "%s %s lnxreq_wlansniff channel=1 enable=true", WLANCTL_PATH, device);
54 if (system(wlanngcmd) != 0)
55 {
56 wl_logerr("Could not set %s in raw mode, check cardtype", device);
57 return 0;
58 }
59 }
60 else if (cardtype == CARD_TYPE_HOSTAP)
61 {
62 wl_logerr("Got a host-ap card, nothing is implemented now");
63 }
64
65 /* Check the interface if it is in the correct raw mode */
66 if((handle = pcap_open_live(device, BUFSIZ, 1, 0, errbuf)) == NULL)
67 {
68 wl_logerr("pcap_open_live() failed: %s", strerror(errno));
69 return 0;
70 }
71
72#ifdef HAVE_PCAP_NONBLOCK
73 pcap_setnonblock(handle, 1, errstr);
74#endif
75
76 /* getting the datalink type */
77 datalink = pcap_datalink(handle);
78
79 if (datalink != DLT_IEEE802_11) /* Rawmode is IEEE802_11 */
80 {
81 wl_loginfo("Interface %s does not work in the correct 802.11 raw mode", device);
82 pcap_close(handle);
83 return 0;
84 }
85 wl_loginfo("Your successfully listen on %s in 802.11 raw mode", device);
86
87 return 1;
88}
89
90/* Set card into promisc mode */
91int card_set_promisc_up (const char *device)
92{
93 char ifconfigcmd[32];
94 snprintf(ifconfigcmd, sizeof(ifconfigcmd), SBIN_PATH, device);
95
96 return (system(ifconfigcmd) ? 1 : 0);
97}
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
new file mode 100644
index 0000000..d80b24b
--- a/dev/null
+++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
@@ -0,0 +1,34 @@
1/* $Id$ */
2
3#ifndef CARDMODE_HH
4#define CARDMODE_HH
5
6#include <string.h>
7#include <stdlib.h>
8#include <pcap.h>
9#include <errno.h>
10#include <sys/socket.h>
11#include <netinet/in.h>
12#include <arpa/inet.h>
13#include <net/bpf.h>
14
15#include "../../libwellenreiter/source/log.hh"
16
17/* Defines, used for the card setup */
18#define DEFAULT_PATH "/proc/driver/aironet/%s/Config"
19 #define CARD_TYPE_CISCO1
20 #define CARD_TYPE_NG 2
21 #define CARD_TYPE_HOSTAP3
22
23/* only for now, until we have the daemon running */
24/*the config file should provide these information */
25#define CARD_TYPE CARD_TYPE_CISCO
26 #define SBIN_PATH "/sbin/ifconfig %s promisc up"
27#define WLANCTL_PATH "/sbin/wlanctl-ng"
28
29/* Prototypes */
30
31int card_into_monitormode (void *, char *, int);
32int card_set_promisc_up (const char *);
33
34#endif /* CARDMODE_HH */
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/extract.hh b/noncore/net/wellenreiter/libwellenreiter/source/extract.hh
new file mode 100644
index 0000000..f948bcb
--- a/dev/null
+++ b/noncore/net/wellenreiter/libwellenreiter/source/extract.hh
@@ -0,0 +1,59 @@
1/* $Id$ */
2/*
3 * Copyright (c) 1992, 1993, 1994, 1995, 1996
4 *The Regents of the University of California. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that: (1) source code distributions
8 * retain the above copyright notice and this paragraph in its entirety, (2)
9 * distributions including binary code include the above copyright notice and
10 * this paragraph in its entirety in the documentation or other materials
11 * provided with the distribution, and (3) all advertising materials mentioning
12 * features or use of this software display the following acknowledgement:
13 * ``This product includes software developed by the University of California,
14 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
15 * the University nor the names of its contributors may be used to endorse
16 * or promote products derived from this software without specific prior
17 * written permission.
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 */
22/* Network to host order macros */
23
24#ifndef EXTRACT_HH
25#define EXTRACT_HH
26
27#ifdef LBL_ALIGN
28#define EXTRACT_16BITS(p) \
29 ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \
30 (u_int16_t)*((const u_int8_t *)(p) + 1)))
31#define EXTRACT_32BITS(p) \
32 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \
33 (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \
34 (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \
35 (u_int32_t)*((const u_int8_t *)(p) + 3)))
36#else
37#define EXTRACT_16BITS(p) \
38 ((u_int16_t)ntohs(*(const u_int16_t *)(p)))
39#define EXTRACT_32BITS(p) \
40 ((u_int32_t)ntohl(*(const u_int32_t *)(p)))
41#endif
42
43#define EXTRACT_24BITS(p) \
44 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \
45 (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \
46 (u_int32_t)*((const u_int8_t *)(p) + 2)))
47
48/* Little endian protocol host order macros */
49#define EXTRACT_LE_8BITS(p) (*(p))
50#define EXTRACT_LE_16BITS(p) \
51 ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \
52 (u_int16_t)*((const u_int8_t *)(p) + 0)))
53#define EXTRACT_LE_32BITS(p) \
54 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 3) << 24 | \
55 (u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \
56 (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \
57 (u_int32_t)*((const u_int8_t *)(p) + 0)))
58
59#endif /* EXTRACT_HH */
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/ieee802_11.hh b/noncore/net/wellenreiter/libwellenreiter/source/ieee802_11.hh
new file mode 100644
index 0000000..872fd40
--- a/dev/null
+++ b/noncore/net/wellenreiter/libwellenreiter/source/ieee802_11.hh
@@ -0,0 +1,250 @@
1/* $Id$ */
2/*
3 * Copyright (c) 2001
4 *Fortress Technologies
5 * Charlie Lenahan ( clenahan@fortresstech.com )
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
18 * written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 */
23
24#ifndef IEEE802_11_HH
25#define IEEE802_11_HH
26
27 #define IEEE802_11_FC_LEN2
28
29#define T_MGMT 0x0 /* management */
30#define T_CTRL 0x1 /* control */
31#define T_DATA 0x2 /* data */
32#define T_RESV 0x3 /* reserved */
33
34 #define ST_ASSOC_REQUEST 0x0
35 #define ST_ASSOC_RESPONSE 0x1
36 #define ST_REASSOC_REQUEST 0x2
37 #define ST_REASSOC_RESPONSE 0x3
38 #define ST_PROBE_REQUEST 0x4
39 #define ST_PROBE_RESPONSE 0x5
40 /* RESERVED 0x6 */
41 /* RESERVED 0x7 */
42 #define ST_BEACON 0x8
43 #define ST_ATIM 0x9
44 #define ST_DISASSOC 0xA
45 #define ST_AUTH 0xB
46 #define ST_DEAUTH 0xC
47 /* RESERVED 0xD */
48 /* RESERVED 0xE */
49 /* RESERVED 0xF */
50
51
52 #define CTRL_PS_POLL0xA
53 #define CTRL_RTS0xB
54 #define CTRL_CTS0xC
55 #define CTRL_ACK0xD
56 #define CTRL_CF_END0xE
57 #define CTRL_END_ACK0xF
58
59/*
60 * Bits in the frame control field.
61 */
62 #define FC_VERSION(fc) ((fc) & 0x3)
63 #define FC_TYPE(fc) (((fc) >> 2) & 0x3)
64 #define FC_SUBTYPE(fc) (((fc) >> 4) & 0xF)
65 #define FC_TO_DS(fc) ((fc) & 0x0100)
66 #define FC_FROM_DS(fc) ((fc) & 0x0200)
67 #define FC_MORE_FLAG(fc)((fc) & 0x0400)
68 #define FC_RETRY(fc) ((fc) & 0x0800)
69 #define FC_POWER_MGMT(fc)((fc) & 0x1000)
70 #define FC_MORE_DATA(fc)((fc) & 0x2000)
71 #define FC_WEP(fc) ((fc) & 0x4000)
72 #define FC_ORDER(fc) ((fc) & 0x8000)
73
74struct mgmt_header_t {
75 u_int16_tfc;
76 u_int16_t duration;
77 u_int8_tda[6];
78 u_int8_tsa[6];
79 u_int8_tbssid[6];
80 u_int16_tseq_ctrl;
81};
82
83 #define MGMT_HEADER_LEN(2+2+6+6+6+2)
84
85 #define CAPABILITY_ESS(cap)((cap) & 0x0001)
86 #define CAPABILITY_IBSS(cap)((cap) & 0x0002)
87 #define CAPABILITY_CFP(cap)((cap) & 0x0004)
88 #define CAPABILITY_CFP_REQ(cap)((cap) & 0x0008)
89 #define CAPABILITY_PRIVACY(cap)((cap) & 0x0010)
90
91struct ssid_t {
92 u_int8_telement_id;
93 u_int8_tlength;
94 u_char ssid[33]; /* 32 + 1 for null */
95} ;
96
97struct rates_t {
98 u_int8_telement_id;
99 u_int8_tlength;
100 u_int8_trate[8];
101};
102
103struct challenge_t {
104 u_int8_telement_id;
105 u_int8_tlength;
106 u_int8_ttext[254]; /* 1-253 + 1 for null */
107};
108struct fh_t {
109 u_int8_telement_id;
110 u_int8_tlength;
111 u_int16_tdwell_time;
112 u_int8_thop_set;
113 u_int8_t hop_pattern;
114 u_int8_thop_index;
115};
116
117struct ds_t {
118 u_int8_telement_id;
119 u_int8_tlength;
120 u_int8_tchannel;
121};
122
123struct cf_t {
124 u_int8_telement_id;
125 u_int8_tlength;
126 u_int8_tcount;
127 u_int8_tperiod;
128 u_int16_tmax_duration;
129 u_int16_tdur_remaing;
130};
131
132struct tim_t {
133 u_int8_telement_id;
134 u_int8_tlength;
135 u_int8_tcount;
136 u_int8_tperiod;
137 u_int8_tbitmap_control;
138 u_int8_tbitmap[251];
139};
140
141 #define E_SSID 0
142 #define E_RATES 1
143 #define E_FH 2
144 #define E_DS 3
145 #define E_CF 4
146 #define E_TIM 5
147 #define E_IBSS 6
148 #define E_CISCO 133
149 /* reserved 7 */
150 /* reserved 8 */
151 /* reserved 9 */
152 /* reserved 10 */
153 /* reserved 11 */
154 /* reserved 12 */
155 /* reserved 13 */
156 /* reserved 14 */
157 /* reserved 15 */
158 /* reserved 16 */
159
160 #define E_CHALLENGE 16
161 /* reserved 17 */
162 /* reserved 18 */
163 /* reserved 19 */
164 /* reserved 16 */
165 /* reserved 16 */
166
167
168struct mgmt_body_t {
169 u_int8_t timestamp[8];
170 u_int16_t beacon_interval;
171 u_int16_t listen_interval;
172 u_int16_t status_code;
173 u_int16_t aid;
174 u_char ap[6];
175 u_int16_treason_code;
176 u_int16_tauth_alg;
177 u_int16_tauth_trans_seq_num;
178 struct challenge_t challenge;
179 u_int16_tcapability_info;
180 struct ssid_tssid;
181 struct rates_t rates;
182 struct ds_tds;
183 struct cf_tcf;
184 struct fh_tfh;
185 struct tim_ttim;
186};
187
188struct ctrl_rts_t {
189 u_int16_tfc;
190 u_int16_tduration;
191 u_int8_tra[6];
192 u_int8_tta[6];
193 u_int8_tfcs[4];
194};
195
196 #define CTRL_RTS_LEN(2+2+6+6+4)
197
198struct ctrl_cts_t {
199 u_int16_tfc;
200 u_int16_tduration;
201 u_int8_tra[6];
202 u_int8_tfcs[4];
203};
204
205 #define CTRL_CTS_LEN(2+2+6+4)
206
207struct ctrl_ack_t {
208 u_int16_tfc;
209 u_int16_tduration;
210 u_int8_tra[6];
211 u_int8_tfcs[4];
212};
213
214 #define CTRL_ACK_LEN(2+2+6+4)
215
216struct ctrl_ps_poll_t {
217 u_int16_tfc;
218 u_int16_taid;
219 u_int8_tbssid[6];
220 u_int8_tta[6];
221 u_int8_tfcs[4];
222};
223
224 #define CTRL_PS_POLL_LEN(2+2+6+6+4)
225
226struct ctrl_end_t {
227 u_int16_tfc;
228 u_int16_tduration;
229 u_int8_tra[6];
230 u_int8_tbssid[6];
231 u_int8_tfcs[4];
232};
233
234 #define CTRL_END_LEN(2+2+6+6+4)
235
236struct ctrl_end_ack_t {
237 u_int16_tfc;
238 u_int16_tduration;
239 u_int8_tra[6];
240 u_int8_tbssid[6];
241 u_int8_tfcs[4];
242};
243
244 #define CTRL_END_ACK_LEN(2+2+6+6+4)
245
246 #define IV_IV(iv)((iv) & 0xFFFFFF)
247 #define IV_PAD(iv)(((iv) >> 24) & 0x3F)
248 #define IV_KEYID(iv)(((iv) >> 30) & 0x03)
249
250#endif /* IEEE802_11_HH */
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc b/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc
new file mode 100644
index 0000000..fedd8fc
--- a/dev/null
+++ b/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc
@@ -0,0 +1,303 @@
1/*
2 * rfmon mode sniffer
3 *
4 * $Id$
5 */
6
7#include "sniff.hh"
8#include "ieee802_11.hh"
9#include "extract.hh"
10#include "log.hh"
11
12/* Main function, checks packets */
13void process_packets(const struct pcap_pkthdr *pkthdr, const unsigned char *packet)
14{
15 unsigned int caplen = pkthdr->caplen;
16 unsigned int length = pkthdr->len;
17 u_int16_t fc;
18 unsigned int HEADER_LENGTH;
19
20 /* pinfo holds all interresting information for us */
21 struct packetinfo pinfo;
22 struct packetinfo *pinfoptr;
23 pinfoptr=&pinfo;
24
25 pinfoptr->isvalid = 0;
26 pinfoptr->pktlen = pkthdr->len;
27
28 if (caplen < IEEE802_11_FC_LEN)
29 {
30 /* This is a garbage packet, because is does not long enough
31 to hold a 802.11b header */
32 pinfoptr->isvalid = 0;
33 return;
34 }
35
36 /* Gets the framecontrol bits (2bytes long) */
37 fc = EXTRACT_LE_16BITS(packet);
38
39 HEADER_LENGTH = GetHeaderLength(fc);
40
41 if (caplen < HEADER_LENGTH)
42 {
43 /* This is a garbage packet, because it is not long enough
44 to hold a correct header of its type */
45 pinfoptr->isvalid = 0;
46 return;
47 }
48
49 /* Decode 802.11b header out of the packet */
50 if (decode_80211b_hdr(packet,pinfoptr) == 0)
51 {
52 /* Justification of the ofset to further process the packet */
53 length -= HEADER_LENGTH;
54 caplen -= HEADER_LENGTH;
55 packet += HEADER_LENGTH;
56 }
57 else /* Something is wrong,could not be a correct packet */
58 return;
59
60 switch (FC_TYPE(fc))
61 {
62 /* Is it a managemnet frame? */
63 case T_MGMT:
64 switch (FC_SUBTYPE(fc))
65 {
66 case ST_BEACON:
67 if (handle_beacon(fc, packet,pinfoptr) ==0)
68 {
69 if (!strcmp(pinfoptr->desthwaddr,"ff:ff:ff:ff:ff:ff") == 0)
70 {
71 /* Every beacon must have the broadcast as destination
72 so it must be a shitti packet */
73 pinfoptr->isvalid = 0;
74 return;
75 }
76
77 if (pinfoptr->cap_ESS == pinfoptr->cap_IBSS)
78 {
79 /* Only one of both are possible, so must be
80 a noise packet, if this comes up */
81 pinfoptr->isvalid = 0;
82 return;
83 }
84 if (pinfoptr->channel < 1 || pinfoptr->channel > 14)
85 {
86 /* Only channels between 1 and 14 are possible
87 others must be noise packets */
88 pinfoptr->isvalid = 0;
89 return;
90 }
91
92
93 /* Here should be the infos to the gui issued */
94 if (pinfoptr->cap_ESS == 1 &&pinfoptr->cap_IBSS ==0)
95 {
96 printf ("\nHave found an accesspoint:");
97 }
98 else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 1)
99 {
100 printf ("\nHave found an AD-HOC station:");
101
102 }
103 if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0)
104 {
105 printf ("\n\tOn a non-broadcasting network");
106 }
107 else
108 {
109 printf ("\n\tOn network : %s",pinfoptr->ssid);
110 }
111 printf ("\n\tLen SSID : %d",pinfoptr->ssid_len);
112 printf ("\n\tOn Channel : %d",pinfoptr->channel);
113 printf ("\n\tEncryption : %s", pinfoptr->cap_WEP ? "ON" : "OFF");
114 printf ("\n\tMacaddress : %s",pinfoptr->sndhwaddr);
115 printf ("\n\tBssid : %s",pinfoptr->bssid);
116 printf ("\n\tDest : %s\n",pinfoptr->desthwaddr);
117 }
118 break;
119 default:
120 wl_logerr("Unknown IEEE802.11 frame subtype (%d)", FC_SUBTYPE(fc));
121 break;
122 } /* End of switch over different mgt frame types */
123
124 break;
125
126 case T_CTRL:
127 wl_loginfo("Received control frame, not implemented yet");
128 break;
129
130 case T_DATA:
131 wl_loginfo("Received date frame, not implemented yet");
132 break;
133
134 default:
135 wl_logerr("Unknown IEEE802.11 frame type (%d)", FC_TYPE(fc));
136 break;
137 }
138}
139
140/* This decodes the 802.11b frame header out of the 802.11b packet
141 all the infos is placed into the packetinfo structure */
142int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo)
143{
144 const struct mgmt_header_t *mgthdr = (const struct mgmt_header_t *) p;
145 ppinfo->fcsubtype = FC_SUBTYPE(mgthdr->fc);
146
147 /* Get the sender, bssid and dest mac address */
148 etheraddr_string(mgthdr->bssid,ppinfo->bssid);
149 etheraddr_string(mgthdr->da,ppinfo->desthwaddr);
150 etheraddr_string(mgthdr->sa,ppinfo->sndhwaddr);
151 ppinfo->fc_wep = FC_WEP(mgthdr->fc);
152 return 0;
153}
154
155
156void etheraddr_string(register const u_char *ep, char *text)
157{
158 static char hex[] = "0123456789abcdef";
159 register unsigned int i, j;
160 register char *cp;
161 char buf[sizeof("00:00:00:00:00:00")];
162 cp = buf;
163 if ((j = *ep >> 4) != 0)
164 *cp++ = hex[j];
165 *cp++ = hex[*ep++ & 0xf];
166 for (i = 5; (int)--i >= 0;) {
167 *cp++ = ':';
168 if ((j = *ep >> 4) != 0)
169 *cp++ = hex[j];
170 *cp++ = hex[*ep++ & 0xf];
171 }
172 *cp = '\0';
173 strcpy(text,buf);
174}
175
176/* beacon handler */
177int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo)
178{
179 struct mgmt_body_t pbody;
180 int offset = 0;
181
182 /* Get the static informations out of the packet */
183 memset(&pbody, 0, sizeof(pbody));
184 memcpy(&pbody.timestamp, p, 8);
185 offset += 8;
186 pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset);
187 offset += 2;
188 pbody.capability_info = EXTRACT_LE_16BITS(p+offset);
189 offset += 2;
190
191 /* Gets the different flags out of the capabilities */
192 ppinfo->cap_ESS = CAPABILITY_ESS(pbody.capability_info);
193 ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info);
194 ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info);
195
196 /* Gets the tagged elements out of the packets */
197 while (offset + 1 < ppinfo->pktlen)
198 {
199 switch (*(p + offset))
200 {
201 case E_SSID:
202 memcpy(&(pbody.ssid),p+offset,2); offset += 2;
203 if (pbody.ssid.length > 0)
204 {
205 memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length;
206 pbody.ssid.ssid[pbody.ssid.length]='\0';
207 if (strcmp((char *)pbody.ssid.ssid,"")==0)
208 ppinfo->ssid = NONBROADCASTING;
209 else
210 ppinfo->ssid = (char *)pbody.ssid.ssid;
211 ppinfo->ssid_len = pbody.ssid.length;
212 }
213 break;
214
215 case E_CHALLENGE:
216 memcpy(&(pbody.challenge),p+offset,2); offset += 2;
217 if (pbody.challenge.length > 0)
218 {
219 memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length;
220 pbody.challenge.text[pbody.challenge.length]='\0';
221 }
222 break;
223 case E_RATES:
224 memcpy(&(pbody.rates),p+offset,2); offset += 2;
225 if (pbody.rates.length > 0)
226 {
227 memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); offset += pbody.rates.length;
228 }
229 break;
230 case E_DS:
231 memcpy(&(pbody.ds),p+offset,3); offset +=3;
232 ppinfo->channel = pbody.ds.channel;
233 break;
234 case E_CF:
235 memcpy(&(pbody.cf),p+offset,8); offset +=8;
236 break;
237 case E_TIM:
238 memcpy(&(pbody.tim),p+offset,2); offset +=2;
239 memcpy(&(pbody.tim.count),p+offset,3); offset +=3;
240 if ((pbody.tim.length -3) > 0)
241 {
242 memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3));
243 offset += pbody.tim.length -3;
244 }
245 break;
246 default:
247
248 offset+= *(p+offset+1) + 2;
249 break;
250 } /* end of switch*/
251 } /* end of for loop */
252 return 0;
253
254} /* End of handle_beacon */
255
256
257int GetHeaderLength(u_int16_t fc)
258{
259 int iLength=0;
260
261 switch (FC_TYPE(fc))
262 {
263 case T_MGMT:
264 iLength = MGMT_HEADER_LEN;
265 break;
266 case T_CTRL:
267 switch (FC_SUBTYPE(fc))
268 {
269 case CTRL_PS_POLL:
270 iLength = CTRL_PS_POLL_LEN;
271 break;
272 case CTRL_RTS:
273 iLength = CTRL_RTS_LEN;
274 break;
275 case CTRL_CTS:
276 iLength = CTRL_CTS_LEN;
277 break;
278 case CTRL_ACK:
279 iLength = CTRL_ACK_LEN;
280 break;
281 case CTRL_CF_END:
282 iLength = CTRL_END_LEN;
283 break;
284 case CTRL_END_ACK:
285 iLength = CTRL_END_ACK_LEN;
286 break;
287 default:
288 iLength = 0;
289 break;
290 }
291 break;
292 case T_DATA:
293 if (FC_TO_DS(fc) && FC_FROM_DS(fc))
294 iLength = 30;
295 else
296 iLength = 24;
297 break;
298 default:
299 wl_logerr("unknown IEEE802.11 frame type (%d)", FC_TYPE(fc));
300 break;
301 }
302 return iLength;
303}
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh b/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh
new file mode 100644
index 0000000..fa8519b
--- a/dev/null
+++ b/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh
@@ -0,0 +1,64 @@
1/* $Id$ */
2
3#ifndef SNIFF_HH
4#define SNIFF_HH
5
6#include <string.h>
7#include <stdio.h>
8#include <stdlib.h>
9#include <pcap.h>
10#include <errno.h>
11#include <sys/socket.h>
12#include <netinet/in.h>
13#include <arpa/inet.h>
14#include <net/bpf.h>
15
16#define NONBROADCASTING "non-broadcasting"
17
18/* holds all the interresting data */
19struct packetinfo
20{
21 int isvalid;
22 int pktlen;
23 int fctype;
24 int fcsubtype;
25 int fc_wep;
26 int cap_WEP;
27 int cap_IBSS;
28 int cap_ESS;
29 int channel;
30 char bssid[sizeof("00:00:00:00:00:00")];
31 char desthwaddr[sizeof("00:00:00:00:00:00")];
32 char sndhwaddr[sizeof("00:00:00:00:00:00")];
33 char *ssid;
34 int ssid_len;
35};
36
37void process_packets(const struct pcap_pkthdr* pkthdr,const u_char* packet);
38int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo);
39void etheraddr_string(register const u_char *ep,char * text);
40int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo);
41
42int GetHeaderLength(u_int16_t fc);
43
44/*
45 * True if "l" bytes of "var" were captured.
46 *
47 * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large
48 * that "snapend - (l)" underflows.
49 *
50 * The check is for <= rather than < because "l" might be 0.
51 */
52#define TTEST2(var, l) (snapend - (l) <= snapend && \
53 (const u_char *)&(var) <= snapend - (l))
54
55/* True if "var" was captured */
56#define TTEST(var) TTEST2(var, sizeof(var))
57
58/* Bail if "l" bytes of "var" were not captured */
59#define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc
60
61/* Bail if "var" was not captured */
62#define TCHECK(var) TCHECK2(var, sizeof(var))
63
64#endif /* SNIFF_HH */