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