1/*-
2 * info.c
3 *
4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 *
6 * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
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 * $FreeBSD$
32 */
33
34#define L2CAP_SOCKET_CHECKED
35#include <bluetooth.h>
36#include <errno.h>
37#include <stdio.h>
38#include <string.h>
39#include "hccontrol.h"
40
41/* Send Read_Local_Version_Information command to the unit */
42static int
43hci_read_local_version_information(int s, int argc, char **argv)
44{
45	ng_hci_read_local_ver_rp	rp;
46	int				n;
47
48	n = sizeof(rp);
49	if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,
50			NG_HCI_OCF_READ_LOCAL_VER), (char *) &rp, &n) == ERROR)
51		return (ERROR);
52
53	if (rp.status != 0x00) {
54		fprintf(stdout, "Status: %s [%#02x]\n",
55			hci_status2str(rp.status), rp.status);
56		return (FAILED);
57	}
58
59	rp.manufacturer = le16toh(rp.manufacturer);
60
61	fprintf(stdout, "HCI version: %s [%#02x]\n",
62		hci_ver2str(rp.hci_version), rp.hci_version);
63	fprintf(stdout, "HCI revision: %#04x\n",
64		le16toh(rp.hci_revision));
65	fprintf(stdout, "LMP version: %s [%#02x]\n",
66		hci_lmpver2str(rp.lmp_version), rp.lmp_version);
67	fprintf(stdout, "LMP sub-version: %#04x\n",
68		le16toh(rp.lmp_subversion));
69	fprintf(stdout, "Manufacturer: %s [%#04x]\n",
70		hci_manufacturer2str(rp.manufacturer), rp.manufacturer);
71
72	return (OK);
73} /* hci_read_local_version_information */
74
75/* Send Read_Local_Supported_Features command to the unit */
76static int
77hci_read_local_supported_features(int s, int argc, char **argv)
78{
79	ng_hci_read_local_features_rp	rp;
80	int				n;
81	char				buffer[1024];
82
83	n = sizeof(rp);
84	if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,
85			NG_HCI_OCF_READ_LOCAL_FEATURES),
86			(char *) &rp, &n) == ERROR)
87		return (ERROR);
88
89	if (rp.status != 0x00) {
90		fprintf(stdout, "Status: %s [%#02x]\n",
91			hci_status2str(rp.status), rp.status);
92		return (FAILED);
93	}
94
95	fprintf(stdout, "Features: ");
96	for (n = 0; n < sizeof(rp.features); n++)
97		fprintf(stdout, "%#02x ", rp.features[n]);
98	fprintf(stdout, "\n%s\n", hci_features2str(rp.features,
99		buffer, sizeof(buffer)));
100
101	return (OK);
102} /* hci_read_local_supported_features */
103
104/* Sent Read_Buffer_Size command to the unit */
105static int
106hci_read_buffer_size(int s, int argc, char **argv)
107{
108	ng_hci_read_buffer_size_rp	rp;
109	int				n;
110
111	n = sizeof(rp);
112	if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,
113			NG_HCI_OCF_READ_BUFFER_SIZE),
114			(char *) &rp, &n) == ERROR)
115		return (ERROR);
116
117	if (rp.status != 0x00) {
118		fprintf(stdout, "Status: %s [%#02x]\n",
119			hci_status2str(rp.status), rp.status);
120		return (FAILED);
121	}
122
123	fprintf(stdout, "Max. ACL packet size: %d bytes\n",
124		le16toh(rp.max_acl_size));
125	fprintf(stdout, "Number of ACL packets: %d\n",
126		le16toh(rp.num_acl_pkt));
127	fprintf(stdout, "Max. SCO packet size: %d bytes\n",
128		rp.max_sco_size);
129	fprintf(stdout, "Number of SCO packets: %d\n",
130		le16toh(rp.num_sco_pkt));
131
132	return (OK);
133} /* hci_read_buffer_size */
134
135/* Send Read_Country_Code command to the unit */
136static int
137hci_read_country_code(int s, int argc, char **argv)
138{
139	ng_hci_read_country_code_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_COUNTRY_CODE),
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, "Country code: %s [%#02x]\n",
155			hci_cc2str(rp.country_code), rp.country_code);
156
157	return (OK);
158} /* hci_read_country_code */
159
160/* Send Read_BD_ADDR command to the unit */
161static int
162hci_read_bd_addr(int s, int argc, char **argv)
163{
164	ng_hci_read_bdaddr_rp	rp;
165	int			n;
166
167	n = sizeof(rp);
168	if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,
169			NG_HCI_OCF_READ_BDADDR), (char *) &rp, &n) == ERROR)
170		return (ERROR);
171
172	if (rp.status != 0x00) {
173		fprintf(stdout, "Status: %s [%#02x]\n",
174			hci_status2str(rp.status), rp.status);
175		return (FAILED);
176	}
177
178	fprintf(stdout, "BD_ADDR: %s\n", bt_ntoa(&rp.bdaddr, NULL));
179
180	return (OK);
181} /* hci_read_bd_addr */
182
183struct hci_command	info_commands[] = {
184{
185"read_local_version_information",
186"\nThis command will read the values for the version information for the\n" \
187"local Bluetooth unit.",
188&hci_read_local_version_information
189},
190{
191"read_local_supported_features",
192"\nThis command requests a list of the supported features for the local\n" \
193"unit. This command will return a list of the LMP features.",
194&hci_read_local_supported_features
195},
196{
197"read_buffer_size",
198"\nThe Read_Buffer_Size command is used to read the maximum size of the\n" \
199"data portion of HCI ACL and SCO Data Packets sent from the Host to the\n" \
200"Host Controller.",
201&hci_read_buffer_size
202},
203{
204"read_country_code",
205"\nThis command will read the value for the Country_Code return parameter.\n" \
206"The Country_Code defines which range of frequency band of the ISM 2.4 GHz\n" \
207"band will be used by the unit.",
208&hci_read_country_code
209},
210{
211"read_bd_addr",
212"\nThis command will read the value for the BD_ADDR parameter. The BD_ADDR\n" \
213"is a 48-bit unique identifier for a Bluetooth unit.",
214&hci_read_bd_addr
215},
216{
217NULL,
218}};
219
220