File: packetsource.h

package info (click to toggle)
kismet 2008-05-R1-4.1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,236 kB
  • ctags: 3,998
  • sloc: cpp: 33,568; sh: 5,544; ansic: 459; makefile: 457; perl: 62; sql: 41
file content (157 lines) | stat: -rw-r--r-- 3,961 bytes parent folder | download | duplicates (2)
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
/*
    This file is part of Kismet

    Kismet is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    Kismet is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Kismet; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#ifndef __PACKETSOURCE_H__
#define __PACKETSOURCE_H__

#include "config.h"

#include <string>
#include <errno.h>

#include "packet.h"
#include "timetracker.h"
#include "gpsd.h"

// All packetsources need to provide out-of-class functions for the 
// packetsourcetracker class
//
// typedef KisPacketSource *(*packsource_registrant)(string, string);
// typedef int (*packsource_chcontrol)(char *, int, char *);
// typedef int (*packsource_monitor)(char *, int, char *);

// Packet capture source superclass
class KisPacketSource {
public:
    KisPacketSource(string in_name, string in_dev) {
        name = in_name;
        interface = in_dev;

        gpsd = NULL;
        timetracker = NULL;

        fcsbytes = 0;

		parameters.fuzzy_crypt = 0;
		parameters.fuzzy_decode = 0;

		flag = 0;
    }

    virtual ~KisPacketSource() { };

    // Open the packet source
    virtual int OpenSource() = 0;

    virtual int CloseSource() = 0;

    // Get the channel
    virtual int FetchChannel() {
		return channel;
	}

	// Set the logical channel (ie, when chan control returns to us)
	virtual void SetLocalChannel(int in_ch) {
		channel = in_ch;
	}

    // Get the FD of our packet source
    virtual int FetchDescriptor() = 0;

    // Get a packet from the medium
    virtual int FetchPacket(kis_packet *packet, uint8_t *data, uint8_t *moddata) = 0;

    // Register a timer event handler for us to use
    void AddTimetracker(Timetracker *in_tracker) { timetracker = in_tracker; }

    // Register the GPS server for us to use
    void AddGpstracker(GPSD *in_gpsd) { gpsd = in_gpsd; }

    // Get the error
    char *FetchError() { return(errstr); }

    // Get the name
    const char *FetchName() { return(name.c_str()); }

    // Get the interface
    const char *FetchInterface() { return(interface.c_str()); }
	// Set the interface
	void SetInterface(string in_if) { interface = in_if; }

    // Fetch number of packets
    int FetchNumPackets() { return num_packets; }

    // Ignore incoming packets
    void Pause() { paused = 1; };

    // Stop ignoring incoming packets
    void Resume() { paused = 0; };

	// Misc flag
	void SetFlag(int in_flag) { flag = in_flag; }
	int FetchFlag() { return flag; }

    // Set packet parameters
    void SetPackparm(packet_parm in_parameters) {
		if (in_parameters.fuzzy_crypt != -1)
			parameters.fuzzy_crypt = in_parameters.fuzzy_crypt;
		if (in_parameters.fuzzy_decode != -1)
			parameters.fuzzy_decode = in_parameters.fuzzy_decode;
    }

    // Get packet parameters
    packet_parm GetPackparm() {
        return parameters;
    }

    // Bytes in the FCS - public so monitor can write it
    int fcsbytes;
protected:
    // Get the bytes in the fcs
    virtual int FCSBytes() {
        return fcsbytes;
    }

    // Global tracking pointers
    Timetracker *timetracker;
    GPSD *gpsd;

    char errstr[1024];

    int paused;

	// Random flag to denote "something" (as defined by a subclass)
	int flag;

    // Name, interface
    string name;
    string interface;

    // Various parameters we track
    packet_parm parameters;

    // Total packets
    unsigned int num_packets;

    // Current channel, if we don't fetch it live
    int channel;

};


#endif