Coverage Report

Created: 2026-05-14 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-bthsp.c
Line
Count
Source
1
/* packet-bthsp.c
2
 * Routines for Bluetooth Headset Profile (HSP)
3
 *
4
 * Copyright 2013, Michal Labedzki for Tieto Corporation
5
 *
6
 * Wireshark - Network traffic analyzer
7
 * By Gerald Combs <gerald@wireshark.org>
8
 * Copyright 1998 Gerald Combs
9
 *
10
 * SPDX-License-Identifier: GPL-2.0-or-later
11
 */
12
13
#include "config.h"
14
15
#include <epan/packet.h>
16
#include <epan/prefs.h>
17
#include <epan/expert.h>
18
#include <epan/strutil.h>
19
#include <epan/unit_strings.h>
20
21
#include <wsutil/strtoi.h>
22
23
#include "packet-btrfcomm.h"
24
#include "packet-btsdp.h"
25
26
static int proto_bthsp;
27
28
static int hf_command;
29
static int hf_parameters;
30
static int hf_command_in;
31
static int hf_unsolicited;
32
static int hf_role;
33
static int hf_at_cmd;
34
static int hf_at_cmd_type;
35
static int hf_at_command_line_prefix;
36
static int hf_at_ignored;
37
static int hf_parameter;
38
static int hf_unknown_parameter;
39
static int hf_data;
40
static int hf_fragment;
41
static int hf_fragmented;
42
static int hf_vgs;
43
static int hf_vgm;
44
static int hf_ckpd;
45
46
static expert_field ei_non_mandatory_command;
47
static expert_field ei_invalid_usage;
48
static expert_field ei_unknown_parameter;
49
static expert_field ei_vgm_gain;
50
static expert_field ei_vgs_gain;
51
static expert_field ei_ckpd;
52
53
static int ett_bthsp;
54
static int ett_bthsp_command;
55
static int ett_bthsp_parameters;
56
57
static dissector_handle_t bthsp_handle;
58
59
static wmem_tree_t *fragments;
60
61
4
#define ROLE_UNKNOWN  0
62
2
#define ROLE_AG       1
63
2
#define ROLE_HS       2
64
65
0
#define TYPE_UNKNOWN       0x0000
66
0
#define TYPE_RESPONSE_ACK  0x0d0a
67
0
#define TYPE_RESPONSE      0x003a
68
0
#define TYPE_ACTION        0x003d
69
0
#define TYPE_ACTION_SIMPLY 0x000d
70
0
#define TYPE_READ          0x003f
71
0
#define TYPE_TEST          0x3d3f
72
73
static int hsp_role = ROLE_UNKNOWN;
74
75
enum reassemble_state_t {
76
    REASSEMBLE_FRAGMENT,
77
    REASSEMBLE_PARTIALLY,
78
    REASSEMBLE_DONE
79
};
80
81
typedef struct _fragment_t {
82
    uint32_t                 interface_id;
83
    uint32_t                 adapter_id;
84
    uint32_t                 chandle;
85
    uint32_t                 dlci;
86
    uint32_t                 role;
87
88
    unsigned                 idx;
89
    unsigned                 length;
90
    uint8_t                 *data;
91
    struct _fragment_t      *previous_fragment;
92
93
    unsigned                 reassemble_start_offset;
94
    unsigned                 reassemble_end_offset;
95
    enum reassemble_state_t  reassemble_state;
96
} fragment_t;
97
98
typedef struct _at_cmd_t {
99
    const char *name;
100
    const char *long_name;
101
102
    bool (*check_command)(int role, uint16_t type);
103
    bool (*dissect_parameter)(tvbuff_t *tvb, packet_info *pinfo,
104
            proto_tree *tree, int offset, int role, uint16_t type,
105
            uint8_t *parameter_stream, unsigned parameter_number,
106
            int parameter_length, void **data);
107
} at_cmd_t;
108
109
static const value_string role_vals[] = {
110
    { ROLE_UNKNOWN,   "Unknown" },
111
    { ROLE_AG,        "AG - Audio Gate" },
112
    { ROLE_HS,        "HS - Headset" },
113
    { 0, NULL }
114
};
115
116
static const value_string at_cmd_type_vals[] = {
117
    { 0x0d,   "Action Command" },
118
    { 0x3a,   "Response" },
119
    { 0x3d,   "Action Command" },
120
    { 0x3f,   "Read Command" },
121
    { 0x0d0a, "Response" },
122
    { 0x3d3f, "Test Command" },
123
    { 0, NULL }
124
};
125
126
static const enum_val_t pref_hsp_role[] = {
127
    { "off",     "Off",                    ROLE_UNKNOWN },
128
    { "ag",      "Sent is AG, Rcvd is HS", ROLE_AG },
129
    { "hs",      "Sent is HS, Rcvd is AG", ROLE_HS },
130
    { NULL, NULL, 0 }
131
};
132
133
static const unit_name_string units_slash15 = { "/15", NULL };
134
135
void proto_register_bthsp(void);
136
void proto_reg_handoff_bthsp(void);
137
138
static uint32_t get_uint_parameter(const uint8_t *parameter_stream, int parameter_length)
139
0
{
140
0
    uint32_t       value;
141
0
    const uint8_t *unused;
142
143
0
    ws_buftou32(parameter_stream, parameter_length, &unused, &value);
144
145
0
    return value;
146
0
}
147
148
0
static bool check_vgs(int role, uint16_t type) {
149
0
    if (role == ROLE_HS && type == TYPE_ACTION) return true;
150
0
    if (role == ROLE_AG && type == TYPE_RESPONSE) return true;
151
152
0
    return false;
153
0
}
154
155
0
static bool check_vgm(int role, uint16_t type) {
156
0
    if (role == ROLE_HS && type == TYPE_ACTION) return true;
157
0
    if (role == ROLE_AG && type == TYPE_RESPONSE) return true;
158
159
0
    return false;
160
0
}
161
162
0
static bool check_ckpd(int role, uint16_t type) {
163
0
    if (role == ROLE_HS && type == TYPE_ACTION) return true;
164
165
0
    return false;
166
0
}
167
168
0
static bool check_only_ag_role(int role, uint16_t type) {
169
0
    if (role == ROLE_AG && type == TYPE_RESPONSE_ACK) return true;
170
171
0
    return false;
172
0
}
173
174
static bool
175
dissect_vgs_parameter(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
176
        int offset, int role, uint16_t type, uint8_t *parameter_stream,
177
        unsigned parameter_number, int parameter_length, void **data _U_)
