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