summaryrefslogtreecommitdiff
path: root/tools/hciattach.c
diff options
context:
space:
mode:
authorseungku kim <seungku.kim@samsung.com>2014-03-28 15:17:11 +0900
committerSebastian Chlad <sebastian.chlad@tieto.com>2014-05-27 12:25:15 +0200
commitdef3c68622ea556483d4302ec1953b2bdfffa2d3 (patch)
tree9bd6c581ba71dc17106ae61e4d70a8f8914c1ddb /tools/hciattach.c
parent717eae65ee914d61f113f0e8bd3779941f094184 (diff)
downloadbluez-def3c68622ea556483d4302ec1953b2bdfffa2d3.tar.gz
bluez-def3c68622ea556483d4302ec1953b2bdfffa2d3.tar.bz2
bluez-def3c68622ea556483d4302ec1953b2bdfffa2d3.zip
[Bluez] enable bluez for mobile environment
1. BROADCOM patchs are applied. 2. hciconfig, hciattach, hcitool, hcidump are changed. Change-Id: Ia8944ec576830308212b6d7a637152042a9be931 Signed-off-by: seungku kim <seungku.kim@samsung.com>
Diffstat (limited to 'tools/hciattach.c')
-rw-r--r--tools/hciattach.c142
1 files changed, 141 insertions, 1 deletions
diff --git a/tools/hciattach.c b/tools/hciattach.c
index 1904ac53..c213fe43 100644
--- a/tools/hciattach.c
+++ b/tools/hciattach.c
@@ -60,8 +60,24 @@ struct uart_t {
char *bdaddr;
int (*init) (int fd, struct uart_t *u, struct termios *ti);
int (*post) (int fd, struct uart_t *u, struct termios *ti);
+
+/* __TIZEN_PATCH__ */
+#ifdef __TI_PATCH__
+ uint16_t device_param;
+#endif
};
+#ifdef __TI_PATCH__
+ int firmware_path = 0;
+#endif
+
+#if defined(__TI_PATCH__) || defined(__BROADCOM_PATCH__)
+#define TIOSETBRFPOWER 0x6000
+#define BRF_DEEP_SLEEP_OPCODE_BYTE_1 0x0c
+#define BRF_DEEP_SLEEP_OPCODE_BYTE_2 0xfd
+#define BRF_DEEP_SLEEP_OPCODE \
+ (BRF_DEEP_SLEEP_OPCODE_BYTE_1 | (BRF_DEEP_SLEEP_OPCODE_BYTE_2 << 8))
+#endif
#define FLOW_CTL 0x0001
#define AMP_DEV 0x0002
#define ENABLE_PM 1
@@ -1000,6 +1016,9 @@ static int bcm2035(int fd, struct uart_t *u, struct termios *ti)
/* Set the baud rate */
memset(cmd, 0, sizeof(cmd));
memset(resp, 0, sizeof(resp));
+
+/* __TIZEN_PATCH__ */
+#ifndef __BROADCOM_PATCH__
cmd[0] = HCI_COMMAND_PKT;
cmd[1] = 0x18;
cmd[2] = 0xfc;
@@ -1035,6 +1054,39 @@ static int bcm2035(int fd, struct uart_t *u, struct termios *ti)
fprintf(stderr, "Failed to write \"set baud rate\" command\n");
return -1;
}
+#else
+ cmd[0] = HCI_COMMAND_PKT;
+ cmd[1] = 0x18;
+ cmd[2] = 0xfc;
+
+ switch (u->speed) {
+ case 57600:
+ case 230400:
+ case 460800:
+ case 921600:
+ case 3000000:
+ break;
+ default:
+ break;
+ }
+
+ cmd[3] = 0x06;
+ cmd[4] = 0x00;
+ cmd[5] = 0x00;
+ cmd[6] = u->speed & 0xFF;
+ cmd[7] = (u->speed >> 8) & 0xFF;
+ cmd[8] = (u->speed >> 16) & 0xFF;
+ cmd[9] = (u->speed >> 24) & 0xFF;
+
+ fprintf(stderr, "Set the baud rate %d : 0x%02x,0x%02x,0x%02x,0x%02x\n",u->speed,cmd[6],cmd[7],cmd[8],cmd[9] );
+
+ /* Send command */
+ if (write(fd, cmd, 10) != 10) {
+ fprintf(stderr, "Failed to write \"set baud rate\" command\n");
+ return -1;
+ }
+
+#endif
if ((n = read_hci_event(fd, resp, 6)) < 0) {
fprintf(stderr, "Failed to set baud rate\n");
@@ -1073,12 +1125,18 @@ struct uart_t uart[] = {
{ "swave", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200,
FLOW_CTL, DISABLE_PM, NULL, swave },
+/* __TIZEN_PATCH__ */
+#ifdef __TI_PATCH__
+ /* Texas Instruments BRF63xx modules */
+ { "texas", 0x0000, 0x0000, HCI_UART_LL, 115200,3000000, FLOW_CTL, NULL, texas, NULL/*texas_continue_script*/, BRF_DEEP_SLEEP_OPCODE},
+#else
/* Texas Instruments Bluelink (BRF) modules */
{ "texas", 0x0000, 0x0000, HCI_UART_LL, 115200, 115200,
FLOW_CTL, DISABLE_PM, NULL, texas, texas2 },
{ "texasalt", 0x0000, 0x0000, HCI_UART_LL, 115200, 115200,
FLOW_CTL, DISABLE_PM, NULL, texasalt, NULL },
+#endif
/* ST Microelectronics minikits based on STLC2410/STLC2415 */
{ "st", 0x0000, 0x0000, HCI_UART_H4, 57600, 115200,
@@ -1193,6 +1251,11 @@ static int init_uart(char *dev, struct uart_t *u, int send_break, int raw)
int fd, i;
unsigned long flags = 0;
+/* __TIZEN_PATCH__ */
+#if defined(__TI_PATCH__) || defined(__BROADCOM_PATCH__)
+ int power;
+#endif
+
if (raw)
flags |= 1 << HCI_UART_RAW_DEVICE;
@@ -1214,11 +1277,14 @@ static int init_uart(char *dev, struct uart_t *u, int send_break, int raw)
cfmakeraw(&ti);
+/* __TIZEN_PATCH__ */
+#ifndef __BROADCOM_PATCH__
ti.c_cflag |= CLOCAL;
if (u->flags & FLOW_CTL)
ti.c_cflag |= CRTSCTS;
else
ti.c_cflag &= ~CRTSCTS;
+#endif
if (tcsetattr(fd, TCSANOW, &ti) < 0) {
perror("Can't set port settings");
@@ -1238,6 +1304,16 @@ static int init_uart(char *dev, struct uart_t *u, int send_break, int raw)
usleep(500000);
}
+/* __TIZEN_PATCH__ */
+#if defined(__TI_PATCH__) || defined(__BROADCOM_PATCH__)
+ /* Power up the BRF chip */
+ power = 1;
+ ioctl(fd, TIOSETBRFPOWER, &power);
+#endif
+#ifdef __TI_PATCH__
+ usleep(500000);
+#endif
+
if (u->init && u->init(fd, u, &ti) < 0)
return -1;
@@ -1276,7 +1352,13 @@ static void usage(void)
{
printf("hciattach - HCI UART driver initialization utility\n");
printf("Usage:\n");
+
+/* __TIZEN_PATCH__ */
+#ifdef __TI_PATCH__
+ printf("\thciattach [-n] [-p] [-b] [-g device_param] [-r] [-f] [-t timeout] [-s initial_speed] <tty> <type | id> [speed] [flow|noflow] [bdaddr]\n");
+#else
printf("\thciattach [-n] [-p] [-b] [-r] [-t timeout] [-s initial_speed] <tty> <type | id> [speed] [flow|noflow] [bdaddr]\n");
+#endif
printf("\thciattach -l\n");
}
@@ -1293,11 +1375,23 @@ int main(int argc, char *argv[])
sigset_t sigs;
char dev[PATH_MAX];
+/* __TIZEN_PATCH__ */
+#if defined(__TI_PATCH__) || defined(__BROADCOM_PATCH__)
+ int power;
+#endif
+#ifdef __TI_PATCH__
+ uint16_t device_param = 0;
+ int reset_device = 0;
+ int bt_fd;
+#endif
detach = 1;
printpid = 0;
raw = 0;
-
+#ifdef __TI_PATCH__
+ while ((opt=getopt(argc, argv, "bnprft:g:s:l")) != EOF) {
+#else
while ((opt=getopt(argc, argv, "bnpt:s:lr")) != EOF) {
+#endif
switch(opt) {
case 'b':
send_break = 1;
@@ -1315,6 +1409,20 @@ int main(int argc, char *argv[])
to = atoi(optarg);
break;
+/* __TIZEN_PATCH__ */
+#ifdef __TI_PATCH__
+ case 'g':
+ device_param = (uint16_t)strtol(optarg, NULL, 16);
+ break;
+
+ case 'r':
+ reset_device = 1;
+ break;
+
+ case 'f':
+ firmware_path = 1;
+ break;
+#endif
case 's':
init_speed = atoi(optarg);
break;
@@ -1337,6 +1445,10 @@ int main(int argc, char *argv[])
}
n = argc - optind;
+/* __TIZEN_PATCH__ */
+#ifdef __TI_PATCH__
+ if (!reset_device || (reset_device && n < 1))
+#endif
if (n < 2) {
usage();
exit(1);
@@ -1394,6 +1506,22 @@ int main(int argc, char *argv[])
break;
}
}
+/* __TIZEN_PATCH__ */
+#ifdef __TI_PATCH__
+ if (reset_device)
+ {
+ // Reset row device
+ bt_fd = open(dev, O_RDWR | O_NOCTTY);
+ if (bt_fd< 0) {
+ perror("Can't open serial port");
+ return -1;
+ }
+ /* Power up the BRF chip */
+ power = 0;
+ ioctl(bt_fd, TIOSETBRFPOWER, &power);
+ return 0;
+ }
+#endif
if (!u) {
fprintf(stderr, "Unknown device type or id\n");
@@ -1404,6 +1532,12 @@ int main(int argc, char *argv[])
the hardware's default */
if (init_speed)
u->init_speed = init_speed;
+#ifdef __TI_PATCH__
+ /* If user specified a device parameter, use that instead of
+ the hardware's default */
+ if (device_param)
+ u->device_param = device_param;
+#endif
memset(&sa, 0, sizeof(sa));
sa.sa_flags = SA_NOCLDSTOP;
@@ -1475,5 +1609,11 @@ int main(int argc, char *argv[])
exit(1);
}
+/* __TIZEN_PATCH__ */
+#if defined(__TI_PATCH__) || defined(__BROADCOM_PATCH__)
+ /* Power down the BRF or BCMchip */
+ power = 0;
+ ioctl(n, TIOSETBRFPOWER, &power);
+#endif
return 0;
}