summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/daemon/source/Makefile2
-rw-r--r--noncore/net/wellenreiter/daemon/source/TODO4
-rw-r--r--noncore/net/wellenreiter/daemon/source/cardmode.cc90
-rw-r--r--noncore/net/wellenreiter/daemon/source/cardmode.hh34
-rw-r--r--noncore/net/wellenreiter/daemon/source/config.hh7
-rw-r--r--noncore/net/wellenreiter/daemon/source/daemon.cc20
-rw-r--r--noncore/net/wellenreiter/daemon/source/daemon.hh3
-rw-r--r--noncore/net/wellenreiter/daemon/source/extract.hh60
-rw-r--r--noncore/net/wellenreiter/daemon/source/ieee802_11.hh250
-rw-r--r--noncore/net/wellenreiter/daemon/source/sniffer.cc308
-rw-r--r--noncore/net/wellenreiter/daemon/source/sniffer.hh64
11 files changed, 14 insertions, 828 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/Makefile b/noncore/net/wellenreiter/daemon/source/Makefile
index f3f41f0..f6efa3d 100644
--- a/noncore/net/wellenreiter/daemon/source/Makefile
+++ b/noncore/net/wellenreiter/daemon/source/Makefile
@@ -1,17 +1,17 @@
1# $Id$ 1# $Id$
2 2
3 CPP = g++ 3 CPP = g++
4 4
5 OPTIMFLAGS= -g 5 OPTIMFLAGS= -g
6 WARNFLAGS= -Wall -pedantic -DDEBUG 6 WARNFLAGS= -Wall -pedantic -DDEBUG
7 LDFLAGS = 7 LDFLAGS =
8 LIBS = -lpcap ../../libwellenreiter/source/libwellenreiter.a 8 LIBS = -lpcap ../../libwellenreiter/source/libwellenreiter.a
9 OBJ = daemon.o cardmode.o sniffer.o 9 OBJ = daemon.o
10 10
11.SUFFIXES: 11.SUFFIXES:
12 .PHONY: all wellenreiterd clean distclean realclean 12 .PHONY: all wellenreiterd clean distclean realclean
13 13
14%.o : %.cc 14%.o : %.cc
15 $(CPP) $(WARNFLAGS) $(OPTIMFLAGS) -c $< -o $@ 15 $(CPP) $(WARNFLAGS) $(OPTIMFLAGS) -c $< -o $@
16 16
17 all:wellenreiterd 17 all:wellenreiterd
diff --git a/noncore/net/wellenreiter/daemon/source/TODO b/noncore/net/wellenreiter/daemon/source/TODO
deleted file mode 100644
index 2d72ab7..0000000
--- a/noncore/net/wellenreiter/daemon/source/TODO
+++ b/dev/null
@@ -1,4 +0,0 @@
1implement communication protocol
2security analysis
3security analysis
4code cleanup \ No newline at end of file
diff --git a/noncore/net/wellenreiter/daemon/source/cardmode.cc b/noncore/net/wellenreiter/daemon/source/cardmode.cc
deleted file mode 100644
index 8069edc..0000000
--- a/noncore/net/wellenreiter/daemon/source/cardmode.cc
+++ b/dev/null
@@ -1,90 +0,0 @@
1/* $Id$ */
2
3#include "config.hh"
4#include "cardmode.hh"
5
6int card_into_monitormode (char *device, int cardtype)
7{
8
9 int datalink; /* used for getting the pcap datalink type */
10 char CiscoRFMON[35] = "/proc/driver/aironet/";
11 FILE *CISCO_CONFIG_FILE;
12 char errbuf[PCAP_ERRBUF_SIZE];
13 pcap_t *handle;
14
15 /* Checks if we have a device to sniff on */
16 if(device == NULL)
17 {
18 printf ("Fatal error i did not have any interfaces to sniff on\n");
19 return 0;
20 }
21
22 /* Setting the prmiscous and up flag to the interface */
23 if (card_set_promisc_up (device) == 0)
24 {
25 printf ("Interface flags correctly set using ifconfig\n");
26 }
27
28 /* Check the cardtype and executes the commands to go into monitor mode */
29 if (cardtype == CARD_TYPE_CISCO) /* I got a cisco card */
30 {
31 /* bring the sniffer into rfmon mode */
32 snprintf(CiscoRFMON, sizeof(CiscoRFMON),DEFAULT_PATH, device);
33 CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w");
34 fputs ("Mode: r",CISCO_CONFIG_FILE);
35 fputs ("Mode: y",CISCO_CONFIG_FILE);
36 fputs ("XmitPower: 1",CISCO_CONFIG_FILE);
37 fclose(CISCO_CONFIG_FILE);
38 }
39 else if (cardtype == CARD_TYPE_NG)
40 {
41 char wlanngcmd[62];
42 snprintf(wlanngcmd, sizeof(wlanngcmd),"%s %s lnxreq_wlansniff channel=1 enable=true",WLANCTL_PATH,device);
43 if (system (wlanngcmd) != 0)
44 {
45 printf ("\n Fatal error could not set %s in raw mode, check cardtype\n\n\tterminating now...\n\n",device);
46 exit(1);
47 }
48 }
49 else if (cardtype == CARD_TYPE_HOSTAP)
50 {
51 printf ("Got a host-ap card, nothing is implemented now\n");
52 }
53
54
55 /* Check the interface if it is in the correct raw mode */
56 handle = pcap_open_live(device, BUFSIZ, 1, 0, errbuf);
57
58 /* getting the datalink type */
59 datalink = pcap_datalink(handle);
60
61 if (datalink == DLT_IEEE802_11) /* Rawmode is IEEE802_11 */
62 {
63 printf ("Your successfully listen on %s in 802.11 raw mode\n",device);
64 pcap_close(handle);
65 return 0;
66
67 }
68 else
69 {
70 printf ("Fatal error, cannot continue, your interface %s does not work in the correct 802.11 raw mode, check you driver please\n\tterminating now",device);
71 pcap_close(handle);
72 exit(1);
73 }
74}
75
76
77
78int card_set_promisc_up (char * device)
79{
80 int ret;
81 char ifconfigcmd[32];
82 snprintf(ifconfigcmd,sizeof(ifconfigcmd),SBIN_PATH, device);
83 ret = system (ifconfigcmd);
84 if (ret > 0)
85 {
86 printf ("\nFatal error, could not execute %s please check your card,binary location and permission\n",ifconfigcmd);
87 return 0;
88 }
89 return 1;
90}
diff --git a/noncore/net/wellenreiter/daemon/source/cardmode.hh b/noncore/net/wellenreiter/daemon/source/cardmode.hh
deleted file mode 100644
index ecc97b1..0000000
--- a/noncore/net/wellenreiter/daemon/source/cardmode.hh
+++ b/dev/null
@@ -1,34 +0,0 @@
1/* $Id$ */
2
3#ifndef CARDMODE_HH
4#define CARDMODE_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/* Defines, used for the card setup */
17#define DEFAULT_PATH "/proc/driver/aironet/%s/Config"
18 #define CARD_TYPE_CISCO1
19 #define CARD_TYPE_NG2
20 #define CARD_TYPE_HOSTAP3
21
22/* only for now, until we have the daemon running */
23/*the config file should provide these information */
24 #define SNIFFER_DEVICE "wlan0"
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 (char * device, int cardtype);
32int card_set_promisc_up (char * device);
33
34#endif /* CARDMODE_HH */
diff --git a/noncore/net/wellenreiter/daemon/source/config.hh b/noncore/net/wellenreiter/daemon/source/config.hh
index b54ff46..42c56da 100644
--- a/noncore/net/wellenreiter/daemon/source/config.hh
+++ b/noncore/net/wellenreiter/daemon/source/config.hh
@@ -15,9 +15,16 @@
15#define VERSION "0.2" /* Version of wellenreiter */ 15#define VERSION "0.2" /* Version of wellenreiter */
16 16
17#define DAEMONADDR "127.0.0.1" 17#define DAEMONADDR "127.0.0.1"
18#define DAEMONPORT 37772 /* Port of Daemon */ 18#define DAEMONPORT 37772 /* Port of Daemon */
19 19
20#define GUIADDR "127.0.0.1" /* Adress of GUI, later specified in configfile */ 20#define GUIADDR "127.0.0.1" /* Adress of GUI, later specified in configfile */
21#define GUIPORT 37773 /* Port of GUI, " " */ 21#define GUIPORT 37773 /* Port of GUI, " " */
22 22
23
24/* Temporary cardmode stuff, will hopefully removed soon */
25#define CARD_TYPE_CISCO 1
26#define CARD_TYPE_NG 2
27#define CARD_TYPE_HOSTAP 3
28#define SNIFFER_DEVICE "wlan0"
29
23#endif /* CONFIG_HH */ 30#endif /* CONFIG_HH */
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc
index a2e1f96..75b2222 100644
--- a/noncore/net/wellenreiter/daemon/source/daemon.cc
+++ b/noncore/net/wellenreiter/daemon/source/daemon.cc
@@ -1,47 +1,35 @@
1/* 1/*
2 * Startup functions of wellenreiter 2 * Startup functions of wellenreiter
3 * 3 *
4 * $Id$ 4 * $Id$
5 */ 5 */
6 6
7#include "config.hh" 7#include "config.hh"
8#include "daemon.hh" 8#include "daemon.hh"
9#include "cardmode.hh"
10#include "sniffer.hh"
11 9
12/* Main function of wellenreiterd */ 10/* Main function of wellenreiterd */
13int main(int argc, char **argv) 11int main(int argc, char **argv)
14{ 12{
15 int sock, maxfd, retval; 13 int sock, maxfd, retval;
16 char buffer[128]; 14 char buffer[128];
17 pcap_t *handletopcap; /* The handle to the libpcap */ 15 pcap_t *handletopcap;
18 char errbuf[PCAP_ERRBUF_SIZE]; /* The errorbuffer of libpacap */
19 struct pcap_pkthdr header; /* The packet header from pcap*/
20 const u_char *packet; /* The actual packet content*/
21 16
22 fd_set rset; 17 fd_set rset;
23 18
24 fprintf(stderr, "wellenreiterd %s\n\n", VERSION); 19 fprintf(stderr, "wellenreiterd %s\n\n", VERSION);
25 20
26#if 0
27 /* will be replaced soon, just for max because max is lazy :-) */ 21 /* will be replaced soon, just for max because max is lazy :-) */
28 if(card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG) < 0) 22 if(!card_into_monitormode(handletopcap, SNIFFER_DEVICE, CARD_TYPE_NG))
29 { 23 {
30 fprintf(stderr, "Cannot set card into mon mode, aborting\n"); 24 wl_logerr("Cannot set card into mon mode, aborting");
31 exit(-1); 25 exit(-1);
32 } 26 }
33#endif 27 wl_loginfo("Set card into monitor mode");
34
35 /* opening the pcap for sniffing */
36 handletopcap = pcap_open_live(SNIFFER_DEVICE, BUFSIZ, 1, 1000, errbuf);
37#ifdef HAVE_PCAP_NONBLOCK
38 pcap_setnonblock(handletopcap, 1, errstr);
39#endif
40 28
41 /* Setup socket for incoming commands */ 29 /* Setup socket for incoming commands */
42 if((sock=commsock(DAEMONADDR, DAEMONPORT)) < 0) 30 if((sock=commsock(DAEMONADDR, DAEMONPORT)) < 0)
43 { 31 {
44 wl_logerr("Cannot setup socket"); 32 wl_logerr("Cannot setup socket");
45 exit(-1); 33 exit(-1);
46 } 34 }
47 wl_loginfo("Set up socket '%d' for GUI communication", sock); 35 wl_loginfo("Set up socket '%d' for GUI communication", sock);
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.hh b/noncore/net/wellenreiter/daemon/source/daemon.hh
index 12ba57e..09acf11 100644
--- a/noncore/net/wellenreiter/daemon/source/daemon.hh
+++ b/noncore/net/wellenreiter/daemon/source/daemon.hh
@@ -11,11 +11,12 @@
11#include <netinet/in.h> 11#include <netinet/in.h>
12#include <arpa/inet.h> 12#include <arpa/inet.h>
13#include <unistd.h> 13#include <unistd.h>
14#include <errno.h> 14#include <errno.h>
15 15
16#include "../../libwellenreiter/source/sock.hh" 16#include "../../libwellenreiter/source/sock.hh"
17#include "../../libwellenreiter/source/log.hh" 17#include "../../libwellenreiter/source/log.hh"
18#include "../../libwellenreiter/source/proto.hh" 18#include "../../libwellenreiter/source/proto.hh"
19 19#include "../../libwellenreiter/source/cardmode.hh"
20#include "../../libwellenreiter/source/sniff.hh"
20 21
21#endif /* DAEMON_HH */ 22#endif /* DAEMON_HH */
diff --git a/noncore/net/wellenreiter/daemon/source/extract.hh b/noncore/net/wellenreiter/daemon/source/extract.hh
deleted file mode 100644
index e900cfa..0000000
--- a/noncore/net/wellenreiter/daemon/source/extract.hh
+++ b/dev/null
@@ -1,60 +0,0 @@
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
50#define EXTRACT_LE_8BITS(p) (*(p))
51#define EXTRACT_LE_16BITS(p) \
52 ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \
53 (u_int16_t)*((const u_int8_t *)(p) + 0)))
54#define EXTRACT_LE_32BITS(p) \
55 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 3) << 24 | \
56 (u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \
57 (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \
58 (u_int32_t)*((const u_int8_t *)(p) + 0)))
59
60#endif /* EXTRACT_HH */
diff --git a/noncore/net/wellenreiter/daemon/source/ieee802_11.hh b/noncore/net/wellenreiter/daemon/source/ieee802_11.hh
deleted file mode 100644
index 3cc5343..0000000
--- a/noncore/net/wellenreiter/daemon/source/ieee802_11.hh
+++ b/dev/null
@@ -1,250 +0,0 @@
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/daemon/source/sniffer.cc b/noncore/net/wellenreiter/daemon/source/sniffer.cc
deleted file mode 100644
index 66d5b6f..0000000
--- a/noncore/net/wellenreiter/daemon/source/sniffer.cc
+++ b/dev/null
@@ -1,308 +0,0 @@
1/*
2 * rfmon mode sniffer
3 * This works only with cisco wireless cards with an rfmon
4 * able driver and not with wifi stuff.
5 *
6 * $Id$
7 */
8
9#include "config.hh"
10#include "cardmode.hh"
11#include "sniffer.hh"
12#include "ieee802_11.hh"
13#include "extract.hh"
14
15void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet)
16{
17 u_int caplen = pkthdr->caplen;
18 u_int length = pkthdr->len;
19 u_int16_t fc;
20 u_int HEADER_LENGTH;
21
22 /* pinfo holds all interresting information for us */
23 struct packetinfo pinfo;
24 struct packetinfo *pinfoptr;
25 pinfoptr=&pinfo;
26
27 pinfoptr->isvalid = 0;
28 pinfoptr->pktlen = pkthdr->len;
29
30 if (caplen < IEEE802_11_FC_LEN)
31 {
32 /* This is a garbage packet, because is does not long enough
33 to hold a 802.11b header */
34 pinfoptr->isvalid = 0;
35 return;
36 }
37
38 /* Gets the framecontrol bits (2bytes long) */
39 fc = EXTRACT_LE_16BITS(packet);
40
41 HEADER_LENGTH = GetHeaderLength(fc);
42
43 if (caplen < HEADER_LENGTH)
44 {
45 /* This is a garbage packet, because it is not long enough
46 to hold a correct header of its type */
47 pinfoptr->isvalid = 0;
48 return;
49 }
50
51 /* Decode 802.11b header out of the packet */
52 if (decode_80211b_hdr(packet,pinfoptr) == 0)
53 {
54 /* Justification of the ofset to further process the packet */
55 length -= HEADER_LENGTH;
56 caplen -= HEADER_LENGTH;
57 packet += HEADER_LENGTH;
58 }
59 else
60 { /* Something is wrong,could not be a correct packet */
61 return;
62 }
63
64 switch (FC_TYPE(fc))
65 {
66 /* Is it a managemnet frame? */
67 case T_MGMT:
68 switch (FC_SUBTYPE(fc))
69 { /* Is it a beacon frame? */
70 case ST_BEACON:
71 if (handle_beacon(fc, packet,pinfoptr) ==0)
72 {
73 if (!strcmp(pinfoptr->desthwaddr,"ff:ff:ff:ff:ff:ff") == 0)
74 {
75 /* Every beacon must have the broadcast as destination
76 so it must be a shitti packet */
77 pinfoptr->isvalid = 0;
78 return;
79 }
80
81 if (pinfoptr->cap_ESS == pinfoptr->cap_IBSS)
82 {
83 /* Only one of both are possible, so must be
84 a noise packet, if this comes up */
85 pinfoptr->isvalid = 0;
86 return;
87 }
88 if (pinfoptr->channel < 1 || pinfoptr->channel > 14)
89 {
90 /* Only channels between 1 and 14 are possible
91 others must be noise packets */
92 pinfoptr->isvalid = 0;
93 return;
94 }
95
96 /* Here should be the infos to the gui issued */
97 if (pinfoptr->cap_ESS == 1 &&pinfoptr->cap_IBSS ==0)
98 {
99 printf ("\nHave found an accesspoint:");
100 }
101 else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 1)
102 {
103 printf ("\nHave found an AD-HOC station:");
104
105 }
106 if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0)
107 {
108 printf ("\n\tOn a non-broadcasting network");
109 }
110 else
111 {
112 printf ("\n\tOn network : %s",pinfoptr->ssid);
113 }
114 printf ("\n\tLen SSID : %d",pinfoptr->ssid_len);
115 printf ("\n\tOn Channel : %d",pinfoptr->channel);
116 printf ("\n\tEncryption : %s", pinfoptr->cap_WEP ? "ON" : "OFF");
117 printf ("\n\tMacaddress : %s",pinfoptr->sndhwaddr);
118 printf ("\n\tBssid : %s",pinfoptr->bssid);
119 printf ("\n\tDest : %s\n",pinfoptr->desthwaddr);
120 }
121 break;
122 default:
123 printf("Unknown IEEE802.11 frame subtype (%d)",FC_SUBTYPE(fc));
124 break;
125 } /* End of switch over different mgt frame types */
126
127 break;
128 case T_CTRL:
129 //decode_control_frames(fc, packet);
130 printf ("Its a control frame");
131 break;
132 case T_DATA:
133 //decode_data_frames(fc, packet);
134 printf ("Its a date frame");
135 break;
136 default:
137 printf("Unknown IEEE802.11 frame type (%d)",FC_TYPE(fc));
138 break;
139 }
140}
141
142
143/* This decodes the 802.11b frame header out of the 802.11b packet
144 all the infos is placed into the packetinfo structure */
145int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo)
146{
147 const struct mgmt_header_t *mgthdr = (const struct mgmt_header_t *) p;
148 ppinfo->fcsubtype = FC_SUBTYPE(mgthdr->fc);
149
150 /* Get the sender, bssid and dest mac address */
151 etheraddr_string(mgthdr->bssid,ppinfo->bssid);
152 etheraddr_string(mgthdr->da,ppinfo->desthwaddr);
153 etheraddr_string(mgthdr->sa,ppinfo->sndhwaddr);
154 ppinfo->fc_wep = FC_WEP(mgthdr->fc);
155 return 0;
156}
157
158
159void etheraddr_string(register const u_char *ep,char * text)
160{
161 static char hex[] = "0123456789abcdef";
162 register u_int i, j;
163 register char *cp;
164 char buf[sizeof("00:00:00:00:00:00")];
165 cp = buf;
166 if ((j = *ep >> 4) != 0)
167 *cp++ = hex[j];
168 *cp++ = hex[*ep++ & 0xf];
169 for (i = 5; (int)--i >= 0;) {
170 *cp++ = ':';
171 if ((j = *ep >> 4) != 0)
172 *cp++ = hex[j];
173 *cp++ = hex[*ep++ & 0xf];
174 }
175 *cp = '\0';
176 strcpy(text,buf);
177}
178
179int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo)
180{
181 struct mgmt_body_t pbody;
182 int offset = 0;
183
184 /* Get the static informations out of the packet */
185 memset(&pbody, 0, sizeof(pbody));
186 memcpy(&pbody.timestamp, p, 8);
187 offset += 8;
188 pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset);
189 offset += 2;
190 pbody.capability_info = EXTRACT_LE_16BITS(p+offset);
191 offset += 2;
192
193 /* Gets the different flags out of the capabilities */
194 ppinfo->cap_ESS = CAPABILITY_ESS(pbody.capability_info);
195 ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info);
196 ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info);
197
198 /* Gets the tagged elements out of the packets */
199 while (offset + 1 < ppinfo->pktlen)
200 {
201 switch (*(p + offset))
202 {
203 case E_SSID:
204 memcpy(&(pbody.ssid),p+offset,2); offset += 2;
205 if (pbody.ssid.length > 0)
206 {
207 memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length;
208 pbody.ssid.ssid[pbody.ssid.length]='\0';
209 if (strcmp((char *)pbody.ssid.ssid,"")==0)
210 {
211 ppinfo->ssid = NONBROADCASTING;
212 }
213 else
214 {
215 ppinfo->ssid = (char *)pbody.ssid.ssid;
216 }
217 ppinfo->ssid_len = pbody.ssid.length;
218 }
219 break;
220
221 case E_CHALLENGE:
222 memcpy(&(pbody.challenge),p+offset,2); offset += 2;
223 if (pbody.challenge.length > 0)
224 {
225 memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length;
226 pbody.challenge.text[pbody.challenge.length]='\0';
227 }
228 break;
229 case E_RATES:
230 memcpy(&(pbody.rates),p+offset,2); offset += 2;
231 if (pbody.rates.length > 0) {
232 memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); offset += pbody.rates.length;
233 }
234 break;
235 case E_DS:
236 memcpy(&(pbody.ds),p+offset,3); offset +=3;
237 ppinfo->channel = pbody.ds.channel;
238 break;
239 case E_CF:
240 memcpy(&(pbody.cf),p+offset,8); offset +=8;
241 break;
242 case E_TIM:
243 memcpy(&(pbody.tim),p+offset,2); offset +=2;
244 memcpy(&(pbody.tim.count),p+offset,3); offset +=3;
245 if ((pbody.tim.length -3) > 0)
246 {
247 memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3));
248 offset += pbody.tim.length -3;
249 }
250 break;
251 default:
252
253 offset+= *(p+offset+1) + 2;
254 break;
255 } /* end of switch*/
256 } /* end of for loop */
257 return 0;
258
259} /* End of handle_beacon */
260
261
262int GetHeaderLength(u_int16_t fc)
263{
264 int iLength=0;
265
266 switch (FC_TYPE(fc)) {
267 case T_MGMT:
268 iLength = MGMT_HEADER_LEN;
269 break;
270 case T_CTRL:
271 switch (FC_SUBTYPE(fc)) {
272 case CTRL_PS_POLL:
273 iLength = CTRL_PS_POLL_LEN;
274 break;
275 case CTRL_RTS:
276 iLength = CTRL_RTS_LEN;
277 break;
278 case CTRL_CTS:
279 iLength = CTRL_CTS_LEN;
280 break;
281 case CTRL_ACK:
282 iLength = CTRL_ACK_LEN;
283 break;
284 case CTRL_CF_END:
285 iLength = CTRL_END_LEN;
286 break;
287 case CTRL_END_ACK:
288 iLength = CTRL_END_ACK_LEN;
289 break;
290 default:
291 iLength = 0;
292 break;
293 }
294 break;
295 case T_DATA:
296 if (FC_TO_DS(fc) && FC_FROM_DS(fc))
297 iLength = 30;
298 else
299 iLength = 24;
300 break;
301 default:
302 printf("unknown IEEE802.11 frame type (%d)",
303 FC_TYPE(fc));
304 break;
305 }
306
307 return iLength;
308}
diff --git a/noncore/net/wellenreiter/daemon/source/sniffer.hh b/noncore/net/wellenreiter/daemon/source/sniffer.hh
deleted file mode 100644
index 7e1e3be..0000000
--- a/noncore/net/wellenreiter/daemon/source/sniffer.hh
+++ b/dev/null
@@ -1,64 +0,0 @@
1/* $Id$ */
2
3#ifndef SNIFFER_HH
4#define SNIFFER_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(u_char *useless,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 /* SNIFFER_HH */