change wrt54g packet source to automatically switch to monitor mode without wl, add...
[oweals/openwrt.git] / openwrt / package / kismet / patches / 130-wrt54g_source.patch
1 diff -urN kismet.old/kis_packsources.cc kismet.dev/kis_packsources.cc
2 --- kismet.old/kis_packsources.cc       2005-07-25 12:18:47.230369000 +0200
3 +++ kismet.dev/kis_packsources.cc       2005-07-25 12:54:44.654390736 +0200
4 @@ -165,7 +165,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, NULL, chancontrol_wext, 1);
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-04-03 07:33:42.000000000 +0200
15 +++ kismet.dev/packetsourcetracker.cc   2005-07-25 13:29:45.698983408 +0200
16 @@ -978,6 +978,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 @@ -999,6 +1000,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-07-25 12:18:47.234368000 +0200
34 +++ kismet.dev/pcapsource.cc    2005-07-25 12:51:19.426590104 +0200
35 @@ -140,6 +140,48 @@
36      return 1;
37  }
38  
39 +
40 +// Open a source
41 +int PcapSourceWrt54g::OpenSource() {
42 +    channel = 0;
43 +
44 +    errstr[0] = '\0';
45 +
46 +    char *unconst = strdup("prism0");
47 +
48 +    pd = pcap_open_live(unconst, MAX_PACKET_LEN, 1, 1000, errstr);
49 +
50 +    free(unconst);
51 +
52 +    if (strlen(errstr) > 0)
53 +        return -1; // Error is already in errstr
54 +
55 +    paused = 0;
56 +
57 +    errstr[0] = '\0';
58 +
59 +    num_packets = 0;
60 +
61 +    if (DatalinkType() < 0)
62 +        return -1;
63 +
64 +#ifdef HAVE_PCAP_NONBLOCK
65 +    pcap_setnonblock(pd, 1, errstr);
66 +#elif !defined(SYS_OPENBSD)
67 +    // do something clever  (Thanks to Guy Harris for suggesting this).
68 +    int save_mode = fcntl(pcap_get_selectable_fd(pd), F_GETFL, 0);
69 +    if (fcntl(pcap_get_selectable_fd(pd), F_SETFL, save_mode | O_NONBLOCK) < 0) {
70 +        snprintf(errstr, 1024, "fcntl failed, errno %d (%s)",
71 +                 errno, strerror(errno));
72 +    }
73 +#endif
74 +
75 +    if (strlen(errstr) > 0)
76 +        return -1; // Ditto
77 +    
78 +    return 1;
79 +}
80 +
81  // Datalink, override as appropriate
82  carrier_type PcapSource::IEEE80211Carrier() {
83      int ch = FetchChannel();
84 @@ -1609,7 +1651,7 @@
85  int monitor_wrt54g(const char *in_dev, int initch, char *in_err, void **in_if, void *in_ext) {
86      char cmdline[2048];
87  
88 -    snprintf(cmdline, 2048, "/usr/sbin/wl monitor 1");
89 +    snprintf(cmdline, 2048, "/usr/sbin/iwpriv %s set_monitor 1", in_dev);
90      if (RunSysCmd(cmdline) < 0) {
91          snprintf(in_err, 1024, "Unable to execute '%s'", cmdline);
92          return -1;
93 diff -urN kismet.old/pcapsource.h kismet.dev/pcapsource.h
94 --- kismet.old/pcapsource.h     2005-04-03 07:33:42.000000000 +0200
95 +++ kismet.dev/pcapsource.h     2005-07-25 12:49:22.089428064 +0200
96 @@ -250,11 +250,13 @@
97  
98  // Override packet fetching logic on this one to discard jumbo corrupt packets
99  // that it likes to generate
100 +// Override OpenSource() to use prism0 as pcap device
101  class PcapSourceWrt54g : public PcapSource {
102  public:
103      PcapSourceWrt54g(string in_name, string in_dev) : PcapSource(in_name, in_dev) { 
104          fcsbytes = 4;
105      }
106 +    int OpenSource();
107      int FetchPacket(kis_packet *packet, uint8_t *data, uint8_t *moddata);
108  protected:
109      carrier_type IEEE80211Carrier();