]> granicus.if.org Git - esp-idf/commitdiff
ble_mesh: add error checks for scan start/stop
authorlly <lly@espressif.com>
Mon, 2 Sep 2019 06:38:12 +0000 (14:38 +0800)
committerlly <lly@espressif.com>
Mon, 9 Sep 2019 09:15:16 +0000 (17:15 +0800)
components/bt/esp_ble_mesh/mesh_core/adv.c

index 87ef3630617b41f012887d55d49e2e4750601227..a1c4cf982578106df590f809cebcb7a8c19acbc2 100644 (file)
@@ -7,6 +7,9 @@
  * SPDX-License-Identifier: Apache-2.0
  */
 
+#include <stdint.h>
+#include <errno.h>
+
 #include "freertos/FreeRTOS.h"
 #include "freertos/queue.h"
 #include "freertos/task.h"
@@ -387,6 +390,8 @@ void bt_mesh_adv_init(void)
 
 int bt_mesh_scan_enable(void)
 {
+    int err;
+
     struct bt_mesh_scan_param scan_param = {
         .type       = BLE_MESH_SCAN_PASSIVE,
 #if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
@@ -400,12 +405,26 @@ int bt_mesh_scan_enable(void)
 
     BT_DBG("%s", __func__);
 
-    return bt_le_scan_start(&scan_param, bt_mesh_scan_cb);
+    err = bt_le_scan_start(&scan_param, bt_mesh_scan_cb);
+    if (err && err != -EALREADY) {
+        BT_ERR("starting scan failed (err %d)", err);
+        return err;
+    }
+
+    return 0;
 }
 
 int bt_mesh_scan_disable(void)
 {
+    int err;
+
     BT_DBG("%s", __func__);
 
-    return bt_le_scan_stop();
+    err = bt_le_scan_stop();
+    if (err && err != -EALREADY) {
+        BT_ERR("stopping scan failed (err %d)", err);
+        return err;
+    }
+
+    return 0;
 }