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 //-----------------------------------------------------------------------------
55 // Virtual Resource Presence Attributes
56 //-----------------------------------------------------------------------------
58 typedef struct PRESENCERESOURCE{
59 OCResourceHandle handle;
64 //-----------------------------------------------------------------------------
65 // Forward declarations
66 //-----------------------------------------------------------------------------
69 //-----------------------------------------------------------------------------
71 //-----------------------------------------------------------------------------
73 // IF here stands for Interface
80 typedef struct resourcetype_t {
81 struct resourcetype_t *next; // linked list; for multiple types on resource
83 // Name of the type; this string is ‘.’ (dot) separate list of segments where each segment is a
84 // namespace and the final segment is the type; type and sub-types can be separate with ‘-‘ (dash)
85 // usually only two segments would be defined. Either way this string is meant to be human friendly
86 // and is used opaquely and not parsed by code
87 // This name is used in the “rt=” parameter of a resource description when resources are introspected
88 // and is also use in the <base URI>/types list of available types
89 char *resourcetypename;
92 typedef struct attr_t {
93 struct attr_t *next; // Points to next resource in list
95 // The name of the attribute; used to look up the attribute in list;
96 // for a given attribute SHOULD not be changed once assigned
98 char *attrValue; // value of the attribute as string
101 typedef struct resourceinterface_t {
102 struct resourceinterface_t *next; // linked list; for multiple interfaces on resource
104 // Name of the interface; this is ‘.’ (dot) separate list of segments where each segment is
105 // a namespace and the final segment is the interface; usually only two segments would be defined.
106 // Either way this string is opaque and not parsed by segment
109 // Supported content types to serialize request and response on this interface
110 // (REMOVE for V1 – only jSON for all but core.ll that uses Link Format)
112 char *inputContentType ;
113 char *outputContentType ;
115 /*** Future placeholder for access control and policy ***/
116 } OCResourceInterface;
118 typedef struct rsrc_t {
119 struct rsrc_t *next; // Points to next resource in list
120 // Relative path on the device; will be combined with base url to create fully qualified path
122 OCResourceType *rsrcType; // Resource type(s); linked list
123 OCResourceInterface *rsrcInterface; // Resource interface(s); linked list
124 OCAttribute *rsrcAttributes; // Resource interface(s); linked list
125 // Array of pointers to resources; can be used to represent a container of resources
126 // (i.e. hierarchies of resources) or for reference resources (i.e. for a resource collection)
127 struct rsrc_t *rsrcResources[MAX_CONTAINED_RESOURCES];
128 //struct rsrc_t *rsrcResources;
129 // Pointer to function that handles the entity bound to the resource.
130 // This handler has to be explicitly defined by the programmer
131 OCEntityHandler entityHandler;
132 // Properties on the resource – defines meta information on the resource
133 OCResourceProperty resourceProperties ; /* ACTIVE, DISCOVERABLE etc */
134 // Pointer to an opaque object where app/user specific data can be placed with the resource;
135 // this could be information for the entity handler between invocations
137 // NOTE: Methods supported by this resource should be based on the interface targeted
138 // i.e. look into the interface structure based on the query request Can be removed here; place holder for the note above
139 /* method_t methods; */
140 // Sequence number for observable resources. Per the CoAP standard it is a 24 bit value.
141 uint32_t sequenceNum;
145 // Observe option field
147 // IP address & port of client registered for observe
149 // CoAP token for the observe request
151 // The result of the observe request
152 OCStackResult result;
155 // following structure will be created in occoap and passed up the stack on the server side
157 // resourceUrl will be filled in occoap using the path options in received request PDU
158 unsigned char * resourceUrl;
159 // qos is indicating if the request is CON or NON
160 OCQualityOfService qos;
161 // this structure points to the information for processing observe option
162 OCObserveReq *observe;
163 // If a subscription update, this is count of observe notifications from server perspective.
164 uint32_t sequenceNum;
165 // this structure will be passed to entity handler
166 OCEntityHandlerRequest * entityHandlerRequest;
169 // following structure will be created in occoap and passed up the stack on the client side
171 // handle is retrieved by comparing the token-handle pair in the PDU.
173 // This is how long this response is valid for (in seconds).
175 // this structure will be passed to client
176 OCClientResponse * clientResponse;
179 //-----------------------------------------------------------------------------
180 // Internal function prototypes
181 //-----------------------------------------------------------------------------
183 OCStackResult HandleStackRequests(OCRequest * request);
184 void HandleStackResponses(OCResponse * response);
185 int ParseIPv4Address(unsigned char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
188 //TODO: should the following function be public?
189 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
190 OCResourceProperty resourceProperties, uint8_t enable);
195 #endif // __cplusplus
197 #endif /* OCSTACKINTERNAL_H_ */