1 #ifndef GATTC_H_
2 #define GATTC_H_
3 
4 /**
5  ****************************************************************************************
6  * @addtogroup GATTC Generic Attribute Profile Controller
7  * @ingroup GATT
8  * @brief Generic Attribute Profile Controller.
9  *
10  * This GATT module is responsible for providing an API for all attribute related operations
11  * related to a BLE connection.
12  * It is responsible for all the service framework activities using the Attribute protocol
13  * for discovering services and for reading and writing characteristic values on a peer device.
14  * To achieve this, the GATT interfaces with @ref ATTC "ATTC" and the @ref ATTS "ATTS".
15  *
16  * @{
17  ****************************************************************************************
18  */
19 
20 /*
21  * INCLUDE FILES
22  ****************************************************************************************
23  */
24 /* kernel task */
25 #include "rwip_config.h"
26 #if (BLE_GATTC)
27 
28 #include "co_list.h"
29 
30 
31 /*
32  * DEFINES
33  ****************************************************************************************
34  */
35 
36 /// Operation type
37 enum gattc_op_type
38 {
39     #if (BLE_ATTS)
40     /// Operation used to Server Request operations
41     GATTC_OP_SERVER,
42     #endif // (BLE_ATTS)
43 
44     #if (BLE_ATTC)
45     /// Operation used to Client Request operations
46     GATTC_OP_CLIENT,
47     /// Service Discovery Procedure operation
48     GATTC_OP_SDP,
49     #endif // (BLE_ATTC)
50 
51     /// Max number of operations
52     GATTC_OP_MAX
53 };
54 
55 /*
56  * TYPES DEFINITIONS
57  ****************************************************************************************
58  */
59 
60 #if (BLE_ATTC)
61 /// Attribute Client environment variable requirements
62 struct attc_env
63 {
64     /// List of ATT message used to aggregate long value in a single buffer.
65     struct co_list rsp_list;
66     /// List that contains peer device event registration
67     struct co_list reg_evt;
68     /// List that contains data for service discovery
69     struct co_list sdp_data;
70 };
71 #endif // (BLE_ATTC)
72 
73 #if (BLE_ATTS)
74 /// Attribute server environment variables
75 struct atts_env
76 {
77     /// This is used to merge save all the prepare write request received ,
78     /// before receiving the execute or cancel or disconnection.
79     struct co_list             prep_wr_req_list;
80     /// This list is used to put any data in order to send a response to peer device
81     struct co_list             rsp;
82     /// This structure is used to store in cache latest attribute read value
83     struct gattc_read_cfm*     read_cache;
84     /// pointer to the PDU which is currently handled by ATTS
85     struct l2cc_pdu_recv_ind*  pdu;
86 };
87 #endif // (BLE_ATTS)
88 
89 /// GATT controller environment variable structure.
90 struct gattc_env_tag
91 {
92     /// Request operation Kernel message
93     void* operation[GATTC_OP_MAX];
94 
95     #if (BLE_ATTC)
96     struct attc_env client;
97     #endif // (BLE_ATTC)
98 
99     #if (BLE_ATTS)
100     struct atts_env server;
101     #endif // (BLE_ATTS)
102 
103     /// Current MTU Size
104     uint16_t mtu_size;
105 
106     /// A transaction timeout occurs, reject next attribute commands
107     bool     trans_timeout;
108 };
109 /*
110  * MACRO DEFINITIONS
111  ****************************************************************************************
112  */
113 
114 
115 /*
116  * FUNCTION DECLARATIONS
117  ****************************************************************************************
118  */
119 
120 
121 /**
122  ****************************************************************************************
123  * @brief Created link connection parameters (from bond data) has been set, connection
124  * ready to be used.
125  *
126  * @param[in] conidx     Connection Index
127  *
128  ****************************************************************************************
129  */
130 void gattc_con_enable(uint8_t conidx);
131 
132 
133 /**
134  ****************************************************************************************
135  * @brief Gets the negotiated MTU. This function gets the negotiated MTU.
136  *
137  * @param[in] idx   connection record index
138  *
139  * @return MTU negotiated
140  *
141  ****************************************************************************************
142  */
143 uint16_t gattc_get_mtu(uint8_t idx);
144 
145 /**
146  ****************************************************************************************
147  * @brief Sets the negotiated MTU This function stores the negotiated MTU.
148  *
149  * @param[in] idx   connection record index
150  * @param[in] mtu   negotiated MTU
151  *
152  * @return status   indicates if the MTU setting operation is successful
153  *
154  ****************************************************************************************
155  */
156 void gattc_set_mtu(uint8_t idx, uint16_t mtu);
157 
158 
159 
160 #endif /* (BLE_GATTC) */
161 
162 /// @} GATTC
163 #endif // GATTC_H_
164