From 06e2a1d4e1210674b6f2d7f64b633affa8de82e7 Mon Sep 17 00:00:00 2001 From: Tian Hao Date: Tue, 29 Nov 2016 14:38:58 +0800 Subject: [PATCH] component/bt : cleanup a macro --- components/bt/bluedroid/api/esp_gattc_api.c | 4 ++++ components/bt/bluedroid/api/esp_gatts_api.c | 2 +- components/bt/bluedroid/api/include/esp_bt_defs.h | 6 ++---- components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c | 8 ++++---- .../bt/bluedroid/btc/profile/std/include/btc_gap_ble.h | 2 ++ 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/components/bt/bluedroid/api/esp_gattc_api.c b/components/bt/bluedroid/api/esp_gattc_api.c index 88e7a627f4..656bfb83b8 100644 --- a/components/bt/bluedroid/api/esp_gattc_api.c +++ b/components/bt/bluedroid/api/esp_gattc_api.c @@ -57,6 +57,10 @@ esp_err_t esp_ble_gattc_app_register(uint16_t app_id) btc_msg_t msg; btc_ble_gattc_args_t arg; + if (app_id < ESP_APP_ID_MIN || app_id > ESP_APP_ID_MAX) { + return ESP_ERR_INVALID_ARG; + } + msg.sig = BTC_SIG_API_CALL; msg.pid = BTC_PID_GATTC; msg.act = BTC_GATTC_ACT_APP_REGISTER; diff --git a/components/bt/bluedroid/api/esp_gatts_api.c b/components/bt/bluedroid/api/esp_gatts_api.c index 047c48c074..66b2b5b165 100644 --- a/components/bt/bluedroid/api/esp_gatts_api.c +++ b/components/bt/bluedroid/api/esp_gatts_api.c @@ -30,7 +30,7 @@ esp_err_t esp_ble_gatts_app_register(uint16_t app_id) btc_msg_t msg; btc_ble_gatts_args_t arg; - if (app_id < APP_ID_MIN || app_id > APP_ID_MAX) { + if (app_id < ESP_APP_ID_MIN || app_id > ESP_APP_ID_MAX) { return ESP_ERR_INVALID_ARG; } diff --git a/components/bt/bluedroid/api/include/esp_bt_defs.h b/components/bt/bluedroid/api/include/esp_bt_defs.h index c93e92b092..6d5c65ebe8 100644 --- a/components/bt/bluedroid/api/include/esp_bt_defs.h +++ b/components/bt/bluedroid/api/include/esp_bt_defs.h @@ -78,11 +78,9 @@ typedef enum { BLE_ADDR_TYPE_RPA_RANDOM = 0x03, } esp_ble_addr_type_t; -#define APP_ID_MIN 0x0000 -#define APP_ID_MAX 0x7fff +#define ESP_APP_ID_MIN 0x0000 +#define ESP_APP_ID_MAX 0x7fff typedef void (* esp_profile_cb_t)(uint32_t event, void *param); -#define API_BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF)) - #endif ///__ESP_BT_DEFS_H__ diff --git a/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c b/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c index 3c879984e0..a37b4054da 100644 --- a/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c +++ b/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c @@ -367,8 +367,8 @@ void btc_ble_start_advertising (esp_ble_adv_params_t *ble_adv_params) disc_mode = BTA_DM_BLE_NON_DISCOVERABLE; } - if (!API_BLE_ISVALID_PARAM(ble_adv_params->adv_int_min, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX) || - !API_BLE_ISVALID_PARAM(ble_adv_params->adv_int_max, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX)) { + if (!BLE_ISVALID_PARAM(ble_adv_params->adv_int_min, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX) || + !BLE_ISVALID_PARAM(ble_adv_params->adv_int_max, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX)) { LOG_ERROR("Invalid advertisting interval parameters.\n"); return ; } @@ -424,8 +424,8 @@ static void btc_scan_params_callback(tGATT_IF gatt_if, tBTM_STATUS status) static void btc_ble_set_scan_params(esp_ble_scan_params_t *scan_params, tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback) { - if (API_BLE_ISVALID_PARAM(scan_params->scan_interval, BTM_BLE_SCAN_INT_MIN, BTM_BLE_SCAN_INT_MAX) && - API_BLE_ISVALID_PARAM(scan_params->scan_window, BTM_BLE_SCAN_WIN_MIN, BTM_BLE_SCAN_WIN_MAX) && + if (BLE_ISVALID_PARAM(scan_params->scan_interval, BTM_BLE_SCAN_INT_MIN, BTM_BLE_SCAN_INT_MAX) && + BLE_ISVALID_PARAM(scan_params->scan_window, BTM_BLE_SCAN_WIN_MIN, BTM_BLE_SCAN_WIN_MAX) && (scan_params->scan_type == BTM_BLE_SCAN_MODE_ACTI || scan_params->scan_type == BTM_BLE_SCAN_MODE_PASS)) { BTA_DmSetBleScanFilterParams(0 /*client_if*/, scan_params->scan_interval, diff --git a/components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h b/components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h index 64f1ff3246..9a35db4083 100644 --- a/components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h +++ b/components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h @@ -18,6 +18,8 @@ #include "esp_bt_defs.h" #include "esp_gap_ble_api.h" +#define BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF)) + typedef enum { BTC_GAP_BLE_ACT_CFG_ADV_DATA = 0, BTC_GAP_BLE_ACT_SET_SCAN_PARAM, -- 2.40.0