Index: Makefile.am =================================================================== RCS file: /cvsroot/bluez/utils/tools/Makefile.am,v retrieving revision 1.29 diff -u -r1.29 Makefile.am --- Makefile.am 16 May 2005 11:51:27 -0000 1.29 +++ Makefile.am 17 Jun 2005 18:08:42 -0000 @@ -24,6 +24,9 @@ noinst_PROGRAMS = hcisecfilter ppporc pskey bccmd +hciattach_SOURCES = hciattach.c ti_bts.h ti_bts.c +hciattach_LDADD = @BLUEZ_LIBS@ + hciconfig_SOURCES = hciconfig.c csr.h csr.c hciconfig_LDADD = @BLUEZ_LIBS@ $(top_builddir)/common/libtextfile.a Index: hciattach.c =================================================================== RCS file: /cvsroot/bluez/utils/tools/hciattach.c,v retrieving revision 1.29 diff -u -r1.29 hciattach.c --- hciattach.c 30 Jan 2005 20:38:04 -0000 1.29 +++ hciattach.c 17 Jun 2005 18:08:42 -0000 @@ -51,6 +51,8 @@ #include #include +#include "ti_bts.h" + struct uart_t { char *type; int m_id; @@ -60,6 +62,7 @@ int speed; int flags; int (*init) (int fd, struct uart_t *u, struct termios *ti); + char *bts; /* bluetooth script */ }; #define FLOW_CTL 0x0001 @@ -235,6 +238,114 @@ return 0; } +static int brf6150(int fd, struct uart_t *u, struct termios *ti) +{ + bts_t *bfp; + int i; + unsigned long vers; + unsigned char actionbuf[256]; + unsigned char resp[128]; /* Response */ + unsigned long count; + unsigned short atype; + + if (u->bts == NULL) /* no script, ignore */ + return 0; + + bfp = bts_load_script( u->bts, &vers ); + if (bfp == NULL) + return -1; + + fprintf( stderr, "Loading BTS script version %lu\n", vers ); + + while ((count = bts_next_action( bfp, actionbuf, + sizeof actionbuf - 1, &atype )) != 0) { + if (atype == ACTION_REMARKS) { + if (actionbuf[0] != 0) + fprintf( stderr, "%s\n", actionbuf ); + } + else if (atype == ACTION_SEND_COMMAND) { +#if 0 + fprintf( stderr, "ACTION_SEND_COMMAND: ", (int)atype ); + for (i=0; idata[i] ); + } + fprintf( stderr, "\n" ); +#endif + usleep(wait->msec); /* seems they give usec, not msec */ + /* Read reply. */ + if ((count = read_hci_event(fd, resp, sizeof resp)) < 0) { + perror("Failed to read TI command response"); + return -1; + } + if (count < wait->size) { + fprintf( stderr, "TI command response is short."); + } + for (i=0; isize; i++) { + if (i == 3) continue; /* ignore */ + if (resp[i] != wait->data[i]) { + fprintf( stderr, "TI command response does not match expected result.\n" ); + } + } + } + else if (atype == ACTION_SERIAL_PORT_PARAMETERS) { + action_serial_t *sercmd = (action_serial_t *)actionbuf; + + /* Set actual baudrate */ + fprintf( stderr, + "BTS changing baud rate to %u, flow control to %u\n", + sercmd->baud, sercmd->flow_control ); + + tcflush(fd, TCIOFLUSH); + + if (sercmd->flow_control) + ti->c_cflag |= CRTSCTS; + else + ti->c_cflag &= ~CRTSCTS; + if (tcsetattr(fd, TCSANOW, ti) < 0) { + perror("Can't set port settings"); + return -1; + } + + u->speed = sercmd->baud; + + tcflush(fd, TCIOFLUSH); + if (set_speed(fd, ti, sercmd->baud) < 0) { + perror("Can't set baud rate"); + return -1; + } + } + else if (atype == ACTION_DELAY) { + action_delay_t *delay = (action_delay_t *)actionbuf; + usleep(delay->msec); /* seems they give usec, not msec */ + } + else { + fprintf( stderr, "BTS action type = %d: ", (int)atype ); + for (i=0; i> 2) == 3) { + int err; + nanosleep(&tm, NULL); + + /* BRF6150 */ + if ((err=brf6150( fd, u, ti )) != 0) { + fprintf( stderr, "TI script failed (err=%d)\n", + err ); + return -1; + } + } nanosleep(&tm, NULL); return 0; @@ -946,7 +1068,7 @@ { 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] [-S bts-script] [speed] [flow|noflow]\n"); printf("\thciattach -l\n"); } @@ -963,11 +1085,12 @@ pid_t pid; struct sigaction sa; char dev[20]; + char *bts = NULL; detach = 1; printpid = 0; - while ((opt=getopt(argc, argv, "bnpt:s:l")) != EOF) { + while ((opt=getopt(argc, argv, "bnpt:s:S:l")) != EOF) { switch(opt) { case 'b': send_break = 1; @@ -989,6 +1112,10 @@ init_speed = atoi(optarg); break; + case 'S': + bts = optarg; + break; + case 'l': for (i = 0; uart[i].type; i++) { printf("%-10s0x%04x,0x%04x\n", uart[i].type, @@ -1060,6 +1187,8 @@ if (init_speed) u->init_speed = init_speed; + u->bts = bts; + memset(&sa, 0, sizeof(sa)); sa.sa_flags = SA_NOCLDSTOP; sa.sa_handler = sig_alarm;