Add callback to hciUp
Upper layer needs to know when the LE stack is ready to be brought up.
This adds a callback parameter to hciUp().
BUG=chromium:840517
TEST=test.c
Change-Id: I19b5934ff22594ad055a11bfde233786515446c1
diff --git a/hci.c b/hci.c
index d6785a0..6b8ae7c 100644
--- a/hci.c
+++ b/hci.c
@@ -329,6 +329,8 @@
static struct workQueue* mCmdsSendWork;
static pthread_t mCmdsSendThread;
static uint8_t mStackState = STACK_STATE_DOWN;
+static hciReadyForUpCbk mReadyForUpCbk;
+static void *mReadyForUpData;
static struct workQueue* mCallbackWork;
static pthread_t mCallbackThread;
@@ -858,8 +860,11 @@
if (addCredit) {
sem_post(&mCmdSendSem);
- if (mStackState == STACK_STATE_DOWN)
+ if (mStackState == STACK_STATE_DOWN) {
mStackState = STACK_STATE_READY_FOR_UP;
+ if (mReadyForUpCbk)
+ mReadyForUpCbk(mReadyForUpData);
+ }
}
if (!handled)
@@ -1512,10 +1517,12 @@
* FUNCTION: hciUp
* USE: Bring up HCI (comms to bt chip)
* PARAMS: addr - the BT addr
+ * cbk - callback when stack is ready for up
+ * cbkData - data to be passed to cbk
* RETURN: true on success, false else
* NOTES: may take a while
*/
-bool hciUp(const uint8_t *addr)
+bool hciUp(const uint8_t *addr, hciReadyForUpCbk cbk, void *cbkData)
{
int ret;
@@ -1561,6 +1568,9 @@
goto out_cmd_worker;
}
+ mReadyForUpCbk = cbk;
+ mReadyForUpData = cbkData;
+
sem_init(&mAclPacketsLe, 0, 0);
sem_init(&mAclPacketsEdr, 0, 0);
diff --git a/hci.h b/hci.h
index eb9102d..5feb590 100644
--- a/hci.h
+++ b/hci.h
@@ -161,8 +161,10 @@
typedef void (*hciOpDoneCbk)(void *cbkData, uint8_t status /* 0 = good */);
+typedef void (*hciReadyForUpCbk)(void *cbkData);
+
/* bring chip communications up or down (also query)*/
-bool hciUp(const uint8_t *addr);
+bool hciUp(const uint8_t *addr, hciReadyForUpCbk cbk, void *cbkData);
void hciDown(void);
/* test if stack is up or needs bringup */
diff --git a/test.c b/test.c
index 6952c77..988c088 100644
--- a/test.c
+++ b/test.c
@@ -96,6 +96,10 @@
}
}
+static void readyForUpCbk() {
+ logi("callback stack is ready for up\n");
+}
+
#define DEVICE_CLASS_SERVICE_RENDERING 0x040000 //PRINTER, SPEAKER
#define DEVICE_CLASS_SERVICE_AUDIO 0x200000 //SPEAKER, MIC, HEADSET
#define DEVICE_CLASS_SERVICE_INFORMATION 0x800000 //WEB-server, WAP-server
@@ -394,7 +398,7 @@
persistLoad();
timersInit();
- if (!hciUp(mac)) {
+ if (!hciUp(mac, readyForUpCbk, NULL)) {
loge("HCI up fail\n");
return -1;
}