Modifying version number for building on tizen 3.0
[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 "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 typedef struct {
55     // Observe option field
56     uint32_t option;
57     // IP address & port of client registered for observe
58     OCDevAddr *subAddr;
59     // CoAP token for the observe request
60     OCCoAPToken *token;
61     // The result of the observe request
62     OCStackResult result;
63 } OCObserveReq;
64
65 // following structure will be created in occoap and passed up the stack on the server side
66 typedef struct {
67     // Observe option field
68     uint32_t observationOption;
69     // the REST method retrieved from received request PDU
70     OCMethod method;
71     // resourceUrl will be filled in occoap using the path options in received request PDU
72     unsigned char resourceUrl[MAX_URI_LENGTH];
73     // resource query send by client
74     unsigned char query[MAX_QUERY_LENGTH];
75     // reqJSON is retrieved from the payload of the received request PDU
76     unsigned char reqJSONPayload[MAX_REQUEST_LENGTH];
77     // qos is indicating if the request is CON or NON
78     OCQualityOfService qos;
79     // An array of the received vendor specific header options
80     uint8_t numRcvdVendorSpecificHeaderOptions;
81     OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
82     //////////////////////////////////////////////////////////
83     // TODO: Consider moving these member to CoAP
84     // IP address & port of client registered for observe
85     OCDevAddr requesterAddr;
86     // CoAP token for the observe request
87     OCCoAPToken requestToken;
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     uint32_t reqTotalSize;
99 } OCServerProtocolRequest;
100
101 typedef struct
102 {
103     // Observe option field
104     uint32_t observationOption;
105     // qos is indicating if the request is CON or NON
106     OCQualityOfService qos;
107     // Allow the entity handler to pass a result with the response
108     OCStackResult result;
109     // IP address & port of client registered for observe
110     OCDevAddr *requesterAddr;
111     // CoAP token for the observe request
112     OCCoAPToken *requestToken;
113     // The ID of CoAP pdu
114     uint16_t coapID;
115     // Flag indicating that response is to be delayed before sending
116     uint8_t delayedResNeeded;
117     uint8_t secured;
118     uint8_t slowFlag;
119     uint8_t notificationFlag;
120     // this is the pointer to server payload data to be transferred
121     unsigned char *payload;
122     // size of server payload data.  Don't rely on null terminated data for size
123     uint16_t payloadSize;
124     // An array of the vendor specific header options the entity handler wishes to use in response
125     uint8_t numSendVendorSpecificHeaderOptions;
126     OCHeaderOption *sendVendorSpecificHeaderOptions;
127     // URI of new resource that entity handler might create
128     unsigned char * resourceUri;
129 } OCServerProtocolResponse;
130
131 // following structure will be created in occoap and passed up the stack on the client side
132 typedef struct {
133     // handle is retrieved by comparing the token-handle pair in the PDU.
134     ClientCB * cbNode;
135     // This is how long this response is valid for (in seconds).
136     uint32_t TTL;
137     // this structure will be passed to client
138     OCClientResponse * clientResponse;
139 } OCResponse;
140
141 //-----------------------------------------------------------------------------
142 // Internal function prototypes
143 //-----------------------------------------------------------------------------
144 OCStackResult OCStackFeedBack(OCCoAPToken * token, uint8_t status);
145 OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
146 void HandleStackResponses(OCResponse * response);
147 int ParseIPv4Address(unsigned char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
148 #ifdef WITH_PRESENCE
149 OCStackResult SendPresenceNotification(OCResourceType *resourceType);
150 #endif
151
152 OCStackResult BindResourceInterfaceToResource(OCResource* resource,
153                                             const char *resourceInterfaceName);
154
155 OCStackResult BindResourceTypeToResource(OCResource* resource,
156                                             const char *resourceTypeName);
157 OCResourceType *findResourceType(OCResourceType * resourceTypeList, const char * resourceTypeName);
158
159 #ifdef WITH_PRESENCE
160 //TODO: should the following function be public?
161 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
162         OCResourceProperty resourceProperties, uint8_t enable);
163 #endif
164
165 #ifdef __cplusplus
166 }
167 #endif // __cplusplus
168
169 #endif /* OCSTACKINTERNAL_H_ */