-rw-r--r-- | noncore/net/wellenreiter/daemon/source/daemon.cc | 26 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/daemon.hh | 1 | ||||
-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc | 9 |
3 files changed, 25 insertions, 11 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc index d6e8f6b..b57e6a0 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.cc +++ b/noncore/net/wellenreiter/daemon/source/daemon.cc | |||
@@ -1,157 +1,165 @@ | |||
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 | // temporary solution, will be removed soon | 10 | // temporary solution, will be removed soon |
11 | #define MAXCHANNEL 13 | 11 | #define MAXCHANNEL 13 |
12 | int card_type; | ||
12 | char sniffer_device[6]; | 13 | char sniffer_device[6]; |
13 | int channel=0; | 14 | int channel=0; |
14 | int timedout=1; | 15 | int timedout=1; |
15 | 16 | ||
16 | static int chanswitch() | 17 | void chanswitch(int blah) |
17 | { | 18 | { |
18 | if(channel >= MAXCHANNEL) | 19 | if(channel >= MAXCHANNEL) |
19 | channel=1 | 20 | { |
21 | channel=1; | ||
22 | } | ||
23 | else | ||
24 | { | ||
25 | channel++; | ||
26 | } | ||
20 | card_set_channel(sniffer_device, channel, card_type); | 27 | card_set_channel(sniffer_device, channel, card_type); |
21 | timedout=0; | 28 | timedout=0; |
29 | alarm(1); | ||
22 | } | 30 | } |
23 | 31 | ||
24 | /* Main function of wellenreiterd */ | 32 | /* Main function of wellenreiterd */ |
25 | int main(int argc, char **argv) | 33 | int main(int argc, char **argv) |
26 | { | 34 | { |
27 | int sock, maxfd, retval, card_type; | 35 | int sock, maxfd, retval; |
28 | char buffer[WL_SOCKBUF]; | 36 | char buffer[WL_SOCKBUF]; |
29 | struct pcap_pkthdr header; | 37 | struct pcap_pkthdr header; |
30 | struct sockaddr_in saddr; | 38 | struct sockaddr_in saddr; |
31 | pcap_t *handletopcap; | 39 | pcap_t *handletopcap; |
32 | const unsigned char *packet; | 40 | const unsigned char *packet; |
33 | 41 | ||
34 | fd_set rset; | 42 | fd_set rset; |
35 | 43 | ||
36 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); | 44 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); |
37 | fprintf(stderr, "(c) 2002 by M-M-M\n\n"); | 45 | fprintf(stderr, "(c) 2002 by M-M-M\n\n"); |
38 | 46 | ||
39 | if(argc < 3) | 47 | if(argc < 3) |
40 | usage(); | 48 | usage(); |
41 | 49 | ||
42 | // removed soon, see above | 50 | // removed soon, see above |
43 | SIGNAL(SIGALRM, chanswitch); | 51 | signal(SIGALRM, chanswitch); |
44 | 52 | alarm(1); | |
45 | /* Set sniffer device */ | 53 | /* Set sniffer device */ |
46 | memset(sniffer_device, 0, sizeof(sniffer_device)); | 54 | memset(sniffer_device, 0, sizeof(sniffer_device)); |
47 | strncpy(sniffer_device, (char *)argv[1], sizeof(sniffer_device) - 1); | 55 | strncpy(sniffer_device, (char *)argv[1], sizeof(sniffer_device) - 1); |
48 | 56 | ||
49 | /* Set card type */ | 57 | /* Set card type */ |
50 | card_type = atoi(argv[2]); | 58 | card_type = atoi(argv[2]); |
51 | if(card_type < 1 || card_type > 3) | 59 | if(card_type < 1 || card_type > 4) |
52 | usage(); | 60 | usage(); |
53 | 61 | ||
54 | if(!card_into_monitormode(&handletopcap, sniffer_device, card_type)) | 62 | if(!card_into_monitormode(&handletopcap, sniffer_device, card_type)) |
55 | { | 63 | { |
56 | wl_logerr("Cannot initialize the wireless-card, aborting"); | 64 | wl_logerr("Cannot initialize the wireless-card, aborting"); |
57 | exit(-1); | 65 | exit(-1); |
58 | } | 66 | } |
59 | wl_loginfo("Set card into monitor mode"); | 67 | wl_loginfo("Set card into monitor mode"); |
60 | 68 | ||
61 | /////// following line will be moved to lib as soon as possible //////////// | 69 | /////// following line will be moved to lib as soon as possible //////////// |
62 | if((handletopcap = pcap_open_live(sniffer_device, BUFSIZ, 1, 0, NULL)) == NULL) | 70 | if((handletopcap = pcap_open_live(sniffer_device, BUFSIZ, 1, 0, NULL)) == NULL) |
63 | { | 71 | { |
64 | wl_logerr("pcap_open_live() failed: %s", strerror(errno)); | 72 | wl_logerr("pcap_open_live() failed: %s", strerror(errno)); |
65 | exit(-1); | 73 | exit(-1); |
66 | } | 74 | } |
67 | 75 | ||
68 | #ifdef HAVE_PCAP_NONBLOCK | 76 | #ifdef HAVE_PCAP_NONBLOCK |
69 | pcap_setnonblock(handletopcap, 1, NULL); | 77 | pcap_setnonblock(handletopcap, 1, NULL); |
70 | #endif | 78 | #endif |
71 | 79 | ||
72 | //////////////////////////////////////// | 80 | //////////////////////////////////////// |
73 | 81 | ||
74 | /* Setup socket for incoming commands */ | 82 | /* Setup socket for incoming commands */ |
75 | if((sock=wl_setupsock(DAEMONADDR, DAEMONPORT, saddr)) < 0) | 83 | if((sock=wl_setupsock(DAEMONADDR, DAEMONPORT, saddr)) < 0) |
76 | { | 84 | { |
77 | wl_logerr("Cannot setup socket"); | 85 | wl_logerr("Cannot setup socket"); |
78 | exit(-1); | 86 | exit(-1); |
79 | } | 87 | } |
80 | wl_loginfo("Set up socket '%d' for GUI communication", sock); | 88 | wl_loginfo("Set up socket '%d' for GUI communication", sock); |
81 | 89 | ||
82 | FD_ZERO(&rset); | 90 | FD_ZERO(&rset); |
83 | 91 | ||
84 | /* Start main loop */ | 92 | /* Start main loop */ |
85 | wl_loginfo("Starting main loop"); | 93 | wl_loginfo("Starting main loop"); |
86 | while(1) | 94 | while(1) |
87 | { | 95 | { |
88 | 96 | ||
89 | FD_SET(sock, &rset); | 97 | FD_SET(sock, &rset); |
90 | FD_SET(pcap_fileno(handletopcap), &rset); | 98 | FD_SET(pcap_fileno(handletopcap), &rset); |
91 | 99 | ||
92 | // blah | 100 | // blah |
93 | timedout=1; | 101 | timedout=1; |
94 | alarm(1); | ||
95 | 102 | ||
96 | /* socket or pcap handle bigger? Will be cleaned up, have to check pcap */ | 103 | /* socket or pcap handle bigger? Will be cleaned up, have to check pcap */ |
97 | maxfd = (sock > pcap_fileno(handletopcap) ? sock : pcap_fileno(handletopcap)) + 1; | 104 | maxfd = (sock > pcap_fileno(handletopcap) ? sock : pcap_fileno(handletopcap)) + 1; |
98 | 105 | ||
99 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0 && timedout) | 106 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0 && timedout) |
100 | { | 107 | { |
101 | wl_logerr("Error calling select: %s", strerror(errno)); | 108 | wl_logerr("Error calling select: %s", strerror(errno)); |
102 | break; | 109 | break; |
103 | } | 110 | } |
104 | 111 | ||
105 | /* Got data on local socket from GUI */ | 112 | /* Got data on local socket from GUI */ |
106 | if(FD_ISSET(sock, &rset)) | 113 | if(FD_ISSET(sock, &rset)) |
107 | { | 114 | { |
108 | /* Receive data from socket */ | 115 | /* Receive data from socket */ |
109 | if((retval=wl_recv(&sock, saddr, buffer, sizeof(buffer))) < 0 && timedout) | 116 | if((retval=wl_recv(&sock, saddr, buffer, sizeof(buffer))) < 0 && timedout) |
110 | { | 117 | { |
111 | wl_logerr("Error trying to read: %s", strerror(errno)); | 118 | wl_logerr("Error trying to read: %s", strerror(errno)); |
112 | break; | 119 | break; |
113 | } | 120 | } |
114 | else | 121 | else |
115 | { | 122 | { |
116 | /* check type of packet and start function according to it */ | 123 | /* check type of packet and start function according to it */ |
117 | switch(retval) | 124 | switch(retval) |
118 | { | 125 | { |
119 | case 98: | 126 | case 98: |
120 | wl_loginfo("Received STARTSNIFF command"); | 127 | wl_loginfo("Received STARTSNIFF command"); |
121 | break; | 128 | break; |
122 | case 99: | 129 | case 99: |
123 | wl_loginfo("Received STOPSNIFF command"); | 130 | wl_loginfo("Received STOPSNIFF command"); |
124 | break; | 131 | break; |
125 | default: | 132 | default: |
126 | wl_logerr("Received unknown command: %d", retval); | 133 | wl_logerr("Received unknown command: %d", retval); |
127 | break; | 134 | break; |
128 | } | 135 | } |
129 | } | 136 | } |
130 | } /* FD_ISSET */ | 137 | } /* FD_ISSET */ |
131 | 138 | ||
132 | /* Check pcap lib for packets */ | 139 | /* Check pcap lib for packets */ |
133 | if(FD_ISSET(pcap_fileno(handletopcap), &rset)) | 140 | if(FD_ISSET(pcap_fileno(handletopcap), &rset)) |
134 | { | 141 | { |
135 | 142 | ||
136 | /* Grab one single packet */ | 143 | /* Grab one single packet */ |
137 | packet = pcap_next(handletopcap, &header); | 144 | packet = pcap_next(handletopcap, &header); |
138 | 145 | ||
139 | /* process the packet */ | 146 | /* process the packet */ |
140 | process_packets(&header,*&packet, GUIADDR, GUIPORT); | 147 | process_packets(&header,*&packet, GUIADDR, GUIPORT); |
141 | } | 148 | } |
142 | 149 | ||
143 | } /* while(1) */ | 150 | } /* while(1) */ |
144 | 151 | ||
145 | close(sock); | 152 | close(sock); |
146 | exit(0); | 153 | exit(0); |
147 | } | 154 | } |
148 | 155 | ||
149 | void usage(void) | 156 | void usage(void) |
150 | { | 157 | { |
151 | fprintf(stderr, "Usage: wellenreiter <device> <cardtype>\n" \ | 158 | fprintf(stderr, "Usage: wellenreiter <device> <cardtype>\n" \ |
152 | "\t<device> = Wirelessdevice (e.g. wlan0)\n" \ | 159 | "\t<device> = Wirelessdevice (e.g. wlan0)\n" \ |
153 | "\t<cardtype> = Cardtype:\t Cisco\t= 1\n" \ | 160 | "\t<cardtype> = Cardtype:\tCisco\t= 1\n" \ |
154 | "\t\t\t\tNG\t= 2\n" \ | 161 | "\t\t\t\tNG\t= 2\n" \ |
155 | "\t\t\t\tHOSTAP\t= 3\n"); | 162 | "\t\t\t\tHOSTAP\t= 3\n" \ |
163 | "\t\t\t\tLUCENT\t= 4\n"); | ||
156 | exit(-1); | 164 | exit(-1); |
157 | } | 165 | } |
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.hh b/noncore/net/wellenreiter/daemon/source/daemon.hh index 1cc3c7c..d50487a 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.hh +++ b/noncore/net/wellenreiter/daemon/source/daemon.hh | |||
@@ -1,25 +1,26 @@ | |||
1 | /* $Id$ */ | 1 | /* $Id$ */ |
2 | 2 | ||
3 | #ifndef DAEMON_HH | 3 | #ifndef DAEMON_HH |
4 | #define DAEMON_HH | 4 | #define DAEMON_HH |
5 | 5 | ||
6 | #include <stdio.h> | 6 | #include <stdio.h> |
7 | #include <string.h> | 7 | #include <string.h> |
8 | #include <sys/types.h> | 8 | #include <sys/types.h> |
9 | #include <sys/time.h> | 9 | #include <sys/time.h> |
10 | #include <sys/socket.h> | 10 | #include <sys/socket.h> |
11 | #include <netinet/in.h> | 11 | #include <netinet/in.h> |
12 | #include <arpa/inet.h> | 12 | #include <arpa/inet.h> |
13 | #include <unistd.h> | 13 | #include <unistd.h> |
14 | #include <errno.h> | 14 | #include <errno.h> |
15 | #include <signal.h> | ||
15 | 16 | ||
16 | #include <libwellenreiter/source/wl_sock.hh> | 17 | #include <libwellenreiter/source/wl_sock.hh> |
17 | #include <libwellenreiter/source/wl_log.hh> | 18 | #include <libwellenreiter/source/wl_log.hh> |
18 | #include <libwellenreiter/source/wl_types.hh> | 19 | #include <libwellenreiter/source/wl_types.hh> |
19 | #include <libwellenreiter/source/wl_proto.hh> | 20 | #include <libwellenreiter/source/wl_proto.hh> |
20 | #include <libwellenreiter/source/cardmode.hh> | 21 | #include <libwellenreiter/source/cardmode.hh> |
21 | #include <libwellenreiter/source/sniff.hh> | 22 | #include <libwellenreiter/source/sniff.hh> |
22 | 23 | ||
23 | void usage(void); | 24 | void usage(void); |
24 | 25 | ||
25 | #endif /* DAEMON_HH */ | 26 | #endif /* DAEMON_HH */ |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc index 697d182..0c23922 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc | |||
@@ -1,187 +1,192 @@ | |||
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 */ |
11 | int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype) | 11 | int 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, "%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 | 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, "%s %s monitor 2", IWPRIV_PATH, device); |
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) |
68 | { | 68 | { |
69 | char lucentcmd[62]; | 69 | char lucentcmd[62]; |
70 | snprintf(lucentcmd, sizeof(lucentcmd) - 1, "$(which iwpriv) %s monitor 2 %d", device, 1); | 70 | snprintf(lucentcmd, sizeof(lucentcmd) - 1, "$(which iwpriv) %s monitor 2 %d", device, 1); |
71 | if (system(lucentcmd) != 0) | 71 | if (system(lucentcmd) != 0) |
72 | { | 72 | { |
73 | wl_logerr("Could not set %s in raw mode, check cardtype", device); | 73 | wl_logerr("Could not set %s in raw mode, check cardtype", device); |
74 | return 0; | 74 | return 0; |
75 | } | 75 | } |
76 | else | ||
77 | { | ||
78 | wl_loginfo("Successfully set %s into raw mode",device); | ||
79 | } | ||
76 | } | 80 | } |
77 | 81 | ||
78 | /* Setting the promiscous and up flag to the interface */ | 82 | /* Setting the promiscous and up flag to the interface */ |
79 | if (!card_check_rfmon_datalink(device)) | 83 | if (!card_check_rfmon_datalink(device)) |
80 | { | 84 | { |
81 | wl_logerr("Cannot set interface to rfmon mode"); | 85 | wl_logerr("Cannot set interface to rfmon mode"); |
82 | return 0; | 86 | return 0; |
83 | } | 87 | } |
84 | else | 88 | else |
85 | { | 89 | { |
86 | wl_loginfo("Interface set to rfmon mode"); | 90 | wl_loginfo("Interface set to rfmon mode"); |
87 | } | 91 | } |
88 | return 1; | 92 | return 1; |
89 | } | 93 | } |
90 | 94 | ||
91 | /* Check card is in the rfmon mode */ | 95 | /* Check card is in the rfmon mode */ |
92 | int card_check_rfmon_datalink (char *device) | 96 | int card_check_rfmon_datalink (char *device) |
93 | { | 97 | { |
94 | int datalinktype=0; | 98 | int datalinktype=0; |
95 | pcap_t *phandle; | 99 | pcap_t *phandle; |
96 | phandle = pcap_open_live(device, 65,0,0,NULL); | 100 | phandle = pcap_open_live(device, 65,0,0,NULL); |
97 | datalinktype = pcap_datalink (phandle); | 101 | datalinktype = pcap_datalink (phandle); |
98 | pcap_close(phandle); | 102 | pcap_close(phandle); |
99 | 103 | ||
100 | if (datalinktype != DLT_IEEE802_11) /* Rawmode is IEEE802_11 */ | 104 | if (datalinktype != DLT_IEEE802_11) /* Rawmode is IEEE802_11 */ |
101 | { | 105 | { |
102 | return 0; | 106 | return 0; |
103 | } | 107 | } |
104 | else | 108 | else |
105 | { | 109 | { |
106 | wl_loginfo("Your successfully listen on %s in 802.11 raw mode", device); | 110 | wl_loginfo("Your successfully listen on %s in 802.11 raw mode", device); |
107 | return 1; | 111 | return 1; |
108 | } | 112 | } |
109 | } | 113 | } |
110 | 114 | ||
111 | /* Set card into promisc mode */ | 115 | /* Set card into promisc mode */ |
112 | int card_set_promisc_up (const char *device) | 116 | int card_set_promisc_up (const char *device) |
113 | { | 117 | { |
114 | int err; | 118 | int err; |
115 | /* First generate a socket to use with iocalls */ | 119 | /* First generate a socket to use with iocalls */ |
116 | int fd = socket(AF_INET, SOCK_DGRAM, 0); | 120 | int fd = socket(AF_INET, SOCK_DGRAM, 0); |
117 | if (fd < 0) | 121 | if (fd < 0) |
118 | { | 122 | { |
119 | /* In case of an error */ | 123 | /* In case of an error */ |
120 | perror("socket"); | 124 | perror("socket"); |
121 | return 0; | 125 | return 0; |
122 | } | 126 | } |
123 | 127 | ||
124 | /* Fill an empty an interface structure with the right flags (UP and Promsic) */ | 128 | /* Fill an empty an interface structure with the right flags (UP and Promsic) */ |
125 | struct ifreq ifr; | 129 | struct ifreq ifr; |
126 | strncpy(ifr.ifr_name, device,10); | 130 | strncpy(ifr.ifr_name, device,10); |
127 | ifr.ifr_flags = IFF_UP + IFF_PROMISC; | 131 | ifr.ifr_flags = IFF_UP + IFF_PROMISC; |
128 | err = ioctl(fd, SIOCSIFFLAGS, &ifr); | 132 | err = ioctl(fd, SIOCSIFFLAGS, &ifr); |
129 | if (err < 0) | 133 | if (err < 0) |
130 | { | 134 | { |
131 | perror("Could not access the interface, "); | 135 | perror("Could not access the interface, "); |
132 | return 0; | 136 | return 0; |
133 | } | 137 | } |
134 | 138 | ||
135 | /* Get the informations back from the interface to check if the flags are correct */ | 139 | /* Get the informations back from the interface to check if the flags are correct */ |
136 | strncpy(ifr.ifr_name, device,10); | 140 | strncpy(ifr.ifr_name, device,10); |
137 | ioctl(fd, SIOCGIFFLAGS, &ifr); | 141 | ioctl(fd, SIOCGIFFLAGS, &ifr); |
138 | if (err < 0) | 142 | if (err < 0) |
139 | { | 143 | { |
140 | perror("Could not access the interface, "); | 144 | perror("Could not access the interface, "); |
141 | return 0; | 145 | return 0; |
142 | } | 146 | } |
143 | 147 | ||
144 | if(ifr.ifr_flags && IFF_UP) | 148 | if(ifr.ifr_flags && IFF_UP) |
145 | { | 149 | { |
146 | printf("%s is ok\n", device); | 150 | printf("%s is ok\n", device); |
147 | return 1; | 151 | return 1; |
148 | } | 152 | } |
149 | else | 153 | else |
150 | { | 154 | { |
151 | printf("%s flags could not be set", device); | 155 | printf("%s flags could not be set", device); |
152 | return 0; | 156 | return 0; |
153 | } | 157 | } |
154 | } | 158 | } |
155 | 159 | ||
156 | /* Set channel (Wireless frequency) of the device */ | 160 | /* Set channel (Wireless frequency) of the device */ |
157 | int card_set_channel (const char *device, int channel, int cardtype) | 161 | int card_set_channel (const char *device, int channel, int cardtype) |
158 | { | 162 | { |
159 | |||
160 | if (cardtype == CARD_TYPE_CISCO) | 163 | if (cardtype == CARD_TYPE_CISCO) |
161 | { | 164 | { |
162 | /* Cisco cards don't need channelswitching */ | 165 | /* Cisco cards don't need channelswitching */ |
163 | return 1; | 166 | return 1; |
164 | } | 167 | } |
165 | /* If it is a lucent orinocco card */ | 168 | /* If it is a lucent orinocco card */ |
166 | else if (cardtype == CARD_TYPE_ORINOCCO) | 169 | else if (cardtype == CARD_TYPE_ORINOCCO) |
167 | { | 170 | { |
168 | char lucentreset[63]; | 171 | char lucentreset[63]; |
169 | char lucentcmd[62]; | 172 | char lucentcmd[62]; |
170 | snprintf(lucentreset, sizeof(lucentreset) -1,"$(which iwpriv) %s card_reset", device); | 173 | snprintf(lucentreset, sizeof(lucentreset) -1,"$(which iwpriv) %s force_reset", device); |
171 | if (system(lucentreset) != 0) | 174 | if (system(lucentreset) != 0) |
172 | { | 175 | { |
173 | wl_logerr("Could not reset the card %s",device); | 176 | wl_logerr("Could not reset the card %s",device); |
174 | return 0; | 177 | return 0; |
175 | } | 178 | } |
176 | snprintf(lucentcmd, sizeof(lucentcmd) - 1, "$(which iwpriv) %s monitor 2 %d", device, channel); | 179 | snprintf(lucentcmd, sizeof(lucentcmd) - 1, "$(which iwpriv) %s monitor 2 %d", device, channel); |
177 | if (system(lucentcmd) != 0) | 180 | if (system(lucentcmd) != 0) |
178 | { | 181 | { |
179 | wl_logerr("Could not set %s in raw mode, check cardtype", device); | 182 | wl_logerr("Could not set %s in raw mode, check cardtype", device); |
180 | return 0; | 183 | return 0; |
181 | } | 184 | } |
185 | wl_loginfo("Channel %d set on interface %s",channel,device); | ||
186 | return 1; | ||
182 | } | 187 | } |
183 | 188 | ||
184 | /* For undefined situations */ | 189 | /* For undefined situations */ |
185 | return 0; | 190 | return 0; |
186 | } | 191 | } |
187 | 192 | ||