178
0
{
179
0
    proto_item  *pitem;
180
0
    uint32_t     value;
181
182
0
    if (!check_vgs(role, type)) return false;
183
184
0
    if (parameter_number > 0) return false;
185
186
0
    value = get_uint_parameter(parameter_stream, parameter_length);
187
188
0
    pitem = proto_tree_add_uint(tree, hf_vgs, tvb, offset, parameter_length, value);
189
190
0
    if (value > 15) {
191
0
        expert_add_info(pinfo, pitem, &ei_vgs_gain);
192
0
    }
193
194
0
    return true;
195
0
}
196
197
static bool
198
dissect_vgm_parameter(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
199
        int offset, int role, uint16_t type, uint8_t *parameter_stream,
200
        unsigned parameter_number, int parameter_length, void **data _U_)
201
0
{
202
0
    proto_item  *pitem;
203
0
    uint32_t     value;
204
205
0
    if (!check_vgm(role, type)) return false;
206
207
0
    if (parameter_number > 0) return false;
208
209
0
    value = get_uint_parameter(parameter_stream, parameter_length);
210
211
0
    pitem = proto_tree_add_uint(tree, hf_vgm, tvb, offset, parameter_length, value);
212
213
0
    if (value > 15) {
214
0
        expert_add_info(pinfo, pitem, &ei_vgm_gain);
215
0
    }
216
217
0
    return true;
218
0
}
219
220
static bool
221
dissect_ckpd_parameter(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
222
        int offset, int role, uint16_t type, uint8_t *parameter_stream,
223
        unsigned parameter_number, int parameter_length, void **data _U_)
224
0
{
225
0
    proto_item  *pitem;
226
0
    uint32_t     value;
227
228
0
    if (!check_ckpd(role, type)) return false;
229
230
231
0
    if (parameter_number > 0) return false;
232
233
0
    value = get_uint_parameter(parameter_stream, parameter_length);
234
235
0
    pitem = proto_tree_add_uint(tree, hf_ckpd, tvb, offset, parameter_length, value);
236
237
0
    if (value != 200) {
238
0
        expert_add_info(pinfo, pitem, &ei_ckpd);
239
0
    }
240
241
0
    return true;
242
0
}
243
244
static bool
245
dissect_no_parameter(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_,
246
        int offset _U_, int role _U_, uint16_t type _U_, uint8_t *parameter_stream _U_,
247
        unsigned parameter_number _U_, int parameter_length _U_, void **data _U_)
248
0
{
249
0
    return false;
250
0
}
251
252
static const at_cmd_t at_cmds[] = {
253
    { "+VGS",       "Gain of Speaker",                          check_vgs,  dissect_vgs_parameter  },
254
    { "+VGM",       "Gain of Microphone",                       check_vgm,  dissect_vgm_parameter  },
255
    { "+CKPD",      "Control Keypad",                           check_ckpd, dissect_ckpd_parameter },
256
    { "ERROR",      "ERROR",                                    check_only_ag_role, dissect_no_parameter },
257
    { "RING",       "Incoming Call Indication",                 check_only_ag_role, dissect_no_parameter },
258
    { "OK",         "OK",                                       check_only_ag_role, dissect_no_parameter },
259
    { NULL, NULL, NULL, NULL }
260
};
261
262
263
static int
264
dissect_at_command(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
265
        int offset, uint32_t role, int command_number)
