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 //-----------------------------------------------------------------------------
32 #include "ocstackconfig.h"
33 #include "occoaptoken.h"
34 #include "occlientcb.h"
43 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
46 extern OCDeviceEntityHandler defaultDeviceHandler;
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
51 #define OC_COAP_SCHEME "coap://"
52 #define OC_OFFSET_SEQUENCE_NUMBER (4) // the first outgoing sequence number will be 5
55 // Observe option field
57 // IP address & port of client registered for observe
59 // CoAP token for the observe request
61 // The result of the observe request
65 // following structure will be created in occoap and passed up the stack on the server side
67 // the REST method retrieved from received request PDU
69 // resourceUrl will be filled in occoap using the path options in received request PDU
70 unsigned char resourceUrl[MAX_URI_LENGTH];
71 // resource query send by client
72 unsigned char query[MAX_QUERY_LENGTH];
73 // reqJSON is retrieved from the payload of the received request PDU
74 unsigned char reqJSONPayload[MAX_REQUEST_LENGTH];
75 // qos is indicating if the request is CON or NON
76 OCQualityOfService qos;
77 // Observe option field
78 uint32_t observationOption;
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;
90 uint8_t delayedResNeeded;
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;
103 // qos is indicating if the request is CON or NON
104 OCQualityOfService qos;
105 // Observe option field
106 uint32_t observationOption;
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
115 // Flag indicating that response is to be delayed before sending
116 uint8_t delayedResNeeded;
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;
131 // following structure will be created in occoap and passed up the stack on the client side
133 // handle is retrieved by comparing the token-handle pair in the PDU.
135 // This is how long this response is valid for (in seconds).
137 // this structure will be passed to client
138 OCClientResponse * clientResponse;
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);
149 OCStackResult SendPresenceNotification(OCResourceType *resourceType);
152 OCStackResult BindResourceInterfaceToResource(OCResource* resource,
153 const char *resourceInterfaceName);
155 OCStackResult BindResourceTypeToResource(OCResource* resource,
156 const char *resourceTypeName);
157 OCResourceType *findResourceType(OCResourceType * resourceTypeList, const char * resourceTypeName);
160 //TODO: should the following function be public?
161 OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
162 OCResourceProperty resourceProperties, uint8_t enable);
167 #endif // __cplusplus
169 #endif /* OCSTACKINTERNAL_H_ */