50 #include "btrCore_logger.h"
53 #include "btrCore_le.h"
54 #include "btrCore_service.h"
56 #include "btrCore_bt_ifce.h"
59 #define BTR_MAX_GATT_PROFILE 16
60 #define BTR_MAX_GATT_SERVICE BT_MAX_NUM_GATT_SERVICE
61 #define BTR_MAX_GATT_CHAR BT_MAX_NUM_GATT_CHAR
62 #define BTR_MAX_GATT_DESC BT_MAX_NUM_GATT_DESC
65 #define BTR_MAX_GATT_CHAR_FLAGS BT_MAX_NUM_GATT_CHAR_FLAGS
66 #define BTR_MAX_GATT_DESC_FLAGS BT_MAX_NUM_GATT_DESC_FLAGS
67 #define BTR_MAX_NUMBER_OF_UUID 32
71 #define BTR_GATT_CHAR_FLAG_READ BT_GATT_CHAR_FLAG_READ
72 #define BTR_GATT_CHAR_FLAG_WRITE BT_GATT_CHAR_FLAG_WRITE
73 #define BTR_GATT_CHAR_FLAG_ENCRYPT_READ BT_GATT_CHAR_FLAG_ENCRYPT_READ
74 #define BTR_GATT_CHAR_FLAG_ENCRYPT_WRITE BT_GATT_CHAR_FLAG_ENCRYPT_WRITE
75 #define BTR_GATT_CHAR_FLAG_ENCRYPT_AUTHENTICATED_READ BT_GATT_CHAR_FLAG_ENCRYPT_AUTHENTICATED_READ
76 #define BTR_GATT_CHAR_FLAG_ENCRYPT_AUTHENTICATED_WRITE BT_GATT_CHAR_FLAG_ENCRYPT_AUTHENTICATED_WRITE
77 #define BTR_GATT_CHAR_FLAG_SECURE_READ BT_GATT_CHAR_FLAG_SECURE_READ
78 #define BTR_GATT_CHAR_FLAG_SECURE_WRITE BT_GATT_CHAR_FLAG_SECURE_WRITE
79 #define BTR_GATT_CHAR_FLAG_NOTIFY BT_GATT_CHAR_FLAG_NOTIFY
80 #define BTR_GATT_CHAR_FLAG_INDICATE BT_GATT_CHAR_FLAG_INDICATE
81 #define BTR_GATT_CHAR_FLAG_BROADCAST BT_GATT_CHAR_FLAG_BROADCAST
82 #define BTR_GATT_CHAR_FLAG_WRITE_WITHOUT_RESPONSE BT_GATT_CHAR_FLAG_WRITE_WITHOUT_RESPONSE
83 #define BTR_GATT_CHAR_FLAG_AUTHENTICATED_SIGNED_WRITES BT_GATT_CHAR_FLAG_AUTHENTICATED_SIGNED_WRITES
84 #define BTR_GATT_CHAR_FLAG_RELIABLE_WRITE BT_GATT_CHAR_FLAG_RELIABLE_WRITE
85 #define BTR_GATT_CHAR_FLAG_WRITABLE_AUXILIARIES BT_GATT_CHAR_FLAG_WRITABLE_AUXILIARIES
89 #define BTR_GATT_DESC_FLAG_READ BTR_GATT_CHAR_FLAG_READ
90 #define BTR_GATT_DESC_FLAG_WRITE BTR_GATT_CHAR_FLAG_WRITE
91 #define BTR_GATT_DESC_FLAG_ENCRYPT_READ BTR_GATT_CHAR_FLAG_ENCRYPT_READ
92 #define BTR_GATT_DESC_FLAG_ENCRYPT_WRITE BTR_GATT_CHAR_FLAG_ENCRYPT_WRITE
93 #define BTR_GATT_DESC_FLAG_ENCRYPT_AUTHENTICATED_READ BTR_GATT_CHAR_FLAG_ENCRYPT_AUTHENTICATED_READ
94 #define BTR_GATT_DESC_FLAG_ENCRYPT_AUTHENTICATED_WRITE BTR_GATT_CHAR_FLAG_ENCRYPT_AUTHENTICATED_WRITE
95 #define BTR_GATT_DESC_FLAG_SECURE_READ BTR_GATT_CHAR_FLAG_SECURE_READ
96 #define BTR_GATT_DESC_FLAG_SECURE_WRITE BTR_GATT_CHAR_FLAG_SECURE_WRITE
101 #define BTR_GATT_LE_IAS_UUID "00001802-0000-1000-8000-00805f9b34fb"
102 #define BTR_LE_IAS_ALERT_LEVEL_CHR_UUID "00002a06-0000-1000-8000-00805f9b34fb"
105 #define BTR_LE_IAS_RW_DESCRIPTOR_UUID "8260c653-1a54-426b-9e36-e84c238bc669"
109 unsigned short ManfID;
110 unsigned int lenManfData;
111 unsigned char data[BT_MAX_GATT_OP_DATA_LEN];
116 uint8_t data[BT_MAX_GATT_OP_DATA_LEN];
127 unsigned char bTxPower;
132 char descPath[BTRCORE_MAX_STR_LEN];
134 unsigned short descFlags;
135 char propertyValue[BT_MAX_GATT_OP_DATA_LEN];
141 char charPath[BTRCORE_MAX_STR_LEN];
144 unsigned short ui16NumberOfGattDesc;
145 unsigned short charFlags;
146 char value[BT_MAX_GATT_OP_DATA_LEN];
153 char servicePath[BTRCORE_MAX_STR_LEN];
156 unsigned short ui16NumberOfGattChar;
162 tBTRCoreDevId deviceID;
163 char devicePath[BTRCORE_MAX_STR_LEN];
164 char i8LeGattOpReady;
166 unsigned short ui16NumberOfGattService;
170 unsigned short flags;
175 unsigned short numberOfUUID;
185 unsigned short ui16NumberOfGattProfile;
187 fPtr_BTRCore_LeStatusUpdateCb fpcBTRCoreLeStatusUpdate;
188 void* pvBtLeStatusUserData;
193 unsigned short ui16NumOfLocalGattServices;
199 static tBTRCoreDevId btrCore_LE_BTGenerateUniqueDeviceID (
const char* apcDeviceAddress);
206 static BOOLEAN btrCore_LE_isServiceSupported (
char* apUUID);
208 static enBTRCoreRet btrCore_LE_GetGattCharacteristicUUIDList (
stBTRCoreLeGattService *pstService,
void* uuidList);
209 static enBTRCoreRet btrCore_LE_GetGattDescriptorUUIDList (
stBTRCoreLeGattChar *pstChar,
void* uuidList);
210 static enBTRCoreRet btrCore_LE_GetDataPath (
stBTRCoreLeHdl* pstBTRCoreLeHdl, tBTRCoreDevId atBTRCoreDevId,
211 const char* apBtLeUuid,
char* rpBtLePath,
enBTOpIfceType* renBTOpIfceType);
213 static enBTRCoreRet btrCore_LE_GetGattInfo(tBTRCoreLeHdl hBTRCoreLe,
char* aUUID, enBTRCoreLEGattProp aGattProp,
void *aValue);
215 static enBTRCoreRet btrCore_LE_UpdateLocalGattInfoCb(
enBTOpIfceType aenBtOpIfceType,
enBTLeGattOp aenBtLeGattOp,
const char* aBtrAddr,
const char* apBtGattPath,
char* apValue,
void* apUserData);
216 static enBTRCoreRet btrCore_LE_LocalGattServerInfoCb(
const char* apBtAdvPath,
const char* apcBtDevAddr,
stBTLeGattService **apstBTRCoreLeGattService,
int *aNumOfGattServices,
void* apUserData);
219 static int btrCore_LE_GattInfoCb (
enBTOpIfceType enBtOpIfceType,
enBTLeGattOp aenGattOp,
const char* apBtGattPath,
const char* aBtdevAddr,
enBTDeviceState aenBTDeviceState,
void* apCbInfo,
void* apUserData );
220 static int btrCore_LE_AdvInfoCb(
const char* apBtAdvPath,
stBTLeCustomAdv** appstBtLeCustomAdv,
void* apUserData);
226 btrCore_LE_BTGenerateUniqueDeviceID (
227 const char* apcDeviceAddress
229 unsigned long long int lBTRCoreDevId = 0;
230 char lcDevHdlArr[13] = {
'\0'};
232 if (apcDeviceAddress && (strlen(apcDeviceAddress) >= 17)) {
233 lcDevHdlArr[0] = apcDeviceAddress[0];
234 lcDevHdlArr[1] = apcDeviceAddress[1];
235 lcDevHdlArr[2] = apcDeviceAddress[3];
236 lcDevHdlArr[3] = apcDeviceAddress[4];
237 lcDevHdlArr[4] = apcDeviceAddress[6];
238 lcDevHdlArr[5] = apcDeviceAddress[7];
239 lcDevHdlArr[6] = apcDeviceAddress[9];
240 lcDevHdlArr[7] = apcDeviceAddress[10];
241 lcDevHdlArr[8] = apcDeviceAddress[12];
242 lcDevHdlArr[9] = apcDeviceAddress[13];
243 lcDevHdlArr[10] = apcDeviceAddress[15];
244 lcDevHdlArr[11] = apcDeviceAddress[16];
246 lBTRCoreDevId = (tBTRCoreDevId) strtoll(lcDevHdlArr, NULL, 16);
249 return lBTRCoreDevId;
254 btrCore_LE_FindGattProfile (
256 tBTRCoreDevId aBtrDeviceID
258 unsigned short ui16LoopIdx = 0;
261 if (pstBTRCoreLeHdl) {
262 for (ui16LoopIdx = 0; ui16LoopIdx < pstBTRCoreLeHdl->ui16NumberOfGattProfile; ui16LoopIdx++) {
263 if (pstBTRCoreLeHdl->astBTRGattProfile[ui16LoopIdx].deviceID == aBtrDeviceID) {
264 pstProfile = &pstBTRCoreLeHdl->astBTRGattProfile[ui16LoopIdx];
265 BTRCORELOG_DEBUG (
"Gatt Profile for Device %llu Found.\n", aBtrDeviceID);
276 btrCore_LE_FindGattService (
280 unsigned short ui16LoopIdx = 0;
284 for (ui16LoopIdx = 0; ui16LoopIdx < pstProfile->ui16NumberOfGattService; ui16LoopIdx++) {
285 if (!strcmp(pstProfile->astBTRGattService[ui16LoopIdx].servicePath, pService)) {
286 pstService = &pstProfile->astBTRGattService[ui16LoopIdx];
287 BTRCORELOG_DEBUG (
"Gatt Service %s Found.\n", pService);
298 btrCore_LE_FindGattCharacteristic (
302 unsigned short ui16LoopIdx = 0;
306 for (ui16LoopIdx = 0; ui16LoopIdx < pstService->ui16NumberOfGattChar; ui16LoopIdx++) {
307 if (!strcmp(pstService->astBTRGattChar[ui16LoopIdx].charPath, pChar)) {
308 pstChar = &pstService->astBTRGattChar[ui16LoopIdx];
309 BTRCORELOG_DEBUG (
"Gatt Char %s Found.\n", pChar);
320 btrCore_LE_FindGattDescriptor (
324 unsigned short ui16LoopIdx = 0;
328 for (ui16LoopIdx = 0; ui16LoopIdx < pstChar->ui16NumberOfGattDesc; ui16LoopIdx++) {
329 if (!strcmp(pstChar->atBTRGattDesc[ui16LoopIdx].descPath, pDesc)) {
330 pstDesc = &pstChar->atBTRGattDesc[ui16LoopIdx];
331 BTRCORELOG_DEBUG (
"Gatt Descriptor %s Found.\n", pDesc);
342 btrCore_LE_isServiceSupported (
349 BTRCORELOG_ERROR (
"enBTRCoreInvalidArg\n");
350 return enBTRCoreInvalidArg;
355 lUUID[2] = apUUID[4];
356 lUUID[3] = apUUID[5];
357 lUUID[4] = apUUID[6];
358 lUUID[5] = apUUID[7];
361 if (!strcmp(lUUID, BTR_CORE_GATT_TILE_1) ||
362 !strcmp(lUUID, BTR_CORE_GATT_TILE_2) ||
363 !strcmp(lUUID, BTR_CORE_GATT_TILE_3) ||
364 !strcmp(lUUID, BTR_CORE_GEN_ATRIB)) {
372 btrCore_LE_GetGattCharacteristicUUIDList (
377 unsigned short ui16LoopIdx = 0;
379 if (!pstService || !uuidList) {
380 BTRCORELOG_ERROR (
"enBTRCoreInvalidArg\n");
381 return enBTRCoreInvalidArg;
384 for (ui16LoopIdx = 0; ui16LoopIdx < pstService->ui16NumberOfGattChar; ui16LoopIdx++) {
385 strncpy(lstBTRCoreLeUUIDList->uuidList[ui16LoopIdx].uuid, pstService->astBTRGattChar[ui16LoopIdx].charUuid,
BT_MAX_UUID_STR_LEN-1);
386 lstBTRCoreLeUUIDList->uuidList[ui16LoopIdx].flags = pstService->astBTRGattChar[ui16LoopIdx].charFlags;
389 lstBTRCoreLeUUIDList->numberOfUUID = ui16LoopIdx;
392 return enBTRCoreSuccess;
397 btrCore_LE_GetGattDescriptorUUIDList (
402 unsigned short ui16LoopIdx = 0;
404 if (!pstChar || !uuidList) {
405 BTRCORELOG_ERROR (
"enBTRCoreInvalidArg\n");
406 return enBTRCoreInvalidArg;
409 for (ui16LoopIdx = 0; ui16LoopIdx < pstChar->ui16NumberOfGattDesc; ui16LoopIdx++) {
410 strncpy(lstBTRCoreLeUUIDList->uuidList[ui16LoopIdx].uuid, pstChar->atBTRGattDesc[ui16LoopIdx].descUuid,
BT_MAX_UUID_STR_LEN-1);
411 lstBTRCoreLeUUIDList->uuidList[ui16LoopIdx].flags = pstChar->atBTRGattDesc[ui16LoopIdx].descFlags;
414 lstBTRCoreLeUUIDList->numberOfUUID = ui16LoopIdx;
417 return enBTRCoreSuccess;
422 btrCore_LE_GetDataPath (
424 tBTRCoreDevId atBTRCoreDevId,
425 const char* apBtLeUuid,
429 unsigned short ui16PLoopindex = 0;
430 char* retLeDataPath = NULL;
433 if (!pstBTRCoreLeHdl || !atBTRCoreDevId || !apBtLeUuid) {
434 BTRCORELOG_ERROR (
"enBTRCoreInvalidArg\n");
435 return enBTRCoreInvalidArg;
438 if (!pstBTRCoreLeHdl->ui16NumberOfGattProfile) {
439 BTRCORELOG_ERROR (
"No Gatt Profile Exists!!!!\n");
440 return enBTRCoreFailure;
443 for (ui16PLoopindex = 0; ui16PLoopindex < pstBTRCoreLeHdl->ui16NumberOfGattProfile; ui16PLoopindex++) {
444 pProfile = &pstBTRCoreLeHdl->astBTRGattProfile[ui16PLoopindex];
446 if (atBTRCoreDevId == pProfile->deviceID) {
447 unsigned short ui16SLoopindex = 0;
450 BTRCORELOG_DEBUG (
"Profile Matched for Device %llu \n", atBTRCoreDevId);
452 if (pProfile->ui16NumberOfGattService == 0) {
453 BTRCORELOG_ERROR (
"No Gatt Service Exists!!!\n");
457 for (ui16SLoopindex = 0; ui16SLoopindex < pProfile->ui16NumberOfGattService; ui16SLoopindex++) {
458 pService = &pProfile->astBTRGattService[ui16SLoopindex];
460 if (strstr(pService->serviceUuid, apBtLeUuid)) {
461 retLeDataPath = pService->servicePath;
462 *renBTOpIfceType = enBTGattService;
463 BTRCORELOG_DEBUG (
"UUID matched Service : %s.\n", pService->servicePath);
468 if (ui16SLoopindex != pProfile->ui16NumberOfGattService) {
472 for (ui16SLoopindex = 0; ui16SLoopindex < pProfile->ui16NumberOfGattService; ui16SLoopindex++) {
473 unsigned short ui16CLoopindex = 0;
476 pService = &pProfile->astBTRGattService[ui16SLoopindex];
478 if (pService->ui16NumberOfGattChar == 0) {
482 for (ui16CLoopindex = 0; ui16CLoopindex < pService->ui16NumberOfGattChar; ui16CLoopindex++) {
483 pChar = &pService->astBTRGattChar[ui16CLoopindex];
485 if (!strcmp(pChar->charUuid, apBtLeUuid)) {
486 retLeDataPath = pChar->charPath;
487 *renBTOpIfceType = enBTGattCharacteristic;
488 BTRCORELOG_DEBUG (
"UUID matched Characteristic : %s.\n", pChar->charPath);
492 unsigned short ui16DLoopindex = 0;
495 if (pChar->ui16NumberOfGattDesc == 0) {
499 for (ui16DLoopindex = 0; ui16DLoopindex < pChar->ui16NumberOfGattDesc; ui16DLoopindex++) {
500 pDesc = &pChar->atBTRGattDesc[ui16DLoopindex];
502 if (!strcmp(apBtLeUuid, pDesc->descUuid)) {
503 retLeDataPath = pDesc->descPath;
504 *renBTOpIfceType = enBTGattDescriptor;
505 BTRCORELOG_DEBUG (
"UUID matched Descriptor : %s\n", pDesc->descPath);
510 if (ui16DLoopindex != pChar->ui16NumberOfGattDesc) {
516 if (ui16CLoopindex != pService->ui16NumberOfGattChar) {
524 if (ui16PLoopindex == pstBTRCoreLeHdl->ui16NumberOfGattProfile) {
525 BTRCORELOG_ERROR (
"Profile Not Found for Dev : %llu!!!\n", atBTRCoreDevId);
531 BTRCORELOG_ERROR (
"No match found for UUID : %s !!!\n", apBtLeUuid);
532 return enBTRCoreFailure;
535 return enBTRCoreSuccess;
539 static unsigned short
540 btrCore_LE_GetAllowedGattFlagValues (
544 unsigned short flagBits = 0;
545 unsigned char u8idx = 0;
546 unsigned char maxFlags = 0;
548 if (!flags || !flags[0]) {
549 BTRCORELOG_ERROR (
"enBTRCoreInvalidArg\n");
553 if (aenBtOpIfceType == enBTGattCharacteristic) {
554 maxFlags = BTR_MAX_GATT_CHAR_FLAGS;
556 else if (aenBtOpIfceType == enBTGattDescriptor) {
557 maxFlags = BTR_MAX_GATT_DESC_FLAGS;
560 for (u8idx = 0; u8idx < maxFlags && flags[u8idx]; u8idx++) {
561 if (!strcmp(
"read", flags[u8idx])) {
562 flagBits |= BTR_GATT_CHAR_FLAG_READ;
564 if (!strcmp(
"write", flags[u8idx])) {
565 flagBits |= BTR_GATT_CHAR_FLAG_WRITE;
567 if (!strcmp(
"encrypt-read", flags[u8idx])) {
568 flagBits |= BTR_GATT_CHAR_FLAG_ENCRYPT_READ;
570 if (!strcmp(
"encrypt-write", flags[u8idx])) {
571 flagBits |= BTR_GATT_CHAR_FLAG_ENCRYPT_WRITE;
573 if (!strcmp(
"encrypt-authenticated-read", flags[u8idx])) {
574 flagBits |= BTR_GATT_CHAR_FLAG_ENCRYPT_AUTHENTICATED_READ;
576 if (!strcmp(
"encrypt-authenticated-write", flags[u8idx])) {
577 flagBits |= BTR_GATT_CHAR_FLAG_ENCRYPT_AUTHENTICATED_WRITE;
579 if (!strcmp(
"secure-read", flags[u8idx])) {
580 flagBits |= BTR_GATT_CHAR_FLAG_SECURE_READ;
582 if (!strcmp(
"secure-write", flags[u8idx])) {
583 flagBits |= BTR_GATT_CHAR_FLAG_SECURE_WRITE;
585 if (!strcmp(
"notify", flags[u8idx])) {
586 flagBits |= BTR_GATT_CHAR_FLAG_NOTIFY;
588 if (!strcmp(
"indicate", flags[u8idx])) {
589 flagBits |= BTR_GATT_CHAR_FLAG_INDICATE;
591 if (!strcmp(
"broadcast", flags[u8idx])) {
592 flagBits |= BTR_GATT_CHAR_FLAG_BROADCAST;
594 if (!strcmp(
"write-without-response", flags[u8idx])) {
595 flagBits |= BTR_GATT_CHAR_FLAG_WRITE_WITHOUT_RESPONSE;
597 if (!strcmp(
"authenticated-signed-writes", flags[u8idx])) {
598 flagBits |= BTR_GATT_CHAR_FLAG_AUTHENTICATED_SIGNED_WRITES;
600 if (!strcmp(
"reliable-write", flags[u8idx])) {
601 flagBits |= BTR_GATT_CHAR_FLAG_RELIABLE_WRITE;
603 if (!strcmp(
"writable-auxiliaries", flags[u8idx])) {
604 flagBits |= BTR_GATT_CHAR_FLAG_WRITABLE_AUXILIARIES;
608 BTRCORELOG_INFO (
"- %d\n", flagBits);
614 btrCore_LE_GetGattInfo (
615 tBTRCoreLeHdl hBTRCoreLe,
617 enBTRCoreLEGattProp aGattProp,
621 enBTRCoreRet lenBTRCoreRet = enBTRCoreSuccess;
622 int lNumGattServices = pstlhBTRCoreLe->ui16NumOfLocalGattServices;
628 lpstBTRCoreLeGattService = pstlhBTRCoreLe->stBTRLeGattService;
629 for (
int ServiceIndex = 0; (ServiceIndex < lNumGattServices) && (FALSE == lbFoundUUID); ServiceIndex++) {
630 lCurrGattService = &lpstBTRCoreLeGattService[ServiceIndex];
631 if (!strncmp(aUUID, lCurrGattService->serviceUuid,
BT_MAX_STR_LEN)) {
636 for (
int index = 0; (index < lCurrGattService->ui16NumberOfGattChar) && (FALSE == lbFoundUUID); index++) {
637 lpstBTRCoreLeGattChar = &lCurrGattService->astBTRGattChar[index];
638 if (!strncmp(aUUID, lpstBTRCoreLeGattChar->charUuid,
BT_MAX_STR_LEN)) {
643 for (
int descIndex = 0; (descIndex < lpstBTRCoreLeGattChar->ui16NumberOfGattDesc); descIndex++) {
644 lpstBTRCoreLeGattDesc = &lpstBTRCoreLeGattChar->atBTRGattDesc[descIndex];
645 if (!strncmp(aUUID, lpstBTRCoreLeGattDesc->descUuid,
BT_MAX_STR_LEN)) {
653 if (
TRUE == lbFoundUUID) {
655 case enBTRCoreLEGPropService: {
657 *lpstGattService = lCurrGattService;
658 BTRCORELOG_INFO(
"enBTRCoreLEGPropService UUID is %s\n", (*lpstGattService)->serviceUuid);
661 case enBTRCoreLEGPropChar: {
663 *lpstGattChar = lpstBTRCoreLeGattChar;
664 BTRCORELOG_INFO(
"enBTRCoreLEGPropChar UUID is %s\n", (*lpstGattChar)->charUuid);
667 case enBTRCoreLEGPropDesc: {
669 *lpstGattDesc = lpstBTRCoreLeGattDesc;
670 BTRCORELOG_INFO(
"enBTRCoreLEGPropDesc UUID is %s\n", (*lpstGattDesc)->descUuid);
673 case enBTRCoreLEGPropValue: {
674 char **lCharPropValue = (
char**)aValue;
675 *lCharPropValue = lpstBTRCoreLeGattChar->value;
676 BTRCORELOG_INFO(
"Characteristic value for UUID is %s\n", *lCharPropValue);
679 case enBTRCoreLEGPropDescValue: {
680 char **lDescPropValue = (
char**)aValue;
681 *lDescPropValue = lpstBTRCoreLeGattDesc->propertyValue;
682 BTRCORELOG_INFO(
"Descriptor value for UUID is %s\n", *lDescPropValue);
686 lenBTRCoreRet = enBTRCoreFailure;
692 BTRCORELOG_ERROR(
"UUID %s could not be found\n", aUUID);
693 lenBTRCoreRet = enBTRCoreFailure;
696 return lenBTRCoreRet;
701 btrCore_LE_LocalGattServerInfoCb(
702 const char* apBtAdvPath,
703 const char* apcBtDevAddr,
705 int* aNumOfGattServices,
712 for (
unsigned short lui16serviceIndex = 0; lui16serviceIndex < lpstlhBTRCoreLe->ui16NumOfLocalGattServices; lui16serviceIndex++) {
713 apstBTRCoreLeGattService->serviceType = lpstBTRLeGattService->serviceType;
714 apstBTRCoreLeGattService->ui16NumberOfGattChar = lpstBTRLeGattService->ui16NumberOfGattChar;
715 strncpy(apstBTRCoreLeGattService->servicePath, lpstBTRLeGattService->servicePath,
BT_MAX_STR_LEN - 1);
716 strncpy(apstBTRCoreLeGattService->serviceUuid, lpstBTRLeGattService->serviceUuid,
BT_MAX_UUID_STR_LEN - 1);
718 stBTLeGattChar* apstBtLeGattChar = apstBTRCoreLeGattService->astBTRGattChar;
720 for (
unsigned short lui16charIndex = 0; lui16charIndex < lpstBTRLeGattService->ui16NumberOfGattChar; lui16charIndex++) {
721 apstBtLeGattChar->charFlags = lpstBTRLeGattChar->charFlags;
722 apstBtLeGattChar->ui16NumberOfGattDesc = lpstBTRLeGattChar->ui16NumberOfGattDesc;
723 strncpy(apstBtLeGattChar->charPath, lpstBTRLeGattChar->charPath,
BT_MAX_STR_LEN - 1);
725 strncpy(apstBtLeGattChar->value, lpstBTRLeGattChar->value, BT_MAX_GATT_OP_DATA_LEN - 1);
727 stBTLeGattDesc* apstBtLeGattDesc = apstBtLeGattChar->atBTRGattDesc;
729 for (
unsigned short lui16descIndex = 0; lui16descIndex < lpstBTRLeGattChar->ui16NumberOfGattDesc; lui16descIndex++) {
730 apstBtLeGattDesc->descFlags = lpstBTRLeGattDesc->descFlags;
731 strncpy(apstBtLeGattDesc->descPath, lpstBTRLeGattDesc->descPath,
BT_MAX_STR_LEN - 1);
733 strncpy(apstBtLeGattDesc->propertyValue, lpstBTRLeGattDesc->propertyValue, BT_MAX_GATT_OP_DATA_LEN - 1);
743 apstBTRCoreLeGattService++;
744 lpstBTRLeGattService++;
747 *aNumOfGattServices = lpstlhBTRCoreLe->ui16NumOfLocalGattServices;
749 return enBTRCoreSuccess;
753 btrCore_LE_UpdateLocalGattInfoCb (
756 const char* aBtrAddr,
757 const char* apBtGattPath,
766 int lNumGattServices = 0;
767 BOOLEAN lbFoundGattPath = FALSE;
768 enBTRCoreRet lRetValue = enBTRCoreSuccess;
770 if (!apBtGattPath || !apUserData) {
771 BTRCORELOG_ERROR(
"Invalid arguments!!!\n");
772 return enBTRCoreInvalidArg;
775 lpstBTRCoreLeGattService = lpstlhBTRCoreLe->stBTRLeGattService;
776 lNumGattServices = lpstlhBTRCoreLe->ui16NumOfLocalGattServices;
779 for (
int ServiceIndex = 0; ServiceIndex < lNumGattServices; ServiceIndex++) {
781 if (FALSE == lbFoundGattPath) {
782 lCurrGattService = &lpstBTRCoreLeGattService[ServiceIndex];
784 for (
int index = 0; index < (lCurrGattService->ui16NumberOfGattChar) && (FALSE == lbFoundGattPath); index++) {
785 lpstBTRCoreLeGattChar = &lCurrGattService->astBTRGattChar[index];
787 if (!strncmp(apBtGattPath, lpstBTRCoreLeGattChar->charPath,
BT_MAX_STR_LEN)) {
788 lbFoundGattPath =
TRUE;
792 for (
int descIndex = 0; descIndex < lpstBTRCoreLeGattChar->ui16NumberOfGattDesc; descIndex++) {
793 lpstBTRCoreLeGattDesc = &lpstBTRCoreLeGattChar->atBTRGattDesc[descIndex];
795 if (!strncmp(apBtGattPath, lpstBTRCoreLeGattDesc->descPath,
BT_MAX_STR_LEN)) {
796 lbFoundGattPath =
TRUE;
804 if (
TRUE == lbFoundGattPath) {
805 switch (aenBtLeGattOp) {
806 case enBTLeGattOpReadValue: {
807 switch (aenBtOpIfceType) {
808 case enBTGattCharacteristic: {
809 lstBtrLeInfo.pui8Uuid = lpstBTRCoreLeGattChar->charUuid;
810 lstBtrLeInfo.enLeProp = enBTRCoreLEGPropChar;
812 lstBtrLeInfo.enLeOper = enBTRCoreLEGOpReadValue;
813 lstBtrLeInfo.pui8Value = apValue;
814 BTRCORELOG_TRACE(
"Btr address of device reading value is %s\n", aBtrAddr);
815 lpstlhBTRCoreLe->fpcBTRCoreLeStatusUpdate(&lstBtrLeInfo, aBtrAddr, lpstlhBTRCoreLe->pvBtLeStatusUserData);
816 BTRCORELOG_TRACE(
"Value of UUID %s\n", apValue);
817 strncpy(lpstBTRCoreLeGattChar->value, apValue, BT_MAX_GATT_OP_DATA_LEN - 1);
820 case enBTGattDescriptor: {
821 lstBtrLeInfo.pui8Uuid = lpstBTRCoreLeGattDesc->descUuid;
822 lstBtrLeInfo.enLeProp = enBTRCoreLEGPropDesc;
824 lstBtrLeInfo.enLeOper = enBTRCoreLEGOpReadValue;
825 lstBtrLeInfo.pui8Value = apValue;
826 BTRCORELOG_TRACE(
"Btr address of device reading value is %s\n", aBtrAddr);
827 lpstlhBTRCoreLe->fpcBTRCoreLeStatusUpdate(&lstBtrLeInfo, aBtrAddr, lpstlhBTRCoreLe->pvBtLeStatusUserData);
828 BTRCORELOG_TRACE(
"Value of UUID %s\n", apValue);
829 strncpy(lpstBTRCoreLeGattDesc->propertyValue, apValue, BT_MAX_GATT_OP_DATA_LEN - 1);
837 case enBTLeGattOpWriteValue: {
838 switch (aenBtOpIfceType) {
839 case enBTGattCharacteristic: {
840 strncpy(lpstBTRCoreLeGattChar->value, apValue, BT_MAX_GATT_OP_DATA_LEN - 1);
841 BTRCORELOG_TRACE(
"Value is %s\n", lpstBTRCoreLeGattChar->value);
842 lstBtrLeInfo.pui8Uuid = lpstBTRCoreLeGattChar->charUuid;
843 lstBtrLeInfo.pui8Value = lpstBTRCoreLeGattChar->value;
844 lstBtrLeInfo.enLeProp = enBTRCoreLEGPropChar;
847 case enBTGattDescriptor: {
848 strncpy(lpstBTRCoreLeGattDesc->propertyValue, apValue, BT_MAX_GATT_OP_DATA_LEN - 1);
849 lstBtrLeInfo.pui8Uuid = lpstBTRCoreLeGattDesc->descUuid;
850 lstBtrLeInfo.pui8Value = lpstBTRCoreLeGattDesc->propertyValue;
851 lstBtrLeInfo.enLeProp = enBTRCoreLEGPropDesc;
859 lstBtrLeInfo.enLeOper = enBTRCoreLEGOpWriteValue;
860 BTRCORELOG_TRACE(
"Btr address of device writing value is %s\n", aBtrAddr);
861 lpstlhBTRCoreLe->fpcBTRCoreLeStatusUpdate(&lstBtrLeInfo, aBtrAddr, lpstlhBTRCoreLe->pvBtLeStatusUserData);
869 lRetValue = enBTRCoreFailure;
870 BTRCORELOG_ERROR(
"UUID could not be found\n");
882 tBTRCoreLeHdl* phBTRCoreLe,
884 const char* apBtAdapter
886 enBTRCoreRet lenBTRCoreRet = enBTRCoreSuccess;
889 if (!phBTRCoreLe || !apBtConn || !apBtAdapter) {
890 BTRCORELOG_ERROR (
"enBTRCoreInvalidArg\n");
891 return enBTRCoreInvalidArg;
894 BTRCORELOG_WARN (
"BTRCore_LE_Init\n");
898 if (!pstlhBTRCoreLe) {
899 BTRCORELOG_ERROR (
"Memory Allocation Failed\n");
900 return enBTRCoreInitFailure;
903 pstlhBTRCoreLe->btIfceHdl = apBtConn;
905 if (BtrCore_BTRegisterLEGattInfoCb (apBtConn,
907 &btrCore_LE_GattInfoCb,
909 lenBTRCoreRet = enBTRCoreFailure;
912 if (BtrCore_BTRegisterLEAdvInfoCb(apBtConn,
914 &btrCore_LE_AdvInfoCb,
916 lenBTRCoreRet = enBTRCoreFailure;
919 if (lenBTRCoreRet != enBTRCoreSuccess) {
920 g_free(pstlhBTRCoreLe);
921 pstlhBTRCoreLe = NULL;
924 *phBTRCoreLe = (tBTRCoreLeHdl)pstlhBTRCoreLe;
926 return lenBTRCoreRet;
932 tBTRCoreLeHdl hBTRCoreLe,
934 const char* apBtAdapter
937 enBTRCoreRet lenBTRCoreRet = enBTRCoreSuccess;
939 if (!hBTRCoreLe || !apBtConn || !apBtAdapter) {
940 return enBTRCoreInvalidArg;
943 if (pstlhBTRCoreLe->btIfceHdl != apBtConn) {
944 BTRCORELOG_WARN (
"Incorrect Argument - btIfceHdl : Continue\n");
949 return lenBTRCoreRet;
955 tBTRCoreLeHdl hBTRCoreLe,
957 const char* apBtAdapter
959 enBTRCoreRet lenBTRCoreRet = enBTRCoreSuccess;
961 if (!hBTRCoreLe || !apBtConn || !apBtAdapter) {
962 return enBTRCoreInvalidArg;
967 BTRCORELOG_ERROR(
"Unable to register advertisement\n");
968 lenBTRCoreRet = enBTRCoreFailure;
972 BTRCORELOG_ERROR(
"Unable to register application (gatt service)\n");
973 lenBTRCoreRet = enBTRCoreFailure;
976 return lenBTRCoreRet;
982 tBTRCoreLeHdl hBTRCoreLe,
984 const char* apBtAdapter
987 enBTRCoreRet lenBTRCoreRet = enBTRCoreSuccess;
989 if (!hBTRCoreLe || !apBtConn || !apBtAdapter) {
990 return enBTRCoreInvalidArg;
993 if (pstlhBTRCoreLe->btIfceHdl != apBtConn) {
994 BTRCORELOG_WARN(
"Incorrect Argument - btIfceHdl : Continue\n");
999 lenBTRCoreRet = enBTRCoreFailure;
1002 return lenBTRCoreRet;
1007 tBTRCoreLeHdl hBTRCoreLe,
1011 enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
1014 if (NULL != lpstlhBTRCoreLe) {
1015 lpstBTRCoreLeCustAdv = &lpstlhBTRCoreLe->stCustomAdv;
1017 if (!(strncmp(aAdvtType,
"peripheral", BTRCORE_MAX_STR_LEN)) ||
1018 !(strncmp(aAdvtType,
"broadcast", BTRCORE_MAX_STR_LEN))) {
1019 strncpy(lpstBTRCoreLeCustAdv->AdvertisementType, aAdvtType, BTRCORE_MAX_STR_LEN);
1020 BTRCORELOG_INFO(
"Adv type : %s\n", lpstBTRCoreLeCustAdv->AdvertisementType);
1021 lenBTRCoreRet = enBTRCoreSuccess;
1024 lenBTRCoreRet = enBTRCoreInvalidArg;
1028 return lenBTRCoreRet;
1033 tBTRCoreLeHdl hBTRCoreLe,
1037 enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
1040 if (NULL != lpstlhBTRCoreLe) {
1041 lpstBTRCoreLeCustAdv = &lpstlhBTRCoreLe->stCustomAdv;
1043 if (BTR_MAX_GATT_SERVICE > lpstBTRCoreLeCustAdv->numServiceUUID) {
1044 strncpy(lpstBTRCoreLeCustAdv->ServiceUUID[lpstBTRCoreLeCustAdv->numServiceUUID], aUUID, BTRCORE_MAX_STR_LEN);
1045 BTRCORELOG_INFO(
"Service UUID : %s\n", lpstBTRCoreLeCustAdv->ServiceUUID[lpstBTRCoreLeCustAdv->numServiceUUID]);
1046 lpstBTRCoreLeCustAdv->numServiceUUID += 1;
1047 lenBTRCoreRet = enBTRCoreSuccess;
1050 lenBTRCoreRet = enBTRCoreInvalidArg;
1054 return lenBTRCoreRet;
1059 tBTRCoreLeHdl hBTRCoreLe,
1060 unsigned short aManfId,
1061 unsigned char* aDeviceDetails,
1065 enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
1069 if (NULL != lpstlhBTRCoreLe) {
1070 lpstBTRCoreLeCustAdv = &lpstlhBTRCoreLe->stCustomAdv;
1072 lpstManfData = &lpstBTRCoreLeCustAdv->ManfData;
1073 lpstManfData->ManfID = aManfId;
1074 BTRCORELOG_INFO(
"Manf ID : %x\n", lpstBTRCoreLeCustAdv->ManfData.ManfID);
1075 lpstManfData->lenManfData = aLenManfData;
1077 for (
int index = 0; index < aLenManfData; index++) {
1078 lpstManfData->data[index] = aDeviceDetails[index];
1079 BTRCORELOG_INFO(
"Manf data %x\n", lpstBTRCoreLeCustAdv->ManfData.data[index]);
1081 lenBTRCoreRet = enBTRCoreSuccess;
1084 return lenBTRCoreRet;
1089 tBTRCoreLeHdl hBTRCoreLe,
1093 enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
1096 if (NULL != lpstlhBTRCoreLe) {
1097 lpstBTRCoreLeCustAdv = &lpstlhBTRCoreLe->stCustomAdv;
1099 lpstBTRCoreLeCustAdv->bTxPower = aTxPower;
1100 BTRCORELOG_INFO(
"TX power is: %d\n", lpstBTRCoreLeCustAdv->bTxPower);
1101 lenBTRCoreRet = enBTRCoreSuccess;
1104 return lenBTRCoreRet;
1109 tBTRCoreLeHdl hBTRCoreLe,
1110 const char* apBtAdapter,
1114 int* aNumGattServices
1118 int* pService = NULL;
1121 btrCore_LE_GetGattInfo(lpstlhBTRCoreLe, aUUID, enBTRCoreLEGPropService, (
void*)&pService);
1123 if (NULL == pService) {
1124 if (BTR_MAX_GATT_SERVICE > lpstlhBTRCoreLe->ui16NumOfLocalGattServices) {
1125 int lIndex = lpstlhBTRCoreLe->ui16NumOfLocalGattServices;
1126 lpstBTRGattService = &lpstlhBTRCoreLe->stBTRLeGattService[lIndex];
1130 strncpy(lCurAdapterAddress, aBtrDevAddr, strlen(aBtrDevAddr));
1132 char *current_pos = strchr(lCurAdapterAddress,
':');
1133 while (current_pos){
1135 current_pos = strchr(current_pos,
':');
1139 strncpy(lpBtLeGattSrvEpPath, apBtAdapter, strlen(apBtAdapter));
1140 strncat(lpBtLeGattSrvEpPath,
"/dev_", (
sizeof(lpBtLeGattSrvEpPath) - strlen(lpBtLeGattSrvEpPath) -1));
1141 strncat(lpBtLeGattSrvEpPath, lCurAdapterAddress, strlen(lCurAdapterAddress));
1144 strncpy(lpstBTRGattService->serviceUuid, aUUID,
sizeof(lpstBTRGattService->serviceUuid));
1146 lpstBTRGattService->serviceType = aServiceType;
1148 snprintf(lpstBTRGattService->servicePath,
BT_MAX_STR_LEN - 1,
"%s/%s%02d", lpBtLeGattSrvEpPath,
"service", lIndex);
1149 BTRCORELOG_INFO(
"Service path %s\n", lpstBTRGattService->servicePath);
1151 lpstlhBTRCoreLe->ui16NumOfLocalGattServices += 1;
1153 *aNumGattServices = lpstlhBTRCoreLe->ui16NumOfLocalGattServices;
1158 return (
int*)lpstBTRGattService;
1164 tBTRCoreLeHdl hBTRCoreLe,
1165 const char* apBtAdapter,
1169 unsigned short aCharFlags,
1176 int* pParent = NULL;
1179 btrCore_LE_GetGattInfo(lpstlhBTRCoreLe, aUUID, enBTRCoreLEGPropChar, (
void*)&pChar);
1180 if (NULL == pChar) {
1182 btrCore_LE_GetGattInfo(lpstlhBTRCoreLe, aParentUUID, enBTRCoreLEGPropService, (
void*)&pParent);
1183 if (NULL != pParent) {
1186 if (BTR_MAX_GATT_CHAR > lpstBTRGattService->ui16NumberOfGattChar) {
1187 int lIndex = lpstBTRGattService->ui16NumberOfGattChar;
1188 lpstBTRCoreLeGattChar = &lpstBTRGattService->astBTRGattChar[lIndex];
1191 strncpy(lpstBTRCoreLeGattChar->charUuid, aUUID,
sizeof(lpstBTRCoreLeGattChar->charUuid));
1193 lpstBTRCoreLeGattChar->parentService = pParent;
1195 int ret = snprintf(lpstBTRCoreLeGattChar->charPath,
BT_MAX_STR_LEN - 1,
"%s/%s%04d", lpstBTRGattService->servicePath,
"char", lIndex);
1197 BTRCORELOG_INFO(
"lpstBTRCoreLeGattChar->charPath truncated\n");
1200 lpstBTRCoreLeGattChar->charFlags = aCharFlags;
1202 if ((NULL != aValue) && (BTR_GATT_CHAR_FLAG_READ == (BTR_GATT_CHAR_FLAG_READ & aCharFlags))) {
1203 strncpy(lpstBTRCoreLeGattChar->value, aValue,
sizeof(lpstBTRCoreLeGattChar->value));
1206 lpstBTRGattService->ui16NumberOfGattChar += 1;
1211 return (
int*)lpstBTRCoreLeGattChar;
1216 tBTRCoreLeHdl hBTRCoreLe,
1217 const char* apBtAdapter,
1221 unsigned short aDescFlags,
1228 int *pParent = NULL;
1231 btrCore_LE_GetGattInfo(lpstlhBTRCoreLe, aUUID, enBTRCoreLEGPropDesc, (
void*)&pDesc);
1232 if (NULL == pDesc) {
1234 btrCore_LE_GetGattInfo(lpstlhBTRCoreLe, aParentUUID, enBTRCoreLEGPropChar, (
void*)&pParent);
1235 if (NULL != pParent) {
1237 if (BTR_MAX_GATT_DESC > lpstBTRGattChar->ui16NumberOfGattDesc) {
1238 int lIndex = lpstBTRGattChar->ui16NumberOfGattDesc;
1239 lpstBTRGattDesc = &lpstBTRGattChar->atBTRGattDesc[lIndex];
1242 strncpy(lpstBTRGattDesc->descUuid, aUUID,
sizeof(lpstBTRGattDesc->descUuid));
1244 lpstBTRGattDesc->parentChar = pParent;
1246 int ret = snprintf(lpstBTRGattDesc->descPath,
BT_MAX_STR_LEN - 1,
"%s/%s%03d", lpstBTRGattChar->charPath,
"desc", lIndex);
1248 BTRCORELOG_INFO(
"lpstBTRGattDesc->descPath truncated\n");
1250 BTRCORELOG_INFO(
"Desc path %s\n", lpstBTRGattDesc->descPath);
1252 lpstBTRGattDesc->descFlags = aDescFlags;
1254 if ((NULL != aValue) && (BTR_GATT_CHAR_FLAG_READ == (BTR_GATT_CHAR_FLAG_READ & aDescFlags))) {
1255 strncpy(lpstBTRGattDesc->propertyValue, aValue,
sizeof(lpstBTRGattDesc->propertyValue));
1258 lpstBTRGattChar->ui16NumberOfGattDesc += 1;
1263 return (
int*)lpstBTRGattDesc;
1268 tBTRCoreLeHdl hBTRCoreLe,
1271 enBTRCoreLEGattProp aGattProp
1279 BTRCORELOG_ERROR(
"enBTRCoreNotInitialized\n");
1280 return enBTRCoreNotInitialized;
1282 else if ((!aValue) || (!aUUID)) {
1283 BTRCORELOG_ERROR(
"enBTRCoreInvalidArg\n");
1284 return enBTRCoreInvalidArg;
1287 lunBtOpAdapProp.enBtGattCharProp = enBTGattCPropValue;
1290 btrCore_LE_GetGattInfo(lpstlhBTRCoreLe, aUUID, aGattProp, (
void*)&lpstBTRGattChar);
1291 BTRCORELOG_INFO(
"Value is %s - \n", aValue);
1292 if (NULL != lpstBTRGattChar) {
1293 if (
BtrCore_BTSetProp(lpstlhBTRCoreLe->btIfceHdl, lpstBTRGattChar->charPath, enBTGattCharacteristic, lunBtOpAdapProp, (
void*)aValue)) {
1294 BTRCORELOG_ERROR(
"Set Char Property Value - FAILED\n");
1295 return enBTRCoreFailure;
1300 return enBTRCoreSuccess;
1305 tBTRCoreLeHdl hBTRCoreLe,
1306 tBTRCoreDevId atBTRCoreDevId,
1307 const char* apcBtUuid,
1308 enBTRCoreLEGattProp aenBTRCoreLEGattProp,
1309 void* apvBtPropValue
1316 if (!hBTRCoreLe || !atBTRCoreDevId || !apcBtUuid) {
1317 BTRCORELOG_ERROR (
"enBTRCoreInvalidArg\n");
1318 return enBTRCoreInvalidArg;
1321 if (btrCore_LE_GetDataPath(lpstlhBTRCoreLe, atBTRCoreDevId, apcBtUuid, lpcBtLePath, &lenBTOpIfceType) != enBTRCoreSuccess) {
1322 BTRCORELOG_ERROR (
"Failed to get LE Path for UUID %s !!!\n", apcBtUuid);
1323 return enBTRCoreFailure;
1326 if (!lpcBtLePath[0]) {
1327 BTRCORELOG_ERROR (
"Obtained LE Path is NULL!!!\n");
1328 return enBTRCoreFailure;
1331 switch (aenBTRCoreLEGattProp) {
1333 case enBTRCoreLEGPropUUID:
1334 if (lenBTOpIfceType == enBTGattService) {
1339 BTRCORELOG_ERROR (
"Failed to find pProfile|pService|pChar : %p|%p\n", pProfile, pService);
1340 return enBTRCoreFailure;
1343 if (btrCore_LE_GetGattCharacteristicUUIDList(pService, apvBtPropValue) != enBTRCoreSuccess) {
1344 BTRCORELOG_ERROR (
"Failed to get Char UUID List for Service %s\n", lpcBtLePath);
1345 return enBTRCoreFailure;
1348 return enBTRCoreSuccess;
1350 else if (lenBTOpIfceType == enBTGattCharacteristic) {
1353 lunBTOpIfceProp.enBtGattCharProp = enBTGattCPropService;
1354 if (
BtrCore_BTGetProp(lpstlhBTRCoreLe->btIfceHdl, lpcBtLePath, lenBTOpIfceType, lunBTOpIfceProp, servicePath)) {
1355 BTRCORELOG_ERROR (
"BtrCore_BTGetProp Failed to get servicePath on %s !!!\n", lpcBtLePath);
1356 return enBTRCoreFailure;
1364 BTRCORELOG_ERROR (
"Failed to find pProfile|pService|pChar : %p|%p|%p\n", pProfile, pService, pChar);
1365 return enBTRCoreFailure;
1368 if (btrCore_LE_GetGattDescriptorUUIDList(pChar, apvBtPropValue) != enBTRCoreSuccess) {
1369 BTRCORELOG_ERROR (
"Failed to get Desc UUID List for Char %s\n", lpcBtLePath);
1370 return enBTRCoreFailure;
1373 return enBTRCoreSuccess;
1375 else if (lenBTOpIfceType == enBTGattDescriptor) {
1379 char retCPath = -1, retSPath = -1;
1381 lunBTOpIfceProp.enBtGattDescProp = enBTGattDPropCharacteristic;
1382 retCPath =
BtrCore_BTGetProp (lpstlhBTRCoreLe->btIfceHdl, lpcBtLePath, lenBTOpIfceType, lunBTOpIfceProp, charPath);
1384 lunBTOpIfceProp.enBtGattCharProp = enBTGattCPropService;
1385 retSPath =
BtrCore_BTGetProp (lpstlhBTRCoreLe->btIfceHdl, charPath, lenBTOpIfceType, lunBTOpIfceProp, servicePath);
1387 if (retCPath || retSPath) {
1388 BTRCORELOG_ERROR (
"BtrCore_BTGetProp Failed to get charPath/servicePath : %s / %s\n", charPath, servicePath);
1389 return enBTRCoreFailure;
1398 BTRCORELOG_ERROR (
"Failed to find pProfile|pService|pChar|pDesc : %p|%p|%p|%p\n", pProfile, pService, pChar, pDesc);
1399 return enBTRCoreFailure;
1403 lstBTRCoreLeUUIDList->uuidList[0].flags = pDesc->descFlags;
1405 return enBTRCoreSuccess;
1409 case enBTRCoreLEGPropPrimary:
1410 lunBTOpIfceProp.enBtGattServiceProp = enBTGattSPropPrimary;
1413 case enBTRCoreLEGPropDevice:
1414 lunBTOpIfceProp.enBtGattServiceProp = enBTGattSPropDevice;
1417 case enBTRCoreLEGPropService:
1418 lunBTOpIfceProp.enBtGattCharProp = enBTGattCPropService;
1421 case enBTRCoreLEGPropValue:
1422 if (lenBTOpIfceType == enBTGattCharacteristic) {
1423 lunBTOpIfceProp.enBtGattCharProp = enBTGattCPropValue;
1425 else if (lenBTOpIfceType == enBTGattDescriptor) {
1426 lunBTOpIfceProp.enBtGattDescProp = enBTGattDPropValue;
1430 case enBTRCoreLEGPropNotifying:
1431 lunBTOpIfceProp.enBtGattCharProp = enBTGattCPropNotifying;
1434 case enBTRCoreLEGPropFlags:
1435 if (lenBTOpIfceType == enBTGattCharacteristic) {
1436 lunBTOpIfceProp.enBtGattCharProp = enBTGattCPropFlags;
1438 else if (lenBTOpIfceType == enBTGattDescriptor) {
1439 lunBTOpIfceProp.enBtGattDescProp = enBTGattDPropFlags;
1443 case enBTRCoreLEGPropChar:
1444 lunBTOpIfceProp.enBtGattDescProp = enBTGattDPropCharacteristic;
1447 case enBTRCoreLEGPropUnknown:
1449 BTRCORELOG_ERROR (
"Invalid enBTRCoreLEGattProp Options %d !!!\n", aenBTRCoreLEGattProp);
1454 if (lenBTOpIfceType == enBTUnknown ||
BtrCore_BTGetProp (lpstlhBTRCoreLe->btIfceHdl,
1459 BTRCORELOG_ERROR (
"Failed to get Gatt %d Prop for UUID : %s!!!\n", aenBTRCoreLEGattProp, apcBtUuid);
1460 return enBTRCoreFailure;
1463 return enBTRCoreSuccess;
1469 tBTRCoreLeHdl hBTRCoreLe,
1470 tBTRCoreDevId atBTRCoreDevId,
1471 const char* apcBtUuid,
1472 enBTRCoreLEGattOp aenBTRCoreLEGattOp,
1478 char* lpDevicePath =
"\0";
1482 if (!hBTRCoreLe || !atBTRCoreDevId || !apcBtUuid) {
1483 BTRCORELOG_ERROR (
"enBTRCoreInvalidArg\n");
1484 return enBTRCoreInvalidArg;
1487 if (btrCore_LE_GetDataPath(lpstlhBTRCoreLe, atBTRCoreDevId, apcBtUuid, lpcBtLePath, &lenBTOpIfceType) != enBTRCoreSuccess) {
1488 BTRCORELOG_ERROR (
"Failed to get LE Path for UUID %s !!!\n", apcBtUuid);
1489 return enBTRCoreFailure;
1492 if (!lpcBtLePath[0]) {
1493 BTRCORELOG_ERROR (
"LE Path is NULL!!!\n");
1494 return enBTRCoreFailure;
1497 if (lenBTOpIfceType == enBTGattService) {
1498 BTRCORELOG_ERROR (
"enBTRCoreInvalidArg | %s is a Service UUID...LE Service Ops are not available!!!\n", apcBtUuid);
1499 return enBTRCoreFailure;
1501 else if ((lenBTOpIfceType == enBTGattCharacteristic) ||
1502 (lenBTOpIfceType == enBTGattDescriptor)) {
1506 lpDevicePath = pProfile->devicePath;
1510 switch (aenBTRCoreLEGattOp) {
1512 case enBTRCoreLEGOpReadValue:
1513 lenBTLeGattOp = enBTLeGattOpReadValue;
1515 case enBTRCoreLEGOpWriteValue:
1516 lenBTLeGattOp = enBTLeGattOpWriteValue;
1518 case enBTRCoreLEGOpStartNotify:
1519 lenBTLeGattOp = enBTLeGattOpStartNotify;
1521 case enBTRCoreLEGOpStopNotify:
1522 lenBTLeGattOp = enBTLeGattOpStopNotify;
1524 case enBTRCoreLEGOpUnknown:
1526 BTRCORELOG_ERROR (
"Invalid enBTRCoreLEGattOp Options %d !!!.\n", aenBTRCoreLEGattOp);
1537 BTRCORELOG_ERROR (
"Failed to Perform Le Gatt Op %d for UUID %s !!!.\n", aenBTRCoreLEGattOp, apcBtUuid);
1538 return enBTRCoreFailure;
1541 return enBTRCoreSuccess;
1546 BTRCore_LE_RegisterStatusUpdateCb (
1547 tBTRCoreLeHdl hBTRCoreLe,
1548 fPtr_BTRCore_LeStatusUpdateCb afpcBTRCoreLeStatusUpdate,
1549 void* apvBtLeStatusUserData
1553 if (!hBTRCoreLe || !afpcBTRCoreLeStatusUpdate) {
1554 BTRCORELOG_ERROR (
"enBTRCoreInvalidArg\n");
1555 return enBTRCoreInvalidArg;
1560 phBTRCoreLe->fpcBTRCoreLeStatusUpdate = afpcBTRCoreLeStatusUpdate;
1561 phBTRCoreLe->pvBtLeStatusUserData = apvBtLeStatusUserData;
1563 return enBTRCoreSuccess;
1570 btrCore_LE_AdvInfoCb (
1571 const char* apBtAdvPath,
1579 strncpy(lpstBTLeCustomAdv->AdvertisementType, lpstCustomAdv->AdvertisementType, (
BT_MAX_STR_LEN - 1));
1580 lpstBTLeCustomAdv->bTxPower = lpstCustomAdv->bTxPower;
1582 lpstBTLeCustomAdv->numServiceUUID = lpstCustomAdv->numServiceUUID;
1583 for (
int index = 0; index < lpstCustomAdv->numServiceUUID; index++) {
1584 strncpy(lpstBTLeCustomAdv->ServiceUUID[index], lpstCustomAdv->ServiceUUID[index], (
BT_MAX_STR_LEN - 1));
1587 lpstBTLeCustomAdv->numSolicitUUID = lpstCustomAdv->numSolicitUUID;
1588 for (
int index = 0; index < lpstCustomAdv->numSolicitUUID; index++) {
1589 strncpy(lpstBTLeCustomAdv->SolicitUUID[index], lpstCustomAdv->SolicitUUID[index], (
BT_MAX_STR_LEN - 1));
1592 lpstBTLeCustomAdv->ManfData.ManfID = lpstCustomAdv->ManfData.ManfID;
1593 lpstBTLeCustomAdv->ManfData.lenManfData = lpstCustomAdv->ManfData.lenManfData;
1594 for (
int index = 0; index < lpstCustomAdv->ManfData.lenManfData; index++) {
1595 lpstBTLeCustomAdv->ManfData.data[index] = lpstCustomAdv->ManfData.data[index];
1602 btrCore_LE_GattInfoCb (
1605 const char* apBtGattPath,
1606 const char* aBtdevAddr,
1613 tBTRCoreDevId ltBTRCoreDevId = -1;
1615 if (!apBtGattPath || !aBtdevAddr || !apUserData) {
1616 BTRCORELOG_ERROR(
"Invalid arguments!!!\n");
1620 ltBTRCoreDevId = btrCore_LE_BTGenerateUniqueDeviceID (aBtdevAddr);
1621 BTRCORELOG_DEBUG(
"apBtGattPath : %s\n", apBtGattPath);
1623 if (enBTAdvertisement == aenBtOpIfceType) {
1624 if (NULL != apLeCbData) {
1625 BTRCORELOG_TRACE(
"Inovking btrCore_LE_LocalGattServerInfoCb\n");
1627 btrCore_LE_LocalGattServerInfoCb(apBtGattPath, aBtdevAddr, &lpstBTLeGattSrv, &((
stBTLeGattInfo*)apLeCbData)->nNumGattServices, apUserData);
1630 else if (aenBTDeviceState == enBTDevStFound) {
1634 if (aenBtOpIfceType == enBTGattService) {
1635 BTRCORELOG_DEBUG (
"Storing GATT Service Info...\n");
1637 char retUuid = -1, retDPath = -1;
1640 aunBTOpIfceProp.enBtGattServiceProp = enBTGattSPropUUID;
1641 retUuid =
BtrCore_BTGetProp(lpstlhBTRCoreLe->btIfceHdl, apBtGattPath, aenBtOpIfceType, aunBTOpIfceProp, (
void*)&lBtUuid);
1643 if (!retUuid && btrCore_LE_isServiceSupported(lBtUuid)) {
1645 aunBTOpIfceProp.enBtGattServiceProp = enBTGattSPropDevice;
1646 retDPath =
BtrCore_BTGetProp(lpstlhBTRCoreLe->btIfceHdl, apBtGattPath, aenBtOpIfceType, aunBTOpIfceProp, (
void*)&lBtDevPath);
1649 if (!(pProfile = btrCore_LE_FindGattProfile(lpstlhBTRCoreLe, ltBTRCoreDevId))) {
1651 if (lpstlhBTRCoreLe->ui16NumberOfGattProfile < BTR_MAX_GATT_PROFILE) {
1652 pProfile = &lpstlhBTRCoreLe->astBTRGattProfile[lpstlhBTRCoreLe->ui16NumberOfGattProfile];
1653 strncpy(pProfile->devicePath, lBtDevPath, BTRCORE_MAX_STR_LEN - 1);
1654 pProfile->deviceID = ltBTRCoreDevId;
1655 lpstlhBTRCoreLe->ui16NumberOfGattProfile++;
1656 BTRCORELOG_DEBUG (
"Added Profile for Device %llu Successfully.\n", ltBTRCoreDevId);
1659 BTRCORELOG_ERROR (
"BTR_MAX_GATT_PROFILE Added. Couldn't add anymore...\n");
1663 if (pProfile && pProfile->ui16NumberOfGattService < BTR_MAX_GATT_SERVICE) {
1664 if (!(pService = btrCore_LE_FindGattService(pProfile, apBtGattPath))) {
1665 pService = &pProfile->astBTRGattService[pProfile->ui16NumberOfGattService];
1667 strncpy(pService->servicePath, apBtGattPath, BTRCORE_MAX_STR_LEN - 1);
1668 pService->parentProfile = pProfile;
1669 pProfile->ui16NumberOfGattService++;
1670 BTRCORELOG_DEBUG (
"Added Service %s Successfully.\n", lBtUuid);
1673 BTRCORELOG_WARN (
"Gatt Service %s already exists...\n", apBtGattPath);
1677 BTRCORELOG_WARN (
"BTR_MAX_GATT_SERVICE Added. Couldn't add anymore...\n");
1681 BTRCORELOG_ERROR (
"BtrCore_BTGetProp Failed retUuid : %d | retDPath : %d.\n",retUuid, retDPath);
1685 BTRCORELOG_WARN (
"Service Not Supported | UUID : %s\n", lBtUuid);
1688 else if (aenBtOpIfceType == enBTGattCharacteristic) {
1689 BTRCORELOG_DEBUG (
"Storing GATT Characteristic Info...\n");
1691 char retUuid = -1, retSPath = -1;
1695 aunBTOpIfceProp.enBtGattCharProp = enBTGattCPropUUID;
1696 retUuid =
BtrCore_BTGetProp(lpstlhBTRCoreLe->btIfceHdl, apBtGattPath, aenBtOpIfceType, aunBTOpIfceProp, (
void*)&lBtUuid);
1698 aunBTOpIfceProp.enBtGattCharProp = enBTGattCPropService;
1699 retSPath =
BtrCore_BTGetProp(lpstlhBTRCoreLe->btIfceHdl, apBtGattPath, aenBtOpIfceType, aunBTOpIfceProp, (
void*)&lBtSerivcePath);
1701 if (!retUuid && !retSPath) {
1703 if ((pProfile = btrCore_LE_FindGattProfile(lpstlhBTRCoreLe, ltBTRCoreDevId))) {
1704 if ((pService = btrCore_LE_FindGattService(pProfile, lBtSerivcePath))) {
1706 if ((pService->ui16NumberOfGattChar < BTR_MAX_GATT_CHAR)) {
1708 if (!(pChar = btrCore_LE_FindGattCharacteristic(pService, apBtGattPath))) {
1710 memset (cFlags, 0,
sizeof(cFlags));
1711 pChar = &pService->astBTRGattChar[pService->ui16NumberOfGattChar];
1713 strncpy(pChar->charPath, apBtGattPath, BTRCORE_MAX_STR_LEN - 1);
1714 pChar->parentService = pService;
1715 aunBTOpIfceProp.enBtGattCharProp = enBTGattCPropFlags;
1716 if (!
BtrCore_BTGetProp(lpstlhBTRCoreLe->btIfceHdl, apBtGattPath, aenBtOpIfceType, aunBTOpIfceProp, (
void*)&cFlags)) {
1717 pChar->charFlags = btrCore_LE_GetAllowedGattFlagValues(cFlags, enBTGattCharacteristic);
1719 pService->ui16NumberOfGattChar++;
1720 BTRCORELOG_DEBUG (
"Added Characteristic %s Successfully.\n", lBtUuid);
1723 BTRCORELOG_WARN (
"Gatt Characteristic %s already exists.\n", apBtGattPath);
1727 BTRCORELOG_WARN (
"BTR_MAX_GATT_CHAR Addedd. Couldn't add anymore.\n");
1731 BTRCORELOG_ERROR (
"Gatt Service %s not found.\n", lBtSerivcePath);
1735 BTRCORELOG_ERROR (
"Gatt Profile for device %llu not found.\n", ltBTRCoreDevId);
1739 BTRCORELOG_ERROR (
"BtrCore_BTGetProp Failed retUuid : %d | retSPath : %d\n",retUuid, retSPath);
1742 else if (aenBtOpIfceType == enBTGattDescriptor) {
1743 BTRCORELOG_DEBUG (
"Storing GATT Descriptor Info...\n");
1746 char retUuid = -1, retCPath = -1, retSPath = -1;
1751 aunBTOpIfceProp.enBtGattDescProp = enBTGattDPropUUID;
1752 retUuid =
BtrCore_BTGetProp(lpstlhBTRCoreLe->btIfceHdl, apBtGattPath, aenBtOpIfceType, aunBTOpIfceProp, (
void*)&lBtUuid);
1754 aunBTOpIfceProp.enBtGattDescProp = enBTGattDPropCharacteristic;
1755 retCPath =
BtrCore_BTGetProp(lpstlhBTRCoreLe->btIfceHdl, apBtGattPath, aenBtOpIfceType, aunBTOpIfceProp, (
void*)&lBtCharPath);
1757 aunBTOpIfceProp.enBtGattCharProp = enBTGattCPropService;
1758 retSPath =
BtrCore_BTGetProp(lpstlhBTRCoreLe->btIfceHdl, lBtCharPath, enBTGattCharacteristic, aunBTOpIfceProp, (
void*)&lBtSerivcePath);
1760 if (!retUuid && !retCPath && !retSPath) {
1762 if ((pProfile = btrCore_LE_FindGattProfile(lpstlhBTRCoreLe, ltBTRCoreDevId))) {
1763 if ((pService = btrCore_LE_FindGattService(pProfile, lBtSerivcePath))) {
1764 if ((pChar = btrCore_LE_FindGattCharacteristic(pService, lBtCharPath))) {
1766 if (pChar->ui16NumberOfGattDesc < BTR_MAX_GATT_DESC) {
1768 if (!(pDesc = btrCore_LE_FindGattDescriptor(pChar, apBtGattPath))) {
1770 memset (dFlags, 0,
sizeof(dFlags));
1771 pDesc = &pChar->atBTRGattDesc[pChar->ui16NumberOfGattDesc];
1773 strncpy(pDesc->descPath, apBtGattPath, BTRCORE_MAX_STR_LEN - 1);
1774 pDesc->parentChar = pChar;
1775 aunBTOpIfceProp.enBtGattDescProp = enBTGattDPropFlags;
1776 if (!
BtrCore_BTGetProp(lpstlhBTRCoreLe->btIfceHdl, apBtGattPath, aenBtOpIfceType, aunBTOpIfceProp, (
void*)&dFlags)) {
1777 pDesc->descFlags = btrCore_LE_GetAllowedGattFlagValues(dFlags, enBTGattDescriptor);
1779 pChar->ui16NumberOfGattDesc++;
1780 BTRCORELOG_DEBUG (
"Added Gatt Descriptor %s Successfully.\n", lBtUuid);
1783 BTRCORELOG_WARN (
"Gatt Descriptor %s already exists.\n", apBtGattPath);
1787 BTRCORELOG_WARN (
"BTR_MAX_GATT_DESC Added. Couldn't add anymore.\n");
1791 BTRCORELOG_ERROR (
"Gatt Characteristic not found for Desc %s\n", lBtCharPath);
1795 BTRCORELOG_ERROR (
"Gatt Service not found for Desc %s.\n", lBtSerivcePath);
1799 BTRCORELOG_ERROR (
"Gatt Profile for device %llu not found...\n", ltBTRCoreDevId);
1803 BTRCORELOG_ERROR (
"BtrCore_BTGetProp Failed retUuid : %d | retCPath : %d | retSpath : %d !!!\n", retUuid, retCPath, retSPath);
1807 else if (aenBTDeviceState == enBTDevStLost) {
1808 if (aenBtOpIfceType == enBTGattService) {
1809 BTRCORELOG_DEBUG (
"Freeing Gatt Service %s \n", apBtGattPath);
1812 else if (aenBtOpIfceType == enBTGattCharacteristic) {
1813 BTRCORELOG_DEBUG (
"Freeing GATT Characteristic %s \n", apBtGattPath);
1816 else if (aenBtOpIfceType == enBTGattDescriptor) {
1817 BTRCORELOG_DEBUG (
"Freeing GATT Descriptor %s \n", apBtGattPath);
1821 else if (aenBTDeviceState == enBTDevStPropChanged) {
1822 if (aenBtOpIfceType == enBTGattService) {
1823 BTRCORELOG_DEBUG (
"Property Changed for Gatt Service %s\n", apBtGattPath);
1825 else if (aenBtOpIfceType == enBTGattCharacteristic) {
1826 BTRCORELOG_DEBUG(
"Property Changed for Gatt Char %s\n", apBtGattPath);
1828 if ((enBTLeGattOpReadValue == aenGattOp) || (enBTLeGattOpWriteValue == aenGattOp)) {
1829 if (NULL != apLeCbData) {
1830 BTRCORELOG_TRACE(
"Inovking btrCore_LE_UpdateLocalGattInfoCb\n");
1831 btrCore_LE_UpdateLocalGattInfoCb(aenBtOpIfceType, aenGattOp, aBtdevAddr, apBtGattPath, (
char*)apLeCbData, apUserData);
1834 else if (enBTLeGattOpUnknown == aenGattOp) {
1837 aunBtOpIfceProp.enBtGattCharProp = enBTGattCPropService;
1841 if (!
BtrCore_BTGetProp(lpstlhBTRCoreLe->btIfceHdl, apBtGattPath, aenBtOpIfceType, aunBtOpIfceProp, (
void*)&lBtSerivcePath)) {
1842 if ((pProfile = btrCore_LE_FindGattProfile(lpstlhBTRCoreLe, ltBTRCoreDevId))) {
1843 if ((pService = btrCore_LE_FindGattService(pProfile, lBtSerivcePath))) {
1844 if ((pChar = btrCore_LE_FindGattCharacteristic(pService, apBtGattPath))) {
1846 if ((pChar->charFlags & BTR_GATT_CHAR_FLAG_READ) ||
1847 (pChar->charFlags & BTR_GATT_CHAR_FLAG_NOTIFY)) {
1849 char value[BT_MAX_GATT_OP_DATA_LEN];
1851 memset(value,
'\0', BT_MAX_GATT_OP_DATA_LEN);
1855 aunBtOpIfceProp.enBtGattCharProp = enBTGattCPropValue;
1856 if (!
BtrCore_BTGetProp(lpstlhBTRCoreLe->btIfceHdl, apBtGattPath, enBTGattCharacteristic, aunBtOpIfceProp, (
void*)&value)) {
1857 BTRCORELOG_TRACE(
"Obtained Characteristic Value \"%s\" with len %lu\n", value, (
unsigned long)strlen(value));
1859 if (!strlen(value)) {
1860 lstBtrLeInfo.enLeOper = enBTRCoreLEGOpStartNotify;
1863 lstBtrLeInfo.enLeOper = enBTRCoreLEGOpReadValue;
1865 lstBtrLeInfo.enLeProp = enBTRCoreLEGPropValue;
1867 lstBtrLeInfo.pui8Value = value;
1868 lstBtrLeInfo.pui8Uuid = pChar->charUuid;
1871 lpstlhBTRCoreLe->fpcBTRCoreLeStatusUpdate(&lstBtrLeInfo, aBtdevAddr, lpstlhBTRCoreLe->pvBtLeStatusUserData);
1874 BTRCORELOG_ERROR(
"BtrCore_BTGetProp Failed to get property enBTGattCPropValue.\n");
1878 BTRCORELOG_ERROR(
"BTR_GATT_CHAR_FLAG_NOTIFY/READ Operation not permitted in interface %s\n", apBtGattPath);
1882 BTRCORELOG_ERROR(
"Gatt Char %s Not Found\n", apBtGattPath);
1886 BTRCORELOG_ERROR(
"Gatt Service %s Not Found\n", lBtSerivcePath);
1890 BTRCORELOG_ERROR(
"Gatt Profile for Device %llu Not Found\n", ltBTRCoreDevId);
1895 BTRCORELOG_ERROR(
"BtrCore_BTGetProp Failed to get property enBTGattCPropService\n");
1898 else if (aenBtOpIfceType == enBTGattDescriptor) {
1899 BTRCORELOG_DEBUG (
"Property Changed for Gatt Desc %s\n", apBtGattPath);
1900 if ((enBTLeGattOpReadValue == aenGattOp) || (enBTLeGattOpWriteValue == aenGattOp)) {
1901 if (NULL != apLeCbData) {
1902 BTRCORELOG_DEBUG(
"Inovking btrCore_LE_UpdateLocalGattInfoCb\n");
1903 btrCore_LE_UpdateLocalGattInfoCb(aenBtOpIfceType, aenGattOp, aBtdevAddr, apBtGattPath, (
char*)apLeCbData, apUserData);
1907 else if (aenBtOpIfceType == enBTDevice) {
1908 if ((pProfile = btrCore_LE_FindGattProfile(lpstlhBTRCoreLe, ltBTRCoreDevId))) {
1915 aunBtOpIfceProp.enBtDeviceProp = enBTDevPropSrvRslvd;
1916 if (!
BtrCore_BTGetProp (lpstlhBTRCoreLe->btIfceHdl, apBtGattPath, enBTDevice, aunBtOpIfceProp, (
void*)&i32value)) {
1917 BTRCORELOG_WARN (
"Obtained Device SERVICESRESOLVED Value %d\n", i32value);
1919 if (pProfile->i8LeGattOpReady != (
char)i32value) {
1920 pProfile->i8LeGattOpReady = (char)i32value;
1922 if (pProfile->i8LeGattOpReady) {
1923 lstBtrLeInfo.enLeOper = enBTRCoreLEGOpReady;
1924 lstBtrLeInfo.pui8Value = &pProfile->i8LeGattOpReady;
1927 lpstlhBTRCoreLe->fpcBTRCoreLeStatusUpdate (&lstBtrLeInfo, aBtdevAddr, lpstlhBTRCoreLe->pvBtLeStatusUserData);
1932 BTRCORELOG_ERROR (
"BtrCore_BTGetProp Failed to get property enBTGattCPropValue.\n");
1938 BTRCORELOG_WARN (
"Callback for irrelavent DeviceState : %d!!!\n", aenBTDeviceState);