Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/btconfig fiddle with printing of "Class of Device" ...
details: https://anonhg.NetBSD.org/src/rev/c84f5da7e612
branches: trunk
changeset: 747998:c84f5da7e612
user: plunky <plunky%NetBSD.org@localhost>
date: Thu Oct 08 19:25:24 2009 +0000
description:
fiddle with printing of "Class of Device" information
- pass the octet stream pointer to the function
- only print where the format is known (we only know format #0)
- use language from the Baseband Assigned numbers document
- use bit numbers from the Baseband Assigned numbers document
- add Health device major class
diffstat:
usr.sbin/btconfig/btconfig.c | 393 ++++++++++++++----------------------------
1 files changed, 134 insertions(+), 259 deletions(-)
diffs (truncated from 614 to 300 lines):
diff -r e50228efed35 -r c84f5da7e612 usr.sbin/btconfig/btconfig.c
--- a/usr.sbin/btconfig/btconfig.c Thu Oct 08 19:06:49 2009 +0000
+++ b/usr.sbin/btconfig/btconfig.c Thu Oct 08 19:25:24 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: btconfig.c,v 1.17 2009/09/11 19:22:15 plunky Exp $ */
+/* $NetBSD: btconfig.c,v 1.18 2009/10/08 19:25:24 plunky Exp $ */
/*-
* Copyright (c) 2006 Itronix Inc.
@@ -33,7 +33,7 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2006 Itronix, Inc. All rights reserved.");
-__RCSID("$NetBSD: btconfig.c,v 1.17 2009/09/11 19:22:15 plunky Exp $");
+__RCSID("$NetBSD: btconfig.c,v 1.18 2009/10/08 19:25:24 plunky Exp $");
#include <sys/ioctl.h>
#include <sys/param.h>
@@ -48,15 +48,6 @@
#include <unistd.h>
#include <util.h>
-/* inquiry results storage */
-struct result {
- bdaddr_t bdaddr;
- uint8_t page_scan_rep_mode;
- uint8_t uclass[HCI_CLASS_SIZE];
- uint16_t clock_offset;
- int8_t rssi;
-};
-
int main(int, char *[]);
void badarg(const char *);
void badparam(const char *);
@@ -67,19 +58,19 @@
void print_val(const char *, const char **, int);
void print_info(int);
void print_stats(void);
-void print_class(const char *);
+void print_class(const char *, uint8_t *);
+void print_class0(void);
void print_voice(int);
void tag(const char *);
void print_features(const char *, uint8_t, uint8_t *);
void print_features0(uint8_t *);
void print_features1(uint8_t *);
+void print_result(int, struct bt_devinquiry *);
void do_inquiry(void);
-void print_result(int, struct result *, int);
void hci_req(uint16_t, uint8_t , void *, size_t, void *, size_t);
-#define save_value(opcode, cbuf, clen) hci_req(opcode, 0, cbuf, clen, NULL, 0)
-#define load_value(opcode, rbuf, rlen) hci_req(opcode, 0, NULL, 0, rbuf, rlen)
-#define hci_cmd(opcode, cbuf, clen) hci_req(opcode, 0, cbuf, clen, NULL, 0)
+void save_value(uint16_t, void *, size_t);
+void load_value(uint16_t, void *, size_t);
#define MAX_STR_SIZE 0xff
@@ -151,7 +142,7 @@
int opt_rssi = 0; /* inquiry_with_rssi (obsolete flag) */
int opt_imode = 0; /* inquiry mode */
int opt_inquiry = 0;
-#define INQUIRY_LENGTH 10 /* about 12 seconds */
+#define INQUIRY_LENGTH 10 /* seconds */
#define INQUIRY_MAX_RESPONSES 10
const char *imodes[] = { "std", "rssi", "ext", NULL };
@@ -390,88 +381,53 @@
}
/*
- * basic HCI cmd request function with argument return.
- *
- * Normally, this will return on COMMAND_STATUS or COMMAND_COMPLETE for the given
- * opcode, but if event is given then it will ignore COMMAND_STATUS (unless error)
- * and wait for the specified event.
- *
- * if rbuf/rlen is given, results will be copied into the result buffer for
- * COMMAND_COMPLETE/event responses.
+ * basic HCI request wrapper with error check
*/
void
-hci_req(uint16_t opcode, uint8_t event, void *cbuf, size_t clen, void *rbuf, size_t rlen)
+hci_req(uint16_t opcode, uint8_t event, void *cbuf, size_t clen,
+ void *rbuf, size_t rlen)
{
- uint8_t msg[sizeof(hci_cmd_hdr_t) + HCI_CMD_PKT_SIZE];
- hci_event_hdr_t *ep;
- hci_cmd_hdr_t *cp;
-
- cp = (hci_cmd_hdr_t *)msg;
- cp->type = HCI_CMD_PKT;
- cp->opcode = opcode = htole16(opcode);
- cp->length = clen = MIN(clen, sizeof(msg) - sizeof(hci_cmd_hdr_t));
-
- if (clen) memcpy((cp + 1), cbuf, clen);
-
- if (send(hci, msg, sizeof(hci_cmd_hdr_t) + clen, 0) < 0)
- err(EXIT_FAILURE, "HCI Send");
+ struct bt_devreq req;
- ep = (hci_event_hdr_t *)msg;
- for(;;) {
- if (recv(hci, msg, sizeof(msg), 0) < 0) {
- if (errno == EAGAIN || errno == EINTR)
- continue;
+ req.opcode = opcode;
+ req.event = event;
+ req.cparam = cbuf;
+ req.clen = clen;
+ req.rparam = rbuf;
+ req.rlen = rlen;
- err(EXIT_FAILURE, "HCI Recv");
- }
+ if (bt_devreq(hci, &req, 10) == -1)
+ err(EXIT_FAILURE, "cmd (%02x|%03x)",
+ HCI_OGF(opcode), HCI_OCF(opcode));
- if (ep->event == HCI_EVENT_COMMAND_STATUS) {
- hci_command_status_ep *cs;
-
- cs = (hci_command_status_ep *)(ep + 1);
- if (cs->opcode != opcode)
- continue;
+ if (event == 0 && rlen > 0 && ((uint8_t *)rbuf)[0] != 0)
+ errx(EXIT_FAILURE, "cmd (%02x|%03x): status 0x%02x",
+ HCI_OGF(opcode), HCI_OCF(opcode), ((uint8_t *)rbuf)[0]);
+}
- if (cs->status)
- errx(EXIT_FAILURE,
- "HCI cmd (%4.4x) failed (status %d)",
- opcode, cs->status);
-
- if (event == 0)
- break;
+/*
+ * write value to device with opcode.
+ * provide a small response buffer so that the status can be checked
+ */
+void
+save_value(uint16_t opcode, void *cbuf, size_t clen)
+{
+ uint8_t buf[1];
- continue;
- }
-
- if (ep->event == HCI_EVENT_COMMAND_COMPL) {
- hci_command_compl_ep *cc;
- uint8_t *ptr;
-
- cc = (hci_command_compl_ep *)(ep + 1);
- if (cc->opcode != opcode)
- continue;
+ hci_req(opcode, 0, cbuf, clen, buf, sizeof(buf));
+}
- if (rbuf == NULL)
- break;
-
- ptr = (uint8_t *)(cc + 1);
- if (*ptr)
- errx(EXIT_FAILURE,
- "HCI cmd (%4.4x) failed (status %d)",
- opcode, *ptr);
+/*
+ * read value from device with opcode.
+ * use our own buffer and only return the value from the response packet
+ */
+void
+load_value(uint16_t opcode, void *rbuf, size_t rlen)
+{
+ uint8_t buf[UINT8_MAX];
- memcpy(rbuf, ++ptr, rlen);
- break;
- }
-
- if (ep->event == event) {
- if (rbuf == NULL)
- break;
-
- memcpy(rbuf, (ep + 1), rlen);
- break;
- }
- }
+ hci_req(opcode, 0, NULL, 0, buf, sizeof(buf));
+ memcpy(rbuf, buf + 1, rlen);
}
int
@@ -505,11 +461,8 @@
config_unit(void)
{
- if (opt_enable) {
- if (opt_enable > 0)
- btr.btr_flags |= BTF_UP;
- else
- btr.btr_flags &= ~BTF_UP;
+ if (opt_enable < 0 || opt_reset) {
+ btr.btr_flags &= ~BTF_UP;
if (ioctl(hci, SIOCSBTFLAGS, &btr) < 0)
err(EXIT_FAILURE, "SIOCSBTFLAGS");
@@ -518,22 +471,12 @@
err(EXIT_FAILURE, "%s", btr.btr_name);
}
- if (opt_reset) {
- hci_cmd(HCI_CMD_RESET, NULL, 0);
+ if (opt_enable > 0 || opt_reset) {
+ btr.btr_flags |= BTF_UP;
- btr.btr_flags |= BTF_INIT;
if (ioctl(hci, SIOCSBTFLAGS, &btr) < 0)
err(EXIT_FAILURE, "SIOCSBTFLAGS");
- /*
- * although the reset command will automatically
- * carry out these commands, we do them manually
- * just so we can wait for completion.
- */
- hci_cmd(HCI_CMD_READ_BDADDR, NULL, 0);
- hci_cmd(HCI_CMD_READ_BUFFER_SIZE, NULL, 0);
- hci_cmd(HCI_CMD_READ_LOCAL_FEATURES, NULL, 0);
-
if (set_unit(SIOCGBTINFO) < 0)
err(EXIT_FAILURE, "%s", btr.btr_name);
}
@@ -713,8 +656,7 @@
}
load_value(HCI_CMD_READ_UNIT_CLASS, buf, HCI_CLASS_SIZE);
- class = (buf[2] << 16) | (buf[1] << 8) | (buf[0]);
- print_class("\t");
+ print_class("\tclass:", buf);
load_value(HCI_CMD_READ_LOCAL_NAME, buf, HCI_UNIT_NAME_SIZE);
printf("\tname: \"%s\"\n", buf);
@@ -790,15 +732,17 @@
if ((buf[7] & HCI_LMP_EXTENDED_FEATURES) == 0) {
print_features("\tfeatures:", 0, buf);
} else {
- buf[0] = 0;
+ hci_read_local_extended_features_rp rp;
+
+ rp.page = 0;
do {
hci_req(HCI_CMD_READ_LOCAL_EXTENDED_FEATURES, 0,
- buf, 1,
- buf, HCI_FEATURES_SIZE + 2);
+ &rp.page, sizeof(rp.page), &rp, sizeof(rp));
- print_features("\tfeatures page#%d:", buf[0], buf + 2);
- } while (buf[0]++ < buf[1]);
+ print_features("\tfeatures (page %d):",
+ rp.page, rp.features);
+ } while (rp.page++ < rp.max_page);
}
}
@@ -934,30 +878,39 @@
}
void
-print_class(const char *str)
+print_class(const char *str, uint8_t *uclass)
{
- int major, minor;
+
+ class = (uclass[2] << 16) | (uclass[1] << 8) | uclass[0];
+ width = printf("%s [0x%06x]", str, class);
- major = (class & 0x1f00) >> 8;
- minor = (class & 0x00fc) >> 2;
+ switch(__SHIFTOUT(class, __BITS(0, 1))) {
+ case 0: print_class0(); break;
+ default: break;
+ }
- width = printf("%sclass: [0x%6.6x]", str, class);
+ tag(NULL);
+}
- switch (major) {
+void
+print_class0(void)
+{
+
+ switch (__SHIFTOUT(class, __BITS(8, 12))) {
case 1: /* Computer */
- switch (minor) {
- case 1: tag("Desktop"); break;
- case 2: tag("Server"); break;
+ switch (__SHIFTOUT(class, __BITS(2, 7))) {
Home |
Main Index |
Thread Index |
Old Index