port libao to buildroot-ng
[openwrt/svn-archive/archive.git] / net / kismet / patches / 100-wrt54g_source.patch
1 diff -urN kismet.old/kis_packsources.cc kismet.dev/kis_packsources.cc
2 --- kismet.old/kis_packsources.cc 2005-08-16 03:22:51.000000000 +0200
3 +++ kismet.dev/kis_packsources.cc 2005-08-23 00:59:04.465379568 +0200
4 @@ -192,7 +192,7 @@
5 chancontrol_wlanng_avs, 1);
6 sourcetracker->RegisterPacketsource("wrt54g", 1, "na", 0,
7 pcapsource_wrt54g_registrant,
8 - monitor_wrt54g, NULL, NULL, 0);
9 + monitor_wrt54g, unmonitor_wrt54g, chancontrol_wext, 0);
10 #else
11 REG_EMPTY_CARD(sourcetracker, "wlanng");
12 REG_EMPTY_CARD(sourcetracker, "wlanng_avs");
13 diff -urN kismet.old/packetsourcetracker.cc kismet.dev/packetsourcetracker.cc
14 --- kismet.old/packetsourcetracker.cc 2005-08-16 03:22:51.000000000 +0200
15 +++ kismet.dev/packetsourcetracker.cc 2005-08-23 00:59:39.969982048 +0200
16 @@ -986,6 +986,7 @@
17 (meta_packsources[chanpak.meta_num]->device.c_str(),
18 chanpak.channel, errstr,
19 (void *) (meta_packsources[chanpak.meta_num]->capsource)) < 0) {
20 +#if 0
21
22 meta_packsources[chanpak.meta_num]->consec_errors++;
23
24 @@ -1007,6 +1008,7 @@
25 CHANFLAG_FATAL));
26 continue;
27 }
28 +#endif
29 } else {
30 // Otherwise reset the error count
31 meta_packsources[chanpak.meta_num]->consec_errors = 0;
32 diff -urN kismet.old/pcapsource.cc kismet.dev/pcapsource.cc
33 --- kismet.old/pcapsource.cc 2005-08-16 03:22:51.000000000 +0200
34 +++ kismet.dev/pcapsource.cc 2005-08-23 01:03:45.652632608 +0200
35 @@ -115,6 +115,53 @@
36 u_char callback_data[MAX_PACKET_LEN];
37
38 // Open a source
39 +int PcapSourceWrt54g::OpenSource() {
40 + channel = 0;
41 +
42 + errstr[0] = '\0';
43 +
44 + char *unconst = strdup("prism0");
45 +
46 + pd = pcap_open_live(unconst, MAX_PACKET_LEN, 1, 1000, errstr);
47 +
48 + #if defined (SYS_OPENBSD) || defined(SYS_NETBSD) && defined(HAVE_RADIOTAP)
49 + /* Request desired DLT on multi-DLT systems that default to EN10MB. We do this
50 + later anyway but doing it here ensures we have the desired DLT from the get go. */
51 + pcap_set_datalink(pd, DLT_IEEE802_11_RADIO);
52 + #endif
53 +
54 + free(unconst);
55 +
56 + if (strlen(errstr) > 0)
57 + return -1; // Error is already in errstr
58 +
59 + paused = 0;
60 +
61 + errstr[0] = '\0';
62 +
63 + num_packets = 0;
64 +
65 + if (DatalinkType() < 0)
66 + return -1;
67 +
68 +#ifdef HAVE_PCAP_NONBLOCK
69 + pcap_setnonblock(pd, 1, errstr);
70 +#elif !defined(SYS_OPENBSD)
71 + // do something clever (Thanks to Guy Harris for suggesting this).
72 + int save_mode = fcntl(pcap_get_selectable_fd(pd), F_GETFL, 0);
73 + if (fcntl(pcap_get_selectable_fd(pd), F_SETFL, save_mode | O_NONBLOCK) < 0) {
74 + snprintf(errstr, 1024, "fcntl failed, errno %d (%s)",
75 + errno, strerror(errno));
76 + }
77 +#endif
78 +
79 + if (strlen(errstr) > 0)
80 + return -1; // Ditto
81 +
82 + return 1;
83 +}
84 +
85 +// Open a source
86 int PcapSource::OpenSource() {
87 channel = 0;
88
89 @@ -1928,63 +1975,32 @@
90 int monitor_wrt54g(const char *in_dev, int initch, char *in_err, void **in_if,
91 void *in_ext) {
92 char cmdline[2048];
93 - int mode;
94 - int wlmode = 0;
95 -
96 -#ifdef HAVE_LINUX_WIRELESS
97 - vector<string> devbits = StrTokenize(in_dev, ":");
98
99 - if (devbits.size() < 2) {
100 - snprintf(cmdline, 2048, "/usr/sbin/wl monitor 1");
101 + snprintf(cmdline, 2048, "/usr/sbin/iwpriv %s set_monitor 1", in_dev);
102 if (RunSysCmd(cmdline) < 0) {
103 - snprintf(in_err, 1024, "Unable to set mode using 'wl monitor 1'. Some "
104 - "custom firmware images require you to specify the origial "
105 + snprintf(in_err, 1024, "Unable to set mode using 'iwpriv %s set_monitor 1'. "
106 + "Some custom firmware images require you to specify the origial "
107 "device and a new dynamic device and use the iwconfig controls. "
108 "see the README for how to configure your capture source.");
109 return -1;
110 }
111 - } else {
112 - // Get the mode ... If this doesn't work, try the old wl method.
113 - if (Iwconfig_Get_Mode(devbits[0].c_str(), in_err, &mode) < 0) {
114 - fprintf(stderr, "WARNING: Getting wireless mode via ioctls failed, "
115 - "defaulting to trying the 'wl' command.\n");
116 - wlmode = 1;
117 - }
118
119 - if (wlmode == 1) {
120 - snprintf(cmdline, 2048, "/usr/sbin/wl monitor 1");
121 - if (RunSysCmd(cmdline) < 0) {
122 - snprintf(in_err, 1024, "Unable to execute '%s'", cmdline);
123 - return -1;
124 - }
125 - } else if (mode != LINUX_WLEXT_MONITOR) {
126 - // Set it
127 - if (Iwconfig_Set_Mode(devbits[0].c_str(), in_err,
128 - LINUX_WLEXT_MONITOR) < 0) {
129 - snprintf(in_err, STATUS_MAX, "Unable to set iwconfig monitor "
130 - "mode. If you are using an older wrt54g, try specifying "
131 - "only the ethernet device, not ethX:prismX");
132 - return -1;
133 - }
134 + return 1;
135 +}
136 +
137 +
138 +int unmonitor_wrt54g(const char *in_dev, int initch, char *in_err, void **in_if,
139 + void *in_ext) {
140 + char cmdline[2048];
141 +
142 + snprintf(cmdline, 2048, "/usr/sbin/iwpriv %s set_monitor 0", in_dev);
143 + if (RunSysCmd(cmdline) < 0) {
144 + snprintf(in_err, 1024, "Unable to set mode using 'iwpriv %s set_monitor 0'. "
145 + "Some custom firmware images require you to specify the origial "
146 + "device and a new dynamic device and use the iwconfig controls. "
147 + "see the README for how to configure your capture source.");
148 + return -1;
149 }
150 - }
151 -#else
152 - snprintf(cmdline, 2048, "/usr/sbin/wl monitor 1");
153 - if (RunSysCmd(cmdline) < 0) {
154 - snprintf(in_err, 1024, "Unable to set mode using 'wl monitor 1'. Some "
155 - "custom firmware images require you to specify the origial "
156 - "device and a new dynamic device and use the iwconfig controls. "
157 - "see the README for how to configure your capture source. "
158 - "Support for wireless extensions was not compiled in, so more "
159 - "advanced modes of setting monitor mode are not available.");
160 - return -1;
161 - }
162 - fprintf(stderr, "WARNING: Support for wireless extensions was not compiled "
163 - "into this binary. Using the iw* tools to set monitor mode will not "
164 - "be available. This may cause opening the source to fail on some "
165 - "firmware versions. To fix this, make sure wireless extensions are "
166 - "available and found by the configure script when building Kismet.");
167 -#endif
168
169 return 1;
170 }
171 diff -urN kismet.old/pcapsource.h kismet.dev/pcapsource.h
172 --- kismet.old/pcapsource.h 2005-08-16 03:22:51.000000000 +0200
173 +++ kismet.dev/pcapsource.h 2005-08-23 01:04:26.057490136 +0200
174 @@ -265,6 +265,7 @@
175 PcapSourceWrt54g(string in_name, string in_dev) : PcapSource(in_name, in_dev) {
176 fcsbytes = 4;
177 }
178 + int OpenSource();
179 int FetchPacket(kis_packet *packet, uint8_t *data, uint8_t *moddata);
180 protected:
181 carrier_type IEEE80211Carrier();
182 @@ -412,6 +413,7 @@
183 int monitor_wlanng_avs(const char *in_dev, int initch, char *in_err, void **in_if, void *in_ext);
184 // linksys wrt54g monitoring
185 int monitor_wrt54g(const char *in_dev, int initch, char *in_err, void **in_if, void *in_ext);
186 +int unmonitor_wrt54g(const char *in_dev, int initch, char *in_err, void **in_if, void *in_ext);
187 #endif
188
189 // This should be expanded to handle BSD...