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"
54 #include "airpcap_loader.h"
55 #include "airpcap_gui_utils.h"
58 /* Controls the releay of settings back to the adapter. */
59 gboolean change_airpcap_settings = FALSE;
62 * Set up the airpcap toolbar for the new capture interface
65 airpcap_set_toolbar_start_capture(airpcap_if_info_t* if_info)
67 GtkWidget *airpcap_toolbar_label;
68 GtkWidget *toolbar_channel_cb;
69 GtkWidget *airpcap_toolbar_channel_lb;
70 GtkWidget *airpcap_toolbar_channel_offset;
71 GtkWidget *airpcap_toolbar_channel_offset_lb;
72 GtkWidget *airpcap_toolbar_button;
73 GtkWidget *airpcap_toolbar_fcs;
74 GtkWidget *airpcap_toolbar_fcs_lb;
75 GtkWidget *airpcap_toolbar_decryption;
76 GtkWidget *airpcap_toolbar_decryption_lb;
77 GtkWidget *airpcap_toolbar_keys_button;
81 airpcap_toolbar_label = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_INTERFACE_KEY);
82 toolbar_channel_cb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_CHANNEL_KEY);
83 airpcap_toolbar_channel_lb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_CHANNEL_LABEL_KEY);
84 airpcap_toolbar_channel_offset = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_CHANNEL_OFFSET_KEY);
85 airpcap_toolbar_channel_offset_lb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_CHANNEL_OFFSET_LABEL_KEY);
86 airpcap_toolbar_fcs = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_FCS_FILTER_KEY);
87 airpcap_toolbar_fcs_lb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_FCS_FILTER_LABEL_KEY);
88 airpcap_toolbar_button = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_ADVANCED_KEY);
89 airpcap_toolbar_decryption = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_DECRYPTION_KEY);
90 airpcap_toolbar_decryption_lb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_DECRYPTION_LABEL_KEY);
91 airpcap_toolbar_keys_button = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_KEY_MANAGEMENT_KEY);
93 /* The current interface is an airpcap interface */
96 gtk_widget_set_sensitive(airpcap_tb,TRUE);
97 gtk_widget_set_sensitive(airpcap_toolbar_label,TRUE);
98 gtk_widget_set_sensitive(toolbar_channel_cb,TRUE);
99 gtk_widget_set_sensitive(airpcap_toolbar_channel_lb,TRUE);
100 gtk_widget_set_sensitive(airpcap_toolbar_channel_offset,TRUE);
101 gtk_widget_set_sensitive(airpcap_toolbar_channel_offset_lb,TRUE);
102 gtk_widget_set_sensitive(airpcap_toolbar_fcs,FALSE);
103 gtk_widget_set_sensitive(airpcap_toolbar_fcs_lb,FALSE);
104 gtk_widget_set_sensitive(airpcap_toolbar_button,FALSE);
105 gtk_widget_set_sensitive(airpcap_toolbar_button,FALSE);
106 gtk_widget_set_sensitive(airpcap_toolbar_decryption,FALSE);
107 gtk_widget_set_sensitive(airpcap_toolbar_decryption_lb,FALSE);
108 gtk_widget_set_sensitive(airpcap_toolbar_keys_button,FALSE);
110 /*decryption check box*/
111 g_signal_handlers_block_by_func (airpcap_toolbar_decryption,airpcap_toolbar_encryption_cb, airpcap_tb);
112 if(if_info->DecryptionOn == AIRPCAP_DECRYPTION_ON)
113 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(airpcap_toolbar_decryption),TRUE);
115 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(airpcap_toolbar_decryption),FALSE);
116 g_signal_handlers_unblock_by_func (airpcap_toolbar_decryption,airpcap_toolbar_encryption_cb, airpcap_tb);
118 if_label_text = g_strdup_printf("Current Wireless Interface: #%s", airpcap_get_if_string_number(if_info));
119 gtk_label_set_text(GTK_LABEL(airpcap_toolbar_label),if_label_text);
120 g_free(if_label_text);
122 change_airpcap_settings = FALSE;
123 if (if_info->pSupportedChannels != NULL && if_info->numSupportedChannels > 0){
126 for (; i<if_info->numSupportedChannels; i++){
127 gtk_combo_box_append_text(GTK_COMBO_BOX(toolbar_channel_cb), ieee80211_mhz_to_str(if_info->pSupportedChannels[i].Frequency));
131 airpcap_update_channel_combo(GTK_WIDGET(toolbar_channel_cb),if_info);
132 airpcap_update_channel_offset_combo(if_info, if_info->channelInfo.Frequency, airpcap_toolbar_channel_offset, TRUE);
133 change_airpcap_settings = TRUE;
135 else /* Current interface is NOT an AirPcap one... */
137 gtk_widget_set_sensitive(airpcap_tb,FALSE);
138 gtk_widget_set_sensitive(airpcap_toolbar_label,FALSE);
139 gtk_widget_set_sensitive(toolbar_channel_cb,FALSE);
140 gtk_widget_set_sensitive(airpcap_toolbar_channel_lb,FALSE);
141 gtk_widget_set_sensitive(airpcap_toolbar_channel_offset,FALSE);
142 gtk_widget_set_sensitive(airpcap_toolbar_channel_offset_lb,FALSE);
143 gtk_widget_set_sensitive(airpcap_toolbar_fcs,FALSE);
144 gtk_widget_set_sensitive(airpcap_toolbar_fcs_lb,FALSE);
145 gtk_widget_set_sensitive(airpcap_toolbar_button,FALSE);
146 gtk_widget_set_sensitive(airpcap_toolbar_button,FALSE);
147 gtk_widget_set_sensitive(airpcap_toolbar_decryption,FALSE);
148 gtk_widget_set_sensitive(airpcap_toolbar_decryption_lb,FALSE);
149 gtk_widget_set_sensitive(airpcap_toolbar_keys_button,FALSE);
154 * Set up the airpcap toolbar for the new capture interface
157 airpcap_set_toolbar_stop_capture(airpcap_if_info_t* if_info)
159 GtkWidget *airpcap_toolbar_crc_filter_combo;
160 GtkWidget *airpcap_toolbar_label;
161 GtkWidget *toolbar_channel_cb;
162 GtkWidget *airpcap_toolbar_channel_lb;
163 GtkWidget *airpcap_toolbar_channel_offset;
164 GtkWidget *airpcap_toolbar_channel_offset_lb;
165 GtkWidget *airpcap_toolbar_button;
166 GtkWidget *airpcap_toolbar_fcs;
167 GtkWidget *airpcap_toolbar_fcs_lb;
168 GtkWidget *airpcap_toolbar_decryption;
169 GtkWidget *airpcap_toolbar_decryption_lb;
170 GtkWidget *airpcap_toolbar_keys_button;
172 gchar *if_label_text;
174 airpcap_toolbar_crc_filter_combo = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_FCS_FILTER_KEY);
175 airpcap_toolbar_label = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_INTERFACE_KEY);
176 toolbar_channel_cb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_CHANNEL_KEY);
177 airpcap_toolbar_channel_lb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_CHANNEL_LABEL_KEY);
178 airpcap_toolbar_channel_offset = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_CHANNEL_OFFSET_KEY);
179 airpcap_toolbar_channel_offset_lb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_CHANNEL_OFFSET_LABEL_KEY);
180 airpcap_toolbar_fcs = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_FCS_FILTER_KEY);
181 airpcap_toolbar_fcs_lb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_FCS_FILTER_LABEL_KEY);
182 airpcap_toolbar_button = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_ADVANCED_KEY);
183 airpcap_toolbar_decryption = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_DECRYPTION_KEY);
184 airpcap_toolbar_decryption_lb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_DECRYPTION_LABEL_KEY);
185 airpcap_toolbar_keys_button = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_KEY_MANAGEMENT_KEY);
187 /* The current interface is an airpcap interface */
190 gtk_widget_set_sensitive(airpcap_tb,TRUE);
191 gtk_widget_set_sensitive(airpcap_toolbar_label,TRUE);
192 gtk_widget_set_sensitive(toolbar_channel_cb,TRUE);
193 gtk_widget_set_sensitive(airpcap_toolbar_channel_lb,TRUE);
194 gtk_widget_set_sensitive(airpcap_toolbar_channel_offset,TRUE);
195 gtk_widget_set_sensitive(airpcap_toolbar_channel_offset_lb,TRUE);
196 gtk_widget_set_sensitive(airpcap_toolbar_fcs,TRUE);
197 gtk_widget_set_sensitive(airpcap_toolbar_fcs_lb,TRUE);
198 gtk_widget_set_sensitive(airpcap_toolbar_button,TRUE);
199 gtk_widget_set_sensitive(airpcap_toolbar_crc_filter_combo,TRUE);
200 gtk_widget_set_sensitive(airpcap_toolbar_decryption,TRUE);
201 gtk_widget_set_sensitive(airpcap_toolbar_decryption_lb,TRUE);
202 gtk_widget_set_sensitive(airpcap_toolbar_keys_button,TRUE);
203 airpcap_validation_type_combo_set_by_type(airpcap_toolbar_crc_filter_combo, if_info->CrcValidationOn);
205 /*decription check box*/
206 g_signal_handlers_block_by_func (airpcap_toolbar_decryption,airpcap_toolbar_encryption_cb, airpcap_tb);
207 if(if_info->DecryptionOn == AIRPCAP_DECRYPTION_ON)
208 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(airpcap_toolbar_decryption),TRUE);
210 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(airpcap_toolbar_decryption),FALSE);
211 g_signal_handlers_unblock_by_func (airpcap_toolbar_decryption,airpcap_toolbar_encryption_cb, airpcap_tb);
213 if_label_text = g_strdup_printf("Current Wireless Interface: #%s", airpcap_get_if_string_number(if_info));
214 gtk_label_set_text(GTK_LABEL(airpcap_toolbar_label),if_label_text);
215 g_free(if_label_text);
217 change_airpcap_settings = FALSE;
218 if (if_info->pSupportedChannels != NULL && if_info->numSupportedChannels > 0){
221 for (; i<if_info->numSupportedChannels; i++){
222 gtk_combo_box_append_text(GTK_COMBO_BOX(toolbar_channel_cb), ieee80211_mhz_to_str(if_info->pSupportedChannels[i].Frequency));
226 airpcap_update_channel_combo(GTK_WIDGET(toolbar_channel_cb),if_info);
227 airpcap_update_channel_offset_combo(if_info, if_info->channelInfo.Frequency, airpcap_toolbar_channel_offset, TRUE);
228 change_airpcap_settings = TRUE;
232 gtk_widget_set_sensitive(airpcap_tb,TRUE);
233 gtk_widget_set_sensitive(airpcap_toolbar_label,FALSE);
234 gtk_widget_set_sensitive(toolbar_channel_cb,FALSE);
235 gtk_widget_set_sensitive(airpcap_toolbar_channel_lb,FALSE);
236 gtk_widget_set_sensitive(airpcap_toolbar_channel_offset,FALSE);
237 gtk_widget_set_sensitive(airpcap_toolbar_channel_offset_lb,FALSE);
238 gtk_widget_set_sensitive(airpcap_toolbar_fcs,FALSE);
239 gtk_widget_set_sensitive(airpcap_toolbar_fcs_lb,FALSE);
240 gtk_widget_set_sensitive(airpcap_toolbar_button,FALSE);
241 gtk_widget_set_sensitive(airpcap_toolbar_crc_filter_combo,FALSE);
242 gtk_widget_set_sensitive(airpcap_toolbar_decryption,TRUE);
243 gtk_widget_set_sensitive(airpcap_toolbar_decryption_lb,TRUE);
244 gtk_widget_set_sensitive(airpcap_toolbar_keys_button,TRUE);
245 change_airpcap_settings = FALSE;
250 * Add a key (string) to the given list
253 airpcap_add_key_to_list(GtkWidget *keylist, gchar* type, gchar* key, gchar* ssid)
257 new_row[0] = g_strdup(type);
258 new_row[1] = g_strdup(key);
259 new_row[2] = g_strdup(ssid);
261 gtk_clist_append(GTK_CLIST(keylist),new_row);
269 * Modify a key given a list and a row
272 airpcap_modify_key_in_list(GtkWidget *keylist, gint row, gchar* type, gchar* key, gchar* ssid)
276 new_row[0] = g_strdup(type);
277 new_row[1] = g_strdup(key);
278 new_row[2] = g_strdup(ssid);
280 gtk_clist_set_text(GTK_CLIST(keylist),row,0,new_row[0]);
281 gtk_clist_set_text(GTK_CLIST(keylist),row,1,new_row[1]);
282 gtk_clist_set_text(GTK_CLIST(keylist),row,2,new_row[2]);
290 * Fill the list with the keys. BEWARE! At this point, Wireshark and Drivers
291 * keys should be EQUALS! But is better to load keys from Wireshark, because
292 * the driver is not always present, and maybe that cannot support some keys
293 * (i.e. the WPA problem)
296 airpcap_fill_key_list(GtkWidget *keylist)
302 airpcap_if_info_t* fake_if_info;
303 GList* wireshark_key_list=NULL;
304 decryption_key_t* curr_key = NULL;
308 fake_if_info = airpcap_driver_fake_if_info_new();
310 /* We can retrieve the driver's key list (i.e. we have the right .dll)*/
311 wireshark_key_list = get_wireshark_keys();
312 n = g_list_length(wireshark_key_list);
314 for(i = 0; i < n; i++)
316 curr_key = (decryption_key_t*)g_list_nth_data(wireshark_key_list,i);
318 if(curr_key->type == AIRPDCAP_KEY_TYPE_WEP)
320 s = g_strdup(curr_key->key->str);
322 new_row[0] = g_strdup(AIRPCAP_WEP_KEY_STRING);
323 new_row[1] = g_strdup(s);
324 new_row[2] = g_strdup("");
326 gtk_clist_append(GTK_CLIST(keylist),new_row);
334 else if(curr_key->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
336 s = g_strdup(curr_key->key->str);
337 if(curr_key->ssid != NULL)
338 s2= g_strdup(format_uri(curr_key->ssid, ":"));
342 new_row[0] = g_strdup(AIRPCAP_WPA_PWD_KEY_STRING);
343 new_row[1] = g_strdup(s);
345 if(curr_key->ssid != NULL)
346 new_row[2] = g_strdup(s2);
348 new_row[2] = g_strdup("");
350 gtk_clist_append(GTK_CLIST(keylist),new_row);
360 else if(curr_key->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
362 s = g_strdup(curr_key->key->str);
364 new_row[0] = g_strdup(AIRPCAP_WPA_BIN_KEY_STRING);
365 new_row[1] = g_strdup(s);
366 new_row[2] = g_strdup("");
368 gtk_clist_append(GTK_CLIST(keylist),new_row);
378 airpcap_if_info_free(fake_if_info);
383 * Function used to retrieve the AirpcapValidationType given the string name.
385 AirpcapValidationType
386 airpcap_get_validation_type(const gchar* name)
388 if(!(g_ascii_strcasecmp(AIRPCAP_VALIDATION_TYPE_NAME_ALL,name)))
390 return AIRPCAP_VT_ACCEPT_EVERYTHING;
392 else if(!(g_ascii_strcasecmp(AIRPCAP_VALIDATION_TYPE_NAME_CORRECT,name)))
394 return AIRPCAP_VT_ACCEPT_CORRECT_FRAMES;
396 else if(!(g_ascii_strcasecmp(AIRPCAP_VALIDATION_TYPE_NAME_CORRUPT,name)))
398 return AIRPCAP_VT_ACCEPT_CORRUPT_FRAMES;
400 return AIRPCAP_VT_UNKNOWN;
404 * Function used to retrieve the string name given an AirpcapValidationType,
405 * or NULL in case of error
408 airpcap_get_validation_name(AirpcapValidationType vt)
410 if(vt == AIRPCAP_VT_ACCEPT_EVERYTHING)
412 return AIRPCAP_VALIDATION_TYPE_NAME_ALL;
414 else if(vt == AIRPCAP_VT_ACCEPT_CORRECT_FRAMES)
416 return AIRPCAP_VALIDATION_TYPE_NAME_CORRECT;
418 else if(vt == AIRPCAP_VT_ACCEPT_CORRUPT_FRAMES)
420 return AIRPCAP_VALIDATION_TYPE_NAME_CORRUPT;
422 else if(vt == AIRPCAP_VT_UNKNOWN)
424 return AIRPCAP_VALIDATION_TYPE_NAME_UNKNOWN;
430 * Return an appropriate combo box entry number for the given an AirpcapValidationType,
434 airpcap_get_validation_combo_entry(AirpcapValidationType vt)
437 case AIRPCAP_VT_ACCEPT_CORRECT_FRAMES:
440 case AIRPCAP_VT_ACCEPT_CORRUPT_FRAMES:
450 * Returns the AirpcapLinkType corresponding to the given string name.
453 airpcap_get_link_type(const gchar* name)
455 if(!(g_ascii_strcasecmp(AIRPCAP_LINK_TYPE_NAME_802_11_ONLY,name))){
456 return AIRPCAP_LT_802_11;
457 }else if(!(g_ascii_strcasecmp(AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_RADIO,name))){
458 return AIRPCAP_LT_802_11_PLUS_RADIO;
459 }else if(!(g_ascii_strcasecmp(AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_PPI,name))){
460 return AIRPCAP_LT_802_11_PLUS_PPI;
462 return AIRPCAP_LT_UNKNOWN;
467 * Returns the string name corresponding to the given AirpcapLinkType, or
468 * NULL in case of error.
471 airpcap_get_link_name(AirpcapLinkType lt)
473 if(lt == AIRPCAP_LT_802_11){
474 return AIRPCAP_LINK_TYPE_NAME_802_11_ONLY;
475 }else if(lt == AIRPCAP_LT_802_11_PLUS_RADIO){
476 return AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_RADIO;
477 }else if(lt == AIRPCAP_LT_802_11_PLUS_PPI){
478 return AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_PPI;
479 }else if(lt == AIRPCAP_LT_UNKNOWN){
480 return AIRPCAP_LINK_TYPE_NAME_UNKNOWN;
486 * Sets the entry of the validation combo using the AirpcapValidationType.
489 airpcap_validation_type_combo_set_by_type(GtkWidget* c, AirpcapValidationType type)
491 gtk_combo_box_set_active(GTK_COMBO_BOX(c), airpcap_get_validation_combo_entry(type));
495 * Returns the string corresponding to the given guint (1-14, for channel only)
498 airpcap_get_channel_name(guint n)
500 return g_strdup_printf("%d",n);
505 * Set the combo box entry string given a channel frequency
508 airpcap_channel_combo_set_by_frequency(GtkWidget* cb, guint chan_freq)
512 for (i = 0; i < airpcap_if_selected->numSupportedChannels; i++) {
513 if (airpcap_if_selected->pSupportedChannels[i].Frequency == chan_freq) {
514 gtk_combo_box_set_active(GTK_COMBO_BOX(cb), i);
521 * Change channel of Airpcap Adapter
524 airpcap_update_frequency_and_offset(airpcap_if_info_t* if_info)
526 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
528 gboolean return_value = FALSE;
530 if (if_info != NULL){
531 ad = airpcap_if_open(if_info->name, ebuf);
534 return_value = airpcap_if_set_device_channel_ex(ad,if_info->channelInfo);
535 airpcap_if_close(ad);
543 * Changed callback for the channel combobox - common routine
546 airpcap_channel_changed_common(GtkWidget *channel_cb, gpointer channel_offset_cb, gboolean set)
550 if (channel_cb && channel_offset_cb && change_airpcap_settings && airpcap_if_active) {
551 cur_chan_idx = gtk_combo_box_get_active(GTK_COMBO_BOX(channel_cb));
552 if (cur_chan_idx >= 0 && cur_chan_idx < (gint) airpcap_if_active->numSupportedChannels) {
554 airpcap_if_active->channelInfo.Frequency = airpcap_if_active->pSupportedChannels[cur_chan_idx].Frequency;
556 airpcap_update_channel_offset_combo(airpcap_if_active,
557 airpcap_if_active->channelInfo.Frequency,
558 GTK_WIDGET(channel_offset_cb), set);
564 * Changed callback for the channel combobox - set channel and offset
567 airpcap_channel_changed_set_cb(GtkWidget *channel_cb, gpointer channel_offset_cb)
569 airpcap_channel_changed_common(channel_cb, channel_offset_cb, TRUE);
573 * Changed callback for the channel combobox - don't set channel and offset
576 airpcap_channel_changed_noset_cb(GtkWidget *channel_cb, gpointer channel_offset_cb)
578 airpcap_channel_changed_common(channel_cb, channel_offset_cb, FALSE);
582 airpcap_get_selected_channel_offset(GtkWidget *channel_offset_cb) {
588 if (channel_offset_cb == NULL || !GTK_WIDGET_SENSITIVE(channel_offset_cb)) {
592 off_str = gtk_combo_box_get_active_text(GTK_COMBO_BOX(channel_offset_cb));
593 if (off_str && (g_ascii_strcasecmp("", off_str)))
595 if (airpcap_if_selected != NULL)
597 sscanf(off_str, "%d", &offset);
598 if (offset >= -1 && offset <= 1) {
608 * Changed callback for the channel offset combobox
611 airpcap_channel_offset_changed_cb(GtkWidget *channel_offset_cb, gpointer data _U_)
613 airpcap_if_selected->channelInfo.ExtChannel = airpcap_get_selected_channel_offset(channel_offset_cb);
614 airpcap_if_selected->saved = FALSE;
615 change_airpcap_settings = TRUE;
616 if (!airpcap_update_frequency_and_offset(airpcap_if_selected)){
617 simple_dialog(ESD_TYPE_ERROR,ESD_BTN_OK,
618 "Unable to set extension channel %d",
619 airpcap_if_selected->channelInfo.ExtChannel);
625 * Update the channel offset of the given combobox according to the given frequency.
628 airpcap_update_channel_offset_combo(airpcap_if_info_t* if_info, guint chan_freq, GtkWidget *channel_offset_cb, gboolean set)
636 if (!if_info || airpcap_if_is_any(if_info) || if_info->pSupportedChannels == NULL || if_info->numSupportedChannels < 1) {
637 gtk_widget_set_sensitive(GTK_WIDGET(channel_offset_cb),FALSE);
638 gtk_combo_box_set_active(GTK_COMBO_BOX(channel_offset_cb), -1);
642 new_offset = current_offset = if_info->channelInfo.ExtChannel;
644 /* Clear out the list */
645 while (gtk_tree_model_iter_n_children(gtk_combo_box_get_model(GTK_COMBO_BOX(channel_offset_cb)), NULL) > 0) {
646 gtk_combo_box_remove_text(GTK_COMBO_BOX(channel_offset_cb), 0);
649 gtk_widget_set_sensitive(GTK_WIDGET(channel_offset_cb), TRUE);
651 for (i = 0; i < if_info->numSupportedChannels; i++) {
652 if (if_info->pSupportedChannels[i].Frequency == chan_freq) {
654 /* If we can't be low or high, nudge the offset to 0 */
655 if (current_offset == -1 && !(if_info->pSupportedChannels[i].Flags & FLAG_CAN_BE_LOW)) {
657 } else if (current_offset == 1 && !(if_info->pSupportedChannels[i].Flags & FLAG_CAN_BE_HIGH)) {
661 if ((if_info->pSupportedChannels[i].Flags & FLAG_CAN_BE_LOW)) {
662 gtk_combo_box_append_text(GTK_COMBO_BOX(channel_offset_cb), "-1");
664 if (new_offset == -1) {
665 active_idx = idx_count;
668 gtk_combo_box_append_text(GTK_COMBO_BOX(channel_offset_cb), "0");
670 if (new_offset == 0) {
671 active_idx = idx_count;
673 if ((if_info->pSupportedChannels[i].Flags & FLAG_CAN_BE_HIGH)){
674 gtk_combo_box_append_text(GTK_COMBO_BOX(channel_offset_cb), "+1");
676 if (new_offset == 1) {
677 active_idx = idx_count;
684 gtk_combo_box_set_active(GTK_COMBO_BOX(channel_offset_cb), active_idx);
688 change_airpcap_settings = TRUE;
690 if_info->channelInfo.ExtChannel = new_offset;
691 if (!airpcap_update_frequency_and_offset(if_info)){
692 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);
697 gtk_widget_set_sensitive(channel_offset_cb, FALSE);
702 * Returns '1' if this is the "Any" adapter, '0' otherwise
705 airpcap_if_is_any(airpcap_if_info_t* if_info)
707 if(g_ascii_strcasecmp(if_info->name,AIRPCAP_DEVICE_ANY_EXTRACT_STRING)==0)
714 * Update channel combo box. If the airpcap interface is "Any", the combo box will be disabled.
717 airpcap_update_channel_combo(GtkWidget* channel_cb, airpcap_if_info_t* if_info)
719 if(!if_info || airpcap_if_is_any(if_info) || !airpcap_if_selected)
721 gtk_combo_box_set_active(GTK_COMBO_BOX(channel_cb), -1);
722 change_airpcap_settings = FALSE;
723 gtk_widget_set_sensitive(GTK_WIDGET(channel_cb),FALSE);
727 while (gtk_tree_model_iter_n_children(gtk_combo_box_get_model(GTK_COMBO_BOX(channel_cb)), NULL) > 0) {
728 gtk_combo_box_remove_text(GTK_COMBO_BOX(channel_cb), 0);
731 if (if_info != NULL && if_info->pSupportedChannels != NULL && if_info->numSupportedChannels > 0){
733 for (i = 0; i<(if_info->numSupportedChannels); i++){
734 gtk_combo_box_append_text(GTK_COMBO_BOX(channel_cb), ieee80211_mhz_to_str(airpcap_if_selected->pSupportedChannels[i].Frequency));
738 airpcap_channel_combo_set_by_frequency(channel_cb, if_info->channelInfo.Frequency);
739 change_airpcap_settings = TRUE;
740 gtk_widget_set_sensitive(GTK_WIDGET(channel_cb), TRUE);
746 * Takes the keys from the GtkList widget, and add them to the interface list
749 airpcap_add_keys_from_list(GtkWidget *key_ls, airpcap_if_info_t *if_info _U_)
756 PAirpcapKeysCollection KeysCollection;
757 guint KeysCollectionSize;
760 guint keys_in_list = 0;
766 keys_in_list = GTK_CLIST(key_ls)->rows;
769 * Save the encryption keys, if we have any of them
771 KeysCollectionSize = 0;
774 * Calculate the size of the keys collection
776 KeysCollectionSize = sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey);
779 * Allocate the collection
781 KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize);
784 /* Simple dialog ERROR */
785 simple_dialog(ESD_TYPE_ERROR,ESD_BTN_OK,"%s","Failed memory allocation for KeysCollection!");
790 * Populate the key collection
792 KeysCollection->nKeys = keys_in_list;
794 for(i = 0; i < keys_in_list; i++)
796 /* Retrieve the row infos */
797 gtk_clist_get_text(GTK_CLIST(key_ls),i,0,&row_type);
798 gtk_clist_get_text(GTK_CLIST(key_ls),i,1,&row_key);
799 gtk_clist_get_text(GTK_CLIST(key_ls),i,2,&row_ssid);
801 if(g_ascii_strcasecmp(row_type,AIRPCAP_WEP_KEY_STRING) == 0)
802 KeysCollection->Keys[i].KeyType = AIRPDCAP_KEY_TYPE_WEP;
803 else if(g_ascii_strcasecmp(row_type,AIRPCAP_WPA_PWD_KEY_STRING) == 0)
804 KeysCollection->Keys[i].KeyType = AIRPCAP_KEYTYPE_TKIP;
805 else if(g_ascii_strcasecmp(row_type,AIRPCAP_WPA_BIN_KEY_STRING) == 0)
806 KeysCollection->Keys[i].KeyType = AIRPCAP_KEYTYPE_CCMP;
808 /* Retrieve the Item corresponding to the i-th key */
809 new_key = g_string_new(row_key);
811 KeysCollection->Keys[i].KeyLen = (guint) new_key->len / 2;
812 memset(&KeysCollection->Keys[i].KeyData, 0, sizeof(KeysCollection->Keys[i].KeyData));
814 for(j = 0 ; j < new_key->len; j += 2)
816 s[0] = new_key->str[j];
817 s[1] = new_key->str[j+1];
819 KeyByte = (guint8)strtol(s, NULL, 16);
820 KeysCollection->Keys[i].KeyData[j / 2] = KeyByte;
825 * Free the old adapter key collection!
827 if(airpcap_if_selected->keysCollection != NULL)
828 g_free(airpcap_if_selected->keysCollection);
831 * Set this collection ad the new one
833 airpcap_if_selected->keysCollection = KeysCollection;
834 airpcap_if_selected->keysCollectionSize = KeysCollectionSize;
840 * Takes the keys from the GtkList widget, and add them to the interface list
843 airpcap_add_keys_to_driver_from_list(GtkWidget *key_ls,airpcap_if_info_t *fake_if_info)
850 PAirpcapKeysCollection KeysCollection;
851 guint KeysCollectionSize;
854 guint keys_in_list = 0;
860 if(fake_if_info == NULL)
863 keys_in_list = GTK_CLIST(key_ls)->rows;
866 * Save the encryption keys, if we have any of them
868 KeysCollectionSize = 0;
871 * Calculate the size of the keys collection
873 KeysCollectionSize = sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey);
876 * Allocate the collection
878 KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize);
881 /* Simple dialog ERROR */
882 simple_dialog(ESD_TYPE_ERROR,ESD_BTN_OK,"%s","Failed memory allocation for KeysCollection!");
887 * Populate the key collection
889 KeysCollection->nKeys = keys_in_list;
891 for(i = 0; i < keys_in_list; i++)
893 /* Retrieve the row infos */
894 gtk_clist_get_text(GTK_CLIST(key_ls),i,0,&row_type);
895 gtk_clist_get_text(GTK_CLIST(key_ls),i,1,&row_key);
896 gtk_clist_get_text(GTK_CLIST(key_ls),i,2,&row_ssid);
898 if(g_ascii_strcasecmp(row_type,AIRPCAP_WEP_KEY_STRING) == 0)
899 KeysCollection->Keys[i].KeyType = AIRPDCAP_KEY_TYPE_WEP;
900 else if(g_ascii_strcasecmp(row_type,AIRPCAP_WPA_PWD_KEY_STRING) == 0)
901 KeysCollection->Keys[i].KeyType = AIRPDCAP_KEY_TYPE_WPA_PWD;
902 else if(g_ascii_strcasecmp(row_type,AIRPCAP_WPA_BIN_KEY_STRING) == 0)
903 KeysCollection->Keys[i].KeyType = AIRPDCAP_KEY_TYPE_WPA_PMK;
905 /* Retrieve the Item corresponding to the i-th key */
906 new_key = g_string_new(row_key);
908 KeysCollection->Keys[i].KeyLen = (guint) new_key->len / 2;
909 memset(&KeysCollection->Keys[i].KeyData, 0, sizeof(KeysCollection->Keys[i].KeyData));
911 /* Key must be saved in adifferent way, depending on its type... */
912 if(KeysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
914 for(j = 0 ; j < new_key->len; j += 2)
916 s[0] = new_key->str[j];
917 s[1] = new_key->str[j+1];
919 KeyByte = (guint8)strtol(s, NULL, 16);
920 KeysCollection->Keys[i].KeyData[j / 2] = KeyByte;
923 /* XXX - Save the keys that are not WEP!!! */
927 * Free the old adapter key collection!
929 if(fake_if_info->keysCollection != NULL)
930 g_free(fake_if_info->keysCollection);
933 * Set this collection ad the new one
935 fake_if_info->keysCollection = KeysCollection;
936 fake_if_info->keysCollectionSize = KeysCollectionSize;
941 * This function will take the current keys (widget list), specified for the
942 * current adapter, and save them as default for ALL the others.
945 airpcap_read_and_save_decryption_keys_from_clist(GtkWidget* key_ls, airpcap_if_info_t* info_if, GList* if_list)
951 airpcap_if_info_t* curr_if = NULL;
952 airpcap_if_info_t* fake_info_if = NULL;
953 GList* key_list=NULL;
955 char* tmp_type = NULL;
956 char* tmp_key = NULL;
957 char* tmp_ssid = NULL;
959 decryption_key_t* tmp_dk=NULL;
962 * Save the keys for Wireshark...
965 /* Create a list of keys from the list widget... */
966 n = GTK_CLIST(key_ls)->rows;
968 for(i = 0; i < n; i++)
970 /* XXX - Create a decryption_key_t struct, and pass a list of those structs!!! */
971 gtk_clist_get_text(GTK_CLIST(key_ls),i,0,&tmp_type);
972 gtk_clist_get_text(GTK_CLIST(key_ls),i,1,&tmp_key);
973 gtk_clist_get_text(GTK_CLIST(key_ls),i,2,&tmp_ssid);
975 if(g_ascii_strcasecmp(tmp_type,AIRPCAP_WEP_KEY_STRING) == 0)
977 tmp_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
978 tmp_dk->key = g_string_new(tmp_key);
980 tmp_dk->type = AIRPDCAP_KEY_TYPE_WEP;
981 tmp_dk->bits = (guint) tmp_dk->key->len * 4;
982 key_list = g_list_append(key_list,tmp_dk);
984 else if(g_ascii_strcasecmp(tmp_type,AIRPCAP_WPA_PWD_KEY_STRING) == 0)
986 tmp_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
987 tmp_dk->key = g_string_new(tmp_key);
988 tmp_dk->ssid = g_byte_array_new();
989 uri_str_to_bytes(tmp_ssid, tmp_dk->ssid);
990 tmp_dk->type = AIRPDCAP_KEY_TYPE_WPA_PWD;
992 key_list = g_list_append(key_list,tmp_dk);
994 else if(g_ascii_strcasecmp(tmp_type,AIRPCAP_WPA_BIN_KEY_STRING) == 0)
996 tmp_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
997 tmp_dk->key = g_string_new(tmp_key);
998 tmp_dk->ssid = NULL; /* No SSID in this case */
999 tmp_dk->type = AIRPDCAP_KEY_TYPE_WPA_PMK;
1001 key_list = g_list_append(key_list,tmp_dk);
1005 r = save_wlan_wireshark_wep_keys(key_list);
1006 /* The key_list has been freed!!! */
1009 * Save the key list for driver.
1011 if( (if_list == NULL) || (info_if == NULL) ) return;
1013 fake_info_if = airpcap_driver_fake_if_info_new();
1015 airpcap_add_keys_to_driver_from_list(key_ls,fake_info_if);
1016 airpcap_save_driver_if_configuration(fake_info_if);
1017 airpcap_if_info_free(fake_info_if);
1019 if_n = g_list_length(if_list);
1021 /* For all the adapters in the list, empty the key list */
1022 for(i = 0; i < if_n; i++)
1024 curr_if = (airpcap_if_info_t*)g_list_nth_data(if_list,i);
1028 /* XXX - Set an empty collection */
1029 airpcap_if_clear_decryption_settings(curr_if);
1031 /* Save to registry */
1032 airpcap_save_selected_if_configuration(curr_if);
1038 * This function will load from the preferences file ALL the
1039 * keys (WEP, WPA and WPA_BIN) and will set them as default for
1040 * each adapter. To do this, it will save the keys in the registry...
1041 * A check will be performed, to make sure that keys found in
1042 * registry and keys found in Wireshark preferences are the same. If not,
1043 * the user will be asked to choose if use all keys (merge them),
1044 * or use Wireshark preferences ones. In the last case, registry keys will
1045 * be overwritten for all the connected AirPcap adapters.
1046 * In the first case, adapters will use their own keys, but those
1047 * keys will not be accessible via Wireshark...
1050 airpcap_check_decryption_keys(GList* if_list)
1054 gint n_adapters_keys = 0;
1055 gint n_driver_keys = 0;
1056 gint n_wireshark_keys = 0;
1057 airpcap_if_info_t* curr_if = NULL;
1059 GList* wireshark_key_list;
1060 GList* driver_key_list;
1061 GList* curr_adapter_key_list;
1063 gboolean equals = TRUE;
1064 gboolean adapters_keys_equals=TRUE;
1067 * If no AirPcap interface is found, return TRUE, so Wireshark
1068 * will use HIS OWN keys.
1073 if_n = g_list_length(if_list);
1075 /* Get Wireshark preferences keys */
1076 wireshark_key_list = get_wireshark_keys();
1077 n_wireshark_keys = g_list_length(wireshark_key_list);
1079 /* Retrieve AirPcap driver's keys */
1080 driver_key_list = get_airpcap_driver_keys();
1081 n_driver_keys = g_list_length(driver_key_list);
1083 equals &= key_lists_are_equal(wireshark_key_list,driver_key_list);
1085 for(i = 0; i < if_n; i++)
1087 curr_if = (airpcap_if_info_t*)g_list_nth_data(if_list,i);
1088 curr_adapter_key_list = get_airpcap_device_keys(curr_if);
1089 n_adapters_keys += g_list_length(curr_adapter_key_list);
1090 adapters_keys_equals &= key_lists_are_equal(wireshark_key_list,curr_adapter_key_list);
1093 if(n_adapters_keys != 0) /* If for some reason at least one specific key has been found */
1094 equals &= adapters_keys_equals; /* */
1096 if(n_driver_keys == 0) /* No keys set in any of the AirPcap adapters... */
1097 return TRUE; /* Use Wireshark keys and set them ad default for airpcap devices */
1103 * This function will load from the preferences file ALL the
1104 * keys (WEP, WPA_PWD and WPA_BIN) and will set them as default for
1105 * each adapter. To do this, it will save the keys in the registry...
1106 * A check will be performed, to make sure that keys found in
1107 * registry and keys found in Wireshark preferences are the same. If not,
1108 * the user will be asked to choose if use all keys (merge them),
1109 * or use Wireshark preferences ones. In the last case, registry keys will
1110 * be overwritten for all the connected AirPcap adapters.
1111 * In the first case, adapters will use their own keys, but those
1112 * keys will not be accessible via Wireshark...
1115 airpcap_load_decryption_keys(GList* if_list)
1119 airpcap_if_info_t* curr_if = NULL;
1121 if(if_list == NULL) return;
1123 if_n = g_list_length(if_list);
1125 for(i = 0; i < if_n; i++)
1127 curr_if = (airpcap_if_info_t*)g_list_nth_data(if_list,i);
1128 load_wlan_driver_wep_keys();
1133 * This function will set the gibven GList of decryption_key_t structures
1134 * as the defoult for both Wireshark and the AirPcap adapters...
1137 airpcap_save_decryption_keys(GList* key_list, GList* adapters_list)
1142 airpcap_if_info_t* curr_if = NULL;
1143 GList* empty_key_list = NULL;
1145 if( (key_list == NULL) || (adapters_list == NULL)) return;
1147 if_n = g_list_length(adapters_list);
1148 key_n = g_list_length(key_list);
1150 /* Set the driver's global list of keys. */
1151 write_wlan_driver_wep_keys_to_registry(key_list);
1153 /* Empty the key list for each interface */
1154 for(i = 0; i < if_n; i++)
1156 curr_if = (airpcap_if_info_t*)g_list_nth_data(adapters_list,i);
1157 write_wlan_wep_keys_to_registry(curr_if,empty_key_list);
1161 * This will set the keys of the current adapter as Wireshark default...
1162 * Now all the adapters have the same keys, so curr_if is ok as any other...
1164 save_wlan_wireshark_wep_keys(key_list);
1168 * This function is used to enable/disable the toolbar widgets
1169 * depending on the type of interface selected... Not the whole
1170 * toolbar must be grayed/enabled ... Only some widgets...
1173 airpcap_enable_toolbar_widgets(GtkWidget* w, gboolean en)
1175 GtkWidget *toolbar_tb,
1177 *toolbar_channel_cb,
1190 if_description_lb = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_INTERFACE_KEY);
1191 channel_lb = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_CHANNEL_LABEL_KEY);
1192 toolbar_channel_cb = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_CHANNEL_KEY);
1193 channel_offset_cb = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_CHANNEL_OFFSET_KEY);
1194 channel_offset_lb = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_CHANNEL_OFFSET_LABEL_KEY);
1195 fcs_lb = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_FCS_FILTER_LABEL_KEY);
1196 fcs_cb = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_FCS_FILTER_KEY);
1197 advanced_bt = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_ADVANCED_KEY);
1200 if(if_description_lb != NULL) gtk_widget_set_sensitive(if_description_lb,en);
1201 if(channel_lb != NULL) gtk_widget_set_sensitive(channel_lb,en);
1202 if(toolbar_channel_cb != NULL) gtk_widget_set_sensitive(toolbar_channel_cb,en);
1203 if(channel_offset_cb != NULL) gtk_widget_set_sensitive(channel_offset_cb,en);
1204 if(channel_offset_lb != NULL) gtk_widget_set_sensitive(channel_offset_lb,en);
1205 if(fcs_lb != NULL) gtk_widget_set_sensitive(fcs_lb,en);
1206 if(fcs_cb != NULL) gtk_widget_set_sensitive(fcs_cb,en);
1207 if(advanced_bt != NULL) gtk_widget_set_sensitive(advanced_bt,en);
1212 #endif /* HAVE_AIRPCAP */
1215 * Editor modelines - http://www.wireshark.org/tools/modelines.html
1220 * indent-tabs-mode: nil
1223 * vi: set shiftwidth=4 tabstop=4 expandtab
1224 * :indentSize=4:tabSize=4:noTabs=true: