From c5d3dee7873e53c907efdcc232770568d3c635dc Mon Sep 17 00:00:00 2001 From: Jonathan Aillet Date: Wed, 12 Sep 2018 17:54:04 +0200 Subject: Get bluetooth device interface from path in HalBt In Hal-Bt plugin, get bluetooth device 'hci' interface from 'Path' key send by 'Bluetooth-Manager'. As, the 'Path' key contains the whole path of the device, some string manipulations are necessary ... Change-Id: I320a41fb1589214b0ae6999e1c8b793c7cdd41a7 Signed-off-by: Jonathan Aillet --- plugins/lib/bluetooth/hal-bt-data.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'plugins/lib/bluetooth/hal-bt-data.c') diff --git a/plugins/lib/bluetooth/hal-bt-data.c b/plugins/lib/bluetooth/hal-bt-data.c index 2723d1d..f3cb0e4 100644 --- a/plugins/lib/bluetooth/hal-bt-data.c +++ b/plugins/lib/bluetooth/hal-bt-data.c @@ -67,7 +67,7 @@ int HalBtDataRemoveSelectedBtDeviceFromList(struct HalBtDeviceData **firstBtDevi struct HalBtDeviceData *HalBtDataAddBtDeviceToBtDeviceList(struct HalBtDeviceData **firstBtDeviceData, json_object *currentSingleBtDeviceDataJ) { - char *currentBtDeviceName, *currentBtDeviceAddress; + char *currentBtDeviceName, *currentBtDeviceAddress, *currentBtDevicePath, *currentBtDeviceHci; struct HalBtDeviceData *currentBtDeviceData; @@ -94,11 +94,11 @@ struct HalBtDeviceData *HalBtDataAddBtDeviceToBtDeviceList(struct HalBtDeviceDat currentBtDeviceData = currentBtDeviceData->next; } - // TODO JAI : get hci device of bt device here if(wrap_json_unpack(currentSingleBtDeviceDataJ, - "{s:s s:s}", + "{s:s s:s s:s}", "Name", ¤tBtDeviceName, - "Address", ¤tBtDeviceAddress)) { + "Address", ¤tBtDeviceAddress, + "Path", ¤tBtDevicePath)) { HalBtDataRemoveSelectedBtDeviceFromList(firstBtDeviceData, currentBtDeviceData); return NULL; } @@ -108,8 +108,11 @@ struct HalBtDeviceData *HalBtDataAddBtDeviceToBtDeviceList(struct HalBtDeviceDat return NULL; } - // JAI : WARNING : hci bt device is currently harcoded - if(! (currentBtDeviceData->hci = strdup("hci0"))) { + currentBtDeviceHci = strtok(currentBtDevicePath, "/"); + while(currentBtDeviceHci && strncmp(currentBtDeviceHci, "hci", 3)) + currentBtDeviceHci = strtok(NULL, "/"); + + if((! currentBtDeviceHci) || (! (currentBtDeviceData->hci = strdup(currentBtDeviceHci)))) { HalBtDataRemoveSelectedBtDeviceFromList(firstBtDeviceData, currentBtDeviceData); return NULL; } -- cgit 1.2.3-korg