2a0eac24a3890347631ba3af775e40f7b7242746
[openwrt/staging/dedeckeh.git] / openwrt / package / kismet / patches / 120-wrt54g_source.patch
1 diff -urN kismet.old/kis_packsources.cc kismet.dev/kis_packsources.cc
2 --- kismet.old/kis_packsources.cc 2005-08-15 00:15:11.107594000 +0200
3 +++ kismet.dev/kis_packsources.cc 2005-08-15 01:56:36.467769104 +0200
4 @@ -215,7 +215,7 @@
5 #endif
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-15 00:33:14.628874000 +0200
15 +++ kismet.dev/packetsourcetracker.cc 2005-08-15 01:20:41.284203096 +0200
16 @@ -984,6 +984,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 @@ -1005,6 +1006,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-15 00:40:28.291416000 +0200
34 +++ kismet.dev/pcapsource.cc 2005-08-15 01:55:53.972229408 +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 @@ -1561,45 +1608,39 @@
90
91 int monitor_wrt54g(const char *in_dev, int initch, char *in_err, void **in_if,
92 void *in_ext) {
93 - char cmdline[2048];
94 + char cmdline[2048];
95 int mode;
96 int wlmode = 0;
97
98 - vector<string> devbits = StrTokenize(in_dev, ":");
99 + vector<string> devbits = StrTokenize(in_dev, ":");
100
101 - if (devbits.size() < 2) {
102 - snprintf(cmdline, 2048, "/usr/sbin/wl monitor 1");
103 - if (RunSysCmd(cmdline) < 0) {
104 - snprintf(in_err, 1024, "Unable to set mode using 'wl monitor 1'. Some "
105 - "custom firmware images require you to specify the origial "
106 - "device and a new dynamic device and use the iwconfig controls. "
107 - "see the README for how to configure your capture source.");
108 - return -1;
109 - }
110 - } else {
111 - // Get the mode ... If this doesn't work, try the old wl method.
112 - if (Iwconfig_Get_Mode(devbits[0].c_str(), in_err, &mode) < 0) {
113 - fprintf(stderr, "WARNING: Getting wireless mode via ioctls failed, "
114 - "defaulting to trying the 'wl' command.\n");
115 - wlmode = 1;
116 - }
117 + snprintf(cmdline, 2048, "/usr/sbin/iwpriv %s set_monitor 1", in_dev);
118 + if (RunSysCmd(cmdline) < 0) {
119 + snprintf(in_err, 1024, "Unable to set mode using 'iwpriv %s set_monitor 1'. Some "
120 + "custom firmware images require you to specify the origial "
121 + "device and a new dynamic device and use the iwconfig controls. "
122 + "see the README for how to configure your capture source.", in_dev);
123 + return -1;
124 + }
125
126 - if (wlmode == 1) {
127 - snprintf(cmdline, 2048, "/usr/sbin/wl monitor 1");
128 - if (RunSysCmd(cmdline) < 0) {
129 - snprintf(in_err, 1024, "Unable to execute '%s'", cmdline);
130 - return -1;
131 - }
132 - } else if (mode != LINUX_WLEXT_MONITOR) {
133 - // Set it
134 - if (Iwconfig_Set_Mode(devbits[0].c_str(), in_err,
135 - LINUX_WLEXT_MONITOR) < 0) {
136 - snprintf(in_err, STATUS_MAX, "Unable to set iwconfig monitor "
137 - "mode. If you are using an older wrt54g, try specifying "
138 - "only the ethernet device, not ethX:prismX");
139 - return -1;
140 - }
141 - }
142 + return 1;
143 +}
144 +
145 +int unmonitor_wrt54g(const char *in_dev, int initch, char *in_err, void **in_if,
146 + void *in_ext) {
147 + char cmdline[2048];
148 + int mode;
149 + int wlmode = 0;
150 +
151 + vector<string> devbits = StrTokenize(in_dev, ":");
152 +
153 + snprintf(cmdline, 2048, "/usr/sbin/iwpriv %s set_monitor 0", in_dev);
154 + if (RunSysCmd(cmdline) < 0) {
155 + snprintf(in_err, 1024, "Unable to set mode using 'iwpriv %s set_monitor 0'. Some "
156 + "custom firmware images require you to specify the origial "
157 + "device and a new dynamic device and use the iwconfig controls. "
158 + "see the README for how to configure your capture source.", in_dev);
159 + return -1;
160 }
161
162 return 1;
163 diff -urN kismet.old/pcapsource.h kismet.dev/pcapsource.h
164 --- kismet.old/pcapsource.h 2005-08-15 00:42:50.849744000 +0200
165 +++ kismet.dev/pcapsource.h 2005-08-15 01:56:07.649150200 +0200
166 @@ -265,6 +265,7 @@
167 PcapSourceWrt54g(string in_name, string in_dev) : PcapSource(in_name, in_dev) {
168 fcsbytes = 4;
169 }
170 + int OpenSource();
171 int FetchPacket(kis_packet *packet, uint8_t *data, uint8_t *moddata);
172 protected:
173 carrier_type IEEE80211Carrier();
174 @@ -388,6 +389,7 @@
175 #ifdef SYS_LINUX
176 // linksys wrt54g monitoring
177 int monitor_wrt54g(const char *in_dev, int initch, char *in_err, void **in_if, void *in_ext);
178 +int unmonitor_wrt54g(const char *in_dev, int initch, char *in_err, void **in_if, void *in_ext);
179 #endif
180
181 // This should be expanded to handle BSD...