summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--rfcomm/main.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/rfcomm/main.c b/rfcomm/main.c
index dbb74869..3a7fe0a5 100644
--- a/rfcomm/main.c
+++ b/rfcomm/main.c
@@ -442,14 +442,21 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv
}
snprintf(devname, MAXPATHLEN - 1, "/dev/rfcomm%d", dev);
- if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) {
+ while ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) {
snprintf(devname, MAXPATHLEN - 1, "/dev/bluetooth/rfcomm/%d", dev);
- while ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) {
+ if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) {
if (try--) {
+ snprintf(devname, MAXPATHLEN - 1, "/dev/rfcomm%d", dev);
sleep(1);
continue;
}
perror("Can't open RFCOMM device");
+
+ memset(&req, 0, sizeof(req));
+ req.dev_id = dev;
+ req.flags = (1 << RFCOMM_HANGUP_NOW);
+ ioctl(ctl, RFCOMMRELEASEDEV, &req);
+
close(sk);
return;
}