This commit is contained in:
lmx
2025-10-29 13:10:02 +08:00
commit 49a07fa419
2284 changed files with 642060 additions and 0 deletions

View File

@ -0,0 +1,147 @@
/*********************************************************************************************
* Filename : att.h
* Description :
* Author : minxian
* Email : liminxian@zh-jieli.com
* Last modifiled : 2020-07-01 16:33
* Copyright:(c)JIELI 2011-2020 @ , All Rights Reserved.
*********************************************************************************************/
#ifndef _BT_ATT_H_
#define _BT_ATT_H_
#include "typedef.h"
#include "btstack/btstack_typedef.h"
#if defined __cplusplus
extern "C" {
#endif
// Minimum/default MTU
#define ATT_DEFAULT_MTU 23
#define ATT_EVENT_MTU_EXCHANGE_COMPLETE 0xB5
#define ATT_EVENT_HANDLE_VALUE_INDICATION_COMPLETE 0xB6
#define ATT_EVENT_CAN_SEND_NOW 0xB7
#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 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
typedef enum {
ATT_OP_AUTO_READ_CCC = 0, //server端 检查对方使能通知CCC来控制 notify or indicate发送
ATT_OP_NOTIFY = 1, //server端 默认notify方式发送不检查使能通知CCC (不需要对方回应答包,没有流控)
ATT_OP_INDICATE = 2, //server端 默认INDICATE方式发送不检查使能通知CCC (需要对方回应答包,有流控)
ATT_OP_READ, //client端 单次读, 用于获取<=MTU 的数据包 (需要对方回应答包,有流控)
ATT_OP_READ_LONG, //client端 多次读,用于支持获取>MTU 的数据包 (需要对方回应答包,有流控)
ATT_OP_WRITE, //client端 写发送 (需要对方回应答包,有流控)
ATT_OP_WRITE_WITHOUT_RESPOND,//client端 写发送 (不需要对方回应答包,没有流控)
//add here
ATT_OP_CMD_MAX = 15,
} att_op_type_e;
//------
typedef struct {
uint16_t start_group_handle;//
uint16_t end_group_handle;
uint16_t uuid16; //为0则是 uuid128
uint8_t uuid128[16];
} service_report_t; //==le_service_t
typedef struct {
uint16_t start_handle;
uint16_t value_handle; //属性操作handle
uint16_t end_handle;
uint16_t properties; //属性对应 ATT_PROPERTY_XXX
uint16_t uuid16; //为0则是 uuid128
uint8_t uuid128[16];
} charact_report_t; //==le_characteristic_t
typedef struct {
u16 packet_type; //数据包类型(notify,indicate,read_respone,...)
u16 value_handle; //属性操作handle
u16 value_offset; //包偏移
u16 blob_length; //包长度
u8 *blob; //包内容
u16 conn_handle; //连接handle
} att_data_report_t;
typedef struct {
service_report_t services;
charact_report_t characteristic;
u16 service_index;
u16 characteristic_index;
} search_result_t;
typedef struct {
u16 handle;//descriptor's handle
u16 uuid16;//为0则是 uuid128
u8 uuid128[16];
} charact_descriptor_t;
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 att_server_set_exchange_mtu(u16 con_handle);
void att_set_db(uint8_t const *db);//change profile_data
//多机接口
//初始化 CCC管理
void multi_att_ccc_config_init(void);
//设置CCC
void multi_att_set_ccc_config(uint16_t conn_handle, uint16_t att_handle, uint16_t cfg);
//获取CCC的值
uint16_t multi_att_get_ccc_config(uint16_t conn_handle, uint16_t att_handle);
//断开, 清链路CCC
int multi_att_clear_ccc_config(uint16_t conn_handle);
// 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);
void ble_att_server_setup_init(const u8 *profile_db, att_read_callback_t read_cbk, att_write_callback_t write_cbk);
void att_server_request_can_send_now_event(hci_con_handle_t con_handle);
int att_server_notify(hci_con_handle_t con_handle, uint16_t attribute_handle, uint8_t *value, uint16_t value_len);
int att_server_indicate(hci_con_handle_t con_handle, uint16_t attribute_handle, uint8_t *value, uint16_t value_len);
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);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,57 @@
/*********************************************************************************************
* Filename : bluetooth_data_types.h
* Description :
* Author :
*********************************************************************************************/
/**
*/
#ifndef __BLUETOOTH_DATA_TYPES_H
#define __BLUETOOTH_DATA_TYPES_H
#define BLUETOOTH_DATA_TYPE_FLAGS 0x01 // Flags
#define BLUETOOTH_DATA_TYPE_INCOMPLETE_LIST_OF_16_BIT_SERVICE_CLASS_UUIDS 0x02 // Incomplete List of 16-bit Service Class UUIDs
#define BLUETOOTH_DATA_TYPE_COMPLETE_LIST_OF_16_BIT_SERVICE_CLASS_UUIDS 0x03 // Complete List of 16-bit Service Class UUIDs
#define BLUETOOTH_DATA_TYPE_INCOMPLETE_LIST_OF_32_BIT_SERVICE_CLASS_UUIDS 0x04 // Incomplete List of 32-bit Service Class UUIDs
#define BLUETOOTH_DATA_TYPE_COMPLETE_LIST_OF_32_BIT_SERVICE_CLASS_UUIDS 0x05 // Complete List of 32-bit Service Class UUIDs
#define BLUETOOTH_DATA_TYPE_INCOMPLETE_LIST_OF_128_BIT_SERVICE_CLASS_UUIDS 0x06 // Incomplete List of 128-bit Service Class UUIDs
#define BLUETOOTH_DATA_TYPE_COMPLETE_LIST_OF_128_BIT_SERVICE_CLASS_UUIDS 0x07 // Complete List of 128-bit Service Class UUIDs
#define BLUETOOTH_DATA_TYPE_SHORTENED_LOCAL_NAME 0x08 // Shortened Local Name
#define BLUETOOTH_DATA_TYPE_COMPLETE_LOCAL_NAME 0x09 // Complete Local Name
#define BLUETOOTH_DATA_TYPE_TX_POWER_LEVEL 0x0A // Tx Power Level
#define BLUETOOTH_DATA_TYPE_CLASS_OF_DEVICE 0x0D // Class of Device
#define BLUETOOTH_DATA_TYPE_SIMPLE_PAIRING_HASH_C 0x0E // Simple Pairing Hash C
#define BLUETOOTH_DATA_TYPE_SIMPLE_PAIRING_HASH_C_192 0x0E // Simple Pairing Hash C-192
#define BLUETOOTH_DATA_TYPE_SIMPLE_PAIRING_RANDOMIZER_R 0x0F // Simple Pairing Randomizer R
#define BLUETOOTH_DATA_TYPE_SIMPLE_PAIRING_RANDOMIZER_R_192 0x0F // Simple Pairing Randomizer R-192
#define BLUETOOTH_DATA_TYPE_DEVICE_ID 0x10 // Device ID
#define BLUETOOTH_DATA_TYPE_SECURITY_MANAGER_TK_VALUE 0x10 // Security Manager TK Value
#define BLUETOOTH_DATA_TYPE_SECURITY_MANAGER_OUT_OF_BAND_FLAGS 0x11 // Security Manager Out of Band Flags
#define BLUETOOTH_DATA_TYPE_SLAVE_CONNECTION_INTERVAL_RANGE 0x12 // Slave Connection Interval Range
#define BLUETOOTH_DATA_TYPE_LIST_OF_16_BIT_SERVICE_SOLICITATION_UUIDS 0x14 // List of 16-bit Service Solicitation UUIDs
#define BLUETOOTH_DATA_TYPE_LIST_OF_32_BIT_SERVICE_SOLICITATION_UUIDS 0x1F // List of 32-bit Service Solicitation UUIDs
#define BLUETOOTH_DATA_TYPE_LIST_OF_128_BIT_SERVICE_SOLICITATION_UUIDS 0x15 // List of 128-bit Service Solicitation UUIDs
#define BLUETOOTH_DATA_TYPE_SERVICE_DATA 0x16 // Service Data
#define BLUETOOTH_DATA_TYPE_SERVICE_DATA_16_BIT_UUID 0x16 // Service Data - 16-bit UUID
#define BLUETOOTH_DATA_TYPE_SERVICE_DATA_32_BIT_UUID 0x20 // Service Data - 32-bit UUID
#define BLUETOOTH_DATA_TYPE_SERVICE_DATA_128_BIT_UUID 0x21 // Service Data - 128-bit UUID
#define BLUETOOTH_DATA_TYPE_LE_SECURE_CONNECTIONS_CONFIRMATION_VALUE 0x22 // LE Secure Connections Confirmation Value
#define BLUETOOTH_DATA_TYPE_LE_SECURE_CONNECTIONS_RANDOM_VALUE 0x23 // LE Secure Connections Random Value
#define BLUETOOTH_DATA_TYPE_URI 0x24 // URI
#define BLUETOOTH_DATA_TYPE_INDOOR_POSITIONING 0x25 // Indoor Positioning
#define BLUETOOTH_DATA_TYPE_TRANSPORT_DISCOVERY_DATA 0x26 // Transport Discovery Data
#define BLUETOOTH_DATA_TYPE_PUBLIC_TARGET_ADDRESS 0x17 // Public Target Address
#define BLUETOOTH_DATA_TYPE_RANDOM_TARGET_ADDRESS 0x18 // Random Target Address
#define BLUETOOTH_DATA_TYPE_APPEARANCE 0x19 // Appearance
#define BLUETOOTH_DATA_TYPE_ADVERTISING_INTERVAL 0x1A // Advertising Interval
#define BLUETOOTH_DATA_TYPE_LE_BLUETOOTH_DEVICE_ADDRESS 0x1B // LE Bluetooth Device Address
#define BLUETOOTH_DATA_TYPE_LE_ROLE 0x1C // LE Role
#define BLUETOOTH_DATA_TYPE_SIMPLE_PAIRING_HASH_C_256 0x1D // Simple Pairing Hash C-256
#define BLUETOOTH_DATA_TYPE_SIMPLE_PAIRING_RANDOMIZER_R_256 0x1E // Simple Pairing Randomizer R-256
#define BLUETOOTH_DATA_TYPE_3D_INFORMATION_DATA 0x3D // 3D Information Data
#define BLUETOOTH_DATA_TYPE_MANUFACTURER_SPECIFIC_DATA 0xFF // Manufacturer Specific Data
#endif

View File

@ -0,0 +1,58 @@
/*********************************************************************************************
* Filename : btstack_event.h
* Description :
* Author : Minxian
* Email : liminxian@zh-jieli.com
* Last modifiled : 2020-07-01 16:23
* Copyright:(c)JIELI 2011-2020 @ , All Rights Reserved.
*********************************************************************************************/
#ifndef __BT_GATT_H
#define __BT_GATT_H
#include "typedef.h"
typedef struct {
uint16_t start_group_handle;
uint16_t end_group_handle;
uint16_t uuid16;
uint8_t uuid128[16];
} le_service_t, gatt_client_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];
} le_characteristic_t, gatt_client_characteristic_t;
typedef struct {
uint16_t handle;
uint16_t uuid16;
uint8_t uuid128[16];
} gatt_client_characteristic_descriptor_t;
void gatt_client_deserialize_service(const uint8_t *packet, int offset, gatt_client_service_t *service);
void gatt_client_deserialize_characteristic(const uint8_t *packet, int offset, gatt_client_characteristic_t *characteristic);
void gatt_client_deserialize_characteristic_descriptor(const uint8_t *packet, int offset, gatt_client_characteristic_descriptor_t *descriptor);
uint8_t gatt_client_read_long_value_of_characteristic_using_value_handle_with_offset(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t characteristic_value_handle, uint16_t offset);
uint8_t gatt_client_read_value_of_characteristic_using_value_handle(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle);
uint8_t gatt_client_write_value_of_characteristic_without_response(hci_con_handle_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t *value);
uint8_t gatt_client_write_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t *data);
void gatt_client_request_can_send_now_event(hci_con_handle_t con_handle);
#endif

