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: Consider moving these member to CoAP
92 // IP address & port of client registered for observe
93 // TODO: YK bundle this up as endpoint
94 CAAddress_t addressInfo;
95 /** Connectivity of the endpoint**/
96 CAConnectivityType_t connectivityType;
98 //token for the observe request
99 CAToken_t requestToken;
101 // The ID of CoAP pdu
103 uint8_t delayedResNeeded;
105 //////////////////////////////////////////////////////////
106 uint8_t reqMorePacket;
107 uint32_t reqPacketNum;
108 uint16_t reqPacketSize;
109 uint32_t resPacketNum;
110 uint16_t resPacketSize;
112 } OCServerProtocolRequest;
116 // Observe option field
117 uint32_t observationOption;
118 // qos is indicating if the request is CON or NON
119 OCQualityOfService qos;
120 // Allow the entity handler to pass a result with the response
121 OCStackResult result;
122 // IP address & port of client registered for observe
123 OCDevAddr *requesterAddr;
125 CAToken_t *requestToken;
127 // The ID of CoAP pdu
129 // Flag indicating that response is to be delayed before sending
130 uint8_t delayedResNeeded;
133 uint8_t notificationFlag;
134 // this is the pointer to server payload data to be transferred
136 // size of server payload data. Don't rely on null terminated data for size
137 uint16_t payloadSize;
138 // An array of the vendor specific header options the entity handler wishes to use in response
139 uint8_t numSendVendorSpecificHeaderOptions;
140 OCHeaderOption *sendVendorSpecificHeaderOptions;
141 // URI of new resource that entity handler might create
143 } OCServerProtocolResponse;
145 // following structure will be created in occoap and passed up the stack on the client side
148 // handle is retrieved by comparing the token-handle pair in the PDU.
150 // This is how long this response is valid for (in seconds).
152 // This is the Uri of the resource. (ex. "coap://192.168.1.1/a/led")
154 // This is the relative Uri of the resource. (ex. "/a/led")
156 // This is the received payload.
159 // This is the token received OTA.
160 CAToken_t * rcvdToken;
162 // this structure will be passed to client
163 OCClientResponse * clientResponse;
166 // following typedef is to represent our Server Instance identification.
167 typedef uint32_t ServerID;
169 //-----------------------------------------------------------------------------
170 // Internal function prototypes
171 //-----------------------------------------------------------------------------
173 OCStackResult OCStackFeedBack(CAToken_t * token, uint8_t status);
175 OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
176 OCStackResult HandleStackResponses(OCResponse * response);
178 OCStackResult SendPresenceNotification(OCResourceType *resourceType);
179 OCStackResult SendStopNotification();
180 #endif // WITH_PRESENCE
181 int ParseIPv4Address(char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
183 OCStackResult BindResourceInterfaceToResource(OCResource* resource,
184 const char *resourceInterfaceName);
186 OCStackResult BindResourceTypeToResource(OCResource* resource,
187 const char *resourceTypeName);
188 OCResourceType *findResourceType(OCResourceType * resourceTypeList, const char * resourceTypeName);
190 // returns the internal representation of the server instance ID.
191 // Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
192 // This is done automatically during the OCInit process (via the call to OCInitCoAP),
193 // so ensure that this call is done after that.
194 const ServerID OCGetServerInstanceID(void);
196 // Converts a CAResult_t type to a OCStackResult type.
197 OCStackResult CAResultToOCResult(CAResult_t caResult);
199 // returns a string representation the server instance ID.
200 // The memory is managed internal to this function, so freeing externally will result
201 // in a compiler error
202 // Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
203 // This is done automatically during the OCInit process (via the call to OCInitCoAP),
204 // so ensure that this call is done after that.
205 const char* OCGetServerInstanceIDString(void);
207 //TODO: should the following function be public?
208 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
209 OCResourceProperty resourceProperties, uint8_t enable);
214 #endif // __cplusplus
216 #endif /* OCSTACKINTERNAL_H_ */