1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH 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 //-----------------------------------------------------------------------------
33 #include "ocstackconfig.h"
34 #include "occoaptoken.h"
35 #include "occlientcb.h"
41 #include "cainterface.h"
49 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
52 extern OCDeviceEntityHandler defaultDeviceHandler;
54 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
57 #define OC_COAP_SCHEME "coap://"
58 #define OC_OFFSET_SEQUENCE_NUMBER (4) // the first outgoing sequence number will be 5
61 // TODO-CA: This has been defined in CA layer as well, but is not exposed externally.
62 // Need to expose it from CA and remove the definition below.
63 #define CA_MAX_TOKEN_LEN (8)
67 // Observe option field
69 // IP address & port of client registered for observe
71 // CoAP token for the observe request
73 // The result of the observe request
77 // following structure will be created in occoap and passed up the stack on the server side
79 // Observe option field
80 uint32_t observationOption;
81 // the REST method retrieved from received request PDU
83 // resourceUrl will be filled in occoap using the path options in received request PDU
84 unsigned char resourceUrl[MAX_URI_LENGTH];
85 // resource query send by client
86 unsigned char query[MAX_QUERY_LENGTH];
87 // reqJSON is retrieved from the payload of the received request PDU
88 unsigned char reqJSONPayload[MAX_REQUEST_LENGTH];
89 // qos is indicating if the request is CON or NON
90 OCQualityOfService qos;
91 // An array of the received vendor specific header options
92 uint8_t numRcvdVendorSpecificHeaderOptions;
93 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
95 /** Remote Endpoint address **/
96 CAAddress_t addressInfo;
97 /** Connectivity of the endpoint**/
98 CAConnectivityType_t connectivityType;
99 char token[CA_MAX_TOKEN_LEN+1];
101 //////////////////////////////////////////////////////////
102 // TODO: Consider moving these member to CoAP
103 // IP address & port of client registered for observe
104 OCDevAddr requesterAddr;
105 // CoAP token for the observe request
106 OCCoAPToken requestToken;
107 // The ID of CoAP pdu
109 uint8_t delayedResNeeded;
111 //////////////////////////////////////////////////////////
112 uint8_t reqMorePacket;
113 uint32_t reqPacketNum;
114 uint16_t reqPacketSize;
115 uint32_t resPacketNum;
116 uint16_t resPacketSize;
118 } OCServerProtocolRequest;
122 // Observe option field
123 uint32_t observationOption;
124 // qos is indicating if the request is CON or NON
125 OCQualityOfService qos;
126 // Allow the entity handler to pass a result with the response
127 OCStackResult result;
128 // IP address & port of client registered for observe
129 OCDevAddr *requesterAddr;
130 // CoAP token for the observe request
131 OCCoAPToken *requestToken;
132 // The ID of CoAP pdu
134 // Flag indicating that response is to be delayed before sending
135 uint8_t delayedResNeeded;
138 uint8_t notificationFlag;
139 // this is the pointer to server payload data to be transferred
140 unsigned char *payload;
141 // size of server payload data. Don't rely on null terminated data for size
142 uint16_t payloadSize;
143 // An array of the vendor specific header options the entity handler wishes to use in response
144 uint8_t numSendVendorSpecificHeaderOptions;
145 OCHeaderOption *sendVendorSpecificHeaderOptions;
146 // URI of new resource that entity handler might create
147 unsigned char * resourceUri;
148 } OCServerProtocolResponse;
150 // following structure will be created in occoap and passed up the stack on the client side
152 // handle is retrieved by comparing the token-handle pair in the PDU.
154 // This is how long this response is valid for (in seconds).
156 // This is the Uri of the resource. (ex. "coap://192.168.1.1/a/led")
157 unsigned char * fullUri;
158 // This is the relative Uri of the resource. (ex. "/a/led")
159 unsigned char * rcvdUri;
160 // This is the received payload.
161 unsigned char * bufRes;
162 // This is the token received OTA.
163 OCCoAPToken * rcvdToken;
164 // this structure will be passed to client
165 OCClientResponse * clientResponse;
168 // following typedef is to represent our Server Instance identification.
169 typedef uint32_t ServerID;
171 //-----------------------------------------------------------------------------
172 // Internal function prototypes
173 //-----------------------------------------------------------------------------
174 OCStackResult OCStackFeedBack(OCCoAPToken * token, uint8_t status);
175 OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
176 OCStackResult HandleStackResponses(OCResponse * response);
178 OCStackResult SendPresenceNotification(OCResourceType *resourceType);
179 #endif // WITH_PRESENCE
180 int ParseIPv4Address(unsigned char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
182 OCStackResult BindResourceInterfaceToResource(OCResource* resource,
183 const char *resourceInterfaceName);
185 OCStackResult BindResourceTypeToResource(OCResource* resource,
186 const char *resourceTypeName);
187 OCResourceType *findResourceType(OCResourceType * resourceTypeList, const char * resourceTypeName);
189 // returns the internal representation of the server instance ID.
190 // Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
191 // This is done automatically during the OCInit process (via the call to OCInitCoAP),
192 // so ensure that this call is done after that.
193 const ServerID OCGetServerInstanceID(void);
195 // returns a string representation the server instance ID.
196 // The memory is managed internal to this function, so freeing externally will result
197 // in a compiler error
198 // Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
199 // This is done automatically during the OCInit process (via the call to OCInitCoAP),
200 // so ensure that this call is done after that.
201 const char* OCGetServerInstanceIDString(void);
203 //TODO: should the following function be public?
204 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
205 OCResourceProperty resourceProperties, uint8_t enable);
210 #endif // __cplusplus
212 #endif /* OCSTACKINTERNAL_H_ */