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 // Observe option field
60 // IP address & port of client registered for observe
65 // The result of the observe request
69 // following structure will be created in occoap and passed up the stack on the server side
71 // Observe option field
72 uint32_t observationOption;
73 // the REST method retrieved from received request PDU
75 // resourceUrl will be filled in occoap using the path options in received request PDU
76 unsigned char resourceUrl[MAX_URI_LENGTH];
77 // resource query send by client
78 unsigned char query[MAX_QUERY_LENGTH];
79 // reqJSON is retrieved from the payload of the received request PDU
80 unsigned char reqJSONPayload[MAX_REQUEST_LENGTH];
81 // qos is indicating if the request is CON or NON
82 OCQualityOfService qos;
83 // An array of the received vendor specific header options
84 uint8_t numRcvdVendorSpecificHeaderOptions;
85 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
87 /** Remote Endpoint address **/
88 //////////////////////////////////////////////////////////
89 // TODO: Consider moving these member to CoAP
90 // IP address & port of client registered for observe
91 // TODO: YK 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;
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
133 unsigned char *payload;
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
140 unsigned char * resourceUri;
141 } OCServerProtocolResponse;
143 // following structure will be created in occoap and passed up the stack on the client side
145 // handle is retrieved by comparing the token-handle pair in the PDU.
147 // This is how long this response is valid for (in seconds).
149 // This is the Uri of the resource. (ex. "coap://192.168.1.1/a/led")
150 unsigned char * fullUri;
151 // This is the relative Uri of the resource. (ex. "/a/led")
152 unsigned char * rcvdUri;
153 // This is the received payload.
154 unsigned char * bufRes;
156 // This is the token received OTA.
157 CAToken_t * rcvdToken;
159 // this structure will be passed to client
160 OCClientResponse * clientResponse;
163 // following typedef is to represent our Server Instance identification.
164 typedef uint32_t ServerID;
166 //-----------------------------------------------------------------------------
167 // Internal function prototypes
168 //-----------------------------------------------------------------------------
170 OCStackResult OCStackFeedBack(CAToken_t * token, uint8_t status);
172 OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
173 OCStackResult HandleStackResponses(OCResponse * response);
175 OCStackResult SendPresenceNotification(OCResourceType *resourceType);
176 #endif // WITH_PRESENCE
177 int ParseIPv4Address(unsigned char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
179 OCStackResult BindResourceInterfaceToResource(OCResource* resource,
180 const char *resourceInterfaceName);
182 OCStackResult BindResourceTypeToResource(OCResource* resource,
183 const char *resourceTypeName);
184 OCResourceType *findResourceType(OCResourceType * resourceTypeList, const char * resourceTypeName);
186 // returns the internal representation of the server instance ID.
187 // Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
188 // This is done automatically during the OCInit process (via the call to OCInitCoAP),
189 // so ensure that this call is done after that.
190 const ServerID OCGetServerInstanceID(void);
192 // Converts a CAResult_t type to a OCStackResult type.
193 static OCStackResult CAResultToOCResult(CAResult_t caResult);
195 // returns a string representation the server instance ID.
196 // The memory is managed internal to this function, so freeing externally will result
197 // in a compiler error
198 // Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
199 // This is done automatically during the OCInit process (via the call to OCInitCoAP),
200 // so ensure that this call is done after that.
201 const char* OCGetServerInstanceIDString(void);
203 //TODO: should the following function be public?
204 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
205 OCResourceProperty resourceProperties, uint8_t enable);
210 #endif // __cplusplus
212 #endif /* OCSTACKINTERNAL_H_ */