From: Denis KENZIOR <denis.kenzior@trolltech.com>
To: BlueZ development <bluez-devel@lists.sourceforge.net>
Subject: [Bluez-devel] [PATCH] STLC2500 Baud Rate & Address Setting
Date: Thu, 29 Mar 2007 11:23:53 +1000 [thread overview]
Message-ID: <200703291123.53675.denis.kenzior@trolltech.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 488 bytes --]
Marcel,
The following patch does two things:
- Adds support for setting the baud rate on the STLC2500.
- Adds another optional argument to hciattach for use with stlc2500/bgb2xx
devices that require initialization of the bdaddr. Basically if you specify
this option on the command line, the address specified will be used during
stlc2500/bgb2xx initialization. Otherwise a default will be used. The
manpage has been updated as well.
Let me know if there are any issues!
-Denis
[-- Attachment #2: hciattach_stlc2500.patch --]
[-- Type: text/x-diff, Size: 9937 bytes --]
Index: hciattach.8
===================================================================
RCS file: /cvsroot/bluez/utils/tools/hciattach.8,v
retrieving revision 1.4
diff -u -5 -r1.4 hciattach.8
--- hciattach.8 1 Jun 2006 18:36:20 -0000 1.4
+++ hciattach.8 29 Mar 2007 01:17:10 -0000
@@ -9,10 +9,11 @@
.IR timeout \|]
.I tty
.IR type \||\| id
.I speed
.I flow
+.I bdaddr
.SH DESCRIPTION
.LP
Hciattach is used to attach a serial UART to the Bluetooth stack as HCI
transport interface.
.SH OPTIONS
@@ -103,9 +104,19 @@
.B flow
set by default. To force no flow control use
.B noflow
instead.
+.TP
+.I bdaddr
+The
+.I bdaddr
+specifies the Bluetooth Address to use. Some devices (like the STLC2500)
+do not store the Bluetooth address in hardware memory. Instead it must
+be uploaded during the initialization process. If this argument
+is specified, then the address will be used to initialize the device.
+Otherwise, a default address will be used.
+
.SH AUTHORS
Written by Maxim Krasnyansky <maxk@qualcomm.com>
.PP
Manual page by Nils Faerber <nils@kernelconcepts.de>
Index: hciattach.c
===================================================================
RCS file: /cvsroot/bluez/utils/tools/hciattach.c,v
retrieving revision 1.43
diff -u -5 -r1.43 hciattach.c
--- hciattach.c 17 Jan 2007 12:31:42 -0000 1.43
+++ hciattach.c 29 Mar 2007 01:17:11 -0000
@@ -66,10 +66,11 @@
int proto;
int init_speed;
int speed;
int flags;
int (*init) (int fd, struct uart_t *u, struct termios *ti);
+ char *bdaddr;
};
#define FLOW_CTL 0x0001
static volatile sig_atomic_t __io_canceled = 0;
@@ -828,23 +829,98 @@
extern int stlc2500_init(int fd, bdaddr_t *bdaddr);
static int stlc2500(int fd, struct uart_t *u, struct termios *ti)
{
bdaddr_t bdaddr;
+ struct timespec tm = {0, 50000};
+ char cmd[5];
+ unsigned char resp[10];
+ int n;
+ int i;
- str2ba("00:80:E1:00:AB:BA", &bdaddr);
+ /* STLC2500 Set Baud Rate stuff */
+ /* We should set the baud rate first, so the firmware download */
+ /* goes much faster */
+
+ /* STLC2500 Seems to support the Ericsson set baud rate stuff */
+ /* It should also support the ST Set Baud Rate command */
+ /* (as in st() function above, but those commands never succeed */
+ cmd[0] = HCI_COMMAND_PKT;
+ cmd[1] = 0x09;
+ cmd[2] = 0xfc;
+ cmd[3] = 0x01;
- return stlc2500_init(fd, &bdaddr);
+ switch (u->speed) {
+ case 57600:
+ cmd[4] = 0x03;
+ break;
+ case 115200:
+ cmd[4] = 0x02;
+ break;
+ case 230400:
+ cmd[4] = 0x01;
+ break;
+ case 460800:
+ cmd[4] = 0x00;
+ break;
+ case 921600:
+ cmd[4] = 0x20;
+ break;
+ default:
+ cmd[4] = 0x02;
+ u->speed = 115200;
+ break;
+ }
+
+#ifdef STLC2500_DEBUG
+ fprintf(stderr, "Sending Baud Rate %02x\n", cmd[4]);
+#endif
+ /* Send initialization command */
+ if (write(fd, cmd, 5) != 5) {
+ perror("Failed to write init command");
+ return -1;
+ }
+
+ /* Need to wait here to give a chance for the device to set baud */
+ /* But no more than 0.5 seconds */
+ usleep(200000);
+
+#ifdef STLC2500_DEBUG
+ fprintf(stderr, "Setting speed\n");
+#endif
+ if (set_speed(fd, ti, u->speed) < 0) {
+ perror("Can't set baud rate");
+ return -1;
+ }
+
+#ifdef STLC2500_DEBUG
+ fprintf(stderr, "Speed set...\n");
+#endif
+
+ /* Read reply */
+ if ((n = read_hci_event(fd, resp, 10)) < 0) {
+ fprintf(stderr, "Failed to set baud rate on chip\n");
+ return -1;
+ }
+
+#ifdef STLC2500_DEBUG
+ for (i = 0; i < n; i++) {
+ fprintf(stderr, "resp[%d] = %02x\n", i, resp[i]);
+ }
+#endif
+
+ str2ba(u->bdaddr, &bdaddr);
+ return stlc2500_init(fd, &bdaddr, u->flags & FLOW_CTL);
}
extern int bgb2xx_init(int fd, bdaddr_t *bdaddr);
static int bgb2xx(int fd, struct uart_t *u, struct termios *ti)
{
bdaddr_t bdaddr;
- str2ba("BD:B2:10:00:AB:BA", &bdaddr);
+ str2ba(u->bdaddr, &bdaddr);
return bgb2xx_init(fd, &bdaddr);
}
/*
@@ -964,73 +1040,73 @@
return 0;
}
struct uart_t uart[] = {
- { "any", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL },
- { "ericsson", 0x0000, 0x0000, HCI_UART_H4, 57600, 115200, FLOW_CTL, ericsson },
- { "digi", 0x0000, 0x0000, HCI_UART_H4, 9600, 115200, FLOW_CTL, digi },
- { "texas", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, texas },
+ { "any", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL, NULL },
+ { "ericsson", 0x0000, 0x0000, HCI_UART_H4, 57600, 115200, FLOW_CTL, ericsson, NULL },
+ { "digi", 0x0000, 0x0000, HCI_UART_H4, 9600, 115200, FLOW_CTL, digi, NULL },
+ { "texas", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, texas, NULL },
- { "bcsp", 0x0000, 0x0000, HCI_UART_BCSP, 115200, 115200, 0, bcsp },
+ { "bcsp", 0x0000, 0x0000, HCI_UART_BCSP, 115200, 115200, 0, bcsp, NULL },
/* Xircom PCMCIA cards: Credit Card Adapter and Real Port Adapter */
- { "xircom", 0x0105, 0x080a, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL },
+ { "xircom", 0x0105, 0x080a, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL, NULL },
/* CSR Casira serial adapter or BrainBoxes serial dongle (BL642) */
- { "csr", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, csr },
+ { "csr", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, csr, NULL },
/* BrainBoxes PCMCIA card (BL620) */
- { "bboxes", 0x0160, 0x0002, HCI_UART_H4, 115200, 460800, FLOW_CTL, csr },
+ { "bboxes", 0x0160, 0x0002, HCI_UART_H4, 115200, 460800, FLOW_CTL, csr, NULL },
/* Silicon Wave kits */
- { "swave", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, swave },
+ { "swave", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, swave, NULL },
/* ST Microelectronics minikits based on STLC2410/STLC2415 */
- { "st", 0x0000, 0x0000, HCI_UART_H4, 57600, 115200, FLOW_CTL, st },
+ { "st", 0x0000, 0x0000, HCI_UART_H4, 57600, 115200, FLOW_CTL, st, NULL },
/* ST Microelectronics minikits based on STLC2500 */
- { "stlc2500", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, stlc2500 },
+ { "stlc2500", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, stlc2500, "00:80:E1:00:AB:BA" },
/* Philips generic Ericsson IP core based */
- { "philips", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL },
+ { "philips", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL, NULL },
/* Philips BGB2xx Module */
- { "bgb2xx", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, bgb2xx },
+ { "bgb2xx", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, bgb2xx, "BD:B2:10:00:AB:BA" },
/* Sphinx Electronics PICO Card */
- { "picocard", 0x025e, 0x1000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL },
+ { "picocard", 0x025e, 0x1000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL, NULL },
/* Inventel BlueBird Module */
- { "inventel", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL },
+ { "inventel", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200, FLOW_CTL, NULL, NULL },
/* COM One Platinium Bluetooth PC Card */
- { "comone", 0xffff, 0x0101, HCI_UART_BCSP, 115200, 115200, 0, bcsp },
+ { "comone", 0xffff, 0x0101, HCI_UART_BCSP, 115200, 115200, 0, bcsp, NULL },
/* TDK Bluetooth PC Card and IBM Bluetooth PC Card II */
- { "tdk", 0x0105, 0x4254, HCI_UART_BCSP, 115200, 115200, 0, bcsp },
+ { "tdk", 0x0105, 0x4254, HCI_UART_BCSP, 115200, 115200, 0, bcsp, NULL },
/* Socket Bluetooth CF Card (Rev G) */
- { "socket", 0x0104, 0x0096, HCI_UART_BCSP, 230400, 230400, 0, bcsp },
+ { "socket", 0x0104, 0x0096, HCI_UART_BCSP, 230400, 230400, 0, bcsp, NULL },
/* 3Com Bluetooth Card (Version 3.0) */
- { "3com", 0x0101, 0x0041, HCI_UART_H4, 115200, 115200, FLOW_CTL, csr },
+ { "3com", 0x0101, 0x0041, HCI_UART_H4, 115200, 115200, FLOW_CTL, csr, NULL },
/* AmbiCom BT2000C Bluetooth PC/CF Card */
- { "bt2000c", 0x022d, 0x2000, HCI_UART_H4, 57600, 460800, FLOW_CTL, csr },
+ { "bt2000c", 0x022d, 0x2000, HCI_UART_H4, 57600, 460800, FLOW_CTL, csr, NULL },
/* Zoom Bluetooth PCMCIA Card */
- { "zoom", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, bcsp },
+ { "zoom", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, bcsp, NULL },
/* Sitecom CN-504 PCMCIA Card */
- { "sitecom", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, bcsp },
+ { "sitecom", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, bcsp, NULL },
/* Billionton PCBTC1 PCMCIA Card */
- { "billionton", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, bcsp },
+ { "billionton", 0x0279, 0x950b, HCI_UART_BCSP, 115200, 115200, 0, bcsp, NULL },
/* Broadcom BCM2035 */
- { "bcm2035", 0x0A5C, 0x2035, HCI_UART_H4, 115200, 115200, 0, bcm2035 },
+ { "bcm2035", 0x0A5C, 0x2035, HCI_UART_H4, 115200, 115200, 0, bcm2035, NULL },
{ NULL, 0 }
};
struct uart_t * get_by_id(int m_id, int p_id)
@@ -1126,11 +1202,11 @@
static void usage(void)
{
printf("hciattach - HCI UART driver initialization utility\n");
printf("Usage:\n");
- printf("\thciattach [-n] [-p] [-b] [-t timeout] [-s initial_speed] <tty> <type | id> [speed] [flow|noflow]\n");
+ printf("\thciattach [-n] [-p] [-b] [-t timeout] [-s initial_speed] <tty> <type | id> [speed] [flow|noflow] [bdaddr]\n");
printf("\thciattach -l\n");
}
int main(int argc, char *argv[])
{
@@ -1225,10 +1301,14 @@
if (!strcmp("flow", argv[optind]))
u->flags |= FLOW_CTL;
else
u->flags &= ~FLOW_CTL;
break;
+
+ case 4:
+ u->bdaddr = argv[optind];
+ break;
}
}
if (!u) {
fprintf(stderr, "Unknown device type or id\n");
[-- Attachment #3: Type: text/plain, Size: 345 bytes --]
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
[-- Attachment #4: Type: text/plain, Size: 164 bytes --]
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
next reply other threads:[~2007-03-29 1:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-29 1:23 Denis KENZIOR [this message]
2007-03-31 13:50 ` [Bluez-devel] [PATCH] STLC2500 Baud Rate & Address Setting Marcel Holtmann
2007-04-01 22:59 ` Denis KENZIOR
2007-04-02 0:32 ` Marcel Holtmann
2007-04-02 4:17 ` Denis KENZIOR
-- strict thread matches above, loose matches on Subject: below --
2007-04-25 21:42 Denis KENZIOR
2007-04-25 22:38 ` Denis KENZIOR
2007-04-25 23:09 ` Marcel Holtmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200703291123.53675.denis.kenzior@trolltech.com \
--to=denis.kenzior@trolltech.com \
--cc=bluez-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.