summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2010-07-12 11:38:29 -0300
committerJohan Hedberg <johan.hedberg@nokia.com>2010-07-12 11:52:27 -0300
commit6e6252937e1e77dcae13467f63b25b043ea03f63 (patch)
tree23e9a3e0190023687e85c193e1a07121149fe2e4
parent1c27615cad21ab49a6c02150564a4fd080751ea8 (diff)
downloadbluez-6e6252937e1e77dcae13467f63b25b043ea03f63.tar.gz
Add hciattach support for initializing a device into raw mode
This patch adds a -r switch to hciattach that can be used to initialize a device into raw mode. This is accomplished with the help of the new HCIUARTSETFLAGS ioctl.
-rw-r--r--tools/hciattach.84
-rw-r--r--tools/hciattach.c24
-rw-r--r--tools/hciattach.h4
3 files changed, 27 insertions, 5 deletions
diff --git a/tools/hciattach.8 b/tools/hciattach.8
index b9ec23e91..9bd15385b 100644
--- a/tools/hciattach.8
+++ b/tools/hciattach.8
@@ -11,6 +11,7 @@ hciattach \- attach serial devices via UART HCI to BlueZ stack
.RB [\| \-s
.IR speed \|]
.RB [\| \-l \|]
+.RB [\| \-r \|]
.I tty
.IR type \||\| id
.I speed
@@ -40,6 +41,9 @@ Specify an initial speed instead of the hardware default.
.B \-l
List all available configurations.
.TP
+.B \-r
+Set the HCI device into raw mode (the kernel and bluetoothd will ignore it).
+.TP
.I tty
This specifies the serial device to attach. A leading
.B /dev
diff --git a/tools/hciattach.c b/tools/hciattach.c
index e772b6f32..81aea7bfd 100644
--- a/tools/hciattach.c
+++ b/tools/hciattach.c
@@ -1097,10 +1097,14 @@ static struct uart_t * get_by_type(char *type)
}
/* Initialize UART driver */
-static int init_uart(char *dev, struct uart_t *u, int send_break)
+static int init_uart(char *dev, struct uart_t *u, int send_break, int raw)
{
struct termios ti;
int fd, i;
+ unsigned long flags = 0;
+
+ if (raw)
+ flags |= 1 << HCI_UART_RAW_DEVICE;
fd = open(dev, O_RDWR | O_NOCTTY);
if (fd < 0) {
@@ -1159,6 +1163,11 @@ static int init_uart(char *dev, struct uart_t *u, int send_break)
return -1;
}
+ if (flags && ioctl(fd, HCIUARTSETFLAGS, flags) < 0) {
+ perror("Can't set UART flags");
+ return -1;
+ }
+
if (ioctl(fd, HCIUARTSETPROTO, u->proto) < 0) {
perror("Can't set device");
return -1;
@@ -1174,14 +1183,14 @@ static void usage(void)
{
printf("hciattach - HCI UART driver initialization utility\n");
printf("Usage:\n");
- printf("\thciattach [-n] [-p] [-b] [-t timeout] [-s initial_speed] <tty> <type | id> [speed] [flow|noflow] [bdaddr]\n");
+ printf("\thciattach [-n] [-p] [-b] [-r] [-t timeout] [-s initial_speed] <tty> <type | id> [speed] [flow|noflow] [bdaddr]\n");
printf("\thciattach -l\n");
}
int main(int argc, char *argv[])
{
struct uart_t *u = NULL;
- int detach, printpid, opt, i, n, ld, err;
+ int detach, printpid, raw, opt, i, n, ld, err;
int to = 10;
int init_speed = 0;
int send_break = 0;
@@ -1193,8 +1202,9 @@ int main(int argc, char *argv[])
detach = 1;
printpid = 0;
+ raw = 0;
- while ((opt=getopt(argc, argv, "bnpt:s:l")) != EOF) {
+ while ((opt=getopt(argc, argv, "bnpt:s:lr")) != EOF) {
switch(opt) {
case 'b':
send_break = 1;
@@ -1223,6 +1233,10 @@ int main(int argc, char *argv[])
}
exit(0);
+ case 'r':
+ raw = 1;
+ break;
+
default:
usage();
exit(1);
@@ -1300,7 +1314,7 @@ int main(int argc, char *argv[])
alarm(to);
bcsp_max_retries = to;
- n = init_uart(dev, u, send_break);
+ n = init_uart(dev, u, send_break, raw);
if (n < 0) {
perror("Can't initialize device");
exit(1);
diff --git a/tools/hciattach.h b/tools/hciattach.h
index 867563bdf..c0b80a1ff 100644
--- a/tools/hciattach.h
+++ b/tools/hciattach.h
@@ -30,6 +30,8 @@
#define HCIUARTSETPROTO _IOW('U', 200, int)
#define HCIUARTGETPROTO _IOR('U', 201, int)
#define HCIUARTGETDEVICE _IOR('U', 202, int)
+#define HCIUARTSETFLAGS _IOW('U', 203, int)
+#define HCIUARTGETFLAGS _IOR('U', 204, int)
#define HCI_UART_H4 0
#define HCI_UART_BCSP 1
@@ -37,6 +39,8 @@
#define HCI_UART_H4DS 3
#define HCI_UART_LL 4
+#define HCI_UART_RAW_DEVICE 0
+
int read_hci_event(int fd, unsigned char* buf, int size);
int set_speed(int fd, struct termios *ti, int speed);