4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
6 * Copyright (c) 2020 Marc Veldman <marc@bumblingdork.com>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/types.h>
38 #define L2CAP_SOCKET_CHECKED
39 #include <bluetooth.h>
40 #include "hccontrol.h"
42 static char* const adv_data2str(int len, uint8_t* data, char* buffer,
44 static char* const adv_name2str(int len, uint8_t* advdata, char* buffer,
46 static char* const adv_uuid2str(int datalen, uint8_t* data, char* buffer,
49 void dump_adv_data(int len, uint8_t* advdata)
52 fprintf(stdout, "\tADV Data: ");
53 for (n = 0; n < len+1; n++) {
54 fprintf(stdout, "%02x ", advdata[n]);
56 fprintf(stdout, "\n");
59 void print_adv_data(int len, uint8_t* advdata)
65 uint8_t datalen = advdata[n];
66 uint8_t datatype = advdata[++n];
82 "\tIncomplete list of service"
83 " class UUIDs (16-bit): %s\n",
92 "\tComplete list of service "
93 "class UUIDs (16-bit): %s\n",
102 "\tComplete list of service "
103 "class UUIDs (128 bit): %s\n",
112 "\tShortened local name: %s\n",
121 "\tComplete local name: %s\n",
130 "\tTx Power level: %d dBm\n",
135 "\tClass of device: %s\n",
144 "\tService data: %s\n",
153 "\tAppearance: %s\n",
162 "\tManufacturer: %s\n",
163 hci_manufacturer2str(
164 advdata[n]|advdata[n+1]<<8));
166 "\tManufacturer specific data: %s\n",
175 "\tUNKNOWN datatype: %02x data %s\n",
187 static char* const adv_data2str(int datalen, uint8_t* data, char* buffer,
196 memset(buffer, 0, size);
199 (void)snprintf(tmpbuf, sizeof(tmpbuf), "%02x ", data[i]);
200 /* Check if buffer is full */
201 if (strlcat(buffer, tmpbuf, size) > size)
208 static char* const adv_name2str(int datalen, uint8_t* data, char* buffer,
214 memset(buffer, 0, size);
216 (void)strlcpy(buffer, (char*)data, datalen+1);
220 static char* const adv_uuid2str(int datalen, uint8_t* data, char* buffer,
231 memset(buffer, 0, size);
234 uuid.time_low = le32dec(data+12);
235 uuid.time_mid = le16dec(data+10);
236 uuid.time_hi_and_version = le16dec(data+8);
237 uuid.clock_seq_hi_and_reserved = data[7];
238 uuid.clock_seq_low = data[6];
239 for(i = 0; i < _UUID_NODE_LEN; i++){
240 uuid.node[i] = data[5 - i];
242 uuid_to_string(&uuid, &tmpstr, &ustatus);
243 if(ustatus == uuid_s_ok) {
244 strlcpy(buffer, tmpstr, size);