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);
146 * Notify Presence subscribers that a resource has been modified.
148 * @param resourceType Handle to the resourceType linked list of resource
150 * @return ::OC_STACK_OK on success, some other value upon failure.
152 OCStackResult SendPresenceNotification(OCResourceType *resourceType);
155 * Send Stop Notification to Presence subscribers.
157 * @return ::OC_STACK_OK on success, some other value upon failure.
159 OCStackResult SendStopNotification();
160 #endif // WITH_PRESENCE
161 bool ParseIPv4Address(char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
164 * Bind a resource interface to a resource.
166 * @param resource Target resource.
167 * @param resourceInterfaceName Resource interface.
168 * @return ::OC_STACK_OK on success, some other value upon failure.
170 OCStackResult BindResourceInterfaceToResource(OCResource* resource,
171 const char *resourceInterfaceName);
173 * Bind a resourcetype to a resource.
175 * @param resource Target resource.
176 * @param resourceTypeName Name of resource type.
177 * @return ::OC_STACK_OK on success, some other value upon failure.
179 OCStackResult BindResourceTypeToResource(OCResource* resource,
180 const char *resourceTypeName);
182 // Converts a CAResult_t type to a OCStackResult type.
184 * Converts a CAResult_t type to a OCStackResult type.
186 * @param caResult CAResult_t value to convert
187 * @return OCStackResult that was converted from the input CAResult_t value.
189 OCStackResult CAResultToOCResult(CAResult_t caResult);
192 * Get a byte representation of the server instance ID.
193 * The memory is managed internal to this function, so freeing it externally will
194 * result in a runtime error
196 * Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
197 * This is done automatically during the OCInit process,
198 * so ensure that this call is done after that.
200 * @return A uint8_t representation the server instance ID.
202 const uint8_t* OCGetServerInstanceID(void);
205 * Get a string representation the server instance ID.
206 * The memory is managed internal to this function, so freeing externally will result
208 * Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
209 * This is done automatically during the OCInit process,
210 * so ensure that this call is done after that.
212 * @return A string representation the server instance ID.
214 const char* OCGetServerInstanceIDString(void);
217 * Map OCQualityOfService to CAMessageType.
219 * @param qos Input qos.
220 * @return CA message type for a given qos.
222 CAMessageType_t qualityOfServiceToMessageType(OCQualityOfService qos);
226 * Enable/disable a resource property.
228 * @param inputProperty Pointer to resource property.
229 * @param resourceProperties Property to be enabled/disabled.
230 * @param enable 0:disable, 1:enable.
232 * @return OCStackResult that was converted from the input CAResult_t value.
234 //TODO: should the following function be public?
235 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
236 OCResourceProperty resourceProperties, uint8_t enable);
241 #endif // __cplusplus
243 #endif /* OCSTACKINTERNAL_H_ */