author | mjm <mjm> | 2003-02-09 15:48:34 (UTC) |
---|---|---|
committer | mjm <mjm> | 2003-02-09 15:48:34 (UTC) |
commit | cc96fbb10eaeef5796f62ac26635b1b6ff42145b (patch) (unidiff) | |
tree | 75b51de32c68edc3e4f0c8cc0e81f0952b91027f /noncore/net/wellenreiter/daemon/source | |
parent | cade16aa686978486acab98bc98602ede356ac09 (diff) | |
download | opie-cc96fbb10eaeef5796f62ac26635b1b6ff42145b.zip opie-cc96fbb10eaeef5796f62ac26635b1b6ff42145b.tar.gz opie-cc96fbb10eaeef5796f62ac26635b1b6ff42145b.tar.bz2 |
implemented new timer function, threaded
added wl_cardtype_t
Diffstat (limited to 'noncore/net/wellenreiter/daemon/source') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/daemon.cc | 109 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/daemon.hh | 3 |
2 files changed, 69 insertions, 43 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc index b57e6a0..4407436 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.cc +++ b/noncore/net/wellenreiter/daemon/source/daemon.cc | |||
@@ -9,23 +9,5 @@ | |||
9 | 9 | ||
10 | // temporary solution, will be removed soon | 10 | /* should be parsed from cfg-file */ |
11 | #define MAXCHANNEL 13 | 11 | #define MAXCHANNEL 13 |
12 | int card_type; | 12 | #define CHANINTERVAL 100000 |
13 | char sniffer_device[6]; | ||
14 | int channel=0; | ||
15 | int timedout=1; | ||
16 | |||
17 | void chanswitch(int blah) | ||
18 | { | ||
19 | if(channel >= MAXCHANNEL) | ||
20 | { | ||
21 | channel=1; | ||
22 | } | ||
23 | else | ||
24 | { | ||
25 | channel++; | ||
26 | } | ||
27 | card_set_channel(sniffer_device, channel, card_type); | ||
28 | timedout=0; | ||
29 | alarm(1); | ||
30 | } | ||
31 | 13 | ||
@@ -39,2 +21,4 @@ int main(int argc, char **argv) | |||
39 | pcap_t *handletopcap; | 21 | pcap_t *handletopcap; |
22 | wl_cardtype_t cardtype; | ||
23 | pthread_t sub; | ||
40 | const unsigned char *packet; | 24 | const unsigned char *packet; |
@@ -49,18 +33,15 @@ int main(int argc, char **argv) | |||
49 | 33 | ||
50 | // removed soon, see above | ||
51 | signal(SIGALRM, chanswitch); | ||
52 | alarm(1); | ||
53 | /* Set sniffer device */ | 34 | /* Set sniffer device */ |
54 | memset(sniffer_device, 0, sizeof(sniffer_device)); | 35 | memset(cardtype.iface, 0, sizeof(cardtype.iface)); |
55 | strncpy(sniffer_device, (char *)argv[1], sizeof(sniffer_device) - 1); | 36 | strncpy(cardtype.iface, (char *)argv[1], sizeof(cardtype.iface) - 1); |
56 | 37 | ||
57 | /* Set card type */ | 38 | /* Set card type */ |
58 | card_type = atoi(argv[2]); | 39 | cardtype.type = atoi(argv[2]); |
59 | if(card_type < 1 || card_type > 4) | 40 | if(cardtype.type < 1 || cardtype.type > 4) |
60 | usage(); | 41 | usage(); |
61 | 42 | ||
62 | if(!card_into_monitormode(&handletopcap, sniffer_device, card_type)) | 43 | if(!card_into_monitormode(&handletopcap, cardtype.iface, cardtype.type)) |
63 | { | 44 | { |
64 | wl_logerr("Cannot initialize the wireless-card, aborting"); | 45 | wl_logerr("Cannot initialize the wireless-card, aborting"); |
65 | exit(-1); | 46 | exit(EXIT_FAILURE); |
66 | } | 47 | } |
@@ -68,7 +49,8 @@ int main(int argc, char **argv) | |||
68 | 49 | ||
50 | |||
69 | /////// following line will be moved to lib as soon as possible //////////// | 51 | /////// following line will be moved to lib as soon as possible //////////// |
70 | if((handletopcap = pcap_open_live(sniffer_device, BUFSIZ, 1, 0, NULL)) == NULL) | 52 | if((handletopcap = pcap_open_live(cardtype.iface, BUFSIZ, 1, 0, NULL)) == NULL) |
71 | { | 53 | { |
72 | wl_logerr("pcap_open_live() failed: %s", strerror(errno)); | 54 | wl_logerr("pcap_open_live() failed: %s", strerror(errno)); |
73 | exit(-1); | 55 | exit(EXIT_FAILURE); |
74 | } | 56 | } |
@@ -78,5 +60,5 @@ int main(int argc, char **argv) | |||
78 | #endif | 60 | #endif |
79 | 61 | //////////////////////////////////////// | |
80 | //////////////////////////////////////// | ||
81 | 62 | ||
63 | |||
82 | /* Setup socket for incoming commands */ | 64 | /* Setup socket for incoming commands */ |
@@ -85,3 +67,3 @@ int main(int argc, char **argv) | |||
85 | wl_logerr("Cannot setup socket"); | 67 | wl_logerr("Cannot setup socket"); |
86 | exit(-1); | 68 | exit(EXIT_FAILURE); |
87 | } | 69 | } |
@@ -89,2 +71,18 @@ int main(int argc, char **argv) | |||
89 | 71 | ||
72 | /* Create channelswitching thread */ | ||
73 | if(pthread_create(&sub, NULL, channel_switcher, (void *)&cardtype) != 0) | ||
74 | { | ||
75 | wl_logerr("Cannot create thread: %s", strerror(errno)); | ||
76 | close(sock); | ||
77 | exit(EXIT_FAILURE); | ||
78 | } | ||
79 | if(pthread_detach(sub)) | ||
80 | { | ||
81 | wl_logerr("Error detaching thread"); | ||
82 | close(sock); | ||
83 | pthread_exit((pthread_t *)sub); | ||
84 | exit(EXIT_FAILURE); | ||
85 | } | ||
86 | wl_loginfo("Created and detached channel switching thread"); | ||
87 | |||
90 | FD_ZERO(&rset); | 88 | FD_ZERO(&rset); |
@@ -99,9 +97,6 @@ int main(int argc, char **argv) | |||
99 | 97 | ||
100 | // blah | ||
101 | timedout=1; | ||
102 | |||
103 | /* socket or pcap handle bigger? Will be cleaned up, have to check pcap */ | 98 | /* socket or pcap handle bigger? Will be cleaned up, have to check pcap */ |
104 | maxfd = (sock > pcap_fileno(handletopcap) ? sock : pcap_fileno(handletopcap)) + 1; | 99 | maxfd = (sock > pcap_fileno(handletopcap) ? sock + 1: pcap_fileno(handletopcap)) + 1; |
105 | 100 | ||
106 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0 && timedout) | 101 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) |
107 | { | 102 | { |
@@ -115,3 +110,3 @@ int main(int argc, char **argv) | |||
115 | /* Receive data from socket */ | 110 | /* Receive data from socket */ |
116 | if((retval=wl_recv(&sock, saddr, buffer, sizeof(buffer))) < 0 && timedout) | 111 | if((retval=wl_recv(&sock, saddr, buffer, sizeof(buffer))) < 0) |
117 | { | 112 | { |
@@ -152,3 +147,3 @@ int main(int argc, char **argv) | |||
152 | close(sock); | 147 | close(sock); |
153 | exit(0); | 148 | exit(EXIT_SUCCESS); |
154 | } | 149 | } |
@@ -163,3 +158,33 @@ void usage(void) | |||
163 | "\t\t\t\tLUCENT\t= 4\n"); | 158 | "\t\t\t\tLUCENT\t= 4\n"); |
164 | exit(-1); | 159 | exit(EXIT_FAILURE); |
160 | } | ||
161 | |||
162 | void * | ||
163 | channel_switcher(void *cardtypeptr) | ||
164 | { | ||
165 | wl_cardtype_t *cardtype; | ||
166 | int channel=1; | ||
167 | |||
168 | /* Get card info struct */ | ||
169 | cardtype = (wl_cardtype_t *)cardtypeptr; | ||
170 | |||
171 | while(1) | ||
172 | { | ||
173 | |||
174 | /* If channel bigger than maxchannel, set to 1 */ | ||
175 | if(channel > MAXCHANNEL) | ||
176 | channel=1; | ||
177 | |||
178 | /* Set channel */ | ||
179 | if(!card_set_channel(cardtype->iface, channel, cardtype->type)) | ||
180 | { | ||
181 | wl_logerr("Cannot set channel, thread exiting"); | ||
182 | pthread_exit(NULL); | ||
183 | } | ||
184 | |||
185 | /* sleep */ | ||
186 | usleep(CHANINTERVAL); | ||
187 | |||
188 | channel++; | ||
189 | } /* while */ | ||
165 | } | 190 | } |
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.hh b/noncore/net/wellenreiter/daemon/source/daemon.hh index d50487a..f9ac45e 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.hh +++ b/noncore/net/wellenreiter/daemon/source/daemon.hh | |||
@@ -12,5 +12,5 @@ | |||
12 | #include <arpa/inet.h> | 12 | #include <arpa/inet.h> |
13 | #include <pthread.h> | ||
13 | #include <unistd.h> | 14 | #include <unistd.h> |
14 | #include <errno.h> | 15 | #include <errno.h> |
15 | #include <signal.h> | ||
16 | 16 | ||
@@ -24,2 +24,3 @@ | |||
24 | void usage(void); | 24 | void usage(void); |
25 | void *channel_switcher(void *); | ||
25 | 26 | ||