初版
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
#ifndef __BLE_API_H__
|
||||
#define __BLE_API_H__
|
||||
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
|
||||
///***注意:该文件的枚举与库编译密切相关,主要是给用户提供调用所用。用户不能自己在中间添加值。*/
|
||||
////----user (command) codes----////
|
||||
|
||||
/**
|
||||
* @brief hci connection handle type
|
||||
*/
|
||||
typedef uint16_t hci_con_handle_t;
|
||||
|
||||
typedef enum {
|
||||
/*
|
||||
*/
|
||||
BLE_CMD_ADV_ENABLE = 1,
|
||||
BLE_CMD_ADV_PARAM,
|
||||
BLE_CMD_ADV_DATA,
|
||||
BLE_CMD_RSP_DATA,
|
||||
BLE_CMD_DISCONNECT,
|
||||
BLE_CMD_REGIEST_THREAD,
|
||||
BLE_CMD_ATT_SEND_INIT,
|
||||
BLE_CMD_ATT_MTU_SIZE,
|
||||
BLE_CMD_ATT_VAILD_LEN,
|
||||
BLE_CMD_ATT_SEND_DATA,
|
||||
BLE_CMD_REQ_CONN_PARAM_UPDATE,
|
||||
|
||||
BLE_CMD_SCAN_ENABLE,
|
||||
BLE_CMD_SCAN_PARAM,
|
||||
BLE_CMD_STACK_EXIT,
|
||||
BLE_CMD_CREATE_CONN,
|
||||
BLE_CMD_CREATE_CONN_CANCEL,
|
||||
BLE_CMD_ADV_PARAM_EXT,
|
||||
BLE_CMD_SEND_TEST_KEY_NUM,
|
||||
//client
|
||||
BLE_CMD_SEARCH_PROFILE = 0x80,
|
||||
BLE_CMD_WRITE_CCC,
|
||||
} ble_cmd_type_e;
|
||||
|
||||
typedef enum {
|
||||
BLE_CMD_RET_SUCESS = 0, //
|
||||
BLE_CMD_RET_BUSY = -100, //
|
||||
BLE_CMD_PARAM_OVERFLOW, //
|
||||
BLE_CMD_OPT_FAIL, //
|
||||
BLE_BUFFER_FULL, //
|
||||
BLE_BUFFER_ERROR, //
|
||||
BLE_CMD_PARAM_ERROR, //
|
||||
BLE_CMD_STACK_NOT_RUN,
|
||||
} ble_cmd_ret_e;
|
||||
|
||||
//--------------------------------------------
|
||||
enum {
|
||||
ATT_OP_AUTO_READ_CCC = 0,
|
||||
ATT_OP_NOTIFY = 1,
|
||||
ATT_OP_INDICATE = 2,
|
||||
ATT_OP_READ,
|
||||
ATT_OP_READ_LONG,
|
||||
ATT_OP_WRITE,
|
||||
ATT_OP_WRITE_WITHOUT_RESPOND,
|
||||
//add here
|
||||
|
||||
ATT_OP_CMD_MAX = 15,
|
||||
};
|
||||
extern ble_cmd_ret_e ble_user_cmd_prepare(ble_cmd_type_e cmd, int argc, ...);
|
||||
|
||||
struct conn_update_param_t {
|
||||
u16 interval_min;
|
||||
u16 interval_max;
|
||||
u16 latency;
|
||||
u16 timeout;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
PFL_SERVER_UUID16 = 1,
|
||||
PFL_SERVER_UUID128,
|
||||
PFL_SERVER_ALL,
|
||||
} search_profile_type_e;
|
||||
|
||||
//------
|
||||
typedef struct {
|
||||
uint16_t start_group_handle;
|
||||
uint16_t end_group_handle;
|
||||
uint16_t uuid16;
|
||||
uint8_t uuid128[16];
|
||||
} service_report_t; //==le_service_t
|
||||
|
||||
typedef struct {
|
||||
uint16_t start_handle;
|
||||
uint16_t value_handle;
|
||||
uint16_t end_handle;
|
||||
uint16_t properties;
|
||||
uint16_t uuid16;
|
||||
uint8_t uuid128[16];
|
||||
} charact_report_t; //==le_characteristic_t
|
||||
|
||||
|
||||
typedef struct {
|
||||
service_report_t services;
|
||||
charact_report_t characteristic;
|
||||
u16 service_index;
|
||||
u16 characteristic_index;
|
||||
} search_result_t;
|
||||
|
||||
//------
|
||||
struct create_conn_param_t {
|
||||
u16 conn_interval;
|
||||
u16 conn_latency;
|
||||
u16 supervision_timeout;
|
||||
u8 peer_address_type;
|
||||
u8 peer_address[6];
|
||||
} _GNU_PACKED_;
|
||||
|
||||
typedef struct {
|
||||
u8 event_type;
|
||||
u8 address_type;
|
||||
u8 address[6];
|
||||
u8 reserve;
|
||||
u8 length;
|
||||
u8 data[0];
|
||||
} adv_report_t;
|
||||
|
||||
typedef struct {
|
||||
u16 packet_type;
|
||||
u16 value_handle;
|
||||
u16 value_offset;
|
||||
u16 blob_length;
|
||||
u8 *blob;
|
||||
} att_data_report_t;
|
||||
|
||||
|
||||
|
||||
//---------------
|
||||
void ble_set_gap_role(u8 role);
|
||||
void att_ccc_config_init(void);
|
||||
void att_set_ccc_config(uint16_t handle, uint16_t cfg);
|
||||
uint16_t att_get_ccc_config(uint16_t handle);
|
||||
void user_client_init(u16 handle, u8 *buffer, u16 buffer_size);
|
||||
#endif
|
||||
@@ -0,0 +1,541 @@
|
||||
#ifndef _BLUETOOTH_H_
|
||||
#define _BLUETOOTH_H_
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
//LE
|
||||
|
||||
#define ISO_SDU_DTAT_LENGTH 0x032c //812byte
|
||||
#define ISO_PDU_DTAT_LENGTH 251 //251byte
|
||||
#define ISO_PDU_INTERVAL_M_S 0x4e20 //20ms
|
||||
#define ISO_PDU_INTERVAL_S_M 0x4e20 //20ms
|
||||
#define HCI_ISO_DATA_PACKET 0x05
|
||||
|
||||
#define HCI_COMMAND_DATA_PACKET 0x01
|
||||
#define HCI_ACL_DATA_PACKET 0x02
|
||||
#define HCI_SCO_DATA_PACKET 0x03
|
||||
#define HCI_EVENT_PACKET 0x04
|
||||
|
||||
// OGFs
|
||||
#define OGF_LINK_CONTROL 0x01
|
||||
#define OGF_LINK_POLICY 0x02
|
||||
#define OGF_CONTROLLER_BASEBAND 0x03
|
||||
#define OGF_INFORMATIONAL_PARAMETERS 0x04
|
||||
#define OGF_STATUS_PARAMETERS 0x05
|
||||
#define OGF_TESTING 0x06
|
||||
#define OGF_LE_CONTROLLER 0x08
|
||||
#define OGF_VENDOR_LE_CONTROLLER 0x3e
|
||||
#define OGF_VENDOR 0x3f
|
||||
|
||||
|
||||
// Events from host controller to host
|
||||
|
||||
/**
|
||||
* @format 1
|
||||
* @param status
|
||||
*/
|
||||
#define HCI_EVENT_INQUIRY_COMPLETE 0x01
|
||||
|
||||
/**
|
||||
* @format 1B11132
|
||||
* @param num_responses
|
||||
* @param bd_addr
|
||||
* @param page_scan_repetition_mode
|
||||
* @param reserved1
|
||||
* @param reserved2
|
||||
* @param class_of_device
|
||||
* @param clock_offset
|
||||
*/
|
||||
#define HCI_EVENT_INQUIRY_RESULT 0x02
|
||||
|
||||
/**
|
||||
* @format 12B11
|
||||
* @param status
|
||||
* @param connection_handle
|
||||
* @param bd_addr
|
||||
* @param link_type
|
||||
* @param encryption_enabled
|
||||
*/
|
||||
#define HCI_EVENT_CONNECTION_COMPLETE 0x03
|
||||
/**
|
||||
* @format B31
|
||||
* @param bd_addr
|
||||
* @param class_of_device
|
||||
* @param link_type
|
||||
*/
|
||||
#define HCI_EVENT_CONNECTION_REQUEST 0x04
|
||||
/**
|
||||
* @format 121
|
||||
* @param status
|
||||
* @param connection_handle
|
||||
* @param reason
|
||||
*/
|
||||
#define HCI_EVENT_DISCONNECTION_COMPLETE 0x05
|
||||
/**
|
||||
* @format 12
|
||||
* @param status
|
||||
* @param connection_handle
|
||||
*/
|
||||
#define HCI_EVENT_AUTHENTICATION_COMPLETE 0x06
|
||||
/**
|
||||
* @format 1BN
|
||||
* @param status
|
||||
* @param bd_addr
|
||||
* @param remote_name
|
||||
*/
|
||||
#define HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE 0x07
|
||||
/**
|
||||
* @format 121
|
||||
* @param status
|
||||
* @param connection_handle
|
||||
* @param encryption_enabled
|
||||
*/
|
||||
#define HCI_EVENT_ENCRYPTION_CHANGE 0x08
|
||||
/**
|
||||
* @format 12
|
||||
* @param status
|
||||
* @param connection_handle
|
||||
*/
|
||||
#define HCI_EVENT_CHANGE_CONNECTION_LINK_KEY_COMPLETE 0x09
|
||||
/**
|
||||
* @format 121
|
||||
* @param status
|
||||
* @param connection_handle
|
||||
* @param key_flag
|
||||
*/
|
||||
#define HCI_EVENT_MASTER_LINK_KEY_COMPLETE 0x0A
|
||||
|
||||
#define HCI_EVENT_READ_REMOTE_SUPPORTED_FEATURES_COMPLETE 0x0B
|
||||
|
||||
#define HCI_EVENT_READ_REMOTE_VERSION_INFORMATION_COMPLETE 0x0C
|
||||
|
||||
#define HCI_EVENT_QOS_SETUP_COMPLETE 0x0D
|
||||
|
||||
/**
|
||||
* @format 12R
|
||||
* @param num_hci_command_packets
|
||||
* @param command_opcode
|
||||
* @param return_parameters
|
||||
*/
|
||||
#define HCI_EVENT_COMMAND_COMPLETE 0x0E
|
||||
/**
|
||||
* @format 112
|
||||
* @param status
|
||||
* @param num_hci_command_packets
|
||||
* @param command_opcode
|
||||
*/
|
||||
#define HCI_EVENT_COMMAND_STATUS 0x0F
|
||||
|
||||
/**
|
||||
* @format 1
|
||||
* @param hardware_code
|
||||
*/
|
||||
#define HCI_EVENT_HARDWARE_ERROR 0x10
|
||||
|
||||
#define HCI_EVENT_FLUSH_OCCURRED 0x11
|
||||
|
||||
/**
|
||||
* @format 1B1
|
||||
* @param status
|
||||
* @param bd_addr
|
||||
* @param role
|
||||
*/
|
||||
#define HCI_EVENT_ROLE_CHANGE 0x12
|
||||
|
||||
// TODO: number_of_handles 1, connection_handle[H*i], hc_num_of_completed_packets[2*i]
|
||||
#define HCI_EVENT_NUMBER_OF_COMPLETED_PACKETS 0x13
|
||||
|
||||
/**
|
||||
* @format 1H12
|
||||
* @param status
|
||||
* @param handle
|
||||
* @param mode
|
||||
* @param interval
|
||||
*/
|
||||
#define HCI_EVENT_MODE_CHANGE_EVENT 0x14
|
||||
|
||||
// TODO: num_keys, bd_addr[B*i], link_key[16 octets * i]
|
||||
#define HCI_EVENT_RETURN_LINK_KEYS 0x15
|
||||
|
||||
/**
|
||||
* @format B
|
||||
* @param bd_addr
|
||||
*/
|
||||
#define HCI_EVENT_PIN_CODE_REQUEST 0x16
|
||||
|
||||
/**
|
||||
* @format B
|
||||
* @param bd_addr
|
||||
*/
|
||||
#define HCI_EVENT_LINK_KEY_REQUEST 0x17
|
||||
|
||||
// TODO: bd_addr B, link_key 16octets, key_type 1
|
||||
#define HCI_EVENT_LINK_KEY_NOTIFICATION 0x18
|
||||
|
||||
/**
|
||||
* @format 1
|
||||
* @param link_type
|
||||
*/
|
||||
#define HCI_EVENT_DATA_BUFFER_OVERFLOW 0x1A
|
||||
|
||||
/**
|
||||
* @format H1
|
||||
* @param handle
|
||||
* @param lmp_max_slots
|
||||
*/
|
||||
#define HCI_EVENT_MAX_SLOTS_CHANGED 0x1B
|
||||
|
||||
/**
|
||||
* @format 1H2
|
||||
* @param status
|
||||
* @param handle
|
||||
* @param clock_offset
|
||||
*/
|
||||
#define HCI_EVENT_READ_CLOCK_OFFSET_COMPLETE 0x1C
|
||||
|
||||
/**
|
||||
* @format 1H2
|
||||
* @param status
|
||||
* @param handle
|
||||
* @param packet_types
|
||||
* @pnote packet_type is in plural to avoid clash with Java binding Packet.getPacketType()
|
||||
*/
|
||||
#define HCI_EVENT_CONNECTION_PACKET_TYPE_CHANGED 0x1D
|
||||
|
||||
#define HCI_EVENT_PAGE_SCAN_REPETITION_MODE_CHANGE 0x20
|
||||
/**
|
||||
* @format 1B11321
|
||||
* @param num_responses
|
||||
* @param bd_addr
|
||||
* @param page_scan_repetition_mode
|
||||
* @param reserved
|
||||
* @param class_of_device
|
||||
* @param clock_offset
|
||||
* @param rssi
|
||||
*/
|
||||
#define HCI_EVENT_INQUIRY_RESULT_WITH_RSSI 0x22
|
||||
|
||||
#define HCI_EVENT_READ_REMOTE_EXTERNED_FEATURES_COMPLETE 0x23
|
||||
/**
|
||||
* @format 1HB111221
|
||||
* @param status
|
||||
* @param handle
|
||||
* @param bd_addr
|
||||
* @param link_type
|
||||
* @param transmission_interval
|
||||
* @param retransmission_interval
|
||||
* @param rx_packet_length
|
||||
* @param tx_packet_length
|
||||
* @param air_mode
|
||||
*/
|
||||
#define HCI_EVENT_SYNCHRONOUS_CONNECTION_COMPLETE 0x2C
|
||||
|
||||
// TODO: serialize extended_inquiry_response and provide parser
|
||||
/**
|
||||
* @format 1B11321
|
||||
* @param num_responses
|
||||
* @param bd_addr
|
||||
* @param page_scan_repetition_mode
|
||||
* @param reserved
|
||||
* @param class_of_device
|
||||
* @param clock_offset
|
||||
* @param rssi
|
||||
*/
|
||||
#define HCI_EVENT_EXTENDED_INQUIRY_RESPONSE 0x2F
|
||||
#define HCI_EVENT_EXTENDED_INQUIRY_RESULT 0x2F
|
||||
|
||||
/**
|
||||
* @format 1H
|
||||
* @param status
|
||||
* @param handle
|
||||
*/
|
||||
#define HCI_EVENT_ENCRYPTION_KEY_REFRESH_COMPLETE 0x30
|
||||
|
||||
#define HCI_EVENT_IO_CAPABILITY_REQUEST 0x31
|
||||
#define HCI_EVENT_IO_CAPABILITY_RESPONSE 0x32
|
||||
|
||||
/**
|
||||
* @format B4
|
||||
* @param bd_addr
|
||||
* @param numeric_value
|
||||
*/
|
||||
#define HCI_EVENT_USER_CONFIRMATION_REQUEST 0x33
|
||||
|
||||
/**
|
||||
* @format B
|
||||
* @param bd_addr
|
||||
*/
|
||||
#define HCI_EVENT_USER_PASSKEY_REQUEST 0x34
|
||||
|
||||
/**
|
||||
* @format B
|
||||
* @param bd_addr
|
||||
*/
|
||||
#define HCI_EVENT_REMOTE_OOB_DATA_REQUEST 0x35
|
||||
|
||||
/**
|
||||
* @format 1B
|
||||
* @param status
|
||||
* @param bd_addr
|
||||
*/
|
||||
#define HCI_EVENT_SIMPLE_PAIRING_COMPLETE 0x36
|
||||
#define HCI_EVENT_LINK_SUPPERVISION_TIMEOUT_CHANGE_EVENT 0x38
|
||||
|
||||
#define HCI_EVENT_USER_PRESSKEY_NOTIFICATION 0x3B
|
||||
#define HCI_EVENT_REMOTE_KEYPRESS_NOTIFICATION 0x3C
|
||||
#define HCI_EVENT_REMOTE_SUPPORTED_FEATURES_NOTIFICATION 0x3D
|
||||
#define HCI_EVENT_LE_META 0x3E
|
||||
|
||||
// last used HCI_EVENT in 2.1 is 0x3d
|
||||
// last used HCI_EVENT in 4.1 is 0x57
|
||||
|
||||
#define HCI_EVENT_VENDOR_SETUP_COMPLETE 0xF9
|
||||
#define HCI_EVENT_VENDOR_DUT 0xFA
|
||||
#define HCI_EVENT_VENDOR_OSC_INTERNAL 0xFB
|
||||
#define HCI_EVENT_VENDOR_FAST_TEST 0xFC
|
||||
#define HCI_EVENT_VENDOR_REMOTE_UPDATE 0xFD
|
||||
#define HCI_EVENT_VENDOR_REMOTE_TEST 0xFE
|
||||
#define HCI_EVENT_VENDOR_SPECIFIC 0xFF
|
||||
|
||||
/**
|
||||
* @format 11H11B2221
|
||||
* @param subevent_code
|
||||
* @param status
|
||||
* @param connection_handle
|
||||
* @param role
|
||||
* @param peer_address_type
|
||||
* @param peer_address
|
||||
* @param conn_interval
|
||||
* @param conn_latency
|
||||
* @param supervision_timeout
|
||||
* @param master_clock_accuracy
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_CONNECTION_COMPLETE 0x01
|
||||
|
||||
// array of advertisements, not handled by event accessor generator
|
||||
#define HCI_SUBEVENT_LE_ADVERTISING_REPORT 0x02
|
||||
|
||||
/**
|
||||
* @format 11H222
|
||||
* @param subevent_code
|
||||
* @param status
|
||||
* @param connection_handle
|
||||
* @param conn_interval
|
||||
* @param conn_latency
|
||||
* @param supervision_timeout
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE 0x03
|
||||
|
||||
/**
|
||||
* @format 1HD2
|
||||
* @param subevent_code
|
||||
* @param connection_handle
|
||||
* @param random_number
|
||||
* @param encryption_diversifier
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_READ_REMOTE_USED_FEATURES_COMPLETE 0x04
|
||||
|
||||
/**
|
||||
* @format 1HD2
|
||||
* @param subevent_code
|
||||
* @param connection_handle
|
||||
* @param random_number
|
||||
* @param encryption_diversifier
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_LONG_TERM_KEY_REQUEST 0x05
|
||||
|
||||
/**
|
||||
* @format 1H2222
|
||||
* @param subevent_code
|
||||
* @param connection_handle
|
||||
* @param interval_min
|
||||
* @param interval_max
|
||||
* @param latency
|
||||
* @param timeout
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_REMOTE_CONNECTION_PARAMETER_REQUEST 0x06
|
||||
|
||||
/**
|
||||
* @format 1H2222
|
||||
* @param subevent_code
|
||||
* @param connection_handle
|
||||
* @param max_tx_octets
|
||||
* @param max_tx_time
|
||||
* @param max_rx_octets
|
||||
* @param max_rx_time
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_DATA_LENGTH_CHANGE 0x07
|
||||
|
||||
/**
|
||||
* @format 11QQ
|
||||
* @param subevent_code
|
||||
* @param status
|
||||
* @param dhkey_x x coordinate of P256 public key
|
||||
* @param dhkey_y y coordinate of P256 public key
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_READ_LOCAL_P256_PUBLIC_KEY_COMPLETE 0x08
|
||||
/**
|
||||
* @format 11Q
|
||||
* @param subevent_code
|
||||
* @param status
|
||||
* @param dhkey Diffie-Hellman key
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_GENERATE_DHKEY_COMPLETE 0x09
|
||||
|
||||
/**
|
||||
* @format 11H11BBB2221
|
||||
* @param subevent_code
|
||||
* @param status
|
||||
* @param connection_handle
|
||||
* @param role
|
||||
* @param peer_address_type
|
||||
* @param perr_addresss
|
||||
* @param local_resolvable_private_addres
|
||||
* @param peer_resolvable_private_addres
|
||||
* @param conn_interval
|
||||
* @param conn_latency
|
||||
* @param supervision_timeout
|
||||
* @param master_clock_accuracy
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_ENHANCED_CONNECTION_COMPLETE 0x0A
|
||||
|
||||
// array of advertisements, not handled by event accessor generator
|
||||
#define HCI_SUBEVENT_LE_DIRECT_ADVERTISING_REPORT 0x0B
|
||||
|
||||
/**
|
||||
* @format 11211
|
||||
* @param subevent_code
|
||||
* @param status
|
||||
* @param connection_handle
|
||||
* @param TX_PHY
|
||||
* @param RX_PHY
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_PHY_UPDATE_COMPLETE 0x0C
|
||||
|
||||
// array of advertisements, not handled by event accessor generator
|
||||
#define HCI_SUBEVENT_LE_EXTENDED_ADVERTISING_REPORT 0x0D
|
||||
|
||||
#define HCI_SUBEVENT_LE_PERIODIC_ADVERTISING_SYNC_ESTABLISHED 0x0E
|
||||
|
||||
/**
|
||||
* @format 1211111B
|
||||
* @param subevent_code
|
||||
* @param sync_handle
|
||||
* @param tx_power
|
||||
* @param rssi
|
||||
* @param unused
|
||||
* @param data_status
|
||||
* @param data_length
|
||||
* @param data
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_PERIODIC_ADVERTISING_REPORT 0x0F
|
||||
|
||||
/**
|
||||
* @format 2
|
||||
* @param sync_handle
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_PERIODIC_ADVERTISING_SYNC_LOST 0x10
|
||||
|
||||
/**
|
||||
* @format
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_SCAN_TIMEOUT 0x11
|
||||
|
||||
/**
|
||||
* @format 1121
|
||||
* @param subevent_code
|
||||
* @param status
|
||||
* @param advertising_handle
|
||||
* @param connection_handle
|
||||
* @param num_completed_extended_advertising_events
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_ADVERTISING_SET_TERMINATED 0x12
|
||||
|
||||
/**
|
||||
* @format 1116
|
||||
* @param subevent_code
|
||||
* @param advertising_handle
|
||||
* @param scanner_address_type
|
||||
* @param scanner_address
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_SCAN_REQUEST_RECEIVED 0x13
|
||||
|
||||
/**
|
||||
* @format 21
|
||||
* @param subevent_code
|
||||
* @param connection_handle
|
||||
* @param channel_selection_algorithm
|
||||
*/
|
||||
#define HCI_SUBEVENT_LE_CHANNEL_SELECTION_ALGORITHM 0x14
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* compact HCI Command packet description
|
||||
*/
|
||||
typedef struct {
|
||||
uint16_t opcode;
|
||||
const char *format;
|
||||
} hci_cmd_t;
|
||||
|
||||
int hci_send_cmd(const hci_cmd_t *cmd, ...);
|
||||
|
||||
|
||||
extern const hci_cmd_t hci_reset;
|
||||
extern const hci_cmd_t hci_read_bd_addr;
|
||||
extern const hci_cmd_t hci_read_local_supported_features;
|
||||
extern const hci_cmd_t hci_read_buffer_size;
|
||||
extern const hci_cmd_t hci_read_local_supported_commands;
|
||||
extern const hci_cmd_t hci_read_local_version_information;
|
||||
extern const hci_cmd_t hci_read_le_host_supported;
|
||||
extern const hci_cmd_t hci_read_local_name;
|
||||
extern const hci_cmd_t hci_write_class_of_device;
|
||||
extern const hci_cmd_t hci_write_local_name;
|
||||
extern const hci_cmd_t hci_write_scan_enable;
|
||||
extern const hci_cmd_t hci_set_event_mask;
|
||||
extern const hci_cmd_t hci_le_add_device_to_white_list;
|
||||
extern const hci_cmd_t hci_le_clear_white_list;
|
||||
extern const hci_cmd_t hci_le_connection_update;
|
||||
extern const hci_cmd_t hci_le_create_connection;
|
||||
extern const hci_cmd_t hci_le_create_connection_cancel;
|
||||
extern const hci_cmd_t hci_le_encrypt;
|
||||
extern const hci_cmd_t hci_le_generate_dhkey;
|
||||
extern const hci_cmd_t hci_le_long_term_key_negative_reply;
|
||||
extern const hci_cmd_t hci_le_long_term_key_request_reply;
|
||||
extern const hci_cmd_t hci_le_rand;
|
||||
extern const hci_cmd_t hci_le_read_advertising_channel_tx_power;
|
||||
extern const hci_cmd_t hci_le_read_buffer_size;
|
||||
extern const hci_cmd_t hci_le_read_channel_map;
|
||||
extern const hci_cmd_t hci_le_read_local_p256_public_key;
|
||||
extern const hci_cmd_t hci_le_read_maximum_data_length;
|
||||
extern const hci_cmd_t hci_le_read_remote_used_features;
|
||||
extern const hci_cmd_t hci_le_read_suggested_default_data_length;
|
||||
extern const hci_cmd_t hci_le_read_supported_features;
|
||||
extern const hci_cmd_t hci_le_read_supported_states;
|
||||
extern const hci_cmd_t hci_le_read_white_list_size;
|
||||
extern const hci_cmd_t hci_le_receiver_test;
|
||||
extern const hci_cmd_t hci_le_remove_device_from_white_list;
|
||||
extern const hci_cmd_t hci_le_set_advertise_enable;
|
||||
extern const hci_cmd_t hci_le_set_advertising_data;
|
||||
extern const hci_cmd_t hci_le_set_advertising_parameters;
|
||||
extern const hci_cmd_t hci_le_set_data_length;
|
||||
extern const hci_cmd_t hci_le_set_event_mask;
|
||||
extern const hci_cmd_t hci_le_set_host_channel_classification;
|
||||
extern const hci_cmd_t hci_le_set_random_address;
|
||||
extern const hci_cmd_t hci_le_set_scan_enable;
|
||||
extern const hci_cmd_t hci_le_set_scan_parameters;
|
||||
extern const hci_cmd_t hci_le_set_scan_response_data;
|
||||
extern const hci_cmd_t hci_le_start_encryption;
|
||||
extern const hci_cmd_t hci_le_test_end;
|
||||
extern const hci_cmd_t hci_le_transmitter_test;
|
||||
extern const hci_cmd_t hci_le_write_suggested_default_data_length;
|
||||
extern const hci_cmd_t hci_le_set_phy;
|
||||
|
||||
extern const hci_cmd_t hci_le_set_ext_advertising_parameters;
|
||||
extern const hci_cmd_t hci_le_set_ext_advertising_data;
|
||||
extern const hci_cmd_t hci_le_set_ext_advertise_enable;
|
||||
extern const hci_cmd_t hci_le_set_ext_scan_parameters;
|
||||
extern const hci_cmd_t hci_le_set_ext_scan_enable;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef BT_PROFILE_H
|
||||
#define BT_PROFILE_H
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define BT_BTSTACK_CLASSIC BIT(0)
|
||||
#define BT_BTSTACK_LE_ADV BIT(1)
|
||||
#define BT_BTSTACK_LE BIT(2)
|
||||
|
||||
extern const int config_stack_modules;
|
||||
#define STACK_MODULES_IS_SUPPORT(x) (config_stack_modules & (x))
|
||||
|
||||
|
||||
|
||||
extern u8 app_bredr_pool[];
|
||||
extern u8 app_le_pool[];
|
||||
extern u8 app_l2cap_pool[];
|
||||
extern u8 app_bredr_profile[];
|
||||
|
||||
extern u16 get_bredr_pool_len(void);
|
||||
extern u16 get_le_pool_len(void);
|
||||
extern u16 get_l2cap_stack_len(void);
|
||||
extern u16 get_profile_pool_len(void);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,250 @@
|
||||
|
||||
#ifndef _LE_USER_H_
|
||||
#define _LE_USER_H_
|
||||
|
||||
#if defined __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "btstack/ble_api.h"
|
||||
|
||||
|
||||
typedef void (*btstack_packet_handler_t)(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
typedef int (*sm_stack_packet_handler_t)(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||
|
||||
typedef void (*ble_cbk_handler_t)(void);
|
||||
|
||||
// Minimum/default MTU
|
||||
#define ATT_DEFAULT_MTU 23
|
||||
#define BT_NAME_LEN_MAX 29
|
||||
#define ADV_RSP_PACKET_MAX 31
|
||||
|
||||
// hci con handles (12 bit): 0x0000..0x0fff
|
||||
#define HCI_CON_HANDLE_INVALID 0xffff
|
||||
|
||||
#define BTSTACK_EVENT_STATE 0x60
|
||||
#define L2CAP_EVENT_CONNECTION_PARAMETER_UPDATE_RESPONSE 0x77
|
||||
|
||||
#define ATT_EVENT_MTU_EXCHANGE_COMPLETE 0xB5
|
||||
#define ATT_EVENT_HANDLE_VALUE_INDICATION_COMPLETE 0xB6
|
||||
#define ATT_EVENT_CAN_SEND_NOW 0xB7
|
||||
|
||||
#define SM_EVENT_JUST_WORKS_REQUEST 0xD0
|
||||
#define SM_EVENT_PASSKEY_DISPLAY_NUMBER 0xD2
|
||||
|
||||
|
||||
#define ATT_TRANSACTION_MODE_NONE 0x0
|
||||
#define ATT_TRANSACTION_MODE_ACTIVE 0x1
|
||||
#define ATT_TRANSACTION_MODE_EXECUTE 0x2
|
||||
#define ATT_TRANSACTION_MODE_CANCEL 0x3
|
||||
#define ATT_TRANSACTION_MODE_VALIDATE 0x4
|
||||
|
||||
#define GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NONE 0
|
||||
#define GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION 1
|
||||
#define GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION 2
|
||||
|
||||
#define ATT_PROPERTY_BROADCAST 0x01
|
||||
#define ATT_PROPERTY_READ 0x02
|
||||
#define ATT_PROPERTY_WRITE_WITHOUT_RESPONSE 0x04
|
||||
#define ATT_PROPERTY_WRITE 0x08
|
||||
#define ATT_PROPERTY_NOTIFY 0x10
|
||||
#define ATT_PROPERTY_INDICATE 0x20
|
||||
|
||||
|
||||
#define GATT_EVENT_NOTIFICATION 0xA7
|
||||
#define GATT_EVENT_INDICATION 0xA8
|
||||
#define GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT 0xA5
|
||||
#define GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT 0xA6
|
||||
// #define GATT_EVENT_SERVICE_QUERY_RESULT 0xA1
|
||||
// #define GATT_EVENT_CHARACTERISTIC_QUERY_RESULT 0xA2
|
||||
// #define GATT_EVENT_QUERY_COMPLETE 0xA0
|
||||
#define GAP_EVENT_ADVERTISING_REPORT 0xE2
|
||||
|
||||
// Authentication requirement flags
|
||||
#define SM_AUTHREQ_NO_BONDING 0x00
|
||||
#define SM_AUTHREQ_BONDING 0x01
|
||||
#define SM_AUTHREQ_MITM_PROTECTION 0x04
|
||||
#define SM_AUTHREQ_SECURE_CONNECTION 0x08
|
||||
#define SM_AUTHREQ_KEYPRESS 0x10
|
||||
|
||||
|
||||
#define L2CAP_EVENT_CONNECTION_PARAMETER_UPDATE_RESPONSE 0x77
|
||||
|
||||
|
||||
#define BT_OP_SUCCESS 0x00
|
||||
#define BT_ERR_ADVERTISING_TIMEOUT 0x3C
|
||||
|
||||
|
||||
//--------------------------------------------
|
||||
enum {
|
||||
HCI_STATE_OFF = 0,
|
||||
HCI_STATE_INITIALIZING,
|
||||
HCI_STATE_WORKING,
|
||||
HCI_STATE_HALTING,
|
||||
HCI_STATE_SLEEPING,
|
||||
HCI_STATE_FALLING_ASLEEP
|
||||
} ;
|
||||
|
||||
|
||||
// IO Capability Values
|
||||
typedef enum {
|
||||
IO_CAPABILITY_DISPLAY_ONLY = 0,
|
||||
IO_CAPABILITY_DISPLAY_YES_NO,
|
||||
IO_CAPABILITY_KEYBOARD_ONLY,
|
||||
IO_CAPABILITY_NO_INPUT_NO_OUTPUT,
|
||||
IO_CAPABILITY_KEYBOARD_DISPLAY, // not used by secure simple pairing
|
||||
} io_capability_t;
|
||||
|
||||
|
||||
struct ble_server_operation_t {
|
||||
int(*adv_enable)(void *priv, u32 enable);
|
||||
int(*disconnect)(void *priv);
|
||||
int(*get_buffer_vaild)(void *priv);
|
||||
int(*send_data)(void *priv, void *buf, u16 len);
|
||||
int(*regist_wakeup_send)(void *priv, void *cbk);
|
||||
int(*regist_recieve_cbk)(void *priv, void *cbk);
|
||||
int(*regist_state_cbk)(void *priv, void *cbk);
|
||||
int(*latency_enable)(void *priv, u32 enable);
|
||||
};
|
||||
void ble_get_server_operation_table(struct ble_server_operation_t **interface_pt);
|
||||
|
||||
|
||||
struct ble_client_operation_t {
|
||||
int(*scan_enable)(void *priv, u32 enable);
|
||||
int(*disconnect)(void *priv);
|
||||
int(*get_buffer_vaild)(void *priv);
|
||||
int(*write_data)(void *priv, void *buf, u16 len);
|
||||
int(*read_do)(void *priv);
|
||||
int(*regist_wakeup_send)(void *priv, void *cbk);
|
||||
int(*regist_recieve_cbk)(void *priv, void *cbk);
|
||||
int(*regist_state_cbk)(void *priv, void *cbk);
|
||||
};
|
||||
void ble_get_client_operation_table(struct ble_client_operation_t **interface_pt);
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
//base info
|
||||
uint8_t type; ///< See <btstack/hci_cmds.h> SM_...
|
||||
uint8_t size;
|
||||
hci_con_handle_t con_handle;
|
||||
uint8_t addr_type;
|
||||
uint8_t address[6];
|
||||
//extend info
|
||||
uint8_t data[4];
|
||||
} sm_just_event_t;
|
||||
|
||||
|
||||
static inline uint32_t ble_min(uint32_t a, uint32_t b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// ATT Client Read Callback for Dynamic Data
|
||||
// - if buffer == NULL, don't copy data, just return size of value
|
||||
// - if buffer != NULL, copy data and return number bytes copied
|
||||
// @param con_handle of hci le connection
|
||||
// @param attribute_handle to be read
|
||||
// @param offset defines start of attribute value
|
||||
// @param buffer
|
||||
// @param buffer_size
|
||||
typedef uint16_t (*att_read_callback_t)(uint16_t con_handle, uint16_t attribute_handle, uint16_t offset, uint8_t *buffer, uint16_t buffer_size);
|
||||
|
||||
// ATT Client Write Callback for Dynamic Data
|
||||
// @param con_handle of hci le connection
|
||||
// @param attribute_handle to be written
|
||||
// @param transaction - ATT_TRANSACTION_MODE_NONE for regular writes, ATT_TRANSACTION_MODE_ACTIVE for prepared writes and ATT_TRANSACTION_MODE_EXECUTE
|
||||
// @param offset into the value - used for queued writes and long attributes
|
||||
// @param buffer
|
||||
// @param buffer_size
|
||||
// @param signature used for signed write commmands
|
||||
// @returns 0 if write was ok, ATT_ERROR_PREPARE_QUEUE_FULL if no space in queue, ATT_ERROR_INVALID_OFFSET if offset is larger than max buffer
|
||||
typedef int (*att_write_callback_t)(uint16_t con_handle, uint16_t attribute_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size);
|
||||
|
||||
//----------------------------------------
|
||||
extern uint16_t little_endian_read_16(const uint8_t *buffer, int pos);
|
||||
extern uint32_t little_endian_read_24(const uint8_t *buffer, int pos);
|
||||
extern uint32_t little_endian_read_32(const uint8_t *buffer, int pos);
|
||||
|
||||
//----------------------------------------
|
||||
//--------------------------------------
|
||||
static inline hci_con_handle_t hci_subevent_le_connection_update_complete_get_connection_handle(const uint8_t *event)
|
||||
{
|
||||
return little_endian_read_16(event, 4);
|
||||
}
|
||||
|
||||
static inline uint16_t hci_subevent_le_connection_update_complete_get_conn_interval(const uint8_t *event)
|
||||
{
|
||||
return little_endian_read_16(event, 6);
|
||||
}
|
||||
static inline uint16_t hci_subevent_le_connection_update_complete_get_conn_latency(const uint8_t *event)
|
||||
{
|
||||
return little_endian_read_16(event, 8);
|
||||
}
|
||||
static inline uint16_t hci_subevent_le_connection_update_complete_get_supervision_timeout(const uint8_t *event)
|
||||
{
|
||||
return little_endian_read_16(event, 10);
|
||||
}
|
||||
|
||||
static inline uint8_t hci_event_packet_get_type(const uint8_t *event)
|
||||
{
|
||||
return event[0];
|
||||
}
|
||||
|
||||
static inline uint8_t hci_event_le_meta_get_subevent_code(const uint8_t *event)
|
||||
{
|
||||
return event[2];
|
||||
}
|
||||
static inline uint16_t att_event_mtu_exchange_complete_get_MTU(const uint8_t *event)
|
||||
{
|
||||
return little_endian_read_16(event, 4);
|
||||
}
|
||||
|
||||
static inline uint8_t btstack_event_state_get_state(const uint8_t *event)
|
||||
{
|
||||
return event[2];
|
||||
}
|
||||
|
||||
static inline uint16_t hci_event_disconnection_complete_get_connection_handle(const uint8_t *event)
|
||||
{
|
||||
return little_endian_read_16(event, 3);
|
||||
}
|
||||
|
||||
static inline hci_con_handle_t hci_subevent_le_connection_complete_get_connection_handle(const uint8_t *event)
|
||||
{
|
||||
return little_endian_read_16(event, 4);
|
||||
}
|
||||
|
||||
static inline uint16_t hci_subevent_le_connection_complete_get_conn_interval(const uint8_t *event)
|
||||
{
|
||||
return little_endian_read_16(event, 14);
|
||||
}
|
||||
|
||||
static inline hci_con_handle_t att_event_mtu_exchange_complete_get_handle(const uint8_t *event)
|
||||
{
|
||||
return little_endian_read_16(event, 2);
|
||||
}
|
||||
static inline hci_con_handle_t sm_event_just_works_request_get_handle(const uint8_t *event)
|
||||
{
|
||||
return little_endian_read_16(event, 2);
|
||||
}
|
||||
|
||||
|
||||
extern void ble_sm_setup_init(io_capability_t io_type, u8 auth_req, uint8_t min_key_size, u8 security_en);
|
||||
extern void sm_just_works_confirm(hci_con_handle_t con_handle);
|
||||
extern void sm_init(void);
|
||||
extern void sm_set_io_capabilities(io_capability_t io_capability);
|
||||
extern void sm_set_authentication_requirements(uint8_t auth_req);
|
||||
extern void sm_set_encryption_key_size_range(uint8_t min_size, uint8_t max_size);
|
||||
extern void sm_set_request_security(int enable);
|
||||
extern void sm_event_callback_set(void(*cbk_sm_ph)(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size));
|
||||
extern void att_server_init(uint8_t const *db, att_read_callback_t read_callback, att_write_callback_t write_callback);
|
||||
extern void att_server_register_packet_handler(btstack_packet_handler_t handler);
|
||||
extern void hci_event_callback_set(void(*cbk_ph)(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size));
|
||||
extern void ll_hci_connection_updata(u8 *data);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user