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
|
/* bluetooth_att_server_attributes_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_att_server_attributes_dialog.h"
#include <ui_bluetooth_att_server_attributes_dialog.h>
#include <ui/qt/utils/color_utils.h>
#include "epan/epan.h"
#include "epan/to_str.h"
#include "epan/epan_dissect.h"
#include "epan/prefs.h"
#include "epan/dissectors/packet-bluetooth.h"
#include "epan/dissectors/packet-btatt.h"
#include "ui/simple_dialog.h"
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <QClipboard>
#include <QContextMenuEvent>
#include <QPushButton>
#include <QTreeWidget>
static const int column_number_handle = 0;
static const int column_number_uuid = 1;
static const int column_number_uuid_name = 2;
static tap_packet_status
btatt_handle_tap_packet(void *tapinfo_ptr, packet_info *pinfo, epan_dissect_t *edt, const void* data, tap_flags_t flags)
{
tapinfo_t *tapinfo = (tapinfo_t *) tapinfo_ptr;
if (tapinfo->tap_packet)
tapinfo->tap_packet(tapinfo, pinfo, edt, data, flags);
return TAP_PACKET_REDRAW;
}
static void
btatt_handle_tap_reset(void *tapinfo_ptr)
{
tapinfo_t *tapinfo = (tapinfo_t *) tapinfo_ptr;
if (tapinfo->tap_reset)
tapinfo->tap_reset(tapinfo);
}
BluetoothAttServerAttributesDialog::BluetoothAttServerAttributesDialog(QWidget &parent, CaptureFile &cf) :
WiresharkDialog(parent, cf),
ui(new Ui::BluetoothAttServerAttributesDialog)
{
ui->setupUi(this);
loadGeometry(parent.width() * 4 / 5, parent.height() * 2 / 3);
connect(ui->tableTreeWidget, &QTreeWidget::customContextMenuRequested, this, &BluetoothAttServerAttributesDialog::tableContextMenu);
connect(ui->interfaceComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &BluetoothAttServerAttributesDialog::interfaceCurrentIndexChanged);
connect(ui->deviceComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &BluetoothAttServerAttributesDialog::deviceCurrentIndexChanged);
connect(ui->removeDuplicatesCheckBox, &QCheckBox::stateChanged, this, &BluetoothAttServerAttributesDialog::removeDuplicatesStateChanged);
ui->tableTreeWidget->sortByColumn(column_number_handle, Qt::AscendingOrder);
ui->tableTreeWidget->setStyleSheet("QTreeView::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);
tapinfo_.tap_packet = tapPacket;
tapinfo_.tap_reset = tapReset;
tapinfo_.ui = this;
registerTapListener("btatt.handles", &tapinfo_, NULL,
0,
btatt_handle_tap_reset,
btatt_handle_tap_packet,
NULL
);
cap_file_.retapPackets();
}
BluetoothAttServerAttributesDialog::~BluetoothAttServerAttributesDialog()
{
delete ui;
}
void BluetoothAttServerAttributesDialog::captureFileClosed()
{
ui->interfaceComboBox->setEnabled(FALSE);
ui->deviceComboBox->setEnabled(FALSE);
ui->removeDuplicatesCheckBox->setEnabled(FALSE);
WiresharkDialog::captureFileClosed();
}
void BluetoothAttServerAttributesDialog::changeEvent(QEvent *event)
{
if (0 != event)
{
switch (event->type())
{
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
QDialog::changeEvent(event);
}
void BluetoothAttServerAttributesDialog::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 BluetoothAttServerAttributesDialog::tableContextMenu(const QPoint &pos)
{
context_menu_.popup(ui->tableTreeWidget->viewport()->mapToGlobal(pos));
}
void BluetoothAttServerAttributesDialog::on_actionMark_Unmark_Cell_triggered()
{
QTreeWidgetItem *current_item = ui->tableTreeWidget->currentItem();
if (!current_item)
return;
QBrush fg;
QBrush bg;
if (current_item->background(ui->tableTreeWidget->currentColumn()) == 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(ui->tableTreeWidget->currentColumn(), fg);
current_item->setBackground(ui->tableTreeWidget->currentColumn(), bg);
}
void BluetoothAttServerAttributesDialog::on_actionMark_Unmark_Row_triggered()
{
QTreeWidgetItem *current_item = ui->tableTreeWidget->currentItem();
if (!current_item)
return;
QBrush fg;
QBrush bg;
bool is_marked = TRUE;
for (int i = 0; i < ui->tableTreeWidget->columnCount(); i += 1) {
if (current_item->background(i) != 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->tableTreeWidget->columnCount(); i += 1) {
current_item->setForeground(i, fg);
current_item->setBackground(i, bg);
}
}
void BluetoothAttServerAttributesDialog::on_actionCopy_Cell_triggered()
{
QTreeWidgetItem *current_item = ui->tableTreeWidget->currentItem();
if (!current_item)
return;
QClipboard *clipboard = QApplication::clipboard();
QString copy;
copy = QString(current_item->text(ui->tableTreeWidget->currentColumn()));
clipboard->setText(copy);
}
void BluetoothAttServerAttributesDialog::on_actionCopy_Rows_triggered()
{
QClipboard *clipboard = QApplication::clipboard();
QString copy;
QList<QTreeWidgetItem *> items;
QList<QTreeWidgetItem *>::iterator i_item;
items = ui->tableTreeWidget->selectedItems();
for (i_item = items.begin(); i_item != items.end(); ++i_item) {
copy += QString("%1 %2 %3\n")
.arg((*i_item)->text(column_number_handle), -6)
.arg((*i_item)->text(column_number_uuid), -32)
.arg((*i_item)->text(column_number_uuid_name));
}
clipboard->setText(copy);
}
void BluetoothAttServerAttributesDialog::tapReset(void *tapinfo_ptr)
{
tapinfo_t *tapinfo = (tapinfo_t *) tapinfo_ptr;
BluetoothAttServerAttributesDialog *bluetooth_att_server_attributes_dialog = static_cast<BluetoothAttServerAttributesDialog *>(tapinfo->ui);
bluetooth_att_server_attributes_dialog->ui->tableTreeWidget->clear();
}
tap_packet_status BluetoothAttServerAttributesDialog::tapPacket(void *tapinfo_ptr, packet_info *pinfo, epan_dissect_t *, const void *data, tap_flags_t)
{
tapinfo_t *tapinfo = static_cast<tapinfo_t *>(tapinfo_ptr);
BluetoothAttServerAttributesDialog *dialog = static_cast<BluetoothAttServerAttributesDialog *>(tapinfo->ui);
tap_handles_t *tap_handles = static_cast<tap_handles_t *>(const_cast<void *>(data));
QString handle;
QString uuid;
QString uuid_name;
gchar *addr = NULL;
if (dialog->file_closed_)
return TAP_PACKET_DONT_REDRAW;
if (pinfo->rec->rec_type != REC_TYPE_PACKET)
return TAP_PACKET_DONT_REDRAW;
if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) {
gchar *interface;
const char *interface_name;
interface_name = epan_get_interface_name(pinfo->epan, pinfo->rec->rec_header.packet_header.interface_id);
interface = wmem_strdup_printf(pinfo->pool, "%u: %s", pinfo->rec->rec_header.packet_header.interface_id, interface_name);
if (dialog->ui->interfaceComboBox->findText(interface) == -1)
dialog->ui->interfaceComboBox->addItem(interface);
if (interface && dialog->ui->interfaceComboBox->currentIndex() > 0) {
if (dialog->ui->interfaceComboBox->currentText() != interface)
return TAP_PACKET_REDRAW;
}
}
if (pinfo->p2p_dir == P2P_DIR_SENT || pinfo->p2p_dir == P2P_DIR_RECV)
addr = address_to_str(pinfo->pool, &pinfo->src);
if (addr && dialog->ui->deviceComboBox->findText(addr) == -1) {
dialog->ui->deviceComboBox->addItem(addr);
}
if (addr && dialog->ui->deviceComboBox->currentIndex() > 0) {
if (dialog->ui->deviceComboBox->currentText() != addr)
return TAP_PACKET_REDRAW;
}
handle = QString("0x%1").arg(tap_handles->handle, 4, 16, QChar('0'));
uuid = QString(print_numeric_bluetooth_uuid(pinfo->pool, &tap_handles->uuid));
uuid_name = QString(print_bluetooth_uuid(pinfo->pool, &tap_handles->uuid));
if (dialog->ui->removeDuplicatesCheckBox->checkState() == Qt::Checked) {
QTreeWidgetItemIterator i_item(dialog->ui->tableTreeWidget);
while (*i_item) {
QTreeWidgetItem *item = static_cast<QTreeWidgetItem*>(*i_item);
if (item->text(column_number_handle) == handle &&
item->text(column_number_uuid) == uuid &&
item->text(column_number_uuid_name) == uuid_name)
return TAP_PACKET_REDRAW;
++i_item;
}
}
QTreeWidgetItem *item = new QTreeWidgetItem(dialog->ui->tableTreeWidget);
item->setText(column_number_handle, handle);
item->setText(column_number_uuid, uuid);
item->setText(column_number_uuid_name, uuid_name);
item->setData(0, Qt::UserRole, QVariant::fromValue(pinfo->num));
for (int i = 0; i < dialog->ui->tableTreeWidget->columnCount(); i++) {
dialog->ui->tableTreeWidget->resizeColumnToContents(i);
}
return TAP_PACKET_REDRAW;
}
void BluetoothAttServerAttributesDialog::interfaceCurrentIndexChanged(int)
{
cap_file_.retapPackets();
}
void BluetoothAttServerAttributesDialog::deviceCurrentIndexChanged(int)
{
cap_file_.retapPackets();
}
void BluetoothAttServerAttributesDialog::removeDuplicatesStateChanged(int)
{
cap_file_.retapPackets();
}
void BluetoothAttServerAttributesDialog::on_tableTreeWidget_itemActivated(QTreeWidgetItem *item, int)
{
if (file_closed_)
return;
guint32 frame_number = item->data(0, Qt::UserRole).value<guint32>();
emit goToPacket(frame_number);
}
void BluetoothAttServerAttributesDialog::on_actionCopy_All_triggered()
{
QClipboard *clipboard = QApplication::clipboard();
QString copy;
QTreeWidgetItemIterator i_item(ui->tableTreeWidget);
copy = QString("%1 %2 %3\n")
.arg(ui->tableTreeWidget->headerItem()->text(column_number_handle), -6)
.arg(ui->tableTreeWidget->headerItem()->text(column_number_uuid), -32)
.arg(ui->tableTreeWidget->headerItem()->text(column_number_uuid_name));
while (*i_item) {
QTreeWidgetItem *item = static_cast<QTreeWidgetItem*>(*i_item);
copy += QString("%1 %2 %3\n")
.arg(item->text(column_number_handle), -6)
.arg(item->text(column_number_uuid), -32)
.arg(item->text(column_number_uuid_name));
++i_item;
}
clipboard->setText(copy);
}
void BluetoothAttServerAttributesDialog::on_actionSave_as_image_triggered()
{
QPixmap image;
QString fileName = WiresharkFileDialog::getSaveFileName(this, tr("Save Table Image"),
"att_server_attributes_table.png",
tr("PNG Image (*.png)"));
if (fileName.isEmpty()) return;
image = ui->tableTreeWidget->grab();
image.save(fileName, "PNG");
}
void BluetoothAttServerAttributesDialog::on_buttonBox_clicked(QAbstractButton *)
{
/* if (button == foo_button_) */
}
|