1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
27 * This file contains the Internal include file used by lower layers of the OC stack
31 #ifndef OCSTACKINTERNAL_H_
32 #define OCSTACKINTERNAL_H_
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
39 #include "ocstackconfig.h"
40 #include "occlientcb.h"
44 #include "cainterface.h"
45 #include "securevirtualresourcetypes.h"
52 //-----------------------------------------------------------------------------
54 //-----------------------------------------------------------------------------
56 /** Default device entity Handler.*/
57 extern OCDeviceEntityHandler defaultDeviceHandler;
59 /** Default Callback parameter.*/
60 extern void* defaultDeviceHandlerCallbackParameter;
62 //-----------------------------------------------------------------------------
64 //-----------------------------------------------------------------------------
66 /** The coap scheme */
67 #define OC_COAP_SCHEME "coap://"
69 /** the first outgoing sequence number will be 5*/
70 #define OC_OFFSET_SEQUENCE_NUMBER (4)
73 * This structure will be created in occoap and passed up the stack on the server side.
77 /** Observe option field.*/
78 uint32_t observationOption;
80 /** The REST method retrieved from received request PDU.*/
83 /** the requested payload format. */
84 OCPayloadFormat acceptFormat;
86 /** resourceUrl will be filled in occoap using the path options in received request PDU.*/
87 char resourceUrl[MAX_URI_LENGTH];
89 /** resource query send by client.*/
90 char query[MAX_QUERY_LENGTH];
92 /** reqJSON is retrieved from the payload of the received request PDU.*/
95 /** qos is indicating if the request is CON or NON.*/
96 OCQualityOfService qos;
98 /** Number of the received vendor specific header options.*/
99 uint8_t numRcvdVendorSpecificHeaderOptions;
101 /** Array of received vendor specific header option .*/
102 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
104 /** Remote end-point address **/
107 /** Token for the observe request.*/
108 CAToken_t requestToken;
113 /** The ID of CoAP PDU.*/
116 /** For delayed Response.*/
117 uint8_t delayedResNeeded;
119 /** For More packet.*/
120 uint8_t reqMorePacket;
122 /** The number of requested packet.*/
123 uint32_t reqPacketNum;
125 /** The size of requested packet.*/
126 uint16_t reqPacketSize;
128 /** The number of responded packet.*/
129 uint32_t resPacketNum;
131 /** Responded packet size.*/
132 uint16_t resPacketSize;
134 /** The total size of requested packet.*/
136 } OCServerProtocolRequest;
139 * This structure will be created in occoap and passed up the stack on the client side.
143 /** handle is retrieved by comparing the token-handle pair in the PDU.*/
146 /** This is how long this response is valid for (in seconds).*/
149 /** This is the Uri of the resource. (ex. "coap://192.168.1.1/a/led").*/
152 /** This is the relative Uri of the resource. (ex. "/a/led").*/
155 /** This is the received payload.*/
158 /** This is the token received OTA.*/
161 /** this structure will be passed to client.*/
162 OCClientResponse * clientResponse;
166 * This typedef is to represent our Server Instance identification.
168 typedef uint8_t ServerID[16];
170 //-----------------------------------------------------------------------------
171 // Internal function prototypes
172 //-----------------------------------------------------------------------------
176 * Handler function for sending a response from multiple resources, such as a collection.
177 * Aggregates responses from multiple resource until all responses are received then sends the
178 * concatenated response
180 * TODO: Need to add a timeout in case a (remote?) resource does not respond
182 * @param token Token to search for.
183 * @param tokenLength Length of token.
184 * @param status Feedback status.
189 OCStackResult OCStackFeedBack(CAToken_t token, uint8_t tokenLength, uint8_t status);
193 * Handler function to execute stack requests
195 * @param protocolRequest Pointer to the protocol requests from server.
200 OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
202 OCStackResult SendDirectStackResponse(const CAEndpoint_t* endPoint, const uint16_t coapID,
203 const CAResponseResult_t responseResult, const CAMessageType_t type,
204 const uint8_t numOptions, const CAHeaderOption_t *options,
205 CAToken_t token, uint8_t tokenLength, const char *resourceUri);
210 * Notify Presence subscribers that a resource has been modified.
212 * @param resourceType Handle to the resourceType linked list of resource that was modified.
213 * @param trigger The simplified reason this API was invoked.
215 * @return ::OC_STACK_OK on success, some other value upon failure.
217 OCStackResult SendPresenceNotification(OCResourceType *resourceType,
218 OCPresenceTrigger trigger);
221 * Send Stop Notification to Presence subscribers.
223 * @return ::OC_STACK_OK on success, some other value upon failure.
225 OCStackResult SendStopNotification();
226 #endif // WITH_PRESENCE
229 * Function to parse the IPv4 address.
231 * @param ipAddrStr Pointer to a string of IPv4 address.
232 * @param ipAddr pointer to IPv4 adress.
233 * @param port Port number.
235 * @return true on success, false upon failure.
237 bool ParseIPv4Address(char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
240 * Bind a resource interface to a resource.
242 * @param resource Target resource.
243 * @param resourceInterfaceName Resource interface.
245 * @return ::OC_STACK_OK on success, some other value upon failure.
247 OCStackResult BindResourceInterfaceToResource(OCResource* resource,
248 const char *resourceInterfaceName);
250 * Bind a resource type to a resource.
252 * @param resource Target resource.
253 * @param resourceTypeName Name of resource type.
254 * @return ::OC_STACK_OK on success, some other value upon failure.
256 OCStackResult BindResourceTypeToResource(OCResource* resource,
257 const char *resourceTypeName);
261 * Converts a CAResult_t type to a OCStackResult type.
263 * @param caResult CAResult_t value to convert.
264 * @return OCStackResult that was converted from the input CAResult_t value.
266 OCStackResult CAResultToOCResult(CAResult_t caResult);
269 * Get a byte representation of the server instance ID.
270 * The memory is managed internal to this function, so freeing it externally will
271 * result in a runtime error.
273 * Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
274 * This is done automatically during the OCInit process,
275 * so ensure that this call is done after that.
277 * @return A uint8_t representation the server instance ID.
279 const OicUuid_t* OCGetServerInstanceID(void);
282 * Get a string representation the server instance ID.
283 * The memory is managed internal to this function, so freeing externally will result
284 * in a runtime error.
285 * Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
286 * This is done automatically during the OCInit process,
287 * so ensure that this call is done after that.
289 * @return A string representation the server instance ID.
291 const char* OCGetServerInstanceIDString(void);
294 * Map OCQualityOfService to CAMessageType.
296 * @param qos Input qos.
298 * @return CA message type for a given qos.
300 CAMessageType_t qualityOfServiceToMessageType(OCQualityOfService qos);
304 * Enable/disable a resource property.
306 * @param inputProperty Pointer to resource property.
307 * @param resourceProperties Property to be enabled/disabled.
308 * @param enable 0:disable, 1:enable.
310 * @return OCStackResult that was converted from the input CAResult_t value.
312 //TODO: should the following function be public?
313 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
314 OCResourceProperty resourceProperties, uint8_t enable);
317 const char *convertTriggerEnumToString(OCPresenceTrigger trigger);
319 OCPresenceTrigger convertTriggerStringToEnum(const char * triggerStr);
321 void CopyEndpointToDevAddr(const CAEndpoint_t *in, OCDevAddr *out);
323 void CopyDevAddrToEndpoint(const OCDevAddr *in, CAEndpoint_t *out);
327 #endif // __cplusplus
329 #endif /* OCSTACKINTERNAL_H_ */