1 /*
2 This file is part of Kismet
3
4 Kismet is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 Kismet is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with Kismet; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 #include "config.h"
20
21 #include <unistd.h>
22 #include "globalregistry.h"
23 #include "util.h"
24 #include "macaddr.h"
25
26 #include "dumpfile.h"
27
GlobalRegistry()28 GlobalRegistry::GlobalRegistry() {
29 fatal_condition = 0;
30 spindown = 0;
31
32 winch = false;
33
34 argc = 0;
35 argv = NULL;
36 envp = NULL;
37
38 kismet_instance = KISMET_INSTANCE_SERVER;
39
40 getopt_long_num = 127;
41
42 next_ext_ref = 0;
43
44 messagebus = NULL;
45 plugintracker = NULL;
46 sourcetracker = NULL;
47 netracker = NULL;
48 packetchain = NULL;
49 alertracker = NULL;
50 timetracker = NULL;
51 kisnetserver = NULL;
52 kisdroneserver = NULL;
53 kismet_config = NULL;
54 kismetui_config = NULL;
55 soundctl = NULL;
56 builtindissector = NULL;
57 rootipc = NULL;
58 panel_interface = NULL;
59 manufdb = NULL;
60
61 start_time = 0;
62
63 metric = 0;
64
65 for (int x = 0; x < PROTO_REF_MAX; x++)
66 netproto_map[x] = -1;
67
68 filter_tracker = 0;
69 filter_tracker_bssid_invert = -1;
70 filter_tracker_source_invert = -1;
71 filter_tracker_dest_invert = -1;
72
73 filter_dump = 0;
74 filter_dump_bssid_invert = -1;
75 filter_dump_source_invert = -1;
76 filter_dump_dest_invert = -1;
77
78 filter_export = 0;
79 filter_export_bssid_invert = -1;
80 filter_export_source_invert = -1;
81 filter_export_dest_invert = -1;
82
83 broadcast_mac = mac_addr("FF:FF:FF:FF:FF:FF");
84
85 alert_backlog = 0;
86
87 for (unsigned int x = 0; x < PACK_COMP_MAX; x++)
88 packetcomp_map[x] = -1;
89
90 for (unsigned int x = 0; x < ALERT_REF_MAX; x++)
91 alertref_map[x] = -1;
92
93 pcapdump = NULL;
94
95 nlhandle = NULL;
96
97 checksum_packets = 0;
98 }
99
100 // External globals -- allow other things to tie structs to us
RegisterGlobal(string in_name)101 int GlobalRegistry::RegisterGlobal(string in_name) {
102 map<string, int>::iterator i;
103
104 if ((i = ext_name_map.find(StrLower(in_name))) != ext_name_map.end())
105 return i->second;
106
107 ext_name_map[StrLower(in_name)] = next_ext_ref++;
108
109 return next_ext_ref;
110 }
111
FetchGlobalRef(string in_name)112 int GlobalRegistry::FetchGlobalRef(string in_name) {
113 if (ext_name_map.find(StrLower(in_name)) == ext_name_map.end())
114 return -1;
115
116 return ext_name_map[StrLower(in_name)];
117 }
118
FetchGlobal(int in_ref)119 void *GlobalRegistry::FetchGlobal(int in_ref) {
120 if (ext_data_map.find(in_ref) == ext_data_map.end())
121 return NULL;
122
123 return ext_data_map[in_ref];
124 }
125
FetchGlobal(string in_name)126 void *GlobalRegistry::FetchGlobal(string in_name) {
127 int ref;
128
129 if ((ref = FetchGlobalRef(in_name)) < 0)
130 return NULL;
131
132 return ext_data_map[ref];
133 }
134
InsertGlobal(int in_ref,void * in_data)135 int GlobalRegistry::InsertGlobal(int in_ref, void *in_data) {
136 if (ext_data_map.find(in_ref) == ext_data_map.end())
137 return -1;
138
139 ext_data_map[in_ref] = in_data;
140
141 return 1;
142 }
143
InsertGlobal(string in_name,void * in_data)144 int GlobalRegistry::InsertGlobal(string in_name, void *in_data) {
145 int ref = RegisterGlobal(in_name);
146
147 return InsertGlobal(ref, in_data);
148 }
149
RegisterPollableSubsys(Pollable * in_subcli)150 int GlobalRegistry::RegisterPollableSubsys(Pollable *in_subcli) {
151 subsys_pollable_vec.push_back(in_subcli);
152 return 1;
153 }
154
RemovePollableSubsys(Pollable * in_subcli)155 int GlobalRegistry::RemovePollableSubsys(Pollable *in_subcli) {
156 for (unsigned int x = 0; x < subsys_pollable_vec.size(); x++) {
157 if (subsys_pollable_vec[x] == in_subcli) {
158 subsys_pollable_vec.erase(subsys_pollable_vec.begin() + x);
159 return 1;
160 }
161 }
162 return 0;
163 }
164
RegisterDumpFile(Dumpfile * in_dump)165 void GlobalRegistry::RegisterDumpFile(Dumpfile *in_dump) {
166 subsys_dumpfile_vec.push_back(in_dump);
167 }
168
RemoveDumpFile(Dumpfile * in_dump)169 int GlobalRegistry::RemoveDumpFile(Dumpfile *in_dump) {
170 for (unsigned int x = 0; x < subsys_dumpfile_vec.size(); x++) {
171 if (subsys_dumpfile_vec[x] == in_dump) {
172 subsys_dumpfile_vec.erase(subsys_dumpfile_vec.begin() + x);
173 return 1;
174 }
175 }
176 return 0;
177 }
178
FindDumpFileType(string in_type)179 Dumpfile *GlobalRegistry::FindDumpFileType(string in_type) {
180 string type = StrUpper(in_type);
181 for (unsigned int x = 0; x < subsys_dumpfile_vec.size(); x++) {
182 if (StrUpper(subsys_dumpfile_vec[x]->FetchFileType()) == type) {
183 return subsys_dumpfile_vec[x];
184 }
185 }
186
187 return NULL;
188 }
189