summaryrefslogtreecommitdiffstats
path: root/plugins/lib/bluetooth/hal-bt-data.c
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2018-09-07 18:40:34 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2018-10-08 15:57:27 +0200
commit6b215041cfe7b072344704d820bbe74fe07ab8eb (patch)
treeb2b654e0c5d4fd3e3f073c1b06070ab2f49d28dd /plugins/lib/bluetooth/hal-bt-data.c
parent624971371bba5ca9a9fa6a862c70b0e928e5649c (diff)
Add handling of hci and profile in hal-bt plugin
Add handling of bluetoothg hci and bluetooth profile when keep bluetooth connected devices up to date. Change-Id: I49b3e67136168bcae711eb8f7ffb2e1ccdbad3ae Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to 'plugins/lib/bluetooth/hal-bt-data.c')
-rw-r--r--plugins/lib/bluetooth/hal-bt-data.c38
1 files changed, 33 insertions, 5 deletions
diff --git a/plugins/lib/bluetooth/hal-bt-data.c b/plugins/lib/bluetooth/hal-bt-data.c
index d56d0db..ff93ab8 100644
--- a/plugins/lib/bluetooth/hal-bt-data.c
+++ b/plugins/lib/bluetooth/hal-bt-data.c
@@ -55,6 +55,7 @@ int HalBtDataRemoveSelectedBtDeviceFromList(struct HalBtDeviceData **firstBtDevi
}
}
+ free(matchingBtDevice->hci);
free(matchingBtDevice->uid);
free(matchingBtDevice->name);
free(matchingBtDevice->address);
@@ -76,7 +77,6 @@ struct HalBtDeviceData *HalBtDataAddBtDeviceToBtDeviceList(struct HalBtDeviceDat
currentBtDeviceData = *firstBtDeviceData;
if(! currentBtDeviceData) {
-
currentBtDeviceData = (struct HalBtDeviceData *) calloc(1, sizeof(struct HalBtDeviceData));
if(! currentBtDeviceData)
return NULL;
@@ -84,7 +84,6 @@ struct HalBtDeviceData *HalBtDataAddBtDeviceToBtDeviceList(struct HalBtDeviceDat
*firstBtDeviceData = currentBtDeviceData;
}
else {
-
while(currentBtDeviceData->next)
currentBtDeviceData = currentBtDeviceData->next;
@@ -95,6 +94,8 @@ struct HalBtDeviceData *HalBtDataAddBtDeviceToBtDeviceList(struct HalBtDeviceDat
currentBtDeviceData = currentBtDeviceData->next;
}
+ // TODO JAI : get hci device of bt device here
+ // TODO JAI : check if a2dp profile is supported here
if(wrap_json_unpack(currentSingleBtDeviceDataJ,
"{s:s s:s}",
"Name", &currentBtDeviceName,
@@ -108,6 +109,12 @@ struct HalBtDeviceData *HalBtDataAddBtDeviceToBtDeviceList(struct HalBtDeviceDat
return NULL;
}
+ // JAI : WARNING : hci bt device is currently harcoded
+ if(! (currentBtDeviceData->hci = strdup("hci0"))) {
+ HalBtDataRemoveSelectedBtDeviceFromList(firstBtDeviceData, currentBtDeviceData);
+ return NULL;
+ }
+
if(! (currentBtDeviceData->name = strdup(currentBtDeviceName))) {
HalBtDataRemoveSelectedBtDeviceFromList(firstBtDeviceData, currentBtDeviceData);
return NULL;
@@ -118,9 +125,31 @@ struct HalBtDeviceData *HalBtDataAddBtDeviceToBtDeviceList(struct HalBtDeviceDat
return NULL;
}
+ // JAI : WARNING : a2dp profile is currently harcoded
+ currentBtDeviceData->a2dp = 1;
+
return currentBtDeviceData;
}
+struct HalBtDeviceData *HalBtDataGetFirstA2dpBtDeviceAvailable(struct HalBtDeviceData **firstBtDeviceData)
+{
+ struct HalBtDeviceData *currentBtDeviceData;
+
+ if(! firstBtDeviceData)
+ return NULL;
+
+ currentBtDeviceData = *firstBtDeviceData;
+
+ while(currentBtDeviceData) {
+ if(currentBtDeviceData->a2dp)
+ return currentBtDeviceData;
+
+ currentBtDeviceData = currentBtDeviceData->next;
+ }
+
+ return NULL;
+}
+
int HalBtDataGetNumberOfBtDeviceInList(struct HalBtDeviceData **firstBtDeviceData)
{
unsigned int btDeviceNb = 0;
@@ -184,15 +213,14 @@ int HalBtDataHandleReceivedSingleBtDeviceData(struct HalBtPluginData *halBtPlugi
return -3;
if(halBtPluginData->selectedBtDevice == currentBtDevice)
- halBtPluginData->selectedBtDevice = halBtPluginData->first;
+ halBtPluginData->selectedBtDevice = HalBtDataGetFirstA2dpBtDeviceAvailable(&halBtPluginData->first);
}
else if(! currentBtDevice && currentBtDeviceIsConnected) {
-
if(! HalBtDataAddBtDeviceToBtDeviceList(&halBtPluginData->first, currentSingleBtDeviceDataJ))
return -4;
if(! halBtPluginData->selectedBtDevice)
- halBtPluginData->selectedBtDevice = halBtPluginData->first;
+ halBtPluginData->selectedBtDevice = HalBtDataGetFirstA2dpBtDeviceAvailable(&halBtPluginData->first);
}
return 0;