summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUwe Stuehler <uwe@cvs.openbsd.org>2008-11-27 00:51:18 +0000
committerUwe Stuehler <uwe@cvs.openbsd.org>2008-11-27 00:51:18 +0000
commita9b4631ad529d16595d8a5030e3911e75c0afabb (patch)
tree335c5e2bcc48b31b8e5218d456be4059961d8401
parent5871ad9f6533a8594cbccf4016e952f96dba4962 (diff)
Ugly workaround to bring up interfaces which were down when we found them
-rw-r--r--usr.sbin/btd/bt.c15
-rw-r--r--usr.sbin/btd/btd.c51
-rw-r--r--usr.sbin/btd/btd.h4
-rw-r--r--usr.sbin/btd/hci.c71
-rw-r--r--usr.sbin/btd/sdp.c7
5 files changed, 125 insertions, 23 deletions
diff --git a/usr.sbin/btd/bt.c b/usr.sbin/btd/bt.c
index 7ea19bcbb97..09313eb0cd0 100644
--- a/usr.sbin/btd/bt.c
+++ b/usr.sbin/btd/bt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bt.c,v 1.5 2008/11/26 21:48:30 uwe Exp $ */
+/* $OpenBSD: bt.c,v 1.6 2008/11/27 00:51:17 uwe Exp $ */
/*
* Copyright (c) 2008 Uwe Stuehler <uwe@openbsd.org>
@@ -370,3 +370,16 @@ bt_device_detach(struct bt_device *btdev)
return -1;
}
}
+
+int
+bt_set_interface_flags(const struct btreq *btr)
+{
+ int err;
+
+ bt_priv_msg(IMSG_SET_INTERFACE_FLAGS);
+ bt_priv_send(btr->btr_name, sizeof(btr->btr_name));
+ bt_priv_send(&btr->btr_flags, sizeof(btr->btr_flags));
+ bt_priv_recv(&err, sizeof(err));
+
+ return (errno = err) ? -1 : 0;
+}
diff --git a/usr.sbin/btd/btd.c b/usr.sbin/btd/btd.c
index e365e5eeabc..129a8c3c821 100644
--- a/usr.sbin/btd/btd.c
+++ b/usr.sbin/btd/btd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: btd.c,v 1.3 2008/11/26 15:32:56 uwe Exp $ */
+/* $OpenBSD: btd.c,v 1.4 2008/11/27 00:51:17 uwe Exp $ */
/*
* Copyright (c) 2008 Uwe Stuehler <uwe@openbsd.org>
@@ -44,6 +44,7 @@ static int write_all(const void *, size_t);
static int dispatch_imsg(struct btd *);
static void btd_open_hci(struct btd *);
static void btd_set_link_policy(struct btd *);
+static void btd_set_interface_flags(struct btd *);
static void btd_devctl(struct btd *, enum imsg_type);
static const char *progname;
@@ -248,6 +249,9 @@ dispatch_imsg(struct btd *env)
case IMSG_SET_LINK_POLICY:
btd_set_link_policy(env);
break;
+ case IMSG_SET_INTERFACE_FLAGS:
+ btd_set_interface_flags(env);
+ break;
case IMSG_ATTACH:
case IMSG_DETACH:
btd_devctl(env, type);
@@ -334,6 +338,51 @@ btd_set_link_policy(struct btd *env)
close(fd);
}
+static void
+btd_set_interface_flags(struct btd *env)
+{
+ struct btreq btr;
+ uint16_t mask;
+ uint16_t flags;
+ int err = 0;
+ int fd;
+
+ memset(&btr, 0, sizeof(btr));
+
+ if (read_all(&btr.btr_name, sizeof(btr.btr_name)) < 0 ||
+ read_all(&flags, sizeof(flags)) < 0)
+ return;
+
+ if ((fd = socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) == -1) {
+ err = errno;
+ write_all(&err, sizeof(err));
+ return;
+ }
+
+ if (ioctl(fd, SIOCGBTINFO, &btr) < 0) {
+ err = errno;
+ log_warn("SIOCGBTINFO");
+ close(fd);
+ write_all(&err, sizeof(err));
+ return;
+ }
+
+ /* limit allowed flags */
+ mask = BTF_UP;
+ btr.btr_flags &= ~mask;
+ btr.btr_flags |= (flags & mask);
+
+ if (ioctl(fd, SIOCSBTFLAGS, &btr) < 0) {
+ err = errno;
+ log_warn("SIOCSBTFLAGS");
+ }
+
+ sleep(1); /* XXX wait until it comes up */
+
+ write_all(&err, sizeof(err));
+ close(fd);
+}
+
void
btd_devctl(struct btd *env, enum imsg_type type)
{
diff --git a/usr.sbin/btd/btd.h b/usr.sbin/btd/btd.h
index aef9d24fc98..335333e246c 100644
--- a/usr.sbin/btd/btd.h
+++ b/usr.sbin/btd/btd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: btd.h,v 1.5 2008/11/26 21:48:30 uwe Exp $ */
+/* $OpenBSD: btd.h,v 1.6 2008/11/27 00:51:17 uwe Exp $ */
/*
* Copyright (c) 2008 Uwe Stuehler <uwe@openbsd.org>
@@ -102,6 +102,7 @@ enum imsg_type {
IMSG_CONFIG_ROLLBACK,
IMSG_OPEN_HCI,
IMSG_SET_LINK_POLICY,
+ IMSG_SET_INTERFACE_FLAGS,
IMSG_ATTACH,
IMSG_DETACH
};
@@ -119,6 +120,7 @@ void bt_priv_msg(enum imsg_type);
void bt_priv_send(const void *, size_t);
void bt_priv_recv(void *, size_t);
void bt_devices_changed(void);
+int bt_set_interface_flags(const struct btreq *);
/* bt_subr.c */
char const *bt_ntoa(bdaddr_t const *, char[18]);
diff --git a/usr.sbin/btd/hci.c b/usr.sbin/btd/hci.c
index 88e7fbd8d4b..41e9da48c02 100644
--- a/usr.sbin/btd/hci.c
+++ b/usr.sbin/btd/hci.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hci.c,v 1.5 2008/11/26 21:48:30 uwe Exp $ */
+/* $OpenBSD: hci.c,v 1.6 2008/11/27 00:51:17 uwe Exp $ */
/* $NetBSD: btconfig.c,v 1.13 2008/07/21 13:36:57 lukem Exp $ */
/*-
@@ -62,6 +62,9 @@ struct hci_state {
void hci_update_physifs(struct btd *);
struct hci_physif *hci_find_physif(struct hci_state *, bdaddr_t *);
+int hci_unit_up(const char *);
+int hci_unit_down(const char *);
+
void hci_if_config(struct bt_interface *, const struct bt_interface *);
void hci_if_apply(struct bt_interface *);
@@ -129,21 +132,25 @@ hci_update_physifs(struct btd *env)
*/
if (!((flags = btr.btr_flags) & BTF_UP) ||
bdaddr_any(&btr.btr_bdaddr)) {
- btr.btr_flags |= BTF_UP;
- if (ioctl(sock, SIOCSBTFLAGS, &btr) < 0) {
- log_warn("%s: SIOCSBTFLAGS", btr.btr_name);
+ if (hci_unit_up(btr.btr_name) < 0)
continue;
- }
+
if (ioctl(sock, SIOCGBTINFO, &btr) < 0) {
log_warn("%s: SIOCGBTINFO", btr.btr_name);
continue;
}
+
if (!(btr.btr_flags & BTF_UP) ||
bdaddr_any(&btr.btr_bdaddr)) {
log_warnx("could not enable %s",
btr.btr_name);
- goto redisable;
+ continue;
}
+
+#if 0
+ if (hci_unit_down(btr.btr_name) < 0)
+ continue;
+#endif
}
if ((physif = hci_find_physif(hci, &btr.btr_bdaddr))) {
@@ -164,14 +171,6 @@ hci_update_physifs(struct btd *env)
found:
(void)conf_add_interface(env, &physif->addr);
-
- redisable:
- /* XXX See above. Grrrr... */
- if (!(flags & BTF_UP)) {
- btr.btr_flags &= ~BTF_UP;
- if (ioctl(sock, SIOCSBTFLAGS, &btr) < 0)
- fatal("hci_init SIOCSBTFLAGS");
- }
}
for (physif = TAILQ_FIRST(&hci->physifs); physif != NULL;) {
@@ -319,6 +318,42 @@ hci_reinit(struct btd *env, const struct btd *conf)
return 0;
}
+int
+hci_unit_up(const char *xname)
+{
+ struct btreq btr;
+
+ memset(&btr, 0, sizeof(btr));
+ strlcpy(btr.btr_name, xname, sizeof(btr.btr_name));
+
+ btr.btr_flags = BTF_UP;
+
+ if (bt_set_interface_flags(&btr) < 0) {
+ log_warn("hci_unit_up: %s", xname);
+ return -1;
+ }
+
+ return 0;
+}
+
+int
+hci_unit_down(const char *xname)
+{
+ struct btreq btr;
+
+ memset(&btr, 0, sizeof(btr));
+ strlcpy(btr.btr_name, xname, sizeof(btr.btr_name));
+
+ btr.btr_flags = 0;
+
+ if (bt_set_interface_flags(&btr) < 0) {
+ log_warn("hci_unit_down: %s", xname);
+ return -1;
+ }
+
+ return 0;
+}
+
void
hci_if_config(struct bt_interface *iface, const struct bt_interface *other)
{
@@ -367,6 +402,9 @@ hci_interface_open(struct bt_interface *iface)
if (physif->fd != -1)
return 0;
+ if (hci_unit_up(physif->xname) < 0)
+ return -1;
+
bt_priv_msg(IMSG_OPEN_HCI);
bt_priv_send(&physif->addr, sizeof(bdaddr_t));
physif->fd = receive_fd(priv_fd);
@@ -415,6 +453,11 @@ hci_interface_close(struct bt_interface *iface)
iface->physif = NULL;
+#if 0
+ if (hci_unit_down(physif->xname) < 0)
+ return;
+#endif
+
log_info("stopped listening on %s", bt_ntoa(&physif->addr, NULL));
}
diff --git a/usr.sbin/btd/sdp.c b/usr.sbin/btd/sdp.c
index 0445bf1b26b..bf307cc9fec 100644
--- a/usr.sbin/btd/sdp.c
+++ b/usr.sbin/btd/sdp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sdp.c,v 1.4 2008/11/26 21:48:30 uwe Exp $ */
+/* $OpenBSD: sdp.c,v 1.5 2008/11/27 00:51:17 uwe Exp $ */
/*
* Copyright (c) 2008 Uwe Stuehler <uwe@openbsd.org>
@@ -55,8 +55,6 @@ sdp_get_devinfo(struct bt_interface *iface, struct bt_device *btdev)
struct sdp_session *sess;
const char *service;
- log_debug("sdp_get_devinfo: raddr %s", bt_ntoa(&btdev->addr, NULL));
-
switch (btdev->type) {
case BTDEV_NONE:
return 1;
@@ -84,7 +82,6 @@ sdp_get_devinfo(struct bt_interface *iface, struct bt_device *btdev)
if (sdp_query(sess, &btdev->info.baa, &iface->addr, &btdev->addr,
service) < 0) {
- log_warnx("sdp_query failed");
sdp_close_session(sess);
return -1;
}
@@ -224,8 +221,6 @@ sdp_close_session(struct sdp_session *sess)
if (sess->state == SDP_SESSION_CLOSED)
return;
- log_debug("sdp_close_session: laddr %s", bt_ntoa(&sess->laddr, NULL));
-
if (sess->req != NULL) {
free(sess->req);
sess->req = NULL;