View File

@ -0,0 +1,201 @@
/*********************************************************************************************
* Filename : le_counter.h
* Description :
* Author : Bingquan
* Email : bingquan_cai@zh-jieli.com
* Last modifiled : 2017-01-17 15:17
* Copyright:(c)JIELI 2011-2016 @ , All Rights Reserved.
*********************************************************************************************/
#ifndef __LE_COMMON_DEFINE_H_
#define __LE_COMMON_DEFINE_H_
#include "typedef.h"
#include <stdint.h>
#include "btstack/bluetooth.h"
//--------------------------------------------
#define ADV_SET_1M_PHY 1
#define ADV_SET_2M_PHY 2
#define ADV_SET_CODED_PHY 3
#define SCAN_SET_1M_PHY BIT(0)
#define SCAN_SET_2M_PHY BIT(1)
#define SCAN_SET_CODED_PHY BIT(2)
#define INIT_SET_1M_PHY BIT(0)
#define INIT_SET_2M_PHY BIT(1)
#define INIT_SET_CODED_PHY BIT(2)
#define CONN_SET_1M_PHY BIT(0)
#define CONN_SET_2M_PHY BIT(1)
#define CONN_SET_CODED_PHY BIT(2)
#define CONN_SET_PHY_OPTIONS_NONE 0
#define CONN_SET_PHY_OPTIONS_S2 1
#define CONN_SET_PHY_OPTIONS_S8 2
struct conn_param_t {
u16 interval;
u16 latency;
u16 timeout;
};
// #define NOTIFY_TYPE 1
// #define INDICATION_TYPE 2
// Minimum/default MTU
#define ATT_CTRL_BLOCK_SIZE (188) //note: fixed,libs use
#define ATT_PACKET_HEAD_SIZE (6) //note: fixed,libs use
/*adv type*/
enum {
ADV_IND = 0, /*Connectable and scannable undirected advertising*/
ADV_DIRECT_IND, /*Connectable high duty cycle directed advertising */
ADV_SCAN_IND, /*Scannable undirected advertising*/
ADV_NONCONN_IND, /*Non connectable undirected advertising*/
ADV_DIRECT_IND_LOW, /*Connectable low duty cycle directed advertising*/
};
/*adv channel*/
#define ADV_CHANNEL_37 BIT(0)
#define ADV_CHANNEL_38 BIT(1)
#define ADV_CHANNEL_39 BIT(2)
#define ADV_CHANNEL_ALL (ADV_CHANNEL_37 | ADV_CHANNEL_38 | ADV_CHANNEL_39)
/*scan type*/
enum {
SCAN_PASSIVE = 0,
SCAN_ACTIVE,
};
/*advertising report,event type*/
#define EVENT_ADV_IND ADV_IND
#define EVENT_ADV_DIRECT_IND ADV_DIRECT_IND
#define EVENT_ADV_SCAN_IND ADV_SCAN_IND
#define EVENT_ADV_NONCONN_IND ADV_NONCONN_IND
#define EVENT_SCAN_RSP (4)
#define EVENT_DEFAULT_REPORT_BITMAP (0x1f)
/*flags*/
#define FLAGS_LIMITED_DISCOVERABLE_MODE BIT(0)
#define FLAGS_GENERAL_DISCOVERABLE_MODE BIT(1)
#define FLAGS_EDR_NOT_SUPPORTED BIT(2)
#define FLAGS_LE_AND_EDR_SAME_CONTROLLER BIT(3)
#define FLAGS_LE_AND_EDR_SAME_HOST BIT(4)
/*eir packet_type*/
typedef enum {
HCI_EIR_DATATYPE_FLAGS = 0x01,
HCI_EIR_DATATYPE_MORE_16BIT_SERVICE_UUIDS = 0x02,
HCI_EIR_DATATYPE_COMPLETE_16BIT_SERVICE_UUIDS = 0x03,
HCI_EIR_DATATYPE_MORE_32BIT_SERVICE_UUIDS = 0x04,
HCI_EIR_DATATYPE_COMPLETE_32BIT_SERVICE_UUIDS = 0x05,
HCI_EIR_DATATYPE_MORE_128BIT_SERVICE_UUIDS = 0x06,
HCI_EIR_DATATYPE_COMPLETE_128BIT_SERVICE_UUIDS = 0x07,
HCI_EIR_DATATYPE_SHORTENED_LOCAL_NAME = 0x08,
HCI_EIR_DATATYPE_COMPLETE_LOCAL_NAME = 0x09,
HCI_EIR_DATATYPE_TX_POWER_LEVEL = 0x0A,
HCI_EIR_DATATYPE_CLASS_OF_DEVICE = 0x0D,
HCI_EIR_DATATYPE_SIMPLE_PAIRING_HASH_C = 0x0E,
HCI_EIR_DATATYPE_SIMPLE_PAIRING_RANDOMIZER_R = 0x0F,
HCI_EIR_DATATYPE_SECURITY_MANAGER_TK_VALUE = 0x10,
HCI_EIR_DATATYPE_SECURITY_MANAGER_OOB_FLAGS = 0x11,
HCI_EIR_DATATYPE_SLAVE_CONNECTION_INTERVAL_RANGE = 0x12,
HCI_EIR_DATATYPE_16BIT_SERVICE_SOLICITATION_UUIDS = 0x14,
HCI_EIR_DATATYPE_128BIT_SERVICE_SOLICITATION_UUIDS = 0x15,
HCI_EIR_DATATYPE_SERVICE_DATA = 0x16,
HCI_EIR_DATATYPE_APPEARANCE_DATA = 0x19,
HCI_EIR_DATATYPE_MANUFACTURER_SPECIFIC_DATA = 0xFF
} HCI_EIR_datatype_t;
//按(长度 + 类型 + 内容)这样的格,组合填入广播包数据
static inline u8 make_eir_packet_data(u8 *buf, u16 offset, u8 data_type, u8 *data, u8 data_len)
{
if (ADV_RSP_PACKET_MAX - offset < data_len + 2) {
return offset + data_len + 2;
}
buf[0] = data_len + 1;
buf[1] = data_type;
memcpy(buf + 2, data, data_len);
return data_len + 2;
}
//按(长度 + 类型 + 内容)这样的格,组合填入广播包数据
static inline u8 make_eir_packet_val(u8 *buf, u16 offset, u8 data_type, u32 val, u8 val_size)
{
if (ADV_RSP_PACKET_MAX - offset < val_size + 2) {
return offset + val_size + 2;
}
buf[0] = val_size + 1;
buf[1] = data_type;
memcpy(buf + 2, &val, val_size);
return val_size + 2;
}
#define BLE_APPEARANCE_UNKNOWN 0 /**< Unknown. */
#define BLE_APPEARANCE_GENERIC_PHONE 64 /* Generic Phone. */
#define BLE_APPEARANCE_GENERIC_COMPUTER 128 /* Generic Computer. */
#define BLE_APPEARANCE_GENERIC_WATCH 192 /* Generic Watch. */
#define BLE_APPEARANCE_WATCH_SPORTS_WATCH 193 /* Watch: Sports Watch. */
#define BLE_APPEARANCE_GENERIC_CLOCK 256 /* Generic Clock. */
#define BLE_APPEARANCE_GENERIC_DISPLAY 320 /* Generic Display. */
#define BLE_APPEARANCE_GENERIC_REMOTE_CONTROL 384 /* Generic Remote Control. */
#define BLE_APPEARANCE_GENERIC_EYE_GLASSES 448 /* Generic Eye-glasses. */
#define BLE_APPEARANCE_GENERIC_TAG 512 /* Generic Tag. */
#define BLE_APPEARANCE_GENERIC_KEYRING 576 /* Generic Keyring. */
#define BLE_APPEARANCE_GENERIC_MEDIA_PLAYER 640 /* Generic Media Player. */
#define BLE_APPEARANCE_GENERIC_BARCODE_SCANNER 704 /* Generic Barcode Scanner. */
#define BLE_APPEARANCE_GENERIC_THERMOMETER 768 /* Generic Thermometer. */
#define BLE_APPEARANCE_THERMOMETER_EAR 769 /* Thermometer: Ear. */
#define BLE_APPEARANCE_GENERIC_HEART_RATE_SENSOR 832 /* Generic Heart rate Sensor. */
#define BLE_APPEARANCE_HEART_RATE_SENSOR_HEART_RATE_BELT 833 /* Heart Rate Sensor: Heart Rate Belt. */
#define BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE 896 /* Generic Blood Pressure. */
#define BLE_APPEARANCE_BLOOD_PRESSURE_ARM 897 /* Blood Pressure: Arm. */
#define BLE_APPEARANCE_BLOOD_PRESSURE_WRIST 898 /* Blood Pressure: Wrist. */
#define BLE_APPEARANCE_GENERIC_HID 960 /* Human Interface Device (HID). */
#define BLE_APPEARANCE_HID_KEYBOARD 961 /* Keyboard (HID Subtype). */
#define BLE_APPEARANCE_HID_MOUSE 962 /* Mouse (HID Subtype). */
#define BLE_APPEARANCE_HID_JOYSTICK 963 /* Joystick (HID Subtype). */
#define BLE_APPEARANCE_HID_GAMEPAD 964 /* Gamepad (HID Subtype). */
#define BLE_APPEARANCE_HID_DIGITIZERSUBTYPE 965 /* Digitizer Tablet (HID Subtype). */
#define BLE_APPEARANCE_HID_CARD_READER 966 /* Card Reader (HID Subtype). */
#define BLE_APPEARANCE_HID_DIGITAL_PEN 967 /* Digital Pen (HID Subtype). */
#define BLE_APPEARANCE_HID_BARCODE 968 /* Barcode Scanner (HID Subtype). */
#define BLE_APPEARANCE_GENERIC_GLUCOSE_METER 1024 /* Generic Glucose Meter. */
#define BLE_APPEARANCE_GENERIC_RUNNING_WALKING_SENSOR 1088 /* Generic Running Walking Sensor. */
#define BLE_APPEARANCE_RUNNING_WALKING_SENSOR_IN_SHOE 1089 /* Running Walking Sensor: In-Shoe. */
#define BLE_APPEARANCE_RUNNING_WALKING_SENSOR_ON_SHOE 1090 /* Running Walking Sensor: On-Shoe. */
#define BLE_APPEARANCE_RUNNING_WALKING_SENSOR_ON_HIP 1091 /* Running Walking Sensor: On-Hip. */
#define BLE_APPEARANCE_GENERIC_CYCLING 1152 /* Generic Cycling. */
#define BLE_APPEARANCE_CYCLING_CYCLING_COMPUTER 1153 /* Cycling: Cycling Computer. */
#define BLE_APPEARANCE_CYCLING_SPEED_SENSOR 1154 /* Cycling: Speed Sensor. */
#define BLE_APPEARANCE_CYCLING_CADENCE_SENSOR 1155 /* Cycling: Cadence Sensor. */
#define BLE_APPEARANCE_CYCLING_POWER_SENSOR 1156 /* Cycling: Power Sensor. */
#define BLE_APPEARANCE_CYCLING_SPEED_CADENCE_SENSOR 1157 /* Cycling: Speed and Cadence Sensor. */
#define BLE_APPEARANCE_GENERIC_PULSE_OXIMETER 3136 /* Generic Pulse Oximeter. */
#define BLE_APPEARANCE_PULSE_OXIMETER_FINGERTIP 3137 /* Fingertip (Pulse Oximeter subtype). */
#define BLE_APPEARANCE_PULSE_OXIMETER_WRIST_WORN 3138 /* Wrist Worn(Pulse Oximeter subtype). */
#define BLE_APPEARANCE_GENERIC_WEIGHT_SCALE 3200 /* Generic Weight Scale. */
#define BLE_APPEARANCE_GENERIC_OUTDOOR_SPORTS_ACT 5184 /* Generic Outdoor Sports Activity. */
#define BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_DISP 5185 /* Location Display Device (Outdoor Sports Activity subtype). */
#define BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_AND_NAV_DISP 5186 /* Location and Navigation Display Device (Outdoor Sports Activity subtype). */
#define BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_POD 5187 /* Location Pod (Outdoor Sports Activity subtype). */
#define BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_AND_NAV_POD 5188 /* Location and Navigation Pod (Outdoor Sports Activity subtype). */
extern void le_l2cap_register_packet_handler(void (*handler)(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size));
#endif

