summaryrefslogtreecommitdiff
authormax <max>2003-02-09 20:50:34 (UTC)
committer max <max>2003-02-09 20:50:34 (UTC)
commit38b97c504a4ee1e0b82fd2e4604c815d9ba3b440 (patch) (unidiff)
tree8c66ca6ae697b95c606756625b219d45ffbe95bb
parentc0f8b347e790f042f0a14e6e58e67046a7e0b8e3 (diff)
downloadopie-38b97c504a4ee1e0b82fd2e4604c815d9ba3b440.zip
opie-38b97c504a4ee1e0b82fd2e4604c815d9ba3b440.tar.gz
opie-38b97c504a4ee1e0b82fd2e4604c815d9ba3b440.tar.bz2
Channelswitch
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/daemon/source/daemon.cc2
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc74
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh9
3 files changed, 53 insertions, 32 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc
index 8471efc..46a50ed 100644
--- a/noncore/net/wellenreiter/daemon/source/daemon.cc
+++ b/noncore/net/wellenreiter/daemon/source/daemon.cc
@@ -1,193 +1,193 @@
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 9
10/* should be parsed from cfg-file */ 10/* should be parsed from cfg-file */
11#define MAXCHANNEL 13 11#define MAXCHANNEL 13
12#define CHANINTERVAL 700000 12#define CHANINTERVAL 500000
13 13
14/* Main function of wellenreiterd */ 14/* Main function of wellenreiterd */
15int main(int argc, char **argv) 15int main(int argc, char **argv)
16{ 16{
17 int sock, maxfd, retval; 17 int sock, maxfd, retval;
18 char buffer[WL_SOCKBUF]; 18 char buffer[WL_SOCKBUF];
19 struct pcap_pkthdr header; 19 struct pcap_pkthdr header;
20 struct sockaddr_in saddr; 20 struct sockaddr_in saddr;
21 pcap_t *handletopcap; 21 pcap_t *handletopcap;
22 wl_cardtype_t cardtype; 22 wl_cardtype_t cardtype;
23 pthread_t sub; 23 pthread_t sub;
24 const unsigned char *packet; 24 const unsigned char *packet;
25 25
26 fd_set rset; 26 fd_set rset;
27 27
28 fprintf(stderr, "wellenreiterd %s\n\n", VERSION); 28 fprintf(stderr, "wellenreiterd %s\n\n", VERSION);
29 fprintf(stderr, "(c) 2002 by M-M-M\n\n"); 29 fprintf(stderr, "(c) 2002 by M-M-M\n\n");
30 30
31 if(argc < 3) 31 if(argc < 3)
32 usage(); 32 usage();
33 33
34 /* Set sniffer device */ 34 /* Set sniffer device */
35 memset(cardtype.iface, 0, sizeof(cardtype.iface)); 35 memset(cardtype.iface, 0, sizeof(cardtype.iface));
36 strncpy(cardtype.iface, (char *)argv[1], sizeof(cardtype.iface) - 1); 36 strncpy(cardtype.iface, (char *)argv[1], sizeof(cardtype.iface) - 1);
37 37
38 /* Set card type */ 38 /* Set card type */
39 cardtype.type = atoi(argv[2]); 39 cardtype.type = atoi(argv[2]);
40 if(cardtype.type < 1 || cardtype.type > 4) 40 if(cardtype.type < 1 || cardtype.type > 4)
41 usage(); 41 usage();
42 42
43 /* set card into monitor mode */ 43 /* set card into monitor mode */
44 if(!card_into_monitormode(&handletopcap, cardtype.iface, 44 if(!card_into_monitormode(&handletopcap, cardtype.iface,
45 cardtype.type)) 45 cardtype.type))
46 { 46 {
47 wl_logerr("Cannot initialize the wireless-card, aborting"); 47 wl_logerr("Cannot initialize the wireless-card, aborting");
48 exit(EXIT_FAILURE); 48 exit(EXIT_FAILURE);
49 } 49 }
50 wl_loginfo("Set card into monitor mode"); 50 wl_loginfo("Set card into monitor mode");
51 51
52 /* setup pcap */ 52 /* setup pcap */
53 if((handletopcap = pcap_open_live(cardtype.iface, 53 if((handletopcap = pcap_open_live(cardtype.iface,
54 BUFSIZ, 1, 0, NULL)) == NULL) 54 BUFSIZ, 1, 0, NULL)) == NULL)
55 { 55 {
56 wl_logerr("pcap_open_live() failed: %s", strerror(errno)); 56 wl_logerr("pcap_open_live() failed: %s", strerror(errno));
57 exit(EXIT_FAILURE); 57 exit(EXIT_FAILURE);
58 } 58 }
59 59
60#ifdef HAVE_PCAP_NONBLOCK 60#ifdef HAVE_PCAP_NONBLOCK
61 pcap_setnonblock(handletopcap, 1, NULL); 61 pcap_setnonblock(handletopcap, 1, NULL);
62#endif 62#endif
63 63
64 /* Setup socket for incoming commands */ 64 /* Setup socket for incoming commands */
65 if((sock=wl_setupsock(DAEMONADDR, DAEMONPORT, saddr)) < 0) 65 if((sock=wl_setupsock(DAEMONADDR, DAEMONPORT, saddr)) < 0)
66 { 66 {
67 wl_logerr("Cannot setup socket"); 67 wl_logerr("Cannot setup socket");
68 exit(EXIT_FAILURE); 68 exit(EXIT_FAILURE);
69 } 69 }
70 wl_loginfo("Set up socket '%d' for GUI communication", sock); 70 wl_loginfo("Set up socket '%d' for GUI communication", sock);
71 71
72 /* Create channelswitching thread */ 72 /* Create channelswitching thread */
73 if(pthread_create(&sub, NULL, channel_switcher, 73 if(pthread_create(&sub, NULL, channel_switcher,
74 (void *)&cardtype) != 0) 74 (void *)&cardtype) != 0)
75 { 75 {
76 wl_logerr("Cannot create thread: %s", strerror(errno)); 76 wl_logerr("Cannot create thread: %s", strerror(errno));
77 close(sock); 77 close(sock);
78 exit(EXIT_FAILURE); 78 exit(EXIT_FAILURE);
79 } 79 }
80 if(pthread_detach(sub)) 80 if(pthread_detach(sub))
81 { 81 {
82 wl_logerr("Error detaching thread"); 82 wl_logerr("Error detaching thread");
83 close(sock); 83 close(sock);
84 pthread_exit((pthread_t *)sub); 84 pthread_exit((pthread_t *)sub);
85 exit(EXIT_FAILURE); 85 exit(EXIT_FAILURE);
86 } 86 }
87 wl_loginfo("Created and detached channel switching thread"); 87 wl_loginfo("Created and detached channel switching thread");
88 88
89 FD_ZERO(&rset); 89 FD_ZERO(&rset);
90 90
91 /* Start main loop */ 91 /* Start main loop */
92 wl_loginfo("Starting main loop"); 92 wl_loginfo("Starting main loop");
93 while(1) 93 while(1)
94 { 94 {
95 95
96 FD_SET(sock, &rset); 96 FD_SET(sock, &rset);
97 FD_SET(pcap_fileno(handletopcap), &rset); 97 FD_SET(pcap_fileno(handletopcap), &rset);
98 98
99 /* maxfd = biggest filefd */ 99 /* maxfd = biggest filefd */
100 maxfd = (sock > pcap_fileno(handletopcap) ? 100 maxfd = (sock > pcap_fileno(handletopcap) ?
101 sock + 1 : pcap_fileno(handletopcap)) + 1; 101 sock + 1 : pcap_fileno(handletopcap)) + 1;
102 102
103 if(select(maxfd, &rset, NULL, NULL, NULL) < 0) 103 if(select(maxfd, &rset, NULL, NULL, NULL) < 0)
104 { 104 {
105 wl_logerr("Error calling select: %s", strerror(errno)); 105 wl_logerr("Error calling select: %s", strerror(errno));
106 break; 106 break;
107 } 107 }
108 108
109 /* Got data on local socket from GUI */ 109 /* Got data on local socket from GUI */
110 if(FD_ISSET(sock, &rset)) 110 if(FD_ISSET(sock, &rset))
111 { 111 {
112 /* Receive data from socket */ 112 /* Receive data from socket */
113 if((retval=wl_recv(&sock, saddr, buffer, sizeof(buffer))) < 0) 113 if((retval=wl_recv(&sock, saddr, buffer, sizeof(buffer))) < 0)
114 { 114 {
115 wl_logerr("Error trying to read: %s", strerror(errno)); 115 wl_logerr("Error trying to read: %s", strerror(errno));
116 break; 116 break;
117 } 117 }
118 else 118 else
119 { 119 {
120 /* check type of packet and start function according to it */ 120 /* check type of packet and start function according to it */
121 switch(retval) 121 switch(retval)
122 { 122 {
123 case 98: 123 case 98:
124 wl_loginfo("Received STARTSNIFF command"); 124 wl_loginfo("Received STARTSNIFF command");
125 break; 125 break;
126 case 99: 126 case 99:
127 wl_loginfo("Received STOPSNIFF command"); 127 wl_loginfo("Received STOPSNIFF command");
128 break; 128 break;
129 default: 129 default:
130 wl_logerr("Received unknown command: %d", retval); 130 wl_logerr("Received unknown command: %d", retval);
131 break; 131 break;
132 } 132 }
133 } 133 }
134 } /* FD_ISSET */ 134 } /* FD_ISSET */
135 135
136 /* Check pcap lib for packets */ 136 /* Check pcap lib for packets */
137 if(FD_ISSET(pcap_fileno(handletopcap), &rset)) 137 if(FD_ISSET(pcap_fileno(handletopcap), &rset))
138 { 138 {
139 139
140 /* Grab one single packet */ 140 /* Grab one single packet */
141 packet = pcap_next(handletopcap, &header); 141 packet = pcap_next(handletopcap, &header);
142 142
143 /* process the packet */ 143 /* process the packet */
144 process_packets(&header,*&packet, GUIADDR, GUIPORT); 144 process_packets(&header,*&packet, GUIADDR, GUIPORT);
145 } 145 }
146 146
147 } /* while(1) */ 147 } /* while(1) */
148 148
149 close(sock); 149 close(sock);
150 exit(EXIT_SUCCESS); 150 exit(EXIT_SUCCESS);
151} 151}
152 152
153void 153void
154usage(void) 154usage(void)
155{ 155{
156 fprintf(stderr, "Usage: wellenreiter <device> <cardtype>\n" \ 156 fprintf(stderr, "Usage: wellenreiter <device> <cardtype>\n" \
157 "\t<device> = Wirelessdevice (e.g. wlan0)\n" \ 157 "\t<device> = Wirelessdevice (e.g. wlan0)\n" \
158 "\t<cardtype> = Cardtype:\tCisco\t= 1\n" \ 158 "\t<cardtype> = Cardtype:\tCisco\t= 1\n" \
159 "\t\t\t\tNG\t= 2\n" \ 159 "\t\t\t\tNG\t= 2\n" \
160 "\t\t\t\tHOSTAP\t= 3\n" \ 160 "\t\t\t\tHOSTAP\t= 3\n" \
161 "\t\t\t\tLUCENT\t= 4\n"); 161 "\t\t\t\tLUCENT\t= 4\n");
162 exit(EXIT_FAILURE); 162 exit(EXIT_FAILURE);
163} 163}
164 164
165void * 165void *
166channel_switcher(void *cardtypeptr) 166channel_switcher(void *cardtypeptr)
167{ 167{
168 wl_cardtype_t *cardtype; 168 wl_cardtype_t *cardtype;
169 int channel=1; 169 int channel=1;
170 170
171 /* Get card info struct */ 171 /* Get card info struct */
172 cardtype = (wl_cardtype_t *)cardtypeptr; 172 cardtype = (wl_cardtype_t *)cardtypeptr;
173 173
174 while(1) 174 while(1)
175 { 175 {
176 176
177 /* If channel bigger than maxchannel, set to 1 */ 177 /* If channel bigger than maxchannel, set to 1 */
178 if(channel > MAXCHANNEL) 178 if(channel > MAXCHANNEL)
179 channel=1; 179 channel=1;
180 180
181 /* Set channel */ 181 /* Set channel */
182 if(!card_set_channel(cardtype->iface, channel, cardtype->type)) 182 if(!card_set_channel(cardtype->iface, channel, cardtype->type))
183 { 183 {
184 wl_logerr("Cannot set channel, thread exiting"); 184 wl_logerr("Cannot set channel, thread exiting");
185 pthread_exit(NULL); 185 pthread_exit(NULL);
186 } 186 }
187 187
188 /* sleep */ 188 /* sleep */
189 usleep(CHANINTERVAL); 189 usleep(CHANINTERVAL);
190 190
191 channel++; 191 channel++;
192 } /* while */ 192 } /* while */
193} 193}
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
index 0c23922..9e0a772 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
+++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
@@ -1,192 +1,210 @@
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 promiscous 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"); 26 wl_logerr("Cannot set interface to promisc mode");
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, "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=true", device, 1);
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 char hostapcmd[250]; 59 char hostapcmd[250];
60 snprintf(hostapcmd, sizeof(hostapcmd) -1, "%s %s monitor 2", IWPRIV_PATH, device); 60 snprintf(hostapcmd, sizeof(hostapcmd) -1, "$(which iwpriv) %s monitor 2 %d", device,1);
61 if (system(hostapcmd) !=0) 61 if (system(hostapcmd) !=0)
62 { 62 {
63 wl_logerr("Could not set %s in raw mode, check cardtype", device); 63 wl_logerr("Could not set %s in raw mode, check cardtype", device);
64 return 0; 64 return 0;
65 } 65 }
66 } 66 }
67 else if (cardtype == CARD_TYPE_ORINOCCO) 67 else if (cardtype == CARD_TYPE_ORINOCCO || cardtype == CARD_TYPE_HOSTAP)
68 { 68 {
69 char lucentcmd[62]; 69 if (!card_set_channel (device, 1, CARD_TYPE_ORINOCCO))
70 snprintf(lucentcmd, sizeof(lucentcmd) - 1, "$(which iwpriv) %s monitor 2 %d", device, 1); 70 {
71 if (system(lucentcmd) != 0) 71 wl_logerr("Could not set %s in raw mode, check cardtype", device);
72 { 72 return 0;
73 wl_logerr("Could not set %s in raw mode, check cardtype", device);
74 return 0;
75 } 73 }
76 else 74 else
77 { 75 {
78 wl_loginfo("Successfully set %s into raw mode",device); 76 wl_loginfo("Successfully set %s into raw mode",device);
79 } 77 }
80 } 78 }
81 79
82 /* Setting the promiscous and up flag to the interface */ 80 /* Setting the promiscous and up flag to the interface */
83 if (!card_check_rfmon_datalink(device)) 81 if (!card_check_rfmon_datalink(device))
84 { 82 {
85 wl_logerr("Cannot set interface to rfmon mode"); 83 wl_logerr("Cannot set interface to rfmon mode");
86 return 0; 84 return 0;
87 } 85 }
88 else 86 else
89 { 87 {
90 wl_loginfo("Interface set to rfmon mode"); 88 wl_loginfo("Interface set to rfmon mode");
91 } 89 }
92 return 1; 90 return 1;
93} 91}
94 92
95/* Check card is in the rfmon mode */ 93/* Check card is in the rfmon mode */
96int card_check_rfmon_datalink (char *device) 94int card_check_rfmon_datalink (char *device)
97{ 95{
98 int datalinktype=0; 96 int datalinktype=0;
99 pcap_t *phandle; 97 pcap_t *phandle;
100 phandle = pcap_open_live(device, 65,0,0,NULL); 98 phandle = pcap_open_live(device, 65,0,0,NULL);
101 datalinktype = pcap_datalink (phandle); 99 datalinktype = pcap_datalink (phandle);
102 pcap_close(phandle); 100 pcap_close(phandle);
103 101
104 if (datalinktype != DLT_IEEE802_11) /* Rawmode is IEEE802_11 */ 102 if (datalinktype != DLT_IEEE802_11) /* Rawmode is IEEE802_11 */
105 { 103 {
106 return 0; 104 return 0;
107 } 105 }
108 else 106 else
109 { 107 {
110 wl_loginfo("Your successfully listen on %s in 802.11 raw mode", device); 108 wl_loginfo("Your successfully listen on %s in 802.11 raw mode", device);
111 return 1; 109 return 1;
112 } 110 }
113} 111}
114 112
115/* Set card into promisc mode */ 113/* Set card into promisc mode */
116int card_set_promisc_up (const char *device) 114int card_set_promisc_up (const char *device)
117{ 115{
118 int err; 116 int err;
119 /* First generate a socket to use with iocalls */ 117 /* First generate a socket to use with iocalls */
120 int fd = socket(AF_INET, SOCK_DGRAM, 0); 118 int fd = socket(AF_INET, SOCK_DGRAM, 0);
121 if (fd < 0) 119 if (fd < 0)
122 { 120 {
123 /* In case of an error */ 121 /* In case of an error */
124 perror("socket"); 122 perror("socket");
125 return 0; 123 return 0;
126 } 124 }
127 125
128 /* Fill an empty an interface structure with the right flags (UP and Promsic) */ 126 /* Fill an empty an interface structure with the right flags (UP and Promsic) */
129 struct ifreq ifr; 127 struct ifreq ifr;
130 strncpy(ifr.ifr_name, device,10); 128 strncpy(ifr.ifr_name, device,10);
131 ifr.ifr_flags = IFF_UP + IFF_PROMISC; 129 ifr.ifr_flags = IFF_UP + IFF_PROMISC;
132 err = ioctl(fd, SIOCSIFFLAGS, &ifr); 130 err = ioctl(fd, SIOCSIFFLAGS, &ifr);
133 if (err < 0) 131 if (err < 0)
134 { 132 {
135 perror("Could not access the interface, "); 133 perror("Could not access the interface, ");
136 return 0; 134 return 0;
137 } 135 }
138 136
139 /* Get the informations back from the interface to check if the flags are correct */ 137 /* Get the informations back from the interface to check if the flags are correct */
140 strncpy(ifr.ifr_name, device,10); 138 strncpy(ifr.ifr_name, device,10);
141 ioctl(fd, SIOCGIFFLAGS, &ifr); 139 ioctl(fd, SIOCGIFFLAGS, &ifr);
142 if (err < 0) 140 if (err < 0)
143 { 141 {
144 perror("Could not access the interface, "); 142 perror("Could not access the interface, ");
145 return 0; 143 return 0;
146 } 144 }
147 145
148 if(ifr.ifr_flags && IFF_UP) 146 if(ifr.ifr_flags && IFF_UP)
149 { 147 {
150 printf("%s is ok\n", device); 148 printf("%s is ok\n", device);
151 return 1; 149 return 1;
152 } 150 }
153 else 151 else
154 { 152 {
155 printf("%s flags could not be set", device); 153 printf("%s flags could not be set", device);
156 return 0; 154 return 0;
157 } 155 }
158} 156}
159 157
160/* Set channel (Wireless frequency) of the device */ 158/* Set channel (Wireless frequency) of the device */
161int card_set_channel (const char *device, int channel, int cardtype) 159int card_set_channel (const char *device, int channel, int cardtype)
162{ 160{
163 if (cardtype == CARD_TYPE_CISCO) 161 if (cardtype == CARD_TYPE_CISCO)
164 { 162 {
165 /* Cisco cards don't need channelswitching */ 163 /* Cisco cards don't need channelswitching */
166 return 1; 164 return 1;
167 } 165 }
168 /* If it is a lucent orinocco card */ 166 /* If it is a lucent orinocco card */
169 else if (cardtype == CARD_TYPE_ORINOCCO) 167 else if (cardtype == CARD_TYPE_ORINOCCO || cardtype == CARD_TYPE_HOSTAP)
170 { 168 {
171 char lucentreset[63]; 169 int fd;
172 char lucentcmd[62]; 170 //Wireless tools structure for the iocalls
173 snprintf(lucentreset, sizeof(lucentreset) -1,"$(which iwpriv) %s force_reset", device); 171 struct iwreq ireq;
174 if (system(lucentreset) != 0) 172 int *ptr;
175 { 173 /* Socket needed to use the iocall to */
176 wl_logerr("Could not reset the card %s",device); 174 fd = socket(AF_INET, SOCK_STREAM, 0);
177 return 0; 175 if ( fd == -1 ) {
178 } 176 return -1;
179 snprintf(lucentcmd, sizeof(lucentcmd) - 1, "$(which iwpriv) %s monitor 2 %d", device, channel); 177 }
180 if (system(lucentcmd) != 0) 178 ptr = (int *) ireq.u.name;
181 { 179 // This is the monitor mode for 802.11 non-prism header
182 wl_logerr("Could not set %s in raw mode, check cardtype", device); 180 ptr[0] = 2;
183 return 0; 181 ptr[1] = channel;
184 } 182 strcpy(ireq.ifr_ifrn.ifrn_name, device);
185 wl_loginfo("Channel %d set on interface %s",channel,device); 183 if (ioctl( fd, SIOCIWFIRSTPRIV + 0x8, &ireq)==0)
186 return 1; 184 {
185 /* All was fine... */
186 // close(fd);
187 wl_loginfo("Set channel %d on interface %s",channel, device);
188 return 1;
189 }
190 else
191 { /* iocall does not work */
192 wl_logerr("Could not set channel %d on %s, check cardtype",channel, device);
193 return 0;
194 }
187 } 195 }
188 196 else if (cardtype == CARD_TYPE_NG)
197 {
198 char wlanngcmd[62];
199 snprintf(wlanngcmd, sizeof(wlanngcmd) - 1, "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=true", device, channel);
200 if (system(wlanngcmd) != 0)
201 {
202 wl_logerr("Could not set channel %d on %s, check cardtype",channel, device);
203 return 0;
204 }
205
206 }
189 /* For undefined situations */ 207 /* For undefined situations */
190 return 0; 208 return 0;
191} 209}
192 210
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
index 3a1991b..242d8c5 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
+++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
@@ -1,44 +1,47 @@
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/types.h> 9#include <sys/types.h>
10#include <sys/time.h> 10#include <sys/time.h>
11#include <sys/socket.h> 11#include <sys/socket.h>
12#include <netinet/in.h> 12#include <netinet/in.h>
13#include <arpa/inet.h> 13#include <arpa/inet.h>
14#include <sys/ioctl.h> 14#include <sys/ioctl.h>
15#include <linux/if.h> 15#include <linux/if.h>
16#include <linux/wireless.h>
17
18#ifndef SIOCIWFIRSTPRIV
19#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
20#endif
21
16 22
17extern "C" 23extern "C"
18{ 24{
19#include <net/bpf.h> 25#include <net/bpf.h>
20#include <pcap.h> 26#include <pcap.h>
21} 27}
22 28
23/* Defines, used for the card setup */ 29/* Defines, used for the card setup */
24#define DEFAULT_PATH "/proc/driver/aironet/%s/Config" 30#define DEFAULT_PATH "/proc/driver/aironet/%s/Config"
25#define CISCO_STATUS "/proc/driver/aironet/%s/Status" 31#define CISCO_STATUS "/proc/driver/aironet/%s/Status"
26 #define CARD_TYPE_CISCO 1 32 #define CARD_TYPE_CISCO 1
27 #define CARD_TYPE_NG 2 33 #define CARD_TYPE_NG 2
28 #define CARD_TYPE_HOSTAP3 34 #define CARD_TYPE_HOSTAP3
29#define CARD_TYPE_ORINOCCO 4 35#define CARD_TYPE_ORINOCCO 4
30 36
31/* only for now, until we have the daemon running */ 37/* only for now, until we have the daemon running */
32/*the config file should provide these information */ 38/*the config file should provide these information */
33#define CARD_TYPE CARD_TYPE_HOSTAP 39#define CARD_TYPE CARD_TYPE_HOSTAP
34 #define SBIN_PATH "/sbin/ifconfig %s promisc up"
35#define WLANCTL_PATH "/sbin/wlanctl-ng"
36 #define IWPRIV_PATH "/sbin/iwpriv"
37 40
38/* Prototypes */ 41/* Prototypes */
39int card_check_rfmon_datalink (char *device); 42int card_check_rfmon_datalink (char *device);
40int card_into_monitormode (pcap_t **, char *, int); 43int card_into_monitormode (pcap_t **, char *, int);
41int card_set_promisc_up (const char *); 44int card_set_promisc_up (const char *);
42int card_set_channel (const char *device, int channel,int cardtype); 45int card_set_channel (const char *device, int channel,int cardtype);
43 46
44#endif /* CARDMODE_HH */ 47#endif /* CARDMODE_HH */