266
0
{
267
0
    proto_item      *pitem;
268
0
    proto_tree      *command_item;
269
0
    proto_item      *command_tree;
270
0
    proto_tree      *parameters_item = NULL;
271
0
    proto_item      *parameters_tree = NULL;
272
0
    char            *col_str = NULL;
273
0
    char            *at_stream;
274
0
    char            *at_command = NULL;
275
0
    int              i_char = 0;
276
0
    unsigned         i_char_fix = 0;
277
0
    int              length;
278
0
    const at_cmd_t  *i_at_cmd;
279
0
    int              parameter_length;
280
0
    unsigned         parameter_number = 0;
281
0
    int              first_parameter_offset = offset;
282
0
    int              last_parameter_offset  = offset;
283
0
    uint16_t         type = TYPE_UNKNOWN;
284
0
    uint32_t         brackets;
285
0
    bool             quotation;
286
0
    bool             next;
287
0
    void            *data;
288
289
0
    length = tvb_reported_length_remaining(tvb, offset);
290
0
    if (length <= 0)
291
0
        return tvb_reported_length(tvb);
292
293
0
    if (!command_number) {
294
0
        proto_tree_add_item(tree, hf_data, tvb, offset, length, ENC_ASCII);
295
0
        col_str = (char *) wmem_alloc(pinfo->pool, length + 1);
296
0
        tvb_memcpy(tvb, col_str, offset, length);
297
0
        col_str[length] = '\0';
298
0
    }
299
300
0
    at_stream = (char *) wmem_alloc(pinfo->pool, length + 1);
301
0
    tvb_memcpy(tvb, at_stream, offset, length);
302
0
    at_stream[length] = '\0';
303
0
    while (at_stream[i_char]) {
304
0
        at_stream[i_char] = g_ascii_toupper(at_stream[i_char]);
305
0
        if (!command_number) {
306
0
            col_str[i_char] = g_ascii_toupper(col_str[i_char]);
307
0
            if (!g_ascii_isgraph(col_str[i_char])) col_str[i_char] = ' ';
308
0
        }
309
0
        i_char += 1;
310
0
    }
311
312
0
    command_item = proto_tree_add_none_format(tree, hf_command, tvb,
313
0
            offset, 0, "Command %u", command_number);
314
0
    command_tree = proto_item_add_subtree(command_item, ett_bthsp_command);
315
316
0
    if (!command_number) col_append_str(pinfo->cinfo, COL_INFO, col_str);
317
318
0
    if (role == ROLE_HS) {
319
0
        if (command_number) {
320
0
            at_command = at_stream;
321
0
            i_char = 0;
322
0
        } else {
323
0
            at_command = g_strstr_len(at_stream, length, "AT");
324
325
0
            if (at_command) {
326
0
                i_char = (int) (at_command - at_stream);
327
328
0
                if (i_char) {
329
0
                    proto_tree_add_item(command_tree, hf_at_ignored, tvb, offset,
330
0
                        i_char, ENC_NA);
331
0
                    offset += i_char;
332
0
                }
333
334
0
                proto_tree_add_item(command_tree, hf_at_command_line_prefix,
335
0
                        tvb, offset, 2, ENC_ASCII);
336
0
                offset += 2;
337
0
                i_char += 2;
338
0
                at_command = at_stream;
339
340
0
                at_command += i_char;
341
0
                length -= i_char;
342
0
                i_char_fix += i_char;
343
0
                i_char = 0;
344
0
            }
345
0
        }
346
0
    } else {
347
0
        at_command = at_stream;
348
0
        i_char = 0;
349
0
        while (i_char <= length &&
350
0
                (at_command[i_char] == '\r' || at_command[i_char] == '\n' ||
351
0
                at_command[i_char] == ' ' || at_command[i_char] == '\t')) {
352
            /* ignore white characters */
353
0
            i_char += 1;
354
0
        }
355
356
0
        offset += i_char;
357
0
        at_command += i_char;
358
0
        length -= i_char;
359
0
        i_char_fix += i_char;
360
0
        i_char = 0;
361
0
    }
362
363
0
    if (at_command) {
364
365
0
        while (i_char < length &&
366
0
                        (at_command[i_char] != '\r' && at_command[i_char] != '=' &&
367
0
                        at_command[i_char] != ';' && at_command[i_char] != '?' &&
368
0
                        at_command[i_char] != ':')) {
369
0
            i_char += 1;
370
0
        }
371
372
0
        i_at_cmd = at_cmds;
373
0
        if (at_command[0] == '\r') {
374
0
            pitem = proto_tree_add_item(command_tree, hf_at_cmd, tvb, offset - 2,
375
0
                    2, ENC_ASCII);
376
0
            i_at_cmd = NULL;
377
0
        } else {
378
0
            pitem = NULL;
379
0
            while (i_at_cmd->name) {
380
0
                if (g_str_has_prefix(&at_command[0], i_at_cmd->name)) {
381
0
                    pitem = proto_tree_add_item(command_tree, hf_at_cmd, tvb, offset,
382
0
                            (int) strlen(i_at_cmd->name), ENC_ASCII);
383
0
                    proto_item_append_text(pitem, " (%s)", i_at_cmd->long_name);
384
0
                    break;
385
0
                }
386
0
                i_at_cmd += 1;
387
0
            }
388
389
0
            if (!pitem) {
390
0
                pitem = proto_tree_add_item(command_tree, hf_at_cmd, tvb, offset,
391
0
                        i_char, ENC_ASCII);
392
0
            }
393
0
        }
394
395
396
0
        if (i_at_cmd && i_at_cmd->name == NULL) {
397
0
            char *name;
398
399
0
            name = format_text(pinfo->pool, at_command, i_char + 1);
400
0
            proto_item_append_text(command_item, ": %s (Unknown)", name);
401
0
            proto_item_append_text(pitem, " (Unknown - Non-Standard HSP Command)");
402
0
            expert_add_info(pinfo, pitem, &ei_non_mandatory_command);
403
0
        } else if (i_at_cmd == NULL) {
404
0
            proto_item_append_text(command_item, ": AT");
405
0
        } else {
406
0
            proto_item_append_text(command_item, ": %s", i_at_cmd->name);
407
0
        }
408
409
0
        offset += i_char;
410
411
0
        if (i_at_cmd && g_strcmp0(i_at_cmd->name, "D")) {
412
0
            if (length >= 2 && at_command[i_char] == '=' && at_command[i_char + 1] == '?') {
413
0
                type = at_command[i_char] << 8 | at_command[i_char + 1];
414
0
                proto_tree_add_uint(command_tree, hf_at_cmd_type, tvb, offset, 2, type);
415
0
                offset += 2;
416
0
                i_char += 2;
417
0
            } else if (role == ROLE_AG && length >= 2 && at_command[i_char] == '\r' && at_command[i_char + 1] == '\n') {
418
0
                type = at_command[i_char] << 8 | at_command[i_char + 1];
419
0
                proto_tree_add_uint(command_tree, hf_at_cmd_type, tvb, offset, 2, type);
420
0
                offset += 2;
421
0
                i_char += 2;
422
0
            } else if (length >= 1 && (at_command[i_char] == '=' ||
423
0
                        at_command[i_char] == '\r' ||
424
0
                        at_command[i_char] == ':' ||
425
0
                        at_command[i_char] == '?')) {
426
0
                type = at_command[i_char];
427
0
                proto_tree_add_uint(command_tree, hf_at_cmd_type, tvb, offset, 1, type);
428
0
                offset += 1;
429
0
                i_char += 1;
430
0
            }
431
0
        }
432
433
0
        if (i_at_cmd && i_at_cmd->check_command && !i_at_cmd->check_command(role, type)) {
434
0
            expert_add_info(pinfo, command_item, &ei_invalid_usage);
435
0
        }
436
437
0
        parameters_item = proto_tree_add_none_format(command_tree, hf_parameters, tvb,
438
0
                offset, 0, "Parameters");
439
0
        parameters_tree = proto_item_add_subtree(parameters_item, ett_bthsp_parameters);
440
441
0
        data = NULL;
442
443
0
        while (i_char < length) {
444
445
0
            while (at_command[i_char] == ' ' || at_command[i_char]  == '\t') {
446
0
                offset += 1;
447
0
                i_char += 1;
448
0
            }
449
450
0
            parameter_length = 0;
451
0
            brackets = 0;
452
0
            quotation = false;
453
0
            next = false;
454
455
0
            if (at_command[i_char + parameter_length] != '\r') {
456
0
                while (i_char + parameter_length < length &&
457
0
                        at_command[i_char + parameter_length] != '\r') {
458
459
0
                    if (at_command[i_char + parameter_length] == ';') {
460
0
                        next = true;
461
0
                        break;
462
0
                    }
463
464
0
                    if (at_command[i_char + parameter_length] == '"') {
465
0
                        quotation = quotation ? false : true;
466
0
                    }
467
468
0
                    if (quotation == true) {
469
0
                        parameter_length += 1;
470
0
                        continue;
471
0
                    }
472
473
0
                    if (at_command[i_char + parameter_length] == '(') {
474
0
                        brackets += 1;
475
0
                    }
476
0
                    if (at_command[i_char + parameter_length] == ')') {
477
0
                        brackets -= 1;
478
0
                    }
479
480
0
                    if (brackets == 0 && at_command[i_char + parameter_length] == ',') {
481
0
                        break;
482
0
                    }
483
484
0
                    parameter_length += 1;
485
0
                }
486
487
/* TODO: Save bthsp.at_cmd, bthsp.at_cmd.type, frame_time  and frame_num here in
488
489
                if (role == ROLE_HS && pinfo->fd->visited == 0) {
490
491
    at_cmd_db = wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope());
492
493
    interface_id
494
    adapter_id
495
    chandle
496
    dlci
497
498
    frame_number
499
-------------------
500
    at_command
501
    at_type
502
    frame_num
503
    frame_time
504
    status
505
    first_response_in (if 0 - no response)
506
507
508
            interface_id = interface_id;
509
            adapter_id   = adapter_id;
510
            chandle      = chandle;
511
            dlci         = dlci;
512
            frame_number = pinfo->num;
513
514
515
            key[0].length = 1;
516
            key[0].key = &interface_id;
517
            key[1].length = 1;
518
            key[1].key = &adapter_id;
519
            key[2].length = 1;
520
            key[2].key = &chandle;
521
            key[3].length = 1;
522
            key[3].key = &dlci;
523
            key[4].length = 1;
524
            key[4].key = &frame_number;
525
            key[5].length = 0;
526
            key[5].key = NULL;
527
528
            cmd = wmem_new(wmem_file_scope(), at_cmd_entry_t);
529
            cmd->interface_id = interface_id;
530
            cmd->adapter_id   = adapter_id;
531
            cmd->chandle      = chandle;
532
            cmd->dlci         = dlci;
533
534
            cmd->frame_number = pinfo->num;
535
            cmd->status = STATUS_NO_RESPONSE;
536
            cmd->time = pinfo->abs_ts;
537
            cmd->at_command
538
            cmd->at_type
539
            cmd->first_response_in = 0;
540
541
            wmem_tree_insert32_array(at_cmd_db, key, cmd);
542
    }
543
544
*/
545
546
0
                first_parameter_offset = offset;
547
0
                if (type == TYPE_ACTION || type == TYPE_RESPONSE) {
548
0
                    if (i_at_cmd && (i_at_cmd->dissect_parameter != NULL &&
549
0
                            !i_at_cmd->dissect_parameter(tvb, pinfo, parameters_tree, offset, role,
550
0
                            type, (uint8_t*)&at_command[i_char], parameter_number, parameter_length, &data) )) {
551
0
                        pitem = proto_tree_add_item(parameters_tree,
552
0
                                hf_unknown_parameter, tvb, offset,
553
0
                                parameter_length, ENC_ASCII);
554
0
                        expert_add_info(pinfo, pitem, &ei_unknown_parameter);
555
0
                    } else if (i_at_cmd && i_at_cmd->dissect_parameter == NULL) {
556
0
                        proto_tree_add_item(parameters_tree, hf_parameter, tvb, offset,
557
0
                                parameter_length, ENC_ASCII);
558
0
                    }
559
0
                }
560
0
            }
561
562
0
            if (type != TYPE_ACTION_SIMPLY && type != TYPE_RESPONSE_ACK && type != TYPE_TEST && type != TYPE_READ)
563
0
                parameter_number += 1;
564
0
            i_char += parameter_length;
565
0
            offset += parameter_length;
566
0
            last_parameter_offset = offset;
567
568
0
            if (role == ROLE_AG &&
569
0
                    i_char + 1 <= length &&
570
0
                    at_command[i_char] == '\r' &&
571
0
                    at_command[i_char + 1] == '\n') {
572
0
                offset += 2;
573
0
                i_char += 2;
574
0
                break;
575
0
            } else if (at_command[i_char] == ',' ||
576
0
                        at_command[i_char] == '\r' ||
577
0
                        at_command[i_char] == ';') {
578
0
                    i_char += 1;
579
0
                    offset += 1;
580
0
            }
581
582
0
            if (next) break;
583
0
        }
584
585
0
        i_char += i_char_fix;
586
0
        proto_item_set_len(command_item, i_char);
587
0
    } else {
588
0
        length = tvb_reported_length_remaining(tvb, offset);
589
0
        if (length < 0)
590
0
            length = 0;
591
0
        proto_item_set_len(command_item, length);
592
0
        offset += length;
593
0
    }
594
595
0
    if (parameter_number > 0 && last_parameter_offset - first_parameter_offset > 0)
596
0
        proto_item_set_len(parameters_item, last_parameter_offset - first_parameter_offset);
597
0
    else
598
0
        proto_item_append_text(parameters_item, ": No");
599
600
0
    if (role == ROLE_AG) {
601
0
        unsigned command_frame_number = 0;
602
603
0
        if (command_frame_number) {
604
0
            pitem = proto_tree_add_uint(command_tree, hf_command_in, tvb, offset,
605
0
                    0, command_frame_number);
606
0
            proto_item_set_generated(pitem);
607
0
        } else {
608
0
            pitem = proto_tree_add_item(command_tree, hf_unsolicited, tvb, offset, 0, ENC_NA);
609
0
            proto_item_set_generated(pitem);
610
0
        }
611
0
    }
612
613
0
    return offset;
614
0
}
615
616
static int
617
dissect_bthsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
618
1
{
619
1
    proto_item       *main_item;
620
1
    proto_tree       *main_tree;
621
1
    proto_item       *pitem;
622
1
    int               offset = 0;
623
1
    uint32_t          role = ROLE_UNKNOWN;
624
1
    wmem_tree_key_t   key[10];
625
1
    uint32_t          interface_id;
626
1
    uint32_t          adapter_id;
627
1
    uint32_t          chandle;
628
1
    uint32_t          dlci;
629
1
    uint32_t          frame_number;
630
1
    uint32_t          direction;
631
1
    uint32_t          bd_addr_oui;
632
1
    uint32_t          bd_addr_id;
633
1
    fragment_t       *fragment;
634
1
    fragment_t       *previous_fragment;
635
1
    fragment_t       *i_fragment;
636
1
    uint8_t          *at_stream;
637
1
    int               length;
638
1
    int               command_number;
639
1
    int               i_length;
640
1
    tvbuff_t         *reassembled_tvb = NULL;
641
1
    unsigned          reassemble_start_offset = 0;
642
1
    unsigned          reassemble_end_offset   = 0;
643
1
    int               previous_proto;
644
645
1
    previous_proto = (GPOINTER_TO_INT(wmem_list_frame_data(wmem_list_frame_prev(wmem_list_tail(pinfo->layers)))));
646
1
    if (data && previous_proto == proto_btrfcomm) {
647
0
        btrfcomm_data_t  *rfcomm_data;
648
649
0
        rfcomm_data = (btrfcomm_data_t *) data;
650
651
0
        interface_id = rfcomm_data->interface_id;
652
0
        adapter_id   = rfcomm_data->adapter_id;
653
0
        chandle      = rfcomm_data->chandle;
654
0
        dlci         = rfcomm_data->dlci;
655
0
        direction    = (rfcomm_data->is_local_psm) ? P2P_DIR_SENT : P2P_DIR_RECV;
656
657
0
        if (direction == P2P_DIR_RECV) {
658
0
            bd_addr_oui     = rfcomm_data->remote_bd_addr_oui;
659
0
            bd_addr_id      = rfcomm_data->remote_bd_addr_id;
660
0
        } else {
661
0
            bd_addr_oui     = 0;
662
0
            bd_addr_id      = 0;
663
0
        }
664
1
    } else {
665
1
        interface_id = HCI_INTERFACE_DEFAULT;
666
1
        adapter_id   = HCI_ADAPTER_DEFAULT;
667
1
        chandle      = 0;
668
1
        dlci         = 0;
669
1
        direction    = P2P_DIR_UNKNOWN;
670
671
1
        bd_addr_oui     = 0;
672
1
        bd_addr_id      = 0;
673
1
    }
674
675
1
    main_item = proto_tree_add_item(tree, proto_bthsp, tvb, 0, tvb_captured_length(tvb), ENC_NA);
676
1
    main_tree = proto_item_add_subtree(main_item, ett_bthsp);
677
678
1
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "HSP");
679
680
1
    switch (pinfo->p2p_dir) {
681
0
        case P2P_DIR_SENT:
682
0
            col_set_str(pinfo->cinfo, COL_INFO, "Sent ");
683
0
            break;
684
0
        case P2P_DIR_RECV:
685
0
            col_set_str(pinfo->cinfo, COL_INFO, "Rcvd ");
686
0
            break;
687
1
        default:
688
1
            col_set_str(pinfo->cinfo, COL_INFO, "UnknownDirection ");
689
1
            break;
690
1
    }
