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 #ifndef __GLOBALREGISTRY_H__ 20 #define __GLOBALREGISTRY_H__ 21 22 #include "config.h" 23 24 #include <unistd.h> 25 #include "util.h" 26 #include "macaddr.h" 27 // #include "packet.h" 28 29 // Pre-defs for all the things we point to 30 class MessageBus; 31 class Packetsourcetracker; 32 33 // Old network tracking core due to be removed 34 class Netracker; 35 // new multiphy tracking core 36 class Devicetracker; 37 38 class Packetchain; 39 class Alertracker; 40 class Timetracker; 41 class KisNetFramework; 42 class KisDroneFramework; 43 class ConfigFile; 44 class GroupConfigFile; 45 class SoundControl; 46 class Plugintracker; 47 class KisBuiltinDissector; 48 // We need these for the vectors of subservices to poll 49 class Pollable; 50 // Vector of dumpfiles to destroy 51 class Dumpfile; 52 // ipc system 53 class IPCRemote; 54 class RootIPCRemote; 55 class KisPanelInterface; 56 // Manuf db 57 class Manuf; 58 // Pcap dump (only built-in dumpfile which supports plugin hooks currently) 59 class Dumpfile_Pcap; 60 61 #define KISMET_INSTANCE_SERVER 0 62 #define KISMET_INSTANCE_DRONE 1 63 #define KISMET_INSTANCE_CLIENT 2 64 65 // These are the offsets into the array of protocol references, not 66 // the reference itself. 67 // tcpserver protocol numbers for all the builtin protocols kismet 68 // uses and needs to refer to internally. Modules are on their own 69 // for tracking this. 70 #define PROTO_REF_KISMET 0 71 #define PROTO_REF_ERROR 1 72 #define PROTO_REF_ACK 2 73 #define PROTO_REF_PROTOCOL 3 74 #define PROTO_REF_CAPABILITY 4 75 #define PROTO_REF_TERMINATE 5 76 #define PROTO_REF_TIME 6 77 #define PROTO_REF_BSSID 7 78 #define PROTO_REF_CLIENT 8 79 #define PROTO_REF_CARD 9 80 #define PROTO_REF_GPS 10 81 #define PROTO_REF_ALERT 11 82 #define PROTO_REF_STATUS 12 83 #define PROTO_REF_INFO 13 84 #define PROTO_REF_REMOVE 14 85 #define PROTO_REF_PACKET 15 86 #define PROTO_REF_STRING 16 87 #define PROTO_REF_WEPKEY 17 88 #define PROTO_REF_SSID 18 89 #define PROTO_REF_MAX 19 90 91 // Same game, packet component references 92 #define PACK_COMP_80211 0 93 #define PACK_COMP_TURBOCELL 1 94 #define PACK_COMP_RADIODATA 2 95 #define PACK_COMP_GPS 3 96 #define PACK_COMP_LINKFRAME 4 97 #define PACK_COMP_80211FRAME 5 98 #define PACK_COMP_MANGLEFRAME 6 99 #define PACK_COMP_TRACKERNET 7 100 #define PACK_COMP_TRACKERCLIENT 8 101 #define PACK_COMP_KISCAPSRC 9 102 #define PACK_COMP_ALERT 10 103 #define PACK_COMP_BASICDATA 11 104 #define PACK_COMP_STRINGS 12 105 #define PACK_COMP_FCSBYTES 13 106 #define PACK_COMP_DEVICE 14 107 #define PACK_COMP_MAX 15 108 109 // Same game again, with alerts that internal things need to generate 110 #define ALERT_REF_KISMET 0 111 #define ALERT_REF_MAX 1 112 113 // Define some macros (ew) to shortcut into the vectors we had to build for 114 // fast access. Kids, don't try this at home. 115 #define _PCM(x) globalreg->packetcomp_map[(x)] 116 #define _NPM(x) globalreg->netproto_map[(x)] 117 #define _ARM(x) globalreg->alertref_map[(x)] 118 #define _ALERT(x, y, z, a) globalreg->alertracker->RaiseAlert((x), (y), \ 119 (z)->bssid_mac, (z)->source_mac, (z)->dest_mac, (z)->other_mac, \ 120 (z)->channel, (a)) 121 122 // Send a msg via gloablreg msgbus 123 #define _MSG(x, y) globalreg->messagebus->InjectMessage((x), (y)) 124 125 // Record how a pid died 126 struct pid_fail { 127 pid_t pid; 128 int status; 129 }; 130 131 // Record of how we failed critically. We want to spin a critfail message out 132 // to the client so it can do something intelligent. A critical fail is something 133 // like the root IPC process failing to load, or dropping dead. 134 struct critical_fail { 135 time_t fail_time; 136 string fail_msg; 137 }; 138 139 // Global registry of references to tracker objects and preferences. This 140 // should supplant the masses of globals and externs we'd otherwise need. 141 // 142 // Really this just just a big ugly hack to do globals without looking like 143 // we're doing globals, but it's a lot nicer for maintenance at least. 144 class GlobalRegistry { 145 public: 146 // argc and argv for modules to allow overrides 147 int argc; 148 char **argv; 149 char **envp; 150 151 // What are we? server, drone, client 152 int kismet_instance; 153 154 // getopt-long number for arguments that don't take a short letter 155 // Anything using a getopt long should grab this and increment it 156 int getopt_long_num; 157 158 // Fatal terminate condition, as soon as we detect this in the main code we 159 // should initiate a shutdown 160 int fatal_condition; 161 // Are we in "spindown" mode, where we're giving components a little time 162 // to clean up their business with pollables and shut down 163 int spindown; 164 165 // Did we receive a SIGWINCH that hasn't been dealt with yet? 166 bool winch; 167 168 MessageBus *messagebus; 169 Plugintracker *plugintracker; 170 Packetsourcetracker *sourcetracker; 171 172 // Old network tracker due to be removed 173 Netracker *netracker; 174 // New multiphy tracker 175 Devicetracker *devicetracker; 176 177 Packetchain *packetchain; 178 Alertracker *alertracker; 179 Timetracker *timetracker; 180 KisNetFramework *kisnetserver; 181 KisDroneFramework *kisdroneserver; 182 ConfigFile *kismet_config; 183 ConfigFile *kismetui_config; 184 SoundControl *soundctl; 185 KisBuiltinDissector *builtindissector; 186 RootIPCRemote *rootipc; 187 KisPanelInterface *panel_interface; 188 Manuf *manufdb; 189 190 string log_prefix; 191 192 string version_major; 193 string version_minor; 194 string version_tiny; 195 string revision; 196 string revdate; 197 198 // Vector of pollable subservices for main()... You should use the util 199 // functions for this, but main needs to be able to see it directly 200 vector<Pollable *> subsys_pollable_vec; 201 202 // Vector of dumpfiles to close cleanly 203 vector<Dumpfile *> subsys_dumpfile_vec; 204 205 // Vector of child signals 206 vector<pid_fail> sigchild_vec; 207 208 time_t start_time; 209 string servername; 210 struct timeval timestamp; 211 212 unsigned int metric; 213 214 // Protocol references we don't want to keep looking up 215 int netproto_map[PROTO_REF_MAX]; 216 217 // Filter maps for the various filter types 218 int filter_tracker; 219 macmap<int> filter_tracker_bssid; 220 macmap<int> filter_tracker_source; 221 macmap<int> filter_tracker_dest; 222 int filter_tracker_bssid_invert, filter_tracker_source_invert, 223 filter_tracker_dest_invert; 224 225 int filter_dump; 226 macmap<int> filter_dump_bssid; 227 macmap<int> filter_dump_source; 228 macmap<int> filter_dump_dest; 229 int filter_dump_bssid_invert, filter_dump_source_invert, 230 filter_dump_dest_invert; 231 232 int filter_export; 233 macmap<int> filter_export_bssid; 234 macmap<int> filter_export_source; 235 macmap<int> filter_export_dest; 236 int filter_export_bssid_invert, filter_export_source_invert, 237 filter_export_dest_invert; 238 239 mac_addr broadcast_mac; 240 241 int alert_backlog; 242 243 // Packet component references we use internally and don't want to keep looking up 244 int packetcomp_map[PACK_COMP_MAX]; 245 246 // Alert references 247 int alertref_map[ALERT_REF_MAX]; 248 249 unsigned int crc32_table[256]; 250 251 Dumpfile_Pcap *pcapdump; 252 253 // global netlink reference 254 void *nlhandle; 255 256 // Critical failure elements 257 vector<critical_fail> critfail_vec; 258 259 GlobalRegistry(); 260 261 // External globals -- allow other things to tie structs to us 262 int RegisterGlobal(string in_name); 263 int FetchGlobalRef(string in_name); 264 265 void *FetchGlobal(int in_ref); 266 void *FetchGlobal(string in_name); 267 268 int InsertGlobal(int in_ref, void *in_data); 269 int InsertGlobal(string in_name, void *in_data); 270 271 // Add something to the poll() main loop 272 int RegisterPollableSubsys(Pollable *in_subcli); 273 int RemovePollableSubsys(Pollable *in_subcli); 274 275 // Add a log file 276 void RegisterDumpFile(Dumpfile *in_dump); 277 int RemoveDumpFile(Dumpfile *in_dump); 278 Dumpfile *FindDumpFileType(string in_type); 279 280 // Are we supposed to start checksumming packets? (ie multiple sources, 281 // whatever other conditions we use) 282 int checksum_packets; 283 284 protected: 285 // Exernal global references, string to intid 286 map<string, int> ext_name_map; 287 // External globals 288 map<int, void *> ext_data_map; 289 int next_ext_ref; 290 }; 291 292 #endif 293 294