Mistake on this page?
Report an issue in GitHub or email us
attc_main.h
Go to the documentation of this file.
1 /*************************************************************************************************/
2 /*!
3  * \file
4  *
5  * \brief ATT client main module.
6  *
7  * Copyright (c) 2009-2019 Arm Ltd. All Rights Reserved.
8  *
9  * Copyright (c) 2019-2020 Packetcraft, Inc.
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 /*************************************************************************************************/
24 #ifndef ATTC_MAIN_H
25 #define ATTC_MAIN_H
26 
27 #include "wsf_queue.h"
28 #include "wsf_timer.h"
29 #include "wsf_assert.h"
30 #include "att_api.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /**************************************************************************************************
37  Macros
38 **************************************************************************************************/
39 
40 /* Buffer lengths for requests */
41 #define ATT_MTU_REQ_BUF_LEN (ATT_MTU_REQ_LEN + L2C_PAYLOAD_START)
42 #define ATT_FIND_INFO_REQ_BUF_LEN (ATT_FIND_INFO_REQ_LEN + L2C_PAYLOAD_START)
43 #define ATT_FIND_TYPE_REQ_BUF_LEN (ATT_FIND_TYPE_REQ_LEN + L2C_PAYLOAD_START)
44 #define ATT_READ_TYPE_REQ_BUF_LEN (ATT_READ_TYPE_REQ_LEN + L2C_PAYLOAD_START)
45 #define ATT_READ_REQ_BUF_LEN (ATT_READ_REQ_LEN + L2C_PAYLOAD_START)
46 #define ATT_READ_BLOB_REQ_BUF_LEN (ATT_READ_BLOB_REQ_LEN + L2C_PAYLOAD_START)
47 #define ATT_READ_MULT_REQ_BUF_LEN (ATT_READ_MULT_REQ_LEN + L2C_PAYLOAD_START)
48 #define ATT_READ_GROUP_TYPE_REQ_BUF_LEN (ATT_READ_GROUP_TYPE_REQ_LEN + L2C_PAYLOAD_START)
49 #define ATT_WRITE_REQ_BUF_LEN (ATT_WRITE_REQ_LEN + L2C_PAYLOAD_START)
50 #define ATT_WRITE_CMD_BUF_LEN (ATT_WRITE_CMD_LEN + L2C_PAYLOAD_START)
51 #define ATT_SIGNED_WRITE_CMD_BUF_LEN (ATT_SIGNED_WRITE_CMD_LEN + L2C_PAYLOAD_START)
52 #define ATT_PREP_WRITE_REQ_BUF_LEN (ATT_PREP_WRITE_REQ_LEN + L2C_PAYLOAD_START)
53 #define ATT_EXEC_WRITE_REQ_BUF_LEN (ATT_EXEC_WRITE_REQ_LEN + L2C_PAYLOAD_START)
54 #define ATT_READ_MULT_VAR_REQ_BUF_LEN (ATT_READ_MULT_VAR_REQ_LEN + L2C_PAYLOAD_START)
55 
56 /* values for 'continuing' flag */
57 #define ATTC_CONTINUING TRUE
58 #define ATTC_NOT_CONTINUING FALSE
59 
60 /**************************************************************************************************
61  Data Types
62 **************************************************************************************************/
63 
64 /* ATTC event handler messages */
65 enum
66 {
67  /* messages from API; note these match method values */
68  ATTC_MSG_API_NONE = ATTC_MSG_START,
69  ATTC_MSG_API_MTU = ATT_METHOD_MTU,
70  ATTC_MSG_API_FIND_INFO = ATT_METHOD_FIND_INFO,
71  ATTC_MSG_API_FIND_BY_TYPE_VALUE = ATT_METHOD_FIND_TYPE,
72  ATTC_MSG_API_READ_BY_TYPE = ATT_METHOD_READ_TYPE,
73  ATTC_MSG_API_READ = ATT_METHOD_READ,
74  ATTC_MSG_API_READ_LONG = ATT_METHOD_READ_BLOB,
75  ATTC_MSG_API_READ_MULTIPLE = ATT_METHOD_READ_MULTIPLE,
76  ATTC_MSG_API_READ_BY_GROUP_TYPE = ATT_METHOD_READ_GROUP_TYPE,
77  ATTC_MSG_API_WRITE = ATT_METHOD_WRITE,
78  ATTC_MSG_API_WRITE_CMD = ATT_METHOD_WRITE_CMD,
79  ATTC_MSG_API_PREP_WRITE = ATT_METHOD_PREPARE_WRITE,
80  ATTC_MSG_API_EXEC_WRITE = ATT_METHOD_EXECUTE_WRITE,
81  ATTC_MSG_API_READ_MULT_VAR = ATT_METHOD_READ_MULT_VAR,
82  ATTC_MSG_API_SIGNED_WRITE_CMD,
83  ATTC_MSG_CMAC_CMPL,
84  ATTC_MSG_API_CANCEL,
85  ATTC_MSG_REQ_TIMEOUT
86 };
87 
88 /*!
89  * Data buffer format for API request messages:
90  *
91  * | attcPktParam_t | ATT request data |
92  * | bytes 0 to 7 | bytes 8 - |
93  */
94 
95 /* Structure for API with offset parameter */
96 typedef struct
97 {
98  uint16_t len;
99  uint16_t offset;
101 
102 /* Structure for API with start and end handle parameters */
103 typedef struct
104 {
105  uint16_t len;
106  uint16_t startHandle;
107  uint16_t endHandle;
109 
110 /* Structure for API with offset and value parameters */
111 typedef struct
112 {
113  uint16_t len;
114  uint16_t offset;
115  uint8_t *pValue;
117 
118 /* union of API parameter types */
119 typedef union
120 {
121  uint16_t len;
126 
127 /* verify attcPktParam_t will work in data buffer format described above */
129 
130 /* API message structure */
131 typedef struct
132 {
133  wsfMsgHdr_t hdr;
134  attcPktParam_t *pPkt;
135  uint16_t handle;
136  uint8_t slot;
137 } attcApiMsg_t;
138 
139 /* union of API parameter types */
140 typedef union
141 {
142  uint16_t len;
147 
148 /* ATTC connection control block */
149 typedef struct
150 {
151  attCcb_t *pMainCcb; /* Pointer to ATT main CCB */
152  attcApiMsg_t outReq; /* Outstanding request waiting for response */
153  attcOutPktParam_t outReqParams; /* Parameters associated with outstanding request */
154  wsfTimer_t outReqTimer; /* Outstanding request timer */
155  uint8_t slot; /* ATT/EATT slot ID */
156  dmConnId_t connId; /* DM connection ID */
157  uint16_t pendWriteCmdHandle[ATT_NUM_SIMUL_WRITE_CMD]; /* Callback to app pending for this write cmd handle */
158 } attcCcb_t;
159 
160 /* Signed data callbacks */
161 typedef void (*attcSignMsgCback_t)(attcCcb_t *pCcb, attcApiMsg_t *pMsg);
162 typedef void (*attcCloseCback_t)(attcCcb_t *pCcb, uint8_t status);
163 
164 /* Signed data callback interface */
165 typedef struct
166 {
167  attcSignMsgCback_t msgCback; /* Message handling callback */
168  attcCloseCback_t closeCback; /* Connection close callback */
170 
171 /* Main control block of the ATTC subsystem */
172 typedef struct
173 {
174  attcCcb_t ccb[DM_CONN_MAX][ATT_BEARER_MAX];
175  attcApiMsg_t onDeck[DM_CONN_MAX]; /* API message "on deck" waiting to be sent */
176  attcSignFcnIf_t const *pSign;
177  bool_t autoCnf;
178 } attcCb_t;
179 
180 /* type for response processing functions */
181 typedef void (*attcProcRsp_t)(attcCcb_t *pCcb, uint16_t len, uint8_t *pPacket, attEvt_t *pEvt);
182 
183 /**************************************************************************************************
184  Global Variables
185 **************************************************************************************************/
186 
187 /* Control block */
188 extern attcCb_t attcCb;
189 
190 /**************************************************************************************************
191  Function Declarations
192 **************************************************************************************************/
193 
194 attcCcb_t *attcCcbByConnId(dmConnId_t connId, uint8_t slot);
195 attcCcb_t *attcCcbByHandle(uint16_t handle, uint8_t slot);
196 attcPktParam_t *attcPrepWriteAllocMsg(uint16_t bufLen);
197 void attcFreePkt(attcApiMsg_t *pMsg);
198 void attcExecCallback(dmConnId_t connId, uint8_t event, uint16_t handle, uint8_t status);
199 void attcReqClear(dmConnId_t connId, attcApiMsg_t *pMsg, uint8_t status);
200 bool_t attcPendWriteCmd(attcCcb_t *pCcb, uint16_t handle);
201 
202 void attcSetupReq(attcCcb_t *pCcb, attcApiMsg_t *pMsg);
203 void attcSendReq(attcCcb_t *pCcb);
204 void attcSendMsg(dmConnId_t connId, uint16_t handle, uint8_t msgId, attcPktParam_t *pPkt, bool_t continuing);
205 void attcMsgCback(attcApiMsg_t *pMsg);
206 void attcWriteCmdCallback(dmConnId_t connId, attcCcb_t *pCcb, uint8_t status);
207 
208 void attcProcRsp(attcCcb_t *pCcb, uint16_t len, uint8_t *pPacket);
209 void attcProcInd(attcCcb_t *pCcb, uint16_t len, uint8_t *pPacket);
210 
211 void attcProcErrRsp(attcCcb_t *pCcb, uint16_t len, uint8_t *pPacket, attEvt_t *pEvt);
212 void attcProcMtuRsp(attcCcb_t *pCcb, uint16_t len, uint8_t *pPacket, attEvt_t *pEvt);
213 void attcProcFindOrReadRsp(attcCcb_t *pCcb, uint16_t len, uint8_t *pPacket, attEvt_t *pEvt);
214 void attcProcFindByTypeRsp(attcCcb_t *pCcb, uint16_t len, uint8_t *pPacket, attEvt_t *pEvt);
215 void attcProcReadRsp(attcCcb_t *pCcb, uint16_t len, uint8_t *pPacket, attEvt_t *pEvt);
216 void attcProcReadLongRsp(attcCcb_t *pCcb, uint16_t len, uint8_t *pPacket, attEvt_t *pEvt);
217 void attcProcWriteRsp(attcCcb_t *pCcb, uint16_t len, uint8_t *pPacket, attEvt_t *pEvt);
218 void attcProcPrepWriteRsp(attcCcb_t *pCcb, uint16_t len, uint8_t *pPacket, attEvt_t *pEvt);
219 void attcProcReadMultVarRsp(attcCcb_t *pCcb, uint16_t len, uint8_t *pPacket, attEvt_t *pEvt);
220 void attcProcMultiVarNtf(attcCcb_t *pCcb, uint16_t len, uint8_t *pPacket);
221 
222 #ifdef __cplusplus
223 };
224 #endif
225 
226 #endif /* ATTC_MAIN_H */
uint8_t dmConnId_t
Connection identifier.
Definition: dm_api.h:588
ATT callback event.
Definition: att_api.h:184
WSF_CT_ASSERT(((int) LCTR_EXT_INIT_MSG_INITIATE_CANCEL==(int) LCTR_INIT_MSG_INITIATE_CANCEL))
LCTR_EXT_INIT_MSG_INITIATE_CANCEL and LCTR_INIT_MSG_INITIATE_CANCEL shall be aligned.
#define ATT_NUM_SIMUL_WRITE_CMD
Maximum number of simultaneous ATT write commands.
Definition: cfg_stack.h:154
#define L2C_PAYLOAD_START
Start of L2CAP payload in an HCI ACL packet buffer.
Definition: l2c_defs.h:52
Assert macro.
Timer structure.
Definition: wsf_timer.h:53
General purpose queue service.
#define DM_CONN_MAX
Maximum number of connections.
Definition: cfg_stack.h:81
Timer service.
Attribute protocol client and server API.
Common message structure passed to event handler.
Definition: wsf_os.h:106
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.