691
692
1
    if ((hsp_role == ROLE_AG && pinfo->p2p_dir == P2P_DIR_SENT) ||
693
1
            (hsp_role == ROLE_HS && pinfo->p2p_dir == P2P_DIR_RECV)) {
694
0
        role = ROLE_AG;
695
1
    } else if (hsp_role != ROLE_UNKNOWN) {
696
0
        role = ROLE_HS;
697
0
    }
698
699
1
    if (role == ROLE_UNKNOWN) {
700
1
        uint32_t         sdp_psm;
701
1
        uint32_t         service_type;
702
1
        uint32_t         service_channel;
703
1
        service_info_t  *service_info;
704
705
1
        sdp_psm         = SDP_PSM_DEFAULT;
706
707
1
        service_type    = BTSDP_RFCOMM_PROTOCOL_UUID;
708
1
        service_channel = dlci >> 1;
709
1
        frame_number    = pinfo->num;
710
711
1
        key[0].length = 1;
712
1
        key[0].key = &interface_id;
713
1
        key[1].length = 1;
714
1
        key[1].key = &adapter_id;
715
1
        key[2].length = 1;
716
1
        key[2].key = &sdp_psm;
717
1
        key[3].length = 1;
718
1
        key[3].key = &direction;
719
1
        key[4].length = 1;
720
1
        key[4].key = &bd_addr_oui;
721
1
        key[5].length = 1;
722
1
        key[5].key = &bd_addr_id;
723
1
        key[6].length = 1;
724
1
        key[6].key = &service_type;
725
1
        key[7].length = 1;
726
1
        key[7].key = &service_channel;
727
1
        key[8].length = 1;
728
1
        key[8].key = &frame_number;
729
1
        key[9].length = 0;
730
1
        key[9].key = NULL;
731
732
1
        service_info = btsdp_get_service_info(key);
733
1
        if (service_info && service_info->interface_id == interface_id &&
734
0
                service_info->adapter_id == adapter_id &&
735
0
                service_info->sdp_psm == SDP_PSM_DEFAULT &&
736
0
                ((service_info->direction == P2P_DIR_RECV &&
737
0
                service_info->bd_addr_oui == bd_addr_oui &&
738
0
                service_info->bd_addr_id == bd_addr_id) ||
739
0
                (service_info->direction != P2P_DIR_RECV &&
740
0
                service_info->bd_addr_oui == 0 &&
741
0
                service_info->bd_addr_id == 0)) &&
742
0
                service_info->type == BTSDP_RFCOMM_PROTOCOL_UUID &&
743
0
                service_info->channel == (dlci >> 1)) {
744
0
            if ((service_info->uuid.bt_uuid == BTSDP_HSP_GW_SERVICE_UUID && service_info->direction == P2P_DIR_RECV && pinfo->p2p_dir == P2P_DIR_SENT) ||
745
0
                (service_info->uuid.bt_uuid == BTSDP_HSP_GW_SERVICE_UUID && service_info->direction == P2P_DIR_SENT && pinfo->p2p_dir == P2P_DIR_RECV) ||
746
0
                ((service_info->uuid.bt_uuid == BTSDP_HSP_SERVICE_UUID || service_info->uuid.bt_uuid == BTSDP_HSP_HS_SERVICE_UUID) && service_info->direction == P2P_DIR_RECV && pinfo->p2p_dir == P2P_DIR_RECV) ||
747
0
                ((service_info->uuid.bt_uuid == BTSDP_HSP_SERVICE_UUID || service_info->uuid.bt_uuid == BTSDP_HSP_HS_SERVICE_UUID) && service_info->direction == P2P_DIR_SENT && pinfo->p2p_dir == P2P_DIR_SENT)) {
748
0
                role = ROLE_HS;
749
0
            } else {
750
0
                role = ROLE_AG;
751
0
            }
752
0
        }
753
1
    }
