1 #ifndef __BLUETOOTH_BLE_CLIENT_H__ 2 #define __BLUETOOTH_BLE_CLIENT_H__ 3 4 #include <RkBtBase.h> 5 6 #ifdef __cplusplus 7 extern "C" { 8 #endif 9 10 #define DESCRIBE_BUG_LEN 50 11 #define UUID_BUF_LEN 40 12 #define PATH_BUF_LEN 70 13 #define MAX_ATTR_VAL_LEN 512 14 15 #define SERVICE_COUNT_MAX 10 16 #define CHRC_COUNT_MAX 20 17 #define DESC_COUNT_MAX 5 18 19 /* 20 * ATT attribute permission bitfield values. Permissions are grouped as 21 * "Access", "Encryption", "Authentication", and "Authorization". A bitmask of 22 * permissions is a byte that encodes a combination of these. 23 */ 24 #define BT_ATT_PERM_READ 0x01 25 #define BT_ATT_PERM_WRITE 0x02 26 #define BT_ATT_PERM_READ_ENCRYPT 0x04 27 #define BT_ATT_PERM_WRITE_ENCRYPT 0x08 28 #define BT_ATT_PERM_ENCRYPT (BT_ATT_PERM_READ_ENCRYPT | \ 29 BT_ATT_PERM_WRITE_ENCRYPT) 30 #define BT_ATT_PERM_READ_AUTHEN 0x10 31 #define BT_ATT_PERM_WRITE_AUTHEN 0x20 32 #define BT_ATT_PERM_AUTHEN (BT_ATT_PERM_READ_AUTHEN | \ 33 BT_ATT_PERM_WRITE_AUTHEN) 34 #define BT_ATT_PERM_AUTHOR 0x40 35 #define BT_ATT_PERM_NONE 0x80 36 #define BT_ATT_PERM_READ_SECURE 0x0100 37 #define BT_ATT_PERM_WRITE_SECURE 0x0200 38 #define BT_ATT_PERM_SECURE (BT_ATT_PERM_READ_SECURE | \ 39 BT_ATT_PERM_WRITE_SECURE) 40 41 /* GATT Characteristic Properties Bitfield values */ 42 #define BT_GATT_CHRC_PROP_BROADCAST 0x01 /* broadcast */ 43 #define BT_GATT_CHRC_PROP_READ 0x02 /* read */ 44 #define BT_GATT_CHRC_PROP_WRITE_WITHOUT_RESP 0x04 /* write-without-response */ 45 #define BT_GATT_CHRC_PROP_WRITE 0x08 /* write */ 46 #define BT_GATT_CHRC_PROP_NOTIFY 0x10 /* notify */ 47 #define BT_GATT_CHRC_PROP_INDICATE 0x20 /* indicate */ 48 #define BT_GATT_CHRC_PROP_AUTH 0x40 /* authenticated-signed-writes */ 49 #define BT_GATT_CHRC_PROP_EXT_PROP 0x80 /* extended-properties */ 50 51 /* GATT Characteristic Extended Properties Bitfield values */ 52 #define BT_GATT_CHRC_EXT_PROP_RELIABLE_WRITE 0x01 /* reliable-write */ 53 #define BT_GATT_CHRC_EXT_PROP_WRITABLE_AUX 0x02 /* writable-auxiliaries */ 54 #define BT_GATT_CHRC_EXT_PROP_ENC_READ 0x04 /* encrypt-read */ 55 #define BT_GATT_CHRC_EXT_PROP_ENC_WRITE 0x08 /* encrypt-write */ 56 #define BT_GATT_CHRC_EXT_PROP_ENC (BT_GATT_CHRC_EXT_PROP_ENC_READ | \ 57 BT_GATT_CHRC_EXT_PROP_ENC_WRITE) 58 #define BT_GATT_CHRC_EXT_PROP_AUTH_READ 0x10 /* encrypt-authenticated-read */ 59 #define BT_GATT_CHRC_EXT_PROP_AUTH_WRITE 0x20 /* encrypt-authenticated-write */ 60 #define BT_GATT_CHRC_EXT_PROP_AUTH (BT_GATT_CHRC_EXT_PROP_AUTH_READ | \ 61 BT_GATT_CHRC_EXT_PROP_AUTH_WRITE) 62 63 typedef enum { 64 RK_BLE_CLIENT_STATE_IDLE = 0, 65 RK_BLE_CLIENT_STATE_CONNECT, 66 RK_BLE_CLIENT_STATE_DISCONNECT, 67 RK_BLE_CLIENT_WRITE_SUCCESS, 68 RK_BLE_CLIENT_WRITE_ERROR, 69 } RK_BLE_CLIENT_STATE; 70 71 typedef struct { 72 char describe[DESCRIBE_BUG_LEN]; 73 char path[PATH_BUF_LEN]; 74 char uuid[UUID_BUF_LEN]; 75 } RK_BLE_CLIENT_DESC; 76 77 typedef struct { 78 char describe[DESCRIBE_BUG_LEN]; 79 char path[PATH_BUF_LEN]; 80 char uuid[UUID_BUF_LEN]; 81 unsigned int props; 82 unsigned int ext_props; 83 unsigned int perm; 84 bool notifying; 85 int desc_cnt; 86 RK_BLE_CLIENT_DESC desc[DESC_COUNT_MAX]; 87 } RK_BLE_CLIENT_CHRC; 88 89 typedef struct { 90 char describe[DESCRIBE_BUG_LEN]; 91 char path[PATH_BUF_LEN]; 92 char uuid[UUID_BUF_LEN]; 93 int chrc_cnt; 94 RK_BLE_CLIENT_CHRC chrc[CHRC_COUNT_MAX]; 95 } RK_BLE_CLIENT_SERVICE; 96 97 typedef struct { 98 int service_cnt; 99 RK_BLE_CLIENT_SERVICE service[SERVICE_COUNT_MAX]; 100 } RK_BLE_CLIENT_SERVICE_INFO; 101 102 typedef void (*RK_BLE_CLIENT_STATE_CALLBACK)(const char *bd_addr, const char *name, RK_BLE_CLIENT_STATE state); 103 typedef void (*RK_BLE_CLIENT_RECV_CALLBACK)(const char *uuid, char *data, int len); 104 105 void rk_ble_client_register_state_callback(RK_BLE_CLIENT_STATE_CALLBACK cb); 106 void rk_ble_client_register_recv_callback(RK_BLE_CLIENT_RECV_CALLBACK cb); 107 void rk_ble_client_register_mtu_callback(RK_BT_MTU_CALLBACK cb); 108 int rk_ble_client_open(bool mtu_change); 109 void rk_ble_client_close(void); 110 RK_BLE_CLIENT_STATE rk_ble_client_get_state(); 111 int rk_ble_client_get_service_info(char *address, RK_BLE_CLIENT_SERVICE_INFO *info); 112 int rk_ble_client_write(const char *uuid, char *data, int data_len); 113 int rk_ble_client_read(const char *uuid); 114 int rk_ble_client_connect(char *address); 115 int rk_ble_client_disconnect(char *address); 116 bool rk_ble_client_is_notifying(const char *uuid); 117 118 //is_indicate: only for bsa 119 int rk_ble_client_notify(const char *uuid, bool is_indicate, bool enable); 120 121 //get broadcast of the remote device 122 int rk_ble_client_get_eir_data(char *address, char *eir_data, int len); 123 124 //only for bsa, hci le write suggested default data length(27 byte) 125 int rk_ble_client_default_data_length(); 126 127 #ifdef __cplusplus 128 } 129 #endif 130 131 #endif /* __BLUETOOTH_BLE_CLIENT_H__ */ 132