From f8a36952f39f2c51d4cd6f2e170817d89724c422 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 20 Mar 2006 22:32:32 +0000 Subject: Add skeleton for ST Microelectronics init routine --- tools/hciattach_st.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tools/hciattach_st.c (limited to 'tools/hciattach_st.c') diff --git a/tools/hciattach_st.c b/tools/hciattach_st.c new file mode 100644 index 00000000..db73cfb5 --- /dev/null +++ b/tools/hciattach_st.c @@ -0,0 +1,29 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2005-2006 Marcel Holtmann + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include -- cgit From ae2bada6379b2d56825f0d8cc48dbd9a1890a1bd Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 16 Apr 2006 21:09:01 +0000 Subject: Update STLC2500 init routine --- tools/hciattach_st.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tools/hciattach_st.c') diff --git a/tools/hciattach_st.c b/tools/hciattach_st.c index db73cfb5..744ae838 100644 --- a/tools/hciattach_st.c +++ b/tools/hciattach_st.c @@ -27,3 +27,8 @@ #include #include + +int stlc2500_init(int fd) +{ + return 0; +} -- cgit From 0bf26d618424720586e0013256bdc39803c90c4a Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 16 Apr 2006 22:04:19 +0000 Subject: Update STLC2500 init routine --- tools/hciattach_st.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'tools/hciattach_st.c') diff --git a/tools/hciattach_st.c b/tools/hciattach_st.c index 744ae838..98179d71 100644 --- a/tools/hciattach_st.c +++ b/tools/hciattach_st.c @@ -27,8 +27,78 @@ #include #include +#include +#include +#include +#include + +static int do_command(int fd, uint8_t ogf, uint16_t ocf, + uint8_t *cparam, int clen, uint8_t *rparam, int rlen) +{ + uint16_t opcode = (uint16_t) ((ocf & 0x03ff) | (ogf << 10)); + unsigned char cp[254], rp[254]; + int len, size, offset = 3; + + memset(cp, 0, sizeof(cp)); + cp[0] = 0x01; + cp[1] = opcode & 0xff; + cp[2] = opcode >> 8; + cp[3] = 0x00; + + if (write(fd, cp, 4) < 0) + return -1; + + do { + if (read(fd, rp, 1) < 1) + return -1; + } while (rp[0] != 0x04); + + if (read(fd, rp + 1, 2) < 2) + return -1; + + do { + len = read(fd, rp + offset, sizeof(rp) - offset); + offset += len; + } while (offset < rp[2] + 3); + + if (rp[0] != 0x04) { + errno = EIO; + return -1; + } + + switch (rp[1]) { + case 0x0e: + if (rp[6] != 0x00) + return -ENXIO; + offset = 3 + 4; + size = rp[2] - 4; + break; + default: + offset = 3; + size = rp[2]; + break; + } + + if (!rparam || rlen < size) + return -ENXIO; + + memcpy(rparam, rp + offset, size); + + return size; +} int stlc2500_init(int fd) { + unsigned char buf[254]; + int len; + + len = do_command(fd, 0x04, 0x0001, NULL, 0, buf, sizeof(buf)); + + //printf("STLC2500 R%d.%d\n", buf[2], buf[1]); + + len = do_command(fd, 0xff, 0x000f, NULL, 0, buf, sizeof(buf)); + + printf("%s\n", buf + 3); + return 0; } -- cgit From 892ff56030437019d237cd33b1434592c48c7df3 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 17 Apr 2006 01:13:57 +0000 Subject: Change device address and reset --- tools/hciattach_st.c | 54 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 9 deletions(-) (limited to 'tools/hciattach_st.c') diff --git a/tools/hciattach_st.c b/tools/hciattach_st.c index 98179d71..ee3ca2a7 100644 --- a/tools/hciattach_st.c +++ b/tools/hciattach_st.c @@ -32,20 +32,32 @@ #include #include +static int debug = 0; + static int do_command(int fd, uint8_t ogf, uint16_t ocf, uint8_t *cparam, int clen, uint8_t *rparam, int rlen) { - uint16_t opcode = (uint16_t) ((ocf & 0x03ff) | (ogf << 10)); + //uint16_t opcode = (uint16_t) ((ocf & 0x03ff) | (ogf << 10)); unsigned char cp[254], rp[254]; int len, size, offset = 3; - memset(cp, 0, sizeof(cp)); cp[0] = 0x01; - cp[1] = opcode & 0xff; - cp[2] = opcode >> 8; - cp[3] = 0x00; + cp[1] = ocf & 0xff; + cp[2] = ogf << 2 | ocf >> 8; + cp[3] = clen; + + if (clen > 0) + memcpy(cp + 4, cparam, clen); + + if (debug) { + int i; + printf("[<"); + for (i = 0; i < clen + 4; i++) + printf(" %02x", cp[i]); + printf("]\n"); + } - if (write(fd, cp, 4) < 0) + if (write(fd, cp, clen + 4) < 0) return -1; do { @@ -61,18 +73,28 @@ static int do_command(int fd, uint8_t ogf, uint16_t ocf, offset += len; } while (offset < rp[2] + 3); + if (debug) { + int i; + printf("[>"); + for (i = 0; i < offset; i++) + printf(" %02x", rp[i]); + printf("]\n"); + } + if (rp[0] != 0x04) { errno = EIO; return -1; } switch (rp[1]) { - case 0x0e: + case 0x0e: /* command complete */ if (rp[6] != 0x00) return -ENXIO; offset = 3 + 4; size = rp[2] - 4; break; + case 0x0f: /* command status */ + /* fall through */ default: offset = 3; size = rp[2]; @@ -89,16 +111,30 @@ static int do_command(int fd, uint8_t ogf, uint16_t ocf, int stlc2500_init(int fd) { + unsigned char cmd[16]; unsigned char buf[254]; int len; len = do_command(fd, 0x04, 0x0001, NULL, 0, buf, sizeof(buf)); - //printf("STLC2500 R%d.%d\n", buf[2], buf[1]); + printf("Patch: STLC2500_R%d_%02d_*.ptc\n", buf[2], buf[1]); len = do_command(fd, 0xff, 0x000f, NULL, 0, buf, sizeof(buf)); - printf("%s\n", buf + 3); + printf("%s\n", buf); + + cmd[0] = 0xfe; + cmd[1] = 0x06; + cmd[2] = 0xba; + cmd[3] = 0xab; + cmd[4] = 0x00; + cmd[5] = 0xe1; + cmd[6] = 0x80; + cmd[7] = 0x00; + + len = do_command(fd, 0xff, 0x0022, cmd, 8, buf, sizeof(buf)); + + len = do_command(fd, 0x03, 0x0003, NULL, 0, buf, sizeof(buf)); return 0; } -- cgit From d168dc64106e440a149718436e63912b18e0064e Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 18 Apr 2006 00:49:40 +0000 Subject: Add patch and configuration download --- tools/hciattach_st.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 100 insertions(+), 7 deletions(-) (limited to 'tools/hciattach_st.c') diff --git a/tools/hciattach_st.c b/tools/hciattach_st.c index ee3ca2a7..0279d398 100644 --- a/tools/hciattach_st.c +++ b/tools/hciattach_st.c @@ -29,8 +29,10 @@ #include #include #include +#include #include #include +#include static int debug = 0; @@ -38,7 +40,7 @@ static int do_command(int fd, uint8_t ogf, uint16_t ocf, uint8_t *cparam, int clen, uint8_t *rparam, int rlen) { //uint16_t opcode = (uint16_t) ((ocf & 0x03ff) | (ogf << 10)); - unsigned char cp[254], rp[254]; + unsigned char cp[260], rp[260]; int len, size, offset = 3; cp[0] = 0x01; @@ -109,17 +111,104 @@ static int do_command(int fd, uint8_t ogf, uint16_t ocf, return size; } -int stlc2500_init(int fd) +static int load_file(int dd, uint16_t version, const char *suffix) +{ + DIR *dir; + struct dirent *d; + char filename[NAME_MAX], prefix[20]; + unsigned char cmd[256]; + unsigned char buf[256]; + uint8_t seqnum = 0; + int fd, size, len; + + memset(filename, 0, sizeof(filename)); + + snprintf(prefix, sizeof(prefix), "STLC2500_R%d_%02d_", + version >> 8, version & 0xff); + + dir = opendir("."); + if (!dir) + return -errno; + + while (1) { + d = readdir(dir); + if (!d) + break; + + if (strncmp(d->d_name + strlen(d->d_name) - strlen(suffix), + suffix, strlen(suffix))) + continue; + + if (strncmp(d->d_name, prefix, strlen(prefix))) + continue; + + snprintf(filename, sizeof(filename), "%s", d->d_name); + } + + closedir(dir); + + printf("Loading file %s\n", filename); + + fd = open(filename, O_RDONLY); + if (fd < 0) { + perror("Can't open firmware file"); + return -errno; + } + + while (1) { + size = read(fd, cmd + 1, 254); + if (size <= 0) + break; + + cmd[0] = seqnum; + + len = do_command(dd, 0xff, 0x002e, cmd, size + 1, buf, sizeof(buf)); + if (len < 1) + break; + + if (buf[0] != seqnum) { + fprintf(stderr, "Sequence number mismatch\n"); + break; + } + + seqnum++; + } + + close(fd); + + return 0; +} + +int stlc2500_init(int dd) { unsigned char cmd[16]; unsigned char buf[254]; + uint16_t version; int len; - len = do_command(fd, 0x04, 0x0001, NULL, 0, buf, sizeof(buf)); + len = do_command(dd, 0x04, 0x0001, NULL, 0, buf, sizeof(buf)); + if (len < 0) + return -1; + + version = buf[2] << 8 | buf[1]; + + if (load_file(dd, version, ".ptc") < 0) + return -1; - printf("Patch: STLC2500_R%d_%02d_*.ptc\n", buf[2], buf[1]); + len = do_command(dd, 0x03, 0x0003, NULL, 0, buf, sizeof(buf)); + if (len < 0) + return -1; - len = do_command(fd, 0xff, 0x000f, NULL, 0, buf, sizeof(buf)); + if (load_file(dd, buf[2] << 8 | buf[1], ".ssf") < 0) + return -1; + + len = do_command(dd, 0x03, 0x0003, NULL, 0, buf, sizeof(buf)); + if (len < 0) + return -1; + + len = do_command(dd, 0xff, 0x000f, NULL, 0, buf, sizeof(buf)); + if (len < 0) + return -1; printf("%s\n", buf); @@ -132,9 +221,13 @@ int stlc2500_init(int fd) cmd[6] = 0x80; cmd[7] = 0x00; - len = do_command(fd, 0xff, 0x0022, cmd, 8, buf, sizeof(buf)); + len = do_command(dd, 0xff, 0x0022, cmd, 8, buf, sizeof(buf)); + if (len < 0) + return -1; - len = do_command(fd, 0x03, 0x0003, NULL, 0, buf, sizeof(buf)); + len = do_command(dd, 0x03, 0x0003, NULL, 0, buf, sizeof(buf)); + if (len < 0) + return -1; return 0; } -- cgit From 99dd5f8c7549a7e7f4183bd8040c3e0e8884594f Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 4 Jun 2006 15:27:17 +0000 Subject: Load firmware files from /lib/firmware --- tools/hciattach_st.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'tools/hciattach_st.c') diff --git a/tools/hciattach_st.c b/tools/hciattach_st.c index 0279d398..46efbc2c 100644 --- a/tools/hciattach_st.c +++ b/tools/hciattach_st.c @@ -115,7 +115,7 @@ static int load_file(int dd, uint16_t version, const char *suffix) { DIR *dir; struct dirent *d; - char filename[NAME_MAX], prefix[20]; + char pathname[PATH_MAX], filename[NAME_MAX], prefix[20]; unsigned char cmd[256]; unsigned char buf[256]; uint8_t seqnum = 0; @@ -126,9 +126,14 @@ static int load_file(int dd, uint16_t version, const char *suffix) snprintf(prefix, sizeof(prefix), "STLC2500_R%d_%02d_", version >> 8, version & 0xff); - dir = opendir("."); - if (!dir) - return -errno; + strcpy(pathname, "/lib/firmware"); + dir = opendir(pathname); + if (!dir) { + strcpy(pathname, "."); + dir = opendir(pathname); + if (!dir) + return -errno; + } while (1) { d = readdir(dir); @@ -142,7 +147,8 @@ static int load_file(int dd, uint16_t version, const char *suffix) if (strncmp(d->d_name, prefix, strlen(prefix))) continue; - snprintf(filename, sizeof(filename), "%s", d->d_name); + snprintf(filename, sizeof(filename), "%s/%s", + pathname, d->d_name); } closedir(dir); -- cgit From 943b02e163e169795a010c36a3b3343cc5092a96 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 27 Jun 2006 07:33:36 +0000 Subject: Include sys/param.h for PATH_MAX when cross-compiling --- tools/hciattach_st.c | 1 + 1 file changed, 1 insertion(+) (limited to 'tools/hciattach_st.c') diff --git a/tools/hciattach_st.c b/tools/hciattach_st.c index 46efbc2c..014ddb2d 100644 --- a/tools/hciattach_st.c +++ b/tools/hciattach_st.c @@ -33,6 +33,7 @@ #include #include #include +#include static int debug = 0; -- cgit From 607695ed109340f4b7a5628420e0a8e8aee34f4e Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 13 Jan 2007 17:48:12 +0000 Subject: Update copyright information --- tools/hciattach_st.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/hciattach_st.c') diff --git a/tools/hciattach_st.c b/tools/hciattach_st.c index 014ddb2d..736597cb 100644 --- a/tools/hciattach_st.c +++ b/tools/hciattach_st.c @@ -2,7 +2,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2005-2006 Marcel Holtmann + * Copyright (C) 2005-2007 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify -- cgit From c3da6a497333f7e21007a3f23312e74464a408bf Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 17 Jan 2007 12:31:42 +0000 Subject: Add support for Philips BGB2xx modules --- tools/hciattach_st.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'tools/hciattach_st.c') diff --git a/tools/hciattach_st.c b/tools/hciattach_st.c index 736597cb..47df4fe1 100644 --- a/tools/hciattach_st.c +++ b/tools/hciattach_st.c @@ -35,6 +35,8 @@ #include #include +#include + static int debug = 0; static int do_command(int fd, uint8_t ogf, uint16_t ocf, @@ -186,7 +188,7 @@ static int load_file(int dd, uint16_t version, const char *suffix) return 0; } -int stlc2500_init(int dd) +int stlc2500_init(int dd, bdaddr_t *bdaddr) { unsigned char cmd[16]; unsigned char buf[254]; @@ -221,12 +223,34 @@ int stlc2500_init(int dd) cmd[0] = 0xfe; cmd[1] = 0x06; - cmd[2] = 0xba; - cmd[3] = 0xab; - cmd[4] = 0x00; - cmd[5] = 0xe1; - cmd[6] = 0x80; - cmd[7] = 0x00; + bacpy((bdaddr_t *) (cmd + 2), bdaddr); + + len = do_command(dd, 0xff, 0x0022, cmd, 8, buf, sizeof(buf)); + if (len < 0) + return -1; + + len = do_command(dd, 0x03, 0x0003, NULL, 0, buf, sizeof(buf)); + if (len < 0) + return -1; + + return 0; +} + +int bgb2xx_init(int dd, bdaddr_t *bdaddr) +{ + unsigned char cmd[16]; + unsigned char buf[254]; + int len; + + len = do_command(dd, 0xff, 0x000f, NULL, 0, buf, sizeof(buf)); + if (len < 0) + return -1; + + printf("%s\n", buf); + + cmd[0] = 0xfe; + cmd[1] = 0x06; + bacpy((bdaddr_t *) (cmd + 2), bdaddr); len = do_command(dd, 0xff, 0x0022, cmd, 8, buf, sizeof(buf)); if (len < 0) -- cgit From ebc48fedda3e9220862c53e2d9afe8b50f14c1a3 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 9 Oct 2007 16:51:17 +0000 Subject: Change init sequence and add comments --- tools/hciattach_st.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'tools/hciattach_st.c') diff --git a/tools/hciattach_st.c b/tools/hciattach_st.c index 47df4fe1..f2be66f5 100644 --- a/tools/hciattach_st.c +++ b/tools/hciattach_st.c @@ -195,40 +195,36 @@ int stlc2500_init(int dd, bdaddr_t *bdaddr) uint16_t version; int len; - len = do_command(dd, 0x04, 0x0001, NULL, 0, buf, sizeof(buf)); + /* Hci_Cmd_Ericsson_Read_Revision_Information */ + len = do_command(dd, 0xff, 0x000f, NULL, 0, buf, sizeof(buf)); if (len < 0) return -1; - version = buf[2] << 8 | buf[1]; - - if (load_file(dd, version, ".ptc") < 0) - return -1; + printf("%s\n", buf); - len = do_command(dd, 0x03, 0x0003, NULL, 0, buf, sizeof(buf)); + /* HCI_Read_Local_Version_Information */ + len = do_command(dd, 0x04, 0x0001, NULL, 0, buf, sizeof(buf)); if (len < 0) return -1; - if (load_file(dd, buf[2] << 8 | buf[1], ".ssf") < 0) - return -1; + version = buf[2] << 8 | buf[1]; - len = do_command(dd, 0x03, 0x0003, NULL, 0, buf, sizeof(buf)); - if (len < 0) + if (load_file(dd, version, ".ptc") < 0) return -1; - len = do_command(dd, 0xff, 0x000f, NULL, 0, buf, sizeof(buf)); - if (len < 0) + if (load_file(dd, buf[2] << 8 | buf[1], ".ssf") < 0) return -1; - printf("%s\n", buf); - cmd[0] = 0xfe; cmd[1] = 0x06; bacpy((bdaddr_t *) (cmd + 2), bdaddr); + /* Hci_Cmd_ST_Store_In_NVDS */ len = do_command(dd, 0xff, 0x0022, cmd, 8, buf, sizeof(buf)); if (len < 0) return -1; + /* HCI_Reset : applies parameters*/ len = do_command(dd, 0x03, 0x0003, NULL, 0, buf, sizeof(buf)); if (len < 0) return -1; -- cgit From bc3ec576543eac39562035172a17e7d5ad734f04 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 9 Oct 2007 16:52:48 +0000 Subject: Make firmware and paramter loading optional --- tools/hciattach_st.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'tools/hciattach_st.c') diff --git a/tools/hciattach_st.c b/tools/hciattach_st.c index f2be66f5..13c68278 100644 --- a/tools/hciattach_st.c +++ b/tools/hciattach_st.c @@ -122,7 +122,7 @@ static int load_file(int dd, uint16_t version, const char *suffix) unsigned char cmd[256]; unsigned char buf[256]; uint8_t seqnum = 0; - int fd, size, len; + int fd, size, len, found_fw_file; memset(filename, 0, sizeof(filename)); @@ -138,6 +138,7 @@ static int load_file(int dd, uint16_t version, const char *suffix) return -errno; } + found_fw_file = 0; while (1) { d = readdir(dir); if (!d) @@ -152,10 +153,14 @@ static int load_file(int dd, uint16_t version, const char *suffix) snprintf(filename, sizeof(filename), "%s/%s", pathname, d->d_name); + found_fw_file = 1; } closedir(dir); + if (!found_fw_file) + return -ENOENT; + printf("Loading file %s\n", filename); fd = open(filename, O_RDONLY); @@ -194,6 +199,7 @@ int stlc2500_init(int dd, bdaddr_t *bdaddr) unsigned char buf[254]; uint16_t version; int len; + int err; /* Hci_Cmd_Ericsson_Read_Revision_Information */ len = do_command(dd, 0xff, 0x000f, NULL, 0, buf, sizeof(buf)); @@ -209,11 +215,21 @@ int stlc2500_init(int dd, bdaddr_t *bdaddr) version = buf[2] << 8 | buf[1]; - if (load_file(dd, version, ".ptc") < 0) - return -1; + err = load_file(dd, version, ".ptc"); + if (err < 0) { + if (err == -ENOENT) + fprintf(stderr, "No ROM patch file loaded.\n"); + else + return -1; + } - if (load_file(dd, buf[2] << 8 | buf[1], ".ssf") < 0) - return -1; + err = load_file(dd, buf[2] << 8 | buf[1], ".ssf"); + if (err < 0) { + if (err == -ENOENT) + fprintf(stderr, "No static settings file loaded.\n"); + else + return -1; + } cmd[0] = 0xfe; cmd[1] = 0x06; -- cgit From e823c15e43a6f924779e466d434c51157002d9ee Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 2 Feb 2008 03:37:05 +0000 Subject: Update copyright information --- tools/hciattach_st.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/hciattach_st.c') diff --git a/tools/hciattach_st.c b/tools/hciattach_st.c index 13c68278..2c7d7438 100644 --- a/tools/hciattach_st.c +++ b/tools/hciattach_st.c @@ -2,7 +2,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2005-2007 Marcel Holtmann + * Copyright (C) 2005-2008 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify -- cgit