754
755
1
    pitem = proto_tree_add_uint(main_tree, hf_role, tvb, 0, 0, role);
756
1
    proto_item_set_generated(pitem);
757
758
1
    if (role == ROLE_UNKNOWN) {
759
1
        col_append_fstr(pinfo->cinfo, COL_INFO, "Data: %s",
760
1
                tvb_format_text(pinfo->pool, tvb, 0, tvb_reported_length(tvb)));
761
1
        proto_tree_add_item(main_tree, hf_data, tvb, 0, tvb_captured_length(tvb), ENC_ASCII);
762
1
        return tvb_reported_length(tvb);
763
1
    }
764
765
    /* save fragments */
766
0
    if (!pinfo->fd->visited) {
767
0
        frame_number = pinfo->num - 1;
768
769
0
        key[0].length = 1;
770
0
        key[0].key = &interface_id;
771
0
        key[1].length = 1;
772
0
        key[1].key = &adapter_id;
773
0
        key[2].length = 1;
774
0
        key[2].key = &chandle;
775
0
        key[3].length = 1;
776
0
        key[3].key = &dlci;
777
0
        key[4].length = 1;
778
0
        key[4].key = &role;
779
0
        key[5].length = 1;
780
0
        key[5].key = &frame_number;
781
0
        key[6].length = 0;
782
0
        key[6].key = NULL;
783
784
0
        previous_fragment = (fragment_t *) wmem_tree_lookup32_array_le(fragments, key);
785
0
        if (!(previous_fragment && previous_fragment->interface_id == interface_id &&
786
0
                previous_fragment->adapter_id == adapter_id &&
787
0
                previous_fragment->chandle == chandle &&
788
0
                previous_fragment->dlci == dlci &&
789
0
                previous_fragment->role == role &&
790
0
                previous_fragment->reassemble_state != REASSEMBLE_DONE)) {
791
0
            previous_fragment = NULL;
792
0
        }
793
794
0
        frame_number = pinfo->num;
795
796
0
        key[0].length = 1;
797
0
        key[0].key = &interface_id;
798
0
        key[1].length = 1;
799
0
        key[1].key = &adapter_id;
800
0
        key[2].length = 1;
801
0
        key[2].key = &chandle;
802
0
        key[3].length = 1;
803
0
        key[3].key = &dlci;
804
0
        key[4].length = 1;
805
0
        key[4].key = &role;
806
0
        key[5].length = 1;
807
0
        key[5].key = &frame_number;
808
0
        key[6].length = 0;
809
0
        key[6].key = NULL;
810
811
0
        fragment = wmem_new(wmem_file_scope(), fragment_t);
812
0
        fragment->interface_id      = interface_id;
813
0
        fragment->adapter_id        = adapter_id;
814
0
        fragment->chandle           = chandle;
815
0
        fragment->dlci              = dlci;
816
0
        fragment->role              = role;
817
0
        fragment->idx               = previous_fragment ? previous_fragment->idx + previous_fragment->length : 0;
818
0
        fragment->reassemble_state  = REASSEMBLE_FRAGMENT;
819
0
        fragment->length            = tvb_reported_length(tvb);
820
0
        fragment->data              = (uint8_t *) wmem_alloc(wmem_file_scope(), fragment->length);
821
0
        fragment->previous_fragment = previous_fragment;
822
0
        tvb_memcpy(tvb, fragment->data, offset, fragment->length);
823
824
0
        wmem_tree_insert32_array(fragments, key, fragment);
825
826
        /* Detect reassemble end character: \r for HS or \n for AG */
827
0
        length = tvb_reported_length(tvb);
828
0
        at_stream = tvb_get_string_enc(pinfo->pool, tvb, 0, length, ENC_ASCII);
829
830
0
        reassemble_start_offset = 0;
831
832
0
        for (i_length = 0; i_length < length; i_length += 1) {
833
0
            if (!((role == ROLE_HS && at_stream[i_length] == '\r') ||
834
0
                    (role == ROLE_AG && at_stream[i_length] == '\n'))) {
835
0
                continue;
836
0
            }
837
838
0
            if (role == ROLE_HS && at_stream[i_length] == '\r') {
839
0
                reassemble_start_offset = i_length + 1;
840
0
                if (reassemble_end_offset == 0) reassemble_end_offset = i_length + 1;
841
0
            }
842
843
0
            if (role == ROLE_AG && at_stream[i_length] == '\n') {
844
0
                reassemble_start_offset = i_length + 1;
845
0
            }
846
847
0
            frame_number = pinfo->num;
848
849
0
            key[0].length = 1;
850
0
            key[0].key = &interface_id;
851
0
            key[1].length = 1;
852
0
            key[1].key = &adapter_id;
853
0
            key[2].length = 1;
854
0
            key[2].key = &chandle;
855
0
            key[3].length = 1;
856
0
            key[3].key = &dlci;
857
0
            key[4].length = 1;
858
0
            key[4].key = &role;
859
0
            key[5].length = 1;
860
0
            key[5].key = &frame_number;
861
0
            key[6].length = 0;
862
0
            key[6].key = NULL;
863
864
0
            fragment = (fragment_t *) wmem_tree_lookup32_array_le(fragments, key);
865
0
            if (fragment && fragment->interface_id == interface_id &&
866
0
                    fragment->adapter_id == adapter_id &&
867
0
                    fragment->chandle == chandle &&
868
0
                    fragment->dlci == dlci &&
869
0
                    fragment->role == role) {
870
0
                i_fragment = fragment;
871
0
                while (i_fragment && i_fragment->idx > 0) {
872
0
                    i_fragment = i_fragment->previous_fragment;
873
0
                }
874
875
0
                if (i_length + 1 == length &&
876
0
                        role == ROLE_HS &&
877
0
                        at_stream[i_length] == '\r') {
878
0
                    fragment->reassemble_state = REASSEMBLE_DONE;
879
0
                } else if (i_length + 1 == length &&
880
0
                        role == ROLE_AG &&
881
0
                        i_length >= 4 &&
882
0
                        at_stream[i_length] == '\n' &&
883
0
                        at_stream[i_length - 1] == '\r' &&
884
0
                        at_stream[0] == '\r' &&
885
0
                        at_stream[1] == '\n') {
886
0
                    fragment->reassemble_state = REASSEMBLE_DONE;
887
0
                } else if (i_length + 1 == length &&
888
0
                        role == ROLE_AG &&
889
0
                        i_length >= 2 &&
890
0
                        at_stream[i_length] == '\n' &&
891
0
                        at_stream[i_length - 1] == '\r' &&
892
0
                        i_fragment &&
893
0
                        i_fragment->reassemble_state == REASSEMBLE_FRAGMENT &&
894
0
                        i_fragment->length >= 2 &&
895
0
                        i_fragment->data[0] == '\r' &&
896
0
                        i_fragment->data[1] == '\n') {
897
0
                    fragment->reassemble_state = REASSEMBLE_DONE;
898
0
                } else if (role == ROLE_HS) {
899
/* XXX: Temporary disable reassembling of partial message, it seems to be broken */
900
/*                    fragment->reassemble_state = REASSEMBLE_PARTIALLY;*/
901
0
                }
902
0
                fragment->reassemble_start_offset = reassemble_start_offset;
903
0
                fragment->reassemble_end_offset = reassemble_end_offset;
904
0
            }
905
0
        }
906
0
    }
