Coverage Report

Created: 2025-02-15 06:25

/src/wireshark/epan/dissectors/packet-bthcrp.c
Line
Count
Source (jump to first uncovered line)
1
/* packet-bthcrp.c
2
 * Routines for Bluetooth HCRP dissection
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
19
#include "packet-btl2cap.h"
20
#include "packet-btsdp.h"
21
22
enum {
23
    FORCE_CLIENT_DEFAULT  = 0,
24
    FORCE_CLIENT_YES      = 1,
25
    FORCE_CLIENT_NO       = 2
26
};
27
28
static int proto_bthcrp;
29
30
static int hf_bthcrp_notification_pdu_id;
31
static int hf_bthcrp_control_pdu_id;
32
static int hf_bthcrp_control_transaction_id;
33
static int hf_bthcrp_control_parameter_length;
34
static int hf_bthcrp_control_status;
35
static int hf_bthcrp_callback_context_id;
36
static int hf_bthcrp_control_callback_timeout;
37
static int hf_bthcrp_control_timeout;
38
static int hf_bthcrp_control_1284_id;
39
static int hf_bthcrp_control_register;
40
static int hf_bthcrp_control_start_byte;
41
static int hf_bthcrp_control_number_of_bytes;
42
static int hf_bthcrp_control_client_credit_granted;
43
static int hf_bthcrp_control_server_credit_granted;
44
static int hf_bthcrp_control_client_credit_return;
45
static int hf_bthcrp_control_server_credit_return;
46
static int hf_bthcrp_control_client_credit_query;
47
static int hf_bthcrp_control_server_credit_query;
48
static int hf_bthcrp_control_status_reserved_76;
49
static int hf_bthcrp_control_status_paper_empty;
50
static int hf_bthcrp_control_status_select;
51
static int hf_bthcrp_control_status_not_error;
52
static int hf_bthcrp_control_status_reserved_20;
53
static int hf_bthcrp_data;
54
55
static int ett_bthcrp;
56
57
static expert_field ei_bthcrp_control_parameter_length;
58
static expert_field ei_bthcrp_unexpected_data;
59
60
static dissector_handle_t bthcrp_handle;
61
62
static int      force_client     = FORCE_CLIENT_DEFAULT;
63
static int      psm_control;
64
static int      psm_data_stream;
65
static int      psm_notification;
66
67
static const value_string control_pdu_id_vals[] = {
68
    { 0x0001,   "CR_DataChannelCreditGrant" },
69
    { 0x0002,   "CR_DataChannelCreditRequest" },
70
    { 0x0003,   "CR_DataChannelCreditReturn" },
71
    { 0x0004,   "CR_DataChannelCreditQuery" },
72
    { 0x0005,   "CR_GetLPTStatus" },
73
    { 0x0006,   "CR_Get1284ID" },
74
    { 0x0007,   "CR_SoftReset" },
75
    { 0x0008,   "CR_HardReset" },
76
    { 0x0009,   "CR_RegisterNotification" },
77
    { 0x000A,   "CR_NotificationConnectionAlive" },
78
    { 0, NULL }
79
};
80
81
static const value_string status_vals[] = {
82
    { 0x0000,   "Feature Unsupported" },
83
    { 0x0001,   "Success" },
84
    { 0x0002,   "Credit Synchronization Error" },
85
    { 0xFFFF,   "Generic Failure" },
86
    { 0, NULL }
87
};
88
89
static const value_string notification_pdu_id_vals[] = {
90
    { 0x0001,   "N_Notification" },
91
    { 0, NULL }
92
};
93
94
static const value_string register_vals[] = {
95
    { 0x00,   "Remove Client From Receiver Notification" },
96
    { 0x01,   "Add Client To Receiver Notification" },
97
    { 0, NULL }
98
};
99
100
static const enum_val_t force_client_enum[] = {
101
    { "default",  "Default",  FORCE_CLIENT_DEFAULT },
102
    { "yes",      "Yes",      FORCE_CLIENT_YES },
103
    { "no",       "No",       FORCE_CLIENT_NO },
104
    { NULL, NULL, 0 }
105
};
106
107
void proto_register_bthcrp(void);
108
void proto_reg_handoff_bthcrp(void);
109
110
111
static int
112
dissect_control(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
113
        int offset,  bool is_client_message)
114
0
{
115
    /* flow: requests: only client -> server; responses: only server ->  */
116
0
    proto_item   *pitem;
117
0
    uint16_t      control_pdu_id;
118
0
    unsigned      credits;
119
0
    unsigned      timeout;
120
0
    unsigned      context_id;
