2 * Routines for Bluetooth SAP dissection
4 * Copyright 2012, Michal Labedzki for Tieto Corporation
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include <epan/packet.h>
16 #include <epan/prefs.h>
17 #include <epan/expert.h>
18 #include "packet-btsdp.h"
22 TOP_DISSECT_INTERNAL
= 1,
27 PARAMETER_MAX_MSG_SIZE
= 0x00,
28 PARAMETER_CONNECTION_STATUS
= 0x01,
29 PARAMETER_RESULT_CODE
= 0x02,
30 PARAMETER_DISCONNECTION_TYPE
= 0x03,
31 PARAMETER_COMMAND_APDU
= 0x04,
32 PARAMETER_RESPONSE_APDU
= 0x05,
34 PARAMETER_CARD_READER_STATUS
= 0x07,
35 PARAMETER_STATUS_CHANGE
= 0x08,
36 PARAMETER_TRANSPORT_PROTOCOL
= 0x09,
37 PARAMETER_COMMAND_APDU_7816
= 0x10
40 static int proto_btsap
;
41 static int hf_btsap_header_msg_id
;
42 static int hf_btsap_header_number_of_parameters
;
43 static int hf_btsap_header_reserved
;
44 static int hf_btsap_parameter
;
45 static int hf_btsap_parameter_id
;
46 static int hf_btsap_parameter_reserved
;
47 static int hf_btsap_parameter_length
;
48 static int hf_btsap_parameter_padding
;
49 static int hf_btsap_parameter_max_msg_size
;
50 static int hf_btsap_parameter_connection_status
;
51 static int hf_btsap_parameter_result_code
;
52 static int hf_btsap_parameter_disconnection_type
;
53 static int hf_btsap_parameter_status_change
;
54 static int hf_btsap_parameter_transport_protocol
;
55 static int hf_btsap_parameter_card_reader_status_card_reader_identity
;
56 static int hf_btsap_parameter_card_reader_status_card_reader_removable
;
57 static int hf_btsap_parameter_card_reader_status_card_reader_present
;
58 static int hf_btsap_parameter_card_reader_status_card_reader_present_lower
;
59 static int hf_btsap_parameter_card_reader_status_card_present
;
60 static int hf_btsap_parameter_card_reader_status_card_powered
;
62 static int hf_btsap_data
;
65 static int ett_btsap_parameter
;
67 static expert_field ei_btsap_parameter_error
;
68 static expert_field ei_unexpected_data
;
70 static int top_dissect
= TOP_DISSECT_INTERNAL
;
72 static dissector_handle_t btsap_handle
;
73 static dissector_handle_t gsm_sim_cmd_handle
;
74 static dissector_handle_t gsm_sim_resp_handle
;
75 static dissector_handle_t iso7816_atr_handle
;
77 static const value_string msg_id_vals
[] = {
78 { 0x00, "CONNECT_REQ" },
79 { 0x01, "CONNECT_RESP" },
80 { 0x02, "DISCONNECT_REQ" },
81 { 0x03, "DISCONNECT_RESP" },
82 { 0x04, "DISCONNECT_IND" },
83 { 0x05, "TRANSFER_APDU_REQ" },
84 { 0x06, "TRANSFER_APDU_RESP" },
85 { 0x07, "TRANSFER_ATR_REQ" },
86 { 0x08, "TRANSFER_ATR_RESP" },
87 { 0x09, "POWER_SIM_OFF_REQ" },
88 { 0x0A, "POWER_SIM_OFF_RESP" },
89 { 0x0B, "POWER_SIM_ON_REQ" },
90 { 0x0C, "POWER_SIM_ON_RESP" },
91 { 0x0D, "RESET_SIM_REQ" },
92 { 0x0E, "RESET_SIM_RESP" },
93 { 0x0F, "TRANSFER_CARD_READER_STATUS_REQ" },
94 { 0x10, "TRANSFER_CARD_READER_STATUS_RESP" },
95 { 0x11, "STATUS_IND" },
96 { 0x12, "ERROR_RESP" },
97 { 0x13, "SET_TRANSPORT_PROTOCOL_REQ" },
98 { 0x14, "SET_TRANSPORT_PROTOCOL_RESP" },
102 static const value_string parameter_id_vals
[] = {
103 { 0x00, "MaxMsgSize" },
104 { 0x01, "ConnectionStatus" },
105 { 0x02, "ResultCode" },
106 { 0x03, "DisconnectionType" },
107 { 0x04, "CommandAPDU" },
108 { 0x05, "ResponseAPDU" },
110 { 0x07, "CardReaderStatus" },
111 { 0x08, "StatusChange" },
112 { 0x09, "TransportProtocol" },
113 { 0x10, "CommandAPDU7816" },
117 static const value_string connection_status_vals
[] = {
118 { 0x00, "OK, Server can fulfill requirements" },
119 { 0x01, "Error, Server unable to establish connection" },
120 { 0x02, "Error, Server does not support maximum message size" },
121 { 0x03, "Error, maximum message size by Client is too small" },
122 { 0x04, "OK, ongoing call" },
126 static const value_string result_code_vals
[] = {
127 { 0x00, "OK, request processed correctly" },
128 { 0x01, "Error, no reason defined" },
129 { 0x02, "Error, card not accessible" },
130 { 0x03, "Error, card (already) powered off" },
131 { 0x04, "Error, card removed" },
132 { 0x05, "Error, card already powered on" },
133 { 0x06, "Error, data no available" },
134 { 0x07, "Error, not supported" },
138 static const value_string disconnection_type_vals
[] = {
139 { 0x00, "Graceful" },
140 { 0x01, "Immediate" },
144 static const value_string status_change_vals
[] = {
145 { 0x00, "Unknown Error" },
146 { 0x01, "Card Reset" },
147 { 0x02, "Card Not Accessible" },
148 { 0x03, "Card Removed" },
149 { 0x04, "Card Inserted" },
150 { 0x05, "Card Recovered" },
154 static const enum_val_t pref_top_dissect
[] = {
155 { "off", "off", TOP_DISSECT_OFF
},
156 { "internal", "Put higher dissectors under this one", TOP_DISSECT_INTERNAL
},
157 { "top", "On top", TOP_DISSECT_TOP
},
161 void proto_register_btsap(void);
162 void proto_reg_handoff_btsap(void);
165 dissect_parameter(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*top_tree
,
166 proto_tree
*tree
, int offset
, uint8_t *parameter
, int *parameter_offset
)
168 proto_item
*parameter_item
;
172 unsigned parameter_id
;
173 unsigned parameter_length
;
174 unsigned parameter_padding_length
;
175 unsigned padding_length
;
177 uint16_t max_msg_size
;
178 uint8_t connection_status
;
180 uint8_t disconnection_type
;
181 uint8_t status_change
;
182 uint8_t transport_protocol
;
184 parameter_id
= tvb_get_uint8(tvb
, offset
);
185 parameter_length
= tvb_get_ntohs(tvb
, offset
+ 2);
186 parameter_padding_length
= parameter_length
% 4;
187 if (parameter_padding_length
> 0)
188 parameter_padding_length
= 4 - parameter_padding_length
;
190 parameter_item
= proto_tree_add_none_format(tree
, hf_btsap_parameter
, tvb
, offset
,
191 2 + 2 + parameter_length
+ parameter_padding_length
, "Parameter: %s: ",
192 val_to_str_const(parameter_id
, parameter_id_vals
, "Unknown ParameterID"));
193 ptree
= proto_item_add_subtree(parameter_item
, ett_btsap_parameter
);
195 proto_tree_add_item(ptree
, hf_btsap_parameter_id
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
197 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " - %s", val_to_str_const(parameter_id
, parameter_id_vals
, "Unknown ParameterID"));
200 proto_tree_add_item(ptree
, hf_btsap_parameter_reserved
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
203 pitem
= proto_tree_add_item(ptree
, hf_btsap_parameter_length
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
205 proto_item_append_text(pitem
, " (in 4 bytes sections, padding length: %u)", parameter_padding_length
);
208 switch(parameter_id
) {
209 case 0x00: /* MaxMsgSize */
210 proto_tree_add_item(ptree
, hf_btsap_parameter_max_msg_size
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
211 max_msg_size
= tvb_get_ntohs(tvb
, offset
);
212 proto_item_append_text(parameter_item
, "%u", max_msg_size
);
213 col_append_fstr(pinfo
->cinfo
, COL_INFO
, ": %u", max_msg_size
);
217 case 0x01: /* ConnectionStatus */
218 proto_tree_add_item(ptree
, hf_btsap_parameter_connection_status
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
219 connection_status
= tvb_get_uint8(tvb
, offset
);
220 proto_item_append_text(parameter_item
, "%s", val_to_str_const(connection_status
, connection_status_vals
, "Unknown"));
221 col_append_fstr(pinfo
->cinfo
, COL_INFO
, ": %s", val_to_str_const(connection_status
, connection_status_vals
, "Unknown"));
225 case 0x02: /* ResultCode */
226 proto_tree_add_item(ptree
, hf_btsap_parameter_result_code
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
227 result_code
= tvb_get_uint8(tvb
, offset
);
228 proto_item_append_text(parameter_item
, "%s", val_to_str_const(result_code
, result_code_vals
, "Unknown"));
229 col_append_fstr(pinfo
->cinfo
, COL_INFO
, ": %s", val_to_str_const(result_code
, result_code_vals
, "Unknown"));
233 case 0x03: /* DisconnectionType */
234 proto_tree_add_item(ptree
, hf_btsap_parameter_disconnection_type
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
235 disconnection_type
= tvb_get_uint8(tvb
, offset
);
236 proto_item_append_text(parameter_item
, "%s", val_to_str_const(disconnection_type
, disconnection_type_vals
, "Unknown"));
237 col_append_fstr(pinfo
->cinfo
, COL_INFO
, ": %s", val_to_str_const(disconnection_type
, disconnection_type_vals
, "Unknown"));
241 case 0x04: /* CommandAPDU */
243 if (gsm_sim_cmd_handle
&& top_dissect
!= TOP_DISSECT_OFF
) {
244 next_tvb
= tvb_new_subset_length(tvb
, offset
, parameter_length
);
245 col_append_str(pinfo
->cinfo
, COL_INFO
, ": ");
247 if (top_dissect
== TOP_DISSECT_INTERNAL
) {
248 call_dissector(gsm_sim_cmd_handle
, next_tvb
, pinfo
, ptree
);
250 col_clear(pinfo
->cinfo
, COL_INFO
);
251 call_dissector(gsm_sim_cmd_handle
, next_tvb
, pinfo
, top_tree
);
254 proto_tree_add_item(ptree
, hf_btsap_data
, tvb
, offset
, parameter_length
, ENC_NA
);
257 length
= parameter_length
;
258 padding_length
= parameter_padding_length
;
260 case 0x05: /* ResponseAPDU */
261 /* GSM 11.11 or ISO/IEC 7816-4; depend of TRANSFER_APDU_REQ */
262 if (gsm_sim_resp_handle
&& top_dissect
!= TOP_DISSECT_OFF
) {
263 next_tvb
= tvb_new_subset_length(tvb
, offset
, parameter_length
);
264 col_append_str(pinfo
->cinfo
, COL_INFO
, ": ");
266 if (top_dissect
== TOP_DISSECT_INTERNAL
) {
267 call_dissector(gsm_sim_resp_handle
, next_tvb
, pinfo
, ptree
);
269 col_clear(pinfo
->cinfo
, COL_INFO
);
270 call_dissector(gsm_sim_resp_handle
, next_tvb
, pinfo
, top_tree
);
273 proto_tree_add_item(ptree
, hf_btsap_data
, tvb
, offset
, parameter_length
, ENC_NA
);
276 length
= parameter_length
;
277 padding_length
= parameter_padding_length
;
281 if (iso7816_atr_handle
&& top_dissect
!= TOP_DISSECT_OFF
) {
282 next_tvb
= tvb_new_subset_length(tvb
, offset
, parameter_length
);
283 col_append_str(pinfo
->cinfo
, COL_INFO
, ": ");
285 if (top_dissect
== TOP_DISSECT_INTERNAL
) {
286 call_dissector(iso7816_atr_handle
, next_tvb
, pinfo
, ptree
);
288 col_clear(pinfo
->cinfo
, COL_INFO
);
289 call_dissector(iso7816_atr_handle
, next_tvb
, pinfo
, top_tree
);
292 proto_tree_add_item(ptree
, hf_btsap_data
, tvb
, offset
, parameter_length
, ENC_NA
);
295 length
= parameter_length
;
296 padding_length
= parameter_padding_length
;
298 case 0x07: /* CardReaderStatus */
300 proto_tree_add_item(ptree
, hf_btsap_parameter_card_reader_status_card_powered
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
301 proto_tree_add_item(ptree
, hf_btsap_parameter_card_reader_status_card_present
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
302 proto_tree_add_item(ptree
, hf_btsap_parameter_card_reader_status_card_reader_present_lower
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
303 proto_tree_add_item(ptree
, hf_btsap_parameter_card_reader_status_card_reader_present
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
304 proto_tree_add_item(ptree
, hf_btsap_parameter_card_reader_status_card_reader_removable
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
305 proto_tree_add_item(ptree
, hf_btsap_parameter_card_reader_status_card_reader_identity
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
309 case 0x08: /* StatusChange */
310 proto_tree_add_item(ptree
, hf_btsap_parameter_status_change
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
311 status_change
= tvb_get_uint8(tvb
, offset
);
312 proto_item_append_text(parameter_item
, "%s", val_to_str_const(status_change
, status_change_vals
, "Unknown"));
313 col_append_fstr(pinfo
->cinfo
, COL_INFO
, ": %s", val_to_str_const(status_change
, status_change_vals
, "Unknown"));
317 case 0x09: /* TransportProtocol */
318 proto_tree_add_item(ptree
, hf_btsap_parameter_transport_protocol
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
319 transport_protocol
= tvb_get_uint8(tvb
, offset
);
320 proto_item_append_text(parameter_item
, "%u", transport_protocol
);
321 col_append_fstr(pinfo
->cinfo
, COL_INFO
, ": %u", transport_protocol
);
325 case 0x10: /* CommandAPDU7816 */
327 if (gsm_sim_cmd_handle
&& top_dissect
!= TOP_DISSECT_OFF
) {
328 next_tvb
= tvb_new_subset_length(tvb
, offset
, parameter_length
);
329 col_append_str(pinfo
->cinfo
, COL_INFO
, ": ");
331 if (top_dissect
== TOP_DISSECT_INTERNAL
) {
332 call_dissector(gsm_sim_cmd_handle
, next_tvb
, pinfo
, ptree
);
334 col_clear(pinfo
->cinfo
, COL_INFO
);
335 call_dissector(gsm_sim_cmd_handle
, next_tvb
, pinfo
, top_tree
);
338 proto_tree_add_item(ptree
, hf_btsap_data
, tvb
, offset
, parameter_length
, ENC_NA
);
341 length
= parameter_length
;
342 padding_length
= parameter_padding_length
;
345 proto_tree_add_item(ptree
, hf_btsap_data
, tvb
, offset
, parameter_length
, ENC_NA
);
346 length
= parameter_length
;
347 padding_length
= parameter_padding_length
;
350 *parameter
= parameter_id
;
351 *parameter_offset
= offset
;
353 if (length
!= parameter_length
|| padding_length
!= parameter_padding_length
) {
354 /* Malformed frame */
355 expert_add_info_format(pinfo
, pitem
, &ei_btsap_parameter_error
,
356 "Parameter Length does not meet content length");
359 offset
+= parameter_length
;
361 if (parameter_padding_length
> 0) {
362 pitem
= proto_tree_add_item(ptree
, hf_btsap_parameter_padding
, tvb
, offset
, parameter_padding_length
, ENC_NA
);
363 proto_item_append_text(pitem
, " (length %d)", parameter_padding_length
);
364 offset
+= parameter_padding_length
;
371 dissect_btsap(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
374 proto_tree
*btsap_tree
;
377 unsigned number_of_parameters
;
379 int *parameter_offsets
;
380 unsigned parameters_check
= 0;
381 unsigned required_parameters
= 0;
382 unsigned i_parameter
;
383 unsigned i_next_parameter
;
385 ti
= proto_tree_add_item(tree
, proto_btsap
, tvb
, offset
, -1, ENC_NA
);
386 btsap_tree
= proto_item_add_subtree(ti
, ett_btsap
);
388 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "SAP");
390 switch (pinfo
->p2p_dir
) {
392 col_set_str(pinfo
->cinfo
, COL_INFO
, "Sent ");
395 col_set_str(pinfo
->cinfo
, COL_INFO
, "Rcvd ");
398 col_set_str(pinfo
->cinfo
, COL_INFO
, "UnknownDirection ");
402 proto_tree_add_item(btsap_tree
, hf_btsap_header_msg_id
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
403 msg_id
= tvb_get_uint8(tvb
, offset
);
404 col_append_str(pinfo
->cinfo
, COL_INFO
, val_to_str_const(msg_id
, msg_id_vals
, "Unknown MsgID"));
407 proto_tree_add_item(btsap_tree
, hf_btsap_header_number_of_parameters
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
408 number_of_parameters
= tvb_get_uint8(tvb
, offset
);
411 proto_tree_add_item(btsap_tree
, hf_btsap_header_reserved
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
414 parameters
= (uint8_t *) wmem_alloc(pinfo
->pool
, number_of_parameters
* sizeof(uint8_t));
415 parameter_offsets
= (int *) wmem_alloc0(pinfo
->pool
, number_of_parameters
* sizeof(unsigned));
417 for (i_parameter
= 0; i_parameter
< number_of_parameters
; ++i_parameter
) {
418 offset
= dissect_parameter(tvb
, pinfo
, tree
, btsap_tree
, offset
, ¶meters
[i_parameter
], ¶meter_offsets
[i_parameter
]);
421 /* detect invalid data */
423 case 0x02: /* DISCONNECT_REQ */
424 case 0x03: /* DISCONNECT_RESP */
425 case 0x07: /* TRANSFER_ATR_REQ */
426 case 0x09: /* POWER_SIM_OFF_REQ */
427 case 0x0B: /* POWER_SIM_ON_REQ */
428 case 0x0D: /* RESET_SIM_REQ */
429 case 0x0F: /* TRANSFER_CARD_READER_STATUS_REQ */
430 case 0x12: /* ERROR_RESP */
431 required_parameters
= 0;
433 case 0x0A: /* POWER_SIM_OFF_RESP */
434 case 0x0C: /* POWER_SIM_ON_RESP */
435 case 0x0E: /* RESET_SIM_RESP */
436 case 0x14: /* SET_TRANSPORT_PROTOCOL_RESP */
437 /* Parameters: 1 - ResultCode */
438 required_parameters
= 1;
439 for (i_parameter
= 0; i_parameter
< number_of_parameters
; ++i_parameter
) {
440 if (parameters
[i_parameter
] == PARAMETER_RESULT_CODE
) ++parameters_check
;
443 case 0x00: /* CONNECT_REQ */
445 required_parameters
= 1;
446 for (i_parameter
= 0; i_parameter
< number_of_parameters
; ++i_parameter
) {
447 if (parameters
[i_parameter
] == PARAMETER_MAX_MSG_SIZE
) ++parameters_check
;
450 case 0x01: /* CONNECT_RESP */
451 /* Parameters: 1..2 - ConnectionStatus, MaxMsgSize (if error cannot fulfill) */
452 required_parameters
= 1;
453 for (i_parameter
= 0; i_parameter
< number_of_parameters
; ++i_parameter
) {
454 if (parameters
[i_parameter
] == PARAMETER_CONNECTION_STATUS
) {
455 if (tvb_get_uint8(tvb
, parameter_offsets
[i_parameter
]) != 0x00) {
456 for (i_next_parameter
= 0; i_next_parameter
< number_of_parameters
; ++i_next_parameter
) {
457 if (parameters
[i_next_parameter
] == PARAMETER_MAX_MSG_SIZE
) {
459 required_parameters
= 2;
467 case 0x04: /* DISCONNECT_IND */
468 /* Parameters: 1 - DisconnectionType */
469 required_parameters
= 1;
470 for (i_parameter
= 0; i_parameter
< number_of_parameters
; ++i_parameter
) {
471 if (parameters
[i_parameter
] == PARAMETER_DISCONNECTION_TYPE
) ++parameters_check
;
474 case 0x05: /* TRANSFER_APDU_REQ */
475 /* Parameters: 1 - CommandAPU or CommandAPU7816 */
476 required_parameters
= 1;
477 for (i_parameter
= 0; i_parameter
< number_of_parameters
; ++i_parameter
) {
478 if (parameters
[i_parameter
] == PARAMETER_COMMAND_APDU
||
479 parameters
[i_parameter
] == PARAMETER_COMMAND_APDU_7816
)
483 case 0x06: /* TRANSFER_APDU_RESP */
484 /* Parameters: 1..2 - ResultCode, ResponseAPDU (if status ok) */
485 required_parameters
= 1;
486 for (i_parameter
= 0; i_parameter
< number_of_parameters
; ++i_parameter
) {
487 if (parameters
[i_parameter
] == PARAMETER_RESULT_CODE
) {
488 if (tvb_get_uint8(tvb
, parameter_offsets
[i_parameter
]) == 0x00) {
489 for (i_next_parameter
= 0; i_next_parameter
< number_of_parameters
; ++i_next_parameter
) {
490 if (parameters
[i_next_parameter
] == PARAMETER_RESPONSE_APDU
) {
492 required_parameters
= 2;
500 case 0x08: /* TRANSFER_ATR_RESP */
501 /* Parameters: 1..2 - ResultCode, ATR (if status ok) */
502 required_parameters
= 1;
503 for (i_parameter
= 0; i_parameter
< number_of_parameters
; ++i_parameter
) {
504 if (parameters
[i_parameter
] == PARAMETER_RESULT_CODE
) {
505 if (tvb_get_uint8(tvb
, parameter_offsets
[i_parameter
]) == 0x00) {
506 for (i_next_parameter
= 0; i_next_parameter
< number_of_parameters
; ++i_next_parameter
) {
507 if (parameters
[i_next_parameter
] == PARAMETER_ATR
) {
509 required_parameters
= 2;
517 case 0x10: /* TRANSFER_CARD_READER_STATUS_RESP */
518 /* Parameters: 1..2 - ResultCode, CardReaderStatus (if status ok) */
519 required_parameters
= 1;
520 for (i_parameter
= 0; i_parameter
< number_of_parameters
; ++i_parameter
) {
521 if (parameters
[i_parameter
] == PARAMETER_RESULT_CODE
) {
522 if (tvb_get_uint8(tvb
, parameter_offsets
[i_parameter
]) == 0x00) {
523 for (i_next_parameter
= 0; i_next_parameter
< number_of_parameters
; ++i_next_parameter
) {
524 if (parameters
[i_next_parameter
] == PARAMETER_CARD_READER_STATUS
) {
526 required_parameters
= 2;
534 case 0x11: /* STATUS_IND */
535 /* Parameters: 1 - StatusChange */
536 required_parameters
= 1;
537 for (i_parameter
= 0; i_parameter
< number_of_parameters
; ++i_parameter
) {
538 if (parameters
[i_parameter
] == PARAMETER_STATUS_CHANGE
) ++parameters_check
;
541 case 0x13: /* SET_TRANSPORT_PROTOCOL_REQ */
542 /* Parameters: 1 - TransportProtocol */
543 required_parameters
= 1;
544 for (i_parameter
= 0; i_parameter
< number_of_parameters
; ++i_parameter
) {
545 if (parameters
[i_parameter
] == PARAMETER_TRANSPORT_PROTOCOL
) ++parameters_check
;
550 if (parameters_check
< required_parameters
) {
551 proto_tree_add_expert_format(tree
, pinfo
, &ei_btsap_parameter_error
,
552 tvb
, offset
, 0, "There are no required parameters");
553 } else if (parameters_check
> required_parameters
) {
554 proto_tree_add_expert_format(tree
, pinfo
, &ei_btsap_parameter_error
,
555 tvb
, offset
, 0, "Invalid parameters");
557 if (number_of_parameters
< required_parameters
) {
558 proto_tree_add_expert_format(tree
, pinfo
, &ei_btsap_parameter_error
,
559 tvb
, offset
, 0, "Too few parameters");
560 } else if (number_of_parameters
> required_parameters
) {
561 proto_tree_add_expert_format(tree
, pinfo
, &ei_btsap_parameter_error
,
562 tvb
, offset
, 0, "Too many parameters");
565 if (tvb_reported_length(tvb
) > offset
)
566 proto_tree_add_expert(tree
, pinfo
, &ei_unexpected_data
, tvb
, offset
, tvb_reported_length_remaining(tvb
, offset
));
573 proto_register_btsap(void)
576 expert_module_t
*expert_btsap
;
578 static hf_register_info hf
[] = {
579 { &hf_btsap_header_msg_id
,
580 { "MsgID", "btsap.msg_id",
581 FT_UINT8
, BASE_HEX
, VALS(msg_id_vals
), 0x00,
584 { &hf_btsap_header_number_of_parameters
,
585 { "Number of Parameters", "btsap.number_of_parameters",
586 FT_UINT8
, BASE_HEX
, NULL
, 0x00,
589 { &hf_btsap_header_reserved
,
590 { "reserved", "btsap.reserved",
591 FT_UINT16
, BASE_HEX
, NULL
, 0x00,
594 { &hf_btsap_parameter
,
595 { "Parameter", "btsap.parameter",
596 FT_NONE
, BASE_NONE
, NULL
, 0x00,
599 { &hf_btsap_parameter_id
,
600 { "Parameter ID", "btsap.parameter_id",
601 FT_UINT8
, BASE_HEX
, VALS(parameter_id_vals
), 0x00,
604 { &hf_btsap_parameter_reserved
,
605 { "reserved", "btsap.parameter.reserved",
606 FT_UINT8
, BASE_HEX
, NULL
, 0x00,
609 { &hf_btsap_parameter_length
,
610 { "Parameter Length", "btsap.parameter.length",
611 FT_UINT16
, BASE_DEC
, NULL
, 0x00,
614 { &hf_btsap_parameter_padding
,
615 { "Parameter Padding", "btsap.parameter.padding",
616 FT_NONE
, BASE_NONE
, NULL
, 0x00,
619 { &hf_btsap_parameter_max_msg_size
,
620 { "Max Msg Size", "btsap.parameter.max_msg_size",
621 FT_UINT16
, BASE_DEC
, NULL
, 0x00,
624 { &hf_btsap_parameter_connection_status
,
625 { "Connection Status", "btsap.parameter.connection_status",
626 FT_UINT8
, BASE_HEX
, VALS(connection_status_vals
), 0x00,
629 { &hf_btsap_parameter_result_code
,
630 { "Result Code", "btsap.parameter.result_code",
631 FT_UINT8
, BASE_HEX
, VALS(result_code_vals
), 0x00,
634 { &hf_btsap_parameter_disconnection_type
,
635 { "Disconnection Type", "btsap.parameter.disconnection_type",
636 FT_UINT8
, BASE_HEX
, VALS(disconnection_type_vals
), 0x00,
639 { &hf_btsap_parameter_card_reader_status_card_reader_identity
,
640 { "Identify of Card Reader", "btsap.parameter.card_reader_status.card_reader_identity",
641 FT_UINT8
, BASE_HEX
, NULL
, 0x03,
644 { &hf_btsap_parameter_card_reader_status_card_reader_removable
,
645 { "Card Reader is Removable", "btsap.parameter.card_reader_status.card_reader_removable",
646 FT_BOOLEAN
, 8, NULL
, 0x08,
649 { &hf_btsap_parameter_card_reader_status_card_reader_present
,
650 { "Card Reader is Present", "btsap.parameter.card_reader_status.card_reader_present",
651 FT_BOOLEAN
, 8, NULL
, 0x10,
654 { &hf_btsap_parameter_card_reader_status_card_reader_present_lower
,
655 { "Card Reader Present is ID-1 Size","btsap.parameter.card_reader_status.card_reader_present_lower",
656 FT_BOOLEAN
, 8, NULL
, 0x20,
659 { &hf_btsap_parameter_card_reader_status_card_present
,
660 { "Card is Present in Reader", "btsap.parameter.card_reader_status.card_present",
661 FT_BOOLEAN
, 8, NULL
, 0x40,
664 { &hf_btsap_parameter_card_reader_status_card_powered
,
665 { "Card in Reader is Powered", "btsap.parameter.card_reader_status.card_powered",
666 FT_BOOLEAN
, 8, NULL
, 0x80,
669 { &hf_btsap_parameter_status_change
,
670 { "Status Change", "btsap.parameter.status_change",
671 FT_UINT8
, BASE_HEX
, VALS(status_change_vals
), 0x00,
674 { &hf_btsap_parameter_transport_protocol
,
675 { "Transport Protocol", "btsap.parameter.transport_protocol",
676 FT_UINT8
, BASE_HEX
, NULL
, 0x00,
681 { "Data", "btsap.data",
682 FT_NONE
, BASE_NONE
, NULL
, 0x0,
688 static int *ett
[] = {
693 static ei_register_info ei
[] = {
694 { &ei_btsap_parameter_error
, { "btsap.parameter_error", PI_PROTOCOL
, PI_WARN
, "Parameter error", EXPFILL
}},
695 { &ei_unexpected_data
, { "btsap.unexpected_data", PI_PROTOCOL
, PI_WARN
, "Unexpected_data", EXPFILL
}},
698 proto_btsap
= proto_register_protocol("Bluetooth SAP Profile", "BT SAP", "btsap");
699 btsap_handle
= register_dissector("btsap", dissect_btsap
, proto_btsap
);
701 proto_register_field_array(proto_btsap
, hf
, array_length(hf
));
702 proto_register_subtree_array(ett
, array_length(ett
));
703 expert_btsap
= expert_register_protocol(proto_btsap
);
704 expert_register_field_array(expert_btsap
, ei
, array_length(ei
));
706 module
= prefs_register_protocol_subtree("Bluetooth", proto_btsap
, NULL
);
707 prefs_register_static_text_preference(module
, "sap.version",
708 "Bluetooth Profile SAP version: 1.1",
709 "Version of protocol supported by this dissector.");
711 prefs_register_enum_preference(module
, "sap.top_dissect",
712 "Dissecting the top protocols", "Dissecting the top protocols",
713 &top_dissect
, pref_top_dissect
, false);
718 proto_reg_handoff_btsap(void)
720 gsm_sim_cmd_handle
= find_dissector_add_dependency("gsm_sim.command", proto_btsap
);
721 gsm_sim_resp_handle
= find_dissector_add_dependency("gsm_sim.response", proto_btsap
);
722 iso7816_atr_handle
= find_dissector_add_dependency("iso7816.atr", proto_btsap
);
724 dissector_add_string("bluetooth.uuid", "112d", btsap_handle
);
726 dissector_add_for_decode_as("btrfcomm.dlci", btsap_handle
);
730 * Editor modelines - https://www.wireshark.org/tools/modelines.html
735 * indent-tabs-mode: nil
738 * vi: set shiftwidth=4 tabstop=8 expandtab:
739 * :indentSize=4:tabSize=8:noTabs=true: