info.c revision 107120
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.7 2002/09/06 18:52:41 max Exp $
29 * $FreeBSD: head/usr.sbin/bluetooth/hccontrol/info.c 107120 2002-11-20 23:01:59Z julian $
30 */
31
32#include <sys/types.h>
33#include <sys/endian.h>
34#include <errno.h>
35#include <ng_hci.h>
36#include <stdio.h>
37#include <string.h>
38#include "hccontrol.h"
39
40/* Send Read_Local_Version_Information command to the unit */
41static int
42hci_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: %#02x\n", rp.lmp_version);
65	fprintf(stdout, "LMP sub-version: %#04x\n",
66		le16toh(rp.lmp_subversion));
67	fprintf(stdout, "Manufacturer: %s [%#04x]\n",
68		hci_manufacturer2str(rp.manufacturer), rp.manufacturer);
69
70	return (OK);
71} /* hci_read_local_version_information */
72
73/* Send Read_Local_Supported_Features command to the unit */
74static int
75hci_read_local_supported_features(int s, int argc, char **argv)
76{
77	ng_hci_read_local_features_rp	rp;
78	int				n;
79	char				buffer[1024];
80
81	n = sizeof(rp);
82	if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,
83			NG_HCI_OCF_READ_LOCAL_FEATURES),
84			(char *) &rp, &n) == ERROR)
85		return (ERROR);
86
87	if (rp.status != 0x00) {
88		fprintf(stdout, "Status: %s [%#02x]\n",
89			hci_status2str(rp.status), rp.status);
90		return (FAILED);
91	}
92
93	fprintf(stdout, "Features: ");
94	for (n = 0; n < sizeof(rp.features); n++)
95		fprintf(stdout, "%#02x ", rp.features[n]);
96	fprintf(stdout, "\n%s\n", hci_features2str(rp.features,
97		buffer, sizeof(buffer)));
98
99	return (OK);
100} /* hci_read_local_supported_features */
101
102/* Sent Read_Buffer_Size command to the unit */
103static int
104hci_read_buffer_size(int s, int argc, char **argv)
105{
106	ng_hci_read_buffer_size_rp	rp;
107	int				n;
108
109	n = sizeof(rp);
110	if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,
111			NG_HCI_OCF_READ_BUFFER_SIZE),
112			(char *) &rp, &n) == ERROR)
113		return (ERROR);
114
115	if (rp.status != 0x00) {
116		fprintf(stdout, "Status: %s [%#02x]\n",
117			hci_status2str(rp.status), rp.status);
118		return (FAILED);
119	}
120
121	fprintf(stdout, "Max. ACL packet size: %d bytes\n",
122		le16toh(rp.max_acl_size));
123	fprintf(stdout, "Number of ACL packets: %d\n",
124		le16toh(rp.num_acl_pkt));
125	fprintf(stdout, "Max. SCO packet size: %d bytes\n",
126		rp.max_sco_size);
127	fprintf(stdout, "Number of SCO packets: %d\n",
128		le16toh(rp.num_sco_pkt));
129
130	return (OK);
131} /* hci_read_buffer_size */
132
133/* Send Read_Country_Code command to the unit */
134static int
135hci_read_country_code(int s, int argc, char **argv)
136{
137	ng_hci_read_country_code_rp	rp;
138	int				n;
139
140	n = sizeof(rp);
141	if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,
142			NG_HCI_OCF_READ_COUNTRY_CODE),
143			(char *) &rp, &n) == ERROR)
144		return (ERROR);
145
146	if (rp.status != 0x00) {
147		fprintf(stdout, "Status: %s [%#02x]\n",
148			hci_status2str(rp.status), rp.status);
149		return (FAILED);
150	}
151
152	fprintf(stdout, "Country code: %s [%#02x]\n",
153			hci_cc2str(rp.country_code), rp.country_code);
154
155	return (OK);
156} /* hci_read_country_code */
157
158/* Send Read_BD_ADDR command to the unit */
159static int
160hci_read_bd_addr(int s, int argc, char **argv)
161{
162	ng_hci_read_bdaddr_rp	rp;
163	int			n;
164
165	n = sizeof(rp);
166	if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,
167			NG_HCI_OCF_READ_BDADDR), (char *) &rp, &n) == ERROR)
168		return (ERROR);
169
170	if (rp.status != 0x00) {
171		fprintf(stdout, "Status: %s [%#02x]\n",
172			hci_status2str(rp.status), rp.status);
173		return (FAILED);
174	}
175
176	fprintf(stdout, "BD_ADDR: %02x:%02x:%02x:%02x:%02x:%02x\n",
177		rp.bdaddr.b[5], rp.bdaddr.b[4], rp.bdaddr.b[3],
178		rp.bdaddr.b[2], rp.bdaddr.b[1], rp.bdaddr.b[0]);
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