]> granicus.if.org Git - esp-idf/commitdiff
components/bt: Add API and EVT for BLE set channels(BLE)
authorbaohongde <baohongde@espressif.com>
Mon, 30 Sep 2019 01:50:28 +0000 (09:50 +0800)
committerbaohongde <baohongde@espressif.com>
Fri, 25 Oct 2019 03:39:35 +0000 (11:39 +0800)
17 files changed:
components/bt/host/bluedroid/api/esp_gap_ble_api.c
components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h
components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h
components/bt/host/bluedroid/bta/dm/bta_dm_act.c
components/bt/host/bluedroid/bta/dm/bta_dm_api.c
components/bt/host/bluedroid/bta/dm/bta_dm_main.c
components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h
components/bt/host/bluedroid/bta/include/bta/bta_api.h
components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c
components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h
components/bt/host/bluedroid/stack/btm/btm_devctl.c
components/bt/host/bluedroid/stack/btm/include/btm_int.h
components/bt/host/bluedroid/stack/btu/btu_hcif.c
components/bt/host/bluedroid/stack/hcic/hciblecmds.c
components/bt/host/bluedroid/stack/include/stack/bt_types.h
components/bt/host/bluedroid/stack/include/stack/btm_api.h
components/bt/host/bluedroid/stack/include/stack/hcimsgs.h

index aef6b3d6d621dc80a536196577ada0db6462464e..7bf705d1b3e8ccdc06c7fb3803a2f9b034bccbad 100644 (file)
@@ -717,6 +717,20 @@ esp_err_t esp_ble_get_current_conn_params(esp_bd_addr_t bd_addr, esp_gap_conn_pa
     return ESP_ERR_NOT_FOUND;
 }
 
+esp_err_t esp_gap_ble_set_channels(esp_gap_ble_channels channels)
+{
+    btc_msg_t msg;
+    btc_ble_gap_args_t arg;
 
+    if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
+        return ESP_ERR_INVALID_STATE;
+    }
 
+    msg.sig = BTC_SIG_API_CALL;
+    msg.pid = BTC_PID_GAP_BLE;
+    msg.act = BTC_GAP_BLE_SET_AFH_CHANNELS;
 
