1 --- bluez-utils-3.1/tools/hciattach.c.orig 2006-07-23 14:02:14.000000000 +0200
2 +++ bluez-utils-3.1/tools/hciattach.c 2006-07-23 14:06:29.000000000 +0200
4 #define HCI_UART_3WIRE 2
5 #define HCI_UART_H4DS 3
15 int (*init) (int fd, struct uart_t *u, struct termios *ti);
16 + char *bts; /* bluetooth script */
19 #define FLOW_CTL 0x0001
24 +static int brf6150(int fd, struct uart_t *u, struct termios *ti)
29 + unsigned char actionbuf[256];
30 + unsigned char resp[128]; /* Response */
31 + unsigned long count;
32 + unsigned short atype;
34 + if (u->bts == NULL) /* no script, ignore */
37 + bfp = bts_load_script( u->bts, &vers );
41 + fprintf( stderr, "Loading BTS script version %lu\n", vers );
43 + while ((count = bts_next_action( bfp, actionbuf,
44 + sizeof actionbuf - 1, &atype )) != 0) {
45 + if (atype == ACTION_REMARKS) {
46 + if (actionbuf[0] != 0)
47 + fprintf( stderr, "%s\n", actionbuf );
49 + else if (atype == ACTION_SEND_COMMAND) {
51 + fprintf( stderr, "ACTION_SEND_COMMAND: ", (int)atype );
52 + for (i=0; i<count; i++) {
53 + fprintf( stderr, "0x%02x ", actionbuf[i] );
55 + fprintf( stderr, "\n" );
58 + n = write(fd, actionbuf, count);
59 + if (n < 0 || n < count) {
60 + perror("Failed to write TI action command");
64 + else if (atype == ACTION_WAIT_EVENT) {
65 + action_wait_t *wait = (action_wait_t *)actionbuf;
67 + fprintf( stderr, "ACTION_WAIT_EVENT: %u msec, %u size, data = ", wait->msec, wait->size );
68 + for (i=0; i<wait->size; i++) {
69 + fprintf( stderr, "0x%02x ", wait->data[i] );
71 + fprintf( stderr, "\n" );
73 + usleep(wait->msec); /* seems they give usec, not msec */
75 + if ((count = read_hci_event(fd, resp, sizeof resp)) < 0) {
76 + perror("Failed to read TI command response");
79 + if (count < wait->size) {
80 + fprintf( stderr, "TI command response is short.");
82 + for (i=0; i<wait->size; i++) {
83 + if (i == 3) continue; /* ignore */
84 + if (resp[i] != wait->data[i]) {
85 + fprintf( stderr, "TI command response does not match expected result.\n" );
89 + else if (atype == ACTION_SERIAL_PORT_PARAMETERS) {
90 + action_serial_t *sercmd = (action_serial_t *)actionbuf;
92 + /* Set actual baudrate */
94 + "BTS changing baud rate to %u, flow control to %u\n",
95 + sercmd->baud, sercmd->flow_control );
97 + tcflush(fd, TCIOFLUSH);
99 + if (sercmd->flow_control)
100 + ti->c_cflag |= CRTSCTS;
102 + ti->c_cflag &= ~CRTSCTS;
103 + if (tcsetattr(fd, TCSANOW, ti) < 0) {
104 + perror("Can't set port settings");
108 + u->speed = sercmd->baud;
110 + tcflush(fd, TCIOFLUSH);
111 + if (set_speed(fd, ti, sercmd->baud) < 0) {
112 + perror("Can't set baud rate");
116 + else if (atype == ACTION_DELAY) {
117 + action_delay_t *delay = (action_delay_t *)actionbuf;
118 + usleep(delay->msec); /* seems they give usec, not msec */
121 + fprintf( stderr, "BTS action type = %d: ", (int)atype );
122 + for (i=0; i<count; i++) {
123 + fprintf( stderr, "0x%02x ", actionbuf[i] );
125 + fprintf( stderr, "\n" );
128 + bts_unload_script( bfp );
132 static int texas(int fd, struct uart_t *u, struct termios *ti)
134 struct timespec tm = {0, 50000};
136 /* Print LMP subversion */
137 fprintf(stderr, "Texas module LMP sub-version : 0x%02x%02x\n", resp[14] & 0xFF, resp[13] & 0xFF);
139 + if ((resp[14] >> 2) == 3) {
143 + nanosleep(&tm, NULL);
144 + if ((err = brf6150(fd, u, ti)) != 0) {
145 + fprintf(stderr, "Texas module script failed (err=%d)\n", err);
150 nanosleep(&tm, NULL);
153 @@ -1204,7 +1326,7 @@
155 printf("hciattach - HCI UART driver initialization utility\n");
157 - printf("\thciattach [-n] [-p] [-b] [-t timeout] [-s initial_speed] <tty> <type | id> [speed] [flow|noflow] [bdaddr]\n");
158 + printf("\thciattach [-n] [-p] [-b] [-t timeout] [-s initial_speed] [-S bts-script] <tty> <type | id> [speed] [flow|noflow] [bdaddr]\n");
159 printf("\thciattach -l\n");
162 @@ -1219,11 +1341,12 @@
171 - while ((opt=getopt(argc, argv, "bnpt:s:l")) != EOF) {
172 + while ((opt=getopt(argc, argv, "bnpt:s:S:l")) != EOF) {
176 @@ -1245,6 +1368,10 @@
177 init_speed = atoi(optarg);
185 for (i = 0; uart[i].type; i++) {
186 printf("%-10s0x%04x,0x%04x\n", uart[i].type,
187 @@ -1320,6 +1447,8 @@
189 u->init_speed = init_speed;
193 memset(&sa, 0, sizeof(sa));
194 sa.sa_flags = SA_NOCLDSTOP;
195 sa.sa_handler = sig_alarm;
196 --- bluez-utils-3.1/tools/ti_bts.h.orig 2006-07-23 14:07:26.000000000 +0200
197 +++ bluez-utils-3.1/tools/ti_bts.h 2006-07-23 14:07:46.000000000 +0200
200 + * Copyright (c) 2005 Texas Instruments, Inc.
201 + * Ported by SDG Systems, LLC
203 + * This program is free software; you can redistribute it and/or modify
204 + * it under the terms of the GNU General Public License version 2 as
205 + * published by the Free Software Foundation;
207 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
208 + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
209 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
210 + * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
211 + * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
212 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
213 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
214 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
216 + * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
217 + * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
218 + * SOFTWARE IS DISCLAIMED.
230 + * Define the interface of Bluetooth Script
236 +#define ACTION_SEND_COMMAND 1 /* Send out raw data (as is) */
237 +#define ACTION_WAIT_EVENT 2 /* Wait for data */
238 +#define ACTION_SERIAL_PORT_PARAMETERS 3
239 +#define ACTION_DELAY 4
240 +#define ACTION_RUN_SCRIPT 5
241 +#define ACTION_REMARKS 6
244 + * Structure for ACTION_SEND_COMMAND
246 +typedef struct tagCActionCommand
248 + unsigned char data[1]; /* Data to send */
252 + * Structure for ACTION_WAIT_EVENT
254 +typedef struct tagCActionWaitEvent
256 + unsigned long msec; /* in milliseconds */
257 + unsigned long size;
258 + unsigned char data[1]; /* Data to wait for */
263 + * Structure for ACTION_SERIAL_PORT_PARAMETERS
265 +typedef struct tagCActionSerialPortParameters
267 + unsigned long baud;
268 + unsigned long flow_control;
271 +/* Flow Control Type */
273 +#define FCT_HARDWARE 1
275 +#define DONT_CHANGE 0xFFFFFFFF /* For both baud rate and flow control */
279 + * Structure for ACTION_DELAY
281 +typedef struct tagCActionDelay
283 + unsigned long msec; /* in milliseconds */
287 + * Structure for ACTION_RUN_SCRIPT
289 +typedef struct tagCActionRunScript
295 + * Structure for ACTION_REMARKS
297 +typedef struct tagCActionRemarks
299 + char m_szRemarks[1];
303 +const char *cis_create_filename(const unsigned char* cmdparms);
304 +bts_t * bts_load_script(const char* fname, unsigned long* version);
305 +unsigned long bts_next_action(const bts_t* bts_fp, unsigned char* action_buf,
306 + unsigned long nMaxSize, unsigned short* ptype);
307 +void bts_unload_script(bts_t* bts_fp);
313 +#endif /* BT_SCRIPT_H */
315 --- bluez-utils-3.1/tools/ti_bts.c.orig 2006-07-23 14:07:28.000000000 +0200
316 +++ bluez-utils-3.1/tools/ti_bts.c 2006-07-23 14:07:46.000000000 +0200
319 + * Copyright (c) 2005 Texas Instruments, Inc.
320 + * Ported by SDG Systems, LLC
322 + * This program is free software; you can redistribute it and/or modify
323 + * it under the terms of the GNU General Public License version 2 as
324 + * published by the Free Software Foundation;
326 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
327 + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
328 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
329 + * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
330 + * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
331 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
332 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
333 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
335 + * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
336 + * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
337 + * SOFTWARE IS DISCLAIMED.
347 +#define MAKEWORD(a, b) ((unsigned short)(((unsigned char)(a)) | ((unsigned short)((unsigned char)(b))) << 8))
350 +#define TI_MANUFACTURER_ID 13
353 + * Common Init Script specific
356 +cis_create_filename(const unsigned char* cmdparms)
358 + static char bts_file[50];
360 + /* Check for TI's id */
361 + unsigned short manfid = MAKEWORD(cmdparms[8], cmdparms[9]);
363 + if (TI_MANUFACTURER_ID == manfid) {
364 + unsigned short version = MAKEWORD(cmdparms[10], cmdparms[11]);
366 + unsigned short chip = (version & 0x7C00) >> 10;
367 + unsigned short min_ver = (version & 0x007F);
368 + unsigned short maj_ver = (version & 0x0380) >> 7;
370 + if (0 != (version & 0x8000)) {
374 + sprintf( bts_file, "TIInit_%d.%d.%d.bts",
375 + (int)chip, (int)maj_ver, (int)min_ver);
377 + return &bts_file[0];
382 +typedef struct tagCHeader
384 + unsigned long magic;
385 + unsigned long version;
386 + unsigned char future[24];
390 +/* The value 0x42535442 stands for (in ASCII) BTSB */
391 +/* which is Bluetooth Script Binary */
392 +#define FILE_HEADER_MAGIC 0x42535442
396 +bts_load_script(const char* fname, unsigned long* version)
399 + FILE* fp = fopen(fname, "rb");
406 + if (1 == fread(&header, sizeof(header), 1, fp)) {
407 + /* Check magic number for correctness */
408 + if (header.magic == FILE_HEADER_MAGIC) {
409 + /* If user wants the version number */
410 + if (NULL != version) {
411 + *version = header.version;
416 + /* If failed reading the file, close it */
425 +bts_next_action(const bts_t* bts_fp, unsigned char* action_buf,
426 + unsigned long nMaxSize, unsigned short* ptype)
428 + unsigned long bytes = 0;
429 + FILE* fp = (FILE*)bts_fp;
430 + unsigned char action_hdr[4];
432 + if (bts_fp == NULL)
435 + /* Each Action has the following: */
436 + /* UINT16 type of this action */
437 + /* UINT16 size of rest */
438 + /* BYTE[] action buffer (for HCI, includes the type byte e.g. 1 for hci command) */
440 + if (1 == fread(&action_hdr[0], sizeof(action_hdr), 1, fp)) {
441 + unsigned short type = *(unsigned short*)&action_hdr[0];
442 + unsigned short size = *(unsigned short*)&action_hdr[2];
444 + if (size <= nMaxSize) {
445 + int nread = fread(action_buf, sizeof(action_buf[0]), size, fp);
447 + if (nread == size) {
449 + bytes = (unsigned long)size;
458 +bts_unload_script(bts_t* bts_fp)
460 + FILE* fp = (FILE*)bts_fp;
467 --- bluez-utils-3.1/tools/Makefile.am.orig 2006-07-23 14:06:59.000000000 +0200
468 +++ bluez-utils-3.1/tools/Makefile.am 2006-07-23 14:07:18.000000000 +0200
471 noinst_PROGRAMS = hcisecfilter ppporc
473 -hciattach_SOURCES = hciattach.c hciattach_st.c
474 +hciattach_SOURCES = hciattach.c hciattach_st.c ti_bts.h ti_bts.c
475 hciattach_LDADD = @BLUEZ_LIBS@
477 hciconfig_SOURCES = hciconfig.c csr.h csr.c