907
908
    /* recover reassembled payload */
909
0
    frame_number = pinfo->num;
910
911
0
    key[0].length = 1;
912
0
    key[0].key = &interface_id;
913
0
    key[1].length = 1;
914
0
    key[1].key = &adapter_id;
915
0
    key[2].length = 1;
916
0
    key[2].key = &chandle;
917
0
    key[3].length = 1;
918
0
    key[3].key = &dlci;
919
0
    key[4].length = 1;
920
0
    key[4].key = &role;
921
0
    key[5].length = 1;
922
0
    key[5].key = &frame_number;
923
0
    key[6].length = 0;
924
0
    key[6].key = NULL;
925
926
0
    fragment = (fragment_t *) wmem_tree_lookup32_array_le(fragments, key);
927
0
    if (fragment && fragment->interface_id == interface_id &&
928
0
            fragment->adapter_id == adapter_id &&
929
0
            fragment->chandle == chandle &&
930
0
            fragment->dlci == dlci &&
931
0
            fragment->role == role &&
932
0
            fragment->reassemble_state != REASSEMBLE_FRAGMENT) {
933
0
        uint8_t   *at_data;
934
0
        unsigned   i_data_offset;
935
936
0
        i_data_offset = fragment->idx + fragment->length;
937
0
        at_data = (uint8_t *) wmem_alloc(pinfo->pool, fragment->idx + fragment->length);
938
939
0
        i_fragment = fragment;
940
941
0
        if (i_fragment && i_fragment->reassemble_state == REASSEMBLE_PARTIALLY) {
942
0
            i_data_offset -= i_fragment->reassemble_end_offset;
943
0
            memcpy(at_data + i_data_offset, i_fragment->data, i_fragment->reassemble_end_offset);
944
0
            i_fragment = i_fragment->previous_fragment;
945
0
        }
946
947
0
        if (i_fragment) {
948
0
            while (i_fragment && i_fragment->idx > 0) {
949
0
                i_data_offset -= i_fragment->length;
950
0
                memcpy(at_data + i_data_offset, i_fragment->data, i_fragment->length);
951
0
                i_fragment = i_fragment->previous_fragment;
952
0
            }
953
954
0
            if (i_fragment && i_fragment->reassemble_state == REASSEMBLE_PARTIALLY) {
955
0
                i_data_offset -= (i_fragment->length - i_fragment->reassemble_start_offset);
956
0
                memcpy(at_data + i_data_offset, i_fragment->data + i_fragment->reassemble_start_offset,
957
0
                        i_fragment->length - i_fragment->reassemble_start_offset);
958
0
            } else if (i_fragment) {
959
0
                i_data_offset -= i_fragment->length;
960
0
                memcpy(at_data + i_data_offset, i_fragment->data, i_fragment->length);
961
0
            }
962
0
        }
963
964
0
        if (fragment->idx > 0 && fragment->length > 0) {
965
0
            proto_tree_add_item(main_tree, hf_fragment, tvb, offset,
966
0
                    tvb_captured_length_remaining(tvb, offset), ENC_ASCII);
967
0
            reassembled_tvb = tvb_new_child_real_data(tvb, at_data,
968
0
                    fragment->idx + fragment->length, fragment->idx + fragment->length);
969
0
            add_new_data_source(pinfo, reassembled_tvb, "Reassembled HSP");
970
0
        }
971
972
0
        command_number = 0;
973
0
        if (reassembled_tvb) {
974
0
            unsigned reassembled_offset = 0;
975
976
0
            while (tvb_reported_length(reassembled_tvb) > reassembled_offset) {
977
0
                reassembled_offset = dissect_at_command(reassembled_tvb,
978
0
                        pinfo, main_tree, reassembled_offset, role, command_number);
979
0
                command_number += 1;
980
0
            }
981
0
            offset = tvb_captured_length(tvb);
982
0
        } else {
983
0
            while (tvb_reported_length(tvb) > (unsigned) offset) {
984
0
                offset = dissect_at_command(tvb, pinfo, main_tree, offset, role, command_number);
985
0
                command_number += 1;
986
0
            }
987
0
        }
988
0
    } else {
989
0
        pitem = proto_tree_add_item(main_tree, hf_fragmented, tvb, 0, 0, ENC_NA);
990
0
        proto_item_set_generated(pitem);
991
0
        char *display_str;
992
0
        proto_tree_add_item_ret_display_string(main_tree, hf_fragment, tvb, offset, -1, ENC_ASCII, pinfo->pool, &display_str);
993
0
        col_append_fstr(pinfo->cinfo, COL_INFO, "Fragment: %s", display_str);
994
0
        offset = tvb_captured_length(tvb);
995
0
    }
