RDK Documentation (Open Sourced RDK Components)
btrCore_dbus_bluez4.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 /*
20  * btrCore_dbus_bluez4.c
21  * Implementation of DBus layer abstraction for BT functionality
22  */
23 
24 /* System Headers */
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <unistd.h>
29 #include <limits.h>
30 #include <signal.h>
31 
32 /* External Library Headers */
33 #include <dbus/dbus.h>
34 
35 /* Local Headers */
36 #include "btrCore_bt_ifce.h"
37 #include "btrCore_logger.h"
38 #ifdef LIBSYSWRAPPER_BUILD
39 #include "secure_wrapper.h"
40 #endif
41 
42 #define BD_NAME_LEN 248
43 
44 #define BT_MEDIA_A2DP_SINK_ENDPOINT "/MediaEndpoint/A2DPSink"
45 #define BT_MEDIA_A2DP_SOURCE_ENDPOINT "/MediaEndpoint/A2DPSource"
46 
47 /* Static Function Prototypes */
48 static int btrCore_BTHandleDusError (DBusError* aDBusErr, int aErrline, const char* aErrfunc);
49 
50 static DBusHandlerResult btrCore_BTDBusConnectionFilter_cb (DBusConnection* apDBusConn, DBusMessage* apDBusMsg, void* apvUserData);
51 static DBusHandlerResult btrCore_BTMediaEndpointHandler_cb (DBusConnection* apDBusConn, DBusMessage* apDBusMsg, void* apvUserData);
52 static DBusHandlerResult btrCore_BTAgentMessageHandler_cb (DBusConnection* apDBusConn, DBusMessage* apDBusMsg, void* apvUserData);
53 
54 static char* btrCore_BTGetDefaultAdapterPath (void);
55 static int btrCore_BTReleaseDefaultAdapterPath (void);
56 
57 static DBusHandlerResult btrCore_BTAgentRelease (DBusConnection* apDBusConn, DBusMessage* apDBusMsg, void* apvUserData);
58 static DBusHandlerResult btrCore_BTAgentRequestPincode (DBusConnection* apDBusConn, DBusMessage* apDBusMsg, void* apvUserData);
59 static DBusHandlerResult btrCore_BTAgentRequestPasskey (DBusConnection* apDBusConn, DBusMessage* apDBusMsg, void* apvUserData);
60 static DBusHandlerResult btrCore_BTAgentRequestConfirmation(DBusConnection* apDBusConn, DBusMessage* apDBusMsg, void* apvUserData);
61 static DBusHandlerResult btrCore_BTAgentAuthorize (DBusConnection* apDBusConn, DBusMessage* apDBusMsg, void* apvUserData);
62 static DBusHandlerResult btrCore_BTAgentCancelMessage (DBusConnection* apDBusConn, DBusMessage* apDBusMsg, void* apvUserData);
63 
64 static DBusMessage* btrCore_BTSendMethodCall (const char* objectpath, const char* interfacename, const char* methodname);
65 static int btrCore_BTParseDevice (DBusMessage* apDBusMsg, stBTDeviceInfo* apstBTDeviceInfo);
66 static int btrCore_BTParsePropertyChange (DBusMessage* apDBusMsg, stBTDeviceInfo* apstBTDeviceInfo);
67 static DBusMessage* btrCore_BTMediaEndpointSelectConfiguration (DBusMessage* apDBusMsg);
68 static DBusMessage* btrCore_BTMediaEndpointSetConfiguration (DBusMessage* apDBusMsg);
69 static DBusMessage* btrCore_BTMediaEndpointClearConfiguration (DBusMessage* apDBusMsg);
70 
71 
72 
73 /* Static Global Variables Defs */
74 static char *gpcBTOutPassCode = NULL;
75 static int do_reject = 0;
76 static char gpcDeviceCurrState[BT_MAX_STR_LEN];
77 static DBusConnection* gpDBusConn = NULL;
78 static char* gpcBTAgentPath = NULL;
79 static char* gpcBTDAdapterPath = NULL;
80 static char* gpcBTAdapterPath = NULL;
81 static char* gpcDevTransportPath = NULL;
82 static void* gpcBDevStatusUserData = NULL;
83 static void* gpcBNegMediaUserData = NULL;
84 static void* gpcBTransPathMediaUserData = NULL;
85 static void* gpcBConnIntimUserData = NULL;
86 static void* gpcBConnAuthUserData = NULL;
87 
88 static unsigned int gpcBConnAuthPassKey = 0;
89 static unsigned int gpDevLost = 0;
90 
91 static const DBusObjectPathVTable gDBusMediaEndpointVTable = {
92  .message_function = btrCore_BTMediaEndpointHandler_cb,
93 };
94 
95 static const DBusObjectPathVTable gDBusAgentVTable = {
96  .message_function = btrCore_BTAgentMessageHandler_cb,
97 };
98 
99 
100 /* Callbacks */
101 static fPtr_BtrCore_BTDevStatusUpdate_cB gfpcBDevStatusUpdate = NULL;
102 static fPtr_BtrCore_BTNegotiateMedia_cB gfpcBNegotiateMedia = NULL;
103 static fPtr_BtrCore_BTTransportPathMedia_cB gfpcBTransportPathMedia = NULL;
104 static fPtr_BtrCore_BTConnIntim_cB gfpcBConnectionIntimation = NULL;
105 static fPtr_BtrCore_BTConnAuth_cB gfpcBConnectionAuthentication = NULL;
106 
107 
108 /* Static Function Defs */
109 static inline int
110 btrCore_BTHandleDusError (
111  DBusError* apDBusErr,
112  int aErrline,
113  const char* apErrfunc
114 ) {
115  if (dbus_error_is_set(apDBusErr)) {
116  BTRCORELOG_ERROR ("%d\t:%s - DBus Error is %s\n", aErrline, apErrfunc, apDBusErr->message);
117  dbus_error_free(apDBusErr);
118  return 1;
119  }
120  return 0;
121 }
122 
123 
124 static DBusHandlerResult
125 btrCore_BTDBusConnectionFilter_cb (
126  DBusConnection* apDBusConn,
127  DBusMessage* apDBusMsg,
128  void* apvUserData
129 ) {
130  int i32OpRet = -1;
131  stBTDeviceInfo lstBTDeviceInfo;
132 
133  memset (&lstBTDeviceInfo, 0, sizeof(stBTDeviceInfo));
134  lstBTDeviceInfo.i32RSSI = INT_MIN;
135 
136  //BTRCORELOG_ERROR ("agent filter activated....\n");
137  if (dbus_message_is_signal(apDBusMsg, "org.bluez.Adapter", "DeviceCreated")) {
138  BTRCORELOG_INFO ("Device Created!\n");
139  if (gfpcBDevStatusUpdate) {
140  if(gfpcBDevStatusUpdate(enBTDevUnknown, enBTDevStPaired, NULL, NULL)) {
141  }
142  }
143  }
144 
145  if (dbus_message_is_signal(apDBusMsg, "org.bluez.Adapter", "DeviceFound")) {
146  BTRCORELOG_INFO ("Device Found!\n");
147 
148  i32OpRet = btrCore_BTParseDevice(apDBusMsg, &lstBTDeviceInfo);
149  if (gfpcBDevStatusUpdate && !i32OpRet) {
150  if(gfpcBDevStatusUpdate(enBTDevUnknown, enBTDevStFound, &lstBTDeviceInfo, gpcBDevStatusUserData)) {
151  }
152  }
153  }
154 
155  if (dbus_message_is_signal(apDBusMsg, "org.bluez.Adapter","DeviceDisappeared")) {
156  BTRCORELOG_INFO ("Device DeviceDisappeared!\n");
157  if (gfpcBDevStatusUpdate) {
158  if(gfpcBDevStatusUpdate(enBTDevUnknown, enBTDevStLost, NULL, NULL)) {
159  }
160  }
161  }
162 
163  if (dbus_message_is_signal(apDBusMsg, "org.bluez.Adapter","DeviceRemoved")) {
164  BTRCORELOG_ERROR ("Device Removed!\n");
165  if (gfpcBDevStatusUpdate) {
166  if(gfpcBDevStatusUpdate(enBTDevUnknown, enBTDevStUnPaired, NULL, NULL)) {
167  }
168  }
169  }
170 
171  if (dbus_message_is_signal(apDBusMsg, "org.bluez.AudioSink","Connected")) {
172  BTRCORELOG_INFO ("Device Connected - AudioSink!\n");
173  if (gfpcBDevStatusUpdate) {
174  if(gfpcBDevStatusUpdate(enBTDevAudioSink, enBTDevStConnected, NULL, NULL)) {
175  }
176  }
177  }
178 
179  if (dbus_message_is_signal(apDBusMsg, "org.bluez.AudioSink","Disconnected")) {
180  BTRCORELOG_INFO ("Device Disconnected - AudioSink!\n");
181  if (gfpcBDevStatusUpdate) {
182  gpDevLost = 1;
183  if(gfpcBDevStatusUpdate(enBTDevAudioSink, enBTDevStDisconnected, NULL, NULL)) {
184  }
185  }
186  }
187 
188  if (dbus_message_is_signal(apDBusMsg, "org.bluez.AudioSink","PropertyChanged")) {
189  enBTDeviceState lenBtDevState = enBTDevStUnknown;
190  BTRCORELOG_INFO ("Device PropertyChanged!\n");
191  btrCore_BTParsePropertyChange(apDBusMsg, &lstBTDeviceInfo);
192  if (gfpcBDevStatusUpdate) {
193  if( !gpDevLost ) {
194  lenBtDevState = enBTDevStPropChanged;
195  }
196  else {
197  lenBtDevState = enBTDevStLost;
198  gpDevLost = 0;
199  }
200  if(gfpcBDevStatusUpdate(enBTDevAudioSink, lenBtDevState, &lstBTDeviceInfo, gpcBDevStatusUserData)) {
201  }
202  }
203  }
204 
205  if (dbus_message_is_signal(apDBusMsg, "org.bluez.AudioSource","Connected")) {
206  BTRCORELOG_ERROR ("Device Connected - AudioSource!\n");
207  if (gfpcBDevStatusUpdate) {
208  if(gfpcBDevStatusUpdate(enBTDevAudioSource, enBTDevStConnected, NULL, NULL)) {
209  }
210  }
211  }
212 
213  if (dbus_message_is_signal(apDBusMsg, "org.bluez.AudioSource","Disconnected")) {
214  BTRCORELOG_INFO ("Device Disconnected - AudioSource!\n");
215  if (gfpcBDevStatusUpdate) {
216  if(gfpcBDevStatusUpdate(enBTDevAudioSource, enBTDevStDisconnected, NULL, NULL)) {
217  }
218  }
219  }
220 
221  if (dbus_message_is_signal(apDBusMsg, "org.bluez.AudioSource","PropertyChanged")) {
222  BTRCORELOG_INFO ("Device PropertyChanged!\n");
223  btrCore_BTParsePropertyChange(apDBusMsg, &lstBTDeviceInfo);
224  if (gfpcBDevStatusUpdate) {
225  if(gfpcBDevStatusUpdate(enBTDevAudioSource, enBTDevStPropChanged, &lstBTDeviceInfo, gpcBDevStatusUserData)) {
226  }
227  }
228  }
229 
230  if (dbus_message_is_signal(apDBusMsg, "org.bluez.Headset","Connected")) {
231  BTRCORELOG_INFO ("Device Connected - Headset!\n");
232  if (gfpcBDevStatusUpdate) {
233  if(gfpcBDevStatusUpdate(enBTDevHFPHeadset,enBTDevStConnected, NULL, NULL)) {
234  }
235  }
236  }
237 
238  if (dbus_message_is_signal(apDBusMsg, "org.bluez.Headset","Disconnected")) {
239  BTRCORELOG_INFO ("Device Disconnected - Headset!\n");
240  if (gfpcBDevStatusUpdate) {
241  if(gfpcBDevStatusUpdate(enBTDevHFPHeadset, enBTDevStDisconnected, NULL, NULL)) {
242  }
243  }
244  }
245 
246  if (dbus_message_is_signal(apDBusMsg, "org.bluez.Headset","PropertyChanged")) {
247  BTRCORELOG_INFO ("Device PropertyChanged!\n");
248  btrCore_BTParsePropertyChange(apDBusMsg, &lstBTDeviceInfo);
249  if (gfpcBDevStatusUpdate) {
250  if(gfpcBDevStatusUpdate(enBTDevHFPHeadset, enBTDevStPropChanged, &lstBTDeviceInfo, gpcBDevStatusUserData)) {
251  }
252  }
253 
254  }
255 
256  if (dbus_message_is_signal(apDBusMsg, "org.bluez.MediaTransport","PropertyChanged")) {
257  BTRCORELOG_INFO ("MediaTransport PropertyChanged!\n");
258  }
259 
260  if (!i32OpRet)
261  return DBUS_HANDLER_RESULT_HANDLED;
262  else
263  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
264 }
265 
266 
267 static DBusHandlerResult
268 btrCore_BTMediaEndpointHandler_cb (
269  DBusConnection* apDBusConn,
270  DBusMessage* apDBusMsg,
271  void* apvUserData
272 ) {
273  DBusMessage* lpDBusReply = NULL;
274  const char* lpcPath;
275 
276  lpcPath = dbus_message_get_path(apDBusMsg);
277 
278  (void)lpcPath;
279 
280  BTRCORELOG_INFO ("endpoint_handler: MediaEndpoint\n");
281 
282  if (dbus_message_is_method_call(apDBusMsg, "org.bluez.MediaEndpoint", "SelectConfiguration")) {
283  BTRCORELOG_DEBUG ("MediaEndpoint-SelectConfiguration\n");
284  lpDBusReply = btrCore_BTMediaEndpointSelectConfiguration(apDBusMsg);
285  }
286  else if (dbus_message_is_method_call(apDBusMsg, "org.bluez.MediaEndpoint", "SetConfiguration")) {
287  BTRCORELOG_DEBUG ("MediaEndpoint-SetConfiguration\n");
288  lpDBusReply = btrCore_BTMediaEndpointSetConfiguration(apDBusMsg);
289  }
290  else if (dbus_message_is_method_call(apDBusMsg, "org.bluez.MediaEndpoint", "ClearConfiguration")) {
291  BTRCORELOG_DEBUG ("MediaEndpoint-ClearConfiguration\n");
292  lpDBusReply = btrCore_BTMediaEndpointClearConfiguration(apDBusMsg);
293  }
294  else {
295  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
296  }
297 
298  if (lpDBusReply) {
299  dbus_connection_send(apDBusConn, lpDBusReply, NULL);
300  dbus_message_unref(lpDBusReply);
301  }
302 
303  return DBUS_HANDLER_RESULT_HANDLED;
304 }
305 
306 
307 static DBusHandlerResult
308 btrCore_BTAgentMessageHandler_cb (
309  DBusConnection* apDBusConn,
310  DBusMessage* apDBusMsg,
311  void* apvUserData
312 ) {
313  if (dbus_message_is_method_call(apDBusMsg, "org.bluez.Agent", "Release"))
314  return btrCore_BTAgentRelease (apDBusConn, apDBusMsg, apvUserData);
315 
316  if (dbus_message_is_method_call(apDBusMsg, "org.bluez.Agent", "RequestPinCode"))
317  return btrCore_BTAgentRequestPincode(apDBusConn, apDBusMsg, apvUserData);
318 
319  if (dbus_message_is_method_call(apDBusMsg, "org.bluez.Agent", "RequestPasskey"))
320  return btrCore_BTAgentRequestPasskey(apDBusConn, apDBusMsg, apvUserData);
321 
322  if (dbus_message_is_method_call(apDBusMsg, "org.bluez.Agent", "RequestConfirmation"))
323  return btrCore_BTAgentRequestConfirmation(apDBusConn, apDBusMsg, apvUserData);
324 
325  if (dbus_message_is_method_call(apDBusMsg, "org.bluez.Agent", "Authorize"))
326  return btrCore_BTAgentAuthorize(apDBusConn, apDBusMsg, apvUserData);
327 
328  if (dbus_message_is_method_call(apDBusMsg, "org.bluez.Agent", "Cancel"))
329  return btrCore_BTAgentCancelMessage(apDBusConn, apDBusMsg, apvUserData);
330 
331  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
332 }
333 
334 
335 static char*
336 btrCore_BTGetDefaultAdapterPath (
337  void
338 ) {
339  DBusMessage* lpDBusMsg = NULL;
340  DBusMessage* lpDBusReply = NULL;
341  const char* lpReplyPath = NULL;
342 
343  DBusError lDBusErr;
344  dbus_bool_t lDBusOp;
345 
346  lpDBusMsg = dbus_message_new_method_call("org.bluez",
347  "/",
348  "org.bluez.Manager",
349  "DefaultAdapter");
350  if (!lpDBusMsg) {
351  BTRCORELOG_ERROR ("Can't allocate new method call\n");
352  return NULL;
353  }
354 
355  dbus_error_init(&lDBusErr);
356  lpDBusReply = dbus_connection_send_with_reply_and_block(gpDBusConn, lpDBusMsg, -1, &lDBusErr);
357  dbus_message_unref(lpDBusMsg);
358 
359  if (!lpDBusReply) {
360  BTRCORELOG_ERROR ("Can't find Default adapter\n");
361  btrCore_BTHandleDusError(&lDBusErr, __LINE__, __FUNCTION__);
362  return NULL;
363  }
364 
365  lDBusOp = dbus_message_get_args(lpDBusReply, &lDBusErr, DBUS_TYPE_OBJECT_PATH, &lpReplyPath, DBUS_TYPE_INVALID);
366  dbus_message_unref(lpDBusReply);
367 
368  if (!lDBusOp) {
369  BTRCORELOG_ERROR ("Can't get lpDBusReply arguments\n");
370  btrCore_BTHandleDusError(&lDBusErr, __LINE__, __FUNCTION__);
371  return NULL;
372  }
373 
374  dbus_connection_flush(gpDBusConn);
375 
376  if (gpcBTDAdapterPath) {
377  free(gpcBTDAdapterPath);
378  gpcBTDAdapterPath = NULL;
379  }
380 
381  gpcBTDAdapterPath = strdup(lpReplyPath);
382  return gpcBTDAdapterPath;
383 }
384 
385 
386 static int
387 btrCore_BTReleaseDefaultAdapterPath (
388  void
389 ) {
390  if (gpcBTDAdapterPath) {
391  free(gpcBTDAdapterPath);
392  gpcBTDAdapterPath = NULL;
393  }
394 
395  return 0;
396 }
397 
398 
399 static DBusHandlerResult
400 btrCore_BTAgentRelease (
401  DBusConnection* apDBusConn,
402  DBusMessage* apDBusMsg,
403  void* apvUserData
404 ) {
405  DBusMessage* lpDBusReply = NULL;
406 
407  if (!dbus_message_get_args(apDBusMsg, NULL, DBUS_TYPE_INVALID)) {
408  BTRCORELOG_ERROR ("Invalid arguments for Release method");
409  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
410  }
411 
412  lpDBusReply = dbus_message_new_method_return(apDBusMsg);
413 
414  if (!lpDBusReply) {
415  BTRCORELOG_ERROR ("Unable to create lpDBusReply message\n");
416  return DBUS_HANDLER_RESULT_NEED_MEMORY;
417  }
418 
419  dbus_connection_send(apDBusConn, lpDBusReply, NULL);
420  dbus_connection_flush(apDBusConn);
421 
422  dbus_message_unref(lpDBusReply);
423  //return the result
424  return DBUS_HANDLER_RESULT_HANDLED;
425 }
426 
427 
428 static DBusHandlerResult
429 btrCore_BTAgentRequestPincode (
430  DBusConnection* apDBusConn,
431  DBusMessage* apDBusMsg,
432  void* apvUserData
433 ) {
434  DBusMessage* lpDBusReply = NULL;
435  const char* lpcPath = NULL;
436 
437  if (!gpcBTOutPassCode)
438  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
439 
440  if (!dbus_message_get_args(apDBusMsg, NULL, DBUS_TYPE_OBJECT_PATH, &lpcPath, DBUS_TYPE_INVALID)) {
441  BTRCORELOG_ERROR ("Invalid arguments for RequestPinCode method");
442  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
443  }
444 
445  if (do_reject) {
446  lpDBusReply = dbus_message_new_error(apDBusMsg, "org.bluez.Error.Rejected", "");
447  goto sendmsg;
448  }
449 
450  lpDBusReply = dbus_message_new_method_return(apDBusMsg);
451  if (!lpDBusReply) {
452  BTRCORELOG_ERROR ("Can't create lpDBusReply message\n");
453  return DBUS_HANDLER_RESULT_NEED_MEMORY;
454  }
455 
456  BTRCORELOG_DEBUG ("Pincode request for device %s\n", lpcPath);
457  dbus_message_append_args(lpDBusReply, DBUS_TYPE_STRING, &gpcBTOutPassCode, DBUS_TYPE_INVALID);
458 
459 sendmsg:
460  dbus_connection_send(apDBusConn, lpDBusReply, NULL);
461  dbus_connection_flush(apDBusConn);
462 
463  dbus_message_unref(lpDBusReply);
464 
465  return DBUS_HANDLER_RESULT_HANDLED;
466 }
467 
468 
469 static DBusHandlerResult
470 btrCore_BTAgentRequestPasskey (
471  DBusConnection* apDBusConn,
472  DBusMessage* apDBusMsg,
473  void* apvUserData
474 ) {
475  DBusMessage* lpDBusReply = NULL;
476  const char* lpcPath = NULL;
477  unsigned int ui32PassCode= 0;
478 
479  if (!gpcBTOutPassCode)
480  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
481 
482  if (!dbus_message_get_args(apDBusMsg, NULL, DBUS_TYPE_OBJECT_PATH, &lpcPath, DBUS_TYPE_INVALID)) {
483  BTRCORELOG_ERROR ("Incorrect args btrCore_BTAgentRequestPasskey");
484  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
485  }
486 
487  lpDBusReply = dbus_message_new_method_return(apDBusMsg);
488  if (!lpDBusReply) {
489  BTRCORELOG_ERROR ("Can't create lpDBusReply message\n");
490  return DBUS_HANDLER_RESULT_NEED_MEMORY;
491  }
492 
493  BTRCORELOG_DEBUG ("Pass code request for device %s\n", lpcPath);
494  ui32PassCode = strtoul(gpcBTOutPassCode, NULL, 10);
495  dbus_message_append_args(lpDBusReply, DBUS_TYPE_UINT32, &ui32PassCode, DBUS_TYPE_INVALID);
496 
497  dbus_connection_send(apDBusConn, lpDBusReply, NULL);
498  dbus_connection_flush(apDBusConn);
499  dbus_message_unref(lpDBusReply);
500 
501  return DBUS_HANDLER_RESULT_HANDLED;
502 }
503 
504 
505 static DBusHandlerResult
506 btrCore_BTAgentRequestConfirmation (
507  DBusConnection* apDBusConn,
508  DBusMessage* apDBusMsg,
509  void* apvUserData
510 ) {
511  DBusMessage* lpDBusReply = NULL;
512  const char* lpcPath = NULL;
513  unsigned int ui32PassCode= 0;
514  int yesNo = 0;
515  int i32OpRet = -1;
516  stBTDeviceInfo lstBTDeviceInfo;
517 
518  memset(&lstBTDeviceInfo, 0, sizeof(stBTDeviceInfo));
519 
520 
521  if (!dbus_message_get_args(apDBusMsg, NULL, DBUS_TYPE_OBJECT_PATH, &lpcPath, DBUS_TYPE_UINT32, &ui32PassCode, DBUS_TYPE_INVALID)) {
522  BTRCORELOG_ERROR ("Invalid arguments for Authorize method");
523  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
524  }
525 
526 
527  BTRCORELOG_DEBUG ("btrCore_BTAgentRequestConfirmation: PASS Code for %s is %6d\n",lpcPath, ui32PassCode);
528 
529  if (gfpcBConnectionIntimation && lpcPath) {
530  //i32OpRet = btrCore_BTGetDeviceInfo(&lstBTDeviceInfo, lpcPath);
531  //enBTDeviceType lenBTDevType = btrCore_BTMapDevClasstoDevType(lstBTDeviceInfo.ui32Class);
532 
533  BTRCORELOG_INFO ("calling ConnIntimation cb for %s - OpRet = %d\n", lpcPath, i32OpRet);
534  yesNo = gfpcBConnectionIntimation(enBTDevUnknown, &lstBTDeviceInfo, ui32PassCode, gpcBConnIntimUserData);
535  }
536 
537  gpcBConnAuthPassKey = ui32PassCode;
538 
539 
540  if (yesNo == 0) {
541  BTRCORELOG_ERROR ("Sorry, you cant connect....\n");
542  lpDBusReply = dbus_message_new_error(apDBusMsg, "org.bluez.Error.Rejected", "");
543  }
544  else {
545  lpDBusReply = dbus_message_new_method_return(apDBusMsg);
546  }
547 
548 
549  if (!lpDBusReply) {
550  BTRCORELOG_ERROR ("Can't create lpDBusReply message\n");
551  return DBUS_HANDLER_RESULT_NEED_MEMORY;
552  }
553  else {
554  BTRCORELOG_INFO ("Intimating request for %s\n", lpcPath);
555  dbus_connection_send(apDBusConn, lpDBusReply, NULL);
556  dbus_connection_flush(apDBusConn);
557  dbus_message_unref(lpDBusReply);
558  return DBUS_HANDLER_RESULT_HANDLED;
559  }
560 }
561 
562 
563 static DBusHandlerResult
564 btrCore_BTAgentAuthorize (
565  DBusConnection* apDBusConn,
566  DBusMessage* apDBusMsg,
567  void* apvUserData
568 ) {
569  DBusMessage* lpDBusReply = NULL;
570  const char* lpcPath = NULL;
571  const char* uuid = NULL;
572  int yesNo = 0;
573  int i32OpRet = -1;
574  stBTDeviceInfo lstBTDeviceInfo;
575 
576  memset(&lstBTDeviceInfo, 0, sizeof(stBTDeviceInfo));
577 
578  if (!dbus_message_get_args(apDBusMsg, NULL, DBUS_TYPE_OBJECT_PATH, &lpcPath, DBUS_TYPE_STRING, &uuid, DBUS_TYPE_INVALID)) {
579  BTRCORELOG_ERROR ("Invalid arguments for Authorize method");
580  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
581  }
582 
583  if (gfpcBConnectionAuthentication && lpcPath) {
584  //i32OpRet = btrCore_BTGetDeviceInfo(&lstBTDeviceInfo, lpcPath);
585  //enBTDeviceType lenBTDevType = btrCore_BTMapDevClasstoDevType(lstBTDeviceInfo.ui32Class);
586 
587  BTRCORELOG_DEBUG ("calling ConnAuth cb for %s - OpRet = %d\n", lpcPath, i32OpRet);
588  yesNo = gfpcBConnectionAuthentication(enBTDevUnknown, &lstBTDeviceInfo, gpcBConnAuthUserData);
589  }
590 
591  gpcBConnAuthPassKey = 0;
592 
593 
594  if (yesNo == 0) {
595  BTRCORELOG_ERROR ("Sorry, you cant connect....\n");
596  lpDBusReply = dbus_message_new_error(apDBusMsg, "org.bluez.Error.Rejected", "");
597  }
598  else {
599  lpDBusReply = dbus_message_new_method_return(apDBusMsg);
600  }
601 
602 
603  if (!lpDBusReply) {
604  BTRCORELOG_ERROR ("Can't create lpDBusReply message\n");
605  return DBUS_HANDLER_RESULT_NEED_MEMORY;
606  }
607  else {
608  BTRCORELOG_INFO ("Authorizing request for %s\n", lpcPath);
609  dbus_connection_send(apDBusConn, lpDBusReply, NULL);
610  dbus_connection_flush(apDBusConn);
611  dbus_message_unref(lpDBusReply);
612  return DBUS_HANDLER_RESULT_HANDLED;
613  }
614 }
615 
616 
617 static DBusHandlerResult
618 btrCore_BTAgentCancelMessage (
619  DBusConnection* apDBusConn,
620  DBusMessage* apDBusMsg,
621  void* apvUserData
622 ) {
623  DBusMessage *lpDBusReply;
624 
625  if (!dbus_message_get_args(apDBusMsg, NULL, DBUS_TYPE_INVALID)) {
626  BTRCORELOG_ERROR ("Invalid arguments for confirmation method");
627  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
628  }
629  BTRCORELOG_INFO ("Request canceled\n");
630  lpDBusReply = dbus_message_new_method_return(apDBusMsg);
631 
632  if (!lpDBusReply) {
633  BTRCORELOG_ERROR ("Can't create lpDBusReply message\n");
634  return DBUS_HANDLER_RESULT_NEED_MEMORY;
635  }
636 
637  dbus_connection_send(apDBusConn, lpDBusReply, NULL);
638  dbus_connection_flush(apDBusConn);
639 
640  dbus_message_unref(lpDBusReply);
641  return DBUS_HANDLER_RESULT_HANDLED;
642 }
643 
644 
645 static DBusMessage*
646 btrCore_BTSendMethodCall (
647  const char* objectpath,
648  const char* interfacename,
649  const char* methodname
650 ) {
651  const char* busname = "org.bluez";
652 
653  DBusMessage* lpDBusMsg = NULL;
654  DBusMessage* lpDBusReply = NULL;
655  DBusPendingCall* lpDBusPendC = NULL;
656 
657 
658  lpDBusMsg = dbus_message_new_method_call(busname,
659  objectpath,
660  interfacename,
661  methodname);
662  if (!lpDBusMsg) {
663  BTRCORELOG_ERROR ("Cannot allocate DBus message!\n");
664  return NULL;
665  }
666 
667  //Now do a sync call
668  if (!dbus_connection_send_with_reply(gpDBusConn, lpDBusMsg, &lpDBusPendC, -1)) { //Send and expect lpDBusReply using pending call object
669  BTRCORELOG_ERROR ("failed to send message!\n");
670  }
671 
672  dbus_connection_flush(gpDBusConn);
673  dbus_message_unref(lpDBusMsg);
674  lpDBusMsg = NULL;
675 
676  dbus_pending_call_block(lpDBusPendC); //Now block on the pending call
677  lpDBusReply = dbus_pending_call_steal_reply(lpDBusPendC); //Get the lpDBusReply message from the queue
678  dbus_pending_call_unref(lpDBusPendC); //Free pending call handle
679 
680  if (dbus_message_get_type(lpDBusReply) == DBUS_MESSAGE_TYPE_ERROR) {
681  BTRCORELOG_ERROR ("Error : %s\n\n", dbus_message_get_error_name(lpDBusReply));
682  dbus_message_unref(lpDBusReply);
683  lpDBusReply = NULL;
684  }
685 
686  return lpDBusReply;
687 }
688 
689 
690 static int
691 btrCore_BTParseDevice (
692  DBusMessage* apDBusMsg,
693  stBTDeviceInfo* apstBTDeviceInfo
694 ) {
695  DBusMessageIter arg_i;
696  DBusMessageIter element_i;
697  DBusMessageIter variant_i;
698  const char* pcKey = NULL;
699  const char* pcBTDevAddr = NULL;
700  int dbus_type;
701  int bPaired = 0;
702  int bConnected = 0;
703  int bTrusted = 0;
704  int bBlocked = 0;
705  unsigned short ui16Vendor = 0;
706  unsigned short ui16VendorSource = 0;
707  unsigned short ui16Product = 0;
708  unsigned short ui16Version = 0;
709  unsigned int ui32Class = 0;
710  short i16RSSI = 0;
711  const char* pcName = NULL;
712  const char* pcAddress = NULL;
713  const char* pcAlias = NULL;
714  const char* pcIcon = NULL;
715 
716  if (!dbus_message_iter_init(apDBusMsg, &arg_i)) {
717  BTRCORELOG_ERROR ("dbus_message_iter_init Failed\n");
718  return -1;
719  }
720 
721  if (!dbus_message_get_args( apDBusMsg, NULL,
722  DBUS_TYPE_STRING, &pcBTDevAddr,
723  DBUS_TYPE_INVALID)) {
724  BTRCORELOG_ERROR ("dbus_message_get_args Failed\n");
725  //return -1; Users of btrCore_BTParseDevice should not call it if the message contains no valid args
726  }
727 
728  dbus_type = dbus_message_iter_get_arg_type(&arg_i);
729  if (dbus_message_iter_get_arg_type(&arg_i) != DBUS_TYPE_ARRAY) {
730  dbus_message_iter_next(&arg_i);
731  dbus_type = dbus_message_iter_get_arg_type(&arg_i);
732 
733  if (dbus_message_iter_get_arg_type(&arg_i) != DBUS_TYPE_ARRAY) {
734  BTRCORELOG_ERROR ("Unknown Prop structure from Bluez\n");
735  return -1;
736  }
737  }
738 
739  dbus_message_iter_recurse(&arg_i, &element_i);
740  while (dbus_message_iter_get_arg_type(&element_i) != DBUS_TYPE_INVALID) {
741  if (dbus_message_iter_get_arg_type(&element_i) == DBUS_TYPE_DICT_ENTRY) {
742  DBusMessageIter dict_i;
743 
744  dbus_message_iter_recurse(&element_i, &dict_i);
745  dbus_message_iter_get_basic(&dict_i, &pcKey);
746 
747  if (strcmp (pcKey, "Address") == 0) {
748  dbus_message_iter_next(&dict_i);
749  dbus_message_iter_recurse(&dict_i, &variant_i);
750  dbus_message_iter_get_basic(&variant_i, &pcAddress);
751  strncpy(apstBTDeviceInfo->pcAddress, pcAddress, BT_MAX_STR_LEN);
752  BTRCORELOG_INFO ("apstBTDeviceInfo->pcAddress : %s\n", apstBTDeviceInfo->pcAddress);
753  }
754  else if (strcmp (pcKey, "Name") == 0) {
755  dbus_message_iter_next(&dict_i);
756  dbus_message_iter_recurse(&dict_i, &variant_i);
757  dbus_message_iter_get_basic(&variant_i, &pcName);
758  strncpy(apstBTDeviceInfo->pcName, pcName, BT_MAX_STR_LEN);
759  BTRCORELOG_INFO ("apstBTDeviceInfo->pcName: %s\n", apstBTDeviceInfo->pcName);
760 
761  }
762  else if (strcmp (pcKey, "Vendor") == 0) {
763  dbus_message_iter_next(&dict_i);
764  dbus_message_iter_recurse(&dict_i, &variant_i);
765  dbus_message_iter_get_basic(&variant_i, &ui16Vendor);
766  apstBTDeviceInfo->ui16Vendor = ui16Vendor;
767  BTRCORELOG_INFO ("apstBTDeviceInfo->ui16Vendor = %d\n", apstBTDeviceInfo->ui16Vendor);
768  }
769  else if (strcmp (pcKey, "VendorSource") == 0) {
770  dbus_message_iter_next(&dict_i);
771  dbus_message_iter_recurse(&dict_i, &variant_i);
772  dbus_message_iter_get_basic(&variant_i, &ui16VendorSource);
773  apstBTDeviceInfo->ui16VendorSource = ui16VendorSource;
774  BTRCORELOG_INFO ("apstBTDeviceInfo->ui16VendorSource = %d\n", apstBTDeviceInfo->ui16VendorSource);
775  }
776  else if (strcmp (pcKey, "Product") == 0) {
777  dbus_message_iter_next(&dict_i);
778  dbus_message_iter_recurse(&dict_i, &variant_i);
779  dbus_message_iter_get_basic(&variant_i, &ui16Product);
780  apstBTDeviceInfo->ui16Product = ui16Product;
781  BTRCORELOG_INFO ("apstBTDeviceInfo->ui16Product = %d\n", apstBTDeviceInfo->ui16Product);
782  }
783  else if (strcmp (pcKey, "Version") == 0) {
784  dbus_message_iter_next(&dict_i);
785  dbus_message_iter_recurse(&dict_i, &variant_i);
786  dbus_message_iter_get_basic(&variant_i, &ui16Version);
787  apstBTDeviceInfo->ui16Version = ui16Version;
788  BTRCORELOG_INFO ("apstBTDeviceInfo->ui16Version = %d\n", apstBTDeviceInfo->ui16Version);
789  }
790  else if (strcmp (pcKey, "Icon") == 0) {
791  dbus_message_iter_next(&dict_i);
792  dbus_message_iter_recurse(&dict_i, &variant_i);
793  dbus_message_iter_get_basic(&variant_i, &pcIcon);
794  strncpy(apstBTDeviceInfo->pcIcon, pcIcon, BT_MAX_STR_LEN);
795  BTRCORELOG_ERROR ("apstBTDeviceInfo->pcIcon: %s\n", apstBTDeviceInfo->pcIcon);
796  }
797  else if (strcmp (pcKey, "Class") == 0) {
798  dbus_message_iter_next(&dict_i);
799  dbus_message_iter_recurse(&dict_i, &variant_i);
800  dbus_message_iter_get_basic(&variant_i, &ui32Class);
801  apstBTDeviceInfo->ui32Class = ui32Class;
802  BTRCORELOG_INFO ("apstBTDeviceInfo->ui32Class: %d\n", apstBTDeviceInfo->ui32Class);
803  }
804  else if (strcmp (pcKey, "Paired") == 0) {
805  dbus_message_iter_next(&dict_i);
806  dbus_message_iter_recurse(&dict_i, &variant_i);
807  dbus_message_iter_get_basic(&variant_i, &bPaired);
808  apstBTDeviceInfo->bPaired = bPaired;
809  BTRCORELOG_ERROR ("apstBTDeviceInfo->bPaired = %d\n", apstBTDeviceInfo->bPaired);
810  }
811  else if (strcmp (pcKey, "Connected") == 0) {
812  dbus_message_iter_next(&dict_i);
813  dbus_message_iter_recurse(&dict_i, &variant_i);
814  dbus_message_iter_get_basic(&variant_i, &bConnected);
815  apstBTDeviceInfo->bConnected = bConnected;
816  BTRCORELOG_INFO ("apstBTDeviceInfo->bConnected = %d\n", apstBTDeviceInfo->bConnected);
817  }
818  else if (strcmp (pcKey, "Trusted") == 0) {
819  dbus_message_iter_next(&dict_i);
820  dbus_message_iter_recurse(&dict_i, &variant_i);
821  dbus_message_iter_get_basic(&variant_i, &bTrusted);
822  apstBTDeviceInfo->bTrusted = bTrusted;
823  BTRCORELOG_INFO ("apstBTDeviceInfo->bTrusted = %d\n", apstBTDeviceInfo->bTrusted);
824  }
825  else if (strcmp (pcKey, "Blocked") == 0) {
826  dbus_message_iter_next(&dict_i);
827  dbus_message_iter_recurse(&dict_i, &variant_i);
828  dbus_message_iter_get_basic(&variant_i, &bBlocked);
829  apstBTDeviceInfo->bBlocked = bBlocked;
830  BTRCORELOG_INFO ("apstBTDeviceInfo->bBlocked = %d\n", apstBTDeviceInfo->bBlocked);
831  }
832  else if (strcmp (pcKey, "Alias") == 0) {
833  dbus_message_iter_next(&dict_i);
834  dbus_message_iter_recurse(&dict_i, &variant_i);
835  dbus_message_iter_get_basic(&variant_i, &pcAlias);
836  strncpy(apstBTDeviceInfo->pcAlias, pcAlias, BT_MAX_STR_LEN);
837  BTRCORELOG_INFO ("apstBTDeviceInfo->pcAlias: %s\n", apstBTDeviceInfo->pcAlias);
838  }
839  else if (strcmp (pcKey, "RSSI") == 0) {
840  dbus_message_iter_next(&dict_i);
841  dbus_message_iter_recurse(&dict_i, &variant_i);
842  dbus_message_iter_get_basic(&variant_i, &i16RSSI);
843  apstBTDeviceInfo->i32RSSI = i16RSSI;
844  BTRCORELOG_INFO ("apstBTDeviceInfo->i32RSSI = %d i16RSSI = %d\n", apstBTDeviceInfo->i32RSSI, i16RSSI);
845  }
846  else if (strcmp (pcKey, "UUIDs") == 0) {
847  dbus_message_iter_next(&dict_i);
848  dbus_message_iter_recurse(&dict_i, &variant_i);
849 
850  dbus_type = dbus_message_iter_get_arg_type (&variant_i);
851  if (dbus_type == DBUS_TYPE_ARRAY) {
852  int count = 0;
853  DBusMessageIter variant_j;
854  dbus_message_iter_recurse(&variant_i, &variant_j);
855 
856  while ((dbus_type = dbus_message_iter_get_arg_type (&variant_j)) != DBUS_TYPE_INVALID)
857  {
858  if ((dbus_type == DBUS_TYPE_STRING) && (count < BT_MAX_DEVICE_PROFILE))
859  {
860  char *pVal = NULL;
861  dbus_message_iter_get_basic (&variant_j, &pVal);
862  BTRCORELOG_INFO ("UUID value is %s\n", pVal);
863  strncpy(apstBTDeviceInfo->aUUIDs[count], pVal, (BT_MAX_UUID_STR_LEN - 1));
864  count++;
865  }
866  dbus_message_iter_next (&variant_j);
867  }
868  }
869  else
870  {
871  BTRCORELOG_ERROR ("apstBTDeviceInfo->Services; Not an Array\n");
872  }
873  }
874  }
875 
876  if (!dbus_message_iter_next(&element_i))
877  break;
878  }
879 
880  (void)dbus_type;
881 
882  if (strlen(apstBTDeviceInfo->pcAlias))
883  strncpy(apstBTDeviceInfo->pcName, apstBTDeviceInfo->pcAlias, strlen(apstBTDeviceInfo->pcAlias));
884 
885  return 0;
886 }
887 
888 static int
889 btrCore_BTParsePropertyChange (
890  DBusMessage* apDBusMsg,
891  stBTDeviceInfo* apstBTDeviceInfo
892 ) {
893  DBusMessageIter arg_i, variant_i;
894  const char* value;
895  const char* bd_addr;
896  int dbus_type;
897 
898  const char* lpcDBusMsgObjPath= dbus_message_get_path(apDBusMsg);
899  char* lpcinBtDevAddr = strstr(lpcDBusMsgObjPath, "/dev_") + strlen("/dev_");
900  char* lpcstBtDevAddr = apstBTDeviceInfo->pcAddress;
901  int i32BtDevAddrLen = strlen(lpcinBtDevAddr);
902  int i32LoopIdx = 0;
903 
904  for (i32LoopIdx = 0; i32LoopIdx < i32BtDevAddrLen; i32LoopIdx++) {
905  if (lpcinBtDevAddr[i32LoopIdx] == '_')
906  lpcstBtDevAddr[i32LoopIdx] = ':';
907  else
908  lpcstBtDevAddr[i32LoopIdx] = lpcinBtDevAddr[i32LoopIdx];
909  }
910 
911  BTRCORELOG_DEBUG("Path = %s Address = %s\n", lpcDBusMsgObjPath, lpcstBtDevAddr);
912 
913  if (!dbus_message_iter_init(apDBusMsg, &arg_i)) {
914  BTRCORELOG_ERROR ("GetProperties lpDBusReply has no arguments.");
915  }
916 
917  if (!dbus_message_get_args( apDBusMsg, NULL,
918  DBUS_TYPE_STRING, &bd_addr,
919  DBUS_TYPE_INVALID)) {
920  BTRCORELOG_ERROR ("Invalid arguments for NameOwnerChanged signal");
921  return -1;
922  }
923 
924  BTRCORELOG_INFO (" Name: %s\n", bd_addr);//"State" then the variant is a string
925  if (strcmp(bd_addr,"State") == 0) {
926  dbus_type = dbus_message_iter_get_arg_type(&arg_i);
927  //BTRCORELOG_ERROR ("type is %d\n", dbus_type);
928 
929  if (dbus_type == DBUS_TYPE_STRING) {
930  dbus_message_iter_next(&arg_i);
931  dbus_message_iter_recurse(&arg_i, &variant_i);
932  dbus_message_iter_get_basic(&variant_i, &value);
933  // BTRCORELOG_ERROR (" the new state is: %s\n", value);
934 
935  if (strcmp(gpcDeviceCurrState, value) != 0) {
936  strncpy(apstBTDeviceInfo->pcDevicePrevState, gpcDeviceCurrState, BT_MAX_STR_LEN - 1);
937  strncpy(apstBTDeviceInfo->pcDeviceCurrState, value, BT_MAX_STR_LEN - 1);
938  strncpy(gpcDeviceCurrState, value, BT_MAX_STR_LEN - 1);
939  }
940  }
941  }
942  else if (strcmp(bd_addr, "Connected") == 0) {
943  int isConnected = 0;
944 
945  // The gpcDeviceCurrState could be either "connecting" or "playing"; just in case, if it comes in other scenario, just ignore
946  if ((strcmp (gpcDeviceCurrState, "connecting") == 0) ||
947  (strcmp (gpcDeviceCurrState, "playing") == 0))
948  {
949  dbus_type = dbus_message_iter_get_arg_type(&arg_i);
950  if (dbus_type == DBUS_TYPE_BOOLEAN)
951  {
952  dbus_message_iter_next(&arg_i);
953  dbus_message_iter_recurse(&arg_i, &variant_i);
954  dbus_message_iter_get_basic(&variant_i, &isConnected);
955 
956  if (1 == isConnected)
957  value = "connected";
958  else if (0 == isConnected)
959  value = "disconnected";
960 
961  strncpy(apstBTDeviceInfo->pcDevicePrevState, gpcDeviceCurrState, BT_MAX_STR_LEN - 1);
962  strncpy(apstBTDeviceInfo->pcDeviceCurrState, value, BT_MAX_STR_LEN - 1);
963  strncpy(gpcDeviceCurrState, value, BT_MAX_STR_LEN - 1);
964  }
965  }
966  }
967 
968  return 0;
969 }
970 
971 static DBusMessage*
972 btrCore_BTMediaEndpointSelectConfiguration (
973  DBusMessage* apDBusMsg
974 ) {
975  int lDBusArgsSize;
976  void* lpInputMediaCaps;
977  void* lpOutputMediaCaps;
978  DBusMessage* lpDBusReply;
979  DBusError lDBusErr;
980 
981 
982  dbus_error_init(&lDBusErr);
983  if (!dbus_message_get_args(apDBusMsg, &lDBusErr, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &lpInputMediaCaps, &lDBusArgsSize, DBUS_TYPE_INVALID)) {
984  btrCore_BTHandleDusError(&lDBusErr, __LINE__, __FUNCTION__);
985  return dbus_message_new_error(apDBusMsg, "org.bluez.MediaEndpoint.Error.InvalidArguments", "Unable to select configuration");
986  }
987 
988  if (gfpcBNegotiateMedia) {
989  if(!(lpOutputMediaCaps = gfpcBNegotiateMedia(lpInputMediaCaps, gpcBNegMediaUserData))) {
990  return dbus_message_new_error(apDBusMsg, "org.bluez.MediaEndpoint.Error.InvalidArguments", "Unable to select configuration");
991  }
992  }
993 
994 
995  lpDBusReply = dbus_message_new_method_return(apDBusMsg);
996  dbus_message_append_args (lpDBusReply, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &lpOutputMediaCaps, lDBusArgsSize, DBUS_TYPE_INVALID);
997  return lpDBusReply;
998 }
999 
1000 
1001 static DBusMessage*
1002 btrCore_BTMediaEndpointSetConfiguration (
1003  DBusMessage* apDBusMsg
1004 ) {
1005  const char* lDevTransportPath = NULL;
1006  const char* lStoredDevTransportPath = NULL;
1007  const char* dev_path = NULL, *uuid = NULL, *routing = NULL;
1008  int codec = 0;
1009  unsigned char* config = NULL;
1010  int size = 0;
1011  int nrec= 0, inbandRingtone = 0;
1012  unsigned short int delay = 0;
1013  unsigned short int volume= 0;
1014 
1015  DBusMessageIter lDBusMsgIter;
1016  DBusMessageIter lDBusMsgIterProp;
1017  DBusMessageIter lDBusMsgIterEntry;
1018  DBusMessageIter lDBusMsgIterValue;
1019  DBusMessageIter lDBusMsgIterArr;
1020 
1021 
1022  dbus_message_iter_init(apDBusMsg, &lDBusMsgIter);
1023  dbus_message_iter_get_basic(&lDBusMsgIter, &lDevTransportPath);
1024  if (!dbus_message_iter_next(&lDBusMsgIter))
1025  return dbus_message_new_error(apDBusMsg, "org.bluez.MediaEndpoint.Error.InvalidArguments", "Unable to set configuration");
1026 
1027  dbus_message_iter_recurse(&lDBusMsgIter, &lDBusMsgIterProp);
1028  if (dbus_message_iter_get_arg_type(&lDBusMsgIterProp) != DBUS_TYPE_DICT_ENTRY)
1029  return dbus_message_new_error(apDBusMsg, "org.bluez.MediaEndpoint.Error.InvalidArguments", "Unable to set configuration");
1030 
1031  while (dbus_message_iter_get_arg_type(&lDBusMsgIterProp) == DBUS_TYPE_DICT_ENTRY) {
1032  const char *key;
1033  int ldBusType;
1034 
1035  dbus_message_iter_recurse(&lDBusMsgIterProp, &lDBusMsgIterEntry);
1036  dbus_message_iter_get_basic(&lDBusMsgIterEntry, &key);
1037 
1038  dbus_message_iter_next(&lDBusMsgIterEntry);
1039  dbus_message_iter_recurse(&lDBusMsgIterEntry, &lDBusMsgIterValue);
1040 
1041  ldBusType = dbus_message_iter_get_arg_type(&lDBusMsgIterValue);
1042  if (strcasecmp(key, "UUID") == 0) {
1043  if (ldBusType != DBUS_TYPE_STRING)
1044  return dbus_message_new_error(apDBusMsg, "org.bluez.MediaEndpoint.Error.InvalidArguments", "Unable to set configuration");
1045 
1046  dbus_message_iter_get_basic(&lDBusMsgIterValue, &uuid);
1047  BTRCORELOG_INFO ("btrCore_BTMediaEndpointSetConfiguration - UUID %s\n", uuid);
1048  }
1049  else if (strcasecmp(key, "Device") == 0) {
1050  if (ldBusType != DBUS_TYPE_OBJECT_PATH)
1051  return dbus_message_new_error(apDBusMsg, "org.bluez.MediaEndpoint.Error.InvalidArguments", "Unable to set configuration");
1052 
1053  dbus_message_iter_get_basic(&lDBusMsgIterValue, &dev_path);
1054  BTRCORELOG_INFO ("btrCore_BTMediaEndpointSetConfiguration - Device %s\n", dev_path);
1055  }
1056  else if (strcasecmp(key, "Codec") == 0) {
1057  if (ldBusType != DBUS_TYPE_BYTE)
1058  return dbus_message_new_error(apDBusMsg, "org.bluez.MediaEndpoint.Error.InvalidArguments", "Unable to set configuration");
1059 
1060  dbus_message_iter_get_basic(&lDBusMsgIterValue, &codec);
1061  BTRCORELOG_ERROR ("btrCore_BTMediaEndpointSetConfiguration - Codec %d\n", codec);
1062  }
1063  else if (strcasecmp(key, "Configuration") == 0) {
1064  if (ldBusType != DBUS_TYPE_ARRAY)
1065  return dbus_message_new_error(apDBusMsg, "org.bluez.MediaEndpoint.Error.InvalidArguments", "Unable to set configuration");
1066 
1067  dbus_message_iter_recurse(&lDBusMsgIterValue, &lDBusMsgIterArr);
1068  dbus_message_iter_get_fixed_array(&lDBusMsgIterArr, &config, &size);
1069  BTRCORELOG_INFO ("btrCore_BTMediaEndpointSetConfiguration - Configuration \n");
1070  }
1071  else if (strcasecmp(key, "Delay") == 0) {
1072  if (ldBusType != DBUS_TYPE_UINT16)
1073  return dbus_message_new_error(apDBusMsg, "org.bluez.MediaEndpoint.Error.InvalidArguments", "Unable to set configuration");
1074 
1075  dbus_message_iter_get_basic(&lDBusMsgIterValue, &delay);
1076  BTRCORELOG_INFO ("btrCore_BTMediaEndpointSetConfiguration - Delay %d\n", delay);
1077  }
1078  else if (strcasecmp(key, "NREC") == 0) {
1079  if (ldBusType != DBUS_TYPE_BOOLEAN)
1080  return dbus_message_new_error(apDBusMsg, "org.bluez.MediaEndpoint.Error.InvalidArguments", "Unable to set configuration");
1081 
1082  dbus_message_iter_get_basic(&lDBusMsgIterValue, &nrec);
1083  BTRCORELOG_INFO ("btrCore_BTMediaEndpointSetConfiguration - NREC %d\n", nrec);
1084  }
1085  else if (strcasecmp(key, "InbandRingtone") == 0) {
1086  if (ldBusType != DBUS_TYPE_BOOLEAN)
1087  return dbus_message_new_error(apDBusMsg, "org.bluez.MediaEndpoint.Error.InvalidArguments", "Unable to set configuration");
1088 
1089  dbus_message_iter_get_basic(&lDBusMsgIterValue, &inbandRingtone);
1090  BTRCORELOG_INFO ("btrCore_BTMediaEndpointSetConfiguration - InbandRingtone %d\n", inbandRingtone);
1091  }
1092  else if (strcasecmp(key, "Routing") == 0) {
1093  if (ldBusType != DBUS_TYPE_STRING)
1094  return dbus_message_new_error(apDBusMsg, "org.bluez.MediaEndpoint.Error.InvalidArguments", "Unable to set configuration");
1095 
1096  dbus_message_iter_get_basic(&lDBusMsgIterValue, &routing);
1097  BTRCORELOG_INFO ("btrCore_BTMediaEndpointSetConfiguration - routing %s\n", routing);
1098  }
1099  else if (strcasecmp(key, "Volume") == 0) {
1100  if (ldBusType != DBUS_TYPE_UINT16)
1101  return dbus_message_new_error(apDBusMsg, "org.bluez.MediaEndpoint.Error.InvalidArguments", "Unable to set configuration");
1102 
1103  dbus_message_iter_get_basic(&lDBusMsgIterValue, &volume);
1104  BTRCORELOG_INFO ("btrCore_BTMediaEndpointSetConfiguration - Volume %d\n", volume);
1105  }
1106 
1107  dbus_message_iter_next(&lDBusMsgIterProp);
1108  }
1109 
1110  BTRCORELOG_INFO ("Set configuration - Transport Path %s\n", lDevTransportPath);
1111 
1112  if (gpcDevTransportPath) {
1113  free(gpcDevTransportPath);
1114  gpcDevTransportPath = NULL;
1115  }
1116 
1117  gpcDevTransportPath = strdup(lDevTransportPath);
1118 
1119  if (gfpcBTransportPathMedia) {
1120  if((lStoredDevTransportPath = gfpcBTransportPathMedia(lDevTransportPath, config, gpcBTransPathMediaUserData))) {
1121  BTRCORELOG_INFO ("Stored - Transport Path 0x%p:%s\n", lStoredDevTransportPath, lStoredDevTransportPath);
1122  }
1123  }
1124 
1125  return dbus_message_new_method_return(apDBusMsg);
1126 }
1127 
1128 
1129 static DBusMessage*
1130 btrCore_BTMediaEndpointClearConfiguration (
1131  DBusMessage* apDBusMsg
1132 ) {
1133  DBusMessage* lpDBusReply = NULL;
1134  DBusMessageIter lDBusMsgIter;
1135  const char* lDevTransportPath = NULL;
1136  const char* lStoredDevTransportPath = NULL;
1137 
1138  dbus_message_iter_init(apDBusMsg, &lDBusMsgIter);
1139  dbus_message_iter_get_basic(&lDBusMsgIter, &lDevTransportPath);
1140  BTRCORELOG_DEBUG ("Clear configuration - Transport Path %s\n", lDevTransportPath);
1141 
1142  if (gpcDevTransportPath) {
1143  free(gpcDevTransportPath);
1144  gpcDevTransportPath = NULL;
1145  }
1146 
1147  if (gfpcBTransportPathMedia) {
1148  if(!(lStoredDevTransportPath = gfpcBTransportPathMedia(lDevTransportPath, NULL, gpcBTransPathMediaUserData))) {
1149  BTRCORELOG_INFO ("Cleared - Transport Path %s\n", lDevTransportPath);
1150  }
1151  }
1152 
1153  lpDBusReply = dbus_message_new_method_return(apDBusMsg);
1154  return lpDBusReply;
1155 }
1156 
1157 
1158 /* Interfaces */
1159 void*
1161  void
1162 ) {
1163  DBusError lDBusErr;
1164  DBusConnection* lpDBusConn = NULL;
1165 
1166  dbus_error_init(&lDBusErr);
1167  lpDBusConn = dbus_bus_get(DBUS_BUS_SYSTEM, &lDBusErr);
1168 
1169  if (lpDBusConn == NULL) {
1170  btrCore_BTHandleDusError(&lDBusErr, __LINE__, __FUNCTION__);
1171  return NULL;
1172  }
1173 
1174  BTRCORELOG_INFO ("DBus Debug DBus Connection Name %s\n", dbus_bus_get_unique_name (lpDBusConn));
1175  gpDBusConn = lpDBusConn;
1176 
1177  if (!dbus_connection_add_filter(gpDBusConn, btrCore_BTDBusConnectionFilter_cb, NULL, NULL)) {
1178  BTRCORELOG_ERROR ("Can't add signal filter - BtrCore_BTInitGetConnection\n");
1180  return NULL;
1181  }
1182 
1183  dbus_bus_add_match(gpDBusConn, "type='signal',interface='org.bluez.Adapter'", NULL);
1184 
1185  gpcBConnAuthPassKey = 0;
1186 
1187  gpcBTransPathMediaUserData = NULL;
1188  gpcBNegMediaUserData = NULL;
1189  gpcBConnIntimUserData = NULL;
1190  gpcBConnAuthUserData = NULL;
1191  gpcBDevStatusUserData = NULL;
1192  gfpcBDevStatusUpdate = NULL;
1193  gfpcBNegotiateMedia = NULL;
1194  gfpcBTransportPathMedia = NULL;
1195  gfpcBConnectionIntimation = NULL;
1196  gfpcBConnectionAuthentication = NULL;
1197 
1198  return (void*)gpDBusConn;
1199 }
1200 
1201 
1202 int
1204  void* apBtConn
1205 ) {
1206  if (!gpDBusConn || (gpDBusConn != apBtConn))
1207  return -1;
1208 
1209 
1210  if (gpcBTAgentPath) {
1211  free(gpcBTAgentPath);
1212  gpcBTAgentPath = NULL;
1213  }
1214 
1215  if (gpcBTDAdapterPath) {
1216  free(gpcBTDAdapterPath);
1217  gpcBTDAdapterPath = NULL;
1218  }
1219 
1220  if (gpcBTAdapterPath) {
1221  free(gpcBTAdapterPath);
1222  gpcBTAdapterPath = NULL;
1223  }
1224 
1225  gfpcBConnectionAuthentication = NULL;
1226  gfpcBConnectionIntimation = NULL;
1227  gfpcBTransportPathMedia = NULL;
1228  gfpcBNegotiateMedia = NULL;
1229  gfpcBDevStatusUpdate = NULL;
1230  gpcBDevStatusUserData = NULL;
1231  gpcBConnAuthUserData = NULL;
1232  gpcBConnIntimUserData = NULL;
1233  gpcBNegMediaUserData = NULL;
1234  gpcBTransPathMediaUserData = NULL;
1235 
1236  gpcBConnAuthPassKey = 0;
1237 
1238  dbus_bus_remove_match(gpDBusConn, "type='signal',interface='org.bluez.Adapter'", NULL);
1239 
1240  dbus_connection_remove_filter(gpDBusConn, btrCore_BTDBusConnectionFilter_cb, NULL);
1241 
1242  gpDBusConn = NULL;
1243 
1244  return 0;
1245 }
1246 
1247 
1248 char*
1250  void* apBtConn
1251 ) {
1252  char lDefaultBTPath[128] = {'\0'};
1253 
1254  if (!gpDBusConn || (gpDBusConn != apBtConn))
1255  return NULL;
1256 
1257  snprintf(lDefaultBTPath, sizeof(lDefaultBTPath), "/org/bluez/agent_%d", getpid());
1258 
1259  if (gpcBTAgentPath) {
1260  free(gpcBTAgentPath);
1261  gpcBTAgentPath = NULL;
1262  }
1263 
1264  gpcBTAgentPath = strdup(lDefaultBTPath);
1265  return gpcBTAgentPath;
1266 }
1267 
1268 
1269 int
1271  void* apBtConn
1272 ) {
1273  if (!gpDBusConn || (gpDBusConn != apBtConn))
1274  return -1;
1275 
1276  if (gpcBTAgentPath) {
1277  free(gpcBTAgentPath);
1278  gpcBTAgentPath = NULL;
1279  }
1280 
1281  return 0;
1282 }
1283 
1284 
1285 int
1287  void* apBtConn,
1288  const char* apBtAdapter,
1289  const char* apBtAgentPath,
1290  const char* capabilities
1291 ) {
1292  DBusMessage* lpDBusMsg = NULL;
1293  DBusMessage* lpDBusReply = NULL;
1294  DBusError lDBusErr;
1295 
1296  if (!gpDBusConn || (gpDBusConn != apBtConn))
1297  return -1;
1298 
1299 
1300  if (!dbus_connection_register_object_path(gpDBusConn, apBtAgentPath, &gDBusAgentVTable, NULL)) {
1301  BTRCORELOG_ERROR ("Error registering object path for agent\n");
1302  return -1;
1303  }
1304 
1305  lpDBusMsg = dbus_message_new_method_call("org.bluez",
1306  apBtAdapter,
1307  "org.bluez.Adapter",
1308  "RegisterAgent");
1309  if (!lpDBusMsg) {
1310  BTRCORELOG_ERROR ("Error allocating new method call\n");
1311  return -1;
1312  }
1313 
1314  dbus_message_append_args(lpDBusMsg, DBUS_TYPE_OBJECT_PATH, &apBtAgentPath, DBUS_TYPE_STRING, &capabilities, DBUS_TYPE_INVALID);
1315 
1316 
1317  dbus_error_init(&lDBusErr);
1318  lpDBusReply = dbus_connection_send_with_reply_and_block(gpDBusConn, lpDBusMsg, -1, &lDBusErr);
1319  dbus_message_unref(lpDBusMsg);
1320 
1321  if (!lpDBusReply) {
1322  BTRCORELOG_ERROR ("Unable to register agent\n");
1323  btrCore_BTHandleDusError(&lDBusErr, __LINE__, __FUNCTION__);
1324  return -1;
1325  }
1326 
1327  dbus_message_unref(lpDBusReply);
1328 
1329  dbus_connection_flush(gpDBusConn);
1330 
1331  return 0;
1332 }
1333 
1334 
1335 int
1337  void* apBtConn,
1338  const char* apBtAdapter,
1339  const char* apBtAgentPath
1340 ) {
1341  DBusMessage* lpDBusMsg = NULL;
1342  DBusMessage* lpDBusReply = NULL;
1343  DBusError lDBusErr;
1344 
1345  if (!gpDBusConn || (gpDBusConn != apBtConn))
1346  return -1;
1347 
1348 
1349  lpDBusMsg = dbus_message_new_method_call("org.bluez",
1350  apBtAdapter,
1351  "org.bluez.Adapter",
1352  "UnregisterAgent");
1353  if (!lpDBusMsg) {
1354  BTRCORELOG_ERROR ("Can't allocate new method call\n");
1355  return -1;
1356  }
1357 
1358  dbus_message_append_args(lpDBusMsg, DBUS_TYPE_OBJECT_PATH, &apBtAgentPath, DBUS_TYPE_INVALID);
1359 
1360 
1361  dbus_error_init(&lDBusErr);
1362  lpDBusReply = dbus_connection_send_with_reply_and_block(gpDBusConn, lpDBusMsg, -1, &lDBusErr);
1363  dbus_message_unref(lpDBusMsg);
1364 
1365  if (!lpDBusReply) {
1366  BTRCORELOG_ERROR ("Can't unregister agent\n");
1367  btrCore_BTHandleDusError(&lDBusErr, __LINE__, __FUNCTION__);
1368  return -1;
1369  }
1370 
1371  dbus_message_unref(lpDBusReply);
1372 
1373  dbus_connection_flush(gpDBusConn);
1374 
1375  if (!dbus_connection_unregister_object_path(gpDBusConn, apBtAgentPath)) {
1376  BTRCORELOG_ERROR ("Error unregistering object path for agent\n");
1377  return -1;
1378  }
1379 
1380  return 0;
1381 }
1382 
1383 
1384 int
1386  void* apBtConn,
1387  unsigned int* apBtNumAdapters,
1388  char** apcArrBtAdapterPath
1389 ) {
1390  DBusMessage* lpDBusReply = NULL;
1391  DBusError lDBusErr;
1392  dbus_bool_t lDBusOp;
1393  char** paths = NULL;
1394  int i = -1;
1395  int rc = -1;
1396  int num = -1;
1397 
1398  if (!gpDBusConn || (gpDBusConn != apBtConn))
1399  return -1;
1400 
1401 
1402  lpDBusReply = btrCore_BTSendMethodCall("/", "org.bluez.Manager", "ListAdapters");
1403  if (!lpDBusReply) {
1404  BTRCORELOG_ERROR ("org.bluez.Manager.ListAdapters returned an error\n");
1405  return rc;
1406  }
1407 
1408 
1409  dbus_error_init(&lDBusErr);
1410  lDBusOp = dbus_message_get_args(lpDBusReply, &lDBusErr, DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &paths, &num, DBUS_TYPE_INVALID);
1411  dbus_message_unref(lpDBusReply);
1412 
1413  if (!lDBusOp) {
1414  BTRCORELOG_ERROR ("org.bluez.Manager.GetProperties parsing failed\n");
1415  btrCore_BTHandleDusError(&lDBusErr, __LINE__, __FUNCTION__);
1416  return rc;
1417  }
1418 
1419 
1420  if (apBtNumAdapters && apcArrBtAdapterPath) {
1421  *apBtNumAdapters = num;
1422 
1423  for (i = 0; i < num; i++) {
1424  if (*(apcArrBtAdapterPath + i)) {
1425  BTRCORELOG_INFO ("Adapter Path: %d is %s\n", i, paths[i]);
1426  strncpy(*(apcArrBtAdapterPath + i), paths[i], BD_NAME_LEN);
1427  rc = 0;
1428  }
1429  }
1430  }
1431 
1432 
1433  return rc;
1434 }
1435 
1436 
1437 char*
1439  void* apBtConn,
1440  const char* apBtAdapter
1441 ) {
1442  DBusMessage* lpDBusMsg = NULL;
1443  DBusMessage* lpDBusReply = NULL;
1444  const char* lpReplyPath = NULL;
1445 
1446  DBusError lDBusErr;
1447  dbus_bool_t lDBusOp;
1448 
1449  if (!gpDBusConn || (gpDBusConn != apBtConn))
1450  return NULL;
1451 
1452  if (!apBtAdapter)
1453  return btrCore_BTGetDefaultAdapterPath();
1454 
1455  lpDBusMsg = dbus_message_new_method_call("org.bluez",
1456  "/",
1457  "org.bluez.Manager",
1458  "FindAdapter");
1459  if (!lpDBusMsg) {
1460  BTRCORELOG_ERROR ("Can't allocate new method call\n");
1461  return NULL;
1462  }
1463 
1464  dbus_message_append_args(lpDBusMsg, DBUS_TYPE_STRING, &apBtAdapter, DBUS_TYPE_INVALID);
1465 
1466  dbus_error_init(&lDBusErr);
1467  lpDBusReply = dbus_connection_send_with_reply_and_block(gpDBusConn, lpDBusMsg, -1, &lDBusErr);
1468  dbus_message_unref(lpDBusMsg);
1469 
1470  if (!lpDBusReply) {
1471  BTRCORELOG_ERROR ("Can't find adapter %s\n", apBtAdapter);
1472  btrCore_BTHandleDusError(&lDBusErr, __LINE__, __FUNCTION__);
1473  return NULL;
1474  }
1475 
1476  lDBusOp = dbus_message_get_args(lpDBusReply, &lDBusErr, DBUS_TYPE_OBJECT_PATH, &lpReplyPath, DBUS_TYPE_INVALID);
1477  dbus_message_unref(lpDBusReply);
1478 
1479  if (!lDBusOp) {
1480  BTRCORELOG_ERROR ("Can't get lpDBusReply arguments\n");
1481  btrCore_BTHandleDusError(&lDBusErr, __LINE__, __FUNCTION__);
1482  return NULL;
1483  }
1484 
1485  dbus_connection_flush(gpDBusConn);
1486 
1487  if (gpcBTAdapterPath) {
1488  free(gpcBTAdapterPath);
1489  gpcBTAdapterPath = NULL;
1490  }
1491 
1492  gpcBTAdapterPath = strndup(lpReplyPath, strlen(lpReplyPath));
1493 
1494  return gpcBTAdapterPath;
1495 }
1496 
1497 
1498 int
1500  void* apBtConn,
1501  const char* apBtAdapter
1502 ) {
1503  if (!gpDBusConn || (gpDBusConn != apBtConn))
1504  return -1;
1505 
1506  if (!apBtAdapter) {
1507  return btrCore_BTReleaseDefaultAdapterPath();
1508  }
1509 
1510  if (gpcBTAdapterPath) {
1511  if (gpcBTAdapterPath != apBtAdapter) {
1512  BTRCORELOG_ERROR ("ERROR: Looks like Adapter path has been changed by User\n");
1513  }
1514  free(gpcBTAdapterPath);
1515  gpcBTAdapterPath = NULL;
1516  }
1517 
1518  return 0;
1519 }
1520 
1521 
1522 int
1524  void* apBtConn,
1525  char* apBtOutIfceName,
1526  char* apBtOutVersion
1527 ) {
1528  FILE* lfpVersion = NULL;
1529  char lcpVersion[8] = {'\0'};
1530 
1531  if (!gpDBusConn || (gpDBusConn != apBtConn))
1532  return -1;
1533 
1534  if (!apBtOutIfceName || !apBtOutVersion)
1535  return -1;
1536 
1537  lfpVersion = popen("/usr/sbin/bluetoothd --version", "r");
1538  if ((lfpVersion == NULL)) {
1539  BTRCORELOG_ERROR ("Failed to run Version command\n");
1540  strncpy(lcpVersion, "4.XXX", strlen("4.XXX"));
1541  }
1542  else {
1543  if (fgets(lcpVersion, sizeof(lcpVersion)-1, lfpVersion) == NULL) {
1544  BTRCORELOG_ERROR ("Failed to Valid Version\n");
1545  strncpy(lcpVersion, "4.XXX", strlen("4.XXX"));
1546  }
1547 
1548  pclose(lfpVersion);
1549  }
1550 
1551 
1552  strncpy(apBtOutIfceName, "Bluez", strlen("Bluez"));
1553  strncpy(apBtOutVersion, lcpVersion, strlen(lcpVersion));
1554 
1555  return 0;
1556 }
1557 
1558 
1559 int
1561  void* apBtConn,
1562  const char* apcBtOpIfcePath,
1563  enBTOpIfceType aenBtOpIfceType,
1564  unBTOpIfceProp aunBtOpIfceProp,
1565  void* apvVal
1566 ) {
1567  int rc = 0;
1568 
1569  DBusMessage* lpDBusReply = NULL;
1570  DBusMessageIter arg_i;
1571  DBusMessageIter element_i;
1572  DBusMessageIter variant_i;
1573  DBusError lDBusErr;
1574  const char* pParsedKey = NULL;
1575  const char* pParsedValueString = NULL;
1576  int parsedValueNumber = 0;
1577  unsigned int parsedValueUnsignedNumber = 0;
1578  unsigned short parsedValueUnsignedShort = 0;
1579 
1580  const char* lDBusKey = NULL;
1581  int lDBusType = DBUS_TYPE_INVALID;
1582 
1583  const char* pInterface = NULL;
1584  const char* pAdapterInterface = "org.bluez.Adapter";
1585  const char* pDeviceInterface = "org.bluez.Device";
1586  const char* pMediaTransInterface= "org.bluez.MediaTransport";
1587 
1588  if (!gpDBusConn || (gpDBusConn != apBtConn))
1589  return -1;
1590 
1591  if ((!apcBtOpIfcePath) || (!apvVal)) {
1592  BTRCORELOG_ERROR ("enBTRCoreInvalidArg - enBTRCoreInitFailure\n");
1593  return -1;
1594  }
1595 
1596  switch (aenBtOpIfceType) {
1597  case enBTAdapter:
1598  pInterface = pAdapterInterface;
1599  switch (aunBtOpIfceProp.enBtAdapterProp) {
1600  case enBTAdPropName:
1601  lDBusType = DBUS_TYPE_STRING;
1602  lDBusKey = "Name";
1603  break;
1604  case enBTAdPropAddress:
1605  lDBusType = DBUS_TYPE_STRING;
1606  lDBusKey = "Address";
1607  break;
1608  case enBTAdPropPowered:
1609  lDBusType = DBUS_TYPE_BOOLEAN;
1610  lDBusKey = "Powered";
1611  break;
1612  case enBTAdPropDiscoverable:
1613  lDBusType = DBUS_TYPE_BOOLEAN;
1614  lDBusKey = "Discoverable";
1615  break;
1616  case enBTAdPropDiscoverableTimeOut:
1617  lDBusType = DBUS_TYPE_UINT32;
1618  lDBusKey = "DiscoverableTimeout";
1619  break;
1620  case enBTAdPropUnknown:
1621  default:
1622  BTRCORELOG_ERROR ("Invalid Adapter Property\n");
1623  return -1;
1624  }
1625  break;
1626  case enBTDevice:
1627  pInterface = pDeviceInterface;
1628  switch (aunBtOpIfceProp.enBtDeviceProp) {
1629  case enBTDevPropPaired:
1630  lDBusType = DBUS_TYPE_BOOLEAN;
1631  lDBusKey = "Paired";
1632  break;
1633  case enBTDevPropConnected:
1634  lDBusType = DBUS_TYPE_BOOLEAN;
1635  lDBusKey = "Connected";
1636  break;
1637  case enBTDevPropVendor:
1638  lDBusType = DBUS_TYPE_UINT16;
1639  lDBusKey = "Vendor";
1640  break;
1641  case enBTDevPropUnknown:
1642  default:
1643  BTRCORELOG_ERROR ("Invalid Device Property\n");
1644  return -1;
1645  }
1646  break;
1647  case enBTMediaTransport:
1648  pInterface = pMediaTransInterface;
1649  switch (aunBtOpIfceProp.enBtMediaTransportProp) {
1650  case enBTMedTPropDelay:
1651  lDBusType = DBUS_TYPE_UINT16;
1652  lDBusKey = "Delay";
1653  break;
1654  case enBTMedTPropUnknown:
1655  default:
1656  BTRCORELOG_ERROR ("Invalid MediaTransport Property\n");
1657  return -1;
1658  }
1659  break;
1660  case enBTUnknown:
1661  default:
1662  BTRCORELOG_ERROR ("Invalid Operational Interface\n");
1663  return -1;
1664  }
1665 
1666 
1667  dbus_error_init(&lDBusErr);
1668  lpDBusReply = btrCore_BTSendMethodCall(apcBtOpIfcePath, pInterface, "GetProperties");
1669  if (!lpDBusReply) {
1670  BTRCORELOG_ERROR ("%s.GetProperties returned an error: '%s'\n", pInterface, lDBusErr.message);
1671  rc = -1;
1672  dbus_error_free(&lDBusErr);
1673  }
1674  else {
1675  if (!dbus_message_iter_init(lpDBusReply, &arg_i)) {
1676  BTRCORELOG_ERROR ("GetProperties lpDBusReply has no arguments.");
1677  rc = -1;
1678  }
1679  else if (dbus_message_iter_get_arg_type(&arg_i) != DBUS_TYPE_ARRAY) {
1680  BTRCORELOG_ERROR ("GetProperties argument is not an array.");
1681  rc = -1;
1682  }
1683  else {
1684  dbus_message_iter_recurse(&arg_i, &element_i);
1685  while (dbus_message_iter_get_arg_type(&element_i) != DBUS_TYPE_INVALID) {
1686  if (dbus_message_iter_get_arg_type(&element_i) == DBUS_TYPE_DICT_ENTRY) {
1687  DBusMessageIter dict_i;
1688  dbus_message_iter_recurse(&element_i, &dict_i);
1689  dbus_message_iter_get_basic(&dict_i, &pParsedKey);
1690 
1691  if ((pParsedKey) && (strcmp (pParsedKey, lDBusKey) == 0)) {
1692  dbus_message_iter_next(&dict_i);
1693  dbus_message_iter_recurse(&dict_i, &variant_i);
1694  if (lDBusType == DBUS_TYPE_STRING) {
1695  dbus_message_iter_get_basic(&variant_i, &pParsedValueString);
1696  //BTRCORELOG_ERROR ("Key is %s and the value in string is %s\n", pParsedKey, pParsedValueString);
1697  strncpy (apvVal, pParsedValueString, BD_NAME_LEN);
1698  }
1699  else if (lDBusType == DBUS_TYPE_UINT16) {
1700  unsigned short* ptr = (unsigned short*) apvVal;
1701  dbus_message_iter_get_basic(&variant_i, &parsedValueUnsignedShort);
1702  //BTRCORELOG_ERROR ("Key is %s and the value is %u\n", pParsedKey, parsedValueUnsignedNumber);
1703  *ptr = parsedValueUnsignedShort;
1704  }
1705  else if (lDBusType == DBUS_TYPE_UINT32) {
1706  unsigned int* ptr = (unsigned int*) apvVal;
1707  dbus_message_iter_get_basic(&variant_i, &parsedValueUnsignedNumber);
1708  //BTRCORELOG_ERROR ("Key is %s and the value is %u\n", pParsedKey, parsedValueUnsignedNumber);
1709  *ptr = parsedValueUnsignedNumber;
1710  }
1711  else { /* As of now ints and bools are used. This function has to be extended for array if needed */
1712  int* ptr = (int*) apvVal;
1713  dbus_message_iter_get_basic(&variant_i, &parsedValueNumber);
1714  //BTRCORELOG_ERROR ("Key is %s and the value is %d\n", pParsedKey, parsedValueNumber);
1715  *ptr = parsedValueNumber;
1716  }
1717  rc = 0;
1718  break;
1719  }
1720  }
1721 
1722  if (!dbus_message_iter_next(&element_i))
1723  break;
1724  }
1725  }
1726 
1727  btrCore_BTHandleDusError(&lDBusErr, __LINE__, __FUNCTION__);
1728 
1729  dbus_message_unref(lpDBusReply);
1730  }
1731 
1732  return rc;
1733 }
1734 
1735 
1736 int
1738  void* apBtConn,
1739  const char* apcBtOpIfcePath,
1740  enBTOpIfceType aenBtOpIfceType,
1741  unBTOpIfceProp aunBtOpIfceProp,
1742  void* apvVal
1743 ) {
1744 
1745  DBusMessage* lpDBusMsg = NULL;
1746  DBusMessage* lpDBusReply = NULL;
1747  DBusMessageIter lDBusMsgIter;
1748  DBusMessageIter lDBusMsgIterValue;
1749  DBusError lDBusErr;
1750 
1751  const char* lDBusTypeAsString;
1752 
1753  const char* lDBusKey = NULL;
1754  int lDBusType = DBUS_TYPE_INVALID;
1755 
1756  const char* pInterface = NULL;
1757  const char* pAdapterInterface = "org.bluez.Adapter";
1758  const char* pDeviceInterface = "org.bluez.Device";
1759  const char* pMediaTransInterface= "org.bluez.MediaTransport";
1760 
1761 
1762  if (!gpDBusConn || (gpDBusConn != apBtConn) || !apvVal)
1763  return -1;
1764 
1765  if ((!apcBtOpIfcePath) || (!apvVal)) {
1766  BTRCORELOG_ERROR ("enBTRCoreInvalidArg - enBTRCoreInitFailure\n");
1767  return -1;
1768  }
1769 
1770 
1771  switch (aenBtOpIfceType) {
1772  case enBTAdapter:
1773  pInterface = pAdapterInterface;
1774  switch (aunBtOpIfceProp.enBtAdapterProp) {
1775  case enBTAdPropName:
1776  lDBusType = DBUS_TYPE_STRING;
1777  lDBusKey = "Alias";
1778  break;
1779  case enBTAdPropAddress:
1780  lDBusType = DBUS_TYPE_STRING;
1781  lDBusKey = "Address";
1782  break;
1783  case enBTAdPropPowered:
1784  lDBusType = DBUS_TYPE_BOOLEAN;
1785  lDBusKey = "Powered";
1786  break;
1787  case enBTAdPropDiscoverable:
1788  lDBusType = DBUS_TYPE_BOOLEAN;
1789  lDBusKey = "Discoverable";
1790  break;
1791  case enBTAdPropDiscoverableTimeOut:
1792  lDBusType = DBUS_TYPE_UINT32;
1793  lDBusKey = "DiscoverableTimeout";
1794  break;
1795  case enBTAdPropUnknown:
1796  default:
1797  BTRCORELOG_ERROR ("Invalid Adapter Property\n");
1798  return -1;
1799  }
1800  break;
1801  case enBTDevice:
1802  pInterface = pDeviceInterface;
1803  switch (aunBtOpIfceProp.enBtDeviceProp) {
1804  case enBTDevPropPaired:
1805  lDBusType = DBUS_TYPE_BOOLEAN;
1806  lDBusKey = "Paired";
1807  break;
1808  case enBTDevPropConnected:
1809  lDBusType = DBUS_TYPE_BOOLEAN;
1810  lDBusKey = "Connected";
1811  break;
1812  case enBTDevPropVendor:
1813  lDBusType = DBUS_TYPE_UINT16;
1814  lDBusKey = "Vendor";
1815  break;
1816  case enBTDevPropUnknown:
1817  default:
1818  BTRCORELOG_ERROR ("Invalid Device Property\n");
1819  return -1;
1820  }
1821  break;
1822  case enBTMediaTransport:
1823  pInterface = pMediaTransInterface;
1824  switch (aunBtOpIfceProp.enBtMediaTransportProp) {
1825  case enBTMedTPropDelay:
1826  lDBusType = DBUS_TYPE_UINT16;
1827  lDBusKey = "Delay";
1828  break;
1829  case enBTMedTPropUnknown:
1830  default:
1831  BTRCORELOG_ERROR ("Invalid MediaTransport Property\n");
1832  return -1;
1833  }
1834  break;
1835  case enBTUnknown:
1836  default:
1837  BTRCORELOG_ERROR ("Invalid Operational Interface\n");
1838  return -1;
1839  }
1840 
1841 
1842  switch (lDBusType) {
1843  case DBUS_TYPE_BOOLEAN:
1844  lDBusTypeAsString = DBUS_TYPE_BOOLEAN_AS_STRING;
1845  break;
1846  case DBUS_TYPE_UINT32:
1847  lDBusTypeAsString = DBUS_TYPE_UINT32_AS_STRING;
1848  break;
1849  case DBUS_TYPE_UINT16:
1850  lDBusTypeAsString = DBUS_TYPE_UINT16_AS_STRING;
1851  break;
1852  case DBUS_TYPE_STRING:
1853  lDBusTypeAsString = DBUS_TYPE_STRING_AS_STRING;
1854  break;
1855  default:
1856  BTRCORELOG_ERROR ("Invalid DBus Type\n");
1857  return -1;
1858  }
1859 
1860 
1861  lpDBusMsg = dbus_message_new_method_call("org.bluez",
1862  apcBtOpIfcePath,
1863  pInterface,
1864  "SetProperty");
1865  if (!lpDBusMsg) {
1866  BTRCORELOG_ERROR ("Can't allocate new method call\n");
1867  return -1;
1868  }
1869 
1870 
1871  dbus_message_iter_init_append(lpDBusMsg, &lDBusMsgIter);
1872  dbus_message_iter_append_basic(&lDBusMsgIter, DBUS_TYPE_STRING, &lDBusKey);
1873  dbus_message_iter_open_container(&lDBusMsgIter, DBUS_TYPE_VARIANT, lDBusTypeAsString, &lDBusMsgIterValue);
1874  dbus_message_iter_append_basic(&lDBusMsgIterValue, lDBusType, apvVal);
1875  dbus_message_iter_close_container(&lDBusMsgIter, &lDBusMsgIterValue);
1876 
1877  dbus_error_init(&lDBusErr);
1878  lpDBusReply = dbus_connection_send_with_reply_and_block(gpDBusConn, lpDBusMsg, -1, &lDBusErr);
1879  dbus_message_unref(lpDBusMsg);
1880 
1881  if (!lpDBusReply) {
1882  BTRCORELOG_ERROR ("Reply Null\n");
1883  btrCore_BTHandleDusError(&lDBusErr, __LINE__, __FUNCTION__);
1884  return -1;
1885  }
1886 
1887  dbus_message_unref(lpDBusReply);
1888 
1889  dbus_connection_flush(gpDBusConn);
1890 
1891  return 0;
1892 }
1893 
1894 
1895 int
1897  void* apBtConn,
1898  const char* apBtAdapter,
1899  const char* apBtAgentPath
1900 ) {
1901  dbus_bool_t lDBusOp;
1902  DBusMessage* lpDBusMsg = NULL;
1903 
1904  if (!gpDBusConn || (gpDBusConn != apBtConn))
1905  return -1;
1906 
1907  lpDBusMsg = dbus_message_new_method_call("org.bluez",
1908  apBtAdapter,
1909  "org.bluez.Adapter",
1910  "StartDiscovery");
1911  if (!lpDBusMsg) {
1912  BTRCORELOG_ERROR ("Can't allocate new method call\n");
1913  return -1;
1914  }
1915 
1916  lDBusOp = dbus_connection_send(gpDBusConn, lpDBusMsg, NULL);
1917  dbus_message_unref(lpDBusMsg);
1918 
1919  if (!lDBusOp) {
1920  BTRCORELOG_ERROR ("Not enough memory for message send\n");
1921  return -1;
1922  }
1923 
1924  dbus_connection_flush(gpDBusConn);
1925 
1926  return 0;
1927 }
1928 
1929 
1930 int
1932  void* apBtConn,
1933  const char* apBtAdapter,
1934  const char* apBtAgentPath
1935 ) {
1936  dbus_bool_t lDBusOp;
1937  DBusMessage* lpDBusMsg = NULL;
1938 
1939  if (!gpDBusConn || (gpDBusConn != apBtConn))
1940  return -1;
1941 
1942  lpDBusMsg = dbus_message_new_method_call("org.bluez",
1943  apBtAdapter,
1944  "org.bluez.Adapter",
1945  "StopDiscovery");
1946  if (!lpDBusMsg) {
1947  BTRCORELOG_ERROR ("Can't allocate new method call\n");
1948  return -1;
1949  }
1950 
1951  lDBusOp = dbus_connection_send(gpDBusConn, lpDBusMsg, NULL);
1952  dbus_message_unref(lpDBusMsg);
1953 
1954  if (!lDBusOp) {
1955  BTRCORELOG_ERROR ("Not enough memory for message send\n");
1956  return -1;
1957  }
1958 
1959  dbus_connection_flush(gpDBusConn);
1960 
1961  return 0;
1962 }
1963 
1964 
1965 int
1967  void* apBtConn,
1968  const char* apBtAdapter,
1969  const char* apBtAgentPath
1970 ) {
1971  return BtrCore_BTStartDiscovery(apBtConn, apBtAdapter, apBtAgentPath);
1972 }
1973 
1974 
1975 int
1977  void* apBtConn,
1978  const char* apBtAdapter,
1979  const char* apBtAgentPath
1980 ) {
1981  return BtrCore_BTStopDiscovery(apBtConn, apBtAdapter, apBtAgentPath);
1982 }
1983 
1984 
1985 int
1987  void* apBtConn,
1988  const char* apBtAdapter,
1989  stBTPairedDeviceInfo* pPairedDeviceInfo
1990 ) {
1991  int i = 0;
1992  int num = 0;
1993  char** paths = NULL;
1994  DBusError lDBusErr;
1995  stBTDeviceInfo apstBTDeviceInfo;
1996 
1997  if (!gpDBusConn || (gpDBusConn != apBtConn) || !apBtAdapter || !pPairedDeviceInfo)
1998  return -1;
1999 
2000  memset (pPairedDeviceInfo, 0, sizeof (stBTPairedDeviceInfo));
2001 
2002  dbus_error_init(&lDBusErr);
2003  DBusMessage* lpDBusReply = btrCore_BTSendMethodCall(apBtAdapter, "org.bluez.Adapter", "ListDevices");
2004  if (lpDBusReply != NULL) {
2005  if (!dbus_message_get_args(lpDBusReply, &lDBusErr, DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &paths, &num, DBUS_TYPE_INVALID)) {
2006  BTRCORELOG_ERROR ("org.bluez.Adapter.ListDevices returned an error: '%s'\n", lDBusErr.message);
2007  }
2008 
2009  /* Update the number of devices */
2010  pPairedDeviceInfo->numberOfDevices = num;
2011 
2012  /* Update the paths of these devices */
2013  for ( i = 0; i < num; i++) {
2014  strcpy(pPairedDeviceInfo->devicePath[i], paths[i]);
2015  }
2016  dbus_message_unref(lpDBusReply);
2017  }
2018 
2019  for ( i = 0; i < num; i++) {
2020  lpDBusReply = btrCore_BTSendMethodCall(pPairedDeviceInfo->devicePath[i], "org.bluez.Device", "GetProperties");
2021  if (lpDBusReply != NULL) {
2022  memset (&apstBTDeviceInfo, 0, sizeof(apstBTDeviceInfo));
2023  if (0 != btrCore_BTParseDevice(lpDBusReply, &apstBTDeviceInfo)) {
2024  BTRCORELOG_ERROR ("Parsing the device %s failed..\n", pPairedDeviceInfo->devicePath[i]);
2025  dbus_message_unref(lpDBusReply);
2026  return -1;
2027  }
2028  else {
2029  memcpy (&pPairedDeviceInfo->deviceInfo[i], &apstBTDeviceInfo, sizeof(apstBTDeviceInfo));
2030  }
2031  }
2032  dbus_message_unref(lpDBusReply);
2033  }
2034 
2035  return 0;
2036 }
2037 
2038 
2039 int
2041  void* apBtConn,
2042  const char* apBtAdapter,
2043  unsigned int* apui32PairedDevCnt,
2044  char** apcArrPairedDevPath
2045 ) {
2046  DBusMessage* lpDBusReply = NULL;
2047  DBusError lDBusErr;
2048  dbus_bool_t lDBusOp;
2049  int rc = -1;
2050  int i = 0;
2051  int num = 0;
2052  char** paths = NULL;
2053 
2054 
2055  if (!gpDBusConn || (gpDBusConn != apBtConn) || !apBtAdapter || !apui32PairedDevCnt || !apcArrPairedDevPath)
2056  return -1;
2057 
2058 
2059  lpDBusReply = btrCore_BTSendMethodCall(apBtAdapter, "org.bluez.Adapter", "ListDevices");
2060  if (!lpDBusReply) {
2061  BTRCORELOG_ERROR ("org.bluez.Adapter.ListDevices returned an error\n");
2062  return rc;
2063  }
2064 
2065 
2066  dbus_error_init(&lDBusErr);
2067  lDBusOp = dbus_message_get_args(lpDBusReply, &lDBusErr, DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &paths, &num, DBUS_TYPE_INVALID);
2068  dbus_message_unref(lpDBusReply);
2069 
2070 
2071  if (!lDBusOp) {
2072  BTRCORELOG_ERROR ("org.bluez.Adapter.ListDevices parsing failed\n");
2073  btrCore_BTHandleDusError(&lDBusErr, __LINE__, __FUNCTION__);
2074  return rc;
2075  }
2076 
2077  for ( i = 0; i < num; i++) {
2078  if (apcArrPairedDevPath[i]) {
2079  strcpy(apcArrPairedDevPath[i], paths[i]);
2080  rc = 0;
2081  }
2082  }
2083 
2084  *apui32PairedDevCnt = num;
2085 
2086 
2087  return rc;
2088 }
2089 
2090 
2091 int
2093  void* apBtConn,
2094  const char* apcDevPath,
2095  stBTDeviceSupportedServiceList* pProfileList
2096 ) {
2097  DBusMessage* lpDBusMsg = NULL;
2098  DBusMessage* lpDBusReply = NULL;
2099  DBusError lDBusErr;
2100  DBusMessageIter arg_i, element_i;
2101  DBusMessageIter dict_i;
2102  int dbus_type;
2103  const char* value;
2104  char* ret;
2105 
2106  int count = 0;
2107  char* pSearchString = "";
2108  char* pUUIDValue = "uuid value=\"0x";
2109  char* pProfileName = "text value=\"";
2110  int lengthOfUUID = strlen (pUUIDValue);
2111  int lengthOfProfile = strlen (pProfileName);
2112  char buff[10] = "";
2113 
2114  int isUUIDFound = 0;
2115  int isProfileFound = 0;
2116 
2117 
2118  if (!gpDBusConn || (gpDBusConn != apBtConn) || !pProfileList)
2119  return -1;
2120 
2121  lpDBusMsg = dbus_message_new_method_call("org.bluez",
2122  apcDevPath,
2123  "org.bluez.Device",
2124  "DiscoverServices");
2125  if (!lpDBusMsg) {
2126  BTRCORELOG_ERROR ("Can't allocate new method call\n");
2127  return -1;
2128  }
2129 
2130  dbus_message_append_args(lpDBusMsg, DBUS_TYPE_STRING, &pSearchString, DBUS_TYPE_INVALID);
2131 
2132  dbus_error_init(&lDBusErr);
2133  lpDBusReply = dbus_connection_send_with_reply_and_block(gpDBusConn, lpDBusMsg, 2500, &lDBusErr); /* Set the timeout as 2.5 sec */
2134  dbus_message_unref(lpDBusMsg);
2135 
2136  if (!lpDBusReply) {
2137  BTRCORELOG_ERROR ("Discover Services FAILED\n");
2138  btrCore_BTHandleDusError(&lDBusErr, __LINE__, __FUNCTION__);
2139  return -1;
2140  }
2141 
2142  if (!dbus_message_iter_init(lpDBusReply, &arg_i)) {
2143  BTRCORELOG_ERROR ("DiscoverServices information lpDBusReply empty");
2144  dbus_message_unref(lpDBusReply);
2145  return -1;
2146  }
2147 
2148  dbus_type = dbus_message_iter_get_arg_type(&arg_i);
2149  // BTRCORELOG_ERROR ("type is %d\n", dbus_type);
2150 
2151  dbus_message_iter_recurse(&arg_i, &element_i);
2152  dbus_type = dbus_message_iter_get_arg_type(&element_i);
2153  //BTRCORELOG_ERROR ("checking the type, it is %d\n", dbus_type);
2154 
2155  while (dbus_message_iter_get_arg_type(&element_i) != DBUS_TYPE_INVALID) {
2156  dbus_type = dbus_message_iter_get_arg_type(&element_i);
2157  //BTRCORELOG_ERROR ("next element_i type is %d\n", dbus_type);
2158 
2159  if (dbus_message_iter_get_arg_type(&element_i) == DBUS_TYPE_DICT_ENTRY) {
2160  isUUIDFound = 0;
2161  isProfileFound = 0;
2162 
2163  dbus_message_iter_recurse(&element_i, &dict_i);
2164  dbus_type = dbus_message_iter_get_arg_type(&dict_i);
2165  // BTRCORELOG_ERROR ("checking the dict subtype, it is %d\n", dbus_type);
2166 
2167  dbus_message_iter_next(&dict_i);
2168  dbus_type = dbus_message_iter_get_arg_type(&dict_i);
2169  // BTRCORELOG_ERROR ("interating the dict subtype, it is %d\n", dbus_type);
2170  dbus_message_iter_get_basic(&dict_i, &value);
2171 
2172  //BTRCORELOG_ERROR ("Services: %s\n", value);
2173  ret = strstr(value, pUUIDValue);
2174  if (ret != NULL) {
2175  ret += lengthOfUUID;
2176 
2177  buff[0] = ret[0];
2178  buff[1] = ret[1];
2179  buff[2] = ret[2];
2180  buff[3] = ret[3];
2181  buff[4] = '\0';
2182  pProfileList->profile[count].uuid_value = strtol(buff, NULL, 16);
2183  isUUIDFound = 1;
2184  }
2185 
2186  ret = strstr(value, pProfileName);
2187  if (ret != NULL) {
2188  char *ptr = NULL;
2189  int index = 0;
2190  ret += lengthOfProfile;
2191  ptr = strchr(ret, '"');
2192  if (ptr != NULL) {
2193  /* shorten the string */
2194  index = ptr - ret;
2195  if (index < BT_MAX_STR_LEN) {
2196  strncpy (pProfileList->profile[count].profile_name, ret, index);
2197  isProfileFound = 1;
2198  }
2199  }
2200  }
2201 
2202  /* increase the Profile/Service Count by 1 */
2203  if ((isUUIDFound) && (isProfileFound)) {
2204  count++;
2205  pProfileList->numberOfService = count;
2206  }
2207  }
2208 
2209  //load the new device into our list of scanned devices
2210  if (!dbus_message_iter_next(&element_i))
2211  break;
2212 
2213  }
2214 
2215  dbus_message_unref(lpDBusReply);
2216  (void)dbus_type;
2217 
2218  return 0;
2219 }
2220 
2221 
2222 int
2224  void* apBtConn,
2225  const char* apcDevPath,
2226  const char* apcSearchString,
2227  char* apcDataString
2228 ) {
2229  DBusMessage* lpDBusMsg = NULL;
2230  DBusMessage* lpDBusReply = NULL;
2231  DBusError lDBusErr;
2232  DBusMessageIter arg_i;
2233  DBusMessageIter element_i;
2234  DBusMessageIter dict_i;
2235  int dbus_type;
2236  int match;
2237  const char* value;
2238  char* ret;
2239 
2240 
2241  if (!gpDBusConn || (gpDBusConn != apBtConn))
2242  return -1;
2243 
2244  //BTRCORELOG_ERROR ("%d\t:%s - apcDevPath is %s\n and service UUID is %s", __LINE__, __FUNCTION__, apcDevPath, apcSearchString);
2245  lpDBusMsg = dbus_message_new_method_call("org.bluez",
2246  apcDevPath,
2247  "org.bluez.Device",
2248  "DiscoverServices");
2249  if (!lpDBusMsg) {
2250  BTRCORELOG_ERROR ("Can't allocate new method call\n");
2251  return -1;
2252  }
2253 
2254  match = 0; //assume it does not match
2255  dbus_message_append_args(lpDBusMsg, DBUS_TYPE_STRING, &apcSearchString, DBUS_TYPE_INVALID);
2256 
2257 
2258  dbus_error_init(&lDBusErr);
2259  lpDBusReply = dbus_connection_send_with_reply_and_block(gpDBusConn, lpDBusMsg, -1, &lDBusErr);
2260  dbus_message_unref(lpDBusMsg);
2261 
2262  if (!lpDBusReply) {
2263  BTRCORELOG_ERROR ("Failure attempting to Discover Services\n");
2264  btrCore_BTHandleDusError(&lDBusErr, __LINE__, __FUNCTION__);
2265  return -1;
2266  }
2267 
2268  if (!dbus_message_iter_init(lpDBusReply, &arg_i)) {
2269  BTRCORELOG_ERROR ("DiscoverServices lpDBusReply has no information.");
2270  dbus_message_unref(lpDBusReply);
2271  return -1;
2272  }
2273 
2274  dbus_type = dbus_message_iter_get_arg_type(&arg_i);
2275  // BTRCORELOG_ERROR ("type is %d\n", dbus_type);
2276 
2277  dbus_message_iter_recurse(&arg_i, &element_i);
2278  dbus_type = dbus_message_iter_get_arg_type(&element_i);
2279  //BTRCORELOG_ERROR ("checking the type, it is %d\n", dbus_type);
2280 
2281  while (dbus_message_iter_get_arg_type(&element_i) != DBUS_TYPE_INVALID) {
2282  dbus_type = dbus_message_iter_get_arg_type(&element_i);
2283  //BTRCORELOG_ERROR ("next element_i type is %d\n", dbus_type);
2284 
2285  if (dbus_message_iter_get_arg_type(&element_i) == DBUS_TYPE_DICT_ENTRY) {
2286 
2287  dbus_message_iter_recurse(&element_i, &dict_i);
2288  dbus_type = dbus_message_iter_get_arg_type(&dict_i);
2289  // BTRCORELOG_ERROR ("checking the dict subtype, it is %d\n", dbus_type);
2290 
2291  dbus_message_iter_next(&dict_i);
2292  dbus_type = dbus_message_iter_get_arg_type(&dict_i);
2293  // BTRCORELOG_ERROR ("interating the dict subtype, it is %d\n", dbus_type);
2294  dbus_message_iter_get_basic(&dict_i, &value);
2295 
2296  // BTRCORELOG_ERROR ("Services: %s\n", value);
2297  if (apcDataString != NULL) {
2298  strcpy(apcDataString, value);
2299  }
2300 
2301  // lets strstr to see if "uuid value="<UUID>" is there
2302  ret = strstr(value, apcSearchString);
2303  if (ret != NULL) {
2304  // BTRCORELOG_ERROR ("%d\t:%s - match\n", __LINE__, __FUNCTION__);
2305  match = 1;//assume it does match
2306  }
2307  else {
2308  //BTRCORELOG_ERROR ("NO match\n");
2309  match = 0;//assume it does not match
2310  }
2311  }
2312 
2313  //load the new device into our list of scanned devices
2314  if (!dbus_message_iter_next(&element_i))
2315  break;
2316 
2317  }
2318 
2319  dbus_message_unref(lpDBusReply);
2320  (void)dbus_type;
2321 
2322  return match;
2323 }
2324 
2325 
2326 int
2328  void* apBtConn,
2329  const char* apBtAdapter,
2330  const char* apBtAgentPath,
2331  const char* apcDevPath,
2332  enBTAdapterOp aenBTAdpOp
2333 ) {
2334  DBusMessage* lpDBusMsg = NULL;
2335  DBusMessage* lpDBusReply = NULL;
2336  DBusError lDBusErr;
2337  char deviceOpString[64] = {'\0'};
2338  int rc = 0;
2339 
2340  /* We can enhance the BTRCore with passcode support later point in time */
2341 #if 0
2342  const char* capabilities = "NoInputNoOutput";
2343 #else
2344  const char* capabilities = "DisplayYesNo";
2345 #endif
2346 
2347  if (!gpDBusConn || (gpDBusConn != apBtConn) || !apBtAdapter || !apBtAgentPath || !apcDevPath || (aenBTAdpOp == enBTAdpOpUnknown))
2348  return -1;
2349 
2350 
2351  switch (aenBTAdpOp) {
2352  case enBTAdpOpFindPairedDev:
2353  strcpy(deviceOpString, "FindDevice");
2354  break;
2355  case enBTAdpOpCreatePairedDev:
2356  strcpy(deviceOpString, "CreatePairedDevice");
2357  break;
2358  case enBTAdpOpRemovePairedDev:
2359  strcpy(deviceOpString, "RemoveDevice");
2360  break;
2361  case enBTAdpOpUnknown:
2362  default:
2363  rc = -1;
2364  break;
2365  }
2366 
2367  if (rc == -1)
2368  return rc;
2369 
2370  lpDBusMsg = dbus_message_new_method_call("org.bluez",
2371  apBtAdapter,
2372  "org.bluez.Adapter",
2373  deviceOpString);
2374  if (!lpDBusMsg) {
2375  BTRCORELOG_ERROR ("Can't allocate new method call\n");
2376  return -1;
2377  }
2378 
2379  if (aenBTAdpOp == enBTAdpOpFindPairedDev) {
2380  dbus_message_append_args(lpDBusMsg, DBUS_TYPE_STRING, &apcDevPath, DBUS_TYPE_INVALID);
2381  }
2382  else if (aenBTAdpOp == enBTAdpOpRemovePairedDev) {
2383  dbus_message_append_args(lpDBusMsg, DBUS_TYPE_OBJECT_PATH, &apcDevPath, DBUS_TYPE_INVALID);
2384  }
2385  else if (aenBTAdpOp == enBTAdpOpCreatePairedDev) {
2386  dbus_message_append_args(lpDBusMsg, DBUS_TYPE_STRING, &apcDevPath,
2387  DBUS_TYPE_OBJECT_PATH, &apBtAgentPath,
2388  DBUS_TYPE_STRING, &capabilities,
2389  DBUS_TYPE_INVALID);
2390  }
2391 
2392  dbus_error_init(&lDBusErr);
2393  lpDBusReply = dbus_connection_send_with_reply_and_block(gpDBusConn, lpDBusMsg, -1, &lDBusErr);
2394  dbus_message_unref(lpDBusMsg);
2395 
2396  if (!lpDBusReply) {
2397  BTRCORELOG_ERROR ("Pairing failed...\n");
2398  btrCore_BTHandleDusError(&lDBusErr, __LINE__, __FUNCTION__);
2399  return -1;
2400  }
2401 
2402  dbus_message_unref(lpDBusReply);
2403 
2404  return 0;
2405 }
2406 
2407 
2408 int
2410  void* apBtConn,
2411  const char* apcDevPath
2412 ) {
2413  FILE* lfpL2Ping = NULL;
2414  int i32OpRet = -1;
2415  char lcpL2PingIp[64] = {'\0'};
2416  char lcpL2PingOp[512] = {'\0'};
2417 
2418  if (!gpDBusConn || (gpDBusConn != apBtConn))
2419  return -1;
2420 
2421  if (!apcDevPath)
2422  return -1;
2423 
2424  snprintf(lcpL2PingIp, 128, "l2ping -i hci0 -c 3 -s 2 -d 2 %s", apcDevPath);
2425  BTRCORELOG_INFO ("lcpL2PingIp: %s\n", lcpL2PingIp);
2426 #ifdef LIBSYSWRAPPER_BUILD
2427  lfpL2Ping = v_secure_popen("r","l2ping -i hci0 -c 3 -s 2 -d 2 %s", apcDevPath);
2428 #else
2429  lfpL2Ping = popen(lcpL2PingIp, "r");
2430 #endif
2431  if ((lfpL2Ping == NULL)) {
2432  BTRCORELOG_ERROR ("Failed to run BTIsDeviceConnectable command\n");
2433  }
2434  else {
2435  if (fgets(lcpL2PingOp, sizeof(lcpL2PingOp)-1, lfpL2Ping) == NULL) {
2436  BTRCORELOG_ERROR ("Failed to Output of l2ping\n");
2437  }
2438  else {
2439  BTRCORELOG_WARN ("Output of l2ping = %s\n", lcpL2PingOp);
2440  if (!strstr(lcpL2PingOp, "Host is down")) {
2441  i32OpRet = 0;
2442  }
2443  }
2444 #ifdef LIBSYSWRAPPER_BUILD
2445  v_secure_pclose(lfpL2Ping);
2446 #else
2447  pclose(lfpL2Ping);
2448 #endif
2449  }
2450 
2451  return i32OpRet;
2452 }
2453 
2454 
2455 int
2457  void* apBtConn,
2458  const char* apDevPath,
2459  enBTDeviceType aenBTDeviceType
2460 ) {
2461  dbus_bool_t lDBusOp;
2462  DBusMessage* lpDBusMsg = NULL;
2463  char larDBusIfce[64] = {'\0'};
2464 
2465  if (!gpDBusConn || (gpDBusConn != apBtConn) || !apDevPath)
2466  return -1;
2467 
2468  switch (aenBTDeviceType) {
2469  case enBTDevAudioSink:
2470  strncpy(larDBusIfce, "org.bluez.AudioSink", strlen("org.bluez.AudioSink"));
2471  break;
2472  case enBTDevAudioSource:
2473  strncpy(larDBusIfce, "org.bluez.AudioSource", strlen("org.bluez.AudioSource"));
2474  break;
2475  case enBTDevHFPHeadset:
2476  strncpy(larDBusIfce, "org.bluez.Headset", strlen("org.bluez.Headset"));
2477  break;
2478  case enBTDevHFPHeadsetGateway:
2479  strncpy(larDBusIfce, "org.bluez.HeadsetGateway", strlen("org.bluez.HeadsetGateway"));
2480  break;
2481  case enBTDevUnknown:
2482  default:
2483  strncpy(larDBusIfce, "org.bluez.AudioSink", strlen("org.bluez.AudioSink"));
2484  break;
2485  }
2486 
2487  lpDBusMsg = dbus_message_new_method_call("org.bluez",
2488  apDevPath,
2489  larDBusIfce,
2490  "Connect");
2491  if (!lpDBusMsg) {
2492  BTRCORELOG_ERROR ("Can't allocate new method call\n");
2493  return -1;
2494  }
2495 
2496  lDBusOp = dbus_connection_send(gpDBusConn, lpDBusMsg, NULL);
2497  dbus_message_unref(lpDBusMsg);
2498 
2499  if (!lDBusOp) {
2500  BTRCORELOG_ERROR ("Not enough memory for message send\n");
2501  return -1;
2502  }
2503 
2504  dbus_connection_flush(gpDBusConn);
2505 
2506  return 0;
2507 }
2508 
2509 
2510 int
2512  void* apBtConn,
2513  const char* apDevPath,
2514  enBTDeviceType aenBTDevType
2515 ) {
2516  dbus_bool_t lDBusOp;
2517  DBusMessage* lpDBusMsg = NULL;
2518  char larDBusIfce[64] = {'\0'};
2519 
2520  if (!gpDBusConn || (gpDBusConn != apBtConn) || !apDevPath)
2521  return -1;
2522 
2523  switch (aenBTDevType) {
2524  case enBTDevAudioSink:
2525  strncpy(larDBusIfce, "org.bluez.AudioSink", strlen("org.bluez.AudioSink"));
2526  break;
2527  case enBTDevAudioSource:
2528  strncpy(larDBusIfce, "org.bluez.AudioSource", strlen("org.bluez.AudioSource"));
2529  break;
2530  case enBTDevHFPHeadset:
2531  strncpy(larDBusIfce, "org.bluez.Headset", strlen("org.bluez.Headset"));
2532  break;
2533  case enBTDevHFPHeadsetGateway:
2534  strncpy(larDBusIfce, "org.bluez.HeadsetGateway", strlen("org.bluez.HeadsetGateway"));
2535  break;
2536  case enBTDevUnknown:
2537  default:
2538  strncpy(larDBusIfce, "org.bluez.AudioSink", strlen("org.bluez.AudioSink"));
2539  break;
2540  }
2541 
2542  lpDBusMsg = dbus_message_new_method_call("org.bluez",
2543  apDevPath,
2544  larDBusIfce,
2545  "Disconnect");
2546  if (!lpDBusMsg) {
2547  BTRCORELOG_ERROR ("Can't allocate new method call\n");
2548  return -1;
2549  }
2550 
2551  lDBusOp = dbus_connection_send(gpDBusConn, lpDBusMsg, NULL);
2552  dbus_message_unref(lpDBusMsg);
2553 
2554  if (!lDBusOp) {
2555  BTRCORELOG_ERROR ("Not enough memory for message send\n");
2556  return -1;
2557  }
2558 
2559  dbus_connection_flush(gpDBusConn);
2560 
2561  return 0;
2562 }
2563 
2564 
2565 int
2567  void* apBtConn,
2568  const char* apBtAdapter,
2569  enBTDeviceType aenBTDevType,
2570  void* apBtUUID,
2571  void* apBtMediaCodec,
2572  void* apBtMediaCapabilities,
2573  int apBtMediaCapabilitiesSize,
2574  int abBtMediaDelayReportEnable
2575 ) {
2576  DBusMessage* lpDBusMsg = NULL;
2577  DBusMessage* lpDBusReply = NULL;
2578  DBusError lDBusErr;
2579  DBusMessageIter lDBusMsgIter;
2580  DBusMessageIter lDBusMsgIterArr;
2581  dbus_bool_t lDBusOp;
2582  dbus_bool_t lBtMediaDelayReport = FALSE;
2583 
2584  const char* lpBtMediaType;
2585 
2586  if (!gpDBusConn || (gpDBusConn != apBtConn))
2587  return -1;
2588 
2589  switch (aenBTDevType) {
2590  case enBTDevAudioSink:
2591  lpBtMediaType = BT_MEDIA_A2DP_SOURCE_ENDPOINT;
2592  dbus_bus_add_match(gpDBusConn, "type='signal',interface='org.bluez.AudioSink'", NULL);
2593  break;
2594  case enBTDevAudioSource:
2595  lpBtMediaType = BT_MEDIA_A2DP_SINK_ENDPOINT;
2596  dbus_bus_add_match(gpDBusConn, "type='signal',interface='org.bluez.AudioSource'", NULL);
2597  break;
2598  case enBTDevHFPHeadset:
2599  lpBtMediaType = BT_MEDIA_A2DP_SOURCE_ENDPOINT; //TODO: Check if this is correct
2600  dbus_bus_add_match(gpDBusConn, "type='signal',interface='org.bluez.Headset'", NULL);
2601  break;
2602  case enBTDevHFPHeadsetGateway:
2603  lpBtMediaType = BT_MEDIA_A2DP_SOURCE_ENDPOINT; //TODO: Check if this is correct
2604  dbus_bus_add_match(gpDBusConn, "type='signal',interface='org.bluez.HeadsetGateway'", NULL);
2605  break;
2606  case enBTDevUnknown:
2607  default:
2608  lpBtMediaType = BT_MEDIA_A2DP_SOURCE_ENDPOINT;
2609  dbus_bus_add_match(gpDBusConn, "type='signal',interface='org.bluez.AudioSink'", NULL);
2610  break;
2611  }
2612 
2613  if (abBtMediaDelayReportEnable)
2614  lBtMediaDelayReport = TRUE;
2615 
2616  lDBusOp = dbus_connection_register_object_path(gpDBusConn, lpBtMediaType, &gDBusMediaEndpointVTable, NULL);
2617  if (!lDBusOp) {
2618  BTRCORELOG_ERROR ("Can't Register Media Object\n");
2619  return -1;
2620  }
2621 
2622  lpDBusMsg = dbus_message_new_method_call("org.bluez",
2623  apBtAdapter,
2624  "org.bluez.Media",
2625  "RegisterEndpoint");
2626  if (!lpDBusMsg) {
2627  BTRCORELOG_ERROR ("Can't allocate new method call\n");
2628  return -1;
2629  }
2630 
2631  dbus_message_iter_init_append (lpDBusMsg, &lDBusMsgIter);
2632  dbus_message_iter_append_basic (&lDBusMsgIter, DBUS_TYPE_OBJECT_PATH, &lpBtMediaType);
2633  dbus_message_iter_open_container (&lDBusMsgIter, DBUS_TYPE_ARRAY, "{sv}", &lDBusMsgIterArr);
2634  {
2635  DBusMessageIter lDBusMsgIterDict, lDBusMsgIterVariant;
2636  char* key = "UUID";
2637  int type = DBUS_TYPE_STRING;
2638 
2639  dbus_message_iter_open_container (&lDBusMsgIterArr, DBUS_TYPE_DICT_ENTRY, NULL, &lDBusMsgIterDict);
2640  dbus_message_iter_append_basic (&lDBusMsgIterDict, DBUS_TYPE_STRING, &key);
2641  dbus_message_iter_open_container (&lDBusMsgIterDict, DBUS_TYPE_VARIANT, (char *)&type, &lDBusMsgIterVariant);
2642  dbus_message_iter_append_basic (&lDBusMsgIterVariant, type, &apBtUUID);
2643  dbus_message_iter_close_container (&lDBusMsgIterDict, &lDBusMsgIterVariant);
2644  dbus_message_iter_close_container (&lDBusMsgIterArr, &lDBusMsgIterDict);
2645  }
2646  {
2647  DBusMessageIter lDBusMsgIterDict, lDBusMsgIterVariant;
2648  char* key = "Codec";
2649  int type = DBUS_TYPE_BYTE;
2650 
2651  dbus_message_iter_open_container (&lDBusMsgIterArr, DBUS_TYPE_DICT_ENTRY, NULL, &lDBusMsgIterDict);
2652  dbus_message_iter_append_basic (&lDBusMsgIterDict, DBUS_TYPE_STRING, &key);
2653  dbus_message_iter_open_container (&lDBusMsgIterDict, DBUS_TYPE_VARIANT, (char *)&type, &lDBusMsgIterVariant);
2654  dbus_message_iter_append_basic (&lDBusMsgIterVariant, type, &apBtMediaCodec);
2655  dbus_message_iter_close_container (&lDBusMsgIterDict, &lDBusMsgIterVariant);
2656  dbus_message_iter_close_container (&lDBusMsgIterArr, &lDBusMsgIterDict);
2657  }
2658  {
2659  DBusMessageIter lDBusMsgIterDict, lDBusMsgIterVariant;
2660  char* key = "DelayReporting";
2661  int type = DBUS_TYPE_BOOLEAN;
2662 
2663  dbus_message_iter_open_container (&lDBusMsgIterArr, DBUS_TYPE_DICT_ENTRY, NULL, &lDBusMsgIterDict);
2664  dbus_message_iter_append_basic (&lDBusMsgIterDict, DBUS_TYPE_STRING, &key);
2665  dbus_message_iter_open_container (&lDBusMsgIterDict, DBUS_TYPE_VARIANT, (char *)&type, &lDBusMsgIterVariant);
2666  dbus_message_iter_append_basic (&lDBusMsgIterVariant, type, &lBtMediaDelayReport);
2667  dbus_message_iter_close_container (&lDBusMsgIterDict, &lDBusMsgIterVariant);
2668  dbus_message_iter_close_container (&lDBusMsgIterArr, &lDBusMsgIterDict);
2669  }
2670  {
2671  DBusMessageIter lDBusMsgIterDict, lDBusMsgIterVariant, lDBusMsgIterSubArray;
2672  char* key = "Capabilities";
2673  int type = DBUS_TYPE_BYTE;
2674 
2675  char array_type[5] = "a";
2676  strncat (array_type, (char*)&type, sizeof(array_type));
2677 
2678  dbus_message_iter_open_container (&lDBusMsgIterArr, DBUS_TYPE_DICT_ENTRY, NULL, &lDBusMsgIterDict);
2679  dbus_message_iter_append_basic (&lDBusMsgIterDict, DBUS_TYPE_STRING, &key);
2680  dbus_message_iter_open_container (&lDBusMsgIterDict, DBUS_TYPE_VARIANT, array_type, &lDBusMsgIterVariant);
2681  dbus_message_iter_open_container (&lDBusMsgIterVariant, DBUS_TYPE_ARRAY, (char *)&type, &lDBusMsgIterSubArray);
2682  dbus_message_iter_append_fixed_array (&lDBusMsgIterSubArray, type, &apBtMediaCapabilities, apBtMediaCapabilitiesSize);
2683  dbus_message_iter_close_container (&lDBusMsgIterVariant, &lDBusMsgIterSubArray);
2684  dbus_message_iter_close_container (&lDBusMsgIterDict, &lDBusMsgIterVariant);
2685  dbus_message_iter_close_container (&lDBusMsgIterArr, &lDBusMsgIterDict);
2686  }
2687  dbus_message_iter_close_container (&lDBusMsgIter, &lDBusMsgIterArr);
2688 
2689 
2690  dbus_error_init(&lDBusErr);
2691  lpDBusReply = dbus_connection_send_with_reply_and_block(gpDBusConn, lpDBusMsg, -1, &lDBusErr);
2692  dbus_message_unref(lpDBusMsg);
2693 
2694  if (!lpDBusReply) {
2695  BTRCORELOG_ERROR ("Reply Null\n");
2696  btrCore_BTHandleDusError(&lDBusErr, __LINE__, __FUNCTION__);
2697  return -1;
2698  }
2699 
2700  dbus_message_unref(lpDBusReply);
2701 
2702  dbus_connection_flush(gpDBusConn);
2703 
2704  return 0;
2705 }
2706 
2707 
2708 int
2710  void* apBtConn,
2711  const char* apBtAdapter,
2712  enBTDeviceType aenBTDevType
2713 ) {
2714  DBusMessage* lpDBusMsg = NULL;
2715  dbus_bool_t lDBusOp;
2716 
2717  const char* lpBtMediaType;
2718 
2719  if (!gpDBusConn || (gpDBusConn != apBtConn))
2720  return -1;
2721 
2722  switch (aenBTDevType) {
2723  case enBTDevAudioSink:
2724  lpBtMediaType = BT_MEDIA_A2DP_SOURCE_ENDPOINT;
2725  break;
2726  case enBTDevAudioSource:
2727  lpBtMediaType = BT_MEDIA_A2DP_SINK_ENDPOINT;
2728  break;
2729  case enBTDevHFPHeadset:
2730  lpBtMediaType = BT_MEDIA_A2DP_SOURCE_ENDPOINT; //TODO: Check if this is correct
2731  break;
2732  case enBTDevHFPHeadsetGateway:
2733  lpBtMediaType = BT_MEDIA_A2DP_SOURCE_ENDPOINT; //TODO: Check if this is correct
2734  break;
2735  case enBTDevUnknown:
2736  default:
2737  lpBtMediaType = BT_MEDIA_A2DP_SOURCE_ENDPOINT;
2738  break;
2739  }
2740 
2741 
2742  lpDBusMsg = dbus_message_new_method_call("org.bluez",
2743  apBtAdapter,
2744  "org.bluez.Media",
2745  "UnregisterEndpoint");
2746  if (!lpDBusMsg) {
2747  BTRCORELOG_ERROR ("Can't allocate new method call\n");
2748  return -1;
2749  }
2750 
2751  dbus_message_append_args(lpDBusMsg, DBUS_TYPE_OBJECT_PATH, &lpBtMediaType, DBUS_TYPE_INVALID);
2752 
2753  lDBusOp = dbus_connection_send(gpDBusConn, lpDBusMsg, NULL);
2754  dbus_message_unref(lpDBusMsg);
2755 
2756  if (!lDBusOp) {
2757  BTRCORELOG_ERROR ("Not enough memory for message send\n");
2758  return -1;
2759  }
2760 
2761  lDBusOp = dbus_connection_unregister_object_path(gpDBusConn, lpBtMediaType);
2762  if (!lDBusOp) {
2763  BTRCORELOG_ERROR ("Can't Register Media Object\n");
2764  return -1;
2765  }
2766 
2767  switch (aenBTDevType) {
2768  case enBTDevAudioSink:
2769  dbus_bus_remove_match(gpDBusConn, "type='signal',interface='org.bluez.AudioSink'", NULL);
2770  break;
2771  case enBTDevAudioSource:
2772  dbus_bus_remove_match(gpDBusConn, "type='signal',interface='org.bluez.AudioSource'", NULL);
2773  break;
2774  case enBTDevHFPHeadset:
2775  dbus_bus_remove_match(gpDBusConn, "type='signal',interface='org.bluez.Headset'", NULL);
2776  break;
2777  case enBTDevHFPHeadsetGateway:
2778  dbus_bus_remove_match(gpDBusConn, "type='signal',interface='org.bluez.HeadsetGateway'", NULL);
2779  break;
2780  case enBTDevUnknown:
2781  default:
2782  dbus_bus_remove_match(gpDBusConn, "type='signal',interface='org.bluez.AudioSink'", NULL);
2783  break;
2784  }
2785 
2786  dbus_connection_flush(gpDBusConn);
2787 
2788  return 0;
2789 }
2790 
2791 
2792 int
2794  void* apBtConn,
2795  char* apcDevTransportPath,
2796  int* dataPathFd,
2797  int* dataReadMTU,
2798  int* dataWriteMTU
2799 ) {
2800  DBusMessage* lpDBusMsg = NULL;
2801  DBusMessage* lpDBusReply = NULL;
2802  DBusMessageIter lDBusMsgIter;
2803  DBusError lDBusErr;
2804  dbus_bool_t lDBusOp;
2805 
2806  //TODO: There is no point in always acquire a rw socket/fd/anything else
2807  //Decide the Access type based on the current Device type
2808  char *access_type = "rw";
2809 
2810  if (!gpDBusConn || (gpDBusConn != apBtConn) || !apcDevTransportPath)
2811  return -1;
2812 
2813  dbus_bus_add_match(gpDBusConn, "type='signal',interface='org.bluez.MediaTransport',member='PropertyChanged'", NULL);
2814 
2815  lpDBusMsg = dbus_message_new_method_call("org.bluez",
2816  apcDevTransportPath,
2817  "org.bluez.MediaTransport",
2818  "Acquire");
2819  if (!lpDBusMsg) {
2820  BTRCORELOG_ERROR ("Can't allocate new method call\n");
2821  return -1;
2822  }
2823 
2824  dbus_message_iter_init_append (lpDBusMsg, &lDBusMsgIter);
2825  dbus_message_iter_append_basic (&lDBusMsgIter, DBUS_TYPE_STRING, &access_type);
2826 
2827 
2828  dbus_error_init(&lDBusErr);
2829  lpDBusReply = dbus_connection_send_with_reply_and_block(gpDBusConn, lpDBusMsg, -1, &lDBusErr);
2830  dbus_message_unref(lpDBusMsg);
2831 
2832  if (!lpDBusReply) {
2833  BTRCORELOG_ERROR ("Reply Null\n");
2834  btrCore_BTHandleDusError(&lDBusErr, __LINE__, __FUNCTION__);
2835  return -1;
2836  }
2837 
2838  lDBusOp = dbus_message_get_args(lpDBusReply, &lDBusErr,
2839  DBUS_TYPE_UNIX_FD, dataPathFd,
2840  DBUS_TYPE_UINT16, dataReadMTU,
2841  DBUS_TYPE_UINT16, dataWriteMTU,
2842  DBUS_TYPE_INVALID);
2843 
2844  dbus_message_unref(lpDBusReply);
2845 
2846  if (!lDBusOp) {
2847  BTRCORELOG_ERROR ("Can't get lpDBusReply arguments\n");
2848  btrCore_BTHandleDusError(&lDBusErr, __LINE__, __FUNCTION__);
2849  return -1;
2850  }
2851 
2852  dbus_connection_flush(gpDBusConn);
2853 
2854  return 0;
2855 }
2856 
2857 
2858 int
2860  void* apBtConn,
2861  char* apcDevTransportPath
2862 ) {
2863  DBusMessage* lpDBusMsg = NULL;
2864  DBusMessage* lpDBusReply = NULL;
2865  DBusMessageIter lDBusMsgIter;
2866  DBusError lDBusErr;
2867 
2868  //TODO: There is no point in always acquire a rw socket/fd/anything else
2869  //Decide the Access type based on the current Device type
2870  char *access_type = "rw";
2871 
2872  if (!gpDBusConn || (gpDBusConn != apBtConn) || !apcDevTransportPath)
2873  return -1;
2874 
2875  lpDBusMsg = dbus_message_new_method_call("org.bluez",
2876  apcDevTransportPath,
2877  "org.bluez.MediaTransport",
2878  "Release");
2879  if (!lpDBusMsg) {
2880  BTRCORELOG_ERROR ("Can't allocate new method call\n");
2881  return -1;
2882  }
2883 
2884  dbus_message_iter_init_append (lpDBusMsg, &lDBusMsgIter);
2885  dbus_message_iter_append_basic (&lDBusMsgIter, DBUS_TYPE_STRING, &access_type);
2886 
2887 
2888  dbus_error_init(&lDBusErr);
2889  lpDBusReply = dbus_connection_send_with_reply_and_block(gpDBusConn, lpDBusMsg, -1, &lDBusErr);
2890  dbus_message_unref(lpDBusMsg);
2891 
2892  if (!lpDBusReply) {
2893  BTRCORELOG_ERROR ("Reply Null\n");
2894  btrCore_BTHandleDusError(&lDBusErr, __LINE__, __FUNCTION__);
2895  return -1;
2896  }
2897 
2898  dbus_message_unref(lpDBusReply);
2899 
2900  dbus_connection_flush(gpDBusConn);
2901 
2902  dbus_bus_remove_match(gpDBusConn, "type='signal',interface='org.bluez.MediaTransport',member='PropertyChanged'", NULL);
2903 
2904  return 0;
2905 }
2906 
2907 
2908 int
2910  void* apBtConn
2911 ) {
2912  if (!gpDBusConn || (gpDBusConn != apBtConn))
2913  return -1;
2914 
2915  if(dbus_connection_read_write_dispatch(gpDBusConn, 25) != TRUE) {
2916  return -1;
2917  }
2918 
2919  return 0;
2920 }
2921 
2922 
2923 int
2924 BtrCore_BTRegisterDevStatusUpdatecB (
2925  void* apBtConn,
2926  fPtr_BtrCore_BTDevStatusUpdate_cB afpcBDevStatusUpdate,
2927  void* apUserData
2928 ) {
2929  if (!gpDBusConn || (gpDBusConn != apBtConn))
2930  return -1;
2931 
2932  if (!afpcBDevStatusUpdate)
2933  return -1;
2934 
2935  gfpcBDevStatusUpdate = afpcBDevStatusUpdate;
2936  gpcBDevStatusUserData = apUserData;
2937 
2938  return 0;
2939 }
2940 
2941 
2942 int
2943 BtrCore_BTRegisterMediaStatusUpdatecB (
2944  void* apBtConn,
2945  fPtr_BtrCore_BTMediaStatusUpdate_cB afpcBMediaStatusUpdate,
2946  void* apUserData
2947 ) {
2948  /* Dummy Function */
2949  return 0;
2950 }
2951 
2952 
2953 int
2954 BtrCore_BTRegisterConnIntimationcB (
2955  void* apBtConn,
2956  fPtr_BtrCore_BTConnIntim_cB afpcBConnIntim,
2957  void* apUserData
2958 ) {
2959  if (!gpDBusConn || (gpDBusConn != apBtConn))
2960  return -1;
2961 
2962  if (!afpcBConnIntim)
2963  return -1;
2964 
2965  gfpcBConnectionIntimation = afpcBConnIntim;
2966  gpcBConnIntimUserData = apUserData;
2967 
2968  return 0;
2969 }
2970 
2971 
2972 int
2973 BtrCore_BTRegisterConnAuthcB (
2974  void* apBtConn,
2975  fPtr_BtrCore_BTConnAuth_cB afpcBConnAuth,
2976  void* apUserData
2977 ) {
2978  if (!gpDBusConn || (gpDBusConn != apBtConn))
2979  return -1;
2980 
2981  if (!afpcBConnAuth)
2982  return -1;
2983 
2984  gfpcBConnectionAuthentication = afpcBConnAuth;
2985  gpcBConnAuthUserData = apUserData;
2986 
2987  return 0;
2988 }
2989 
2990 
2991 int
2992 BtrCore_BTRegisterNegotiateMediacB (
2993  void* apBtConn,
2994  const char* apBtAdapter,
2995  fPtr_BtrCore_BTNegotiateMedia_cB afpcBNegotiateMedia,
2996  void* apUserData
2997 ) {
2998  if (!gpDBusConn || (gpDBusConn != apBtConn))
2999  return -1;
3000 
3001  if (!apBtAdapter || !afpcBNegotiateMedia)
3002  return -1;
3003 
3004  gfpcBNegotiateMedia = afpcBNegotiateMedia;
3005  gpcBNegMediaUserData = apUserData;
3006 
3007  return 0;
3008 }
3009 
3010 
3011 int
3012 BtrCore_BTRegisterTransportPathMediacB (
3013  void* apBtConn,
3014  const char* apBtAdapter,
3015  fPtr_BtrCore_BTTransportPathMedia_cB afpcBTransportPathMedia,
3016  void* apUserData
3017 ) {
3018  if (!gpDBusConn || (gpDBusConn != apBtConn))
3019  return -1;
3020 
3021  if (!apBtAdapter || !afpcBTransportPathMedia)
3022  return -1;
3023 
3024  gfpcBTransportPathMedia = afpcBTransportPathMedia;
3025  gpcBTransPathMediaUserData = apUserData;
3026 
3027  return 0;
3028 }
3029 
3030 
3031 int
3032 BtrCore_BTRegisterMediaPlayerPathcB (
3033  void* apBtConn,
3034  const char* apBtAdapter,
3035  fPtr_BtrCore_BTMediaPlayerPath_cB afpcBTMediaPlayerPath,
3036  void* apUserData
3037 ) {
3038 
3039  return 0;
3040 }
3041 
3042 
3043 /* Control Media on Remote BT Device*/
3044 int
3046  void* apBtConn,
3047  const char* apDevPath,
3048  void* aBTMediaOper
3049 ) {
3050  dbus_bool_t lDBusOp;
3051  DBusMessage* lpDBusMsg = NULL;
3052  char mediaOper[16] = {'\0'};
3053  enBTMediaControl aenBTMediaOper = *(enBTMediaControl*)aBTMediaOper;
3054 
3055  if (!gpDBusConn || (gpDBusConn != apBtConn) || !apDevPath)
3056  return -1;
3057 
3058  switch (aenBTMediaOper) {
3059  case enBTMediaPlay:
3060  strcpy(mediaOper, "Play");
3061  break;
3062  case enBTMediaPause:
3063  strcpy(mediaOper, "Pause");
3064  break;
3065  case enBTMediaStop:
3066  strcpy(mediaOper, "Stop");
3067  break;
3068  case enBTMediaNext:
3069  strcpy(mediaOper, "Next");
3070  break;
3071  case enBTMediaPrevious:
3072  strcpy(mediaOper, "Previous");
3073  break;
3074  case enBTMediaFastForward:
3075  strcpy(mediaOper, "FastForward");
3076  break;
3077  case enBTMediaRewind:
3078  strcpy(mediaOper, "Rewind");
3079  break;
3080  case enBTMediaVolumeUp:
3081  strcpy(mediaOper, "VolumeUp");
3082  break;
3083  case enBTMediaVolumeDown:
3084  strcpy(mediaOper, "VolumeDown");
3085  break;
3086  }
3087 
3088 
3089  lpDBusMsg = dbus_message_new_method_call("org.bluez",
3090  apDevPath,
3091  "org.bluez.Control",
3092  mediaOper);
3093  if (!lpDBusMsg) {
3094  BTRCORELOG_ERROR ("Cannot allocate Dbus message to play media file\n\n");
3095  return -1;
3096  }
3097 
3098  lDBusOp = dbus_connection_send(gpDBusConn, lpDBusMsg, NULL);
3099  dbus_message_unref(lpDBusMsg);
3100 
3101  if (!lDBusOp) {
3102  BTRCORELOG_ERROR ("Not enough memory for message send\n");
3103  return -1;
3104  }
3105 
3106  dbus_connection_flush(gpDBusConn);
3107 
3108  return 0;
3109 }
3110 
3111 
3113  void* apBtConn,
3114  const char* apBtMediaPlayerPath,
3115  const char* mediaProperty,
3116  void* mediaPropertyValue
3117 ) {
3118  /* Dummy Function */
3119  return 0;
3120 }
3121 
3122 
3123 char* BtrCore_BTGetPlayerObjectPath (void* apBtConn, const char* apBtDevPath)
3124 {
3125  /* Dummy Function */
3126  return NULL;
3127 }
3128 
3129 
3130 int BtrCore_BTSetMediaProperty (void* apBtConn, const char* apBtAdapterPath, char* mediaProperty, char* pValue)
3131 {
3132  /* Dummy Function */
3133  return 0;
3134 }
3135 
3136 int BtrCore_BTGetTrackInformation (void* apBtConn, const char* apBtmediaPlayerObjectPath, void* mediaTracktInfo)
3137 {
3138  /* Dummy Function */
3139  return 0;
3140 }
3141 
3142 int BtrCore_BTGetTransportState (void* apBtConn, const char* apBtDataPath, void* state)
3143 {
3144  /* Dummy Function */
3145  return 0;
3146 }
3147 
3148 
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
_stBTDeviceSupportedServiceList
Definition: btrCore_bt_ifce.h:684
BtrCore_BTDevMediaControl
int BtrCore_BTDevMediaControl(void *apBtConn, const char *apmediaPlayerPath, enBTMediaControlCmd aenBTMediaOper)
This API is used to control the media device.
Definition: btrCore_dbus_bluez5.c:6089
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_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_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_BTRegisterMedia
int BtrCore_BTRegisterMedia(void *apBtConn, const char *apBtAdapter, enBTDeviceType aenBTDevType, enBTMediaType aenBTMediaType, const char *apBtUUID, void *apBtMediaCapabilities, int apBtMediaCapabilitiesSize, int abBtMediaDelayReportEnable)
This API is used to register a media device.
Definition: btrCore_dbus_bluez5.c:5594
BtrCore_BTSetProp
int BtrCore_BTSetProp(void *apBtConn, const char *apcBtOpIfcePath, 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_BTConnectDevice
int BtrCore_BTConnectDevice(void *apBtConn, const char *apDevPath, enBTDeviceType aenBTDeviceType)
This API is used to establish the connection with a BT device.
Definition: btrCore_dbus_bluez4.c:2456
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
enBTDeviceType
enum _enBTDeviceType enBTDeviceType
Bluetooth device types.
BtrCore_BTGetPairedDevices
int BtrCore_BTGetPairedDevices(void *apBtConn, const char *apBtAdapter, unsigned int *apui32PairedDevCnt, char **apcArrPairedDevPath)
This API fetches all the paired devices' paths and number of paired devices.
Definition: btrCore_dbus_bluez4.c:2040
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_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_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_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_BTReleaseDevDataPath
int BtrCore_BTReleaseDevDataPath(void *apBtConn, char *apcDevTransportPath)
This API is used to release the acquired device data path.
Definition: btrCore_dbus_bluez4.c:2859
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_BTAcquireDevDataPath
int BtrCore_BTAcquireDevDataPath(void *apBtConn, char *apcDevTransportPath, int *dataPathFd, int *dataReadMTU, int *dataWriteMTU)
This API is used to acquire device data path.
Definition: btrCore_dbus_bluez4.c:2793
enBTDeviceState
enum _enBTDeviceState enBTDeviceState
Bluetooth device state.
BT_MAX_UUID_STR_LEN
#define BT_MAX_UUID_STR_LEN
Bluetooth max uuid length.
Definition: btrCore_bt_ifce.h:52
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 *apcBtOpIfcePath, enBTOpIfceType aenBtOpIfceType, unBTOpIfceProp aunBtOpIfceProp, void *apvVal)
This API gets different properties of different BT devices and services.
Definition: btrCore_dbus_bluez4.c:1560
BtrCore_BTUnRegisterMedia
int BtrCore_BTUnRegisterMedia(void *apBtConn, const char *apBtAdapter, enBTDeviceType aenBTDevType, enBTMediaType aenBTMediaType)
This API is used to unregister the media device.
Definition: btrCore_dbus_bluez5.c:5789
BtrCore_BTGetMediaPlayerProperty
int BtrCore_BTGetMediaPlayerProperty(void *apBtConn, const char *apBtMediaPlayerPath, const char *mediaProperty, void *mediaPropertyValue)
This API is used to get media player property value using the object path of BT device and media prop...
Definition: btrCore_dbus_bluez4.c:3112
BtrCore_BTGetAdapterList
int BtrCore_BTGetAdapterList(void *apBtConn, unsigned int *apBtNumAdapters, char *apcArrBtAdapterPath[4])
This API obtains adapter list from Dbus object path.
enBTAdapterOp
enum _enBTAdapterOp enBTAdapterOp
Bluetooth Adapter operations.
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_BTGetTransportState
int BtrCore_BTGetTransportState(void *apBtConn, const char *apBtDataPath, void *state)
This API is used to get the state of the BT device .
Definition: btrCore_dbus_bluez4.c:3142
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_BTSetMediaProperty
int BtrCore_BTSetMediaProperty(void *apBtConn, const char *apBtAdapterPath, char *mediaProperty, char *pValue)
This API is used to set the media property of the BT device .
Definition: btrCore_dbus_bluez4.c:3130
BtrCore_BTGetTrackInformation
int BtrCore_BTGetTrackInformation(void *apBtConn, const char *apBtmediaPlayerObjectPath, stBTMediaTrackInfo *lpstBTMediaTrackInfo)
This API is used to retrieve the information about the track that is being played on BT media device.
Definition: btrCore_dbus_bluez5.c:6352
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
BT_MAX_STR_LEN
#define BT_MAX_STR_LEN
Bluetooth max string length.
Definition: btrCore_bt_ifce.h:38
_stBTDeviceInfo
Definition: btrCore_bt_ifce.h:647
enBTOpIfceType
enum _enBTOpType enBTOpIfceType
Bluetooth device operation types.
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
TRUE
#define TRUE
Defines for TRUE/FALSE/ENABLE flags.
Definition: wifi_common_hal.h:199
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
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
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_BTSendReceiveMessages
int BtrCore_BTSendReceiveMessages(void *apBtConn)
This API is used to read, write and dispatch BT device information.
Definition: btrCore_dbus_bluez4.c:2909