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"
45 #include "cainterface.h"
46 #include "securevirtualresourcetypes.h"
53 //-----------------------------------------------------------------------------
55 //-----------------------------------------------------------------------------
57 /** Default device entity Handler.*/
58 extern OCDeviceEntityHandler defaultDeviceHandler;
60 /** Default Callback parameter.*/
61 extern void* defaultDeviceHandlerCallbackParameter;
63 //-----------------------------------------------------------------------------
65 //-----------------------------------------------------------------------------
67 /** The coap scheme */
68 #define OC_COAP_SCHEME "coap://"
70 /** the first outgoing sequence number will be 5*/
71 #define OC_OFFSET_SEQUENCE_NUMBER (4)
74 * This structure will be created in occoap and passed up the stack on the server side.
78 /** Observe option field.*/
79 uint32_t observationOption;
81 /** The REST method retrieved from received request PDU.*/
84 /** resourceUrl will be filled in occoap using the path options in received request PDU.*/
85 char resourceUrl[MAX_URI_LENGTH];
87 /** resource query send by client.*/
88 char query[MAX_QUERY_LENGTH];
90 /** reqJSON is retrieved from the payload of the received request PDU.*/
93 /** qos is indicating if the request is CON or NON.*/
94 OCQualityOfService qos;
96 /** Number of the received vendor specific header options.*/
97 uint8_t numRcvdVendorSpecificHeaderOptions;
99 /** Array of received vendor specific header option .*/
100 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
102 /** Remote end-point address **/
105 /** Token for the observe request.*/
106 CAToken_t requestToken;
111 /** The ID of CoAP PDU.*/
114 /** For delayed Response.*/
115 uint8_t delayedResNeeded;
117 /** For More packet.*/
118 uint8_t reqMorePacket;
120 /** The number of requested packet.*/
121 uint32_t reqPacketNum;
123 /** The size of requested packet.*/
124 uint16_t reqPacketSize;
126 /** The number of responded packet.*/
127 uint32_t resPacketNum;
129 /** Responded packet size.*/
130 uint16_t resPacketSize;
132 /** The total size of requested packet.*/
134 } OCServerProtocolRequest;
137 * This structure will be created in occoap and passed up the stack on the client side.
141 /** handle is retrieved by comparing the token-handle pair in the PDU.*/
144 /** This is how long this response is valid for (in seconds).*/
147 /** This is the Uri of the resource. (ex. "coap://192.168.1.1/a/led").*/
150 /** This is the relative Uri of the resource. (ex. "/a/led").*/
153 /** This is the received payload.*/
156 /** This is the token received OTA.*/
159 /** this structure will be passed to client.*/
160 OCClientResponse * clientResponse;
164 * This typedef is to represent our Server Instance identification.
166 typedef uint8_t ServerID[16];
168 //-----------------------------------------------------------------------------
169 // Internal function prototypes
170 //-----------------------------------------------------------------------------
174 * Handler function for sending a response from multiple resources, such as a collection.
175 * Aggregates responses from multiple resource until all responses are received then sends the
176 * concatenated response
178 * TODO: Need to add a timeout in case a (remote?) resource does not respond
180 * @param token Token to search for.
181 * @param tokenLength Length of token.
182 * @param status Feedback status.
187 OCStackResult OCStackFeedBack(CAToken_t token, uint8_t tokenLength, uint8_t status);
191 * Handler function to execute stack requests
193 * @param protocolRequest Pointer to the protocol requests from server.
198 OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
200 OCStackResult SendDirectStackResponse(const CAEndpoint_t* endPoint, const uint16_t coapID,
201 const CAResponseResult_t responseResult, const CAMessageType_t type,
202 const uint8_t numOptions, const CAHeaderOption_t *options,
203 CAToken_t token, uint8_t tokenLength);
208 * Notify Presence subscribers that a resource has been modified.
210 * @param resourceType Handle to the resourceType linked list of resource that was modified.
211 * @param trigger The simplified reason this API was invoked.
213 * @return ::OC_STACK_OK on success, some other value upon failure.
215 OCStackResult SendPresenceNotification(OCResourceType *resourceType,
216 OCPresenceTrigger trigger);
219 * Send Stop Notification to Presence subscribers.
221 * @return ::OC_STACK_OK on success, some other value upon failure.
223 OCStackResult SendStopNotification();
224 #endif // WITH_PRESENCE
227 * Function to parse the IPv4 address.
229 * @param ipAddrStr Pointer to a string of IPv4 address.
230 * @param ipAddr pointer to IPv4 adress.
231 * @param port Port number.
233 * @return true on success, false upon failure.
235 bool ParseIPv4Address(char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
238 * Bind a resource interface to a resource.
240 * @param resource Target resource.
241 * @param resourceInterfaceName Resource interface.
243 * @return ::OC_STACK_OK on success, some other value upon failure.
245 OCStackResult BindResourceInterfaceToResource(OCResource* resource,
246 const char *resourceInterfaceName);
248 * Bind a resource type to a resource.
250 * @param resource Target resource.
251 * @param resourceTypeName Name of resource type.
252 * @return ::OC_STACK_OK on success, some other value upon failure.
254 OCStackResult BindResourceTypeToResource(OCResource* resource,
255 const char *resourceTypeName);
259 * Converts a CAResult_t type to a OCStackResult type.
261 * @param caResult CAResult_t value to convert.
262 * @return OCStackResult that was converted from the input CAResult_t value.
264 OCStackResult CAResultToOCResult(CAResult_t caResult);
267 * Get a byte representation of the server instance ID.
268 * The memory is managed internal to this function, so freeing it externally will
269 * result in a runtime error.
271 * Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
272 * This is done automatically during the OCInit process,
273 * so ensure that this call is done after that.
275 * @return A uint8_t representation the server instance ID.
277 const OicUuid_t* OCGetServerInstanceID(void);
280 * Get a string representation the server instance ID.
281 * The memory is managed internal to this function, so freeing externally will result
282 * in a runtime error.
283 * Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
284 * This is done automatically during the OCInit process,
285 * so ensure that this call is done after that.
287 * @return A string representation the server instance ID.
289 const char* OCGetServerInstanceIDString(void);
292 * Map OCQualityOfService to CAMessageType.
294 * @param qos Input qos.
296 * @return CA message type for a given qos.
298 CAMessageType_t qualityOfServiceToMessageType(OCQualityOfService qos);
302 * Enable/disable a resource property.
304 * @param inputProperty Pointer to resource property.
305 * @param resourceProperties Property to be enabled/disabled.
306 * @param enable 0:disable, 1:enable.
308 * @return OCStackResult that was converted from the input CAResult_t value.
310 //TODO: should the following function be public?
311 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
312 OCResourceProperty resourceProperties, uint8_t enable);
315 const char *convertTriggerEnumToString(OCPresenceTrigger trigger);
317 OCPresenceTrigger convertTriggerStringToEnum(const char * triggerStr);
319 void CopyEndpointToDevAddr(const CAEndpoint_t *in, OCDevAddr *out);
321 void CopyDevAddrToEndpoint(const OCDevAddr *in, CAEndpoint_t *out);
325 #endif // __cplusplus
327 #endif /* OCSTACKINTERNAL_H_ */