From b272b9337e23a89fa87a7f7e21b561229707c279 Mon Sep 17 00:00:00 2001
From: Tuomas Kulve <tuomas@kulve.fi>
Date: Tue, 6 May 2008 21:57:49 +0300
Subject: [PATCH] Applied bluez-utils-hciattach-infineon-startupevent.patch.

---
 tools/hciattach.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/tools/hciattach.c b/tools/hciattach.c
index c24a61a..9a7e1b9 100644
--- a/tools/hciattach.c
+++ b/tools/hciattach.c
@@ -840,7 +840,9 @@ static int gumstix(int fd, struct uart_t *u, struct termios *ti)
 	unsigned char cmd[10], resp[HCI_MAX_EVENT_SIZE];
 	int baudrates[] = { 57600, 115200, 921600 };
 	int old_alarm = alarm(20); // Extend timeout
-	int i, j, retval;
+	int i, j, retval, tries;
+
+  tries = 0;
 
 	cmd[0] = HCI_COMMAND_PKT; // Determine what module we're talking to
 	cmd[1] = OCF_READ_LOCAL_VERSION;
@@ -876,11 +878,18 @@ static int gumstix(int fd, struct uart_t *u, struct termios *ti)
 			printf("No response from BT module\n");
 			continue;
 		} else {
+retry:
 			retval = read_hci_event(fd, resp, HCI_MAX_EVENT_SIZE);
 			if (retval < 0) {
 				perror("Error reading response");
 				continue;
-			} else if(retval == READ_LOCAL_VERSION_RP_SIZE + 6) { // The 6 is 0x04 0x0e 0xnn 0xmm 0x01 0x10
+			} else if (retval == 4) {
+        printf ("Got Startup Event -- retrying once\n");
+        if (tries++ == 0)
+          goto retry;
+        else
+          continue; 
+      } else if(retval == READ_LOCAL_VERSION_RP_SIZE + 6) { // The 6 is 0x04 0x0e 0xnn 0xmm 0x01 0x10
 				read_local_version_rp *vers = (read_local_version_rp *)&(resp[6]);
 				printf("Detected bluetooth module at %d baud\n",baudrates[i]);
 				printf("Got: status=0x%02x, hci_ver=0x%02x, hci_rev=0x%04x, lmp_ver=0x%02x, manuf=0x%04x, lmp_subver=0x%04x\n",
-- 
1.5.4.5

