From c98b2f82a4e532ca61592b08e3ad60749eb9f8d7 Mon Sep 17 00:00:00 2001 From: Max Krasnyansky Date: Fri, 8 Mar 2002 21:12:35 +0000 Subject: Initial revision --- tools/hciattach.c | 751 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 751 insertions(+) create mode 100644 tools/hciattach.c (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c new file mode 100644 index 00000000..a4489019 --- /dev/null +++ b/tools/hciattach.c @@ -0,0 +1,751 @@ +/* + BlueZ - Bluetooth protocol stack for Linux + Copyright (C) 2000-2001 Qualcomm Incorporated + + Written 2000,2001 by Maxim Krasnyansky + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 as + published by the Free Software Foundation; + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. + IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM, + OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE + USE OR PERFORMANCE OF THIS SOFTWARE. + + ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS, + TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED. +*/ +/* + * $Id$ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +struct uart_t { + char *type; + int m_id; + int p_id; + int proto; + int speed; + int flags; + int (*init) (int fd, struct uart_t *u, struct termios *ti); +}; + +#define FLOW_CTL 0x0001 + +static int uart_speed(int s) +{ + switch (s) { + case 9600: + return B9600; + case 19200: + return B19200; + case 38400: + return B38400; + case 57600: + return B57600; + case 115200: + return B115200; + case 230400: + return B230400; + case 460800: + return B460800; + case 921600: + return B921600; + default: + return B57600; + } +} + +static int set_speed(int fd, struct termios *ti, int speed) +{ + cfsetospeed(ti, uart_speed(speed)); + return tcsetattr(fd, TCSANOW, ti); +} + +static void sig_alarm(int sig) +{ + fprintf(stderr, "Initialization timed out.\n"); + exit(1); +} + +/* + * Read an HCI event from the given file descriptor. + */ +static int read_hci_event(int fd, unsigned char* buf, int size) +{ + int remain, r; + int count = 0; + + if (size <= 0) + return -1; + + /* The first byte identifies the packet type. For HCI event packets, it + * should be 0x04, so we read until we get to the 0x04. */ + while (1) { + r = read(fd, buf, 1); + if (r <= 0) + return -1; + if (buf[0] == 0x04) + break; + } + count++; + + /* The next two bytes are the event code and parameter total length. */ + while (count < 3) { + r = read(fd, buf + count, 3 - count); + if (r <= 0) + return -1; + count += r; + } + + /* Now we read the parameters. */ + if (buf[2] < (size - 3)) + remain = buf[2]; + else + remain = size - 3; + + while ((count - 3) < remain) { + r = read(fd, buf + count, remain - (count - 3)); + if (r <= 0) + return -1; + count += r; + } + return count; +} + +/* + * Ericsson specific initialization + */ +static int ericsson(int fd, struct uart_t *u, struct termios *ti) +{ + struct timespec tm = {0, 50000}; + char cmd[10]; + + /* Switch to default Ericsson baudrate*/ + if (set_speed(fd, ti, 57600) < 0) { + perror("Can't set default baud rate"); + return -1; + } + + cmd[0] = HCI_COMMAND_PKT; + cmd[1] = 0x09; + cmd[2] = 0xfc; + cmd[3] = 0x01; + + switch (u->speed) { + case 57600: + cmd[4] = 0x03; + break; + case 115200: + cmd[4] = 0x02; + break; + case 230400: + cmd[4] = 0x01; + break; + case 460800: + cmd[4] = 0x00; + break; + default: + cmd[4] = 0x03; + u->speed = 57600; + break; + } + + /* Send initialization command */ + if (write(fd, cmd, 5) != 5) { + perror("Failed to write init command"); + return -1; + } + nanosleep(&tm, NULL); + return 0; +} + +/* + * Digianswer specific initialization + */ +static int digi(int fd, struct uart_t *u, struct termios *ti) +{ + struct timespec tm = {0, 50000}; + char cmd[10]; + + /* Switch to default Digi baudrate*/ + if (set_speed(fd, ti, 9600) < 0) { + perror("Can't set default baud rate"); + return -1; + } + + /* DigiAnswer set baud rate command */ + cmd[0] = HCI_COMMAND_PKT; + cmd[1] = 0x07; + cmd[2] = 0xfc; + cmd[3] = 0x01; + + switch (u->speed) { + case 57600: + cmd[4] = 0x08; + break; + case 115200: + cmd[4] = 0x09; + break; + default: + cmd[4] = 0x09; + u->speed = 115200; + break; + } + + /* Send initialization command */ + if (write(fd, cmd, 5) != 5) { + perror("Failed to write init command"); + return -1; + } + nanosleep(&tm, NULL); + return 0; +} + +/* + * CSR specific initialization + * Inspired strongly by code in OpenBT and experimentations with Brainboxes + * Pcmcia card. + * Jean Tourrilhes - 14.11.01 + */ +static int csr(int fd, struct uart_t *u, struct termios *ti) +{ + struct timespec tm = {0, 10000000}; /* 10ms - be generous */ + unsigned char cmd[30]; /* Command */ + unsigned char resp[30]; /* Response */ + int clen = 0; /* Command len */ + static int csr_seq = 0; /* Sequence number of command */ + int divisor; + + /* Switch to default CSR baudrate */ + if (set_speed(fd, ti, 115200) < 0) { + perror("Can't set default baud rate"); + return -1; + } + + /* It seems that if we set the CSR UART speed straight away, it + * won't work, the CSR UART gets into a state where we can't talk + * to it anymore. + * On the other hand, doing a read before setting the CSR speed + * seems to be ok. + * Therefore, the strategy is to read the build ID (useful for + * debugging) and only then set the CSR UART speed. Doing like + * this is more complex but at least it works ;-) + * The CSR UART control may be slow to wake up or something because + * every time I read its speed, its bogus... + * Jean II */ + + /* Try to read the build ID of the CSR chip */ + clen = 5 + (5 + 6) * 2; + /* HCI header */ + cmd[0] = HCI_COMMAND_PKT; + cmd[1] = 0x00; /* CSR command */ + cmd[2] = 0xfc; /* MANUFACTURER_SPEC */ + cmd[3] = 1 + (5 + 6) * 2; /* len */ + /* CSR MSG header */ + cmd[4] = 0xC2; /* first+last+channel=BCC */ + /* CSR BCC header */ + cmd[5] = 0x00; /* type = GET-REQ */ + cmd[6] = 0x00; /* - msB */ + cmd[7] = 5 + 4; /* len */ + cmd[8] = 0x00; /* - msB */ + cmd[9] = csr_seq & 0xFF;/* seq num */ + cmd[10] = (csr_seq >> 8) & 0xFF; /* - msB */ + csr_seq++; + cmd[11] = 0x19; /* var_id = CSR_CMD_BUILD_ID */ + cmd[12] = 0x28; /* - msB */ + cmd[13] = 0x00; /* status = STATUS_OK */ + cmd[14] = 0x00; /* - msB */ + /* CSR BCC payload */ + memset(cmd + 15, 0, 6 * 2); + + /* Send command */ + do { + if (write(fd, cmd, clen) != clen) { + perror("Failed to write init command (GET_BUILD_ID)"); + return -1; + } + + /* Read reply. */ + if (read_hci_event(fd, resp, 100) < 0) { + perror("Failed to read init response (GET_BUILD_ID)"); + return -1; + } + + /* Event code 0xFF is for vendor-specific events, which is + * what we're looking for. */ + } while (resp[1] != 0xFF); + +#ifdef CSR_DEBUG + { + char temp[512]; + int i; + for (i=0; i < rlen; i++) + sprintf(temp + (i*3), "-%02X", resp[i]); + fprintf(stderr, "Reading CSR build ID %d [%s]\n", rlen, temp + 1); + // In theory, it should look like : + // 04-FF-13-FF-01-00-09-00-00-00-19-28-00-00-73-00-00-00-00-00-00-00 + } +#endif + /* Display that to user */ + fprintf(stderr, "CSR build ID 0x%02X-0x%02X\n", + resp[15] & 0xFF, resp[14] & 0xFF); + + /* Try to read the current speed of the CSR chip */ + clen = 5 + (5 + 4)*2; + /* -- HCI header */ + cmd[3] = 1 + (5 + 4)*2; /* len */ + /* -- CSR BCC header -- */ + cmd[9] = csr_seq & 0xFF; /* seq num */ + cmd[10] = (csr_seq >> 8) & 0xFF; /* - msB */ + csr_seq++; + cmd[11] = 0x02; /* var_id = CONFIG_UART */ + cmd[12] = 0x68; /* - msB */ + +#ifdef CSR_DEBUG + /* Send command */ + do { + if (write(fd, cmd, clen) != clen) { + perror("Failed to write init command (GET_BUILD_ID)"); + return -1; + } + + /* Read reply. */ + if (read_hci_event(fd, resp, 100) < 0) { + perror("Failed to read init response (GET_BUILD_ID)"); + return -1; + } + + /* Event code 0xFF is for vendor-specific events, which is + * what we're looking for. */ + } while (resp[1] != 0xFF); + + { + char temp[512]; + int i; + for (i=0; i < rlen; i++) + sprintf(temp + (i*3), "-%02X", resp[i]); + fprintf(stderr, "Reading CSR UART speed %d [%s]\n", rlen, temp+1); + } +#endif + + /* Now, create the command that will set the UART speed */ + /* CSR BCC header */ + cmd[5] = 0x02; /* type = SET-REQ */ + cmd[6] = 0x00; /* - msB */ + cmd[9] = csr_seq & 0xFF; /* seq num */ + cmd[10] = (csr_seq >> 8) & 0xFF;/* - msB */ + csr_seq++; + + switch (u->speed) { + case 9600: + divisor = 0x0027; + break; + /* Various speeds ommited */ + case 57600: + divisor = 0x00EC; + break; + case 115200: + divisor = 0x01D8; + break; + /* For Brainbox Pcmcia cards */ + case 460800: + divisor = 0x075F; + break; + case 921600: + divisor = 0x0EBF; + break; + default: + /* Safe default */ + divisor = 0x01D8; + u->speed = 115200; + break; + } + /* No parity, one stop bit -> divisor |= 0x0000; */ + cmd[15] = (divisor) & 0xFF; /* divider */ + cmd[16] = (divisor >> 8) & 0xFF; /* - msB */ + /* The rest of the payload will be 0x00 */ + +#ifdef CSR_DEBUG + { + char temp[512]; + int i; + for(i = 0; i < clen; i++) + sprintf(temp + (i*3), "-%02X", cmd[i]); + fprintf(stderr, "Writing CSR UART speed %d [%s]\n", clen, temp + 1); + // In theory, it should look like : + // 01-00-FC-13-C2-02-00-09-00-03-00-02-68-00-00-BF-0E-00-00-00-00-00-00 + // 01-00-FC-13-C2-02-00-09-00-01-00-02-68-00-00-D8-01-00-00-00-00-00-00 + } +#endif + + /* Send the command to set the CSR UART speed */ + if (write(fd, cmd, clen) != clen) { + perror("Failed to write init command (SET_UART_SPEED)"); + return -1; + } + nanosleep(&tm, NULL); + return 0; +} + +/* + * Silicon Wave specific initialization + * Thomas Moser + */ +static int swave(int fd, struct uart_t *u, struct termios *ti) +{ + struct timespec tm = {0, 500000}; + char cmd[10], rsp[100]; + int r; + + /* Switch to default Silicon Wave baudrate*/ + if (set_speed(fd, ti, 115200) < 0) { + perror("Can't set default baud rate"); + return -1; + } + + // Silicon Wave set baud rate command + // see HCI Vendor Specific Interface from Silicon Wave + // first send a "param access set" command to set the + // appropriate data fields in RAM. Then send a "HCI Reset + // Subcommand", e.g. "soft reset" to make the changes effective. + + cmd[0] = HCI_COMMAND_PKT; // it's a command packet + cmd[1] = 0x0B; // OCF 0x0B = param access set + cmd[2] = 0xfc; // OGF bx111111 = vendor specific + cmd[3] = 0x06; // 6 bytes of data following + cmd[4] = 0x01; // param sub command + cmd[5] = 0x11; // tag 17 = 0x11 = HCI Transport Params + cmd[6] = 0x03; // length of the parameter following + cmd[7] = 0x01; // HCI Transport flow control enable + cmd[8] = 0x01; // HCI Transport Type = UART + + switch (u->speed) { + case 19200: + cmd[9] = 0x03; + break; + case 38400: + cmd[9] = 0x02; + break; + case 57600: + cmd[9] = 0x01; + break; + case 115200: + cmd[9] = 0x00; + break; + default: + u->speed = 115200; + cmd[9] = 0x00; + break; + } + + /* Send initialization command */ + if (write(fd, cmd, 10) != 5) { + perror("Failed to write init command"); + return -1; + } + + // We should wait for a "GET Event" to confirm the success of + // the baud rate setting. Wait some time before reading. Better: + // read with timeout, parse data + // until correct answer, else error handling ... todo ... + + nanosleep(&tm, NULL); + + r = read(fd, rsp, sizeof(rsp)); + if (r > 0) { + // guess it's okay, but we should parse the reply. But since + // I don't react on an error anyway ... todo + // Response packet format: + // 04 Event + // FF Vendor specific + // 07 Parameter length + // 0B Subcommand + // 01 Setevent + // 11 Tag specifying HCI Transport Layer Parameter + // 03 length + // 01 flow on + // 01 Hci Transport type = Uart + // xx Baud rate set (see above) + } else { + // ups, got error. + return -1; + } + + // we probably got the reply. Now we must send the "soft reset": + cmd[0] = HCI_COMMAND_PKT; // it's a command packet + cmd[1] = 0x0B; // OCF 0x0B = param access set + cmd[2] = 0xfc; // OGF bx111111 = vendor specific + cmd[3] = 0x01; // 1 byte of data following + cmd[4] = 0x03; // HCI Reset Subcommand + + // Send initialization command + if (write(fd, cmd, 5) != 5) { + perror("Can't write Silicon Wave reset cmd."); + return -1; + } + + nanosleep(&tm, NULL); + + // now the uart baud rate on the silicon wave module is set and effective. + // change our own baud rate as well. Then there is a reset event comming in + // on the *new* baud rate. This is *undocumented*! The packet looks like this: + // 04 FF 01 0B (which would make that a confirmation of 0x0B = "Param + // subcommand class". So: change to new baud rate, read with timeout, parse + // data, error handling. BTW: all param access in Silicon Wave is done this way. + // Maybe this code would belong in a seperate file, or at least code reuse... + + return 0; +} + +struct uart_t uart[] = { + { "any", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, NULL }, + { "ericsson", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, ericsson }, + { "digi", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, digi }, + + /* Xircom PCMCIA cards: Credit Card Adapter and Real Port Adapter */ + { "xircom", 0x0105, 0x080a, HCI_UART_H4, 115200, FLOW_CTL, NULL }, + + /* CSR Casira serial adapter or BrainBoxes serial dongle (BL642) */ + { "csr", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, csr }, + + /* BrainBoxes PCMCIA card (BL620) */ + { "bboxes", 0x0160, 0x0002, HCI_UART_H4, 460800, FLOW_CTL, csr }, + + /* Silicon Wave kits */ + { "swave", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, swave }, + + /* Sphinx Electronics PICO Card */ + { "picocard", 0x025e, 0x1000, HCI_UART_H4, 115200, FLOW_CTL, NULL }, + + { NULL, 0 } +}; + +struct uart_t * get_by_id(int m_id, int p_id) +{ + int i; + for (i = 0; uart[i].type; i++) { + if (uart[i].m_id == m_id && uart[i].p_id == p_id) + return &uart[i]; + } + return NULL; +} + +struct uart_t * get_by_type(char *type) +{ + int i; + for (i = 0; uart[i].type; i++) { + if (!strcmp(uart[i].type, type)) + return &uart[i]; + } + return NULL; +} + +/* Initialize UART driver */ +int init_uart(char *dev, struct uart_t *u) +{ + struct termios ti; + int fd, i; + + fd = open(dev, O_RDWR | O_NOCTTY); + if (fd < 0) { + perror("Can't open serial port"); + return -1; + } + + tcflush(fd, TCIOFLUSH); + + if (tcgetattr(fd, &ti) < 0) { + perror("Can't get port settings"); + return -1; + } + + cfmakeraw(&ti); + + ti.c_cflag |= CLOCAL; + if (u->flags & FLOW_CTL) + ti.c_cflag |= CRTSCTS; + else + ti.c_cflag &= ~CRTSCTS; + + if (tcsetattr(fd, TCSANOW, &ti) < 0) { + perror("Can't set port settings"); + return -1; + } + + tcflush(fd, TCIOFLUSH); + + if (u->init && u->init(fd, u, &ti) < 0) + return -1; + + tcflush(fd, TCIOFLUSH); + + /* Set actual baudrate */ + if (set_speed(fd, &ti, u->speed) < 0) { + perror("Can't set baud rate"); + return -1; + } + + /* Set TTY to N_HCI line discpline */ + i = N_HCI; + if (ioctl(fd, TIOCSETD, &i) < 0) { + perror("Can't set line disc"); + return -1; + } + + if (ioctl(fd, HCIUARTSETPROTO, u->proto) < 0) { + perror("Can't set device"); + return -1; + } + + return fd; +} + +static void usage(void) +{ + printf("hciattach - HCI UART driver initialization utility\n"); + printf("Usage:\n"); + printf("\thciattach [speed] [flow]\n"); + printf("\thciattach -l\n"); +} + +extern int optind, opterr, optopt; +extern char *optarg; + +int main(int argc, char *argv[]) +{ + struct uart_t *u = NULL; + int detach, opt, i, n; + int to = 5; + struct sigaction sa; + char dev[20]; + + detach = 1; + + while ((opt=getopt(argc, argv, "nt:l")) != EOF) { + switch(opt) { + case 'n': + detach = 0; + break; + + case 't': + to = atoi(optarg); + break; + + case 'l': + for (i = 0; uart[i].type; i++) { + printf("%-10s0x%04x,0x%04x\n", uart[i].type, + uart[i].m_id, uart[i].p_id); + } + exit(0); + + default: + usage(); + exit(1); + } + } + + n = argc - optind; + if (n < 2) { + usage(); + exit(1); + } + + for (n = 0; optind < argc; n++, optind++) { + char *opt; + + opt = argv[optind]; + + switch(n) { + case 0: + dev[0] = 0; + if (!strchr(opt, '/')) + strcpy(dev, "/dev/"); + strcat(dev, opt); + break; + + case 1: + if (strchr(argv[optind], ',')) { + int m_id, p_id; + sscanf(argv[optind], "%x,%x", &m_id, &p_id); + u = get_by_id(m_id, p_id); + } else { + u = get_by_type(opt); + } + + if (!u) { + fprintf(stderr, "Unknow device type or id\n"); + exit(1); + } + + break; + + case 2: + u->speed = atoi(argv[optind]); + break; + + case 3: + if (!strcmp("flow", argv[optind])) + u->flags |= FLOW_CTL; + else + u->flags &= ~FLOW_CTL; + break; + } + } + + if (!u) { + fprintf(stderr, "Unknow device type or id\n"); + exit(1); + } + + memset(&sa, 0, sizeof(sa)); + sa.sa_flags = SA_NOCLDSTOP; + sa.sa_handler = sig_alarm; + sigaction(SIGALRM, &sa, NULL); + + /* 5 seconds should be enought for intialization */ + alarm(to); + + n = init_uart(dev, u); + if (n < 0) { + perror("Can't init device"); + exit(1); + } + + alarm(0); + + if (detach) { + if (fork()) return 0; + for (i=0; i<20; i++) + if (i != n) close(i); + } + + while (1) sleep(999999999); + return 0; +} -- cgit From d5355b836015bbe6d4bb4b4229c2cc7c8d330d9d Mon Sep 17 00:00:00 2001 From: Max Krasnyansky Date: Mon, 18 Mar 2002 19:36:42 +0000 Subject: Support for Inventel devices. --- tools/hciattach.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index a4489019..cf882b92 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -544,6 +544,9 @@ struct uart_t uart[] = { /* Sphinx Electronics PICO Card */ { "picocard", 0x025e, 0x1000, HCI_UART_H4, 115200, FLOW_CTL, NULL }, + /* Inventel BlueBird Module */ + { "inventel", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, NULL }, + { NULL, 0 } }; -- cgit From eb965f147eaa15028d1abca397a6dc49c55d7868 Mon Sep 17 00:00:00 2001 From: Max Krasnyansky Date: Tue, 19 Mar 2002 05:37:10 +0000 Subject: COM One PC Card support --- tools/hciattach.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index cf882b92..a7f89e21 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -547,6 +547,9 @@ struct uart_t uart[] = { /* Inventel BlueBird Module */ { "inventel", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, NULL }, + /* COM One Platinium Bluetooth PC Card */ + { "comone", 0xffff, 0x0101, HCI_UART_H4, 115200, FLOW_CTL, NULL }, + { NULL, 0 } }; -- cgit From 940d830204a87da484eec5e84f18281476c9a505 Mon Sep 17 00:00:00 2001 From: Max Krasnyansky Date: Fri, 31 May 2002 17:14:39 +0000 Subject: -p print pid option --- tools/hciattach.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index a7f89e21..9668460c 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -647,30 +647,36 @@ extern char *optarg; int main(int argc, char *argv[]) { struct uart_t *u = NULL; - int detach, opt, i, n; + int detach, printpid, opt, i, n; int to = 5; + pid_t pid; struct sigaction sa; char dev[20]; detach = 1; + printpid = 0; - while ((opt=getopt(argc, argv, "nt:l")) != EOF) { + while ((opt=getopt(argc, argv, "npt:l")) != EOF) { switch(opt) { case 'n': detach = 0; break; - + + case 'p': + printpid = 1; + break; + case 't': to = atoi(optarg); break; - + case 'l': for (i = 0; uart[i].type; i++) { printf("%-10s0x%04x,0x%04x\n", uart[i].type, uart[i].m_id, uart[i].p_id); } exit(0); - + default: usage(); exit(1); @@ -747,7 +753,11 @@ int main(int argc, char *argv[]) alarm(0); if (detach) { - if (fork()) return 0; + if ((pid = fork())) { + if (printpid) + printf("%d\n", pid); + return 0; + } for (i=0; i<20; i++) if (i != n) close(i); } -- cgit From 671854ad5a6f8b40adb397d30aa93ff66efa1376 Mon Sep 17 00:00:00 2001 From: Max Krasnyansky Date: Sun, 4 Aug 2002 22:13:31 +0000 Subject: BCSP inti support. --- tools/hciattach.c | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 9668460c..b24f33ab 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -228,6 +228,26 @@ static int digi(int fd, struct uart_t *u, struct termios *ti) return 0; } +/* + * BCSP specific initialization + */ +static int bcsp(int fd, struct uart_t *u, struct termios *ti) +{ + ti->c_cflag &= ~CBAUD; + ti->c_cflag |= B115200 | CS8 | CLOCAL | PARENB; + ti->c_cflag &= ~(PARODD|CRTSCTS); + + ti->c_oflag = 0; /* turn off output processing */ + ti->c_lflag = 0; /* no local modes */ + + if (tcsetattr(fd, TCSANOW, ti) < 0) { + perror("Can't set port settings"); + return -1; + } + + return 0; +} + /* * CSR specific initialization * Inspired strongly by code in OpenBT and experimentations with Brainboxes @@ -525,30 +545,32 @@ static int swave(int fd, struct uart_t *u, struct termios *ti) } struct uart_t uart[] = { - { "any", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, NULL }, - { "ericsson", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, ericsson }, - { "digi", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, digi }, + { "any", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, NULL }, + { "ericsson", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, ericsson }, + { "digi", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, digi }, + + { "bcsp", 0x0000, 0x0000, HCI_UART_BCSP, 115200, 0, bcsp }, /* Xircom PCMCIA cards: Credit Card Adapter and Real Port Adapter */ - { "xircom", 0x0105, 0x080a, HCI_UART_H4, 115200, FLOW_CTL, NULL }, + { "xircom", 0x0105, 0x080a, HCI_UART_H4, 115200, FLOW_CTL, NULL }, /* CSR Casira serial adapter or BrainBoxes serial dongle (BL642) */ - { "csr", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, csr }, + { "csr", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, csr }, /* BrainBoxes PCMCIA card (BL620) */ - { "bboxes", 0x0160, 0x0002, HCI_UART_H4, 460800, FLOW_CTL, csr }, + { "bboxes", 0x0160, 0x0002, HCI_UART_H4, 460800, FLOW_CTL, csr }, /* Silicon Wave kits */ - { "swave", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, swave }, + { "swave", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, swave }, /* Sphinx Electronics PICO Card */ - { "picocard", 0x025e, 0x1000, HCI_UART_H4, 115200, FLOW_CTL, NULL }, + { "picocard", 0x025e, 0x1000, HCI_UART_H4, 115200, FLOW_CTL, NULL }, /* Inventel BlueBird Module */ - { "inventel", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, NULL }, + { "inventel", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, NULL }, /* COM One Platinium Bluetooth PC Card */ - { "comone", 0xffff, 0x0101, HCI_UART_H4, 115200, FLOW_CTL, NULL }, + { "comone", 0xffff, 0x0101, HCI_UART_BCSP, 115200, 0, bcsp }, { NULL, 0 } }; -- cgit From 04c8ddd5a5d720e75144755d071e2331c979d1ed Mon Sep 17 00:00:00 2001 From: Max Krasnyansky Date: Tue, 20 Aug 2002 04:39:54 +0000 Subject: Add 'bluetooth/' to includes --- tools/hciattach.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index b24f33ab..ca81117b 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -41,10 +41,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include struct uart_t { char *type; -- cgit From f93bdd3e8438c165bc3ba98dc1730d2701f98bfc Mon Sep 17 00:00:00 2001 From: Max Krasnyansky Date: Mon, 9 Sep 2002 16:27:39 +0000 Subject: BCSP fixes --- tools/hciattach.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 6 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index ca81117b..cee27e46 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -77,6 +77,8 @@ static int uart_speed(int s) return B460800; case 921600: return B921600; + case 1000000: + return B1000000; default: return B57600; } @@ -233,18 +235,88 @@ static int digi(int fd, struct uart_t *u, struct termios *ti) */ static int bcsp(int fd, struct uart_t *u, struct termios *ti) { - ti->c_cflag &= ~CBAUD; - ti->c_cflag |= B115200 | CS8 | CLOCAL | PARENB; - ti->c_cflag &= ~(PARODD|CRTSCTS); + unsigned char byte, bcsph[4], bcspp[4], + bcsp_sync_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xda,0xdc,0xed,0xed,0xc0}, + bcsp_sync_resp_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xac,0xaf,0xef,0xee,0xc0}, + bcsp_conf_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xad,0xef,0xac,0xed,0xc0}, + bcsp_conf_resp_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xde,0xad,0xd0,0xd0,0xc0}, + bcspsync[4] = {0xda, 0xdc, 0xed, 0xed}, + bcspsyncresp[4] = {0xac,0xaf,0xef,0xee}, + bcspconf[4] = {0xad,0xef,0xac,0xed}, + bcspconfresp[4] = {0xde,0xad,0xd0,0xd0}; + int sync_sent = 0; + + if (set_speed(fd, ti, u->speed) < 0) { + perror("Can't set default baud rate"); + return -1; + } - ti->c_oflag = 0; /* turn off output processing */ - ti->c_lflag = 0; /* no local modes */ + ti->c_cflag |= PARENB; + ti->c_cflag &= ~(PARODD); if (tcsetattr(fd, TCSANOW, ti) < 0) { perror("Can't set port settings"); return -1; } + /* State = shy */ + + while (1) { + do { + read(fd, &byte, 1); + } while(byte != 0xC0); + + do { + read(fd, &bcsph[0], 1); + } while(bcsph[0] == 0xC0); + + read(fd, &bcsph[1], 3); + if (((bcsph[0] + bcsph[1] + bcsph[2]) & 0xFF) != (unsigned char)~bcsph[3]) + continue; + if (bcsph[1] != 0x41 || bcsph[2] != 0x00) + continue; + + read(fd, &bcspp, 4); + if (!memcmp(bcspp, bcspsync, 4)) { + write(fd, &bcsp_sync_resp_pkt,10); + if (!sync_sent) { + write(fd, &bcsp_sync_pkt, 10); /* muzzled = false */ + sync_sent = 1; + } + } else if (!memcmp(bcspp, bcspsyncresp, 4)) + break; + } + + /* State = curious */ + + write(fd, &bcsp_conf_pkt, 10); + while (1) { + do { + read(fd, &byte, 1); + } while(byte != 0xC0); + + do { + read(fd, &bcsph[0], 1); + } while(bcsph[0] == 0xC0); + + read(fd, &bcsph[1], 3); + if (((bcsph[0] + bcsph[1] + bcsph[2]) & 0xFF) != (unsigned char)~bcsph[3]) + continue; + + if (bcsph[1] != 0x41 || bcsph[2] != 0x00) + continue; + + read(fd, &bcspp, 4); + if (!memcmp(bcspp, bcspsync, 4)) + write(fd, &bcsp_sync_resp_pkt, 10); + else if (!memcmp(bcspp, bcspconf, 4)) + write(fd, &bcsp_conf_resp_pkt, 10); + else if (!memcmp(bcspp, bcspconfresp, 4)) + break; + } + + /* State = garrulous */ + return 0; } @@ -763,7 +835,7 @@ int main(int argc, char *argv[]) sa.sa_handler = sig_alarm; sigaction(SIGALRM, &sa, NULL); - /* 5 seconds should be enought for intialization */ + /* 5 seconds should be enough for intialization */ alarm(to); n = init_uart(dev, u); -- cgit From 2af38a90ac802ab706ed984b3105ada22d6f060d Mon Sep 17 00:00:00 2001 From: Max Krasnyansky Date: Thu, 26 Sep 2002 05:13:23 +0000 Subject: BCSP initialization improvements --- tools/hciattach.c | 134 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 109 insertions(+), 25 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index cee27e46..78deb53b 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -230,21 +230,67 @@ static int digi(int fd, struct uart_t *u, struct termios *ti) return 0; } +static int read_check(int fd, void *buf, int count) +{ + int res; + + do{ + res = read(fd, buf, count); + if (res != -1) { + buf += res; count -= res; + } + } while (count && (errno == 0 || errno == EINTR)); + + if (count) + return -1; + + return 0; +} + /* * BCSP specific initialization */ +int serial_fd; + +static void bcsp_tshy_sig_alarm(int sig) +{ + static int retries=0; + unsigned char bcsp_sync_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xda,0xdc,0xed,0xed,0xc0}; + + if (retries < 10) { + retries++; + write(serial_fd, &bcsp_sync_pkt, 10); + alarm(1); + return; + } + fprintf(stderr, "BCSP initialization timed out\n"); + exit(1); +} + +static void bcsp_tconf_sig_alarm(int sig) +{ + static int retries=0; + unsigned char bcsp_conf_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xad,0xef,0xac,0xed,0xc0}; + if (retries < 10){ + retries++; + write(serial_fd, &bcsp_conf_pkt, 10); + alarm(1); + return; + } + fprintf(stderr, "BCSP initialization timed out\n"); + exit(1); +} + static int bcsp(int fd, struct uart_t *u, struct termios *ti) { unsigned char byte, bcsph[4], bcspp[4], - bcsp_sync_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xda,0xdc,0xed,0xed,0xc0}, bcsp_sync_resp_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xac,0xaf,0xef,0xee,0xc0}, - bcsp_conf_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xad,0xef,0xac,0xed,0xc0}, bcsp_conf_resp_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xde,0xad,0xd0,0xd0,0xc0}, - bcspsync[4] = {0xda, 0xdc, 0xed, 0xed}, + bcspsync[4] = {0xda, 0xdc, 0xed, 0xed}, bcspsyncresp[4] = {0xac,0xaf,0xef,0xee}, - bcspconf[4] = {0xad,0xef,0xac,0xed}, + bcspconf[4] = {0xad,0xef,0xac,0xed}, bcspconfresp[4] = {0xde,0xad,0xd0,0xd0}; - int sync_sent = 0; + struct sigaction sa; if (set_speed(fd, ti, u->speed) < 0) { perror("Can't set default baud rate"); @@ -259,54 +305,92 @@ static int bcsp(int fd, struct uart_t *u, struct termios *ti) return -1; } + alarm(0); + + serial_fd = fd; + memset(&sa, 0, sizeof(sa)); + sa.sa_flags = SA_NOCLDSTOP; + sa.sa_handler = bcsp_tshy_sig_alarm; + sigaction(SIGALRM, &sa, NULL); + /* State = shy */ + bcsp_tshy_sig_alarm(0); while (1) { do { - read(fd, &byte, 1); - } while(byte != 0xC0); + if (read_check(fd, &byte, 1) == -1){ + perror("Failed to read"); + return -1; + } + } while (byte != 0xC0); do { - read(fd, &bcsph[0], 1); - } while(bcsph[0] == 0xC0); + if ( read_check(fd, &bcsph[0], 1) == -1){ + perror("Failed to read"); + return -1; + } + + } while (bcsph[0] == 0xC0); + + if ( read_check(fd, &bcsph[1], 3) == -1){ + perror("Failed to read"); + return -1; + } - read(fd, &bcsph[1], 3); if (((bcsph[0] + bcsph[1] + bcsph[2]) & 0xFF) != (unsigned char)~bcsph[3]) - continue; + continue; if (bcsph[1] != 0x41 || bcsph[2] != 0x00) - continue; - - read(fd, &bcspp, 4); + continue; + + if (read_check(fd, &bcspp, 4) == -1){ + perror("Failed to read"); + return -1; + } + if (!memcmp(bcspp, bcspsync, 4)) { write(fd, &bcsp_sync_resp_pkt,10); - if (!sync_sent) { - write(fd, &bcsp_sync_pkt, 10); /* muzzled = false */ - sync_sent = 1; - } } else if (!memcmp(bcspp, bcspsyncresp, 4)) break; } /* State = curious */ - write(fd, &bcsp_conf_pkt, 10); + alarm(0); + sa.sa_handler = bcsp_tconf_sig_alarm; + sigaction(SIGALRM, &sa, NULL); + alarm(1); + while (1) { do { - read(fd, &byte, 1); - } while(byte != 0xC0); + if (read_check(fd, &byte, 1) == -1){ + perror("Failed to read"); + return -1; + } + } while (byte != 0xC0); do { - read(fd, &bcsph[0], 1); - } while(bcsph[0] == 0xC0); + if (read_check(fd, &bcsph[0], 1) == -1){ + perror("Failed to read"); + return -1; + } + } while (bcsph[0] == 0xC0); - read(fd, &bcsph[1], 3); + if (read_check(fd, &bcsph[1], 3) == -1){ + perror("Failed to read"); + return -1; + } + if (((bcsph[0] + bcsph[1] + bcsph[2]) & 0xFF) != (unsigned char)~bcsph[3]) continue; if (bcsph[1] != 0x41 || bcsph[2] != 0x00) continue; - read(fd, &bcspp, 4); + if (read_check(fd, &bcspp, 4) == -1){ + perror("Failed to read"); + return -1; + } + if (!memcmp(bcspp, bcspsync, 4)) write(fd, &bcsp_sync_resp_pkt, 10); else if (!memcmp(bcspp, bcspconf, 4)) -- cgit From aaa780de16b91375ba63bdf4929bc5b7a2a0c8f6 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Sat, 8 Feb 2003 12:08:55 +0000 Subject: typos --- tools/hciattach.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 78deb53b..f30ae033 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -796,10 +796,10 @@ int init_uart(char *dev, struct uart_t *u) return -1; } - /* Set TTY to N_HCI line discpline */ + /* Set TTY to N_HCI line discipline */ i = N_HCI; if (ioctl(fd, TIOCSETD, &i) < 0) { - perror("Can't set line disc"); + perror("Can't set line discipline"); return -1; } @@ -890,7 +890,7 @@ int main(int argc, char *argv[]) } if (!u) { - fprintf(stderr, "Unknow device type or id\n"); + fprintf(stderr, "Unknown device type or id\n"); exit(1); } @@ -910,7 +910,7 @@ int main(int argc, char *argv[]) } if (!u) { - fprintf(stderr, "Unknow device type or id\n"); + fprintf(stderr, "Unknown device type or id\n"); exit(1); } @@ -919,12 +919,12 @@ int main(int argc, char *argv[]) sa.sa_handler = sig_alarm; sigaction(SIGALRM, &sa, NULL); - /* 5 seconds should be enough for intialization */ + /* 5 seconds should be enough for initialization */ alarm(to); n = init_uart(dev, u); if (n < 0) { - perror("Can't init device"); + perror("Can't initialize device"); exit(1); } -- cgit From 427f4bbc07f40706dd5e3c5500f14c63a160c979 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Wed, 12 Feb 2003 12:34:16 +0000 Subject: describe optional arguments --- tools/hciattach.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index f30ae033..b6aa7376 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -815,7 +815,7 @@ static void usage(void) { printf("hciattach - HCI UART driver initialization utility\n"); printf("Usage:\n"); - printf("\thciattach [speed] [flow]\n"); + printf("\thciattach [-n] [-p] [-t timeout] [speed] [flow]\n"); printf("\thciattach -l\n"); } -- cgit From 047f07b46aa8afabe5ebd67fa02365c92a4ff224 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Wed, 12 Feb 2003 13:46:00 +0000 Subject: add support for texas module --- tools/hciattach.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index b6aa7376..0131dcb6 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -230,14 +230,74 @@ static int digi(int fd, struct uart_t *u, struct termios *ti) return 0; } +static int texas(int fd, struct uart_t *u, struct termios *ti) +{ + struct timespec tm = {0, 50000}; + char cmd[10]; + unsigned char resp[100]; /* Response */ + int n; + + memset(resp,'\0', 100); + + /* Switch to default Texas baudrate*/ + if (set_speed(fd, ti, 115200) < 0) { + perror("Can't set default baud rate"); + return -1; + } + + /* It is possible to get software version with manufacturer specific + HCI command HCI_VS_TI_Version_Number. But the only thing you get more + is if this is point-to-point or point-to-multipoint module */ + + /* Get Manufacturer and LMP version */ + cmd[0] = HCI_COMMAND_PKT; + cmd[1] = 0x01; + cmd[2] = 0x10; + cmd[3] = 0x00; + + do { + n = write(fd, cmd, 4); + if (n < 0) { + perror("Failed to write init command (READ_LOCAL_VERSION_INFORMATION)"); + return -1; + } + if (n < 4) { + fprintf(stderr, "Wanted to write 4 bytes, could only write %d. Stop\n", n); + return -1; + } + + /* Read reply. */ + if (read_hci_event(fd, resp, 100) < 0) { + perror("Failed to read init response (READ_LOCAL_VERSION_INFORMATION)"); + return -1; + } + + /* Wait for command complete event for our Opcode */ + } while (resp[4] != cmd[1] && resp[5] != cmd[2]); + + /* Verify manufacturer */ + if ((resp[11] & 0xFF) != 0x0d) + fprintf(stderr,"WARNING : module's manufacturer is not Texas Instrument\n"); + + /* Print LMP version */ + fprintf(stderr, "Texas module LMP version : 0x%02x\n", resp[10] & 0xFF); + + /* Print LMP subversion */ + fprintf(stderr, "Texas module LMP sub-version : 0x%02x%02x\n", resp[14] & 0xFF, resp[13] & 0xFF); + + nanosleep(&tm, NULL); + return 0; +} + static int read_check(int fd, void *buf, int count) { int res; - do{ + do { res = read(fd, buf, count); if (res != -1) { - buf += res; count -= res; + buf += res; + count -= res; } } while (count && (errno == 0 || errno == EINTR)); @@ -704,6 +764,7 @@ struct uart_t uart[] = { { "any", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, NULL }, { "ericsson", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, ericsson }, { "digi", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, digi }, + { "texas", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, texas}, { "bcsp", 0x0000, 0x0000, HCI_UART_BCSP, 115200, 0, bcsp }, -- cgit From a8b6c0b9d190457f40f30147fe70ef0f8467a60b Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 17 Mar 2003 09:06:19 +0000 Subject: Flush the serial buffer before quit in BCSP initialization --- tools/hciattach.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 0131dcb6..6959a006 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -323,6 +323,7 @@ static void bcsp_tshy_sig_alarm(int sig) alarm(1); return; } + tcflush(serial_fd, TCIOFLUSH); fprintf(stderr, "BCSP initialization timed out\n"); exit(1); } @@ -337,6 +338,7 @@ static void bcsp_tconf_sig_alarm(int sig) alarm(1); return; } + tcflush(serial_fd, TCIOFLUSH); fprintf(stderr, "BCSP initialization timed out\n"); exit(1); } -- cgit From 55682f4240f0854ea60d53314fc0c471d1e146b2 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 19 Mar 2003 21:17:46 +0000 Subject: Add 921600 bps for Ericsson modules --- tools/hciattach.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 6959a006..15a9d367 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -173,6 +173,9 @@ static int ericsson(int fd, struct uart_t *u, struct termios *ti) case 460800: cmd[4] = 0x00; break; + case 921600: + cmd[4] = 0x20; + break; default: cmd[4] = 0x03; u->speed = 57600; -- cgit From 40fbc58cb2874081e624d2658282f90f29525624 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 5 Apr 2003 14:13:04 +0000 Subject: Support for initial baud rate and sending of a break --- tools/hciattach.c | 128 +++++++++++++++++++++++++----------------------------- 1 file changed, 58 insertions(+), 70 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 15a9d367..7b8c20a0 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -51,6 +51,7 @@ struct uart_t { int m_id; int p_id; int proto; + int start_speed; int speed; int flags; int (*init) (int fd, struct uart_t *u, struct termios *ti); @@ -79,6 +80,8 @@ static int uart_speed(int s) return B921600; case 1000000: return B1000000; + case 1152000: + return B1152000; default: return B57600; } @@ -149,12 +152,6 @@ static int ericsson(int fd, struct uart_t *u, struct termios *ti) struct timespec tm = {0, 50000}; char cmd[10]; - /* Switch to default Ericsson baudrate*/ - if (set_speed(fd, ti, 57600) < 0) { - perror("Can't set default baud rate"); - return -1; - } - cmd[0] = HCI_COMMAND_PKT; cmd[1] = 0x09; cmd[2] = 0xfc; @@ -199,12 +196,6 @@ static int digi(int fd, struct uart_t *u, struct termios *ti) struct timespec tm = {0, 50000}; char cmd[10]; - /* Switch to default Digi baudrate*/ - if (set_speed(fd, ti, 9600) < 0) { - perror("Can't set default baud rate"); - return -1; - } - /* DigiAnswer set baud rate command */ cmd[0] = HCI_COMMAND_PKT; cmd[1] = 0x07; @@ -242,12 +233,6 @@ static int texas(int fd, struct uart_t *u, struct termios *ti) memset(resp,'\0', 100); - /* Switch to default Texas baudrate*/ - if (set_speed(fd, ti, 115200) < 0) { - perror("Can't set default baud rate"); - return -1; - } - /* It is possible to get software version with manufacturer specific HCI command HCI_VS_TI_Version_Number. But the only thing you get more is if this is point-to-point or point-to-multipoint module */ @@ -484,12 +469,6 @@ static int csr(int fd, struct uart_t *u, struct termios *ti) static int csr_seq = 0; /* Sequence number of command */ int divisor; - /* Switch to default CSR baudrate */ - if (set_speed(fd, ti, 115200) < 0) { - perror("Can't set default baud rate"); - return -1; - } - /* It seems that if we set the CSR UART speed straight away, it * won't work, the CSR UART gets into a state where we can't talk * to it anymore. @@ -596,6 +575,19 @@ static int csr(int fd, struct uart_t *u, struct termios *ti) } #endif + if (u->speed > 1500000) { + fprintf(stderr, "Speed %d too high. Remaining at %d baud\n", + u->speed, u->start_speed); + u->speed = u->start_speed; + } else if (u->speed != 57600 && uart_speed(u->speed) == B57600) { + /* Unknown speed. Why oh why can't we just pass an int to the kernel? */ + fprintf(stderr, "Speed %d unrecognised. Remaining at %d baud\n", + u->speed, u->start_speed); + u->speed = u->start_speed; + } + if (u->speed == u->start_speed) + return 0; + /* Now, create the command that will set the UART speed */ /* CSR BCC header */ cmd[5] = 0x02; /* type = SET-REQ */ @@ -604,30 +596,8 @@ static int csr(int fd, struct uart_t *u, struct termios *ti) cmd[10] = (csr_seq >> 8) & 0xFF;/* - msB */ csr_seq++; - switch (u->speed) { - case 9600: - divisor = 0x0027; - break; - /* Various speeds ommited */ - case 57600: - divisor = 0x00EC; - break; - case 115200: - divisor = 0x01D8; - break; - /* For Brainbox Pcmcia cards */ - case 460800: - divisor = 0x075F; - break; - case 921600: - divisor = 0x0EBF; - break; - default: - /* Safe default */ - divisor = 0x01D8; - u->speed = 115200; - break; - } + divisor = (u->speed*64+7812)/15625; + /* No parity, one stop bit -> divisor |= 0x0000; */ cmd[15] = (divisor) & 0xFF; /* divider */ cmd[16] = (divisor >> 8) & 0xFF; /* - msB */ @@ -665,12 +635,6 @@ static int swave(int fd, struct uart_t *u, struct termios *ti) char cmd[10], rsp[100]; int r; - /* Switch to default Silicon Wave baudrate*/ - if (set_speed(fd, ti, 115200) < 0) { - perror("Can't set default baud rate"); - return -1; - } - // Silicon Wave set baud rate command // see HCI Vendor Specific Interface from Silicon Wave // first send a "param access set" command to set the @@ -766,33 +730,33 @@ static int swave(int fd, struct uart_t *u, struct termios *ti) } struct uart_t uart[] = { - { "any", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, NULL }, - { "ericsson", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, ericsson }, - { "digi", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, digi }, - { "texas", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, texas}, + { "any", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, + { "ericsson", 0x0000, 0x0000, HCI_UART_H4, 57600, 115200, FLOW_CTL, ericsson }, + { "digi", 0x0000, 0x0000, HCI_UART_H4, 9600, 115200, FLOW_CTL, digi }, + { "texas", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, texas}, - { "bcsp", 0x0000, 0x0000, HCI_UART_BCSP, 115200, 0, bcsp }, + { "bcsp", 0x0000, 0x0000, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, /* Xircom PCMCIA cards: Credit Card Adapter and Real Port Adapter */ - { "xircom", 0x0105, 0x080a, HCI_UART_H4, 115200, FLOW_CTL, NULL }, + { "xircom", 0x0105, 0x080a, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, /* CSR Casira serial adapter or BrainBoxes serial dongle (BL642) */ - { "csr", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, csr }, + { "csr", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, csr }, /* BrainBoxes PCMCIA card (BL620) */ - { "bboxes", 0x0160, 0x0002, HCI_UART_H4, 460800, FLOW_CTL, csr }, + { "bboxes", 0x0160, 0x0002, HCI_UART_H4, 115200, 460800, FLOW_CTL, csr }, /* Silicon Wave kits */ - { "swave", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, swave }, + { "swave", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, swave }, /* Sphinx Electronics PICO Card */ - { "picocard", 0x025e, 0x1000, HCI_UART_H4, 115200, FLOW_CTL, NULL }, + { "picocard", 0x025e, 0x1000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, /* Inventel BlueBird Module */ - { "inventel", 0x0000, 0x0000, HCI_UART_H4, 115200, FLOW_CTL, NULL }, + { "inventel", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, /* COM One Platinium Bluetooth PC Card */ - { "comone", 0xffff, 0x0101, HCI_UART_BCSP, 115200, 0, bcsp }, + { "comone", 0xffff, 0x0101, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, { NULL, 0 } }; @@ -818,7 +782,7 @@ struct uart_t * get_by_type(char *type) } /* Initialize UART driver */ -int init_uart(char *dev, struct uart_t *u) +int init_uart(char *dev, struct uart_t *u, int send_break) { struct termios ti; int fd, i; @@ -849,8 +813,17 @@ int init_uart(char *dev, struct uart_t *u) return -1; } + /* Set initial baudrate */ + if (set_speed(fd, &ti, u->start_speed) < 0) { + perror("Can't set initial baud rate"); + return -1; + } + tcflush(fd, TCIOFLUSH); + if (send_break) + tcsendbreak(fd, 0); + if (u->init && u->init(fd, u, &ti) < 0) return -1; @@ -881,7 +854,7 @@ static void usage(void) { printf("hciattach - HCI UART driver initialization utility\n"); printf("Usage:\n"); - printf("\thciattach [-n] [-p] [-t timeout] [speed] [flow]\n"); + printf("\thciattach [-n] [-p] [-b] [-t timeout] [-s initial_speed] [speed] [flow]\n"); printf("\thciattach -l\n"); } @@ -893,6 +866,8 @@ int main(int argc, char *argv[]) struct uart_t *u = NULL; int detach, printpid, opt, i, n; int to = 5; + int start_speed = 0; + int send_break = 0; pid_t pid; struct sigaction sa; char dev[20]; @@ -900,8 +875,12 @@ int main(int argc, char *argv[]) detach = 1; printpid = 0; - while ((opt=getopt(argc, argv, "npt:l")) != EOF) { + while ((opt=getopt(argc, argv, "bnpt:s:l")) != EOF) { switch(opt) { + case 'b': + send_break = 1; + break; + case 'n': detach = 0; break; @@ -914,6 +893,10 @@ int main(int argc, char *argv[]) to = atoi(optarg); break; + case 's': + start_speed = atoi(optarg); + break; + case 'l': for (i = 0; uart[i].type; i++) { printf("%-10s0x%04x,0x%04x\n", uart[i].type, @@ -980,6 +963,11 @@ int main(int argc, char *argv[]) exit(1); } + /* If user specified a starting speed, use that instead of + the hardware's default */ + if (start_speed) + u->start_speed = start_speed; + memset(&sa, 0, sizeof(sa)); sa.sa_flags = SA_NOCLDSTOP; sa.sa_handler = sig_alarm; @@ -988,7 +976,7 @@ int main(int argc, char *argv[]) /* 5 seconds should be enough for initialization */ alarm(to); - n = init_uart(dev, u); + n = init_uart(dev, u, send_break); if (n < 0) { perror("Can't initialize device"); exit(1); -- cgit From 1c341784341174627ca3d8a76a4a2ca3bde2713b Mon Sep 17 00:00:00 2001 From: Max Krasnyansky Date: Tue, 8 Apr 2003 00:12:02 +0000 Subject: start_speed -> init_speed --- tools/hciattach.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 7b8c20a0..54980ded 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -51,7 +51,7 @@ struct uart_t { int m_id; int p_id; int proto; - int start_speed; + int init_speed; int speed; int flags; int (*init) (int fd, struct uart_t *u, struct termios *ti); @@ -577,15 +577,15 @@ static int csr(int fd, struct uart_t *u, struct termios *ti) if (u->speed > 1500000) { fprintf(stderr, "Speed %d too high. Remaining at %d baud\n", - u->speed, u->start_speed); - u->speed = u->start_speed; + u->speed, u->init_speed); + u->speed = u->init_speed; } else if (u->speed != 57600 && uart_speed(u->speed) == B57600) { /* Unknown speed. Why oh why can't we just pass an int to the kernel? */ fprintf(stderr, "Speed %d unrecognised. Remaining at %d baud\n", - u->speed, u->start_speed); - u->speed = u->start_speed; + u->speed, u->init_speed); + u->speed = u->init_speed; } - if (u->speed == u->start_speed) + if (u->speed == u->init_speed) return 0; /* Now, create the command that will set the UART speed */ @@ -814,7 +814,7 @@ int init_uart(char *dev, struct uart_t *u, int send_break) } /* Set initial baudrate */ - if (set_speed(fd, &ti, u->start_speed) < 0) { + if (set_speed(fd, &ti, u->init_speed) < 0) { perror("Can't set initial baud rate"); return -1; } @@ -866,7 +866,7 @@ int main(int argc, char *argv[]) struct uart_t *u = NULL; int detach, printpid, opt, i, n; int to = 5; - int start_speed = 0; + int init_speed = 0; int send_break = 0; pid_t pid; struct sigaction sa; @@ -894,7 +894,7 @@ int main(int argc, char *argv[]) break; case 's': - start_speed = atoi(optarg); + init_speed = atoi(optarg); break; case 'l': @@ -963,10 +963,10 @@ int main(int argc, char *argv[]) exit(1); } - /* If user specified a starting speed, use that instead of + /* If user specified a initial speed, use that instead of the hardware's default */ - if (start_speed) - u->start_speed = start_speed; + if (init_speed) + u->init_speed = init_speed; memset(&sa, 0, sizeof(sa)); sa.sa_flags = SA_NOCLDSTOP; -- cgit From 0ce9154a53a990998d0030a78e544ef8e8285352 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 29 May 2003 16:41:48 +0000 Subject: Support for TDK, IBM and Socket cards --- tools/hciattach.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 54980ded..05230d3c 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -758,7 +758,13 @@ struct uart_t uart[] = { /* COM One Platinium Bluetooth PC Card */ { "comone", 0xffff, 0x0101, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, - { NULL, 0 } + /* TDK Bluetooth PC Card and IBM Bluetooth PC Card II */ + { "tdk", 0x0105, 0x4254, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, + + /* Socket Bluetooth CF Card (Rev G) */ + { "socket", 0x0104, 0x0096, HCI_UART_BCSP, 230400, 230400, 0, bcsp }, + + { NULL, 0 } }; struct uart_t * get_by_id(int m_id, int p_id) -- cgit From 4e2dd78121a7c16836a1e28b6f545e4dd9c2d596 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 27 Aug 2003 09:55:43 +0000 Subject: Support for 3Com card version 3.0 --- tools/hciattach.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 05230d3c..5e33c97e 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -764,6 +764,9 @@ struct uart_t uart[] = { /* Socket Bluetooth CF Card (Rev G) */ { "socket", 0x0104, 0x0096, HCI_UART_BCSP, 230400, 230400, 0, bcsp }, + /* 3Com Bluetooth Card (Version 3.0) */ + { "3com", 0x0101, 0x0041, HCI_UART_H4, 115200, 115200, FLOW_CTL, csr }, + { NULL, 0 } }; -- cgit From d877c418537d529a9c693f23b59ca8b61e089e43 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 18 Nov 2003 08:16:21 +0000 Subject: Add ST Microelectronics specific initialization --- tools/hciattach.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 6 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 5e33c97e..799e338d 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -150,7 +150,7 @@ static int read_hci_event(int fd, unsigned char* buf, int size) static int ericsson(int fd, struct uart_t *u, struct termios *ti) { struct timespec tm = {0, 50000}; - char cmd[10]; + char cmd[5]; cmd[0] = HCI_COMMAND_PKT; cmd[1] = 0x09; @@ -194,7 +194,7 @@ static int ericsson(int fd, struct uart_t *u, struct termios *ti) static int digi(int fd, struct uart_t *u, struct termios *ti) { struct timespec tm = {0, 50000}; - char cmd[10]; + char cmd[5]; /* DigiAnswer set baud rate command */ cmd[0] = HCI_COMMAND_PKT; @@ -227,7 +227,7 @@ static int digi(int fd, struct uart_t *u, struct termios *ti) static int texas(int fd, struct uart_t *u, struct termios *ti) { struct timespec tm = {0, 50000}; - char cmd[10]; + char cmd[4]; unsigned char resp[100]; /* Response */ int n; @@ -241,7 +241,7 @@ static int texas(int fd, struct uart_t *u, struct termios *ti) cmd[0] = HCI_COMMAND_PKT; cmd[1] = 0x01; cmd[2] = 0x10; - cmd[3] = 0x00; + cmd[3] = 0x00; do { n = write(fd, cmd, 4); @@ -632,7 +632,7 @@ static int csr(int fd, struct uart_t *u, struct termios *ti) static int swave(int fd, struct uart_t *u, struct termios *ti) { struct timespec tm = {0, 500000}; - char cmd[10], rsp[100]; + char cmd[9], rsp[100]; int r; // Silicon Wave set baud rate command @@ -671,7 +671,7 @@ static int swave(int fd, struct uart_t *u, struct termios *ti) } /* Send initialization command */ - if (write(fd, cmd, 10) != 5) { + if (write(fd, cmd, 9) != 9) { perror("Failed to write init command"); return -1; } @@ -729,6 +729,61 @@ static int swave(int fd, struct uart_t *u, struct termios *ti) return 0; } +/* + * ST Microelectronics specific initialization + * Marcel Holtmann + */ +static int st(int fd, struct uart_t *u, struct termios *ti) +{ + struct timespec tm = {0, 50000}; + char cmd[5]; + + /* ST Microelectronics set baud rate command */ + cmd[0] = HCI_COMMAND_PKT; + cmd[1] = 0x46; // OCF = Hci_Cmd_ST_Set_Uart_Baud_Rate + cmd[2] = 0xfc; // OGF = Vendor specific + cmd[3] = 0x01; + + switch (u->speed) { + case 9600: + cmd[4] = 0x09; + break; + case 19200: + cmd[4] = 0x0b; + break; + case 38400: + cmd[4] = 0x0d; + break; + case 57600: + cmd[4] = 0x0e; + break; + case 115200: + cmd[4] = 0x10; + break; + case 230400: + cmd[4] = 0x12; + break; + case 460800: + cmd[4] = 0x13; + break; + case 921600: + cmd[4] = 0x14; + break; + default: + cmd[4] = 0x10; + u->speed = 57600; + break; + } + + /* Send initialization command */ + if (write(fd, cmd, 5) != 5) { + perror("Failed to write init command"); + return -1; + } + nanosleep(&tm, NULL); + return 0; +} + struct uart_t uart[] = { { "any", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, { "ericsson", 0x0000, 0x0000, HCI_UART_H4, 57600, 115200, FLOW_CTL, ericsson }, @@ -749,6 +804,9 @@ struct uart_t uart[] = { /* Silicon Wave kits */ { "swave", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, swave }, + /* ST Microelectronics minikits based on STLC2410/STLC2415 */ + { "st", 0x0000, 0x0000, HCI_UART_H4, 57600, 115200, FLOW_CTL, st }, + /* Sphinx Electronics PICO Card */ { "picocard", 0x025e, 0x1000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, -- cgit From 1d3715db11f573060cb02a2b7b7c44f06607d337 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 3 Apr 2004 06:04:35 +0000 Subject: Update BlueZ library configuration --- tools/hciattach.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 799e338d..926e3fab 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -24,6 +24,10 @@ * $Id$ */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include -- cgit From b66d3f9b2cb8934a0eb7ac07f347001984488ac6 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 28 Apr 2004 10:39:47 +0000 Subject: Unify copyright and license information --- tools/hciattach.c | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 926e3fab..7194ad6a 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -1,27 +1,31 @@ -/* - BlueZ - Bluetooth protocol stack for Linux - Copyright (C) 2000-2001 Qualcomm Incorporated - - Written 2000,2001 by Maxim Krasnyansky - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License version 2 as - published by the Free Software Foundation; - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. - IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM, - OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER - RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE - USE OR PERFORMANCE OF THIS SOFTWARE. - - ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS, - TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED. -*/ /* - * $Id$ + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2000-2001 Qualcomm Incorporated + * Copyright (C) 2002-2003 Maxim Krasnyansky + * Copyright (C) 2002-2004 Marcel Holtmann + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY + * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, + * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS + * SOFTWARE IS DISCLAIMED. + * + * + * $Id$ */ #ifdef HAVE_CONFIG_H @@ -47,8 +51,8 @@ #include #include -#include #include +#include struct uart_t { char *type; -- cgit From 596ce96eefb0a1f7feda4ecd29a49d8bc6792cf3 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 3 May 2004 13:25:14 +0000 Subject: Fix default baudrate for ST devices --- tools/hciattach.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 7194ad6a..3e8be20a 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -779,7 +779,7 @@ static int st(int fd, struct uart_t *u, struct termios *ti) break; default: cmd[4] = 0x10; - u->speed = 57600; + u->speed = 115200; break; } -- cgit From 0a61c1514914951ff94e1228e8031737cc423e41 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 12 May 2004 13:47:19 +0000 Subject: Use 10 characters array in swave() routine --- tools/hciattach.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 3e8be20a..50432ec3 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -640,7 +640,7 @@ static int csr(int fd, struct uart_t *u, struct termios *ti) static int swave(int fd, struct uart_t *u, struct termios *ti) { struct timespec tm = {0, 500000}; - char cmd[9], rsp[100]; + char cmd[10], rsp[100]; int r; // Silicon Wave set baud rate command -- cgit From 587fe743849609dd150666d84f8fa53cd403a70e Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 23 Jun 2004 16:30:41 +0000 Subject: Add support for AmbiCom BT2000C card --- tools/hciattach.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 50432ec3..2024c1de 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -833,6 +833,9 @@ struct uart_t uart[] = { /* 3Com Bluetooth Card (Version 3.0) */ { "3com", 0x0101, 0x0041, HCI_UART_H4, 115200, 115200, FLOW_CTL, csr }, + /* AmbiCom BT2000C Bluetooth PC/CF Card */ + { "bt2000c", 0x022d, 0x2000, HCI_UART_H4, 57600, 460800, FLOW_CTL, csr }, + { NULL, 0 } }; -- cgit From 5c8acb2c0dabd7fe0c8397d97c140d78b7bd8cd7 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 16 Aug 2004 10:10:13 +0000 Subject: Don't include asm/types.h --- tools/hciattach.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 2024c1de..b3f40b3a 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -47,7 +47,7 @@ #include #include #include -#include +#include #include #include -- cgit From ca8d9c9f9ac9b20b33bde4c1407ce80f44b814ec Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 20 Sep 2004 15:51:15 +0000 Subject: Mention flow|noflow in help text and other speeds --- tools/hciattach.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index b3f40b3a..a22a0b1d 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -84,12 +84,18 @@ static int uart_speed(int s) return B230400; case 460800: return B460800; + case 500000: + return B500000; + case 576000: + return B576000; case 921600: return B921600; case 1000000: return B1000000; case 1152000: return B1152000; + case 1500000: + return B1500000; default: return B57600; } @@ -932,7 +938,7 @@ 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] [speed] [flow]\n"); + printf("\thciattach [-n] [-p] [-b] [-t timeout] [-s initial_speed] [speed] [flow|noflow]\n"); printf("\thciattach -l\n"); } -- cgit From 70bc373b28975204b08974d45213e5772a07a41e Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 11 Oct 2004 09:52:09 +0000 Subject: Add support for the Zoom PCMCIA card --- tools/hciattach.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index a22a0b1d..d59992e1 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -842,6 +842,9 @@ struct uart_t uart[] = { /* AmbiCom BT2000C Bluetooth PC/CF Card */ { "bt2000c", 0x022d, 0x2000, HCI_UART_H4, 57600, 460800, FLOW_CTL, csr }, + /* Zoom Bluetooth PCMCIA Card */ + { "zoom", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, + { NULL, 0 } }; -- cgit From 3aa6a3e9a775e1d143d3640fe7f3ced170bb71b9 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 11 Oct 2004 13:59:57 +0000 Subject: Sleep some time after sending break --- tools/hciattach.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index d59992e1..ac94c41e 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -908,8 +908,10 @@ int init_uart(char *dev, struct uart_t *u, int send_break) tcflush(fd, TCIOFLUSH); - if (send_break) + if (send_break) { tcsendbreak(fd, 0); + usleep(500000); + } if (u->init && u->init(fd, u, &ti) < 0) return -1; -- cgit From f0e34fdbb90a899cca2ae6b1d75549d2050f9855 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 11 Jan 2005 18:46:46 +0000 Subject: Add Sitecom CN-504 Bluetooth PCMCIA card --- tools/hciattach.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index ac94c41e..e730ab7d 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -4,7 +4,7 @@ * * Copyright (C) 2000-2001 Qualcomm Incorporated * Copyright (C) 2002-2003 Maxim Krasnyansky - * Copyright (C) 2002-2004 Marcel Holtmann + * Copyright (C) 2002-2005 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify @@ -33,21 +33,18 @@ #endif #include -#include +#include +#include #include +#include #include #include -#include #include -#include -#include #include -#include - +#include +#include #include #include -#include -#include #include #include @@ -845,6 +842,8 @@ struct uart_t uart[] = { /* Zoom Bluetooth PCMCIA Card */ { "zoom", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, + /* Sitecom CN-504 PCMCIA Card */ + { "sitecom", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, { NULL, 0 } }; -- cgit From 591e892366b6ccf2d7c765c47741794cb8a30e42 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 30 Jan 2005 20:38:04 +0000 Subject: Add Billionton PCMCIA card --- tools/hciattach.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index e730ab7d..33ecdf03 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -796,54 +796,58 @@ static int st(int fd, struct uart_t *u, struct termios *ti) } struct uart_t uart[] = { - { "any", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, - { "ericsson", 0x0000, 0x0000, HCI_UART_H4, 57600, 115200, FLOW_CTL, ericsson }, - { "digi", 0x0000, 0x0000, HCI_UART_H4, 9600, 115200, FLOW_CTL, digi }, - { "texas", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, texas}, + { "any", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, + { "ericsson", 0x0000, 0x0000, HCI_UART_H4, 57600, 115200, FLOW_CTL, ericsson }, + { "digi", 0x0000, 0x0000, HCI_UART_H4, 9600, 115200, FLOW_CTL, digi }, + { "texas", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, texas }, - { "bcsp", 0x0000, 0x0000, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, + { "bcsp", 0x0000, 0x0000, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, /* Xircom PCMCIA cards: Credit Card Adapter and Real Port Adapter */ - { "xircom", 0x0105, 0x080a, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, + { "xircom", 0x0105, 0x080a, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, /* CSR Casira serial adapter or BrainBoxes serial dongle (BL642) */ - { "csr", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, csr }, + { "csr", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, csr }, /* BrainBoxes PCMCIA card (BL620) */ - { "bboxes", 0x0160, 0x0002, HCI_UART_H4, 115200, 460800, FLOW_CTL, csr }, + { "bboxes", 0x0160, 0x0002, HCI_UART_H4, 115200, 460800, FLOW_CTL, csr }, /* Silicon Wave kits */ - { "swave", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, swave }, + { "swave", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, swave }, /* ST Microelectronics minikits based on STLC2410/STLC2415 */ - { "st", 0x0000, 0x0000, HCI_UART_H4, 57600, 115200, FLOW_CTL, st }, + { "st", 0x0000, 0x0000, HCI_UART_H4, 57600, 115200, FLOW_CTL, st }, /* Sphinx Electronics PICO Card */ - { "picocard", 0x025e, 0x1000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, + { "picocard", 0x025e, 0x1000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, /* Inventel BlueBird Module */ - { "inventel", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, + { "inventel", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, /* COM One Platinium Bluetooth PC Card */ - { "comone", 0xffff, 0x0101, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, + { "comone", 0xffff, 0x0101, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, /* TDK Bluetooth PC Card and IBM Bluetooth PC Card II */ - { "tdk", 0x0105, 0x4254, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, + { "tdk", 0x0105, 0x4254, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, /* Socket Bluetooth CF Card (Rev G) */ - { "socket", 0x0104, 0x0096, HCI_UART_BCSP, 230400, 230400, 0, bcsp }, + { "socket", 0x0104, 0x0096, HCI_UART_BCSP, 230400, 230400, 0, bcsp }, /* 3Com Bluetooth Card (Version 3.0) */ - { "3com", 0x0101, 0x0041, HCI_UART_H4, 115200, 115200, FLOW_CTL, csr }, + { "3com", 0x0101, 0x0041, HCI_UART_H4, 115200, 115200, FLOW_CTL, csr }, /* AmbiCom BT2000C Bluetooth PC/CF Card */ - { "bt2000c", 0x022d, 0x2000, HCI_UART_H4, 57600, 460800, FLOW_CTL, csr }, + { "bt2000c", 0x022d, 0x2000, HCI_UART_H4, 57600, 460800, FLOW_CTL, csr }, /* Zoom Bluetooth PCMCIA Card */ - { "zoom", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, + { "zoom", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, /* Sitecom CN-504 PCMCIA Card */ - { "sitecom", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, + { "sitecom", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, + + /* Billionton PCBTC1 PCMCIA Card */ + { "billionton", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, + { NULL, 0 } }; -- cgit From 4cf1f07d58e85915f12099d9eb5560e7acbf4deb Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 21 Jun 2005 16:49:26 +0000 Subject: Don't use hci_uart.h anymore --- tools/hciattach.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 33ecdf03..b7f6dab6 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -49,7 +49,18 @@ #include #include #include -#include + +#ifndef N_HCI +#define N_HCI 15 +#endif + +#define HCIUARTSETPROTO _IOW('U', 200, int) +#define HCIUARTGETPROTO _IOR('U', 201, int) + +#define HCI_UART_H4 0 +#define HCI_UART_BCSP 1 +#define HCI_UART_3WIRE 2 +#define HCI_UART_H4DS 3 struct uart_t { char *type; -- cgit From 632a9432774ff3a0c6e556e8f32a565b38890767 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 29 Oct 2005 22:36:31 +0000 Subject: Big cleanup of CVS relics --- tools/hciattach.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index b7f6dab6..8091d655 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -8,24 +8,19 @@ * * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. - * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY - * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, - * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS - * SOFTWARE IS DISCLAIMED. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * - * $Id$ */ #ifdef HAVE_CONFIG_H @@ -649,7 +644,7 @@ static int csr(int fd, struct uart_t *u, struct termios *ti) /* * Silicon Wave specific initialization - * Thomas Moser + * Thomas Moser */ static int swave(int fd, struct uart_t *u, struct termios *ti) { -- cgit From 2a6755856c498491474e64aa506b81031a1269f7 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 2 Dec 2005 15:01:51 +0000 Subject: Fix array length for device name --- tools/hciattach.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 8091d655..bcdad95b 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -968,7 +968,7 @@ int main(int argc, char *argv[]) int send_break = 0; pid_t pid; struct sigaction sa; - char dev[20]; + char dev[PATH_MAX]; detach = 1; printpid = 0; -- cgit From 27454e3869df7f30ba170fefc17018fa07b5d194 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 7 Dec 2005 09:04:58 +0000 Subject: Update the Silicon Wave init routine --- tools/hciattach.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index bcdad95b..d0e03cce 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -648,7 +648,7 @@ static int csr(int fd, struct uart_t *u, struct termios *ti) */ static int swave(int fd, struct uart_t *u, struct termios *ti) { - struct timespec tm = {0, 500000}; + struct timespec tm = { 0, 500000 }; char cmd[10], rsp[100]; int r; @@ -688,7 +688,7 @@ static int swave(int fd, struct uart_t *u, struct termios *ti) } /* Send initialization command */ - if (write(fd, cmd, 9) != 9) { + if (write(fd, cmd, 10) != 10) { perror("Failed to write init command"); return -1; } @@ -720,15 +720,16 @@ static int swave(int fd, struct uart_t *u, struct termios *ti) return -1; } - // we probably got the reply. Now we must send the "soft reset": + // we probably got the reply. Now we must send the "soft reset" + // which is standard HCI RESET. + cmd[0] = HCI_COMMAND_PKT; // it's a command packet - cmd[1] = 0x0B; // OCF 0x0B = param access set - cmd[2] = 0xfc; // OGF bx111111 = vendor specific - cmd[3] = 0x01; // 1 byte of data following - cmd[4] = 0x03; // HCI Reset Subcommand - - // Send initialization command - if (write(fd, cmd, 5) != 5) { + cmd[1] = 0x03; + cmd[2] = 0x0c; + cmd[3] = 0x00; + + /* Send reset command */ + if (write(fd, cmd, 4) != 4) { perror("Can't write Silicon Wave reset cmd."); return -1; } -- cgit From f2e48c44a7e4c9ee31b8ce2e302186f6047cfeab Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 3 Jan 2006 13:28:56 +0000 Subject: Update copyright information --- tools/hciattach.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index d0e03cce..6a806039 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -4,7 +4,7 @@ * * Copyright (C) 2000-2001 Qualcomm Incorporated * Copyright (C) 2002-2003 Maxim Krasnyansky - * Copyright (C) 2002-2005 Marcel Holtmann + * Copyright (C) 2002-2006 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify -- cgit From 5094a9971637f88dd38383faa7be81dafd997adb Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 21 Jan 2006 01:45:01 +0000 Subject: Add support for Broadcom BCM2035 chips --- tools/hciattach.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 6a806039..e583e8db 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -802,6 +802,117 @@ static int st(int fd, struct uart_t *u, struct termios *ti) return 0; } + +/* + * Broadcom specific initialization + * Extracted from Jungo openrg + */ +static int bcm2035(int fd, struct uart_t *u, struct termios *ti) +{ + int n; + unsigned char cmd[30], resp[30]; + + /* Reset the BT Chip */ + memset(cmd, 0, sizeof(cmd)); + memset(resp, 0, sizeof(resp)); + cmd[0] = HCI_COMMAND_PKT; + cmd[1] = 0x03; + cmd[2] = 0x0c; + cmd[3] = 0x00; + /* Send command */ + if (write(fd, cmd, 4) != 4) { + fprintf(stderr, "Failed to write reset command\n"); + return -1; + } + /* Read reply */ + if ((n = read_hci_event(fd, resp, 4)) < 0) { + fprintf(stderr, "Failed to reset chip\n"); + return -1; + } + + /* Read the local version info */ + memset(cmd, 0, sizeof(cmd)); + memset(resp, 0, sizeof(resp)); + cmd[0] = HCI_COMMAND_PKT; + cmd[1] = 0x01; + cmd[2] = 0x10; + cmd[3] = 0x00; + /* Send command */ + if (write(fd, cmd, 4) != 4) { + fprintf(stderr, "Failed to write \"read local version\" " + "command\n"); + return -1; + } + /* Read reply */ + if ((n = read_hci_event(fd, resp, 4)) < 0) { + fprintf(stderr, "Failed to read local version\n"); + return -1; + } + + /* Read the local supported commands info */ + memset(cmd, 0, sizeof(cmd)); + memset(resp, 0, sizeof(resp)); + cmd[0] = HCI_COMMAND_PKT; + cmd[1] = 0x02; + cmd[2] = 0x10; + cmd[3] = 0x00; + /* Send command */ + if (write(fd, cmd, 4) != 4) { + fprintf(stderr, "Failed to write \"read local supported " + "commands\" command\n"); + return -1; + } + /* Read reply */ + if ((n = read_hci_event(fd, resp, 4)) < 0) { + fprintf(stderr, "Failed to read local supported commands\n"); + return -1; + } + + /* Set the baud rate */ + memset(cmd, 0, sizeof(cmd)); + memset(resp, 0, sizeof(resp)); + cmd[0] = HCI_COMMAND_PKT; + cmd[1] = 0x18; + cmd[2] = 0xfc; + cmd[3] = 0x02; + switch (u->speed) { + case 57600: + cmd[4] = 0x00; + cmd[5] = 0xe6; + break; + case 230400: + cmd[4] = 0x22; + cmd[5] = 0xfa; + break; + case 460800: + cmd[4] = 0x11; + cmd[5] = 0xfd; + break; + case 921600: + cmd[4] = 0x65; + cmd[5] = 0xff; + break; + default: + /* Default is 115200 */ + cmd[4] = 0x00; + cmd[5] = 0xf3; + break; + } + fprintf(stderr, "Baud rate parameters: DHBR=0x%2x,DLBR=0x%2x\n", + cmd[4], cmd[5]); + + /* Send command */ + if (write(fd, cmd, 6) != 6) { + fprintf(stderr, "Failed to write \"set baud rate\" command\n"); + return -1; + } + if ((n = read_hci_event(fd, resp, 6)) < 0) { + fprintf(stderr, "Failed to set baud rate\n"); + return -1; + } + return 0; +} + struct uart_t uart[] = { { "any", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, { "ericsson", 0x0000, 0x0000, HCI_UART_H4, 57600, 115200, FLOW_CTL, ericsson }, @@ -855,6 +966,9 @@ struct uart_t uart[] = { /* Billionton PCBTC1 PCMCIA Card */ { "billionton", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, + /* Broadcom BCM2035 */ + { "bcm2035", 0x0A5C, 0x2035, HCI_UART_H4, 115200, 115200, 0, bcm2035 }, + { NULL, 0 } }; -- cgit From fc4ca3634da071b9a75961be179cccbe88101b75 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 20 Mar 2006 22:29:03 +0000 Subject: Detect TTY detach and restore line discipline --- tools/hciattach.c | 124 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 89 insertions(+), 35 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index e583e8db..cfccb9ab 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -70,6 +71,23 @@ struct uart_t { #define FLOW_CTL 0x0001 +static volatile sig_atomic_t __io_canceled = 0; + +static void sig_hup(int sig) +{ +} + +static void sig_term(int sig) +{ + __io_canceled = 1; +} + +static void sig_alarm(int sig) +{ + fprintf(stderr, "Initialization timed out.\n"); + exit(1); +} + static int uart_speed(int s) { switch (s) { @@ -110,12 +128,6 @@ static int set_speed(int fd, struct termios *ti, int speed) return tcsetattr(fd, TCSANOW, ti); } -static void sig_alarm(int sig) -{ - fprintf(stderr, "Initialization timed out.\n"); - exit(1); -} - /* * Read an HCI event from the given file descriptor. */ @@ -158,6 +170,7 @@ static int read_hci_event(int fd, unsigned char* buf, int size) return -1; count += r; } + return count; } @@ -201,6 +214,7 @@ static int ericsson(int fd, struct uart_t *u, struct termios *ti) perror("Failed to write init command"); return -1; } + nanosleep(&tm, NULL); return 0; } @@ -237,6 +251,7 @@ static int digi(int fd, struct uart_t *u, struct termios *ti) perror("Failed to write init command"); return -1; } + nanosleep(&tm, NULL); return 0; } @@ -289,7 +304,7 @@ static int texas(int fd, struct uart_t *u, struct termios *ti) /* Print LMP subversion */ fprintf(stderr, "Texas module LMP sub-version : 0x%02x%02x\n", resp[14] & 0xFF, resp[13] & 0xFF); - + nanosleep(&tm, NULL); return 0; } @@ -297,7 +312,7 @@ static int texas(int fd, struct uart_t *u, struct termios *ti) static int read_check(int fd, void *buf, int count) { int res; - + do { res = read(fd, buf, count); if (res != -1) { @@ -305,10 +320,10 @@ static int read_check(int fd, void *buf, int count) count -= res; } } while (count && (errno == 0 || errno == EINTR)); - + if (count) return -1; - + return 0; } @@ -321,13 +336,14 @@ static void bcsp_tshy_sig_alarm(int sig) { static int retries=0; unsigned char bcsp_sync_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xda,0xdc,0xed,0xed,0xc0}; - + if (retries < 10) { retries++; write(serial_fd, &bcsp_sync_pkt, 10); alarm(1); return; } + tcflush(serial_fd, TCIOFLUSH); fprintf(stderr, "BCSP initialization timed out\n"); exit(1); @@ -337,12 +353,14 @@ static void bcsp_tconf_sig_alarm(int sig) { static int retries=0; unsigned char bcsp_conf_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xad,0xef,0xac,0xed,0xc0}; + if (retries < 10){ retries++; write(serial_fd, &bcsp_conf_pkt, 10); alarm(1); return; } + tcflush(serial_fd, TCIOFLUSH); fprintf(stderr, "BCSP initialization timed out\n"); exit(1); @@ -390,20 +408,19 @@ static int bcsp(int fd, struct uart_t *u, struct termios *ti) return -1; } } while (byte != 0xC0); - + do { if ( read_check(fd, &bcsph[0], 1) == -1){ perror("Failed to read"); return -1; } - } while (bcsph[0] == 0xC0); - + if ( read_check(fd, &bcsph[1], 3) == -1){ perror("Failed to read"); return -1; } - + if (((bcsph[0] + bcsph[1] + bcsph[2]) & 0xFF) != (unsigned char)~bcsph[3]) continue; if (bcsph[1] != 0x41 || bcsph[2] != 0x00) @@ -437,8 +454,8 @@ static int bcsp(int fd, struct uart_t *u, struct termios *ti) do { if (read_check(fd, &bcsph[0], 1) == -1){ - perror("Failed to read"); - return -1; + perror("Failed to read"); + return -1; } } while (bcsph[0] == 0xC0); @@ -446,7 +463,7 @@ static int bcsp(int fd, struct uart_t *u, struct termios *ti) perror("Failed to read"); return -1; } - + if (((bcsph[0] + bcsph[1] + bcsph[2]) & 0xFF) != (unsigned char)~bcsph[3]) continue; @@ -553,7 +570,7 @@ static int csr(int fd, struct uart_t *u, struct termios *ti) /* Display that to user */ fprintf(stderr, "CSR build ID 0x%02X-0x%02X\n", resp[15] & 0xFF, resp[14] & 0xFF); - + /* Try to read the current speed of the CSR chip */ clen = 5 + (5 + 4)*2; /* -- HCI header */ @@ -638,6 +655,7 @@ static int csr(int fd, struct uart_t *u, struct termios *ti) perror("Failed to write init command (SET_UART_SPEED)"); return -1; } + nanosleep(&tm, NULL); return 0; } @@ -715,7 +733,7 @@ static int swave(int fd, struct uart_t *u, struct termios *ti) // 01 flow on // 01 Hci Transport type = Uart // xx Baud rate set (see above) - } else { + } else { // ups, got error. return -1; } @@ -735,7 +753,7 @@ static int swave(int fd, struct uart_t *u, struct termios *ti) } nanosleep(&tm, NULL); - + // now the uart baud rate on the silicon wave module is set and effective. // change our own baud rate as well. Then there is a reset event comming in // on the *new* baud rate. This is *undocumented*! The packet looks like this: @@ -798,11 +816,11 @@ static int st(int fd, struct uart_t *u, struct termios *ti) perror("Failed to write init command"); return -1; } + nanosleep(&tm, NULL); return 0; } - /* * Broadcom specific initialization * Extracted from Jungo openrg @@ -819,11 +837,13 @@ static int bcm2035(int fd, struct uart_t *u, struct termios *ti) cmd[1] = 0x03; cmd[2] = 0x0c; cmd[3] = 0x00; + /* Send command */ if (write(fd, cmd, 4) != 4) { fprintf(stderr, "Failed to write reset command\n"); return -1; } + /* Read reply */ if ((n = read_hci_event(fd, resp, 4)) < 0) { fprintf(stderr, "Failed to reset chip\n"); @@ -837,12 +857,14 @@ static int bcm2035(int fd, struct uart_t *u, struct termios *ti) cmd[1] = 0x01; cmd[2] = 0x10; cmd[3] = 0x00; + /* Send command */ if (write(fd, cmd, 4) != 4) { fprintf(stderr, "Failed to write \"read local version\" " "command\n"); return -1; } + /* Read reply */ if ((n = read_hci_event(fd, resp, 4)) < 0) { fprintf(stderr, "Failed to read local version\n"); @@ -856,12 +878,14 @@ static int bcm2035(int fd, struct uart_t *u, struct termios *ti) cmd[1] = 0x02; cmd[2] = 0x10; cmd[3] = 0x00; + /* Send command */ if (write(fd, cmd, 4) != 4) { fprintf(stderr, "Failed to write \"read local supported " "commands\" command\n"); return -1; } + /* Read reply */ if ((n = read_hci_event(fd, resp, 4)) < 0) { fprintf(stderr, "Failed to read local supported commands\n"); @@ -906,10 +930,12 @@ static int bcm2035(int fd, struct uart_t *u, struct termios *ti) fprintf(stderr, "Failed to write \"set baud rate\" command\n"); return -1; } + if ((n = read_hci_event(fd, resp, 6)) < 0) { fprintf(stderr, "Failed to set baud rate\n"); return -1; } + return 0; } @@ -996,7 +1022,7 @@ struct uart_t * get_by_type(char *type) int init_uart(char *dev, struct uart_t *u, int send_break) { struct termios ti; - int fd, i; + int fd, i; fd = open(dev, O_RDWR | O_NOCTTY); if (fd < 0) { @@ -1071,23 +1097,21 @@ static void usage(void) printf("\thciattach -l\n"); } -extern int optind, opterr, optopt; -extern char *optarg; - int main(int argc, char *argv[]) { struct uart_t *u = NULL; - int detach, printpid, opt, i, n; + int detach, printpid, opt, i, n, ld; int to = 5; int init_speed = 0; int send_break = 0; pid_t pid; struct sigaction sa; + struct pollfd p; char dev[PATH_MAX]; detach = 1; printpid = 0; - + while ((opt=getopt(argc, argv, "bnpt:s:l")) != EOF) { switch(opt) { case 'b': @@ -1131,9 +1155,9 @@ int main(int argc, char *argv[]) for (n = 0; optind < argc; n++, optind++) { char *opt; - + opt = argv[optind]; - + switch(n) { case 0: dev[0] = 0; @@ -1182,13 +1206,13 @@ int main(int argc, char *argv[]) u->init_speed = init_speed; memset(&sa, 0, sizeof(sa)); - sa.sa_flags = SA_NOCLDSTOP; + sa.sa_flags = SA_NOCLDSTOP; sa.sa_handler = sig_alarm; sigaction(SIGALRM, &sa, NULL); /* 5 seconds should be enough for initialization */ alarm(to); - + n = init_uart(dev, u, send_break); if (n < 0) { perror("Can't initialize device"); @@ -1197,16 +1221,46 @@ int main(int argc, char *argv[]) alarm(0); + memset(&sa, 0, sizeof(sa)); + sa.sa_flags = SA_NOCLDSTOP; + sa.sa_handler = SIG_IGN; + sigaction(SIGCHLD, &sa, NULL); + sigaction(SIGPIPE, &sa, NULL); + + sa.sa_handler = sig_term; + sigaction(SIGTERM, &sa, NULL); + sigaction(SIGINT, &sa, NULL); + + sa.sa_handler = sig_hup; + sigaction(SIGHUP, &sa, NULL); + if (detach) { if ((pid = fork())) { if (printpid) printf("%d\n", pid); return 0; } - for (i=0; i<20; i++) - if (i != n) close(i); + + for (i = 0; i < 20; i++) + if (i != n) + close(i); + } + + p.fd = n; + p.events = POLLERR | POLLHUP; + + while (!__io_canceled) { + p.revents = 0; + if (poll(&p, 1, 100)) + break; + } + + /* Restore TTY line discipline */ + ld = N_TTY; + if (ioctl(n, TIOCSETD, &ld) < 0) { + perror("Can't restore line discipline"); + exit(1); } - while (1) sleep(999999999); return 0; } -- cgit From ae2bada6379b2d56825f0d8cc48dbd9a1890a1bd Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 16 Apr 2006 21:09:01 +0000 Subject: Update STLC2500 init routine --- tools/hciattach.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index cfccb9ab..885f202d 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -821,6 +821,13 @@ static int st(int fd, struct uart_t *u, struct termios *ti) return 0; } +extern stlc2500_init(int fd); + +static int stlc2500(int fd, struct uart_t *u, struct termios *ti) +{ + return stlc2500_init(fd); +} + /* * Broadcom specific initialization * Extracted from Jungo openrg @@ -962,6 +969,9 @@ struct uart_t uart[] = { /* ST Microelectronics minikits based on STLC2410/STLC2415 */ { "st", 0x0000, 0x0000, HCI_UART_H4, 57600, 115200, FLOW_CTL, st }, + /* ST Microelectronics minikits based on STLC2500 */ + { "stlc2500", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, stlc2500 }, + /* Sphinx Electronics PICO Card */ { "picocard", 0x025e, 0x1000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, -- cgit From 910d9fe22770d744f88eb42762ec678e4e0a16de Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 29 Apr 2006 18:21:14 +0000 Subject: Fix a small typo --- tools/hciattach.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 885f202d..08b28f45 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -821,7 +821,7 @@ static int st(int fd, struct uart_t *u, struct termios *ti) return 0; } -extern stlc2500_init(int fd); +extern int stlc2500_init(int fd); static int stlc2500(int fd, struct uart_t *u, struct termios *ti) { -- cgit From 943b02e163e169795a010c36a3b3343cc5092a96 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 27 Jun 2006 07:33:36 +0000 Subject: Include sys/param.h for PATH_MAX when cross-compiling --- tools/hciattach.c | 1 + 1 file changed, 1 insertion(+) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 08b28f45..909a6465 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include -- cgit From 7449f2395ee3df35bb76c04ab211042e05af1c89 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 27 Jul 2006 02:08:02 +0000 Subject: Don't ignore return value of write() --- tools/hciattach.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 909a6465..ca7f91c7 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -337,10 +337,11 @@ static void bcsp_tshy_sig_alarm(int sig) { static int retries=0; unsigned char bcsp_sync_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xda,0xdc,0xed,0xed,0xc0}; + int len; if (retries < 10) { retries++; - write(serial_fd, &bcsp_sync_pkt, 10); + len = write(serial_fd, &bcsp_sync_pkt, 10); alarm(1); return; } @@ -354,10 +355,11 @@ static void bcsp_tconf_sig_alarm(int sig) { static int retries=0; unsigned char bcsp_conf_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xad,0xef,0xac,0xed,0xc0}; + int len; if (retries < 10){ retries++; - write(serial_fd, &bcsp_conf_pkt, 10); + len = write(serial_fd, &bcsp_conf_pkt, 10); alarm(1); return; } @@ -377,6 +379,7 @@ static int bcsp(int fd, struct uart_t *u, struct termios *ti) bcspconf[4] = {0xad,0xef,0xac,0xed}, bcspconfresp[4] = {0xde,0xad,0xd0,0xd0}; struct sigaction sa; + int len; if (set_speed(fd, ti, u->speed) < 0) { perror("Can't set default baud rate"); @@ -433,7 +436,7 @@ static int bcsp(int fd, struct uart_t *u, struct termios *ti) } if (!memcmp(bcspp, bcspsync, 4)) { - write(fd, &bcsp_sync_resp_pkt,10); + len = write(fd, &bcsp_sync_resp_pkt,10); } else if (!memcmp(bcspp, bcspsyncresp, 4)) break; } @@ -477,9 +480,9 @@ static int bcsp(int fd, struct uart_t *u, struct termios *ti) } if (!memcmp(bcspp, bcspsync, 4)) - write(fd, &bcsp_sync_resp_pkt, 10); + len = write(fd, &bcsp_sync_resp_pkt, 10); else if (!memcmp(bcspp, bcspconf, 4)) - write(fd, &bcsp_conf_resp_pkt, 10); + len = write(fd, &bcsp_conf_resp_pkt, 10); else if (!memcmp(bcspp, bcspconfresp, 4)) break; } -- cgit From 35e9349ffc53950c4b78fba9537a50cdb6e5fd7a Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 10 Aug 2006 10:20:59 +0000 Subject: Change default poll() timeout --- tools/hciattach.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index ca7f91c7..a38d2481 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -1265,7 +1265,7 @@ int main(int argc, char *argv[]) while (!__io_canceled) { p.revents = 0; - if (poll(&p, 1, 100)) + if (poll(&p, 1, 500)) break; } -- cgit From 607695ed109340f4b7a5628420e0a8e8aee34f4e Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 13 Jan 2007 17:48:12 +0000 Subject: Update copyright information --- tools/hciattach.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index a38d2481..ab8a0f25 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -4,7 +4,7 @@ * * Copyright (C) 2000-2001 Qualcomm Incorporated * Copyright (C) 2002-2003 Maxim Krasnyansky - * Copyright (C) 2002-2006 Marcel Holtmann + * Copyright (C) 2002-2007 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify -- cgit From c3da6a497333f7e21007a3f23312e74464a408bf Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 17 Jan 2007 12:31:42 +0000 Subject: Add support for Philips BGB2xx modules --- tools/hciattach.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index ab8a0f25..45ce4d7b 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -825,11 +825,26 @@ static int st(int fd, struct uart_t *u, struct termios *ti) return 0; } -extern int stlc2500_init(int fd); +extern int stlc2500_init(int fd, bdaddr_t *bdaddr); static int stlc2500(int fd, struct uart_t *u, struct termios *ti) { - return stlc2500_init(fd); + bdaddr_t bdaddr; + + str2ba("00:80:E1:00:AB:BA", &bdaddr); + + return stlc2500_init(fd, &bdaddr); +} + +extern int bgb2xx_init(int fd, bdaddr_t *bdaddr); + +static int bgb2xx(int fd, struct uart_t *u, struct termios *ti) +{ + bdaddr_t bdaddr; + + str2ba("BD:B2:10:00:AB:BA", &bdaddr); + + return bgb2xx_init(fd, &bdaddr); } /* @@ -976,6 +991,12 @@ struct uart_t uart[] = { /* ST Microelectronics minikits based on STLC2500 */ { "stlc2500", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, stlc2500 }, + /* Philips generic Ericsson IP core based */ + { "philips", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, + + /* Philips BGB2xx Module */ + { "bgb2xx", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, bgb2xx }, + /* Sphinx Electronics PICO Card */ { "picocard", 0x025e, 0x1000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, -- cgit From dcf9a09a033ce0e5420a7ef719e8e88e3eeaeb5c Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 17 Apr 2007 23:25:14 +0000 Subject: Handle EINTR errors --- tools/hciattach.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 45ce4d7b..a01c149f 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -1135,7 +1135,7 @@ static void usage(void) int main(int argc, char *argv[]) { struct uart_t *u = NULL; - int detach, printpid, opt, i, n, ld; + int detach, printpid, opt, i, n, ld, err; int to = 5; int init_speed = 0; int send_break = 0; @@ -1286,7 +1286,10 @@ int main(int argc, char *argv[]) while (!__io_canceled) { p.revents = 0; - if (poll(&p, 1, 500)) + err = poll(&p, 1, 500); + if (err < 0 && errno == EINTR) + continue; + if (err) break; } -- cgit From 6709e54559ae9f94749c5401579b03716400eb02 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 25 Apr 2007 23:09:02 +0000 Subject: Add support for STLC2500 address and baud rate settings --- tools/hciattach.c | 132 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 105 insertions(+), 27 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index a01c149f..776035e0 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -67,6 +67,7 @@ struct uart_t { int init_speed; int speed; int flags; + char *bdaddr; int (*init) (int fd, struct uart_t *u, struct termios *ti); }; @@ -830,9 +831,82 @@ extern int stlc2500_init(int fd, bdaddr_t *bdaddr); static int stlc2500(int fd, struct uart_t *u, struct termios *ti) { bdaddr_t bdaddr; + char cmd[5]; + unsigned char resp[10]; + int n; + + /* STLC2500 Set Baud Rate stuff */ + /* We should set the baud rate first, so the firmware download */ + /* goes much faster */ + + /* STLC2500 Seems to support the Ericsson set baud rate stuff */ + /* It should also support the ST Set Baud Rate command */ + /* (as in st() function above, but those commands never succeed */ + cmd[0] = HCI_COMMAND_PKT; + cmd[1] = 0x09; + cmd[2] = 0xfc; + cmd[3] = 0x01; + + switch (u->speed) { + case 57600: + cmd[4] = 0x03; + break; + case 115200: + cmd[4] = 0x02; + break; + case 230400: + cmd[4] = 0x01; + break; + case 460800: + cmd[4] = 0x00; + break; + case 921600: + cmd[4] = 0x20; + break; + default: + cmd[4] = 0x02; + u->speed = 115200; + break; + } + +#ifdef STLC2500_DEBUG + fprintf(stderr, "Sending Baud Rate %02x\n", cmd[4]); +#endif + /* Send initialization command */ + if (write(fd, cmd, 5) != 5) { + perror("Failed to write init command"); + return -1; + } - str2ba("00:80:E1:00:AB:BA", &bdaddr); + /* Need to wait here to give a chance for the device to set baud */ + /* But no more than 0.5 seconds */ + usleep(200000); +#ifdef STLC2500_DEBUG + fprintf(stderr, "Setting speed\n"); +#endif + if (set_speed(fd, ti, u->speed) < 0) { + perror("Can't set baud rate"); + return -1; + } + +#ifdef STLC2500_DEBUG + fprintf(stderr, "Speed set...\n"); +#endif + + /* Read reply */ + if ((n = read_hci_event(fd, resp, 10)) < 0) { + fprintf(stderr, "Failed to set baud rate on chip\n"); + return -1; + } + +#ifdef STLC2500_DEBUG + for (i = 0; i < n; i++) { + fprintf(stderr, "resp[%d] = %02x\n", i, resp[i]); + } +#endif + + str2ba(u->bdaddr, &bdaddr); return stlc2500_init(fd, &bdaddr); } @@ -842,7 +916,7 @@ static int bgb2xx(int fd, struct uart_t *u, struct termios *ti) { bdaddr_t bdaddr; - str2ba("BD:B2:10:00:AB:BA", &bdaddr); + str2ba(u->bdaddr, &bdaddr); return bgb2xx_init(fd, &bdaddr); } @@ -966,69 +1040,69 @@ static int bcm2035(int fd, struct uart_t *u, struct termios *ti) } struct uart_t uart[] = { - { "any", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, - { "ericsson", 0x0000, 0x0000, HCI_UART_H4, 57600, 115200, FLOW_CTL, ericsson }, - { "digi", 0x0000, 0x0000, HCI_UART_H4, 9600, 115200, FLOW_CTL, digi }, - { "texas", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, texas }, + { "any", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL, NULL }, + { "ericsson", 0x0000, 0x0000, HCI_UART_H4, 57600, 115200, FLOW_CTL, NULL, ericsson }, + { "digi", 0x0000, 0x0000, HCI_UART_H4, 9600, 115200, FLOW_CTL, NULL, digi }, + { "texas", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL, texas }, - { "bcsp", 0x0000, 0x0000, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, + { "bcsp", 0x0000, 0x0000, HCI_UART_BCSP, 115200, 115200, 0, NULL, bcsp }, /* Xircom PCMCIA cards: Credit Card Adapter and Real Port Adapter */ - { "xircom", 0x0105, 0x080a, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, + { "xircom", 0x0105, 0x080a, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL, NULL }, /* CSR Casira serial adapter or BrainBoxes serial dongle (BL642) */ - { "csr", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, csr }, + { "csr", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL, csr }, /* BrainBoxes PCMCIA card (BL620) */ - { "bboxes", 0x0160, 0x0002, HCI_UART_H4, 115200, 460800, FLOW_CTL, csr }, + { "bboxes", 0x0160, 0x0002, HCI_UART_H4, 115200, 460800, FLOW_CTL, NULL, csr }, /* Silicon Wave kits */ - { "swave", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, swave }, + { "swave", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL, swave }, /* ST Microelectronics minikits based on STLC2410/STLC2415 */ - { "st", 0x0000, 0x0000, HCI_UART_H4, 57600, 115200, FLOW_CTL, st }, + { "st", 0x0000, 0x0000, HCI_UART_H4, 57600, 115200, FLOW_CTL, NULL, st }, /* ST Microelectronics minikits based on STLC2500 */ - { "stlc2500", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, stlc2500 }, + { "stlc2500", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, "00:80:E1:00:AB:BA", stlc2500 }, /* Philips generic Ericsson IP core based */ - { "philips", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, + { "philips", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL, NULL }, /* Philips BGB2xx Module */ - { "bgb2xx", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, bgb2xx }, + { "bgb2xx", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, "BD:B2:10:00:AB:BA", bgb2xx }, /* Sphinx Electronics PICO Card */ - { "picocard", 0x025e, 0x1000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, + { "picocard", 0x025e, 0x1000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL, NULL }, /* Inventel BlueBird Module */ - { "inventel", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL }, + { "inventel", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL, NULL }, /* COM One Platinium Bluetooth PC Card */ - { "comone", 0xffff, 0x0101, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, + { "comone", 0xffff, 0x0101, HCI_UART_BCSP, 115200, 115200, 0, NULL, bcsp }, /* TDK Bluetooth PC Card and IBM Bluetooth PC Card II */ - { "tdk", 0x0105, 0x4254, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, + { "tdk", 0x0105, 0x4254, HCI_UART_BCSP, 115200, 115200, 0, NULL, bcsp }, /* Socket Bluetooth CF Card (Rev G) */ - { "socket", 0x0104, 0x0096, HCI_UART_BCSP, 230400, 230400, 0, bcsp }, + { "socket", 0x0104, 0x0096, HCI_UART_BCSP, 230400, 230400, 0, NULL, bcsp }, /* 3Com Bluetooth Card (Version 3.0) */ - { "3com", 0x0101, 0x0041, HCI_UART_H4, 115200, 115200, FLOW_CTL, csr }, + { "3com", 0x0101, 0x0041, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL, csr }, /* AmbiCom BT2000C Bluetooth PC/CF Card */ - { "bt2000c", 0x022d, 0x2000, HCI_UART_H4, 57600, 460800, FLOW_CTL, csr }, + { "bt2000c", 0x022d, 0x2000, HCI_UART_H4, 57600, 460800, FLOW_CTL, NULL, csr }, /* Zoom Bluetooth PCMCIA Card */ - { "zoom", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, + { "zoom", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, NULL, bcsp }, /* Sitecom CN-504 PCMCIA Card */ - { "sitecom", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, + { "sitecom", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, NULL, bcsp }, /* Billionton PCBTC1 PCMCIA Card */ - { "billionton", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, bcsp }, + { "billionton", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, NULL, bcsp }, /* Broadcom BCM2035 */ - { "bcm2035", 0x0A5C, 0x2035, HCI_UART_H4, 115200, 115200, 0, bcm2035 }, + { "bcm2035", 0x0A5C, 0x2035, HCI_UART_H4, 115200, 115200, 0, NULL, bcm2035 }, { NULL, 0 } }; @@ -1128,7 +1202,7 @@ 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] [speed] [flow|noflow]\n"); + printf("\thciattach [-n] [-p] [-b] [-t timeout] [-s initial_speed] [speed] [flow|noflow] [bdaddr]\n"); printf("\thciattach -l\n"); } @@ -1227,6 +1301,10 @@ int main(int argc, char *argv[]) else u->flags &= ~FLOW_CTL; break; + + case 4: + u->bdaddr = argv[optind]; + break; } } -- cgit From bb02c974cc53e2a8ef9e01293070b339f00a33c4 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 9 May 2007 09:34:21 +0000 Subject: Add HCIUARTGETDEVICE ioctl constant --- tools/hciattach.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 776035e0..c07d996b 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -51,8 +51,9 @@ #define N_HCI 15 #endif -#define HCIUARTSETPROTO _IOW('U', 200, int) -#define HCIUARTGETPROTO _IOR('U', 201, int) +#define HCIUARTSETPROTO _IOW('U', 200, int) +#define HCIUARTGETPROTO _IOR('U', 201, int) +#define HCIUARTGETDEVICE _IOR('U', 202, int) #define HCI_UART_H4 0 #define HCI_UART_BCSP 1 -- cgit From dc910eeb1f381a883ad9e1617a7f72efd04a2d46 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 21 Jun 2007 23:07:13 +0000 Subject: Improve the BCM2035 init routine --- tools/hciattach.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index c07d996b..ece80ce1 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -951,6 +951,29 @@ static int bcm2035(int fd, struct uart_t *u, struct termios *ti) return -1; } + if (u->bdaddr != NULL) { + /* Set BD_ADDR */ + memset(cmd, 0, sizeof(cmd)); + memset(resp, 0, sizeof(resp)); + cmd[0] = HCI_COMMAND_PKT; + cmd[1] = 0x01; + cmd[2] = 0xfc; + cmd[3] = 0x06; + str2ba(u->bdaddr, (bdaddr_t *) (cmd + 4)); + + /* Send command */ + if (write(fd, cmd, 10) != 10) { + fprintf(stderr, "Failed to write BD_ADDR command\n"); + return -1; + } + + /* Read reply */ + if ((n = read_hci_event(fd, resp, 10)) < 0) { + fprintf(stderr, "Failed to set BD_ADDR\n"); + return -1; + } + } + /* Read the local version info */ memset(cmd, 0, sizeof(cmd)); memset(resp, 0, sizeof(resp)); @@ -983,7 +1006,7 @@ static int bcm2035(int fd, struct uart_t *u, struct termios *ti) /* Send command */ if (write(fd, cmd, 4) != 4) { fprintf(stderr, "Failed to write \"read local supported " - "commands\" command\n"); + "commands\" command\n"); return -1; } @@ -1010,11 +1033,11 @@ static int bcm2035(int fd, struct uart_t *u, struct termios *ti) cmd[5] = 0xfa; break; case 460800: - cmd[4] = 0x11; + cmd[4] = 0x22; cmd[5] = 0xfd; break; case 921600: - cmd[4] = 0x65; + cmd[4] = 0x55; cmd[5] = 0xff; break; default: @@ -1103,7 +1126,7 @@ struct uart_t uart[] = { { "billionton", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, NULL, bcsp }, /* Broadcom BCM2035 */ - { "bcm2035", 0x0A5C, 0x2035, HCI_UART_H4, 115200, 115200, 0, NULL, bcm2035 }, + { "bcm2035", 0x0A5C, 0x2035, HCI_UART_H4, 115200, 460800, FLOW_CTL, NULL, bcm2035 }, { NULL, 0 } }; -- cgit From bb8dcb8334611f47697796b4abb1972cb6b8cfec Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 9 Oct 2007 16:48:10 +0000 Subject: Support higher baud rates for Ericcson based chips --- tools/hciattach.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index ece80ce1..2f9b7715 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -120,6 +120,16 @@ static int uart_speed(int s) return B1152000; case 1500000: return B1500000; + case 2000000: + return B2000000; + case 2500000: + return B2500000; + case 3000000: + return B3000000; + case 3500000: + return B3500000; + case 4000000: + return B4000000; default: return B57600; } @@ -206,9 +216,19 @@ static int ericsson(int fd, struct uart_t *u, struct termios *ti) case 921600: cmd[4] = 0x20; break; + case 2000000: + cmd[4] = 0x25; + break; + case 3000000: + cmd[4] = 0x27; + break; + case 4000000: + cmd[4] = 0x2B; + break; default: cmd[4] = 0x03; u->speed = 57600; + fprintf(stderr, "Invalid speed requested, using %d bps instead\n", u->speed); break; } -- cgit From 2d49c5ba27bd59638a3fb6e357beae609d4eb27a Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 9 Oct 2007 16:49:23 +0000 Subject: Share code for Ericsson and ST chips --- tools/hciattach.c | 52 +++++----------------------------------------------- 1 file changed, 5 insertions(+), 47 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 2f9b7715..781ccd06 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -852,56 +852,14 @@ extern int stlc2500_init(int fd, bdaddr_t *bdaddr); static int stlc2500(int fd, struct uart_t *u, struct termios *ti) { bdaddr_t bdaddr; - char cmd[5]; unsigned char resp[10]; int n; + int rvalue; - /* STLC2500 Set Baud Rate stuff */ - /* We should set the baud rate first, so the firmware download */ - /* goes much faster */ - - /* STLC2500 Seems to support the Ericsson set baud rate stuff */ - /* It should also support the ST Set Baud Rate command */ - /* (as in st() function above, but those commands never succeed */ - cmd[0] = HCI_COMMAND_PKT; - cmd[1] = 0x09; - cmd[2] = 0xfc; - cmd[3] = 0x01; - - switch (u->speed) { - case 57600: - cmd[4] = 0x03; - break; - case 115200: - cmd[4] = 0x02; - break; - case 230400: - cmd[4] = 0x01; - break; - case 460800: - cmd[4] = 0x00; - break; - case 921600: - cmd[4] = 0x20; - break; - default: - cmd[4] = 0x02; - u->speed = 115200; - break; - } - -#ifdef STLC2500_DEBUG - fprintf(stderr, "Sending Baud Rate %02x\n", cmd[4]); -#endif - /* Send initialization command */ - if (write(fd, cmd, 5) != 5) { - perror("Failed to write init command"); - return -1; - } - - /* Need to wait here to give a chance for the device to set baud */ - /* But no more than 0.5 seconds */ - usleep(200000); + /* STLC2500 has an ericsson core */ + rvalue = ericsson(fd, u, ti); + if (rvalue != 0) + return rvalue; #ifdef STLC2500_DEBUG fprintf(stderr, "Setting speed\n"); -- cgit From e823c15e43a6f924779e466d434c51157002d9ee Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 2 Feb 2008 03:37:05 +0000 Subject: Update copyright information --- tools/hciattach.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 781ccd06..00f5cc14 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -4,7 +4,7 @@ * * Copyright (C) 2000-2001 Qualcomm Incorporated * Copyright (C) 2002-2003 Maxim Krasnyansky - * Copyright (C) 2002-2007 Marcel Holtmann + * Copyright (C) 2002-2008 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify -- cgit From 042cbdb0ffbd503738c294ce43c3f1691980633e Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 13 Feb 2008 11:12:51 +0000 Subject: Add ifdefs around some baud rate definitions --- tools/hciattach.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 00f5cc14..36f3c72b 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -122,14 +122,22 @@ static int uart_speed(int s) return B1500000; case 2000000: return B2000000; +#ifdef B2500000 case 2500000: return B2500000; +#endif +#ifdef B3000000 case 3000000: return B3000000; +#endif +#ifdef B3500000 case 3500000: return B3500000; +#endif +#ifdef B4000000 case 4000000: return B4000000; +#endif default: return B57600; } -- cgit From c24fa29e216026c41a14a89690002f45d8031e86 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 10 Jul 2008 02:24:46 +0000 Subject: Mention the broken bgb2xx init routine --- tools/hciattach.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 36f3c72b..0210519e 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -897,7 +897,11 @@ static int stlc2500(int fd, struct uart_t *u, struct termios *ti) return stlc2500_init(fd, &bdaddr); } -extern int bgb2xx_init(int fd, bdaddr_t *bdaddr); +static int bgb2xx_init(int fd, bdaddr_t *bdaddr) +{ + /* This is broken and the routine got lost somewhere */ + return -EIO; +} static int bgb2xx(int fd, struct uart_t *u, struct termios *ti) { -- cgit From e0c96954340a6ccb8f40bb7106f8208484fa8599 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 11 Jul 2008 02:31:48 +0000 Subject: Set input speed and the LL protocol identifier --- tools/hciattach.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 0210519e..7f699d92 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -59,6 +60,7 @@ #define HCI_UART_BCSP 1 #define HCI_UART_3WIRE 2 #define HCI_UART_H4DS 3 +#define HCI_UART_LL 4 struct uart_t { char *type; @@ -146,6 +148,7 @@ static int uart_speed(int s) static int set_speed(int fd, struct termios *ti, int speed) { cfsetospeed(ti, uart_speed(speed)); + cfsetispeed(ti, uart_speed(speed)); return tcsetattr(fd, TCSANOW, ti); } -- cgit From 13c0e26a0213f67f5bb9bd6915fddee9a7ca3b49 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 11 Jul 2008 02:47:01 +0000 Subject: Add alternate TI init routine --- tools/hciattach.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 7f699d92..1ef961b2 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -155,7 +155,7 @@ static int set_speed(int fd, struct termios *ti, int speed) /* * Read an HCI event from the given file descriptor. */ -static int read_hci_event(int fd, unsigned char* buf, int size) +int read_hci_event(int fd, unsigned char* buf, int size) { int remain, r; int count = 0; @@ -343,6 +343,13 @@ static int texas(int fd, struct uart_t *u, struct termios *ti) return 0; } +extern int texasalt_init(int fd, int speed); + +static int texasalt(int fd, struct uart_t *u, struct termios *ti) +{ + return texasalt_init(fd, u->speed); +} + static int read_check(int fd, void *buf, int count) { int res; @@ -1061,6 +1068,7 @@ struct uart_t uart[] = { { "ericsson", 0x0000, 0x0000, HCI_UART_H4, 57600, 115200, FLOW_CTL, NULL, ericsson }, { "digi", 0x0000, 0x0000, HCI_UART_H4, 9600, 115200, FLOW_CTL, NULL, digi }, { "texas", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL, texas }, + { "texasalt", 0x0000, 0x0000, HCI_UART_LL, 115200, 115200, FLOW_CTL, NULL, texasalt }, { "bcsp", 0x0000, 0x0000, HCI_UART_BCSP, 115200, 115200, 0, NULL, bcsp }, -- cgit From 14f84d602a7584f0805c93ae9ad1bd26e2387f6d Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 11 Jul 2008 06:10:50 +0000 Subject: Update the TI init routine with BRF support --- tools/hciattach.c | 76 +++++++++++++++---------------------------------------- 1 file changed, 21 insertions(+), 55 deletions(-) (limited to 'tools/hciattach.c') diff --git a/tools/hciattach.c b/tools/hciattach.c index 1ef961b2..439b6658 100644 --- a/tools/hciattach.c +++ b/tools/hciattach.c @@ -72,6 +72,7 @@ struct uart_t { int flags; char *bdaddr; int (*init) (int fd, struct uart_t *u, struct termios *ti); + int (*post) (int fd, struct uart_t *u, struct termios *ti); }; #define FLOW_CTL 0x0001 @@ -145,7 +146,7 @@ static int uart_speed(int s) } } -static int set_speed(int fd, struct termios *ti, int speed) +int set_speed(int fd, struct termios *ti, int speed) { cfsetospeed(ti, uart_speed(speed)); cfsetispeed(ti, uart_speed(speed)); @@ -290,57 +291,17 @@ static int digi(int fd, struct uart_t *u, struct termios *ti) return 0; } +extern int texas_init(int fd, struct termios *ti); +extern int texas_post(int fd, struct termios *ti); + static int texas(int fd, struct uart_t *u, struct termios *ti) { - struct timespec tm = {0, 50000}; - char cmd[4]; - unsigned char resp[100]; /* Response */ - int n; - - memset(resp,'\0', 100); - - /* It is possible to get software version with manufacturer specific - HCI command HCI_VS_TI_Version_Number. But the only thing you get more - is if this is point-to-point or point-to-multipoint module */ - - /* Get Manufacturer and LMP version */ - cmd[0] = HCI_COMMAND_PKT; - cmd[1] = 0x01; - cmd[2] = 0x10; - cmd[3] = 0x00; - - do { - n = write(fd, cmd, 4); - if (n < 0) { - perror("Failed to write init command (READ_LOCAL_VERSION_INFORMATION)"); - return -1; - } - if (n < 4) { - fprintf(stderr, "Wanted to write 4 bytes, could only write %d. Stop\n", n); - return -1; - } - - /* Read reply. */ - if (read_hci_event(fd, resp, 100) < 0) { - perror("Failed to read init response (READ_LOCAL_VERSION_INFORMATION)"); - return -1; - } - - /* Wait for command complete event for our Opcode */ - } while (resp[4] != cmd[1] && resp[5] != cmd[2]); - - /* Verify manufacturer */ - if ((resp[11] & 0xFF) != 0x0d) - fprintf(stderr,"WARNING : module's manufacturer is not Texas Instrument\n"); - - /* Print LMP version */ - fprintf(stderr, "Texas module LMP version : 0x%02x\n", resp[10] & 0xFF); - - /* Print LMP subversion */ - fprintf(stderr, "Texas module LMP sub-version : 0x%02x%02x\n", resp[14] & 0xFF, resp[13] & 0xFF); + return texas_init(fd, ti); +} - nanosleep(&tm, NULL); - return 0; +static int texas2(int fd, struct uart_t *u, struct termios *ti) +{ + return texas_post(fd, ti); } extern int texasalt_init(int fd, int speed); @@ -1067,8 +1028,6 @@ struct uart_t uart[] = { { "any", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL, NULL }, { "ericsson", 0x0000, 0x0000, HCI_UART_H4, 57600, 115200, FLOW_CTL, NULL, ericsson }, { "digi", 0x0000, 0x0000, HCI_UART_H4, 9600, 115200, FLOW_CTL, NULL, digi }, - { "texas", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL, texas }, - { "texasalt", 0x0000, 0x0000, HCI_UART_LL, 115200, 115200, FLOW_CTL, NULL, texasalt }, { "bcsp", 0x0000, 0x0000, HCI_UART_BCSP, 115200, 115200, 0, NULL, bcsp }, @@ -1084,17 +1043,21 @@ struct uart_t uart[] = { /* Silicon Wave kits */ { "swave", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL, swave }, + /* Texas Instruments Bluelink (BRF) modules */ + { "texas", 0x0000, 0x0000, HCI_UART_LL, 115200, 115200, FLOW_CTL, NULL, texas, texas2 }, + { "texasalt", 0x0000, 0x0000, HCI_UART_LL, 115200, 115200, FLOW_CTL, NULL, texasalt, NULL }, + /* ST Microelectronics minikits based on STLC2410/STLC2415 */ { "st", 0x0000, 0x0000, HCI_UART_H4, 57600, 115200, FLOW_CTL, NULL, st }, /* ST Microelectronics minikits based on STLC2500 */ - { "stlc2500", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, "00:80:E1:00:AB:BA", stlc2500 }, + { "stlc2500", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, "00:80:E1:00:AB:BA", stlc2500 }, /* Philips generic Ericsson IP core based */ { "philips", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL, NULL }, /* Philips BGB2xx Module */ - { "bgb2xx", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, "BD:B2:10:00:AB:BA", bgb2xx }, + { "bgb2xx", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, "BD:B2:10:00:AB:BA", bgb2xx }, /* Sphinx Electronics PICO Card */ { "picocard", 0x025e, 0x1000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL, NULL }, @@ -1220,6 +1183,9 @@ int init_uart(char *dev, struct uart_t *u, int send_break) return -1; } + if (u->post && u->post(fd, u, &ti) < 0) + return -1; + return fd; } @@ -1235,7 +1201,7 @@ int main(int argc, char *argv[]) { struct uart_t *u = NULL; int detach, printpid, opt, i, n, ld, err; - int to = 5; + int to = 10; int init_speed = 0; int send_break = 0; pid_t pid; @@ -1348,7 +1314,7 @@ int main(int argc, char *argv[]) sa.sa_handler = sig_alarm; sigaction(SIGALRM, &sa, NULL); - /* 5 seconds should be enough for initialization */ + /* 10 seconds should be enough for initialization */ alarm(to); n = init_uart(dev, u, send_break); -- cgit