summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2018-09-11 17:23:48 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2018-10-08 15:57:27 +0200
commitad0caaef716aef6a79c4b86b86916a6dcd3e395a (patch)
tree712fb2b051695cce59af00baba2169bccff28f39
parent106db2e301d8688c0b1353bf7388897b3e91232d (diff)
Prevent Hal-Bt plugin from crashing 4A
Prevent Hal-Bt plugin from crashing 4A when 'Bluetooth-Manager' api is not found. Change-Id: Id8ecc3efcc36825abbb4a2bb8cf553327c45d173 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r--plugins/lib/bluetooth/hal-bt-data.h4
-rw-r--r--plugins/lib/bluetooth/hal-bt.c20
2 files changed, 19 insertions, 5 deletions
diff --git a/plugins/lib/bluetooth/hal-bt-data.h b/plugins/lib/bluetooth/hal-bt-data.h
index eb5eb26..500654b 100644
--- a/plugins/lib/bluetooth/hal-bt-data.h
+++ b/plugins/lib/bluetooth/hal-bt-data.h
@@ -41,10 +41,12 @@ struct HalBtDeviceData {
// Structure to store hal bluetooth plugin data
struct HalBtPluginData {
- unsigned int btStreamEnabled;
+ unsigned int halBtPluginEnabled;
struct SpecificHalData *currentHalData;
+ unsigned int btStreamEnabled;
+
struct HalBtDeviceData *selectedBtDevice;
struct HalBtDeviceData *first;
};
diff --git a/plugins/lib/bluetooth/hal-bt.c b/plugins/lib/bluetooth/hal-bt.c
index 3fcaef2..0f49311 100644
--- a/plugins/lib/bluetooth/hal-bt.c
+++ b/plugins/lib/bluetooth/hal-bt.c
@@ -45,20 +45,22 @@ CTLP_ONLOAD(plugin, callbacks)
memset(&localHalBtPluginData, '\0', sizeof(localHalBtPluginData));
if(AFB_RequireApi(plugin->api, BT_MANAGER_API, 1)) {
- AFB_ApiError(plugin->api, "Didn't succeed to require %s api", BT_MANAGER_API);
- return -1;
+ AFB_ApiWarning(plugin->api, "Didn't succeed to require %s api, bluetooth is disable because not reachable", BT_MANAGER_API);
+ return 0;
}
if(! (ctrlConfig = (CtlConfigT *) afb_dynapi_get_userdata(plugin->api))) {
AFB_ApiError(plugin->api, "Can't get current hal controller config");
- return -2;
+ return -1;
}
if(! (localHalBtPluginData.currentHalData = (struct SpecificHalData *) ctrlConfig->external)) {
AFB_ApiError(plugin->api, "%s: Can't get current hal controller data", __func__);
- return -3;
+ return -2;
}
+ localHalBtPluginData.halBtPluginEnabled = 1;
+
/* TDB JAI :
- Register 'init' plugin function (HAL_BT_PLUGIN_NAME#init) as onload action here (to avoid adding it in json)
- Register 'event' plugin function (HAL_BT_PLUGIN_NAME#event) as action for BT_MANAGER_API#BT_MANAGER_DEVICE_UPDATE_EVENT event here (to avoid adding it in json)
@@ -74,6 +76,11 @@ CTLP_CAPI(init, source, argsJ, queryJ)
struct json_object *toSendJ, *returnedJ, *returnedBtList = NULL;
+ if(! localHalBtPluginData.halBtPluginEnabled) {
+ AFB_ApiWarning(source->api, "Controller onload initialization of HAL-BT plugin cannot be done because bluetooth is not reachable");
+ return 0;
+ }
+
AFB_ApiNotice(source->api, "Initializing HAL-BT plugin");
// Loading hal BT plugin specific verbs
@@ -196,6 +203,11 @@ CTLP_CAPI(events, source, argsJ, queryJ)
{
struct HalBtDeviceData *previouslySelectedBtDevice = localHalBtPluginData.selectedBtDevice;
+ if(! localHalBtPluginData.halBtPluginEnabled) {
+ AFB_ApiWarning(source->api, "Bluetooth event received but cannot be handled because bluetooth is not reachable");
+ return 0;
+ }
+
if(HalBtDataHandleReceivedSingleBtDeviceData(&localHalBtPluginData, queryJ)) {
AFB_ApiError(source->api, "Error while decoding bluetooth event received json (%s)", json_object_get_string(queryJ));
return -1;