4 files changed, 11 insertions, 18 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc index a1c3945..3aaa4a7 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc | |||
@@ -1,77 +1,78 @@ | |||
1 | /* | 1 | /* |
2 | * Set card modes for sniffing | 2 | * Set card modes for sniffing |
3 | * | 3 | * |
4 | * $Id$ | 4 | * $Id$ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include "cardmode.hh" | 7 | #include "cardmode.hh" |
8 | #include "log.hh" | ||
8 | 9 | ||
9 | /* main card into monitor function */ | 10 | /* main card into monitor function */ |
10 | int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype) | 11 | int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype) |
11 | { | 12 | { |
12 | char CiscoRFMON[35] = "/proc/driver/aironet/"; | 13 | char CiscoRFMON[35] = "/proc/driver/aironet/"; |
13 | FILE *CISCO_CONFIG_FILE; | 14 | FILE *CISCO_CONFIG_FILE; |
14 | pcap_t *handle = (pcap_t*)orighandle; | 15 | pcap_t *handle = (pcap_t*)orighandle; |
15 | 16 | ||
16 | /* Checks if we have a device to sniff on */ | 17 | /* Checks if we have a device to sniff on */ |
17 | if(device == NULL) | 18 | if(device == NULL) |
18 | { | 19 | { |
19 | wl_logerr("No device given"); | 20 | wl_logerr("No device given"); |
20 | return 0; | 21 | return 0; |
21 | } | 22 | } |
22 | 23 | ||
23 | /* Setting the prmiscous and up flag to the interface */ | 24 | /* Setting the prmiscous and up flag to the interface */ |
24 | if (!card_set_promisc_up(device)) | 25 | if (!card_set_promisc_up(device)) |
25 | { | 26 | { |
26 | wl_logerr("Cannot set interface to promisc mode: %s", strerror(errno)); | 27 | wl_logerr("Cannot set interface to promisc mode: %s", strerror(errno)); |
27 | return 0; | 28 | return 0; |
28 | } | 29 | } |
29 | wl_loginfo("Interface set to promisc mode"); | 30 | wl_loginfo("Interface set to promisc mode"); |
30 | 31 | ||
31 | /* Check the cardtype and executes the commands to go into monitor mode */ | 32 | /* Check the cardtype and executes the commands to go into monitor mode */ |
32 | if (cardtype == CARD_TYPE_CISCO) | 33 | if (cardtype == CARD_TYPE_CISCO) |
33 | { | 34 | { |
34 | /* bring the sniffer into rfmon mode */ | 35 | /* bring the sniffer into rfmon mode */ |
35 | snprintf(CiscoRFMON, sizeof(CiscoRFMON), DEFAULT_PATH, device); | 36 | snprintf(CiscoRFMON, sizeof(CiscoRFMON), DEFAULT_PATH, device); |
36 | if((CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w")) == NULL) | 37 | if((CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w")) == NULL) |
37 | { | 38 | { |
38 | wl_logerr("Cannot open config file: %s", strerror(errno)); | 39 | wl_logerr("Cannot open config file: %s", strerror(errno)); |
39 | return 0; | 40 | return 0; |
40 | } | 41 | } |
41 | fputs ("Mode: r",CISCO_CONFIG_FILE); | 42 | fputs ("Mode: r",CISCO_CONFIG_FILE); |
42 | fputs ("Mode: y",CISCO_CONFIG_FILE); | 43 | fputs ("Mode: y",CISCO_CONFIG_FILE); |
43 | fputs ("XmitPower: 1",CISCO_CONFIG_FILE); | 44 | fputs ("XmitPower: 1",CISCO_CONFIG_FILE); |
44 | fclose(CISCO_CONFIG_FILE); | 45 | fclose(CISCO_CONFIG_FILE); |
45 | } | 46 | } |
46 | else if (cardtype == CARD_TYPE_NG) | 47 | else if (cardtype == CARD_TYPE_NG) |
47 | { | 48 | { |
48 | char wlanngcmd[62]; | 49 | char wlanngcmd[62]; |
49 | snprintf(wlanngcmd, sizeof(wlanngcmd), "%s %s lnxreq_wlansniff channel=1 enable=true", WLANCTL_PATH, device); | 50 | snprintf(wlanngcmd, sizeof(wlanngcmd), "%s %s lnxreq_wlansniff channel=1 enable=true", WLANCTL_PATH, device); |
50 | if (system(wlanngcmd) != 0) | 51 | if (system(wlanngcmd) != 0) |
51 | { | 52 | { |
52 | wl_logerr("Could not set %s in raw mode, check cardtype", device); | 53 | wl_logerr("Could not set %s in raw mode, check cardtype", device); |
53 | return 0; | 54 | return 0; |
54 | } | 55 | } |
55 | } | 56 | } |
56 | else if (cardtype == CARD_TYPE_HOSTAP) | 57 | else if (cardtype == CARD_TYPE_HOSTAP) |
57 | { | 58 | { |
58 | wl_logerr("Got a host-ap card, nothing is implemented now"); | 59 | wl_logerr("Got a host-ap card, nothing is implemented now"); |
59 | } | 60 | } |
60 | 61 | ||
61 | return 1; | 62 | return 1; |
62 | } | 63 | } |
63 | 64 | ||
64 | /* Set card into promisc mode */ | 65 | /* Set card into promisc mode */ |
65 | int card_set_promisc_up (const char *device) | 66 | int card_set_promisc_up (const char *device) |
66 | { | 67 | { |
67 | char ifconfigcmd[32]; | 68 | char ifconfigcmd[32]; |
68 | int retval=0; | 69 | int retval=0; |
69 | 70 | ||
70 | snprintf(ifconfigcmd, sizeof(ifconfigcmd), SBIN_PATH, device); | 71 | snprintf(ifconfigcmd, sizeof(ifconfigcmd), SBIN_PATH, device); |
71 | retval = system(ifconfigcmd); | 72 | retval = system(ifconfigcmd); |
72 | 73 | ||
73 | if(retval != 0) | 74 | if(retval != 0) |
74 | return 0; | 75 | return 0; |
75 | 76 | ||
76 | return 1; | 77 | return 1; |
77 | } | 78 | } |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh index fad74cf..7c6a21d 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh | |||
@@ -1,37 +1,35 @@ | |||
1 | /* $Id$ */ | 1 | /* $Id$ */ |
2 | 2 | ||
3 | #ifndef CARDMODE_HH | 3 | #ifndef CARDMODE_HH |
4 | #define CARDMODE_HH | 4 | #define CARDMODE_HH |
5 | 5 | ||
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
8 | #include <errno.h> | 8 | #include <errno.h> |
9 | #include <sys/socket.h> | 9 | #include <sys/socket.h> |
10 | #include <netinet/in.h> | 10 | #include <netinet/in.h> |
11 | #include <arpa/inet.h> | 11 | #include <arpa/inet.h> |
12 | 12 | ||
13 | extern "C" | 13 | extern "C" |
14 | { | 14 | { |
15 | #include <net/bpf.h> | 15 | #include <net/bpf.h> |
16 | #include <pcap.h> | 16 | #include <pcap.h> |
17 | } | 17 | } |
18 | 18 | ||
19 | #include "../../libwellenreiter/source/log.hh" | ||
20 | |||
21 | /* Defines, used for the card setup */ | 19 | /* Defines, used for the card setup */ |
22 | #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" | 20 | #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" |
23 | #define CARD_TYPE_CISCO1 | 21 | #define CARD_TYPE_CISCO1 |
24 | #define CARD_TYPE_NG 2 | 22 | #define CARD_TYPE_NG 2 |
25 | #define CARD_TYPE_HOSTAP3 | 23 | #define CARD_TYPE_HOSTAP3 |
26 | 24 | ||
27 | /* only for now, until we have the daemon running */ | 25 | /* only for now, until we have the daemon running */ |
28 | /*the config file should provide these information */ | 26 | /*the config file should provide these information */ |
29 | #define CARD_TYPE CARD_TYPE_HOSTAP | 27 | #define CARD_TYPE CARD_TYPE_HOSTAP |
30 | #define SBIN_PATH "/sbin/ifconfig %s promisc up" | 28 | #define SBIN_PATH "/sbin/ifconfig %s promisc up" |
31 | #define WLANCTL_PATH "/sbin/wlanctl-ng" | 29 | #define WLANCTL_PATH "/sbin/wlanctl-ng" |
32 | 30 | ||
33 | /* Prototypes */ | 31 | /* Prototypes */ |
34 | int card_into_monitormode (pcap_t **, char *, int); | 32 | int card_into_monitormode (pcap_t **, char *, int); |
35 | int card_set_promisc_up (const char *); | 33 | int card_set_promisc_up (const char *); |
36 | 34 | ||
37 | #endif /* CARDMODE_HH */ | 35 | #endif /* CARDMODE_HH */ |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/proto.cc b/noncore/net/wellenreiter/libwellenreiter/source/proto.cc index 305f401..2ec23f4 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/proto.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/proto.cc | |||
@@ -1,109 +1,108 @@ | |||
1 | /* | 1 | /* |
2 | * Communication protocol | 2 | * Communication protocol |
3 | * | 3 | * |
4 | * $Id$ | 4 | * $Id$ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include "proto.hh" | 7 | #include "proto.hh" |
8 | #include "sock.hh" | 8 | #include "sock.hh" |
9 | 9 | ||
10 | /* Send found network to GUI */ | 10 | /* Send found network to GUI */ |
11 | int send_network_found (const char *guihost, int guiport, void *structure) | 11 | int send_network_found (const char *guihost, int guiport, void *structure) |
12 | { | 12 | { |
13 | wl_network_t *ptr; | 13 | wl_network_t *ptr; |
14 | char buffer[2048]; | 14 | char buffer[2048]; |
15 | char temp[5]; | 15 | char temp[5]; |
16 | 16 | ||
17 | ptr = (wl_network_t *)structure; | 17 | ptr = (wl_network_t *)structure; |
18 | 18 | ||
19 | memset(buffer, 0, 2048); | 19 | memset(buffer, 0, 2048); |
20 | 20 | ||
21 | /* Type = Found new net */ | 21 | /* Type = Found new net */ |
22 | memcpy(buffer, "01", 2); | 22 | memcpy(buffer, "01", 2); |
23 | 23 | ||
24 | /* Set Net-type */ | 24 | /* Set Net-type */ |
25 | memset(temp, 0, sizeof(temp)); | 25 | memset(temp, 0, sizeof(temp)); |
26 | snprintf(temp, 2, "%d", ptr->net_type); | 26 | snprintf(temp, 2, "%d", ptr->net_type); |
27 | memcpy(buffer + 2, temp, 1); | 27 | memcpy(buffer + 2, temp, 1); |
28 | 28 | ||
29 | /* Set channel */ | 29 | /* Set channel */ |
30 | memset(temp, 0, sizeof(temp)); | 30 | memset(temp, 0, sizeof(temp)); |
31 | 31 | ||
32 | if(ptr->channel < 10) | 32 | if(ptr->channel < 10) |
33 | snprintf(temp, 3, "0%d", ptr->channel); | 33 | snprintf(temp, 3, "0%d", ptr->channel); |
34 | else | 34 | else |
35 | snprintf(temp, 3, "%d", ptr->channel); | 35 | snprintf(temp, 3, "%d", ptr->channel); |
36 | 36 | ||
37 | memcpy(buffer + 3, temp, 2); | 37 | memcpy(buffer + 3, temp, 2); |
38 | 38 | ||
39 | /* Set WEP y/n */ | 39 | /* Set WEP y/n */ |
40 | memset(temp, 0, sizeof(temp)); | 40 | memset(temp, 0, sizeof(temp)); |
41 | snprintf(temp, 2, "%d", ptr->wep); | 41 | snprintf(temp, 2, "%d", ptr->wep); |
42 | memcpy(buffer + 5, temp, 1); | 42 | memcpy(buffer + 5, temp, 1); |
43 | 43 | ||
44 | /* Set MAC address */ | 44 | /* Set MAC address */ |
45 | memcpy(buffer + 6, ptr->mac, 17); | 45 | memcpy(buffer + 6, ptr->mac, 17); |
46 | 46 | ||
47 | /* Set lenght of ssid */ | 47 | /* Set lenght of ssid */ |
48 | memset(temp, 0, sizeof(temp)); | 48 | memset(temp, 0, sizeof(temp)); |
49 | 49 | ||
50 | if(ptr->ssid_len > 99) | 50 | if(ptr->ssid_len > 99) |
51 | snprintf(temp, 4, "%d", ptr->ssid_len); | 51 | snprintf(temp, 4, "%d", ptr->ssid_len); |
52 | else if(ptr->ssid_len < 10) | 52 | else if(ptr->ssid_len < 10) |
53 | snprintf(temp, 4, "00%d", ptr->ssid_len); | 53 | snprintf(temp, 4, "00%d", ptr->ssid_len); |
54 | else | 54 | else |
55 | snprintf(temp, 4, "0%d", ptr->ssid_len); | 55 | snprintf(temp, 4, "0%d", ptr->ssid_len); |
56 | 56 | ||
57 | memcpy(buffer + 23, temp, 3); | 57 | memcpy(buffer + 23, temp, 3); |
58 | 58 | ||
59 | fprintf( stderr, "Temp is %s\n", temp ); | ||
60 | fprintf( stderr, "ssid_len is %d\n", ptr->ssid_len ); | ||
61 | |||
62 | /* Set ssid */ | 59 | /* Set ssid */ |
63 | memcpy(buffer + 26, ptr->bssid, ptr->ssid_len); | 60 | memcpy(buffer + 26, ptr->bssid, ptr->ssid_len); |
64 | 61 | ||
65 | fprintf( stderr, "Buffer is %s\n", buffer ); | ||
66 | |||
67 | /* Send prepared buffer to GUI */ | 62 | /* Send prepared buffer to GUI */ |
63 | #ifdef DEBUG | ||
64 | wl_loginfo("Sending network to GUI: '%s'", buffer); | ||
65 | #endif | ||
66 | |||
68 | sendcomm(guihost, guiport, buffer); | 67 | sendcomm(guihost, guiport, buffer); |
69 | 68 | ||
70 | return 1; | 69 | return 1; |
71 | } | 70 | } |
72 | 71 | ||
73 | /* Fill buffer into structur */ | 72 | /* Fill buffer into structur */ |
74 | int get_network_found (void *structure, const char *buffer) | 73 | int get_network_found (void *structure, const char *buffer) |
75 | { | 74 | { |
76 | wl_network_t *ptr; | 75 | wl_network_t *ptr; |
77 | char temp[512]; | 76 | char temp[512]; |
78 | 77 | ||
79 | ptr = (wl_network_t *)structure; | 78 | ptr = (wl_network_t *)structure; |
80 | 79 | ||
81 | /* Get net type */ | 80 | /* Get net type */ |
82 | memset(temp, 0, sizeof(temp)); | 81 | memset(temp, 0, sizeof(temp)); |
83 | memcpy(temp, buffer + 2, 1); | 82 | memcpy(temp, buffer + 2, 1); |
84 | ptr->net_type = atoi(temp); | 83 | ptr->net_type = atoi(temp); |
85 | 84 | ||
86 | /* Get channel */ | 85 | /* Get channel */ |
87 | memset(temp, 0, sizeof(temp)); | 86 | memset(temp, 0, sizeof(temp)); |
88 | memcpy(temp, buffer + 3, 2); | 87 | memcpy(temp, buffer + 3, 2); |
89 | ptr->channel = atoi(temp); | 88 | ptr->channel = atoi(temp); |
90 | 89 | ||
91 | /* Set WEP y/n */ | 90 | /* Set WEP y/n */ |
92 | memset(temp, 0, sizeof(temp)); | 91 | memset(temp, 0, sizeof(temp)); |
93 | memcpy(temp, buffer + 5, 1); | 92 | memcpy(temp, buffer + 5, 1); |
94 | ptr->wep = atoi(temp); | 93 | ptr->wep = atoi(temp); |
95 | 94 | ||
96 | /* Set MAC address */ | 95 | /* Set MAC address */ |
97 | memcpy(ptr->mac, buffer + 6, 17); | 96 | memcpy(ptr->mac, buffer + 6, 17); |
98 | ptr->mac[17]='\0'; | 97 | ptr->mac[17]='\0'; |
99 | 98 | ||
100 | /* Set lenght of ssid */ | 99 | /* Set lenght of ssid */ |
101 | memset(temp, 0, sizeof(temp)); | 100 | memset(temp, 0, sizeof(temp)); |
102 | memcpy(temp, buffer + 23, 3); | 101 | memcpy(temp, buffer + 23, 3); |
103 | ptr->ssid_len = atoi(temp); | 102 | ptr->ssid_len = atoi(temp); |
104 | 103 | ||
105 | /* Set ssid */ | 104 | /* Set ssid */ |
106 | memcpy(ptr->bssid, buffer + 26, ptr->ssid_len + 1); | 105 | memcpy(ptr->bssid, buffer + 26, ptr->ssid_len + 1); |
107 | 106 | ||
108 | return 1; | 107 | return 1; |
109 | } | 108 | } |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc b/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc index 84caf12..c703052 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc | |||
@@ -1,336 +1,331 @@ | |||
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 "log.hh" | 10 | #include "log.hh" |
11 | #include "proto.hh" | 11 | #include "proto.hh" |
12 | 12 | ||
13 | /* Main function, checks packets */ | 13 | /* Main function, checks packets */ |
14 | void process_packets(const struct pcap_pkthdr *pkthdr, const unsigned char *packet, char *guihost, int guiport) | 14 | void 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 | printf( "cap_ESS is %d, cap_IBSS is %d\n", pinfoptr->cap_ESS, pinfoptr->cap_IBSS ); | ||
98 | |||
99 | /* Here should be the infos to the gui issued */ | 97 | /* Here should be the infos to the gui issued */ |
100 | if (pinfoptr->cap_ESS == 1 &&pinfoptr->cap_IBSS ==0) | 98 | if (pinfoptr->cap_ESS == 1 &&pinfoptr->cap_IBSS ==0) |
101 | { | 99 | { |
102 | wl_loginfo("Found an access point"); | 100 | wl_loginfo("Found an access point"); |
103 | wl_net.net_type=1; | 101 | wl_net.net_type=1; |
104 | } | 102 | } |
105 | else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 2) | 103 | else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 2) |
106 | { | 104 | { |
107 | wl_loginfo("Found an ad-hoc network"); | 105 | wl_loginfo("Found an ad-hoc network"); |
108 | wl_net.net_type=2; | 106 | wl_net.net_type=2; |
109 | } | 107 | } |
108 | |||
110 | if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0) | 109 | if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0) |
111 | { | ||
112 | wl_loginfo("Net is a non-broadcasting network"); | 110 | wl_loginfo("Net is a non-broadcasting network"); |
113 | } | ||
114 | else | 111 | else |
115 | { | ||
116 | wl_loginfo("SSID is: %s", pinfoptr->ssid); | 112 | wl_loginfo("SSID is: %s", pinfoptr->ssid); |
117 | // wl_net.bssid=pinfoptr->ssid; | 113 | |
118 | } | 114 | wl_loginfo("SSID is: %s", pinfoptr->ssid); |
115 | memcpy(wl_net.bssid, pinfoptr->ssid, sizeof(wl_net.bssid)-1); | ||
119 | 116 | ||
120 | wl_loginfo("SSID length is: %d", pinfoptr->ssid_len); | 117 | wl_loginfo("SSID length is: %d", pinfoptr->ssid_len); |
121 | wl_net.ssid_len=pinfoptr->ssid_len; | 118 | wl_net.ssid_len=pinfoptr->ssid_len; |
122 | 119 | ||
123 | wl_loginfo("Channel is: %d", pinfoptr->channel); | 120 | wl_loginfo("Channel is: %d", pinfoptr->channel); |
124 | wl_net.channel=pinfoptr->channel; | 121 | wl_net.channel=pinfoptr->channel; |
125 | wl_net.wep=pinfoptr->cap_WEP; | 122 | wl_net.wep=pinfoptr->cap_WEP; |
126 | 123 | ||
127 | wl_loginfo("Mac is: %s", pinfoptr->sndhwaddr); | 124 | wl_loginfo("Mac is: %s", pinfoptr->sndhwaddr); |
128 | memcpy(wl_net.mac, pinfoptr->sndhwaddr, sizeof(wl_net.mac)-1);; | 125 | memcpy(wl_net.mac, pinfoptr->sndhwaddr, sizeof(wl_net.mac)-1);; |
129 | wl_loginfo("SSID is: %s", pinfoptr->ssid); | 126 | |
130 | memcpy(wl_net.bssid, pinfoptr->ssid, sizeof(wl_net.bssid)-1); | ||
131 | |||
132 | // printf ("\n\tDest : %s\n",pinfoptr->desthwaddr); | ||
133 | send_network_found((char *)guihost, guiport, &wl_net); | 127 | send_network_found((char *)guihost, guiport, &wl_net); |
134 | wl_loginfo("Sent network to GUI '%s:%d'", guihost, guiport); | 128 | wl_loginfo("Sent network to GUI '%s:%d'", guihost, guiport); |
135 | } | 129 | } |
136 | break; | 130 | break; |
131 | |||
137 | default: | 132 | default: |
138 | wl_logerr("Unknown IEEE802.11 frame subtype (%d)", FC_SUBTYPE(fc)); | 133 | wl_logerr("Unknown IEEE802.11 frame subtype (%d)", FC_SUBTYPE(fc)); |
139 | break; | 134 | break; |
140 | } /* End of switch over different mgt frame types */ | 135 | } /* End of switch over different mgt frame types */ |
141 | 136 | ||
142 | break; | 137 | break; |
143 | 138 | ||
144 | case T_CTRL: | 139 | case T_CTRL: |
145 | wl_loginfo("Received control frame, not implemented yet"); | 140 | wl_loginfo("Received control frame, not implemented yet"); |
146 | break; | 141 | break; |
147 | 142 | ||
148 | case T_DATA: | 143 | case T_DATA: |
149 | wl_loginfo("Received date frame, not implemented yet"); | 144 | wl_loginfo("Received date frame, not implemented yet"); |
150 | break; | 145 | break; |
151 | 146 | ||
152 | default: | 147 | default: |
153 | wl_logerr("Unknown IEEE802.11 frame type (%d)", FC_TYPE(fc)); | 148 | wl_logerr("Unknown IEEE802.11 frame type (%d)", FC_TYPE(fc)); |
154 | break; | 149 | break; |
155 | } | 150 | } |
156 | } | 151 | } |
157 | 152 | ||
158 | /* This decodes the 802.11b frame header out of the 802.11b packet | 153 | /* This decodes the 802.11b frame header out of the 802.11b packet |
159 | all the infos is placed into the packetinfo structure */ | 154 | all the infos is placed into the packetinfo structure */ |
160 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo) | 155 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo) |
161 | { | 156 | { |
162 | const struct mgmt_header_t *mgthdr = (const struct mgmt_header_t *) p; | 157 | const struct mgmt_header_t *mgthdr = (const struct mgmt_header_t *) p; |
163 | ppinfo->fcsubtype = FC_SUBTYPE(mgthdr->fc); | 158 | ppinfo->fcsubtype = FC_SUBTYPE(mgthdr->fc); |
164 | 159 | ||
165 | /* Get the sender, bssid and dest mac address */ | 160 | /* Get the sender, bssid and dest mac address */ |
166 | etheraddr_string(mgthdr->bssid,ppinfo->bssid); | 161 | etheraddr_string(mgthdr->bssid,ppinfo->bssid); |
167 | etheraddr_string(mgthdr->da,ppinfo->desthwaddr); | 162 | etheraddr_string(mgthdr->da,ppinfo->desthwaddr); |
168 | etheraddr_string(mgthdr->sa,ppinfo->sndhwaddr); | 163 | etheraddr_string(mgthdr->sa,ppinfo->sndhwaddr); |
169 | ppinfo->fc_wep = FC_WEP(mgthdr->fc); | 164 | ppinfo->fc_wep = FC_WEP(mgthdr->fc); |
170 | return 0; | 165 | return 0; |
171 | } | 166 | } |
172 | 167 | ||
173 | 168 | ||
174 | void etheraddr_string(register const u_char *ep, char *text) | 169 | void etheraddr_string(register const u_char *ep, char *text) |
175 | { | 170 | { |
176 | static char hex[] = "0123456789abcdef"; | 171 | static char hex[] = "0123456789abcdef"; |
177 | register unsigned int i, j; | 172 | register unsigned int i, j; |
178 | register char *cp; | 173 | register char *cp; |
179 | char buf[sizeof("00:00:00:00:00:00\0")]; | 174 | char buf[sizeof("00:00:00:00:00:00\0")]; |
180 | cp = buf; | 175 | cp = buf; |
181 | if ((j = *ep >> 4) != 0) | 176 | if ((j = *ep >> 4) != 0) |
182 | { | 177 | { |
183 | *cp++ = hex[j]; | 178 | *cp++ = hex[j]; |
184 | } | 179 | } |
185 | else | 180 | else |
186 | { | 181 | { |
187 | *cp++ = '0'; | 182 | *cp++ = '0'; |
188 | } | 183 | } |
189 | *cp++ = hex[*ep++ & 0xf]; | 184 | *cp++ = hex[*ep++ & 0xf]; |
190 | 185 | ||
191 | for (i = 5; (int)--i >= 0;) | 186 | for (i = 5; (int)--i >= 0;) |
192 | { | 187 | { |
193 | *cp++ = ':'; | 188 | *cp++ = ':'; |
194 | if ((j = *ep >> 4) != 0) | 189 | if ((j = *ep >> 4) != 0) |
195 | { | 190 | { |
196 | *cp++ = hex[j]; | 191 | *cp++ = hex[j]; |
197 | } | 192 | } |
198 | else | 193 | else |
199 | { | 194 | { |
200 | *cp++ = '0'; | 195 | *cp++ = '0'; |
201 | } | 196 | } |
202 | 197 | ||
203 | *cp++ = hex[*ep++ & 0xf]; | 198 | *cp++ = hex[*ep++ & 0xf]; |
204 | } | 199 | } |
205 | *cp = '\0'; | 200 | *cp = '\0'; |
206 | strcpy(text,buf); | 201 | strcpy(text,buf); |
207 | } | 202 | } |
208 | 203 | ||
209 | /* beacon handler */ | 204 | /* beacon handler */ |
210 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | 205 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) |
211 | { | 206 | { |
212 | struct mgmt_body_t pbody; | 207 | struct mgmt_body_t pbody; |
213 | int offset = 0; | 208 | int offset = 0; |
214 | 209 | ||
215 | /* Get the static informations out of the packet */ | 210 | /* Get the static informations out of the packet */ |
216 | memset(&pbody, 0, sizeof(pbody)); | 211 | memset(&pbody, 0, sizeof(pbody)); |
217 | memcpy(&pbody.timestamp, p, 8); | 212 | memcpy(&pbody.timestamp, p, 8); |
218 | offset += 8; | 213 | offset += 8; |
219 | pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); | 214 | pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); |
220 | offset += 2; | 215 | offset += 2; |
221 | pbody.capability_info = EXTRACT_LE_16BITS(p+offset); | 216 | pbody.capability_info = EXTRACT_LE_16BITS(p+offset); |
222 | offset += 2; | 217 | offset += 2; |
223 | 218 | ||
224 | /* Gets the different flags out of the capabilities */ | 219 | /* Gets the different flags out of the capabilities */ |
225 | ppinfo->cap_ESS = CAPABILITY_ESS(pbody.capability_info); | 220 | ppinfo->cap_ESS = CAPABILITY_ESS(pbody.capability_info); |
226 | ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info); | 221 | ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info); |
227 | ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info); | 222 | ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info); |
228 | 223 | ||
229 | /* Gets the tagged elements out of the packets */ | 224 | /* Gets the tagged elements out of the packets */ |
230 | while (offset + 1 < ppinfo->pktlen) | 225 | while (offset + 1 < ppinfo->pktlen) |
231 | { | 226 | { |
232 | switch (*(p + offset)) | 227 | switch (*(p + offset)) |
233 | { | 228 | { |
234 | case E_SSID: | 229 | case E_SSID: |
235 | memcpy(&(pbody.ssid),p+offset,2); offset += 2; | 230 | memcpy(&(pbody.ssid),p+offset,2); offset += 2; |
236 | if (pbody.ssid.length > 0) | 231 | if (pbody.ssid.length > 0) |
237 | { | 232 | { |
238 | memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length; | 233 | memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length; |
239 | pbody.ssid.ssid[pbody.ssid.length]='\0'; | 234 | pbody.ssid.ssid[pbody.ssid.length]='\0'; |
240 | if (strcmp((char *)pbody.ssid.ssid,"")==0) | 235 | if (strcmp((char *)pbody.ssid.ssid,"")==0) |
241 | memcpy(ppinfo->ssid, NONBROADCASTING, sizeof(ppinfo->ssid)); | 236 | memcpy(ppinfo->ssid, NONBROADCASTING, sizeof(ppinfo->ssid)); |
242 | else | 237 | else |
243 | memcpy(ppinfo->ssid, pbody.ssid.ssid, sizeof(ppinfo->ssid)); | 238 | memcpy(ppinfo->ssid, pbody.ssid.ssid, sizeof(ppinfo->ssid)); |
244 | ppinfo->ssid_len = pbody.ssid.length; | 239 | ppinfo->ssid_len = pbody.ssid.length; |
245 | } | 240 | } |
246 | break; | 241 | break; |
247 | 242 | ||
248 | case E_CHALLENGE: | 243 | case E_CHALLENGE: |
249 | memcpy(&(pbody.challenge),p+offset,2); offset += 2; | 244 | memcpy(&(pbody.challenge),p+offset,2); offset += 2; |
250 | if (pbody.challenge.length > 0) | 245 | if (pbody.challenge.length > 0) |
251 | { | 246 | { |
252 | memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length; | 247 | memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length; |
253 | pbody.challenge.text[pbody.challenge.length]='\0'; | 248 | pbody.challenge.text[pbody.challenge.length]='\0'; |
254 | } | 249 | } |
255 | break; | 250 | break; |
256 | case E_RATES: | 251 | case E_RATES: |
257 | memcpy(&(pbody.rates),p+offset,2); offset += 2; | 252 | memcpy(&(pbody.rates),p+offset,2); offset += 2; |
258 | if (pbody.rates.length > 0) | 253 | if (pbody.rates.length > 0) |
259 | { | 254 | { |
260 | memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); offset += pbody.rates.length; | 255 | memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); offset += pbody.rates.length; |
261 | } | 256 | } |
262 | break; | 257 | break; |
263 | case E_DS: | 258 | case E_DS: |
264 | memcpy(&(pbody.ds),p+offset,3); offset +=3; | 259 | memcpy(&(pbody.ds),p+offset,3); offset +=3; |
265 | ppinfo->channel = pbody.ds.channel; | 260 | ppinfo->channel = pbody.ds.channel; |
266 | break; | 261 | break; |
267 | case E_CF: | 262 | case E_CF: |
268 | memcpy(&(pbody.cf),p+offset,8); offset +=8; | 263 | memcpy(&(pbody.cf),p+offset,8); offset +=8; |
269 | break; | 264 | break; |
270 | case E_TIM: | 265 | case E_TIM: |
271 | memcpy(&(pbody.tim),p+offset,2); offset +=2; | 266 | memcpy(&(pbody.tim),p+offset,2); offset +=2; |
272 | memcpy(&(pbody.tim.count),p+offset,3); offset +=3; | 267 | memcpy(&(pbody.tim.count),p+offset,3); offset +=3; |
273 | if ((pbody.tim.length -3) > 0) | 268 | if ((pbody.tim.length -3) > 0) |
274 | { | 269 | { |
275 | memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3)); | 270 | memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3)); |
276 | offset += pbody.tim.length -3; | 271 | offset += pbody.tim.length -3; |
277 | } | 272 | } |
278 | break; | 273 | break; |
279 | default: | 274 | default: |
280 | 275 | ||
281 | offset+= *(p+offset+1) + 2; | 276 | offset+= *(p+offset+1) + 2; |
282 | break; | 277 | break; |
283 | } /* end of switch*/ | 278 | } /* end of switch*/ |
284 | } /* end of for loop */ | 279 | } /* end of for loop */ |
285 | return 0; | 280 | return 0; |
286 | 281 | ||
287 | } /* End of handle_beacon */ | 282 | } /* End of handle_beacon */ |
288 | 283 | ||
289 | 284 | ||
290 | int GetHeaderLength(u_int16_t fc) | 285 | int GetHeaderLength(u_int16_t fc) |
291 | { | 286 | { |
292 | int iLength=0; | 287 | int iLength=0; |
293 | 288 | ||
294 | switch (FC_TYPE(fc)) | 289 | switch (FC_TYPE(fc)) |
295 | { | 290 | { |
296 | case T_MGMT: | 291 | case T_MGMT: |
297 | iLength = MGMT_HEADER_LEN; | 292 | iLength = MGMT_HEADER_LEN; |
298 | break; | 293 | break; |
299 | case T_CTRL: | 294 | case T_CTRL: |
300 | switch (FC_SUBTYPE(fc)) | 295 | switch (FC_SUBTYPE(fc)) |
301 | { | 296 | { |
302 | case CTRL_PS_POLL: | 297 | case CTRL_PS_POLL: |
303 | iLength = CTRL_PS_POLL_LEN; | 298 | iLength = CTRL_PS_POLL_LEN; |
304 | break; | 299 | break; |
305 | case CTRL_RTS: | 300 | case CTRL_RTS: |
306 | iLength = CTRL_RTS_LEN; | 301 | iLength = CTRL_RTS_LEN; |
307 | break; | 302 | break; |
308 | case CTRL_CTS: | 303 | case CTRL_CTS: |
309 | iLength = CTRL_CTS_LEN; | 304 | iLength = CTRL_CTS_LEN; |
310 | break; | 305 | break; |
311 | case CTRL_ACK: | 306 | case CTRL_ACK: |
312 | iLength = CTRL_ACK_LEN; | 307 | iLength = CTRL_ACK_LEN; |
313 | break; | 308 | break; |
314 | case CTRL_CF_END: | 309 | case CTRL_CF_END: |
315 | iLength = CTRL_END_LEN; | 310 | iLength = CTRL_END_LEN; |
316 | break; | 311 | break; |
317 | case CTRL_END_ACK: | 312 | case CTRL_END_ACK: |
318 | iLength = CTRL_END_ACK_LEN; | 313 | iLength = CTRL_END_ACK_LEN; |
319 | break; | 314 | break; |
320 | default: | 315 | default: |
321 | iLength = 0; | 316 | iLength = 0; |
322 | break; | 317 | break; |
323 | } | 318 | } |
324 | break; | 319 | break; |
325 | case T_DATA: | 320 | case T_DATA: |
326 | if (FC_TO_DS(fc) && FC_FROM_DS(fc)) | 321 | if (FC_TO_DS(fc) && FC_FROM_DS(fc)) |
327 | iLength = 30; | 322 | iLength = 30; |
328 | else | 323 | else |
329 | iLength = 24; | 324 | iLength = 24; |
330 | break; | 325 | break; |
331 | default: | 326 | default: |
332 | wl_logerr("unknown IEEE802.11 frame type (%d)", FC_TYPE(fc)); | 327 | wl_logerr("unknown IEEE802.11 frame type (%d)", FC_TYPE(fc)); |
333 | break; | 328 | break; |
334 | } | 329 | } |
335 | return iLength; | 330 | return iLength; |
336 | } | 331 | } |