View File

@ -0,0 +1,140 @@
#ifndef _LE_USER_H_
#define _LE_USER_H_
#include "typedef.h"
#include "btstack/btstack_typedef.h"
#include "ble_api.h"
#if defined __cplusplus
extern "C" {
#endif
#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 SM_EVENT_NUMERIC_COMPARISON_REQUEST 0xD6
#define SM_EVENT_JUST_WORKS_REQUEST 0xD0
#define SM_EVENT_JUST_WORKS_CANCEL 0xD1
#define SM_EVENT_PASSKEY_DISPLAY_NUMBER 0xD2
#define SM_EVENT_PASSKEY_DISPLAY_CANCEL 0xD3
#define SM_EVENT_PASSKEY_INPUT_NUMBER 0xD4
#define SM_EVENT_PASSKEY_INPUT_CANCEL 0xD5
#define SM_EVENT_PAIR_PROCESS 0xDF
//0xdf 's sub
#define SM_EVENT_PAIR_SUB_RECONNECT_START 0x01
#define SM_EVENT_PAIR_SUB_PIN_KEY_MISS 0x02
#define SM_EVENT_PAIR_SUB_PAIR_FAIL 0x03
#define SM_EVENT_PAIR_SUB_PAIR_TIMEOUT 0x04
#define SM_EVENT_PAIR_SUB_ENCRYPTION_FAIL 0x05
#define SM_EVENT_PAIR_SUB_SEND_DISCONN 0x0f
#define SM_EVENT_PAIR_SUB_ADD_LIST_SUCCESS 0x10
#define SM_EVENT_PAIR_SUB_ADD_LIST_FAILED 0x11
#define GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NONE 0
#define GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION 1
#define GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION 2
#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 SM_AUTHREQ_CT2 0x20
#define L2CAP_EVENT_CONNECTION_PARAMETER_UPDATE_RESPONSE 0x77
#define BT_OP_SUCCESS 0x00
#define BT_ERR_ADVERTISING_TIMEOUT 0x3C
//--------------------------------------------
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);
int (*init_config)(void *priv, void *cfg);
int (*opt_comm_send)(u16 handle, u8 *data, u16 len, u8 att_op_type);
int (*set_force_search)(u8 onoff, s8 rssi);
int (*create_connect)(u8 *addr, u8 addr_type, u8 mode);
int (*create_connect_cannel)(void);
int (*get_work_state)(void);
int (*opt_comm_send_ext)(u16 conn_handle, u16 handle, u8 *data, u16 len, u8 att_op_type);
};
struct ble_client_operation_t *ble_get_client_operation_table(void);
static inline uint32_t ble_min(uint32_t a, uint32_t b)
{
return a < b ? a : b;
}
//---------------------------------------------------------------------------------------------------
//----------------------------------------
//----------------------------------------
extern int get_ble_btstack_state(void);
extern int get_indicate_state(void);
extern u8 get_ble_local_name(u8 *name_buf);
extern u8 get_ble_local_name_len();
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

