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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 //-----------------------------------------------------------------------------
23 // Internal include file used by lower layers of the OC stack
24 //-----------------------------------------------------------------------------
25 #ifndef OCSTACKINTERNAL_H_
26 #define OCSTACKINTERNAL_H_
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
33 #include "ocstackconfig.h"
34 #include "occlientcb.h"
39 #include "cainterface.h"
46 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
49 extern OCDeviceEntityHandler defaultDeviceHandler;
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
54 #define OC_COAP_SCHEME "coap://"
55 #define OC_OFFSET_SEQUENCE_NUMBER (4) // the first outgoing sequence number will be 5
58 * This structure will be created in occoap and passed up the stack on the server side.
62 // Observe option field
63 uint32_t observationOption;
64 // the REST method retrieved from received request PDU
66 // resourceUrl will be filled in occoap using the path options in received request PDU
67 char resourceUrl[MAX_URI_LENGTH];
68 // resource query send by client
69 char query[MAX_QUERY_LENGTH];
70 // reqJSON is retrieved from the payload of the received request PDU
71 char reqJSONPayload[MAX_REQUEST_LENGTH];
72 // qos is indicating if the request is CON or NON
73 OCQualityOfService qos;
74 // An array of the received vendor specific header options
75 uint8_t numRcvdVendorSpecificHeaderOptions;
76 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
78 /** Remote Endpoint address **/
79 //////////////////////////////////////////////////////////
80 // TODO: bundle this up as endpoint
81 CAAddress_t addressInfo;
82 /** Connectivity of the endpoint**/
83 CATransportType_t connectivityType;
85 //token for the observe request
86 CAToken_t requestToken;
87 uint8_t tokenLength; //token length
90 uint8_t delayedResNeeded;
92 //////////////////////////////////////////////////////////
93 uint8_t reqMorePacket;
94 uint32_t reqPacketNum;
95 uint16_t reqPacketSize;
96 uint32_t resPacketNum;
97 uint16_t resPacketSize;
99 } OCServerProtocolRequest;
102 * This structure will be created in occoap and passed up the stack on the client side.
106 // handle is retrieved by comparing the token-handle pair in the PDU.
108 // This is how long this response is valid for (in seconds).
110 // This is the Uri of the resource. (ex. "coap://192.168.1.1/a/led")
112 // This is the relative Uri of the resource. (ex. "/a/led")
114 // This is the received payload.
117 // This is the token received OTA.
120 // this structure will be passed to client
121 OCClientResponse * clientResponse;
125 * This typedef is to represent our Server Instance identification.
127 typedef uint8_t ServerID[16];
129 //-----------------------------------------------------------------------------
130 // Internal function prototypes
131 //-----------------------------------------------------------------------------
134 OCStackResult OCStackFeedBack(CAToken_t token, uint8_t tokenLength, uint8_t status);
136 OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
138 OCStackResult SendDirectStackResponse(const CARemoteEndpoint_t* endPoint, const uint16_t coapID,
139 const CAResponseResult_t responseResult, const CAMessageType_t type,
140 const uint8_t numOptions, const CAHeaderOption_t *options,
141 CAToken_t token, uint8_t tokenLength);
145 * The OCPresenceTrigger enum delineates the three spec-compliant modes for
146 * "Trigger." These enum values are then mapped to JSON strings
147 * "create", "change", "delete", respectively, before getting encoded into
150 * @enum OC_PRESENCE_TRIGGER_CREATE The creation of a resource is associated with
151 * this invocation of @ref SendPresenceNotification.
152 * @enum OC_PRESENCE_TRIGGER_CHANGE The change/update of a resource is associated
153 * this invocation of @ref SendPresenceNotification.
154 * @enum OC_PRESENCE_TRIGGER_DELETE The deletion of a resource is associated with
155 * this invocation of @ref SendPresenceNotification.
160 OC_PRESENCE_TRIGGER_CREATE = 0,
161 OC_PRESENCE_TRIGGER_CHANGE = 1,
162 OC_PRESENCE_TRIGGER_DELETE = 2
166 * Notify Presence subscribers that a resource has been modified.
168 * @param resourceType Handle to the resourceType linked list of resource
170 * @param trigger The simplified reason this API was invoked. Valid values are
171 * @ref OC_PRESENCE_TRIGGER_CREATE, @ref OC_PRESENCE_TRIGGER_CHANGE,
172 * @ref OC_PRESENCE_TRIGGER_DELETE.
173 * @return ::OC_STACK_OK on success, some other value upon failure.
175 OCStackResult SendPresenceNotification(OCResourceType *resourceType,
176 OCPresenceTrigger trigger);
179 * Send Stop Notification to Presence subscribers.
181 * @return ::OC_STACK_OK on success, some other value upon failure.
183 OCStackResult SendStopNotification();
184 #endif // WITH_PRESENCE
185 bool ParseIPv4Address(char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
188 * Bind a resource interface to a resource.
190 * @param resource Target resource.
191 * @param resourceInterfaceName Resource interface.
192 * @return ::OC_STACK_OK on success, some other value upon failure.
194 OCStackResult BindResourceInterfaceToResource(OCResource* resource,
195 const char *resourceInterfaceName);
197 * Bind a resourcetype to a resource.
199 * @param resource Target resource.
200 * @param resourceTypeName Name of resource type.
201 * @return ::OC_STACK_OK on success, some other value upon failure.
203 OCStackResult BindResourceTypeToResource(OCResource* resource,
204 const char *resourceTypeName);
206 // Converts a CAResult_t type to a OCStackResult type.
208 * Converts a CAResult_t type to a OCStackResult type.
210 * @param caResult CAResult_t value to convert
211 * @return OCStackResult that was converted from the input CAResult_t value.
213 OCStackResult CAResultToOCResult(CAResult_t caResult);
216 * Get a byte representation of the server instance ID.
217 * The memory is managed internal to this function, so freeing it externally will
218 * result in a runtime error
220 * Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
221 * This is done automatically during the OCInit process,
222 * so ensure that this call is done after that.
224 * @return A uint8_t representation the server instance ID.
226 const uint8_t* OCGetServerInstanceID(void);
229 * Get a string representation the server instance ID.
230 * The memory is managed internal to this function, so freeing externally will result
232 * Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
233 * This is done automatically during the OCInit process,
234 * so ensure that this call is done after that.
236 * @return A string representation the server instance ID.
238 const char* OCGetServerInstanceIDString(void);
241 * Map OCQualityOfService to CAMessageType.
243 * @param qos Input qos.
244 * @return CA message type for a given qos.
246 CAMessageType_t qualityOfServiceToMessageType(OCQualityOfService qos);
250 * Enable/disable a resource property.
252 * @param inputProperty Pointer to resource property.
253 * @param resourceProperties Property to be enabled/disabled.
254 * @param enable 0:disable, 1:enable.
256 * @return OCStackResult that was converted from the input CAResult_t value.
258 //TODO: should the following function be public?
259 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
260 OCResourceProperty resourceProperties, uint8_t enable);
264 * Clones a string IFF its pointer value is not NULL.
266 * Note: The caller to this function is responsible for calling @ref OCFree
267 * for the destination parameter.
269 * @param dest The destination string for the string value to be cloned.
271 * @param src The source for the string value to be to cloned.
273 OCStackResult CloneStringIfNonNull(char **dest, const char *src);
276 const char *convertTriggerEnumToString(OCPresenceTrigger trigger);
278 OCPresenceTrigger convertTriggerStringToEnum(const char * triggerStr);
282 #endif // __cplusplus
284 #endif /* OCSTACKINTERNAL_H_ */