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