View File

@ -0,0 +1,69 @@
/*********************************************************************************************
* Filename : sm.h
* Description :
* Author : Minxian
* Email : liminxian@zh-jieli.com
* Last modifiled : 2020-07-01 16:36
* Copyright:(c)JIELI 2011-2020 @ , All Rights Reserved.
*********************************************************************************************/
#ifndef _BT_SM_H_
#define _BT_SM_H_
#include "typedef.h"
// 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;
void ble_sm_setup_init(io_capability_t io_type, u8 auth_req, uint8_t min_key_size, u8 security_en);
void ble_cbk_handler_register(btstack_packet_handler_t packet_cbk, sm_stack_packet_handler_t sm_cbk);
void sm_just_works_confirm(hci_con_handle_t con_handle);
void sm_init(void);
/*接口同时设置master 和 slave的配置*/
void sm_set_io_capabilities(io_capability_t io_capability);
/*接口只设置master配置*/
void sm_set_master_io_capabilities(io_capability_t io_capability);
/*接口同时设置master 和 slave的配置*/
void sm_set_authentication_requirements(uint8_t auth_req);
/*接口只设置master配置*/
void sm_set_master_authentication_requirements(uint8_t auth_req);
void sm_set_encryption_key_size_range(uint8_t min_size, uint8_t max_size);
void sm_set_request_security(int enable);
void sm_event_callback_set(void(*cbk_sm_ph)(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size));
//配从机默认发请求加密命令
void sm_set_request_security(int enable);
//配主机默认发加密请求命令
void sm_set_master_request_pair(int enable);
//指定链接发加密请求命令
bool sm_api_request_pairing(hci_con_handle_t con_handle);
//设置回连出现key missing后,流程重新发起加密
void sm_set_master_pair_redo(int enable);
//设置回连时,延时发起加密流程的时间,可用于兼容一些设备连接
void sm_set_master_reconnect_enc_delay(u16 delay_ms);
void sm_passkey_input(hci_con_handle_t con_handle, uint32_t passkey);
#endif