summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/lib/bluetooth/hal-bt-cb.c17
-rw-r--r--plugins/lib/bluetooth/hal-bt-data.c38
-rw-r--r--plugins/lib/bluetooth/hal-bt-data.h6
3 files changed, 50 insertions, 11 deletions
diff --git a/plugins/lib/bluetooth/hal-bt-cb.c b/plugins/lib/bluetooth/hal-bt-cb.c
index 243b3b9..f57f7ac 100644
--- a/plugins/lib/bluetooth/hal-bt-cb.c
+++ b/plugins/lib/bluetooth/hal-bt-cb.c
@@ -98,9 +98,11 @@ void HalBtGetConnectedBluetoothDevices(AFB_ReqT request)
while(currentBtDeviceData) {
wrap_json_pack(&currentBtDeviceObjectJ,
- "{s:s s:s}",
+ "{s:s s:s s:s s:b}",
+ "Hci", currentBtDeviceData->hci,
"Name", currentBtDeviceData->name,
- "Address", currentBtDeviceData->address);
+ "Address", currentBtDeviceData->address,
+ "A2dp", currentBtDeviceData->a2dp);
json_object_array_add(requestAnswer, currentBtDeviceObjectJ);
currentBtDeviceData = currentBtDeviceData->next;
@@ -126,9 +128,11 @@ void HalBtGetSelectedBluetoothDevice(AFB_ReqT request)
}
wrap_json_pack(&selectedBtDeviceObject,
- "{s:s s:s}",
+ "{s:s s:s s:s s:b}",
+ "Hci", localHalBtPluginData->selectedBtDevice->hci,
"Name", localHalBtPluginData->selectedBtDevice->name,
- "Address", localHalBtPluginData->selectedBtDevice->address);
+ "Address", localHalBtPluginData->selectedBtDevice->address,
+ "A2dp", localHalBtPluginData->selectedBtDevice->a2dp);
AFB_ReqSuccess(request, selectedBtDeviceObject, "Selected Bluetooth device");
}
@@ -162,6 +166,11 @@ void HalBtSetSelectedBluetoothDevice(AFB_ReqT request)
return;
}
+ if(! selectedBtDeviceData->a2dp) {
+ AFB_ReqFail(request, "requested_device_to_select", "Requested bluetooth device to select is not able to use A2DP profile");
+ return;
+ }
+
localHalBtPluginData->selectedBtDevice = selectedBtDeviceData;
// TODO JAI : Tell the softmixer that we want it as an input using 'bluealsa:HCI=hci0,DEV=F6:32:15:2A:80:70,PROFILE=a2dp'
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;
diff --git a/plugins/lib/bluetooth/hal-bt-data.h b/plugins/lib/bluetooth/hal-bt-data.h
index 030c8d1..ea3fe99 100644
--- a/plugins/lib/bluetooth/hal-bt-data.h
+++ b/plugins/lib/bluetooth/hal-bt-data.h
@@ -27,16 +27,18 @@
// Structure to store bluetooth device data
struct HalBtDeviceData {
char *uid;
+
+ char *hci;
char *name;
char *address;
- // TODO JAI : Get bluetooth device's profile and store it here
+
+ unsigned int a2dp;
struct HalBtDeviceData *next;
};
// Structure to store hal bluetooth plugin data
struct HalBtPluginData {
- // TODO JAI : Get hci device and store it here
unsigned int btStreamEnabled;
struct HalBtDeviceData *selectedBtDevice;