4 * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
28 * $Id: status.c,v 1.2 2003/05/21 22:40:30 max Exp $
32 #include <sys/types.h>
33 #include <sys/endian.h>
35 #include <netgraph/bluetooth/include/ng_hci.h>
37 #include "hccontrol.h"
39 /* Send Read_Failed_Contact_Counter command to the unit */
41 hci_read_failed_contact_counter(int s, int argc, char **argv)
43 ng_hci_read_failed_contact_cntr_cp cp;
44 ng_hci_read_failed_contact_cntr_rp rp;
49 /* connection handle */
50 if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff)
53 cp.con_handle = (uint16_t) (n & 0x0fff);
54 cp.con_handle = htole16(cp.con_handle);
63 if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_STATUS,
64 NG_HCI_OCF_READ_FAILED_CONTACT_CNTR),
65 (char const *) &cp, sizeof(cp),
66 (char *) &rp, &n) == ERROR)
69 if (rp.status != 0x00) {
70 fprintf(stdout, "Status: %s [%#02x]\n",
71 hci_status2str(rp.status), rp.status);
75 fprintf(stdout, "Connection handle: %d\n", le16toh(rp.con_handle));
76 fprintf(stdout, "Failed contact counter: %d\n", le16toh(rp.counter));
79 } /* hci_read_failed_contact_counter */
81 /* Send Reset_Failed_Contact_Counter command to the unit */
83 hci_reset_failed_contact_counter(int s, int argc, char **argv)
85 ng_hci_reset_failed_contact_cntr_cp cp;
86 ng_hci_reset_failed_contact_cntr_rp rp;
91 /* connection handle */
92 if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff)
95 cp.con_handle = (uint16_t) (n & 0x0fff);
96 cp.con_handle = htole16(cp.con_handle);
105 if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_STATUS,
106 NG_HCI_OCF_RESET_FAILED_CONTACT_CNTR),
107 (char const *) &cp, sizeof(cp),
108 (char *) &rp, &n) == ERROR)
111 if (rp.status != 0x00) {
112 fprintf(stdout, "Status: %s [%#02x]\n",
113 hci_status2str(rp.status), rp.status);
118 } /* hci_reset_failed_contact_counter */
120 /* Sent Get_Link_Quality command to the unit */
122 hci_get_link_quality(int s, int argc, char **argv)
124 ng_hci_get_link_quality_cp cp;
125 ng_hci_get_link_quality_rp rp;
130 /* connection handle */
131 if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff)
134 cp.con_handle = (uint16_t) (n & 0x0fff);
135 cp.con_handle = htole16(cp.con_handle);
144 if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_STATUS,
145 NG_HCI_OCF_GET_LINK_QUALITY),
146 (char const *) &cp, sizeof(cp),
147 (char *) &rp, &n) == ERROR)
150 if (rp.status != 0x00) {
151 fprintf(stdout, "Status: %s [%#02x]\n",
152 hci_status2str(rp.status), rp.status);
156 fprintf(stdout, "Connection handle: %d\n", le16toh(rp.con_handle));
157 fprintf(stdout, "Link quality: %d\n", le16toh(rp.quality));
160 } /* hci_get_link_quality */
162 /* Send Read_RSSI command to the unit */
164 hci_read_rssi(int s, int argc, char **argv)
166 ng_hci_read_rssi_cp cp;
167 ng_hci_read_rssi_rp rp;
172 /* connection handle */
173 if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff)
176 cp.con_handle = (uint16_t) (n & 0x0fff);
177 cp.con_handle = htole16(cp.con_handle);
186 if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_STATUS,
187 NG_HCI_OCF_READ_RSSI),
188 (char const *) &cp, sizeof(cp),
189 (char *) &rp, &n) == ERROR)
192 if (rp.status != 0x00) {
193 fprintf(stdout, "Status: %s [%#02x]\n",
194 hci_status2str(rp.status), rp.status);
198 fprintf(stdout, "Connection handle: %d\n", le16toh(rp.con_handle));
199 fprintf(stdout, "RSSI: %d dB\n", (int) rp.rssi);
202 } /* hci_read_rssi */
204 struct hci_command status_commands[] = {
206 "read_failed_contact_counter <connection_handle>",
207 "\nThis command will read the value for the Failed_Contact_Counter\n" \
208 "parameter for a particular ACL connection to another device.\n\n" \
209 "\t<connection_handle> - dddd; ACL connection handle\n",
210 &hci_read_failed_contact_counter
213 "reset_failed_contact_counter <connection_handle>",
214 "\nThis command will reset the value for the Failed_Contact_Counter\n" \
215 "parameter for a particular ACL connection to another device.\n\n" \
216 "\t<connection_handle> - dddd; ACL connection handle\n",
217 &hci_reset_failed_contact_counter
220 "get_link_quality <connection_handle>",
221 "\nThis command will return the value for the Link_Quality for the\n" \
222 "specified ACL connection handle. This command will return a Link_Quality\n" \
223 "value from 0-255, which represents the quality of the link between two\n" \
224 "Bluetooth devices. The higher the value, the better the link quality is.\n" \
225 "Each Bluetooth module vendor will determine how to measure the link quality." \
227 "\t<connection_handle> - dddd; ACL connection handle\n",
228 &hci_get_link_quality
231 "read_rssi <connection_handle>",
232 "\nThis command will read the value for the difference between the\n" \
233 "measured Received Signal Strength Indication (RSSI) and the limits of\n" \
234 "the Golden Receive Power Range for a ACL connection handle to another\n" \
235 "Bluetooth device. Any positive RSSI value returned by the Host Controller\n" \
236 "indicates how many dB the RSSI is above the upper limit, any negative\n" \
237 "value indicates how many dB the RSSI is below the lower limit. The value\n" \
238 "zero indicates that the RSSI is inside the Golden Receive Power Range.\n\n" \
239 "\t<connection_handle> - dddd; ACL connection handle\n",