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;
50 extern void* defaultDeviceHandlerCallbackParameter;
52 //-----------------------------------------------------------------------------
54 //-----------------------------------------------------------------------------
55 #define OC_COAP_SCHEME "coap://"
56 #define OC_OFFSET_SEQUENCE_NUMBER (4) // the first outgoing sequence number will be 5
59 * This structure will be created in occoap and passed up the stack on the server side.
63 // Observe option field
64 uint32_t observationOption;
65 // the REST method retrieved from received request PDU
67 // resourceUrl will be filled in occoap using the path options in received request PDU
68 char resourceUrl[MAX_URI_LENGTH];
69 // resource query send by client
70 char query[MAX_QUERY_LENGTH];
71 // reqJSON is retrieved from the payload of the received request PDU
72 uint8_t payload[MAX_REQUEST_LENGTH];
73 // qos is indicating if the request is CON or NON
74 OCQualityOfService qos;
75 // An array of the received vendor specific header options
76 uint8_t numRcvdVendorSpecificHeaderOptions;
77 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
79 /** Remote endpoint address **/
82 //token for the observe request
83 CAToken_t requestToken;
84 uint8_t tokenLength; //token length
87 uint8_t delayedResNeeded;
88 uint8_t reqMorePacket;
89 uint32_t reqPacketNum;
90 uint16_t reqPacketSize;
91 uint32_t resPacketNum;
92 uint16_t resPacketSize;
94 } OCServerProtocolRequest;
97 * This structure will be created in occoap and passed up the stack on the client side.
101 // handle is retrieved by comparing the token-handle pair in the PDU.
103 // This is how long this response is valid for (in seconds).
105 // This is the Uri of the resource. (ex. "coap://192.168.1.1/a/led")
107 // This is the relative Uri of the resource. (ex. "/a/led")
109 // This is the received payload.
112 // This is the token received OTA.
115 // this structure will be passed to client
116 OCClientResponse * clientResponse;
120 * This typedef is to represent our Server Instance identification.
122 typedef uint8_t ServerID[16];
124 //-----------------------------------------------------------------------------
125 // Internal function prototypes
126 //-----------------------------------------------------------------------------
129 OCStackResult OCStackFeedBack(CAToken_t token, uint8_t tokenLength, uint8_t status);
131 OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
133 OCStackResult SendDirectStackResponse(const CAEndpoint_t* endPoint, const uint16_t coapID,
134 const CAResponseResult_t responseResult, const CAMessageType_t type,
135 const uint8_t numOptions, const CAHeaderOption_t *options,
136 CAToken_t token, uint8_t tokenLength);
141 * Notify Presence subscribers that a resource has been modified.
143 * @param resourceType Handle to the resourceType linked list of resource
145 * @param trigger The simplified reason this API was invoked. Valid values are
146 * @ref OC_PRESENCE_TRIGGER_CREATE, @ref OC_PRESENCE_TRIGGER_CHANGE,
147 * @ref OC_PRESENCE_TRIGGER_DELETE.
148 * @return ::OC_STACK_OK on success, some other value upon failure.
150 OCStackResult SendPresenceNotification(OCResourceType *resourceType,
151 OCPresenceTrigger trigger);
154 * Send Stop Notification to Presence subscribers.
156 * @return ::OC_STACK_OK on success, some other value upon failure.
158 OCStackResult SendStopNotification();
159 #endif // WITH_PRESENCE
160 bool ParseIPv4Address(char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
163 * Bind a resource interface to a resource.
165 * @param resource Target resource.
166 * @param resourceInterfaceName Resource interface.
167 * @return ::OC_STACK_OK on success, some other value upon failure.
169 OCStackResult BindResourceInterfaceToResource(OCResource* resource,
170 const char *resourceInterfaceName);
172 * Bind a resourcetype to a resource.
174 * @param resource Target resource.
175 * @param resourceTypeName Name of resource type.
176 * @return ::OC_STACK_OK on success, some other value upon failure.
178 OCStackResult BindResourceTypeToResource(OCResource* resource,
179 const char *resourceTypeName);
181 // Converts a CAResult_t type to a OCStackResult type.
183 * Converts a CAResult_t type to a OCStackResult type.
185 * @param caResult CAResult_t value to convert
186 * @return OCStackResult that was converted from the input CAResult_t value.
188 OCStackResult CAResultToOCResult(CAResult_t caResult);
191 * Get a byte representation of the server instance ID.
192 * The memory is managed internal to this function, so freeing it externally will
193 * result in a runtime error
195 * Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
196 * This is done automatically during the OCInit process,
197 * so ensure that this call is done after that.
199 * @return A uint8_t representation the server instance ID.
201 const uint8_t* OCGetServerInstanceID(void);
204 * Get a string representation the server instance ID.
205 * The memory is managed internal to this function, so freeing externally will result
207 * Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
208 * This is done automatically during the OCInit process,
209 * so ensure that this call is done after that.
211 * @return A string representation the server instance ID.
213 const char* OCGetServerInstanceIDString(void);
216 * Map OCQualityOfService to CAMessageType.
218 * @param qos Input qos.
219 * @return CA message type for a given qos.
221 CAMessageType_t qualityOfServiceToMessageType(OCQualityOfService qos);
225 * Enable/disable a resource property.
227 * @param inputProperty Pointer to resource property.
228 * @param resourceProperties Property to be enabled/disabled.
229 * @param enable 0:disable, 1:enable.
231 * @return OCStackResult that was converted from the input CAResult_t value.
233 //TODO: should the following function be public?
234 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
235 OCResourceProperty resourceProperties, uint8_t enable);
238 const char *convertTriggerEnumToString(OCPresenceTrigger trigger);
240 OCPresenceTrigger convertTriggerStringToEnum(const char * triggerStr);
242 void CopyEndpointToDevAddr(const CAEndpoint_t *in, OCDevAddr *out);
244 void CopyDevAddrToEndpoint(const OCDevAddr *in, CAEndpoint_t *out);
248 #endif // __cplusplus
250 #endif /* OCSTACKINTERNAL_H_ */