4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
6 * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.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
30 * $Id: status.c,v 1.2 2003/05/21 22:40:30 max Exp $
34 #include <sys/types.h>
35 #include <sys/endian.h>
37 #include <netgraph/bluetooth/include/ng_hci.h>
39 #include "hccontrol.h"
41 /* Send Read_Failed_Contact_Counter command to the unit */
43 hci_read_failed_contact_counter(int s, int argc, char **argv)
45 ng_hci_read_failed_contact_cntr_cp cp;
46 ng_hci_read_failed_contact_cntr_rp rp;
51 /* connection handle */
52 if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff)
55 cp.con_handle = (uint16_t) (n & 0x0fff);
56 cp.con_handle = htole16(cp.con_handle);
65 if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_STATUS,
66 NG_HCI_OCF_READ_FAILED_CONTACT_CNTR),
67 (char const *) &cp, sizeof(cp),
68 (char *) &rp, &n) == ERROR)
71 if (rp.status != 0x00) {
72 fprintf(stdout, "Status: %s [%#02x]\n",
73 hci_status2str(rp.status), rp.status);
77 fprintf(stdout, "Connection handle: %d\n", le16toh(rp.con_handle));
78 fprintf(stdout, "Failed contact counter: %d\n", le16toh(rp.counter));
81 } /* hci_read_failed_contact_counter */
83 /* Send Reset_Failed_Contact_Counter command to the unit */
85 hci_reset_failed_contact_counter(int s, int argc, char **argv)
87 ng_hci_reset_failed_contact_cntr_cp cp;
88 ng_hci_reset_failed_contact_cntr_rp rp;
93 /* connection handle */
94 if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff)
97 cp.con_handle = (uint16_t) (n & 0x0fff);
98 cp.con_handle = htole16(cp.con_handle);
107 if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_STATUS,
108 NG_HCI_OCF_RESET_FAILED_CONTACT_CNTR),
109 (char const *) &cp, sizeof(cp),
110 (char *) &rp, &n) == ERROR)
113 if (rp.status != 0x00) {
114 fprintf(stdout, "Status: %s [%#02x]\n",
115 hci_status2str(rp.status), rp.status);
120 } /* hci_reset_failed_contact_counter */
122 /* Sent Get_Link_Quality command to the unit */
124 hci_get_link_quality(int s, int argc, char **argv)
126 ng_hci_get_link_quality_cp cp;
127 ng_hci_get_link_quality_rp rp;
132 /* connection handle */
133 if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff)
136 cp.con_handle = (uint16_t) (n & 0x0fff);
137 cp.con_handle = htole16(cp.con_handle);
146 if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_STATUS,
147 NG_HCI_OCF_GET_LINK_QUALITY),
148 (char const *) &cp, sizeof(cp),
149 (char *) &rp, &n) == ERROR)
152 if (rp.status != 0x00) {
153 fprintf(stdout, "Status: %s [%#02x]\n",
154 hci_status2str(rp.status), rp.status);
158 fprintf(stdout, "Connection handle: %d\n", le16toh(rp.con_handle));
159 fprintf(stdout, "Link quality: %d\n", le16toh(rp.quality));
162 } /* hci_get_link_quality */
164 /* Send Read_RSSI command to the unit */
166 hci_read_rssi(int s, int argc, char **argv)
168 ng_hci_read_rssi_cp cp;
169 ng_hci_read_rssi_rp rp;
174 /* connection handle */
175 if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff)
178 cp.con_handle = (uint16_t) (n & 0x0fff);
179 cp.con_handle = htole16(cp.con_handle);
188 if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_STATUS,
189 NG_HCI_OCF_READ_RSSI),
190 (char const *) &cp, sizeof(cp),
191 (char *) &rp, &n) == ERROR)
194 if (rp.status != 0x00) {
195 fprintf(stdout, "Status: %s [%#02x]\n",
196 hci_status2str(rp.status), rp.status);
200 fprintf(stdout, "Connection handle: %d\n", le16toh(rp.con_handle));
201 fprintf(stdout, "RSSI: %d dB\n", (int) rp.rssi);
204 } /* hci_read_rssi */
206 struct hci_command status_commands[] = {
208 "read_failed_contact_counter <connection_handle>",
209 "\nThis command will read the value for the Failed_Contact_Counter\n" \
210 "parameter for a particular ACL connection to another device.\n\n" \
211 "\t<connection_handle> - dddd; ACL connection handle\n",
212 &hci_read_failed_contact_counter
215 "reset_failed_contact_counter <connection_handle>",
216 "\nThis command will reset the value for the Failed_Contact_Counter\n" \
217 "parameter for a particular ACL connection to another device.\n\n" \
218 "\t<connection_handle> - dddd; ACL connection handle\n",
219 &hci_reset_failed_contact_counter
222 "get_link_quality <connection_handle>",
223 "\nThis command will return the value for the Link_Quality for the\n" \
224 "specified ACL connection handle. This command will return a Link_Quality\n" \
225 "value from 0-255, which represents the quality of the link between two\n" \
226 "Bluetooth devices. The higher the value, the better the link quality is.\n" \
227 "Each Bluetooth module vendor will determine how to measure the link quality." \
229 "\t<connection_handle> - dddd; ACL connection handle\n",
230 &hci_get_link_quality
233 "read_rssi <connection_handle>",
234 "\nThis command will read the value for the difference between the\n" \
235 "measured Received Signal Strength Indication (RSSI) and the limits of\n" \
236 "the Golden Receive Power Range for a ACL connection handle to another\n" \
237 "Bluetooth device. Any positive RSSI value returned by the Host Controller\n" \
238 "indicates how many dB the RSSI is above the upper limit, any negative\n" \
239 "value indicates how many dB the RSSI is below the lower limit. The value\n" \
240 "zero indicates that the RSSI is inside the Golden Receive Power Range.\n\n" \
241 "\t<connection_handle> - dddd; ACL connection handle\n",