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
59 // Observe option field
61 // IP address & port of client registered for observe
66 // The result of the observe request
70 // following structure will be created in occoap and passed up the stack on the server side
73 // Observe option field
74 uint32_t observationOption;
75 // the REST method retrieved from received request PDU
77 // resourceUrl will be filled in occoap using the path options in received request PDU
78 char resourceUrl[MAX_URI_LENGTH];
79 // resource query send by client
80 char query[MAX_QUERY_LENGTH];
81 // reqJSON is retrieved from the payload of the received request PDU
82 char reqJSONPayload[MAX_REQUEST_LENGTH];
83 // qos is indicating if the request is CON or NON
84 OCQualityOfService qos;
85 // An array of the received vendor specific header options
86 uint8_t numRcvdVendorSpecificHeaderOptions;
87 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
89 /** Remote Endpoint address **/
90 //////////////////////////////////////////////////////////
91 // TODO: bundle this up as endpoint
92 CAAddress_t addressInfo;
93 /** Connectivity of the endpoint**/
94 CAConnectivityType_t connectivityType;
96 //token for the observe request
97 CAToken_t requestToken;
98 uint8_t tokenLength; //token length
101 uint8_t delayedResNeeded;
103 //////////////////////////////////////////////////////////
104 uint8_t reqMorePacket;
105 uint32_t reqPacketNum;
106 uint16_t reqPacketSize;
107 uint32_t resPacketNum;
108 uint16_t resPacketSize;
110 } OCServerProtocolRequest;
114 // Observe option field
115 uint32_t observationOption;
116 // qos is indicating if the request is CON or NON
117 OCQualityOfService qos;
118 // Allow the entity handler to pass a result with the response
119 OCStackResult result;
120 // IP address & port of client registered for observe
121 OCDevAddr *requesterAddr;
123 CAToken_t *requestToken;
125 // The ID of CoAP pdu
127 // Flag indicating that response is to be delayed before sending
128 uint8_t delayedResNeeded;
131 uint8_t notificationFlag;
132 // this is the pointer to server payload data to be transferred
134 // size of server payload data. Don't rely on null terminated data for size
135 uint16_t payloadSize;
136 // An array of the vendor specific header options the entity handler wishes to use in response
137 uint8_t numSendVendorSpecificHeaderOptions;
138 OCHeaderOption *sendVendorSpecificHeaderOptions;
139 // URI of new resource that entity handler might create
141 } OCServerProtocolResponse;
143 // following structure will be created in occoap and passed up the stack on the client side
146 // handle is retrieved by comparing the token-handle pair in the PDU.
148 // 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")
152 // This is the relative Uri of the resource. (ex. "/a/led")
154 // This is the received payload.
157 // This is the token received OTA.
158 CAToken_t * rcvdToken;
160 // this structure will be passed to client
161 OCClientResponse * clientResponse;
164 // following typedef is to represent our Server Instance identification.
165 typedef uint32_t ServerID;
167 //-----------------------------------------------------------------------------
168 // Internal function prototypes
169 //-----------------------------------------------------------------------------
173 * Notify Presence subscribers that a resource has been modified
175 * @param resourceType - Handle to the resourceType linked list of resource
178 * OC_STACK_OK - no errors
179 * OC_STACK_ERROR - stack process error
181 OCStackResult SendPresenceNotification(OCResourceType *resourceType);
183 * Send Stop Notification to Presence subscribers
186 * OC_STACK_OK - no errors
187 * OC_STACK_ERROR - stack process error
190 OCStackResult SendStopNotification();
191 #endif // WITH_PRESENCE
194 * Bind a resource interface to a resource
196 * @param resource - target resource
197 * @param resourceInterfaceName - resource interface
201 OCStackResult BindResourceInterfaceToResource(OCResource* resource,
202 const char *resourceInterfaceName);
204 * Bind a resourcetype to a resource
206 * @param resource - target resource
207 * @param resourceTypeName - resourcetype
211 OCStackResult BindResourceTypeToResource(OCResource* resource,
212 const char *resourceTypeName);
214 * Finds a resource type in an OCResourceType link-list.
216 * @param resourceTypeList - the link-list to be searched through
217 * @param resourceTypeName - the key to search for
220 * resourceType that matches the key (ie. resourceTypeName)
221 * NULL - either an invalid parameter or this function was unable to find the key.
223 OCResourceType *findResourceType(OCResourceType * resourceTypeList, const char * resourceTypeName);
225 // returns the internal representation of the server instance ID.
226 // Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
227 // This is done automatically during the OCInit process (via the call to OCInitCoAP),
228 // so ensure that this call is done after that.
229 const ServerID OCGetServerInstanceID(void);
231 // Converts a CAResult_t type to a OCStackResult type.
232 OCStackResult CAResultToOCResult(CAResult_t caResult);
234 // returns a string representation the server instance ID.
235 // The memory is managed internal to this function, so freeing externally will result
236 // in a compiler error
237 // Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
238 // This is done automatically during the OCInit process (via the call to OCInitCoAP),
239 // so ensure that this call is done after that.
240 const char* OCGetServerInstanceIDString(void);
243 * Map OCQualityOfService to CAMessageType
245 * @param OCQualityOfService - Input qos.
247 * Returns CA message type for a given qos.
249 CAMessageType_t qualityOfServiceToMessageType(OCQualityOfService qos);
253 * Enable/disable a resource property
255 * @param inputProperty - pointer to resource property
256 * @param resourceProperties - property to be enabled/disabled
257 * @param enable - 0:disable, 1:enable
262 //TODO: should the following function be public?
263 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
264 OCResourceProperty resourceProperties, uint8_t enable);
269 #endif // __cplusplus
271 #endif /* OCSTACKINTERNAL_H_ */