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 /** the requested payload format. */
85 OCPayloadFormat acceptFormat;
87 /** resourceUrl will be filled in occoap using the path options in received request PDU.*/
88 char resourceUrl[MAX_URI_LENGTH];
90 /** resource query send by client.*/
91 char query[MAX_QUERY_LENGTH];
93 /** reqJSON is retrieved from the payload of the received request PDU.*/
96 /** qos is indicating if the request is CON or NON.*/
97 OCQualityOfService qos;
99 /** Number of the received vendor specific header options.*/
100 uint8_t numRcvdVendorSpecificHeaderOptions;
102 /** Array of received vendor specific header option .*/
103 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
105 /** Remote end-point address **/
108 /** Token for the observe request.*/
109 CAToken_t requestToken;
114 /** The ID of CoAP PDU.*/
117 /** For delayed Response.*/
118 uint8_t delayedResNeeded;
120 /** For More packet.*/
121 uint8_t reqMorePacket;
123 /** The number of requested packet.*/
124 uint32_t reqPacketNum;
126 /** The size of requested packet.*/
127 uint16_t reqPacketSize;
129 /** The number of responded packet.*/
130 uint32_t resPacketNum;
132 /** Responded packet size.*/
133 uint16_t resPacketSize;
135 /** The total size of requested packet.*/
137 } OCServerProtocolRequest;
140 * This structure will be created in occoap and passed up the stack on the client side.
144 /** handle is retrieved by comparing the token-handle pair in the PDU.*/
147 /** This is how long this response is valid for (in seconds).*/
150 /** This is the Uri of the resource. (ex. "coap://192.168.1.1/a/led").*/
153 /** This is the relative Uri of the resource. (ex. "/a/led").*/
156 /** This is the received payload.*/
159 /** This is the token received OTA.*/
162 /** this structure will be passed to client.*/
163 OCClientResponse * clientResponse;
167 * This typedef is to represent our Server Instance identification.
169 typedef uint8_t ServerID[16];
171 //-----------------------------------------------------------------------------
172 // Internal function prototypes
173 //-----------------------------------------------------------------------------
177 * Handler function for sending a response from multiple resources, such as a collection.
178 * Aggregates responses from multiple resource until all responses are received then sends the
179 * concatenated response
181 * TODO: Need to add a timeout in case a (remote?) resource does not respond
183 * @param token Token to search for.
184 * @param tokenLength Length of token.
185 * @param status Feedback status.
190 OCStackResult OCStackFeedBack(CAToken_t token, uint8_t tokenLength, uint8_t status);
194 * Handler function to execute stack requests
196 * @param protocolRequest Pointer to the protocol requests from server.
201 OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
203 OCStackResult SendDirectStackResponse(const CAEndpoint_t* endPoint, const uint16_t coapID,
204 const CAResponseResult_t responseResult, const CAMessageType_t type,
205 const uint8_t numOptions, const CAHeaderOption_t *options,
206 CAToken_t token, uint8_t tokenLength, const char *resourceUri);
211 * Notify Presence subscribers that a resource has been modified.
213 * @param resourceType Handle to the resourceType linked list of resource that was modified.
214 * @param trigger The simplified reason this API was invoked.
216 * @return ::OC_STACK_OK on success, some other value upon failure.
218 OCStackResult SendPresenceNotification(OCResourceType *resourceType,
219 OCPresenceTrigger trigger);
222 * Send Stop Notification to Presence subscribers.
224 * @return ::OC_STACK_OK on success, some other value upon failure.
226 OCStackResult SendStopNotification();
227 #endif // WITH_PRESENCE
230 * Function to parse the IPv4 address.
232 * @param ipAddrStr Pointer to a string of IPv4 address.
233 * @param ipAddr pointer to IPv4 adress.
234 * @param port Port number.
236 * @return true on success, false upon failure.
238 bool ParseIPv4Address(char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
241 * Bind a resource interface to a resource.
243 * @param resource Target resource.
244 * @param resourceInterfaceName Resource interface.
246 * @return ::OC_STACK_OK on success, some other value upon failure.
248 OCStackResult BindResourceInterfaceToResource(OCResource* resource,
249 const char *resourceInterfaceName);
251 * Bind a resource type to a resource.
253 * @param resource Target resource.
254 * @param resourceTypeName Name of resource type.
255 * @return ::OC_STACK_OK on success, some other value upon failure.
257 OCStackResult BindResourceTypeToResource(OCResource* resource,
258 const char *resourceTypeName);
262 * Converts a CAResult_t type to a OCStackResult type.
264 * @param caResult CAResult_t value to convert.
265 * @return OCStackResult that was converted from the input CAResult_t value.
267 OCStackResult CAResultToOCResult(CAResult_t caResult);
270 * Get a byte representation of the server instance ID.
271 * The memory is managed internal to this function, so freeing it externally will
272 * result in a runtime error.
274 * Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
275 * This is done automatically during the OCInit process,
276 * so ensure that this call is done after that.
278 * @return A uint8_t representation the server instance ID.
280 const OicUuid_t* OCGetServerInstanceID(void);
283 * Get a string representation the server instance ID.
284 * The memory is managed internal to this function, so freeing externally will result
285 * in a runtime error.
286 * Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
287 * This is done automatically during the OCInit process,
288 * so ensure that this call is done after that.
290 * @return A string representation the server instance ID.
292 const char* OCGetServerInstanceIDString(void);
295 * Map OCQualityOfService to CAMessageType.
297 * @param qos Input qos.
299 * @return CA message type for a given qos.
301 CAMessageType_t qualityOfServiceToMessageType(OCQualityOfService qos);
305 * Enable/disable a resource property.
307 * @param inputProperty Pointer to resource property.
308 * @param resourceProperties Property to be enabled/disabled.
309 * @param enable 0:disable, 1:enable.
311 * @return OCStackResult that was converted from the input CAResult_t value.
313 //TODO: should the following function be public?
314 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
315 OCResourceProperty resourceProperties, uint8_t enable);
318 const char *convertTriggerEnumToString(OCPresenceTrigger trigger);
320 OCPresenceTrigger convertTriggerStringToEnum(const char * triggerStr);
322 void CopyEndpointToDevAddr(const CAEndpoint_t *in, OCDevAddr *out);
324 void CopyDevAddrToEndpoint(const OCDevAddr *in, CAEndpoint_t *out);
328 #endif // __cplusplus
330 #endif /* OCSTACKINTERNAL_H_ */