Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/usr.sbin/bluetooth/hccontrol/info.c
105240 views
1
/*-
2
* info.c
3
*
4
* SPDX-License-Identifier: BSD-2-Clause
5
*
6
* Copyright (c) 2001-2002 Maksim Yevmenkin <[email protected]>
7
* All rights reserved.
8
*
9
* Redistribution and use in source and binary forms, with or without
10
* modification, are permitted provided that the following conditions
11
* are met:
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.
17
*
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
28
* SUCH DAMAGE.
29
*
30
* $Id: info.c,v 1.3 2003/08/18 19:19:54 max Exp $
31
*/
32
33
#define L2CAP_SOCKET_CHECKED
34
#include <bluetooth.h>
35
#include <errno.h>
36
#include <stdio.h>
37
#include <string.h>
38
#include "hccontrol.h"
39
40
/* Send Read_Local_Version_Information command to the unit */
41
static int
42
hci_read_local_version_information(int s, int argc, char **argv)
43
{
44
ng_hci_read_local_ver_rp rp;
45
int n;
46
47
n = sizeof(rp);
48
if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,
49
NG_HCI_OCF_READ_LOCAL_VER), (char *) &rp, &n) == ERROR)
50
return (ERROR);
51
52
if (rp.status != 0x00) {
53
fprintf(stdout, "Status: %s [%#02x]\n",
54
hci_status2str(rp.status), rp.status);
55
return (FAILED);
56
}
57
58
rp.manufacturer = le16toh(rp.manufacturer);
59
60
fprintf(stdout, "HCI version: %s [%#02x]\n",
61
hci_ver2str(rp.hci_version), rp.hci_version);
62
fprintf(stdout, "HCI revision: %#04x\n",
63
le16toh(rp.hci_revision));
64
fprintf(stdout, "LMP version: %s [%#02x]\n",
65
hci_lmpver2str(rp.lmp_version), rp.lmp_version);
66
fprintf(stdout, "LMP sub-version: %#04x\n",
67
le16toh(rp.lmp_subversion));
68
fprintf(stdout, "Manufacturer: %s [%#04x]\n",
69
hci_manufacturer2str(rp.manufacturer), rp.manufacturer);
70
71
return (OK);
72
} /* hci_read_local_version_information */
73
74
/* Send Read_Local_Supported_Commands command to the unit */
75
static int
76
hci_read_local_supported_commands(int s, int argc, char **argv)
77
{
78
ng_hci_read_local_commands_rp rp;
79
int n;
80
char buffer[16384];
81
82
n = sizeof(rp);
83
if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,
84
NG_HCI_OCF_READ_LOCAL_COMMANDS),
85
(char *) &rp, &n) == ERROR)
86
return (ERROR);
87
88
if (rp.status != 0x00) {
89
fprintf(stdout, "Status: %s [%#02x]\n",
90
hci_status2str(rp.status), rp.status);
91
return (FAILED);
92
}
93
94
fprintf(stdout, "Supported commands:");
95
for (n = 0; n < sizeof(rp.features); n++) {
96
if (n % 8 == 0)
97
fprintf(stdout, "\n");
98
fprintf(stdout, "%#02x ", rp.features[n]);
99
}
100
fprintf(stdout, "\n%s\n", hci_commands2str(rp.features,
101
buffer, sizeof(buffer)));
102
103
return (OK);
104
} /* hci_read_local_supported_commands */
105
106
/* Send Read_Local_Supported_Features command to the unit */
107
static int
108
hci_read_local_supported_features(int s, int argc, char **argv)
109
{
110
ng_hci_read_local_features_rp rp;
111
int n;
112
char buffer[2048];
113
114
n = sizeof(rp);
115
if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,
116
NG_HCI_OCF_READ_LOCAL_FEATURES),
117
(char *) &rp, &n) == ERROR)
118
return (ERROR);
119
120
if (rp.status != 0x00) {
121
fprintf(stdout, "Status: %s [%#02x]\n",
122
hci_status2str(rp.status), rp.status);
123
return (FAILED);
124
}
125
126
fprintf(stdout, "Features: ");
127
for (n = 0; n < sizeof(rp.features); n++)
128
fprintf(stdout, "%#02x ", rp.features[n]);
129
fprintf(stdout, "\n%s\n", hci_features2str(rp.features,
130
buffer, sizeof(buffer)));
131
132
return (OK);
133
} /* hci_read_local_supported_features */
134
135
/* Sent Read_Buffer_Size command to the unit */
136
static int
137
hci_read_buffer_size(int s, int argc, char **argv)
138
{
139
ng_hci_read_buffer_size_rp rp;
140
int n;
141
142
n = sizeof(rp);
143
if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,
144
NG_HCI_OCF_READ_BUFFER_SIZE),
145
(char *) &rp, &n) == ERROR)
146
return (ERROR);
147
148
if (rp.status != 0x00) {
149
fprintf(stdout, "Status: %s [%#02x]\n",
150
hci_status2str(rp.status), rp.status);
151
return (FAILED);
152
}
153
154
fprintf(stdout, "Max. ACL packet size: %d bytes\n",
155
le16toh(rp.max_acl_size));
156
fprintf(stdout, "Number of ACL packets: %d\n",
157
le16toh(rp.num_acl_pkt));
158
fprintf(stdout, "Max. SCO packet size: %d bytes\n",
159
rp.max_sco_size);
160
fprintf(stdout, "Number of SCO packets: %d\n",
161
le16toh(rp.num_sco_pkt));
162
163
return (OK);
164
} /* hci_read_buffer_size */
165
166
/* Send Read_Country_Code command to the unit */
167
static int
168
hci_read_country_code(int s, int argc, char **argv)
169
{
170
ng_hci_read_country_code_rp rp;
171
int n;
172
173
n = sizeof(rp);
174
if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,
175
NG_HCI_OCF_READ_COUNTRY_CODE),
176
(char *) &rp, &n) == ERROR)
177
return (ERROR);
178
179
if (rp.status != 0x00) {
180
fprintf(stdout, "Status: %s [%#02x]\n",
181
hci_status2str(rp.status), rp.status);
182
return (FAILED);
183
}
184
185
fprintf(stdout, "Country code: %s [%#02x]\n",
186
hci_cc2str(rp.country_code), rp.country_code);
187
188
return (OK);
189
} /* hci_read_country_code */
190
191
/* Send Read_BD_ADDR command to the unit */
192
static int
193
hci_read_bd_addr(int s, int argc, char **argv)
194
{
195
ng_hci_read_bdaddr_rp rp;
196
int n;
197
198
n = sizeof(rp);
199
if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,
200
NG_HCI_OCF_READ_BDADDR), (char *) &rp, &n) == ERROR)
201
return (ERROR);
202
203
if (rp.status != 0x00) {
204
fprintf(stdout, "Status: %s [%#02x]\n",
205
hci_status2str(rp.status), rp.status);
206
return (FAILED);
207
}
208
209
fprintf(stdout, "BD_ADDR: %s\n", bt_ntoa(&rp.bdaddr, NULL));
210
211
return (OK);
212
} /* hci_read_bd_addr */
213
214
struct hci_command info_commands[] = {
215
{
216
"read_local_version_information",
217
"\nThis command will read the values for the version information for the\n" \
218
"local Bluetooth unit.",
219
&hci_read_local_version_information
220
},
221
{
222
"read_local_supported_commands",
223
"\nThis command will read the commands the local Bluetooth unit supports.\n",
224
&hci_read_local_supported_commands
225
},
226
{
227
"read_local_supported_features",
228
"\nThis command requests a list of the supported features for the local\n" \
229
"unit. This command will return a list of the LMP features.",
230
&hci_read_local_supported_features
231
},
232
{
233
"read_buffer_size",
234
"\nThe Read_Buffer_Size command is used to read the maximum size of the\n" \
235
"data portion of HCI ACL and SCO Data Packets sent from the Host to the\n" \
236
"Host Controller.",
237
&hci_read_buffer_size
238
},
239
{
240
"read_country_code",
241
"\nThis command will read the value for the Country_Code return parameter.\n" \
242
"The Country_Code defines which range of frequency band of the ISM 2.4 GHz\n" \
243
"band will be used by the unit.",
244
&hci_read_country_code
245
},
246
{
247
"read_bd_addr",
248
"\nThis command will read the value for the BD_ADDR parameter. The BD_ADDR\n" \
249
"is a 48-bit unique identifier for a Bluetooth unit.",
250
&hci_read_bd_addr
251
},
252
{
253
NULL,
254
}};
255
256
257