121
0
    unsigned      notification_register;
122
0
    unsigned      number;
123
0
    int           parameter_length;
124
125
0
    pitem = proto_tree_add_item(tree, hf_bthcrp_control_pdu_id, tvb, offset, 2, ENC_BIG_ENDIAN);
126
0
    control_pdu_id = tvb_get_ntohs(tvb, offset);
127
0
    offset += 2;
128
129
0
    col_append_fstr(pinfo->cinfo, COL_INFO, "Control: %s %s",
130
0
            ((is_client_message) ? "Request" : "Response"),
131
0
            val_to_str_const(control_pdu_id, control_pdu_id_vals,  "Unknown PDU ID"));
132
133
0
    if (control_pdu_id >= 0x8000) {
134
0
        proto_item_append_text(pitem, " (Vendor Specific)");
135
0
        col_append_str(pinfo->cinfo, COL_INFO, " (Vendor Specific)");
136
0
    } else if (control_pdu_id == 0x0000 || control_pdu_id >= 0x000B ) {
137
0
        proto_item_append_text(pitem, " (Reserved)");
138
0
        col_append_str(pinfo->cinfo, COL_INFO, " (Reserved)");
139
0
    }
140
141
0
    proto_tree_add_item(tree, hf_bthcrp_control_transaction_id, tvb, offset, 2, ENC_BIG_ENDIAN);
142
0
    offset += 2;
143
144
0
    pitem = proto_tree_add_item(tree, hf_bthcrp_control_parameter_length, tvb, offset, 2, ENC_BIG_ENDIAN);
145
0
    parameter_length = tvb_get_ntohs(tvb, offset);
146
0
    offset += 2;
147
148
0
    if (!is_client_message && parameter_length < 2) {
149
0
        expert_add_info_format(pinfo, pitem, &ei_bthcrp_control_parameter_length,
150
0
                "Parameter length is shorter than 2 in response");
151
0
    }
152
153
0
    if (parameter_length < tvb_reported_length_remaining(tvb, offset)) {
154
0
        expert_add_info_format(pinfo, pitem, &ei_bthcrp_control_parameter_length,
155
0
                "Parameter length is shorter than payload length");
156
0
    } else if (parameter_length > tvb_reported_length_remaining(tvb, offset)) {
157
0
        expert_add_info_format(pinfo, pitem, &ei_bthcrp_control_parameter_length,
158
0
                "Parameter length is larger than payload length");
159
0
    }
160
161
0
    if (!is_client_message) {
162
0
        proto_tree_add_item(tree, hf_bthcrp_control_status, tvb, offset, 2, ENC_BIG_ENDIAN);
163
0
        offset += 2;
164
0
    }
