diff options
-rw-r--r-- | usr.sbin/btctl/Makefile | 9 | ||||
-rw-r--r-- | usr.sbin/btctl/btctl.h | 3 | ||||
-rw-r--r-- | usr.sbin/btctl/parse.y | 21 | ||||
-rw-r--r-- | usr.sbin/btd/Makefile | 11 | ||||
-rw-r--r-- | usr.sbin/btd/bt.c | 3 | ||||
-rw-r--r-- | usr.sbin/btd/btd.h | 47 | ||||
-rw-r--r-- | usr.sbin/btd/conf.c | 161 | ||||
-rw-r--r-- | usr.sbin/btd/control.c | 126 | ||||
-rw-r--r-- | usr.sbin/btd/db.c | 1 | ||||
-rw-r--r-- | usr.sbin/btd/devinfo.c | 1 | ||||
-rw-r--r-- | usr.sbin/btd/hci.c | 38 | ||||
-rw-r--r-- | usr.sbin/btd/log.c | 3 | ||||
-rw-r--r-- | usr.sbin/btd/parse.y | 3 | ||||
-rw-r--r-- | usr.sbin/btd/sdp.c | 3 |
14 files changed, 279 insertions, 151 deletions
diff --git a/usr.sbin/btctl/Makefile b/usr.sbin/btctl/Makefile index 75d6649e1a6..48fb7517db0 100644 --- a/usr.sbin/btctl/Makefile +++ b/usr.sbin/btctl/Makefile @@ -1,14 +1,13 @@ -# $OpenBSD: Makefile,v 1.1 2008/11/24 23:34:41 uwe Exp $ +# $OpenBSD: Makefile,v 1.2 2008/11/25 17:13:53 uwe Exp $ .PATH: ${.CURDIR}/../btd PROG= btctl -SRCS= btctl.c conf.c log.c parse.y +SRCS= bt_subr.c btctl.c conf.c log.c parse.y NOMAN= -LDADD+= -lbluetooth -lsdp -lusbhid -LDFLAGS+= -L/usr/local/lib -CPPFLAGS+= -I${.CURDIR} -I${.CURDIR}/../btd -I/usr/local/include +LDADD+= -lusbhid +CPPFLAGS+= -I${.CURDIR} -I${.CURDIR}/../btd COPTS+= -Wall -Werror DEBUG= -g diff --git a/usr.sbin/btctl/btctl.h b/usr.sbin/btctl/btctl.h index 291eaaf2021..7bf2a0e9de2 100644 --- a/usr.sbin/btctl/btctl.h +++ b/usr.sbin/btctl/btctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: btctl.h,v 1.1 2008/11/24 23:34:41 uwe Exp $ */ +/* $OpenBSD: btctl.h,v 1.2 2008/11/25 17:13:53 uwe Exp $ */ /* * Copyright (c) 2008 Uwe Stuehler <uwe@openbsd.org> @@ -38,6 +38,7 @@ typedef struct { bdaddr_t addr; uint16_t type; uint8_t pin[HCI_PIN_SIZE]; + uint8_t pin_len; } btctl_attach_stmt; /* parse.y */ diff --git a/usr.sbin/btctl/parse.y b/usr.sbin/btctl/parse.y index b9278fd1724..164ae1bbc46 100644 --- a/usr.sbin/btctl/parse.y +++ b/usr.sbin/btctl/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.1 2008/11/24 23:34:41 uwe Exp $ */ +/* $OpenBSD: parse.y,v 1.2 2008/11/25 17:13:53 uwe Exp $ */ /* * Copyright (c) 2008 Uwe Stuehler <uwe@openbsd.org> @@ -28,7 +28,6 @@ #include <dev/bluetooth/btdev.h> -#include <bluetooth.h> #include <ctype.h> #include <errno.h> #include <stdarg.h> @@ -116,14 +115,18 @@ main btctl_interface_stmt stmt; bdaddr_copy(&stmt.addr, &$2); + strbufcpy("interface name", $3, stmt.name); + free($3); + stmt.flags = $4 ? BTCTL_INTERFACE_DISABLED : 0; switch (exec_stmt(BTCTL_INTERFACE_STMT, &stmt, sizeof(stmt))) { case 0: break; case EEXIST: yyerror("interface %s is already defined", - bdaddr_any(&$2) ? "*" : bt_ntoa(&$2, NULL)); + bdaddr_any(&stmt.addr) ? "*" : + bt_ntoa(&stmt.addr, NULL)); YYERROR; default: yyerror("could not add interface"); @@ -135,14 +138,22 @@ main btctl_attach_stmt stmt; bdaddr_copy(&stmt.addr, &$2); + stmt.type = $3; - strbufcpy("PIN code", $4, stmt.pin); + + if ($4 != NULL) { + strbufcpy("PIN code", $4, stmt.pin); + stmt.pin_len = strlen(stmt.pin); + free($4); + } else + stmt.pin_len = 0; switch (exec_stmt(BTCTL_ATTACH_STMT, &stmt, sizeof(stmt))) { case 0: break; case EEXIST: yyerror("device %s is already defined", - bdaddr_any(&$2) ? "*" : bt_ntoa(&$2, NULL)); + bdaddr_any(&stmt.addr) ? "*" : + bt_ntoa(&stmt.addr, NULL)); YYERROR; default: yyerror("could not add device"); diff --git a/usr.sbin/btd/Makefile b/usr.sbin/btd/Makefile index 2fabc09fb19..ab5c4a92188 100644 --- a/usr.sbin/btd/Makefile +++ b/usr.sbin/btd/Makefile @@ -1,13 +1,12 @@ -# $OpenBSD: Makefile,v 1.1 2008/11/24 23:34:41 uwe Exp $ +# $OpenBSD: Makefile,v 1.2 2008/11/25 17:13:53 uwe Exp $ PROG= btd -SRCS= bt.c btd.c conf.c control.c db.c devinfo.c \ - hci.c log.c sdp.c util.c +SRCS= bt.c bt_subr.c btd.c conf.c control.c db.c devinfo.c \ + hci.c log.c util.c NOMAN= -LDADD+= -levent -lbluetooth -lsdp -lusbhid -LDFLAGS+= -L/usr/local/lib -CPPFLAGS+= -I${.CURDIR} -I${.CURDIR}/../btctl -I/usr/local/include +LDADD+= -levent -lusbhid +CPPFLAGS+= -I${.CURDIR} -I${.CURDIR}/../btctl COPTS+= -Wall -Werror DEBUG= -g diff --git a/usr.sbin/btd/bt.c b/usr.sbin/btd/bt.c index aac9cc66247..1a141c67651 100644 --- a/usr.sbin/btd/bt.c +++ b/usr.sbin/btd/bt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bt.c,v 1.1 2008/11/24 23:34:41 uwe Exp $ */ +/* $OpenBSD: bt.c,v 1.2 2008/11/25 17:13:53 uwe Exp $ */ /* * Copyright (c) 2008 Uwe Stuehler <uwe@openbsd.org> @@ -24,7 +24,6 @@ #include <dev/bluetooth/btdev.h> -#include <bluetooth.h> #include <errno.h> #include <event.h> #include <fcntl.h> diff --git a/usr.sbin/btd/btd.h b/usr.sbin/btd/btd.h index 1e88ff00546..f51ff35ec33 100644 --- a/usr.sbin/btd/btd.h +++ b/usr.sbin/btd/btd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: btd.h,v 1.1 2008/11/24 23:34:42 uwe Exp $ */ +/* $OpenBSD: btd.h,v 1.2 2008/11/25 17:13:53 uwe Exp $ */ /* * Copyright (c) 2008 Uwe Stuehler <uwe@openbsd.org> @@ -21,6 +21,7 @@ #include <dev/bluetooth/btdev.h> #include <netbt/bluetooth.h> +#include <netbt/hci.h> #include <db.h> #include <event.h> @@ -40,21 +41,21 @@ struct btd; +struct btd_db { + DB *dbh; +}; + struct bt_interface { TAILQ_ENTRY(bt_interface) entry; - struct event ev; struct btd *env; const char *xname; bdaddr_t addr; - const char *name; + char name[HCI_UNIT_NAME_SIZE]; int disabled; + struct event ev; int fd; }; -struct btd_db { - DB *dbh; -}; - struct btd_hci { struct bt_interface *inquiry_interface; int inquiry_running; @@ -68,9 +69,11 @@ struct bt_devinfo { struct bt_device { TAILQ_ENTRY(bt_device) entry; + struct btd *env; bdaddr_t addr; uint16_t type; - uint8_t *pin; /* HCI_PIN_SIZE when not NULL */ + uint8_t pin[HCI_PIN_SIZE]; + uint8_t pin_len; time_t last_seen; /* last response to an inquiry */ int flags; struct bt_devinfo info; @@ -105,16 +108,26 @@ enum imsg_type { /* bt.c */ pid_t bt_main(int[2], struct btd *, struct passwd *); +/* bt_subr.c */ +char const *bt_ntoa(bdaddr_t const *, char[18]); +int bt_aton(char const *, bdaddr_t *); + /* conf.c */ -struct bt_device *conf_add_device(struct btd *, - const bdaddr_t *); -struct bt_device *conf_find_device(const struct btd *, - const bdaddr_t *); -struct bt_interface *conf_add_interface(struct btd *, - const bdaddr_t *); -struct bt_interface *conf_find_interface(const struct btd *, - const bdaddr_t *); -const uint8_t *conf_lookup_pin(const struct btd *, const bdaddr_t *); +struct btd *conf_new(void); +void conf_delete(struct btd *); + +struct bt_interface *conf_add_interface(struct btd *, const bdaddr_t *); +struct bt_interface *conf_find_interface(const struct btd *, const bdaddr_t *); +void conf_delete_interface(struct bt_interface *); + +struct bt_device *conf_add_device(struct btd *, const bdaddr_t *); +struct bt_device *conf_find_device(const struct btd *, const bdaddr_t *); +void conf_delete_device(struct bt_device *); + +void conf_lookup_pin(const struct btd *, const bdaddr_t *, + uint8_t[HCI_PIN_SIZE], uint8_t *); + +void conf_dump(const struct btd *); /* control.c */ void control_init(struct btd *); diff --git a/usr.sbin/btd/conf.c b/usr.sbin/btd/conf.c index 7ed0f67f5a4..c29d95abf6d 100644 --- a/usr.sbin/btd/conf.c +++ b/usr.sbin/btd/conf.c @@ -3,85 +3,104 @@ #include <netbt/hci.h> #include <assert.h> +#include <errno.h> #include <stdlib.h> #include <string.h> #include "btd.h" -struct bt_device * -conf_add_device(struct btd *conf, const bdaddr_t *addr) +struct btd * +conf_new(void) { - struct bt_device *btdev; - struct bt_device *defaults; + struct btd *conf; - assert(conf_find_device(conf, addr) == NULL); - - btdev = calloc(1, sizeof(*btdev)); - if (btdev == NULL) { - log_warn("conf_add_device"); + if ((conf = calloc(1, sizeof(*conf))) == NULL) return NULL; - } - bdaddr_copy(&btdev->addr, addr); + TAILQ_INIT(&conf->interfaces); + TAILQ_INIT(&conf->devices); - defaults = bdaddr_any(addr) ? NULL : - conf_find_device(conf, BDADDR_ANY); - - if (defaults != NULL) { - btdev->type = defaults->type; - btdev->flags = defaults->flags; - - if (defaults->pin != NULL) { - if ((btdev->pin = malloc(HCI_KEY_SIZE)) == NULL) { - log_warn("conf_add_device malloc"); - TAILQ_REMOVE(&conf->devices, btdev, entry); - return NULL; - } - memcpy(btdev->pin, defaults->pin, HCI_KEY_SIZE); - } - } + return conf; +} - TAILQ_INSERT_TAIL(&conf->devices, btdev, entry); +void +conf_delete(struct btd *conf) +{ + while (!TAILQ_EMPTY(&conf->interfaces)) + conf_delete_interface(TAILQ_FIRST(&conf->interfaces)); - return btdev; + while (!TAILQ_EMPTY(&conf->devices)) + conf_delete_device(TAILQ_FIRST(&conf->devices)); } +/* cope well, and silently with bad arguments, because this function + may be called via the control socket */ struct bt_interface * conf_add_interface(struct btd *conf, const bdaddr_t *addr) { struct bt_interface *iface; - struct bt_interface *defaults; - - assert(conf_find_interface(conf, addr) == NULL); - iface = calloc(1, sizeof(*iface)); - if (iface == NULL) { - log_warn("conf_add_interface"); + if (conf_find_interface(conf, addr) != NULL) { + errno = EEXIST; return NULL; } - bdaddr_copy(&iface->addr, addr); + if ((iface = calloc(1, sizeof(*iface))) == NULL) + return NULL; + iface->env = conf; + bdaddr_copy(&iface->addr, addr); iface->fd = -1; - defaults = bdaddr_any(addr) ? NULL : - conf_find_interface(conf, BDADDR_ANY); + TAILQ_INSERT_TAIL(&conf->interfaces, iface, entry); - if (defaults != NULL) { - if (defaults->name != NULL && - (iface->name = strdup(defaults->name)) == NULL) { - log_warn("conf_add_interface strdup"); - TAILQ_REMOVE(&conf->interfaces, iface, entry); - free(iface); - return NULL; - } + return iface; +} - iface->disabled = defaults->disabled; +struct bt_interface * +conf_find_interface(const struct btd *conf, const bdaddr_t *addr) +{ + struct bt_interface *iface; + + TAILQ_FOREACH(iface, &conf->interfaces, entry) { + if (bdaddr_same(&iface->addr, addr)) + return iface; } - TAILQ_INSERT_TAIL(&conf->interfaces, iface, entry); + return NULL; +} - return iface; +void +conf_delete_interface(struct bt_interface *iface) +{ + struct btd *conf = iface->env; + + TAILQ_REMOVE(&conf->interfaces, iface, entry); + + free(iface); +} + +/* cope well, and silently with bad arguments, because this function + may be called via the control socket */ +struct bt_device * +conf_add_device(struct btd *conf, const bdaddr_t *addr) +{ + struct bt_device *btdev; + + if (conf_find_device(conf, addr) != NULL) { + errno = EEXIST; + return NULL; + } + + if ((btdev = calloc(1, sizeof(*btdev))) == NULL) + return NULL; + + btdev->env = conf; + bdaddr_copy(&btdev->addr, addr); + + TAILQ_INSERT_TAIL(&conf->devices, btdev, entry); + + return btdev; } struct bt_device * @@ -97,27 +116,45 @@ conf_find_device(const struct btd *conf, const bdaddr_t *addr) return NULL; } -struct bt_interface * -conf_find_interface(const struct btd *conf, const bdaddr_t *addr) +void +conf_delete_device(struct bt_device *btdev) { - struct bt_interface *iface; + struct btd *conf = btdev->env; - TAILQ_FOREACH(iface, &conf->interfaces, entry) { - if (bdaddr_same(&iface->addr, addr)) - return iface; - } + TAILQ_REMOVE(&conf->devices, btdev, entry); - return NULL; + free(btdev); } -const uint8_t * -conf_lookup_pin(const struct btd *conf, const bdaddr_t *addr) +void +conf_lookup_pin(const struct btd *conf, const bdaddr_t *addr, + uint8_t pin[HCI_PIN_SIZE], uint8_t *pin_len) { struct bt_device *btdev; if ((btdev = conf_find_device(conf, addr)) == NULL && - (btdev = conf_find_device(conf, BDADDR_ANY)) == NULL) - return NULL; + (btdev = conf_find_device(conf, BDADDR_ANY)) == NULL) { + memset(pin, 0, HCI_PIN_SIZE); + *pin_len = 0; + return; + } + + memcpy(pin, btdev->pin, HCI_PIN_SIZE); + *pin_len = btdev->pin_len; +} + +void +conf_dump(const struct btd *conf) +{ + struct bt_interface *iface; + struct bt_device *btdev; + + TAILQ_FOREACH(iface, &conf->interfaces, entry) { + log_info("interface %s", bt_ntoa(&iface->addr, NULL)); + } + + TAILQ_FOREACH(btdev, &conf->devices, entry) { + log_info("device %s", bt_ntoa(&btdev->addr, NULL)); + } - return btdev->pin; } diff --git a/usr.sbin/btd/control.c b/usr.sbin/btd/control.c index f81961e2b7f..39ad760a47d 100644 --- a/usr.sbin/btd/control.c +++ b/usr.sbin/btd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.1 2008/11/24 23:34:42 uwe Exp $ */ +/* $OpenBSD: control.c,v 1.2 2008/11/25 17:13:53 uwe Exp $ */ /* * Copyright (c) 2008 Uwe Stuehler <uwe@openbsd.org> @@ -33,15 +33,19 @@ #define CONTROL_BACKLOG 5 +void socket_blockmode(int, int); void control_acceptcb(int, short, void *); void control_readcb(struct bufferevent *, void *); void control_errorcb(struct bufferevent *, short, void *); - -void socket_blockmode(int, int); +int control_interface_stmt(struct btd *, btctl_interface_stmt *); +int control_attach_stmt(struct btd *, btctl_attach_stmt *); +int control_commit(struct btd *, const struct btd *); struct control_connection { TAILQ_ENTRY(control_connection) entry; struct bufferevent *ev; + struct btd *env; + struct btd *new_env; int fd; }; @@ -90,6 +94,7 @@ control_init(struct btd *env) event_add(&ev_control, NULL); } +/* called from priv process */ void control_cleanup(void) { @@ -98,13 +103,32 @@ control_cleanup(void) } void +socket_blockmode(int fd, int block) +{ + int flags; + + if ((flags = fcntl(fd, F_GETFL, 0)) == -1) + fatal("fcntl F_GETFL"); + + if (block) + flags &= ~O_NONBLOCK; + else + flags |= O_NONBLOCK; + + if ((flags = fcntl(fd, F_SETFL, flags)) == -1) + fatal("fcntl F_SETFL"); +} + +void control_acceptcb(int fd, short evflags, void *arg) { + struct btd *env = arg; struct control_connection *conn; struct sockaddr_storage sa; - socklen_t salen = sizeof(sa); + socklen_t salen; int new_fd; + salen = sizeof(sa); if ((new_fd = accept(fd, (struct sockaddr *)&sa, &salen)) == -1) { log_warn("control_eventcb: accept"); return; @@ -113,6 +137,7 @@ control_acceptcb(int fd, short evflags, void *arg) if ((conn = calloc(1, sizeof(*conn))) == NULL) fatal("control_eventcb: calloc"); + conn->env = env; conn->fd = new_fd; if ((conn->ev = bufferevent_new(new_fd, control_readcb, NULL, @@ -160,22 +185,56 @@ control_readcb(struct bufferevent *ev, void *arg) switch (stmt_type) { case BTCTL_CONFIG: + if (conn->new_env == NULL) { + conn->new_env = conf_new(); + err = conn->new_env == NULL ? ENOMEM : 0; + } else + err = EALREADY; + break; + case BTCTL_COMMIT: + if (conn->new_env != NULL) { + err = control_commit(conn->env, conn->new_env); + if (err == 0) { + conf_delete(conn->new_env); + conn->new_env = NULL; + } + } else + err = 0; + break; + case BTCTL_ROLLBACK: + if (conn->new_env != NULL) { + conf_delete(conn->new_env); + conn->new_env = NULL; + } + err = 0; break; + case BTCTL_INTERFACE_STMT: + if (conn->new_env == NULL) { + err = EOPNOTSUPP; + break; + } bufferevent_read(ev, &interface_stmt, stmt_size); + err = control_interface_stmt(conn->new_env, &interface_stmt); break; + case BTCTL_ATTACH_STMT: + if (conn->new_env == NULL) { + err = EOPNOTSUPP; + break; + } bufferevent_read(ev, &attach_stmt, stmt_size); + err = control_attach_stmt(conn->new_env, &attach_stmt); break; + default: log_warnx("Invalid control packet of type %#x", stmt_type); close(conn->fd); return; } - err = 0; bufferevent_write(ev, &err, sizeof(err)); } @@ -185,24 +244,59 @@ control_errorcb(struct bufferevent *ev, short what, void *arg) struct control_connection *conn = arg; TAILQ_REMOVE(&connections, conn, entry); + + if (conn->new_env != NULL) + conf_delete(conn->new_env); + bufferevent_free(conn->ev); close(conn->fd); free(conn); } -void -socket_blockmode(int fd, int block) +int +control_interface_stmt(struct btd *conf, btctl_interface_stmt *stmt) { - int flags; + struct bt_interface *iface; - if ((flags = fcntl(fd, F_GETFL, 0)) == -1) - fatal("fcntl F_GETFL"); + if ((iface = conf_add_interface(conf, &stmt->addr)) == NULL) + return errno; - if (block) - flags &= ~O_NONBLOCK; - else - flags |= O_NONBLOCK; + strlcpy(iface->name, stmt->name, sizeof(iface->name)); - if ((flags = fcntl(fd, F_SETFL, flags)) == -1) - fatal("fcntl F_SETFL"); + if (stmt->flags & BTCTL_INTERFACE_DISABLED) + iface->disabled = 1; + + return 0; +} + +int +control_attach_stmt(struct btd *conf, btctl_attach_stmt *stmt) +{ + struct bt_device *btdev; + + if ((btdev = conf_add_device(conf, &stmt->addr)) == NULL) + return errno; + + btdev->type = stmt->type; + + strlcpy(btdev->pin, stmt->pin, sizeof(btdev->pin)); + btdev->pin_len = stmt->pin_len; + + btdev->flags |= BTDF_ATTACH; + + return 0; +} + +int +control_commit(struct btd *env, const struct btd *conf) +{ +#if 0 + struct bt_interface *iface; + struct bt_interface *conf_iface; +#endif + + conf_dump(env); + conf_dump(conf); + + return 0; } diff --git a/usr.sbin/btd/db.c b/usr.sbin/btd/db.c index e147b072b8d..41404acb094 100644 --- a/usr.sbin/btd/db.c +++ b/usr.sbin/btd/db.c @@ -3,7 +3,6 @@ #include <netbt/hci.h> #include <assert.h> -#include <bluetooth.h> #include <fcntl.h> #include <stdlib.h> #include <string.h> diff --git a/usr.sbin/btd/devinfo.c b/usr.sbin/btd/devinfo.c index 5471b2bbe4a..08b54bc66bb 100644 --- a/usr.sbin/btd/devinfo.c +++ b/usr.sbin/btd/devinfo.c @@ -1,4 +1,3 @@ -#include <bluetooth.h> #include <stdlib.h> #include <string.h> diff --git a/usr.sbin/btd/hci.c b/usr.sbin/btd/hci.c index 93d42318b9c..d5e8ec90ea9 100644 --- a/usr.sbin/btd/hci.c +++ b/usr.sbin/btd/hci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hci.c,v 1.1 2008/11/24 23:34:42 uwe Exp $ */ +/* $OpenBSD: hci.c,v 1.2 2008/11/25 17:13:53 uwe Exp $ */ /* $NetBSD: btconfig.c,v 1.13 2008/07/21 13:36:57 lukem Exp $ */ /*- @@ -36,7 +36,6 @@ #include <sys/ioctl.h> #include <assert.h> -#include <bluetooth.h> #include <errno.h> #include <event.h> #include <string.h> @@ -45,6 +44,8 @@ #include "btd.h" +#define MIN(a, b) ((a) < (b) ? (a) : (b)) + int hci_init_config(struct bt_interface *); void hci_eventcb(int, short, void *); @@ -160,7 +161,7 @@ hci_init(struct btd *env) continue; } - /* Skip disabled interfaces. */ + /* Skip manually disabled interfaces. */ if (iface->disabled) { log_info("interface disabled: %s (%s)", bt_ntoa(&iface->addr, NULL), iface->xname); @@ -218,22 +219,10 @@ int hci_init_config(struct bt_interface *iface) { struct btreq btr; - struct btd *env = iface->env; - struct bt_interface *defaults; - const char *name; uint8_t val; - defaults = conf_find_interface(env, BDADDR_ANY); - - if (iface->name != NULL) - name = iface->name; - else if (defaults != NULL && defaults->name != NULL) - name = defaults->name; - else - name = NULL; - - if (name != NULL && hci_write(iface, HCI_CMD_WRITE_LOCAL_NAME, - (char *)name, HCI_UNIT_NAME_SIZE)) + if (hci_write(iface, HCI_CMD_WRITE_LOCAL_NAME, iface->name, + HCI_UNIT_NAME_SIZE)) return -1; if (hci_read(iface, HCI_CMD_READ_SCAN_ENABLE, &val, sizeof(val))) @@ -319,25 +308,16 @@ int hci_process_pin_code_req(struct bt_interface *iface, struct sockaddr_bt *sa, const bdaddr_t *addr) { - const uint8_t *pin; + hci_pin_code_rep_cp cp; - pin = conf_lookup_pin(iface->env, addr); + conf_lookup_pin(iface->env, addr, cp.pin, &cp.pin_size); - if (pin == NULL) { + if (cp.pin_size == 0) { log_info("%s: PIN code not found", bt_ntoa(addr, NULL)); return hci_send_cmd(iface->fd, sa, HCI_CMD_PIN_CODE_NEG_REP, sizeof(bdaddr_t), (void *)addr); } else { - hci_pin_code_rep_cp cp; - int n; - bdaddr_copy(&cp.bdaddr, addr); - memcpy(cp.pin, pin, HCI_PIN_SIZE); - - n = HCI_PIN_SIZE; - while (n > 0 && pin[n - 1] == 0) - n--; - cp.pin_size = n; log_info("%s: PIN code found", bt_ntoa(addr, NULL)); return hci_send_cmd(iface->fd, sa, HCI_CMD_PIN_CODE_REP, diff --git a/usr.sbin/btd/log.c b/usr.sbin/btd/log.c index 8346fe08cb7..8d18b240a2c 100644 --- a/usr.sbin/btd/log.c +++ b/usr.sbin/btd/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.1 2008/11/24 23:34:42 uwe Exp $ */ +/* $OpenBSD: log.c,v 1.2 2008/11/25 17:13:53 uwe Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -16,7 +16,6 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <bluetooth.h> #include <errno.h> #include <stdarg.h> #include <stdio.h> diff --git a/usr.sbin/btd/parse.y b/usr.sbin/btd/parse.y index bef3126cc54..a4f3a2d2c01 100644 --- a/usr.sbin/btd/parse.y +++ b/usr.sbin/btd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.1 2008/11/24 23:34:42 uwe Exp $ */ +/* $OpenBSD: parse.y,v 1.2 2008/11/25 17:13:53 uwe Exp $ */ /* * Copyright (c) 2008 Uwe Stuehler <uwe@openbsd.org> @@ -25,7 +25,6 @@ #include <dev/bluetooth/btdev.h> -#include <bluetooth.h> #include <ctype.h> #include <stdarg.h> #include <stdio.h> diff --git a/usr.sbin/btd/sdp.c b/usr.sbin/btd/sdp.c index 6ff2fbfd0d3..06ec58382ce 100644 --- a/usr.sbin/btd/sdp.c +++ b/usr.sbin/btd/sdp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sdp.c,v 1.1 2008/11/24 23:34:42 uwe Exp $ */ +/* $OpenBSD: sdp.c,v 1.2 2008/11/25 17:13:53 uwe Exp $ */ /* $NetBSD: sdp.c,v 1.5 2008/04/20 19:34:23 plunky Exp $ */ /*- @@ -61,7 +61,6 @@ #include <dev/usb/usb.h> #include <dev/usb/usbhid.h> -#include <bluetooth.h> #include <err.h> #include <errno.h> #include <sdp.h> |