summaryrefslogtreecommitdiffstats
path: root/ui/qt/bluetooth_device_dialog.cpp
blob: 6e679b8a81ad6341fd56385512c166078cd509bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
/* bluetooth_device_dialog.cpp
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "bluetooth_device_dialog.h"
#include <ui_bluetooth_device_dialog.h>

#include <ui/qt/utils/color_utils.h>

#include "epan/epan.h"
#include "epan/addr_resolv.h"
#include "epan/to_str.h"
#include "epan/epan_dissect.h"
#include "epan/prefs.h"
#include "epan/dissectors/packet-bthci_cmd.h"
#include "epan/dissectors/packet-bthci_evt.h"

#include "ui/simple_dialog.h"

#include <ui/qt/utils/variant_pointer.h>
#include "ui/qt/widgets/wireshark_file_dialog.h"

#include <QClipboard>
#include <QContextMenuEvent>
#include <QPushButton>
#include <QTreeWidget>

static const int column_number_value = 0;
static const int column_number_changes = 1;

static const int row_number_bd_addr = 0;
static const int row_number_bd_addr_oui = 1;
static const int row_number_name = 2;
static const int row_number_class_of_device = 3;
static const int row_number_lmp_version = 4;
static const int row_number_lmp_subversion = 5;
static const int row_number_manufacturer = 6;
static const int row_number_hci_version = 7;
static const int row_number_hci_revision = 8;
static const int row_number_scan = 9;
static const int row_number_authentication = 10;
static const int row_number_encryption = 11;
static const int row_number_acl_mtu = 12;
static const int row_number_acl_packets = 13;
static const int row_number_sco_mtu = 14;
static const int row_number_sco_packets = 15;
static const int row_number_le_acl_mtu = 16;
static const int row_number_le_acl_packets = 17;
static const int row_number_le_iso_mtu = 18;
static const int row_number_le_iso_packets = 19;
static const int row_number_inquiry_mode = 20;
static const int row_number_page_timeout = 21;
static const int row_number_simple_pairing_mode = 22;
static const int row_number_voice_setting = 23;

static tap_packet_status
bluetooth_device_tap_packet(void *tapinfo_ptr, packet_info *pinfo, epan_dissect_t *edt, const void* data, tap_flags_t flags)
{
    bluetooth_device_tapinfo_t *tapinfo = (bluetooth_device_tapinfo_t *) tapinfo_ptr;

    if (tapinfo->tap_packet)
        tapinfo->tap_packet(tapinfo, pinfo, edt, data, flags);

    return TAP_PACKET_REDRAW;
}

static void
bluetooth_device_tap_reset(void *tapinfo_ptr)
{
    bluetooth_device_tapinfo_t *tapinfo = (bluetooth_device_tapinfo_t *) tapinfo_ptr;

    if (tapinfo->tap_reset)
        tapinfo->tap_reset(tapinfo);
}


static void
bluetooth_devices_tap(void *data)
{
    GString *error_string;

    error_string = register_tap_listener("bluetooth.device", data, NULL,
            0,
            bluetooth_device_tap_reset,
            bluetooth_device_tap_packet,
            NULL,
            NULL
            );

    if (error_string != NULL) {
        simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                "%s", error_string->str);
        g_string_free(error_string, TRUE);
    }
}


BluetoothDeviceDialog::BluetoothDeviceDialog(QWidget &parent, CaptureFile &cf, QString bdAddr, QString name, guint32 interface_id, guint32 adapter_id, gboolean is_local) :
    WiresharkDialog(parent, cf),
    ui(new Ui::BluetoothDeviceDialog)
{
    ui->setupUi(this);
    resize(parent.width() * 4 / 10, parent.height() * 2 / 2);

    setTitle(bdAddr, name);

    connect(ui->tableWidget, &QTableWidget::customContextMenuRequested, this, &BluetoothDeviceDialog::tableContextMenu);

    ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);

    ui->tableWidget->setStyleSheet("QTableView::item:hover{background-color:lightyellow; color:black;}");

    context_menu_.addActions(QList<QAction *>() << ui->actionMark_Unmark_Cell);
    context_menu_.addActions(QList<QAction *>() << ui->actionMark_Unmark_Row);
    context_menu_.addActions(QList<QAction *>() << ui->actionCopy_Cell);
    context_menu_.addActions(QList<QAction *>() << ui->actionCopy_Rows);
    context_menu_.addActions(QList<QAction *>() << ui->actionCopy_All);
    context_menu_.addActions(QList<QAction *>() << ui->actionSave_as_image);

    changes_ = 0;

    tapinfo_.tap_packet   = tapPacket;
    tapinfo_.tap_reset    = tapReset;
    tapinfo_.ui           = this;
    tapinfo_.is_local     = is_local;
    tapinfo_.bdAddr       = bdAddr;
    tapinfo_.interface_id = interface_id;
    tapinfo_.adapter_id   = adapter_id;
    tapinfo_.changes      = &changes_;

    ui->hintLabel->setText(ui->hintLabel->text().arg(changes_));

    for (int i_row = 0; i_row < ui->tableWidget->rowCount(); i_row += 1) {
        for (int i_column = 0; i_column < ui->tableWidget->columnCount(); i_column += 1) {
            QTableWidgetItem *item = new QTableWidgetItem();
            ui->tableWidget->setItem(i_row, i_column, item);
        }
    }

    bluetooth_devices_tap(&tapinfo_);

    cap_file_.retapPackets();
}


BluetoothDeviceDialog::~BluetoothDeviceDialog()
{
    delete ui;

    remove_tap_listener(&tapinfo_);
}

void BluetoothDeviceDialog::setTitle(QString bdAddr, QString name)
{
    QString titleBdAddr;
    QString titleName;

    if (bdAddr.isEmpty())
        titleBdAddr = QString(tr("Unknown"));
    else
        titleBdAddr = bdAddr;

    if (name.isEmpty())
        titleName = "";
    else
        titleName = " ("+name+")";

    setWindowTitle(tr("Bluetooth Device - %1%2").arg(titleBdAddr).arg(titleName));
}

void BluetoothDeviceDialog::captureFileClosing()
{
    remove_tap_listener(&tapinfo_);

    WiresharkDialog::captureFileClosing();
}


void BluetoothDeviceDialog::changeEvent(QEvent *event)
{
    if (0 != event)
    {
        switch (event->type())
        {
        case QEvent::LanguageChange:
            ui->retranslateUi(this);
            break;
        default:
            break;
        }
    }
    QDialog::changeEvent(event);
}


void BluetoothDeviceDialog::keyPressEvent(QKeyEvent *event)
{
/* NOTE: Do nothing*, but in real it "takes focus" from button_box so allow user
 * to use Enter button to jump to frame from tree widget */
