Replaced (conditionally) OCCoAPToken with CAToken_t
[platform/upstream/iotivity.git] / resource / csdk / stack / include / internal / ocstackinternal.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20 //
21
22 //-----------------------------------------------------------------------------
23 // Internal include file used by lower layers of the OC stack
24 //-----------------------------------------------------------------------------
25 #ifndef OCSTACKINTERNAL_H_
26 #define OCSTACKINTERNAL_H_
27
28 //-----------------------------------------------------------------------------
29 // Includes
30 //-----------------------------------------------------------------------------
31 #include <stdbool.h>
32 #include "ocstack.h"
33 #include "ocstackconfig.h"
34 #include "occlientcb.h"
35 #include <logger.h>
36 #include <ocrandom.h>
37
38 #ifdef CA_INT
39 #include "cacommon.h"
40 #include "cainterface.h"
41 #else
42 #include "occoaptoken.h"
43 #endif
44
45 #ifdef __cplusplus
46 extern "C" {
47 #endif // __cplusplus
48
49
50 //-----------------------------------------------------------------------------
51 // Global variables
52 //-----------------------------------------------------------------------------
53 extern OCDeviceEntityHandler defaultDeviceHandler;
54
55 //-----------------------------------------------------------------------------
56 // Defines
57 //-----------------------------------------------------------------------------
58 #define OC_COAP_SCHEME "coap://"
59 #define OC_OFFSET_SEQUENCE_NUMBER (4) // the first outgoing sequence number will be 5
60
61 typedef struct {
62     // Observe option field
63     uint32_t option;
64     // IP address & port of client registered for observe
65     OCDevAddr *subAddr;
66
67 #ifdef CA_INT
68     CAToken_t *token;
69 #else // CA_INT
70     // token for the observe request
71     OCCoAPToken *token;
72 #endif // CA_INT
73
74     // The result of the observe request
75     OCStackResult result;
76 } OCObserveReq;
77
78 // following structure will be created in occoap and passed up the stack on the server side
79 typedef struct {
80     // Observe option field
81     uint32_t observationOption;
82     // the REST method retrieved from received request PDU
83     OCMethod method;
84     // resourceUrl will be filled in occoap using the path options in received request PDU
85     unsigned char resourceUrl[MAX_URI_LENGTH];
86     // resource query send by client
87     unsigned char query[MAX_QUERY_LENGTH];
88     // reqJSON is retrieved from the payload of the received request PDU
89     unsigned char reqJSONPayload[MAX_REQUEST_LENGTH];
90     // qos is indicating if the request is CON or NON
91     OCQualityOfService qos;
92     // An array of the received vendor specific header options
93     uint8_t numRcvdVendorSpecificHeaderOptions;
94     OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
95 #ifdef CA_INT
96     /** Remote Endpoint address **/
97     CAAddress_t addressInfo;
98     /** Connectivity of the endpoint**/
99     CAConnectivityType_t connectivityType;
100 #endif
101     //////////////////////////////////////////////////////////
102     // TODO: Consider moving these member to CoAP
103     // IP address & port of client registered for observe
104     OCDevAddr requesterAddr;
105
106 #ifdef CA_INT
107     //token for the observe request
108     CAToken_t requestToken;
109 #else // CA_INT
110     // CoAP token for the observe request
111     OCCoAPToken requestToken;
112 #endif // CA_INT
113
114     // The ID of CoAP pdu
115     uint16_t coapID;
116     uint8_t delayedResNeeded;
117     uint8_t secured;
118     //////////////////////////////////////////////////////////
119     uint8_t reqMorePacket;
120     uint32_t reqPacketNum;
121     uint16_t reqPacketSize;
122     uint32_t resPacketNum;
123     uint16_t resPacketSize;
124     size_t reqTotalSize;
125 } OCServerProtocolRequest;
126
127 typedef struct
128 {
129     // Observe option field
130     uint32_t observationOption;
131     // qos is indicating if the request is CON or NON
132     OCQualityOfService qos;
133     // Allow the entity handler to pass a result with the response
134     OCStackResult result;
135     // IP address & port of client registered for observe
136     OCDevAddr *requesterAddr;
137
138 #ifdef CA_INT
139     CAToken_t *requestToken;
140 #else // CA_INT
141     // CoAP token for the observe request
142     OCCoAPToken *requestToken;
143 #endif // CA_INT
144
145     // The ID of CoAP pdu
146     uint16_t coapID;
147     // Flag indicating that response is to be delayed before sending
148     uint8_t delayedResNeeded;
149     uint8_t secured;
150     uint8_t slowFlag;
151     uint8_t notificationFlag;
152     // this is the pointer to server payload data to be transferred
153     unsigned char *payload;
154     // size of server payload data.  Don't rely on null terminated data for size
155     uint16_t payloadSize;
156     // An array of the vendor specific header options the entity handler wishes to use in response
157     uint8_t numSendVendorSpecificHeaderOptions;
158     OCHeaderOption *sendVendorSpecificHeaderOptions;
159     // URI of new resource that entity handler might create
160     unsigned char * resourceUri;
161 } OCServerProtocolResponse;
162
163 // following structure will be created in occoap and passed up the stack on the client side
164 typedef struct {
165     // handle is retrieved by comparing the token-handle pair in the PDU.
166     ClientCB * cbNode;
167     // This is how long this response is valid for (in seconds).
168     uint32_t maxAge;
169     // This is the Uri of the resource. (ex. "coap://192.168.1.1/a/led")
170     unsigned char * fullUri;
171     // This is the relative Uri of the resource. (ex. "/a/led")
172     unsigned char * rcvdUri;
173     // This is the received payload.
174     unsigned char * bufRes;
175
176 #ifdef CA_INT
177     // This is the token received OTA.
178     CAToken_t * rcvdToken;
179 #else // CA_INT
180    // This is the token received OTA.
181     OCCoAPToken * rcvdToken;
182 #endif // CA_INT
183
184     // this structure will be passed to client
185     OCClientResponse * clientResponse;
186 } OCResponse;
187
188 // following typedef is to represent our Server Instance identification.
189 typedef uint32_t ServerID;
190
191 //-----------------------------------------------------------------------------
192 // Internal function prototypes
193 //-----------------------------------------------------------------------------
194
195 #ifdef CA_INT
196 OCStackResult OCStackFeedBack(CAToken_t * token, uint8_t status);
197 #else // CA_INT
198 OCStackResult OCStackFeedBack(OCCoAPToken * token, uint8_t status);
199 #endif // CA_INT
200
201 OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
202 OCStackResult HandleStackResponses(OCResponse * response);
203 #ifdef WITH_PRESENCE
204 OCStackResult SendPresenceNotification(OCResourceType *resourceType);
205 #endif // WITH_PRESENCE
206 int ParseIPv4Address(unsigned char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
207
208 OCStackResult BindResourceInterfaceToResource(OCResource* resource,
209                                             const char *resourceInterfaceName);
210
211 OCStackResult BindResourceTypeToResource(OCResource* resource,
212                                             const char *resourceTypeName);
213 OCResourceType *findResourceType(OCResourceType * resourceTypeList, const char * resourceTypeName);
214
215 // returns the internal representation of the server instance ID.
216 // Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
217 // This is done automatically during the OCInit process (via the call to OCInitCoAP),
218 // so ensure that this call is done after that.
219 const ServerID OCGetServerInstanceID(void);
220
221 // returns a string representation  the server instance ID.
222 // The memory is managed internal to this function, so freeing externally will result
223 // in a compiler error
224 // Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
225 // This is done automatically during the OCInit process (via the call to OCInitCoAP),
226 // so ensure that this call is done after that.
227 const char* OCGetServerInstanceIDString(void);
228 #ifdef WITH_PRESENCE
229 //TODO: should the following function be public?
230 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
231         OCResourceProperty resourceProperties, uint8_t enable);
232 #endif
233
234 #ifdef __cplusplus
235 }
236 #endif // __cplusplus
237
238 #endif /* OCSTACKINTERNAL_H_ */