+    memcpy(&arg.set_channels.channels, channels, ESP_GAP_BLE_CHANNELS_LEN);
+    arg.set_channels.channels[ESP_GAP_BLE_CHANNELS_LEN -1] &= 0x1F;
+    return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+}
index 657610a1303ffbcf1fc26b005c701331108f38c1..59cf45bb4ba6723b31ae6efeb91be73c216dfbcc 100644 (file)
@@ -143,31 +143,36 @@ typedef enum {
     ESP_GAP_BLE_SCAN_RESULT_EVT,                            /*!< When one scan result ready, the event comes each time */
     ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT,              /*!< When raw advertising data set complete, the event comes */
     ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT,         /*!< When raw advertising data set complete, the event comes */
-    ESP_GAP_BLE_ADV_START_COMPLETE_EVT,                     /*!< When start advertising complete, the event comes */
-    ESP_GAP_BLE_SCAN_START_COMPLETE_EVT,                    /*!< When start scan complete, the event comes */
-    ESP_GAP_BLE_AUTH_CMPL_EVT,                              /* Authentication complete indication. */
-    ESP_GAP_BLE_KEY_EVT,                                    /* BLE  key event for peer device keys */
-    ESP_GAP_BLE_SEC_REQ_EVT,                                /* BLE  security request */
-    ESP_GAP_BLE_PASSKEY_NOTIF_EVT,                          /* passkey notification event */
-    ESP_GAP_BLE_PASSKEY_REQ_EVT,                            /* passkey request event */
-    ESP_GAP_BLE_OOB_REQ_EVT,                                /* OOB request event */
-    ESP_GAP_BLE_LOCAL_IR_EVT,                               /* BLE local IR event */
-    ESP_GAP_BLE_LOCAL_ER_EVT,                               /* BLE local ER event */
-    ESP_GAP_BLE_NC_REQ_EVT,                                 /* Numeric Comparison request event */
-    ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT,                      /*!< When stop adv complete, the event comes */
-    ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT,                     /*!< When stop scan complete, the event comes */
-    ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT,                   /*!< When set the static rand address complete, the event comes */
-    ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT,                     /*!< When update connection parameters complete, the event comes */
-    ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT,                /*!< When set pkt length complete, the event comes */
-    ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT,             /*!< When  Enable/disable privacy on the local device complete, the event comes */
-    ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT,               /*!< When remove the bond device complete, the event comes */
-    ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT,                /*!< When clear the bond device clear complete, the event comes */
-    ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT,                  /*!< When get the bond device list complete, the event comes */
-    ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT,                     /*!< When read the rssi complete, the event comes */
-    ESP_GAP_BLE_UPDATE_WHITELIST_COMPLETE_EVT,              /*!< When add or remove whitelist complete, the event comes */
-    ESP_GAP_BLE_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_COMPLETE_EVT,  /*!< When update duplicate exceptional list complete, the event comes */
+    ESP_GAP_BLE_ADV_START_COMPLETE_EVT,                     /*!< When starting advertising complete, the event comes */
+    ESP_GAP_BLE_SCAN_START_COMPLETE_EVT,                    /*!< When starting scan complete, the event comes */
+    ESP_GAP_BLE_AUTH_CMPL_EVT,                              /*!< Authentication complete indication. */
+    ESP_GAP_BLE_KEY_EVT,                                    /*!< BLE  key event for peer device keys */
+    ESP_GAP_BLE_SEC_REQ_EVT,                                /*!< BLE  security request */
+    ESP_GAP_BLE_PASSKEY_NOTIF_EVT,                          /*!< passkey notification event */
+    ESP_GAP_BLE_PASSKEY_REQ_EVT,                            /*!< passkey request event */
+    ESP_GAP_BLE_OOB_REQ_EVT,                                /*!< OOB request event */
+    ESP_GAP_BLE_LOCAL_IR_EVT,                               /*!< BLE local IR event */
+    ESP_GAP_BLE_LOCAL_ER_EVT,                               /*!< BLE local ER event */
+    ESP_GAP_BLE_NC_REQ_EVT,                                 /*!< Numeric Comparison request event */
+    ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT,                      /*!< When stopping adv complete, the event comes */
+    ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT,                     /*!< When stopping scan complete, the event comes */
+    ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT,                   /*!< When setting the static rand address complete, the event comes */
+    ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT,                     /*!< When updating connection parameters complete, the event comes */
+    ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT,                /*!< When setting pkt length complete, the event comes */
+    ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT,             /*!< When enabling/disabling privacy on the local device complete, the event comes */
+    ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT,               /*!< When removing the bond device complete, the event comes */
+    ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT,                /*!< When clearing the bond device clear complete, the event comes */
+    ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT,                  /*!< When getting the bond device list complete, the event comes */
+    ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT,                     /*!< When reading the rssi complete, the event comes */
+    ESP_GAP_BLE_UPDATE_WHITELIST_COMPLETE_EVT,              /*!< When adding or removing whitelist complete, the event comes */
+    ESP_GAP_BLE_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_COMPLETE_EVT,  /*!< When updating duplicate exceptional list complete, the event comes */
+    ESP_GAP_BLE_SET_CHANNELS_EVT,                           /*!< When setting BLE channels complete, the event comes */
     ESP_GAP_BLE_EVT_MAX,
 } esp_gap_ble_cb_event_t;
+
+#define ESP_GAP_BLE_CHANNELS_LEN     5
+typedef uint8_t esp_gap_ble_channels[ESP_GAP_BLE_CHANNELS_LEN];
+
 /// This is the old name, just for backwards compatibility
 #define ESP_GAP_BLE_ADD_WHITELIST_COMPLETE_EVT ESP_GAP_BLE_UPDATE_WHITELIST_COMPLETE_EVT
 
@@ -780,6 +785,12 @@ typedef union {
         uint16_t         length;                     /*!< The length of device_info */
         esp_duplicate_info_t device_info;           /*!< device information, when subcode is ESP_BLE_DUPLICATE_EXCEPTIONAL_LIST_CLEAN, the value is invalid */
     } update_duplicate_exceptional_list_cmpl;       /*!< Event parameter of ESP_GAP_BLE_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_COMPLETE_EVT */
+    /**
+     * @brief ESP_GAP_BLE_SET_CHANNELS_EVT
+     */
+    struct ble_set_channels_evt_param {
+        esp_bt_status_t stat;                       /*!< BLE set channel status */
+    } ble_set_channels;                             /*!< Event parameter of ESP_GAP_BLE_SET_CHANNELS_EVT */
 } esp_ble_gap_cb_param_t;
 
 /**
@@ -1266,6 +1277,22 @@ esp_err_t esp_ble_gap_disconnect(esp_bd_addr_t remote_device);
 */
 esp_err_t esp_ble_get_current_conn_params(esp_bd_addr_t bd_addr, esp_gap_conn_params_t *conn_params);
 
+/**
+* @brief            BLE set channels
+*
+* @param[in]        channels :   The n th such field (in the range 0 to 36) contains the value for the link layer channel index n.
+*                                0 means channel n is bad.
+*                                1 means channel n is unknown.
+*                                The most significant bits are reserved and shall be set to 0.
+*                                At least one channel shall be marked as unknown.
+*
+* @return           - ESP_OK : success
+*                   - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
+*                   - other  : failed
+*
+*/
+esp_err_t esp_gap_ble_set_channels(esp_gap_ble_channels channels);
+
 #ifdef __cplusplus
 }
 #endif
index 7270c6cf77ffc4d9603c010fc43a006caa542590..59369a6218382654687a7e4f48ecee8aff4a81e7 100644 (file)
@@ -323,7 +323,7 @@ typedef union {
      */
     struct set_afh_channels_param {
         esp_bt_status_t stat;                  /*!< set AFH channel status */
-    } set_afh_channels;
+    } set_afh_channels;                        /*!< set AFH channel parameter struct */
 } esp_bt_gap_cb_param_t;
 
 /**
@@ -652,18 +652,18 @@ esp_err_t esp_bt_gap_ssp_confirm_reply(esp_bd_addr_t bd_addr, bool accept);
 /**
 * @brief            Set the AFH channels
 *
-* @param[in]        channles :  The n th such field (in the range 0 to 78) contains the value for channel n :
-*                               Channel n is bad = 0
-*                               Channel n is unknown = 1
-*                               The most significant bit is reserved and shall be set to 0
-*                               At least 20 channels shall be marked as unknown
+* @param[in]        channels :  The n th such field (in the range 0 to 78) contains the value for channel n :
+*                               0 means channel n is bad.
+*                               1 means channel n is unknown.
+*                               The most significant bit is reserved and shall be set to 0.
+*                               At least 20 channels shall be marked as unknown.
 *
 * @return           - ESP_OK : success
 *                   - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
 *                   - other  : failed
 *
 */
-esp_err_t esp_bt_gap_set_afh_channels(esp_bt_gap_afh_channels channles);
+esp_err_t esp_bt_gap_set_afh_channels(esp_bt_gap_afh_channels channels);
 
 #ifdef __cplusplus
 }
index 22d2b1cbaca11b31f152558a245a7615f8c0be16..9c510ad341d264f6ec1e15bcf9a924b9d83aaa94 100644 (file)
@@ -722,6 +722,23 @@ void bta_dm_config_eir (tBTA_DM_MSG *p_data)
     bta_dm_set_eir(NULL);
 }
 
+/*******************************************************************************
+**
+** Function         bta_dm_set_afh_channels
+**
+** Description      Sets AFH channels
+**
+**
+** Returns          void
+**
+*******************************************************************************/
+void bta_dm_ble_set_channels (tBTA_DM_MSG *p_data)
+{
+#if (BLE_INCLUDED == TRUE)
+    BTM_BleSetChannels (p_data->ble_set_channels.channels, p_data->ble_set_channels.set_channels_cb);
+#endif /// BLE_INCLUDED == TRUE
+}
+
 void bta_dm_update_white_list(tBTA_DM_MSG *p_data)
 {
 #if (BLE_INCLUDED == TRUE)
index d868f77e6dff1b25c900d594ef855a8bbf728080..13f733e8d2f07d555c563e2bc163be8b3e0b1fef 100644 (file)
@@ -255,6 +255,33 @@ void BTA_DmSetAfhChannels(const uint8_t *channels, tBTA_CMPL_CB  *set_afh_cb)
 #endif /// CLASSIC_BT_INCLUDED == TRUE
 
 #if (BLE_INCLUDED == TRUE)
+/*******************************************************************************
+**
+** Function         BTA_DmBleSetChannels
+**
+** Description      This function sets BLE channels
+**
+**
+** Returns          void
+**
+*******************************************************************************/
+void BTA_DmBleSetChannels(const uint8_t *channels, tBTA_CMPL_CB  *set_channels_cb)
+{
+
+    tBTA_DM_API_BLE_SET_CHANNELS *p_msg;
+
+    if ((p_msg = (tBTA_DM_API_BLE_SET_CHANNELS *) osi_malloc(sizeof(tBTA_DM_API_BLE_SET_CHANNELS))) != NULL) {
+        p_msg->hdr.event = BTA_DM_API_BLE_SET_CHANNELS_EVT;
+
+        p_msg->set_channels_cb = set_channels_cb;
+        memcpy(p_msg->channels, channels, BLE_CHANNELS_LEN);
+
+        bta_sys_sendmsg(p_msg);
+    }
+
+
+}
+
 void BTA_DmUpdateWhiteList(BOOLEAN add_remove,  BD_ADDR remote_addr, tBLE_ADDR_TYPE addr_type, tBTA_ADD_WHITELIST_CBACK *add_wl_cb)
 {
     tBTA_DM_API_UPDATE_WHITE_LIST *p_msg;
index ec1d3235a8af6a713d905ec866f1fc7496318893..212e91f1c13ba776d9eac4eb75d3404725d9a03a 100644 (file)
@@ -158,6 +158,7 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = {
 
     bta_dm_remove_all_acl,                  /* BTA_DM_API_REMOVE_ALL_ACL_EVT */
     bta_dm_remove_device,                   /* BTA_DM_API_REMOVE_DEVICE_EVT */
+    bta_dm_ble_set_channels,                /* BTA_DM_API_BLE_SET_CHANNELS_EVT */
     bta_dm_update_white_list,               /* BTA_DM_API_UPDATE_WHITE_LIST_EVT */
     bta_dm_ble_read_adv_tx_power,           /* BTA_DM_API_BLE_READ_ADV_TX_POWER_EVT */
     bta_dm_ble_read_rssi,                   /* BTA_DM_API_BLE_READ_RSSI_EVT */
index 74fe5c586021f9bca1c05de51e37d394e540c3e4..8bdecc6ba8ecfdcf33b691d48ad639efb6958a85 100644 (file)
@@ -155,6 +155,7 @@ enum {
     BTA_DM_API_EXECUTE_CBACK_EVT,
     BTA_DM_API_REMOVE_ALL_ACL_EVT,
     BTA_DM_API_REMOVE_DEVICE_EVT,
+    BTA_DM_API_BLE_SET_CHANNELS_EVT,
     BTA_DM_API_UPDATE_WHITE_LIST_EVT,
     BTA_DM_API_BLE_READ_ADV_TX_POWER_EVT,
     BTA_DM_API_BLE_READ_RSSI_EVT,
@@ -214,6 +215,13 @@ typedef struct {
 }tBTA_DM_API_SET_AFH_CHANNELS;
 
 #if (BLE_INCLUDED == TRUE)
+/* data type for BTA_DM_API_BLE_SET_CHANNELS_EVT */
+typedef struct {
+    BT_HDR              hdr;
+    AFH_CHANNELS        channels;
+    tBTA_CMPL_CB        *set_channels_cb;
+}tBTA_DM_API_BLE_SET_CHANNELS;
+
 typedef struct {
     BT_HDR    hdr;
     BOOLEAN   add_remove;
@@ -816,6 +824,7 @@ typedef union {
     tBTA_DM_API_SET_AFH_CHANNELS set_afh_channels;
 
 #if (BLE_INCLUDED == TRUE)
+    tBTA_DM_API_BLE_SET_CHANNELS  ble_set_channels;
     tBTA_DM_API_UPDATE_WHITE_LIST white_list;
     tBTA_DM_API_READ_ADV_TX_POWER read_tx_power;
     tBTA_DM_API_READ_RSSI rssi;
@@ -1273,6 +1282,7 @@ extern void bta_dm_disable (tBTA_DM_MSG *p_data);
 extern void bta_dm_set_dev_name (tBTA_DM_MSG *p_data);
 extern void bta_dm_config_eir (tBTA_DM_MSG *p_data);
 extern void bta_dm_set_afh_channels (tBTA_DM_MSG *p_data);
+extern void bta_dm_ble_set_channels (tBTA_DM_MSG *p_data);
 extern void bta_dm_update_white_list(tBTA_DM_MSG *p_data);
 extern void bta_dm_ble_read_adv_tx_power(tBTA_DM_MSG *p_data);
 extern void bta_dm_ble_read_rssi(tBTA_DM_MSG *p_data);
index 7f767366ab84c627775faf00d2dd240a9370d440..d2de7959f8b9bc1f6e10afb40e517cd74e03c263 100644 (file)
@@ -434,7 +434,7 @@ typedef tBTM_TX_POWER_RESULTS tBTA_TX_POWER_RESULTS;
 typedef tBTM_RSSI_RESULTS tBTA_RSSI_RESULTS;
 
 typedef tBTM_SET_AFH_CHANNELS_RESULTS tBTA_SET_AFH_CHANNELS_RESULTS;
-
+typedef tBTM_BLE_SET_CHANNELS_RESULTS tBTA_BLE_SET_CHANNELS_RESULTS;
 /* advertising channel map */
 #define BTA_BLE_ADV_CHNL_37 BTM_BLE_ADV_CHNL_37
 #define BTA_BLE_ADV_CHNL_38 BTM_BLE_ADV_CHNL_38
@@ -1488,6 +1488,18 @@ extern void BTA_DmConfigEir(tBTA_DM_EIR_CONF *eir_config);
 void BTA_DmSetAfhChannels(const uint8_t *channels, tBTA_CMPL_CB  *set_afh_cb);
 
 #if (BLE_INCLUDED == TRUE)
+/*******************************************************************************
+**
+** Function         BTA_DmBleSetChannels
+**
+** Description      This function sets BLE channels
+**
+**
+** Returns          void
+**
+*******************************************************************************/
+void BTA_DmBleSetChannels(const uint8_t *channels, tBTA_CMPL_CB  *set_channels_cb);
+
 extern void BTA_DmUpdateWhiteList(BOOLEAN add_remove,  BD_ADDR remote_addr, tBLE_ADDR_TYPE addr_type, tBTA_ADD_WHITELIST_CBACK *add_wl_cb);
 
 extern void BTA_DmBleReadAdvTxPower(tBTA_CMPL_CB *cmpl_cb);
index d9a9cde7d1822101922e487a21a86743d3c16018..181e26ec531787aa30f2e6d394ba26ffd2fad493 100644 (file)
@@ -704,6 +704,27 @@ static void btc_set_pkt_length_callback(UINT8 status, tBTM_LE_SET_PKT_DATA_LENGT
     }
 }
 
+static void btc_gap_ble_set_channels_cmpl_callback(void *p_data)
+{
+    tBTA_BLE_SET_CHANNELS_RESULTS *result = (tBTA_BLE_SET_CHANNELS_RESULTS *)p_data;
+    esp_ble_gap_cb_param_t param;
+    bt_status_t ret;
+    btc_msg_t msg;
+    msg.sig = BTC_SIG_API_CB;
+    msg.pid = BTC_PID_GAP_BLE;
+    msg.act = ESP_GAP_BLE_SET_CHANNELS_EVT;
+
+    param.ble_set_channels.stat = btc_btm_status_to_esp_status(result->status);
+
+    ret = btc_transfer_context(&msg, &param,
+                               sizeof(esp_ble_gap_cb_param_t), NULL);
+
+    if (ret != BT_STATUS_SUCCESS) {
+        BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__);
+    }
+}
+
+
 static void btc_add_whitelist_complete_callback(UINT8 status, tBTM_WL_OPERATION wl_opration)
 {
     esp_ble_gap_cb_param_t param;
@@ -897,6 +918,12 @@ static void btc_ble_disconnect(BD_ADDR bd_addr)
     BTA_DmBleDisconnect(bd_addr);
 }
 
+static void btc_gap_ble_set_channels(esp_gap_ble_channels channels)
+{
+    BTA_DmBleSetChannels(channels, btc_gap_ble_set_channels_cmpl_callback);
+}
+
+
 void btc_gap_ble_cb_handler(btc_msg_t *msg)
 {
     esp_ble_gap_cb_param_t *param = (esp_ble_gap_cb_param_t *)msg->arg;
@@ -1264,6 +1291,9 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
     case BTC_GAP_BLE_DISCONNECT_EVT:
         btc_ble_disconnect(arg->disconnect.remote_device);
         break;
+    case BTC_GAP_BLE_SET_AFH_CHANNELS:
+        btc_gap_ble_set_channels(arg->set_channels.channels);
+        break;
     default:
         break;
     }
index 3af1559ff860428baac9080122be202ca9962654..ee5bea30a06f711d3fa4250cac7ae8a114d56831 100644 (file)
@@ -56,6 +56,7 @@ typedef enum {
     BTC_GAP_BLE_REMOVE_BOND_DEV_EVT,
     BTC_GAP_BLE_OOB_REQ_REPLY_EVT,
     BTC_GAP_BLE_UPDATE_DUPLICATE_SCAN_EXCEPTIONAL_LIST,
+    BTC_GAP_BLE_SET_AFH_CHANNELS,
 } btc_gap_ble_act_t;
 
 /* btc_ble_gap_args_t */
@@ -179,6 +180,10 @@ typedef union {
     struct read_rssi_args {
         esp_bd_addr_t remote_addr;
     } read_rssi;
+    // BTC_GAP_BLE_SET_AFH_CHANNELS
+    struct set_channels_args {
+       esp_gap_ble_channels channels;
+    } set_channels;
 } btc_ble_gap_args_t;
 
 void btc_gap_ble_call_handler(btc_msg_t *msg);
index 12e83de90b71529811306ff5a49c3178c1de285a..475591d7556580bfee8b1f9f5cd05059e6bcc1b3 100644 (file)
@@ -1040,7 +1040,7 @@ tBTM_STATUS BTM_SetAfhChannels (AFH_CHANNELS channels, tBTM_CMPL_CB *p_afh_chann
 **
 ** Function         btm_set_afh_channels_complete
 **
-** Description      This function is called when set AFH channels complete.
+** Description      This function is called when setting AFH channels complete.
 **                  message is received from the HCI.
 **
 ** Returns          void
@@ -1053,7 +1053,7 @@ void btm_set_afh_channels_complete (UINT8 *p)
 
     btu_free_timer (&btm_cb.devcb.afh_channels_timer);
 
-    /* If there was a callback address for set AFH channels, call it */
+    /* If there is a callback address for setting AFH channels, call it */
     btm_cb.devcb.p_afh_channels_cmpl_cb = NULL;
 
     if (p_cb) {
@@ -1074,4 +1074,77 @@ void btm_set_afh_channels_complete (UINT8 *p)
         (*p_cb)(&results);
     }
 }
-#endif /// CLASSIC_BT_INCLUDED == TRUE
\ No newline at end of file
+#endif /// CLASSIC_BT_INCLUDED == TRUE
+
+#if (BLE_INCLUDED == TRUE)
+/*******************************************************************************
+**
+** Function         BTM_BleSetChannels
+**
+** Description      This function is called to set BLE channels
+**
+** Returns          status of the operation
+**
+*******************************************************************************/
+tBTM_STATUS BTM_BleSetChannels (BLE_CHANNELS channels, tBTM_CMPL_CB *p_ble_channels_cmpl_cback)
+{
+    if (!controller_get_interface()->get_is_ready()) {
+        return (BTM_DEV_RESET);
+    }
+
+    /* Check if set afh already in progress */
+    if (btm_cb.devcb.p_ble_channels_cmpl_cb) {
+        return (BTM_NO_RESOURCES);
+    }
+
+    /* Save callback */
+    btm_cb.devcb.p_ble_channels_cmpl_cb = p_ble_channels_cmpl_cback;
+
+    if (!btsnd_hcic_ble_set_channels (channels)) {
+        return (BTM_NO_RESOURCES);
+    }
+
+    btu_start_timer (&btm_cb.devcb.ble_channels_timer, BTU_TTYPE_BTM_ACL, BTM_DEV_REPLY_TIMEOUT);
+
+    return BTM_CMD_STARTED;
+}
+
+/*******************************************************************************
+**
+** Function         btm_set_afh_channels_complete
+**
+** Description      This function is called when setting AFH channels complete.
+**                  message is received from the HCI.
+**
+** Returns          void
+**
+*******************************************************************************/
+void btm_ble_set_channels_complete (UINT8 *p)
+{
+    tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_ble_channels_cmpl_cb;
+    tBTM_BLE_SET_CHANNELS_RESULTS results;
+
+    btu_free_timer (&btm_cb.devcb.ble_channels_timer);
+
+    /* If there is a callback address for setting AFH channels, call it */
+    btm_cb.devcb.p_ble_channels_cmpl_cb = NULL;
+
+    if (p_cb) {
+        STREAM_TO_UINT8 (results.hci_status, p);
+
+        switch (results.hci_status){
+            case HCI_SUCCESS:
+                results.status = BTM_SUCCESS;
+                break;
+            case HCI_ERR_UNSUPPORTED_VALUE:
+            case HCI_ERR_ILLEGAL_PARAMETER_FMT:
+                results.status = BTM_ILLEGAL_VALUE;
+                break;
+            default:
+                results.status = BTM_ERR_PROCESSING;
+                break;
+        }
+        (*p_cb)(&results);
+    }
+}
+#endif /// BLE_INCLUDED == TRUE
\ No newline at end of file
index 81211c38214aa40c36d4238cb54b52a87fe6cfe7..c1eb658fe5930b151a7818d873cc88e90a22d882 100644 (file)
@@ -173,6 +173,10 @@ DEV_CLASS            dev_class;         /* Local device class
 
 #if BLE_INCLUDED == TRUE
 
+TIMER_LIST_ENT       ble_channels_timer;
+tBTM_CMPL_CB        *p_ble_channels_cmpl_cb; /* Callback function to be called  When
+                                                ble set host channels is completed   */
+
 tBTM_CMPL_CB        *p_le_test_cmd_cmpl_cb;   /* Callback function to be called when
                                                   LE test mode command has been sent successfully */
 
@@ -1074,6 +1078,7 @@ void btm_vendor_specific_evt (UINT8 *p, UINT8 evt_len);
 void btm_delete_stored_link_key_complete (UINT8 *p);
 void btm_report_device_status (tBTM_DEV_STATUS status);
 void btm_set_afh_channels_complete (UINT8 *p);
+void btm_ble_set_channels_complete (UINT8 *p);
 
 /* Internal functions provided by btm_dev.c
 **********************************************
index e3402d3d909beee61b8f844b711c7fcacbcbdfd6..68f353cc23d467232d395d6fa07527d516289f1e 100644 (file)
@@ -918,7 +918,10 @@ static void btu_hcif_hdl_command_complete (UINT16 opcode, UINT8 *p, UINT16 evt_l
 #endif
 
 #if (BLE_INCLUDED == TRUE)
-    /* BLE Commands sComplete*/
+    /* BLE Commands Complete*/
+    case HCI_BLE_SET_HOST_CHNL_CLASS:
+        btm_ble_set_channels_complete(p);
+        break;
     case HCI_BLE_ADD_WHITE_LIST:
         btm_ble_add_2_white_list_complete(*p);
         break;
index 1d814cc8d023ef43a8bc88f07dcf9f7c05d5a566..f922a58fa76592bda19abfe84404b58332a7372b 100644 (file)
@@ -1023,5 +1023,28 @@ BOOLEAN btsnd_hcic_ble_update_adv_report_flow_control (UINT16 num)
     return TRUE;
 }
 
+BOOLEAN btsnd_hcic_ble_set_channels (BLE_CHANNELS channels)
+{
+    BT_HDR *p;
+    UINT8 *pp;
+
+    if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_SET_CHANNELS)) == NULL) {
+        return (FALSE);
+    }
+
+    pp = (UINT8 *)(p + 1);
+
+    p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_CHANNELS;
+    p->offset = 0;
+
+    UINT16_TO_STREAM (pp, HCI_BLE_SET_HOST_CHNL_CLASS);
+    UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_SET_CHANNELS);
+
+    ARRAY_TO_STREAM  (pp, channels, HCIC_PARAM_SIZE_BLE_SET_CHANNELS);
+
+    btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
+    return (TRUE);
+}
+
 #endif
 
index 50edb6c123334a14ce61d2cbea8fb7acc9c26c7a..e5f716d6eca61125a5d8419cf4f37180c28323e5 100644 (file)
@@ -356,6 +356,8 @@ typedef UINT8 COF[COF_LEN];                 /* ciphering offset number */
 
 #define AFH_CHANNELS_LEN    10
 typedef UINT8 AFH_CHANNELS[AFH_CHANNELS_LEN];
+#define BLE_CHANNELS_LEN    5
+typedef UINT8 BLE_CHANNELS[BLE_CHANNELS_LEN];
 
 typedef struct {
     UINT8               qos_flags;          /* TBD */
@@ -690,8 +692,6 @@ typedef void (BT_LOG_FUNC) (int trace_type, const char *fmt_str, ...);
 typedef uint8_t BD_ADDR[BD_ADDR_LEN];
 #endif
 
-/*  */
-
 // From bd.c
 
 /*****************************************************************************
index fa2e9818972cce92ba0c0f2efce2c1eb2a76f3a7..e33435cf4fe9610a70eccea299d6f7ef623e77a2 100644 (file)
@@ -806,6 +806,14 @@ typedef struct {
     UINT8       hci_status;
 } tBTM_SET_AFH_CHANNELS_RESULTS;
 
+/* Structure returned with set BLE channels event (in tBTM_CMPL_CB callback function)
+** in response to BTM_BleSetChannels call.
+*/
+typedef struct {
+    tBTM_STATUS status;
+    UINT8       hci_status;
+} tBTM_BLE_SET_CHANNELS_RESULTS;
+
 /* Structure returned with read inq tx power quality event (in tBTM_CMPL_CB callback function)
 ** in response to BTM_ReadInquiryRspTxPower call.
 */
@@ -4118,6 +4126,17 @@ tBTM_CONTRL_STATE BTM_PM_ReadControllerState(void);
 *******************************************************************************/
 tBTM_STATUS BTM_SetAfhChannels (AFH_CHANNELS channels, tBTM_CMPL_CB *p_afh_channels_cmpl_cback);
 
+/*******************************************************************************
+**
+** Function         BTM_BleSetChannels
+**
+** Description      This function is called to set BLE channels
+**
+** Returns          status of the operation
+**
+*******************************************************************************/
+tBTM_STATUS BTM_BleSetChannels (BLE_CHANNELS channels, tBTM_CMPL_CB *p_ble_channels_cmpl_cback);
+
 /*
 #ifdef __cplusplus
 }
index f5002d967b8d98dd1bf2afc0ea2cb5190c12ff78..f2fa59fd98755ec572a57437bcb0d9c55c524d24 100644 (file)
@@ -523,6 +523,8 @@ BOOLEAN btsnd_hcic_change_name(BD_NAME name);
 /* set AFH channels */
 BOOLEAN btsnd_hcic_set_afh_channels (AFH_CHANNELS channels);
 #define HCIC_PARAM_SIZE_SET_AFH_CHANNELS    10
+BOOLEAN btsnd_hcic_ble_set_channels (BLE_CHANNELS channels);
+#define HCIC_PARAM_SIZE_BLE_SET_CHANNELS    5
 
 BOOLEAN btsnd_hcic_write_pin_type(UINT8 type);                   /* Write PIN Type */
 BOOLEAN btsnd_hcic_write_auto_accept(UINT8 flag);                /* Write Auto Accept */