165
166
0
    if (control_pdu_id >= 0x8000) {
167
0
        if (tvb_reported_length_remaining(tvb, offset)) {
168
0
            proto_tree_add_item(tree, hf_bthcrp_data, tvb, offset, tvb_reported_length_remaining(tvb, offset), ENC_NA);
169
0
            offset += tvb_reported_length_remaining(tvb, offset);
170
0
        }
171
0
    } else switch(control_pdu_id) {
172
0
        case 0x0001: /* CR_DataChannelCreditGrant */
173
0
            if (is_client_message) {
174
0
                proto_tree_add_item(tree, hf_bthcrp_control_client_credit_granted, tvb, offset, 4, ENC_BIG_ENDIAN);
175
0
                credits = tvb_get_ntohl(tvb, offset);
176
0
                col_append_fstr(pinfo->cinfo, COL_INFO, " - CreditGranted: %u", credits);
177
0
                offset += 4;
178
0
            }
179
0
            break;
180
0
        case 0x0002: /* CR_DataChannelCreditRequest */
181
0
            if (!is_client_message) {
182
0
                proto_tree_add_item(tree, hf_bthcrp_control_server_credit_granted, tvb, offset, 4, ENC_BIG_ENDIAN);
183
0
                credits = tvb_get_ntohl(tvb, offset);
184
0
                col_append_fstr(pinfo->cinfo, COL_INFO, " - CreditGranted: %u", credits);
185
0
                offset += 4;
186
0
            }
187
0
            break;
188
0
        case 0x0003: /* CR_DataChannelCreditReturn */
189
0
            if (is_client_message) {
190
0
                proto_tree_add_item(tree, hf_bthcrp_control_client_credit_return, tvb, offset, 4, ENC_BIG_ENDIAN);
191
0
                credits = tvb_get_ntohl(tvb, offset);
192
0
                col_append_fstr(pinfo->cinfo, COL_INFO, " - Client Credit Return: %u", credits);
193
0
                offset += 4;
194
0
            } else {
195
0
                proto_tree_add_item(tree, hf_bthcrp_control_server_credit_return, tvb, offset, 4, ENC_BIG_ENDIAN);
196
0
                credits = tvb_get_ntohl(tvb, offset);
197
0
                col_append_fstr(pinfo->cinfo, COL_INFO, " - Server Credit Return: %u", credits);
198
0
                offset += 4;
199
0
            }
200
0
            break;
201
0
        case 0x0004: /* CR_DataChannelCreditQuery */
202
0
            if (is_client_message) {
203
0
                proto_tree_add_item(tree, hf_bthcrp_control_client_credit_query, tvb, offset, 4, ENC_BIG_ENDIAN);
204
0
                credits = tvb_get_ntohl(tvb, offset);
205
0
                col_append_fstr(pinfo->cinfo, COL_INFO, " - Client Credit: %u", credits);
206
0
                offset += 4;
207
0
            } else {
208
0
                proto_tree_add_item(tree, hf_bthcrp_control_server_credit_query, tvb, offset, 4, ENC_BIG_ENDIAN);
209
0
                credits = tvb_get_ntohl(tvb, offset);
210
0
                col_append_fstr(pinfo->cinfo, COL_INFO, " - Server Credit: %u", credits);
211
0
                offset += 4;
212
0
            }
213
0
            break;
214
0
        case 0x0005: /* CR_GetLPTStatus */
215
0
            if (!is_client_message) {
216
0
                proto_tree_add_item(tree, hf_bthcrp_control_status_reserved_76, tvb, offset, 1, ENC_BIG_ENDIAN);
217
0
                proto_tree_add_item(tree, hf_bthcrp_control_status_paper_empty, tvb, offset, 1, ENC_BIG_ENDIAN);
218
0
                proto_tree_add_item(tree, hf_bthcrp_control_status_select, tvb, offset, 1, ENC_BIG_ENDIAN);
219
0
                proto_tree_add_item(tree, hf_bthcrp_control_status_not_error, tvb, offset, 1, ENC_BIG_ENDIAN);
220
0
                proto_tree_add_item(tree, hf_bthcrp_control_status_reserved_20, tvb, offset, 1, ENC_BIG_ENDIAN);
221
0
                offset += 1;
222
0
            }
223
0
            break;
224
0
        case 0x0006: /* CR_Get1284ID */
225
0
            if (is_client_message) {
226
0
                proto_tree_add_item(tree, hf_bthcrp_control_start_byte, tvb, offset, 2, ENC_BIG_ENDIAN);
227
0
                number = tvb_get_ntohs(tvb, offset);
228
0
                col_append_fstr(pinfo->cinfo, COL_INFO, " - Start Byte: %u", number);
229
0
                offset += 2;
230
231
0
                proto_tree_add_item(tree, hf_bthcrp_control_number_of_bytes, tvb, offset, 2, ENC_BIG_ENDIAN);
232
0
                number = tvb_get_ntohs(tvb, offset);
233
0
                col_append_fstr(pinfo->cinfo, COL_INFO, ", Number Of Bytes: %u", number);
234
0
                offset += 2;
235
0
            } else {
236
0
                const uint8_t *id;
237
238
0
                proto_tree_add_item_ret_string(tree, hf_bthcrp_control_1284_id, tvb, offset, tvb_reported_length_remaining(tvb, offset), ENC_ASCII | ENC_NA, pinfo->pool, &id);
239
0
                col_append_fstr(pinfo->cinfo, COL_INFO, " - 1284 ID: %s", id);
240
0
                offset += tvb_reported_length_remaining(tvb, offset);
241
0
            }
242
0
            break;
243
0
        case 0x0007: /* CR_SoftReset */
244
0
        case 0x0008: /* CR_HardReset */
245
0
            break;
246
0
        case 0x0009: /* CR_RegisterNotification */
247
0
            if (is_client_message) {
248
0
                proto_tree_add_item(tree, hf_bthcrp_control_register, tvb, offset, 1, ENC_BIG_ENDIAN);
249
0
                notification_register = tvb_get_uint8(tvb, offset);
250
0
                col_append_fstr(pinfo->cinfo, COL_INFO, " -  Register: %s", val_to_str_const(notification_register, register_vals, "unknown register"));
251
0
                offset += 1;
252
253
0
                proto_tree_add_item(tree, hf_bthcrp_callback_context_id, tvb, offset, 4, ENC_BIG_ENDIAN);
254
0
                context_id = tvb_get_ntohl(tvb, offset);
255
0
                col_append_fstr(pinfo->cinfo, COL_INFO, ", Callback ContextID: %u", context_id);
256
0
                offset += 4;
257
258
0
                proto_tree_add_item(tree, hf_bthcrp_control_callback_timeout, tvb, offset, 4, ENC_BIG_ENDIAN);
259
0
                timeout = tvb_get_ntohl(tvb, offset);
260
0
                col_append_fstr(pinfo->cinfo, COL_INFO, ", Callback Timeout: %u", timeout);
261
0
                offset += 4;
262
0
            } else {
263
0
                proto_tree_add_item(tree, hf_bthcrp_control_timeout, tvb, offset, 4, ENC_BIG_ENDIAN);
264
0
                timeout = tvb_get_ntohl(tvb, offset);
265
0
                col_append_fstr(pinfo->cinfo, COL_INFO, " - Timeout: %u", timeout);
266
0
                offset += 4;
267
268
0
                proto_tree_add_item(tree, hf_bthcrp_control_callback_timeout, tvb, offset, 4, ENC_BIG_ENDIAN);
269
0
                timeout = tvb_get_ntohl(tvb, offset);
270
0
                col_append_fstr(pinfo->cinfo, COL_INFO, ", Callback Timeout: %u", timeout);
271
0
                offset += 4;
272
0
            }
273
0
            break;
274
0
        case 0x000A: /* CR_NotificationConnectionAlive */
275
0
            if (!is_client_message) {
276
0
                proto_tree_add_item(tree, hf_bthcrp_control_timeout, tvb, offset, 4, ENC_BIG_ENDIAN);
277
0
                timeout = tvb_get_ntohl(tvb, offset);
278
0
                col_append_fstr(pinfo->cinfo, COL_INFO, " - Timeout: %u", timeout);
279
0
                offset += 4;
280
0
            }
281
0
            break;
282
0
    }
