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"
40 #include "cainterface.h"
42 #include "occoaptoken.h"
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
53 extern OCDeviceEntityHandler defaultDeviceHandler;
55 //-----------------------------------------------------------------------------
57 //-----------------------------------------------------------------------------
58 #define OC_COAP_SCHEME "coap://"
59 #define OC_OFFSET_SEQUENCE_NUMBER (4) // the first outgoing sequence number will be 5
62 // Observe option field
64 // IP address & port of client registered for observe
70 // token for the observe request
74 // The result of the observe request
78 // following structure will be created in occoap and passed up the stack on the server side
80 // Observe option field
81 uint32_t observationOption;
82 // the REST method retrieved from received request PDU
84 // resourceUrl will be filled in occoap using the path options in received request PDU
85 unsigned char resourceUrl[MAX_URI_LENGTH];
86 // resource query send by client
87 unsigned char query[MAX_QUERY_LENGTH];
88 // reqJSON is retrieved from the payload of the received request PDU
89 unsigned char reqJSONPayload[MAX_REQUEST_LENGTH];
90 // qos is indicating if the request is CON or NON
91 OCQualityOfService qos;
92 // An array of the received vendor specific header options
93 uint8_t numRcvdVendorSpecificHeaderOptions;
94 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
96 /** Remote Endpoint address **/
97 CAAddress_t addressInfo;
98 /** Connectivity of the endpoint**/
99 CAConnectivityType_t connectivityType;
101 //////////////////////////////////////////////////////////
102 // TODO: Consider moving these member to CoAP
103 // IP address & port of client registered for observe
104 OCDevAddr requesterAddr;
107 //token for the observe request
108 CAToken_t requestToken;
110 // CoAP token for the observe request
111 OCCoAPToken requestToken;
114 // The ID of CoAP pdu
116 uint8_t delayedResNeeded;
118 //////////////////////////////////////////////////////////
119 uint8_t reqMorePacket;
120 uint32_t reqPacketNum;
121 uint16_t reqPacketSize;
122 uint32_t resPacketNum;
123 uint16_t resPacketSize;
125 } OCServerProtocolRequest;
129 // Observe option field
130 uint32_t observationOption;
131 // qos is indicating if the request is CON or NON
132 OCQualityOfService qos;
133 // Allow the entity handler to pass a result with the response
134 OCStackResult result;
135 // IP address & port of client registered for observe
136 OCDevAddr *requesterAddr;
139 CAToken_t *requestToken;
141 // CoAP token for the observe request
142 OCCoAPToken *requestToken;
145 // The ID of CoAP pdu
147 // Flag indicating that response is to be delayed before sending
148 uint8_t delayedResNeeded;
151 uint8_t notificationFlag;
152 // this is the pointer to server payload data to be transferred
153 unsigned char *payload;
154 // size of server payload data. Don't rely on null terminated data for size
155 uint16_t payloadSize;
156 // An array of the vendor specific header options the entity handler wishes to use in response
157 uint8_t numSendVendorSpecificHeaderOptions;
158 OCHeaderOption *sendVendorSpecificHeaderOptions;
159 // URI of new resource that entity handler might create
160 unsigned char * resourceUri;
161 } OCServerProtocolResponse;
163 // following structure will be created in occoap and passed up the stack on the client side
165 // handle is retrieved by comparing the token-handle pair in the PDU.
167 // This is how long this response is valid for (in seconds).
169 // This is the Uri of the resource. (ex. "coap://192.168.1.1/a/led")
170 unsigned char * fullUri;
171 // This is the relative Uri of the resource. (ex. "/a/led")
172 unsigned char * rcvdUri;
173 // This is the received payload.
174 unsigned char * bufRes;
177 // This is the token received OTA.
178 CAToken_t * rcvdToken;
180 // This is the token received OTA.
181 OCCoAPToken * rcvdToken;
184 // this structure will be passed to client
185 OCClientResponse * clientResponse;
188 // following typedef is to represent our Server Instance identification.
189 typedef uint32_t ServerID;
191 //-----------------------------------------------------------------------------
192 // Internal function prototypes
193 //-----------------------------------------------------------------------------
196 OCStackResult OCStackFeedBack(CAToken_t * token, uint8_t status);
198 OCStackResult OCStackFeedBack(OCCoAPToken * token, uint8_t status);
201 OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
202 OCStackResult HandleStackResponses(OCResponse * response);
204 OCStackResult SendPresenceNotification(OCResourceType *resourceType);
205 #endif // WITH_PRESENCE
206 int ParseIPv4Address(unsigned char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
208 OCStackResult BindResourceInterfaceToResource(OCResource* resource,
209 const char *resourceInterfaceName);
211 OCStackResult BindResourceTypeToResource(OCResource* resource,
212 const char *resourceTypeName);
213 OCResourceType *findResourceType(OCResourceType * resourceTypeList, const char * resourceTypeName);
215 // returns the internal representation of the server instance ID.
216 // Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
217 // This is done automatically during the OCInit process (via the call to OCInitCoAP),
218 // so ensure that this call is done after that.
219 const ServerID OCGetServerInstanceID(void);
221 // returns a string representation the server instance ID.
222 // The memory is managed internal to this function, so freeing externally will result
223 // in a compiler error
224 // Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
225 // This is done automatically during the OCInit process (via the call to OCInitCoAP),
226 // so ensure that this call is done after that.
227 const char* OCGetServerInstanceIDString(void);
229 //TODO: should the following function be public?
230 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
231 OCResourceProperty resourceProperties, uint8_t enable);
236 #endif // __cplusplus
238 #endif /* OCSTACKINTERNAL_H_ */