summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bluetooth/hccontrol/hccontrol.c
diff options
context:
space:
mode:
authormarkus <markus@FreeBSD.org>2006-05-22 17:58:09 +0000
committermarkus <markus@FreeBSD.org>2006-05-22 17:58:09 +0000
commit583587debb36a5d8742e2c0878d7f05293ef8000 (patch)
treec78652a387f02ed912650bf02a36cec2dd3dbe97 /usr.sbin/bluetooth/hccontrol/hccontrol.c
parent83d28e2330e303ab86bb548bc7d4dc0fa8ae3c2b (diff)
downloadFreeBSD-src-583587debb36a5d8742e2c0878d7f05293ef8000.zip
FreeBSD-src-583587debb36a5d8742e2c0878d7f05293ef8000.tar.gz
- Add HCI node autodetection. As a consequence of this, make the '-n'
parameter optional. - Add Read_Node_List command which prints a list of available HCI nodes, their Netgraph IDs and connected hooks Reviewed by: emax Approved by: emax MFC after: 1 week
Diffstat (limited to 'usr.sbin/bluetooth/hccontrol/hccontrol.c')
-rw-r--r--usr.sbin/bluetooth/hccontrol/hccontrol.c60
1 files changed, 53 insertions, 7 deletions
diff --git a/usr.sbin/bluetooth/hccontrol/hccontrol.c b/usr.sbin/bluetooth/hccontrol/hccontrol.c
index 0bf5583..c77200e 100644
--- a/usr.sbin/bluetooth/hccontrol/hccontrol.c
+++ b/usr.sbin/bluetooth/hccontrol/hccontrol.c
@@ -30,10 +30,12 @@
*/
#include <bluetooth.h>
+#include <sys/ioctl.h>
#include <sys/sysctl.h>
#include <assert.h>
#include <err.h>
#include <errno.h>
+#include <netgraph/ng_message.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -43,6 +45,7 @@
/* Prototypes */
static int do_hci_command (char const *, int, char **);
static struct hci_command * find_hci_command (char const *, struct hci_command *);
+static int find_hci_nodes (struct nodeinfo **);
static void print_hci_command (struct hci_command *);
static void usage (void);
@@ -94,13 +97,21 @@ main(int argc, char *argv[])
static int
socket_open(char const *node)
{
- struct sockaddr_hci addr;
- struct ng_btsocket_hci_raw_filter filter;
- int s, mib[4];
- size_t size;
+ struct sockaddr_hci addr;
+ struct ng_btsocket_hci_raw_filter filter;
+ int s, mib[4];
+ size_t size;
+ struct nodeinfo *nodes;
+
+ if (find_hci_nodes(&nodes) == 0)
+ err(7, "Could not find HCI nodes");
+
+ if (node == NULL) {
+ node = strdup(nodes[0].name);
+ fprintf(stdout, "Using HCI node: %s\n", node);
+ }
- if (node == NULL)
- usage();
+ free(nodes);
s = socket(PF_BLUETOOTH, SOCK_RAW, BLUETOOTH_PROTO_HCI);
if (s < 0)
@@ -254,6 +265,41 @@ find_hci_command(char const *command, struct hci_command *category)
return (NULL);
} /* find_hci_command */
+/* Find all HCI nodes */
+static int
+find_hci_nodes(struct nodeinfo** nodes)
+{
+ struct ng_btsocket_hci_raw_node_list_names r;
+ struct sockaddr_hci addr;
+ int s;
+ const char * node = "ubt0hci";
+
+ r.num_names = MAX_NODE_NUM;
+ r.names = (struct nodeinfo*)calloc(MAX_NODE_NUM, sizeof(struct nodeinfo));
+ if (r.names == NULL)
+ err(8, "Could not allocate memory");
+
+ s = socket(PF_BLUETOOTH, SOCK_RAW, BLUETOOTH_PROTO_HCI);
+ if (s < 0)
+ err(9, "Could not create socket");
+
+ memset(&addr, 0, sizeof(addr));
+ addr.hci_len = sizeof(addr);
+ addr.hci_family = AF_BLUETOOTH;
+ strncpy(addr.hci_node, node, sizeof(addr.hci_node));
+ if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0)
+ err(10, "Could not bind socket");
+
+ if (ioctl(s, SIOC_HCI_RAW_NODE_LIST_NAMES, &r, sizeof(r)) < 0)
+ err(11, "Could not get list of HCI nodes");
+
+ close(s);
+
+ *nodes = r.names;
+
+ return (r.num_names);
+} /* find_hci_nodes */
+
/* Print commands in specified category */
static void
print_hci_command(struct hci_command *category)
@@ -268,7 +314,7 @@ print_hci_command(struct hci_command *category)
static void
usage(void)
{
- fprintf(stdout, "Usage: hccontrol -n HCI_node_name [-h] cmd [p1] [..]]\n");
+ fprintf(stdout, "Usage: hccontrol [-hN] [-n HCI_node_name] cmd [p1] [..]\n");
exit(255);
} /* usage */
OpenPOWER on IntegriCloud