Module Name: src Committed By: plunky Date: Mon Oct 5 12:34:26 UTC 2009
Modified Files: src/usr.sbin/bthcid: bthcid.c bthcid.h hci.c Log Message: use the bt_dev(3) API for increased portability To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/bthcid/bthcid.c cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/bthcid/bthcid.h cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/bthcid/hci.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.sbin/bthcid/bthcid.c diff -u src/usr.sbin/bthcid/bthcid.c:1.4 src/usr.sbin/bthcid/bthcid.c:1.5 --- src/usr.sbin/bthcid/bthcid.c:1.4 Mon Jul 21 13:36:57 2008 +++ src/usr.sbin/bthcid/bthcid.c Mon Oct 5 12:34:26 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: bthcid.c,v 1.4 2008/07/21 13:36:57 lukem Exp $ */ +/* $NetBSD: bthcid.c,v 1.5 2009/10/05 12:34:26 plunky Exp $ */ /*- * Copyright (c) 2006 Itronix Inc. @@ -33,7 +33,7 @@ __COPYRIGHT("@(#) Copyright (c) 2006 Itronix, Inc.\ Copyright (c) 2001-2002 Maksim Yevmenkin m_evmen...@yahoo.com.\ All rights reserved."); -__RCSID("$NetBSD: bthcid.c,v 1.4 2008/07/21 13:36:57 lukem Exp $"); +__RCSID("$NetBSD: bthcid.c,v 1.5 2009/10/05 12:34:26 plunky Exp $"); #include <sys/param.h> #include <sys/stat.h> @@ -62,18 +62,17 @@ int main(int argc, char *argv[]) { - bdaddr_t bdaddr; + const char *device; int ch; mode_t mode; - bdaddr_copy(&bdaddr, BDADDR_ANY); + device = NULL; mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP; while ((ch = getopt(argc, argv, "d:fm:ns:h")) != -1) { switch (ch) { case 'd': - if (!bt_devaddr(optarg, &bdaddr)) - err(EXIT_FAILURE, "%s", optarg); + device = optarg; break; case 'f': @@ -130,8 +129,8 @@ exit(EXIT_FAILURE); } - if (init_hci(&bdaddr) < 0) { - syslog(LOG_ERR, "init_hci(%s)", bt_ntoa(&bdaddr, NULL)); + if (init_hci(device) < 0) { + syslog(LOG_ERR, "init_hci(%s)", device); exit(EXIT_FAILURE); } @@ -172,7 +171,7 @@ { fprintf(stderr, - "Usage: %s [-fhn] [-c config] [-d devaddr] [-m mode] [-s path]\n" + "Usage: %s [-fhn] [-c config] [-d device] [-m mode] [-s path]\n" "Where:\n" "\t-c config specify config filename\n" "\t-d device specify device address\n" Index: src/usr.sbin/bthcid/bthcid.h diff -u src/usr.sbin/bthcid/bthcid.h:1.3 src/usr.sbin/bthcid/bthcid.h:1.4 --- src/usr.sbin/bthcid/bthcid.h:1.3 Tue Sep 26 19:18:19 2006 +++ src/usr.sbin/bthcid/bthcid.h Mon Oct 5 12:34:26 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: bthcid.h,v 1.3 2006/09/26 19:18:19 plunky Exp $ */ +/* $NetBSD: bthcid.h,v 1.4 2009/10/05 12:34:26 plunky Exp $ */ /*- * Copyright (c) 2006 Itronix Inc. @@ -42,7 +42,7 @@ uint8_t *lookup_pin (bdaddr_t *, bdaddr_t *); /* hci.c */ -int init_hci (bdaddr_t *); +int init_hci (const char *); int send_pin_code_reply (int, struct sockaddr_bt *, bdaddr_t *, uint8_t *); #endif /* _BTHCID_H_ */ Index: src/usr.sbin/bthcid/hci.c diff -u src/usr.sbin/bthcid/hci.c:1.2 src/usr.sbin/bthcid/hci.c:1.3 --- src/usr.sbin/bthcid/hci.c:1.2 Thu Jan 25 20:33:41 2007 +++ src/usr.sbin/bthcid/hci.c Mon Oct 5 12:34:26 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: hci.c,v 1.2 2007/01/25 20:33:41 plunky Exp $ */ +/* $NetBSD: hci.c,v 1.3 2009/10/05 12:34:26 plunky Exp $ */ /*- * Copyright (c) 2006 Itronix Inc. @@ -55,7 +55,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: hci.c,v 1.2 2007/01/25 20:33:41 plunky Exp $"); +__RCSID("$NetBSD: hci.c,v 1.3 2009/10/05 12:34:26 plunky Exp $"); #include <sys/ioctl.h> #include <sys/time.h> @@ -89,32 +89,21 @@ /* Initialise HCI Events */ int -init_hci(bdaddr_t *bdaddr) +init_hci(const char *device) { - struct sockaddr_bt sa; - struct hci_filter filter; + struct bt_devfilter filter; int hci; - hci = socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); + hci = bt_devopen(device, 0); if (hci < 0) return -1; - memset(&sa, 0, sizeof(sa)); - sa.bt_len = sizeof(sa); - sa.bt_family = AF_BLUETOOTH; - bdaddr_copy(&sa.bt_bdaddr, bdaddr); - if (bind(hci, (struct sockaddr *)&sa, sizeof(sa)) < 0) { - close(hci); - return -1; - } - memset(&filter, 0, sizeof(filter)); - hci_filter_set(HCI_EVENT_PIN_CODE_REQ, &filter); - hci_filter_set(HCI_EVENT_LINK_KEY_REQ, &filter); - hci_filter_set(HCI_EVENT_LINK_KEY_NOTIFICATION, &filter); - - if (setsockopt(hci, BTPROTO_HCI, SO_HCI_EVT_FILTER, - (const void *)&filter, sizeof(filter)) < 0) { + bt_devfilter_pkt_set(&filter, HCI_EVENT_PKT); + bt_devfilter_evt_set(&filter, HCI_EVENT_PIN_CODE_REQ); + bt_devfilter_evt_set(&filter, HCI_EVENT_LINK_KEY_REQ); + bt_devfilter_evt_set(&filter, HCI_EVENT_LINK_KEY_NOTIFICATION); + if (bt_devfilter(hci, &filter, NULL) < 0) { close(hci); return -1; }