Updated C stack external API comments for doxygen documentation.
[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
24 /**
25  * @file
26  *
27  * This file contains the Internal include file used by lower layers of the OC stack
28  *
29  */
30
31 #ifndef OCSTACKINTERNAL_H_
32 #define OCSTACKINTERNAL_H_
33
34 //-----------------------------------------------------------------------------
35 // Includes
36 //-----------------------------------------------------------------------------
37 #include <stdbool.h>
38 #include "ocstack.h"
39 #include "ocstackconfig.h"
40 #include "occlientcb.h"
41 #include <logger.h>
42 #include <ocrandom.h>
43
44 #include "cacommon.h"
45 #include "cainterface.h"
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif // __cplusplus
50
51
52 //-----------------------------------------------------------------------------
53 // Global variables
54 //-----------------------------------------------------------------------------
55
56 /** Default device entity Handler.*/
57 extern OCDeviceEntityHandler defaultDeviceHandler;
58
59 /** Default Callback parameter.*/
60 extern void* defaultDeviceHandlerCallbackParameter;
61
62 //-----------------------------------------------------------------------------
63 // Defines
64 //-----------------------------------------------------------------------------
65
66 /** The coap scheme */
67 #define OC_COAP_SCHEME "coap://"
68
69 /** the first outgoing sequence number will be 5*/
70 #define OC_OFFSET_SEQUENCE_NUMBER (4)
71
72 /**
73  * This structure will be created in occoap and passed up the stack on the server side.
74  */
75 typedef struct
76 {
77     /** Observe option field.*/
78     uint32_t observationOption;
79
80     /** The REST method retrieved from received request PDU.*/
81     OCMethod method;
82
83     /** resourceUrl will be filled in occoap using the path options in received request PDU.*/
84     char resourceUrl[MAX_URI_LENGTH];
85
86     /** resource query send by client.*/
87     char query[MAX_QUERY_LENGTH];
88
89     /** reqJSON is retrieved from the payload of the received request PDU.*/
90     uint8_t payload[MAX_REQUEST_LENGTH];
91
92     /** qos is indicating if the request is CON or NON.*/
93     OCQualityOfService qos;
94
95     /** Number of the received vendor specific header options.*/
96     uint8_t numRcvdVendorSpecificHeaderOptions;
97
98     /** Array of received vendor specific header option .*/
99     OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
100
101     /** Remote end-point address **/
102     OCDevAddr devAddr;
103
104     /** Token for the observe request.*/
105     CAToken_t requestToken;
106
107     /** token length.*/
108     uint8_t tokenLength;
109
110     /** The ID of CoAP PDU.*/
111     uint16_t coapID;
112
113     /** For delayed Response.*/
114     uint8_t delayedResNeeded;
115
116     /** For More packet.*/
117     uint8_t reqMorePacket;
118
119     /** The number of requested packet.*/
120     uint32_t reqPacketNum;
121
122     /** The size of requested packet.*/
123     uint16_t reqPacketSize;
124
125     /** The number of responded packet.*/
126     uint32_t resPacketNum;
127
128     /** Responded packet size.*/
129     uint16_t resPacketSize;
130
131     /** The total size of requested packet.*/
132     size_t reqTotalSize;
133 } OCServerProtocolRequest;
134
135 /**
136  * This structure will be created in occoap and passed up the stack on the client side.
137  */
138 typedef struct
139 {
140     /** handle is retrieved by comparing the token-handle pair in the PDU.*/
141     ClientCB * cbNode;
142
143     /** This is how long this response is valid for (in seconds).*/
144     uint32_t maxAge;
145
146     /** This is the Uri of the resource. (ex. "coap://192.168.1.1/a/led").*/
147     char * fullUri;
148
149     /** This is the relative Uri of the resource. (ex. "/a/led").*/
150     char * rcvdUri;
151
152     /** This is the received payload.*/
153     char * bufRes;
154
155     /** This is the token received OTA.*/
156     CAToken_t rcvdToken;
157
158     /** this structure will be passed to client.*/
159     OCClientResponse * clientResponse;
160 } OCResponse;
161
162 /**
163  * This typedef is to represent our Server Instance identification.
164  */
165 typedef uint8_t ServerID[16];
166
167 //-----------------------------------------------------------------------------
168 // Internal function prototypes
169 //-----------------------------------------------------------------------------
170
171
172 /**
173  * Handler function for sending a response from multiple resources, such as a collection.
174  * Aggregates responses from multiple resource until all responses are received then sends the
175  * concatenated response
176  *
177  * TODO: Need to add a timeout in case a (remote?) resource does not respond
178  *
179  * @param token         Token to search for.
180  * @param tokenLength   Length of token.
181  * @param status        Feedback status.
182  * @return
183  *     ::OCStackResult
184  */
185
186 OCStackResult OCStackFeedBack(CAToken_t token, uint8_t tokenLength, uint8_t status);
187
188
189 /**
190  * Handler function to execute stack requests
191  *
192  * @param protocolRequest      Pointer to the protocol requests from server.
193  *
194  * @return
195  *     ::OCStackResult
196  */
197 OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
198
199 OCStackResult SendDirectStackResponse(const CAEndpoint_t* endPoint, const uint16_t coapID,
200         const CAResponseResult_t responseResult, const CAMessageType_t type,
201         const uint8_t numOptions, const CAHeaderOption_t *options,
202         CAToken_t token, uint8_t tokenLength);
203
204 #ifdef WITH_PRESENCE
205
206 /**
207  * Notify Presence subscribers that a resource has been modified.
208  *
209  * @param resourceType    Handle to the resourceType linked list of resource that was modified.
210  * @param trigger         The simplified reason this API was invoked.
211  *
212  * @return ::OC_STACK_OK on success, some other value upon failure.
213  */
214 OCStackResult SendPresenceNotification(OCResourceType *resourceType,
215         OCPresenceTrigger trigger);
216
217 /**
218  * Send Stop Notification to Presence subscribers.
219  *
220  * @return ::OC_STACK_OK on success, some other value upon failure.
221  */
222 OCStackResult SendStopNotification();
223 #endif // WITH_PRESENCE
224
225 /**
226  * Function to parse the IPv4 address.
227  *
228  * @param ipAddrStr       Pointer to a string of IPv4 address.
229  * @param ipAddr          pointer to IPv4 adress.
230  * @param port            Port number.
231  *
232  * @return true on success, false upon failure.
233  */
234 bool ParseIPv4Address(char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
235
236 /**
237  * Bind a resource interface to a resource.
238  *
239  * @param resource Target resource.
240  * @param resourceInterfaceName Resource interface.
241  *
242  * @return ::OC_STACK_OK on success, some other value upon failure.
243  */
244 OCStackResult BindResourceInterfaceToResource(OCResource* resource,
245                                             const char *resourceInterfaceName);
246 /**
247  * Bind a resource type to a resource.
248  *
249  * @param resource Target resource.
250  * @param resourceTypeName Name of resource type.
251  * @return ::OC_STACK_OK on success, some other value upon failure.
252  */
253 OCStackResult BindResourceTypeToResource(OCResource* resource,
254                                             const char *resourceTypeName);
255
256
257 /**
258  * Converts a CAResult_t type to a OCStackResult type.
259  *
260  * @param caResult CAResult_t value to convert.
261  * @return OCStackResult that was converted from the input CAResult_t value.
262  */
263 OCStackResult CAResultToOCResult(CAResult_t caResult);
264
265 /**
266  * Get a byte representation of the server instance ID.
267  * The memory is managed internal to this function, so freeing it externally will
268  * result in a runtime error.
269  *
270  * Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
271  * This is done automatically during the OCInit process,
272  * so ensure that this call is done after that.
273  *
274  * @return A uint8_t representation the server instance ID.
275  */
276 const uint8_t* OCGetServerInstanceID(void);
277
278 /**
279  * Get a string representation the server instance ID.
280  * The memory is managed internal to this function, so freeing externally will result
281  * in a runtime error.
282  * Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
283  * This is done automatically during the OCInit process,
284  * so ensure that this call is done after that.
285  *
286  * @return A string representation  the server instance ID.
287  */
288 const char* OCGetServerInstanceIDString(void);
289
290 /**
291  * Map OCQualityOfService to CAMessageType.
292  *
293  * @param qos Input qos.
294  *
295  * @return CA message type for a given qos.
296  */
297 CAMessageType_t qualityOfServiceToMessageType(OCQualityOfService qos);
298
299 #ifdef WITH_PRESENCE
300 /**
301  * Enable/disable a resource property.
302  *
303  * @param inputProperty             Pointer to resource property.
304  * @param resourceProperties        Property to be enabled/disabled.
305  * @param enable                    0:disable, 1:enable.
306  *
307  * @return OCStackResult that was converted from the input CAResult_t value.
308  */
309 //TODO: should the following function be public?
310 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
311         OCResourceProperty resourceProperties, uint8_t enable);
312 #endif
313
314 const char *convertTriggerEnumToString(OCPresenceTrigger trigger);
315
316 OCPresenceTrigger convertTriggerStringToEnum(const char * triggerStr);
317
318 void CopyEndpointToDevAddr(const CAEndpoint_t *in, OCDevAddr *out);
319
320 void CopyDevAddrToEndpoint(const OCDevAddr *in, CAEndpoint_t *out);
321
322 #ifdef __cplusplus
323 }
324 #endif // __cplusplus
325
326 #endif /* OCSTACKINTERNAL_H_ */
327