996
997
0
    return offset;
998
1
}
999
1000
void
1001
proto_register_bthsp(void)
1002
15
{
1003
15
    module_t         *module;
1004
15
    expert_module_t  *expert_bthsp;
1005
1006
15
    static hf_register_info hf[] = {
1007
15
        { &hf_command,
1008
15
           { "Command",                          "bthsp.command",
1009
15
           FT_NONE, BASE_NONE, NULL, 0,
1010
15
           NULL, HFILL}
1011
15
        },
1012
15
        { &hf_parameters,
1013
15
           { "Parameters",                       "bthsp.parameters",
1014
15
           FT_NONE, BASE_NONE, NULL, 0,
1015
15
           NULL, HFILL}
1016
15
        },
1017
15
        { &hf_command_in,
1018
15
           { "Command frame number in",          "bthsp.command_in",
1019
15
           FT_FRAMENUM, BASE_NONE, NULL, 0,
1020
15
           NULL, HFILL}
1021
15
        },
1022
15
        { &hf_unsolicited,
1023
15
           { "Unsolicited",                      "bthsp.unsolicited",
1024
15
           FT_NONE, BASE_NONE, NULL, 0,
1025
15
           NULL, HFILL}
1026
15
        },
1027
15
        { &hf_data,
1028
15
           { "AT Stream",                        "bthsp.data",
1029
15
           FT_STRING, BASE_NONE, NULL, 0,
1030
15
           NULL, HFILL}
1031
15
        },
1032
15
        { &hf_fragment,
1033
15
           { "Fragment",                         "bthsp.fragment",
1034
15
           FT_STRING, BASE_NONE, NULL, 0,
1035
15
           NULL, HFILL}
1036
15
        },
1037
15
        { &hf_fragmented,
1038
15
           { "Fragmented",                       "bthsp.fragmented",
1039
15
           FT_NONE, BASE_NONE, NULL, 0,
1040
15
           NULL, HFILL}
1041
15
        },
1042
15
        { &hf_at_ignored,
1043
15
           { "Ignored",                          "bthsp.ignored",
1044
15
           FT_BYTES, BASE_NONE, NULL, 0,
1045
15
           NULL, HFILL}
1046
15
        },
1047
15
        { &hf_at_cmd,
1048
15
           { "Command",                          "bthsp.at_cmd",
1049
15
           FT_STRING, BASE_NONE, NULL, 0,
1050
15
           NULL, HFILL}
1051
15
        },
1052
15
        { &hf_at_cmd_type,
1053
15
           { "Type",                             "bthsp.at_cmd.type",
1054
15
           FT_UINT16, BASE_HEX, VALS(at_cmd_type_vals), 0,
1055
15
           NULL, HFILL}
1056
15
        },
1057
15
        { &hf_at_command_line_prefix,
1058
15
           { "Command Line Prefix",              "bthsp.command_line_prefix",
1059
15
           FT_STRING, BASE_NONE, NULL, 0,
1060
15
           NULL, HFILL}
1061
15
        },
1062
15
        { &hf_parameter,
1063
15
           { "Parameter",                        "bthsp.parameter",
1064
15
           FT_STRING, BASE_NONE, NULL, 0,
1065
15
           NULL, HFILL}
1066
15
        },
1067
15
        { &hf_unknown_parameter,
1068
15
           { "Unknown Parameter",                "bthsp.unknown_parameter",
1069
15
           FT_STRING, BASE_NONE, NULL, 0,
1070
15
           NULL, HFILL}
1071
15
        },
1072
15
        { &hf_role,
1073
15
           { "Role",                             "bthsp.role",
1074
15
           FT_UINT8, BASE_DEC, VALS(role_vals), 0,
1075
15
           NULL, HFILL}
1076
15
        },
1077
15
        { &hf_vgs,
1078
15
           { "Gain",                             "bthsp.vgs",
1079
15
           FT_UINT8, BASE_DEC|BASE_UNIT_STRING, UNS(&units_slash15), 0,
1080
15
           NULL, HFILL}
1081
15
        },
1082
15
        { &hf_vgm,
1083
15
           { "Gain",                             "bthsp.vgm",
1084
15
           FT_UINT8, BASE_DEC|BASE_UNIT_STRING, UNS(&units_slash15), 0,
1085
15
           NULL, HFILL}
1086
15
        },
1087
15
        { &hf_ckpd,
1088
15
           { "Key",                             "bthsp.ckpd",
1089
15
           FT_UINT8, BASE_DEC, NULL, 0,
1090
15
           NULL, HFILL}
1091
15
        }
1092
15
    };
1093
1094
15
    static ei_register_info ei[] = {
1095
15
        { &ei_non_mandatory_command, { "bthsp.expert.non_mandatory_command", PI_PROTOCOL, PI_NOTE, "Non-mandatory command in HSP", EXPFILL }},
1096
15
        { &ei_invalid_usage,         { "bthsp.expert.invalid_usage", PI_PROTOCOL, PI_WARN, "Non mandatory type or command in this role", EXPFILL }},
1097
15
        { &ei_unknown_parameter,     { "bthsp.expert.unknown_parameter", PI_PROTOCOL, PI_WARN, "Unknown parameter", EXPFILL }},
1098
15
        { &ei_vgm_gain,              { "bthsp.expert.vgm", PI_PROTOCOL, PI_WARN, "Gain of microphone exceeds range 0-15", EXPFILL }},
1099
15
        { &ei_vgs_gain,              { "bthsp.expert.vgs", PI_PROTOCOL, PI_WARN, "Gain of speaker exceeds range 0-15", EXPFILL }},
1100
15
        { &ei_ckpd,              { "bthsp.expert.ckpd", PI_PROTOCOL, PI_WARN, "Only key 200 is covered in HSP", EXPFILL }}    };
1101
1102
15
    static int *ett[] = {
1103
15
        &ett_bthsp,
1104
15
        &ett_bthsp_command,
1105
15
        &ett_bthsp_parameters
1106
15
    };
1107
1108
15
    fragments = wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope());
