RDK Documentation (Open Sourced RDK Components)
btrCore.c
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 //btrCore.c
20 
21 /* System Headers */
22 #include <stdio.h>
23 #include <limits.h>
24 #include <stdlib.h> //for strtoll
25 #include <unistd.h> //for getpid
26 #include <sched.h> //for StopDiscovery test
27 #include <string.h> //for strcnp
28 #include <errno.h> //for error numbers
29 #include <stdint.h>
30 
31 /* Ext lib Headers */
32 #include <glib.h>
33 
34 /* Interface lib Headers */
35 #include "btrCore_logger.h"
36 
37 /* Local Headers */
38 #include "btrCore.h"
39 #include "btrCore_service.h"
40 
41 #include "btrCore_avMedia.h"
42 #include "btrCore_le.h"
43 
44 #include "btrCore_bt_ifce.h"
45 
46 
47 #ifdef RDK_LOGGER_ENABLED
48 int b_rdk_logger_enabled = 0;
49 #endif
50 
51 /* Local types */
52 //TODO: Move to a private header
53 typedef enum _enBTRCoreTaskOp {
54  enBTRCoreTaskOpStart,
55  enBTRCoreTaskOpStop,
56  enBTRCoreTaskOpIdle,
57  enBTRCoreTaskOpProcess,
58  enBTRCoreTaskOpExit,
59  enBTRCoreTaskOpUnknown
60 } enBTRCoreTaskOp;
61 
62 typedef enum _enBTRCoreTaskProcessType {
63  enBTRCoreTaskPTcBAdapterStatus,
64  enBTRCoreTaskPTcBDeviceDisc,
65  enBTRCoreTaskPTcBDeviceRemoved,
66  enBTRCoreTaskPTcBDeviceLost,
67  enBTRCoreTaskPTcBDeviceStatus,
68  enBTRCoreTaskPTcBMediaStatus,
69  enBTRCoreTaskPTcBDevOpInfoStatus,
70  enBTRCoreTaskPTcBConnIntim,
71  enBTRCoreTaskPTcBConnAuth,
72  enBTRCoreTaskPTUnknown
73 } enBTRCoreTaskProcessType;
74 
75 
76 typedef struct _stBTRCoreTaskGAqData {
77  enBTRCoreTaskOp enBTRCoreTskOp;
78  enBTRCoreTaskProcessType enBTRCoreTskPT;
79  void* pvBTRCoreTskInData;
81 
82 
83 typedef struct _stBTRCoreOTskInData {
84  tBTRCoreDevId bTRCoreDevId;
85  enBTRCoreDeviceType enBTRCoreDevType;
86  stBTDeviceInfo* pstBTDevInfo;
88 
89 
90 typedef struct _stBTRCoreDevStateInfo {
91  enBTRCoreDeviceState eDevicePrevState;
92  enBTRCoreDeviceState eDeviceCurrState;
94 
95 
96 typedef struct _stBTRCoreHdl {
97 
98  tBTRCoreAVMediaHdl avMediaHdl;
99  tBTRCoreLeHdl leHdl;
100 
101  void* connHdl;
102  char* agentPath;
103 
104  unsigned int numOfAdapters;
105  char* adapterPath[BTRCORE_MAX_NUM_BT_ADAPTERS];
106  char* adapterAddr[BTRCORE_MAX_NUM_BT_ADAPTERS];
107 
108  char* curAdapterPath;
109  char* curAdapterAddr;
110 
111  unsigned int numOfScannedDevices;
112  stBTRCoreBTDevice stScannedDevicesArr[BTRCORE_MAX_NUM_BT_DEVICES];
113  stBTRCoreDevStateInfo stScannedDevStInfoArr[BTRCORE_MAX_NUM_BT_DEVICES];
114 
115  unsigned int numOfPairedDevices;
116  stBTRCoreBTDevice stKnownDevicesArr[BTRCORE_MAX_NUM_BT_DEVICES];
117  stBTRCoreDevStateInfo stKnownDevStInfoArr[BTRCORE_MAX_NUM_BT_DEVICES];
118 
119 
120  stBTRCoreDiscoveryCBInfo stDiscoveryCbInfo;
121  stBTRCoreDevStatusCBInfo stDevStatusCbInfo;
122  stBTRCoreMediaStatusCBInfo stMediaStatusCbInfo;
123  stBTRCoreConnCBInfo stConnCbInfo;
124 
125  fPtr_BTRCore_DeviceDiscCb fpcBBTRCoreDeviceDisc;
126  fPtr_BTRCore_StatusCb fpcBBTRCoreStatus;
127  fPtr_BTRCore_MediaStatusCb fpcBBTRCoreMediaStatus;
128  fPtr_BTRCore_ConnIntimCb fpcBBTRCoreConnIntim;
129  fPtr_BTRCore_ConnAuthCb fpcBBTRCoreConnAuth;
130 
131  void* pvcBDevDiscUserData;
132  void* pvcBStatusUserData;
133  void* pvcBMediaStatusUserData;
134  void* pvcBConnIntimUserData;
135  void* pvcBConnAuthUserData;
136 
137 
138  GThread* pThreadRunTask;
139  GAsyncQueue* pGAQueueRunTask;
140 
141  GThread* pThreadOutTask;
142  GAsyncQueue* pGAQueueOutTask;
143  enBTRCoreDeviceType aenDeviceDiscoveryType;
144 
145 } stBTRCoreHdl;
146 
147 
148 /* Static Function Prototypes */
149 static void btrCore_InitDataSt (stBTRCoreHdl* apsthBTRCore);
150 static tBTRCoreDevId btrCore_GenerateUniqueDeviceID (const char* apcDeviceMac);
151 static enBTRCoreDeviceClass btrCore_MapClassIDtoAVDevClass(unsigned int aui32ClassId);
152 static enBTRCoreDeviceClass btrCore_MapServiceClasstoDevType(unsigned int aui32ClassId);
153 static enBTRCoreDeviceClass btrCore_MapClassIDtoDevClass(unsigned int aui32ClassId);
154 static enBTRCoreDeviceType btrCore_MapClassIDToDevType(unsigned int aui32ClassId, enBTDeviceType aeBtDeviceType);
155 static enBTRCoreDeviceType btrCore_MapDevClassToDevType(enBTRCoreDeviceClass aenBTRCoreDevCl);
156 static void btrCore_ClearScannedDevicesList (stBTRCoreHdl* apsthBTRCore);
157 static int btrCore_AddDeviceToScannedDevicesArr (stBTRCoreHdl* apsthBTRCore, stBTDeviceInfo* apstBTDeviceInfo, stBTRCoreBTDevice* apstFoundDevice);
158 static enBTRCoreRet btrCore_RemoveDeviceFromScannedDevicesArr (stBTRCoreHdl* apsthBTRCore, tBTRCoreDevId aBTRCoreDevId, stBTRCoreBTDevice* astRemovedDevice);
159 static int btrCore_AddDeviceToKnownDevicesArr (stBTRCoreHdl* apsthBTRCore, stBTDeviceInfo* apstBTDeviceInfo);
160 static enBTRCoreRet btrCore_RemoveDeviceFromKnownDevicesArr (stBTRCoreHdl* apstlhBTRCore, tBTRCoreDevId aBTRCoreDevId);
161 static enBTRCoreRet btrCore_PopulateListOfPairedDevices(stBTRCoreHdl* apsthBTRCore, const char* pAdapterPath);
162 static void btrCore_MapKnownDeviceListFromPairedDeviceInfo (stBTRCoreBTDevice* knownDevicesArr, stBTPairedDeviceInfo* pairedDeviceInfo);
163 static const char* btrCore_GetScannedDeviceAddress (stBTRCoreHdl* apsthBTRCore, tBTRCoreDevId aBTRCoreDevId);
164 static const char* btrCore_GetKnownDeviceMac (stBTRCoreHdl* apsthBTRCore, tBTRCoreDevId aBTRCoreDevId);
165 static enBTRCoreRet btrCore_GetDeviceInfo (stBTRCoreHdl* apsthBTRCore, tBTRCoreDevId aBTRCoreDevId, enBTRCoreDeviceType aenBTRCoreDevType,
166  enBTDeviceType* apenBTDeviceType, stBTRCoreBTDevice** appstBTRCoreBTDevice,
167  stBTRCoreDevStateInfo** appstBTRCoreDevStateInfo, const char** appcBTRCoreBTDevicePath, const char** appcBTRCoreBTDeviceName);
168 static enBTRCoreRet btrCore_GetDeviceInfoKnown (stBTRCoreHdl* apsthBTRCore, tBTRCoreDevId aBTRCoreDevId, enBTRCoreDeviceType aenBTRCoreDevType,
169  enBTDeviceType* apenBTDeviceType, stBTRCoreBTDevice** appstBTRCoreBTDevice,
170  stBTRCoreDevStateInfo** appstBTRCoreDevStateInfo, const char** appcBTRCoreBTDevicePath);
171 static void btrCore_ShowSignalStrength (short strength);
172 static unsigned int btrCore_BTParseUUIDValue (const char *pUUIDString, char* pServiceNameOut);
173 static enBTRCoreDeviceState btrCore_BTParseDeviceState (const char* pcStateValue);
174 static eBTRCoreMedElementType btrCore_GetMediaElementType (eBTRCoreAVMElementType aeMediaElementType);
175 
176 static enBTRCoreRet btrCore_RunTaskAddOp (GAsyncQueue* apRunTaskGAq, enBTRCoreTaskOp aenRunTaskOp, enBTRCoreTaskProcessType aenRunTaskPT, void* apvRunTaskInData);
177 static enBTRCoreRet btrCore_OutTaskAddOp (GAsyncQueue* apOutTaskGAq, enBTRCoreTaskOp aenOutTaskOp, enBTRCoreTaskProcessType aenOutTaskPT, void* apvOutTaskInData);
178 
179 static BOOLEAN btrCore_IsDevNameSameAsAddress(const stBTRCoreBTDevice *dev);
180 
181 /* Local Op Threads Prototypes */
182 static gpointer btrCore_RunTask (gpointer apsthBTRCore);
183 static gpointer btrCore_OutTask (gpointer apsthBTRCore);
184 
185 /* Incoming Callbacks Prototypes */
186 static int btrCore_BTAdapterStatusUpdateCb (enBTAdapterProp aeBtAdapterProp, stBTAdapterInfo* apstBTAdapterInfo, void* apUserData);
187 static int btrCore_BTDeviceStatusUpdateCb (enBTDeviceType aeBtDeviceType, enBTDeviceState aeBtDeviceState, stBTDeviceInfo* apstBTDeviceInfo, void* apUserData);
188 static int btrCore_BTDeviceConnectionIntimationCb (enBTDeviceType aeBtDeviceType, stBTDeviceInfo* apstBTDeviceInfo, unsigned int aui32devPassKey, unsigned char ucIsReqConfirmation, void* apUserData);
189 static int btrCore_BTDeviceAuthenticationCb (enBTDeviceType aeBtDeviceType, stBTDeviceInfo* apstBTDeviceInfo, void* apUserData);
190 
191 static enBTRCoreRet btrCore_BTMediaStatusUpdateCb (stBTRCoreAVMediaStatusUpdate* apMediaStreamStatus, const char* apBtdevAddr, void* apUserData);
192 static enBTRCoreRet btrCore_BTLeStatusUpdateCb (stBTRCoreLeGattInfo* apstBtrLeInfo, const char* apcBtdevAddr, void* apvUserData);
193 
194 
195 /* Static Function Definition */
196 static void
197 btrCore_InitDataSt (
198  stBTRCoreHdl* apsthBTRCore
199 ) {
200  int i;
201 
202 
203  apsthBTRCore->avMediaHdl = NULL;
204  apsthBTRCore->leHdl = NULL;
205  apsthBTRCore->agentPath = NULL;
206 
207 
208  /* Current Adapter Path */
209  apsthBTRCore->curAdapterPath = NULL;
210 
211  /* Current Adapter */
212  apsthBTRCore->curAdapterAddr = NULL;
213  apsthBTRCore->curAdapterAddr = (char*)g_malloc0(sizeof(char) * (BD_NAME_LEN + 1));
214  memset(apsthBTRCore->curAdapterAddr, '\0', sizeof(char) * (BD_NAME_LEN + 1));
215 
216  /* Adapters */
217  for (i = 0; i < BTRCORE_MAX_NUM_BT_ADAPTERS; i++) {
218  apsthBTRCore->adapterPath[i] = NULL;
219  apsthBTRCore->adapterPath[i] = (char*)g_malloc0(sizeof(char) * (BD_NAME_LEN + 1));
220  memset(apsthBTRCore->adapterPath[i], '\0', sizeof(char) * (BD_NAME_LEN + 1));
221 
222  apsthBTRCore->adapterAddr[i] = NULL;
223  apsthBTRCore->adapterAddr[i] = (char*)g_malloc0(sizeof(char) * (BD_NAME_LEN + 1));
224  memset(apsthBTRCore->adapterAddr[i], '\0', sizeof(char) * (BD_NAME_LEN + 1));
225  }
226 
227  /* Scanned Devices */
228  for (i = 0; i < BTRCORE_MAX_NUM_BT_DEVICES; i++) {
229  apsthBTRCore->stScannedDevicesArr[i].tDeviceId = 0;
230  apsthBTRCore->stScannedDevicesArr[i].enDeviceType = enBTRCore_DC_Unknown;
231  apsthBTRCore->stScannedDevicesArr[i].bFound = FALSE;
232  apsthBTRCore->stScannedDevicesArr[i].bDeviceConnected = FALSE;
233  apsthBTRCore->stScannedDevicesArr[i].i32RSSI = INT_MIN;
234 
235  memset (apsthBTRCore->stScannedDevicesArr[i].pcDeviceName, '\0', sizeof(char) * (BD_NAME_LEN + 1));
236  memset (apsthBTRCore->stScannedDevicesArr[i].pcDeviceAddress, '\0', sizeof(char) * (BD_NAME_LEN + 1));
237  memset (apsthBTRCore->stScannedDevicesArr[i].pcDevicePath, '\0', sizeof(char) * (BD_NAME_LEN + 1));
238 
239  memset (apsthBTRCore->stScannedDevicesArr[i].stAdServiceData, 0, (BTRCORE_MAX_DEVICE_PROFILE * sizeof(stBTRCoreAdServiceData)));
240 
241  apsthBTRCore->stScannedDevStInfoArr[i].eDevicePrevState = enBTRCoreDevStInitialized;
242  apsthBTRCore->stScannedDevStInfoArr[i].eDeviceCurrState = enBTRCoreDevStInitialized;
243  }
244 
245  apsthBTRCore->numOfScannedDevices = 0;
246  apsthBTRCore->numOfPairedDevices = 0;
247 
248 
249  /* Known Devices */
250  for (i = 0; i < BTRCORE_MAX_NUM_BT_DEVICES; i++) {
251  apsthBTRCore->stKnownDevicesArr[i].tDeviceId = 0;
252  apsthBTRCore->stKnownDevicesArr[i].enDeviceType = enBTRCore_DC_Unknown;
253  apsthBTRCore->stKnownDevicesArr[i].bFound = FALSE;
254  apsthBTRCore->stKnownDevicesArr[i].bDeviceConnected = FALSE;
255  apsthBTRCore->stKnownDevicesArr[i].i32RSSI = INT_MIN;
256 
257  memset (apsthBTRCore->stKnownDevicesArr[i].pcDeviceName, '\0', sizeof(char) * (BD_NAME_LEN + 1));
258  memset (apsthBTRCore->stKnownDevicesArr[i].pcDeviceAddress, '\0', sizeof(char) * (BD_NAME_LEN + 1));
259  memset (apsthBTRCore->stKnownDevicesArr[i].pcDevicePath, '\0', sizeof(char) * (BD_NAME_LEN + 1));
260 
261  memset (apsthBTRCore->stKnownDevicesArr[i].stAdServiceData, 0, (BTRCORE_MAX_DEVICE_PROFILE * sizeof(stBTRCoreAdServiceData)));
262 
263  apsthBTRCore->stKnownDevStInfoArr[i].eDevicePrevState = enBTRCoreDevStInitialized;
264  apsthBTRCore->stKnownDevStInfoArr[i].eDeviceCurrState = enBTRCoreDevStInitialized;
265  }
266 
267  /* Callback Info */
268  apsthBTRCore->stDevStatusCbInfo.eDevicePrevState = enBTRCoreDevStInitialized;
269  apsthBTRCore->stDevStatusCbInfo.eDeviceCurrState = enBTRCoreDevStInitialized;
270 
271 
272  memset(&apsthBTRCore->stConnCbInfo, 0, sizeof(stBTRCoreConnCBInfo));
273 
274  apsthBTRCore->fpcBBTRCoreDeviceDisc = NULL;
275  apsthBTRCore->fpcBBTRCoreStatus = NULL;
276  apsthBTRCore->fpcBBTRCoreMediaStatus = NULL;
277  apsthBTRCore->fpcBBTRCoreConnIntim = NULL;
278  apsthBTRCore->fpcBBTRCoreConnAuth = NULL;
279 
280  apsthBTRCore->pvcBDevDiscUserData = NULL;
281  apsthBTRCore->pvcBStatusUserData = NULL;
282  apsthBTRCore->pvcBMediaStatusUserData = NULL;
283  apsthBTRCore->pvcBConnIntimUserData = NULL;
284  apsthBTRCore->pvcBConnAuthUserData = NULL;
285 
286  apsthBTRCore->pThreadRunTask = NULL;
287  apsthBTRCore->pGAQueueRunTask = NULL;
288 
289  apsthBTRCore->pThreadOutTask = NULL;
290  apsthBTRCore->pGAQueueOutTask = NULL;
291 
292  /* Always safer to initialze Global variables, init if any left or added */
293 }
294 
295 
296 static tBTRCoreDevId
297 btrCore_GenerateUniqueDeviceID (
298  const char* apcDeviceMac
299 ) {
300  tBTRCoreDevId lBTRCoreDevId = 0;
301  char lcDevHdlArr[13] = {'\0'};
302 
303  // MAC Address Format
304  // AA:BB:CC:DD:EE:FF\0
305  if (apcDeviceMac && (strlen(apcDeviceMac) >= 17)) {
306  lcDevHdlArr[0] = apcDeviceMac[0];
307  lcDevHdlArr[1] = apcDeviceMac[1];
308  lcDevHdlArr[2] = apcDeviceMac[3];
309  lcDevHdlArr[3] = apcDeviceMac[4];
310  lcDevHdlArr[4] = apcDeviceMac[6];
311  lcDevHdlArr[5] = apcDeviceMac[7];
312  lcDevHdlArr[6] = apcDeviceMac[9];
313  lcDevHdlArr[7] = apcDeviceMac[10];
314  lcDevHdlArr[8] = apcDeviceMac[12];
315  lcDevHdlArr[9] = apcDeviceMac[13];
316  lcDevHdlArr[10] = apcDeviceMac[15];
317  lcDevHdlArr[11] = apcDeviceMac[16];
318 
319  lBTRCoreDevId = (tBTRCoreDevId) strtoll(lcDevHdlArr, NULL, 16);
320  }
321 
322  return lBTRCoreDevId;
323 }
324 
325 static enBTRCoreDeviceClass
326 btrCore_MapClassIDtoAVDevClass (
327  unsigned int aui32ClassId
328 ) {
329  enBTRCoreDeviceClass rc = enBTRCore_DC_Unknown;
330 
331  if (((aui32ClassId & 0x400u) == 0x400u) || ((aui32ClassId & 0x200u) == 0x200u) || ((aui32ClassId & 0x100u) == 0x100u)) {
332  unsigned int ui32DevClassID = aui32ClassId & 0xFFFu;
333  BTRCORELOG_TRACE ("ui32DevClassID = 0x%x\n", ui32DevClassID);
334 
335  if (ui32DevClassID == enBTRCore_DC_Tablet) {
336  BTRCORELOG_INFO ("Its a enBTRCore_DC_Tablet\n");
337  rc = enBTRCore_DC_Tablet;
338  }
339  else if (ui32DevClassID == enBTRCore_DC_SmartPhone) {
340  BTRCORELOG_INFO ("enBTRCore_DC_SmartPhone\n");
341  rc = enBTRCore_DC_SmartPhone;
342  }
343  else if (ui32DevClassID == enBTRCore_DC_WearableHeadset) {
344  BTRCORELOG_INFO ("enBTRCore_DC_WearableHeadset\n");
345  rc = enBTRCore_DC_WearableHeadset;
346  }
347  else if (ui32DevClassID == enBTRCore_DC_Handsfree) {
348  BTRCORELOG_INFO ("enBTRCore_DC_Handsfree\n");
349  rc = enBTRCore_DC_Handsfree;
350  }
351  else if (ui32DevClassID == enBTRCore_DC_Reserved) {
352  BTRCORELOG_INFO ("enBTRCore_DC_Reserved\n");
353  rc = enBTRCore_DC_Reserved;
354  }
355  else if (ui32DevClassID == enBTRCore_DC_Microphone) {
356  BTRCORELOG_INFO ("enBTRCore_DC_Microphone\n");
357  rc = enBTRCore_DC_Microphone;
358  }
359  else if (ui32DevClassID == enBTRCore_DC_Loudspeaker) {
360  BTRCORELOG_INFO ("enBTRCore_DC_Loudspeaker\n");
361  rc = enBTRCore_DC_Loudspeaker;
362  }
363  else if (ui32DevClassID == enBTRCore_DC_Headphones) {
364  BTRCORELOG_INFO ("enBTRCore_DC_Headphones\n");
365  rc = enBTRCore_DC_Headphones;
366  }
367  else if (ui32DevClassID == enBTRCore_DC_HID_AudioRemote) {
368  BTRCORELOG_INFO ("enBTRCore_DC_HID_AudioRemote\n");
369  rc = enBTRCore_DC_HID_AudioRemote;
370  }
371  else if (ui32DevClassID == enBTRCore_DC_PortableAudio) {
372  BTRCORELOG_INFO ("enBTRCore_DC_PortableAudio\n");
373  rc = enBTRCore_DC_PortableAudio;
374  }
375  else if (ui32DevClassID == enBTRCore_DC_CarAudio) {
376  BTRCORELOG_INFO ("enBTRCore_DC_CarAudio\n");
377  rc = enBTRCore_DC_CarAudio;
378  }
379  else if (ui32DevClassID == enBTRCore_DC_STB) {
380  BTRCORELOG_INFO ("enBTRCore_DC_STB\n");
381  rc = enBTRCore_DC_STB;
382  }
383  else if (ui32DevClassID == enBTRCore_DC_HIFIAudioDevice) {
384  BTRCORELOG_INFO ("enBTRCore_DC_HIFIAudioDevice\n");
385  rc = enBTRCore_DC_HIFIAudioDevice;
386  }
387  else if (ui32DevClassID == enBTRCore_DC_VCR) {
388  BTRCORELOG_INFO ("enBTRCore_DC_VCR\n");
389  rc = enBTRCore_DC_VCR;
390  }
391  else if (ui32DevClassID == enBTRCore_DC_VideoCamera) {
392  BTRCORELOG_INFO ("enBTRCore_DC_VideoCamera\n");
393  rc = enBTRCore_DC_VideoCamera;
394  }
395  else if (ui32DevClassID == enBTRCore_DC_Camcoder) {
396  BTRCORELOG_INFO ("enBTRCore_DC_Camcoder\n");
397  rc = enBTRCore_DC_Camcoder;
398  }
399  else if (ui32DevClassID == enBTRCore_DC_VideoMonitor) {
400  BTRCORELOG_INFO ("enBTRCore_DC_VideoMonitor\n");
401  rc = enBTRCore_DC_VideoMonitor;
402  }
403  else if (ui32DevClassID == enBTRCore_DC_TV) {
404  BTRCORELOG_INFO ("enBTRCore_DC_TV\n");
405  rc = enBTRCore_DC_TV;
406  }
407  else if (ui32DevClassID == enBTRCore_DC_VideoConference) {
408  BTRCORELOG_INFO ("enBTRCore_DC_VideoConference\n");
409  rc = enBTRCore_DC_TV;
410  }
411  }
412 
413  return rc;
414 }
415 
416 static enBTRCoreDeviceClass
417 btrCore_MapServiceClasstoDevType (
418  unsigned int aui32ClassId
419 ) {
420  enBTRCoreDeviceClass rc = enBTRCore_DC_Unknown;
421 
422  /* Refer https://www.bluetooth.com/specifications/assigned-numbers/baseband
423  * The bit 18 set to represent AUDIO OUT service Devices.
424  * The bit 19 can be set to represent AUDIO IN Service devices
425  * The bit 21 set to represent AUDIO Services (Mic, Speaker, headset).
426  * The bit 22 set to represent Telephone Services (headset).
427  */
428 
429  if (0x40000u & aui32ClassId) {
430  BTRCORELOG_TRACE ("Its a Rendering Class of Service.\n");
431  if ((rc = btrCore_MapClassIDtoAVDevClass(aui32ClassId)) == enBTRCore_DC_Unknown) {
432  BTRCORELOG_TRACE ("Its a Rendering Class of Service. But no Audio Device Class defined\n");
433  }
434  }
435  else if (0x80000u & aui32ClassId) {
436  BTRCORELOG_TRACE ("Its a Capturing Service.\n");
437  if ((rc = btrCore_MapClassIDtoAVDevClass(aui32ClassId)) == enBTRCore_DC_Unknown) {
438  BTRCORELOG_TRACE ("Its a Capturing Service. But no Audio Device Class defined\n");
439  }
440  }
441  else if (0x200000u & aui32ClassId) {
442  BTRCORELOG_TRACE ("Its a Audio Class of Service.\n");
443  if ((rc = btrCore_MapClassIDtoAVDevClass(aui32ClassId)) == enBTRCore_DC_Unknown) {
444  BTRCORELOG_TRACE ("Its a Audio Class of Service. But no Audio Device Class defined; Lets assume its Loud Speaker\n");
445  rc = enBTRCore_DC_Loudspeaker;
446  }
447  }
448  else if (0x400000u & aui32ClassId) {
449  BTRCORELOG_TRACE ("Its a Telephony Class of Service. So, enBTDevAudioSink\n");
450  if ((rc = btrCore_MapClassIDtoAVDevClass(aui32ClassId)) == enBTRCore_DC_Unknown) {
451  BTRCORELOG_TRACE ("Its a Telephony Class of Service. But no Audio Device Class defined;\n");
452  }
453  }
454 
455  return rc;
456 }
457 
458 static enBTRCoreDeviceClass
459 btrCore_MapClassIDtoDevClass (
460  unsigned int aui32ClassId
461 ) {
462  enBTRCoreDeviceClass rc = enBTRCore_DC_Unknown;
463  BTRCORELOG_TRACE ("classID = 0x%x\n", aui32ClassId);
464 
465  if (aui32ClassId == enBTRCore_DC_Tile) {
466  BTRCORELOG_INFO ("enBTRCore_DC_Tile\n");
467  rc = enBTRCore_DC_Tile;
468  }
469 
470  if (rc == enBTRCore_DC_Unknown)
471  rc = btrCore_MapServiceClasstoDevType(aui32ClassId);
472 
473  /* If the Class of Service is not audio, lets parse the COD */
474  if (rc == enBTRCore_DC_Unknown) {
475  if ((aui32ClassId & 0x500u) == 0x500u) {
476  unsigned int ui32DevClassID = aui32ClassId & 0xFFFu;
477  BTRCORELOG_TRACE ("ui32DevClassID = 0x%x\n", ui32DevClassID);
478 
479  if (ui32DevClassID == enBTRCore_DC_HID_Keyboard) {
480  BTRCORELOG_INFO ("Its a enBTRCore_DC_HID_Keyboard\n");
481  rc = enBTRCore_DC_HID_Keyboard;
482  }
483  else if (ui32DevClassID == enBTRCore_DC_HID_Mouse) {
484  BTRCORELOG_INFO ("Its a enBTRCore_DC_HID_Mouse\n");
485  rc = enBTRCore_DC_HID_Mouse;
486  }
487  else if (ui32DevClassID == enBTRCore_DC_HID_MouseKeyBoard) {
488  BTRCORELOG_INFO ("Its a enBTRCore_DC_HID_MouseKeyBoard\n");
489  rc = enBTRCore_DC_HID_MouseKeyBoard;
490  }
491  else if (ui32DevClassID == enBTRCore_DC_HID_AudioRemote) {
492  BTRCORELOG_INFO ("Its a enBTRCore_DC_HID_AudioRemote\n");
493  rc = enBTRCore_DC_HID_AudioRemote;
494  }
495  else if (ui32DevClassID == enBTRCore_DC_HID_Joystick) {
496  BTRCORELOG_INFO ("Its a enBTRCore_DC_HID_Joystick\n");
497  rc = enBTRCore_DC_HID_Joystick;
498  }
499  else if (ui32DevClassID == enBTRCore_DC_HID_GamePad) {
500  BTRCORELOG_INFO ("Its a enBTRCore_DC_HID_GamePad\n");
501  rc = enBTRCore_DC_HID_GamePad;
502  }
503  }
504  else
505  {
506  rc = btrCore_MapClassIDtoAVDevClass(aui32ClassId);
507  }
508  }
509 
510  return rc;
511 }
512 
513 static enBTRCoreDeviceType
514 btrCore_MapClassIDToDevType (
515  unsigned int aui32ClassId,
516  enBTDeviceType aeBtDeviceType
517 ) {
518  enBTRCoreDeviceType lenBTRCoreDevType = enBTRCoreUnknown;
519  enBTRCoreDeviceClass lenBTRCoreDevCl = enBTRCore_DC_Unknown;
520 
521  switch (aeBtDeviceType) {
522  case enBTDevAudioSink:
523  lenBTRCoreDevCl = btrCore_MapClassIDtoDevClass(aui32ClassId);
524  if (lenBTRCoreDevCl == enBTRCore_DC_WearableHeadset) {
525  lenBTRCoreDevType = enBTRCoreHeadSet;
526  }
527  else if (lenBTRCoreDevCl == enBTRCore_DC_Headphones) {
528  lenBTRCoreDevType = enBTRCoreHeadSet;
529  }
530  else if (lenBTRCoreDevCl == enBTRCore_DC_Loudspeaker) {
531  lenBTRCoreDevType = enBTRCoreSpeakers;
532  }
533  else if (lenBTRCoreDevCl == enBTRCore_DC_HIFIAudioDevice) {
534  lenBTRCoreDevType = enBTRCoreSpeakers;
535  }
536  else {
537  lenBTRCoreDevType = enBTRCoreSpeakers;
538  }
539  break;
540  case enBTDevAudioSource:
541  lenBTRCoreDevCl = btrCore_MapClassIDtoDevClass(aui32ClassId);
542  if (lenBTRCoreDevCl == enBTRCore_DC_SmartPhone) {
543  lenBTRCoreDevType = enBTRCoreMobileAudioIn;
544  }
545  else if (lenBTRCoreDevCl == enBTRCore_DC_Tablet) {
546  lenBTRCoreDevType = enBTRCorePCAudioIn;
547  }
548  else {
549  lenBTRCoreDevType = enBTRCoreMobileAudioIn;
550  }
551  break;
552  case enBTDevHFPHeadset:
553  lenBTRCoreDevType = enBTRCoreHeadSet;
554  break;
555  case enBTDevHFPAudioGateway:
556  lenBTRCoreDevType = enBTRCoreHeadSet;
557  break;
558  case enBTDevLE:
559  lenBTRCoreDevType = enBTRCoreLE;
560  break;
561  case enBTDevHID:
562  lenBTRCoreDevType = enBTRCoreHID;
563  break;
564  case enBTDevUnknown:
565  default:
566  lenBTRCoreDevType = enBTRCoreUnknown;
567  break;
568  }
569 
570  return lenBTRCoreDevType;
571 }
572 
573 
574 static enBTRCoreDeviceType
575 btrCore_MapDevClassToDevType (
576  enBTRCoreDeviceClass aenBTRCoreDevCl
577 ) {
578  enBTRCoreDeviceType lenBTRCoreDevType = enBTRCoreUnknown;
579 
580  if (aenBTRCoreDevCl == enBTRCore_DC_WearableHeadset) {
581  lenBTRCoreDevType = enBTRCoreHeadSet;
582  }
583  else if (aenBTRCoreDevCl == enBTRCore_DC_Headphones) {
584  lenBTRCoreDevType = enBTRCoreHeadSet;
585  }
586  else if (aenBTRCoreDevCl == enBTRCore_DC_Loudspeaker) {
587  lenBTRCoreDevType = enBTRCoreSpeakers;
588  }
589  else if (aenBTRCoreDevCl == enBTRCore_DC_HIFIAudioDevice) {
590  lenBTRCoreDevType = enBTRCoreSpeakers;
591  }
592  else if (aenBTRCoreDevCl == enBTRCore_DC_PortableAudio) {
593  lenBTRCoreDevType = enBTRCoreSpeakers;
594  }
595  else if (aenBTRCoreDevCl == enBTRCore_DC_CarAudio) {
596  lenBTRCoreDevType = enBTRCoreSpeakers;
597  }
598  else if (aenBTRCoreDevCl == enBTRCore_DC_SmartPhone) {
599  lenBTRCoreDevType = enBTRCoreMobileAudioIn;
600  }
601  else if (aenBTRCoreDevCl == enBTRCore_DC_Tablet) {
602  lenBTRCoreDevType = enBTRCorePCAudioIn;
603  }
604  else if (aenBTRCoreDevCl == enBTRCore_DC_HID_Keyboard) {
605  lenBTRCoreDevType = enBTRCoreHID;
606  }
607  else if (aenBTRCoreDevCl == enBTRCore_DC_HID_Mouse) {
608  lenBTRCoreDevType = enBTRCoreHID;
609  }
610  else if (aenBTRCoreDevCl == enBTRCore_DC_HID_MouseKeyBoard) {
611  lenBTRCoreDevType = enBTRCoreHID;
612  }
613  else if (aenBTRCoreDevCl == enBTRCore_DC_HID_AudioRemote) {
614  lenBTRCoreDevType = enBTRCoreHID;
615  }
616  else if (aenBTRCoreDevCl == enBTRCore_DC_HID_Joystick) {
617  lenBTRCoreDevType = enBTRCoreHID;
618  }
619  else if (aenBTRCoreDevCl == enBTRCore_DC_HID_GamePad) {
620  lenBTRCoreDevType = enBTRCoreHID;
621  }
622  else if (aenBTRCoreDevCl == enBTRCore_DC_Tile) {
623  lenBTRCoreDevType = enBTRCoreLE;
624  //TODO: May be use should have AudioDeviceClass & LE DeviceClass
625  // will help us to identify the device Type as LE
626  }
627  else {
628  lenBTRCoreDevType = enBTRCoreUnknown;
629  }
630 
631  return lenBTRCoreDevType;
632 }
633 
634 static eBTRCoreMedElementType
635 btrCore_GetMediaElementType (
636  eBTRCoreAVMElementType aeMediaElementType
637 ) {
638  eBTRCoreMedElementType lenMedElementType;
639 
640  switch (aeMediaElementType) {
641  case eBTRCoreAVMETypeAlbum:
642  lenMedElementType = enBTRCoreMedETypeAlbum;
643  break;
644  case eBTRCoreAVMETypeArtist:
645  lenMedElementType = enBTRCoreMedETypeArtist;
646  break;
647  case eBTRCoreAVMETypeGenre:
648  lenMedElementType = enBTRCoreMedETypeGenre;
649  break;
650  case eBTRCoreAVMETypeCompilation:
651  lenMedElementType = enBTRCoreMedETypeCompilation;
652  break;
653  case eBTRCoreAVMETypePlayList:
654  lenMedElementType = enBTRCoreMedETypePlayList;
655  break;
656  case eBTRCoreAVMETypeTrackList:
657  lenMedElementType = enBTRCoreMedETypeTrackList;
658  break;
659  case eBTRCoreAVMETypeTrack:
660  lenMedElementType = enBTRCoreMedETypeTrack;
661  break;
662  default:
663  lenMedElementType = enBTRCoreMedETypeTrackList;
664  }
665 
666  return lenMedElementType;
667 }
668 
669 static void
670 btrCore_ClearScannedDevicesList (
671  stBTRCoreHdl* apsthBTRCore
672 ) {
673  int i;
674 
675  for (i = 0; i < BTRCORE_MAX_NUM_BT_DEVICES; i++) {
676  apsthBTRCore->stScannedDevicesArr[i].tDeviceId = 0;
677  apsthBTRCore->stScannedDevicesArr[i].i32RSSI = INT_MIN;
678  apsthBTRCore->stScannedDevicesArr[i].bFound = FALSE;
679  apsthBTRCore->stScannedDevicesArr[i].bDeviceConnected = FALSE;
680  apsthBTRCore->stScannedDevicesArr[i].enDeviceType = enBTRCore_DC_Unknown;
681 
682  memset (apsthBTRCore->stScannedDevicesArr[i].pcDeviceName, '\0', sizeof(apsthBTRCore->stScannedDevicesArr[i].pcDeviceName));
683  memset (apsthBTRCore->stScannedDevicesArr[i].pcDeviceAddress, '\0', sizeof(apsthBTRCore->stScannedDevicesArr[i].pcDeviceAddress));
684  memset (apsthBTRCore->stScannedDevicesArr[i].pcDevicePath, '\0', sizeof(apsthBTRCore->stScannedDevicesArr[i].pcDevicePath));
685 
686  apsthBTRCore->stScannedDevStInfoArr[i].eDevicePrevState = enBTRCoreDevStInitialized;
687  apsthBTRCore->stScannedDevStInfoArr[i].eDeviceCurrState = enBTRCoreDevStInitialized;
688  }
689 
690  apsthBTRCore->numOfScannedDevices = 0;
691 }
692 
693 
694 static int
695 btrCore_AddDeviceToScannedDevicesArr (
696  stBTRCoreHdl* apsthBTRCore,
697  stBTDeviceInfo* apstBTDeviceInfo,
698  stBTRCoreBTDevice* apstFoundDevice
699 ) {
700  int i;
701  int count = 0;
702  stBTRCoreBTDevice lstFoundDevice;
703 
704  memset(&lstFoundDevice, 0, sizeof(stBTRCoreBTDevice));
705 
706 
707  lstFoundDevice.bFound = FALSE;
708  lstFoundDevice.i32RSSI = apstBTDeviceInfo->i32RSSI;
709  lstFoundDevice.ui32VendorId = apstBTDeviceInfo->ui16Vendor;
710  lstFoundDevice.tDeviceId = btrCore_GenerateUniqueDeviceID(apstBTDeviceInfo->pcAddress);
711  lstFoundDevice.enDeviceType = btrCore_MapClassIDtoDevClass(apstBTDeviceInfo->ui32Class);
712  lstFoundDevice.ui32DevClassBtSpec = apstBTDeviceInfo->ui32Class;
713 
714  strncpy(lstFoundDevice.pcDeviceName, apstBTDeviceInfo->pcName, BD_NAME_LEN);
715  strncpy(lstFoundDevice.pcDeviceAddress, apstBTDeviceInfo->pcAddress, BD_NAME_LEN);
716  strncpy(lstFoundDevice.pcDevicePath, apstBTDeviceInfo->pcDevicePath, BD_NAME_LEN);
717 
718  /* Populate the profile supported */
719  for (i = 0; i < BT_MAX_DEVICE_PROFILE; i++) {
720  if (apstBTDeviceInfo->aUUIDs[i][0] == '\0')
721  break;
722  else
723  lstFoundDevice.stDeviceProfile.profile[i].uuid_value = btrCore_BTParseUUIDValue(apstBTDeviceInfo->aUUIDs[i],
724  lstFoundDevice.stDeviceProfile.profile[i].profile_name);
725  }
726  lstFoundDevice.stDeviceProfile.numberOfService = i;
727 
728  if (lstFoundDevice.enDeviceType == enBTRCore_DC_Unknown) {
729  for (i = 0; i < lstFoundDevice.stDeviceProfile.numberOfService; i++) {
730  if (lstFoundDevice.stDeviceProfile.profile[i].uuid_value == strtol(BTR_CORE_A2SNK, NULL, 16)) {
731  lstFoundDevice.enDeviceType = enBTRCore_DC_Loudspeaker;
732  }
733  else if (lstFoundDevice.stDeviceProfile.profile[i].uuid_value == strtol(BTR_CORE_A2SRC, NULL, 16)) {
734  lstFoundDevice.enDeviceType = enBTRCore_DC_SmartPhone;
735  }
736  else if ((lstFoundDevice.stDeviceProfile.profile[i].uuid_value == strtol(BTR_CORE_GATT_TILE_1, NULL, 16)) ||
737  (lstFoundDevice.stDeviceProfile.profile[i].uuid_value == strtol(BTR_CORE_GATT_TILE_2, NULL, 16)) ||
738  (lstFoundDevice.stDeviceProfile.profile[i].uuid_value == strtol(BTR_CORE_GATT_TILE_3, NULL, 16))) {
739  lstFoundDevice.enDeviceType = enBTRCore_DC_Tile;
740  }
741  else if (lstFoundDevice.stDeviceProfile.profile[i].uuid_value == strtol(BTR_CORE_HID_1, NULL, 16) ||
742  lstFoundDevice.stDeviceProfile.profile[i].uuid_value == strtol(BTR_CORE_HID_2, NULL, 16)) {
743  lstFoundDevice.enDeviceType = enBTRCore_DC_HID_Keyboard;
744  }
745  }
746  }
747 
748  // It seems like the GAP appearance is known well before the GATT service discovery is
749  // completed. If we can identify the device as a gamepad now, then let's go ahead and
750  // do that. The result is that gamepad discovery takes place much more quickly.
751  if (lstFoundDevice.enDeviceType == enBTRCore_DC_Unknown && !btrCore_IsDevNameSameAsAddress(&lstFoundDevice)) {
752  if (((apstBTDeviceInfo->ui16Appearance & 0xffc0) >> 6) == 0x0f) {
753  if ((apstBTDeviceInfo->ui16Appearance & 0x3f) == 0x03 || (apstBTDeviceInfo->ui16Appearance & 0x3f) == 0x04) {
754  lstFoundDevice.enDeviceType = enBTRCore_DC_HID_Joystick;
755  BTRCORELOG_INFO ("Setting device type to Joystick based on GAP appearance\n");
756  }
757  }
758  }
759 
760  /* Populate the Ad Service Data */
761  for(count = 0; count < lstFoundDevice.stDeviceProfile.numberOfService; count++)
762  {
763  strncpy(lstFoundDevice.stAdServiceData[count].pcUUIDs, apstBTDeviceInfo->saServices[count].pcUUIDs, (BT_MAX_UUID_STR_LEN - 1));
764 
765  if(0 != apstBTDeviceInfo->saServices[count].len)
766  {
767  lstFoundDevice.stAdServiceData[count].len = apstBTDeviceInfo->saServices[count].len;
768  memcpy(lstFoundDevice.stAdServiceData[count].pcData, apstBTDeviceInfo->saServices[count].pcData, apstBTDeviceInfo->saServices[count].len);
769 
770  BTRCORELOG_TRACE ("ServiceData from %s\n", __FUNCTION__);
771  for (int i =0; i < apstBTDeviceInfo->saServices[count].len; i++){
772  BTRCORELOG_TRACE ("ServiceData[%d] = [%x]\n ", i, lstFoundDevice.stAdServiceData[count].pcData[i]);
773  }
774  }
775  }
776 
777  if (apsthBTRCore->aenDeviceDiscoveryType == enBTRCoreHID) {
778  if ((lstFoundDevice.enDeviceType != enBTRCore_DC_HID_Keyboard) &&
779  (lstFoundDevice.enDeviceType != enBTRCore_DC_HID_Mouse) &&
780  (lstFoundDevice.enDeviceType != enBTRCore_DC_HID_AudioRemote) &&
781  (lstFoundDevice.enDeviceType != enBTRCore_DC_HID_Joystick) &&
782  (lstFoundDevice.enDeviceType != enBTRCore_DC_HID_GamePad) &&
783  (lstFoundDevice.enDeviceType != enBTRCore_DC_HID_MouseKeyBoard) ){
784  BTRCORELOG_ERROR("Skipped the device %s DevID = %lld as the it is not interested device\n", lstFoundDevice.pcDeviceAddress, lstFoundDevice.tDeviceId);
785  return -1;
786  }
787  }
788 
789  for (i = 0; i < BTRCORE_MAX_NUM_BT_DEVICES; i++) {
790  if ((lstFoundDevice.tDeviceId == apsthBTRCore->stScannedDevicesArr[i].tDeviceId) || (apsthBTRCore->stScannedDevicesArr[i].bFound == FALSE)) {
791  BTRCORELOG_DEBUG ("Unique DevID = %lld\n", lstFoundDevice.tDeviceId);
792  BTRCORELOG_DEBUG ("Adding %s at location %d\n", lstFoundDevice.pcDeviceAddress, i);
793 
794  lstFoundDevice.bFound = TRUE; //mark the record as found
795 
796  memcpy (&apsthBTRCore->stScannedDevicesArr[i], &lstFoundDevice, sizeof(stBTRCoreBTDevice));
797 
798  apsthBTRCore->stScannedDevStInfoArr[i].eDevicePrevState = apsthBTRCore->stScannedDevStInfoArr[i].eDeviceCurrState;
799  apsthBTRCore->stScannedDevStInfoArr[i].eDeviceCurrState = enBTRCoreDevStFound;
800 
801  apsthBTRCore->numOfScannedDevices++;
802 
803  break;
804  }
805  }
806 
807 
808  if ((i < BTRCORE_MAX_NUM_BT_DEVICES) || (lstFoundDevice.enDeviceType == enBTRCore_DC_Tile)) {
809 
810  if (lstFoundDevice.enDeviceType == enBTRCore_DC_Tile) {
811  lstFoundDevice.bFound = TRUE; //mark the record as found
812  }
813 
814  memcpy(apstFoundDevice, &lstFoundDevice, sizeof(stBTRCoreBTDevice));
815  return i;
816  }
817 
818  BTRCORELOG_DEBUG ("Skipped %s DevID = %lld\n", lstFoundDevice.pcDeviceAddress, lstFoundDevice.tDeviceId);
819  return -1;
820 }
821 
822 static enBTRCoreRet
823 btrCore_RemoveDeviceFromScannedDevicesArr (
824  stBTRCoreHdl* apstlhBTRCore,
825  tBTRCoreDevId aBTRCoreDevId,
826  stBTRCoreBTDevice* astRemovedDevice
827 ) {
828  enBTRCoreRet retResult = enBTRCoreSuccess;
829  int i32LoopIdx = -1;
830 
831  for (i32LoopIdx = 0; i32LoopIdx < apstlhBTRCore->numOfScannedDevices; i32LoopIdx++) {
832  if (apstlhBTRCore->stScannedDevicesArr[i32LoopIdx].tDeviceId == aBTRCoreDevId) {
833  break;
834  }
835  }
836 
837  if (i32LoopIdx != apstlhBTRCore->numOfScannedDevices) {
838  BTRCORELOG_TRACE ("i32ScannedDevIdx = %d\n", i32LoopIdx);
839  BTRCORELOG_TRACE ("pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].eDeviceCurrState = %d\n", apstlhBTRCore->stScannedDevStInfoArr[i32LoopIdx].eDeviceCurrState);
840  BTRCORELOG_TRACE ("pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].eDevicePrevState = %d\n", apstlhBTRCore->stScannedDevStInfoArr[i32LoopIdx].eDevicePrevState);
841 
842  memcpy (astRemovedDevice, &apstlhBTRCore->stScannedDevicesArr[i32LoopIdx], sizeof(stBTRCoreBTDevice));
843  astRemovedDevice->bFound = FALSE;
844 
845  // Clean flipping logic. This will suffice
846  if (i32LoopIdx != apstlhBTRCore->numOfScannedDevices - 1) {
847  memcpy (&apstlhBTRCore->stScannedDevicesArr[i32LoopIdx], &apstlhBTRCore->stScannedDevicesArr[apstlhBTRCore->numOfScannedDevices - 1], sizeof(stBTRCoreBTDevice));
848  memcpy (&apstlhBTRCore->stScannedDevStInfoArr[i32LoopIdx], &apstlhBTRCore->stScannedDevStInfoArr[apstlhBTRCore->numOfScannedDevices - 1], sizeof(stBTRCoreDevStateInfo));
849  }
850 
851  memset(&apstlhBTRCore->stScannedDevicesArr[apstlhBTRCore->numOfScannedDevices - 1], 0, sizeof(stBTRCoreBTDevice));
852  memset(&apstlhBTRCore->stScannedDevStInfoArr[apstlhBTRCore->numOfScannedDevices - 1], 0, sizeof(stBTRCoreDevStateInfo));
853 
854  apstlhBTRCore->numOfScannedDevices--;
855  }
856  else {
857  BTRCORELOG_ERROR ("Device %lld not found in Scanned List!\n", aBTRCoreDevId);
858  retResult = enBTRCoreDeviceNotFound;
859  }
860 
861  return retResult;
862 }
863 
864 static int
865 btrCore_AddDeviceToKnownDevicesArr (
866  stBTRCoreHdl* apsthBTRCore,
867  stBTDeviceInfo* apstBTDeviceInfo
868 ) {
869  tBTRCoreDevId ltDeviceId;
870  int i32LoopIdx = 0;
871  int i32KnownDevIdx = -1;
872  int i32ScannedDevIdx= -1;
873 
874 
875  ltDeviceId = btrCore_GenerateUniqueDeviceID(apstBTDeviceInfo->pcAddress);
876 
877  for (i32LoopIdx = 0; i32LoopIdx < apsthBTRCore->numOfPairedDevices; i32LoopIdx++) {
878  if (ltDeviceId == apsthBTRCore->stKnownDevicesArr[i32LoopIdx].tDeviceId) {
879  i32KnownDevIdx = i32LoopIdx;
880  break;
881  }
882  }
883 
884  if (i32KnownDevIdx != -1) {
885  BTRCORELOG_DEBUG ("Already Present in stKnownDevicesArr - DevID = %lld\n", ltDeviceId);
886  return i32KnownDevIdx;
887  }
888 
889  if (apsthBTRCore->numOfPairedDevices >= BTRCORE_MAX_NUM_BT_DEVICES) {
890  BTRCORELOG_ERROR ("No Space in stKnownDevicesArr - DevID = %lld\n", ltDeviceId);
891  return i32KnownDevIdx;
892  }
893 
894  for (i32LoopIdx = 0; i32LoopIdx < apsthBTRCore->numOfScannedDevices; i32LoopIdx++) {
895  if (ltDeviceId == apsthBTRCore->stScannedDevicesArr[i32LoopIdx].tDeviceId) {
896  i32ScannedDevIdx = i32LoopIdx;
897  break;
898  }
899  }
900 
901  if (i32ScannedDevIdx == -1) {
902  BTRCORELOG_DEBUG ("Not Present in stScannedDevicesArr - DevID = %lld\n", ltDeviceId);
903  return i32ScannedDevIdx;
904  }
905 
906 
907  i32KnownDevIdx = apsthBTRCore->numOfPairedDevices++;
908 
909  memcpy (&apsthBTRCore->stKnownDevicesArr[i32KnownDevIdx], &apsthBTRCore->stScannedDevicesArr[i32ScannedDevIdx], sizeof(stBTRCoreBTDevice));
910  apsthBTRCore->stKnownDevicesArr[i32KnownDevIdx].bDeviceConnected = apstBTDeviceInfo->bConnected;
911 
912  BTRCORELOG_TRACE ("Added in stKnownDevicesArr - DevID = %lld i32KnownDevIdx = %d NumOfPairedDevices = %d\n", ltDeviceId, i32KnownDevIdx, apsthBTRCore->numOfPairedDevices);
913 
914  return i32KnownDevIdx;
915 }
916 
917 
918 static enBTRCoreRet
919 btrCore_RemoveDeviceFromKnownDevicesArr (
920  stBTRCoreHdl* apstlhBTRCore,
921  tBTRCoreDevId aBTRCoreDevId
922 ) {
923  enBTRCoreRet retResult = enBTRCoreSuccess;
924  int i32LoopIdx = -1;
925 
926  for (i32LoopIdx = 0; i32LoopIdx < apstlhBTRCore->numOfPairedDevices; i32LoopIdx++) {
927  if (apstlhBTRCore->stKnownDevicesArr[i32LoopIdx].tDeviceId == aBTRCoreDevId) {
928  break;
929  }
930  }
931 
932  if (i32LoopIdx != apstlhBTRCore->numOfPairedDevices) {
933  BTRCORELOG_TRACE ("i32ScannedDevIdx = %d\n", i32LoopIdx);
934  BTRCORELOG_TRACE ("pstlhBTRCore->stKnownDevicesArr[i32LoopIdx].eDeviceCurrState = %d\n", apstlhBTRCore->stKnownDevStInfoArr[i32LoopIdx].eDeviceCurrState);
935  BTRCORELOG_TRACE ("pstlhBTRCore->stKnownDevicesArr[i32LoopIdx].eDevicePrevState = %d\n", apstlhBTRCore->stKnownDevStInfoArr[i32LoopIdx].eDevicePrevState);
936 
937  // Clean flipping logic. This will suffice
938  if (i32LoopIdx != apstlhBTRCore->numOfScannedDevices - 1) {
939  memcpy (&apstlhBTRCore->stKnownDevicesArr[i32LoopIdx], &apstlhBTRCore->stKnownDevicesArr[apstlhBTRCore->numOfPairedDevices - 1], sizeof(stBTRCoreBTDevice));
940  memcpy (&apstlhBTRCore->stKnownDevStInfoArr[i32LoopIdx], &apstlhBTRCore->stKnownDevStInfoArr[apstlhBTRCore->numOfPairedDevices - 1], sizeof(stBTRCoreDevStateInfo));
941  }
942 
943  memset(&apstlhBTRCore->stKnownDevicesArr[apstlhBTRCore->numOfPairedDevices - 1], 0, sizeof(stBTRCoreBTDevice));
944  memset(&apstlhBTRCore->stScannedDevStInfoArr[apstlhBTRCore->numOfPairedDevices - 1], 0, sizeof(stBTRCoreDevStateInfo));
945 
946  apstlhBTRCore->numOfPairedDevices--;
947  }
948  else {
949  BTRCORELOG_ERROR ("Device %lld not found in Paired List!\n", aBTRCoreDevId);
950  retResult = enBTRCoreDeviceNotFound;
951  }
952 
953  return retResult;
954 }
955 
956 
957 static void
958 btrCore_MapKnownDeviceListFromPairedDeviceInfo (
959  stBTRCoreBTDevice* knownDevicesArr,
960  stBTPairedDeviceInfo* pairedDeviceInfo
961 ) {
962  unsigned char i_idx = 0;
963  unsigned char j_idx = 0;
964 
965  for (i_idx = 0; i_idx < pairedDeviceInfo->numberOfDevices; i_idx++) {
966  knownDevicesArr[i_idx].ui32VendorId = pairedDeviceInfo->deviceInfo[i_idx].ui16Vendor;
967  knownDevicesArr[i_idx].bDeviceConnected = pairedDeviceInfo->deviceInfo[i_idx].bConnected;
968  knownDevicesArr[i_idx].tDeviceId = btrCore_GenerateUniqueDeviceID(pairedDeviceInfo->deviceInfo[i_idx].pcAddress);
969  knownDevicesArr[i_idx].enDeviceType = btrCore_MapClassIDtoDevClass(pairedDeviceInfo->deviceInfo[i_idx].ui32Class);
970  knownDevicesArr[i_idx].ui32DevClassBtSpec = pairedDeviceInfo->deviceInfo[i_idx].ui32Class;
971 
972  strncpy(knownDevicesArr[i_idx].pcDeviceName, pairedDeviceInfo->deviceInfo[i_idx].pcName, BD_NAME_LEN);
973  strncpy(knownDevicesArr[i_idx].pcDeviceAddress, pairedDeviceInfo->deviceInfo[i_idx].pcAddress, BD_NAME_LEN);
974  strncpy(knownDevicesArr[i_idx].pcDevicePath, pairedDeviceInfo->devicePath[i_idx], BD_NAME_LEN);
975 
976  BTRCORELOG_TRACE ("Unique DevID = %lld\n", knownDevicesArr[i_idx].tDeviceId);
977 
978  for (j_idx = 0; j_idx < BT_MAX_DEVICE_PROFILE; j_idx++) {
979  if (pairedDeviceInfo->deviceInfo[i_idx].aUUIDs[j_idx][0] == '\0')
980  break;
981  else
982  knownDevicesArr[i_idx].stDeviceProfile.profile[j_idx].uuid_value = btrCore_BTParseUUIDValue (
983  pairedDeviceInfo->deviceInfo[i_idx].aUUIDs[j_idx],
984  knownDevicesArr[i_idx].stDeviceProfile.profile[j_idx].profile_name);
985  }
986  knownDevicesArr[i_idx].stDeviceProfile.numberOfService = j_idx;
987 
988  if (knownDevicesArr[i_idx].enDeviceType == enBTRCore_DC_Unknown) {
989  for (j_idx = 0; j_idx < knownDevicesArr[i_idx].stDeviceProfile.numberOfService; j_idx++) {
990  if (knownDevicesArr[i_idx].stDeviceProfile.profile[j_idx].uuid_value == strtol(BTR_CORE_A2SNK, NULL, 16)) {
991  knownDevicesArr[i_idx].enDeviceType = enBTRCore_DC_Loudspeaker;
992  }
993  else if ((knownDevicesArr[i_idx].stDeviceProfile.profile[j_idx].uuid_value == strtol(BTR_CORE_HID_1, NULL, 16)) ||
994  (knownDevicesArr[i_idx].stDeviceProfile.profile[j_idx].uuid_value == strtol(BTR_CORE_HID_2, NULL, 16))) {
995  knownDevicesArr[i_idx].enDeviceType = enBTRCore_DC_HID_Keyboard;
996  }
997  }
998  }
999  }
1000 }
1001 
1002 
1003 static enBTRCoreRet
1004 btrCore_PopulateListOfPairedDevices (
1005  stBTRCoreHdl* apsthBTRCore,
1006  const char* pAdapterPath
1007 ) {
1008  unsigned char i_idx = 0;
1009  unsigned char j_idx = 0;
1010  enBTRCoreRet retResult = enBTRCoreSuccess;
1011  stBTPairedDeviceInfo* pstBTPairedDeviceInfo = NULL;
1012  stBTRCoreBTDevice knownDevicesArr[BTRCORE_MAX_NUM_BT_DEVICES];
1013 
1014 
1015  if ((pstBTPairedDeviceInfo = g_malloc0(sizeof(stBTPairedDeviceInfo))) == NULL)
1016  return enBTRCoreFailure;
1017 
1018 
1019  pstBTPairedDeviceInfo->numberOfDevices = 0;
1020  for (i_idx = 0; i_idx < BT_MAX_NUM_DEVICE; i_idx++) {
1021  memset(&pstBTPairedDeviceInfo->devicePath[i_idx][0], '\0', BT_MAX_DEV_PATH_LEN);
1022  memset(&pstBTPairedDeviceInfo->deviceInfo[i_idx], 0, sizeof(stBTDeviceInfo));
1023  }
1024 
1025  if (BtrCore_BTGetPairedDeviceInfo (apsthBTRCore->connHdl, pAdapterPath, pstBTPairedDeviceInfo) != 0) {
1026  BTRCORELOG_ERROR ("Failed to populate List Of Paired Devices\n");
1027  return enBTRCoreFailure;
1028  }
1029 
1030  for (j_idx = 0; j_idx < BTRCORE_MAX_NUM_BT_DEVICES; j_idx++) {
1031  memset (&knownDevicesArr[j_idx], 0, sizeof(stBTRCoreBTDevice));
1032  }
1033 
1034  /* Initially stBTRCoreKnownDevice List is populated from pstBTPairedDeviceInfo(bluez i/f) directly *********/
1035  if (!apsthBTRCore->numOfPairedDevices) {
1036  apsthBTRCore->numOfPairedDevices = pstBTPairedDeviceInfo->numberOfDevices;
1037  btrCore_MapKnownDeviceListFromPairedDeviceInfo (knownDevicesArr, pstBTPairedDeviceInfo);
1038 
1039  for (i_idx = 0; i_idx < pstBTPairedDeviceInfo->numberOfDevices; i_idx++) {
1040  memcpy (&apsthBTRCore->stKnownDevicesArr[i_idx], &knownDevicesArr[i_idx], sizeof(stBTRCoreBTDevice));
1041  apsthBTRCore->stKnownDevStInfoArr[i_idx].eDevicePrevState = enBTRCoreDevStInitialized;
1042  apsthBTRCore->stKnownDevStInfoArr[i_idx].eDeviceCurrState = enBTRCoreDevStPaired;
1043  }
1044  }
1045  else {
1046  /**************************************************************************************************
1047  stBTRCoreKnownDevice in stBTRCoreHdl is handled seperately, instead of populating directly from bluez i/f
1048  pstBTPairedDeviceInfo list as it causes inconsistency in indices of stKnownDevStInfoArr during pair and unpair
1049  of devices.
1050  This case of the addition of Dev6, Dev7 and removal of Dev5 in stBTRCoreKnownDevice list using index
1051  arrays shows the working of the below algorithm.
1052 
1053  stBTPairedDeviceInfo List from bluez i/f stBTRCoreKnownDevice List maintained in BTRCore
1054  +------+------+------+------+------+------+ +------+------+------+------+------+
1055  | | | | | | | | | | | | |
1056  | Dev7 | Dev1 | Dev2 | Dev4 | Dev3 | Dev6 | | Dev3 | Dev1 | Dev4 | Dev5 | Dev2 |
1057  | | | | | | | | | | | | |
1058  +------+------+------+------+------+------+ +------+------+------+------+------+
1059  +------+------+------+------+------+------+ +------+------+------+------+------+
1060  | 0 | 1 | 1 | 1 | 1 | 0 | | 1 | 1 | 1 | 0 | 1 |
1061  +------+------+------+------+------+------+ +------+------+------+------+------+
1062  | | | | | |
1063  +---------------------------+ | +-------------------+ | | |
1064  | | | +-------------------+ | |
1065  | | | | +-------------------+ |
1066  | | | | | +--------------------------+
1067  | | | | | |
1068  +------+------+------+------+------+------+
1069  | | | | | | |
1070  | Dev7 | Dev6 | Dev3 | Dev1 | Dev4 | Dev2 |
1071  | | | | | | |
1072  +------+------+------+------+------+------+
1073  -----Updated stBTRCoreKnownDevice List-----
1074  Now as the change of indexes is known, stKnownDevStInfoArr is also handled accordingly.******************/
1075 
1076  unsigned char count = 0;
1077  unsigned char k_idx = 0;
1078  unsigned char numOfDevices = 0;
1079  unsigned char knownDev_index_array[BTRCORE_MAX_NUM_BT_DEVICES];
1080  unsigned char pairedDev_index_array[BTRCORE_MAX_NUM_BT_DEVICES];
1081 
1082  memset (knownDev_index_array, 0, sizeof(knownDev_index_array));
1083  memset (pairedDev_index_array, 0, sizeof(pairedDev_index_array));
1084 
1085  for (j_idx = 0; j_idx < BTRCORE_MAX_NUM_BT_DEVICES; j_idx++) {
1086  memcpy (&knownDevicesArr[j_idx], &apsthBTRCore->stKnownDevicesArr[j_idx], sizeof(stBTRCoreBTDevice));
1087  memset (&apsthBTRCore->stKnownDevicesArr[j_idx], 0, sizeof(stBTRCoreBTDevice));
1088  }
1089 
1090  /*Loops through to mark the new added and removed device entries in the list */
1091  for (i_idx = 0, j_idx = 0; i_idx < pstBTPairedDeviceInfo->numberOfDevices && j_idx < apsthBTRCore->numOfPairedDevices; j_idx++) {
1092  if (btrCore_GenerateUniqueDeviceID(pstBTPairedDeviceInfo->deviceInfo[i_idx].pcAddress) == knownDevicesArr[j_idx].tDeviceId) {
1093  knownDev_index_array[j_idx] = 1;
1094  pairedDev_index_array[i_idx]= 1;
1095  i_idx++;
1096  }
1097  else {
1098  for (k_idx = i_idx + 1; k_idx < pstBTPairedDeviceInfo->numberOfDevices; k_idx++) {
1099  if (btrCore_GenerateUniqueDeviceID(pstBTPairedDeviceInfo->deviceInfo[k_idx].pcAddress) == knownDevicesArr[j_idx].tDeviceId) {
1100  knownDev_index_array[j_idx] = 1;
1101  pairedDev_index_array[k_idx]= 1;
1102  break;
1103  }
1104  }
1105  }
1106  }
1107 
1108  numOfDevices = apsthBTRCore->numOfPairedDevices;
1109 
1110  /*Loops through to check for the removal of Device entries from the list during Unpairing */
1111  for (i_idx = 0; i_idx < numOfDevices; i_idx++) {
1112  if (knownDev_index_array[i_idx]) {
1113  memcpy (&apsthBTRCore->stKnownDevicesArr[i_idx - count], &knownDevicesArr[i_idx], sizeof(stBTRCoreBTDevice));
1114  apsthBTRCore->stKnownDevStInfoArr[i_idx - count].eDevicePrevState = apsthBTRCore->stKnownDevStInfoArr[i_idx].eDevicePrevState;
1115  apsthBTRCore->stKnownDevStInfoArr[i_idx - count].eDeviceCurrState = apsthBTRCore->stKnownDevStInfoArr[i_idx].eDeviceCurrState;
1116  }
1117  else {
1118  count++;
1119  apsthBTRCore->numOfPairedDevices--;
1120  }
1121  }
1122  btrCore_MapKnownDeviceListFromPairedDeviceInfo (knownDevicesArr, pstBTPairedDeviceInfo);
1123 
1124  /*Loops through to checks for the addition of Device entries to the list during paring */
1125  for (i_idx = 0; i_idx < pstBTPairedDeviceInfo->numberOfDevices; i_idx++) {
1126  if (!pairedDev_index_array[i_idx]) {
1127  memcpy(&apsthBTRCore->stKnownDevicesArr[apsthBTRCore->numOfPairedDevices], &knownDevicesArr[i_idx], sizeof(stBTRCoreBTDevice));
1128  if (apsthBTRCore->stKnownDevStInfoArr[apsthBTRCore->numOfPairedDevices].eDeviceCurrState != enBTRCoreDevStConnected) {
1129  apsthBTRCore->stKnownDevStInfoArr[apsthBTRCore->numOfPairedDevices].eDevicePrevState = enBTRCoreDevStInitialized;
1130  apsthBTRCore->stKnownDevStInfoArr[apsthBTRCore->numOfPairedDevices].eDeviceCurrState = enBTRCoreDevStPaired;
1131  apsthBTRCore->stKnownDevicesArr[apsthBTRCore->numOfPairedDevices].bDeviceConnected = FALSE;
1132  apsthBTRCore->stKnownDevicesArr[apsthBTRCore->numOfPairedDevices].bFound = TRUE; // Paired Now
1133  }
1134  apsthBTRCore->numOfPairedDevices++;
1135  }
1136  }
1137  }
1138 
1139  g_free(pstBTPairedDeviceInfo);
1140 
1141  return retResult;
1142 }
1143 
1144 
1145 static const char*
1146 btrCore_GetScannedDeviceAddress (
1147  stBTRCoreHdl* apsthBTRCore,
1148  tBTRCoreDevId aBTRCoreDevId
1149 ) {
1150  int i = 0;
1151 
1152  if (apsthBTRCore->numOfScannedDevices) {
1153  for (i = 0; i < apsthBTRCore->numOfScannedDevices; i++) {
1154  if (aBTRCoreDevId == apsthBTRCore->stScannedDevicesArr[i].tDeviceId)
1155  return apsthBTRCore->stScannedDevicesArr[i].pcDevicePath;
1156  }
1157  }
1158 
1159  return NULL;
1160 }
1161 
1162 
1163 static const char*
1164 btrCore_GetKnownDeviceMac (
1165  stBTRCoreHdl* apsthBTRCore,
1166  tBTRCoreDevId aBTRCoreDevId
1167 ) {
1168  int i32LoopIdx = -1;
1169 
1170  if (apsthBTRCore->numOfPairedDevices) {
1171  for (i32LoopIdx = 0; i32LoopIdx < apsthBTRCore->numOfPairedDevices; i32LoopIdx++) {
1172  if (aBTRCoreDevId == apsthBTRCore->stKnownDevicesArr[i32LoopIdx].tDeviceId)
1173  return apsthBTRCore->stKnownDevicesArr[i32LoopIdx].pcDeviceAddress;
1174  }
1175  }
1176 
1177  return NULL;
1178 }
1179 
1180 
1181 static enBTRCoreRet
1182 btrCore_GetDeviceInfo (
1183  stBTRCoreHdl* apsthBTRCore,
1184  tBTRCoreDevId aBTRCoreDevId,
1185  enBTRCoreDeviceType aenBTRCoreDevType,
1186  enBTDeviceType* apenBTDeviceType,
1187  stBTRCoreBTDevice** appstBTRCoreBTDevice,
1188  stBTRCoreDevStateInfo** appstBTRCoreDevStateInfo,
1189  const char** appcBTRCoreBTDevicePath,
1190  const char** appcBTRCoreBTDeviceName
1191 ) {
1192  stBTRCoreBTDevice* lpstBTRCoreBTDeviceArr = NULL;
1193  stBTRCoreDevStateInfo* lpstBTRCoreDevStInfoArr = NULL;
1194  unsigned int ui32NumOfDevices = 0;
1195  unsigned int ui32LoopIdx = 0;
1196 
1197 
1198  if (!apsthBTRCore->numOfPairedDevices) {
1199  BTRCORELOG_DEBUG ("Possibly the list is not populated; like booted and connecting\n");
1200  btrCore_PopulateListOfPairedDevices(apsthBTRCore, apsthBTRCore->curAdapterPath); /* Keep the list upto date */
1201  }
1202 
1203 
1204  if (aenBTRCoreDevType != enBTRCoreLE) {
1205  ui32NumOfDevices = apsthBTRCore->numOfPairedDevices;
1206  lpstBTRCoreBTDeviceArr = apsthBTRCore->stKnownDevicesArr;
1207  lpstBTRCoreDevStInfoArr = apsthBTRCore->stKnownDevStInfoArr;
1208  }
1209  else {
1210  ui32NumOfDevices = apsthBTRCore->numOfScannedDevices;
1211  lpstBTRCoreBTDeviceArr = apsthBTRCore->stScannedDevicesArr;
1212  lpstBTRCoreDevStInfoArr = apsthBTRCore->stScannedDevStInfoArr;
1213  }
1214 
1215 
1216  if (!ui32NumOfDevices) {
1217  BTRCORELOG_ERROR ("There is no device paried/scanned for this adapter\n");
1218  return enBTRCoreFailure;
1219  }
1220 
1221 
1222  if (aBTRCoreDevId < BTRCORE_MAX_NUM_BT_DEVICES) {
1223  *appstBTRCoreBTDevice = &lpstBTRCoreBTDeviceArr[aBTRCoreDevId];
1224  *appstBTRCoreDevStateInfo = &lpstBTRCoreDevStInfoArr[aBTRCoreDevId];
1225  }
1226  else {
1227  for (ui32LoopIdx = 0; ui32LoopIdx < ui32NumOfDevices; ui32LoopIdx++) {
1228  if (aBTRCoreDevId == lpstBTRCoreBTDeviceArr[ui32LoopIdx].tDeviceId) {
1229  *appstBTRCoreBTDevice = &lpstBTRCoreBTDeviceArr[ui32LoopIdx];
1230  *appstBTRCoreDevStateInfo = &lpstBTRCoreDevStInfoArr[ui32LoopIdx];
1231  break;
1232  }
1233  }
1234  }
1235 
1236  if (*appstBTRCoreBTDevice) {
1237  *appcBTRCoreBTDevicePath = (*appstBTRCoreBTDevice)->pcDevicePath;
1238  *appcBTRCoreBTDeviceName = (*appstBTRCoreBTDevice)->pcDeviceName;
1239  }
1240 
1241  if (!(*appcBTRCoreBTDevicePath) || !strlen(*appcBTRCoreBTDevicePath)) {
1242  BTRCORELOG_ERROR ("Failed to find device in paired/scanned devices list\n");
1243  return enBTRCoreDeviceNotFound;
1244  }
1245 
1246 
1247  switch (aenBTRCoreDevType) {
1248  case enBTRCoreSpeakers:
1249  case enBTRCoreHeadSet:
1250  *apenBTDeviceType = enBTDevAudioSink;
1251  break;
1252  case enBTRCoreMobileAudioIn:
1253  case enBTRCorePCAudioIn:
1254  *apenBTDeviceType = enBTDevAudioSource;
1255  break;
1256  case enBTRCoreLE:
1257  *apenBTDeviceType = enBTDevLE;
1258  break;
1259  case enBTRCoreHID:
1260  *apenBTDeviceType = enBTDevHID;
1261  break;
1262  case enBTRCoreUnknown:
1263  default:
1264  *apenBTDeviceType = enBTDevUnknown;
1265  break;
1266  }
1267 
1268  return enBTRCoreSuccess;
1269 }
1270 
1271 
1272 static enBTRCoreRet
1273 btrCore_GetDeviceInfoKnown (
1274  stBTRCoreHdl* apsthBTRCore,
1275  tBTRCoreDevId aBTRCoreDevId,
1276  enBTRCoreDeviceType aenBTRCoreDevType,
1277  enBTDeviceType* apenBTDeviceType,
1278  stBTRCoreBTDevice** appstBTRCoreBTDevice,
1279  stBTRCoreDevStateInfo** appstBTRCoreDevStateInfo,
1280  const char** appcBTRCoreBTDevicePath
1281 ) {
1282  unsigned int ui32NumOfDevices = 0;
1283  unsigned int ui32LoopIdx = 0;
1284 
1285  if (!apsthBTRCore->numOfPairedDevices) {
1286  BTRCORELOG_DEBUG ("Possibly the list is not populated; like booted and connecting\n");
1287  btrCore_PopulateListOfPairedDevices(apsthBTRCore, apsthBTRCore->curAdapterPath); /* Keep the list upto date */
1288  }
1289 
1290 
1291  ui32NumOfDevices = apsthBTRCore->numOfPairedDevices;
1292  if (!ui32NumOfDevices) {
1293  BTRCORELOG_ERROR ("There is no device paried for this adapter\n");
1294  return enBTRCoreFailure;
1295  }
1296 
1297 
1298  if (aBTRCoreDevId < BTRCORE_MAX_NUM_BT_DEVICES) {
1299  *appstBTRCoreBTDevice = &apsthBTRCore->stKnownDevicesArr[aBTRCoreDevId];
1300  *appstBTRCoreDevStateInfo = &apsthBTRCore->stKnownDevStInfoArr[aBTRCoreDevId];
1301  }
1302  else {
1303  for (ui32LoopIdx = 0; ui32LoopIdx < ui32NumOfDevices; ui32LoopIdx++) {
1304  if (aBTRCoreDevId == apsthBTRCore->stKnownDevicesArr[ui32LoopIdx].tDeviceId) {
1305  *appstBTRCoreBTDevice = &apsthBTRCore->stKnownDevicesArr[ui32LoopIdx];
1306  *appstBTRCoreDevStateInfo = &apsthBTRCore->stKnownDevStInfoArr[ui32LoopIdx];
1307  }
1308  }
1309  }
1310 
1311  if (*appstBTRCoreBTDevice) {
1312  *appcBTRCoreBTDevicePath = (*appstBTRCoreBTDevice)->pcDevicePath;
1313  }
1314 
1315  if (!(*appcBTRCoreBTDevicePath) || !strlen(*appcBTRCoreBTDevicePath)) {
1316  BTRCORELOG_ERROR ("Failed to find device in paired devices list\n");
1317  return enBTRCoreDeviceNotFound;
1318  }
1319 
1320 
1321  switch (aenBTRCoreDevType) {
1322  case enBTRCoreSpeakers:
1323  case enBTRCoreHeadSet:
1324  *apenBTDeviceType = enBTDevAudioSink;
1325  break;
1326  case enBTRCoreMobileAudioIn:
1327  case enBTRCorePCAudioIn:
1328  *apenBTDeviceType = enBTDevAudioSource;
1329  break;
1330  case enBTRCoreHID:
1331  *apenBTDeviceType = enBTDevHID;
1332  break;
1333  case enBTRCoreUnknown:
1334  default:
1335  *apenBTDeviceType = enBTDevUnknown;
1336  break;
1337  }
1338 
1339  return enBTRCoreSuccess;
1340 }
1341 
1342 static void
1343 btrCore_ShowSignalStrength (
1344  short strength
1345 ) {
1346  short pos_str;
1347 
1348  pos_str = 100 + strength;//strength is usually negative with number meaning more strength
1349 
1350  BTRCORELOG_TRACE (" Signal Strength: %d dbmv \n", strength);
1351 
1352  if (pos_str > 70) {
1353  BTRCORELOG_TRACE ("++++\n");
1354  }
1355 
1356  if ((pos_str > 50) && (pos_str <= 70)) {
1357  BTRCORELOG_TRACE ("+++\n");
1358  }
1359 
1360  if ((pos_str > 37) && (pos_str <= 50)) {
1361  BTRCORELOG_TRACE ("++\n");
1362  }
1363 
1364  if (pos_str <= 37) {
1365  BTRCORELOG_TRACE ("+\n");
1366  }
1367 }
1368 
1369 
1370 static unsigned int
1371 btrCore_BTParseUUIDValue (
1372  const char* pUUIDString,
1373  char* pServiceNameOut
1374 ) {
1375  char aUUID[8];
1376  unsigned int uuid_value = 0;
1377 
1378 
1379  if (pUUIDString) {
1380  /* Arrive at short form of UUID */
1381  aUUID[0] = '0';
1382  aUUID[1] = 'x';
1383  aUUID[2] = pUUIDString[4];
1384  aUUID[3] = pUUIDString[5];
1385  aUUID[4] = pUUIDString[6];
1386  aUUID[5] = pUUIDString[7];
1387  aUUID[6] = '\0';
1388 
1389  uuid_value = strtol(aUUID, NULL, 16);
1390 
1391  /* Have the name by list comparision */
1392  if (!strcasecmp(aUUID, BTR_CORE_SP))
1393  strcpy(pServiceNameOut, BTR_CORE_SP_TEXT);
1394 
1395  else if (!strcasecmp(aUUID, BTR_CORE_HEADSET))
1396  strcpy(pServiceNameOut, BTR_CORE_HEADSET_TEXT);
1397 
1398  else if (!strcasecmp(aUUID, BTR_CORE_A2SRC))
1399  strcpy(pServiceNameOut, BTR_CORE_A2SRC_TEXT);
1400 
1401  else if (!strcasecmp(aUUID, BTR_CORE_A2SNK))
1402  strcpy(pServiceNameOut, BTR_CORE_A2SNK_TEXT);
1403 
1404  else if (!strcasecmp(aUUID, BTR_CORE_AVRTG))
1405  strcpy(pServiceNameOut, BTR_CORE_AVRTG_TEXT);
1406 
1407  else if (!strcasecmp(aUUID, BTR_CORE_AAD))
1408  strcpy(pServiceNameOut, BTR_CORE_AAD_TEXT);
1409 
1410  else if (!strcasecmp(aUUID, BTR_CORE_AVRCT))
1411  strcpy(pServiceNameOut, BTR_CORE_AVRCT_TEXT);
1412 
1413  else if (!strcasecmp(aUUID, BTR_CORE_AVREMOTE))
1414  strcpy(pServiceNameOut, BTR_CORE_AVREMOTE_TEXT);
1415 
1416  else if (!strcasecmp(aUUID, BTR_CORE_HS_AG))
1417  strcpy(pServiceNameOut, BTR_CORE_HS_AG_TEXT);
1418 
1419  else if (!strcasecmp(aUUID, BTR_CORE_HANDSFREE))
1420  strcpy(pServiceNameOut, BTR_CORE_HANDSFREE_TEXT);
1421 
1422  else if (!strcasecmp(aUUID, BTR_CORE_HAG))
1423  strcpy(pServiceNameOut, BTR_CORE_HAG_TEXT);
1424 
1425  else if (!strcasecmp(aUUID, BTR_CORE_HEADSET2))
1426  strcpy(pServiceNameOut, BTR_CORE_HEADSET2_TEXT);
1427 
1428  else if (!strcasecmp(aUUID, BTR_CORE_GEN_AUDIO))
1429  strcpy(pServiceNameOut, BTR_CORE_GEN_AUDIO_TEXT);
1430 
1431  else if (!strcasecmp(aUUID, BTR_CORE_PNP))
1432  strcpy(pServiceNameOut, BTR_CORE_PNP_TEXT);
1433 
1434  else if (!strcasecmp(aUUID, BTR_CORE_GEN_ATRIB))
1435  strcpy(pServiceNameOut, BTR_CORE_GEN_ATRIB_TEXT);
1436 
1437  else if (!strcasecmp(aUUID, BTR_CORE_GATT_TILE_1))
1438  strcpy(pServiceNameOut, BTR_CORE_GATT_TILE_TEXT);
1439 
1440  else if (!strcasecmp(aUUID, BTR_CORE_GATT_TILE_2))
1441  strcpy(pServiceNameOut, BTR_CORE_GATT_TILE_TEXT);
1442 
1443  else if (!strcasecmp(aUUID, BTR_CORE_GATT_TILE_3))
1444  strcpy(pServiceNameOut, BTR_CORE_GATT_TILE_TEXT);
1445 
1446  else if (!strcasecmp(aUUID, BTR_CORE_GEN_ACCESS))
1447  strcpy(pServiceNameOut, BTR_CORE_GEN_ACCESS_TEXT);
1448 
1449  else if (!strcasecmp(aUUID, BTR_CORE_GEN_ATTRIBUTE))
1450  strcpy(pServiceNameOut, BTR_CORE_GEN_ATTRIBUTE_TEXT);
1451 
1452  else if (!strcasecmp(aUUID, BTR_CORE_DEVICE_INFO))
1453  strcpy(pServiceNameOut, BTR_CORE_DEVICE_INFO_TEXT);
1454 
1455  else if (!strcasecmp(aUUID, BTR_CORE_BATTERY_SERVICE))
1456  strcpy(pServiceNameOut, BTR_CORE_BATTERY_SERVICE_TEXT);
1457 
1458  else if (!strcasecmp(aUUID, BTR_CORE_HID_1))
1459  strcpy(pServiceNameOut, BTR_CORE_HID_TEXT);
1460 
1461  else if (!strcasecmp(aUUID, BTR_CORE_HID_2))
1462  strcpy(pServiceNameOut, BTR_CORE_HID_TEXT);
1463 
1464  else
1465  strcpy (pServiceNameOut, "Not Identified");
1466  }
1467  else
1468  strcpy (pServiceNameOut, "Not Identified");
1469 
1470  return uuid_value;
1471 }
1472 
1473 
1474 static enBTRCoreDeviceState
1475 btrCore_BTParseDeviceState (
1476  const char* pcStateValue
1477 ) {
1478  enBTRCoreDeviceState rc = enBTRCoreDevStInitialized;
1479 
1480  if ((pcStateValue) && (pcStateValue[0] != '\0')) {
1481  BTRCORELOG_DEBUG ("Current State of this connection is @@%s@@\n", pcStateValue);
1482 
1483  if (!strcasecmp("unpaired", pcStateValue)) {
1484  rc = enBTRCoreDevStUnpaired;
1485  }
1486  else if (!strcasecmp("paired", pcStateValue)) {
1487  rc = enBTRCoreDevStPaired;
1488  }
1489  else if (!strcasecmp("disconnected", pcStateValue)) {
1490  rc = enBTRCoreDevStDisconnected;
1491  }
1492  else if (!strcasecmp("connecting", pcStateValue)) {
1493  rc = enBTRCoreDevStConnecting;
1494  }
1495  else if (!strcasecmp("connected", pcStateValue)) {
1496  rc = enBTRCoreDevStConnected;
1497  }
1498  else if (!strcasecmp("playing", pcStateValue)) {
1499  rc = enBTRCoreDevStPlaying;
1500  }
1501  }
1502 
1503  return rc;
1504 }
1505 
1506 
1507 static enBTRCoreRet
1508 btrCore_RunTaskAddOp (
1509  GAsyncQueue* apRunTaskGAq,
1510  enBTRCoreTaskOp aenRunTaskOp,
1511  enBTRCoreTaskProcessType aenRunTaskPT,
1512  void* apvRunTaskInData
1513 ) {
1514  stBTRCoreTaskGAqData* lpstRunTaskGAqData = NULL;
1515 
1516  if ((apRunTaskGAq == NULL) || (aenRunTaskOp == enBTRCoreTaskOpUnknown)) {
1517  return enBTRCoreInvalidArg;
1518  }
1519 
1520 
1521  if (!(lpstRunTaskGAqData = g_malloc0(sizeof(stBTRCoreTaskGAqData)))) {
1522  return enBTRCoreFailure;
1523  }
1524 
1525 
1526  lpstRunTaskGAqData->enBTRCoreTskOp = aenRunTaskOp;
1527  switch (lpstRunTaskGAqData->enBTRCoreTskOp) {
1528  case enBTRCoreTaskOpStart:
1529  break;
1530  case enBTRCoreTaskOpStop:
1531  break;
1532  case enBTRCoreTaskOpIdle:
1533  break;
1534  case enBTRCoreTaskOpProcess:
1535  break;
1536  case enBTRCoreTaskOpExit:
1537  break;
1538  case enBTRCoreTaskOpUnknown:
1539  default:
1540  break;
1541  }
1542 
1543 
1544  lpstRunTaskGAqData->enBTRCoreTskPT = aenRunTaskPT;
1545  if (lpstRunTaskGAqData->enBTRCoreTskPT == enBTRCoreTaskPTUnknown) {
1546  }
1547  else {
1548  }
1549 
1550 
1551  BTRCORELOG_INFO ("g_async_queue_push %d %d %p\n", lpstRunTaskGAqData->enBTRCoreTskOp, lpstRunTaskGAqData->enBTRCoreTskPT, lpstRunTaskGAqData->pvBTRCoreTskInData);
1552  g_async_queue_push(apRunTaskGAq, lpstRunTaskGAqData);
1553 
1554 
1555  return enBTRCoreSuccess;
1556 }
1557 
1558 static enBTRCoreRet
1559 btrCore_OutTaskAddOp (
1560  GAsyncQueue* apOutTaskGAq,
1561  enBTRCoreTaskOp aenOutTaskOp,
1562  enBTRCoreTaskProcessType aenOutTaskPT,
1563  void* apvOutTaskInData
1564 ) {
1565  stBTRCoreTaskGAqData* lpstOutTaskGAqData = NULL;
1566 
1567  if ((apOutTaskGAq == NULL) || (aenOutTaskOp == enBTRCoreTaskOpUnknown)) {
1568  return enBTRCoreInvalidArg;
1569  }
1570 
1571 
1572  if (!(lpstOutTaskGAqData = g_malloc0(sizeof(stBTRCoreTaskGAqData)))) {
1573  return enBTRCoreFailure;
1574  }
1575 
1576 
1577  lpstOutTaskGAqData->enBTRCoreTskOp = aenOutTaskOp;
1578  switch (lpstOutTaskGAqData->enBTRCoreTskOp) {
1579  case enBTRCoreTaskOpStart:
1580  break;
1581  case enBTRCoreTaskOpStop:
1582  break;
1583  case enBTRCoreTaskOpIdle:
1584  break;
1585  case enBTRCoreTaskOpProcess:
1586  break;
1587  case enBTRCoreTaskOpExit:
1588  break;
1589  case enBTRCoreTaskOpUnknown:
1590  default:
1591  break;
1592  }
1593 
1594 
1595  lpstOutTaskGAqData->enBTRCoreTskPT = aenOutTaskPT;
1596  if (lpstOutTaskGAqData->enBTRCoreTskPT == enBTRCoreTaskPTcBAdapterStatus) {
1597  if ((lpstOutTaskGAqData->pvBTRCoreTskInData = g_malloc0(sizeof(stBTAdapterInfo)))) {
1598  memcpy(lpstOutTaskGAqData->pvBTRCoreTskInData, (stBTAdapterInfo*)apvOutTaskInData, sizeof(stBTAdapterInfo));
1599  }
1600  }
1601  else if (lpstOutTaskGAqData->enBTRCoreTskPT == enBTRCoreTaskPTcBDeviceDisc) {
1602  if ((apvOutTaskInData) &&
1603  (lpstOutTaskGAqData->pvBTRCoreTskInData = g_malloc0(sizeof(stBTRCoreOTskInData))) &&
1604  (((stBTRCoreOTskInData*)lpstOutTaskGAqData->pvBTRCoreTskInData)->pstBTDevInfo = g_malloc0(sizeof(stBTDeviceInfo)))) {
1605  memcpy(((stBTRCoreOTskInData*)lpstOutTaskGAqData->pvBTRCoreTskInData)->pstBTDevInfo, (stBTDeviceInfo*)((stBTRCoreOTskInData*)apvOutTaskInData)->pstBTDevInfo, sizeof(stBTDeviceInfo));
1606  ((stBTRCoreOTskInData*)lpstOutTaskGAqData->pvBTRCoreTskInData)->bTRCoreDevId = ((stBTRCoreOTskInData*)apvOutTaskInData)->bTRCoreDevId;
1607  ((stBTRCoreOTskInData*)lpstOutTaskGAqData->pvBTRCoreTskInData)->enBTRCoreDevType= ((stBTRCoreOTskInData*)apvOutTaskInData)->enBTRCoreDevType;
1608  }
1609  }
1610  else if (lpstOutTaskGAqData->enBTRCoreTskPT == enBTRCoreTaskPTcBDeviceRemoved) {
1611  if ((apvOutTaskInData) &&
1612  (lpstOutTaskGAqData->pvBTRCoreTskInData = g_malloc0(sizeof(stBTRCoreOTskInData))) &&
1613  (((stBTRCoreOTskInData*)lpstOutTaskGAqData->pvBTRCoreTskInData)->pstBTDevInfo = g_malloc0(sizeof(stBTDeviceInfo)))) {
1614  memcpy(((stBTRCoreOTskInData*)lpstOutTaskGAqData->pvBTRCoreTskInData)->pstBTDevInfo, (stBTDeviceInfo*)((stBTRCoreOTskInData*)apvOutTaskInData)->pstBTDevInfo, sizeof(stBTDeviceInfo));
1615  ((stBTRCoreOTskInData*)lpstOutTaskGAqData->pvBTRCoreTskInData)->bTRCoreDevId = ((stBTRCoreOTskInData*)apvOutTaskInData)->bTRCoreDevId;
1616  ((stBTRCoreOTskInData*)lpstOutTaskGAqData->pvBTRCoreTskInData)->enBTRCoreDevType= ((stBTRCoreOTskInData*)apvOutTaskInData)->enBTRCoreDevType;
1617  }
1618  }
1619  else if (lpstOutTaskGAqData->enBTRCoreTskPT == enBTRCoreTaskPTcBDeviceLost) {
1620  if ((apvOutTaskInData) &&
1621  (lpstOutTaskGAqData->pvBTRCoreTskInData = g_malloc0(sizeof(stBTRCoreOTskInData))) &&
1622  (((stBTRCoreOTskInData*)lpstOutTaskGAqData->pvBTRCoreTskInData)->pstBTDevInfo = g_malloc0(sizeof(stBTDeviceInfo)))) {
1623  memcpy(((stBTRCoreOTskInData*)lpstOutTaskGAqData->pvBTRCoreTskInData)->pstBTDevInfo, (stBTDeviceInfo*)((stBTRCoreOTskInData*)apvOutTaskInData)->pstBTDevInfo, sizeof(stBTDeviceInfo));
1624  ((stBTRCoreOTskInData*)lpstOutTaskGAqData->pvBTRCoreTskInData)->bTRCoreDevId = ((stBTRCoreOTskInData*)apvOutTaskInData)->bTRCoreDevId;
1625  ((stBTRCoreOTskInData*)lpstOutTaskGAqData->pvBTRCoreTskInData)->enBTRCoreDevType= ((stBTRCoreOTskInData*)apvOutTaskInData)->enBTRCoreDevType;
1626  }
1627  }
1628  else if (lpstOutTaskGAqData->enBTRCoreTskPT == enBTRCoreTaskPTcBDeviceStatus) {
1629  if ((apvOutTaskInData) &&
1630  (lpstOutTaskGAqData->pvBTRCoreTskInData = g_malloc0(sizeof(stBTRCoreOTskInData))) &&
1631  (((stBTRCoreOTskInData*)lpstOutTaskGAqData->pvBTRCoreTskInData)->pstBTDevInfo = g_malloc0(sizeof(stBTDeviceInfo)))) {
1632  memcpy(((stBTRCoreOTskInData*)lpstOutTaskGAqData->pvBTRCoreTskInData)->pstBTDevInfo, (stBTDeviceInfo*)((stBTRCoreOTskInData*)apvOutTaskInData)->pstBTDevInfo, sizeof(stBTDeviceInfo));
1633  ((stBTRCoreOTskInData*)lpstOutTaskGAqData->pvBTRCoreTskInData)->bTRCoreDevId = ((stBTRCoreOTskInData*)apvOutTaskInData)->bTRCoreDevId;
1634  ((stBTRCoreOTskInData*)lpstOutTaskGAqData->pvBTRCoreTskInData)->enBTRCoreDevType= ((stBTRCoreOTskInData*)apvOutTaskInData)->enBTRCoreDevType;
1635  }
1636  }
1637  else if (lpstOutTaskGAqData->enBTRCoreTskPT == enBTRCoreTaskPTcBMediaStatus) {
1638  if ((lpstOutTaskGAqData->pvBTRCoreTskInData = g_malloc0(sizeof(stBTRCoreMediaStatusCBInfo)))) {
1639  memcpy(lpstOutTaskGAqData->pvBTRCoreTskInData, (stBTRCoreMediaStatusCBInfo*)apvOutTaskInData, sizeof(stBTRCoreMediaStatusCBInfo));
1640  }
1641  }
1642  else if (lpstOutTaskGAqData->enBTRCoreTskPT == enBTRCoreTaskPTcBDevOpInfoStatus) {
1643  if ((apvOutTaskInData) &&
1644  (lpstOutTaskGAqData->pvBTRCoreTskInData = g_malloc0(sizeof(stBTRCoreDevStatusCBInfo)))) {
1645  memcpy(lpstOutTaskGAqData->pvBTRCoreTskInData, (stBTRCoreDevStatusCBInfo*)apvOutTaskInData, sizeof(stBTRCoreDevStatusCBInfo));
1646  }
1647  }
1648  else if (lpstOutTaskGAqData->enBTRCoreTskPT == enBTRCoreTaskPTcBConnIntim) {
1649  }
1650  else if (lpstOutTaskGAqData->enBTRCoreTskPT == enBTRCoreTaskPTcBConnAuth) {
1651  }
1652  else if (lpstOutTaskGAqData->enBTRCoreTskPT == enBTRCoreTaskPTUnknown) {
1653  }
1654  else {
1655  }
1656 
1657 
1658  BTRCORELOG_INFO ("g_async_queue_push %d %d %p\n", lpstOutTaskGAqData->enBTRCoreTskOp, lpstOutTaskGAqData->enBTRCoreTskPT, lpstOutTaskGAqData->pvBTRCoreTskInData);
1659  g_async_queue_push(apOutTaskGAq, lpstOutTaskGAqData);
1660 
1661 
1662  return enBTRCoreSuccess;
1663 }
1664 
1665 
1666 /* Local Op Threads */
1667 static gpointer
1668 btrCore_RunTask (
1669  gpointer apsthBTRCore
1670 ) {
1671  stBTRCoreHdl* pstlhBTRCore = NULL;
1672  enBTRCoreRet* penExitStatusRunTask= NULL;
1673  enBTRCoreRet lenBTRCoreRet = enBTRCoreSuccess;
1674 
1675  gint64 li64usTimeout = 0;
1676  guint16 lui16msTimeout = 20;
1677  BOOLEAN lbRunTaskExit = FALSE;
1678  enBTRCoreTaskOp lenRunTskOpPrv = enBTRCoreTaskOpUnknown;
1679  enBTRCoreTaskOp lenRunTskOpCur = enBTRCoreTaskOpUnknown;
1680  enBTRCoreTaskProcessType lenRunTskPTCur = enBTRCoreTaskPTUnknown;
1681  void* lpvRunTskInData = NULL;
1682  stBTRCoreTaskGAqData* lpstRunTaskGAqData = NULL;
1683 
1684 
1685  pstlhBTRCore = (stBTRCoreHdl*)apsthBTRCore;
1686 
1687  if (!(penExitStatusRunTask = g_malloc0(sizeof(enBTRCoreRet)))) {
1688  BTRCORELOG_ERROR ("RunTask failure - No Memory\n");
1689  return NULL;
1690  }
1691 
1692  if (!pstlhBTRCore || !pstlhBTRCore->connHdl) {
1693  BTRCORELOG_ERROR ("RunTask failure - BTRCore not initialized\n");
1694  *penExitStatusRunTask = enBTRCoreNotInitialized;
1695  return (gpointer)penExitStatusRunTask;
1696  }
1697 
1698 
1699  BTRCORELOG_DEBUG ("%s \n", "RunTask Started");
1700 
1701  do {
1702 
1703  /* Process incoming task-ops */
1704  {
1705  li64usTimeout = lui16msTimeout * G_TIME_SPAN_MILLISECOND;
1706  if ((lpstRunTaskGAqData = g_async_queue_timeout_pop(pstlhBTRCore->pGAQueueRunTask, li64usTimeout))) {
1707  lenRunTskOpCur = lpstRunTaskGAqData->enBTRCoreTskOp;
1708  lenRunTskPTCur = lpstRunTaskGAqData->enBTRCoreTskPT;
1709  lpvRunTskInData= lpstRunTaskGAqData->pvBTRCoreTskInData;
1710  g_free(lpstRunTaskGAqData);
1711  lpstRunTaskGAqData = NULL;
1712  BTRCORELOG_INFO ("g_async_queue_timeout_pop %d %d %p\n", lenRunTskOpCur, lenRunTskPTCur, lpvRunTskInData);
1713  }
1714  }
1715 
1716 
1717  /* Set up operation - Schedule state changes for next interation */
1718  if (lenRunTskOpPrv != lenRunTskOpCur) {
1719  lenRunTskOpPrv = lenRunTskOpCur;
1720 
1721  switch (lenRunTskOpCur) {
1722  case enBTRCoreTaskOpStart: {
1723  BTRCORELOG_INFO ("enBTRCoreTaskOpStart\n");
1724  if ((lenBTRCoreRet = btrCore_RunTaskAddOp(pstlhBTRCore->pGAQueueRunTask, enBTRCoreTaskOpProcess, enBTRCoreTaskPTUnknown, NULL)) != enBTRCoreSuccess) {
1725  BTRCORELOG_ERROR("Failure btrCore_RunTaskAddOp enBTRCoreTaskOpProcess enBTRCoreTaskPTUnknown = %d\n", lenBTRCoreRet);
1726  }
1727 
1728  break;
1729  }
1730  case enBTRCoreTaskOpStop: {
1731  BTRCORELOG_INFO ("enBTRCoreTaskOpStop\n");
1732 
1733  break;
1734  }
1735  case enBTRCoreTaskOpIdle: {
1736  BTRCORELOG_INFO ("enBTRCoreTaskOpIdle\n");
1737 
1738  break;
1739  }
1740  case enBTRCoreTaskOpProcess: {
1741  BTRCORELOG_INFO ("enBTRCoreTaskOpProcess\n");
1742 
1743  break;
1744  }
1745  case enBTRCoreTaskOpExit: {
1746  BTRCORELOG_INFO ("enBTRCoreTaskOpExit\n");
1747 
1748  break;
1749  }
1750  case enBTRCoreTaskOpUnknown: {
1751  BTRCORELOG_INFO ("enBTRCoreTaskOpUnknown\n");
1752 
1753  break;
1754  }
1755  default:
1756  BTRCORELOG_INFO ("default\n");
1757  break;
1758  }
1759 
1760  }
1761 
1762 
1763  /* Process Operations */
1764  {
1765  switch (lenRunTskOpCur) {
1766  case enBTRCoreTaskOpStart: {
1767 
1768  break;
1769  }
1770  case enBTRCoreTaskOpStop: {
1771  g_thread_yield();
1772 
1773  break;
1774  }
1775  case enBTRCoreTaskOpIdle: {
1776  g_thread_yield();
1777 
1778  break;
1779  }
1780  case enBTRCoreTaskOpProcess: {
1781  if (BtrCore_BTSendReceiveMessages(pstlhBTRCore->connHdl) != 0) {
1782  *penExitStatusRunTask = enBTRCoreFailure;
1783  lbRunTaskExit = TRUE;
1784  }
1785 
1786  break;
1787  }
1788  case enBTRCoreTaskOpExit: {
1789  *penExitStatusRunTask = enBTRCoreSuccess;
1790  lbRunTaskExit = TRUE;
1791 
1792  break;
1793  }
1794  case enBTRCoreTaskOpUnknown: {
1795  g_thread_yield();
1796 
1797  break;
1798  }
1799  default:
1800  g_thread_yield();
1801  break;
1802  }
1803 
1804  }
1805 
1806  } while (lbRunTaskExit == FALSE);
1807 
1808  BTRCORELOG_DEBUG ("RunTask Exiting\n");
1809 
1810 
1811  return (gpointer)penExitStatusRunTask;
1812 }
1813 
1814 
1815 static gpointer
1816 btrCore_OutTask (
1817  gpointer apsthBTRCore
1818 ) {
1819  stBTRCoreHdl* pstlhBTRCore = NULL;
1820  enBTRCoreRet* penExitStatusOutTask= NULL;
1821  enBTRCoreRet lenBTRCoreRet = enBTRCoreSuccess;
1822 
1823  gint64 li64usTimeout = 0;
1824  guint16 lui16msTimeout = 50;
1825  BOOLEAN lbOutTaskExit = FALSE;
1826  enBTRCoreTaskOp lenOutTskOpPrv = enBTRCoreTaskOpUnknown;
1827  enBTRCoreTaskOp lenOutTskOpCur = enBTRCoreTaskOpUnknown;
1828  enBTRCoreTaskProcessType lenOutTskPTCur = enBTRCoreTaskPTUnknown;
1829  stBTRCoreOTskInData* lpstOutTskInData = NULL;
1830  stBTRCoreTaskGAqData* lpstOutTaskGAqData = NULL;
1831 
1832 
1833 
1834  pstlhBTRCore = (stBTRCoreHdl*)apsthBTRCore;
1835 
1836  if (!(penExitStatusOutTask = g_malloc0(sizeof(enBTRCoreRet)))) {
1837  BTRCORELOG_ERROR ("OutTask failure - No Memory\n");
1838  return NULL;
1839  }
1840 
1841  if (!pstlhBTRCore || !pstlhBTRCore->connHdl) {
1842  BTRCORELOG_ERROR ("OutTask failure - BTRCore not initialized\n");
1843  *penExitStatusOutTask = enBTRCoreNotInitialized;
1844  return (gpointer)penExitStatusOutTask;
1845  }
1846 
1847 
1848  BTRCORELOG_DEBUG ("OutTask Started\n");
1849 
1850  do {
1851 
1852  /* Process incoming task-ops */
1853  {
1854  li64usTimeout = lui16msTimeout * G_TIME_SPAN_MILLISECOND;
1855  if ((lpstOutTaskGAqData = (stBTRCoreTaskGAqData*)(g_async_queue_timeout_pop(pstlhBTRCore->pGAQueueOutTask, li64usTimeout)))) {
1856  lenOutTskOpCur = lpstOutTaskGAqData->enBTRCoreTskOp;
1857  lenOutTskPTCur = lpstOutTaskGAqData->enBTRCoreTskPT;
1858  lpstOutTskInData= lpstOutTaskGAqData->pvBTRCoreTskInData;
1859  g_free(lpstOutTaskGAqData);
1860  lpstOutTaskGAqData = NULL;
1861  BTRCORELOG_INFO ("g_async_queue_timeout_pop %d %d %p\n", lenOutTskOpCur, lenOutTskPTCur, lpstOutTskInData);
1862  }
1863  }
1864 
1865 
1866  /* Set up operation - Schedule state changes for next interation */
1867  if (lenOutTskOpPrv != lenOutTskOpCur) {
1868  lenOutTskOpPrv = lenOutTskOpCur;
1869 
1870  switch (lenOutTskOpCur) {
1871  case enBTRCoreTaskOpStart: {
1872  BTRCORELOG_INFO ("enBTRCoreTaskOpStart\n");
1873  if ((lenBTRCoreRet = btrCore_OutTaskAddOp(pstlhBTRCore->pGAQueueOutTask, enBTRCoreTaskOpIdle, enBTRCoreTaskPTUnknown, NULL)) != enBTRCoreSuccess) {
1874  BTRCORELOG_ERROR("Failure btrCore_OutTaskAddOp enBTRCoreTaskOpProcess enBTRCoreTaskPTUnknown = %d\n", lenBTRCoreRet);
1875  }
1876 
1877  break;
1878  }
1879  case enBTRCoreTaskOpStop: {
1880  BTRCORELOG_INFO ("enBTRCoreTaskOpStop\n");
1881 
1882  break;
1883  }
1884  case enBTRCoreTaskOpIdle: {
1885  BTRCORELOG_INFO ("enBTRCoreTaskOpIdle\n");
1886 
1887  break;
1888  }
1889  case enBTRCoreTaskOpProcess: {
1890  BTRCORELOG_INFO ("enBTRCoreTaskOpProcess\n");
1891  if ((lenBTRCoreRet = btrCore_OutTaskAddOp(pstlhBTRCore->pGAQueueOutTask, enBTRCoreTaskOpIdle, enBTRCoreTaskPTUnknown, NULL)) != enBTRCoreSuccess) {
1892  BTRCORELOG_ERROR("Failure btrCore_OutTaskAddOp enBTRCoreTaskOpProcess enBTRCoreTaskPTUnknown = %d\n", lenBTRCoreRet);
1893  }
1894 
1895  break;
1896  }
1897  case enBTRCoreTaskOpExit: {
1898  BTRCORELOG_INFO ("enBTRCoreTaskOpExit\n");
1899 
1900  break;
1901  }
1902  case enBTRCoreTaskOpUnknown: {
1903  BTRCORELOG_INFO ("enBTRCoreTaskOpUnknown\n");
1904 
1905  break;
1906  }
1907  default:
1908  BTRCORELOG_INFO ("default\n");
1909  break;
1910  }
1911 
1912  }
1913 
1914 
1915  /* Process Operations */
1916  /* Should handle all State updates - Handle with care */
1917  {
1918  switch (lenOutTskOpCur) {
1919  case enBTRCoreTaskOpStart: {
1920 
1921  break;
1922  }
1923  case enBTRCoreTaskOpStop: {
1924  g_thread_yield();
1925 
1926  break;
1927  }
1928  case enBTRCoreTaskOpIdle: {
1929  g_thread_yield();
1930 
1931  break;
1932  }
1933  case enBTRCoreTaskOpProcess: {
1934 
1935  if (lenOutTskPTCur == enBTRCoreTaskPTcBDeviceDisc) {
1936 
1937  if (lpstOutTskInData && lpstOutTskInData->pstBTDevInfo) {
1938  stBTDeviceInfo* lpstBTDeviceInfo = (stBTDeviceInfo*)lpstOutTskInData->pstBTDevInfo;
1939  stBTRCoreBTDevice lstFoundDevice;
1940  int i32ScannedDevIdx = -1;
1941 
1942  if ((i32ScannedDevIdx = btrCore_AddDeviceToScannedDevicesArr(pstlhBTRCore, lpstBTDeviceInfo, &lstFoundDevice)) != -1) {
1943  BTRCORELOG_DEBUG ("btrCore_AddDeviceToScannedDevicesArr - Success Index = %d\n", i32ScannedDevIdx);
1944 
1945  pstlhBTRCore->stDiscoveryCbInfo.type = enBTRCoreOpTypeDevice;
1946  memcpy(&pstlhBTRCore->stDiscoveryCbInfo.device, &lstFoundDevice, sizeof(stBTRCoreBTDevice));
1947 
1948  if (pstlhBTRCore->fpcBBTRCoreDeviceDisc) {
1949  if ((lenBTRCoreRet = pstlhBTRCore->fpcBBTRCoreDeviceDisc(&pstlhBTRCore->stDiscoveryCbInfo,
1950  pstlhBTRCore->pvcBDevDiscUserData)) != enBTRCoreSuccess) {
1951  BTRCORELOG_ERROR ("Failure fpcBBTRCoreDeviceDisc Ret = %d\n", lenBTRCoreRet);
1952  }
1953  }
1954  }
1955 
1956  g_free(lpstOutTskInData->pstBTDevInfo);
1957  lpstOutTskInData->pstBTDevInfo = NULL;
1958  }
1959 
1960  if (lpstOutTskInData) {
1961  g_free(lpstOutTskInData);
1962  lpstOutTskInData = NULL;
1963  }
1964  }
1965  else if (lenOutTskPTCur == enBTRCoreTaskPTcBDeviceRemoved) {
1966 
1967  if (lpstOutTskInData && lpstOutTskInData->pstBTDevInfo) {
1968  stBTDeviceInfo* lpstBTDeviceInfo = (stBTDeviceInfo*)lpstOutTskInData->pstBTDevInfo;
1969  stBTRCoreBTDevice lstRemovedDevice;
1970  tBTRCoreDevId lBTRCoreDevId = lpstOutTskInData->bTRCoreDevId;
1971 
1972  (void)lpstBTDeviceInfo;
1973  memset (&lstRemovedDevice, 0, sizeof(stBTRCoreBTDevice));
1974 
1975  lenBTRCoreRet = btrCore_RemoveDeviceFromScannedDevicesArr (pstlhBTRCore, lBTRCoreDevId, &lstRemovedDevice);
1976 
1977  if (lenBTRCoreRet == enBTRCoreSuccess && lstRemovedDevice.tDeviceId) {
1978 
1979  pstlhBTRCore->stDiscoveryCbInfo.type = enBTRCoreOpTypeDevice;
1980  memcpy(&pstlhBTRCore->stDiscoveryCbInfo.device, &lstRemovedDevice, sizeof(stBTRCoreBTDevice));
1981 
1982  if (pstlhBTRCore->fpcBBTRCoreDeviceDisc) {
1983  if ((lenBTRCoreRet = pstlhBTRCore->fpcBBTRCoreDeviceDisc(&pstlhBTRCore->stDiscoveryCbInfo,
1984  pstlhBTRCore->pvcBDevDiscUserData)) != enBTRCoreSuccess) {
1985  BTRCORELOG_ERROR ("Failure fpcBBTRCoreDeviceDisc Ret = %d\n", lenBTRCoreRet);
1986  }
1987  }
1988  }
1989  else {
1990  BTRCORELOG_ERROR ("Failed to remove dev %lld from Scanned List | Ret = %d\n", lBTRCoreDevId, lenBTRCoreRet);
1991  }
1992 
1993 
1994  if (!pstlhBTRCore->numOfScannedDevices) {
1995  BTRCORELOG_INFO ("\nClearing Scanned Device List...\n");
1996  btrCore_ClearScannedDevicesList(pstlhBTRCore);
1997 
1998  pstlhBTRCore->stDevStatusCbInfo.deviceId = 0; // Need to have any special IDs for this purpose like 0xFFFFFFFF
1999  pstlhBTRCore->stDevStatusCbInfo.eDevicePrevState = enBTRCoreDevStFound;
2000  pstlhBTRCore->stDevStatusCbInfo.eDeviceCurrState = enBTRCoreDevStLost;
2001  pstlhBTRCore->stDevStatusCbInfo.isPaired = 0;
2002 
2003  if (pstlhBTRCore->fpcBBTRCoreStatus) {
2004  // We are already in OutTask - But use btrCore_OutTaskAddOp - Dont trigger Status callbacks from DeviceRemoved Process Type
2005  //if (pstlhBTRCore->fpcBBTRCoreStatus(&pstlhBTRCore->stDevStatusCbInfo, pstlhBTRCore->pvcBStatusUserData) != enBTRCoreSuccess) {
2006  //}
2007  }
2008  }
2009 
2010  g_free(lpstOutTskInData->pstBTDevInfo);
2011  lpstOutTskInData->pstBTDevInfo = NULL;
2012  }
2013 
2014  if (lpstOutTskInData) {
2015  g_free(lpstOutTskInData);
2016  lpstOutTskInData = NULL;
2017  }
2018  }
2019  else if (lenOutTskPTCur == enBTRCoreTaskPTcBDeviceLost) {
2020 
2021  if (lpstOutTskInData && lpstOutTskInData->pstBTDevInfo) {
2022  stBTDeviceInfo* lpstBTDeviceInfo = (stBTDeviceInfo*)lpstOutTskInData->pstBTDevInfo;
2023  tBTRCoreDevId lBTRCoreDevId = lpstOutTskInData->bTRCoreDevId;
2024  int i32LoopIdx = -1;
2025  int i32KnownDevIdx = -1;
2026  BOOLEAN postEvent = FALSE;
2027 
2028  (void)lpstBTDeviceInfo;
2029 
2030  for (i32LoopIdx = 0; i32LoopIdx < pstlhBTRCore->numOfPairedDevices; i32LoopIdx++) {
2031  if (lBTRCoreDevId == pstlhBTRCore->stKnownDevicesArr[i32LoopIdx].tDeviceId) {
2032  i32KnownDevIdx = i32LoopIdx;
2033  break;
2034  }
2035  }
2036 
2037 
2038  if (pstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx].tDeviceId == lBTRCoreDevId) {
2039  BTRCORELOG_INFO ("Device %llu power state Off or OOR\n", pstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx].tDeviceId);
2040  BTRCORELOG_TRACE ("i32LoopIdx = %d\n", i32KnownDevIdx);
2041  BTRCORELOG_TRACE ("pstlhBTRCore->stKnownDevStInfoArr[i32LoopIdx].eDeviceCurrState = %d\n", pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState);
2042  BTRCORELOG_TRACE ("pstlhBTRCore->stKnownDevStInfoArr[i32LoopIdx].eDevicePrevState = %d\n", pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState);
2043 
2044  if (((pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState == enBTRCoreDevStConnected) ||
2045  (pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState == enBTRCoreDevStPlaying)) &&
2046  (pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState == enBTRCoreDevStDisconnecting)) {
2047 
2048  pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState = pstlhBTRCore->stKnownDevStInfoArr[i32LoopIdx].eDeviceCurrState;
2049  pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState = enBTRCoreDevStDisconnected;
2050  pstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx].bDeviceConnected = FALSE;
2051  postEvent = TRUE;
2052  }
2053  else if (pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState == enBTRCoreDevStPlaying ||
2054  pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState == enBTRCoreDevStConnected ) {
2055 
2056  pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState = pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState;
2057  pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState = enBTRCoreDevStLost;
2058  pstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx].bDeviceConnected = FALSE;
2059  postEvent = TRUE;
2060  }
2061 
2062  // move this out of if block. populating stDevStatusCbInfo should be done common for both paired and scanned devices
2063  if (postEvent) {
2064  pstlhBTRCore->stDevStatusCbInfo.deviceId = pstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx].tDeviceId;
2065  pstlhBTRCore->stDevStatusCbInfo.eDeviceClass = pstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx].enDeviceType;
2066  pstlhBTRCore->stDevStatusCbInfo.ui32DevClassBtSpec = pstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx].ui32DevClassBtSpec;
2067  pstlhBTRCore->stDevStatusCbInfo.eDevicePrevState = pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState;
2068  pstlhBTRCore->stDevStatusCbInfo.eDeviceCurrState = pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState;
2069  pstlhBTRCore->stDevStatusCbInfo.eDeviceType = btrCore_MapDevClassToDevType(pstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx].enDeviceType);
2070  pstlhBTRCore->stDevStatusCbInfo.isPaired = 1;
2071  strncpy(pstlhBTRCore->stDevStatusCbInfo.deviceName, pstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx].pcDeviceName, BD_NAME_LEN);
2072  strncpy(pstlhBTRCore->stDevStatusCbInfo.deviceAddress, pstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx].pcDeviceAddress, BD_NAME_LEN);
2073 
2074  if (pstlhBTRCore->fpcBBTRCoreStatus) {
2075  if ((lenBTRCoreRet = pstlhBTRCore->fpcBBTRCoreStatus(&pstlhBTRCore->stDevStatusCbInfo, pstlhBTRCore->pvcBStatusUserData)) != enBTRCoreSuccess) {
2076  BTRCORELOG_ERROR ("Failure fpcBBTRCoreStatus Ret = %d\n", lenBTRCoreRet);
2077  }
2078  }
2079  }
2080  }
2081 
2082  g_free(lpstOutTskInData->pstBTDevInfo);
2083  lpstOutTskInData->pstBTDevInfo = NULL;
2084  }
2085 
2086  if (lpstOutTskInData) {
2087  g_free(lpstOutTskInData);
2088  lpstOutTskInData = NULL;
2089  }
2090  }
2091  else if (lenOutTskPTCur == enBTRCoreTaskPTcBDeviceStatus) {
2092 
2093  if (lpstOutTskInData && lpstOutTskInData->pstBTDevInfo) {
2094  stBTDeviceInfo* lpstBTDeviceInfo = (stBTDeviceInfo*)lpstOutTskInData->pstBTDevInfo;
2095 
2096  int i32LoopIdx = -1;
2097  int i32KnownDevIdx = -1;
2098  int i32ScannedDevIdx = -1;
2099 
2100  tBTRCoreDevId lBTRCoreDevId = lpstOutTskInData->bTRCoreDevId;
2101  enBTRCoreDeviceType lenBTRCoreDevType = lpstOutTskInData->enBTRCoreDevType;
2102  enBTRCoreDeviceState leBTDevState = btrCore_BTParseDeviceState(lpstBTDeviceInfo->pcDeviceCurrState);
2103 
2104 
2105  if (pstlhBTRCore->numOfPairedDevices) {
2106  for (i32LoopIdx = 0; i32LoopIdx < pstlhBTRCore->numOfPairedDevices; i32LoopIdx++) {
2107  if (lBTRCoreDevId == pstlhBTRCore->stKnownDevicesArr[i32LoopIdx].tDeviceId) {
2108  i32KnownDevIdx = i32LoopIdx;
2109  break;
2110  }
2111  }
2112  }
2113 
2114  if (pstlhBTRCore->numOfScannedDevices) {
2115  for (i32LoopIdx = 0; i32LoopIdx < pstlhBTRCore->numOfScannedDevices; i32LoopIdx++) {
2116  if (lBTRCoreDevId == pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].tDeviceId) {
2117  i32ScannedDevIdx = i32LoopIdx;
2118  break;
2119  }
2120  }
2121  }
2122 
2123 
2124  // Current device for which Property has changed must be either in Found devices or Paired devices
2125  // TODO: if-else's for SM or HSM are bad. Find a better way
2126  if (((i32ScannedDevIdx != -1) || (i32KnownDevIdx != -1)) && (leBTDevState != enBTRCoreDevStInitialized)) {
2127  BOOLEAN bTriggerDevStatusChangeCb = FALSE;
2128  stBTRCoreBTDevice* lpstBTRCoreBTDevice = NULL;
2129  stBTRCoreDevStateInfo* lpstBTRCoreDevStateInfo = NULL;
2130 
2131  if ((i32KnownDevIdx != -1) && (leBTDevState != enBTRCoreDevStPaired)) {
2132 
2133  BTRCORELOG_TRACE ("i32KnownDevIdx = %d\n", i32KnownDevIdx);
2134  BTRCORELOG_TRACE ("leBTDevState = %d\n", leBTDevState);
2135  BTRCORELOG_TRACE ("lpstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState = %d\n", pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState);
2136  BTRCORELOG_TRACE ("lpstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState = %d\n", pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState);
2137 
2138  if ((pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState != leBTDevState) &&
2139  (pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState != enBTRCoreDevStInitialized)) {
2140 
2141  if ((enBTRCoreMobileAudioIn != lenBTRCoreDevType) && (enBTRCorePCAudioIn != lenBTRCoreDevType)) {
2142 
2143  if ( !(((pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState != enBTRCoreDevStPlaying) &&
2144  (pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState == enBTRCoreDevStConnected) && (leBTDevState == enBTRCoreDevStDisconnected)) ||
2145  ((pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState == enBTRCoreDevStDisconnected) && (leBTDevState == enBTRCoreDevStConnected) &&
2146  ((pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState != enBTRCoreDevStPaired) ||
2147  (pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState != enBTRCoreDevStConnecting))))) {
2148  bTriggerDevStatusChangeCb = TRUE;
2149  }
2150 
2151  if ((enBTRCoreHID == lenBTRCoreDevType) &&
2152  (((enBTRCoreDevStConnected == pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState) && (enBTRCoreDevStDisconnected == leBTDevState)) ||
2153  ((enBTRCoreDevStDisconnected == pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState) && (enBTRCoreDevStConnected == leBTDevState)))) {
2154  bTriggerDevStatusChangeCb = TRUE;
2155 
2156  if (strstr(pstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx].pcDeviceName, "Xbox")) {
2157  if (leBTDevState == enBTRCoreDevStConnected) {
2158  if (BtrCore_BTDisableEnhancedRetransmissionMode(pstlhBTRCore->connHdl) != 0) {
2159  BTRCORELOG_ERROR ("Failed to Disable ERTM\n");
2160  }
2161  }
2162  else if (leBTDevState == enBTRCoreDevStDisconnected) {
2163  if (BtrCore_BTEnableEnhancedRetransmissionMode(pstlhBTRCore->connHdl) != 0) {
2164  BTRCORELOG_ERROR ("Failed to Enable ERTM\n");
2165  }
2166  }
2167  }
2168  }
2169 
2170  // To make the state changes in a better logical way once the BTRCore dev structures are unified further
2171 
2172  //workaround for notifying the power Up event of a <paired && !connected> devices, as we are not able to track the
2173  //power Down event of such devices as per the current analysis
2174  if ((leBTDevState == enBTRCoreDevStDisconnected) &&
2175  ((pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState == enBTRCoreDevStConnected) ||
2176  (pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState == enBTRCoreDevStDisconnecting))) {
2177  pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState = enBTRCoreDevStPaired;
2178  }
2179  else if ( !((leBTDevState == enBTRCoreDevStConnected) &&
2180  ((pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState == enBTRCoreDevStDisconnecting) ||
2181  (pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState == enBTRCoreDevStDisconnected) ||
2182  (pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState == enBTRCoreDevStInitialized)))) {
2183  pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState = pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState;
2184  }
2185 
2186 
2187  if ((leBTDevState == enBTRCoreDevStDisconnected) &&
2188  (pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState == enBTRCoreDevStPlaying)) {
2189  leBTDevState = enBTRCoreDevStLost;
2190  pstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx].bDeviceConnected = FALSE;
2191  }
2192 
2193 
2194  if ( !((leBTDevState == enBTRCoreDevStDisconnected) &&
2195  (pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState == enBTRCoreDevStLost) &&
2196  (pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState == enBTRCoreDevStPlaying))) {
2197 
2198  if ( !((leBTDevState == enBTRCoreDevStConnected) &&
2199  (pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState == enBTRCoreDevStLost) &&
2200  (pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState != enBTRCoreDevStPlaying))) {
2201  pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState = pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState;
2202  pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState = leBTDevState;
2203  }
2204  else {
2205  pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState = enBTRCoreDevStConnecting;
2206  }
2207  }
2208  else {
2209  leBTDevState = enBTRCoreDevStConnected;
2210  pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState = enBTRCoreDevStConnecting;
2211  }
2212 
2213  }
2214  else {
2215  bTriggerDevStatusChangeCb = TRUE;
2216 
2217  if (enBTRCoreDevStInitialized != pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState) {
2218  pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState =
2219  pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState;
2220  }
2221  else {
2222  pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState = enBTRCoreDevStConnecting;
2223  }
2224 
2225  pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState = leBTDevState;
2226 
2227  //TODO: There should be no need to do this. Find out why the enDeviceType = 0;
2228  pstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx].enDeviceType = btrCore_MapClassIDtoDevClass(lpstBTDeviceInfo->ui32Class);
2229  }
2230 
2231  pstlhBTRCore->stDevStatusCbInfo.isPaired = 1;
2232  lpstBTRCoreBTDevice = &pstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx];
2233  lpstBTRCoreDevStateInfo = &pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx];
2234 
2235 
2236  if ((pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState == enBTRCoreDevStConnected) &&
2237  (pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState == enBTRCoreDevStPaired)) {
2238  pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState = enBTRCoreDevStPaired;
2239  pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState = enBTRCoreDevStConnected;
2240  }
2241 
2242  BTRCORELOG_TRACE ("i32KnownDevIdx = %d\n", i32KnownDevIdx);
2243  BTRCORELOG_TRACE ("leBTDevState = %d\n", leBTDevState);
2244  BTRCORELOG_TRACE ("lpstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState = %d\n", pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState);
2245  BTRCORELOG_TRACE ("lpstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState = %d\n", pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState);
2246  BTRCORELOG_TRACE ("lpstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx].enDeviceType = %x\n", pstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx].enDeviceType);
2247 
2248  if (pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState == enBTRCoreDevStDisconnected) {
2249  pstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx].bDeviceConnected = FALSE;
2250  }
2251  else if (pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState == enBTRCoreDevStConnected) {
2252  pstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx].bDeviceConnected = TRUE;
2253  }
2254 
2255  }
2256  }
2257  else if (i32ScannedDevIdx != -1) {
2258 
2259  BTRCORELOG_TRACE ("i32ScannedDevIdx = %d\n", i32ScannedDevIdx);
2260  BTRCORELOG_TRACE ("leBTDevState = %d\n", leBTDevState);
2261  BTRCORELOG_TRACE ("lpstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDeviceCurrState = %d\n", pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDeviceCurrState);
2262  BTRCORELOG_TRACE ("lpstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDevicePrevState = %d\n", pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDevicePrevState);
2263 
2264  if ((pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDeviceCurrState != leBTDevState) &&
2265  (pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDeviceCurrState != enBTRCoreDevStInitialized)) {
2266 
2267  pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDevicePrevState = pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDeviceCurrState;
2268  pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDeviceCurrState = leBTDevState;
2269  pstlhBTRCore->stDevStatusCbInfo.isPaired = lpstBTDeviceInfo->bPaired;
2270 
2271  lpstBTRCoreBTDevice = &pstlhBTRCore->stScannedDevicesArr[i32ScannedDevIdx];
2272  lpstBTRCoreDevStateInfo = &pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx];
2273 
2274  if (lpstBTDeviceInfo->bPaired &&
2275  lpstBTDeviceInfo->bConnected &&
2276  (((pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDevicePrevState == enBTRCoreDevStFound) &&
2277  (pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDeviceCurrState == enBTRCoreDevStConnected)) ||
2278  ((pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDevicePrevState == enBTRCoreDevStFound) &&
2279  (pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDeviceCurrState == enBTRCoreDevStPaired)) ||
2280  ((pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDevicePrevState == enBTRCoreDevStConnected) &&
2281  (pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDeviceCurrState == enBTRCoreDevStPaired)))) {
2282 
2283  if ((i32KnownDevIdx = btrCore_AddDeviceToKnownDevicesArr(pstlhBTRCore, lpstBTDeviceInfo)) != -1) {
2284 
2285  if ((pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDevicePrevState == enBTRCoreDevStConnected) &&
2286  (pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDeviceCurrState == enBTRCoreDevStPaired)) {
2287  pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDevicePrevState = enBTRCoreDevStPaired;
2288  pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDeviceCurrState = enBTRCoreDevStConnected;
2289  }
2290 
2291  if (!((pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState == enBTRCoreDevStPaired) &&
2292  (pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState == enBTRCoreDevStConnected))) {
2293  pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDevicePrevState = pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDevicePrevState;
2294  pstlhBTRCore->stKnownDevStInfoArr[i32KnownDevIdx].eDeviceCurrState = pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDeviceCurrState;
2295  }
2296 
2297  BTRCORELOG_DEBUG ("btrCore_AddDeviceToKnownDevicesArr - Success Index = %d\n", i32KnownDevIdx);
2298  }
2299 
2300  //TODO: Really really dont like this - Live with it for now
2301  if (pstlhBTRCore->numOfPairedDevices) {
2302  for (i32LoopIdx = 0; i32LoopIdx < pstlhBTRCore->numOfPairedDevices; i32LoopIdx++) {
2303  if (lBTRCoreDevId == pstlhBTRCore->stKnownDevicesArr[i32LoopIdx].tDeviceId) {
2304  //i32KnownDevIdx = i32LoopIdx;
2305  lpstBTRCoreBTDevice = &pstlhBTRCore->stKnownDevicesArr[i32LoopIdx];
2306  lpstBTRCoreDevStateInfo = &pstlhBTRCore->stKnownDevStInfoArr[i32LoopIdx];
2307  }
2308  }
2309  }
2310  }
2311 
2312  if (lenBTRCoreDevType == enBTRCoreLE &&
2313  (leBTDevState == enBTRCoreDevStConnected ||
2314  leBTDevState == enBTRCoreDevStDisconnected)) {
2315  lpstBTRCoreBTDevice = &pstlhBTRCore->stScannedDevicesArr[i32ScannedDevIdx];
2316  lpstBTRCoreDevStateInfo = &pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx];
2317 
2318  if (leBTDevState == enBTRCoreDevStDisconnected) {
2319  lpstBTRCoreBTDevice->bDeviceConnected = FALSE;
2320  }
2321 
2322  if (pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDevicePrevState == enBTRCoreDevStInitialized) {
2323  pstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDevicePrevState = enBTRCoreDevStConnecting;
2324  }
2325  }
2326 
2327  bTriggerDevStatusChangeCb = TRUE;
2328  }
2329  }
2330 
2331  if (bTriggerDevStatusChangeCb == TRUE) {
2332 
2333  if (lpstBTRCoreBTDevice->enDeviceType == enBTRCore_DC_Unknown) {
2334  for (i32LoopIdx = 0; i32LoopIdx < lpstBTRCoreBTDevice->stDeviceProfile.numberOfService; i32LoopIdx++) {
2335  if (lpstBTRCoreBTDevice->stDeviceProfile.profile[i32LoopIdx].uuid_value == strtol(BTR_CORE_A2SNK, NULL, 16)) {
2336  lpstBTRCoreBTDevice->enDeviceType = enBTRCore_DC_Loudspeaker;
2337  }
2338  else if (lpstBTRCoreBTDevice->stDeviceProfile.profile[i32LoopIdx].uuid_value == strtol(BTR_CORE_A2SRC, NULL, 16)) {
2339  lpstBTRCoreBTDevice->enDeviceType = enBTRCore_DC_SmartPhone;
2340  }
2341  else if ((lpstBTRCoreBTDevice->stDeviceProfile.profile[i32LoopIdx].uuid_value == strtol(BTR_CORE_GATT_TILE_1, NULL, 16)) ||
2342  (lpstBTRCoreBTDevice->stDeviceProfile.profile[i32LoopIdx].uuid_value == strtol(BTR_CORE_GATT_TILE_2, NULL, 16)) ||
2343  (lpstBTRCoreBTDevice->stDeviceProfile.profile[i32LoopIdx].uuid_value == strtol(BTR_CORE_GATT_TILE_3, NULL, 16))) {
2344  lpstBTRCoreBTDevice->enDeviceType = enBTRCore_DC_Tile;
2345  }
2346  else if (lpstBTRCoreBTDevice->stDeviceProfile.profile[i32LoopIdx].uuid_value == strtol(BTR_CORE_HID_1, NULL, 16) ||
2347  lpstBTRCoreBTDevice->stDeviceProfile.profile[i32LoopIdx].uuid_value == strtol(BTR_CORE_HID_2, NULL, 16)) {
2348  lpstBTRCoreBTDevice->enDeviceType = enBTRCore_DC_HID_Keyboard;
2349  }
2350  }
2351  }
2352 
2353  pstlhBTRCore->stDevStatusCbInfo.deviceId = lBTRCoreDevId;
2354  pstlhBTRCore->stDevStatusCbInfo.eDeviceType = btrCore_MapDevClassToDevType(lpstBTRCoreBTDevice->enDeviceType);
2355  pstlhBTRCore->stDevStatusCbInfo.eDevicePrevState = lpstBTRCoreDevStateInfo->eDevicePrevState;
2356  pstlhBTRCore->stDevStatusCbInfo.eDeviceCurrState = leBTDevState;
2357  pstlhBTRCore->stDevStatusCbInfo.eDeviceClass = lpstBTRCoreBTDevice->enDeviceType;
2358  pstlhBTRCore->stDevStatusCbInfo.ui32DevClassBtSpec = lpstBTRCoreBTDevice->ui32DevClassBtSpec;
2359  strncpy(pstlhBTRCore->stDevStatusCbInfo.deviceName, lpstBTRCoreBTDevice->pcDeviceName, BD_NAME_LEN);
2360  strncpy(pstlhBTRCore->stDevStatusCbInfo.deviceAddress, lpstBTRCoreBTDevice->pcDeviceAddress, BD_NAME_LEN);
2361 
2362  if (pstlhBTRCore->fpcBBTRCoreStatus) {
2363  if (pstlhBTRCore->fpcBBTRCoreStatus(&pstlhBTRCore->stDevStatusCbInfo, pstlhBTRCore->pvcBStatusUserData) != enBTRCoreSuccess) {
2364  /* Invoke the callback */
2365  }
2366  }
2367  }
2368  }
2369 
2370  g_free(lpstOutTskInData->pstBTDevInfo);
2371  lpstOutTskInData->pstBTDevInfo = NULL;
2372  }
2373 
2374  if (lpstOutTskInData) {
2375  g_free(lpstOutTskInData);
2376  lpstOutTskInData = NULL;
2377  }
2378  }
2379  else if (lenOutTskPTCur == enBTRCoreTaskPTcBAdapterStatus) {
2380  if (lpstOutTskInData) {
2381  stBTRCoreAdapter* lpstBTRCoreAdapter = (stBTRCoreAdapter*)lpstOutTskInData;
2382 
2383  BTRCORELOG_TRACE ("stDiscoveryCbInfo.adapter.bDiscovering = %d, lpstBTRCoreAdapter->bDiscovering = %d\n",
2384  pstlhBTRCore->stDiscoveryCbInfo.adapter.bDiscovering, lpstBTRCoreAdapter->bDiscovering);
2385 
2386  // invoke the callback to mgr only if the adapter's properties (such as its discovering state) changed
2387  if (pstlhBTRCore->stDiscoveryCbInfo.adapter.bDiscovering != lpstBTRCoreAdapter->bDiscovering)
2388  {
2389  pstlhBTRCore->stDiscoveryCbInfo.type = enBTRCoreOpTypeAdapter;
2390  memcpy(&pstlhBTRCore->stDiscoveryCbInfo.adapter, lpstBTRCoreAdapter, sizeof(stBTRCoreAdapter));
2391  if (pstlhBTRCore->fpcBBTRCoreDeviceDisc) {
2392  if ((lenBTRCoreRet = pstlhBTRCore->fpcBBTRCoreDeviceDisc(&pstlhBTRCore->stDiscoveryCbInfo,
2393  pstlhBTRCore->pvcBDevDiscUserData)) != enBTRCoreSuccess) {
2394  BTRCORELOG_ERROR ("Failure fpcBBTRCoreDeviceDisc Ret = %d\n", lenBTRCoreRet);
2395  }
2396  }
2397  }
2398 
2399  g_free(lpstOutTskInData);
2400  lpstOutTskInData = NULL;
2401  }
2402  }
2403  else if (lenOutTskPTCur == enBTRCoreTaskPTcBMediaStatus) {
2404  if (lpstOutTskInData) {
2405  stBTRCoreMediaStatusCBInfo* lpstMediaStatusUpdateCbInfo = (stBTRCoreMediaStatusCBInfo*)lpstOutTskInData;
2406  tBTRCoreDevId lBTRCoreDevId = lpstMediaStatusUpdateCbInfo->deviceId;
2407  int i32LoopIdx = -1;
2408  int i32KnownDevIdx = -1;
2409 
2410  for (i32LoopIdx = 0; i32LoopIdx < pstlhBTRCore->numOfPairedDevices; i32LoopIdx++) {
2411  if (lBTRCoreDevId == pstlhBTRCore->stKnownDevicesArr[i32LoopIdx].tDeviceId) {
2412  i32KnownDevIdx = i32LoopIdx;
2413  break;
2414  }
2415  }
2416 
2417  BTRCORELOG_TRACE ("i32KnownDevIdx = %d\n", i32KnownDevIdx);
2418 
2419  if ((i32KnownDevIdx != -1) &&
2420  ((pstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx].bDeviceConnected == TRUE) ||
2421  (lpstMediaStatusUpdateCbInfo->m_mediaStatusUpdate.bIsMediaCtrlAvailable == TRUE))) {
2422  memcpy(&pstlhBTRCore->stMediaStatusCbInfo, lpstMediaStatusUpdateCbInfo, sizeof(stBTRCoreMediaStatusCBInfo));
2423  pstlhBTRCore->stMediaStatusCbInfo.deviceId = pstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx].tDeviceId;
2424  pstlhBTRCore->stMediaStatusCbInfo.eDeviceClass = pstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx].enDeviceType;
2425  strncpy(pstlhBTRCore->stMediaStatusCbInfo.deviceName, pstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx].pcDeviceName, BD_NAME_LEN);
2426 
2427  if (pstlhBTRCore->fpcBBTRCoreMediaStatus) {
2428  if ((lenBTRCoreRet = pstlhBTRCore->fpcBBTRCoreMediaStatus(&pstlhBTRCore->stMediaStatusCbInfo, pstlhBTRCore->pvcBMediaStatusUserData)) != enBTRCoreSuccess) {
2429  BTRCORELOG_ERROR ("Failure fpcBBTRCoreMediaStatus Ret = %d\n", lenBTRCoreRet);
2430  }
2431  }
2432  }
2433 
2434  g_free(lpstOutTskInData);
2435  lpstOutTskInData = NULL;
2436  }
2437  }
2438  else if (lenOutTskPTCur == enBTRCoreTaskPTcBDevOpInfoStatus) {
2439  if (lpstOutTskInData) {
2440  stBTRCoreDevStatusCBInfo* lpstDevStatusCbInfo = (stBTRCoreDevStatusCBInfo*)lpstOutTskInData;
2441  memcpy(&pstlhBTRCore->stDevStatusCbInfo, lpstDevStatusCbInfo,sizeof(stBTRCoreDevStatusCBInfo));
2442 
2443  if (pstlhBTRCore->fpcBBTRCoreStatus) {
2444  if ((lenBTRCoreRet = pstlhBTRCore->fpcBBTRCoreStatus(&pstlhBTRCore->stDevStatusCbInfo, pstlhBTRCore->pvcBStatusUserData)) != enBTRCoreSuccess) {
2445  BTRCORELOG_ERROR ("Failure fpcBBTRCoreStatus Ret = %d\n", lenBTRCoreRet);
2446  }
2447  }
2448 
2449  g_free(lpstOutTskInData);
2450  lpstOutTskInData = NULL;
2451  }
2452  }
2453  else if (lenOutTskPTCur == enBTRCoreTaskPTcBConnIntim) {
2454  }
2455  else if (lenOutTskPTCur == enBTRCoreTaskPTcBConnAuth) {
2456  }
2457  else if (lenOutTskPTCur == enBTRCoreTaskPTUnknown) {
2458  g_thread_yield();
2459  }
2460  else {
2461  g_thread_yield();
2462  }
2463 
2464  break;
2465  }
2466  case enBTRCoreTaskOpExit: {
2467  lbOutTaskExit = TRUE;
2468  break;
2469  }
2470  case enBTRCoreTaskOpUnknown: {
2471  g_thread_yield();
2472 
2473  break;
2474  }
2475  default:
2476  g_thread_yield();
2477  break;
2478  }
2479 
2480  }
2481 
2482  } while (lbOutTaskExit == FALSE);
2483 
2484  BTRCORELOG_DEBUG ("OutTask Exiting\n");
2485 
2486 
2487  *penExitStatusOutTask = enBTRCoreSuccess;
2488  return (gpointer)penExitStatusOutTask;
2489 }
2490 
2491 
2492 /* Interfaces */
2493 enBTRCoreRet
2495  tBTRCoreHandle* phBTRCore
2496 ) {
2497  stBTRCoreHdl* pstlhBTRCore = NULL;
2498  unBTOpIfceProp lunBtOpAdapProp;
2499 
2500 #ifdef RDK_LOGGER_ENABLED
2501  const char* pDebugConfig = NULL;
2502  const char* BTRCORE_DEBUG_ACTUAL_PATH = "/etc/debug.ini";
2503  const char* BTRCORE_DEBUG_OVERRIDE_PATH = "/opt/debug.ini";
2504 
2505  /* Init the logger */
2506  if (access(BTRCORE_DEBUG_OVERRIDE_PATH, F_OK) != -1 ) {
2507  pDebugConfig = BTRCORE_DEBUG_OVERRIDE_PATH;
2508  }
2509  else {
2510  pDebugConfig = BTRCORE_DEBUG_ACTUAL_PATH;
2511  }
2512 
2513  if (rdk_logger_init(pDebugConfig) == 0) {
2514  b_rdk_logger_enabled = 1;
2515  }
2516 #endif
2517 
2518  BTRCORELOG_INFO ("BTRCore_Init\n");
2519 
2520  if (!phBTRCore) {
2521  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
2522  return enBTRCoreInvalidArg;
2523  }
2524 
2525 
2526  pstlhBTRCore = (stBTRCoreHdl*)g_malloc0(sizeof(stBTRCoreHdl));
2527  if (!pstlhBTRCore) {
2528  BTRCORELOG_ERROR ("Insufficient memory - enBTRCoreInitFailure\n");
2529  return enBTRCoreInitFailure;
2530  }
2531  memset(pstlhBTRCore, 0, sizeof(stBTRCoreHdl));
2532 
2533 
2534  pstlhBTRCore->connHdl = BtrCore_BTInitGetConnection();
2535  if (!pstlhBTRCore->connHdl) {
2536  BTRCORELOG_ERROR ("Can't get on system bus - enBTRCoreInitFailure\n");
2537  BTRCore_DeInit((tBTRCoreHandle)pstlhBTRCore);
2538  return enBTRCoreInitFailure;
2539  }
2540 
2541  //init array of scanned , known & found devices
2542  btrCore_InitDataSt(pstlhBTRCore);
2543 
2544  pstlhBTRCore->agentPath = BtrCore_BTGetAgentPath(pstlhBTRCore->connHdl);
2545  if (!pstlhBTRCore->agentPath) {
2546  BTRCORELOG_ERROR ("Can't get agent path - enBTRCoreInitFailure\n");
2547  BTRCore_DeInit((tBTRCoreHandle)pstlhBTRCore);
2548  return enBTRCoreInitFailure;
2549  }
2550 
2551 
2552  if (!(pstlhBTRCore->pGAQueueOutTask = g_async_queue_new()) ||
2553  !(pstlhBTRCore->pThreadOutTask = g_thread_new("btrCore_OutTask", btrCore_OutTask, (gpointer)pstlhBTRCore))) {
2554  BTRCORELOG_ERROR ("Failed to create btrCore_OutTask Thread - enBTRCoreInitFailure\n");
2555  BTRCore_DeInit((tBTRCoreHandle)pstlhBTRCore);
2556  return enBTRCoreInitFailure;
2557  }
2558 
2559  if (!(pstlhBTRCore->pGAQueueRunTask = g_async_queue_new()) ||
2560  !(pstlhBTRCore->pThreadRunTask = g_thread_new("btrCore_RunTask", btrCore_RunTask, (gpointer)pstlhBTRCore))) {
2561  BTRCORELOG_ERROR ("Failed to create btrCore_RunTask Thread - enBTRCoreInitFailure\n");
2562  BTRCore_DeInit((tBTRCoreHandle)pstlhBTRCore);
2563  return enBTRCoreInitFailure;
2564  }
2565 
2566  if (btrCore_OutTaskAddOp(pstlhBTRCore->pGAQueueOutTask, enBTRCoreTaskOpStart, enBTRCoreTaskPTUnknown, NULL) != enBTRCoreSuccess) {
2567  BTRCORELOG_ERROR("Failure btrCore_OutTaskAddOp enBTRCoreTaskOpStart enBTRCoreTaskPTUnknown\n");
2568  }
2569 
2570  if (btrCore_RunTaskAddOp(pstlhBTRCore->pGAQueueRunTask, enBTRCoreTaskOpStart, enBTRCoreTaskPTUnknown, NULL) != enBTRCoreSuccess) {
2571  BTRCORELOG_ERROR("Failure btrCore_RunTaskAddOp enBTRCoreTaskOpStart enBTRCoreTaskPTUnknown\n");
2572  }
2573 
2574 
2575  sched_yield();
2576 
2577 
2578  pstlhBTRCore->curAdapterPath = BtrCore_BTGetAdapterPath(pstlhBTRCore->connHdl, NULL); //mikek hard code to default adapter for now
2579  if (!pstlhBTRCore->curAdapterPath) {
2580  BTRCORELOG_ERROR ("Failed to get BT Adapter - enBTRCoreInitFailure\n");
2581  BTRCore_DeInit((tBTRCoreHandle)pstlhBTRCore);
2582  return enBTRCoreInitFailure;
2583  }
2584 
2585  lunBtOpAdapProp.enBtAdapterProp = enBTAdPropAddress;
2586  if (BtrCore_BTGetProp(pstlhBTRCore->connHdl,
2587  pstlhBTRCore->curAdapterPath,
2588  enBTAdapter,
2589  lunBtOpAdapProp,
2590  pstlhBTRCore->curAdapterAddr)) {
2591  BTRCORELOG_ERROR ("Failed to get BT Adapter Address - enBTRCoreInitFailure\n");
2592  BTRCore_DeInit((tBTRCoreHandle)pstlhBTRCore);
2593  return enBTRCoreInitFailure;
2594  }
2595 
2596  BTRCORELOG_DEBUG ("Adapter path %s - Adapter Address %s \n", pstlhBTRCore->curAdapterPath, pstlhBTRCore->curAdapterAddr);
2597 
2598 
2599  /* Initialize BTRCore SubSystems - AVMedia/Telemetry..etc. */
2600  if (BTRCore_AVMedia_Init(&pstlhBTRCore->avMediaHdl, pstlhBTRCore->connHdl, pstlhBTRCore->curAdapterPath) != enBTRCoreSuccess) {
2601  BTRCORELOG_ERROR ("Failed to Init AV Media Subsystem - enBTRCoreInitFailure\n");
2602  BTRCore_DeInit((tBTRCoreHandle)pstlhBTRCore);
2603  return enBTRCoreInitFailure;
2604  }
2605 
2606  /* Initialize BTRCore SubSystems - LE Gatt profile. */
2607  if (BTRCore_LE_Init(&pstlhBTRCore->leHdl, pstlhBTRCore->connHdl, pstlhBTRCore->curAdapterPath) != enBTRCoreSuccess) {
2608  BTRCORELOG_ERROR ("Failed to Init LE Subsystem - enBTRCoreInitFailure\n");
2609  BTRCore_DeInit((tBTRCoreHandle)pstlhBTRCore);
2610  return enBTRCoreInitFailure;
2611  }
2612 
2613 
2614  if(BtrCore_BTRegisterAdapterStatusUpdateCb(pstlhBTRCore->connHdl, &btrCore_BTAdapterStatusUpdateCb, pstlhBTRCore)) {
2615  BTRCORELOG_ERROR ("Failed to Register Adapter Status CB - enBTRCoreInitFailure\n");
2616  BTRCore_DeInit((tBTRCoreHandle)pstlhBTRCore);
2617  }
2618 
2619  if(BtrCore_BTRegisterDevStatusUpdateCb(pstlhBTRCore->connHdl, &btrCore_BTDeviceStatusUpdateCb, pstlhBTRCore)) {
2620  BTRCORELOG_ERROR ("Failed to Register Device Status CB - enBTRCoreInitFailure\n");
2621  BTRCore_DeInit((tBTRCoreHandle)pstlhBTRCore);
2622  }
2623 
2624  if(BtrCore_BTRegisterConnIntimationCb(pstlhBTRCore->connHdl, &btrCore_BTDeviceConnectionIntimationCb, pstlhBTRCore)) {
2625  BTRCORELOG_ERROR ("Failed to Register Connection Intimation CB - enBTRCoreInitFailure\n");
2626  BTRCore_DeInit((tBTRCoreHandle)pstlhBTRCore);
2627  }
2628 
2629  if(BtrCore_BTRegisterConnAuthCb(pstlhBTRCore->connHdl, &btrCore_BTDeviceAuthenticationCb, pstlhBTRCore)) {
2630  BTRCORELOG_ERROR ("Failed to Register Connection Authentication CB - enBTRCoreInitFailure\n");
2631  BTRCore_DeInit((tBTRCoreHandle)pstlhBTRCore);
2632  }
2633 
2634  if(BTRCore_AVMedia_RegisterMediaStatusUpdateCb(pstlhBTRCore->avMediaHdl, &btrCore_BTMediaStatusUpdateCb, pstlhBTRCore) != enBTRCoreSuccess) {
2635  BTRCORELOG_ERROR ("Failed to Register Media Status CB - enBTRCoreInitFailure\n");
2636  BTRCore_DeInit((tBTRCoreHandle)pstlhBTRCore);
2637  }
2638 
2639  if(BTRCore_LE_RegisterStatusUpdateCb(pstlhBTRCore->leHdl, &btrCore_BTLeStatusUpdateCb, pstlhBTRCore) != enBTRCoreSuccess) {
2640  BTRCORELOG_ERROR ("Failed to Register LE Status CB - enBTRCoreInitFailure\n");
2641  BTRCore_DeInit((tBTRCoreHandle)pstlhBTRCore);
2642  }
2643 
2644  *phBTRCore = (tBTRCoreHandle)pstlhBTRCore;
2645 
2646  //Initialize array of known devices so we can use it for stuff
2647  btrCore_PopulateListOfPairedDevices(*phBTRCore, pstlhBTRCore->curAdapterPath);
2648 
2649  /* Discovery Type */
2650  pstlhBTRCore->aenDeviceDiscoveryType = enBTRCoreUnknown;
2651 
2652  return enBTRCoreSuccess;
2653 }
2654 
2655 
2656 enBTRCoreRet
2658  tBTRCoreHandle hBTRCore
2659 ) {
2660  gpointer penExitStatusRunTask = NULL;
2661  enBTRCoreRet lenExitStatusRunTask = enBTRCoreSuccess;
2662 
2663  gpointer penExitStatusOutTask = NULL;
2664  enBTRCoreRet lenExitStatusOutTask = enBTRCoreSuccess;
2665 
2666  enBTRCoreRet lenBTRCoreRet = enBTRCoreSuccess;
2667 
2668  stBTRCoreHdl* pstlhBTRCore = NULL;
2669  int i;
2670 
2671  if (!hBTRCore) {
2672  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
2673  return enBTRCoreNotInitialized;
2674  }
2675 
2676  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
2677 
2678  BTRCORELOG_INFO ("hBTRCore = %8p\n", hBTRCore);
2679 
2680 
2681  /* Stop BTRCore Task Threads */
2682  if (pstlhBTRCore->pThreadRunTask) {
2683 
2684  if (pstlhBTRCore->pGAQueueRunTask) {
2685  if (btrCore_RunTaskAddOp(pstlhBTRCore->pGAQueueRunTask, enBTRCoreTaskOpExit, enBTRCoreTaskPTUnknown, NULL) != enBTRCoreSuccess) {
2686  BTRCORELOG_ERROR("Failure btrCore_RunTaskAddOp enBTRCoreTaskOpExit enBTRCoreTaskPTUnknown\n");
2687  }
2688  }
2689 
2690  penExitStatusRunTask = g_thread_join(pstlhBTRCore->pThreadRunTask);
2691  pstlhBTRCore->pThreadRunTask = NULL;
2692  }
2693 
2694  if (penExitStatusRunTask) {
2695  BTRCORELOG_INFO ("BTRCore_DeInit - RunTask Exiting BTRCore - %d\n", *((enBTRCoreRet*)penExitStatusRunTask));
2696  lenExitStatusRunTask = *((enBTRCoreRet*)penExitStatusRunTask);
2697  g_free(penExitStatusRunTask);
2698  penExitStatusRunTask = NULL;
2699  }
2700 
2701  if (pstlhBTRCore->pGAQueueRunTask) {
2702  g_async_queue_unref(pstlhBTRCore->pGAQueueRunTask);
2703  pstlhBTRCore->pGAQueueRunTask = NULL;
2704  }
2705 
2706 
2707  if (pstlhBTRCore->pThreadOutTask) {
2708 
2709  if (pstlhBTRCore->pGAQueueOutTask) {
2710  if (btrCore_OutTaskAddOp(pstlhBTRCore->pGAQueueOutTask, enBTRCoreTaskOpExit, enBTRCoreTaskPTUnknown, NULL) != enBTRCoreSuccess) {
2711  BTRCORELOG_ERROR("Failure btrCore_OutTaskAddOp enBTRCoreTaskOpExit enBTRCoreTaskPTUnknown\n");
2712  }
2713  }
2714 
2715  penExitStatusOutTask = g_thread_join(pstlhBTRCore->pThreadOutTask);
2716  pstlhBTRCore->pThreadOutTask = NULL;
2717  }
2718 
2719  if (penExitStatusOutTask) {
2720  BTRCORELOG_INFO ("BTRCore_DeInit - OutTask Exiting BTRCore - %d\n", *((enBTRCoreRet*)penExitStatusOutTask));
2721  lenExitStatusOutTask = *((enBTRCoreRet*)penExitStatusOutTask);
2722  g_free(penExitStatusOutTask);
2723  penExitStatusOutTask = NULL;
2724  }
2725 
2726  if (pstlhBTRCore->pGAQueueOutTask) {
2727  g_async_queue_unref(pstlhBTRCore->pGAQueueOutTask);
2728  pstlhBTRCore->pGAQueueOutTask = NULL;
2729  }
2730 
2731 
2732  /* Free any memory allotted for use in BTRCore */
2733 
2734  /* DeInitialize BTRCore SubSystems - AVMedia/Telemetry..etc. */
2735  if (pstlhBTRCore->leHdl && (BTRCore_LE_DeInit(pstlhBTRCore->leHdl, pstlhBTRCore->connHdl, pstlhBTRCore->curAdapterPath) != enBTRCoreSuccess)) {
2736  BTRCORELOG_ERROR ("Failed to DeInit LE Subsystem\n");
2737  lenBTRCoreRet = enBTRCoreFailure;
2738  }
2739 
2740  if (pstlhBTRCore->avMediaHdl && (BTRCore_AVMedia_DeInit(pstlhBTRCore->avMediaHdl, pstlhBTRCore->connHdl, pstlhBTRCore->curAdapterPath) != enBTRCoreSuccess)) {
2741  BTRCORELOG_ERROR ("Failed to DeInit AV Media Subsystem\n");
2742  lenBTRCoreRet = enBTRCoreFailure;
2743  }
2744 
2745  if (pstlhBTRCore->curAdapterPath) {
2746  if (BtrCore_BTReleaseAdapterPath(pstlhBTRCore->connHdl, NULL)) {
2747  BTRCORELOG_ERROR ("Failure BtrCore_BTReleaseAdapterPath\n");
2748  lenBTRCoreRet = enBTRCoreFailure;
2749  }
2750  pstlhBTRCore->curAdapterPath = NULL;
2751  }
2752 
2753  /* Adapters */
2754  for (i = 0; i < BTRCORE_MAX_NUM_BT_ADAPTERS; i++) {
2755  if (pstlhBTRCore->adapterPath[i]) {
2756  g_free(pstlhBTRCore->adapterPath[i]);
2757  pstlhBTRCore->adapterPath[i] = NULL;
2758  }
2759 
2760  if (pstlhBTRCore->adapterAddr[i]) {
2761  g_free(pstlhBTRCore->adapterAddr[i]);
2762  pstlhBTRCore->adapterAddr[i] = NULL;
2763  }
2764  }
2765 
2766  if (pstlhBTRCore->curAdapterAddr) {
2767  g_free(pstlhBTRCore->curAdapterAddr);
2768  pstlhBTRCore->curAdapterAddr = NULL;
2769  }
2770 
2771  if (pstlhBTRCore->agentPath) {
2772  if (BtrCore_BTReleaseAgentPath(pstlhBTRCore->connHdl)) {
2773  BTRCORELOG_ERROR ("Failure BtrCore_BTReleaseAgentPath\n");
2774  lenBTRCoreRet = enBTRCoreFailure;
2775  }
2776  pstlhBTRCore->agentPath = NULL;
2777  }
2778 
2779  if (pstlhBTRCore->connHdl) {
2780  if (BtrCore_BTDeInitReleaseConnection(pstlhBTRCore->connHdl)) {
2781  BTRCORELOG_ERROR ("Failure BtrCore_BTDeInitReleaseConnection\n");
2782  lenBTRCoreRet = enBTRCoreFailure;
2783  }
2784  pstlhBTRCore->connHdl = NULL;
2785  }
2786 
2787  if (hBTRCore) {
2788  g_free(hBTRCore);
2789  hBTRCore = NULL;
2790  }
2791 
2792  lenBTRCoreRet = ((lenExitStatusRunTask == enBTRCoreSuccess) &&
2793  (lenExitStatusOutTask == enBTRCoreSuccess) &&
2794  (lenBTRCoreRet == enBTRCoreSuccess)) ? enBTRCoreSuccess : enBTRCoreFailure;
2795  BTRCORELOG_DEBUG ("Exit Status = %d\n", lenBTRCoreRet);
2796 
2797 
2798  return lenBTRCoreRet;
2799 }
2800 
2801 
2802 enBTRCoreRet
2804  tBTRCoreHandle hBTRCore,
2805  int iBTRCapMode
2806 ) {
2807  char capabilities[32] = {'\0'};
2808  stBTRCoreHdl* pstlhBTRCore = NULL;
2809 
2810  if (!hBTRCore) {
2811  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
2812  return enBTRCoreNotInitialized;
2813  }
2814 
2815  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
2816 
2817  if (iBTRCapMode == 1) {
2818  strcpy(capabilities,"DisplayYesNo");
2819  }
2820  else {
2821  strcpy(capabilities,"NoInputNoOutput"); //default is no input no output
2822  }
2823 
2824 
2825  if (BtrCore_BTRegisterAgent(pstlhBTRCore->connHdl, pstlhBTRCore->curAdapterPath, pstlhBTRCore->agentPath, capabilities) < 0) {
2826  BTRCORELOG_ERROR ("Agent registration ERROR occurred\n");
2827  return enBTRCoreFailure;
2828  }
2829 
2830  BTRCORELOG_TRACE ("Starting Agent in mode %s\n", capabilities);
2831  return enBTRCoreSuccess;
2832 }
2833 
2834 
2835 enBTRCoreRet
2837  tBTRCoreHandle hBTRCore
2838 ) {
2839  stBTRCoreHdl* pstlhBTRCore = NULL;
2840 
2841  if (!hBTRCore) {
2842  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
2843  return enBTRCoreNotInitialized;
2844  }
2845 
2846  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
2847 
2848  if (BtrCore_BTUnregisterAgent(pstlhBTRCore->connHdl, pstlhBTRCore->curAdapterPath, pstlhBTRCore->agentPath) < 0) {
2849  BTRCORELOG_ERROR ("Agent unregistration ERROR occurred\n");
2850  return enBTRCoreFailure;
2851  }
2852 
2853  BTRCORELOG_TRACE ("Stopping Agent\n");
2854  return enBTRCoreSuccess;
2855 }
2856 
2857 
2858 enBTRCoreRet
2860  tBTRCoreHandle hBTRCore,
2861  stBTRCoreListAdapters* pstListAdapters
2862 ) {
2863  stBTRCoreHdl* pstlhBTRCore = NULL;
2864  enBTRCoreRet rc = enBTRCoreFailure;
2865  unBTOpIfceProp lunBtOpAdapProp;
2866  int i;
2867 
2868  if (!hBTRCore) {
2869  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
2870  return enBTRCoreNotInitialized;
2871  }
2872  else if (!pstListAdapters) {
2873  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
2874  return enBTRCoreInvalidArg;
2875  }
2876 
2877  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
2878 
2879  if (!BtrCore_BTGetAdapterList(pstlhBTRCore->connHdl, &pstlhBTRCore->numOfAdapters, pstlhBTRCore->adapterPath)) {
2880  pstListAdapters->number_of_adapters = pstlhBTRCore->numOfAdapters;
2881  for (i = 0; i < pstListAdapters->number_of_adapters; i++) {
2882  memset(&pstListAdapters->adapter_path[i][0], '\0', BD_NAME_LEN + 1);
2883  strncpy(&pstListAdapters->adapter_path[i][0], pstlhBTRCore->adapterPath[i], BD_NAME_LEN);
2884 
2885  memset(&pstListAdapters->adapterAddr[i][0], '\0', BD_NAME_LEN + 1);
2886  lunBtOpAdapProp.enBtAdapterProp = enBTAdPropAddress;
2887  if (!BtrCore_BTGetProp(pstlhBTRCore->connHdl, pstlhBTRCore->adapterPath[i], enBTAdapter, lunBtOpAdapProp, pstlhBTRCore->adapterAddr[i])) {
2888  strncpy(&pstListAdapters->adapterAddr[i][0], pstlhBTRCore->adapterAddr[i], BD_NAME_LEN);
2889  }
2890  rc = enBTRCoreSuccess;
2891  }
2892  }
2893 
2894  return rc;
2895 }
2896 
2897 
2898 enBTRCoreRet
2900  tBTRCoreHandle hBTRCore,
2901  stBTRCoreGetAdapters* pstGetAdapters
2902 ) {
2903  stBTRCoreHdl* pstlhBTRCore = NULL;
2904 
2905  if (!hBTRCore) {
2906  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
2907  return enBTRCoreNotInitialized;
2908  }
2909  else if (!pstGetAdapters) {
2910  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
2911  return enBTRCoreInvalidArg;
2912  }
2913 
2914  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
2915 
2916  if (!BtrCore_BTGetAdapterList(pstlhBTRCore->connHdl, &pstlhBTRCore->numOfAdapters, pstlhBTRCore->adapterPath)) {
2917  pstGetAdapters->number_of_adapters = pstlhBTRCore->numOfAdapters;
2918  return enBTRCoreSuccess;
2919  }
2920 
2921  return enBTRCoreSuccess;
2922 }
2923 
2924 
2925 enBTRCoreRet
2927  tBTRCoreHandle hBTRCore,
2928  stBTRCoreAdapter* apstBTRCoreAdapter
2929 ) {
2930  stBTRCoreHdl* pstlhBTRCore = NULL;
2931 
2932  if (!hBTRCore) {
2933  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
2934  return enBTRCoreNotInitialized;
2935  }
2936 
2937  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
2938 
2939  if (!pstlhBTRCore->curAdapterPath) {
2940  if ((pstlhBTRCore->curAdapterPath = BtrCore_BTGetAdapterPath(pstlhBTRCore->connHdl, NULL)) == NULL) { //mikek hard code to default adapter for now
2941  BTRCORELOG_ERROR ("Failed to get BT Adapter");
2942  return enBTRCoreInvalidAdapter;
2943  }
2944  }
2945 
2946 
2947  if (apstBTRCoreAdapter) {
2948  apstBTRCoreAdapter->adapter_number = 0; //hard code to default adapter for now
2949  apstBTRCoreAdapter->pcAdapterPath = pstlhBTRCore->curAdapterPath;
2950  apstBTRCoreAdapter->pcAdapterDevName = NULL;
2951  }
2952 
2953  return enBTRCoreSuccess;
2954 }
2955 
2956 
2957 enBTRCoreRet
2959  tBTRCoreHandle hBTRCore,
2960  int adapter_number
2961 ) {
2962  stBTRCoreHdl* pstlhBTRCore = NULL;
2963  int pathlen;
2964 
2965  if (!hBTRCore) {
2966  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
2967  return enBTRCoreNotInitialized;
2968  }
2969 
2970  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
2971 
2972  pathlen = strlen(pstlhBTRCore->curAdapterPath);
2973  switch (adapter_number) {
2974  case 0:
2975  pstlhBTRCore->curAdapterPath[pathlen-1]='0';
2976  break;
2977  case 1:
2978  pstlhBTRCore->curAdapterPath[pathlen-1]='1';
2979  break;
2980  case 2:
2981  pstlhBTRCore->curAdapterPath[pathlen-1]='2';
2982  break;
2983  case 3:
2984  pstlhBTRCore->curAdapterPath[pathlen-1]='3';
2985  break;
2986  case 4:
2987  pstlhBTRCore->curAdapterPath[pathlen-1]='4';
2988  break;
2989  case 5:
2990  pstlhBTRCore->curAdapterPath[pathlen-1]='5';
2991  break;
2992  default:
2993  BTRCORELOG_INFO ("max adapter value is 5, setting default\n");//6 adapters seems like plenty for now
2994  pstlhBTRCore->curAdapterPath[pathlen-1]='0';
2995  break;
2996  }
2997 
2998  BTRCORELOG_INFO ("Now current adatper is %s\n", pstlhBTRCore->curAdapterPath);
2999 
3000  return enBTRCoreSuccess;
3001 }
3002 
3003 
3004 enBTRCoreRet
3006  tBTRCoreHandle hBTRCore,
3007  stBTRCoreAdapter* apstBTRCoreAdapter
3008 ) {
3009  stBTRCoreHdl* pstlhBTRCore = NULL;
3010  unBTOpIfceProp lunBtOpAdapProp;
3011  int powered = 1;
3012 
3013 
3014  if (!hBTRCore) {
3015  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3016  return enBTRCoreNotInitialized;
3017  }
3018 
3019  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3020 
3021 
3022  BTRCORELOG_ERROR ("BTRCore_EnableAdapter\n");
3023  apstBTRCoreAdapter->enable = TRUE; //does this even mean anything?
3024  lunBtOpAdapProp.enBtAdapterProp = enBTAdPropPowered;
3025 
3026  if (BtrCore_BTSetProp(pstlhBTRCore->connHdl, pstlhBTRCore->curAdapterPath, enBTAdapter, lunBtOpAdapProp, &powered)) {
3027  BTRCORELOG_ERROR ("Set Adapter Property enBTAdPropPowered - FAILED\n");
3028  return enBTRCoreFailure;
3029  }
3030 
3031  return enBTRCoreSuccess;
3032 }
3033 
3034 
3035 enBTRCoreRet
3037  tBTRCoreHandle hBTRCore,
3038  stBTRCoreAdapter* apstBTRCoreAdapter
3039 ) {
3040  stBTRCoreHdl* pstlhBTRCore = NULL;
3041  unBTOpIfceProp lunBtOpAdapProp;
3042  int powered = 0;
3043 
3044  if (!hBTRCore) {
3045  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3046  return enBTRCoreNotInitialized;
3047  }
3048 
3049  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3050 
3051  BTRCORELOG_ERROR ("BTRCore_DisableAdapter\n");
3052  apstBTRCoreAdapter->enable = FALSE;
3053  lunBtOpAdapProp.enBtAdapterProp = enBTAdPropPowered;
3054 
3055  if (BtrCore_BTSetProp(pstlhBTRCore->connHdl, pstlhBTRCore->curAdapterPath, enBTAdapter, lunBtOpAdapProp, &powered)) {
3056  BTRCORELOG_ERROR ("Set Adapter Property enBTAdPropPowered - FAILED\n");
3057  return enBTRCoreFailure;
3058  }
3059 
3060  return enBTRCoreSuccess;
3061 }
3062 
3063 
3064 enBTRCoreRet
3066  tBTRCoreHandle hBTRCore,
3067  unsigned char aui8adapterIdx,
3068  char* apui8adapterAddr
3069 ) {
3070  stBTRCoreHdl* pstlhBTRCore = NULL;
3071  enBTRCoreRet lenBTRCoreRet= enBTRCoreFailure;
3072  int i = 0;
3073 
3074  if (!hBTRCore) {
3075  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3076  return enBTRCoreNotInitialized;
3077  }
3078  else if (!apui8adapterAddr) {
3079  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
3080  return enBTRCoreInvalidArg;
3081  }
3082 
3083  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3084 
3085  for (i = 0; i < pstlhBTRCore->numOfAdapters; i++) {
3086  if (aui8adapterIdx == i) {
3087  strncpy(apui8adapterAddr, pstlhBTRCore->adapterAddr[i], (strlen(pstlhBTRCore->adapterAddr[i]) < BD_NAME_LEN) ? strlen(pstlhBTRCore->adapterAddr[i]) : BD_NAME_LEN - 1);
3088  lenBTRCoreRet = enBTRCoreSuccess;
3089  break;
3090  }
3091  }
3092 
3093  return lenBTRCoreRet;
3094 }
3095 
3096 
3097 enBTRCoreRet
3099  tBTRCoreHandle hBTRCore,
3100  const char* pAdapterPath,
3101  unsigned char discoverable
3102 ) {
3103  stBTRCoreHdl* pstlhBTRCore = NULL;
3104  unBTOpIfceProp lunBtOpAdapProp;
3105  int isDiscoverable = (int) discoverable;
3106 
3107  if (!hBTRCore) {
3108  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3109  return enBTRCoreNotInitialized;
3110  }
3111  else if (!pAdapterPath) {
3112  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
3113  return enBTRCoreInvalidArg;
3114  }
3115 
3116  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3117 
3118  lunBtOpAdapProp.enBtAdapterProp = enBTAdPropDiscoverable;
3119 
3120  if (BtrCore_BTSetProp(pstlhBTRCore->connHdl, pstlhBTRCore->curAdapterPath, enBTAdapter, lunBtOpAdapProp, &isDiscoverable)) {
3121  BTRCORELOG_ERROR ("Set Adapter Property enBTAdPropDiscoverable - FAILED\n");
3122  return enBTRCoreFailure;
3123  }
3124 
3125  return enBTRCoreSuccess;
3126 }
3127 
3128 
3129 enBTRCoreRet
3131  tBTRCoreHandle hBTRCore,
3132  const char* pAdapterPath,
3133  unsigned short timeout
3134 ) {
3135  stBTRCoreHdl* pstlhBTRCore = NULL;
3136  unBTOpIfceProp lunBtOpAdapProp;
3137  unsigned int givenTimeout = (unsigned int)timeout;
3138 
3139  if (!hBTRCore) {
3140  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3141  return enBTRCoreNotInitialized;
3142  }
3143  else if (!pAdapterPath) {
3144  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
3145  return enBTRCoreInvalidArg;
3146  }
3147 
3148  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3149 
3150 
3151  lunBtOpAdapProp.enBtAdapterProp = enBTAdPropDiscoverableTimeOut;
3152 
3153  if (BtrCore_BTSetProp(pstlhBTRCore->connHdl, pstlhBTRCore->curAdapterPath, enBTAdapter, lunBtOpAdapProp, &givenTimeout)) {
3154  BTRCORELOG_ERROR ("Set Adapter Property enBTAdPropDiscoverableTimeOut - FAILED\n");
3155  return enBTRCoreFailure;
3156  }
3157 
3158  return enBTRCoreSuccess;
3159 }
3160 
3161 
3162 enBTRCoreRet
3164  tBTRCoreHandle hBTRCore,
3165  const char* pAdapterPath,
3166  unsigned char* pDiscoverable
3167 ) {
3168  stBTRCoreHdl* pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3169  unBTOpIfceProp lunBtOpAdapProp;
3170  int discoverable = 0;
3171 
3172  if (!hBTRCore) {
3173  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3174  return enBTRCoreNotInitialized;
3175  }
3176  else if ((!pAdapterPath) || (!pDiscoverable)) {
3177  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
3178  return enBTRCoreInvalidArg;
3179  }
3180 
3181  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3182  lunBtOpAdapProp.enBtAdapterProp = enBTAdPropDiscoverable;
3183  if (!BtrCore_BTGetProp(pstlhBTRCore->connHdl, pAdapterPath, enBTAdapter, lunBtOpAdapProp, &discoverable)) {
3184  BTRCORELOG_INFO ("Get value for org.bluez.Adapter.Discoverable = %d\n", discoverable);
3185  *pDiscoverable = (unsigned char) discoverable;
3186  return enBTRCoreSuccess;
3187  }
3188 
3189  return enBTRCoreFailure;
3190 }
3191 
3192 
3193 enBTRCoreRet
3195  tBTRCoreHandle hBTRCore,
3196  stBTRCoreAdapter* apstBTRCoreAdapter,
3197  char* apcAdapterDeviceName
3198 ) {
3199  stBTRCoreHdl* pstlhBTRCore = NULL;
3200  unBTOpIfceProp lunBtOpAdapProp;
3201 
3202  if (!hBTRCore) {
3203  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3204  return enBTRCoreNotInitialized;
3205  }
3206  else if (!apcAdapterDeviceName) {
3207  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
3208  return enBTRCoreInvalidArg;
3209  }
3210 
3211  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3212 
3213  if(apstBTRCoreAdapter->pcAdapterDevName) {
3214  g_free(apstBTRCoreAdapter->pcAdapterDevName);
3215  apstBTRCoreAdapter->pcAdapterDevName = NULL;
3216  }
3217 
3218  apstBTRCoreAdapter->pcAdapterDevName = g_strndup(apcAdapterDeviceName, BTRCORE_MAX_STR_LEN - 1); //TODO: Free this memory
3219  lunBtOpAdapProp.enBtAdapterProp = enBTAdPropName;
3220 
3221  if (BtrCore_BTSetProp(pstlhBTRCore->connHdl, pstlhBTRCore->curAdapterPath, enBTAdapter, lunBtOpAdapProp, &(apstBTRCoreAdapter->pcAdapterDevName))) {
3222  BTRCORELOG_ERROR ("Set Adapter Property enBTAdPropName - FAILED\n");
3223  return enBTRCoreFailure;
3224  }
3225 
3226  return enBTRCoreSuccess;
3227 }
3228 
3229 
3230 enBTRCoreRet
3232  tBTRCoreHandle hBTRCore,
3233  const char* pAdapterPath,
3234  const char* pAdapterName
3235 ) {
3236  stBTRCoreHdl* pstlhBTRCore = NULL;
3237  unBTOpIfceProp lunBtOpAdapProp;
3238 
3239  if (!hBTRCore) {
3240  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3241  return enBTRCoreNotInitialized;
3242  }
3243  else if ((!pAdapterPath) ||(!pAdapterName)) {
3244  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
3245  return enBTRCoreInvalidArg;
3246  }
3247 
3248  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3249  lunBtOpAdapProp.enBtAdapterProp = enBTAdPropName;
3250 
3251  if (BtrCore_BTSetProp(pstlhBTRCore->connHdl, pstlhBTRCore->curAdapterPath, enBTAdapter, lunBtOpAdapProp, &pAdapterName)) {
3252  BTRCORELOG_ERROR ("Set Adapter Property enBTAdPropName - FAILED\n");
3253  return enBTRCoreFailure;
3254  }
3255 
3256  return enBTRCoreSuccess;
3257 }
3258 
3259 
3260 enBTRCoreRet
3262  tBTRCoreHandle hBTRCore,
3263  const char* pAdapterPath,
3264  char* pAdapterName
3265 ) {
3266  stBTRCoreHdl* pstlhBTRCore = NULL;
3267  unBTOpIfceProp lunBtOpAdapProp;
3268 
3269  char name[BD_NAME_LEN + 1] = {'\0'};
3270  memset (name, '\0', sizeof(char) * (BD_NAME_LEN + 1));
3271 
3272  if (!hBTRCore) {
3273  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3274  return enBTRCoreNotInitialized;
3275  }
3276  else if ((!pAdapterPath) || (!pAdapterName)) {
3277  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
3278  return enBTRCoreInvalidArg;
3279  }
3280 
3281  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3282  lunBtOpAdapProp.enBtAdapterProp = enBTAdPropName;
3283  if (!BtrCore_BTGetProp(pstlhBTRCore->connHdl, pAdapterPath, enBTAdapter, lunBtOpAdapProp, name)) {
3284  BTRCORELOG_INFO ("Get value for org.bluez.Adapter.Name = %s\n", name);
3285  strncpy(pAdapterName, name, strlen(name) < BD_NAME_LEN ? strlen(name) : BD_NAME_LEN -1);
3286  return enBTRCoreSuccess;
3287  }
3288 
3289  return enBTRCoreFailure;
3290 }
3291 
3292 
3293 enBTRCoreRet
3295  tBTRCoreHandle hBTRCore,
3296  const char* pAdapterPath,
3297  unsigned char powerStatus
3298 ) {
3299  stBTRCoreHdl* pstlhBTRCore = NULL;
3300  unBTOpIfceProp lunBtOpAdapProp;
3301  int power = powerStatus;
3302 
3303  if (!hBTRCore) {
3304  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3305  return enBTRCoreNotInitialized;
3306  }
3307  else if (!pAdapterPath) {
3308  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
3309  return enBTRCoreInvalidArg;
3310  }
3311 
3312  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3313  lunBtOpAdapProp.enBtAdapterProp = enBTAdPropPowered;
3314 
3315  if (BtrCore_BTSetProp(pstlhBTRCore->connHdl, pstlhBTRCore->curAdapterPath, enBTAdapter, lunBtOpAdapProp, &power)) {
3316  BTRCORELOG_ERROR ("Set Adapter Property enBTAdPropPowered - FAILED\n");
3317  return enBTRCoreFailure;
3318  }
3319 
3320  return enBTRCoreSuccess;
3321 }
3322 
3323 
3324 enBTRCoreRet
3326  tBTRCoreHandle hBTRCore,
3327  const char* pAdapterPath,
3328  unsigned char* pAdapterPower
3329 ) {
3330  stBTRCoreHdl* pstlhBTRCore = NULL;
3331  unBTOpIfceProp lunBtOpAdapProp;
3332  int powerStatus = 0;
3333 
3334  if (!hBTRCore) {
3335  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3336  return enBTRCoreNotInitialized;
3337  }
3338  else if ((!pAdapterPath) || (!pAdapterPower)) {
3339  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
3340  return enBTRCoreInvalidArg;
3341  }
3342 
3343  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3344  lunBtOpAdapProp.enBtAdapterProp = enBTAdPropPowered;
3345  if (!BtrCore_BTGetProp(pstlhBTRCore->connHdl, pAdapterPath, enBTAdapter, lunBtOpAdapProp, &powerStatus)) {
3346  BTRCORELOG_INFO ("Get value for org.bluez.Adapter.powered = %d\n", powerStatus);
3347  *pAdapterPower = (unsigned char) powerStatus;
3348  return enBTRCoreSuccess;
3349  }
3350 
3351  return enBTRCoreFailure;
3352 }
3353 
3354 
3355 enBTRCoreRet
3357  tBTRCoreHandle hBTRCore,
3358  char* apcBtVersion
3359 ) {
3360  stBTRCoreHdl* pstlhBTRCore = NULL;
3361  char lBtIfceName[BTRCORE_STR_LEN];
3362  char lBtVersion[BTRCORE_STR_LEN];
3363 
3364  if (!hBTRCore) {
3365  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3366  return enBTRCoreNotInitialized;
3367  }
3368  else if (!apcBtVersion) {
3369  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
3370  return enBTRCoreInvalidArg;
3371  }
3372 
3373  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3374 
3375  memset(lBtIfceName, '\0', BTRCORE_STR_LEN);
3376  memset(lBtVersion, '\0', BTRCORE_STR_LEN);
3377 
3378  if (!BtrCore_BTGetIfceNameVersion(pstlhBTRCore->connHdl, lBtIfceName, lBtVersion)) {
3379  strncpy(apcBtVersion, lBtIfceName, strlen(lBtIfceName));
3380  strncat(apcBtVersion, "-", sizeof(apcBtVersion) - strlen(apcBtVersion) -1);
3381  strncat(apcBtVersion, lBtVersion, strlen(lBtVersion));
3382  BTRCORELOG_INFO ("Ifce: %s Version: %s", lBtIfceName, lBtVersion);
3383  BTRCORELOG_INFO ("Out: %s\n", apcBtVersion);
3384  return enBTRCoreSuccess;
3385  }
3386 
3387  return enBTRCoreFailure;
3388 }
3389 
3390 
3391 enBTRCoreRet
3393  tBTRCoreHandle hBTRCore,
3394  const char* pAdapterPath,
3395  enBTRCoreDeviceType aenBTRCoreDevType,
3396  unsigned int aui32DiscDuration
3397 ) {
3398  stBTRCoreHdl* pstlhBTRCore = NULL;
3399 
3400  if (!hBTRCore) {
3401  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3402  return enBTRCoreNotInitialized;
3403  }
3404  else if (!pAdapterPath) {
3405  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
3406  return enBTRCoreInvalidArg;
3407  }
3408 
3409  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3410 
3411  btrCore_ClearScannedDevicesList(pstlhBTRCore);
3412 
3413  /* Discovery Type */
3414  pstlhBTRCore->aenDeviceDiscoveryType = aenBTRCoreDevType;
3415 
3416  if (aenBTRCoreDevType == enBTRCoreLE) {
3417  if (BtrCore_BTStartLEDiscovery(pstlhBTRCore->connHdl, pAdapterPath, pstlhBTRCore->agentPath)) {
3418  return enBTRCoreDiscoveryFailure;
3419  }
3420 
3421  if (aui32DiscDuration) {
3422  sleep(aui32DiscDuration); //TODO: Better to setup a timer which calls BTStopDiscovery
3423  if (BtrCore_BTStopLEDiscovery(pstlhBTRCore->connHdl, pAdapterPath, pstlhBTRCore->agentPath)) {
3424  return enBTRCoreDiscoveryFailure;
3425  }
3426  }
3427  }
3428  else if ((aenBTRCoreDevType == enBTRCoreSpeakers) || (aenBTRCoreDevType == enBTRCoreHeadSet) ||
3429  (aenBTRCoreDevType == enBTRCoreMobileAudioIn) || (aenBTRCoreDevType == enBTRCorePCAudioIn)) {
3430  if (BtrCore_BTStartClassicDiscovery(pstlhBTRCore->connHdl, pAdapterPath, pstlhBTRCore->agentPath)) {
3431  return enBTRCoreDiscoveryFailure;
3432  }
3433 
3434  if (aui32DiscDuration) {
3435  sleep(aui32DiscDuration); //TODO: Better to setup a timer which calls BTStopDiscovery
3436  if (BtrCore_BTStopClassicDiscovery(pstlhBTRCore->connHdl, pAdapterPath, pstlhBTRCore->agentPath)) {
3437  return enBTRCoreDiscoveryFailure;
3438  }
3439  }
3440  }
3441  else {
3442  if (BtrCore_BTStartDiscovery(pstlhBTRCore->connHdl, pAdapterPath, pstlhBTRCore->agentPath)) {
3443  return enBTRCoreDiscoveryFailure;
3444  }
3445 
3446  if (aui32DiscDuration) {
3447  sleep(aui32DiscDuration); //TODO: Better to setup a timer which calls BTStopDiscovery
3448  if (BtrCore_BTStopDiscovery(pstlhBTRCore->connHdl, pAdapterPath, pstlhBTRCore->agentPath)) {
3449  return enBTRCoreDiscoveryFailure;
3450  }
3451  }
3452  }
3453 
3454  return enBTRCoreSuccess;
3455 }
3456 
3457 
3458 enBTRCoreRet
3460  tBTRCoreHandle hBTRCore,
3461  const char* pAdapterPath,
3462  enBTRCoreDeviceType aenBTRCoreDevType
3463 ) {
3464  stBTRCoreHdl* pstlhBTRCore = NULL;
3465 
3466  if (!hBTRCore) {
3467  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3468  return enBTRCoreNotInitialized;
3469  }
3470  else if (!pAdapterPath) {
3471  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
3472  return enBTRCoreInvalidArg;
3473  }
3474 
3475  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3476 
3477 
3478  if (aenBTRCoreDevType == enBTRCoreLE) {
3479  if (BtrCore_BTStopLEDiscovery(pstlhBTRCore->connHdl, pAdapterPath, pstlhBTRCore->agentPath)) {
3480  return enBTRCoreDiscoveryFailure;
3481  }
3482  }
3483  else if ((aenBTRCoreDevType == enBTRCoreSpeakers) || (aenBTRCoreDevType == enBTRCoreHeadSet) ||
3484  (aenBTRCoreDevType == enBTRCoreMobileAudioIn) || (aenBTRCoreDevType == enBTRCorePCAudioIn)) {
3485  if (BtrCore_BTStopClassicDiscovery(pstlhBTRCore->connHdl, pAdapterPath, pstlhBTRCore->agentPath)) {
3486  return enBTRCoreDiscoveryFailure;
3487  }
3488  }
3489  else {
3490  if (BtrCore_BTStopDiscovery(pstlhBTRCore->connHdl, pAdapterPath, pstlhBTRCore->agentPath)) {
3491  return enBTRCoreDiscoveryFailure;
3492  }
3493  }
3494 
3495  return enBTRCoreSuccess;
3496 }
3497 
3498 
3499 enBTRCoreRet
3501  tBTRCoreHandle hBTRCore,
3502  stBTRCoreScannedDevicesCount* pListOfScannedDevices
3503 ) {
3504  stBTRCoreHdl* pstlhBTRCore = NULL;
3505  int i;
3506 
3507  if (!hBTRCore) {
3508  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3509  return enBTRCoreNotInitialized;
3510  }
3511  else if (!pListOfScannedDevices) {
3512  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
3513  return enBTRCoreInvalidArg;
3514  }
3515 
3516  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3517  memset (pListOfScannedDevices, 0, sizeof(stBTRCoreScannedDevicesCount));
3518 
3519  BTRCORELOG_TRACE ("adapter path is %s\n", pstlhBTRCore->curAdapterPath);
3520  for (i = 0; i < BTRCORE_MAX_NUM_BT_DEVICES; i++) {
3521  if (pstlhBTRCore->stScannedDevicesArr[i].bFound) {
3522  BTRCORELOG_TRACE ("Device : %d\n", i);
3523  BTRCORELOG_TRACE ("Name : %s\n", pstlhBTRCore->stScannedDevicesArr[i].pcDeviceName);
3524  BTRCORELOG_TRACE ("Mac Ad : %s\n", pstlhBTRCore->stScannedDevicesArr[i].pcDeviceAddress);
3525  BTRCORELOG_TRACE ("Rssi : %d dbmV\n", pstlhBTRCore->stScannedDevicesArr[i].i32RSSI);
3526  btrCore_ShowSignalStrength(pstlhBTRCore->stScannedDevicesArr[i].i32RSSI);
3527 
3528  memcpy (&pListOfScannedDevices->devices[pListOfScannedDevices->numberOfDevices++], &pstlhBTRCore->stScannedDevicesArr[i], sizeof (stBTRCoreBTDevice));
3529  }
3530  }
3531 
3532  BTRCORELOG_TRACE ("Copied scanned details of %d devices\n", pListOfScannedDevices->numberOfDevices);
3533 
3534  return enBTRCoreSuccess;
3535 }
3536 
3537 
3538 enBTRCoreRet
3540  tBTRCoreHandle hBTRCore,
3541  tBTRCoreDevId aBTRCoreDevId
3542 ) {
3543  stBTRCoreHdl* pstlhBTRCore = NULL;
3544  const char* pDeviceAddress = NULL;
3545  stBTRCoreBTDevice* pstScannedDev = NULL;
3546  int i32LoopIdx = 0;
3547  enBTAdapterOp pairingOp = enBTAdpOpCreatePairedDev;
3548  unBTOpIfceProp lunBtOpAdapProp;
3549  int ispairable = 1;
3550  char lpcBtVersion[BTRCORE_STR_LEN] = {'\0'};
3551 
3552  if (!hBTRCore) {
3553  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3554  return enBTRCoreNotInitialized;
3555  }
3556  else if (aBTRCoreDevId < 0) {
3557  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
3558  return enBTRCoreInvalidArg;
3559  }
3560 
3561  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3562 
3563  if (aBTRCoreDevId < BTRCORE_MAX_NUM_BT_DEVICES) {
3564  pstScannedDev = &pstlhBTRCore->stScannedDevicesArr[aBTRCoreDevId];
3565  }
3566  else {
3567  for (i32LoopIdx = 0; i32LoopIdx < pstlhBTRCore->numOfScannedDevices; i32LoopIdx++) {
3568  if (aBTRCoreDevId == pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].tDeviceId) {
3569  pstScannedDev = &pstlhBTRCore->stScannedDevicesArr[i32LoopIdx];
3570  break;
3571  }
3572  }
3573  }
3574 
3575 
3576  if (pstScannedDev)
3577  pDeviceAddress = pstScannedDev->pcDeviceAddress;
3578 
3579 
3580  if (!pstScannedDev || !pDeviceAddress || !strlen(pDeviceAddress)) {
3581  BTRCORELOG_ERROR ("Failed to find device in Scanned devices list\n");
3582  return enBTRCoreDeviceNotFound;
3583  }
3584 
3585  BTRCORELOG_DEBUG ("We will pair %s\n", pstScannedDev->pcDeviceName);
3586  BTRCORELOG_DEBUG ("We will address %s\n", pDeviceAddress);
3587 
3588  if ((pstScannedDev->enDeviceType == enBTRCore_DC_HID_Keyboard) ||
3589  (pstScannedDev->enDeviceType == enBTRCore_DC_HID_Mouse) ||
3590  (pstScannedDev->enDeviceType == enBTRCore_DC_HID_MouseKeyBoard) ||
3591  //(pstScannedDev->enDeviceType == enBTRCore_DC_HID_AudioRemote) ||
3592  (pstScannedDev->enDeviceType == enBTRCore_DC_HID_Joystick) ||
3593  (pstScannedDev->enDeviceType == enBTRCore_DC_HID_GamePad)) {
3594 
3595  if ((pstScannedDev->enDeviceType == enBTRCore_DC_HID_GamePad) &&
3596  (enBTRCoreSuccess == BTRCore_GetVersionInfo(hBTRCore, lpcBtVersion))
3597  && (!strncmp(lpcBtVersion, "Bluez-5.48", strlen("Bluez-5.48")))) {
3598  BTRCORELOG_DEBUG (" sky devices Bluez-5.48 \n");
3599  lunBtOpAdapProp.enBtAdapterProp = enBTAdPropPairable;
3600 
3601  if (BtrCore_BTSetProp(pstlhBTRCore->connHdl, pstlhBTRCore->curAdapterPath, enBTAdapter, lunBtOpAdapProp, &ispairable)) {
3602  BTRCORELOG_ERROR ("Set Adapter Property enBTAdPropPairable - FAILED\n");
3603  return enBTRCoreFailure;
3604  }
3605  } else {
3606  BTRCORELOG_DEBUG (" Non sky devices or non HID Gamepad\n");
3607  }
3608  BTRCORELOG_DEBUG ("We will do a Async Pairing for the HID Devices\n");
3609  pairingOp = enBTAdpOpCreatePairedDevASync;
3610  }
3611 
3612  if (BtrCore_BTPerformAdapterOp( pstlhBTRCore->connHdl,
3613  pstlhBTRCore->curAdapterPath,
3614  pstlhBTRCore->agentPath,
3615  pDeviceAddress,
3616  pairingOp) < 0) {
3617  BTRCORELOG_ERROR ("Failed to pair a device\n");
3618  return enBTRCorePairingFailed;
3619  }
3620 
3621  //Calling this api will update the KnownDevList appropriately
3622  btrCore_PopulateListOfPairedDevices(pstlhBTRCore, pstlhBTRCore->curAdapterPath);
3623 
3624  BTRCORELOG_INFO ("Pairing Success\n");
3625  return enBTRCoreSuccess;
3626 }
3627 
3628 
3629 enBTRCoreRet
3631  tBTRCoreHandle hBTRCore,
3632  tBTRCoreDevId aBTRCoreDevId
3633 ) {
3634  stBTRCoreHdl* pstlhBTRCore = NULL;
3635 
3636  const char* pDeviceAddress = NULL;
3637  stBTRCoreBTDevice* pstKnownDevice = NULL;
3638  stBTRCoreDevStateInfo* lpstKnownDevStInfo = NULL;
3639  enBTDeviceType lenBTDeviceType = enBTDevUnknown;
3640  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
3641 
3642  enBTRCoreDeviceType aenBTRCoreDevType = enBTRCoreUnknown;
3643  stBTRCoreBTDevice pstScannedDevice;
3644 
3645  /* We can enhance the BTRCore with passcode support later point in time */
3646  if (!hBTRCore) {
3647  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3648  return enBTRCoreNotInitialized;
3649  }
3650  else if (aBTRCoreDevId < 0) {
3651  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
3652  return enBTRCoreInvalidArg;
3653  }
3654 
3655  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3656 
3657  if ((lenBTRCoreRet = btrCore_GetDeviceInfoKnown(pstlhBTRCore, aBTRCoreDevId, aenBTRCoreDevType,
3658  &lenBTDeviceType, &pstKnownDevice, &lpstKnownDevStInfo, &pDeviceAddress)) != enBTRCoreSuccess) {
3659  BTRCORELOG_ERROR ("Failed to Get Device Information\n");
3660  return lenBTRCoreRet;
3661  }
3662 
3663 
3664  if (BtrCore_BTPerformAdapterOp( pstlhBTRCore->connHdl,
3665  pstlhBTRCore->curAdapterPath,
3666  pstlhBTRCore->agentPath,
3667  pDeviceAddress,
3668  enBTAdpOpRemovePairedDev) != 0) {
3669  BTRCORELOG_ERROR ("Failed to unpair a device\n");
3670  return enBTRCorePairingFailed;
3671  }
3672 
3673 
3674  btrCore_RemoveDeviceFromKnownDevicesArr(pstlhBTRCore, aBTRCoreDevId);
3675 
3676  //Calling this api will update the KnownDevList appropriately
3677  btrCore_PopulateListOfPairedDevices(pstlhBTRCore, pstlhBTRCore->curAdapterPath);
3678 
3679  memset (&pstScannedDevice, 0 ,sizeof(stBTRCoreBTDevice));
3680  //Clear corresponding device entry from Scanned List if any
3681  if (btrCore_GetScannedDeviceAddress(pstlhBTRCore, aBTRCoreDevId)) {
3682  lenBTRCoreRet = btrCore_RemoveDeviceFromScannedDevicesArr (pstlhBTRCore, aBTRCoreDevId, &pstScannedDevice);
3683 
3684  if (!(enBTRCoreSuccess == lenBTRCoreRet && pstScannedDevice.tDeviceId)) {
3685  BTRCORELOG_ERROR ("Remove device %lld from Scanned List Failed!\n", aBTRCoreDevId);
3686  }
3687  }
3688 
3689  BTRCORELOG_INFO ("UnPairing Success\n");
3690  return enBTRCoreSuccess;
3691 }
3692 
3693 
3694 enBTRCoreRet
3696  tBTRCoreHandle hBTRCore,
3697  stBTRCorePairedDevicesCount* pListOfDevices
3698 ) {
3699  stBTRCoreHdl* pstlhBTRCore = NULL;
3700  int i32DevIdx = 0;
3701 
3702  if (!hBTRCore) {
3703  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3704  return enBTRCoreNotInitialized;
3705  }
3706  else if (!pListOfDevices) {
3707  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
3708  return enBTRCoreInvalidArg;
3709  }
3710 
3711  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3712 
3713  if (btrCore_PopulateListOfPairedDevices(pstlhBTRCore, pstlhBTRCore->curAdapterPath) == enBTRCoreSuccess) {
3714  pListOfDevices->numberOfDevices = pstlhBTRCore->numOfPairedDevices;
3715  for (i32DevIdx = 0; i32DevIdx < pListOfDevices->numberOfDevices; i32DevIdx++) {
3716  memcpy (&pListOfDevices->devices[i32DevIdx], &pstlhBTRCore->stKnownDevicesArr[i32DevIdx], sizeof(stBTRCoreBTDevice));
3717  }
3718 
3719  return enBTRCoreSuccess;
3720  }
3721 
3722  return enBTRCoreFailure;
3723 }
3724 
3725 
3726 enBTRCoreRet
3728  tBTRCoreHandle hBTRCore,
3729  tBTRCoreDevId aBTRCoreDevId
3730 ) {
3731  stBTRCoreHdl* pstlhBTRCore = NULL;
3732  stBTRCoreBTDevice* pstScannedDevice = NULL;
3733 
3734  if (!hBTRCore) {
3735  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3736  return enBTRCoreNotInitialized;
3737  }
3738 
3739  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3740  pstScannedDevice = &pstlhBTRCore->stScannedDevicesArr[aBTRCoreDevId];
3741 
3742  BTRCORELOG_DEBUG (" We will try to find %s\n"
3743  " address %s\n",
3744  pstlhBTRCore->stScannedDevicesArr[aBTRCoreDevId].pcDeviceName,
3745  pstlhBTRCore->stScannedDevicesArr[aBTRCoreDevId].pcDeviceAddress);
3746 
3747  if (BtrCore_BTPerformAdapterOp( pstlhBTRCore->connHdl,
3748  pstlhBTRCore->curAdapterPath,
3749  pstlhBTRCore->agentPath,
3750  pstScannedDevice->pcDeviceAddress,
3751  enBTAdpOpFindPairedDev) < 0) {
3752  // BTRCORELOG_ERROR ("device not found\n");
3753  return enBTRCoreFailure;
3754  }
3755 
3756  return enBTRCoreSuccess;
3757 }
3758 
3759 
3760 /*BTRCore_FindService, other inputs will include string and boolean pointer for returning*/
3761 enBTRCoreRet
3763  tBTRCoreHandle hBTRCore,
3764  tBTRCoreDevId aBTRCoreDevId,
3765  const char* UUID,
3766  char* XMLdata,
3767  int* found
3768 ) {
3769  stBTRCoreHdl* pstlhBTRCore = NULL;
3770 
3771  const char* pDeviceAddress = NULL;
3772  stBTRCoreBTDevice* pstKnownDevice = NULL;
3773  stBTRCoreDevStateInfo* lpstKnownDevStInfo = NULL;
3774  enBTDeviceType lenBTDeviceType = enBTDevUnknown;
3775  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
3776 
3777  enBTRCoreDeviceType aenBTRCoreDevType = enBTRCoreUnknown;
3778 
3779  if (!hBTRCore) {
3780  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3781  return enBTRCoreNotInitialized;
3782  }
3783 
3784  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3785 
3786 
3787  if ((lenBTRCoreRet = btrCore_GetDeviceInfoKnown(pstlhBTRCore, aBTRCoreDevId, aenBTRCoreDevType,
3788  &lenBTDeviceType, &pstKnownDevice, &lpstKnownDevStInfo, &pDeviceAddress)) != enBTRCoreSuccess) {
3789  BTRCORELOG_ERROR ("Failed to Get Device Information\n");
3790  return lenBTRCoreRet;
3791  }
3792 
3793  BTRCORELOG_INFO ("Checking for service %s on %s\n", UUID, pDeviceAddress);
3794  *found = BtrCore_BTFindServiceSupported (pstlhBTRCore->connHdl, pDeviceAddress, UUID, XMLdata);
3795  if (*found < 0) {
3796  return enBTRCoreFailure;
3797  }
3798 
3799  return enBTRCoreSuccess;
3800 }
3801 
3802 
3803 enBTRCoreRet
3805  tBTRCoreHandle hBTRCore,
3806  tBTRCoreDevId aBTRCoreDevId,
3807  stBTRCoreSupportedServiceList* pProfileList
3808 ) {
3809  stBTRCoreHdl* pstlhBTRCore = NULL;
3810 
3811  const char* lpcBTRCoreBTDevicePath = NULL;
3812  stBTRCoreBTDevice* lpstBTRCoreBTDevice = NULL;
3813  stBTRCoreDevStateInfo* lpstBTRCoreDevStateInfo = NULL;
3814  enBTDeviceType lenBTDeviceType = enBTDevUnknown;
3815  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
3816 
3817  enBTRCoreDeviceType aenBTRCoreDevType = enBTRCoreUnknown;
3818  unsigned int ui32LoopIdx = 0;
3819 
3820  stBTDeviceSupportedServiceList profileList;
3821 
3822 
3823  if (!hBTRCore) {
3824  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3825  return enBTRCoreNotInitialized;
3826  }
3827  else if ((!pProfileList) || (!aBTRCoreDevId)) {
3828  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
3829  return enBTRCoreInvalidArg;
3830  }
3831 
3832  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3833 
3834 
3835  if ((lenBTRCoreRet = btrCore_GetDeviceInfoKnown(pstlhBTRCore, aBTRCoreDevId, aenBTRCoreDevType,
3836  &lenBTDeviceType, &lpstBTRCoreBTDevice, &lpstBTRCoreDevStateInfo, &lpcBTRCoreBTDevicePath)) != enBTRCoreSuccess) {
3837  BTRCORELOG_ERROR ("Failed to Get Device Information\n");
3838  return lenBTRCoreRet;
3839  }
3840 
3841 
3842  /* Initialize the array */
3843  memset (pProfileList, 0 , sizeof(stBTRCoreSupportedServiceList));
3844  memset (&profileList, 0 , sizeof(stBTDeviceSupportedServiceList));
3845 
3846 
3847  if (BtrCore_BTDiscoverDeviceServices(pstlhBTRCore->connHdl, lpcBTRCoreBTDevicePath, &profileList) != 0) {
3848  return enBTRCoreFailure;
3849  }
3850 
3851  BTRCORELOG_INFO ("Successfully received the supported services... \n");
3852 
3853  pProfileList->numberOfService = profileList.numberOfService;
3854  for (ui32LoopIdx = 0; ui32LoopIdx < profileList.numberOfService; ui32LoopIdx++) {
3855  pProfileList->profile[ui32LoopIdx].uuid_value = profileList.profile[ui32LoopIdx].uuid_value;
3856  strncpy (pProfileList->profile[ui32LoopIdx].profile_name, profileList.profile[ui32LoopIdx].profile_name, 30);
3857  }
3858 
3859  return enBTRCoreSuccess;
3860 }
3861 
3862 
3863 enBTRCoreRet
3865  tBTRCoreHandle hBTRCore,
3866  tBTRCoreDevId aBTRCoreDevId
3867 ) {
3868  stBTRCoreHdl* pstlhBTRCore = NULL;
3869  const char* pDeviceMac = NULL;
3870  stBTRCoreBTDevice* pstKnownDevice = NULL;
3871 
3872 
3873  if (!hBTRCore) {
3874  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3875  return enBTRCoreNotInitialized;
3876  }
3877  else if (aBTRCoreDevId < 0) {
3878  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
3879  return enBTRCoreInvalidArg;
3880  }
3881 
3882  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3883 
3884  if (!pstlhBTRCore->numOfPairedDevices) {
3885  BTRCORELOG_DEBUG ("Possibly the list is not populated; like booted and connecting\n");
3886  /* Keep the list upto date */
3887  btrCore_PopulateListOfPairedDevices(pstlhBTRCore, pstlhBTRCore->curAdapterPath);
3888  }
3889 
3890  if (!pstlhBTRCore->numOfPairedDevices) {
3891  BTRCORELOG_ERROR ("There is no device paried for this adapter\n");
3892  return enBTRCoreFailure;
3893  }
3894 
3895  if (aBTRCoreDevId < BTRCORE_MAX_NUM_BT_DEVICES) {
3896  pstKnownDevice = &pstlhBTRCore->stKnownDevicesArr[aBTRCoreDevId];
3897  pDeviceMac = pstKnownDevice->pcDeviceAddress;
3898  }
3899  else {
3900  pDeviceMac = btrCore_GetKnownDeviceMac(pstlhBTRCore, aBTRCoreDevId);
3901  }
3902 
3903 
3904  if (!pDeviceMac || !strlen(pDeviceMac)) {
3905  BTRCORELOG_ERROR ("Failed to find device in paired devices list\n");
3906  return enBTRCoreDeviceNotFound;
3907  }
3908 
3909 
3910  if (BtrCore_BTIsDeviceConnectable(pstlhBTRCore->connHdl, pDeviceMac) != 0) {
3911  BTRCORELOG_ERROR ("Device NOT CONNECTABLE\n");
3912  return enBTRCoreFailure;
3913  }
3914 
3915  BTRCORELOG_INFO ("Device CONNECTABLE\n");
3916  return enBTRCoreSuccess;
3917 }
3918 
3919 
3920 enBTRCoreRet
3922  tBTRCoreHandle hBTRCore,
3923  tBTRCoreDevId aBTRCoreDevId,
3924  enBTRCoreDeviceType aenBTRCoreDevType
3925 ) {
3926  stBTRCoreHdl* pstlhBTRCore = NULL;
3927  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
3928  enBTDeviceType lenBTDeviceType = enBTDevUnknown;
3929  stBTRCoreBTDevice* lpstBTRCoreBTDevice = NULL;
3930  stBTRCoreDevStateInfo* lpstBTRCoreDevStateInfo = NULL;
3931  const char* lpcBTRCoreBTDevicePath = NULL;
3932  const char* lpcBTRCoreBTDeviceName = NULL;
3933 
3934 
3935  if (!hBTRCore) {
3936  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
3937  return enBTRCoreNotInitialized;
3938  }
3939  else if (aBTRCoreDevId < 0) {
3940  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
3941  return enBTRCoreInvalidArg;
3942  }
3943 
3944  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
3945 
3946  if ((lenBTRCoreRet = btrCore_GetDeviceInfo(pstlhBTRCore, aBTRCoreDevId, aenBTRCoreDevType,
3947  &lenBTDeviceType, &lpstBTRCoreBTDevice, &lpstBTRCoreDevStateInfo,
3948  &lpcBTRCoreBTDevicePath, &lpcBTRCoreBTDeviceName)) != enBTRCoreSuccess) {
3949  BTRCORELOG_ERROR ("Failed to Get Device Information - %llu\n", aBTRCoreDevId);
3950  return lenBTRCoreRet;
3951  }
3952 
3953 
3954  if ((lenBTDeviceType == enBTDevHID) &&
3955  strstr(lpcBTRCoreBTDeviceName, "Xbox")) {
3956  if (BtrCore_BTDisableEnhancedRetransmissionMode(pstlhBTRCore->connHdl) != 0) {
3957  BTRCORELOG_ERROR ("Failed to Disable ERTM\n");
3958  }
3959  }
3960 
3961 
3962  // TODO: Implement a Device State Machine and Check whether the device is in a Connectable State
3963  // before making the connect call
3964  if (BtrCore_BTConnectDevice(pstlhBTRCore->connHdl, lpcBTRCoreBTDevicePath, lenBTDeviceType) != 0) {
3965  BTRCORELOG_ERROR ("Connect to device failed - %llu\n", aBTRCoreDevId);
3966  return enBTRCoreFailure;
3967  }
3968 
3969  BTRCORELOG_INFO ("Connected to device %s Successfully. = %llu\n", lpcBTRCoreBTDeviceName, aBTRCoreDevId);
3970  /* Should think on moving a connected LE device from scanned list to paired list */
3971 
3972 
3973  lpstBTRCoreBTDevice->bDeviceConnected = TRUE;
3974  if ((lpstBTRCoreDevStateInfo->eDevicePrevState != enBTRCoreDevStConnected) &&
3975  (lpstBTRCoreDevStateInfo->eDeviceCurrState != enBTRCoreDevStPlaying)) {
3976  lpstBTRCoreDevStateInfo->eDevicePrevState = lpstBTRCoreDevStateInfo->eDeviceCurrState;
3977  }
3978 
3979  if ((lpstBTRCoreDevStateInfo->eDeviceCurrState != enBTRCoreDevStConnected) &&
3980  (lpstBTRCoreDevStateInfo->eDeviceCurrState != enBTRCoreDevStPlaying) ) {
3981  lpstBTRCoreDevStateInfo->eDeviceCurrState = enBTRCoreDevStConnecting;
3982 
3983  lenBTRCoreRet = enBTRCoreSuccess;
3984  }
3985 
3986 
3987  BTRCORELOG_DEBUG ("Ret - %d - %llu\n", lenBTRCoreRet, aBTRCoreDevId);
3988  return enBTRCoreSuccess;
3989 }
3990 
3991 
3992 enBTRCoreRet
3994  tBTRCoreHandle hBTRCore,
3995  tBTRCoreDevId aBTRCoreDevId,
3996  enBTRCoreDeviceType aenBTRCoreDevType
3997 ) {
3998  stBTRCoreHdl* pstlhBTRCore = NULL;
3999  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
4000  enBTDeviceType lenBTDeviceType = enBTDevUnknown;
4001  stBTRCoreBTDevice* lpstBTRCoreBTDevice = NULL;
4002  stBTRCoreDevStateInfo* lpstBTRCoreDevStateInfo = NULL;
4003  const char* lpcBTRCoreBTDevicePath = NULL;
4004  const char* lpcBTRCoreBTDeviceName = NULL;
4005 
4006 
4007  if (!hBTRCore) {
4008  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
4009  return enBTRCoreNotInitialized;
4010  }
4011  else if (aBTRCoreDevId < 0) {
4012  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
4013  return enBTRCoreInvalidArg;
4014  }
4015 
4016  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
4017 
4018  if ((lenBTRCoreRet = btrCore_GetDeviceInfo(pstlhBTRCore, aBTRCoreDevId, aenBTRCoreDevType,
4019  &lenBTDeviceType, &lpstBTRCoreBTDevice, &lpstBTRCoreDevStateInfo,
4020  &lpcBTRCoreBTDevicePath, &lpcBTRCoreBTDeviceName)) != enBTRCoreSuccess) {
4021  BTRCORELOG_ERROR ("Failed to Get Device Information - %llu\n", aBTRCoreDevId);
4022  return lenBTRCoreRet;
4023  }
4024 
4025 
4026  // TODO: Implement a Device State Machine and Check whether the device is in a Disconnectable State
4027  // before making the connect call
4028  if (BtrCore_BTDisconnectDevice(pstlhBTRCore->connHdl, lpcBTRCoreBTDevicePath, lenBTDeviceType) != 0) {
4029  BTRCORELOG_ERROR ("DisConnect from device failed - %llu\n", aBTRCoreDevId);
4030  return enBTRCoreFailure;
4031  }
4032 
4033  BTRCORELOG_INFO ("DisConnected from device %s Successfully.\n", lpcBTRCoreBTDeviceName);
4034 
4035 
4036  lpstBTRCoreBTDevice->bDeviceConnected = FALSE;
4037 
4038  if (lpstBTRCoreDevStateInfo->eDeviceCurrState != enBTRCoreDevStDisconnected &&
4039  lpstBTRCoreDevStateInfo->eDeviceCurrState != enBTRCoreDevStLost) {
4040  lpstBTRCoreDevStateInfo->eDevicePrevState = lpstBTRCoreDevStateInfo->eDeviceCurrState;
4041  lpstBTRCoreDevStateInfo->eDeviceCurrState = enBTRCoreDevStDisconnecting;
4042 
4043  lenBTRCoreRet = enBTRCoreSuccess;
4044  }
4045 
4046 
4047  if ((lenBTDeviceType == enBTDevHID) &&
4048  strstr(lpcBTRCoreBTDeviceName, "Xbox")) {
4049  if (BtrCore_BTEnableEnhancedRetransmissionMode(pstlhBTRCore->connHdl) != 0) {
4050  BTRCORELOG_ERROR ("Failed to Enable ERTM\n");
4051  }
4052  }
4053 
4054 
4055  BTRCORELOG_DEBUG ("Ret - %d - %llu\n", lenBTRCoreRet, aBTRCoreDevId);
4056  return enBTRCoreSuccess;
4057 }
4058 
4059 
4060 enBTRCoreRet
4062  tBTRCoreHandle hBTRCore,
4063  tBTRCoreDevId aBTRCoreDevId,
4064  enBTRCoreDeviceType aenBTRCoreDevType
4065 ) {
4066  stBTRCoreHdl* pstlhBTRCore = NULL;
4067  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
4068  enBTDeviceType lenBTDeviceType = enBTDevUnknown;
4069  stBTRCoreBTDevice* lpstBTRCoreBTDevice = NULL;
4070  stBTRCoreDevStateInfo* lpstBTRCoreDevStateInfo = NULL;
4071  const char* lpcBTRCoreBTDevicePath = NULL;
4072  const char* lpcBTRCoreBTDeviceName = NULL;
4073 
4074 
4075  if (!hBTRCore) {
4076  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
4077  return enBTRCoreNotInitialized;
4078  }
4079  else if (aBTRCoreDevId < 0) {
4080  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
4081  return enBTRCoreInvalidArg;
4082  }
4083 
4084  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
4085 
4086  if ((lenBTRCoreRet = btrCore_GetDeviceInfo(pstlhBTRCore, aBTRCoreDevId, aenBTRCoreDevType,
4087  &lenBTDeviceType, &lpstBTRCoreBTDevice, &lpstBTRCoreDevStateInfo,
4088  &lpcBTRCoreBTDevicePath, &lpcBTRCoreBTDeviceName)) != enBTRCoreSuccess) {
4089  BTRCORELOG_ERROR ("Failed to Get Device Information\n");
4090  return lenBTRCoreRet;
4091  }
4092 
4093 
4094  (void)lenBTDeviceType;
4095 
4096  if ((lpstBTRCoreDevStateInfo->eDeviceCurrState == enBTRCoreDevStConnected) ||
4097  (lpstBTRCoreDevStateInfo->eDeviceCurrState == enBTRCoreDevStPlaying)) {
4098  BTRCORELOG_DEBUG ("enBTRCoreDevStConnected = %s\n", lpcBTRCoreBTDeviceName);
4099  lenBTRCoreRet = enBTRCoreSuccess;
4100  }
4101  else {
4102  lenBTRCoreRet = enBTRCoreFailure;
4103  }
4104 
4105  BTRCORELOG_DEBUG ("Ret - %d : CurrState - %d\n", lenBTRCoreRet, lpstBTRCoreDevStateInfo->eDeviceCurrState);
4106  return lenBTRCoreRet;
4107 }
4108 
4109 
4110 enBTRCoreRet
4112  tBTRCoreHandle hBTRCore,
4113  tBTRCoreDevId aBTRCoreDevId,
4114  enBTRCoreDeviceType aenBTRCoreDevType
4115 ) {
4116  stBTRCoreHdl* pstlhBTRCore = NULL;
4117  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
4118  enBTDeviceType lenBTDeviceType = enBTDevUnknown;
4119  stBTRCoreBTDevice* lpstBTRCoreBTDevice = NULL;
4120  stBTRCoreDevStateInfo* lpstBTRCoreDevStateInfo = NULL;
4121  const char* lpcBTRCoreBTDevicePath = NULL;
4122  const char* lpcBTRCoreBTDeviceName = NULL;
4123 
4124 
4125  if (!hBTRCore) {
4126  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
4127  return enBTRCoreNotInitialized;
4128  }
4129  else if (aBTRCoreDevId < 0) {
4130  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
4131  return enBTRCoreInvalidArg;
4132  }
4133 
4134  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
4135 
4136  if ((lenBTRCoreRet = btrCore_GetDeviceInfo(pstlhBTRCore, aBTRCoreDevId, aenBTRCoreDevType,
4137  &lenBTDeviceType, &lpstBTRCoreBTDevice, &lpstBTRCoreDevStateInfo,
4138  &lpcBTRCoreBTDevicePath, &lpcBTRCoreBTDeviceName)) != enBTRCoreSuccess) {
4139  BTRCORELOG_ERROR ("Failed to Get Device Information\n");
4140  return lenBTRCoreRet;
4141  }
4142 
4143 
4144  (void)lenBTDeviceType;
4145 
4146  if ((lpstBTRCoreDevStateInfo->eDeviceCurrState == enBTRCoreDevStDisconnected) ||
4147  (lpstBTRCoreDevStateInfo->eDeviceCurrState == enBTRCoreDevStLost)) {
4148  BTRCORELOG_DEBUG ("enBTRCoreDevStDisconnected = %s\n", lpcBTRCoreBTDeviceName);
4149  lenBTRCoreRet = enBTRCoreSuccess;
4150  }
4151  else {
4152  lenBTRCoreRet = enBTRCoreFailure;
4153  }
4154 
4155  BTRCORELOG_DEBUG ("Ret - %d : CurrState - %d\n", lenBTRCoreRet, lpstBTRCoreDevStateInfo->eDeviceCurrState);
4156  return lenBTRCoreRet;
4157 }
4158 
4159 
4160 enBTRCoreRet
4162  tBTRCoreHandle hBTRCore,
4163  tBTRCoreDevId aBTRCoreDevId,
4164  enBTRCoreDeviceType* apenBTRCoreDevTy,
4165  enBTRCoreDeviceClass* apenBTRCoreDevCl
4166 ) {
4167  stBTRCoreHdl* pstlhBTRCore = NULL;
4168  stBTRCoreBTDevice* pstBTDevice = NULL;
4169  int i32LoopIdx = 0;
4170 
4171  if (!hBTRCore) {
4172  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
4173  return enBTRCoreNotInitialized;
4174  }
4175  else if (aBTRCoreDevId < 0) {
4176  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
4177  return enBTRCoreInvalidArg;
4178  }
4179  else if (!apenBTRCoreDevTy || !apenBTRCoreDevCl) {
4180  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
4181  return enBTRCoreInvalidArg;
4182  }
4183 
4184 
4185  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
4186 
4187  if (pstlhBTRCore->numOfPairedDevices) {
4188  if (aBTRCoreDevId < BTRCORE_MAX_NUM_BT_DEVICES) {
4189  pstBTDevice = &pstlhBTRCore->stKnownDevicesArr[aBTRCoreDevId];
4190  }
4191  else {
4192  for (i32LoopIdx = 0; i32LoopIdx < pstlhBTRCore->numOfPairedDevices; i32LoopIdx++) {
4193  if (aBTRCoreDevId == pstlhBTRCore->stKnownDevicesArr[i32LoopIdx].tDeviceId) {
4194  pstBTDevice = &pstlhBTRCore->stKnownDevicesArr[i32LoopIdx];
4195  break;
4196  }
4197  }
4198  }
4199  }
4200 
4201 
4202  if (!pstBTDevice && pstlhBTRCore->numOfScannedDevices) {
4203  if (aBTRCoreDevId < BTRCORE_MAX_NUM_BT_DEVICES) {
4204  pstBTDevice = &pstlhBTRCore->stScannedDevicesArr[aBTRCoreDevId];
4205  }
4206  else {
4207  for (i32LoopIdx = 0; i32LoopIdx < pstlhBTRCore->numOfScannedDevices; i32LoopIdx++) {
4208  if (aBTRCoreDevId == pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].tDeviceId) {
4209  pstBTDevice = &pstlhBTRCore->stScannedDevicesArr[i32LoopIdx];
4210  break;
4211  }
4212  }
4213  }
4214  }
4215 
4216 
4217  if (!pstBTDevice) {
4218  *apenBTRCoreDevTy = enBTRCoreUnknown;
4219  *apenBTRCoreDevCl = enBTRCore_DC_Unknown;
4220  return enBTRCoreFailure;
4221  }
4222 
4223 
4224  *apenBTRCoreDevCl = pstBTDevice->enDeviceType;
4225  *apenBTRCoreDevTy = btrCore_MapDevClassToDevType(pstBTDevice->enDeviceType);
4226 
4227  return enBTRCoreSuccess;
4228 }
4229 
4230 
4231 enBTRCoreRet
4233  tBTRCoreHandle hBTRCore,
4234  tBTRCoreDevId aBTRCoreDevId,
4235  enBTRCoreDeviceType aenBTRCoreDevType,
4236  stBTRCoreDevMediaInfo* apstBTRCoreDevMediaInfo
4237 ) {
4238  stBTRCoreHdl* pstlhBTRCore = NULL;
4239 
4240  const char* pDeviceAddress = NULL;
4241  stBTRCoreBTDevice* pstKnownDevice = NULL;
4242  stBTRCoreDevStateInfo* lpstKnownDevStInfo = NULL;
4243  enBTDeviceType lenBTDeviceType = enBTDevUnknown;
4244  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
4245 
4246  stBTRCoreAVMediaInfo lstBtrCoreMediaInfo;
4247  unsigned int ui32AVMCodecInfoSize = 0;
4248 
4249 
4250  if (!hBTRCore) {
4251  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
4252  return enBTRCoreNotInitialized;
4253  }
4254  else if ((aBTRCoreDevId < 0) || !apstBTRCoreDevMediaInfo || !apstBTRCoreDevMediaInfo->pstBtrCoreDevMCodecInfo) {
4255  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
4256  return enBTRCoreInvalidArg;
4257  }
4258 
4259  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
4260 
4261  memset(&lstBtrCoreMediaInfo, 0, sizeof(stBTRCoreAVMediaInfo));
4262  if ((lenBTRCoreRet = btrCore_GetDeviceInfoKnown(pstlhBTRCore, aBTRCoreDevId, aenBTRCoreDevType,
4263  &lenBTDeviceType, &pstKnownDevice, &lpstKnownDevStInfo, &pDeviceAddress)) != enBTRCoreSuccess) {
4264  BTRCORELOG_ERROR ("Failed to Get Device Information\n");
4265  return lenBTRCoreRet;
4266  }
4267 
4268 
4269  BTRCORELOG_INFO (" We will get Media Info for %s - DevTy %d\n", pDeviceAddress, lenBTDeviceType);
4270 
4271  switch (lenBTDeviceType) {
4272  case enBTDevAudioSink:
4273  lstBtrCoreMediaInfo.eBtrCoreAVMFlow = eBTRCoreAVMediaFlowOut;
4274  break;
4275  case enBTDevAudioSource:
4276  lstBtrCoreMediaInfo.eBtrCoreAVMFlow = eBTRCoreAVMediaFlowIn;
4277  break;
4278  case enBTDevHFPHeadset:
4279  lstBtrCoreMediaInfo.eBtrCoreAVMFlow = eBTRCoreAVMediaFlowInOut;
4280  break;
4281  case enBTDevHFPAudioGateway:
4282  lstBtrCoreMediaInfo.eBtrCoreAVMFlow = eBTRCoreAVMediaFlowInOut;
4283  break;
4284  case enBTDevLE:
4285  lstBtrCoreMediaInfo.eBtrCoreAVMFlow = eBTRCoreAVMediaFlowUnknown;
4286  break;
4287  case enBTDevUnknown:
4288  lstBtrCoreMediaInfo.eBtrCoreAVMFlow = eBTRCoreAVMediaFlowUnknown;
4289  break;
4290  default:
4291  lstBtrCoreMediaInfo.eBtrCoreAVMFlow = eBTRCoreAVMediaFlowUnknown;
4292  break;
4293  }
4294 
4295 
4296  ui32AVMCodecInfoSize = sizeof(stBTRCoreAVMediaMpegInfo) > sizeof(stBTRCoreAVMediaSbcInfo) ? sizeof(stBTRCoreAVMediaMpegInfo) : sizeof(stBTRCoreAVMediaSbcInfo);
4297  ui32AVMCodecInfoSize = ui32AVMCodecInfoSize > sizeof(stBTRMgrAVMediaPcmInfo) ? ui32AVMCodecInfoSize : sizeof(stBTRMgrAVMediaPcmInfo);
4298 
4299  lstBtrCoreMediaInfo.eBtrCoreAVMType = eBTRCoreAVMTypeUnknown;
4300  if (!(lstBtrCoreMediaInfo.pstBtrCoreAVMCodecInfo = g_malloc0(ui32AVMCodecInfoSize))) {
4301  BTRCORELOG_ERROR ("AVMedia_GetCurMediaInfo - Unable to alloc Memory\n");
4302  return lenBTRCoreRet;
4303  }
4304 
4305 
4306  // TODO: Implement a Device State Machine and Check whether the device is Connected before making the call
4307  if ((lenBTRCoreRet = BTRCore_AVMedia_GetCurMediaInfo (pstlhBTRCore->avMediaHdl, pDeviceAddress, &lstBtrCoreMediaInfo)) != enBTRCoreSuccess) {
4308  BTRCORELOG_ERROR ("AVMedia_GetCurMediaInfo ERROR occurred\n");
4309  g_free(lstBtrCoreMediaInfo.pstBtrCoreAVMCodecInfo);
4310  return lenBTRCoreRet;
4311  }
4312 
4313  switch (lstBtrCoreMediaInfo.eBtrCoreAVMType) {
4314  case eBTRCoreAVMTypePCM:
4315  apstBTRCoreDevMediaInfo->eBtrCoreDevMType = eBTRCoreDevMediaTypePCM;
4316  break;
4317  case eBTRCoreAVMTypeSBC: {
4318  stBTRCoreDevMediaSbcInfo* lapstBtrCoreDevMCodecInfo = (stBTRCoreDevMediaSbcInfo*)(apstBTRCoreDevMediaInfo->pstBtrCoreDevMCodecInfo);
4319  stBTRCoreAVMediaSbcInfo* lpstBtrCoreAVMSbcInfo = (stBTRCoreAVMediaSbcInfo*)(lstBtrCoreMediaInfo.pstBtrCoreAVMCodecInfo);
4320 
4321  apstBTRCoreDevMediaInfo->eBtrCoreDevMType = eBTRCoreDevMediaTypeSBC;
4322 
4323  switch (lpstBtrCoreAVMSbcInfo->eAVMAChan) {
4324  case eBTRCoreAVMAChanMono:
4325  lapstBtrCoreDevMCodecInfo->eDevMAChan = eBTRCoreDevMediaAChanMono;
4326  break;
4327  case eBTRCoreAVMAChanDualChannel:
4328  lapstBtrCoreDevMCodecInfo->eDevMAChan = eBTRCoreDevMediaAChanDualChannel;
4329  break;
4330  case eBTRCoreAVMAChanStereo:
4331  lapstBtrCoreDevMCodecInfo->eDevMAChan = eBTRCoreDevMediaAChanStereo;
4332  break;
4333  case eBTRCoreAVMAChanJointStereo:
4334  lapstBtrCoreDevMCodecInfo->eDevMAChan = eBTRCoreDevMediaAChanJointStereo;
4335  break;
4336  case eBTRCoreAVMAChan5_1:
4337  lapstBtrCoreDevMCodecInfo->eDevMAChan = eBTRCoreDevMediaAChan5_1;
4338  break;
4339  case eBTRCoreAVMAChan7_1:
4340  lapstBtrCoreDevMCodecInfo->eDevMAChan = eBTRCoreDevMediaAChan7_1;
4341  break;
4342  case eBTRCoreAVMAChanUnknown:
4343  default:
4344  lapstBtrCoreDevMCodecInfo->eDevMAChan = eBTRCoreDevMediaAChanUnknown;
4345  break;
4346  }
4347 
4348  lapstBtrCoreDevMCodecInfo->ui32DevMSFreq = lpstBtrCoreAVMSbcInfo->ui32AVMSFreq;
4349  lapstBtrCoreDevMCodecInfo->ui8DevMSbcAllocMethod = lpstBtrCoreAVMSbcInfo->ui8AVMSbcAllocMethod;
4350  lapstBtrCoreDevMCodecInfo->ui8DevMSbcSubbands = lpstBtrCoreAVMSbcInfo->ui8AVMSbcSubbands;
4351  lapstBtrCoreDevMCodecInfo->ui8DevMSbcBlockLength = lpstBtrCoreAVMSbcInfo->ui8AVMSbcBlockLength;
4352  lapstBtrCoreDevMCodecInfo->ui8DevMSbcMinBitpool = lpstBtrCoreAVMSbcInfo->ui8AVMSbcMinBitpool;
4353  lapstBtrCoreDevMCodecInfo->ui8DevMSbcMaxBitpool = lpstBtrCoreAVMSbcInfo->ui8AVMSbcMaxBitpool;
4354  lapstBtrCoreDevMCodecInfo->ui16DevMSbcFrameLen = lpstBtrCoreAVMSbcInfo->ui16AVMSbcFrameLen;
4355  lapstBtrCoreDevMCodecInfo->ui16DevMSbcBitrate = lpstBtrCoreAVMSbcInfo->ui16AVMSbcBitrate;
4356 
4357  break;
4358  }
4359  case eBTRCoreAVMTypeMPEG:
4360  apstBTRCoreDevMediaInfo->eBtrCoreDevMType = eBTRCoreDevMediaTypeMPEG;
4361  break;
4362  case eBTRCoreAVMTypeAAC: {
4363  stBTRCoreDevMediaMpegInfo* lapstBtrCoreDevMCodecInfo = (stBTRCoreDevMediaMpegInfo*)(apstBTRCoreDevMediaInfo->pstBtrCoreDevMCodecInfo);
4364  stBTRCoreAVMediaMpegInfo* lpstBtrCoreAVMAacInfo = (stBTRCoreAVMediaMpegInfo*)(lstBtrCoreMediaInfo.pstBtrCoreAVMCodecInfo);
4365 
4366  apstBTRCoreDevMediaInfo->eBtrCoreDevMType = eBTRCoreDevMediaTypeAAC;
4367 
4368  switch (lpstBtrCoreAVMAacInfo->eAVMAChan) {
4369  case eBTRCoreAVMAChanMono:
4370  lapstBtrCoreDevMCodecInfo->eDevMAChan = eBTRCoreDevMediaAChanMono;
4371  break;
4372  case eBTRCoreAVMAChanDualChannel:
4373  lapstBtrCoreDevMCodecInfo->eDevMAChan = eBTRCoreDevMediaAChanDualChannel;
4374  break;
4375  case eBTRCoreAVMAChanStereo:
4376  lapstBtrCoreDevMCodecInfo->eDevMAChan = eBTRCoreDevMediaAChanStereo;
4377  break;
4378  case eBTRCoreAVMAChanJointStereo:
4379  lapstBtrCoreDevMCodecInfo->eDevMAChan = eBTRCoreDevMediaAChanJointStereo;
4380  break;
4381  case eBTRCoreAVMAChan5_1:
4382  lapstBtrCoreDevMCodecInfo->eDevMAChan = eBTRCoreDevMediaAChan5_1;
4383  break;
4384  case eBTRCoreAVMAChan7_1:
4385  lapstBtrCoreDevMCodecInfo->eDevMAChan = eBTRCoreDevMediaAChan7_1;
4386  break;
4387  case eBTRCoreAVMAChanUnknown:
4388  default:
4389  lapstBtrCoreDevMCodecInfo->eDevMAChan = eBTRCoreDevMediaAChanUnknown;
4390  break;
4391  }
4392 
4393  lapstBtrCoreDevMCodecInfo->ui32DevMSFreq = lpstBtrCoreAVMAacInfo->ui32AVMSFreq;
4394  lapstBtrCoreDevMCodecInfo->ui8DevMMpegCrc = lpstBtrCoreAVMAacInfo->ui8AVMMpegCrc;
4395  lapstBtrCoreDevMCodecInfo->ui8DevMMpegLayer = lpstBtrCoreAVMAacInfo->ui8AVMMpegLayer;
4396  lapstBtrCoreDevMCodecInfo->ui8DevMMpegMpf = lpstBtrCoreAVMAacInfo->ui8AVMMpegMpf;
4397  lapstBtrCoreDevMCodecInfo->ui8DevMMpegRfa = lpstBtrCoreAVMAacInfo->ui8AVMMpegRfa;
4398  lapstBtrCoreDevMCodecInfo->ui16DevMMpegFrameLen = lpstBtrCoreAVMAacInfo->ui16AVMMpegFrameLen;
4399  lapstBtrCoreDevMCodecInfo->ui16DevMMpegBitrate = lpstBtrCoreAVMAacInfo->ui16AVMMpegBitrate;
4400 
4401  break;
4402  }
4403  case eBTRCoreAVMTypeUnknown:
4404  default:
4405  apstBTRCoreDevMediaInfo->eBtrCoreDevMType = eBTRCoreDevMediaTypeUnknown;
4406  break;
4407  }
4408 
4409  g_free(lstBtrCoreMediaInfo.pstBtrCoreAVMCodecInfo);
4410  return enBTRCoreSuccess;
4411 }
4412 
4413 
4414 enBTRCoreRet
4416  tBTRCoreHandle hBTRCore,
4417  tBTRCoreDevId aBTRCoreDevId,
4418  enBTRCoreDeviceType aenBTRCoreDevType,
4419  int* aiDataPath,
4420  int* aidataReadMTU,
4421  int* aidataWriteMTU,
4422  unsigned int* apui32Delay
4423 ) {
4424  stBTRCoreHdl* pstlhBTRCore = NULL;
4425 
4426  const char* pDeviceAddress = NULL;
4427  stBTRCoreBTDevice* pstKnownDevice = NULL;
4428  stBTRCoreDevStateInfo* lpstKnownDevStInfo = NULL;
4429  enBTDeviceType lenBTDeviceType = enBTDevUnknown;
4430  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
4431  enBTRCoreDeviceState lenDevPrevState = enBTRCoreDevStUnknown;
4432  enBTRCoreDeviceState lenDevCurrState = enBTRCoreDevStUnknown;
4433 
4434  int liDataPath = 0;
4435  int lidataReadMTU = 0;
4436  int lidataWriteMTU = 0;
4437  unsigned int ui32Delay = 0xFFFFu;
4438 
4439 
4440  if (!hBTRCore) {
4441  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
4442  return enBTRCoreNotInitialized;
4443  }
4444  else if (!aiDataPath || !aidataReadMTU || !aidataWriteMTU || !apui32Delay || (aBTRCoreDevId < 0)) {
4445  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
4446  return enBTRCoreInvalidArg;
4447  }
4448 
4449  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
4450 
4451 
4452  if ((lenBTRCoreRet = btrCore_GetDeviceInfoKnown(pstlhBTRCore, aBTRCoreDevId, aenBTRCoreDevType,
4453  &lenBTDeviceType, &pstKnownDevice, &lpstKnownDevStInfo, &pDeviceAddress)) != enBTRCoreSuccess) {
4454  BTRCORELOG_ERROR ("Failed to Get Device Information\n");
4455  return lenBTRCoreRet;
4456  }
4457 
4458  lenDevPrevState = lpstKnownDevStInfo->eDevicePrevState;
4459  lenDevCurrState = lpstKnownDevStInfo->eDeviceCurrState;
4460  lpstKnownDevStInfo->eDevicePrevState = lpstKnownDevStInfo->eDeviceCurrState;
4461  if (lpstKnownDevStInfo->eDeviceCurrState != enBTRCoreDevStPlaying) {
4462  lpstKnownDevStInfo->eDeviceCurrState = enBTRCoreDevStPlaying;
4463  }
4464 
4465  BTRCORELOG_INFO (" We will Acquire Data Path for %s\n", pDeviceAddress);
4466  if (BTRCore_AVMedia_AcquireDataPath(pstlhBTRCore->avMediaHdl, pDeviceAddress, &liDataPath, &lidataReadMTU, &lidataWriteMTU, &ui32Delay) != enBTRCoreSuccess) {
4467  BTRCORELOG_ERROR ("AVMedia_AcquireDataPath ERROR occurred\n");
4468  lpstKnownDevStInfo->eDevicePrevState = lenDevPrevState;
4469  lpstKnownDevStInfo->eDeviceCurrState = lenDevCurrState;
4470  return enBTRCoreFailure;
4471  }
4472 
4473  *aiDataPath = liDataPath;
4474  *aidataReadMTU = lidataReadMTU;
4475  *aidataWriteMTU = lidataWriteMTU;
4476  *apui32Delay = ui32Delay;
4477 
4478  return enBTRCoreSuccess;
4479 }
4480 
4481 
4482 enBTRCoreRet
4484  tBTRCoreHandle hBTRCore,
4485  tBTRCoreDevId aBTRCoreDevId,
4486  enBTRCoreDeviceType aenBTRCoreDevType
4487 ) {
4488  stBTRCoreHdl* pstlhBTRCore = NULL;
4489 
4490  const char* pDeviceAddress = NULL;
4491  stBTRCoreBTDevice* pstKnownDevice = NULL;
4492  stBTRCoreDevStateInfo* lpstKnownDevStInfo = NULL;
4493  enBTDeviceType lenBTDeviceType = enBTDevUnknown;
4494  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
4495 
4496 
4497  if (!hBTRCore) {
4498  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
4499  return enBTRCoreNotInitialized;
4500  }
4501  else if (aBTRCoreDevId < 0) {
4502  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
4503  return enBTRCoreInvalidArg;
4504  }
4505 
4506  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
4507 
4508 
4509  if ((lenBTRCoreRet = btrCore_GetDeviceInfoKnown(pstlhBTRCore, aBTRCoreDevId, aenBTRCoreDevType,
4510  &lenBTDeviceType, &pstKnownDevice, &lpstKnownDevStInfo, &pDeviceAddress)) != enBTRCoreSuccess) {
4511  BTRCORELOG_ERROR ("Failed to Get Device Information\n");
4512  return lenBTRCoreRet;
4513  }
4514 
4515  //TODO: Make a Device specific call baced on lenBTDeviceType
4516  (void)lenBTDeviceType;
4517 
4518  BTRCORELOG_INFO (" We will Release Data Path for %s\n", pDeviceAddress);
4519 
4520  // TODO: Implement a Device State Machine and Check whether the device is in a State to acquire Device Data path
4521  // before making the call
4522  if(BTRCore_AVMedia_ReleaseDataPath(pstlhBTRCore->avMediaHdl, pDeviceAddress) != enBTRCoreSuccess) {
4523  BTRCORELOG_ERROR ("AVMedia_ReleaseDataPath ERROR occurred\n");
4524  return enBTRCoreFailure;
4525  }
4526 
4527  return enBTRCoreSuccess;
4528 }
4529 
4530 
4531 enBTRCoreRet
4533  tBTRCoreHandle hBTRCore,
4534  unsigned int aui32AckTOutms
4535 ) {
4536  stBTRCoreHdl* pstlhBTRCore = NULL;
4537 
4538  if (!hBTRCore) {
4539  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
4540  return enBTRCoreNotInitialized;
4541  }
4542 
4543  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
4544 
4545  if (BtrCore_BTSetDevDataAckTimeout(pstlhBTRCore->connHdl, aui32AckTOutms) != 0) {
4546  BTRCORELOG_ERROR ("Failed to SetDevDataAckTimeout\n");
4547  return enBTRCoreFailure;
4548  }
4549 
4550  return enBTRCoreSuccess;
4551 }
4552 
4553 
4554 enBTRCoreRet
4556  tBTRCoreHandle hBTRCore,
4557  tBTRCoreDevId aBTRCoreDevId,
4558  enBTRCoreDeviceType aenBTRCoreDevType,
4559  enBTRCoreMediaCtrl aenBTRCoreMediaCtrl,
4560  stBTRCoreMediaCtData* apstBTRCoreMediaCData
4561 ) {
4562  stBTRCoreHdl* pstlhBTRCore = NULL;
4563 
4564  const char* pDeviceAddress = NULL;
4565  stBTRCoreBTDevice* pstKnownDevice = NULL;
4566  stBTRCoreDevStateInfo* lpstKnownDevStInfo = NULL;
4567  enBTDeviceType lenBTDeviceType = enBTDevUnknown;
4568  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
4569 
4570  BOOLEAN lbBTDeviceConnected = FALSE;
4571  enBTRCoreAVMediaCtrl lenBTRCoreAVMediaCtrl = 0;
4572  eBTRCoreAVMediaFlow lenBTRCoreAVMediaFlow = eBTRCoreAVMediaFlowUnknown;
4573  stBTRCoreAVMediaCtData* lpstBTRCoreAVMCtData = NULL;
4574 
4575 
4576  if (!hBTRCore) {
4577  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
4578  return enBTRCoreNotInitialized;
4579  }
4580  else if (aBTRCoreDevId < 0) {
4581  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
4582  return enBTRCoreInvalidArg;
4583  }
4584 
4585  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
4586 
4587 
4588  if ((lenBTRCoreRet = btrCore_GetDeviceInfoKnown(pstlhBTRCore, aBTRCoreDevId, aenBTRCoreDevType,
4589  &lenBTDeviceType, &pstKnownDevice, &lpstKnownDevStInfo, &pDeviceAddress)) != enBTRCoreSuccess) {
4590  BTRCORELOG_ERROR ("Failed to Get Device Information\n");
4591  return lenBTRCoreRet;
4592  }
4593 
4594  if ((lbBTDeviceConnected = pstKnownDevice->bDeviceConnected) == FALSE) {
4595  BTRCORELOG_ERROR ("Device is not Connected!!!\n");
4596  return enBTRCoreFailure;
4597  }
4598 
4599 
4600  switch (lenBTDeviceType) {
4601  case enBTDevAudioSink:
4602  lenBTRCoreAVMediaFlow = eBTRCoreAVMediaFlowOut;
4603  break;
4604  case enBTDevAudioSource:
4605  lenBTRCoreAVMediaFlow = eBTRCoreAVMediaFlowIn;
4606  break;
4607  case enBTDevHFPHeadset:
4608  lenBTRCoreAVMediaFlow = eBTRCoreAVMediaFlowInOut;
4609  break;
4610  case enBTDevHFPAudioGateway:
4611  lenBTRCoreAVMediaFlow = eBTRCoreAVMediaFlowInOut;
4612  break;
4613  case enBTDevLE:
4614  lenBTRCoreAVMediaFlow = eBTRCoreAVMediaFlowUnknown;
4615  break;
4616  case enBTDevUnknown:
4617  lenBTRCoreAVMediaFlow = eBTRCoreAVMediaFlowUnknown;
4618  break;
4619  default:
4620  lenBTRCoreAVMediaFlow = eBTRCoreAVMediaFlowUnknown;
4621  break;
4622  }
4623 
4624  switch (aenBTRCoreMediaCtrl) {
4625  case enBTRCoreMediaCtrlPlay:
4626  lenBTRCoreAVMediaCtrl = enBTRCoreAVMediaCtrlPlay;
4627  break;
4628  case enBTRCoreMediaCtrlPause:
4629  lenBTRCoreAVMediaCtrl = enBTRCoreAVMediaCtrlPause;
4630  break;
4631  case enBTRCoreMediaCtrlStop:
4632  lenBTRCoreAVMediaCtrl = enBTRCoreAVMediaCtrlStop;
4633  break;
4634  case enBTRCoreMediaCtrlNext:
4635  lenBTRCoreAVMediaCtrl = enBTRCoreAVMediaCtrlNext;
4636  break;
4637  case enBTRCoreMediaCtrlPrevious:
4638  lenBTRCoreAVMediaCtrl = enBTRCoreAVMediaCtrlPrevious;
4639  break;
4640  case enBTRCoreMediaCtrlFastForward:
4641  lenBTRCoreAVMediaCtrl = enBTRCoreAVMediaCtrlFastForward;
4642  break;
4643  case enBTRCoreMediaCtrlRewind:
4644  lenBTRCoreAVMediaCtrl = enBTRCoreAVMediaCtrlRewind;
4645  break;
4646  case enBTRCoreMediaCtrlVolumeUp:
4647  lenBTRCoreAVMediaCtrl = enBTRCoreAVMediaCtrlVolumeUp;
4648  break;
4649  case enBTRCoreMediaCtrlVolumeDown:
4650  lenBTRCoreAVMediaCtrl = enBTRCoreAVMediaCtrlVolumeDown;
4651  break;
4652  case enBTRCoreMediaCtrlEqlzrOff:
4653  lenBTRCoreAVMediaCtrl = enBTRcoreAVMediaCtrlEqlzrOff;
4654  break;
4655  case enBTRCoreMediaCtrlEqlzrOn:
4656  lenBTRCoreAVMediaCtrl = enBTRcoreAVMediaCtrlEqlzrOn;
4657  break;
4658  case enBTRCoreMediaCtrlShflOff:
4659  lenBTRCoreAVMediaCtrl = enBTRCoreAVMediaCtrlShflOff;
4660  break;
4661  case enBTRCoreMediaCtrlShflAllTracks:
4662  lenBTRCoreAVMediaCtrl = enBTRCoreAVMediaCtrlShflAllTracks;
4663  break;
4664  case enBTRCoreMediaCtrlShflGroup:
4665  lenBTRCoreAVMediaCtrl = enBTRCoreAVMediaCtrlShflGroup;
4666  break;
4667  case enBTRCoreMediaCtrlRptOff:
4668  lenBTRCoreAVMediaCtrl = enBTRCoreAVMediaCtrlRptOff;
4669  break;
4670  case enBTRCoreMediaCtrlRptSingleTrack:
4671  lenBTRCoreAVMediaCtrl = enBTRCoreAVMediaCtrlRptSingleTrack;
4672  break;
4673  case enBTRCoreMediaCtrlRptAllTracks:
4674  lenBTRCoreAVMediaCtrl = enBTRCoreAVMediaCtrlRptAllTracks;
4675  break;
4676  case enBTRCoreMediaCtrlRptGroup:
4677  lenBTRCoreAVMediaCtrl = enBTRCoreAVMediaCtrlRptGroup;
4678  break;
4679  default:
4680  lenBTRCoreAVMediaCtrl = enBTRCoreAVMediaCtrlUnknown;
4681  break;
4682  }
4683 
4684  if (lenBTRCoreAVMediaCtrl == enBTRCoreAVMediaCtrlUnknown) {
4685  BTRCORELOG_ERROR ("Media Play Control Unknown!\n");
4686  lenBTRCoreRet = enBTRCoreFailure;
4687  }
4688  else {
4689  stBTRCoreAVMediaCtData lstBTRCoreAVMCtData;
4690 
4691  if (apstBTRCoreMediaCData != NULL) {
4692  lstBTRCoreAVMCtData.m_mediaAbsTransportVolume = apstBTRCoreMediaCData->m_mediaAbsoluteVolume;
4693  lpstBTRCoreAVMCtData = &lstBTRCoreAVMCtData;
4694  }
4695 
4696  BTRCORELOG_INFO (" We will Perform Media Control for %s - DevTy %d - Ctrl %d - Flow %d\n", pDeviceAddress, lenBTDeviceType, lenBTRCoreAVMediaCtrl, lenBTRCoreAVMediaFlow);
4697  if ((lenBTRCoreRet = BTRCore_AVMedia_MediaControl(pstlhBTRCore->avMediaHdl,
4698  pDeviceAddress,
4699  lenBTRCoreAVMediaCtrl,
4700  lenBTRCoreAVMediaFlow,
4701  lpstBTRCoreAVMCtData)) != enBTRCoreSuccess) {
4702  BTRCORELOG_ERROR ("Media Play Control Failed!!!\n");
4703  }
4704  }
4705 
4706  return lenBTRCoreRet;
4707 }
4708 
4709 enBTRCoreRet
4711  tBTRCoreHandle hBTRCore,
4712  tBTRCoreDevId aBTRCoreDevId,
4713  enBTRCoreDeviceType aenBTRCoreDevType,
4714  stBTRCoreMediaTrackInfo* apstBTMediaTrackInfo
4715 ) {
4716  stBTRCoreHdl* pstlhBTRCore = NULL;
4717 
4718  const char* pDeviceAddress = NULL;
4719  stBTRCoreBTDevice* pstKnownDevice = NULL;
4720  stBTRCoreDevStateInfo* lpstKnownDevStInfo = NULL;
4721  enBTDeviceType lenBTDeviceType = enBTDevUnknown;
4722  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
4723 
4724  BOOLEAN lbBTDeviceConnected = FALSE;
4725 
4726 
4727  if (!hBTRCore) {
4728  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
4729  return enBTRCoreNotInitialized;
4730  }
4731 
4732  if (aBTRCoreDevId < 0) {
4733  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
4734  return enBTRCoreInvalidArg;
4735  }
4736 
4737  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
4738 
4739 
4740  if ((lenBTRCoreRet = btrCore_GetDeviceInfoKnown(pstlhBTRCore, aBTRCoreDevId, aenBTRCoreDevType,
4741  &lenBTDeviceType, &pstKnownDevice, &lpstKnownDevStInfo, &pDeviceAddress)) != enBTRCoreSuccess) {
4742  BTRCORELOG_ERROR ("Failed to Get Device Information\n");
4743  return lenBTRCoreRet;
4744  }
4745 
4746  if ((lbBTDeviceConnected = pstKnownDevice->bDeviceConnected) == FALSE) {
4747  BTRCORELOG_ERROR ("Device is not Connected!!!\n");
4748  return enBTRCoreFailure;
4749  }
4750 
4751 
4752  if (BTRCore_AVMedia_GetTrackInfo(pstlhBTRCore->avMediaHdl,
4753  pDeviceAddress,
4754  (stBTRCoreAVMediaTrackInfo*)apstBTMediaTrackInfo) != enBTRCoreSuccess) {
4755  BTRCORELOG_ERROR ("AVMedia get media track information Failed!!!\n");
4756  return enBTRCoreFailure;
4757  }
4758 
4759  return enBTRCoreSuccess;
4760 }
4761 
4762 enBTRCoreRet
4764  tBTRCoreHandle hBTRCore,
4765  tBTRCoreDevId aBTRCoreDevId,
4766  enBTRCoreDeviceType aenBTRCoreDevType,
4767  tBTRCoreMediaElementId aBtrMediaElementId,
4768  stBTRCoreMediaTrackInfo* apstBTMediaTrackInfo
4769 ) {
4770  stBTRCoreHdl* pstlhBTRCore = NULL;
4771 
4772  const char* pDeviceAddress = NULL;
4773  stBTRCoreBTDevice* pstKnownDevice = NULL;
4774  stBTRCoreDevStateInfo* lpstKnownDevStInfo = NULL;
4775  enBTDeviceType lenBTDeviceType = enBTDevUnknown;
4776  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
4777 
4778  BOOLEAN lbBTDeviceConnected = FALSE;
4779 
4780 
4781  if (!hBTRCore) {
4782  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
4783  return enBTRCoreNotInitialized;
4784  }
4785 
4786  if (aBTRCoreDevId < 0) {
4787  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
4788  return enBTRCoreInvalidArg;
4789  }
4790 
4791  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
4792 
4793 
4794  if ((lenBTRCoreRet = btrCore_GetDeviceInfoKnown(pstlhBTRCore, aBTRCoreDevId, aenBTRCoreDevType,
4795  &lenBTDeviceType, &pstKnownDevice, &lpstKnownDevStInfo, &pDeviceAddress)) != enBTRCoreSuccess) {
4796  BTRCORELOG_ERROR ("Failed to Get Device Information\n");
4797  return lenBTRCoreRet;
4798  }
4799 
4800  if ((lbBTDeviceConnected = pstKnownDevice->bDeviceConnected) == FALSE) {
4801  BTRCORELOG_ERROR ("Device is not Connected!!!\n");
4802  return enBTRCoreFailure;
4803  }
4804 
4805 
4806  if (BTRCore_AVMedia_GetElementTrackInfo(pstlhBTRCore->avMediaHdl,
4807  pDeviceAddress,
4808  aBtrMediaElementId,
4809  (stBTRCoreAVMediaTrackInfo*)apstBTMediaTrackInfo) != enBTRCoreSuccess) {
4810  BTRCORELOG_ERROR ("AVMedia get media track information Failed!!!\n");
4811  return enBTRCoreFailure;
4812  }
4813 
4814  return enBTRCoreSuccess;
4815 }
4816 
4817 
4818 
4819 enBTRCoreRet
4821  tBTRCoreHandle hBTRCore,
4822  tBTRCoreDevId aBTRCoreDevId,
4823  enBTRCoreDeviceType aenBTRCoreDevType,
4824  stBTRCoreMediaPositionInfo* apstBTMediaPositionInfo
4825 ) {
4826  stBTRCoreHdl* pstlhBTRCore = NULL;
4827 
4828  const char* pDeviceAddress = NULL;
4829  stBTRCoreBTDevice* pstKnownDevice = NULL;
4830  stBTRCoreDevStateInfo* lpstKnownDevStInfo = NULL;
4831  enBTDeviceType lenBTDeviceType = enBTDevUnknown;
4832  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
4833 
4834  BOOLEAN lbBTDeviceConnected = FALSE;
4835 
4836 
4837  if (!hBTRCore) {
4838  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
4839  return enBTRCoreNotInitialized;
4840  }
4841 
4842  if (aBTRCoreDevId < 0) {
4843  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
4844  return enBTRCoreInvalidArg;
4845  }
4846 
4847  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
4848 
4849 
4850  if ((lenBTRCoreRet = btrCore_GetDeviceInfoKnown(pstlhBTRCore, aBTRCoreDevId, aenBTRCoreDevType,
4851  &lenBTDeviceType, &pstKnownDevice, &lpstKnownDevStInfo, &pDeviceAddress)) != enBTRCoreSuccess) {
4852  BTRCORELOG_ERROR ("Failed to Get Device Information\n");
4853  return lenBTRCoreRet;
4854  }
4855 
4856  if ((lbBTDeviceConnected = pstKnownDevice->bDeviceConnected) == FALSE) {
4857  BTRCORELOG_ERROR ("Device is not Connected!!!\n");
4858  return enBTRCoreFailure;
4859  }
4860 
4861 
4862  if (BTRCore_AVMedia_GetPositionInfo(pstlhBTRCore->avMediaHdl,
4863  pDeviceAddress,
4864  (stBTRCoreAVMediaPositionInfo*)apstBTMediaPositionInfo) != enBTRCoreSuccess) {
4865  BTRCORELOG_ERROR ("AVMedia get Media Position Info Failed!!!\n");
4866  return enBTRCoreFailure;
4867  }
4868 
4869  return enBTRCoreSuccess;
4870 }
4871 
4872 
4873 
4874 enBTRCoreRet
4876  tBTRCoreHandle hBTRCore,
4877  tBTRCoreDevId aBTRCoreDevId,
4878  enBTRCoreDeviceType aenBTRCoreDevType,
4879  const char* mediaPropertyKey,
4880  void* mediaPropertyValue
4881 ) {
4882  stBTRCoreHdl* pstlhBTRCore = NULL;
4883 
4884  const char* pDeviceAddress = NULL;
4885  stBTRCoreBTDevice* pstKnownDevice = NULL;
4886  stBTRCoreDevStateInfo* lpstKnownDevStInfo = NULL;
4887  enBTDeviceType lenBTDeviceType = enBTDevUnknown;
4888  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
4889 
4890  BOOLEAN lbBTDeviceConnected = FALSE;
4891 
4892 
4893  if (!hBTRCore) {
4894  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
4895  return enBTRCoreNotInitialized;
4896  }
4897 
4898  if (aBTRCoreDevId < 0) {
4899  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
4900  return enBTRCoreInvalidArg;
4901  }
4902 
4903  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
4904 
4905 
4906  if ((lenBTRCoreRet = btrCore_GetDeviceInfoKnown(pstlhBTRCore, aBTRCoreDevId, aenBTRCoreDevType,
4907  &lenBTDeviceType, &pstKnownDevice, &lpstKnownDevStInfo, &pDeviceAddress)) != enBTRCoreSuccess) {
4908  BTRCORELOG_ERROR ("Failed to Get Device Information\n");
4909  return lenBTRCoreRet;
4910  }
4911 
4912  if ((lbBTDeviceConnected = pstKnownDevice->bDeviceConnected) == FALSE) {
4913  BTRCORELOG_ERROR ("Device is not Connected!!!\n");
4914  return enBTRCoreFailure;
4915  }
4916 
4917 
4918  if (BTRCore_AVMedia_GetMediaProperty(pstlhBTRCore->avMediaHdl,
4919  pDeviceAddress,
4920  mediaPropertyKey,
4921  mediaPropertyValue) != enBTRCoreSuccess) {
4922  BTRCORELOG_ERROR ("AVMedia get property Failed!!!\n");
4923  return enBTRCoreFailure;
4924  }
4925 
4926  return enBTRCoreSuccess;
4927 }
4928 
4929 
4930 enBTRCoreRet
4932  tBTRCoreHandle hBTRCore,
4933  tBTRCoreDevId aBTRCoreDevId,
4934  tBTRCoreMediaElementId aBtrMediaElementId,
4935  enBTRCoreDeviceType aenBTRCoreDevType,
4936  eBTRCoreMedElementType aenBTRCoreMedElementType
4937 ) {
4938  stBTRCoreHdl* pstlhBTRCore = NULL;
4939 
4940  const char* pDeviceAddress = NULL;
4941  stBTRCoreBTDevice* pstKnownDevice = NULL;
4942  stBTRCoreDevStateInfo* lpstKnownDevStInfo = NULL;
4943  enBTDeviceType lenBTDeviceType = enBTDevUnknown;
4944  eBTRCoreAVMElementType lAVMediaElementType = eBTRCoreAVMETypeUnknown;
4945  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
4946  char isPlayable = 0;
4947 
4948  if (!hBTRCore) {
4949  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
4950  return enBTRCoreNotInitialized;
4951  }
4952 
4953  if (aBTRCoreDevId < 0 || aBtrMediaElementId < 0) {
4954  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
4955  return enBTRCoreInvalidArg;
4956  }
4957 
4958  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
4959 
4960 
4961  if ((lenBTRCoreRet = btrCore_GetDeviceInfoKnown(pstlhBTRCore, aBTRCoreDevId, aenBTRCoreDevType,
4962  &lenBTDeviceType, &pstKnownDevice, &lpstKnownDevStInfo, &pDeviceAddress)) != enBTRCoreSuccess) {
4963  BTRCORELOG_ERROR ("Failed to Get Device Information\n");
4964  return lenBTRCoreRet;
4965  }
4966 
4967  if (pstKnownDevice->bDeviceConnected == FALSE) {
4968  BTRCORELOG_ERROR ("Device is not Connected!!!\n");
4969  return enBTRCoreFailure;
4970  }
4971 
4972  switch (aenBTRCoreMedElementType) {
4973  case enBTRCoreMedETypeAlbum:
4974  lAVMediaElementType = eBTRCoreAVMETypeAlbum;
4975  break;
4976  case enBTRCoreMedETypeArtist:
4977  lAVMediaElementType = eBTRCoreAVMETypeArtist;
4978  break;
4979  case enBTRCoreMedETypeGenre:
4980  lAVMediaElementType = eBTRCoreAVMETypeGenre;
4981  break;
4982  case enBTRCoreMedETypeCompilation:
4983  lAVMediaElementType = eBTRCoreAVMETypeCompilation;
4984  break;
4985  case enBTRCoreMedETypePlayList:
4986  lAVMediaElementType = eBTRCoreAVMETypePlayList;
4987  break;
4988  case enBTRCoreMedETypeTrackList:
4989  lAVMediaElementType = eBTRCoreAVMETypeTrackList;
4990  break;
4991  case enBTRCoreMedETypeTrack:
4992  lAVMediaElementType = eBTRCoreAVMETypeTrack;
4993  break;
4994  default:
4995  break;
4996  }
4997 
4998  if (BTRCore_AVMedia_IsMediaElementPlayable (pstlhBTRCore->avMediaHdl,
4999  pDeviceAddress,
5000  aBtrMediaElementId,
5001  &isPlayable) != enBTRCoreSuccess) {
5002  BTRCORELOG_ERROR ("Failed to MediaElement's playable state!\n");
5003  return enBTRCoreFailure;
5004  }
5005 
5006  if (isPlayable) {
5007 
5008  if (BTRCore_AVMedia_PlayTrack (pstlhBTRCore->avMediaHdl, pDeviceAddress, aBtrMediaElementId) != enBTRCoreSuccess) {
5009  BTRCORELOG_ERROR ("AVMedia Play Media Track by Element Id(%llu) Failed!!!\n", aBtrMediaElementId);
5010  return enBTRCoreFailure;
5011  }
5012  }
5013  else {
5014 
5015  if (BTRCore_AVMedia_ChangeBrowserLocation (pstlhBTRCore->avMediaHdl,
5016  pDeviceAddress,
5017  aBtrMediaElementId,
5018  lAVMediaElementType) != enBTRCoreSuccess) {
5019  BTRCORELOG_ERROR ("AVMedia change browser location to %llu Failed!\n", aBtrMediaElementId);
5020  return enBTRCoreFailure;
5021  }
5022  }
5023 
5024  (void)lAVMediaElementType;
5025  return lenBTRCoreRet;
5026 }
5027 
5028 
5029 enBTRCoreRet
5031  tBTRCoreHandle hBTRCore,
5032  tBTRCoreDevId aBTRCoreDevId,
5033  tBTRCoreMediaElementId aBtrMediaElementId,
5034  unsigned short aui16BtrMedElementStartIdx,
5035  unsigned short aui16BtrMedElementEndIdx,
5036  enBTRCoreDeviceType aenBTRCoreDevType,
5037  eBTRCoreMedElementType aenBTRCoreMedElementType,
5038  stBTRCoreMediaElementInfoList* apstMediaElementListInfo
5039 ) {
5040  stBTRCoreHdl* pstlhBTRCore = NULL;
5041 
5042  const char* pDeviceAddress = NULL;
5043  stBTRCoreBTDevice* pstKnownDevice = NULL;
5044  stBTRCoreDevStateInfo* lpstKnownDevStInfo = NULL;
5045  enBTDeviceType lenBTDeviceType = enBTDevUnknown;
5046  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
5047 
5048  stBTRCoreAVMediaElementInfoList lpstAVMediaElementInfoList;
5049 
5050  if (!hBTRCore || !apstMediaElementListInfo) {
5051  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
5052  return enBTRCoreNotInitialized;
5053  }
5054 
5055  if (aBTRCoreDevId < 0 || aBtrMediaElementId < 0) {
5056  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
5057  return enBTRCoreInvalidArg;
5058  }
5059 
5060  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
5061 
5062 
5063  if ((lenBTRCoreRet = btrCore_GetDeviceInfoKnown(pstlhBTRCore, aBTRCoreDevId, aenBTRCoreDevType,
5064  &lenBTDeviceType, &pstKnownDevice, &lpstKnownDevStInfo, &pDeviceAddress)) != enBTRCoreSuccess) {
5065  BTRCORELOG_ERROR ("Failed to Get Device Information\n");
5066  return lenBTRCoreRet;
5067  }
5068 
5069  if (pstKnownDevice->bDeviceConnected == FALSE) {
5070  BTRCORELOG_ERROR ("Device is not Connected!!!\n");
5071  return enBTRCoreFailure;
5072  }
5073 
5074  /* TODO find if its current folder or not and prevent calling SelectMediaBrowserElements() for non current folder */
5075 
5076  if (BTRCore_AVMedia_SelectMediaBrowserElements (pstlhBTRCore->avMediaHdl,
5077  pDeviceAddress,
5078  aui16BtrMedElementStartIdx,
5079  aui16BtrMedElementEndIdx) != enBTRCoreSuccess) {
5080  BTRCORELOG_ERROR ("AVMedia Select Media Browser Elements Failed for %llu (%u - %u)!\n", aBtrMediaElementId
5081  , aui16BtrMedElementStartIdx, aui16BtrMedElementEndIdx);
5082  //return enBTRCoreFailure;
5083  }
5084 
5085  memset (&lpstAVMediaElementInfoList, 0, sizeof(stBTRCoreAVMediaElementInfoList));
5086 
5087  if (BTRCore_AVMedia_GetMediaElementList (pstlhBTRCore->avMediaHdl,
5088  pDeviceAddress,
5089  aBtrMediaElementId,
5090  aui16BtrMedElementStartIdx,
5091  aui16BtrMedElementEndIdx,
5092  aenBTRCoreMedElementType,
5093  &lpstAVMediaElementInfoList) != enBTRCoreSuccess) {
5094  BTRCORELOG_ERROR ("AVMedia Get Media Item List Failed for %llu (%u - %u)!\n", aBtrMediaElementId, aui16BtrMedElementStartIdx, aui16BtrMedElementEndIdx);
5095  return enBTRCoreFailure;
5096  }
5097 
5098  memcpy (apstMediaElementListInfo, &lpstAVMediaElementInfoList, sizeof(stBTRCoreMediaElementInfoList));
5099 
5100  return lenBTRCoreRet;
5101 }
5102 
5103 enBTRCoreRet
5105  tBTRCoreHandle hBTRCore,
5106  tBTRCoreDevId aBTRCoreDevId,
5107  tBTRCoreMediaElementId aBtrMediaElementId,
5108  enBTRCoreDeviceType aenBTRCoreDevType,
5109  eBTRCoreMedElementType aenBTRCoreMedElementType
5110 ) {
5111  stBTRCoreHdl* pstlhBTRCore = NULL;
5112 
5113  const char* pDeviceAddress = NULL;
5114  stBTRCoreBTDevice* pstKnownDevice = NULL;
5115  stBTRCoreDevStateInfo* lpstKnownDevStInfo = NULL;
5116  enBTDeviceType lenBTDeviceType = enBTDevUnknown;
5117  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
5118  char isPlayable = 0;
5119 
5120  if (!hBTRCore) {
5121  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
5122  return enBTRCoreNotInitialized;
5123  }
5124 
5125  if (aBTRCoreDevId < 0 || aBtrMediaElementId < 0) {
5126  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
5127  return enBTRCoreInvalidArg;
5128  }
5129 
5130  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
5131 
5132 
5133  if ((lenBTRCoreRet = btrCore_GetDeviceInfoKnown(pstlhBTRCore, aBTRCoreDevId, aenBTRCoreDevType,
5134  &lenBTDeviceType, &pstKnownDevice, &lpstKnownDevStInfo, &pDeviceAddress)) != enBTRCoreSuccess) {
5135  BTRCORELOG_ERROR ("Failed to Get Device Information\n");
5136  return lenBTRCoreRet;
5137  }
5138 
5139  if (pstKnownDevice->bDeviceConnected == FALSE) {
5140  BTRCORELOG_ERROR ("Device is not Connected!!!\n");
5141  return enBTRCoreFailure;
5142  }
5143 
5144  /* Enhance */
5145 
5146  BTRCORELOG_ERROR ("BTRCore_AVMedia_IsMediaElementPlayable calling !\n");
5147  if (BTRCore_AVMedia_IsMediaElementPlayable (pstlhBTRCore->avMediaHdl,
5148  pDeviceAddress,
5149  aBtrMediaElementId,
5150  &isPlayable) != enBTRCoreSuccess) {
5151  BTRCORELOG_ERROR ("Failed to MediaElement's playable state!\n");
5152  return enBTRCoreFailure;
5153  }
5154 
5155  if (isPlayable) {
5156 
5157  if ((lenBTRCoreRet = BTRCore_AVMedia_SelectTrack (pstlhBTRCore->avMediaHdl,
5158  pDeviceAddress, aBtrMediaElementId)) != enBTRCoreSuccess) {
5159  BTRCORELOG_ERROR ("AVMedia Set Media Track by Element Id(%llu) Failed!!!\n", aBtrMediaElementId);
5160  return enBTRCoreFailure;
5161  }
5162  }
5163  else {
5164  // TODO
5165  }
5166 
5167 
5168  return lenBTRCoreRet;
5169 }
5170 
5171 
5172 enBTRCoreRet
5174  tBTRCoreHandle hBTRCore,
5175  tBTRCoreDevId aBTRCoreDevId,
5176  const char* apcBTRCoreLEUuid,
5177  enBTRCoreLeProp aenBTRCoreLeProp,
5178  void* apvBTRCorePropValue
5179 ) {
5180 
5181  if (!hBTRCore || !apcBTRCoreLEUuid || aBTRCoreDevId < 0) {
5182  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
5183  return enBTRCoreInvalidArg;
5184  }
5185 
5186  stBTRCoreHdl* pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
5187  stBTRCoreBTDevice* pstScannedDev = NULL;
5188  tBTRCoreDevId ltBTRCoreDevId = 0;
5189  int i32LoopIdx = 0;
5190 
5191  if (aBTRCoreDevId < BTRCORE_MAX_NUM_BT_DEVICES) {
5192  pstScannedDev = &pstlhBTRCore->stScannedDevicesArr[aBTRCoreDevId];
5193  }
5194  else {
5195  for (i32LoopIdx = 0; i32LoopIdx < pstlhBTRCore->numOfScannedDevices; i32LoopIdx++) {
5196  if (aBTRCoreDevId == pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].tDeviceId) {
5197  pstScannedDev = &pstlhBTRCore->stScannedDevicesArr[i32LoopIdx];
5198  break;
5199  }
5200  }
5201  }
5202 
5203  if (pstScannedDev) {
5204  ltBTRCoreDevId = pstScannedDev->tDeviceId;
5205  }
5206 
5207  if (!pstScannedDev || !ltBTRCoreDevId) {
5208  BTRCORELOG_ERROR ("Failed to find device in Scanned devices list\n");
5209  return enBTRCoreDeviceNotFound;
5210  }
5211 
5212  BTRCORELOG_DEBUG ("Get LE Property for Device : %s\n", pstScannedDev->pcDeviceName);
5213  BTRCORELOG_DEBUG ("LE DeviceID %llu\n", ltBTRCoreDevId);
5214 
5215  enBTRCoreLEGattProp lenBTRCoreLEGattProp = enBTRCoreLEGPropUnknown;
5216 
5217  switch (aenBTRCoreLeProp) {
5218 
5219  case enBTRCoreLePropGUUID:
5220  lenBTRCoreLEGattProp = enBTRCoreLEGPropUUID;
5221  break;
5222  case enBTRCoreLePropGPrimary:
5223  lenBTRCoreLEGattProp = enBTRCoreLEGPropPrimary;
5224  break;
5225  case enBTRCoreLePropGDevice:
5226  lenBTRCoreLEGattProp = enBTRCoreLEGPropDevice;
5227  break;
5228  case enBTRCoreLePropGService:
5229  lenBTRCoreLEGattProp = enBTRCoreLEGPropService;
5230  break;
5231  case enBTRCoreLePropGValue:
5232  lenBTRCoreLEGattProp = enBTRCoreLEGPropValue;
5233  break;
5234  case enBTRCoreLePropGNotifying:
5235  lenBTRCoreLEGattProp = enBTRCoreLEGPropNotifying;
5236  break;
5237  case enBTRCoreLePropGFlags:
5238  lenBTRCoreLEGattProp = enBTRCoreLEGPropFlags;
5239  break;
5240  case enBTRCoreLePropGChar:
5241  lenBTRCoreLEGattProp = enBTRCoreLEGPropChar;
5242  break;
5243  case enBTRCoreLePropUnknown:
5244  default:
5245  lenBTRCoreLEGattProp = enBTRCoreLEGPropUnknown;
5246  }
5247 
5248  if (lenBTRCoreLEGattProp == enBTRCoreLEGPropUnknown || BTRCore_LE_GetGattProperty(pstlhBTRCore->leHdl,
5249  ltBTRCoreDevId,
5250  apcBTRCoreLEUuid,
5251  lenBTRCoreLEGattProp,
5252  apvBTRCorePropValue) != enBTRCoreSuccess) {
5253  BTRCORELOG_ERROR ("Failed to get Gatt Property %d!!!\n", lenBTRCoreLEGattProp);
5254  return enBTRCoreFailure;
5255  }
5256 
5257  return enBTRCoreSuccess;
5258 }
5259 
5260 
5261 enBTRCoreRet
5263  tBTRCoreHandle hBTRCore,
5264  tBTRCoreDevId aBTRCoreDevId,
5265  const char* apBtUuid,
5266  enBTRCoreLeOp aenBTRCoreLeOp,
5267  char* apLeOpArg,
5268  char* rpLeOpRes
5269 ) {
5270 
5271  if (!hBTRCore || !apBtUuid || aBTRCoreDevId < 0) {
5272  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
5273  return enBTRCoreInvalidArg;
5274  }
5275 
5276  stBTRCoreHdl* pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
5277  stBTRCoreBTDevice* pstScannedDev = NULL;
5278  tBTRCoreDevId ltBTRCoreDevId = 0;
5279  int i32LoopIdx = 0;
5280 
5281  if (aBTRCoreDevId < BTRCORE_MAX_NUM_BT_DEVICES) {
5282  pstScannedDev = &pstlhBTRCore->stScannedDevicesArr[aBTRCoreDevId];
5283  }
5284  else {
5285  for (i32LoopIdx = 0; i32LoopIdx < pstlhBTRCore->numOfScannedDevices; i32LoopIdx++) {
5286  if (aBTRCoreDevId == pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].tDeviceId) {
5287  pstScannedDev = &pstlhBTRCore->stScannedDevicesArr[i32LoopIdx];
5288  break;
5289  }
5290  }
5291  }
5292 
5293  if (pstScannedDev) {
5294  ltBTRCoreDevId = pstScannedDev->tDeviceId;
5295  }
5296 
5297  if (!pstScannedDev || !ltBTRCoreDevId) {
5298  BTRCORELOG_ERROR ("Failed to find device in Scanned devices list\n");
5299  return enBTRCoreDeviceNotFound;
5300  }
5301 
5302  if (!pstScannedDev->bFound || !pstScannedDev->bDeviceConnected) {
5303  BTRCORELOG_ERROR ("Le Device is not connected, Please connect and perform LE method operation\n");
5304  return enBTRCoreDeviceNotFound;
5305  }
5306 
5307  BTRCORELOG_DEBUG ("Perform LE Op for Device : %s\n", pstScannedDev->pcDeviceName);
5308  BTRCORELOG_DEBUG ("LE DeviceID %llu\n", ltBTRCoreDevId);
5309 
5310  enBTRCoreLEGattOp lenBTRCoreLEGattOp = enBTRCoreLEGOpUnknown;
5311 
5312  switch (aenBTRCoreLeOp) {
5313 
5314  case enBTRCoreLeOpGReadValue:
5315  lenBTRCoreLEGattOp = enBTRCoreLEGOpReadValue;
5316  break;
5317  case enBTRCoreLeOpGWriteValue:
5318  lenBTRCoreLEGattOp = enBTRCoreLEGOpWriteValue;
5319  break;
5320  case enBTRCoreLeOpGStartNotify:
5321  lenBTRCoreLEGattOp = enBTRCoreLEGOpStartNotify;
5322  break;
5323  case enBTRCoreLeOpGStopNotify:
5324  lenBTRCoreLEGattOp = enBTRCoreLEGOpStopNotify;
5325  break;
5326  case enBTRCoreLeOpUnknown:
5327  default :
5328  lenBTRCoreLEGattOp = enBTRCoreLEGOpUnknown;
5329  }
5330 
5331  if (lenBTRCoreLEGattOp == enBTRCoreLEGOpUnknown || BtrCore_LE_PerformGattOp(pstlhBTRCore->leHdl,
5332  ltBTRCoreDevId,
5333  apBtUuid,
5334  lenBTRCoreLEGattOp,
5335  apLeOpArg,
5336  rpLeOpRes) != enBTRCoreSuccess) {
5337  BTRCORELOG_ERROR ("Failed to Perform LE Method Op %d!!!\n", aenBTRCoreLeOp);
5338  return enBTRCoreFailure;
5339  }
5340 
5341  return enBTRCoreSuccess;
5342 }
5343 
5344 enBTRCoreRet
5346  tBTRCoreHandle hBTRCore
5347 ) {
5348  stBTRCoreHdl* pstlhBTRCore = NULL;
5349  enBTRCoreRet lenBTRCoreRet = enBTRCoreSuccess;
5350 
5351  if (NULL == hBTRCore) {
5352  BTRCORELOG_ERROR("enBTRCoreNotInitialized\n");
5353  lenBTRCoreRet = enBTRCoreNotInitialized;
5354  }
5355  else {
5356  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
5357  lenBTRCoreRet = BTRCore_LE_StartAdvertisement(pstlhBTRCore->leHdl, pstlhBTRCore->connHdl, pstlhBTRCore->curAdapterPath);
5358  }
5359 
5360  return lenBTRCoreRet;
5361 }
5362 
5363 enBTRCoreRet
5365  tBTRCoreHandle hBTRCore
5366 ) {
5367  stBTRCoreHdl* pstlhBTRCore = NULL;
5368  enBTRCoreRet lenBTRCoreRet = enBTRCoreSuccess;
5369 
5370  if (NULL == hBTRCore) {
5371  BTRCORELOG_ERROR("enBTRCoreNotInitialized\n");
5372  lenBTRCoreRet = enBTRCoreNotInitialized;
5373  }
5374  else {
5375  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
5376  lenBTRCoreRet = BTRCore_LE_StopAdvertisement(pstlhBTRCore->leHdl, pstlhBTRCore->connHdl, pstlhBTRCore->curAdapterPath);
5377  }
5378 
5379  return lenBTRCoreRet;
5380 }
5381 
5382 enBTRCoreRet
5384  tBTRCoreHandle hBTRCore,
5385  char* aUUID,
5386  char* aValue,
5387  enBTRCoreLeProp aElement
5388 ) {
5389  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
5390  //enBTRCoreLEGattProp lGattProp = enBTRCoreLEGPropValue;
5391 
5392  if ((NULL == hBTRCore) || (NULL == aUUID) || (NULL == aValue)) {
5393  BTRCORELOG_ERROR("enBTRCoreNotInitialized\n");
5394  lenBTRCoreRet = enBTRCoreNotInitialized;
5395  }
5396  else {
5397  }
5398 
5399  return lenBTRCoreRet;
5400 }
5401 
5402 enBTRCoreRet
5404  tBTRCoreHandle hBTRCore,
5405  char* aAdvtType
5406 ) {
5407  stBTRCoreHdl* pstlhBTRCore = NULL;
5408  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
5409 
5410  if ((NULL != hBTRCore) && ( NULL != aAdvtType)) {
5411  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
5412  lenBTRCoreRet = BTRCore_LE_SetAdvertisementType(pstlhBTRCore->leHdl, aAdvtType);
5413  }
5414 
5415  return lenBTRCoreRet;
5416 }
5417 
5418 enBTRCoreRet
5420  tBTRCoreHandle hBTRCore,
5421  char* aUUID
5422 ) {
5423  stBTRCoreHdl* pstlhBTRCore = NULL;
5424  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
5425 
5426  if ((NULL != hBTRCore) && (NULL != aUUID)) {
5427  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
5428  lenBTRCoreRet = BTRCore_LE_SetServiceUUIDs(pstlhBTRCore->leHdl, aUUID);
5429  }
5430 
5431  return lenBTRCoreRet;
5432 }
5433 
5434 enBTRCoreRet
5436  tBTRCoreHandle hBTRCore,
5437  unsigned short aManfId,
5438  unsigned char* aDeviceDetails,
5439  int aLenManfData
5440 ) {
5441  stBTRCoreHdl* pstlhBTRCore = NULL;
5442  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
5443 
5444  if ((NULL != hBTRCore) && (NULL != aDeviceDetails)) {
5445  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
5446 
5447  lenBTRCoreRet = BTRCore_LE_SetManufacturerData(pstlhBTRCore->leHdl, aManfId, aDeviceDetails, aLenManfData);
5448  }
5449 
5450  return lenBTRCoreRet;
5451 }
5452 
5453 enBTRCoreRet
5455  tBTRCoreHandle hBTRCore,
5456  BOOLEAN aTxPower
5457 ) {
5458  stBTRCoreHdl* pstlhBTRCore = NULL;
5459  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
5460 
5461  if (NULL != hBTRCore) {
5462  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
5463  lenBTRCoreRet = BTRCore_LE_SetEnableTxPower(pstlhBTRCore->leHdl, aTxPower);
5464  }
5465 
5466  return lenBTRCoreRet;
5467 }
5468 
5469 enBTRCoreRet
5471  tBTRCoreHandle hBTRCore,
5472  char* aUUID,
5473  BOOLEAN aServiceType
5474 ) {
5475  stBTRCoreHdl* pstlhBTRCore = NULL;
5476  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
5477  int lNumGattServices = 0;
5478 
5479  if ((NULL != hBTRCore) && (NULL != aUUID)) {
5480  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
5481  if (NULL != BTRCore_LE_AddGattServiceInfo(pstlhBTRCore->leHdl, pstlhBTRCore->curAdapterPath, pstlhBTRCore->curAdapterAddr, aUUID, aServiceType, &lNumGattServices)) {
5482  //*aNumGattServices = lNumGattServices;
5483  lenBTRCoreRet = enBTRCoreSuccess;
5484  }
5485  }
5486  return lenBTRCoreRet;
5487 }
5488 
5489 enBTRCoreRet
5491  tBTRCoreHandle hBTRCore,
5492  char* aParentUUID,
5493  char* aUUID,
5494  unsigned short aFlags,
5495  char* aValue,
5496  enBTRCoreLeProp aElement
5497 ) {
5498  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
5499  stBTRCoreHdl* pstlhBTRCore = NULL;
5500 
5501  if ((NULL != hBTRCore) && (NULL != aParentUUID) && (NULL != aUUID) && (NULL != aValue)) {
5502  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
5503 
5504  if (enBTRCoreLePropGChar == aElement) {
5505  if (NULL != BTRCore_LE_AddGattCharInfo(pstlhBTRCore->leHdl, pstlhBTRCore->curAdapterPath, pstlhBTRCore->curAdapterAddr, aParentUUID, aUUID, aFlags, aValue)) {
5506  lenBTRCoreRet = enBTRCoreSuccess;
5507  }
5508  }
5509  else {
5510  if (NULL != BTRCore_LE_AddGattDescInfo(pstlhBTRCore->leHdl, pstlhBTRCore->curAdapterPath, pstlhBTRCore->curAdapterAddr, aParentUUID, aUUID, aFlags, aValue)) {
5511  lenBTRCoreRet = enBTRCoreSuccess;
5512  }
5513  }
5514  }
5515 
5516  return lenBTRCoreRet;
5517 }
5518 
5519 enBTRCoreRet
5521  tBTRCoreHandle hBTRCore,
5522  char* aUUID,
5523  char* aValue,
5524  enBTRCoreLeProp aElement
5525 ) {
5526  stBTRCoreHdl* pstlhBTRCore = NULL;
5527 
5528  if (!hBTRCore) {
5529  BTRCORELOG_ERROR("enBTRCoreNotInitialized\n");
5530  return enBTRCoreNotInitialized;
5531  }
5532  else if (!aValue) {
5533  BTRCORELOG_ERROR("enBTRCoreInvalidArg\n");
5534  return enBTRCoreInvalidArg;
5535  }
5536 
5537  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
5538 
5539  if (BTRCore_LE_SetPropertyValue(pstlhBTRCore->leHdl, aUUID, aValue, aElement)) {
5540  BTRCORELOG_ERROR("Set Gatt Property value - FAILED\n");
5541  return enBTRCoreFailure;
5542  }
5543 
5544  return enBTRCoreSuccess;
5545 }
5546 
5547 
5548 // Outgoing callbacks Registration Interfaces
5549 enBTRCoreRet
5550 BTRCore_RegisterDiscoveryCb (
5551  tBTRCoreHandle hBTRCore,
5552  fPtr_BTRCore_DeviceDiscCb afpcBBTRCoreDeviceDisc,
5553  void* apUserData
5554 ) {
5555  stBTRCoreHdl* pstlhBTRCore = NULL;
5556 
5557  if (!hBTRCore) {
5558  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
5559  return enBTRCoreNotInitialized;
5560  }
5561 
5562  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
5563 
5564  if (!pstlhBTRCore->fpcBBTRCoreDeviceDisc) {
5565  pstlhBTRCore->fpcBBTRCoreDeviceDisc = afpcBBTRCoreDeviceDisc;
5566  pstlhBTRCore->pvcBDevDiscUserData = apUserData;
5567  BTRCORELOG_INFO ("Device Discovery Callback Registered Successfully\n");
5568  }
5569  else {
5570  BTRCORELOG_INFO ("Device Discovery Callback Already Registered - Not Registering current CB\n");
5571  }
5572 
5573  return enBTRCoreSuccess;
5574 }
5575 
5576 
5577 enBTRCoreRet
5578 BTRCore_RegisterStatusCb (
5579  tBTRCoreHandle hBTRCore,
5580  fPtr_BTRCore_StatusCb afpcBBTRCoreStatus,
5581  void* apUserData
5582 ) {
5583  stBTRCoreHdl* pstlhBTRCore = NULL;
5584 
5585  if (!hBTRCore) {
5586  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
5587  return enBTRCoreNotInitialized;
5588  }
5589 
5590  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
5591 
5592  if (!pstlhBTRCore->fpcBBTRCoreStatus) {
5593  pstlhBTRCore->fpcBBTRCoreStatus = afpcBBTRCoreStatus;
5594  pstlhBTRCore->pvcBStatusUserData= apUserData;
5595  BTRCORELOG_INFO ("BT Status Callback Registered Successfully\n");
5596  }
5597  else {
5598  BTRCORELOG_INFO ("BT Status Callback Already Registered - Not Registering current CB\n");
5599  }
5600 
5601  return enBTRCoreSuccess;
5602 }
5603 
5604 
5605 enBTRCoreRet
5606 BTRCore_RegisterMediaStatusCb (
5607  tBTRCoreHandle hBTRCore,
5608  fPtr_BTRCore_MediaStatusCb afpcBBTRCoreMediaStatus,
5609  void* apUserData
5610 ) {
5611  stBTRCoreHdl* pstlhBTRCore = NULL;
5612 
5613  if (!hBTRCore) {
5614  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
5615  return enBTRCoreNotInitialized;
5616  }
5617 
5618  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
5619 
5620  if (!pstlhBTRCore->fpcBBTRCoreMediaStatus) {
5621  pstlhBTRCore->fpcBBTRCoreMediaStatus = afpcBBTRCoreMediaStatus;
5622  pstlhBTRCore->pvcBMediaStatusUserData= apUserData;
5623  BTRCORELOG_INFO ("BT Media Status Callback Registered Successfully\n");
5624  }
5625  else {
5626  BTRCORELOG_INFO ("BT Media Status Callback Already Registered - Not Registering current CB\n");
5627  }
5628 
5629  return enBTRCoreSuccess;
5630 }
5631 
5632 
5633 enBTRCoreRet
5634 BTRCore_RegisterConnectionIntimationCb (
5635  tBTRCoreHandle hBTRCore,
5636  fPtr_BTRCore_ConnIntimCb afpcBBTRCoreConnIntim,
5637  void* apUserData
5638 ) {
5639  stBTRCoreHdl* pstlhBTRCore = NULL;
5640 
5641  if (!hBTRCore) {
5642  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
5643  return enBTRCoreNotInitialized;
5644  }
5645 
5646  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
5647 
5648  (void)pstlhBTRCore;
5649 
5650  if (!pstlhBTRCore->fpcBBTRCoreConnIntim) {
5651  pstlhBTRCore->fpcBBTRCoreConnIntim = afpcBBTRCoreConnIntim;
5652  pstlhBTRCore->pvcBConnIntimUserData= apUserData;
5653  BTRCORELOG_INFO ("BT Conn In Intimation Callback Registered Successfully\n");
5654  }
5655  else {
5656  BTRCORELOG_INFO ("BT Conn In Intimation Callback Already Registered - Not Registering current CB\n");
5657  }
5658 
5659  return enBTRCoreSuccess;
5660 }
5661 
5662 
5663 enBTRCoreRet
5664 BTRCore_RegisterConnectionAuthenticationCb (
5665  tBTRCoreHandle hBTRCore,
5666  fPtr_BTRCore_ConnAuthCb afpcBBTRCoreConnAuth,
5667  void* apUserData
5668 ) {
5669  stBTRCoreHdl* pstlhBTRCore = NULL;
5670 
5671  if (!hBTRCore) {
5672  BTRCORELOG_ERROR ("enBTRCoreNotInitialized\n");
5673  return enBTRCoreNotInitialized;
5674  }
5675 
5676  pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;
5677 
5678  (void)pstlhBTRCore;
5679 
5680  if (!pstlhBTRCore->fpcBBTRCoreConnAuth) {
5681  pstlhBTRCore->fpcBBTRCoreConnAuth = afpcBBTRCoreConnAuth;
5682  pstlhBTRCore->pvcBConnAuthUserData= apUserData;
5683  BTRCORELOG_INFO ("BT Conn Auth Callback Registered Successfully\n");
5684  }
5685  else {
5686  BTRCORELOG_INFO ("BT Conn Auth Callback Already Registered - Not Registering current CB\n");
5687  }
5688 
5689  return enBTRCoreSuccess;
5690 }
5691 
5692 /* Incoming Callbacks */
5693 static int
5694 btrCore_BTAdapterStatusUpdateCb (
5695  enBTAdapterProp aeBtAdapterProp,
5696  stBTAdapterInfo* apstBTAdapterInfo,
5697  void* apUserData
5698 ) {
5699  stBTRCoreHdl* lpstlhBTRCore = (stBTRCoreHdl*)apUserData;
5700  enBTRCoreRet lenBTRCoreRet = enBTRCoreSuccess;
5701  stBTRCoreAdapter lstAdapterInfo;
5702  int pathlen;
5703 
5704  if (!apstBTAdapterInfo || !apUserData) {
5705  BTRCORELOG_ERROR ("enBTRCoreInvalidArg!!!");
5706  return -1;
5707  }
5708 
5709  if (!apstBTAdapterInfo->pcPath ||
5710  !(pathlen = strlen (apstBTAdapterInfo->pcPath)) ||
5711  strcmp(apstBTAdapterInfo->pcPath, lpstlhBTRCore->curAdapterPath)) {
5712  BTRCORELOG_INFO ("Dropping event for non-current adapter path %s\n", apstBTAdapterInfo->pcPath ? apstBTAdapterInfo->pcPath : "<null>");
5713  return -1;
5714  }
5715 
5716  lstAdapterInfo.adapter_number = atoi(apstBTAdapterInfo->pcPath+pathlen-1);
5717 
5718  BTRCORELOG_DEBUG ("adapter number = %d, path = %s, discovering = %d\n",
5719  lstAdapterInfo.adapter_number, apstBTAdapterInfo->pcPath, apstBTAdapterInfo->bDiscovering);
5720 
5721  switch (aeBtAdapterProp) {
5722  case enBTAdPropDiscoveryStatus: {
5723  lstAdapterInfo.discoverable = apstBTAdapterInfo->bDiscoverable;
5724  lstAdapterInfo.bDiscovering = apstBTAdapterInfo->bDiscovering;
5725 
5726  if ((lenBTRCoreRet = btrCore_OutTaskAddOp(lpstlhBTRCore->pGAQueueOutTask,
5727  enBTRCoreTaskOpProcess,
5728  enBTRCoreTaskPTcBAdapterStatus,
5729  &lstAdapterInfo)) != enBTRCoreSuccess) {
5730  BTRCORELOG_WARN("Failure btrCore_OutTaskAddOp enBTRCoreTaskOpProcess enBTRCoreTaskPTcBAdapterStatus %d\n", lenBTRCoreRet);
5731  }
5732  break;
5733  }
5734  case enBTAdPropUnknown: {
5735  break;
5736  }
5737  default:
5738  break;
5739  }
5740 
5741  return 0;
5742 }
5743 
5744 
5745 static int
5746 btrCore_BTDeviceStatusUpdateCb (
5747  enBTDeviceType aeBtDeviceType,
5748  enBTDeviceState aeBtDeviceState,
5749  stBTDeviceInfo* apstBTDeviceInfo,
5750  void* apUserData
5751 ) {
5752  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
5753  enBTRCoreDeviceType lenBTRCoreDevType = enBTRCoreUnknown;
5754 
5755 
5756  BTRCORELOG_INFO ("enBTDeviceType = %d enBTDeviceState = %d apstBTDeviceInfo = %p\n", aeBtDeviceType, aeBtDeviceState, apstBTDeviceInfo);
5757 
5758  lenBTRCoreDevType = btrCore_MapClassIDToDevType(apstBTDeviceInfo->ui32Class, aeBtDeviceType);
5759 
5760  switch (aeBtDeviceState) {
5761  case enBTDevStCreated: {
5762  break;
5763  }
5764  case enBTDevStScanInProgress: {
5765  break;
5766  }
5767  case enBTDevStFound: {
5768  stBTRCoreHdl* lpstlhBTRCore = (stBTRCoreHdl*)apUserData;
5769 
5770  if (lpstlhBTRCore && apstBTDeviceInfo) {
5771  int j = 0;
5772  tBTRCoreDevId lBTRCoreDevId = 0;
5773 
5774  BTRCORELOG_TRACE ("bPaired = %d\n", apstBTDeviceInfo->bPaired);
5775  BTRCORELOG_TRACE ("bConnected = %d\n", apstBTDeviceInfo->bConnected);
5776  BTRCORELOG_TRACE ("bTrusted = %d\n", apstBTDeviceInfo->bTrusted);
5777  BTRCORELOG_TRACE ("bBlocked = %d\n", apstBTDeviceInfo->bBlocked);
5778  BTRCORELOG_TRACE ("ui16Vendor = %d\n", apstBTDeviceInfo->ui16Vendor);
5779  BTRCORELOG_TRACE ("ui16VendorSource = %d\n", apstBTDeviceInfo->ui16VendorSource);
5780  BTRCORELOG_TRACE ("ui16Product = %d\n", apstBTDeviceInfo->ui16Product);
5781  BTRCORELOG_TRACE ("ui16Version = %d\n", apstBTDeviceInfo->ui16Version);
5782  BTRCORELOG_TRACE ("ui32Class = %d\n", apstBTDeviceInfo->ui32Class);
5783  BTRCORELOG_TRACE ("i32RSSI = %d\n", apstBTDeviceInfo->i32RSSI);
5784  BTRCORELOG_TRACE ("pcName = %s\n", apstBTDeviceInfo->pcName);
5785  BTRCORELOG_TRACE ("pcAddress = %s\n", apstBTDeviceInfo->pcAddress);
5786  BTRCORELOG_TRACE ("pcAlias = %s\n", apstBTDeviceInfo->pcAlias);
5787  BTRCORELOG_TRACE ("pcIcon = %s\n", apstBTDeviceInfo->pcIcon);
5788  BTRCORELOG_TRACE ("pcDevicePath = %s\n", apstBTDeviceInfo->pcDevicePath);
5789 
5790  for (j = 0; j < BT_MAX_DEVICE_PROFILE; j++) {
5791  if (apstBTDeviceInfo->aUUIDs[j][0] == '\0')
5792  break;
5793  else
5794  BTRCORELOG_INFO ("aUUIDs = %s\n", apstBTDeviceInfo->aUUIDs[j]);
5795  }
5796 
5797  lBTRCoreDevId = btrCore_GenerateUniqueDeviceID(apstBTDeviceInfo->pcAddress);
5798 
5799  if (btrCore_GetScannedDeviceAddress(lpstlhBTRCore, lBTRCoreDevId)) {
5800  BTRCORELOG_INFO ("Already we have a entry in the list; Skip Parsing now \n");
5801  }
5802  else {
5803  stBTRCoreOTskInData lstOTskInData;
5804 
5805  lstOTskInData.bTRCoreDevId = lBTRCoreDevId;
5806  lstOTskInData.enBTRCoreDevType = lenBTRCoreDevType;
5807  lstOTskInData.pstBTDevInfo = apstBTDeviceInfo;
5808 
5809  if ((lenBTRCoreRet = btrCore_OutTaskAddOp(lpstlhBTRCore->pGAQueueOutTask, enBTRCoreTaskOpProcess, enBTRCoreTaskPTcBDeviceDisc, &lstOTskInData)) != enBTRCoreSuccess) {
5810  BTRCORELOG_WARN("Failure btrCore_OutTaskAddOp enBTRCoreTaskOpProcess enBTRCoreTaskPTcBDeviceDisc %d\n", lenBTRCoreRet);
5811  }
5812  }
5813  }
5814 
5815  break;
5816  }
5817  case enBTDevStLost: {
5818  stBTRCoreHdl* lpstlhBTRCore = (stBTRCoreHdl*)apUserData;
5819 
5820  if (lpstlhBTRCore && apstBTDeviceInfo) {
5821  tBTRCoreDevId lBTRCoreDevId = btrCore_GenerateUniqueDeviceID(apstBTDeviceInfo->pcAddress);
5822 
5823  if (btrCore_GetKnownDeviceMac(lpstlhBTRCore, lBTRCoreDevId)) {
5824  stBTRCoreOTskInData lstOTskInData;
5825 
5826  lstOTskInData.bTRCoreDevId = lBTRCoreDevId;
5827  lstOTskInData.enBTRCoreDevType = lenBTRCoreDevType;
5828  lstOTskInData.pstBTDevInfo = apstBTDeviceInfo;
5829 
5830  if ((lenBTRCoreRet = btrCore_OutTaskAddOp(lpstlhBTRCore->pGAQueueOutTask, enBTRCoreTaskOpProcess, enBTRCoreTaskPTcBDeviceLost, &lstOTskInData)) != enBTRCoreSuccess) {
5831  BTRCORELOG_WARN("Failure btrCore_OutTaskAddOp enBTRCoreTaskOpProcess enBTRCoreTaskPTcBDeviceLost%d\n", lenBTRCoreRet);
5832  }
5833  }
5834  else if (btrCore_GetScannedDeviceAddress(lpstlhBTRCore, lBTRCoreDevId)) {
5835  stBTRCoreOTskInData lstOTskInData;
5836 
5837  lstOTskInData.bTRCoreDevId = lBTRCoreDevId;
5838  lstOTskInData.enBTRCoreDevType = lenBTRCoreDevType;
5839  lstOTskInData.pstBTDevInfo = apstBTDeviceInfo;
5840 
5841  if ((lenBTRCoreRet = btrCore_OutTaskAddOp(lpstlhBTRCore->pGAQueueOutTask, enBTRCoreTaskOpProcess, enBTRCoreTaskPTcBDeviceRemoved, &lstOTskInData)) != enBTRCoreSuccess) {
5842  BTRCORELOG_WARN("Failure btrCore_OutTaskAddOp enBTRCoreTaskOpProcess enBTRCoreTaskPTcBDeviceRemoved %d\n", lenBTRCoreRet);
5843  }
5844  }
5845  else {
5846  BTRCORELOG_INFO ("We dont have a entry in the list; Skip Parsing now \n");
5847  }
5848  }
5849  break;
5850  }
5851  case enBTDevStPairingRequest: {
5852  break;
5853  }
5854  case enBTDevStPairingInProgress: {
5855  break;
5856  }
5857  case enBTDevStPaired: {
5858  break;
5859  }
5860  case enBTDevStUnPaired: {
5861  break;
5862  }
5863  case enBTDevStConnectInProgress: {
5864  break;
5865  }
5866  case enBTDevStConnected: {
5867  break;
5868  }
5869  case enBTDevStDisconnected: {
5870  break;
5871  }
5872  case enBTDevStPropChanged: {
5873  stBTRCoreHdl* lpstlhBTRCore = (stBTRCoreHdl*)apUserData;
5874 
5875  if (lpstlhBTRCore && apstBTDeviceInfo) {
5876  tBTRCoreDevId lBTRCoreDevId = btrCore_GenerateUniqueDeviceID(apstBTDeviceInfo->pcAddress);
5877 
5878  if (btrCore_GetKnownDeviceMac(lpstlhBTRCore, lBTRCoreDevId)) {
5879  stBTRCoreOTskInData lstOTskInData;
5880 
5881  lstOTskInData.bTRCoreDevId = lBTRCoreDevId;
5882  lstOTskInData.enBTRCoreDevType = lenBTRCoreDevType;
5883  lstOTskInData.pstBTDevInfo = apstBTDeviceInfo;
5884 
5885  if ((lenBTRCoreRet = btrCore_OutTaskAddOp(lpstlhBTRCore->pGAQueueOutTask, enBTRCoreTaskOpProcess, enBTRCoreTaskPTcBDeviceStatus, &lstOTskInData)) != enBTRCoreSuccess) {
5886  BTRCORELOG_WARN("Failure btrCore_OutTaskAddOp enBTRCoreTaskOpProcess enBTRCoreTaskPTcBDeviceStatus %d\n", lenBTRCoreRet);
5887  }
5888  }
5889  else if (btrCore_GetScannedDeviceAddress(lpstlhBTRCore, lBTRCoreDevId)) {
5890  stBTRCoreOTskInData lstOTskInData;
5891 
5892  lstOTskInData.bTRCoreDevId = lBTRCoreDevId;
5893  lstOTskInData.enBTRCoreDevType = lenBTRCoreDevType;
5894  lstOTskInData.pstBTDevInfo = apstBTDeviceInfo;
5895 
5896  if ((lenBTRCoreRet = btrCore_OutTaskAddOp(lpstlhBTRCore->pGAQueueOutTask, enBTRCoreTaskOpProcess, enBTRCoreTaskPTcBDeviceStatus, &lstOTskInData)) != enBTRCoreSuccess) {
5897  BTRCORELOG_WARN("Failure btrCore_OutTaskAddOp enBTRCoreTaskOpProcess enBTRCoreTaskPTcBDeviceStatus %d\n", lenBTRCoreRet);
5898  }
5899  }
5900  }
5901 
5902  break;
5903  }
5904  case enBTDevStRSSIUpdate: {
5905  BTRCORELOG_INFO ("Received RSSI Update...\n");
5906  break;
5907  }
5908  case enBTDevStUnknown: {
5909  break;
5910  }
5911  default: {
5912  break;
5913  }
5914  }
5915 
5916  return 0;
5917 }
5918 
5919 
5920 static int
5921 btrCore_BTDeviceConnectionIntimationCb (
5922  enBTDeviceType aeBtDeviceType,
5923  stBTDeviceInfo* apstBTDeviceInfo,
5924  unsigned int aui32devPassKey,
5925  unsigned char ucIsReqConfirmation,
5926  void* apUserData
5927 ) {
5928  int i32DevConnIntimRet = 0;
5929  stBTRCoreHdl* lpstlhBTRCore = (stBTRCoreHdl*)apUserData;
5930  enBTRCoreDeviceType lenBTRCoreDevType = enBTRCoreUnknown;
5931 
5932  lenBTRCoreDevType = btrCore_MapClassIDToDevType(apstBTDeviceInfo->ui32Class, aeBtDeviceType);
5933 
5934 
5935  if (lpstlhBTRCore) {
5936  stBTRCoreBTDevice lstFoundDevice;
5937  int i32ScannedDevIdx = -1;
5938 
5939  if ((i32ScannedDevIdx = btrCore_AddDeviceToScannedDevicesArr(lpstlhBTRCore, apstBTDeviceInfo, &lstFoundDevice)) != -1) {
5940  BTRCORELOG_DEBUG ("btrCore_AddDeviceToScannedDevicesArr - Success Index = %d\n", i32ScannedDevIdx);
5941  }
5942 
5943  BTRCORELOG_DEBUG("btrCore_BTDeviceConnectionIntimationCb\n");
5944  lpstlhBTRCore->stConnCbInfo.ui32devPassKey = aui32devPassKey;
5945  lpstlhBTRCore->stConnCbInfo.ucIsReqConfirmation = ucIsReqConfirmation;
5946 
5947  if (apstBTDeviceInfo->pcName)
5948  strncpy(lpstlhBTRCore->stConnCbInfo.cConnAuthDeviceName, apstBTDeviceInfo->pcName, (strlen(apstBTDeviceInfo->pcName) < (BTRCORE_STR_LEN - 1)) ? strlen(apstBTDeviceInfo->pcName) : BTRCORE_STR_LEN - 1);
5949 
5950 
5951  memcpy (&lpstlhBTRCore->stConnCbInfo.stFoundDevice, &lstFoundDevice, sizeof(stBTRCoreBTDevice));
5952  lpstlhBTRCore->stConnCbInfo.stFoundDevice.bFound = TRUE;
5953 
5954  if ((lenBTRCoreDevType == enBTRCoreMobileAudioIn) || (lenBTRCoreDevType == enBTRCorePCAudioIn) || (lenBTRCoreDevType == enBTRCoreHID)) {
5955  if (lpstlhBTRCore->fpcBBTRCoreConnIntim) {
5956  if (lpstlhBTRCore->fpcBBTRCoreConnIntim(&lpstlhBTRCore->stConnCbInfo, &i32DevConnIntimRet, lpstlhBTRCore->pvcBConnIntimUserData) != enBTRCoreSuccess) {
5957  //TODO: Triggering Outgoing callbacks from Incoming callbacks..aaaaaaaahhhh not a good idea
5958  }
5959  }
5960  }
5961  else if ((lenBTRCoreDevType == enBTRCoreSpeakers) || (lenBTRCoreDevType == enBTRCoreHeadSet)) {
5962  if (lpstlhBTRCore->numOfPairedDevices) {
5963  unsigned int i32LoopIdx = 0;
5964 
5965  //TODO: Even before we loop, check if we are already connected and playing Audio-Out
5966  for (i32LoopIdx = 0; i32LoopIdx < lpstlhBTRCore->numOfPairedDevices; i32LoopIdx++) {
5967  if (lpstlhBTRCore->stKnownDevicesArr[i32LoopIdx].tDeviceId == lpstlhBTRCore->stConnCbInfo.stFoundDevice.tDeviceId) {
5968  BTRCORELOG_DEBUG("ACCEPT INCOMING INTIMATION stKnownDevice : %s", lpstlhBTRCore->stKnownDevicesArr[i32LoopIdx].pcDeviceName);
5969  i32DevConnIntimRet = 1;
5970  }
5971  }
5972  }
5973  }
5974  else {
5975  i32DevConnIntimRet = 1; // SM - hack to allow incoming pairing request for LE devices/characteristics with secure write/read
5976  }
5977  }
5978 
5979  return i32DevConnIntimRet;
5980 }
5981 
5982 static int
5983 btrCore_BTDeviceAuthenticationCb (
5984  enBTDeviceType aeBtDeviceType,
5985  stBTDeviceInfo* apstBTDeviceInfo,
5986  void* apUserData
5987 ) {
5988  int i32DevAuthRet = 0;
5989  stBTRCoreHdl* lpstlhBTRCore = (stBTRCoreHdl*)apUserData;
5990  enBTRCoreDeviceType lenBTRCoreDevType = enBTRCoreUnknown;
5991 
5992  lenBTRCoreDevType = btrCore_MapClassIDToDevType(apstBTDeviceInfo->ui32Class, aeBtDeviceType);
5993 
5994 
5995  if (lpstlhBTRCore) {
5996  stBTRCoreBTDevice lstFoundDevice;
5997  int i32ScannedDevIdx = -1;
5998  int i32KnownDevIdx = -1;
5999 
6000  if ((i32ScannedDevIdx = btrCore_AddDeviceToScannedDevicesArr(lpstlhBTRCore, apstBTDeviceInfo, &lstFoundDevice)) != -1) {
6001  BTRCORELOG_DEBUG ("btrCore_AddDeviceToScannedDevicesArr - Success Index = %d\n", i32ScannedDevIdx);
6002  }
6003 
6004  BTRCORELOG_DEBUG("btrCore_BTDeviceAuthenticationCb\n");
6005  if (apstBTDeviceInfo->pcName)
6006  strncpy(lpstlhBTRCore->stConnCbInfo.cConnAuthDeviceName, apstBTDeviceInfo->pcName, (strlen(apstBTDeviceInfo->pcName) < (BTRCORE_STR_LEN - 1)) ? strlen(apstBTDeviceInfo->pcName) : BTRCORE_STR_LEN - 1);
6007 
6008 
6009  if ((i32KnownDevIdx = btrCore_AddDeviceToKnownDevicesArr(lpstlhBTRCore, apstBTDeviceInfo)) != -1) {
6010  memcpy (&lpstlhBTRCore->stConnCbInfo.stKnownDevice, &lpstlhBTRCore->stKnownDevicesArr[i32KnownDevIdx], sizeof(stBTRCoreBTDevice));
6011  BTRCORELOG_DEBUG ("btrCore_AddDeviceToKnownDevicesArr - Success Index = %d Unique DevID = %lld\n", i32KnownDevIdx, lpstlhBTRCore->stConnCbInfo.stKnownDevice.tDeviceId);
6012  }
6013 
6014  if (lpstlhBTRCore->fpcBBTRCoreConnAuth) {
6015  if (lpstlhBTRCore->fpcBBTRCoreConnAuth(&lpstlhBTRCore->stConnCbInfo, &i32DevAuthRet, lpstlhBTRCore->pvcBConnAuthUserData) != enBTRCoreSuccess) {
6016  //TODO: Triggering Outgoing callbacks from Incoming callbacks..aaaaaaaahhhh not a good idea
6017  }
6018  }
6019 
6020 
6021  if (lpstlhBTRCore->numOfPairedDevices && i32DevAuthRet) {
6022 
6023  if ((lenBTRCoreDevType == enBTRCoreMobileAudioIn) ||
6024  (lenBTRCoreDevType == enBTRCorePCAudioIn)) {
6025  unsigned int i32LoopIdx = 0;
6026 
6027  for (i32LoopIdx = 0; i32LoopIdx < lpstlhBTRCore->numOfPairedDevices; i32LoopIdx++) {
6028  if (lpstlhBTRCore->stKnownDevicesArr[i32LoopIdx].tDeviceId == lpstlhBTRCore->stConnCbInfo.stKnownDevice.tDeviceId) {
6029 
6030  if (lpstlhBTRCore->stKnownDevStInfoArr[i32LoopIdx].eDeviceCurrState == enBTRCoreDevStInitialized) {
6031  lpstlhBTRCore->stKnownDevStInfoArr[i32LoopIdx].eDevicePrevState = lpstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDevicePrevState;
6032  lpstlhBTRCore->stKnownDevStInfoArr[i32LoopIdx].eDeviceCurrState = lpstlhBTRCore->stScannedDevStInfoArr[i32ScannedDevIdx].eDeviceCurrState;
6033  }
6034 
6035  lpstlhBTRCore->stConnCbInfo.stKnownDevice.bDeviceConnected = TRUE;
6036  lpstlhBTRCore->stKnownDevicesArr[i32LoopIdx].bDeviceConnected = TRUE;
6037  BTRCORELOG_DEBUG("stKnownDevice.device_connected set : %d\n", lpstlhBTRCore->stKnownDevicesArr[i32LoopIdx].bDeviceConnected);
6038  }
6039  }
6040  }
6041  else if ((lenBTRCoreDevType == enBTRCoreSpeakers) ||
6042  (lenBTRCoreDevType == enBTRCoreHeadSet)) {
6043  unsigned int i32LoopIdx = 0;
6044 
6045  //TODO: Even before we loop, check if we are already connected and playing Audio-Out
6046  for (i32LoopIdx = 0; i32LoopIdx < lpstlhBTRCore->numOfPairedDevices; i32LoopIdx++) {
6047  if (lpstlhBTRCore->stKnownDevicesArr[i32LoopIdx].tDeviceId == lpstlhBTRCore->stConnCbInfo.stKnownDevice.tDeviceId) {
6048  BTRCORELOG_DEBUG("ACCEPTED INCOMING CONNECT stKnownDevice : %s\n", lpstlhBTRCore->stKnownDevicesArr[i32LoopIdx].pcDeviceName);
6049  if ((lpstlhBTRCore->stKnownDevStInfoArr[i32LoopIdx].eDevicePrevState != enBTRCoreDevStPlaying) &&
6050  (lpstlhBTRCore->stKnownDevStInfoArr[i32LoopIdx].eDeviceCurrState != enBTRCoreDevStConnected)) {
6051  lpstlhBTRCore->stKnownDevStInfoArr[i32LoopIdx].eDevicePrevState = lpstlhBTRCore->stKnownDevStInfoArr[i32LoopIdx].eDeviceCurrState;
6052 
6053  if (lpstlhBTRCore->stKnownDevStInfoArr[i32LoopIdx].eDeviceCurrState != enBTRCoreDevStPlaying)
6054  lpstlhBTRCore->stKnownDevStInfoArr[i32LoopIdx].eDeviceCurrState = enBTRCoreDevStConnected;
6055  }
6056  }
6057  }
6058  }
6059  else if ((lenBTRCoreDevType == enBTRCoreHID) &&
6060  strstr(apstBTDeviceInfo->pcName, "Xbox")) {
6061  if (BtrCore_BTDisableEnhancedRetransmissionMode(lpstlhBTRCore->connHdl) != 0) {
6062  BTRCORELOG_ERROR ("Failed to Disable ERTM\n");
6063  }
6064  }
6065  }
6066 
6067  }
6068 
6069  return i32DevAuthRet;
6070 }
6071 
6072 
6073 static enBTRCoreRet
6074 btrCore_BTMediaStatusUpdateCb (
6075  stBTRCoreAVMediaStatusUpdate* apMediaStreamStatus,
6076  const char* apBtdevAddr,
6077  void* apUserData
6078 ) {
6079  stBTRCoreHdl* lpstlhBTRCore = (stBTRCoreHdl*)apUserData;
6080  enBTRCoreRet lenBTRCoreRet = enBTRCoreSuccess;
6081  tBTRCoreDevId lBTRCoreDevId = 0;
6082  stBTRCoreMediaStatusCBInfo lstMediaStatusUpdateCbInfo;
6083 
6084 
6085  if (!apMediaStreamStatus || !apBtdevAddr || !apUserData) {
6086  BTRCORELOG_ERROR ("enBTRCoreInvalidArg!!!");
6087  return enBTRCoreInvalidArg;
6088  }
6089 
6090 
6091  lBTRCoreDevId = btrCore_GenerateUniqueDeviceID(apBtdevAddr);
6092  if (!btrCore_GetKnownDeviceMac(lpstlhBTRCore, lBTRCoreDevId)) {
6093  BTRCORELOG_INFO ("We dont have a entry in the list; Skip Parsing now \n");
6094  return enBTRCoreDeviceNotFound;
6095  }
6096 
6097  memset (&lstMediaStatusUpdateCbInfo, 0, sizeof(stBTRCoreMediaStatusCBInfo));
6098 
6099  switch (apMediaStreamStatus->eAVMediaState) {
6100 
6101  case eBTRCoreAVMediaTrkStStarted:
6102  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.eBTMediaStUpdate = eBTRCoreMediaTrkStStarted;
6103  memcpy (&lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.m_mediaPositionInfo, &apMediaStreamStatus->m_mediaPositionInfo, sizeof(stBTRCoreMediaPositionInfo));
6104  break;
6105  case eBTRCoreAVMediaTrkStPlaying:
6106  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.eBTMediaStUpdate = eBTRCoreMediaTrkStPlaying;
6107  memcpy (&lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.m_mediaPositionInfo, &apMediaStreamStatus->m_mediaPositionInfo, sizeof(stBTRCoreMediaPositionInfo));
6108  break;
6109  case eBTRCoreAVMediaTrkStPaused:
6110  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.eBTMediaStUpdate = eBTRCoreMediaTrkStPaused;
6111  memcpy (&lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.m_mediaPositionInfo, &apMediaStreamStatus->m_mediaPositionInfo, sizeof(stBTRCoreMediaPositionInfo));
6112  break;
6113  case eBTRCoreAVMediaTrkStStopped:
6114  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.eBTMediaStUpdate = eBTRCoreMediaTrkStStopped;
6115  memcpy (&lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.m_mediaPositionInfo, &apMediaStreamStatus->m_mediaPositionInfo, sizeof(stBTRCoreMediaPositionInfo));
6116  break;
6117  case eBTRCoreAVMediaTrkStChanged:
6118  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.eBTMediaStUpdate = eBTRCoreMediaTrkStChanged;
6119  memcpy (&lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.m_mediaTrackInfo, &apMediaStreamStatus->m_mediaTrackInfo, sizeof(stBTRCoreMediaTrackInfo));
6120  break;
6121  case eBTRCoreAVMediaTrkPosition:
6122  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.eBTMediaStUpdate = eBTRCoreMediaTrkPosition;
6123  memcpy (&lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.m_mediaTrackInfo, &apMediaStreamStatus->m_mediaTrackInfo, sizeof(stBTRCoreMediaTrackInfo));
6124  break;
6125  case eBTRCoreAVMediaPlaybackEnded:
6126  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.eBTMediaStUpdate = eBTRCoreMediaPlaybackEnded;
6127  break;
6128  case eBTRCoreAVMediaPlyrName:
6129  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.eBTMediaStUpdate = eBTRCoreMediaPlyrName;
6130  strncpy (lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.m_mediaPlayerName, apMediaStreamStatus->m_mediaPlayerName, BTRCORE_MAX_STR_LEN -1);
6131  break;
6132  case eBTRCoreAVMediaPlyrEqlzrStOff:
6133  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.eBTMediaStUpdate = eBTRCoreMediaPlyrEqlzrStOff;
6134  break;
6135  case eBTRCoreAVMediaPlyrEqlzrStOn:
6136  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.eBTMediaStUpdate = eBTRCoreMediaPlyrEqlzrStOn;
6137  break;
6138  case eBTRCoreAVMediaPlyrShflStOff:
6139  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.eBTMediaStUpdate = eBTRCoreMediaPlyrShflStOff;
6140  break;
6141  case eBTRCoreAVMediaPlyrShflStAllTracks:
6142  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.eBTMediaStUpdate = eBTRCoreMediaPlyrShflStAllTracks;
6143  break;
6144  case eBTRCoreAVMediaPlyrShflStGroup:
6145  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.eBTMediaStUpdate = eBTRCoreMediaPlyrShflStGroup;
6146  break;
6147  case eBTRCoreAVMediaPlyrRptStOff:
6148  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.eBTMediaStUpdate = eBTRCoreMediaPlyrRptStOff;
6149  break;
6150  case eBTRCoreAVMediaPlyrRptStSingleTrack:
6151  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.eBTMediaStUpdate = eBTRCoreMediaPlyrRptStSingleTrack;
6152  break;
6153  case eBTRCoreAVMediaPlyrRptStAllTracks:
6154  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.eBTMediaStUpdate = eBTRCoreMediaPlyrRptStAllTracks;
6155  break;
6156  case eBTRCoreAVMediaPlyrRptStGroup:
6157  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.eBTMediaStUpdate = eBTRCoreMediaPlyrRptStGroup;
6158  break;
6159  case eBTRCoreAVMediaPlyrVolume:
6160  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.eBTMediaStUpdate = eBTRCoreMediaPlyrVolume;
6161  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.m_mediaPlayerVolume = apMediaStreamStatus->m_mediaPlayerTransportVolume;
6162  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.bIsMediaCtrlAvailable = (apMediaStreamStatus->bIsAVMediaCtrlAvail == 1) ? TRUE : FALSE;
6163  break;
6164  case eBTRCoreAVMediaElementAdded:
6165  {
6166  stBTRCoreMediaElementInfo* mediaElement = &lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.m_mediaElementInfo;
6167 
6168  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.eBTMediaStUpdate = eBTRCoreMediaElementInScope;
6169 
6170  mediaElement->ui32MediaElementId = apMediaStreamStatus->m_mediaElementInfo.ui32AVMediaElementId;
6171  mediaElement->eAVMedElementType = btrCore_GetMediaElementType (apMediaStreamStatus->m_mediaElementInfo.eAVMElementType);
6172 
6173  if ((mediaElement->bIsPlayable = apMediaStreamStatus->m_mediaElementInfo.bIsPlayable)) {
6174  memcpy (&mediaElement->m_mediaTrackInfo, &apMediaStreamStatus->m_mediaElementInfo.m_mediaTrackInfo, sizeof(stBTRCoreMediaTrackInfo));
6175  }
6176  else {
6177  strncpy (mediaElement->m_mediaElementName, apMediaStreamStatus->m_mediaElementInfo.m_mediaElementName, BTRCORE_MAX_STR_LEN -1);
6178  }
6179  }
6180  break;
6181  case eBTRCoreAVMediaElementRemoved:
6182  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.eBTMediaStUpdate = eBTRCoreMediaElementOofScope;
6183  lstMediaStatusUpdateCbInfo.m_mediaStatusUpdate.m_mediaElementInfo.ui32MediaElementId = apMediaStreamStatus->m_mediaElementInfo.ui32AVMediaElementId;
6184  break;
6185 
6186  default:
6187  break;
6188  }
6189 
6190  lstMediaStatusUpdateCbInfo.deviceId = lBTRCoreDevId;
6191 
6192  if ((lenBTRCoreRet = btrCore_OutTaskAddOp(lpstlhBTRCore->pGAQueueOutTask, enBTRCoreTaskOpProcess, enBTRCoreTaskPTcBMediaStatus, &lstMediaStatusUpdateCbInfo)) != enBTRCoreSuccess) {
6193  BTRCORELOG_WARN("Failure btrCore_OutTaskAddOp enBTRCoreTaskOpProcess enBTRCoreTaskPTcBMediaStatus %d\n", lenBTRCoreRet);
6194  lenBTRCoreRet = enBTRCoreFailure;
6195  }
6196 
6197 
6198  return lenBTRCoreRet;
6199 }
6200 
6201 
6202 static enBTRCoreRet
6203 btrCore_BTLeStatusUpdateCb (
6204  stBTRCoreLeGattInfo* apstBtrLeInfo,
6205  const char* apcBtdevAddr,
6206  void* apvUserData
6207 ) {
6208  stBTRCoreHdl* lpstlhBTRCore = (stBTRCoreHdl*)apvUserData;
6209  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
6210  enBTDeviceType lenBTDeviceType = enBTDevUnknown;
6211  stBTRCoreBTDevice* lpstScannedDevice = NULL;
6212  stBTRCoreDevStateInfo* lpstScannedDevStInfo= NULL;
6213  const char* pDevicePath = NULL;
6214  const char* pDeviceName = NULL;
6215  tBTRCoreDevId lBTRCoreDevId = 0;
6216  stBTRCoreDevStatusCBInfo lstDevStatusCbInfo;
6217 
6218 
6219  if (!apstBtrLeInfo || !apcBtdevAddr || !apvUserData) {
6220  BTRCORELOG_ERROR ("enBTRCoreInvalidArg!!!\n");
6221  return enBTRCoreInvalidArg;
6222  }
6223 
6224 
6225  //TODO : Look if we can get the infos from the CB itslef
6226  lBTRCoreDevId = btrCore_GenerateUniqueDeviceID(apcBtdevAddr);
6227  if ((lenBTRCoreRet = btrCore_GetDeviceInfo(lpstlhBTRCore, lBTRCoreDevId, enBTRCoreLE, &lenBTDeviceType,
6228  &lpstScannedDevice, &lpstScannedDevStInfo, &pDevicePath, &pDeviceName)) != enBTRCoreSuccess) {
6229  BTRCORELOG_ERROR ("Failed to find Device in ScannedList!\n");
6230  return enBTRCoreDeviceNotFound;
6231  }
6232 
6233 
6234  BTRCORELOG_DEBUG ("LE Dev %s Path %s\n", pDeviceName, pDevicePath);
6235 
6236  lstDevStatusCbInfo.deviceId = lBTRCoreDevId;
6237  lstDevStatusCbInfo.eDeviceType = enBTRCoreLE;
6238  lstDevStatusCbInfo.eDeviceClass = lpstScannedDevice->enDeviceType;
6239  lstDevStatusCbInfo.ui32DevClassBtSpec = lpstScannedDevice->ui32DevClassBtSpec;
6240  lstDevStatusCbInfo.isPaired = 0;
6241  lstDevStatusCbInfo.eDevicePrevState = lpstScannedDevStInfo->eDeviceCurrState;
6242  strncpy(lstDevStatusCbInfo.deviceName, pDeviceName, BD_NAME_LEN);
6243  strncpy(lstDevStatusCbInfo.deviceAddress, apcBtdevAddr, BTRCORE_MAX_STR_LEN - 1);
6244 
6245  lstDevStatusCbInfo.eCoreLeProp = apstBtrLeInfo->enLeProp;
6246  lstDevStatusCbInfo.eDeviceType = enBTRCoreLE;
6247  lstDevStatusCbInfo.eCoreLeOper = apstBtrLeInfo->enLeOper;
6248 
6249  switch (apstBtrLeInfo->enLeOper) {
6250  case enBTRCoreLEGOpReady:
6251  lstDevStatusCbInfo.eDeviceCurrState = enBTRCoreDevStOpReady;
6252  strncpy(lstDevStatusCbInfo.devOpResponse, apstBtrLeInfo->pui8Value, BTRCORE_MAX_DEV_OP_DATA_LEN - 1);
6253  break;
6254  case enBTRCoreLEGOpReadValue:
6255  lstDevStatusCbInfo.eDeviceCurrState = enBTRCoreDevStOpInfo;
6256  strncpy(lstDevStatusCbInfo.uuid, apstBtrLeInfo->pui8Uuid, BTRCORE_UUID_LEN - 1);
6257  memset(lstDevStatusCbInfo.devOpResponse, '\0', BTRCORE_MAX_DEV_OP_DATA_LEN);
6258  strncpy(lstDevStatusCbInfo.devOpResponse, apstBtrLeInfo->pui8Value, BTRCORE_MAX_DEV_OP_DATA_LEN - 1);
6259  break;
6260  case enBTRCoreLEGOpWriteValue:
6261  lstDevStatusCbInfo.eDeviceCurrState = enBTRCoreDevStOpInfo;
6262  strncpy(lstDevStatusCbInfo.uuid, apstBtrLeInfo->pui8Uuid, BTRCORE_UUID_LEN - 1);
6263  memset(lstDevStatusCbInfo.devOpResponse, '\0', BTRCORE_MAX_DEV_OP_DATA_LEN);
6264  strncpy(lstDevStatusCbInfo.devOpResponse, apstBtrLeInfo->pui8Value, BTRCORE_MAX_DEV_OP_DATA_LEN - 1);
6265  break;
6266  case enBTRCoreLEGOpStartNotify:
6267  lstDevStatusCbInfo.eDeviceCurrState = enBTRCoreDevStOpInfo;
6268  memset(lstDevStatusCbInfo.devOpResponse, '\0', BTRCORE_MAX_DEV_OP_DATA_LEN);
6269  strncpy(lstDevStatusCbInfo.devOpResponse, apstBtrLeInfo->pui8Value, BTRCORE_MAX_DEV_OP_DATA_LEN - 1);
6270  break;
6271  case enBTRCoreLEGOpStopNotify:
6272  lstDevStatusCbInfo.eDeviceCurrState = enBTRCoreDevStOpInfo;
6273  memset(lstDevStatusCbInfo.devOpResponse, '\0', BTRCORE_MAX_DEV_OP_DATA_LEN);
6274  strncpy(lstDevStatusCbInfo.devOpResponse, apstBtrLeInfo->pui8Value, BTRCORE_MAX_DEV_OP_DATA_LEN - 1);
6275  break;
6276  case enBTRCoreLEGOpUnknown:
6277  default:
6278  break;
6279  }
6280 
6281  if ((enBTRCoreLEGOpReadValue == apstBtrLeInfo->enLeOper) && (lpstScannedDevice->enDeviceType != enBTRCore_DC_Tile)) {
6282  if (lpstlhBTRCore->fpcBBTRCoreStatus) {
6283  BTRCORELOG_INFO(" Not adding to the task queue !!!!!!\n");
6284  /* Invoke the callback */
6285  if (enBTRCoreSuccess != lpstlhBTRCore->fpcBBTRCoreStatus(&lstDevStatusCbInfo, lpstlhBTRCore->pvcBStatusUserData) ) {
6286  BTRCORELOG_ERROR(" CallBack Error !!!!!!\n");
6287  lenBTRCoreRet = enBTRCoreFailure;
6288  }
6289  else {
6290  strncpy(apstBtrLeInfo->pui8Value, lstDevStatusCbInfo.devOpResponse, BTRCORE_MAX_DEV_OP_DATA_LEN - 1);
6291  }
6292  }
6293  }
6294  else {
6295  if ((lenBTRCoreRet = btrCore_OutTaskAddOp(lpstlhBTRCore->pGAQueueOutTask, enBTRCoreTaskOpProcess, enBTRCoreTaskPTcBDevOpInfoStatus, &lstDevStatusCbInfo)) != enBTRCoreSuccess) {
6296  BTRCORELOG_WARN("Failure btrCore_OutTaskAddOp enBTRCoreTaskOpProcess enBTRCoreTaskPTcBDeviceStatus %d\n", lenBTRCoreRet);
6297  }
6298  }
6299 
6300 
6301  return lenBTRCoreRet;
6302 }
6303 
6304 BOOLEAN btrCore_IsDevNameSameAsAddress(const stBTRCoreBTDevice *dev)
6305 {
6306  const char *name = &dev->pcDeviceName[0];
6307  const char *mac = &dev->pcDeviceAddress[0];
6308 
6309  // comparing
6310  // "14:CB:65:F9:57:FC" with
6311  // "14-CB-65-F9-57-FC"
6312  #define btrCore_ByteCompare(A) (name[A] == mac[A])
6313 
6314  BOOLEAN same =
6315  btrCore_ByteCompare(0) && btrCore_ByteCompare(1) &&
6316  // skip 2
6317  btrCore_ByteCompare(3) && btrCore_ByteCompare(4) &&
6318  // skip 5
6319  btrCore_ByteCompare(6) && btrCore_ByteCompare(7) &&
6320  // skip 8
6321  btrCore_ByteCompare(9) && btrCore_ByteCompare(10) &&
6322  // skip 11
6323  btrCore_ByteCompare(12) && btrCore_ByteCompare(13) &&
6324  // skip 14
6325  btrCore_ByteCompare(15) && btrCore_ByteCompare(16);
6326 
6327  return same;
6328 }
6329 /* End of File */
BtrCore_BTStopDiscovery
int BtrCore_BTStopDiscovery(void *apBtConn, const char *apBtAdapter, const char *apBtAgentPath)
This API is used to stop discovering Bluetooth adapter.
Definition: btrCore_dbus_bluez4.c:1931
BTRCore_GetAdapterAddr
enBTRCoreRet BTRCore_GetAdapterAddr(tBTRCoreHandle hBTRCore, unsigned char aui8adapterIdx, char *apui8adapterAddr)
This API gets Address of BT Adapter.
Definition: btrCore.c:3065
_stBTRCoreBTDevice
Definition: btrCore.h:318
BTRCore_SetEnableTxPower
enBTRCoreRet BTRCore_SetEnableTxPower(tBTRCoreHandle hBTRCore, BOOLEAN aTxPower)
This API is used to Enable Tx Power transmission.
Definition: btrCore.c:5454
BTRCore_Init
enBTRCoreRet BTRCore_Init(tBTRCoreHandle *phBTRCore)
This API connects to a bus daemon and registers the client with it.
Definition: btrCore.c:2494
BOOLEAN
unsigned char BOOLEAN
DTCP Manager return codes.
Definition: dtcpmgr.h:163
_stBTDeviceSupportedServiceList
Definition: btrCore_bt_ifce.h:684
BtrCore_BTEnableEnhancedRetransmissionMode
int BtrCore_BTEnableEnhancedRetransmissionMode(void *apstBtIfceHdl)
This API is used to Enable Enhanced Retransmission on all BT adapter.
Definition: btrCore_dbus_bluez5.c:5494
BTRCore_GetAdapters
enBTRCoreRet BTRCore_GetAdapters(tBTRCoreHandle hBTRCore, stBTRCoreGetAdapters *pstGetAdapters)
This API returns the value of org.bluez.Manager.Getadapters .
Definition: btrCore.c:2899
BTRCore_DisableAdapter
enBTRCoreRet BTRCore_DisableAdapter(tBTRCoreHandle hBTRCore, stBTRCoreAdapter *apstBTRCoreAdapter)
This API disables specific adapter.
Definition: btrCore.c:3036
_stBTRCoreOTskInData
Definition: btrCore.c:83
BtrCore_BTUnregisterAgent
int BtrCore_BTUnregisterAgent(void *apBtConn, const char *apBtAdapter, const char *apBtAgentPath)
Using this API, DBus object path is unregistered with bluetooth agent path and current adapter's path...
Definition: btrCore_dbus_bluez4.c:1336
BTRCore_SetAdapterDeviceName
enBTRCoreRet BTRCore_SetAdapterDeviceName(tBTRCoreHandle hBTRCore, stBTRCoreAdapter *apstBTRCoreAdapter, char *apcAdapterDeviceName)
This API sets a friendly name to BT adapter device.
Definition: btrCore.c:3194
_stBTRMgrAVMediaPcmInfo
Definition: btrCore_avMedia.h:132
_stBTAdapterInfo
Definition: btrCore_bt_ifce.h:625
BTRCore_GetLEProperty
enBTRCoreRet BTRCore_GetLEProperty(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId, const char *apcBTRCoreLEUuid, enBTRCoreLeProp aenBTRCoreLeProp, void *apvBTRCorePropValue)
This API returns the Low energy profile device name and address.
Definition: btrCore.c:5173
BTRCore_GetDeviceDisconnected
enBTRCoreRet BTRCore_GetDeviceDisconnected(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId, enBTRCoreDeviceType aenBTRCoreDevType)
This method checks the current device that is disconnected.
Definition: btrCore.c:4111
BtrCore_BTGetPairedDeviceInfo
int BtrCore_BTGetPairedDeviceInfo(void *apBtConn, const char *apBtAdapter, stBTPairedDeviceInfo *pPairedDeviceInfo)
This API fetches all BT paired devices' device information.
Definition: btrCore_dbus_bluez4.c:1986
BTRCore_AcquireDeviceDataPath
enBTRCoreRet BTRCore_AcquireDeviceDataPath(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId, enBTRCoreDeviceType aenBTRCoreDevType, int *aiDataPath, int *aidataReadMTU, int *aidataWriteMTU, unsigned int *apui32Delay)
This API returns the bluetooth device address.
Definition: btrCore.c:4415
BTRCore_GetPropertyValue
enBTRCoreRet BTRCore_GetPropertyValue(tBTRCoreHandle hBTRCore, char *aUUID, char *aValue, enBTRCoreLeProp aElement)
This API is used to Get Property value.
Definition: btrCore.c:5383
BtrCore_BTReleaseAdapterPath
int BtrCore_BTReleaseAdapterPath(void *apBtConn, const char *apBtAdapter)
Using this API the path assigned to the current Bluetooth Adapter is released.
Definition: btrCore_dbus_bluez4.c:1499
BTRCore_AVMedia_IsMediaElementPlayable
enBTRCoreRet BTRCore_AVMedia_IsMediaElementPlayable(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, tBTRCoreAVMediaElementId aBtrAVMediaElementId, char *isPlayable)
This API is used to find if a MediaElement is Playable or Non-Playable.
Definition: btrCore_avMedia.c:2330
BTRCore_SetGattInfo
enBTRCoreRet BTRCore_SetGattInfo(tBTRCoreHandle hBTRCore, char *aParentUUID, char *aUUID, unsigned short aFlags, char *aValue, enBTRCoreLeProp aElement)
This API is used to Set Gatt Info value.
Definition: btrCore.c:5490
BTRCore_GetMediaProperty
enBTRCoreRet BTRCore_GetMediaProperty(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId, enBTRCoreDeviceType aenBTRCoreDevType, const char *mediaPropertyKey, void *mediaPropertyValue)
This API returns the media file properties of the Bluetooth device.
Definition: btrCore.c:4875
BtrCore_BTSetDevDataAckTimeout
int BtrCore_BTSetDevDataAckTimeout(void *apBtConn, unsigned int aui32AckTOutms)
This API is used to release the acquired device data path.
Definition: btrCore_dbus_bluez5.c:6010
BTRCore_GetListOfScannedDevices
enBTRCoreRet BTRCore_GetListOfScannedDevices(tBTRCoreHandle hBTRCore, stBTRCoreScannedDevicesCount *pListOfScannedDevices)
This API returns the number of devices scanned.
Definition: btrCore.c:3500
BtrCore_BTDisableEnhancedRetransmissionMode
int BtrCore_BTDisableEnhancedRetransmissionMode(void *apstBtIfceHdl)
This API is used to Disable Enhanced Retransmission on all BT adapter.
Definition: btrCore_dbus_bluez5.c:5544
BTRCore_StartAdvertisement
enBTRCoreRet BTRCore_StartAdvertisement(tBTRCoreHandle hBTRCore)
This API is used to start advertisement registration.
Definition: btrCore.c:5345
BTRCore_StartDiscovery
enBTRCoreRet BTRCore_StartDiscovery(tBTRCoreHandle hBTRCore, const char *pAdapterPath, enBTRCoreDeviceType aenBTRCoreDevType, unsigned int aui32DiscDuration)
This method starts the device discovery session.
Definition: btrCore.c:3392
BtrCore_BTSetProp
int BtrCore_BTSetProp(void *apBtConn, const char *apcOpIfcePath, enBTOpIfceType aenBtOpIfceType, unBTOpIfceProp aunBtOpIfceProp, void *apvVal)
This API sets different properties of different BT devices and services.
Definition: btrCore_dbus_bluez4.c:1737
_stBTPairedDeviceInfo
Definition: btrCore_bt_ifce.h:673
BTRCore_IsDeviceConnectable
enBTRCoreRet BTRCore_IsDeviceConnectable(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId)
This API checks the device is connectable.
Definition: btrCore.c:3864
BtrCore_BTConnectDevice
int BtrCore_BTConnectDevice(void *apBtConn, const char *apDevPath, enBTDeviceType aenBTDevType)
This API is used to establish the connection with a BT device.
Definition: btrCore_dbus_bluez4.c:2456
_stBTRCoreAVMediaElementInfoList
Definition: btrCore_avMedia.h:195
BtrCore_BTGetAdapterPath
char * BtrCore_BTGetAdapterPath(void *apBtConn, const char *apBtAdapter)
Using this API adapter path is fetched from Dbus object path.
Definition: btrCore_dbus_bluez4.c:1438
_stBTRCoreDevStateInfo
Definition: btrCore.c:90
BTRCore_SetManufacturerData
enBTRCoreRet BTRCore_SetManufacturerData(tBTRCoreHandle hBTRCore, unsigned short aManfId, unsigned char *aDeviceDetails, int aLenManfData)
This API is used to set manufacturer data.
Definition: btrCore.c:5435
BTRCore_GetAdapterPower
enBTRCoreRet BTRCore_GetAdapterPower(tBTRCoreHandle hBTRCore, const char *pAdapterPath, unsigned char *pAdapterPower)
This API returns the value of org.bluez.Adapter.powered .
Definition: btrCore.c:3325
BTRCore_LE_GetGattProperty
enBTRCoreRet BTRCore_LE_GetGattProperty(tBTRCoreLeHdl hBTRCoreLe, tBTRCoreDevId atBTRCoreDevId, const char *apBtUuid, enBTRCoreLEGattProp aenBTRCoreLEGattProp, void *apBtPropValue)
This API fetches the GATT property value that is supported.
Definition: btrCore_le.c:1304
BTRCore_SetAdapterPower
enBTRCoreRet BTRCore_SetAdapterPower(tBTRCoreHandle hBTRCore, const char *pAdapterPath, unsigned char powerStatus)
This API sets the bluetooth adapter power as ON/OFF.
Definition: btrCore.c:3294
_stBTRCoreHdl
Definition: btrCore.c:96
BtrCore_LE_PerformGattOp
enBTRCoreRet BtrCore_LE_PerformGattOp(tBTRCoreLeHdl hBTRCoreLe, tBTRCoreDevId atBTRCoreDevId, const char *apBtUuid, enBTRCoreLEGattOp aenBTRCoreLEGattOp, char *apLeOpArg, char *rpLeOpRes)
This API is used to perform read, write, notify operations on LE devices.
Definition: btrCore_le.c:1468
BTRCore_AVMedia_GetMediaElementList
enBTRCoreRet BTRCore_AVMedia_GetMediaElementList(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, tBTRCoreAVMediaElementId aBtrAVMediaElementId, unsigned short aui16StartIdx, unsigned short aui16EndIdx, eBTRCoreAVMElementType aeBtrAVMElementType, stBTRCoreAVMediaElementInfoList *aAVMediaElementInfoList)
This API is used to fetch the media item list.
Definition: btrCore_avMedia.c:2121
enBTDeviceType
enum _enBTDeviceType enBTDeviceType
Bluetooth device types.
BTRCore_EnableAdapter
enBTRCoreRet BTRCore_EnableAdapter(tBTRCoreHandle hBTRCore, stBTRCoreAdapter *apstBTRCoreAdapter)
This API enables specific adapter.
Definition: btrCore.c:3005
BTRCore_SelectMediaElement
enBTRCoreRet BTRCore_SelectMediaElement(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId, tBTRCoreMediaElementId aBtrMediaElementId, enBTRCoreDeviceType aenBTRCoreDevType, eBTRCoreMedElementType aenBTRCoreMedElementType)
This API performs operation according to the element type selected.
Definition: btrCore.c:4931
_stBTRCoreMediaTrackInfo
Definition: btrCore.h:387
BTRCore_LE_SetPropertyValue
enBTRCoreRet BTRCore_LE_SetPropertyValue(tBTRCoreLeHdl hBTRCoreLe, char *aUUID, char *aValue, enBTRCoreLEGattProp aElement)
This API Returns the specified property value associated with the UUID.
Definition: btrCore_le.c:1267
BtrCore_BTStopLEDiscovery
int BtrCore_BTStopLEDiscovery(void *apBtConn, const char *apBtAdapter, const char *apBtAgentPath)
This API is used to stop discovering low energy Bluetooth adapter.
Definition: btrCore_dbus_bluez4.c:1976
BtrCore_BTInitGetConnection
void * BtrCore_BTInitGetConnection(void)
This API Initializes the Bluetooth core and fetches DBus connection and returns a handle to the insta...
Definition: btrCore_dbus_bluez4.c:1160
BTRCore_GetAdapterName
enBTRCoreRet BTRCore_GetAdapterName(tBTRCoreHandle hBTRCore, const char *pAdapterPath, char *pAdapterName)
This API gets the name of BT adapter.
Definition: btrCore.c:3261
BtrCore_BTGetAgentPath
char * BtrCore_BTGetAgentPath(void *apBtConn)
Using this API, a default Path is assigned to the Bluetooth Agent.
Definition: btrCore_dbus_bluez4.c:1249
BTRCore_FindService
enBTRCoreRet BTRCore_FindService(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId, const char *UUID, char *XMLdata, int *found)
This API is used to confirm if a given service exists on a device.
Definition: btrCore.c:3762
_stBTRCoreGetAdapters
Definition: btrCore.h:257
BtrCore_BTPerformAdapterOp
int BtrCore_BTPerformAdapterOp(void *apBtConn, const char *apBtAdapter, const char *apBtAgentPath, const char *apcDevPath, enBTAdapterOp aenBTAdpOp)
This API is used to perform BT adapter operations.
Definition: btrCore_dbus_bluez4.c:2327
BTRCore_AVMedia_GetElementTrackInfo
enBTRCoreRet BTRCore_AVMedia_GetElementTrackInfo(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, tBTRCoreAVMediaElementId aBtrAVMediaElementId, stBTRCoreAVMediaTrackInfo *apstBTAVMediaTrackInfo)
This API is used to retrieve the information about the track that is being played on the media device...
Definition: btrCore_avMedia.c:1797
BTRCore_AVMedia_GetTrackInfo
enBTRCoreRet BTRCore_AVMedia_GetTrackInfo(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, stBTRCoreAVMediaTrackInfo *apstBTAVMediaTrackInfo)
This API is used to retrieve the information about the track that is being played on the media device...
Definition: btrCore_avMedia.c:1763
BTRCore_SetDeviceDataAckTimeout
enBTRCoreRet BTRCore_SetDeviceDataAckTimeout(tBTRCoreHandle hBTRCore, unsigned int aui32AckTOutms)
This API release the bluetooth device address.
Definition: btrCore.c:4532
BTRCore_GetVersionInfo
enBTRCoreRet BTRCore_GetVersionInfo(tBTRCoreHandle hBTRCore, char *apcBtVersion)
This API gets BT Version.
Definition: btrCore.c:3356
BTRCore_SetAdapterName
enBTRCoreRet BTRCore_SetAdapterName(tBTRCoreHandle hBTRCore, const char *pAdapterPath, const char *pAdapterName)
This API sets a friendly name to BT adapter.
Definition: btrCore.c:3231
enBTAdapterProp
enum _enBTAdapterProp enBTAdapterProp
Bluetooth adapter properties.
BTRCore_LE_StartAdvertisement
enBTRCoreRet BTRCore_LE_StartAdvertisement(tBTRCoreLeHdl hBTRCoreLe, void *apBtConn, const char *apBtAdapter)
This API is used to invoke method calls to RegisterAdvertisement and RegisterApplication to begin LE ...
Definition: btrCore_le.c:954
BTRCore_GetMediaPositionInfo
enBTRCoreRet BTRCore_GetMediaPositionInfo(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId, enBTRCoreDeviceType aenBTRCoreDevType, stBTRCoreMediaPositionInfo *apstBTMediaPositionInfo)
This API returns the duration and the current position of the media.
Definition: btrCore.c:4820
BtrCore_BTGetIfceNameVersion
int BtrCore_BTGetIfceNameVersion(void *apBtConn, char *apBtOutIfceName, char *apBtOutVersion)
using this API, Bluetooth interface version is obtained from bluetooth daemon of the kernel and defau...
Definition: btrCore_dbus_bluez4.c:1523
_unBTOpIfceProp
Definition: btrCore_bt_ifce.h:609
BtrCore_BTStartLEDiscovery
int BtrCore_BTStartLEDiscovery(void *apBtConn, const char *apBtAdapter, const char *apBtAgentPath)
This API is used to discover the low energy Bluetooth adapter.
Definition: btrCore_dbus_bluez4.c:1966
BTRCore_AVMedia_ChangeBrowserLocation
enBTRCoreRet BTRCore_AVMedia_ChangeBrowserLocation(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, tBTRCoreAVMediaElementId aBtrAVMediaElementId, eBTRCoreAVMElementType aeBtrAVMElementType)
This API is used to change the media browsing location in the connected AudioIn device.
Definition: btrCore_avMedia.c:1931
BTRCore_LE_AddGattDescInfo
int * BTRCore_LE_AddGattDescInfo(tBTRCoreLeHdl hBTRCoreLe, const char *apBtAdapter, char *aBtdevAddr, char *aParentUUID, char *aUUID, unsigned short aDescFlags, char *aValue)
This API is used to add gatt descriptor info for the advertisement.
Definition: btrCore_le.c:1215
BTRCore_FindDevice
enBTRCoreRet BTRCore_FindDevice(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId)
This API checks the device entry in the scanned device list.
Definition: btrCore.c:3727
BTRCore_GetSupportedServices
enBTRCoreRet BTRCore_GetSupportedServices(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId, stBTRCoreSupportedServiceList *pProfileList)
This API retuns the list of services supported by the device.
Definition: btrCore.c:3804
BTRCore_GetDeviceMediaInfo
enBTRCoreRet BTRCore_GetDeviceMediaInfo(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId, enBTRCoreDeviceType aenBTRCoreDevType, stBTRCoreDevMediaInfo *apstBTRCoreDevMediaInfo)
This API returns current media info that includes the codec info, channel modes, subbands etc.
Definition: btrCore.c:4232
BTRCore_ReleaseDeviceDataPath
enBTRCoreRet BTRCore_ReleaseDeviceDataPath(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId, enBTRCoreDeviceType aenBTRCoreDevType)
This API release the bluetooth device address.
Definition: btrCore.c:4483
BTRCore_GetDeviceTypeClass
enBTRCoreRet BTRCore_GetDeviceTypeClass(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId, enBTRCoreDeviceType *apenBTRCoreDevTy, enBTRCoreDeviceClass *apenBTRCoreDevCl)
This API returns current media info that includes the codec info, channel modes, subbands etc.
Definition: btrCore.c:4161
_stBTRCoreDevMediaSbcInfo
Definition: btrCore.h:359
_stBTRCoreSupportedServiceList
Definition: btrCore.h:294
BTRCore_UnregisterAgent
enBTRCoreRet BTRCore_UnregisterAgent(tBTRCoreHandle hBTRCore)
This unregisters the agent that has been previously registered.
Definition: btrCore.c:2836
_stBTRCoreListAdapters
Definition: btrCore.h:261
BTRCore_AVMedia_DeInit
enBTRCoreRet BTRCore_AVMedia_DeInit(tBTRCoreAVMediaHdl hBTRCoreAVM, void *apBtConn, const char *apBtAdapter)
This API DeInitializes the media device by unregistering both source and sink.
Definition: btrCore_avMedia.c:1097
BTRCore_GetListOfPairedDevices
enBTRCoreRet BTRCore_GetListOfPairedDevices(tBTRCoreHandle hBTRCore, stBTRCorePairedDevicesCount *pListOfDevices)
Gets the paired devices list.
Definition: btrCore.c:3695
BTRCore_LE_SetEnableTxPower
enBTRCoreRet BTRCore_LE_SetEnableTxPower(tBTRCoreLeHdl hBTRCoreLe, BOOLEAN aTxPower)
This API is used to enable/disable sending tranmission power with the advertisement data.
Definition: btrCore_le.c:1088
_stBTRCoreAdServiceData
Definition: btrCore.h:299
BTRCore_AVMedia_Init
enBTRCoreRet BTRCore_AVMedia_Init(tBTRCoreAVMediaHdl *phBTRCoreAVM, void *apBtConn, const char *apBtAdapter)
This API Initializes the media device by registering both source and sink.
Definition: btrCore_avMedia.c:912
BTRCore_GetAdapter
enBTRCoreRet BTRCore_GetAdapter(tBTRCoreHandle hBTRCore, stBTRCoreAdapter *apstBTRCoreAdapter)
This API returns the bluetooth adapter path.
Definition: btrCore.c:2926
BTRCore_AVMedia_GetPositionInfo
enBTRCoreRet BTRCore_AVMedia_GetPositionInfo(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, stBTRCoreAVMediaPositionInfo *apstBTAVMediaPositionInfo)
This API is used to retrieve the position information about the media device.
Definition: btrCore_avMedia.c:1846
enBTDeviceState
enum _enBTDeviceState enBTDeviceState
Bluetooth device state.
BtrCore_BTStopClassicDiscovery
int BtrCore_BTStopClassicDiscovery(void *apBtConn, const char *apBtAdapter, const char *apBtAgentPath)
This API is used to stop discovering Classic Bluetooth Devices.
Definition: btrCore_dbus_bluez5.c:4587
BTRCore_StopAdvertisement
enBTRCoreRet BTRCore_StopAdvertisement(tBTRCoreHandle hBTRCore)
This API is used to stop advertisement registration.
Definition: btrCore.c:5364
BTRCore_SetAdvertisementType
enBTRCoreRet BTRCore_SetAdvertisementType(tBTRCoreHandle hBTRCore, char *aAdvtType)
This API is used to set advertisement type.
Definition: btrCore.c:5403
BTRCore_PairDevice
enBTRCoreRet BTRCore_PairDevice(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId)
This API initiates the pairing of the device.
Definition: btrCore.c:3539
BT_MAX_UUID_STR_LEN
#define BT_MAX_UUID_STR_LEN
Bluetooth max uuid length.
Definition: btrCore_bt_ifce.h:52
BTRCore_GetMediaTrackInfo
enBTRCoreRet BTRCore_GetMediaTrackInfo(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId, enBTRCoreDeviceType aenBTRCoreDevType, stBTRCoreMediaTrackInfo *apstBTMediaTrackInfo)
This API is used to retrieve the media track information.
Definition: btrCore.c:4710
_stBTRCoreAVMediaCtData
Definition: btrCore_avMedia.h:215
_stBTRCoreMediaPositionInfo
Definition: btrCore.h:397
BTRCore_AVMedia_GetCurMediaInfo
enBTRCoreRet BTRCore_AVMedia_GetCurMediaInfo(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, stBTRCoreAVMediaInfo *apstBtrCoreAVMediaInfo)
This API gets current media information of the media device by unregistering both source and sink.
Definition: btrCore_avMedia.c:1214
BTRCore_DeInit
enBTRCoreRet BTRCore_DeInit(tBTRCoreHandle hBTRCore)
This APi deinitialzes and free BTRCore.
Definition: btrCore.c:2657
BT_MAX_NUM_DEVICE
#define BT_MAX_NUM_DEVICE
Bluetooth max number of devices that can be connected.
Definition: btrCore_bt_ifce.h:57
BTRCore_DisconnectDevice
enBTRCoreRet BTRCore_DisconnectDevice(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId, enBTRCoreDeviceType aenBTRCoreDevType)
This method gracefully disconnects all connected profiles and then terminates connection.
Definition: btrCore.c:3993
_stBTRCoreAVMediaPositionInfo
Definition: btrCore_avMedia.h:182
BtrCore_BTRegisterAgent
int BtrCore_BTRegisterAgent(void *apBtConn, const char *apBtAdapter, const char *apBtAgentPath, const char *capabilities)
using this API, DBus object path is registered with bluetooth agent path and current adapter's path.
Definition: btrCore_dbus_bluez4.c:1286
BtrCore_BTGetProp
int BtrCore_BTGetProp(void *apBtConn, const char *apcOpIfcePath, enBTOpIfceType aenBtOpIfceType, unBTOpIfceProp aunBtOpIfceProp, void *apvVal)
This API gets different properties of different BT devices and services.
Definition: btrCore_dbus_bluez4.c:1560
_stBTRCoreDevMediaInfo
Definition: btrCore.h:382
_stBTRCoreMediaCtData
Definition: btrCore.h:436
BTRCore_GetMediaElementTrackInfo
enBTRCoreRet BTRCore_GetMediaElementTrackInfo(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId, enBTRCoreDeviceType aenBTRCoreDevType, tBTRCoreMediaElementId aBtrMediaElementId, stBTRCoreMediaTrackInfo *apstBTMediaTrackInfo)
This API is used to retrieve the media track information.
Definition: btrCore.c:4763
BTRCore_AVMedia_ReleaseDataPath
enBTRCoreRet BTRCore_AVMedia_ReleaseDataPath(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr)
This API releases the acquired data path of the media device.
Definition: btrCore_avMedia.c:1592
BTRCore_SetAdapterDiscoverable
enBTRCoreRet BTRCore_SetAdapterDiscoverable(tBTRCoreHandle hBTRCore, const char *pAdapterPath, unsigned char discoverable)
This API sets adapter as discoverable.
Definition: btrCore.c:3098
BTRCore_LE_SetServiceUUIDs
enBTRCoreRet BTRCore_LE_SetServiceUUIDs(tBTRCoreLeHdl hBTRCoreLe, char *aUUID)
This API is used to store the UUIDs that would be advertised by the device during the advertisement.
Definition: btrCore_le.c:1032
BTRCore_SetServiceInfo
enBTRCoreRet BTRCore_SetServiceInfo(tBTRCoreHandle hBTRCore, char *aUUID, BOOLEAN aServiceType)
This API is used to Set Service Info value.
Definition: btrCore.c:5470
BtrCore_BTStartClassicDiscovery
int BtrCore_BTStartClassicDiscovery(void *apBtConn, const char *apBtAdapter, const char *apBtAgentPath)
This API is used to discover the Classic Bluetooth Devices.
Definition: btrCore_dbus_bluez5.c:4523
BTRCore_GetListOfAdapters
enBTRCoreRet BTRCore_GetListOfAdapters(tBTRCoreHandle hBTRCore, stBTRCoreListAdapters *pstListAdapters)
Returns list of adapter object paths under /org/bluez.
Definition: btrCore.c:2859
_stBTRCorePairedDevicesCount
Definition: btrCore.h:338
BTRCore_MediaControl
enBTRCoreRet BTRCore_MediaControl(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId, enBTRCoreDeviceType aenBTRCoreDevType, enBTRCoreMediaCtrl aenBTRCoreMediaCtrl, stBTRCoreMediaCtData *apstBTRCoreMediaCData)
This API is used to perform media control operations like play, pause, NExt, Previous,...
Definition: btrCore.c:4555
BTRCore_LE_AddGattCharInfo
int * BTRCore_LE_AddGattCharInfo(tBTRCoreLeHdl hBTRCoreLe, const char *apBtAdapter, char *aBtdevAddr, char *aParentUUID, char *aUUID, unsigned short aCharFlags, char *aValue)
This API is used to add gatt characteristic info for the advertisement.
Definition: btrCore_le.c:1163
BtrCore_BTGetAdapterList
int BtrCore_BTGetAdapterList(void *apBtConn, unsigned int *apBtNumAdapters, char *apcArrBtAdapterPath[4])
This API obtains adapter list from Dbus object path.
BTRCore_LE_SetManufacturerData
enBTRCoreRet BTRCore_LE_SetManufacturerData(tBTRCoreLeHdl hBTRCoreLe, unsigned short aManfId, unsigned char *aDeviceDetails, int aLenManfData)
This API is used to store the manufacturer data to be sent with the advertisement.
Definition: btrCore_le.c:1058
enBTAdapterOp
enum _enBTAdapterOp enBTAdapterOp
Bluetooth Adapter operations.
BTRCore_SetMediaElementActive
enBTRCoreRet BTRCore_SetMediaElementActive(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId, tBTRCoreMediaElementId aBtrMediaElementId, enBTRCoreDeviceType aenBTRCoreDevType, eBTRCoreMedElementType aenBTRCoreMedElementType)
This API sets the mentioned media list active/in_scope at the lower to allow further operations on th...
Definition: btrCore.c:5104
BTRCore_GetAdapterDiscoverableStatus
enBTRCoreRet BTRCore_GetAdapterDiscoverableStatus(tBTRCoreHandle hBTRCore, const char *pAdapterPath, unsigned char *pDiscoverable)
This API checks whether the discovery is in progress or not.
Definition: btrCore.c:3163
BtrCore_BTStartDiscovery
int BtrCore_BTStartDiscovery(void *apBtConn, const char *apBtAdapter, const char *apBtAgentPath)
This API is used to discover the Bluetooth adapter.
Definition: btrCore_dbus_bluez4.c:1896
BTRCore_AVMedia_PlayTrack
enBTRCoreRet BTRCore_AVMedia_PlayTrack(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, tBTRCoreAVMediaElementId aBtrAVMediaElementId)
This API starts playing the mentioned media item.
Definition: btrCore_avMedia.c:2212
BTRCore_RegisterAgent
enBTRCoreRet BTRCore_RegisterAgent(tBTRCoreHandle hBTRCore, int iBTRCapMode)
This API registers an agent handler.
Definition: btrCore.c:2803
_stBTRCoreAVMediaMpegInfo
Definition: btrCore_avMedia.h:152
BTRCore_SetAdapter
enBTRCoreRet BTRCore_SetAdapter(tBTRCoreHandle hBTRCore, int adapter_number)
This API sets Current Bluetooth Adapter to use.
Definition: btrCore.c:2958
BTRCore_SetPropertyValue
enBTRCoreRet BTRCore_SetPropertyValue(tBTRCoreHandle hBTRCore, char *aUUID, char *aValue, enBTRCoreLeProp aElement)
This API is used to Set Property value.
Definition: btrCore.c:5520
BTRCore_LE_StopAdvertisement
enBTRCoreRet BTRCore_LE_StopAdvertisement(tBTRCoreLeHdl hBTRCoreLe, void *apBtConn, const char *apBtAdapter)
This API is used to invoke method calls to UnRegisterAdvertisement and UnRegisterApplication to stop ...
Definition: btrCore_le.c:981
_stBTRCoreAVMediaSbcInfo
Definition: btrCore_avMedia.h:139
BTRCore_LE_Init
enBTRCoreRet BTRCore_LE_Init(tBTRCoreLeHdl *phBTRCoreLe, void *apBtConn, const char *apBtAdapter)
This API registers the callback function that has to be called when the LE device are added or remove...
Definition: btrCore_le.c:881
BtrCore_BTIsDeviceConnectable
int BtrCore_BTIsDeviceConnectable(void *apBtConn, const char *apcDevPath)
This API is used to run device connectable command.
Definition: btrCore_dbus_bluez4.c:2409
BtrCore_BTDeInitReleaseConnection
int BtrCore_BTDeInitReleaseConnection(void *apBtConn)
This API DeInitializes the Bluetooth core and releases the DBus connection.
Definition: btrCore_dbus_bluez4.c:1203
BTRCore_UnPairDevice
enBTRCoreRet BTRCore_UnPairDevice(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId)
This API removes the remote device object at the given path.
Definition: btrCore.c:3630
BTRCore_PerformLEOp
enBTRCoreRet BTRCore_PerformLEOp(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId, const char *apBtUuid, enBTRCoreLeOp aenBTRCoreLeOp, char *apLeOpArg, char *rpLeOpRes)
This API is used to perform read, write, notify operations on LE devices.
Definition: btrCore.c:5262
_stBTRCoreAVMediaInfo
Definition: btrCore_avMedia.h:166
_stBTRCoreDevStatusCBInfo
Definition: btrCore.h:273
BTRCore_LE_DeInit
enBTRCoreRet BTRCore_LE_DeInit(tBTRCoreLeHdl hBTRCoreLe, void *apBtConn, const char *apBtAdapter)
This API deinitializes the LE device.
Definition: btrCore_le.c:931
BtrCore_BTDisconnectDevice
int BtrCore_BTDisconnectDevice(void *apBtConn, const char *apDevPath, enBTDeviceType aenBTDevType)
This API is used to diconnect a BT device.
Definition: btrCore_dbus_bluez4.c:2511
_stBTRCoreMediaElementInfoList
Definition: btrCore.h:410
BTRCore_SetServiceUUIDs
enBTRCoreRet BTRCore_SetServiceUUIDs(tBTRCoreHandle hBTRCore, char *aUUID)
This API is used to set service UUIDs.
Definition: btrCore.c:5419
_stBTRCoreScannedDevicesCount
Definition: btrCore.h:333
BTRCore_GetMediaElementList
enBTRCoreRet BTRCore_GetMediaElementList(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId, tBTRCoreMediaElementId aBtrMediaElementId, unsigned short aui16BtrMedElementStartIdx, unsigned short aui16BtrMedElementEndIdx, enBTRCoreDeviceType aenBTRCoreDevType, eBTRCoreMedElementType aenBTRCoreMedElementType, stBTRCoreMediaElementInfoList *apstMediaElementListInfo)
This API returns the mentioned media list.
Definition: btrCore.c:5030
_stBTRCoreAVMediaTrackInfo
Definition: btrCore_avMedia.h:172
_stBTRCoreAVMediaStatusUpdate
Definition: btrCore_avMedia.h:200
BTRCore_AVMedia_GetMediaProperty
enBTRCoreRet BTRCore_AVMedia_GetMediaProperty(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, const char *mediaPropertyKey, void *mediaPropertyValue)
This API is used to get media property value using the device address and media property key.
Definition: btrCore_avMedia.c:1895
_stBTDeviceInfo
Definition: btrCore_bt_ifce.h:647
_stBTRCoreMediaStatusCBInfo
Definition: btrCore.h:428
BtrCore_BTReleaseAgentPath
int BtrCore_BTReleaseAgentPath(void *apBtConn)
Using this API the path assigned to the Bluetooth Agent is released.
Definition: btrCore_dbus_bluez4.c:1270
BTRCore_LE_SetAdvertisementType
enBTRCoreRet BTRCore_LE_SetAdvertisementType(tBTRCoreLeHdl hBTRCoreLe, char *aAdvtType)
This API is used to store the advertisement type supported by device.
Definition: btrCore_le.c:1006
BTRCore_AVMedia_SelectTrack
enBTRCoreRet BTRCore_AVMedia_SelectTrack(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, tBTRCoreAVMediaElementId aBtrAVMediaElementId)
This API select track the mentioned media item.
Definition: btrCore_avMedia.c:2267
BTRCore_SetAdapterDiscoverableTimeout
enBTRCoreRet BTRCore_SetAdapterDiscoverableTimeout(tBTRCoreHandle hBTRCore, const char *pAdapterPath, unsigned short timeout)
This API sets how long the adapter is discoverable.
Definition: btrCore.c:3130
BTRCore_GetDeviceConnected
enBTRCoreRet BTRCore_GetDeviceConnected(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId, enBTRCoreDeviceType aenBTRCoreDevType)
This method checks the current device that is connected.
Definition: btrCore.c:4061
_stBTRCoreLeGattInfo
Definition: btrCore_le.h:74
_stBTRCoreDiscoveryCBInfo
Definition: btrCore.h:459
rdk_logger_init
rdk_Error rdk_logger_init(const char *debugConfigFile)
Initialize the logger. Sets up the environment variable storage by parsing debug configuration file t...
Definition: rdk_logger_init.c:57
_stBTRCoreMediaElementInfo
Definition: btrCore.h:402
BT_MAX_DEV_PATH_LEN
#define BT_MAX_DEV_PATH_LEN
Bluetooth max device path length.
Definition: btrCore_bt_ifce.h:44
BTRCore_AVMedia_SelectMediaBrowserElements
enBTRCoreRet BTRCore_AVMedia_SelectMediaBrowserElements(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, unsigned short aui16StartIdx, unsigned short aui16EndIdx)
This API is used to List(implicitly) the media elements in the current browsing location of the conne...
Definition: btrCore_avMedia.c:2052
_stBTRCoreConnCBInfo
Definition: btrCore.h:343
TRUE
#define TRUE
Defines for TRUE/FALSE/ENABLE flags.
Definition: wifi_common_hal.h:199
BTRCore_ConnectDevice
enBTRCoreRet BTRCore_ConnectDevice(tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId, enBTRCoreDeviceType aenBTRCoreDevType)
This method connect any profiles the remote device supports.
Definition: btrCore.c:3921
BtrCore_BTFindServiceSupported
int BtrCore_BTFindServiceSupported(void *apBtConn, const char *apcDevPath, const char *apcSearchString, char *apcDataString)
This API is used to find all supported services and fetch the profiles of all those devices.
Definition: btrCore_dbus_bluez4.c:2223
_stBTRCoreDevMediaMpegInfo
Definition: btrCore.h:371
BT_MAX_DEVICE_PROFILE
#define BT_MAX_DEVICE_PROFILE
Bluetooth max number of device profiles that are allowed. Device Profiles are definitions of possible...
Definition: btrCore_bt_ifce.h:64
_stBTRCoreTaskGAqData
Definition: btrCore.c:76
BTRCore_AVMedia_MediaControl
enBTRCoreRet BTRCore_AVMedia_MediaControl(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, enBTRCoreAVMediaCtrl aenBTRCoreAVMediaCtrl, eBTRCoreAVMediaFlow aenBTRCoreAVMediaFlow, stBTRCoreAVMediaCtData *apstBTRCoreAVMediaCtrlData)
This API is used to control the media device. BTRCore_MediaControl() invokes this API.
Definition: btrCore_avMedia.c:1629
BTRCore_AVMedia_RegisterMediaStatusUpdateCb
enBTRCoreRet BTRCore_AVMedia_RegisterMediaStatusUpdateCb(tBTRCoreAVMediaHdl hBTRCoreAVM, fPtr_BTRCore_AVMediaStatusUpdateCb afpcBBTRCoreAVMediaStatusUpdate, void *apcBMediaStatusUserData)
Definition: btrCore_avMedia.c:2388
_stBTRCoreAdapter
Definition: btrCore.h:306
BTRCore_LE_AddGattServiceInfo
int * BTRCore_LE_AddGattServiceInfo(tBTRCoreLeHdl hBTRCoreLe, const char *apBtAdapter, char *aBtdevAddr, char *aUUID, BOOLEAN aServiceType, int *aNumGattServices)
This API is used to add service info for the advertisement.
Definition: btrCore_le.c:1108
BtrCore_BTDiscoverDeviceServices
int BtrCore_BTDiscoverDeviceServices(void *apBtConn, const char *apcDevPath, stBTDeviceSupportedServiceList *pProfileList)
This API is used to discover the supported services and fetch the profiles of all those devices.
Definition: btrCore_dbus_bluez4.c:2092
BTRCore_StopDiscovery
enBTRCoreRet BTRCore_StopDiscovery(tBTRCoreHandle hBTRCore, const char *pAdapterPath, enBTRCoreDeviceType aenBTRCoreDevType)
This method will cancel any previous StartDiscovery transaction.
Definition: btrCore.c:3459
BTRCore_AVMedia_AcquireDataPath
enBTRCoreRet BTRCore_AVMedia_AcquireDataPath(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, int *apDataPath, int *apDataReadMTU, int *apDataWriteMTU, unsigned int *apui32Delay)
This API acquires the data path and MTU of a media device.
Definition: btrCore_avMedia.c:1538
BtrCore_BTSendReceiveMessages
int BtrCore_BTSendReceiveMessages(void *apBtConn)
This API is used to read, write and dispatch BT device information.
Definition: btrCore_dbus_bluez4.c:2909