author | mjm <mjm> | 2002-12-14 19:13:32 (UTC) |
---|---|---|
committer | mjm <mjm> | 2002-12-14 19:13:32 (UTC) |
commit | d9d4e587e62eac418b892c90145e958d6495d081 (patch) (side-by-side diff) | |
tree | 6a554548d6dfaaa082f4b088f8912f4c5fc7e528 | |
parent | 57918323f3b2e1377d9cf97ed6466e31b260d24a (diff) | |
download | opie-d9d4e587e62eac418b892c90145e958d6495d081.zip opie-d9d4e587e62eac418b892c90145e958d6495d081.tar.gz opie-d9d4e587e62eac418b892c90145e958d6495d081.tar.bz2 |
code cleanup, possible bug in sniff.cc fixed
4 files changed, 10 insertions, 17 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 @@ /* * Set card modes for sniffing * * $Id$ */ #include "cardmode.hh" +#include "log.hh" /* main card into monitor function */ int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype) { char CiscoRFMON[35] = "/proc/driver/aironet/"; FILE *CISCO_CONFIG_FILE; pcap_t *handle = (pcap_t*)orighandle; /* Checks if we have a device to sniff on */ if(device == NULL) { wl_logerr("No device given"); return 0; } /* Setting the prmiscous and up flag to the interface */ if (!card_set_promisc_up(device)) { wl_logerr("Cannot set interface to promisc mode: %s", strerror(errno)); return 0; } wl_loginfo("Interface set to promisc mode"); /* Check the cardtype and executes the commands to go into monitor mode */ if (cardtype == CARD_TYPE_CISCO) { /* bring the sniffer into rfmon mode */ snprintf(CiscoRFMON, sizeof(CiscoRFMON), DEFAULT_PATH, device); if((CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w")) == NULL) { wl_logerr("Cannot open config file: %s", strerror(errno)); return 0; } fputs ("Mode: r",CISCO_CONFIG_FILE); fputs ("Mode: y",CISCO_CONFIG_FILE); fputs ("XmitPower: 1",CISCO_CONFIG_FILE); fclose(CISCO_CONFIG_FILE); } else if (cardtype == CARD_TYPE_NG) { char wlanngcmd[62]; snprintf(wlanngcmd, sizeof(wlanngcmd), "%s %s lnxreq_wlansniff channel=1 enable=true", WLANCTL_PATH, device); if (system(wlanngcmd) != 0) { wl_logerr("Could not set %s in raw mode, check cardtype", device); return 0; } } else if (cardtype == CARD_TYPE_HOSTAP) { wl_logerr("Got a host-ap card, nothing is implemented now"); } return 1; } /* Set card into promisc mode */ int card_set_promisc_up (const char *device) { char ifconfigcmd[32]; int retval=0; snprintf(ifconfigcmd, sizeof(ifconfigcmd), SBIN_PATH, device); retval = system(ifconfigcmd); if(retval != 0) return 0; return 1; } 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 @@ /* $Id$ */ #ifndef CARDMODE_HH #define CARDMODE_HH #include <string.h> #include <stdlib.h> #include <errno.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> extern "C" { #include <net/bpf.h> #include <pcap.h> } -#include "../../libwellenreiter/source/log.hh" - /* Defines, used for the card setup */ #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" #define CARD_TYPE_CISCO 1 #define CARD_TYPE_NG 2 #define CARD_TYPE_HOSTAP 3 /* only for now, until we have the daemon running */ /*the config file should provide these information */ #define CARD_TYPE CARD_TYPE_HOSTAP #define SBIN_PATH "/sbin/ifconfig %s promisc up" #define WLANCTL_PATH "/sbin/wlanctl-ng" /* Prototypes */ int card_into_monitormode (pcap_t **, char *, int); int card_set_promisc_up (const char *); #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 @@ /* * Communication protocol * * $Id$ */ #include "proto.hh" #include "sock.hh" /* Send found network to GUI */ int send_network_found (const char *guihost, int guiport, void *structure) { wl_network_t *ptr; char buffer[2048]; char temp[5]; ptr = (wl_network_t *)structure; memset(buffer, 0, 2048); /* Type = Found new net */ memcpy(buffer, "01", 2); /* Set Net-type */ memset(temp, 0, sizeof(temp)); snprintf(temp, 2, "%d", ptr->net_type); memcpy(buffer + 2, temp, 1); /* Set channel */ memset(temp, 0, sizeof(temp)); if(ptr->channel < 10) snprintf(temp, 3, "0%d", ptr->channel); else snprintf(temp, 3, "%d", ptr->channel); memcpy(buffer + 3, temp, 2); /* Set WEP y/n */ memset(temp, 0, sizeof(temp)); snprintf(temp, 2, "%d", ptr->wep); memcpy(buffer + 5, temp, 1); /* Set MAC address */ memcpy(buffer + 6, ptr->mac, 17); /* Set lenght of ssid */ memset(temp, 0, sizeof(temp)); if(ptr->ssid_len > 99) snprintf(temp, 4, "%d", ptr->ssid_len); else if(ptr->ssid_len < 10) snprintf(temp, 4, "00%d", ptr->ssid_len); else snprintf(temp, 4, "0%d", ptr->ssid_len); memcpy(buffer + 23, temp, 3); - fprintf( stderr, "Temp is %s\n", temp ); - fprintf( stderr, "ssid_len is %d\n", ptr->ssid_len ); - /* Set ssid */ memcpy(buffer + 26, ptr->bssid, ptr->ssid_len); - fprintf( stderr, "Buffer is %s\n", buffer ); - /* Send prepared buffer to GUI */ +#ifdef DEBUG + wl_loginfo("Sending network to GUI: '%s'", buffer); +#endif + sendcomm(guihost, guiport, buffer); return 1; } /* Fill buffer into structur */ int get_network_found (void *structure, const char *buffer) { wl_network_t *ptr; char temp[512]; ptr = (wl_network_t *)structure; /* Get net type */ memset(temp, 0, sizeof(temp)); memcpy(temp, buffer + 2, 1); ptr->net_type = atoi(temp); /* Get channel */ memset(temp, 0, sizeof(temp)); memcpy(temp, buffer + 3, 2); ptr->channel = atoi(temp); /* Set WEP y/n */ memset(temp, 0, sizeof(temp)); memcpy(temp, buffer + 5, 1); ptr->wep = atoi(temp); /* Set MAC address */ memcpy(ptr->mac, buffer + 6, 17); ptr->mac[17]='\0'; /* Set lenght of ssid */ memset(temp, 0, sizeof(temp)); memcpy(temp, buffer + 23, 3); ptr->ssid_len = atoi(temp); /* Set ssid */ memcpy(ptr->bssid, buffer + 26, ptr->ssid_len + 1); return 1; } 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,264 +1,259 @@ /* * rfmon mode sniffer * * $Id$ */ #include "sniff.hh" #include "ieee802_11.hh" #include "extract.hh" #include "log.hh" #include "proto.hh" /* Main function, checks packets */ void process_packets(const struct pcap_pkthdr *pkthdr, const unsigned char *packet, char *guihost, int guiport) { unsigned int caplen = pkthdr->caplen; unsigned int length = pkthdr->len; u_int16_t fc; unsigned int HEADER_LENGTH; /* pinfo holds all interresting information for us */ struct packetinfo pinfo; struct packetinfo *pinfoptr; /* wl_network_t will finally be set and send to the ui */ wl_network_t wl_net; pinfoptr=&pinfo; pinfoptr->isvalid = 0; pinfoptr->pktlen = pkthdr->len; if (caplen < IEEE802_11_FC_LEN) { /* This is a garbage packet, because is does not long enough to hold a 802.11b header */ pinfoptr->isvalid = 0; return; } /* Gets the framecontrol bits (2bytes long) */ fc = EXTRACT_LE_16BITS(packet); HEADER_LENGTH = GetHeaderLength(fc); if (caplen < HEADER_LENGTH) { /* This is a garbage packet, because it is not long enough to hold a correct header of its type */ pinfoptr->isvalid = 0; return; } /* Decode 802.11b header out of the packet */ if (decode_80211b_hdr(packet,pinfoptr) == 0) { /* Justification of the ofset to further process the packet */ length -= HEADER_LENGTH; caplen -= HEADER_LENGTH; packet += HEADER_LENGTH; } else /* Something is wrong,could not be a correct packet */ return; switch (FC_TYPE(fc)) { /* Is it a managemnet frame? */ case T_MGMT: switch (FC_SUBTYPE(fc)) { case ST_BEACON: if (handle_beacon(fc, packet,pinfoptr) ==0) { if (!strcmp(pinfoptr->desthwaddr,"ff:ff:ff:ff:ff:ff") == 0) { /* Every beacon must have the broadcast as destination so it must be a shitti packet */ pinfoptr->isvalid = 0; return; } if (pinfoptr->cap_ESS == pinfoptr->cap_IBSS) { /* Only one of both are possible, so must be a noise packet, if this comes up */ pinfoptr->isvalid = 0; return; } if (pinfoptr->channel < 1 || pinfoptr->channel > 14) { /* Only channels between 1 and 14 are possible others must be noise packets */ pinfoptr->isvalid = 0; return; } - printf( "cap_ESS is %d, cap_IBSS is %d\n", pinfoptr->cap_ESS, pinfoptr->cap_IBSS ); - /* Here should be the infos to the gui issued */ if (pinfoptr->cap_ESS == 1 &&pinfoptr->cap_IBSS ==0) { wl_loginfo("Found an access point"); wl_net.net_type=1; } else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 2) { wl_loginfo("Found an ad-hoc network"); wl_net.net_type=2; } + if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0) - { wl_loginfo("Net is a non-broadcasting network"); - } else - { wl_loginfo("SSID is: %s", pinfoptr->ssid); - // wl_net.bssid=pinfoptr->ssid; - } + + wl_loginfo("SSID is: %s", pinfoptr->ssid); + memcpy(wl_net.bssid, pinfoptr->ssid, sizeof(wl_net.bssid)-1); wl_loginfo("SSID length is: %d", pinfoptr->ssid_len); wl_net.ssid_len=pinfoptr->ssid_len; wl_loginfo("Channel is: %d", pinfoptr->channel); wl_net.channel=pinfoptr->channel; wl_net.wep=pinfoptr->cap_WEP; wl_loginfo("Mac is: %s", pinfoptr->sndhwaddr); memcpy(wl_net.mac, pinfoptr->sndhwaddr, sizeof(wl_net.mac)-1);; - wl_loginfo("SSID is: %s", pinfoptr->ssid); - memcpy(wl_net.bssid, pinfoptr->ssid, sizeof(wl_net.bssid)-1); - // printf ("\n\tDest : %s\n",pinfoptr->desthwaddr); send_network_found((char *)guihost, guiport, &wl_net); wl_loginfo("Sent network to GUI '%s:%d'", guihost, guiport); } break; + default: wl_logerr("Unknown IEEE802.11 frame subtype (%d)", FC_SUBTYPE(fc)); break; } /* End of switch over different mgt frame types */ break; case T_CTRL: wl_loginfo("Received control frame, not implemented yet"); break; case T_DATA: wl_loginfo("Received date frame, not implemented yet"); break; default: wl_logerr("Unknown IEEE802.11 frame type (%d)", FC_TYPE(fc)); break; } } /* This decodes the 802.11b frame header out of the 802.11b packet all the infos is placed into the packetinfo structure */ int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo) { const struct mgmt_header_t *mgthdr = (const struct mgmt_header_t *) p; ppinfo->fcsubtype = FC_SUBTYPE(mgthdr->fc); /* Get the sender, bssid and dest mac address */ etheraddr_string(mgthdr->bssid,ppinfo->bssid); etheraddr_string(mgthdr->da,ppinfo->desthwaddr); etheraddr_string(mgthdr->sa,ppinfo->sndhwaddr); ppinfo->fc_wep = FC_WEP(mgthdr->fc); return 0; } void etheraddr_string(register const u_char *ep, char *text) { static char hex[] = "0123456789abcdef"; register unsigned int i, j; register char *cp; char buf[sizeof("00:00:00:00:00:00\0")]; cp = buf; if ((j = *ep >> 4) != 0) { *cp++ = hex[j]; } else { *cp++ = '0'; } *cp++ = hex[*ep++ & 0xf]; for (i = 5; (int)--i >= 0;) { *cp++ = ':'; if ((j = *ep >> 4) != 0) { *cp++ = hex[j]; } else { *cp++ = '0'; } *cp++ = hex[*ep++ & 0xf]; } *cp = '\0'; strcpy(text,buf); } /* beacon handler */ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) { struct mgmt_body_t pbody; int offset = 0; /* Get the static informations out of the packet */ memset(&pbody, 0, sizeof(pbody)); memcpy(&pbody.timestamp, p, 8); offset += 8; pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); offset += 2; pbody.capability_info = EXTRACT_LE_16BITS(p+offset); offset += 2; /* Gets the different flags out of the capabilities */ ppinfo->cap_ESS = CAPABILITY_ESS(pbody.capability_info); ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info); ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info); /* Gets the tagged elements out of the packets */ while (offset + 1 < ppinfo->pktlen) { switch (*(p + offset)) { case E_SSID: memcpy(&(pbody.ssid),p+offset,2); offset += 2; if (pbody.ssid.length > 0) { memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length; pbody.ssid.ssid[pbody.ssid.length]='\0'; if (strcmp((char *)pbody.ssid.ssid,"")==0) memcpy(ppinfo->ssid, NONBROADCASTING, sizeof(ppinfo->ssid)); else memcpy(ppinfo->ssid, pbody.ssid.ssid, sizeof(ppinfo->ssid)); ppinfo->ssid_len = pbody.ssid.length; } break; case E_CHALLENGE: memcpy(&(pbody.challenge),p+offset,2); offset += 2; if (pbody.challenge.length > 0) { memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length; pbody.challenge.text[pbody.challenge.length]='\0'; } break; case E_RATES: memcpy(&(pbody.rates),p+offset,2); offset += 2; if (pbody.rates.length > 0) { memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); offset += pbody.rates.length; } break; case E_DS: memcpy(&(pbody.ds),p+offset,3); offset +=3; |