First step in integrating the AirPcap WEP preferences with those
[obnox/wireshark/wip.git] / airpcap_loader.h
1 /* airpcap_loader.h
2  * Declarations of routines for the "About" dialog
3  *
4  * $Id$
5  *
6  * Giorgio Tino <giorgio.tino@cacetech.com>
7  * Copyright (c) CACE Technologies, LLC 2006
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifndef __AIRPCAP_LOADER_H__
29 #define __AIRPCAP_LOADER_H__
30
31 /* Error values from "get_airpcap_interface_list()". */
32 #define CANT_GET_AIRPCAP_INTERFACE_LIST 0       /* error getting list */
33 #define NO_AIRPCAP_INTERFACES_FOUND     1       /* list is empty */
34
35 #define AIRPCAP_CHANNEL_ANY_NAME "ANY"
36
37 /*
38  * WEP_KEY_MAX_SIZE is in bytes. but each byte is rapresented in strings with an ascii char
39  * 4 bit are needed to store an exadecimal number, 8 bit to store a char...
40  */
41 #define WEP_KEY_MAX_CHAR_SIZE (WEP_KEY_MAX_SIZE*2)
42
43 typedef PCHAR (*AirpcapGetLastErrorHandler)(PAirpcapHandle AdapterHandle);
44 typedef BOOL (*AirpcapGetDeviceListHandler)(PAirpcapDeviceDescription *PPAllDevs, PCHAR Ebuf);
45 typedef VOID (*AirpcapFreeDeviceListHandler)(PAirpcapDeviceDescription PAllDevs);
46 typedef PAirpcapHandle (*AirpcapOpenHandler)(PCHAR DeviceName, PCHAR Ebuf);
47 typedef VOID (*AirpcapCloseHandler)(PAirpcapHandle AdapterHandle);
48 typedef BOOL (*AirpcapGetLinkTypeHandler)(PAirpcapHandle AdapterHandle, PAirpcapLinkType PLinkType);
49 typedef BOOL (*AirpcapSetLinkTypeHandler)(PAirpcapHandle AdapterHandle, AirpcapLinkType NewLinkType);
50 typedef BOOL (*AirpcapSetKernelBufferHandler)(PAirpcapHandle AdapterHandle, UINT BufferSize);
51 typedef BOOL (*AirpcapSetFilterHandler)(PAirpcapHandle AdapterHandle, PVOID Instructions, UINT Len);
52 typedef BOOL (*AirpcapGetMacAddressHandler)(PAirpcapHandle AdapterHandle, PAirpcapMacAddress PMacAddress);
53 typedef BOOL (*AirpcapSetMinToCopyHandler)(PAirpcapHandle AdapterHandle, UINT MinToCopy);
54 typedef BOOL (*AirpcapGetReadEventHandler)(PAirpcapHandle AdapterHandle, HANDLE* PReadEvent);
55 typedef BOOL (*AirpcapReadHandler)(PAirpcapHandle AdapterHandle, PBYTE Buffer, UINT BufSize, PUINT PReceievedBytes);
56 typedef BOOL (*AirpcapGetStatsHandler)(PAirpcapHandle AdapterHandle, PAirpcapStats PStats);
57 typedef BOOL (*AirpcapTurnLedOnHandler)(PAirpcapHandle  AdapterHandle, UINT  LedNumber);
58 typedef BOOL (*AirpcapTurnLedOffHandler)(PAirpcapHandle  AdapterHandle, UINT  LedNumber);
59 typedef BOOL (*AirpcapSetDeviceChannelHandler)(PAirpcapHandle  AdapterHandle, UINT  Channel);
60 typedef BOOL (*AirpcapGetDeviceChannelHandler)(PAirpcapHandle  AdapterHandle, PUINT PChannel);
61 typedef BOOL (*AirpcapSetFcsPresenceHandler)(PAirpcapHandle  AdapterHandle, BOOL  IsFcsPresent);
62 typedef BOOL (*AirpcapGetFcsPresenceHandler)(PAirpcapHandle  AdapterHandle, PBOOL PIsFcsPresent);
63 typedef BOOL (*AirpcapSetFcsValidationHandler)(PAirpcapHandle  AdapterHandle, AirpcapValidationType ValidationType);
64 typedef BOOL (*AirpcapGetFcsValidationHandler)(PAirpcapHandle  AdapterHandle, PAirpcapValidationType PValidationType);
65 typedef BOOL (*AirpcapSetDeviceKeysHandler)(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
66 typedef BOOL (*AirpcapGetDeviceKeysHandler)(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, PUINT PKeysCollectionSize);
67 typedef BOOL (*AirpcapSetDecryptionStateHandler)(PAirpcapHandle AdapterHandle, AirpcapDecryptionState Enable);
68 typedef BOOL (*AirpcapGetDecryptionStateHandler)(PAirpcapHandle AdapterHandle, PAirpcapDecryptionState PEnable);
69 typedef BOOL (*AirpcapStoreCurConfigAsAdapterDefaultHandler)(PAirpcapHandle AdapterHandle);
70 /*
71  * The list of interfaces returned by "get_airpcap_interface_list()" is
72  * a list of these structures.
73  */
74 typedef struct {
75         char                                    *name;                          /* e.g. "eth0" */
76         char                                    *description;           /* from OS, e.g. "Local Area Connection" or NULL */
77         GSList                                  *ip_addr;                       /* containing address values of if_addr_t */
78         gboolean                                loopback;                       /* TRUE if loopback, FALSE otherwise */
79         AirpcapLinkType                 linkType;                       /* The link layer type*/
80         UINT                                    channel;                        /* Channel (1-14)*/
81         BOOL                                    IsFcsPresent;           /* Include 802.11 CRC in frames */
82         AirpcapValidationType   CrcValidationOn;        /* Capture Frames with Wrong CRC */
83         AirpcapDecryptionState  DecryptionOn;           /* TRUE if decryption is on, FALSE otherwise*/
84         PAirpcapKeysCollection  keysCollection;         /* WEP Key collection for the adapter */
85         UINT                                    keysCollectionSize;     /* Size of the key collection */
86         gboolean                                blinking;                       /* TRUE if is blinkng, FALSE otherwise*/
87         gboolean                                led;                            /* TRUE if on, FALSE if off*/
88         gboolean                                saved;                          /* TRUE if current configuration has been saved, FALSE otherwise */
89         gint                                    tag;                            /* int for the gtk blinking callback */
90 } airpcap_if_info_t;
91
92 /* Airpcap interface list */
93 extern GList *airpcap_if_list;
94
95 /* Airpcap current selected interface */
96 extern airpcap_if_info_t *airpcap_if_selected;
97
98 /* Airpcap current active interface */
99 extern airpcap_if_info_t *airpcap_if_active;
100
101 /*
102  * Callback used to free an instance of airpcap_if_info_t
103  */
104 static void
105 free_airpcap_if_cb(gpointer data, gpointer user_data _U_);
106
107 /*
108  * Used to retrieve the two chars string from interface
109  */
110 gchar*
111 airpcap_get_if_string_number_from_description(gchar* description);
112
113 /*
114  * Function used to free the airpcap interface list
115  */
116 void
117 free_airpcap_interface_list(GList *if_list);
118
119 /*
120  * Used to retrieve the interface given the name
121  * (the name is used in AirpcapOpen)
122  */
123 airpcap_if_info_t* get_airpcap_if_by_name(GList* if_list, const gchar* name);
124
125 /*
126  * Airpcap wrapper, used to store the current settings for the selected adapter
127  */
128 BOOL
129 airpcap_if_store_cur_config_as_adapter_default(PAirpcapHandle ah);
130
131 /*
132  * Function used to load the WEP keys for a selected interface
133  */
134 BOOL
135 airpcap_if_load_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info);
136
137 /*
138  * Function used to save the WEP keys for a selected interface
139  */
140 void
141 airpcap_if_save_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info);
142
143 /*
144  * Airpcap wrapper, used to get the fcs validation of an airpcap adapter
145  */
146 BOOL
147 airpcap_if_get_fcs_validation(PAirpcapHandle ah, PAirpcapValidationType val);
148
149 /*
150  * Airpcap wrapper, used to set the fcs validation of an airpcap adapter
151  */
152 BOOL
153 airpcap_if_set_fcs_validation(PAirpcapHandle ah, AirpcapValidationType val);
154
155 /*
156  * Airpcap wrapper, used to get the decryption enabling of an airpcap adapter
157  */
158 BOOL
159 airpcap_if_get_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState val);
160
161 /*
162  * Airpcap wrapper, used to set the decryption enabling of an airpcap adapter
163  */
164 BOOL
165 airpcap_if_set_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState val);
166
167 /*
168  * Airpcap wrapper, used to get the fcs presence of an airpcap adapter
169  */
170 BOOL
171 airpcap_if_get_fcs_presence(PAirpcapHandle ah, PBOOL ch);
172
173 /*
174  * Airpcap wrapper, used to set the fcs presence of an airpcap adapter
175  */
176 BOOL
177 airpcap_if_set_fcs_presence(PAirpcapHandle ah, BOOL ch);
178
179 /*
180  * Airpcap wrapper, used to get the link type of an airpcap adapter
181  */
182 BOOL
183 airpcap_if_get_link_type(PAirpcapHandle ah, PAirpcapLinkType lt);
184
185 /*
186  * Airpcap wrapper, used to set the link type of an airpcap adapter
187  */
188 BOOL
189 airpcap_if_set_link_type(PAirpcapHandle ah, AirpcapLinkType lt);
190
191 /*
192  * Airpcap wrapper, used to get the channel of an airpcap adapter
193  */
194 BOOL
195 airpcap_if_get_device_channel(PAirpcapHandle ah, PUINT ch);
196
197 /*
198  * Airpcap wrapper, used to set the channel of an airpcap adapter
199  */
200 BOOL
201 airpcap_if_set_device_channel(PAirpcapHandle ah, UINT ch);
202
203 /*
204  * Airpcap wrapper, used to open an airpcap adapter
205  */
206 PAirpcapHandle airpcap_if_open(PCHAR name, PCHAR err);
207
208 /*
209  * Airpcap wrapper, used to close an airpcap adapter
210  */
211 VOID airpcap_if_close(PAirpcapHandle handle);
212
213 /*
214  * Airpcap wrapper, used to turn on the led of an airpcap adapter
215  */
216 BOOL airpcap_if_turn_led_on(PAirpcapHandle AdapterHandle, UINT LedNumber);
217
218 /*
219  * Airpcap wrapper, used to turn off the led of an airpcap adapter
220  */
221 BOOL airpcap_if_turn_led_off(PAirpcapHandle AdapterHandle, UINT LedNumber);
222
223 /*
224  * This function will create a new airpcap_if_info_t using a name and a description
225  */
226 airpcap_if_info_t* airpcap_if_info_new(char *name, char *description);
227
228 /*
229  *  Used to dinamically load the airpcap library in order link it only when
230  *  it's present on the system.
231  */
232 BOOL load_airpcap(void);
233
234 /*
235  * Get an error message string for a CANT_GET_INTERFACE_LIST error from
236  * "get_airpcap_interface_list()".
237  */
238 gchar*
239 cant_get_airpcap_if_list_error_message(const char *err_str);
240
241 /*
242  * This function will use the airpcap.dll to find all the airpcap devices.
243  * Will return null if no device is found.
244  */
245 GList*
246 get_airpcap_interface_list(int *err, char *err_str);
247
248 /*
249  * Returns the ASCII string of a key given the key bites
250  */
251 gchar*
252 airpcap_get_key_string(AirpcapKey key);
253
254 /*
255  * Load the configuration for the specified interface
256  */
257 void
258 airpcap_load_selected_if_configuration(airpcap_if_info_t* if_info);
259
260 /*
261  * Save the configuration for the specified interface
262  */
263 void
264 airpcap_save_selected_if_configuration(airpcap_if_info_t* if_info);
265
266 /*
267  * Used to retrieve the name of the interface given the description
268  * (the name is used in AirpcapOpen, the description is put in the combo box)
269  */
270 gchar*
271 get_airpcap_name_from_description(GList* if_list, gchar* description);
272
273 /*
274  * Used to retrieve the airpcap_if_info_t of the selected interface given the
275  * description (that is the entry of the combo box).
276  */
277 gpointer
278 get_airpcap_if_from_description(GList* if_list, const gchar* description);
279
280 /*
281  * Used to retrieve the two chars string from interface description
282  */
283 gchar*
284 airpcap_get_if_string_number(airpcap_if_info_t* if_info);
285
286 /*
287  * Returns the default airpcap interface of a list, NULL if list is empty
288  */
289 airpcap_if_info_t*
290 airpcap_get_default_if(GList* airpcap_if_list);
291
292 /*
293  * Airpcap wrapper, used to save the settings for the selected_if
294  */
295 BOOL
296 airpcap_if_set_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
297
298 /*
299  * Airpcap wrapper, used to save the settings for the selected_if
300  */
301 BOOL
302 airpcap_if_get_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, PUINT PKeysCollectionSize);
303 #endif