Mistake on this page?
Report an issue in GitHub or email us
att_main.h
Go to the documentation of this file.
1 /*************************************************************************************************/
2 /*!
3  * \file
4  *
5  * \brief ATT 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 ATT_MAIN_H
25 #define ATT_MAIN_H
26 
27 #include "wsf_queue.h"
28 #include "wsf_timer.h"
29 #include "l2c_api.h"
30 #include "dm_api.h"
31 #include "att_api.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 /**************************************************************************************************
38  Macros
39 **************************************************************************************************/
40 
41 /* ATT protocol methods */
42 #define ATT_METHOD_ERR 0 /* Error response */
43 #define ATT_METHOD_MTU 1 /* Exchange mtu */
44 #define ATT_METHOD_FIND_INFO 2 /* Find information */
45 #define ATT_METHOD_FIND_TYPE 3 /* Find by type value */
46 #define ATT_METHOD_READ_TYPE 4 /* Read by type value */
47 #define ATT_METHOD_READ 5 /* Read */
48 #define ATT_METHOD_READ_BLOB 6 /* Read long */
49 #define ATT_METHOD_READ_MULTIPLE 7 /* Read multiple */
50 #define ATT_METHOD_READ_GROUP_TYPE 8 /* Read group type */
51 #define ATT_METHOD_WRITE 9 /* Write */
52 #define ATT_METHOD_WRITE_CMD 10 /* Write command */
53 #define ATT_METHOD_PREPARE_WRITE 11 /* Prepare write */
54 #define ATT_METHOD_EXECUTE_WRITE 12 /* Execute write */
55 #define ATT_METHOD_VALUE_NTF 13 /* Handle value notification */
56 #define ATT_METHOD_VALUE_IND 14 /* Handle value indication */
57 #define ATT_METHOD_VALUE_CNF 15 /* Handle value confirm */
58 #define ATT_METHOD_READ_MULT_VAR 16 /* Read multiple variable length */
59 #define ATT_METHOD_SIGNED_WRITE_CMD 17 /* Signed write command */
60 
61 /* Convert opcode to method */
62 #define ATT_OPCODE_2_METHOD(op) (((op) & ~ATT_PDU_MASK_SERVER) / 2)
63 
64 /* Client and server message macros */
65 #define ATTC_MSG_START 0x00
66 #define ATTS_MSG_START 0x20
67 #define EATTC_MSG_START 0x40
68 #define EATTS_MSG_START 0x60
69 #define EATT_MSG_START 0x80
70 
71 /* Buffer lengths for messages */
72 #define ATT_VALUE_IND_NTF_BUF_LEN (ATT_VALUE_NTF_LEN + L2C_PAYLOAD_START)
73 #define ATT_MULT_VALUE_NTF_BUF_LEN (ATT_PDU_MULT_VALUE_NTF_LEN + L2C_PAYLOAD_START)
74 
75 /* attCcb_t control bits */
76 #define ATT_CCB_STATUS_MTU_SENT (1<<0) /* MTU req or rsp sent */
77 #define ATT_CCB_STATUS_FLOW_DISABLED (1<<1) /* Data flow disabled */
78 #define ATT_CCB_STATUS_TX_TIMEOUT (1<<2) /* ATT transaction timed out */
79 #define ATT_CCB_STATUS_RSP_PENDING (1<<3) /* ATTS write rsp pending */
80 #define ATT_CCB_STATUS_CNF_PENDING (1<<4) /* ATTC confirm pending */
81 
82 /* Number of ATT bearers */
83 #define ATT_BEARER_MAX (EATT_CONN_CHAN_MAX + 1)
84 
85 /* Single ATT bearer slot ID */
86 #define ATT_BEARER_SLOT_ID 0
87 #define ATT_BEARER_SLOT_INVALID 0xff
88 
89 /**************************************************************************************************
90  Data Types
91 **************************************************************************************************/
92 
93 typedef struct
94 {
95  uint16_t startHandle; /* Start handle of the requested operation. Used if an Error Response is sent. */
96  uint16_t handle; /* Attribute handle of pending response. */
98 
99 /* Bearer slot control block */
100 typedef struct
101 {
102  uint16_t mtu; /* connection mtu */
103  uint8_t control; /* Control bitfield */
104 } attSccb_t;
105 
106 /* Connection control block */
107 typedef struct
108 {
109  attSccb_t sccb[ATT_BEARER_MAX]; /* Bearer slot control blocks */
110  uint16_t handle; /* connection handle */
111  dmConnId_t connId; /* DM connection ID */
112  attPendDbHashRsp_t *pPendDbHashRsp; /* Pending ATT Response information. */
113 } attCcb_t;
114 
115 /* ATT message handling function type */
116 typedef void (*attMsgHandler_t)(void *pMsg);
117 
118 /* ATT connection callback type */
119 typedef void (*attConnCback_t)(attCcb_t *pCcb, dmEvt_t *pDmEvt);
120 
121 /* EATT event hamdler callback type */
122 typedef void (*eattEventCback_t)(wsfMsgHdr_t *pMsg);
123 
124 /* EATT L2C COC data request function type */
125 typedef void (*eattL2cDataReq_t)(attCcb_t *pCcb, uint8_t slot, uint16_t len, uint8_t *pPacket);
126 
127 /* Callback interface for client and server */
128 typedef struct
129 {
130  l2cDataCback_t dataCback; /* Data callback */
131  l2cCtrlCback_t ctrlCback; /* Control callback */
132  attMsgHandler_t msgCback; /* Message handling callback */
133  attConnCback_t connCback; /* Connection callback */
134 } attFcnIf_t;
135 
136 /* Callback interface for enhanced client and server */
137 typedef struct
138 {
139  l2cCocCback_t l2cCocData; /* L2CAP COC data indication callback */
140  l2cCocCback_t l2cCocCnf; /* L2CAP COC data confirm callback */
141  attMsgHandler_t msgCback; /* Message handling callback */
142  attConnCback_t connCback; /* Connection callback */
143 } eattFcnIf_t;
144 
145 /* Main control block of the ATT subsystem */
146 typedef struct
147 {
148  attCcb_t ccb[DM_CONN_MAX]; /* Connection control blocks */
149  attFcnIf_t const *pClient; /* Client callback interface */
150  attFcnIf_t const *pServer; /* Server callback interface */
151  eattFcnIf_t const *pEnServer; /* Enhanced Server callback interface */
152  eattFcnIf_t const *pEnClient; /* Enhanced Client callback interface */
153  eattEventCback_t eattHandler; /* Enhanced ATT event callback */
154  dmCback_t eattDmCback; /* Enhanced ATT DM callback */
155  eattL2cDataReq_t eattL2cDataReq; /* Enhanced ATT L2C COC data request function */
156  attCback_t cback; /* ATT callback function */
157  dmCback_t connCback; /* ATT connection callback function */
158  wsfHandlerId_t handlerId; /* WSF handler ID */
159  uint8_t errTest; /* Status code for error testing */
160 } attCb_t;
161 
162 /**************************************************************************************************
163  Global Variables
164 **************************************************************************************************/
165 
166 /* Default component function inteface */
167 extern const attFcnIf_t attFcnDefault;
168 
169 /* Control block */
170 extern attCb_t attCb;
171 
172 /**************************************************************************************************
173  Function Declarations
174 **************************************************************************************************/
175 
176 void attEmptyHandler(wsfMsgHdr_t *pMsg);
177 void attEmptyDataCback(uint16_t handle, uint16_t len, uint8_t *pPacket);
178 void attEmptyConnCback(attCcb_t *pCcb, dmEvt_t *pDmEvt);
179 void attEmptyL2cCocCback(l2cCocEvt_t *pMsg);
180 
181 attCcb_t *attCcbByHandle(uint16_t handle);
182 attCcb_t *attCcbByConnId(dmConnId_t connId);
183 
184 bool_t attUuidCmp16to128(const uint8_t *pUuid16, const uint8_t *pUuid128);
185 void attSetMtu(attCcb_t *pCcb, uint8_t slot, uint16_t peerMtu, uint16_t localMtu);
186 void attExecCallback(dmConnId_t connId, uint8_t event, uint16_t handle, uint8_t status, uint16_t mtu);
187 void *attMsgAlloc(uint16_t len);
188 
189 void attL2cDataReq(attCcb_t *pCcb, uint8_t slot, uint16_t len, uint8_t *pPacket);
190 uint16_t attMsgParam(dmConnId_t connId, uint8_t slot);
191 void attDecodeMsgParam(uint16_t param, dmConnId_t *pConnId, uint8_t *pSlot);
192 
193 #ifdef __cplusplus
194 };
195 #endif
196 
197 #endif /* ATT_MAIN_H */
uint8_t dmConnId_t
Connection identifier.
Definition: dm_api.h:588
void(* l2cCocCback_t)(l2cCocEvt_t *pMsg)
This callback function sends data and other events to connection oriented channels clients...
Definition: l2c_api.h:256
void(* l2cDataCback_t)(uint16_t handle, uint16_t len, uint8_t *pPacket)
This callback function sends a received L2CAP packet to the client.
Definition: l2c_api.h:233
void(* attCback_t)(attEvt_t *pEvt)
ATT event callback type.
Definition: att_api.h:203
Connection oriented channel event structure.
Definition: l2c_api.h:178
Union of DM callback event data types.
Definition: dm_api.h:760
void(* l2cCtrlCback_t)(wsfMsgHdr_t *pMsg)
This callback function sends control messages to the client.
Definition: l2c_api.h:244
uint8_t wsfHandlerId_t
Event handler ID data type.
Definition: wsf_os.h:80
void(* dmCback_t)(dmEvt_t *pDmEvt)
Callback type.
Definition: dm_api.h:868
Device Manager subsystem API.
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
L2CAP subsystem API.
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.