xref: /freebsd/usr.sbin/bluetooth/hccontrol/info.c (revision f0adf7f5cdd241db2f2c817683191a6ef64a4e95)
1 /*
2  * info.c
3  *
4  * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $Id: info.c,v 1.3 2003/08/18 19:19:54 max Exp $
29  * $FreeBSD$
30  */
31 
32 #include <bluetooth.h>
33 #include <errno.h>
34 #include <stdio.h>
35 #include <string.h>
36 #include "hccontrol.h"
37 
38 /* Send Read_Local_Version_Information command to the unit */
39 static int
40 hci_read_local_version_information(int s, int argc, char **argv)
41 {
42 	ng_hci_read_local_ver_rp	rp;
43 	int				n;
44 
45 	n = sizeof(rp);
46 	if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,
47 			NG_HCI_OCF_READ_LOCAL_VER), (char *) &rp, &n) == ERROR)
48 		return (ERROR);
49 
50 	if (rp.status != 0x00) {
51 		fprintf(stdout, "Status: %s [%#02x]\n",
52 			hci_status2str(rp.status), rp.status);
53 		return (FAILED);
54 	}
55 
56 	rp.manufacturer = le16toh(rp.manufacturer);
57 
58 	fprintf(stdout, "HCI version: %s [%#02x]\n",
59 		hci_ver2str(rp.hci_version), rp.hci_version);
60 	fprintf(stdout, "HCI revision: %#04x\n",
61 		le16toh(rp.hci_revision));
62 	fprintf(stdout, "LMP version: %#02x\n", rp.lmp_version);
63 	fprintf(stdout, "LMP sub-version: %#04x\n",
64 		le16toh(rp.lmp_subversion));
65 	fprintf(stdout, "Manufacturer: %s [%#04x]\n",
66 		hci_manufacturer2str(rp.manufacturer), rp.manufacturer);
67 
68 	return (OK);
69 } /* hci_read_local_version_information */
70 
71 /* Send Read_Local_Supported_Features command to the unit */
72 static int
73 hci_read_local_supported_features(int s, int argc, char **argv)
74 {
75 	ng_hci_read_local_features_rp	rp;
76 	int				n;
77 	char				buffer[1024];
78 
79 	n = sizeof(rp);
80 	if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,
81 			NG_HCI_OCF_READ_LOCAL_FEATURES),
82 			(char *) &rp, &n) == ERROR)
83 		return (ERROR);
84 
85 	if (rp.status != 0x00) {
86 		fprintf(stdout, "Status: %s [%#02x]\n",
87 			hci_status2str(rp.status), rp.status);
88 		return (FAILED);
89 	}
90 
91 	fprintf(stdout, "Features: ");
92 	for (n = 0; n < sizeof(rp.features); n++)
93 		fprintf(stdout, "%#02x ", rp.features[n]);
94 	fprintf(stdout, "\n%s\n", hci_features2str(rp.features,
95 		buffer, sizeof(buffer)));
96 
97 	return (OK);
98 } /* hci_read_local_supported_features */
99 
100 /* Sent Read_Buffer_Size command to the unit */
101 static int
102 hci_read_buffer_size(int s, int argc, char **argv)
103 {
104 	ng_hci_read_buffer_size_rp	rp;
105 	int				n;
106 
107 	n = sizeof(rp);
108 	if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,
109 			NG_HCI_OCF_READ_BUFFER_SIZE),
110 			(char *) &rp, &n) == ERROR)
111 		return (ERROR);
112 
113 	if (rp.status != 0x00) {
114 		fprintf(stdout, "Status: %s [%#02x]\n",
115 			hci_status2str(rp.status), rp.status);
116 		return (FAILED);
117 	}
118 
119 	fprintf(stdout, "Max. ACL packet size: %d bytes\n",
120 		le16toh(rp.max_acl_size));
121 	fprintf(stdout, "Number of ACL packets: %d\n",
122 		le16toh(rp.num_acl_pkt));
123 	fprintf(stdout, "Max. SCO packet size: %d bytes\n",
124 		rp.max_sco_size);
125 	fprintf(stdout, "Number of SCO packets: %d\n",
126 		le16toh(rp.num_sco_pkt));
127 
128 	return (OK);
129 } /* hci_read_buffer_size */
130 
131 /* Send Read_Country_Code command to the unit */
132 static int
133 hci_read_country_code(int s, int argc, char **argv)
134 {
135 	ng_hci_read_country_code_rp	rp;
136 	int				n;
137 
138 	n = sizeof(rp);
139 	if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,
140 			NG_HCI_OCF_READ_COUNTRY_CODE),
141 			(char *) &rp, &n) == ERROR)
142 		return (ERROR);
143 
144 	if (rp.status != 0x00) {
145 		fprintf(stdout, "Status: %s [%#02x]\n",
146 			hci_status2str(rp.status), rp.status);
147 		return (FAILED);
148 	}
149 
150 	fprintf(stdout, "Country code: %s [%#02x]\n",
151 			hci_cc2str(rp.country_code), rp.country_code);
152 
153 	return (OK);
154 } /* hci_read_country_code */
155 
156 /* Send Read_BD_ADDR command to the unit */
157 static int
158 hci_read_bd_addr(int s, int argc, char **argv)
159 {
160 	ng_hci_read_bdaddr_rp	rp;
161 	int			n;
162 
163 	n = sizeof(rp);
164 	if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,
165 			NG_HCI_OCF_READ_BDADDR), (char *) &rp, &n) == ERROR)
166 		return (ERROR);
167 
168 	if (rp.status != 0x00) {
169 		fprintf(stdout, "Status: %s [%#02x]\n",
170 			hci_status2str(rp.status), rp.status);
171 		return (FAILED);
172 	}
173 
174 	fprintf(stdout, "BD_ADDR: %s\n", bt_ntoa(&rp.bdaddr, NULL));
175 
176 	return (OK);
177 } /* hci_read_bd_addr */
178 
179 struct hci_command	info_commands[] = {
180 {
181 "read_local_version_information",
182 "\nThis command will read the values for the version information for the\n" \
183 "local Bluetooth unit.",
184 &hci_read_local_version_information
185 },
186 {
187 "read_local_supported_features",
188 "\nThis command requests a list of the supported features for the local\n" \
189 "unit. This command will return a list of the LMP features.",
190 &hci_read_local_supported_features
191 },
192 {
193 "read_buffer_size",
194 "\nThe Read_Buffer_Size command is used to read the maximum size of the\n" \
195 "data portion of HCI ACL and SCO Data Packets sent from the Host to the\n" \
196 "Host Controller.",
197 &hci_read_buffer_size
198 },
199 {
200 "read_country_code",
201 "\nThis command will read the value for the Country_Code return parameter.\n" \
202 "The Country_Code defines which range of frequency band of the ISM 2.4 GHz\n" \
203 "band will be used by the unit.",
204 &hci_read_country_code
205 },
206 {
207 "read_bd_addr",
208 "\nThis command will read the value for the BD_ADDR parameter. The BD_ADDR\n" \
209 "is a 48-bit unique identifier for a Bluetooth unit.",
210 &hci_read_bd_addr
211 },
212 {
213 NULL,
214 }};
215 
216