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 // the REST method retrieved from received request PDU
70 // resourceUrl will be filled in occoap using the path options in received request PDU
71 unsigned char resourceUrl[MAX_URI_LENGTH];
72 // resource query send by client
73 unsigned char query[MAX_QUERY_LENGTH];
74 // reqJSON is retrieved from the payload of the received request PDU
75 unsigned char reqJSONPayload[MAX_REQUEST_LENGTH];
76 // qos is indicating if the request is CON or NON
77 OCQualityOfService qos;
78 // Observe option field
79 uint32_t observationOption;
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 // qos is indicating if the request is CON or NON
105 OCQualityOfService qos;
106 // Observe option field
107 uint32_t observationOption;
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 structure will be passed to client
139 OCClientResponse * clientResponse;
142 // following typedef is to represent our Server Instance identification.
143 typedef uint32_t ServerID;
145 //-----------------------------------------------------------------------------
146 // Internal function prototypes
147 //-----------------------------------------------------------------------------
148 OCStackResult OCStackFeedBack(OCCoAPToken * token, uint8_t status);
149 OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
150 void HandleStackResponses(OCResponse * response);
151 int ParseIPv4Address(unsigned char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
153 OCStackResult SendPresenceNotification(OCResourceType *resourceType);
156 OCStackResult BindResourceInterfaceToResource(OCResource* resource,
157 const char *resourceInterfaceName);
159 OCStackResult BindResourceTypeToResource(OCResource* resource,
160 const char *resourceTypeName);
161 OCResourceType *findResourceType(OCResourceType * resourceTypeList, const char * resourceTypeName);
163 // returns the internal representation of the server instance ID.
164 // Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
165 // This is done automatically during the OCInit process (via the call to OCInitCoAP),
166 // so ensure that this call is done after that.
167 const ServerID OCGetServerInstanceID(void);
169 // returns a string representation the server instance ID.
170 // The memory is managed internal to this function, so freeing externally will result
171 // in a compiler error
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 char* OCGetServerInstanceIDString(void);
177 //TODO: should the following function be public?
178 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
179 OCResourceProperty resourceProperties, uint8_t enable);
184 #endif // __cplusplus
186 #endif /* OCSTACKINTERNAL_H_ */