bluez: document that hciattach-ti-bts.patch has landed upstream
[vuplus_openembedded] / recipes / bluez / bluez-utils-3.x / hciattach-ti-bts.patch
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"
3
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
6 @@ -57,6 +57,8 @@
7  #define HCI_UART_3WIRE 2
8  #define HCI_UART_H4DS  3
9  
10 +#include "ti_bts.h"
11 +
12  struct uart_t {
13         char *type;
14         int  m_id;
15 @@ -66,6 +68,7 @@
16         int  speed;
17         int  flags;
18         int  (*init) (int fd, struct uart_t *u, struct termios *ti);
19 +       char *bts;      /* bluetooth script */
20  };
21  
22  #define FLOW_CTL       0x0001
23 @@ -241,6 +244,114 @@
24         return 0;
25  }
26  
27 +static int brf6150(int fd, struct uart_t *u, struct termios *ti)
28 +{
29 +       bts_t *bfp;
30 +       int i;
31 +       unsigned long vers;
32 +       unsigned char actionbuf[256];
33 +       unsigned char resp[128];                /* Response */
34 +       unsigned long count;
35 +       unsigned short atype;
36 +
37 +       if (u->bts == NULL)     /* no script, ignore */
38 +               return 0;
39 +
40 +       bfp = bts_load_script( u->bts, &vers );
41 +       if (bfp == NULL)
42 +               return -1;
43 +
44 +       fprintf( stderr, "Loading BTS script version %lu\n", vers );
45 +
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 );
51 +               }
52 +               else if (atype == ACTION_SEND_COMMAND) {
53 +#if 0
54 +                       fprintf( stderr, "ACTION_SEND_COMMAND: ", (int)atype );
55 +                       for (i=0; i<count; i++) {
56 +                               fprintf( stderr, "0x%02x ", actionbuf[i] );
57 +                       }
58 +                       fprintf( stderr, "\n" );
59 +#endif
60 +                       int n;
61 +                       n = write(fd, actionbuf, count);
62 +                       if (n < 0 || n < count) {
63 +                               perror("Failed to write TI action command");
64 +                               return -1;
65 +                       }
66 +               }
67 +               else if (atype == ACTION_WAIT_EVENT) {
68 +                       action_wait_t *wait = (action_wait_t *)actionbuf;
69 +#if 0
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] );
73 +                       }
74 +                       fprintf( stderr, "\n" );
75 +#endif
76 +                       usleep(wait->msec);     /* seems they give usec, not msec */
77 +                       /* Read reply. */
78 +                       if ((count = read_hci_event(fd, resp, sizeof resp)) < 0) {
79 +                               perror("Failed to read TI command response");
80 +                               return -1;
81 +                       }
82 +                       if (count < wait->size) {
83 +                               fprintf( stderr, "TI command response is short.");
84 +                       }
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" );
89 +                               }
90 +                       }
91 +               }
92 +               else if (atype == ACTION_SERIAL_PORT_PARAMETERS) {
93 +                       action_serial_t *sercmd = (action_serial_t *)actionbuf;
94 +
95 +                       /* Set actual baudrate */
96 +                       fprintf( stderr,
97 +                               "BTS changing baud rate to %u, flow control to %u\n",
98 +                               sercmd->baud, sercmd->flow_control );
99 +
100 +                       tcflush(fd, TCIOFLUSH);
101 +
102 +                       if (sercmd->flow_control)
103 +                               ti->c_cflag |= CRTSCTS;
104 +                       else
105 +                               ti->c_cflag &= ~CRTSCTS;
106 +                       if (tcsetattr(fd, TCSANOW, ti) < 0) {
107 +                               perror("Can't set port settings");
108 +                               return -1;
109 +                       }
110 +
111 +                       u->speed = sercmd->baud;
112 +
113 +                       tcflush(fd, TCIOFLUSH);
114 +                       if (set_speed(fd, ti, sercmd->baud) < 0) {
115 +                               perror("Can't set baud rate");
116 +                               return -1;
117 +                       }
118 +               }
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 */
122 +               }
123 +               else {
124 +                       fprintf( stderr, "BTS action type = %d: ", (int)atype );
125 +                       for (i=0; i<count; i++) {
126 +                               fprintf( stderr, "0x%02x ", actionbuf[i] );
127 +                       }
128 +                       fprintf( stderr, "\n" );
129 +               }
130 +       }
131 +       bts_unload_script( bfp );
132 +       return 0;
133 +}
134 +
135  static int texas(int fd, struct uart_t *u, struct termios *ti)
136  {
137         struct timespec tm = {0, 50000};
138 @@ -281,14 +392,25 @@
139         } while (resp[4] != cmd[1] && resp[5] != cmd[2]);
140  
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");
145  
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]);
149  
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) {
154 +               int err;
155 +               nanosleep(&tm, NULL);
156 +
157 +               /* BRF6150 */
158 +               if ((err=brf6150( fd, u, ti )) != 0) {
159 +                       fprintf( stderr, "TI script failed (err=%d)\n",
160 +                               err );
161 +                       return -1;
162 +               }
163 +       }
164         
165         nanosleep(&tm, NULL);
166         return 0;
167 @@ -953,7 +1075,7 @@
168  {
169         printf("hciattach - HCI UART driver initialization utility\n");
170         printf("Usage:\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");
174  }
175  
176 @@ -970,11 +1092,12 @@
177         pid_t pid;
178         struct sigaction sa;
179         char dev[PATH_MAX];
180 +       char *bts = NULL;
181  
182         detach = 1;
183         printpid = 0;
184         
185 -       while ((opt=getopt(argc, argv, "bnpt:s:l")) != EOF) {
186 +       while ((opt=getopt(argc, argv, "bnpt:s:S:l")) != EOF) {
187                 switch(opt) {
188                 case 'b':
189                         send_break = 1;
190 @@ -996,6 +1119,10 @@
191                         init_speed = atoi(optarg);
192                         break;
193  
194 +               case 'S':
195 +                       bts = optarg;
196 +                       break;
197 +
198                 case 'l':
199                         for (i = 0; uart[i].type; i++) {
200                                 printf("%-10s0x%04x,0x%04x\n", uart[i].type,
201 @@ -1067,6 +1194,8 @@
202         if (init_speed)
203                 u->init_speed = init_speed;
204  
205 +       u->bts = bts;
206 +
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
212 @@ -37,6 +37,9 @@
213  
214  noinst_PROGRAMS = hcisecfilter ppporc
215  
216 +hciattach_SOURCES = hciattach.c ti_bts.h ti_bts.c
217 +hciattach_LDADD = @BLUEZ_LIBS@
218
219  hciconfig_SOURCES = hciconfig.c csr.h csr.c
220  hciconfig_LDADD = @BLUEZ_LIBS@ $(top_builddir)/common/libtextfile.a
221  
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
224 @@ -0,0 +1,116 @@
225 +/*
226 + * Copyright (c) 2005 Texas Instruments, Inc.
227 + *    Ported by SDG Systems, LLC
228 + *
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;
232 + *
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.
241 + *
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.
245 + *
246 + */
247 +
248 +#ifndef BT_SCRIPT_H
249 +#define BT_SCRIPT_H
250 +
251 +#ifdef __cplusplus
252 +extern "C" {
253 +#endif
254 +
255 +/*
256 + * Define the interface of Bluetooth Script
257 + */
258 +
259 +typedef void bts_t;
260 +
261 +
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
268 +
269 +/*
270 + * Structure for ACTION_SEND_COMMAND
271 + */
272 +typedef struct tagCActionCommand
273 +{
274 +    unsigned char data[1]; /* Data to send */
275 +} action_command_t;
276 +
277 +/*
278 + * Structure for ACTION_WAIT_EVENT
279 + */
280 +typedef struct tagCActionWaitEvent
281 +{
282 +    unsigned long msec; /* in milliseconds */
283 +    unsigned long size;
284 +    unsigned char data[1]; /* Data to wait for */
285 +} action_wait_t;
286 +
287 +
288 +/*
289 + * Structure for ACTION_SERIAL_PORT_PARAMETERS
290 + */
291 +typedef struct tagCActionSerialPortParameters
292 +{
293 +    unsigned long baud;
294 +    unsigned long flow_control;
295 +} action_serial_t;
296 +
297 +/* Flow Control Type */
298 +#define FCT_NONE        0
299 +#define FCT_HARDWARE    1
300 +
301 +#define DONT_CHANGE     0xFFFFFFFF  /* For both baud rate and flow control */
302 +
303 +
304 +/*
305 + * Structure for ACTION_DELAY
306 + */
307 +typedef struct tagCActionDelay
308 +{
309 +    unsigned long msec; /* in milliseconds */
310 +} action_delay_t;
311 +
312 +/*
313 + * Structure for ACTION_RUN_SCRIPT
314 + */
315 +typedef struct tagCActionRunScript
316 +{
317 +    char filename[1];
318 +} action_run_t;
319 +
320 +/*
321 + * Structure for ACTION_REMARKS
322 + */
323 +typedef struct tagCActionRemarks
324 +{
325 +    char m_szRemarks[1];
326 +} action_remarks_t;
327 +
328 +
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);
334 +
335 +#ifdef __cplusplus
336 +};
337 +#endif
338 +
339 +#endif /* BT_SCRIPT_H */
340 +
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
343 @@ -0,0 +1,149 @@
344 +/*
345 + * Copyright (c) 2005 Texas Instruments, Inc.
346 + *    Ported by SDG Systems, LLC
347 + *
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;
351 + *
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.
360 + *
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.
364 + *
365 + */
366 +
367 +
368 +#include <stdio.h>
369 +#include <stdlib.h>
370 +#include "ti_bts.h"
371 +
372 +#ifndef MAKEWORD
373 +#define MAKEWORD(a, b)      ((unsigned short)(((unsigned char)(a)) | ((unsigned short)((unsigned char)(b))) << 8))
374 +#endif
375 +
376 +#define TI_MANUFACTURER_ID  13
377 +
378 +/*
379 + * Common Init Script specific
380 + */
381 +const char *
382 +cis_create_filename(const unsigned char* cmdparms)
383 +{
384 +    static char bts_file[50];
385 +
386 +    /* Check for TI's id */
387 +    unsigned short manfid = MAKEWORD(cmdparms[8], cmdparms[9]);
388 +
389 +    if (TI_MANUFACTURER_ID == manfid) {
390 +        unsigned short version = MAKEWORD(cmdparms[10], cmdparms[11]);
391 +        
392 +        unsigned short chip =  (version & 0x7C00) >> 10;
393 +        unsigned short min_ver = (version & 0x007F);
394 +        unsigned short maj_ver = (version & 0x0380) >> 7;
395 +
396 +        if (0 != (version & 0x8000)) {
397 +            maj_ver |= 0x0008;
398 +        }
399 +        
400 +        sprintf( bts_file, "TIInit_%d.%d.%d.bts", 
401 +            (int)chip, (int)maj_ver, (int)min_ver);
402 +
403 +        return &bts_file[0];
404 +    }
405 +    return NULL;
406 +}
407 +
408 +typedef struct tagCHeader 
409 +{
410 +    unsigned long magic;
411 +    unsigned long version;
412 +    unsigned char future[24];
413 +} cheader_t;
414 +
415 +
416 +/* The value 0x42535442 stands for (in ASCII) BTSB */
417 +/* which is Bluetooth Script Binary */
418 +#define FILE_HEADER_MAGIC   0x42535442
419 +
420 +
421 +bts_t *
422 +bts_load_script(const char* fname, unsigned long* version)
423 +{
424 +    bts_t* bts = NULL;
425 +    FILE* fp = fopen(fname, "rb");
426 +
427 +    if (NULL != fp) {
428 +        /* Read header */
429 +        cheader_t header;
430 +
431 +        /* Read header */
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;
438 +                }
439 +                bts = (bts_t*)fp;
440 +            }
441 +        }
442 +        /* If failed reading the file, close it */
443 +        if (NULL == bts) {
444 +            fclose(fp);
445 +        }
446 +    }
447 +    return bts;
448 +}
449 +
450 +unsigned long
451 +bts_next_action(const bts_t* bts_fp, unsigned char* action_buf,
452 +    unsigned long nMaxSize, unsigned short* ptype)
453 +{
454 +    unsigned long bytes = 0;
455 +    FILE* fp = (FILE*)bts_fp;
456 +    unsigned char action_hdr[4];
457 +
458 +    if (bts_fp == NULL)
459 +        return 0;
460 +
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) */
465 +
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];
469 +
470 +        if (size <= nMaxSize) {
471 +            int nread = fread(action_buf, sizeof(action_buf[0]), size, fp);
472 +
473 +            if (nread == size) {
474 +                *ptype = type;
475 +                bytes = (unsigned long)size;
476 +            }
477 +        }
478 +    }
479 +
480 +    return bytes;
481 +}
482 +
483 +void
484 +bts_unload_script(bts_t* bts_fp)
485 +{
486 +    FILE* fp = (FILE*)bts_fp;
487 +
488 +    if (NULL != fp) {
489 +        fclose(fp);
490 +    }
491 +}
492 +