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.
37 #include <epan/epan.h>
38 #include <epan/frequency-utils.h>
40 #include "simple_dialog.h"
42 #include "main_airpcap_toolbar.h"
48 #include "airpcap_loader.h"
49 #include "airpcap_dlg.h"
50 #include "airpcap_gui_utils.h"
53 #include <epan/crypt/airpdcap_ws.h>
57 gboolean block_toolbar_signals = FALSE;
58 static GtkWidget *driver_warning_dialog;
62 * Callback for the wrong crc combo
65 airpcap_toolbar_fcs_filter_combo_cb(GtkWidget *fcs_filter_cb, gpointer user_data _U_)
68 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
69 gchar *fcs_filter_str;
71 if (fcs_filter_cb != NULL && !block_toolbar_signals && (airpcap_if_active != NULL)) {
72 fcs_filter_str = gtk_combo_box_get_active_text(GTK_COMBO_BOX(fcs_filter_cb));
73 ad = airpcap_if_open(airpcap_if_active->name, ebuf);
75 if (fcs_filter_str && (g_ascii_strcasecmp("", fcs_filter_str)) && ad) {
76 airpcap_if_selected->CrcValidationOn = airpcap_get_validation_type(fcs_filter_str);
77 airpcap_if_selected->saved = FALSE;
78 airpcap_if_set_fcs_validation(ad,airpcap_if_active->CrcValidationOn);
79 /* Save configuration */
80 airpcap_if_store_cur_config_as_adapter_default(ad);
83 g_free(fcs_filter_str);
88 airpcap_toolbar_encryption_cb(GtkWidget *entry _U_, gpointer user_data _U_)
90 /* We need to directly access the .dll functions here... */
91 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
96 airpcap_if_info_t* curr_if = NULL;
98 /* Apply changes to the current adapter */
99 if( (airpcap_if_active != NULL)) {
100 ad = airpcap_if_open(airpcap_if_active->name, ebuf);
103 if(airpcap_if_active->DecryptionOn == AIRPCAP_DECRYPTION_ON) {
104 airpcap_if_active->DecryptionOn = AIRPCAP_DECRYPTION_OFF;
105 airpcap_if_set_decryption_state(ad,airpcap_if_active->DecryptionOn);
106 /* Save configuration */
107 if(!airpcap_if_store_cur_config_as_adapter_default(ad)) {
108 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.");
110 airpcap_if_close(ad);
112 airpcap_if_active->DecryptionOn = AIRPCAP_DECRYPTION_ON;
113 airpcap_if_set_decryption_state(ad,airpcap_if_active->DecryptionOn);
114 /* Save configuration */
115 if(!airpcap_if_store_cur_config_as_adapter_default(ad)) {
116 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.");
118 airpcap_if_close(ad);
122 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "No active AirPcap Adapter selected!");
126 if (!(airpcap_if_list == NULL)){
127 n = g_list_length(airpcap_if_list);
129 /* The same kind of settings should be propagated to all the adapters */
130 /* Apply this change to all the adapters !!! */
131 for(i = 0; i < n; i++) {
132 curr_if = (airpcap_if_info_t*)g_list_nth_data(airpcap_if_list,i);
134 if( (curr_if != NULL) && (curr_if != airpcap_if_selected) ) {
135 ad = airpcap_if_open(curr_if->name, ebuf);
137 curr_if->DecryptionOn = airpcap_if_selected->DecryptionOn;
138 airpcap_if_set_decryption_state(ad,curr_if->DecryptionOn);
139 /* Save configuration for the curr_if */
140 if(!airpcap_if_store_cur_config_as_adapter_default(ad)) {
141 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.");
143 airpcap_if_close(ad);
148 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "AirPcap Adapter Error!");
154 * Callback for the Advanced Wireless Settings button
157 toolbar_display_airpcap_advanced_cb(GtkWidget *w, gpointer data)
161 from_widget = (gint*)g_malloc(sizeof(gint));
162 *from_widget = AIRPCAP_ADVANCED_FROM_TOOLBAR;
163 g_object_set_data(G_OBJECT(airpcap_tb),AIRPCAP_ADVANCED_FROM_KEY,from_widget);
165 display_airpcap_advanced_cb(w,data);
169 * Callback for the Decryption Key Management button
172 toolbar_display_airpcap_key_management_cb(GtkWidget *w, gpointer data)
176 from_widget = (gint*)g_malloc(sizeof(gint));
177 *from_widget = AIRPCAP_ADVANCED_FROM_TOOLBAR;
178 g_object_set_data(G_OBJECT(airpcap_tb),AIRPCAP_ADVANCED_FROM_KEY,from_widget);
180 display_airpcap_key_management_cb(w,data);
183 GtkWidget *airpcap_toolbar_new()
185 GtkWidget *channel_lb = NULL,
187 *channel_offset_lb = NULL,
188 *channel_offset_cb = NULL,
189 *fcs_filter_lb = NULL,
190 *fcs_filter_cb = NULL;
191 GtkWidget *airpcap_tb;
193 GtkWidget *decryption_mode_lb;
194 GtkWidget *decryption_mode_cb;
196 GtkTooltips *airpcap_tooltips;
197 GtkToolItem *key_management_bt = NULL,
201 /* airpcap toolbar */
202 airpcap_tooltips = gtk_tooltips_new();
203 airpcap_tb = gtk_toolbar_new();
204 gtk_toolbar_set_orientation(GTK_TOOLBAR(airpcap_tb),
205 GTK_ORIENTATION_HORIZONTAL);
207 /* Create the "802.11 Channel:" label */
208 channel_lb = gtk_label_new("802.11 Channel: ");
209 g_object_set_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_CHANNEL_LABEL_KEY,channel_lb);
210 gtk_widget_show(channel_lb);
212 gtk_widget_set_size_request(channel_lb, 85, -1);
214 tool_item = gtk_tool_item_new ();
215 gtk_container_add (GTK_CONTAINER (tool_item), channel_lb);
216 gtk_widget_show (GTK_WIDGET (tool_item));
217 gtk_toolbar_insert(GTK_TOOLBAR(airpcap_tb),
221 gtk_tooltips_set_tip(GTK_TOOLTIPS(airpcap_tooltips), GTK_WIDGET(tool_item),
222 "Current 802.11 Channel",
225 /* Create the channel combo box */
226 channel_cb = gtk_combo_box_new_text();
227 g_object_set_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_CHANNEL_KEY,channel_cb);
229 /* Select the current channel */
230 airpcap_update_channel_combo(GTK_WIDGET(channel_cb), airpcap_if_selected);
232 gtk_widget_set_size_request(channel_cb, 120, -1);
234 gtk_widget_show(channel_cb);
236 tool_item = gtk_tool_item_new ();
237 gtk_container_add (GTK_CONTAINER (tool_item), channel_cb);
238 gtk_widget_show (GTK_WIDGET (tool_item));
239 gtk_toolbar_insert(GTK_TOOLBAR(airpcap_tb),
243 gtk_tooltips_set_tip(GTK_TOOLTIPS(airpcap_tooltips), GTK_WIDGET(tool_item),
248 /* Create the "Channel Offset:" label */
249 channel_offset_lb = gtk_label_new("Channel Offset: ");
250 g_object_set_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_CHANNEL_OFFSET_LABEL_KEY,channel_offset_lb);
251 gtk_widget_show(channel_offset_lb);
253 gtk_widget_set_size_request(channel_offset_lb, 90, -1);
254 tool_item = gtk_tool_item_new ();
255 gtk_container_add (GTK_CONTAINER (tool_item), channel_offset_lb);
256 gtk_widget_show (GTK_WIDGET (tool_item));
257 gtk_toolbar_insert(GTK_TOOLBAR(airpcap_tb),
261 gtk_tooltips_set_tip(GTK_TOOLTIPS(airpcap_tooltips), GTK_WIDGET(tool_item),
262 "Current 802.11 Channel Offset",
265 /* Start: Channel offset combo box */
266 channel_offset_cb = gtk_combo_box_new_text();
267 g_object_set_data(G_OBJECT(airpcap_tb), AIRPCAP_TOOLBAR_CHANNEL_OFFSET_KEY, channel_offset_cb);
269 if(airpcap_if_active != NULL){
270 airpcap_update_channel_offset_combo(airpcap_if_active, airpcap_if_active->channelInfo.Frequency, channel_offset_cb, FALSE);
272 gtk_combo_box_set_active(GTK_COMBO_BOX(channel_offset_cb), -1);
275 gtk_tooltips_set_tip(airpcap_tooltips, GTK_WIDGET(channel_offset_cb),
276 "802.11 Channel Offset", "Private");
278 gtk_widget_set_size_request(channel_offset_cb, 50, -1);
280 gtk_widget_show(channel_offset_cb);
282 tool_item = gtk_tool_item_new ();
283 gtk_container_add (GTK_CONTAINER (tool_item), channel_offset_cb);
284 gtk_widget_show (GTK_WIDGET (tool_item));
285 gtk_toolbar_insert(GTK_TOOLBAR(airpcap_tb),
289 /* callback for channel combo box */
290 g_signal_connect(channel_cb,"changed", G_CALLBACK(airpcap_channel_changed_set_cb), channel_offset_cb);
291 /* callback for channel offset combo box */
292 g_signal_connect(channel_offset_cb, "changed", G_CALLBACK(airpcap_channel_offset_changed_cb), NULL);
293 /* End: Channel offset combo box */
295 /* Wrong CRC Label */
296 fcs_filter_lb = gtk_label_new(" FCS Filter: ");
297 g_object_set_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_FCS_FILTER_LABEL_KEY,fcs_filter_lb);
298 gtk_widget_show(fcs_filter_lb);
299 gtk_tooltips_set_tip(airpcap_tooltips, GTK_WIDGET(fcs_filter_lb),
301 tool_item = gtk_tool_item_new ();
302 gtk_container_add (GTK_CONTAINER (tool_item), fcs_filter_lb);
303 gtk_widget_show (GTK_WIDGET (tool_item));
304 gtk_toolbar_insert(GTK_TOOLBAR(airpcap_tb),
308 /* FCS filter combo box */
309 fcs_filter_cb = gtk_combo_box_new_text();
310 g_object_set_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_FCS_FILTER_KEY,fcs_filter_cb);
312 gtk_widget_set_size_request(fcs_filter_cb, 100, -1);
314 gtk_combo_box_append_text(GTK_COMBO_BOX(fcs_filter_cb), airpcap_get_validation_name(AIRPCAP_VT_ACCEPT_EVERYTHING));
315 gtk_combo_box_append_text(GTK_COMBO_BOX(fcs_filter_cb), airpcap_get_validation_name(AIRPCAP_VT_ACCEPT_CORRECT_FRAMES));
316 gtk_combo_box_append_text(GTK_COMBO_BOX(fcs_filter_cb), airpcap_get_validation_name(AIRPCAP_VT_ACCEPT_CORRUPT_FRAMES));
317 gtk_combo_box_set_active(GTK_COMBO_BOX(fcs_filter_cb), 0);
319 gtk_tooltips_set_tip(airpcap_tooltips, GTK_WIDGET(fcs_filter_cb),
320 "Select the 802.11 FCS filter that the wireless adapter will apply.",
323 if (airpcap_if_selected != NULL)
325 airpcap_validation_type_combo_set_by_type(fcs_filter_cb, airpcap_if_selected->CrcValidationOn);
328 g_signal_connect (fcs_filter_cb, "changed", G_CALLBACK(airpcap_toolbar_fcs_filter_combo_cb), NULL);
329 gtk_widget_show(fcs_filter_cb);
331 tool_item = gtk_tool_item_new ();
332 gtk_container_add (GTK_CONTAINER (tool_item), fcs_filter_cb);
333 gtk_widget_show (GTK_WIDGET (tool_item));
334 gtk_toolbar_insert(GTK_TOOLBAR(airpcap_tb),
338 /* Decryption mode combo box */
339 decryption_mode_lb = gtk_label_new ("Decryption Mode: ");
340 g_object_set_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_DECRYPTION_LABEL_KEY,decryption_mode_lb);
341 gtk_widget_set_name (decryption_mode_lb, "decryption_mode_lb");
342 gtk_widget_show (decryption_mode_lb);
344 decryption_mode_cb = gtk_combo_box_new_text();
345 gtk_widget_set_name (decryption_mode_cb, "decryption_mode_cb");
346 gtk_widget_show (decryption_mode_cb);
347 gtk_widget_set_size_request(decryption_mode_cb, 83, -1);
348 update_decryption_mode_list(decryption_mode_cb);
350 tool_item = gtk_tool_item_new ();
351 gtk_container_add (GTK_CONTAINER (tool_item), decryption_mode_cb);
352 gtk_widget_show (GTK_WIDGET (tool_item));
353 gtk_toolbar_insert(GTK_TOOLBAR(airpcap_tb),
357 gtk_tooltips_set_tip(airpcap_tooltips, GTK_WIDGET(fcs_filter_lb),
358 "Choose a Decryption Mode", "Private");
360 /* Set current decryption mode!!!! */
361 update_decryption_mode(decryption_mode_cb);
362 g_signal_connect(decryption_mode_cb, "changed", G_CALLBACK(on_decryption_mode_cb_changed), airpcap_tb);
363 g_object_set_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_DECRYPTION_KEY,decryption_mode_cb);
365 /* Advanced button */
366 advanced_bt = gtk_tool_button_new(NULL, /* a widget that will be used as icon widget, or NULL */
367 "Wireless Settings...");
368 g_object_set_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_ADVANCED_KEY,advanced_bt);
370 g_signal_connect(advanced_bt, "clicked", G_CALLBACK(toolbar_display_airpcap_advanced_cb), airpcap_tb);
371 gtk_widget_show(GTK_WIDGET(advanced_bt));
372 gtk_toolbar_insert(GTK_TOOLBAR(airpcap_tb),
375 gtk_tooltips_set_tip(GTK_TOOLTIPS(airpcap_tooltips), GTK_WIDGET(advanced_bt),
376 "Set Advanced Wireless Settings",
378 /* Key Management button */
379 key_management_bt = gtk_tool_button_new(NULL, /* a widget that will be used as icon widget, or NULL */
380 "Decryption Keys...");
382 g_object_set_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_KEY_MANAGEMENT_KEY,key_management_bt);
384 g_signal_connect(key_management_bt, "clicked", G_CALLBACK(toolbar_display_airpcap_key_management_cb), airpcap_tb);
385 gtk_widget_show(GTK_WIDGET(key_management_bt));
386 gtk_toolbar_insert(GTK_TOOLBAR(airpcap_tb),
389 gtk_tooltips_set_tip(GTK_TOOLTIPS(airpcap_tooltips), GTK_WIDGET(key_management_bt),
390 "Manage Decryption Keys",
393 /* If no airpcap interface is present, gray everything */
394 if(airpcap_if_active == NULL) {
395 if(airpcap_if_list == NULL || g_list_length(airpcap_if_list) == 0) {
396 /* No airpcap device found */
397 airpcap_enable_toolbar_widgets(airpcap_tb,FALSE);
398 /* recent.airpcap_toolbar_show = TRUE; */
400 /* default adapter is not airpcap... or is airpcap but is not found*/
401 airpcap_set_toolbar_stop_capture(airpcap_if_active);
402 airpcap_enable_toolbar_widgets(airpcap_tb,FALSE);
403 /* recent.airpcap_toolbar_show = TRUE; */
406 airpcap_set_toolbar_stop_capture(airpcap_if_active);
407 /* recent.airpcap_toolbar_show = TRUE; */
414 driver_warning_dialog_cb(gpointer dialog, gint btn _U_, gpointer data _U_)
418 r = simple_dialog_check_get(dialog);
419 recent.airpcap_driver_check_show = !r;
422 void airpcap_toolbar_show(GtkWidget *airpcap_tb _U_)
425 * This will read the decryption keys from the preferences file, and will
426 * store them into the registry...
428 if(airpcap_if_list != NULL && g_list_length(airpcap_if_list) > 0){
429 if (!airpcap_check_decryption_keys(airpcap_if_list)) {
430 /* Ask the user what to do ...*/
431 airpcap_keys_check_w(NULL,NULL);
433 /* Keys from lists are equals, or Wireshark has got no keys */
434 airpcap_load_decryption_keys(airpcap_if_list);
438 switch (airpcap_dll_ret_val) {
443 case AIRPCAP_DLL_OLD:
444 if(recent.airpcap_driver_check_show) {
445 driver_warning_dialog = simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s",
446 "WARNING: The version of AirPcap on this system\n"
447 "does not support driver-level decryption. Please\n"
448 "download a more recent version from\n" "http://www.cacetech.com/support/downloads.htm \n");
449 simple_dialog_check_set(driver_warning_dialog,"Don't show this message again.");
450 simple_dialog_set_cb(driver_warning_dialog, driver_warning_dialog_cb, NULL);
456 * XXX - Maybe we need to warn the user if one of the following happens???
458 case AIRPCAP_DLL_ERROR:
459 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DLL_ERROR\n");
462 case AIRPCAP_DLL_NOT_FOUND:
463 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DDL_NOT_FOUND\n");
469 #endif /* HAVE_AIRPCAP */