summaryrefslogtreecommitdiffstats
path: root/meta/packages/bluez/files/hciattach-ti-bts.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/packages/bluez/files/hciattach-ti-bts.patch')
-rw-r--r--meta/packages/bluez/files/hciattach-ti-bts.patch489
1 files changed, 489 insertions, 0 deletions
diff --git a/meta/packages/bluez/files/hciattach-ti-bts.patch b/meta/packages/bluez/files/hciattach-ti-bts.patch
new file mode 100644
index 0000000000..8fe37de9d3
--- /dev/null
+++ b/meta/packages/bluez/files/hciattach-ti-bts.patch
@@ -0,0 +1,489 @@
1--- bluez-utils-2.24/tools/hciattach.c.orig 2005-12-10 15:14:36.000000000 +0100
2+++ bluez-utils-2.24/tools/hciattach.c 2006-01-22 13:56:13.000000000 +0100
3@@ -57,6 +57,8 @@
4 #define HCI_UART_3WIRE 2
5 #define HCI_UART_H4DS 3
6
7+#include "ti_bts.h"
8+
9 struct uart_t {
10 char *type;
11 int m_id;
12@@ -66,6 +68,7 @@
13 int speed;
14 int flags;
15 int (*init) (int fd, struct uart_t *u, struct termios *ti);
16+ char *bts; /* bluetooth script */
17 };
18
19 #define FLOW_CTL 0x0001
20@@ -241,6 +244,114 @@
21 return 0;
22 }
23
24+static int brf6150(int fd, struct uart_t *u, struct termios *ti)
25+{
26+ bts_t *bfp;
27+ int i;
28+ unsigned long vers;
29+ unsigned char actionbuf[256];
30+ unsigned char resp[128]; /* Response */
31+ unsigned long count;
32+ unsigned short atype;
33+
34+ if (u->bts == NULL) /* no script, ignore */
35+ return 0;
36+
37+ bfp = bts_load_script( u->bts, &vers );
38+ if (bfp == NULL)
39+ return -1;
40+
41+ fprintf( stderr, "Loading BTS script version %lu\n", vers );
42+
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 );
48+ }
49+ else if (atype == ACTION_SEND_COMMAND) {
50+#if 0
51+ fprintf( stderr, "ACTION_SEND_COMMAND: ", (int)atype );
52+ for (i=0; i<count; i++) {
53+ fprintf( stderr, "0x%02x ", actionbuf[i] );
54+ }
55+ fprintf( stderr, "\n" );
56+#endif
57+ int n;
58+ n = write(fd, actionbuf, count);
59+ if (n < 0 || n < count) {
60+ perror("Failed to write TI action command");
61+ return -1;
62+ }
63+ }
64+ else if (atype == ACTION_WAIT_EVENT) {
65+ action_wait_t *wait = (action_wait_t *)actionbuf;
66+#if 0
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] );
70+ }
71+ fprintf( stderr, "\n" );
72+#endif
73+ usleep(wait->msec); /* seems they give usec, not msec */
74+ /* Read reply. */
75+ if ((count = read_hci_event(fd, resp, sizeof resp)) < 0) {
76+ perror("Failed to read TI command response");
77+ return -1;
78+ }
79+ if (count < wait->size) {
80+ fprintf( stderr, "TI command response is short.");
81+ }
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" );
86+ }
87+ }
88+ }
89+ else if (atype == ACTION_SERIAL_PORT_PARAMETERS) {
90+ action_serial_t *sercmd = (action_serial_t *)actionbuf;
91+
92+ /* Set actual baudrate */
93+ fprintf( stderr,
94+ "BTS changing baud rate to %u, flow control to %u\n",
95+ sercmd->baud, sercmd->flow_control );
96+
97+ tcflush(fd, TCIOFLUSH);
98+
99+ if (sercmd->flow_control)
100+ ti->c_cflag |= CRTSCTS;
101+ else
102+ ti->c_cflag &= ~CRTSCTS;
103+ if (tcsetattr(fd, TCSANOW, ti) < 0) {
104+ perror("Can't set port settings");
105+ return -1;
106+ }
107+
108+ u->speed = sercmd->baud;
109+
110+ tcflush(fd, TCIOFLUSH);
111+ if (set_speed(fd, ti, sercmd->baud) < 0) {
112+ perror("Can't set baud rate");
113+ return -1;
114+ }
115+ }
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 */
119+ }
120+ else {
121+ fprintf( stderr, "BTS action type = %d: ", (int)atype );
122+ for (i=0; i<count; i++) {
123+ fprintf( stderr, "0x%02x ", actionbuf[i] );
124+ }
125+ fprintf( stderr, "\n" );
126+ }
127+ }
128+ bts_unload_script( bfp );
129+ return 0;
130+}
131+
132 static int texas(int fd, struct uart_t *u, struct termios *ti)
133 {
134 struct timespec tm = {0, 50000};
135@@ -281,14 +392,25 @@
136 } while (resp[4] != cmd[1] && resp[5] != cmd[2]);
137
138 /* Verify manufacturer */
139- if ((resp[11] & 0xFF) != 0x0d)
140+ if (resp[11] != 0x0d)
141 fprintf(stderr,"WARNING : module's manufacturer is not Texas Instrument\n");
142
143 /* Print LMP version */
144- fprintf(stderr, "Texas module LMP version : 0x%02x\n", resp[10] & 0xFF);
145+ fprintf(stderr, "TI module LMP version : 0x%02x\n", resp[10]);
146
147 /* Print LMP subversion */
148- fprintf(stderr, "Texas module LMP sub-version : 0x%02x%02x\n", resp[14] & 0xFF, resp[13] & 0xFF);
149+ fprintf(stderr, "TI module LMP sub-version : 0x%02x%02x\n", resp[14], resp[13]);
150+ if ((resp[14] >> 2) == 3) {
151+ int err;
152+ nanosleep(&tm, NULL);
153+
154+ /* BRF6150 */
155+ if ((err=brf6150( fd, u, ti )) != 0) {
156+ fprintf( stderr, "TI script failed (err=%d)\n",
157+ err );
158+ return -1;
159+ }
160+ }
161
162 nanosleep(&tm, NULL);
163 return 0;
164@@ -953,7 +1075,7 @@
165 {
166 printf("hciattach - HCI UART driver initialization utility\n");
167 printf("Usage:\n");
168- printf("\thciattach [-n] [-p] [-b] [-t timeout] [-s initial_speed] <tty> <type | id> [speed] [flow|noflow]\n");
169+ printf("\thciattach [-n] [-p] [-b] [-t timeout] [-s initial_speed] [-S bts-script] <tty> <type | id> [speed] [flow|noflow]\n");
170 printf("\thciattach -l\n");
171 }
172
173@@ -970,11 +1092,12 @@
174 pid_t pid;
175 struct sigaction sa;
176 char dev[PATH_MAX];
177+ char *bts = NULL;
178
179 detach = 1;
180 printpid = 0;
181
182- while ((opt=getopt(argc, argv, "bnpt:s:l")) != EOF) {
183+ while ((opt=getopt(argc, argv, "bnpt:s:S:l")) != EOF) {
184 switch(opt) {
185 case 'b':
186 send_break = 1;
187@@ -996,6 +1119,10 @@
188 init_speed = atoi(optarg);
189 break;
190
191+ case 'S':
192+ bts = optarg;
193+ break;
194+
195 case 'l':
196 for (i = 0; uart[i].type; i++) {
197 printf("%-10s0x%04x,0x%04x\n", uart[i].type,
198@@ -1067,6 +1194,8 @@
199 if (init_speed)
200 u->init_speed = init_speed;
201
202+ u->bts = bts;
203+
204 memset(&sa, 0, sizeof(sa));
205 sa.sa_flags = SA_NOCLDSTOP;
206 sa.sa_handler = sig_alarm;
207--- bluez-utils-2.24/tools/Makefile.am.orig 2005-12-03 07:22:16.000000000 +0100
208+++ bluez-utils-2.24/tools/Makefile.am 2006-01-22 13:53:59.000000000 +0100
209@@ -37,6 +37,9 @@
210
211 noinst_PROGRAMS = hcisecfilter ppporc
212
213+hciattach_SOURCES = hciattach.c ti_bts.h ti_bts.c
214+hciattach_LDADD = @BLUEZ_LIBS@
215+
216 hciconfig_SOURCES = hciconfig.c csr.h csr.c
217 hciconfig_LDADD = @BLUEZ_LIBS@ $(top_builddir)/common/libtextfile.a
218
219--- bluez-utils-2.24/tools/ti_bts.h.orig 2006-01-22 13:56:38.000000000 +0100
220+++ bluez-utils-2.24/tools/ti_bts.h 2006-01-22 13:53:59.000000000 +0100
221@@ -0,0 +1,116 @@
222+/*
223+ * Copyright (c) 2005 Texas Instruments, Inc.
224+ * Ported by SDG Systems, LLC
225+ *
226+ * This program is free software; you can redistribute it and/or modify
227+ * it under the terms of the GNU General Public License version 2 as
228+ * published by the Free Software Foundation;
229+ *
230+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
231+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
232+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
233+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
234+ * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
235+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
236+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
237+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
238+ *
239+ * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
240+ * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
241+ * SOFTWARE IS DISCLAIMED.
242+ *
243+ */
244+
245+#ifndef BT_SCRIPT_H
246+#define BT_SCRIPT_H
247+
248+#ifdef __cplusplus
249+extern "C" {
250+#endif
251+
252+/*
253+ * Define the interface of Bluetooth Script
254+ */
255+
256+typedef void bts_t;
257+
258+
259+#define ACTION_SEND_COMMAND 1 /* Send out raw data (as is) */
260+#define ACTION_WAIT_EVENT 2 /* Wait for data */
261+#define ACTION_SERIAL_PORT_PARAMETERS 3
262+#define ACTION_DELAY 4
263+#define ACTION_RUN_SCRIPT 5
264+#define ACTION_REMARKS 6
265+
266+/*
267+ * Structure for ACTION_SEND_COMMAND
268+ */
269+typedef struct tagCActionCommand
270+{
271+ unsigned char data[1]; /* Data to send */
272+} action_command_t;
273+
274+/*
275+ * Structure for ACTION_WAIT_EVENT
276+ */
277+typedef struct tagCActionWaitEvent
278+{
279+ unsigned long msec; /* in milliseconds */
280+ unsigned long size;
281+ unsigned char data[1]; /* Data to wait for */
282+} action_wait_t;
283+
284+
285+/*
286+ * Structure for ACTION_SERIAL_PORT_PARAMETERS
287+ */
288+typedef struct tagCActionSerialPortParameters
289+{
290+ unsigned long baud;
291+ unsigned long flow_control;
292+} action_serial_t;
293+
294+/* Flow Control Type */
295+#define FCT_NONE 0
296+#define FCT_HARDWARE 1
297+
298+#define DONT_CHANGE 0xFFFFFFFF /* For both baud rate and flow control */
299+
300+
301+/*
302+ * Structure for ACTION_DELAY
303+ */
304+typedef struct tagCActionDelay
305+{
306+ unsigned long msec; /* in milliseconds */
307+} action_delay_t;
308+
309+/*
310+ * Structure for ACTION_RUN_SCRIPT
311+ */
312+typedef struct tagCActionRunScript
313+{
314+ char filename[1];
315+} action_run_t;
316+
317+/*
318+ * Structure for ACTION_REMARKS
319+ */
320+typedef struct tagCActionRemarks
321+{
322+ char m_szRemarks[1];
323+} action_remarks_t;
324+
325+
326+const char *cis_create_filename(const unsigned char* cmdparms);
327+bts_t * bts_load_script(const char* fname, unsigned long* version);
328+unsigned long bts_next_action(const bts_t* bts_fp, unsigned char* action_buf,
329+ unsigned long nMaxSize, unsigned short* ptype);
330+void bts_unload_script(bts_t* bts_fp);
331+
332+#ifdef __cplusplus
333+};
334+#endif
335+
336+#endif /* BT_SCRIPT_H */
337+
338--- bluez-utils-2.24/tools/ti_bts.c.orig 2006-01-22 13:56:36.000000000 +0100
339+++ bluez-utils-2.24/tools/ti_bts.c 2006-01-22 13:56:31.000000000 +0100
340@@ -0,0 +1,149 @@
341+/*
342+ * Copyright (c) 2005 Texas Instruments, Inc.
343+ * Ported by SDG Systems, LLC
344+ *
345+ * This program is free software; you can redistribute it and/or modify
346+ * it under the terms of the GNU General Public License version 2 as
347+ * published by the Free Software Foundation;
348+ *
349+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
350+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
351+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
352+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
353+ * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
354+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
355+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
356+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
357+ *
358+ * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
359+ * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
360+ * SOFTWARE IS DISCLAIMED.
361+ *
362+ */
363+
364+
365+#include <stdio.h>
366+#include <stdlib.h>
367+#include "ti_bts.h"
368+
369+#ifndef MAKEWORD
370+#define MAKEWORD(a, b) ((unsigned short)(((unsigned char)(a)) | ((unsigned short)((unsigned char)(b))) << 8))
371+#endif
372+
373+#define TI_MANUFACTURER_ID 13
374+
375+/*
376+ * Common Init Script specific
377+ */
378+const char *
379+cis_create_filename(const unsigned char* cmdparms)
380+{
381+ static char bts_file[50];
382+
383+ /* Check for TI's id */
384+ unsigned short manfid = MAKEWORD(cmdparms[8], cmdparms[9]);
385+
386+ if (TI_MANUFACTURER_ID == manfid) {
387+ unsigned short version = MAKEWORD(cmdparms[10], cmdparms[11]);
388+
389+ unsigned short chip = (version & 0x7C00) >> 10;
390+ unsigned short min_ver = (version & 0x007F);
391+ unsigned short maj_ver = (version & 0x0380) >> 7;
392+
393+ if (0 != (version & 0x8000)) {
394+ maj_ver |= 0x0008;
395+ }
396+
397+ sprintf( bts_file, "TIInit_%d.%d.%d.bts",
398+ (int)chip, (int)maj_ver, (int)min_ver);
399+
400+ return &bts_file[0];
401+ }
402+ return NULL;
403+}
404+
405+typedef struct tagCHeader
406+{
407+ unsigned long magic;
408+ unsigned long version;
409+ unsigned char future[24];
410+} cheader_t;
411+
412+
413+/* The value 0x42535442 stands for (in ASCII) BTSB */
414+/* which is Bluetooth Script Binary */
415+#define FILE_HEADER_MAGIC 0x42535442
416+
417+
418+bts_t *
419+bts_load_script(const char* fname, unsigned long* version)
420+{
421+ bts_t* bts = NULL;
422+ FILE* fp = fopen(fname, "rb");
423+
424+ if (NULL != fp) {
425+ /* Read header */
426+ cheader_t header;
427+
428+ /* Read header */
429+ if (1 == fread(&header, sizeof(header), 1, fp)) {
430+ /* Check magic number for correctness */
431+ if (header.magic == FILE_HEADER_MAGIC) {
432+ /* If user wants the version number */
433+ if (NULL != version) {
434+ *version = header.version;
435+ }
436+ bts = (bts_t*)fp;
437+ }
438+ }
439+ /* If failed reading the file, close it */
440+ if (NULL == bts) {
441+ fclose(fp);
442+ }
443+ }
444+ return bts;
445+}
446+
447+unsigned long
448+bts_next_action(const bts_t* bts_fp, unsigned char* action_buf,
449+ unsigned long nMaxSize, unsigned short* ptype)
450+{
451+ unsigned long bytes = 0;
452+ FILE* fp = (FILE*)bts_fp;
453+ unsigned char action_hdr[4];
454+
455+ if (bts_fp == NULL)
456+ return 0;
457+
458+ /* Each Action has the following: */
459+ /* UINT16 type of this action */
460+ /* UINT16 size of rest */
461+ /* BYTE[] action buffer (for HCI, includes the type byte e.g. 1 for hci command) */
462+
463+ if (1 == fread(&action_hdr[0], sizeof(action_hdr), 1, fp)) {
464+ unsigned short type = *(unsigned short*)&action_hdr[0];
465+ unsigned short size = *(unsigned short*)&action_hdr[2];
466+
467+ if (size <= nMaxSize) {
468+ int nread = fread(action_buf, sizeof(action_buf[0]), size, fp);
469+
470+ if (nread == size) {
471+ *ptype = type;
472+ bytes = (unsigned long)size;
473+ }
474+ }
475+ }
476+
477+ return bytes;
478+}
479+
480+void
481+bts_unload_script(bts_t* bts_fp)
482+{
483+ FILE* fp = (FILE*)bts_fp;
484+
485+ if (NULL != fp) {
486+ fclose(fp);
487+ }
488+}
489+