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(GtkListStore *key_list_store, gchar* type, gchar* key, gchar* ssid)
257 gtk_list_store_insert_with_values(key_list_store , &iter, G_MAXINT,
265 * Fill the list with the keys. BEWARE! At this point, Wireshark and Drivers
266 * keys should be EQUALS! But is better to load keys from Wireshark, because
267 * the driver is not always present, and maybe that cannot support some keys
268 * (i.e. the WPA problem)
271 airpcap_fill_key_list(GtkListStore *key_list_store)
275 airpcap_if_info_t* fake_if_info;
276 GList* wireshark_key_list=NULL;
277 decryption_key_t* curr_key = NULL;
282 fake_if_info = airpcap_driver_fake_if_info_new();
284 /* We can retrieve the driver's key list (i.e. we have the right .dll)*/
285 wireshark_key_list = get_wireshark_keys();
286 n = g_list_length(wireshark_key_list);
288 for(i = 0; i < n; i++)
290 curr_key = (decryption_key_t*)g_list_nth_data(wireshark_key_list,i);
292 if(curr_key->type == AIRPDCAP_KEY_TYPE_WEP)
294 gtk_list_store_insert_with_values(key_list_store , &iter, G_MAXINT,
295 KL_COL_TYPE, AIRPCAP_WEP_KEY_STRING,
296 KL_COL_KEY, curr_key->key->str,
300 else if(curr_key->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
302 if(curr_key->ssid != NULL)
303 s = format_uri(curr_key->ssid, ":");
307 gtk_list_store_insert_with_values(key_list_store , &iter, G_MAXINT,
308 KL_COL_TYPE, AIRPCAP_WPA_PWD_KEY_STRING,
309 KL_COL_KEY, curr_key->key->str,
314 else if(curr_key->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
316 gtk_list_store_insert_with_values(key_list_store , &iter, G_MAXINT,
317 KL_COL_TYPE, AIRPCAP_WPA_BIN_KEY_STRING,
318 KL_COL_KEY, curr_key->key->str,
325 airpcap_if_info_free(fake_if_info);
330 * Function used to retrieve the AirpcapValidationType given the string name.
332 AirpcapValidationType
333 airpcap_get_validation_type(const gchar* name)
335 if(!(g_ascii_strcasecmp(AIRPCAP_VALIDATION_TYPE_NAME_ALL,name)))
337 return AIRPCAP_VT_ACCEPT_EVERYTHING;
339 else if(!(g_ascii_strcasecmp(AIRPCAP_VALIDATION_TYPE_NAME_CORRECT,name)))
341 return AIRPCAP_VT_ACCEPT_CORRECT_FRAMES;
343 else if(!(g_ascii_strcasecmp(AIRPCAP_VALIDATION_TYPE_NAME_CORRUPT,name)))
345 return AIRPCAP_VT_ACCEPT_CORRUPT_FRAMES;
347 return AIRPCAP_VT_UNKNOWN;
351 * Function used to retrieve the string name given an AirpcapValidationType,
352 * or NULL in case of error
355 airpcap_get_validation_name(AirpcapValidationType vt)
357 if(vt == AIRPCAP_VT_ACCEPT_EVERYTHING)
359 return AIRPCAP_VALIDATION_TYPE_NAME_ALL;
361 else if(vt == AIRPCAP_VT_ACCEPT_CORRECT_FRAMES)
363 return AIRPCAP_VALIDATION_TYPE_NAME_CORRECT;
365 else if(vt == AIRPCAP_VT_ACCEPT_CORRUPT_FRAMES)
367 return AIRPCAP_VALIDATION_TYPE_NAME_CORRUPT;
369 else if(vt == AIRPCAP_VT_UNKNOWN)
371 return AIRPCAP_VALIDATION_TYPE_NAME_UNKNOWN;
377 * Return an appropriate combo box entry number for the given an AirpcapValidationType,
381 airpcap_get_validation_combo_entry(AirpcapValidationType vt)
384 case AIRPCAP_VT_ACCEPT_CORRECT_FRAMES:
387 case AIRPCAP_VT_ACCEPT_CORRUPT_FRAMES:
397 * Returns the AirpcapLinkType corresponding to the given string name.
400 airpcap_get_link_type(const gchar* name)
402 if(!(g_ascii_strcasecmp(AIRPCAP_LINK_TYPE_NAME_802_11_ONLY,name))){
403 return AIRPCAP_LT_802_11;
404 }else if(!(g_ascii_strcasecmp(AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_RADIO,name))){
405 return AIRPCAP_LT_802_11_PLUS_RADIO;
406 }else if(!(g_ascii_strcasecmp(AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_PPI,name))){
407 return AIRPCAP_LT_802_11_PLUS_PPI;
409 return AIRPCAP_LT_UNKNOWN;
414 * Returns the string name corresponding to the given AirpcapLinkType, or
415 * NULL in case of error.
418 airpcap_get_link_name(AirpcapLinkType lt)
420 if(lt == AIRPCAP_LT_802_11){
421 return AIRPCAP_LINK_TYPE_NAME_802_11_ONLY;
422 }else if(lt == AIRPCAP_LT_802_11_PLUS_RADIO){
423 return AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_RADIO;
424 }else if(lt == AIRPCAP_LT_802_11_PLUS_PPI){
425 return AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_PPI;
426 }else if(lt == AIRPCAP_LT_UNKNOWN){
427 return AIRPCAP_LINK_TYPE_NAME_UNKNOWN;
433 * Sets the entry of the validation combo using the AirpcapValidationType.
436 airpcap_validation_type_combo_set_by_type(GtkWidget* c, AirpcapValidationType type)
438 gtk_combo_box_set_active(GTK_COMBO_BOX(c), airpcap_get_validation_combo_entry(type));
442 * Returns the string corresponding to the given guint (1-14, for channel only)
445 airpcap_get_channel_name(guint n)
447 return g_strdup_printf("%d",n);
452 * Set the combo box entry string given a channel frequency
455 airpcap_channel_combo_set_by_frequency(GtkWidget* cb, guint chan_freq)
459 for (i = 0; i < airpcap_if_selected->numSupportedChannels; i++) {
460 if (airpcap_if_selected->pSupportedChannels[i].Frequency == chan_freq) {
461 gtk_combo_box_set_active(GTK_COMBO_BOX(cb), i);
468 * Change channel of Airpcap Adapter
471 airpcap_update_frequency_and_offset(airpcap_if_info_t* if_info)
473 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
475 gboolean return_value = FALSE;
477 if (if_info != NULL){
478 ad = airpcap_if_open(if_info->name, ebuf);
481 return_value = airpcap_if_set_device_channel_ex(ad,if_info->channelInfo);
482 airpcap_if_close(ad);
490 * Changed callback for the channel combobox - common routine
493 airpcap_channel_changed_common(GtkWidget *channel_cb, gpointer channel_offset_cb, gboolean set)
497 if (channel_cb && channel_offset_cb && change_airpcap_settings && airpcap_if_active) {
498 cur_chan_idx = gtk_combo_box_get_active(GTK_COMBO_BOX(channel_cb));
499 if (cur_chan_idx >= 0 && cur_chan_idx < (gint) airpcap_if_active->numSupportedChannels) {
501 airpcap_if_active->channelInfo.Frequency = airpcap_if_active->pSupportedChannels[cur_chan_idx].Frequency;
503 airpcap_update_channel_offset_combo(airpcap_if_active,
504 airpcap_if_active->channelInfo.Frequency,
505 GTK_WIDGET(channel_offset_cb), set);
511 * Changed callback for the channel combobox - set channel and offset
514 airpcap_channel_changed_set_cb(GtkWidget *channel_cb, gpointer channel_offset_cb)
516 airpcap_channel_changed_common(channel_cb, channel_offset_cb, TRUE);
520 * Changed callback for the channel combobox - don't set channel and offset
523 airpcap_channel_changed_noset_cb(GtkWidget *channel_cb, gpointer channel_offset_cb)
525 airpcap_channel_changed_common(channel_cb, channel_offset_cb, FALSE);
529 airpcap_get_selected_channel_offset(GtkWidget *channel_offset_cb) {
535 if (channel_offset_cb == NULL || !GTK_WIDGET_SENSITIVE(channel_offset_cb)) {
539 off_str = gtk_combo_box_get_active_text(GTK_COMBO_BOX(channel_offset_cb));
540 if (off_str && (g_ascii_strcasecmp("", off_str)))
542 if (airpcap_if_selected != NULL)
544 sscanf(off_str, "%d", &offset);
545 if (offset >= -1 && offset <= 1) {
555 * Changed callback for the channel offset combobox
558 airpcap_channel_offset_changed_cb(GtkWidget *channel_offset_cb, gpointer data _U_)
560 airpcap_if_selected->channelInfo.ExtChannel = airpcap_get_selected_channel_offset(channel_offset_cb);
561 airpcap_if_selected->saved = FALSE;
562 change_airpcap_settings = TRUE;
563 if (!airpcap_update_frequency_and_offset(airpcap_if_selected)){
564 simple_dialog(ESD_TYPE_ERROR,ESD_BTN_OK,
565 "Unable to set extension channel %d",
566 airpcap_if_selected->channelInfo.ExtChannel);
572 * Update the channel offset of the given combobox according to the given frequency.
575 airpcap_update_channel_offset_combo(airpcap_if_info_t* if_info, guint chan_freq, GtkWidget *channel_offset_cb, gboolean set)
583 if (!if_info || airpcap_if_is_any(if_info) || if_info->pSupportedChannels == NULL || if_info->numSupportedChannels < 1) {
584 gtk_widget_set_sensitive(GTK_WIDGET(channel_offset_cb),FALSE);
585 gtk_combo_box_set_active(GTK_COMBO_BOX(channel_offset_cb), -1);
589 new_offset = current_offset = if_info->channelInfo.ExtChannel;
591 /* Clear out the list */
592 while (gtk_tree_model_iter_n_children(gtk_combo_box_get_model(GTK_COMBO_BOX(channel_offset_cb)), NULL) > 0) {
593 gtk_combo_box_remove_text(GTK_COMBO_BOX(channel_offset_cb), 0);
596 gtk_widget_set_sensitive(GTK_WIDGET(channel_offset_cb), TRUE);
598 for (i = 0; i < if_info->numSupportedChannels; i++) {
599 if (if_info->pSupportedChannels[i].Frequency == chan_freq) {
601 /* If we can't be low or high, nudge the offset to 0 */
602 if (current_offset == -1 && !(if_info->pSupportedChannels[i].Flags & FLAG_CAN_BE_LOW)) {
604 } else if (current_offset == 1 && !(if_info->pSupportedChannels[i].Flags & FLAG_CAN_BE_HIGH)) {
608 if ((if_info->pSupportedChannels[i].Flags & FLAG_CAN_BE_LOW)) {
609 gtk_combo_box_append_text(GTK_COMBO_BOX(channel_offset_cb), "-1");
611 if (new_offset == -1) {
612 active_idx = idx_count;
615 gtk_combo_box_append_text(GTK_COMBO_BOX(channel_offset_cb), "0");
617 if (new_offset == 0) {
618 active_idx = idx_count;
620 if ((if_info->pSupportedChannels[i].Flags & FLAG_CAN_BE_HIGH)){
621 gtk_combo_box_append_text(GTK_COMBO_BOX(channel_offset_cb), "+1");
623 if (new_offset == 1) {
624 active_idx = idx_count;
631 gtk_combo_box_set_active(GTK_COMBO_BOX(channel_offset_cb), active_idx);
635 change_airpcap_settings = TRUE;
637 if_info->channelInfo.ExtChannel = new_offset;
638 if (!airpcap_update_frequency_and_offset(if_info)){
639 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);
644 gtk_widget_set_sensitive(channel_offset_cb, FALSE);
649 * Returns '1' if this is the "Any" adapter, '0' otherwise
652 airpcap_if_is_any(airpcap_if_info_t* if_info)
654 if(g_ascii_strcasecmp(if_info->name,AIRPCAP_DEVICE_ANY_EXTRACT_STRING)==0)
661 * Update channel combo box. If the airpcap interface is "Any", the combo box will be disabled.
664 airpcap_update_channel_combo(GtkWidget* channel_cb, airpcap_if_info_t* if_info)
666 if(!if_info || airpcap_if_is_any(if_info) || !airpcap_if_selected)
668 gtk_combo_box_set_active(GTK_COMBO_BOX(channel_cb), -1);
669 change_airpcap_settings = FALSE;
670 gtk_widget_set_sensitive(GTK_WIDGET(channel_cb),FALSE);
674 while (gtk_tree_model_iter_n_children(gtk_combo_box_get_model(GTK_COMBO_BOX(channel_cb)), NULL) > 0) {
675 gtk_combo_box_remove_text(GTK_COMBO_BOX(channel_cb), 0);
678 if (if_info != NULL && if_info->pSupportedChannels != NULL && if_info->numSupportedChannels > 0){
680 for (i = 0; i<(if_info->numSupportedChannels); i++){
681 gtk_combo_box_append_text(GTK_COMBO_BOX(channel_cb), ieee80211_mhz_to_str(airpcap_if_selected->pSupportedChannels[i].Frequency));
685 airpcap_channel_combo_set_by_frequency(channel_cb, if_info->channelInfo.Frequency);
686 change_airpcap_settings = TRUE;
687 gtk_widget_set_sensitive(GTK_WIDGET(channel_cb), TRUE);
692 * Takes the keys from the GtkList widget, and add them to the interface list
695 airpcap_add_keys_to_driver_from_list(GtkListStore *key_list_store, airpcap_if_info_t *fake_if_info)
699 GtkTreeModel *model = GTK_TREE_MODEL(key_list_store);
704 PAirpcapKeysCollection KeysCollection;
705 guint KeysCollectionSize;
708 guint keys_in_list = 0;
710 gchar *row_type, *row_key; /* SSID not needed for AirPcap */
713 if(fake_if_info == NULL)
716 keys_in_list = gtk_tree_model_iter_n_children(model, NULL);
719 * Save the encryption keys, if we have any of them
721 KeysCollectionSize = 0;
724 * Calculate the size of the keys collection
726 KeysCollectionSize = sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey);
729 * Allocate the collection
731 KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize);
734 * Populate the key collection
736 KeysCollection->nKeys = keys_in_list;
738 for(i = 0; i < keys_in_list; i++)
740 path = gtk_tree_path_new_from_indices(i, -1);
741 gtk_tree_model_get_iter(model, &iter, path);
742 gtk_tree_path_free(path);
743 gtk_tree_model_get(model, &iter,
744 KL_COL_TYPE, &row_type,
745 KL_COL_KEY, &row_key,
748 if(g_ascii_strcasecmp(row_type,AIRPCAP_WEP_KEY_STRING) == 0)
749 KeysCollection->Keys[i].KeyType = AIRPDCAP_KEY_TYPE_WEP;
750 else if(g_ascii_strcasecmp(row_type,AIRPCAP_WPA_PWD_KEY_STRING) == 0)
751 KeysCollection->Keys[i].KeyType = AIRPDCAP_KEY_TYPE_WPA_PWD;
752 else if(g_ascii_strcasecmp(row_type,AIRPCAP_WPA_BIN_KEY_STRING) == 0)
753 KeysCollection->Keys[i].KeyType = AIRPDCAP_KEY_TYPE_WPA_PMK;
755 /* Retrieve the Item corresponding to the i-th key */
756 key_len = strlen(row_key);
758 KeysCollection->Keys[i].KeyLen = (guint) key_len / 2;
759 memset(&KeysCollection->Keys[i].KeyData, 0, sizeof(KeysCollection->Keys[i].KeyData));
761 /* Key must be saved in adifferent way, depending on its type... */
762 if(KeysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
764 for(j = 0 ; j < key_len; j += 2)
769 KeyByte = (guint8)strtol(s, NULL, 16);
770 KeysCollection->Keys[i].KeyData[j / 2] = KeyByte;
778 * Free the old adapter key collection!
780 if(fake_if_info->keysCollection != NULL)
781 g_free(fake_if_info->keysCollection);
784 * Set this collection ad the new one
786 fake_if_info->keysCollection = KeysCollection;
787 fake_if_info->keysCollectionSize = KeysCollectionSize;
792 * This function will take the current keys (widget list), specified for the
793 * current adapter, and save them as default for ALL the others.
796 airpcap_read_and_save_decryption_keys_from_list_store(GtkListStore* key_list_store, airpcap_if_info_t* info_if, GList* if_list)
799 GtkTreeModel *model = GTK_TREE_MODEL(key_list_store);
804 airpcap_if_info_t* curr_if = NULL;
805 airpcap_if_info_t* fake_info_if = NULL;
806 GList* key_list=NULL;
808 char* tmp_type = NULL;
809 char* tmp_key = NULL;
812 decryption_key_t* tmp_dk=NULL;
815 * Save the keys for Wireshark...
818 /* Create a list of keys from the list store */
819 for (items_left = gtk_tree_model_get_iter_first (model, &iter);
821 items_left = gtk_tree_model_iter_next (model, &iter)) {
823 gtk_tree_model_get(model, &iter,
824 KL_COL_TYPE, &tmp_type,
825 KL_COL_KEY, &tmp_key,
826 KL_COL_SSID, &tmp_ssid,
829 if(g_ascii_strcasecmp(tmp_type, AIRPCAP_WEP_KEY_STRING) == 0)
831 tmp_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
832 tmp_dk->key = g_string_new(tmp_key);
834 tmp_dk->type = AIRPDCAP_KEY_TYPE_WEP;
835 tmp_dk->bits = (guint) tmp_dk->key->len * 4;
836 key_list = g_list_append(key_list,tmp_dk);
838 else if(g_ascii_strcasecmp(tmp_type, AIRPCAP_WPA_PWD_KEY_STRING) == 0)
840 tmp_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
841 tmp_dk->key = g_string_new(tmp_key);
842 tmp_dk->ssid = g_byte_array_new();
843 uri_str_to_bytes(tmp_ssid, tmp_dk->ssid);
844 tmp_dk->type = AIRPDCAP_KEY_TYPE_WPA_PWD;
846 key_list = g_list_append(key_list,tmp_dk);
848 else if(g_ascii_strcasecmp(tmp_type, AIRPCAP_WPA_BIN_KEY_STRING) == 0)
850 tmp_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
851 tmp_dk->key = g_string_new(tmp_key);
852 tmp_dk->ssid = NULL; /* No SSID in this case */
853 tmp_dk->type = AIRPDCAP_KEY_TYPE_WPA_PMK;
855 key_list = g_list_append(key_list,tmp_dk);
861 r = save_wlan_wireshark_wep_keys(key_list);
862 /* The key_list has been freed!!! */
865 * Save the key list for driver.
867 if( (if_list == NULL) || (info_if == NULL) ) return;
869 fake_info_if = airpcap_driver_fake_if_info_new();
871 airpcap_add_keys_to_driver_from_list(key_list_store,fake_info_if);
872 airpcap_save_driver_if_configuration(fake_info_if);
873 airpcap_if_info_free(fake_info_if);
875 if_n = g_list_length(if_list);
877 /* For all the adapters in the list, empty the key list */
878 for(i = 0; i < if_n; i++)
880 curr_if = (airpcap_if_info_t*)g_list_nth_data(if_list,i);
884 /* XXX - Set an empty collection */
885 airpcap_if_clear_decryption_settings(curr_if);
887 /* Save to registry */
888 airpcap_save_selected_if_configuration(curr_if);
894 * This function will load from the preferences file ALL the
895 * keys (WEP, WPA and WPA_BIN) and will set them as default for
896 * each adapter. To do this, it will save the keys in the registry...
897 * A check will be performed, to make sure that keys found in
898 * registry and keys found in Wireshark preferences are the same. If not,
899 * the user will be asked to choose if use all keys (merge them),
900 * or use Wireshark preferences ones. In the last case, registry keys will
901 * be overwritten for all the connected AirPcap adapters.
902 * In the first case, adapters will use their own keys, but those
903 * keys will not be accessible via Wireshark...
906 airpcap_check_decryption_keys(GList* if_list)
910 gint n_adapters_keys = 0;
911 gint n_driver_keys = 0;
912 gint n_wireshark_keys = 0;
913 airpcap_if_info_t* curr_if = NULL;
915 GList* wireshark_key_list;
916 GList* driver_key_list;
917 GList* curr_adapter_key_list;
919 gboolean equals = TRUE;
920 gboolean adapters_keys_equals=TRUE;
923 * If no AirPcap interface is found, return TRUE, so Wireshark
924 * will use HIS OWN keys.
929 if_n = g_list_length(if_list);
931 /* Get Wireshark preferences keys */
932 wireshark_key_list = get_wireshark_keys();
933 n_wireshark_keys = g_list_length(wireshark_key_list);
935 /* Retrieve AirPcap driver's keys */
936 driver_key_list = get_airpcap_driver_keys();
937 n_driver_keys = g_list_length(driver_key_list);
939 equals &= key_lists_are_equal(wireshark_key_list,driver_key_list);
941 for(i = 0; i < if_n; i++)
943 curr_if = (airpcap_if_info_t*)g_list_nth_data(if_list,i);
944 curr_adapter_key_list = get_airpcap_device_keys(curr_if);
945 n_adapters_keys += g_list_length(curr_adapter_key_list);
946 adapters_keys_equals &= key_lists_are_equal(wireshark_key_list,curr_adapter_key_list);
949 if(n_adapters_keys != 0) /* If for some reason at least one specific key has been found */
950 equals &= adapters_keys_equals; /* */
952 if(n_driver_keys == 0) /* No keys set in any of the AirPcap adapters... */
953 return TRUE; /* Use Wireshark keys and set them ad default for airpcap devices */
959 * This function will load from the preferences file ALL the
960 * keys (WEP, WPA_PWD and WPA_BIN) and will set them as default for
961 * each adapter. To do this, it will save the keys in the registry...
962 * A check will be performed, to make sure that keys found in
963 * registry and keys found in Wireshark preferences are the same. If not,
964 * the user will be asked to choose if use all keys (merge them),
965 * or use Wireshark preferences ones. In the last case, registry keys will
966 * be overwritten for all the connected AirPcap adapters.
967 * In the first case, adapters will use their own keys, but those
968 * keys will not be accessible via Wireshark...
971 airpcap_load_decryption_keys(GList* if_list)
975 airpcap_if_info_t* curr_if = NULL;
977 if(if_list == NULL) return;
979 if_n = g_list_length(if_list);
981 for(i = 0; i < if_n; i++)
983 curr_if = (airpcap_if_info_t*)g_list_nth_data(if_list,i);
984 load_wlan_driver_wep_keys();
989 * This function will set the gibven GList of decryption_key_t structures
990 * as the defoult for both Wireshark and the AirPcap adapters...
993 airpcap_save_decryption_keys(GList* key_list, GList* adapters_list)
998 airpcap_if_info_t* curr_if = NULL;
999 GList* empty_key_list = NULL;
1001 if( (key_list == NULL) || (adapters_list == NULL)) return;
1003 if_n = g_list_length(adapters_list);
1004 key_n = g_list_length(key_list);
1006 /* Set the driver's global list of keys. */
1007 write_wlan_driver_wep_keys_to_registry(key_list);
1009 /* Empty the key list for each interface */
1010 for(i = 0; i < if_n; i++)
1012 curr_if = (airpcap_if_info_t*)g_list_nth_data(adapters_list,i);
1013 write_wlan_wep_keys_to_registry(curr_if,empty_key_list);
1017 * This will set the keys of the current adapter as Wireshark default...
1018 * Now all the adapters have the same keys, so curr_if is ok as any other...
1020 save_wlan_wireshark_wep_keys(key_list);
1024 * This function is used to enable/disable the toolbar widgets
1025 * depending on the type of interface selected... Not the whole
1026 * toolbar must be grayed/enabled ... Only some widgets...
1029 airpcap_enable_toolbar_widgets(GtkWidget* w, gboolean en)
1031 GtkWidget *toolbar_tb,
1033 *toolbar_channel_cb,
1046 if_description_lb = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_INTERFACE_KEY);
1047 channel_lb = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_CHANNEL_LABEL_KEY);
1048 toolbar_channel_cb = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_CHANNEL_KEY);
1049 channel_offset_cb = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_CHANNEL_OFFSET_KEY);
1050 channel_offset_lb = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_CHANNEL_OFFSET_LABEL_KEY);
1051 fcs_lb = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_FCS_FILTER_LABEL_KEY);
1052 fcs_cb = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_FCS_FILTER_KEY);
1053 advanced_bt = g_object_get_data(G_OBJECT(toolbar_tb),AIRPCAP_TOOLBAR_ADVANCED_KEY);
1056 if(if_description_lb != NULL)
1057 gtk_widget_set_sensitive(if_description_lb,en);
1058 if(channel_lb != NULL)
1059 gtk_widget_set_sensitive(channel_lb,en);
1060 if(toolbar_channel_cb != NULL)
1061 gtk_widget_set_sensitive(toolbar_channel_cb,en);
1062 if(channel_offset_cb != NULL)
1063 gtk_widget_set_sensitive(channel_offset_cb,en);
1064 if(channel_offset_lb != NULL)
1065 gtk_widget_set_sensitive(channel_offset_lb,en);
1067 gtk_widget_set_sensitive(fcs_lb,en);
1069 gtk_widget_set_sensitive(fcs_cb,en);
1070 if(advanced_bt != NULL)
1071 gtk_widget_set_sensitive(advanced_bt,en);
1076 #endif /* HAVE_AIRPCAP */
1079 * Editor modelines - http://www.wireshark.org/tools/modelines.html
1084 * indent-tabs-mode: nil
1087 * vi: set shiftwidth=4 tabstop=4 expandtab
1088 * :indentSize=4:tabSize=4:noTabs=true: