mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
abb79e4fb5
Separate Bluetooth HCI component example which adds some macros and functions used by HCI Layer defined by the spec.
71 lines
2.3 KiB
C
71 lines
2.3 KiB
C
/* Basic functionality for Bluetooth Host Controller Interface Layer.
|
|
|
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
|
|
Unless required by applicable law or agreed to in writing, this
|
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
CONDITIONS OF ANY KIND, either express or implied.
|
|
*/
|
|
|
|
#include "bt_hci_common.h"
|
|
|
|
|
|
uint16_t make_cmd_ble_set_adv_enable (uint8_t *buf, uint8_t adv_enable)
|
|
{
|
|
UINT8_TO_STREAM (buf, H4_TYPE_COMMAND);
|
|
UINT16_TO_STREAM (buf, HCI_BLE_WRITE_ADV_ENABLE);
|
|
UINT8_TO_STREAM (buf, HCIC_PARAM_SIZE_WRITE_ADV_ENABLE);
|
|
UINT8_TO_STREAM (buf, adv_enable);
|
|
return HCI_H4_CMD_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_ADV_ENABLE;
|
|
}
|
|
|
|
uint16_t make_cmd_ble_set_adv_param (uint8_t *buf, uint16_t adv_int_min, uint16_t adv_int_max,
|
|
uint8_t adv_type, uint8_t addr_type_own,
|
|
uint8_t addr_type_dir, bd_addr_t direct_bda,
|
|
uint8_t channel_map, uint8_t adv_filter_policy)
|
|
{
|
|
UINT8_TO_STREAM (buf, H4_TYPE_COMMAND);
|
|
UINT16_TO_STREAM (buf, HCI_BLE_WRITE_ADV_PARAMS);
|
|
UINT8_TO_STREAM (buf, HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS );
|
|
|
|
UINT16_TO_STREAM (buf, adv_int_min);
|
|
UINT16_TO_STREAM (buf, adv_int_max);
|
|
UINT8_TO_STREAM (buf, adv_type);
|
|
UINT8_TO_STREAM (buf, addr_type_own);
|
|
UINT8_TO_STREAM (buf, addr_type_dir);
|
|
BDADDR_TO_STREAM (buf, direct_bda);
|
|
UINT8_TO_STREAM (buf, channel_map);
|
|
UINT8_TO_STREAM (buf, adv_filter_policy);
|
|
return HCI_H4_CMD_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS;
|
|
}
|
|
|
|
uint16_t make_cmd_reset(uint8_t *buf)
|
|
{
|
|
UINT8_TO_STREAM (buf, H4_TYPE_COMMAND);
|
|
UINT16_TO_STREAM (buf, HCI_RESET);
|
|
UINT8_TO_STREAM (buf, 0);
|
|
return HCI_H4_CMD_PREAMBLE_SIZE;
|
|
}
|
|
|
|
|
|
|
|
uint16_t make_cmd_ble_set_adv_data(uint8_t *buf, uint8_t data_len, uint8_t *p_data)
|
|
{
|
|
UINT8_TO_STREAM (buf, H4_TYPE_COMMAND);
|
|
UINT16_TO_STREAM (buf, HCI_BLE_WRITE_ADV_DATA);
|
|
UINT8_TO_STREAM (buf, HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1);
|
|
|
|
memset(buf, 0, HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA);
|
|
|
|
if (p_data != NULL && data_len > 0) {
|
|
if (data_len > HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA) {
|
|
data_len = HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA;
|
|
}
|
|
|
|
UINT8_TO_STREAM (buf, data_len);
|
|
|
|
ARRAY_TO_STREAM (buf, p_data, data_len);
|
|
}
|
|
return HCI_H4_CMD_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1;
|
|
}
|