Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/bthcid use the bt_dev(3) API for increased portability
details: https://anonhg.NetBSD.org/src/rev/4a6a9f714609
branches: trunk
changeset: 747906:4a6a9f714609
user: plunky <plunky%NetBSD.org@localhost>
date: Mon Oct 05 12:34:26 2009 +0000
description:
use the bt_dev(3) API for increased portability
diffstat:
usr.sbin/bthcid/bthcid.c | 17 ++++++++---------
usr.sbin/bthcid/bthcid.h | 4 ++--
usr.sbin/bthcid/hci.c | 31 ++++++++++---------------------
3 files changed, 20 insertions(+), 32 deletions(-)
diffs (137 lines):
diff -r daf7f03d1d80 -r 4a6a9f714609 usr.sbin/bthcid/bthcid.c
--- a/usr.sbin/bthcid/bthcid.c Mon Oct 05 10:47:52 2009 +0000
+++ b/usr.sbin/bthcid/bthcid.c Mon Oct 05 12:34:26 2009 +0000
@@ -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_evmenkin%yahoo.com@localhost.\
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"
diff -r daf7f03d1d80 -r 4a6a9f714609 usr.sbin/bthcid/bthcid.h
--- a/usr.sbin/bthcid/bthcid.h Mon Oct 05 10:47:52 2009 +0000
+++ b/usr.sbin/bthcid/bthcid.h Mon Oct 05 12:34:26 2009 +0000
@@ -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_ */
diff -r daf7f03d1d80 -r 4a6a9f714609 usr.sbin/bthcid/hci.c
--- a/usr.sbin/bthcid/hci.c Mon Oct 05 10:47:52 2009 +0000
+++ b/usr.sbin/bthcid/hci.c Mon Oct 05 12:34:26 2009 +0000
@@ -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;
}
Home |
Main Index |
Thread Index |
Old Index