283
284
0
    return offset;
285
0
}
286
287
288
static int
289
dissect_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset)
290
0
{
291
    /* flow: server <-> client */
292
0
    tvbuff_t *next_tvb;
293
294
0
    col_append_str(pinfo->cinfo, COL_INFO, "HCRP data stream");
295
296
0
    next_tvb = tvb_new_subset_remaining(tvb, offset);
297
0
    call_data_dissector(next_tvb, pinfo, tree);
298
299
0
    offset += tvb_reported_length_remaining(tvb, offset);
300
301
0
    return offset;
302
0
}
303
304
305
static int
306
dissect_notification(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
307
        int offset, bool is_client_message)
308
0
{
309
    /* flow: only server -> client */
310
0
    uint16_t      notification_pdu_id;
311
0
    proto_item   *pitem;
312
313
0
    if (is_client_message) {
314
0
        col_append_str(pinfo->cinfo, COL_INFO, "Notification: unexpected notification stream");
315
0
        return offset;
316
0
    }
317
318
0
    pitem = proto_tree_add_item(tree, hf_bthcrp_notification_pdu_id, tvb, offset, 2, ENC_BIG_ENDIAN);
319
0
    notification_pdu_id = tvb_get_ntohs(tvb, offset);
320
0
    offset += 2;
321
322
0
    col_append_fstr(pinfo->cinfo, COL_INFO, "Notification: %s", val_to_str_const(notification_pdu_id, notification_pdu_id_vals,  "Unknown PDU ID"));
323
324
0
    if (notification_pdu_id >= 0x8000) {
325
0
        proto_item_append_text(pitem, " (Vendor Specific)");
326
0
        col_append_str(pinfo->cinfo, COL_INFO, " (Vendor Specific)");
327
0
        if (tvb_reported_length_remaining(tvb, offset)) {
328
0
            proto_tree_add_item(tree, hf_bthcrp_data, tvb, offset, tvb_reported_length_remaining(tvb, offset), ENC_NA);
329
0
            offset += tvb_reported_length_remaining(tvb, offset);
330
0
        }
331
0
    } else if (notification_pdu_id != 0x001) {
332
0
        proto_item_append_text(pitem, " (Reserved)");
333
0
        col_append_str(pinfo->cinfo, COL_INFO, " (Reserved)");
334
0
    }
335
336
0
    switch(notification_pdu_id) {
337
0
        case 0x01: /* N_NOTIFICATION */
338
0
            proto_tree_add_item(tree, hf_bthcrp_callback_context_id, tvb, offset, 4, ENC_BIG_ENDIAN);
339
0
            offset += 4;
340
0
            break;
341
0
    }
342
343
0
    return offset;
344
0
}
345
346
static int
347
dissect_bthcrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
348
0
{
349
0
    proto_item      *main_item;
350
0
    proto_tree      *main_tree;
351
0
    int              offset = 0;
352
0
    int              protocol = -1;
353
0
    bool             is_client_message = false;
354
0
    int              previous_proto;
355
356
0
    previous_proto = (GPOINTER_TO_INT(wmem_list_frame_data(wmem_list_frame_prev(wmem_list_tail(pinfo->layers)))));
357
0
    if (previous_proto == proto_btl2cap) {
358
0
        btl2cap_data_t  *l2cap_data;
359
0
        wmem_tree_key_t  key[10];
360
0
        uint32_t         interface_id;
361
0
        uint32_t         adapter_id;
362
0
        uint32_t         sdp_psm = SDP_PSM_DEFAULT;
363
0
        uint32_t         direction;
364
0
        uint32_t         bd_addr_oui;
365
0
        uint32_t         bd_addr_id;
366
0
        uint32_t         service_type;
367
0
        uint32_t         service_channel;
368
0
        uint32_t         frame_number;
369
0
        service_info_t  *service_info;
370
371
0
        l2cap_data = (btl2cap_data_t *) data;
372
373
0
        interface_id       = l2cap_data->interface_id;
374
0
        adapter_id         = l2cap_data->adapter_id;
375
376
0
        direction       = (l2cap_data->is_local_psm) ? P2P_DIR_SENT : P2P_DIR_RECV;
377
0
        if (direction == P2P_DIR_RECV) {
378
0
            bd_addr_oui = l2cap_data->remote_bd_addr_oui;
379
0
            bd_addr_id  = l2cap_data->remote_bd_addr_id;
380
0
        } else {
381
0
            bd_addr_oui = 0;
382
0
            bd_addr_id  = 0;
383
0
        }
384
385
0
        service_type    = BTSDP_L2CAP_PROTOCOL_UUID;
386
0
        service_channel = l2cap_data->psm;
387
0
        frame_number    = pinfo->num;
388
389
0
        key[0].length = 1;
390
0
        key[0].key = &interface_id;
391
0
        key[1].length = 1;
392
0
        key[1].key = &adapter_id;
393
0
        key[2].length = 1;
394
0
        key[2].key = &sdp_psm;
395
0
        key[3].length = 1;
396
0
        key[3].key = &direction;
397
0
        key[4].length = 1;
398
0
        key[4].key = &bd_addr_oui;
399
0
        key[5].length = 1;
400
0
        key[5].key = &bd_addr_id;
401
0
        key[6].length = 1;
402
0
        key[6].key = &service_type;
403
0
        key[7].length = 1;
404
0
        key[7].key = &service_channel;
405
0
        key[8].length = 1;
406
0
        key[8].key = &frame_number;
407
0
        key[9].length = 0;
408
0
        key[9].key = NULL;
409
410
0
        service_info = btsdp_get_service_info(key);
411
0
        if (service_info && service_info->interface_id == interface_id &&
412
0
                service_info->adapter_id == adapter_id &&
413
0
                service_info->sdp_psm == SDP_PSM_DEFAULT &&
414
0
                ((service_info->direction == P2P_DIR_RECV &&
415
0
                service_info->bd_addr_oui == bd_addr_oui &&
416
0
                service_info->bd_addr_id == bd_addr_id) ||
417
0
                (service_info->direction != P2P_DIR_RECV &&
418
0
                service_info->bd_addr_oui == 0 &&
419
0
                service_info->bd_addr_id == 0)) &&
420
0
                service_info->type == BTSDP_L2CAP_PROTOCOL_UUID &&
421
0
                service_info->channel == l2cap_data->psm) {
422
423
0
            if ((service_info->protocol == BTSDP_HARDCOPY_CONTROL_CHANNEL_PROTOCOL_UUID ||
424
0
                    service_info->protocol == BTSDP_HARDCOPY_DATA_CHANNEL_PROTOCOL_UUID) &&
425
0
                    ((!l2cap_data->is_local_psm && pinfo->p2p_dir == P2P_DIR_SENT) ||
426
0
                    (l2cap_data->is_local_psm && pinfo->p2p_dir == P2P_DIR_RECV))) {
427
0
                is_client_message = true;
428
0
            } else if (service_info->protocol == BTSDP_HARDCOPY_NOTIFICATION_PROTOCOL_UUID &&
429
0
                    ((l2cap_data->is_local_psm && pinfo->p2p_dir == P2P_DIR_SENT) ||
430
0
                    (!l2cap_data->is_local_psm && pinfo->p2p_dir == P2P_DIR_RECV))) {
431
0
                is_client_message = true;
432
0
            }
433
434
0
            protocol = service_info->protocol;
435
0
        }
436
437
0
        if (psm_control != 0 && l2cap_data->psm == psm_control) {
438
0
            protocol = BTSDP_HARDCOPY_CONTROL_CHANNEL_PROTOCOL_UUID;
439
0
        } else if (psm_data_stream != 0 && l2cap_data->psm == psm_data_stream) {
440
0
            protocol = BTSDP_HARDCOPY_DATA_CHANNEL_PROTOCOL_UUID;
441
0
        } else if (psm_notification != 0 && l2cap_data->psm == psm_notification) {
442
0
            protocol = BTSDP_HARDCOPY_NOTIFICATION_PROTOCOL_UUID;
443
0
        }
444
445
0
    }
446
447
0
    main_item = proto_tree_add_item(tree, proto_bthcrp, tvb, offset, -1, ENC_NA);
448
0
    main_tree = proto_item_add_subtree(main_item, ett_bthcrp);
449
450
0
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "HCRP");
451
452
0
    switch (pinfo->p2p_dir) {
453
0
        case P2P_DIR_SENT:
454
0
            col_set_str(pinfo->cinfo, COL_INFO, "Sent ");
455
0
            break;
456
0
        case P2P_DIR_RECV:
457
0
            col_set_str(pinfo->cinfo, COL_INFO, "Rcvd ");
458
0
            break;
459
0
        default:
460
0
            col_set_str(pinfo->cinfo, COL_INFO, "UnknownDirection ");
461
0
            break;
462
0
    }
