1 /* main_airpcap_toolbar.c
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 * This file implements the wireless toolbar for Wireshark.
36 #include "ui/gtk/old-gtk-compat.h"
38 #include <epan/epan.h>
39 #include <epan/frequency-utils.h>
41 #include "simple_dialog.h"
43 #include "main_airpcap_toolbar.h"
49 #include "airpcap_loader.h"
50 #include "airpcap_dlg.h"
51 #include "airpcap_gui_utils.h"
53 #include <epan/crypt/airpdcap_ws.h>
56 gboolean block_toolbar_signals = FALSE;
57 static GtkWidget *driver_warning_dialog;
61 * Callback for the wrong crc combo
64 airpcap_toolbar_fcs_filter_combo_cb(GtkWidget *fcs_filter_cb, gpointer user_data _U_)
67 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
68 gchar *fcs_filter_str;
70 if (fcs_filter_cb != NULL && !block_toolbar_signals && (airpcap_if_active != NULL)) {
71 fcs_filter_str = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT(fcs_filter_cb));
72 ad = airpcap_if_open(airpcap_if_active->name, ebuf);
74 if (fcs_filter_str && (g_ascii_strcasecmp("", fcs_filter_str)) && ad) {
75 airpcap_if_selected->CrcValidationOn = airpcap_get_validation_type(fcs_filter_str);
76 airpcap_if_selected->saved = FALSE;
77 airpcap_if_set_fcs_validation(ad,airpcap_if_active->CrcValidationOn);
78 /* Save configuration */
79 airpcap_if_store_cur_config_as_adapter_default(ad);
82 g_free(fcs_filter_str);
87 airpcap_toolbar_encryption_cb(GtkWidget *entry _U_, gpointer user_data _U_)
89 /* We need to directly access the .dll functions here... */
90 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
95 airpcap_if_info_t* curr_if = NULL;
97 /* Apply changes to the current adapter */
98 if( (airpcap_if_active != NULL)) {
99 ad = airpcap_if_open(airpcap_if_active->name, ebuf);
102 if(airpcap_if_active->DecryptionOn == AIRPCAP_DECRYPTION_ON) {
103 airpcap_if_active->DecryptionOn = AIRPCAP_DECRYPTION_OFF;
104 airpcap_if_set_decryption_state(ad,airpcap_if_active->DecryptionOn);
105 /* Save configuration */
106 if(!airpcap_if_store_cur_config_as_adapter_default(ad)) {
107 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Cannot save configuration!!!\nRemember that in order to store the configuration in the registry you have to:\n\n- Close all the airpcap-based applications.\n- Be sure to have administrative privileges.");
109 airpcap_if_close(ad);
111 airpcap_if_active->DecryptionOn = AIRPCAP_DECRYPTION_ON;
112 airpcap_if_set_decryption_state(ad,airpcap_if_active->DecryptionOn);
113 /* Save configuration */
114 if(!airpcap_if_store_cur_config_as_adapter_default(ad)) {
115 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Cannot save configuration!!!\nRemember that in order to store the configuration in the registry you have to:\n\n- Close all the airpcap-based applications.\n- Be sure to have administrative privileges.");
117 airpcap_if_close(ad);
121 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "No active AirPcap Adapter selected!");
125 if (!(airpcap_if_list == NULL)) {
126 n = g_list_length(airpcap_if_list);
128 /* The same kind of settings should be propagated to all the adapters */
129 /* Apply this change to all the adapters !!! */
130 for(i = 0; i < n; i++) {
131 curr_if = (airpcap_if_info_t*)g_list_nth_data(airpcap_if_list,i);
133 if( (curr_if != NULL) && (curr_if != airpcap_if_selected) ) {
134 ad = airpcap_if_open(curr_if->name, ebuf);
136 curr_if->DecryptionOn = airpcap_if_selected->DecryptionOn;
137 airpcap_if_set_decryption_state(ad,curr_if->DecryptionOn);
138 /* Save configuration for the curr_if */
139 if(!airpcap_if_store_cur_config_as_adapter_default(ad)) {
140 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Cannot save configuration!!!\nRemember that in order to store the configuration in the registry you have to:\n\n- Close all the airpcap-based applications.\n- Be sure to have administrative privileges.");
142 airpcap_if_close(ad);
147 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "AirPcap Adapter Error!");
153 * Callback for the Advanced Wireless Settings button
156 toolbar_display_airpcap_advanced_cb(GtkWidget *w, gpointer data)
160 from_widget = (gint*)g_malloc(sizeof(gint));
161 *from_widget = AIRPCAP_ADVANCED_FROM_TOOLBAR;
162 g_object_set_data(G_OBJECT(airpcap_tb),AIRPCAP_ADVANCED_FROM_KEY,from_widget);
164 display_airpcap_advanced_cb(w,data);
168 * Callback for the Decryption Key Management button
171 toolbar_display_airpcap_key_management_cb(GtkWidget *w, gpointer data)
175 from_widget = (gint*)g_malloc(sizeof(gint));
176 *from_widget = AIRPCAP_ADVANCED_FROM_TOOLBAR;
177 g_object_set_data(G_OBJECT(airpcap_tb), AIRPCAP_ADVANCED_FROM_KEY, from_widget);
179 display_airpcap_key_management_cb(w,data);
182 GtkWidget *airpcap_toolbar_new(void)
184 GtkWidget *channel_lb = NULL,
186 *channel_offset_lb = NULL,
187 *channel_offset_cb = NULL,
188 *fcs_filter_lb = NULL,
189 *fcs_filter_cb = NULL;
190 GtkWidget *airpcap_tb;
192 GtkWidget *decryption_mode_lb;
193 GtkWidget *decryption_mode_cb;
195 GtkToolItem *key_management_bt = NULL,
199 /* airpcap toolbar */
200 airpcap_tb = gtk_toolbar_new();
201 gtk_orientable_set_orientation(GTK_ORIENTABLE(airpcap_tb),
202 GTK_ORIENTATION_HORIZONTAL);
204 /* Create the "802.11 Channel:" label */
205 channel_lb = gtk_label_new("802.11 Channel: ");
206 g_object_set_data(G_OBJECT(airpcap_tb), AIRPCAP_TOOLBAR_CHANNEL_LABEL_KEY, channel_lb);
207 gtk_widget_show(channel_lb);
209 gtk_widget_set_size_request(channel_lb, 85, -1);
211 tool_item = gtk_tool_item_new ();
212 gtk_container_add (GTK_CONTAINER (tool_item), channel_lb);
213 gtk_widget_show (GTK_WIDGET (tool_item));
214 gtk_toolbar_insert(GTK_TOOLBAR(airpcap_tb), tool_item, -1);
216 gtk_widget_set_tooltip_text(GTK_WIDGET(tool_item), "Current 802.11 Channel");
218 /* Create the channel combo box */
219 channel_cb = gtk_combo_box_text_new();
220 g_object_set_data(G_OBJECT(airpcap_tb), AIRPCAP_TOOLBAR_CHANNEL_KEY, channel_cb);
222 /* Select the current channel */
223 airpcap_update_channel_combo(GTK_WIDGET(channel_cb), airpcap_if_selected);
225 gtk_widget_set_size_request(channel_cb, 120, -1);
227 gtk_widget_show(channel_cb);
229 tool_item = gtk_tool_item_new ();
230 gtk_container_add (GTK_CONTAINER (tool_item), channel_cb);
231 gtk_widget_show (GTK_WIDGET (tool_item));
232 gtk_toolbar_insert(GTK_TOOLBAR(airpcap_tb), tool_item, -1);
234 gtk_widget_set_tooltip_text(GTK_WIDGET(tool_item), "802.11 Channel");
236 /* Create the "Channel Offset:" label */
237 channel_offset_lb = gtk_label_new("Channel Offset: ");
238 g_object_set_data(G_OBJECT(airpcap_tb), AIRPCAP_TOOLBAR_CHANNEL_OFFSET_LABEL_KEY, channel_offset_lb);
239 gtk_widget_show(channel_offset_lb);
241 gtk_widget_set_size_request(channel_offset_lb, 90, -1);
242 tool_item = gtk_tool_item_new ();
243 gtk_container_add (GTK_CONTAINER (tool_item), channel_offset_lb);
244 gtk_widget_show (GTK_WIDGET (tool_item));
245 gtk_toolbar_insert(GTK_TOOLBAR(airpcap_tb), tool_item, -1);
247 gtk_widget_set_tooltip_text(GTK_WIDGET(tool_item), "Current 802.11 Channel Offset");
249 /* Start: Channel offset combo box */
250 channel_offset_cb = gtk_combo_box_text_new();
251 g_object_set_data(G_OBJECT(airpcap_tb), AIRPCAP_TOOLBAR_CHANNEL_OFFSET_KEY, channel_offset_cb);
253 if(airpcap_if_active != NULL){
254 airpcap_update_channel_offset_combo(airpcap_if_active, airpcap_if_active->channelInfo.Frequency, channel_offset_cb, FALSE);
256 gtk_combo_box_set_active(GTK_COMBO_BOX(channel_offset_cb), -1);
259 gtk_widget_set_tooltip_text(channel_offset_cb, "Current 802.11 Channel Offset");
261 gtk_widget_set_size_request(channel_offset_cb, 50, -1);
263 gtk_widget_show(channel_offset_cb);
265 tool_item = gtk_tool_item_new ();
266 gtk_container_add (GTK_CONTAINER (tool_item), channel_offset_cb);
267 gtk_widget_show (GTK_WIDGET (tool_item));
268 gtk_toolbar_insert(GTK_TOOLBAR(airpcap_tb), tool_item, -1);
270 /* callback for channel combo box */
271 g_signal_connect(channel_cb,"changed", G_CALLBACK(airpcap_channel_changed_set_cb), channel_offset_cb);
272 /* callback for channel offset combo box */
273 g_signal_connect(channel_offset_cb, "changed", G_CALLBACK(airpcap_channel_offset_changed_cb), NULL);
274 /* End: Channel offset combo box */
276 /* Wrong CRC Label */
277 fcs_filter_lb = gtk_label_new(" FCS Filter: ");
278 g_object_set_data(G_OBJECT(airpcap_tb), AIRPCAP_TOOLBAR_FCS_FILTER_LABEL_KEY, fcs_filter_lb);
279 gtk_widget_show(fcs_filter_lb);
280 tool_item = gtk_tool_item_new ();
281 gtk_container_add (GTK_CONTAINER (tool_item), fcs_filter_lb);
282 gtk_widget_show (GTK_WIDGET (tool_item));
283 gtk_toolbar_insert(GTK_TOOLBAR(airpcap_tb), tool_item, -1);
285 /* FCS filter combo box */
286 fcs_filter_cb = gtk_combo_box_text_new();
287 g_object_set_data(G_OBJECT(airpcap_tb), AIRPCAP_TOOLBAR_FCS_FILTER_KEY, fcs_filter_cb);
289 gtk_widget_set_size_request(fcs_filter_cb, 100, -1);
291 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(fcs_filter_cb), airpcap_get_validation_name(AIRPCAP_VT_ACCEPT_EVERYTHING));
292 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(fcs_filter_cb), airpcap_get_validation_name(AIRPCAP_VT_ACCEPT_CORRECT_FRAMES));
293 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(fcs_filter_cb), airpcap_get_validation_name(AIRPCAP_VT_ACCEPT_CORRUPT_FRAMES));
294 gtk_combo_box_set_active(GTK_COMBO_BOX(fcs_filter_cb), 0);
296 gtk_widget_set_tooltip_text(fcs_filter_cb, "Select the 802.11 FCS filter that the wireless adapter will apply.");
298 if (airpcap_if_selected != NULL) {
299 airpcap_validation_type_combo_set_by_type(fcs_filter_cb, airpcap_if_selected->CrcValidationOn);
302 g_signal_connect (fcs_filter_cb, "changed", G_CALLBACK(airpcap_toolbar_fcs_filter_combo_cb), NULL);
303 gtk_widget_show(fcs_filter_cb);
305 tool_item = gtk_tool_item_new ();
306 gtk_container_add (GTK_CONTAINER (tool_item), fcs_filter_cb);
307 gtk_widget_show (GTK_WIDGET (tool_item));
308 gtk_toolbar_insert(GTK_TOOLBAR(airpcap_tb), tool_item, -1);
310 /* Decryption mode combo box */
311 decryption_mode_lb = gtk_label_new ("Decryption Mode: ");
312 g_object_set_data(G_OBJECT(airpcap_tb), AIRPCAP_TOOLBAR_DECRYPTION_LABEL_KEY, decryption_mode_lb);
313 gtk_widget_set_name (decryption_mode_lb, "decryption_mode_lb");
314 gtk_widget_show (decryption_mode_lb);
316 decryption_mode_cb = gtk_combo_box_text_new();
317 gtk_widget_set_name (decryption_mode_cb, "decryption_mode_cb");
318 gtk_widget_show (decryption_mode_cb);
319 gtk_widget_set_size_request(decryption_mode_cb, 83, -1);
320 update_decryption_mode_list(decryption_mode_cb);
322 tool_item = gtk_tool_item_new ();
323 gtk_container_add (GTK_CONTAINER (tool_item), decryption_mode_cb);
324 gtk_widget_show (GTK_WIDGET (tool_item));
325 gtk_toolbar_insert(GTK_TOOLBAR(airpcap_tb), tool_item, -1);
327 gtk_widget_set_tooltip_text(fcs_filter_lb, "Choose a Decryption Mode");
328 /* Set current decryption mode!!!! */
329 update_decryption_mode(decryption_mode_cb);
330 g_signal_connect(decryption_mode_cb, "changed", G_CALLBACK(on_decryption_mode_cb_changed), NULL);
331 g_object_set_data(G_OBJECT(airpcap_tb), AIRPCAP_TOOLBAR_DECRYPTION_KEY, decryption_mode_cb);
333 /* Advanced button */
334 advanced_bt = gtk_tool_button_new(NULL, /* a widget that will be used as icon widget, or NULL */
335 "Wireless Settings...");
336 g_object_set_data(G_OBJECT(airpcap_tb), AIRPCAP_TOOLBAR_ADVANCED_KEY, advanced_bt);
338 g_signal_connect(advanced_bt, "clicked", G_CALLBACK(toolbar_display_airpcap_advanced_cb), airpcap_tb);
339 gtk_widget_show(GTK_WIDGET(advanced_bt));
340 gtk_toolbar_insert(GTK_TOOLBAR(airpcap_tb), advanced_bt, -1);
342 gtk_widget_set_tooltip_text(GTK_WIDGET(advanced_bt), "Set Advanced Wireless Settings");
343 /* Key Management button */
344 key_management_bt = gtk_tool_button_new(NULL, /* a widget that will be used as icon widget, or NULL */
345 "Decryption Keys...");
347 g_object_set_data(G_OBJECT(airpcap_tb), AIRPCAP_TOOLBAR_KEY_MANAGEMENT_KEY, key_management_bt);
349 g_signal_connect(key_management_bt, "clicked", G_CALLBACK(toolbar_display_airpcap_key_management_cb), airpcap_tb);
350 gtk_widget_show(GTK_WIDGET(key_management_bt));
351 gtk_toolbar_insert(GTK_TOOLBAR(airpcap_tb), key_management_bt, -1);
352 gtk_widget_set_tooltip_text(GTK_WIDGET(key_management_bt), "Manage Decryption Keys");
354 /* If no airpcap interface is present, gray everything */
355 if(airpcap_if_active == NULL) {
356 if(airpcap_if_list == NULL || g_list_length(airpcap_if_list) == 0) {
357 /* No airpcap device found */
358 airpcap_enable_toolbar_widgets(airpcap_tb, FALSE);
359 /* recent.airpcap_toolbar_show = TRUE; */
361 /* default adapter is not airpcap... or is airpcap but is not found*/
362 airpcap_set_toolbar_stop_capture(airpcap_if_active);
363 airpcap_enable_toolbar_widgets(airpcap_tb, FALSE);
364 /* recent.airpcap_toolbar_show = TRUE; */
367 airpcap_set_toolbar_stop_capture(airpcap_if_active);
368 /* recent.airpcap_toolbar_show = TRUE; */
375 driver_warning_dialog_cb(gpointer dialog, gint btn _U_, gpointer data _U_)
379 r = simple_dialog_check_get(dialog);
380 recent.airpcap_driver_check_show = !r;
383 void airpcap_toolbar_show(GtkWidget *airpcap_tb _U_)
386 * This will read the decryption keys from the preferences file, and will
387 * store them into the registry...
389 if(airpcap_if_list != NULL && g_list_length(airpcap_if_list) > 0){
390 if (!airpcap_check_decryption_keys(airpcap_if_list)) {
391 /* Ask the user what to do ...*/
392 airpcap_keys_check_w(NULL,NULL);
394 /* Keys from lists are equals, or Wireshark has got no keys */
395 airpcap_load_decryption_keys(airpcap_if_list);
399 switch (airpcap_dll_ret_val) {
404 case AIRPCAP_DLL_OLD:
405 if(recent.airpcap_driver_check_show) {
406 driver_warning_dialog = simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s",
407 "WARNING: The version of AirPcap on this system\n"
408 "does not support driver-level decryption. Please\n"
409 "download a more recent version from\n" "http://www.cacetech.com/support/downloads.htm \n");
410 simple_dialog_check_set(driver_warning_dialog,"Don't show this message again.");
411 simple_dialog_set_cb(driver_warning_dialog, driver_warning_dialog_cb, NULL);
417 * XXX - Maybe we need to warn the user if one of the following happens???
419 case AIRPCAP_DLL_ERROR:
420 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DLL_ERROR\n");
423 case AIRPCAP_DLL_NOT_FOUND:
424 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DDL_NOT_FOUND\n");
430 #endif /* HAVE_AIRPCAP */