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 //-----------------------------------------------------------------------------
32 #include "ocstackconfig.h"
33 #include "occoaptoken.h"
34 #include "occlientcb.h"
43 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
46 extern OCDeviceEntityHandler defaultDeviceHandler;
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
51 #define OC_COAP_SCHEME "coap://"
52 #define OC_OFFSET_SEQUENCE_NUMBER (4) // the first outgoing sequence number will be 5
54 #define OC_OBSERVER_NOT_INTERESTED (0)
55 #define OC_OBSERVER_STILL_INTERESTED (1)
56 #define OC_OBSERVER_FAILED_COMM (2)
58 //-----------------------------------------------------------------------------
59 // Virtual Resource Presence Attributes
60 //-----------------------------------------------------------------------------
62 typedef struct PRESENCERESOURCE{
63 OCResourceHandle handle;
68 //-----------------------------------------------------------------------------
69 // Forward declarations
70 //-----------------------------------------------------------------------------
73 //-----------------------------------------------------------------------------
75 //-----------------------------------------------------------------------------
77 // IF here stands for Interface
85 typedef struct resourcetype_t {
86 struct resourcetype_t *next; // linked list; for multiple types on resource
88 // Name of the type; this string is ‘.’ (dot) separate list of segments where each segment is a
89 // namespace and the final segment is the type; type and sub-types can be separate with ‘-‘ (dash)
90 // usually only two segments would be defined. Either way this string is meant to be human friendly
91 // and is used opaquely and not parsed by code
92 // This name is used in the “rt=” parameter of a resource description when resources are introspected
93 // and is also use in the <base URI>/types list of available types
94 char *resourcetypename;
97 typedef struct attr_t {
98 struct attr_t *next; // Points to next resource in list
100 // The name of the attribute; used to look up the attribute in list;
101 // for a given attribute SHOULD not be changed once assigned
102 const char *attrName;
103 char *attrValue; // value of the attribute as string
106 typedef struct resourceinterface_t {
107 struct resourceinterface_t *next; // linked list; for multiple interfaces on resource
109 // Name of the interface; this is ‘.’ (dot) separate list of segments where each segment is
110 // a namespace and the final segment is the interface; usually only two segments would be defined.
111 // Either way this string is opaque and not parsed by segment
114 // Supported content types to serialize request and response on this interface
115 // (REMOVE for V1 – only jSON for all but core.ll that uses Link Format)
117 char *inputContentType ;
118 char *outputContentType ;
120 /*** Future placeholder for access control and policy ***/
121 } OCResourceInterface;
123 typedef struct rsrc_t {
124 struct rsrc_t *next; // Points to next resource in list
125 // Relative path on the device; will be combined with base url to create fully qualified path
128 OCResourceType *rsrcType; // Resource type(s); linked list
129 OCResourceInterface *rsrcInterface; // Resource interface(s); linked list
130 OCAttribute *rsrcAttributes; // Resource interface(s); linked list
131 // Array of pointers to resources; can be used to represent a container of resources
132 // (i.e. hierarchies of resources) or for reference resources (i.e. for a resource collection)
133 struct rsrc_t *rsrcResources[MAX_CONTAINED_RESOURCES];
134 //struct rsrc_t *rsrcResources;
135 // Pointer to function that handles the entity bound to the resource.
136 // This handler has to be explicitly defined by the programmer
137 OCEntityHandler entityHandler;
138 // Properties on the resource – defines meta information on the resource
139 OCResourceProperty resourceProperties ; /* ACTIVE, DISCOVERABLE etc */
140 // Pointer to an opaque object where app/user specific data can be placed with the resource;
141 // this could be information for the entity handler between invocations
143 // NOTE: Methods supported by this resource should be based on the interface targeted
144 // i.e. look into the interface structure based on the query request Can be removed here; place holder for the note above
145 /* method_t methods; */
146 // Sequence number for observable resources. Per the CoAP standard it is a 24 bit value.
147 uint32_t sequenceNum;
151 // Observe option field
153 // IP address & port of client registered for observe
155 // CoAP token for the observe request
157 // The result of the observe request
158 OCStackResult result;
161 // following structure will be created in occoap and passed up the stack on the server side
163 // Observe option field
164 uint32_t observationOption;
165 // the REST method retrieved from received request PDU
167 // resourceUrl will be filled in occoap using the path options in received request PDU
168 unsigned char resourceUrl[MAX_URI_LENGTH];
169 // resource query send by client
170 unsigned char query[MAX_QUERY_LENGTH];
171 // reqJSON is retrieved from the payload of the received request PDU
172 unsigned char reqJSONPayload[MAX_REQUEST_LENGTH];
173 // qos is indicating if the request is CON or NON
174 OCQualityOfService qos;
175 // An array of the received vendor specific header options
176 uint8_t numRcvdVendorSpecificHeaderOptions;
177 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
178 //////////////////////////////////////////////////////////
179 // TODO: Consider moving these member to CoAP
180 // IP address & port of client registered for observe
181 OCDevAddr requesterAddr;
182 // CoAP token for the observe request
183 OCCoAPToken requestToken;
184 // The ID of CoAP pdu
186 uint8_t delayedResNeeded;
188 //////////////////////////////////////////////////////////
189 uint8_t reqMorePacket;
190 uint32_t reqPacketNum;
191 uint16_t reqPacketSize;
192 uint32_t resPacketNum;
193 uint16_t resPacketSize;
194 uint32_t reqTotalSize;
195 } OCServerProtocolRequest;
199 // Observe option field
200 uint32_t observationOption;
201 // qos is indicating if the request is CON or NON
202 OCQualityOfService qos;
203 // Allow the entity handler to pass a result with the response
204 OCStackResult result;
205 // IP address & port of client registered for observe
206 OCDevAddr *requesterAddr;
207 // CoAP token for the observe request
208 OCCoAPToken *requestToken;
209 // The ID of CoAP pdu
211 // Flag indicating that response is to be delayed before sending
212 uint8_t delayedResNeeded;
215 uint8_t notificationFlag;
216 // this is the pointer to server payload data to be transferred
217 unsigned char *payload;
218 // size of server payload data. Don't rely on null terminated data for size
219 uint16_t payloadSize;
220 // An array of the vendor specific header options the entity handler wishes to use in response
221 uint8_t numSendVendorSpecificHeaderOptions;
222 OCHeaderOption *sendVendorSpecificHeaderOptions;
223 // URI of new resource that entity handler might create
224 unsigned char * resourceUri;
225 } OCServerProtocolResponse;
227 // following structure will be created in occoap and passed up the stack on the client side
229 // handle is retrieved by comparing the token-handle pair in the PDU.
231 // This is how long this response is valid for (in seconds).
233 // this structure will be passed to client
234 OCClientResponse * clientResponse;
237 //-----------------------------------------------------------------------------
238 // Internal function prototypes
239 //-----------------------------------------------------------------------------
240 OCStackResult OCStackFeedBack(OCCoAPToken * token, uint8_t status);
241 OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
242 void HandleStackResponses(OCResponse * response);
243 int ParseIPv4Address(unsigned char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
245 OCStackResult SendPresenceNotification(OCResourceType *resourceType);
248 OCStackResult BindResourceInterfaceToResource(OCResource* resource,
249 const char *resourceInterfaceName);
251 OCStackResult BindResourceTypeToResource(OCResource* resource,
252 const char *resourceTypeName);
255 //TODO: should the following function be public?
256 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
257 OCResourceProperty resourceProperties, uint8_t enable);
262 #endif // __cplusplus
264 #endif /* OCSTACKINTERNAL_H_ */