Merge "[CA] [All] URI support , Optimization , License verification" into connectivit...
[platform/upstream/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 <stdbool.h>
32 #include "ocstack.h"
33 #include "ocstackconfig.h"
34 #include "occoaptoken.h"
35 #include "occlientcb.h"
36 #include <logger.h>
37 #include <ocrandom.h>
38
39 #ifdef CA_INT
40     #include "cacommon.h"
41     #include "cainterface.h"
42 #endif
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif // __cplusplus
47
48
49 //-----------------------------------------------------------------------------
50 // Global variables
51 //-----------------------------------------------------------------------------
52 extern OCDeviceEntityHandler defaultDeviceHandler;
53
54 //-----------------------------------------------------------------------------
55 // Defines
56 //-----------------------------------------------------------------------------
57 #define OC_COAP_SCHEME "coap://"
58 #define OC_OFFSET_SEQUENCE_NUMBER (4) // the first outgoing sequence number will be 5
59
60 typedef struct {
61     // Observe option field
62     uint32_t option;
63     // IP address & port of client registered for observe
64     OCDevAddr *subAddr;
65     // CoAP token for the observe request
66     OCCoAPToken *token;
67     // The result of the observe request
68     OCStackResult result;
69 } OCObserveReq;
70
71 // following structure will be created in occoap and passed up the stack on the server side
72 typedef struct {
73     // Observe option field
74     uint32_t observationOption;
75     // the REST method retrieved from received request PDU
76     OCMethod method;
77     // resourceUrl will be filled in occoap using the path options in received request PDU
78     unsigned char resourceUrl[MAX_URI_LENGTH];
79     // resource query send by client
80     unsigned char query[MAX_QUERY_LENGTH];
81     // reqJSON is retrieved from the payload of the received request PDU
82     unsigned char reqJSONPayload[MAX_REQUEST_LENGTH];
83     // qos is indicating if the request is CON or NON
84     OCQualityOfService qos;
85     // An array of the received vendor specific header options
86     uint8_t numRcvdVendorSpecificHeaderOptions;
87     OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
88 #ifdef CA_INT
89     /** Remote Endpoint address **/
90     CAAddress_t addressInfo;
91     /** Connectivity of the endpoint**/
92     CAConnectivityType_t connectivityType;
93     char token[32];   // TODO-CA:  What is max CAToken_t length?  Get rid of magic number
94 #endif
95     //////////////////////////////////////////////////////////
96     // TODO: Consider moving these member to CoAP
97     // IP address & port of client registered for observe
98     OCDevAddr requesterAddr;
99     // CoAP token for the observe request
100     OCCoAPToken requestToken;
101     // The ID of CoAP pdu
102     uint16_t coapID;
103     uint8_t delayedResNeeded;
104     uint8_t secured;
105     //////////////////////////////////////////////////////////
106     uint8_t reqMorePacket;
107     uint32_t reqPacketNum;
108     uint16_t reqPacketSize;
109     uint32_t resPacketNum;
110     uint16_t resPacketSize;
111     size_t reqTotalSize;
112 } OCServerProtocolRequest;
113
114 typedef struct
115 {
116     // Observe option field
117     uint32_t observationOption;
118     // qos is indicating if the request is CON or NON
119     OCQualityOfService qos;
120     // Allow the entity handler to pass a result with the response
121     OCStackResult result;
122     // IP address & port of client registered for observe
123     OCDevAddr *requesterAddr;
124     // CoAP token for the observe request
125     OCCoAPToken *requestToken;
126     // The ID of CoAP pdu
127     uint16_t coapID;
128     // Flag indicating that response is to be delayed before sending
129     uint8_t delayedResNeeded;
130     uint8_t secured;
131     uint8_t slowFlag;
132     uint8_t notificationFlag;
133     // this is the pointer to server payload data to be transferred
134     unsigned char *payload;
135     // size of server payload data.  Don't rely on null terminated data for size
136     uint16_t payloadSize;
137     // An array of the vendor specific header options the entity handler wishes to use in response
138     uint8_t numSendVendorSpecificHeaderOptions;
139     OCHeaderOption *sendVendorSpecificHeaderOptions;
140     // URI of new resource that entity handler might create
141     unsigned char * resourceUri;
142 } OCServerProtocolResponse;
143
144 // following structure will be created in occoap and passed up the stack on the client side
145 typedef struct {
146     // handle is retrieved by comparing the token-handle pair in the PDU.
147     ClientCB * cbNode;
148     // This is how long this response is valid for (in seconds).
149     uint32_t maxAge;
150     // This is the Uri of the resource. (ex. "coap://192.168.1.1/a/led")
151     unsigned char * fullUri;
152     // This is the relative Uri of the resource. (ex. "/a/led")
153     unsigned char * rcvdUri;
154     // This is the received payload.
155     unsigned char * bufRes;
156     // This is the token received OTA.
157     OCCoAPToken * rcvdToken;
158     // this structure will be passed to client
159     OCClientResponse * clientResponse;
160 } OCResponse;
161
162 // following typedef is to represent our Server Instance identification.
163 typedef uint32_t ServerID;
164
165 //-----------------------------------------------------------------------------
166 // Internal function prototypes
167 //-----------------------------------------------------------------------------
168 OCStackResult OCStackFeedBack(OCCoAPToken * token, uint8_t status);
169 OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
170 OCStackResult HandleStackResponses(OCResponse * response);
171 #ifdef WITH_PRESENCE
172 OCStackResult SendPresenceNotification(OCResourceType *resourceType);
173 #endif // WITH_PRESENCE
174 int ParseIPv4Address(unsigned char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
175
176 OCStackResult BindResourceInterfaceToResource(OCResource* resource,
177                                             const char *resourceInterfaceName);
178
179 OCStackResult BindResourceTypeToResource(OCResource* resource,
180                                             const char *resourceTypeName);
181 OCResourceType *findResourceType(OCResourceType * resourceTypeList, const char * resourceTypeName);
182
183 // returns the internal representation of the server instance ID.
184 // Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
185 // This is done automatically during the OCInit process (via the call to OCInitCoAP),
186 // so ensure that this call is done after that.
187 const ServerID OCGetServerInstanceID(void);
188
189 // returns a string representation  the server instance ID.
190 // The memory is managed internal to this function, so freeing externally will result
191 // in a compiler error
192 // Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
193 // This is done automatically during the OCInit process (via the call to OCInitCoAP),
194 // so ensure that this call is done after that.
195 const char* OCGetServerInstanceIDString(void);
196 #ifdef WITH_PRESENCE
197 //TODO: should the following function be public?
198 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
199         OCResourceProperty resourceProperties, uint8_t enable);
200 #endif
201
202 #ifdef __cplusplus
203 }
204 #endif // __cplusplus
205
206 #endif /* OCSTACKINTERNAL_H_ */