1 //******************************************************************
3 // Copyright 2014 Intel Corporation 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 "occoaptoken.h"
33 #include "occlientcb.h"
39 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
42 #define OC_COAP_SCHEME "coap://"
44 //-----------------------------------------------------------------------------
45 // Forward declarations
46 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
52 typedef struct resourcetype_t {
53 struct resourcetype_t *next; // linked list; for multiple types on resource
55 // Name of the type; this string is ‘.’ (dot) separate list of segments where each segment is a
56 // namespace and the final segment is the type; type and sub-types can be separate with ‘-‘ (dash)
57 // usually only two segments would be defined. Either way this string is meant to be human friendly
58 // and is used opaquely and not parsed by code
59 // This name is used in the “rt=” parameter of a resource description when resources are introspected
60 // and is also use in the <base URI>/types list of available types
61 char *resourcetypename;
62 // An array of strings; each string defines the attribute and attribute data type.
63 // NOTE: this is not the same as the request/response payload representation;
64 // but is the definition of attribute/value pairs that go into the payload
65 char *typerepresentation;
68 typedef struct attr_t {
69 struct attr_t *next; // Points to next resource in list
71 // The name of the attribute; used to look up the attribute in list;
72 // for a given attribute SHOULD not be changed once assigned
74 char *attrValue; // value of the attribute as string
77 typedef struct resourceinterface_t {
78 struct resourceinterface_t *next; // linked list; for multiple interfaces on resource
80 // Name of the interface; this is ‘.’ (dot) separate list of segments where each segment is
81 // a namespace and the final segment is the interface; usually only two segments would be defined.
82 // Either way this string is opaque and not parsed by segment
84 // Allowed methods on this resource through this interface
85 // Use the methods in OCMethod to create a bitmap
86 // Example: OC_REST_GET|OC_REST_PUT.
87 uint8_t allowedMethods;
88 // Supported content types to serialize request and response on this interface
89 // (REMOVE for V1 – only jSON for all but core.ll that uses Link Format)
91 char *inputContentType ;
92 char *outputContentType ;
94 /*** Future placeholder for access control and policy ***/
95 } OCResourceInterface;
97 typedef struct rsrc_t {
98 struct rsrc_t *next; // Points to next resource in list
99 // Relative path on the device; will be combined with base url to create fully qualified path
101 OCResourceType *rsrcType; // Resource type(s); linked list
102 OCResourceInterface *rsrcInterface; // Resource interface(s); linked list
103 OCAttribute *rsrcAttributes; // Resource interface(s); linked list
104 // Array of pointers to resources; can be used to represent a container of resources
105 // (i.e. hierarchies of resources) or for reference resources (i.e. for a resource collection)
106 struct rsrc_t *rsrcResources[MAX_CONTAINED_RESOURCES];
107 //struct rsrc_t *rsrcResources;
108 // Pointer to function that handles the entity bound to the resource.
109 // This handler has to be explicitly defined by the programmer
110 OCEntityHandler entityHandler;
111 // Properties on the resource – defines meta information on the resource
112 OCResourceProperty resourceProperties ; /* ACTIVE, DISCOVERABLE etc */
113 // Pointer to an opaque object where app/user specific data can be placed with the resource;
114 // this could be information for the entity handler between invocations
116 // NOTE: Methods supported by this resource should be based on the interface targeted
117 // i.e. look into the interface structure based on the query request Can be removed here; place holder for the note above
118 /* method_t methods; */
119 // Sequence number for observable resources. Per the CoAP standard it is a 24 bit value.
120 uint32_t sequenceNum;
124 // Observe option field
125 unsigned char *option;
126 // IP address & port of client registered for observe
128 // CoAP token for the observe request
132 // following structure will be created in occoap and passed up the stack on the server side
134 // resourceUrl will be filled in occoap using the path options in received request PDU
135 unsigned char * resourceUrl;
136 // qos is indicating if the request is CON or NON
137 OCQualityOfService qos;
138 // this structure points to the information for processing observe option
139 OCObserveReq *observe;
140 // If a subscription update, this is count of observe notifications from server perspective.
141 uint32_t sequenceNum;
142 // this structure will be passed to entity handler
143 OCEntityHandlerRequest * entityHandlerRequest;
146 // 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 structure will be passed to client
151 OCClientResponse * clientResponse;
154 //-----------------------------------------------------------------------------
155 // Internal function prototypes
156 //-----------------------------------------------------------------------------
158 OCStackResult HandleStackRequests(OCRequest * request);
159 void HandleStackResponses(OCResponse * response);
160 int ParseIPv4Address(unsigned char * ipAddrStr, uint8_t * ipAddr);
162 // TODO: ultimately OCMalloc and OCFree should be defined in a different module
163 void OCFree(void *ptr);
164 void *OCMalloc(size_t size);
168 #endif // __cplusplus
170 #endif /* OCSTACKINTERNAL_H_ */