3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2011-2014 Intel Corporation
6 * Copyright (C) 2002-2010 Marcel Holtmann <marcel@holtmann.org>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #ifndef TIZEN_FEATURE_BLUEZ_MODIFY
35 #include "lib/bluetooth.h"
38 #include "src/shared/util.h"
44 #define COLOR_COMMAND COLOR_BLUE
45 #define COLOR_COMMAND_UNKNOWN COLOR_WHITE_BG
47 static void null_cmd(const void *data, uint16_t size)
51 static void null_rsp(const void *data, uint16_t size)
55 static void read_supported_features_rsp(const void *data, uint16_t size)
57 const struct msft_rsp_read_supported_features *rsp = data;
59 packet_print_features_msft(rsp->features);
60 print_field("Event prefix length: %u", rsp->evt_prefix_len);
61 print_field("Event prefix:");
62 packet_hexdump(rsp->evt_prefix, rsp->evt_prefix_len);
63 packet_set_msft_evt_prefix(rsp->evt_prefix, rsp->evt_prefix_len);
66 static void monitor_rssi_cmd(const void *data, uint16_t size)
68 const struct msft_cmd_monitor_rssi *cmd = data;
70 print_field("Connection handle: 0x%04x", cmd->handle);
71 packet_print_rssi("RSSI threshold high", cmd->rssi_high);
72 packet_print_rssi("RSSI threshold low", cmd->rssi_low);
73 print_field("RSSI threshold low time interval: %u sec (0x%2.2x)",
74 cmd->rssi_low_interval,
75 cmd->rssi_low_interval);
76 print_field("RSSI sampling period: %u msec (0x%2.2x)",
77 cmd->rssi_period * 100,
81 static void cancel_monitor_rssi_cmd(const void *data, uint16_t size)
83 const struct msft_cmd_cancel_monitor_rssi *cmd = data;
85 print_field("Connection handle: 0x%04x", cmd->handle);
88 static void le_monitor_advertisement_cmd(const void *data, uint16_t size)
90 const struct msft_cmd_le_monitor_adv *cmd = data;
91 const struct msft_le_monitor_adv_patterns *patterns;
92 const struct msft_le_monitor_adv_uuid *uuid;
93 const struct msft_le_monitor_adv_irk *irk;
94 const struct msft_le_monitor_adv_addr *addr;
96 char uuidstr[MAX_LEN_UUID_STR];
98 packet_print_rssi("RSSI threshold high", cmd->rssi_high);
99 packet_print_rssi("RSSI threshold low", cmd->rssi_low);
100 print_field("RSSI threshold low time interval: %u sec (0x%2.2x)",
101 cmd->rssi_low_interval,
102 cmd->rssi_low_interval);
103 print_field("RSSI sampling period: %u msec (0x%2.2x)",
104 cmd->rssi_period * 100,
108 case MSFT_LE_MONITOR_ADV_PATTERN:
109 print_field("Type: Pattern (0x%2.2x)", cmd->type);
110 patterns = (void *)cmd->data;
111 print_field("Number of patterns: %u", patterns->num);
112 packet_hexdump((void *)patterns->data,
113 size - (sizeof(*cmd) + sizeof(*patterns)));
115 case MSFT_LE_MONITOR_ADV_UUID:
116 print_field("Type: UUID (0x%2.2x)", cmd->type);
117 uuid = (void *)cmd->data;
119 switch (uuid->type) {
121 str = bt_uuid16_to_str(uuid->value.u16);
122 print_field("UUID: %s (0x%4.4x)", str, uuid->value.u16);
125 str = bt_uuid32_to_str(uuid->value.u32);
126 print_field("UUID: %s (0x%8.8x)", str, uuid->value.u32);
129 sprintf(uuidstr, "%8.8x-%4.4x-%4.4x-%4.4x-%8.8x%4.4x",
130 get_le32(uuid->value.u128 + 12),
131 get_le16(uuid->value.u128 + 10),
132 get_le16(uuid->value.u128 + 8),
133 get_le16(uuid->value.u128 + 6),
134 get_le32(uuid->value.u128 + 2),
135 get_le16(uuid->value.u128 + 0));
136 str = bt_uuidstr_to_str(uuidstr);
137 print_field("UUID: %s (%s)", str, uuidstr);
140 packet_hexdump((void *)&uuid->value,
141 size - sizeof(*cmd));
145 case MSFT_LE_MONITOR_ADV_IRK:
146 print_field("Type: IRK (0x%2.2x)", cmd->type);
147 irk = (void *)cmd->data;
149 packet_hexdump(irk->irk, size - sizeof(*cmd));
151 case MSFT_LE_MONITOR_ADV_ADDR:
152 print_field("Type: Adderss (0x%2.2x)", cmd->type);
153 addr = (void *)cmd->data;
154 packet_print_addr(NULL, addr->addr, addr->type);
157 print_field("Type: Unknown (0x%2.2x)", cmd->type);
158 packet_hexdump(cmd->data, size - sizeof(*cmd));
163 static void le_monitor_advertisement_rsp(const void *data, uint16_t size)
165 const struct msft_rsp_le_monitor_adv *rsp = data;
167 print_field("Monitor handle: %u", rsp->handle);
170 static void le_cancel_monitor_adv_cmd(const void *data, uint16_t size)
172 const struct msft_cmd_le_cancel_monitor_adv *cmd = data;
174 print_field("Monitor handle: %u", cmd->handle);
177 static void set_adv_filter_enable_cmd(const void *data, uint16_t size)
179 const struct msft_cmd_le_monitor_adv_enable *cmd = data;
182 switch (cmd->enable) {
184 str = "Current allow list";
187 str = "All filter conditions";
194 print_field("Enable: %s (0x%2.2x)", str, cmd->enable);
197 typedef void (*func_t) (const void *data, uint16_t size);
199 static const struct {
205 { 0x00, "Read Supported Features",
207 read_supported_features_rsp },
208 { 0x01, "Monitor RSSI",
210 { 0x02, "Cancel Monitor RSSI",
211 cancel_monitor_rssi_cmd },
212 { 0x03, "LE Monitor Advertisement",
213 le_monitor_advertisement_cmd,
214 le_monitor_advertisement_rsp },
215 { 0x04, "LE Cancel Monitor Advertisement",
216 le_cancel_monitor_adv_cmd },
217 { 0x05, "LE Set Advertisement Filter Enable",
218 set_adv_filter_enable_cmd,
220 { 0x06, "Read Absolute RSSI" },
224 static void msft_cmd(uint16_t index, const void *data, uint8_t size)
226 uint8_t code = get_u8(data);
227 const char *code_color, *code_str = NULL;
228 func_t code_func = NULL;
231 for (i = 0; cmd_table[i].str; i++) {
232 if (cmd_table[i].code == code) {
233 code_str = cmd_table[i].str;
234 code_func = cmd_table[i].cmd_func;
241 code_color = COLOR_COMMAND;
243 code_color = COLOR_COMMAND_UNKNOWN;
245 code_color = COLOR_COMMAND_UNKNOWN;
246 code_str = "Unknown";
249 print_indent(6, code_color, "", code_str, COLOR_OFF,
253 code_func(data, size);
255 packet_hexdump(data + 1, size - 1);
258 static void msft_rsp(uint16_t index, const void *data, uint8_t size)
260 uint8_t status = get_u8(data);
261 uint8_t code = get_u8(data + 1);
262 const char *code_color, *code_str = NULL;
263 func_t code_func = NULL;
266 for (i = 0; cmd_table[i].str; i++) {
267 if (cmd_table[i].code == code) {
268 code_str = cmd_table[i].str;
269 code_func = cmd_table[i].rsp_func;
276 code_color = COLOR_COMMAND;
278 code_color = COLOR_COMMAND_UNKNOWN;
280 code_color = COLOR_COMMAND_UNKNOWN;
281 code_str = "Unknown";
284 print_indent(6, code_color, "", code_str, COLOR_OFF,
287 packet_print_error("Status", status);
290 code_func(data, size);
292 packet_hexdump(data + 2, size - 2);
295 static const struct vendor_ocf vendor_ocf_entry = {
296 0x000, "Extension", msft_cmd, 1, false, msft_rsp, 2, false
299 const struct vendor_ocf *msft_vendor_ocf(void)
301 return &vendor_ocf_entry;
304 static void msft_evt(struct timeval *tv, uint16_t index,
305 const void *data, uint8_t size)
307 packet_hexdump(data, size);
310 static const struct vendor_evt vendor_evt_entry = {
311 0x00, "Extension", msft_evt, 1, false
314 const struct vendor_evt *msft_vendor_evt(void)
316 return &vendor_evt_entry;