463
464
0
    if (force_client != FORCE_CLIENT_DEFAULT) {
465
0
        is_client_message = (force_client == FORCE_CLIENT_YES && pinfo->p2p_dir == P2P_DIR_SENT) ||
466
0
                (force_client != FORCE_CLIENT_YES && pinfo->p2p_dir == P2P_DIR_RECV);
467
0
    }
468
469
0
    if (protocol == BTSDP_HARDCOPY_CONTROL_CHANNEL_PROTOCOL_UUID) {
470
0
        offset = dissect_control(tvb, pinfo, main_tree, offset, is_client_message);
471
0
    } else if (protocol == BTSDP_HARDCOPY_DATA_CHANNEL_PROTOCOL_UUID) {
472
0
        offset = dissect_data(tvb, pinfo, main_tree, offset);
473
0
    } else if (protocol == BTSDP_HARDCOPY_NOTIFICATION_PROTOCOL_UUID) {
474
0
        offset = dissect_notification(tvb, pinfo, main_tree, offset, is_client_message);
475
0
    } else {
476
0
        col_append_str(pinfo->cinfo, COL_INFO, "HCRP stream");
477
0
    }
478
479
0
    if (tvb_reported_length_remaining(tvb, offset)) {
480
0
        proto_item *pitem;
481
482
0
        pitem = proto_tree_add_item(main_tree, hf_bthcrp_data, tvb, offset, tvb_reported_length_remaining(tvb, offset), ENC_NA);
483
0
        expert_add_info(pinfo, pitem, &ei_bthcrp_unexpected_data);
484
0
    }
485
486
0
    return offset;
487
0
}
488
489
490
void
491
proto_register_bthcrp(void)
492
14
{
493
14
    module_t *module;
494
14
    expert_module_t* expert_bthcrp;
495
496
14
    static hf_register_info hf[] = {
497
14
        { &hf_bthcrp_control_pdu_id,
498
14
            { "Control PDU ID",                  "bthcrp.control.pdu_id",
499
14
            FT_UINT16, BASE_HEX, VALS(control_pdu_id_vals), 0x00,
500
14
            NULL, HFILL }
501
14
        },
502
14
        { &hf_bthcrp_control_transaction_id,
503
14
            { "Transaction ID",                  "bthcrp.control.transaction_id",
504
14
            FT_UINT16, BASE_HEX, NULL, 0x00,
505
14
            NULL, HFILL }
506
14
        },
507
14
        { &hf_bthcrp_control_parameter_length,
508
14
            { "Parameter Length",                "bthcrp.control.parameter_length",
509
14
            FT_UINT16, BASE_HEX, NULL, 0x00,
510
14
            NULL, HFILL }
511
14
        },
512
14
        { &hf_bthcrp_control_status,
513
14
            { "Status",                          "bthcrp.control.status",
514
14
            FT_UINT16, BASE_HEX, VALS(status_vals), 0x00,
515
14
            NULL, HFILL }
516
14
        },
517
14
        { &hf_bthcrp_notification_pdu_id,
518
14
            { "Notification PDU ID",             "bthcrp.notification.pdu_id",
519
14
            FT_UINT16, BASE_HEX, VALS(notification_pdu_id_vals), 0x00,
520
14
            NULL, HFILL }
521
14
        },
522
14
        { &hf_bthcrp_callback_context_id,
523
14
            { "Callback Context ID",             "bthcrp.callback.context_id",
524
14
            FT_UINT32, BASE_HEX, NULL, 0x00,
525
14
            NULL, HFILL }
526
14
        },
527
14
        { &hf_bthcrp_control_callback_timeout,
528
14
            { "Callback Timeout",                "bthcrp.callback.timeout",
529
14
            FT_UINT32, BASE_DEC, NULL, 0x00,
530
14
            NULL, HFILL }
531
14
        },
532
14
        { &hf_bthcrp_control_timeout,
533
14
            { "Timeout",                         "bthcrp.timeout",
534
14
            FT_UINT32, BASE_DEC, NULL, 0x00,
535
14
            NULL, HFILL }
536
14
        },
537
14
        { &hf_bthcrp_control_register,
538
14
            { "Register",                        "bthcrp.register",
539
14
            FT_UINT8, BASE_HEX, VALS(register_vals), 0x00,
540
14
            NULL, HFILL }
541
14
        },
542
14
        { &hf_bthcrp_control_1284_id,
543
14
            { "1284 ID",                         "bthcrp.1284_id",
544
14
            FT_STRING, BASE_NONE, NULL, 0x00,
545
14
            NULL, HFILL }
546
14
        },
547
14
        { &hf_bthcrp_control_start_byte,
548
14
            { "Start Byte",                      "bthcrp.start_byte",
549
14
            FT_UINT16, BASE_DEC, NULL, 0x00,
550
14
            NULL, HFILL }
551
14
        },
552
14
        { &hf_bthcrp_control_number_of_bytes,
553
14
            { "Number Of Bytes",                 "bthcrp.number_of_bytes",
554
14
            FT_UINT16, BASE_DEC, NULL, 0x00,
555
14
            NULL, HFILL }
556
14
        },
557
14
        { &hf_bthcrp_control_client_credit_granted,
558
14
            { "Client Credit Granted",           "bthcrp.client_credit_granted",
559
14
            FT_UINT32, BASE_DEC, NULL, 0x00,
560
14
            NULL, HFILL }
561
14
        },
562
14
        { &hf_bthcrp_control_server_credit_granted,
563
14
            { "Server Credit Granted",           "bthcrp.server_credit_granted",
564
14
            FT_UINT32, BASE_DEC, NULL, 0x00,
565
14
            NULL, HFILL }
566
14
        },
567
14
        { &hf_bthcrp_control_client_credit_return,
568
14
            { "Client Credit Return",            "bthcrp.client_credit_return",
569
14
            FT_UINT32, BASE_DEC, NULL, 0x00,
570
14
            NULL, HFILL }
571
14
        },
572
14
        { &hf_bthcrp_control_server_credit_return,
573
14
            { "Server Credit Return",            "bthcrp.server_credit_return",
574
14
            FT_UINT32, BASE_DEC, NULL, 0x00,
575
14
            NULL, HFILL }
576
14
        },
577
14
        { &hf_bthcrp_control_client_credit_query,
578
14
            { "Client Credit Query",             "bthcrp.client_credit_query",
579
14
            FT_UINT32, BASE_DEC, NULL, 0x00,
580
14
            NULL, HFILL }
581
14
        },
582
14
        { &hf_bthcrp_control_server_credit_query,
583
14
            { "Server Credit Query",             "bthcrp.server_credit_query",
584
14
            FT_UINT32, BASE_DEC, NULL, 0x00,
585
14
            NULL, HFILL }
586
14
        },
587
14
        { &hf_bthcrp_control_status_reserved_76,
588
14
            { "Reserved",                        "bthcrp.status.reserved76",
589
14
            FT_UINT8, BASE_DEC, NULL, 0xC0,
590
14
            NULL, HFILL }
591
14
        },
592
14
        { &hf_bthcrp_control_status_paper_empty,
593
14
            { "Paper Empty",                     "bthcrp.status.paper_empty",
594
14
            FT_BOOLEAN, 8, NULL, 0x20,
595
14
            NULL, HFILL }
596
14
        },
597
14
        { &hf_bthcrp_control_status_select,
598
14
            { "Select",                          "bthcrp.status.select",
599
14
            FT_BOOLEAN, 8, NULL, 0x10,
600
14
            NULL, HFILL }
601
14
        },
602
14
        { &hf_bthcrp_control_status_not_error,
603
14
            { "Not Error",                       "bthcrp.status.not_error",
604
14
            FT_BOOLEAN, 8, NULL, 0x08,
605
14
            NULL, HFILL }
606
14
        },
607
14
        { &hf_bthcrp_control_status_reserved_20,
608
14
            { "Reserved",                        "bthcrp.status.reserved210",
609
14
            FT_UINT8, BASE_HEX, NULL, 0x07,
610
14
            NULL, HFILL }
611
14
        },
612
14
        { &hf_bthcrp_data,
613
14
            { "Data",                            "bthcrp.data",
614
14
            FT_NONE, BASE_NONE, NULL, 0x00,
615
14
            NULL, HFILL }
616
14
        }
617
14
    };
618
619
14
    static int *ett[] = {
620
14
        &ett_bthcrp
621
14
    };
622
623
14
    static ei_register_info ei[] = {
624
14
        { &ei_bthcrp_control_parameter_length, { "bthcrp.control_parameter_length.bad", PI_PROTOCOL, PI_WARN, "Length bad", EXPFILL }},
625
14
        { &ei_bthcrp_unexpected_data, { "bthcrp.unexpected_data", PI_PROTOCOL, PI_WARN, "Unexpected data", EXPFILL }},
626
14
    };
627
628
14
    proto_bthcrp = proto_register_protocol("Bluetooth HCRP Profile", "BT HCRP", "bthcrp");
629
14
    bthcrp_handle = register_dissector("bthcrp", dissect_bthcrp, proto_bthcrp);
630
631
14
    proto_register_field_array(proto_bthcrp, hf, array_length(hf));
632
14
    proto_register_subtree_array(ett, array_length(ett));
633
14
    expert_bthcrp = expert_register_protocol(proto_bthcrp);
634
14
    expert_register_field_array(expert_bthcrp, ei, array_length(ei));
635
636
14
    module = prefs_register_protocol_subtree("Bluetooth", proto_bthcrp, NULL);
637
14
    prefs_register_static_text_preference(module, "hcrp.version",
638
14
            "Bluetooth Profile HCRP version: 1.2",
639
14
            "Version of profile supported by this dissector.");
640
641
14
    prefs_register_obsolete_preference(module, "hcrp.is_client");
642
643
14
    prefs_register_enum_preference(module, "hcrp.force_client", "Force Client",
644
14
         "If \"yes\" localhost will be treat as Client, \"no\" as Server",
645
14
         &force_client, force_client_enum, false);
646
647
14
    prefs_register_uint_preference(module, "hcrp.control.psm", "L2CAP PSM for Control",
648
14
         "L2CAP PSM for Control",
649
14
         10, &psm_control);
650
14
    prefs_register_uint_preference(module, "hcrp.data.psm", "L2CAP PSM for Data",
651
14
         "L2CAP PSM for Data",
652
14
         10, &psm_data_stream);
653
14
    prefs_register_uint_preference(module, "hcrp.notification.psm", "L2CAP PSM for Notification",
654
14
         "L2CAP PSM for Notification",
655
14
         10, &psm_notification);
656
14
}
657
658
void
659
proto_reg_handoff_bthcrp(void)
660
14
{
661
14
    dissector_add_string("bluetooth.uuid", "12", bthcrp_handle);
662
14
    dissector_add_string("bluetooth.uuid", "14", bthcrp_handle);
663
14
    dissector_add_string("bluetooth.uuid", "16", bthcrp_handle);
664
14
    dissector_add_string("bluetooth.uuid", "1125", bthcrp_handle);
665
14
    dissector_add_string("bluetooth.uuid", "1126", bthcrp_handle);
666
14
    dissector_add_string("bluetooth.uuid", "1127", bthcrp_handle);
667
668
14
    dissector_add_for_decode_as("btl2cap.psm", bthcrp_handle);
669
14
    dissector_add_for_decode_as("btl2cap.cid", bthcrp_handle);
670
14
}
671
672
/*
673
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
674
 *
675
 * Local variables:
676
 * c-basic-offset: 4
677
 * tab-width: 8
678
 * indent-tabs-mode: nil
679
 * End:
680
 *
681
 * vi: set shiftwidth=4 tabstop=8 expandtab:
682
 * :indentSize=4:tabSize=8:noTabs=true:
683
 */