5 * Giorgio Tino <giorgio.tino@cacetech.com>
6 * Copyright (c) CACE Technologies, LLC 2006
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 2000 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
39 #include <epan/filesystem.h>
40 #include <epan/strutil.h>
41 #include <epan/frequency-utils.h>
42 #include <epan/crypt/airpdcap_ws.h>
44 #include "../simple_dialog.h"
47 #include "gtk/dlg_utils.h"
48 #include "gtk/gui_utils.h"
49 #include "gtk/dfilter_expr_dlg.h"
50 #include "gtk/help_dlg.h"
52 #include "gtk/old-gtk-compat.h"
55 #include "airpcap_loader.h"
56 #include "airpcap_gui_utils.h"
59 /* Controls the releay of settings back to the adapter. */
60 gboolean change_airpcap_settings = FALSE;
63 * Set up the airpcap toolbar for the new capture interface
66 airpcap_set_toolbar_start_capture(airpcap_if_info_t* if_info)
68 GtkWidget *airpcap_toolbar_label;
69 GtkWidget *toolbar_channel_cb;
70 GtkWidget *airpcap_toolbar_channel_lb;
71 GtkWidget *airpcap_toolbar_channel_offset;
72 GtkWidget *airpcap_toolbar_channel_offset_lb;
73 GtkWidget *airpcap_toolbar_button;
74 GtkWidget *airpcap_toolbar_fcs;
75 GtkWidget *airpcap_toolbar_fcs_lb;
76 GtkWidget *airpcap_toolbar_decryption;
77 GtkWidget *airpcap_toolbar_decryption_lb;
78 GtkWidget *airpcap_toolbar_keys_button;
82 airpcap_toolbar_label = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_INTERFACE_KEY);
83 toolbar_channel_cb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_CHANNEL_KEY);
84 airpcap_toolbar_channel_lb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_CHANNEL_LABEL_KEY);
85 airpcap_toolbar_channel_offset = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_CHANNEL_OFFSET_KEY);
86 airpcap_toolbar_channel_offset_lb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_CHANNEL_OFFSET_LABEL_KEY);
87 airpcap_toolbar_fcs = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_FCS_FILTER_KEY);
88 airpcap_toolbar_fcs_lb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_FCS_FILTER_LABEL_KEY);
89 airpcap_toolbar_button = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_ADVANCED_KEY);
90 airpcap_toolbar_decryption = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_DECRYPTION_KEY);
91 airpcap_toolbar_decryption_lb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_DECRYPTION_LABEL_KEY);
92 airpcap_toolbar_keys_button = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_KEY_MANAGEMENT_KEY);
94 /* The current interface is an airpcap interface */
97 gtk_widget_set_sensitive(airpcap_tb,TRUE);
98 gtk_widget_set_sensitive(airpcap_toolbar_label,TRUE);
99 gtk_widget_set_sensitive(toolbar_channel_cb,TRUE);
100 gtk_widget_set_sensitive(airpcap_toolbar_channel_lb,TRUE);
101 gtk_widget_set_sensitive(airpcap_toolbar_channel_offset,TRUE);
102 gtk_widget_set_sensitive(airpcap_toolbar_channel_offset_lb,TRUE);
103 gtk_widget_set_sensitive(airpcap_toolbar_fcs,FALSE);
104 gtk_widget_set_sensitive(airpcap_toolbar_fcs_lb,FALSE);
105 gtk_widget_set_sensitive(airpcap_toolbar_button,FALSE);
106 gtk_widget_set_sensitive(airpcap_toolbar_button,FALSE);
107 gtk_widget_set_sensitive(airpcap_toolbar_decryption,FALSE);
108 gtk_widget_set_sensitive(airpcap_toolbar_decryption_lb,FALSE);
109 gtk_widget_set_sensitive(airpcap_toolbar_keys_button,FALSE);
111 /*decryption check box*/
112 g_signal_handlers_block_by_func (airpcap_toolbar_decryption,airpcap_toolbar_encryption_cb, airpcap_tb);
113 if(if_info->DecryptionOn == AIRPCAP_DECRYPTION_ON)
114 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(airpcap_toolbar_decryption),TRUE);
116 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(airpcap_toolbar_decryption),FALSE);
117 g_signal_handlers_unblock_by_func (airpcap_toolbar_decryption,airpcap_toolbar_encryption_cb, airpcap_tb);
119 if_label_text = g_strdup_printf("Current Wireless Interface: #%s", airpcap_get_if_string_number(if_info));
120 gtk_label_set_text(GTK_LABEL(airpcap_toolbar_label),if_label_text);
121 g_free(if_label_text);
123 change_airpcap_settings = FALSE;
124 if (if_info->pSupportedChannels != NULL && if_info->numSupportedChannels > 0){
127 for (; i<if_info->numSupportedChannels; i++){
128 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(toolbar_channel_cb), ieee80211_mhz_to_str(if_info->pSupportedChannels[i].Frequency));
132 airpcap_update_channel_combo(GTK_WIDGET(toolbar_channel_cb),if_info);
133 airpcap_update_channel_offset_combo(if_info, if_info->channelInfo.Frequency, airpcap_toolbar_channel_offset, TRUE);
134 change_airpcap_settings = TRUE;
136 else /* Current interface is NOT an AirPcap one... */
138 gtk_widget_set_sensitive(airpcap_tb,FALSE);
139 gtk_widget_set_sensitive(airpcap_toolbar_label,FALSE);
140 gtk_widget_set_sensitive(toolbar_channel_cb,FALSE);
141 gtk_widget_set_sensitive(airpcap_toolbar_channel_lb,FALSE);
142 gtk_widget_set_sensitive(airpcap_toolbar_channel_offset,FALSE);
143 gtk_widget_set_sensitive(airpcap_toolbar_channel_offset_lb,FALSE);
144 gtk_widget_set_sensitive(airpcap_toolbar_fcs,FALSE);
145 gtk_widget_set_sensitive(airpcap_toolbar_fcs_lb,FALSE);
146 gtk_widget_set_sensitive(airpcap_toolbar_button,FALSE);
147 gtk_widget_set_sensitive(airpcap_toolbar_button,FALSE);
148 gtk_widget_set_sensitive(airpcap_toolbar_decryption,FALSE);
149 gtk_widget_set_sensitive(airpcap_toolbar_decryption_lb,FALSE);
150 gtk_widget_set_sensitive(airpcap_toolbar_keys_button,FALSE);
155 * Set up the airpcap toolbar for the new capture interface
158 airpcap_set_toolbar_stop_capture(airpcap_if_info_t* if_info)
160 GtkWidget *airpcap_toolbar_crc_filter_combo;
161 GtkWidget *airpcap_toolbar_label;
162 GtkWidget *toolbar_channel_cb;
163 GtkWidget *airpcap_toolbar_channel_lb;
164 GtkWidget *airpcap_toolbar_channel_offset;
165 GtkWidget *airpcap_toolbar_channel_offset_lb;
166 GtkWidget *airpcap_toolbar_button;
167 GtkWidget *airpcap_toolbar_fcs;
168 GtkWidget *airpcap_toolbar_fcs_lb;
169 GtkWidget *airpcap_toolbar_decryption;
170 GtkWidget *airpcap_toolbar_decryption_lb;
171 GtkWidget *airpcap_toolbar_keys_button;
173 gchar *if_label_text;
175 airpcap_toolbar_crc_filter_combo = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_FCS_FILTER_KEY);
176 airpcap_toolbar_label = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_INTERFACE_KEY);
177 toolbar_channel_cb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_CHANNEL_KEY);
178 airpcap_toolbar_channel_lb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_CHANNEL_LABEL_KEY);
179 airpcap_toolbar_channel_offset = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_CHANNEL_OFFSET_KEY);
180 airpcap_toolbar_channel_offset_lb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_CHANNEL_OFFSET_LABEL_KEY);
181 airpcap_toolbar_fcs = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_FCS_FILTER_KEY);
182 airpcap_toolbar_fcs_lb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_FCS_FILTER_LABEL_KEY);
183 airpcap_toolbar_button = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_ADVANCED_KEY);
184 airpcap_toolbar_decryption = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_DECRYPTION_KEY);
185 airpcap_toolbar_decryption_lb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_DECRYPTION_LABEL_KEY);
186 airpcap_toolbar_keys_button = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_KEY_MANAGEMENT_KEY);
188 /* The current interface is an airpcap interface */
191 gtk_widget_set_sensitive(airpcap_tb,TRUE);
192 gtk_widget_set_sensitive(airpcap_toolbar_label,TRUE);
193 gtk_widget_set_sensitive(toolbar_channel_cb,TRUE);
194 gtk_widget_set_sensitive(airpcap_toolbar_channel_lb,TRUE);
195 gtk_widget_set_sensitive(airpcap_toolbar_channel_offset,TRUE);
196 gtk_widget_set_sensitive(airpcap_toolbar_channel_offset_lb,TRUE);
197 gtk_widget_set_sensitive(airpcap_toolbar_fcs,TRUE);
198 gtk_widget_set_sensitive(airpcap_toolbar_fcs_lb,TRUE);
199 gtk_widget_set_sensitive(airpcap_toolbar_button,TRUE);
200 gtk_widget_set_sensitive(airpcap_toolbar_crc_filter_combo,TRUE);
201 gtk_widget_set_sensitive(airpcap_toolbar_decryption,TRUE);
202 gtk_widget_set_sensitive(airpcap_toolbar_decryption_lb,TRUE);
203 gtk_widget_set_sensitive(airpcap_toolbar_keys_button,TRUE);
204 airpcap_validation_type_combo_set_by_type(airpcap_toolbar_crc_filter_combo, if_info->CrcValidationOn);
206 /*decription check box*/
207 g_signal_handlers_block_by_func (airpcap_toolbar_decryption,airpcap_toolbar_encryption_cb, airpcap_tb);
208 if(if_info->DecryptionOn == AIRPCAP_DECRYPTION_ON)
209 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(airpcap_toolbar_decryption),TRUE);
211 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(airpcap_toolbar_decryption),FALSE);
212 g_signal_handlers_unblock_by_func (airpcap_toolbar_decryption,airpcap_toolbar_encryption_cb, airpcap_tb);
214 if_label_text = g_strdup_printf("Current Wireless Interface: #%s", airpcap_get_if_string_number(if_info));
215 gtk_label_set_text(GTK_LABEL(airpcap_toolbar_label),if_label_text);
216 g_free(if_label_text);
218 change_airpcap_settings = FALSE;
219 if (if_info->pSupportedChannels != NULL && if_info->numSupportedChannels > 0){
222 for (; i<if_info->numSupportedChannels; i++){
223 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(toolbar_channel_cb), ieee80211_mhz_to_str(if_info->pSupportedChannels[i].Frequency));
227 airpcap_update_channel_combo(GTK_WIDGET(toolbar_channel_cb),if_info);
228 airpcap_update_channel_offset_combo(if_info, if_info->channelInfo.Frequency, airpcap_toolbar_channel_offset, TRUE);
229 change_airpcap_settings = TRUE;
233 gtk_widget_set_sensitive(airpcap_tb,TRUE);
234 gtk_widget_set_sensitive(airpcap_toolbar_label,FALSE);
235 gtk_widget_set_sensitive(toolbar_channel_cb,FALSE);
236 gtk_widget_set_sensitive(airpcap_toolbar_channel_lb,FALSE);
237 gtk_widget_set_sensitive(airpcap_toolbar_channel_offset,FALSE);
238 gtk_widget_set_sensitive(airpcap_toolbar_channel_offset_lb,FALSE);
239 gtk_widget_set_sensitive(airpcap_toolbar_fcs,FALSE);
240 gtk_widget_set_sensitive(airpcap_toolbar_fcs_lb,FALSE);
241 gtk_widget_set_sensitive(airpcap_toolbar_button,FALSE);
242 gtk_widget_set_sensitive(airpcap_toolbar_crc_filter_combo,FALSE);
243 gtk_widget_set_sensitive(airpcap_toolbar_decryption,TRUE);
244 gtk_widget_set_sensitive(airpcap_toolbar_decryption_lb,TRUE);
245 gtk_widget_set_sensitive(airpcap_toolbar_keys_button,TRUE);
246 change_airpcap_settings = FALSE;
251 * Add a key (string) to the given list
254 airpcap_add_key_to_list(GtkListStore *key_list_store, gchar* type, gchar* key, gchar* ssid)
258 gtk_list_store_insert_with_values(key_list_store , &iter, G_MAXINT,
266 * Fill the list with the keys. BEWARE! At this point, Wireshark and Drivers
267 * keys should be EQUALS! But is better to load keys from Wireshark, because
268 * the driver is not always present, and maybe that cannot support some keys
269 * (i.e. the WPA problem)
272 airpcap_fill_key_list(GtkListStore *key_list_store)
276 airpcap_if_info_t* fake_if_info;
277 GList* wireshark_key_list=NULL;
278 decryption_key_t* curr_key = NULL;
283 fake_if_info = airpcap_driver_fake_if_info_new();
285 /* We can retrieve the driver's key list (i.e. we have the right .dll)*/
286 wireshark_key_list = get_wireshark_keys();
287 n = g_list_length(wireshark_key_list);
289 for(i = 0; i < n; i++)
291 curr_key = (decryption_key_t*)g_list_nth_data(wireshark_key_list,i);
293 if(curr_key->type == AIRPDCAP_KEY_TYPE_WEP)
295 gtk_list_store_insert_with_values(key_list_store , &iter, G_MAXINT,
296 KL_COL_TYPE, AIRPCAP_WEP_KEY_STRING,
297 KL_COL_KEY, curr_key->key->str,
301 else if(curr_key->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
303 if(curr_key->ssid != NULL)
304 s = format_uri(curr_key->ssid, ":");
308 gtk_list_store_insert_with_values(key_list_store , &iter, G_MAXINT,
309 KL_COL_TYPE, AIRPCAP_WPA_PWD_KEY_STRING,
310 KL_COL_KEY, curr_key->key->str,
315 else if(curr_key->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
317 gtk_list_store_insert_with_values(key_list_store , &iter, G_MAXINT,
318 KL_COL_TYPE, AIRPCAP_WPA_BIN_KEY_STRING,
319 KL_COL_KEY, curr_key->key->str,
326 airpcap_if_info_free(fake_if_info);
331 * Function used to retrieve the AirpcapValidationType given the string name.
333 AirpcapValidationType
334 airpcap_get_validation_type(const gchar* name)
336 if(!(g_ascii_strcasecmp(AIRPCAP_VALIDATION_TYPE_NAME_ALL,name)))
338 return AIRPCAP_VT_ACCEPT_EVERYTHING;
340 else if(!(g_ascii_strcasecmp(AIRPCAP_VALIDATION_TYPE_NAME_CORRECT,name)))
342 return AIRPCAP_VT_ACCEPT_CORRECT_FRAMES;
344 else if(!(g_ascii_strcasecmp(AIRPCAP_VALIDATION_TYPE_NAME_CORRUPT,name)))
346 return AIRPCAP_VT_ACCEPT_CORRUPT_FRAMES;
348 return AIRPCAP_VT_UNKNOWN;
352 * Function used to retrieve the string name given an AirpcapValidationType,
353 * or NULL in case of error
356 airpcap_get_validation_name(AirpcapValidationType vt)
358 if(vt == AIRPCAP_VT_ACCEPT_EVERYTHING)
360 return AIRPCAP_VALIDATION_TYPE_NAME_ALL;
362 else if(vt == AIRPCAP_VT_ACCEPT_CORRECT_FRAMES)
364 return AIRPCAP_VALIDATION_TYPE_NAME_CORRECT;
366 else if(vt == AIRPCAP_VT_ACCEPT_CORRUPT_FRAMES)
368 return AIRPCAP_VALIDATION_TYPE_NAME_CORRUPT;
370 else if(vt == AIRPCAP_VT_UNKNOWN)
372 return AIRPCAP_VALIDATION_TYPE_NAME_UNKNOWN;
378 * Return an appropriate combo box entry number for the given an AirpcapValidationType,
382 airpcap_get_validation_combo_entry(AirpcapValidationType vt)
385 case AIRPCAP_VT_ACCEPT_CORRECT_FRAMES:
388 case AIRPCAP_VT_ACCEPT_CORRUPT_FRAMES:
398 * Returns the AirpcapLinkType corresponding to the given string name.
401 airpcap_get_link_type(const gchar* name)
403 if(!(g_ascii_strcasecmp(AIRPCAP_LINK_TYPE_NAME_802_11_ONLY,name))){
404 return AIRPCAP_LT_802_11;
405 }else if(!(g_ascii_strcasecmp(AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_RADIO,name))){
406 return AIRPCAP_LT_802_11_PLUS_RADIO;
407 }else if(!(g_ascii_strcasecmp(AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_PPI,name))){
408 return AIRPCAP_LT_802_11_PLUS_PPI;
410 return AIRPCAP_LT_UNKNOWN;
415 * Returns the string name corresponding to the given AirpcapLinkType, or
416 * NULL in case of error.
419 airpcap_get_link_name(AirpcapLinkType lt)
421 if(lt == AIRPCAP_LT_802_11){
422 return AIRPCAP_LINK_TYPE_NAME_802_11_ONLY;
423 }else if(lt == AIRPCAP_LT_802_11_PLUS_RADIO){
424 return AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_RADIO;
425 }else if(lt == AIRPCAP_LT_802_11_PLUS_PPI){
426 return AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_PPI;
427 }else if(lt == AIRPCAP_LT_UNKNOWN){
428 return AIRPCAP_LINK_TYPE_NAME_UNKNOWN;
434 * Sets the entry of the validation combo using the AirpcapValidationType.
437 airpcap_validation_type_combo_set_by_type(GtkWidget* c, AirpcapValidationType type)
439 gtk_combo_box_set_active(GTK_COMBO_BOX(c), airpcap_get_validation_combo_entry(type));
443 * Returns the string corresponding to the given guint (1-14, for channel only)
446 airpcap_get_channel_name(guint n)
448 return g_strdup_printf("%d",n);
453 * Set the combo box entry string given a channel frequency
456 airpcap_channel_combo_set_by_frequency(GtkWidget* cb, guint chan_freq)
460 for (i = 0; i < airpcap_if_selected->numSupportedChannels; i++) {
461 if (airpcap_if_selected->pSupportedChannels[i].Frequency == chan_freq) {
462 gtk_combo_box_set_active(GTK_COMBO_BOX(cb), i);
469 * Change channel of Airpcap Adapter
472 airpcap_update_frequency_and_offset(airpcap_if_info_t* if_info)
474 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
476 gboolean return_value = FALSE;
478 if (if_info != NULL){
479 ad = airpcap_if_open(if_info->name, ebuf);
482 return_value = airpcap_if_set_device_channel_ex(ad,if_info->channelInfo);
483 airpcap_if_close(ad);
491 * Changed callback for the channel combobox - common routine
494 airpcap_channel_changed_common(GtkWidget *channel_cb, gpointer channel_offset_cb, gboolean set)
498 if (channel_cb && channel_offset_cb && change_airpcap_settings && airpcap_if_active) {
499 cur_chan_idx = gtk_combo_box_get_active(GTK_COMBO_BOX(channel_cb));
500 if (cur_chan_idx >= 0 && cur_chan_idx < (gint) airpcap_if_active->numSupportedChannels) {
502 airpcap_if_active->channelInfo.Frequency = airpcap_if_active->pSupportedChannels[cur_chan_idx].Frequency;
504 airpcap_update_channel_offset_combo(airpcap_if_active,
505 airpcap_if_active->channelInfo.Frequency,
506 GTK_WIDGET(channel_offset_cb), set);
512 * Changed callback for the channel combobox - set channel and offset
515 airpcap_channel_changed_set_cb(GtkWidget *channel_cb, gpointer channel_offset_cb)
517 airpcap_channel_changed_common(channel_cb, channel_offset_cb, TRUE);
521 * Changed callback for the channel combobox - don't set channel and offset
524 airpcap_channel_changed_noset_cb(GtkWidget *channel_cb, gpointer channel_offset_cb)
526 airpcap_channel_changed_common(channel_cb, channel_offset_cb, FALSE);
530 airpcap_get_selected_channel_offset(GtkWidget *channel_offset_cb) {
536 if (channel_offset_cb == NULL || !gtk_widget_get_sensitive(channel_offset_cb)) {
540 off_str = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT(channel_offset_cb));
541 if (off_str && (g_ascii_strcasecmp("", off_str)))
543 if (airpcap_if_selected != NULL)
545 sscanf(off_str, "%d", &offset);
546 if (offset >= -1 && offset <= 1) {
556 * Changed callback for the channel offset combobox
559 airpcap_channel_offset_changed_cb(GtkWidget *channel_offset_cb, gpointer data _U_)
561 airpcap_if_selected->channelInfo.ExtChannel = airpcap_get_selected_channel_offset(channel_offset_cb);
562 airpcap_if_selected->saved = FALSE;
563 change_airpcap_settings = TRUE;
564 if (!airpcap_update_frequency_and_offset(airpcap_if_selected)){
565 simple_dialog(ESD_TYPE_ERROR,ESD_BTN_OK,
566 "Unable to set extension channel %d",
567 airpcap_if_selected->channelInfo.ExtChannel);
573 * Update the channel offset of the given combobox according to the given frequency.
576 airpcap_update_channel_offset_combo(airpcap_if_info_t* if_info, guint chan_freq, GtkWidget *channel_offset_cb, gboolean set)
584 if (!if_info || airpcap_if_is_any(if_info) || if_info->pSupportedChannels == NULL || if_info->numSupportedChannels < 1) {
585 gtk_widget_set_sensitive(GTK_WIDGET(channel_offset_cb),FALSE);
586 gtk_combo_box_set_active(GTK_COMBO_BOX(channel_offset_cb), -1);
590 new_offset = current_offset = if_info->channelInfo.ExtChannel;
592 /* Clear out the list */
593 while (gtk_tree_model_iter_n_children(gtk_combo_box_get_model(GTK_COMBO_BOX(channel_offset_cb)), NULL) > 0) {
594 gtk_combo_box_text_remove(GTK_COMBO_BOX_TEXT(channel_offset_cb), 0);
597 gtk_widget_set_sensitive(GTK_WIDGET(channel_offset_cb), TRUE);
599 for (i = 0; i < if_info->numSupportedChannels; i++) {
600 if (if_info->pSupportedChannels[i].Frequency == chan_freq) {
602 /* If we can't be low or high, nudge the offset to 0 */
603 if (current_offset == -1 && !(if_info->pSupportedChannels[i].Flags & FLAG_CAN_BE_LOW)) {
605 } else if (current_offset == 1 && !(if_info->pSupportedChannels[i].Flags & FLAG_CAN_BE_HIGH)) {
609 if ((if_info->pSupportedChannels[i].Flags & FLAG_CAN_BE_LOW)) {
610 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(channel_offset_cb), "-1");
612 if (new_offset == -1) {
613 active_idx = idx_count;
616 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(channel_offset_cb), "0");
618 if (new_offset == 0) {
619 active_idx = idx_count;
621 if ((if_info->pSupportedChannels[i].Flags & FLAG_CAN_BE_HIGH)){
622 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(channel_offset_cb), "+1");
624 if (new_offset == 1) {
625 active_idx = idx_count;
632 gtk_combo_box_set_active(GTK_COMBO_BOX(channel_offset_cb), active_idx);
636 change_airpcap_settings = TRUE;
638 if_info->channelInfo.ExtChannel = new_offset;
639 if (!airpcap_update_frequency_and_offset(if_info)){
640 simple_dialog(ESD_TYPE_ERROR,ESD_BTN_OK,"Adapter failed to be set with the following settings: Frequency - %d Extension Channel - %d", if_info->channelInfo.Frequency, if_info->channelInfo.ExtChannel);
645 gtk_widget_set_sensitive(channel_offset_cb, FALSE);
650 * Returns '1' if this is the "Any" adapter, '0' otherwise
653 airpcap_if_is_any(airpcap_if_info_t* if_info)
655 if(g_ascii_strcasecmp(if_info->name,AIRPCAP_DEVICE_ANY_EXTRACT_STRING)==0)
662 * Update channel combo box. If the airpcap interface is "Any", the combo box will be disabled.
665 airpcap_update_channel_combo(GtkWidget* channel_cb, airpcap_if_info_t* if_info)
667 if(!if_info || airpcap_if_is_any(if_info) || !airpcap_if_selected)
669 gtk_combo_box_set_active(GTK_COMBO_BOX(channel_cb), -1);
670 change_airpcap_settings = FALSE;
671 gtk_widget_set_sensitive(GTK_WIDGET(channel_cb),FALSE);
675 while (gtk_tree_model_iter_n_children(gtk_combo_box_get_model(GTK_COMBO_BOX(channel_cb)), NULL) > 0) {
676 gtk_combo_box_text_remove(GTK_COMBO_BOX_TEXT(channel_cb), 0);
679 if (if_info != NULL && if_info->pSupportedChannels != NULL && if_info->numSupportedChannels > 0){
681 for (i = 0; i<(if_info->numSupportedChannels); i++){
682 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(channel_cb), ieee80211_mhz_to_str(airpcap_if_selected->pSupportedChannels[i].Frequency));
686 airpcap_channel_combo_set_by_frequency(channel_cb, if_info->channelInfo.Frequency);
687 change_airpcap_settings = TRUE;
688 gtk_widget_set_sensitive(GTK_WIDGET(channel_cb), TRUE);
693 * Takes the keys from the GtkList widget, and add them to the interface list
696 airpcap_add_keys_to_driver_from_list(GtkListStore *key_list_store, airpcap_if_info_t *fake_if_info)
700 GtkTreeModel *model = GTK_TREE_MODEL(key_list_store);
705 PAirpcapKeysCollection KeysCollection;
706 guint KeysCollectionSize;
709 guint keys_in_list = 0;
711 gchar *row_type, *row_key; /* SSID not needed for AirPcap */
714 if(fake_if_info == NULL)
717 keys_in_list = gtk_tree_model_iter_n_children(model, NULL);
720 * Save the encryption keys, if we have any of them
722 KeysCollectionSize = 0;
725 * Calculate the size of the keys collection
727 KeysCollectionSize = sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey);
730 * Allocate the collection
732 KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize);
735 * Populate the key collection
737 KeysCollection->nKeys = keys_in_list;
739 for(i = 0; i < keys_in_list; i++)
741 path = gtk_tree_path_new_from_indices(i, -1);
742 gtk_tree_model_get_iter(model, &iter, path);
743 gtk_tree_path_free(path);
744 gtk_tree_model_get(model, &iter,
745 KL_COL_TYPE, &row_type,
746 KL_COL_KEY, &row_key,
749 if(g_ascii_strcasecmp(row_type,AIRPCAP_WEP_KEY_STRING) == 0)
750 KeysCollection->Keys[i].KeyType = AIRPDCAP_KEY_TYPE_WEP;
751 else if(g_ascii_strcasecmp(row_type,AIRPCAP_WPA_PWD_KEY_STRING) == 0)
752 KeysCollection->Keys[i].KeyType = AIRPDCAP_KEY_TYPE_WPA_PWD;
753 else if(g_ascii_strcasecmp(row_type,AIRPCAP_WPA_BIN_KEY_STRING) == 0)
754 KeysCollection->Keys[i].KeyType = AIRPDCAP_KEY_TYPE_WPA_PMK;
756 /* Retrieve the Item corresponding to the i-th key */
757 key_len = strlen(row_key);
759 KeysCollection->Keys[i].KeyLen = (guint) key_len / 2;
760 memset(&KeysCollection->Keys[i].KeyData, 0, sizeof(KeysCollection->Keys[i].KeyData));
762 /* Key must be saved in adifferent way, depending on its type... */
763 if(KeysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
765 for(j = 0 ; j < key_len; j += 2)
770 KeyByte = (guint8)strtol(s, NULL, 16);
771 KeysCollection->Keys[i].KeyData[j / 2] = KeyByte;
779 * Free the old adapter key collection!
781 if(fake_if_info->keysCollection != NULL)
782 g_free(fake_if_info->keysCollection);
785 * Set this collection ad the new one
787 fake_if_info->keysCollection = KeysCollection;
788 fake_if_info->keysCollectionSize = KeysCollectionSize;
793 * This function will take the current keys (widget list), specified for the
794 * current adapter, and save them as default for ALL the others.
797 airpcap_read_and_save_decryption_keys_from_list_store(GtkListStore* key_list_store, airpcap_if_info_t* info_if, GList* if_list)
800 GtkTreeModel *model = GTK_TREE_MODEL(key_list_store);
805 airpcap_if_info_t* curr_if = NULL;
806 airpcap_if_info_t* fake_info_if = NULL;
807 GList* key_list=NULL;
809 char* tmp_type = NULL;
810 char* tmp_key = NULL;
813 decryption_key_t* tmp_dk=NULL;
816 * Save the keys for Wireshark...
819 /* Create a list of keys from the list store */
820 for (items_left = gtk_tree_model_get_iter_first (model, &iter);
822 items_left = gtk_tree_model_iter_next (model, &iter)) {
824 gtk_tree_model_get(model, &iter,
825 KL_COL_TYPE, &tmp_type,
826 KL_COL_KEY, &tmp_key,
827 KL_COL_SSID, &tmp_ssid,
830 if(g_ascii_strcasecmp(tmp_type, AIRPCAP_WEP_KEY_STRING) == 0)
832 tmp_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
833 tmp_dk->key = g_string_new(tmp_key);
835 tmp_dk->type = AIRPDCAP_KEY_TYPE_WEP;
836 tmp_dk->bits = (guint) tmp_dk->key->len * 4;
837 key_list = g_list_append(key_list,tmp_dk);
839 else if(g_ascii_strcasecmp(tmp_type, AIRPCAP_WPA_PWD_KEY_STRING) == 0)
841 tmp_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
842 tmp_dk->key = g_string_new(tmp_key);
843 tmp_dk->ssid = g_byte_array_new();
844 uri_str_to_bytes(tmp_ssid, tmp_dk->ssid);
845 tmp_dk->type = AIRPDCAP_KEY_TYPE_WPA_PWD;
847 key_list = g_list_append(key_list,tmp_dk);
849 else if(g_ascii_strcasecmp(tmp_type, AIRPCAP_WPA_BIN_KEY_STRING) == 0)
851 tmp_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
852 tmp_dk->key = g_string_new(tmp_key);
853 tmp_dk->ssid = NULL; /* No SSID in this case */
854 tmp_dk->type = AIRPDCAP_KEY_TYPE_WPA_PMK;
856 key_list = g_list_append(key_list,tmp_dk);
862 r = save_wlan_wireshark_wep_keys(key_list);
863 /* The key_list has been freed!!! */
866 * Save the key list for driver.
868 if( (if_list == NULL) || (info_if == NULL) ) return;
870 fake_info_if = airpcap_driver_fake_if_info_new();
872 airpcap_add_keys_to_driver_from_list(key_list_store,fake_info_if);
873 airpcap_save_driver_if_configuration(fake_info_if);
874 airpcap_if_info_free(fake_info_if);
876 if_n = g_list_length(if_list);
878 /* For all the adapters in the list, empty the key list */
879 for(i = 0; i < if_n; i++)
881 curr_if = (airpcap_if_info_t*)g_list_nth_data(if_list,i);
885 /* XXX - Set an empty collection */
886 airpcap_if_clear_decryption_settings(curr_if);
888 /* Save to registry */
889 airpcap_save_selected_if_configuration(curr_if);
895 * This function will load from the preferences file ALL the
896 * keys (WEP, WPA and WPA_BIN) and will set them as default for
897 * each adapter. To do this, it will save the keys in the registry...
898 * A check will be performed, to make sure that keys found in
899 * registry and keys found in Wireshark preferences are the same. If not,
900 * the user will be asked to choose if use all keys (merge them),
901 * or use Wireshark preferences ones. In the last case, registry keys will
902 * be overwritten for all the connected AirPcap adapters.
903 * In the first case, adapters will use their own keys, but those
904 * keys will not be accessible via Wireshark...
907 airpcap_check_decryption_keys(GList* if_list)
911 gint n_adapters_keys = 0;
912 gint n_driver_keys = 0;
913 gint n_wireshark_keys = 0;
914 airpcap_if_info_t* curr_if = NULL;
916 GList* wireshark_key_list;
917 GList* driver_key_list;
918 GList* curr_adapter_key_list;
920 gboolean equals = TRUE;
921 gboolean adapters_keys_equals=TRUE;
924 * If no AirPcap interface is found, return TRUE, so Wireshark
925 * will use HIS OWN keys.
930 if_n = g_list_length(if_list);
932 /* Get Wireshark preferences keys */
933 wireshark_key_list = get_wireshark_keys();
934 n_wireshark_keys = g_list_length(wireshark_key_list);
936 /* Retrieve AirPcap driver's keys */
937 driver_key_list = get_airpcap_driver_keys();
938 n_driver_keys = g_list_length(driver_key_list);
940 equals &= key_lists_are_equal(wireshark_key_list,driver_key_list);
942 for(i = 0; i < if_n; i++)
944 curr_if = (airpcap_if_info_t*)g_list_nth_data(if_list,i);
945 curr_adapter_key_list = get_airpcap_device_keys(curr_if);
946 n_adapters_keys += g_list_length(curr_adapter_key_list);
947 adapters_keys_equals &= key_lists_are_equal(wireshark_key_list,curr_adapter_key_list);
950 if(n_adapters_keys != 0) /* If for some reason at least one specific key has been found */
951 equals &= adapters_keys_equals; /* */
953 if(n_driver_keys == 0) /* No keys set in any of the AirPcap adapters... */
954 return TRUE; /* Use Wireshark keys and set them ad default for airpcap devices */
960 * This function will load from the preferences file ALL the
961 * keys (WEP, WPA_PWD and WPA_BIN) and will set them as default for
962 * each adapter. To do this, it will save the keys in the registry...
963 * A check will be performed, to make sure that keys found in
964 * registry and keys found in Wireshark preferences are the same. If not,
965 * the user will be asked to choose if use all keys (merge them),
966 * or use Wireshark preferences ones. In the last case, registry keys will
967 * be overwritten for all the connected AirPcap adapters.
968 * In the first case, adapters will use their own keys, but those
969 * keys will not be accessible via Wireshark...
972 airpcap_load_decryption_keys(GList* if_list)
976 airpcap_if_info_t* curr_if = NULL;
978 if(if_list == NULL) return;
980 if_n = g_list_length(if_list);
982 for(i = 0; i < if_n; i++)
984 curr_if = (airpcap_if_info_t*)g_list_nth_data(if_list,i);
985 load_wlan_driver_wep_keys();
990 * This function will set the gibven GList of decryption_key_t structures
991 * as the defoult for both Wireshark and the AirPcap adapters...
994 airpcap_save_decryption_keys(GList* key_list, GList* adapters_list)
999 airpcap_if_info_t* curr_if = NULL;
1000 GList* empty_key_list = NULL;
1002 if( (key_list == NULL) || (adapters_list == NULL)) return;
1004 if_n = g_list_length(adapters_list);
1005 key_n = g_list_length(key_list);
1007 /* Set the driver's global list of keys. */
1008 write_wlan_driver_wep_keys_to_registry(key_list);
1010 /* Empty the key list for each interface */
1011 for(i = 0; i < if_n; i++)
1013 curr_if = (airpcap_if_info_t*)g_list_nth_data(adapters_list,i);
1014 write_wlan_wep_keys_to_registry(curr_if,empty_key_list);
1018 * This will set the keys of the current adapter as Wireshark default...
1019 * Now all the adapters have the same keys, so curr_if is ok as any other...
1021 save_wlan_wireshark_wep_keys(key_list);
1025 * This function is used to enable/disable the toolbar widgets
1026 * depending on the type of interface selected... Not the whole
1027 * toolbar must be grayed/enabled ... Only some widgets...
1030 airpcap_enable_toolbar_widgets(GtkWidget* w, gboolean en)
1032 GtkWidget *toolbar_tb,
1034 *toolbar_channel_cb,
1047 if_description_lb = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_INTERFACE_KEY);
1048 channel_lb = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_CHANNEL_LABEL_KEY);
1049 toolbar_channel_cb = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_CHANNEL_KEY);
1050 channel_offset_cb = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_CHANNEL_OFFSET_KEY);
1051 channel_offset_lb = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_CHANNEL_OFFSET_LABEL_KEY);
1052 fcs_lb = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_FCS_FILTER_LABEL_KEY);
1053 fcs_cb = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_FCS_FILTER_KEY);
1054 advanced_bt = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_ADVANCED_KEY);
1057 if(if_description_lb != NULL)
1058 gtk_widget_set_sensitive(if_description_lb,en);
1059 if(channel_lb != NULL)
1060 gtk_widget_set_sensitive(channel_lb,en);
1061 if(toolbar_channel_cb != NULL)
1062 gtk_widget_set_sensitive(toolbar_channel_cb,en);
1063 if(channel_offset_cb != NULL)
1064 gtk_widget_set_sensitive(channel_offset_cb,en);
1065 if(channel_offset_lb != NULL)
1066 gtk_widget_set_sensitive(channel_offset_lb,en);
1068 gtk_widget_set_sensitive(fcs_lb,en);
1070 gtk_widget_set_sensitive(fcs_cb,en);
1071 if(advanced_bt != NULL)
1072 gtk_widget_set_sensitive(advanced_bt,en);
1077 #endif /* HAVE_AIRPCAP */
1080 * Editor modelines - http://www.wireshark.org/tools/modelines.html
1085 * indent-tabs-mode: nil
1088 * vi: set shiftwidth=4 tabstop=4 expandtab
1089 * :indentSize=4:tabSize=4:noTabs=true: