summaryrefslogtreecommitdiffstats
path: root/tools/hciattach_st.c
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2006-04-16 22:04:19 +0000
committerMarcel Holtmann <marcel@holtmann.org>2006-04-16 22:04:19 +0000
commit0bf26d618424720586e0013256bdc39803c90c4a (patch)
tree81a606e15c0a1dea6278d3f89a3763883398c08e /tools/hciattach_st.c
parentae2bada6379b2d56825f0d8cc48dbd9a1890a1bd (diff)
Update STLC2500 init routine
Diffstat (limited to 'tools/hciattach_st.c')
-rw-r--r--tools/hciattach_st.c70
1 files changed, 70 insertions, 0 deletions
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 <stdio.h>
#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <string.h>
+
+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;
}