1 upstream: accepted, this patch has landed upstream albeit in a different form
2 sometime between 3.35 and 3.36. see the commit message in "git log e1d12d8bb5b40a6313cce52974f174fd76cbf32c"
4 --- bluez-utils-2.24/tools/hciattach.c.orig 2005-12-10 15:14:36.000000000 +0100
5 +++ bluez-utils-2.24/tools/hciattach.c 2006-01-22 13:56:13.000000000 +0100
7 #define HCI_UART_3WIRE 2
8 #define HCI_UART_H4DS 3
18 int (*init) (int fd, struct uart_t *u, struct termios *ti);
19 + char *bts; /* bluetooth script */
22 #define FLOW_CTL 0x0001
27 +static int brf6150(int fd, struct uart_t *u, struct termios *ti)
32 + unsigned char actionbuf[256];
33 + unsigned char resp[128]; /* Response */
34 + unsigned long count;
35 + unsigned short atype;
37 + if (u->bts == NULL) /* no script, ignore */
40 + bfp = bts_load_script( u->bts, &vers );
44 + fprintf( stderr, "Loading BTS script version %lu\n", vers );
46 + while ((count = bts_next_action( bfp, actionbuf,
47 + sizeof actionbuf - 1, &atype )) != 0) {
48 + if (atype == ACTION_REMARKS) {
49 + if (actionbuf[0] != 0)
50 + fprintf( stderr, "%s\n", actionbuf );
52 + else if (atype == ACTION_SEND_COMMAND) {
54 + fprintf( stderr, "ACTION_SEND_COMMAND: ", (int)atype );
55 + for (i=0; i<count; i++) {
56 + fprintf( stderr, "0x%02x ", actionbuf[i] );
58 + fprintf( stderr, "\n" );
61 + n = write(fd, actionbuf, count);
62 + if (n < 0 || n < count) {
63 + perror("Failed to write TI action command");
67 + else if (atype == ACTION_WAIT_EVENT) {
68 + action_wait_t *wait = (action_wait_t *)actionbuf;
70 + fprintf( stderr, "ACTION_WAIT_EVENT: %u msec, %u size, data = ", wait->msec, wait->size );
71 + for (i=0; i<wait->size; i++) {
72 + fprintf( stderr, "0x%02x ", wait->data[i] );
74 + fprintf( stderr, "\n" );
76 + usleep(wait->msec); /* seems they give usec, not msec */
78 + if ((count = read_hci_event(fd, resp, sizeof resp)) < 0) {
79 + perror("Failed to read TI command response");
82 + if (count < wait->size) {
83 + fprintf( stderr, "TI command response is short.");
85 + for (i=0; i<wait->size; i++) {
86 + if (i == 3) continue; /* ignore */
87 + if (resp[i] != wait->data[i]) {
88 + fprintf( stderr, "TI command response does not match expected result.\n" );
92 + else if (atype == ACTION_SERIAL_PORT_PARAMETERS) {
93 + action_serial_t *sercmd = (action_serial_t *)actionbuf;
95 + /* Set actual baudrate */
97 + "BTS changing baud rate to %u, flow control to %u\n",
98 + sercmd->baud, sercmd->flow_control );
100 + tcflush(fd, TCIOFLUSH);
102 + if (sercmd->flow_control)
103 + ti->c_cflag |= CRTSCTS;
105 + ti->c_cflag &= ~CRTSCTS;
106 + if (tcsetattr(fd, TCSANOW, ti) < 0) {
107 + perror("Can't set port settings");
111 + u->speed = sercmd->baud;
113 + tcflush(fd, TCIOFLUSH);
114 + if (set_speed(fd, ti, sercmd->baud) < 0) {
115 + perror("Can't set baud rate");
119 + else if (atype == ACTION_DELAY) {
120 + action_delay_t *delay = (action_delay_t *)actionbuf;
121 + usleep(delay->msec); /* seems they give usec, not msec */
124 + fprintf( stderr, "BTS action type = %d: ", (int)atype );
125 + for (i=0; i<count; i++) {
126 + fprintf( stderr, "0x%02x ", actionbuf[i] );
128 + fprintf( stderr, "\n" );
131 + bts_unload_script( bfp );
135 static int texas(int fd, struct uart_t *u, struct termios *ti)
137 struct timespec tm = {0, 50000};
138 @@ -281,14 +392,25 @@
139 } while (resp[4] != cmd[1] && resp[5] != cmd[2]);
141 /* Verify manufacturer */
142 - if ((resp[11] & 0xFF) != 0x0d)
143 + if (resp[11] != 0x0d)
144 fprintf(stderr,"WARNING : module's manufacturer is not Texas Instrument\n");
146 /* Print LMP version */
147 - fprintf(stderr, "Texas module LMP version : 0x%02x\n", resp[10] & 0xFF);
148 + fprintf(stderr, "TI module LMP version : 0x%02x\n", resp[10]);
150 /* Print LMP subversion */
151 - fprintf(stderr, "Texas module LMP sub-version : 0x%02x%02x\n", resp[14] & 0xFF, resp[13] & 0xFF);
152 + fprintf(stderr, "TI module LMP sub-version : 0x%02x%02x\n", resp[14], resp[13]);
153 + if ((resp[14] >> 2) == 3) {
155 + nanosleep(&tm, NULL);
158 + if ((err=brf6150( fd, u, ti )) != 0) {
159 + fprintf( stderr, "TI script failed (err=%d)\n",
165 nanosleep(&tm, NULL);
169 printf("hciattach - HCI UART driver initialization utility\n");
171 - printf("\thciattach [-n] [-p] [-b] [-t timeout] [-s initial_speed] <tty> <type | id> [speed] [flow|noflow]\n");
172 + printf("\thciattach [-n] [-p] [-b] [-t timeout] [-s initial_speed] [-S bts-script] <tty> <type | id> [speed] [flow|noflow]\n");
173 printf("\thciattach -l\n");
176 @@ -970,11 +1092,12 @@
185 - while ((opt=getopt(argc, argv, "bnpt:s:l")) != EOF) {
186 + while ((opt=getopt(argc, argv, "bnpt:s:S:l")) != EOF) {
190 @@ -996,6 +1119,10 @@
191 init_speed = atoi(optarg);
199 for (i = 0; uart[i].type; i++) {
200 printf("%-10s0x%04x,0x%04x\n", uart[i].type,
201 @@ -1067,6 +1194,8 @@
203 u->init_speed = init_speed;
207 memset(&sa, 0, sizeof(sa));
208 sa.sa_flags = SA_NOCLDSTOP;
209 sa.sa_handler = sig_alarm;
210 --- bluez-utils-2.24/tools/Makefile.am.orig 2005-12-03 07:22:16.000000000 +0100
211 +++ bluez-utils-2.24/tools/Makefile.am 2006-01-22 13:53:59.000000000 +0100
214 noinst_PROGRAMS = hcisecfilter ppporc
216 +hciattach_SOURCES = hciattach.c ti_bts.h ti_bts.c
217 +hciattach_LDADD = @BLUEZ_LIBS@
219 hciconfig_SOURCES = hciconfig.c csr.h csr.c
220 hciconfig_LDADD = @BLUEZ_LIBS@ $(top_builddir)/common/libtextfile.a
222 --- bluez-utils-2.24/tools/ti_bts.h.orig 2006-01-22 13:56:38.000000000 +0100
223 +++ bluez-utils-2.24/tools/ti_bts.h 2006-01-22 13:53:59.000000000 +0100
226 + * Copyright (c) 2005 Texas Instruments, Inc.
227 + * Ported by SDG Systems, LLC
229 + * This program is free software; you can redistribute it and/or modify
230 + * it under the terms of the GNU General Public License version 2 as
231 + * published by the Free Software Foundation;
233 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
234 + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
235 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
236 + * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
237 + * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
238 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
239 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
240 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
242 + * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
243 + * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
244 + * SOFTWARE IS DISCLAIMED.
256 + * Define the interface of Bluetooth Script
262 +#define ACTION_SEND_COMMAND 1 /* Send out raw data (as is) */
263 +#define ACTION_WAIT_EVENT 2 /* Wait for data */
264 +#define ACTION_SERIAL_PORT_PARAMETERS 3
265 +#define ACTION_DELAY 4
266 +#define ACTION_RUN_SCRIPT 5
267 +#define ACTION_REMARKS 6
270 + * Structure for ACTION_SEND_COMMAND
272 +typedef struct tagCActionCommand
274 + unsigned char data[1]; /* Data to send */
278 + * Structure for ACTION_WAIT_EVENT
280 +typedef struct tagCActionWaitEvent
282 + unsigned long msec; /* in milliseconds */
283 + unsigned long size;
284 + unsigned char data[1]; /* Data to wait for */
289 + * Structure for ACTION_SERIAL_PORT_PARAMETERS
291 +typedef struct tagCActionSerialPortParameters
293 + unsigned long baud;
294 + unsigned long flow_control;
297 +/* Flow Control Type */
299 +#define FCT_HARDWARE 1
301 +#define DONT_CHANGE 0xFFFFFFFF /* For both baud rate and flow control */
305 + * Structure for ACTION_DELAY
307 +typedef struct tagCActionDelay
309 + unsigned long msec; /* in milliseconds */
313 + * Structure for ACTION_RUN_SCRIPT
315 +typedef struct tagCActionRunScript
321 + * Structure for ACTION_REMARKS
323 +typedef struct tagCActionRemarks
325 + char m_szRemarks[1];
329 +const char *cis_create_filename(const unsigned char* cmdparms);
330 +bts_t * bts_load_script(const char* fname, unsigned long* version);
331 +unsigned long bts_next_action(const bts_t* bts_fp, unsigned char* action_buf,
332 + unsigned long nMaxSize, unsigned short* ptype);
333 +void bts_unload_script(bts_t* bts_fp);
339 +#endif /* BT_SCRIPT_H */
341 --- bluez-utils-2.24/tools/ti_bts.c.orig 2006-01-22 13:56:36.000000000 +0100
342 +++ bluez-utils-2.24/tools/ti_bts.c 2006-01-22 13:56:31.000000000 +0100
345 + * Copyright (c) 2005 Texas Instruments, Inc.
346 + * Ported by SDG Systems, LLC
348 + * This program is free software; you can redistribute it and/or modify
349 + * it under the terms of the GNU General Public License version 2 as
350 + * published by the Free Software Foundation;
352 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
353 + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
354 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
355 + * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
356 + * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
357 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
358 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
359 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
361 + * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
362 + * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
363 + * SOFTWARE IS DISCLAIMED.
373 +#define MAKEWORD(a, b) ((unsigned short)(((unsigned char)(a)) | ((unsigned short)((unsigned char)(b))) << 8))
376 +#define TI_MANUFACTURER_ID 13
379 + * Common Init Script specific
382 +cis_create_filename(const unsigned char* cmdparms)
384 + static char bts_file[50];
386 + /* Check for TI's id */
387 + unsigned short manfid = MAKEWORD(cmdparms[8], cmdparms[9]);
389 + if (TI_MANUFACTURER_ID == manfid) {
390 + unsigned short version = MAKEWORD(cmdparms[10], cmdparms[11]);
392 + unsigned short chip = (version & 0x7C00) >> 10;
393 + unsigned short min_ver = (version & 0x007F);
394 + unsigned short maj_ver = (version & 0x0380) >> 7;
396 + if (0 != (version & 0x8000)) {
400 + sprintf( bts_file, "TIInit_%d.%d.%d.bts",
401 + (int)chip, (int)maj_ver, (int)min_ver);
403 + return &bts_file[0];
408 +typedef struct tagCHeader
410 + unsigned long magic;
411 + unsigned long version;
412 + unsigned char future[24];
416 +/* The value 0x42535442 stands for (in ASCII) BTSB */
417 +/* which is Bluetooth Script Binary */
418 +#define FILE_HEADER_MAGIC 0x42535442
422 +bts_load_script(const char* fname, unsigned long* version)
425 + FILE* fp = fopen(fname, "rb");
432 + if (1 == fread(&header, sizeof(header), 1, fp)) {
433 + /* Check magic number for correctness */
434 + if (header.magic == FILE_HEADER_MAGIC) {
435 + /* If user wants the version number */
436 + if (NULL != version) {
437 + *version = header.version;
442 + /* If failed reading the file, close it */
451 +bts_next_action(const bts_t* bts_fp, unsigned char* action_buf,
452 + unsigned long nMaxSize, unsigned short* ptype)
454 + unsigned long bytes = 0;
455 + FILE* fp = (FILE*)bts_fp;
456 + unsigned char action_hdr[4];
458 + if (bts_fp == NULL)
461 + /* Each Action has the following: */
462 + /* UINT16 type of this action */
463 + /* UINT16 size of rest */
464 + /* BYTE[] action buffer (for HCI, includes the type byte e.g. 1 for hci command) */
466 + if (1 == fread(&action_hdr[0], sizeof(action_hdr), 1, fp)) {
467 + unsigned short type = *(unsigned short*)&action_hdr[0];
468 + unsigned short size = *(unsigned short*)&action_hdr[2];
470 + if (size <= nMaxSize) {
471 + int nread = fread(action_buf, sizeof(action_buf[0]), size, fp);
473 + if (nread == size) {
475 + bytes = (unsigned long)size;
484 +bts_unload_script(bts_t* bts_fp)
486 + FILE* fp = (FILE*)bts_fp;