/* * - reimplement shortcuts from contex menu */

   if (event->modifiers() & Qt::ControlModifier && event->key()== Qt::Key_M)
        on_actionMark_Unmark_Row_triggered();
}

void BluetoothDeviceDialog::on_actionMark_Unmark_Cell_triggered()
{
    QTableWidgetItem *current_item = ui->tableWidget->currentItem();
    if (!current_item)
        return;

    QBrush fg;
    QBrush bg;

    if (current_item->background() == QBrush(ColorUtils::fromColorT(&prefs.gui_marked_bg))) {
        fg = QBrush();
        bg = QBrush();
    } else {
        fg = QBrush(ColorUtils::fromColorT(&prefs.gui_marked_fg));
        bg = QBrush(ColorUtils::fromColorT(&prefs.gui_marked_bg));
    }

    current_item->setForeground(fg);
    current_item->setBackground(bg);
}


void BluetoothDeviceDialog::on_actionMark_Unmark_Row_triggered()
{
    QBrush fg;
    QBrush bg;
    bool   is_marked = TRUE;

    QTableWidgetItem *current_item = ui->tableWidget->currentItem();
    if (!current_item)
        return;

    for (int i = 0; i < ui->tableWidget->columnCount(); i += 1) {
        QTableWidgetItem *item = ui->tableWidget->item(current_item->row(), i);
        if (item->background() != QBrush(ColorUtils::fromColorT(&prefs.gui_marked_bg)))
            is_marked = FALSE;
    }

    if (is_marked) {
        fg = QBrush();
        bg = QBrush();
    } else {
        fg = QBrush(ColorUtils::fromColorT(&prefs.gui_marked_fg));
        bg = QBrush(ColorUtils::fromColorT(&prefs.gui_marked_bg));
    }

    for (int i = 0; i < ui->tableWidget->columnCount(); i += 1) {
        QTableWidgetItem *item = ui->tableWidget->item(current_item->row(), i);
        item->setForeground(fg);
        item->setBackground(bg);
    }
}


