075b109bde22e13671e800136552c36073361894
[contrib/iotivity.git] / resource / csdk / stack / include / internal / ocstackinternal.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20 //
21
22 //-----------------------------------------------------------------------------
23 // Internal include file used by lower layers of the OC stack
24 //-----------------------------------------------------------------------------
25 #ifndef OCSTACKINTERNAL_H_
26 #define OCSTACKINTERNAL_H_
27
28 //-----------------------------------------------------------------------------
29 // Includes
30 //-----------------------------------------------------------------------------
31 #include "ocstack.h"
32 #include "ocstackconfig.h"
33 #include "occoaptoken.h"
34 #include "occlientcb.h"
35 #include <logger.h>
36 #include <ocrandom.h>
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif // __cplusplus
41
42
43 //-----------------------------------------------------------------------------
44 // Global variables
45 //-----------------------------------------------------------------------------
46 extern OCDeviceEntityHandler defaultDeviceHandler;
47
48 //-----------------------------------------------------------------------------
49 // Defines
50 //-----------------------------------------------------------------------------
51 #define OC_COAP_SCHEME "coap://"
52 #define OC_OFFSET_SEQUENCE_NUMBER (4) // the first outgoing sequence number will be 5
53
54 //-----------------------------------------------------------------------------
55 // Virtual Resource Presence Attributes
56 //-----------------------------------------------------------------------------
57 #ifdef WITH_PRESENCE
58 typedef struct PRESENCERESOURCE{
59     OCResourceHandle handle;
60     uint32_t presenceTTL;
61 } PresenceResource;
62 #endif
63
64 //-----------------------------------------------------------------------------
65 // Forward declarations
66 //-----------------------------------------------------------------------------
67 struct rsrc_t;
68
69 //-----------------------------------------------------------------------------
70 // Typedefs
71 //-----------------------------------------------------------------------------
72
73 // IF here stands for Interface
74 typedef enum {
75     STACK_IF_DEFAULT = 0,
76     STACK_IF_LL,
77     STACK_IF_BATCH
78 } OCStackIfTypes;
79
80 typedef struct resourcetype_t {
81     struct resourcetype_t *next; // linked list; for multiple types on resource
82
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;
90 } OCResourceType;
91
92 typedef struct attr_t {
93     struct attr_t *next; // Points to next resource in list
94
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
97     const char *attrName;
98     char *attrValue; // value of the attribute as string
99 } OCAttribute;
100
101 typedef struct resourceinterface_t {
102     struct resourceinterface_t *next; // linked list; for multiple interfaces on resource
103
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
107     char *name ;
108
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)
111 #if 0
112     char *inputContentType ;
113     char *outputContentType ;
114 #endif
115     /*** Future placeholder for access control and policy ***/
116 } OCResourceInterface;
117
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
121     char *uri;
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
136     void *context;
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;
142 } OCResource;
143
144 typedef struct {
145     // Observe option field
146     uint32_t option;
147     // IP address & port of client registered for observe
148     OCDevAddr *subAddr;
149     // CoAP token for the observe request
150     OCCoAPToken *token;
151     // The result of the observe request
152     OCStackResult result;
153 } OCObserveReq;
154
155 // following structure will be created in occoap and passed up the stack on the server side
156 typedef struct {
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;
167 } OCRequest;
168
169 // following structure will be created in occoap and passed up the stack on the client side
170 typedef struct {
171     // handle is retrieved by comparing the token-handle pair in the PDU.
172     ClientCB * cbNode;
173     // This is how long this response is valid for (in seconds).
174     uint32_t TTL;
175     // this structure will be passed to client
176     OCClientResponse * clientResponse;
177 } OCResponse;
178
179 //-----------------------------------------------------------------------------
180 // Internal function prototypes
181 //-----------------------------------------------------------------------------
182
183 OCStackResult HandleStackRequests(OCRequest * request);
184 void HandleStackResponses(OCResponse * response);
185 int ParseIPv4Address(unsigned char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
186
187 #ifdef WITH_PRESENCE
188 //TODO: should the following function be public?
189 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
190         OCResourceProperty resourceProperties, uint8_t enable);
191 #endif
192
193 #ifdef __cplusplus
194 }
195 #endif // __cplusplus
196
197 #endif /* OCSTACKINTERNAL_H_ */