Diffstat (limited to 'noncore/net/wellenreiter/daemon/source/cardmode.cc') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/cardmode.cc | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/cardmode.cc b/noncore/net/wellenreiter/daemon/source/cardmode.cc new file mode 100644 index 0000000..ae32af4 --- a/dev/null +++ b/noncore/net/wellenreiter/daemon/source/cardmode.cc | |||
@@ -0,0 +1,89 @@ | |||
1 | /* $Id$ */ | ||
2 | |||
3 | #include "cardmode.hh" | ||
4 | |||
5 | int card_into_monitormode (char *device, int cardtype) | ||
6 | { | ||
7 | |||
8 | int datalink; /* used for getting the pcap datalink type */ | ||
9 | char CiscoRFMON[35] = "/proc/driver/aironet/"; | ||
10 | FILE *CISCO_CONFIG_FILE; | ||
11 | char errbuf[PCAP_ERRBUF_SIZE]; | ||
12 | pcap_t *handle; | ||
13 | |||
14 | /* Checks if we have a device to sniff on */ | ||
15 | if(device == NULL) | ||
16 | { | ||
17 | printf ("Fatal error i did not have any interfaces to sniff on\n"); | ||
18 | return 0; | ||
19 | } | ||
20 | |||
21 | /* Setting the prmiscous and up flag to the interface */ | ||
22 | if (card_set_promisc_up (device) == 0) | ||
23 | { | ||
24 | printf ("Interface flags correctly set using ifconfig\n"); | ||
25 | } | ||
26 | |||
27 | /* Check the cardtype and executes the commands to go into monitor mode */ | ||
28 | if (cardtype == CARD_TYPE_CISCO) /* I got a cisco card */ | ||
29 | { | ||
30 | /* bring the sniffer into rfmon mode */ | ||
31 | snprintf(CiscoRFMON, sizeof(CiscoRFMON),DEFAULT_PATH, device); | ||
32 | CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w"); | ||
33 | fputs ("Mode: r",CISCO_CONFIG_FILE); | ||
34 | fputs ("Mode: y",CISCO_CONFIG_FILE); | ||
35 | fputs ("XmitPower: 1",CISCO_CONFIG_FILE); | ||
36 | fclose(CISCO_CONFIG_FILE); | ||
37 | } | ||
38 | else if (cardtype == CARD_TYPE_NG) | ||
39 | { | ||
40 | char wlanngcmd[62]; | ||
41 | snprintf(wlanngcmd, sizeof(wlanngcmd),"%s %s lnxreq_wlansniff channel=1 enable=true",WLANCTL_PATH,device); | ||
42 | if (system (wlanngcmd) != 0) | ||
43 | { | ||
44 | printf ("\n Fatal error could not set %s in raw mode, check cardtype\n",device); | ||
45 | return 0; | ||
46 | } | ||
47 | } | ||
48 | else if (cardtype == CARD_TYPE_HOSTAP) | ||
49 | { | ||
50 | printf ("Got a host-ap card, nothing is implemented now\n"); | ||
51 | } | ||
52 | |||
53 | |||
54 | /* Check the interface if it is in the correct raw mode */ | ||
55 | handle = pcap_open_live(device, BUFSIZ, 1, 0, errbuf); | ||
56 | |||
57 | /* getting the datalink type */ | ||
58 | datalink = pcap_datalink(handle); | ||
59 | |||
60 | if (datalink == DLT_IEEE802_11) /* Rawmode is IEEE802_11 */ | ||
61 | { | ||
62 | printf ("Your successfully listen on %s in 802.11 raw mode\n",device); | ||
63 | pcap_close(handle); | ||
64 | return 0; | ||
65 | |||
66 | } | ||
67 | else | ||
68 | { | ||
69 | printf ("Fatal error, cannot continue, your interface %s does not work in the correct 802.11 raw mode, check you driver please\n",device); | ||
70 | pcap_close(handle); | ||
71 | return 0; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | |||
76 | |||
77 | int card_set_promisc_up (char * device) | ||
78 | { | ||
79 | int ret; | ||
80 | char ifconfigcmd[32]; | ||
81 | snprintf(ifconfigcmd,sizeof(ifconfigcmd),SBIN_PATH, device); | ||
82 | ret = system (ifconfigcmd); | ||
83 | if (ret > 0) | ||
84 | { | ||
85 | printf ("\nFatal error, could not execute %s please check your card,binary location and permission\n",ifconfigcmd); | ||
86 | return 0; | ||
87 | } | ||
88 | return 1; | ||
89 | } | ||