void BluetoothDeviceDialog::tableContextMenu(const QPoint &pos)
{
    context_menu_.popup(ui->tableWidget->viewport()->mapToGlobal(pos));
}

void BluetoothDeviceDialog::on_actionCopy_Cell_triggered()
{
    QTableWidgetItem *current_item = ui->tableWidget->currentItem();
    if (!current_item)
        return;

    QClipboard *clipboard = QApplication::clipboard();
    QString     copy;

    copy = QString(current_item->text());

    clipboard->setText(copy);
}

void BluetoothDeviceDialog::on_actionCopy_Rows_triggered()
{
    QClipboard                         *clipboard = QApplication::clipboard();
    QString                             copy;
    QList<QTableWidgetItem *>           items;
    QList<QTableWidgetItem *>::iterator i_item;

    items =  ui->tableWidget->selectedItems();

    for (i_item = items.begin(); i_item != items.end(); ++i_item) {
        copy += QString("%1  %2  %3\n")
                .arg(ui->tableWidget->verticalHeaderItem((*i_item)->row())->text(), -40)
                .arg(ui->tableWidget->item((*i_item)->row(), column_number_value)->text(), -50)
                .arg(ui->tableWidget->item((*i_item)->row(), column_number_changes)->text(), -10);
    }

    clipboard->setText(copy);
}

void BluetoothDeviceDialog::on_actionCopy_All_triggered()
{
    QClipboard             *clipboard = QApplication::clipboard();
    QString                 copy;

    copy += QString("%1  %2  %3\n")
            .arg("Headers", -40)
            .arg(ui->tableWidget->horizontalHeaderItem(column_number_value)->text(), -50)
            .arg(ui->tableWidget->horizontalHeaderItem(column_number_changes)->text(), -10);

    for (int i_row = 0; i_row < ui->tableWidget->rowCount(); i_row += 1) {
        for (int i_column = 0; i_column < ui->tableWidget->columnCount(); i_column += 1) {

        copy += QString("%1  %2  %3\n")
                .arg(ui->tableWidget->verticalHeaderItem(i_row)->text(), -40)
                .arg(ui->tableWidget->item(i_row, column_number_value)->text(), -50)
                .arg(ui->tableWidget->item(i_row, column_number_changes)->text(), -10);
        }
    }

    clipboard->setText(copy);
}



void BluetoothDeviceDialog::tapReset(void *tapinfo_ptr)
{
    bluetooth_device_tapinfo_t *tapinfo = (bluetooth_device_tapinfo_t *) tapinfo_ptr;
    BluetoothDeviceDialog  *dialog = static_cast<BluetoothDeviceDialog *>(tapinfo->ui);

    for (int i_row = 0; i_row < dialog->ui->tableWidget->rowCount(); i_row += 1) {
        for (int i_column = 0; i_column < dialog->ui->tableWidget->columnCount(); i_column += 1) {
            QTableWidgetItem *item = new QTableWidgetItem();
            dialog->ui->tableWidget->setItem(i_row, i_column, item);
        }
    }
    *tapinfo->changes = 0;
}

void BluetoothDeviceDialog::updateChanges(QTableWidget *tableWidget, QString value, const int row, guint *changes, packet_info *pinfo)
{
    QTableWidgetItem *item = tableWidget->item(row, column_number_value);
    bluetooth_item_data_t *item_data = VariantPointer<bluetooth_item_data_t>::asPtr(item->data(Qt::UserRole));

    if (item->text() == value)
        return;

    if (item_data->changes == -1) {
        item_data->changes = 0;
    } else {
        *changes += 1;
        item_data->changes += 1;
        item_data->frame_number = pinfo->fd->num;
        tableWidget->item(row, column_number_changes)->setText(QString::number(item_data->changes));
    }
}

