Integrated WIFI/ETHERNET adapters to single IPAdapter.
[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 /**
58  * This structure will be created in occoap and passed up the stack on the server side.
59  */
60 typedef struct
61 {
62     // Observe option field
63     uint32_t observationOption;
64     // the REST method retrieved from received request PDU
65     OCMethod method;
66     // resourceUrl will be filled in occoap using the path options in received request PDU
67     char resourceUrl[MAX_URI_LENGTH];
68     // resource query send by client
69     char query[MAX_QUERY_LENGTH];
70     // reqJSON is retrieved from the payload of the received request PDU
71     char reqJSONPayload[MAX_REQUEST_LENGTH];
72     // qos is indicating if the request is CON or NON
73     OCQualityOfService qos;
74     // An array of the received vendor specific header options
75     uint8_t numRcvdVendorSpecificHeaderOptions;
76     OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
77
78     /** Remote Endpoint address **/
79     //////////////////////////////////////////////////////////
80     // TODO: bundle this up as endpoint
81     CAAddress_t addressInfo;
82     /** Connectivity of the endpoint**/
83     CATransportType_t connectivityType;
84
85     //token for the observe request
86     CAToken_t requestToken;
87     uint8_t tokenLength; //token length
88     // The ID of CoAP pdu
89     uint16_t coapID;
90     uint8_t delayedResNeeded;
91     uint8_t secured;
92     //////////////////////////////////////////////////////////
93     uint8_t reqMorePacket;
94     uint32_t reqPacketNum;
95     uint16_t reqPacketSize;
96     uint32_t resPacketNum;
97     uint16_t resPacketSize;
98     size_t reqTotalSize;
99 } OCServerProtocolRequest;
100
101 /**
102  * This structure will be created in occoap and passed up the stack on the client side.
103  */
104 typedef struct
105 {
106     // handle is retrieved by comparing the token-handle pair in the PDU.
107     ClientCB * cbNode;
108     // This is how long this response is valid for (in seconds).
109     uint32_t maxAge;
110     // This is the Uri of the resource. (ex. "coap://192.168.1.1/a/led")
111     char * fullUri;
112     // This is the relative Uri of the resource. (ex. "/a/led")
113     char * rcvdUri;
114     // This is the received payload.
115     char * bufRes;
116
117     // This is the token received OTA.
118     CAToken_t rcvdToken;
119
120     // this structure will be passed to client
121     OCClientResponse * clientResponse;
122 } OCResponse;
123
124 /**
125  * This typedef is to represent our Server Instance identification.
126  */
127 typedef uint32_t ServerID;
128
129 //-----------------------------------------------------------------------------
130 // Internal function prototypes
131 //-----------------------------------------------------------------------------
132
133
134 OCStackResult OCStackFeedBack(CAToken_t token, uint8_t tokenLength, uint8_t status);
135
136 OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
137
138 OCStackResult SendDirectStackResponse(const CARemoteEndpoint_t* endPoint, const uint16_t coapID,
139         const CAResponseResult_t responseResult, const CAMessageType_t type,
140         const uint8_t numOptions, const CAHeaderOption_t *options,
141         CAToken_t token, uint8_t tokenLength);
142
143
144 #ifdef WITH_PRESENCE
145 /**
146  * Notify Presence subscribers that a resource has been modified.
147  *
148  * @param resourceType Handle to the resourceType linked list of resource
149  *                     that was modified.
150  * @return ::OC_STACK_OK on success, some other value upon failure.
151  */
152 OCStackResult SendPresenceNotification(OCResourceType *resourceType);
153
154 /**
155  * Send Stop Notification to Presence subscribers.
156  *
157  * @return ::OC_STACK_OK on success, some other value upon failure.
158  */
159 OCStackResult SendStopNotification();
160 #endif // WITH_PRESENCE
161 bool ParseIPv4Address(char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
162
163 /**
164  * Bind a resource interface to a resource.
165  *
166  * @param resource Target resource.
167  * @param resourceInterfaceName Resource interface.
168  * @return ::OC_STACK_OK on success, some other value upon failure.
169  */
170 OCStackResult BindResourceInterfaceToResource(OCResource* resource,
171                                             const char *resourceInterfaceName);
172 /**
173  * Bind a resourcetype to a resource.
174  *
175  * @param resource Target resource.
176  * @param resourceTypeName Name of resource type.
177  * @return ::OC_STACK_OK on success, some other value upon failure.
178  */
179 OCStackResult BindResourceTypeToResource(OCResource* resource,
180                                             const char *resourceTypeName);
181
182 // Converts a CAResult_t type to a OCStackResult type.
183 /**
184  * Converts a CAResult_t type to a OCStackResult type.
185  *
186  * @param caResult CAResult_t value to convert
187  * @return OCStackResult that was converted from the input CAResult_t value.
188  */
189 OCStackResult CAResultToOCResult(CAResult_t caResult);
190
191 /**
192  * Get a string representation the server instance ID.
193  * The memory is managed internal to this function, so freeing externally will result
194  * in a compiler error
195  * Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
196  * This is done automatically during the OCInit process (via the call to OCInitCoAP),
197  * so ensure that this call is done after that.
198  *
199  * @return A string representation  the server instance ID.
200  */
201 const char* OCGetServerInstanceIDString(void);
202
203 /**
204  * Map OCQualityOfService to CAMessageType.
205  *
206  * @param qos Input qos.
207  * @return CA message type for a given qos.
208  */
209 CAMessageType_t qualityOfServiceToMessageType(OCQualityOfService qos);
210
211 #ifdef WITH_PRESENCE
212 /**
213  * Enable/disable a resource property.
214  *
215  * @param inputProperty Pointer to resource property.
216  * @param resourceProperties Property to be enabled/disabled.
217  * @param enable 0:disable, 1:enable.
218  *
219  * @return OCStackResult that was converted from the input CAResult_t value.
220  */
221 //TODO: should the following function be public?
222 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
223         OCResourceProperty resourceProperties, uint8_t enable);
224 #endif
225
226 #ifdef __cplusplus
227 }
228 #endif // __cplusplus
229
230 #endif /* OCSTACKINTERNAL_H_ */
231