1109
1110
15
    proto_bthsp = proto_register_protocol("Bluetooth HSP Profile", "BT HSP", "bthsp");
1111
15
    bthsp_handle = register_dissector("bthsp", dissect_bthsp, proto_bthsp);
1112
1113
15
    proto_register_field_array(proto_bthsp, hf, array_length(hf));
1114
15
    proto_register_subtree_array(ett, array_length(ett));
1115
1116
15
    module = prefs_register_protocol_subtree("Bluetooth", proto_bthsp, NULL);
1117
15
    prefs_register_static_text_preference(module, "hsp.version",
1118
15
            "Bluetooth Profile HSP version: 1.2",
1119
15
            "Version of profile supported by this dissector.");
1120
1121
15
    prefs_register_enum_preference(module, "hsp.hsp_role",
1122
15
            "Force treat packets as AG or HS role",
1123
15
            "Force treat packets as AG or HS role",
1124
15
            &hsp_role, pref_hsp_role, true);
1125
1126
15
    expert_bthsp = expert_register_protocol(proto_bthsp);
1127
15
    expert_register_field_array(expert_bthsp, ei, array_length(ei));
1128
15
}
1129
1130
void
1131
proto_reg_handoff_bthsp(void)
1132
15
{
1133
15
    dissector_add_string("bluetooth.uuid",  "1108", bthsp_handle);
1134
15
    dissector_add_string("bluetooth.uuid",  "1112", bthsp_handle);
1135
15
    dissector_add_string("bluetooth.uuid",  "1131", bthsp_handle);
1136
1137
15
    dissector_add_for_decode_as("btrfcomm.dlci", bthsp_handle);
1138
15
}
1139
1140
/*
1141
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
1142
 *
1143
 * Local variables:
1144
 * c-basic-offset: 4
1145
 * tab-width: 8
1146
 * indent-tabs-mode: nil
1147
 * End:
1148
 *
1149
 * vi: set shiftwidth=4 tabstop=8 expandtab:
1150
 * :indentSize=4:tabSize=8:noTabs=true:
1151
 */