void BluetoothDeviceDialog::saveItemData(QTableWidgetItem *item,
        bluetooth_device_tap_t *tap_device, packet_info *pinfo)
{
    if (item->data(Qt::UserRole).isValid())
        return;

    bluetooth_item_data_t *item_data = wmem_new(wmem_file_scope(), bluetooth_item_data_t);
    item_data->interface_id = tap_device->interface_id;
    item_data->adapter_id = tap_device->adapter_id;
    item_data->changes = -1;
    item_data->frame_number = pinfo->fd->num;
    item->setData(Qt::UserRole, VariantPointer<bluetooth_item_data_t>::asQVariant(item_data));

}

tap_packet_status BluetoothDeviceDialog::tapPacket(void *tapinfo_ptr, packet_info *pinfo, epan_dissect_t *, const void *data, tap_flags_t)
{
    bluetooth_device_tapinfo_t   *tapinfo    = static_cast<bluetooth_device_tapinfo_t *>(tapinfo_ptr);
    BluetoothDeviceDialog        *dialog     = static_cast<BluetoothDeviceDialog *>(tapinfo->ui);
    bluetooth_device_tap_t       *tap_device = static_cast<bluetooth_device_tap_t *>(const_cast<void *>(data));
    QString                       bd_addr;
    QString                       bd_addr_oui;
    const gchar                  *manuf;
    QTableWidget                 *tableWidget;
    QTableWidgetItem             *item;
    QString                       field;

    tableWidget = dialog->ui->tableWidget;

    if (!((!tap_device->is_local && tap_device->has_bd_addr) || (tap_device->is_local && tapinfo->is_local && tap_device->interface_id == tapinfo->interface_id && tap_device->adapter_id == tapinfo->adapter_id))) {
        return TAP_PACKET_REDRAW;
    }

    if (tap_device->has_bd_addr) {
        for (int i = 0; i < 6; ++i) {
            bd_addr += QString("%1:").arg(tap_device->bd_addr[i], 2, 16, QChar('0'));
        }
        bd_addr.chop(1); // remove extra character ":" from the end of the string
        if (!tap_device->is_local && bd_addr != tapinfo->bdAddr)
            return TAP_PACKET_REDRAW;

        manuf = get_ether_name(tap_device->bd_addr);
        if (manuf) {
            int pos;

            bd_addr_oui = QString(manuf);
            pos = static_cast<int>(bd_addr_oui.indexOf('_'));
            if (pos < 0) {
                manuf = NULL;
            } else {
                bd_addr_oui.remove(pos, bd_addr_oui.size());
            }
        }

        if (!manuf)
            bd_addr_oui = "";

        item = tableWidget->item(row_number_bd_addr, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, bd_addr, row_number_bd_addr, tapinfo->changes, pinfo);
        item->setText(bd_addr);

        item = tableWidget->item(row_number_bd_addr_oui, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, bd_addr_oui, row_number_bd_addr_oui, tapinfo->changes, pinfo);
        item->setText(bd_addr_oui);

        dialog->setTitle(bd_addr, tableWidget->item(row_number_name, column_number_value)->text());
    }

    switch (tap_device->type) {
    case BLUETOOTH_DEVICE_LOCAL_ADAPTER:
    case BLUETOOTH_DEVICE_BD_ADDR:
        break;
    case BLUETOOTH_DEVICE_NAME:
        item = tableWidget->item(row_number_name, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, QString(tap_device->data.name), row_number_name, tapinfo->changes, pinfo);

        item->setText(tap_device->data.name);

        dialog->setTitle(tableWidget->item(row_number_bd_addr, column_number_value)->text(), tap_device->data.name);

        break;
    case BLUETOOTH_DEVICE_RESET:
        for (int i_row = 0; i_row < dialog->ui->tableWidget->rowCount(); i_row += 1) {
            bluetooth_item_data_t       *item_data;

            item = dialog->ui->tableWidget->item(i_row, column_number_value);
            saveItemData(item, tap_device, pinfo);

            item_data = VariantPointer<bluetooth_item_data_t>::asPtr(item->data(Qt::UserRole));

            if (item_data->changes > -1) {
                item_data->changes += 1;
                item_data->frame_number = pinfo->fd->num;
                dialog->ui->tableWidget->item(i_row, column_number_changes)->setText(QString::number(item_data->changes));
            } else {
                item_data->changes = 0;
            }
            dialog->ui->tableWidget->item(i_row, column_number_value)->setText("");
        }
        *tapinfo->changes += 1;

        break;
    case BLUETOOTH_DEVICE_SCAN:
        field = QString(val_to_str_const(tap_device->data.scan, bthci_cmd_scan_enable_values, "Unknown 0x%02x"));
        item = tableWidget->item(row_number_scan, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_scan, tapinfo->changes, pinfo);
        item->setText(field);
        break;
    case BLUETOOTH_DEVICE_LOCAL_VERSION:
        field = QString(val_to_str_const(tap_device->data.local_version.hci_version, bthci_evt_hci_version, "Unknown 0x%02x"));
        item = tableWidget->item(row_number_hci_version, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_hci_version, tapinfo->changes, pinfo);
        item->setText(field);

        field = QString::number(tap_device->data.local_version.hci_revision);
        item = tableWidget->item(row_number_hci_revision, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_hci_revision, tapinfo->changes, pinfo);
        item->setText(field);

        field = QString(val_to_str_const(tap_device->data.local_version.lmp_version, bthci_evt_lmp_version, "Unknown 0x%02x"));
        item = tableWidget->item(row_number_lmp_version, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_lmp_version, tapinfo->changes, pinfo);
        item->setText(field);

        field = QString(val_to_str_const(tap_device->data.local_version.lmp_version, bthci_evt_lmp_version, "Unknown 0x%02x"));
        item = tableWidget->item(row_number_lmp_version, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_lmp_version, tapinfo->changes, pinfo);
        item->setText(field);

        field = QString::number(tap_device->data.local_version.lmp_subversion);
        item = tableWidget->item(row_number_lmp_subversion, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_lmp_subversion, tapinfo->changes, pinfo);
        item->setText(field);

        field = QString(val_to_str_ext_const(tap_device->data.local_version.manufacturer, &bluetooth_company_id_vals_ext, "Unknown 0x%04x"));
        item = tableWidget->item(row_number_manufacturer, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_manufacturer, tapinfo->changes, pinfo);
        item->setText(field);

        break;
    case BLUETOOTH_DEVICE_REMOTE_VERSION:
        field = QString(val_to_str_const(tap_device->data.remote_version.lmp_version, bthci_evt_lmp_version, "Unknown 0x%02x"));
        item = tableWidget->item(row_number_lmp_version, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_lmp_version, tapinfo->changes, pinfo);
        item->setText(field);

        field = QString::number(tap_device->data.remote_version.lmp_subversion);
        item = tableWidget->item(row_number_lmp_subversion, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_lmp_subversion, tapinfo->changes, pinfo);
        item->setText(field);

        field = QString(val_to_str_ext_const(tap_device->data.remote_version.manufacturer, &bluetooth_company_id_vals_ext, "Unknown 0x%04x"));
        item = tableWidget->item(row_number_manufacturer, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_manufacturer, tapinfo->changes, pinfo);
        item->setText(field);

        break;
    case BLUETOOTH_DEVICE_VOICE_SETTING:
        field = QString("%1").arg(tap_device->data.voice_setting, 4, 16, QChar('0'));
        item = tableWidget->item(row_number_voice_setting, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_voice_setting, tapinfo->changes, pinfo);
        item->setText(field);

        break;
    case BLUETOOTH_DEVICE_CLASS_OF_DEVICE:
        field = QString("%1").arg(tap_device->data.class_of_device, 6, 16, QChar('0'));
        item = tableWidget->item(row_number_class_of_device, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_class_of_device, tapinfo->changes, pinfo);
        item->setText(field);

        break;
    case BLUETOOTH_DEVICE_AUTHENTICATION:
        field = QString(val_to_str_const(tap_device->data.authentication, bthci_cmd_authentication_enable_values, "Unknown 0x%02x"));
        item = tableWidget->item(row_number_authentication, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_authentication, tapinfo->changes, pinfo);
        item->setText(field);

        break;
    case BLUETOOTH_DEVICE_ENCRYPTION:
        field = QString(val_to_str_const(tap_device->data.encryption, bthci_cmd_encrypt_mode_vals, "Unknown 0x%02x"));
        item = tableWidget->item(row_number_encryption, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_encryption, tapinfo->changes, pinfo);
        item->setText(field);

        break;
    case BLUETOOTH_DEVICE_SIMPLE_PAIRING_MODE:
        field = QString(tap_device->data.encryption ? tr("enabled") : tr("disabled"));
        item = tableWidget->item(row_number_simple_pairing_mode, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_simple_pairing_mode, tapinfo->changes, pinfo);
        item->setText(field);

        break;
    case BLUETOOTH_DEVICE_PAGE_TIMEOUT:
        field = QString(tr("%1 ms (%2 slots)")).arg(tap_device->data.page_timeout * 0.625).arg(tap_device->data.page_timeout);
        item = tableWidget->item(row_number_page_timeout, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_page_timeout, tapinfo->changes, pinfo);
        item->setText(field);

        break;
    case BLUETOOTH_DEVICE_INQUIRY_MODE:
        field = QString(val_to_str_const(tap_device->data.inquiry_mode, bthci_cmd_inq_modes, "Unknown 0x%02x"));
        item = tableWidget->item(row_number_inquiry_mode, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_inquiry_mode, tapinfo->changes, pinfo);
        item->setText(field);

        break;
    case BLUETOOTH_DEVICE_MTUS:
        field = QString::number(tap_device->data.mtus.acl_mtu);
        item = tableWidget->item(row_number_acl_mtu, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_acl_mtu, tapinfo->changes, pinfo);
        item->setText(field);

        field = QString::number(tap_device->data.mtus.acl_packets);
        item = tableWidget->item(row_number_acl_packets, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_acl_packets, tapinfo->changes, pinfo);
        item->setText(field);

        field = QString::number(tap_device->data.mtus.sco_mtu);
        item = tableWidget->item(row_number_sco_mtu, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_sco_mtu, tapinfo->changes, pinfo);
        item->setText(field);

        field = QString::number(tap_device->data.mtus.sco_packets);
        item = tableWidget->item(row_number_sco_packets, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_sco_packets, tapinfo->changes, pinfo);
        item->setText(field);

        break;
    case BLUETOOTH_DEVICE_LE_MTU:
        field = QString::number(tap_device->data.le_mtus.acl_mtu);
        item = tableWidget->item(row_number_le_acl_mtu, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_le_acl_mtu, tapinfo->changes, pinfo);
        item->setText(field);

        field = QString::number(tap_device->data.le_mtus.acl_packets);
        item = tableWidget->item(row_number_le_acl_packets, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_le_acl_packets, tapinfo->changes, pinfo);
        item->setText(field);

        field = QString::number(tap_device->data.le_mtus.iso_mtu);
        item = tableWidget->item(row_number_le_iso_mtu, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_le_iso_mtu, tapinfo->changes, pinfo);
        item->setText(field);

        field = QString::number(tap_device->data.le_mtus.iso_packets);
        item = tableWidget->item(row_number_le_iso_packets, column_number_value);
        saveItemData(item, tap_device, pinfo);
        updateChanges(tableWidget, field, row_number_le_iso_packets, tapinfo->changes, pinfo);
        item->setText(field);

        break;
    }

    dialog->ui->hintLabel->setText(QString(tr("%1 changes")).arg(*tapinfo->changes));

    return TAP_PACKET_REDRAW;
}

void BluetoothDeviceDialog::interfaceCurrentIndexChanged(int)
{
    cap_file_.retapPackets();
}

void BluetoothDeviceDialog::showInformationStepsChanged(int)
{
    cap_file_.retapPackets();
}


void BluetoothDeviceDialog::on_tableWidget_itemActivated(QTableWidgetItem *item)
{
    if (!cap_file_.isValid())
        return;

    if (!item->data(Qt::UserRole).isValid())
        return;

    bluetooth_item_data_t *item_data = VariantPointer<bluetooth_item_data_t>::asPtr(item->data(Qt::UserRole));

    emit goToPacket(item_data->frame_number);

}

void BluetoothDeviceDialog::on_actionSave_as_image_triggered()
{
    QPixmap image;

    QString fileName = WiresharkFileDialog::getSaveFileName(this,
            tr("Save Table Image"),
            "bluetooth_device_table.png",
            tr("PNG Image (*.png)"));

    if (fileName.isEmpty()) return;

    image = ui->tableWidget->grab();
    image.save(fileName, "PNG");
}

void BluetoothDeviceDialog::on_buttonBox_clicked(QAbstractButton *)
{

}