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 1*/
70 #define OC_OFFSET_SEQUENCE_NUMBER (0)
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 typedef is to represent our Server Instance identification.
141 typedef uint8_t ServerID[16];
143 //-----------------------------------------------------------------------------
144 // Internal function prototypes
145 //-----------------------------------------------------------------------------
149 * Handler function for sending a response from multiple resources, such as a collection.
150 * Aggregates responses from multiple resource until all responses are received then sends the
151 * concatenated response
153 * TODO: Need to add a timeout in case a (remote?) resource does not respond
155 * @param token Token to search for.
156 * @param tokenLength Length of token.
157 * @param status Feedback status.
162 OCStackResult OCStackFeedBack(CAToken_t token, uint8_t tokenLength, uint8_t status);
166 * Handler function to execute stack requests
168 * @param protocolRequest Pointer to the protocol requests from server.
173 OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
175 OCStackResult SendDirectStackResponse(const CAEndpoint_t* endPoint, const uint16_t coapID,
176 const CAResponseResult_t responseResult, const CAMessageType_t type,
177 const uint8_t numOptions, const CAHeaderOption_t *options,
178 CAToken_t token, uint8_t tokenLength, const char *resourceUri,
179 CADataType_t dataType);
184 * Notify Presence subscribers that a resource has been modified.
186 * @param resourceType Handle to the resourceType linked list of resource that was modified.
187 * @param trigger The simplified reason this API was invoked.
189 * @return ::OC_STACK_OK on success, some other value upon failure.
191 OCStackResult SendPresenceNotification(OCResourceType *resourceType,
192 OCPresenceTrigger trigger);
195 * Send Stop Notification to Presence subscribers.
197 * @return ::OC_STACK_OK on success, some other value upon failure.
199 OCStackResult SendStopNotification();
200 #endif // WITH_PRESENCE
203 * Function to parse the IPv4 address.
205 * @param ipAddrStr Pointer to a string of IPv4 address.
206 * @param ipAddr pointer to IPv4 adress.
207 * @param port Port number.
209 * @return true on success, false upon failure.
211 bool ParseIPv4Address(char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
214 * Bind a resource interface to a resource.
216 * @param resource Target resource.
217 * @param resourceInterfaceName Resource interface.
219 * @return ::OC_STACK_OK on success, some other value upon failure.
221 OCStackResult BindResourceInterfaceToResource(OCResource* resource,
222 const char *resourceInterfaceName);
224 * Bind a resource type to a resource.
226 * @param resource Target resource.
227 * @param resourceTypeName Name of resource type.
228 * @return ::OC_STACK_OK on success, some other value upon failure.
230 OCStackResult BindResourceTypeToResource(OCResource* resource,
231 const char *resourceTypeName);
234 * Convert OCStackResult to CAResponseResult_t.
236 * @param ocCode OCStackResult code.
237 * @param method OCMethod method the return code replies to.
238 * @return ::CA_CONTENT on OK, some other value upon failure.
240 CAResponseResult_t OCToCAStackResult(OCStackResult ocCode, OCMethod method);
243 * Converts a CAResult_t type to a OCStackResult type.
245 * @param caResult CAResult_t value to convert.
246 * @return OCStackResult that was converted from the input CAResult_t value.
248 OCStackResult CAResultToOCResult(CAResult_t caResult);
251 * Converts a OCStackResult type to a bool type.
253 * @param ocResult OCStackResult value to convert.
254 * @return true on success, false upon failure.
256 bool OCResultToSuccess(OCStackResult ocResult);
259 * Map OCQualityOfService to CAMessageType.
261 * @param qos Input qos.
263 * @return CA message type for a given qos.
265 CAMessageType_t qualityOfServiceToMessageType(OCQualityOfService qos);
269 * Enable/disable a resource property.
271 * @param inputProperty Pointer to resource property.
272 * @param resourceProperties Property to be enabled/disabled.
273 * @param enable 0:disable, 1:enable.
275 * @return OCStackResult that was converted from the input CAResult_t value.
277 //TODO: should the following function be public?
278 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
279 OCResourceProperty resourceProperties, uint8_t enable);
282 const char *convertTriggerEnumToString(OCPresenceTrigger trigger);
284 OCPresenceTrigger convertTriggerStringToEnum(const char * triggerStr);
286 OCStackResult encodeAddressForRFC6874(char * outputAddress,
288 const char * inputAddress);
290 void CopyEndpointToDevAddr(const CAEndpoint_t *in, OCDevAddr *out);
292 void CopyDevAddrToEndpoint(const OCDevAddr *in, CAEndpoint_t *out);
296 #endif // __cplusplus
298 #endif /* OCSTACKINTERNAL_H_ */