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"
44 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
47 extern OCDeviceEntityHandler defaultDeviceHandler;
49 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
52 #define OC_COAP_SCHEME "coap://"
53 #define OC_OFFSET_SEQUENCE_NUMBER (4) // the first outgoing sequence number will be 5
56 // Observe option field
58 // IP address & port of client registered for observe
60 // CoAP token for the observe request
62 // The result of the observe request
66 // following structure will be created in occoap and passed up the stack on the server side
68 // Observe option field
69 uint32_t observationOption;
70 // the REST method retrieved from received request PDU
72 // resourceUrl will be filled in occoap using the path options in received request PDU
73 unsigned char resourceUrl[MAX_URI_LENGTH];
74 // resource query send by client
75 unsigned char query[MAX_QUERY_LENGTH];
76 // reqJSON is retrieved from the payload of the received request PDU
77 unsigned char reqJSONPayload[MAX_REQUEST_LENGTH];
78 // qos is indicating if the request is CON or NON
79 OCQualityOfService qos;
80 // An array of the received vendor specific header options
81 uint8_t numRcvdVendorSpecificHeaderOptions;
82 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
83 //////////////////////////////////////////////////////////
84 // TODO: Consider moving these member to CoAP
85 // IP address & port of client registered for observe
86 OCDevAddr requesterAddr;
87 // CoAP token for the observe request
88 OCCoAPToken requestToken;
91 uint8_t delayedResNeeded;
93 //////////////////////////////////////////////////////////
94 uint8_t reqMorePacket;
95 uint32_t reqPacketNum;
96 uint16_t reqPacketSize;
97 uint32_t resPacketNum;
98 uint16_t resPacketSize;
99 uint32_t reqTotalSize;
100 } OCServerProtocolRequest;
104 // Observe option field
105 uint32_t observationOption;
106 // qos is indicating if the request is CON or NON
107 OCQualityOfService qos;
108 // Allow the entity handler to pass a result with the response
109 OCStackResult result;
110 // IP address & port of client registered for observe
111 OCDevAddr *requesterAddr;
112 // CoAP token for the observe request
113 OCCoAPToken *requestToken;
114 // The ID of CoAP pdu
116 // Flag indicating that response is to be delayed before sending
117 uint8_t delayedResNeeded;
120 uint8_t notificationFlag;
121 // this is the pointer to server payload data to be transferred
122 unsigned char *payload;
123 // size of server payload data. Don't rely on null terminated data for size
124 uint16_t payloadSize;
125 // An array of the vendor specific header options the entity handler wishes to use in response
126 uint8_t numSendVendorSpecificHeaderOptions;
127 OCHeaderOption *sendVendorSpecificHeaderOptions;
128 // URI of new resource that entity handler might create
129 unsigned char * resourceUri;
130 } OCServerProtocolResponse;
132 // following structure will be created in occoap and passed up the stack on the client side
134 // handle is retrieved by comparing the token-handle pair in the PDU.
136 // This is how long this response is valid for (in seconds).
138 // This is the Uri of the resource. (ex. "coap://192.168.1.1/a/led")
139 unsigned char * fullUri;
140 // This is the relative Uri of the resource. (ex. "/a/led")
141 unsigned char * rcvdUri;
142 // This is the received payload.
143 unsigned char * bufRes;
144 // This is the token received OTA.
145 OCCoAPToken * rcvdToken;
146 // this structure will be passed to client
147 OCClientResponse * clientResponse;
150 // following typedef is to represent our Server Instance identification.
151 typedef uint32_t ServerID;
153 //-----------------------------------------------------------------------------
154 // Internal function prototypes
155 //-----------------------------------------------------------------------------
156 OCStackResult OCStackFeedBack(OCCoAPToken * token, uint8_t status);
157 OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
158 OCStackResult HandleStackResponses(OCResponse * response);
160 OCStackResult SendPresenceNotification(OCResourceType *resourceType);
161 #endif // WITH_PRESENCE
162 int ParseIPv4Address(unsigned char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
164 OCStackResult BindResourceInterfaceToResource(OCResource* resource,
165 const char *resourceInterfaceName);
167 OCStackResult BindResourceTypeToResource(OCResource* resource,
168 const char *resourceTypeName);
169 OCResourceType *findResourceType(OCResourceType * resourceTypeList, const char * resourceTypeName);
171 // returns the internal representation of the server instance ID.
172 // Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
173 // This is done automatically during the OCInit process (via the call to OCInitCoAP),
174 // so ensure that this call is done after that.
175 const ServerID OCGetServerInstanceID(void);
177 // returns a string representation the server instance ID.
178 // The memory is managed internal to this function, so freeing externally will result
179 // in a compiler error
180 // Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
181 // This is done automatically during the OCInit process (via the call to OCInitCoAP),
182 // so ensure that this call is done after that.
183 const char* OCGetServerInstanceIDString(void);
185 //TODO: should the following function be public?
186 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
187 OCResourceProperty resourceProperties, uint8_t enable);
192 #endif // __cplusplus
194 #endif /* OCSTACKINTERNAL_H_ */