| Airoha M0 BLE API 1.0.5.4

ble_att.h
1 /******************************************************************************
2 Copyright (c) Airoha 2016 - All rights reserved
3
4 FILE NAME
5 ble_att.h
6 DESCRIPTION
7 NOTES
8 ********************************************************************************/
9 #ifndef _ATT_H_
10 #define _ATT_H_
11
21 #include <stdint.h>
22
26 //ATT Error Code==============================================================
27 #define ATT_NOERR 0x00
28 #define ATT_ERR_INVALID_HANDLE 0x01
29 #define ATT_ERR_READ_NOT_PERMITTED 0x02
30 #define ATT_ERR_WRITE_NOT_PERMITTED 0x03
31 #define ATT_ERR_INVALID_PDU 0x04
32 #define ATT_ERR_INSUFFICIENT_AUTHEN 0x05
33 #define ATT_ERR_UNSUPPORTED_REQ 0x06
34 #define ATT_ERR_INVALID_OFFSET 0x07
35 #define ATT_ERR_INSUFFICIENT_AUTHOR 0x08
36 #define ATT_ERR_PREPARE_QUEUE_FULL 0x09
37 #define ATT_ERR_ATTR_NOT_FOUND 0x0A
38 #define ATT_ERR_ATTR_NOT_LONG 0x0B
39 #define ATT_ERR_INSUFFICIENT_KEY_SIZE 0x0C
40 #define ATT_ERR_INVALID_VALUE_LENGTH 0x0D
41 #define ATT_ERR_UNLIKELY 0x0E
42 #define ATT_ERR_INSUFFICIENT_ENCRYPT 0x0F
43 #define ATT_ERR_UNSUPPORTED_GRP_TYPE 0x10
44 #define ATT_ERR_INSUFFICIENT_RESOURCES 0x11
45 //reserved 0x12-0x7F
46
47 //end ATT Error Code==========================================================
48
52 typedef uint16_t att_handle;
53
54
58 typedef enum
59 {
60 UUID_16bit = 2,
61 UUID_128bit = 16,
62 }UUID_size;
63
64
65
66 typedef enum
67 {
68 CB_BEFORE_SENDING = 0x01,
69 CB_AFTER_WRITING = 0x02,
70 } ATT_CB_TYPE;
71
72 typedef enum {
73 ATT_R_PERMIT = 0x00, /* Always permitted, no restrictions*/
74 ATT_R_AUTHEN = 0x01, /* Authentication required */
75 ATT_R_AUTHOR = 0x02, /* Authorization required */
76 ATT_R_ENCRYPT = 0x04, /* Can only be accessed in encrypted link*/
77 ATT_R_BANNED = 0x08, /* Operation not permitted */
78
79 ATT_W_PERMIT = 0x00, /* Always permitted, no restrictions*/
80 ATT_W_AUTHEN = 0x10, /* Authentication required */
81 ATT_W_AUTHOR = 0x20, /* Authorization required */
82 ATT_W_ENCRYPT = 0x40, /* Can only be accessed in encrypted link*/
83 ATT_W_BANNED = 0x80, /* Operation not permitted */
84 } ATT_READ_WRITE_PERMISSION_ENUM;
85
86 #define A_RP_WP (ATT_R_PERMIT|ATT_W_PERMIT)
87 #define A_RP_WN (ATT_R_PERMIT|ATT_W_AUTHEN)
88 #define A_RP_WO (ATT_R_PERMIT|ATT_W_AUTHOR)
89 #define A_RP_WB (ATT_R_PERMIT|ATT_W_BANNED)
90
91 #define A_RN_WP (ATT_R_AUTHEN|ATT_W_PERMIT)
92 #define A_RN_WN (ATT_R_AUTHEN|ATT_W_AUTHEN)
93 #define A_RN_WO (ATT_R_AUTHEN|ATT_W_AUTHOR)
94 #define A_RN_WB (ATT_R_AUTHEN|ATT_W_BANNED)
95
96 #define A_RO_WP (ATT_R_AUTHOR|ATT_W_PERMIT)
97 #define A_RO_WN (ATT_R_AUTHOR|ATT_W_AUTHEN)
98 #define A_RO_WO (ATT_R_AUTHOR|ATT_W_AUTHOR)
99 #define A_RO_WB (ATT_R_AUTHOR|ATT_W_BANNED)
100
101 #define A_RB_WP (ATT_R_BANNED|ATT_W_PERMIT)
102 #define A_RB_WN (ATT_R_BANNED|ATT_W_AUTHEN)
103 #define A_RB_WO (ATT_R_BANNED|ATT_W_AUTHOR)
104 #define A_RB_WB (ATT_R_BANNED|ATT_W_BANNED)
105
111 typedef void (*ATTCB)(ATT_CB_TYPE type, uint8_t linkindex, uint16_t handle);
112
118 typedef void (*INDI_CB)(uint8_t link_index);
119
120
127 uint16_t BLE_att_get_attribute_length(att_handle handle);
128
136 bool BLE_att_set_attribute_length(att_handle handle, uint16_t new_length);
137
144 uint8_t * BLE_att_get_attribute_data_ptr(att_handle handle);
145
153 bool BLE_att_set_attribute_data_ptr(att_handle handle, uint8_t *new_data_ptr);
154
160 void BLE_att_set_default_mtu(uint16_t default_mtu);
161
162 /*
163 @brief Judge write operaion is finished.
164 @param linkidx link index
165 @param att_handle attribute handle
166 @return true: write is finished. false: some prepared write queued in system.
167 */
168 bool BLE_att_is_write_finished(uint8_t linkidx, uint8_t att_handle);
169
173 #endif
UUID_128bit
Definition: ble_att.h:61
BLE_att_set_attribute_data_ptr
bool BLE_att_set_attribute_data_ptr(att_handle handle, uint8_t *new_data_ptr)
set data pointer of attribute value
att_handle
uint16_t att_handle
attribute handle.
Definition: ble_att.h:52
UUID_16bit
Definition: ble_att.h:60
ATTCB
void(* ATTCB)(ATT_CB_TYPE type, uint8_t linkindex, uint16_t handle)
attribute value accessed call back function.
Definition: ble_att.h:111
BLE_att_set_attribute_length
bool BLE_att_set_attribute_length(att_handle handle, uint16_t new_length)
set current length of attribute value
BLE_att_get_attribute_data_ptr
uint8_t * BLE_att_get_attribute_data_ptr(att_handle handle)
get data pointer of attribute value
BLE_att_set_default_mtu
void BLE_att_set_default_mtu(uint16_t default_mtu)
Set default MTU.
BLE_att_get_attribute_length
uint16_t BLE_att_get_attribute_length(att_handle handle)
get current length of attribute value
INDI_CB
void(* INDI_CB)(uint8_t link_index)
characteristic value indication confirmed call back function.
Definition: ble_att.h:118
UUID_size
UUID_size
UUID size in bytes.
Definition: ble_att.h:58