IP address plumbing changes to support IPv6
[platform/upstream/iotivity.git] / resource / csdk / stack / include / octypes.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 #ifndef OCTYPES_H_
22 #define OCTYPES_H_
23
24 #include "ocstackconfig.h"
25
26 #ifdef __cplusplus
27 #include <string.h>
28
29 extern "C" {
30 #endif // __cplusplus
31 #define WITH_PRESENCE
32 //-----------------------------------------------------------------------------
33 // Defines
34 //-----------------------------------------------------------------------------
35 #define OC_WELL_KNOWN_QUERY                  "/oic/res"
36 #define OC_MULTICAST_DISCOVERY_URI           "/oic/res"
37
38 #ifdef WITH_PRESENCE
39 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
40 /// OC_MAX_PRESENCE_TTL_SECONDS sets the maximum time to live (TTL) for presence.
41 /// NOTE: Changing the setting to a longer duration may lead to unsupported and untested
42 /// operation.
43 #define OC_MAX_PRESENCE_TTL_SECONDS     (60 * 60 * 24) // 60 sec/min * 60 min/hr * 24 hr/day
44 #define OC_PRESENCE_URI                      "/oic/ad"
45 #endif
46
47 ///Separtor for multiple query string
48 #define OC_QUERY_SEPARATOR                "&;"
49
50 /**
51  * Attributes used to form a proper OIC conforming JSON message.
52  */
53 #define OC_RSRVD_OC                     "oic"
54 #define OC_RSRVD_PAYLOAD                "payload"
55 #define OC_RSRVD_HREF                   "href"
56 #define OC_RSRVD_PROPERTY               "prop"
57 #define OC_RSRVD_REPRESENTATION         "rep"
58 #define OC_RSRVD_CONTENT_TYPE           "ct"
59 #define OC_RSRVD_RESOURCE_TYPE          "rt"
60 #define OC_RSRVD_RESOURCE_TYPE_PRESENCE "oic.wk.ad"
61 #define OC_RSRVD_INTERFACE              "if"
62 #define OC_RSRVD_TTL                    "ttl"
63 #define OC_RSRVD_NONCE                  "non"
64 #define OC_RSRVD_TRIGGER                "trg"
65
66 #define OC_RSRVD_INTERFACE_DEFAULT      "oic.if.baseline"
67 #define OC_RSRVD_INTERFACE_LL           "oic.if.ll"
68 #define OC_RSRVD_INTERFACE_BATCH        "oic.if.b"
69 #define OC_RSRVD_INTERFACE_GROUP        "oic.mi.grp"
70 #define OC_RSRVD_MFG_DATE               "mndt"
71 #define OC_RSRVD_FW_VERSION             "mnfv"
72 #define OC_RSRVD_HOST_NAME              "hn"
73 #define OC_RSRVD_VERSION                "icv"
74 #define OC_RSRVD_POLICY                 "p"
75 #define OC_RSRVD_BITMAP                 "bm"
76 #define OC_RSRVD_SECURE                 "sec"
77 #define OC_RSRVD_HOSTING_PORT           "port"
78 #define OC_RSRVD_SERVER_INSTANCE_ID     "sid"
79
80 //**** Presence "Announcement Triggers" ****
81 #define OC_RSRVD_TRIGGER_CREATE         "create"
82 #define OC_RSRVD_TRIGGER_CHANGE         "change"
83 #define OC_RSRVD_TRIGGER_DELETE         "delete"
84 //*******************
85
86 //**** Platform ****
87 #define OC_RSRVD_PLATFORM_ID            "pi"
88 #define OC_RSRVD_MFG_NAME               "mnmn"
89 #define OC_RSRVD_MFG_URL                "mnml"
90 #define OC_RSRVD_MODEL_NUM              "mnmo"
91 #define OC_RSRVD_MFG_DATE               "mndt"
92 #define OC_RSRVD_PLATFORM_VERSION       "mnpv"
93 #define OC_RSRVD_OS_VERSION             "mnos"
94 #define OC_RSRVD_HARDWARE_VERSION       "mnhw"
95 #define OC_RSRVD_FIRMWARE_VERSION       "mnfv"
96 #define OC_RSRVD_SUPPORT_URL            "mnsl"
97 #define OC_RSRVD_SYSTEM_TIME             "st"
98 //*******************
99
100 //**** Device ****
101 #define OC_RSRVD_DEVICE_ID              "di"
102 #define OC_RSRVD_DEVICE_NAME            "n"
103 #define OC_RSRVD_SPEC_VERSION           "lcv"
104 #define OC_RSRVD_DATA_MODEL_VERSION     "dmv"
105
106 #define OC_SPEC_VERSION                "0.9.0"
107 #define OC_DATA_MODEL_VERSION          "sec.0.95"
108 //*******************
109
110 // These provide backward compatibility - their use is deprecated
111 #ifndef GOING_AWAY
112 #define OC_MULTICAST_PREFIX                  "224.0.1.187:5683"
113 #define OC_MULTICAST_IP                      "224.0.1.187:5683"
114 #define OC_MULTICAST_PORT                    5683
115 #endif // GOING_AWAY
116
117 //-----------------------------------------------------------------------------
118 // Typedefs
119 //-----------------------------------------------------------------------------
120
121 #define MAX_ADDR_STR_SIZE (40)
122 #define MAX_IDENTITY_SIZE (32)
123
124 /*
125  * These enums (OCTransportAdapter and OCTransportFlags) must
126  * be kept synchronized with OCConnectivityType (below) as well as
127  * CATransportAdapter and CATransportFlags (in CACommon.h).
128  */
129
130 typedef enum
131 {
132     OC_DEFAULT_ADAPTER = 0,
133
134     // value zero indicates discovery
135     OC_ADAPTER_IP           = (1 << 0),   // IPv4 and IPv6, including 6LoWPAN
136     OC_ADAPTER_GATT_BTLE    = (1 << 1),   // GATT over Bluetooth LE
137     OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),   // RFCOMM over Bluetooth EDR
138 } OCTransportAdapter;
139
140 // enum layout assumes some targets have 16-bit integer (e.g., Arduino)
141 typedef enum
142 {
143     OC_DEFAULT_FLAGS = 0,
144
145     // Insecure transport is the default (subject to change)
146     OC_FLAG_SECURE     = (1 << 4),   // secure the transport path
147
148     // IPv4 & IPv6 autoselection is the default
149     OC_IP_USE_V6       = (1 << 5),   // IP adapter only
150     OC_IP_USE_V4       = (1 << 6),   // IP adapter only
151
152     // Link-Local multicast is the default multicast scope for IPv6.
153     // These are placed here to correspond to the IPv6 multicast address bits.
154     OC_SCOPE_INTERFACE = 0x1, // IPv6 Interface-Local scope (loopback)
155     OC_SCOPE_LINK      = 0x2, // IPv6 Link-Local scope (default)
156     OC_SCOPE_REALM     = 0x3, // IPv6 Realm-Local scope
157     OC_SCOPE_ADMIN     = 0x4, // IPv6 Admin-Local scope
158     OC_SCOPE_SITE      = 0x5, // IPv6 Site-Local scope
159     OC_SCOPE_ORG       = 0x8, // IPv6 Organization-Local scope
160     OC_SCOPE_GLOBAL    = 0xE, // IPv6 Global scope
161 } OCTransportFlags;
162
163 #define OC_MASK_SCOPE    (0x000F)
164 #define OC_MASK_MODS     (0x0FF0)
165
166 /*
167  * endpoint identity
168  */
169 typedef struct
170 {
171     uint16_t id_length;
172     unsigned char id[MAX_IDENTITY_SIZE];
173 } OCIdentity;
174
175 /**
176  * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
177  *
178  * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
179  */
180 typedef struct
181 {
182     OCTransportAdapter      adapter;    // adapter type
183     OCTransportFlags        flags;      // transport modifiers
184     char                    addr[MAX_ADDR_STR_SIZE]; // address for all adapters
185     uint32_t                interface;  // usually zero for default interface
186     uint16_t                port;       // for IP
187     OCIdentity              identity;   // secure node identity
188 } OCDevAddr;
189
190 /*
191  * OCConnectivityType includes elements of both OCTransportAdapter
192  * and OCTransportFlags. It is defined conditionally because the
193  * smaller definition limits expandability on 32/64 bit integer machines,
194  * and the larger definition won't fit into an enum on 16-bit integer
195  * machines like Arduino.
196  *
197  * This structure must directly correspond to OCTransportAdapter
198  * and OCTransportFlags.
199  */
200 typedef enum
201 {
202     CT_DEFAULT = 0,                // use when defaults are ok
203
204     #if defined (__UINT32_MAX__) && (__UINT32_MAX__ == 65535) // 16-bit int
205     CT_ADAPTER_IP           = (1 << 10),  // IPv4 and IPv6, including 6LoWPAN
206     CT_ADAPTER_GATT_BTLE    = (1 << 11),  // GATT over Bluetooth LE
207     CT_ADAPTER_RFCOMM_BTEDR = (1 << 12),  // RFCOMM over Bluetooth EDR
208     #define CT_ADAPTER_SHIFT 10
209     #define CT_MASK_FLAGS 0x03FF
210     #define CT_MASK_ADAPTER 0xFC00
211     #else   // assume 32-bit int
212     CT_ADAPTER_IP           = (1 << 16),  // IPv4 and IPv6, including 6LoWPAN
213     CT_ADAPTER_GATT_BTLE    = (1 << 17),  // GATT over Bluetooth LE
214     CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),  // RFCOMM over Bluetooth EDR
215     #define CT_ADAPTER_SHIFT 16
216     #define CT_MASK_FLAGS 0xFFFF
217     #define CT_MASK_ADAPTER 0xFFFF0000
218     #endif
219
220     // Insecure transport is the default (subject to change)
221     CT_FLAG_SECURE     = (1 << 4), // secure the transport path
222
223     // IPv4 & IPv6 autoselection is the default
224     CT_IP_USE_V6       = (1 << 5), // IP adapter only
225     CT_IP_USE_V4       = (1 << 6), // IP adapter only
226
227     // Link-Local multicast is the default multicast scope for IPv6.
228     // These are placed here to correspond to the IPv6 address bits.
229     CT_SCOPE_INTERFACE = 0x1, // IPv6 Interface-Local scope (loopback)
230     CT_SCOPE_LINK      = 0x2, // IPv6 Link-Local scope (default)
231     CT_SCOPE_REALM     = 0x3, // IPv6 Realm-Local scope
232     CT_SCOPE_ADMIN     = 0x4, // IPv6 Admin-Local scope
233     CT_SCOPE_SITE      = 0x5, // IPv6 Site-Local scope
234     CT_SCOPE_ORG       = 0x8, // IPv6 Organization-Local scope
235     CT_SCOPE_GLOBAL    = 0xE, // IPv6 Global scope
236 } OCConnectivityType;
237
238 /**
239  * OC Virtual resources supported by every OC device.
240  */
241 typedef enum
242 {
243     OC_WELL_KNOWN_URI= 0,       ///< "/oic/res"
244     OC_DEVICE_URI,              ///< "/oic/d"
245     OC_PLATFORM_URI,            ///< "/oic/p"
246     OC_RESOURCE_TYPES_URI,      ///< "/oic/res/d/type"
247     #ifdef WITH_PRESENCE
248     OC_PRESENCE,                ///< "/oic/ad"
249     #endif
250     OC_MAX_VIRTUAL_RESOURCES    ///<s Max items in the list
251 } OCVirtualResources;
252
253 /**
254  *  OCDoResource methods
255  */
256 typedef enum
257 {
258     OC_REST_NOMETHOD       = 0,
259     OC_REST_GET            = (1 << 0),     ///< Read
260     OC_REST_PUT            = (1 << 1),     ///< Write
261     OC_REST_POST           = (1 << 2),     ///< Update
262     OC_REST_DELETE         = (1 << 3),     ///< Delete
263     /// Register observe request for most up date notifications ONLY.
264     OC_REST_OBSERVE        = (1 << 4),
265     /// Register observe request for all notifications, including stale notifications.
266     OC_REST_OBSERVE_ALL    = (1 << 5),
267     /// Deregister observation, intended for internal use
268     OC_REST_CANCEL_OBSERVE = (1 << 6),
269     #ifdef WITH_PRESENCE
270     /// Subscribe for all presence notifications of a particular resource.
271     OC_REST_PRESENCE       = (1 << 7),
272     #endif
273     /// Allows OCDoResource caller to do discovery.
274     OC_REST_DISCOVER       = (1 << 8)
275 } OCMethod;
276
277 /**
278  * Host Mode of Operation.
279  */
280 typedef enum
281 {
282     OC_CLIENT = 0,
283     OC_SERVER,
284     OC_CLIENT_SERVER
285 } OCMode;
286
287 /**
288  * Quality of Service.
289  *
290  * OCQualityOfService attempts to abstract the guarantees provided by the underlying transport
291  * protocol.  The precise definitions of each quality of service level depend on the
292  * implementation.  In descriptions below are for the current implementation and may changed
293  * over time.
294  */
295 typedef enum
296 {
297     /// Packet delivery is best effort
298     OC_LOW_QOS = 0,
299     /// Packet delivery is best effort
300     OC_MEDIUM_QOS,
301     /// Acknowledgements are used to confirm delivery
302     OC_HIGH_QOS,
303     /// No Quality is defined, let the stack decide
304     OC_NA_QOS
305 } OCQualityOfService;
306
307 /**
308  * Resource Properties.
309  * The value of a policy property is defined as bitmap.
310  * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
311  * Not including the policy property is equivalent to zero.
312  *
313  * ::OC_RES_PROP_NONE When none of the bits are set, the resource is non-discoverable &
314  *                    non-observable by the client.
315  * ::OC_DISCOVERABLE When this bit is set, the resource is allowed to be discovered by clients.
316  * ::OC_OBSERVABLE   When this bit is set, the resource is allowed to be observed by clients.
317  * ::OC_ACTIVE        When this bit is set, the resource is initialized, otherwise the resource
318  *                    is 'inactive'. 'inactive' signifies that the resource has been marked for
319  *                    deletion or is already deleted.
320  * ::OC_SLOW          When this bit is set, the resource has been marked as 'slow'. 'slow'
321  *                    signifies that responses from this resource can expect delays in
322  *                    processing its requests from clients.
323  * ::OC_SECURE        When this bit is set, the resource is a secure resource.
324  */
325 typedef enum
326 {
327     OC_RES_PROP_NONE = (0),
328     OC_DISCOVERABLE  = (1 << 0),
329     OC_OBSERVABLE    = (1 << 1),
330     OC_ACTIVE        = (1 << 2),
331     OC_SLOW          = (1 << 3),
332     OC_SECURE        = (1 << 4)
333 } OCResourceProperty;
334
335 /**
336  * Transport Protocol IDs.
337  */
338 typedef enum
339 {
340     OC_INVALID_ID   = (1 << 0),
341     OC_COAP_ID      = (1 << 1)
342 } OCTransportProtocolID;
343
344 /**
345  * Declares Stack Results & Errors.
346  */
347 typedef enum
348 {
349     /* Success status code - START HERE */
350     OC_STACK_OK = 0,
351     OC_STACK_RESOURCE_CREATED,
352     OC_STACK_RESOURCE_DELETED,
353     OC_STACK_CONTINUE,
354     /* Success status code - END HERE */
355     /* Error status code - START HERE */
356     OC_STACK_INVALID_URI = 20,
357     OC_STACK_INVALID_QUERY,
358     OC_STACK_INVALID_IP,
359     OC_STACK_INVALID_PORT,
360     OC_STACK_INVALID_CALLBACK,
361     OC_STACK_INVALID_METHOD,
362     OC_STACK_INVALID_PARAM,
363     OC_STACK_INVALID_OBSERVE_PARAM,
364     OC_STACK_NO_MEMORY,
365     OC_STACK_COMM_ERROR,
366     OC_STACK_TIMEOUT,
367     OC_STACK_ADAPTER_NOT_ENABLED,
368     OC_STACK_NOTIMPL,
369     OC_STACK_NO_RESOURCE,               /* resource not found */
370     OC_STACK_RESOURCE_ERROR,            /* ex: not supported method or interface */
371     OC_STACK_SLOW_RESOURCE,
372     OC_STACK_DUPLICATE_REQUEST,
373     OC_STACK_NO_OBSERVERS,              /* resource has no registered observers */
374     OC_STACK_OBSERVER_NOT_FOUND,
375     OC_STACK_VIRTUAL_DO_NOT_HANDLE,
376     OC_STACK_INVALID_OPTION,
377     OC_STACK_MALFORMED_RESPONSE,        /* the remote reply contained malformed data */
378     OC_STACK_PERSISTENT_BUFFER_REQUIRED,
379     OC_STACK_INVALID_REQUEST_HANDLE,
380     OC_STACK_INVALID_DEVICE_INFO,
381     OC_STACK_INVALID_JSON,
382     /* NOTE: Insert all new error codes here!*/
383     #ifdef WITH_PRESENCE
384     OC_STACK_PRESENCE_STOPPED = 128,
385     OC_STACK_PRESENCE_TIMEOUT,
386     OC_STACK_PRESENCE_DO_NOT_HANDLE,
387     #endif
388     OC_STACK_ERROR = 255
389     /* Error status code - END HERE */
390 } OCStackResult;
391
392 /**
393  * Handle to an @ref OCDoResource invocation.
394  */
395 typedef void * OCDoHandle;
396
397 /**
398  * Handle to an OCResource object owned by the OCStack.
399  */
400 typedef void * OCResourceHandle;
401
402 typedef void * OCRequestHandle;
403
404 /**
405  * Unique identifier for each observation request. Used when observations are
406  * registered or deregistering. Used by entity handler to signal specific
407  * observers to be notified of resource changes.
408  * There can be maximum of 256 observations per server.
409  */
410 typedef uint8_t OCObservationId;
411
412 /**
413  * Action associated with observation.
414  */
415 typedef enum
416 {
417     OC_OBSERVE_REGISTER = 0,
418     OC_OBSERVE_DEREGISTER = 1,
419     OC_OBSERVE_NO_OPTION = 2
420 } OCObserveAction;
421
422
423 /**
424  * Persistent storage handlers. An app must provide OCPersistentStorage handler pointers when it
425  * calls OCRegisterPersistentStorageHandler.
426  */
427 typedef struct {
428     /*
429      *  Persistent storage open handler points to default file path.
430      *  Application can point to appropriate SVR database path for its Iotivity Server.
431      */
432     FILE* (* open)(const char *path, const char *mode);
433     // Persistent storage read handler
434     size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
435     // Persistent storage write handler
436     size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
437     // Persistent storage close handler
438     int (* close)(FILE *fp);
439     // Persistent storage unlink handler
440     int (* unlink)(const char *path);
441 } OCPersistentStorage;
442
443 typedef struct
444 {
445     // Action associated with observation request
446     OCObserveAction action;
447     // Identifier for observation being registered/deregistered
448     OCObservationId obsId;
449 } OCObservationInfo;
450
451 /**
452  * Possible returned values from entity handler.
453  */
454 typedef enum
455 {
456     OC_EH_OK = 0,
457     OC_EH_ERROR,
458     OC_EH_RESOURCE_CREATED,
459     OC_EH_RESOURCE_DELETED,
460     OC_EH_SLOW,
461     OC_EH_FORBIDDEN,
462     OC_EH_RESOURCE_NOT_FOUND
463 } OCEntityHandlerResult;
464
465 /**
466  * This structure will be used to define the vendor specific header options to be included
467  * in communication packets.
468  */
469 typedef struct OCHeaderOption
470 {
471     // The protocol ID this option applies to
472     OCTransportProtocolID protocolID;
473     // The header option ID which will be added to communication packets
474     uint16_t optionID;
475     // its length   191
476     uint16_t optionLength;
477     // pointer to its data
478     uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
479
480 #ifdef __cplusplus
481     OCHeaderOption() = default;
482     OCHeaderOption(OCTransportProtocolID pid,
483                    uint16_t optId,
484                    uint16_t optlen,
485                    const uint8_t* optData)
486         : protocolID(pid),
487           optionID(optId),
488           optionLength(optlen)
489     {
490
491         // parameter includes the null terminator.
492         optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
493                         optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
494         memcpy(optionData, optData, optionLength);
495         optionData[optionLength - 1] = '\0';
496     }
497 #endif
498 } OCHeaderOption;
499
500 /**
501  * Incoming requests handled by the server. Requests are passed in as a parameter to the
502  * @ref OCEntityHandler callback API.
503  * @brief The @ref OCEntityHandler callback API must be implemented in the application in order
504  * to receive these requests.
505  */
506 typedef struct
507 {
508     // Associated resource
509     OCResourceHandle resource;
510     OCRequestHandle requestHandle;
511     // the REST method retrieved from received request PDU
512     OCMethod method;
513     // resource query send by client
514     char * query;
515     // Information associated with observation - valid only when OCEntityHandler
516     // flag includes OC_OBSERVE_FLAG
517     OCObservationInfo obsInfo;
518     // An array of the received vendor specific header options
519     uint8_t numRcvdVendorSpecificHeaderOptions;
520     OCHeaderOption * rcvdVendorSpecificHeaderOptions;
521     // reqJSON is retrieved from the payload of the received request PDU
522     char * reqJSONPayload;
523 } OCEntityHandlerRequest;
524
525 /**
526  * Response from queries to remote servers. Queries are made by calling the @ref OCDoResource API.
527  */
528 typedef struct
529 {
530     /// Address of remote server
531     OCDevAddr devAddr;
532     OCDevAddr *addr;            // backward compatibility (points to devAddr)
533     OCConnectivityType connType;  // backward compatibility
534     /// the is the result of our stack, OCStackResult should contain coap/other error codes;
535     OCStackResult result;
536     /// If associated with observe, this will represent the sequence of notifications from server.
537     uint32_t sequenceNumber;
538     /// resourceURI
539     const char * resourceUri;
540     /// resJSONPayload is retrieved from the payload of the received request PDU
541     const char * resJSONPayload;
542     /// An array of the received vendor specific header options
543     uint8_t numRcvdVendorSpecificHeaderOptions;
544     OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
545 } OCClientResponse;
546
547 /**
548  * This structure describes the platform properties. All non-Null properties will be included
549  * in a platform discovery request.
550  */
551 typedef struct
552 {
553     char *platformID;
554     char *manufacturerName;
555     char *manufacturerUrl;
556     char *modelNumber;
557     char *dateOfManufacture;
558     char *platformVersion;
559     char *operatingSystemVersion;
560     char *hardwareVersion;
561     char *firmwareVersion;
562     char *supportUrl;
563     char *systemTime;
564
565 } OCPlatformInfo;
566
567 /**
568  * This structure is expected as input for device properties.
569  * device name is mandatory and expected from the application.
570  * device id of type UUID will be generated by the stack.
571  */
572 typedef struct
573 {
574     char *deviceName;
575
576 } OCDeviceInfo;
577
578 typedef struct
579 {
580     // Request handle is passed to server via the entity handler for each incoming request.
581     // Stack assigns when request is received, server sets to indicate what request response is for
582     OCRequestHandle requestHandle;
583     // Resource handle
584     OCResourceHandle resourceHandle;
585     // Allow the entity handler to pass a result with the response
586     OCEntityHandlerResult  ehResult;
587     // this is the pointer to server payload data to be transferred
588     char *payload;
589     // size of server payload data.  I don't think we should rely on null terminated data for size
590     uint16_t payloadSize;
591     // An array of the vendor specific header options the entity handler wishes to use in response
592     uint8_t numSendVendorSpecificHeaderOptions;
593     OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
594     // URI of new resource that entity handler might create
595     char resourceUri[MAX_URI_LENGTH];
596     // Server sets to true for persistent response buffer, false for non-persistent response buffer
597     uint8_t persistentBufferFlag;
598 } OCEntityHandlerResponse;
599
600 typedef enum
601 {
602     OC_REQUEST_FLAG = (1 << 1),
603     OC_OBSERVE_FLAG = (1 << 2)
604 } OCEntityHandlerFlag; //entity_handler_flag_t ;
605
606 /**
607  * Possible returned values from client application.
608  */
609 typedef enum
610 {
611     OC_STACK_DELETE_TRANSACTION = 0,//!< OC_STACK_DELETE_TRANSACTION
612     OC_STACK_KEEP_TRANSACTION       //!< OC_STACK_KEEP_TRANSACTION
613 } OCStackApplicationResult;
614
615 //-----------------------------------------------------------------------------
616 // Callback function definitions
617 //-----------------------------------------------------------------------------
618
619 /**
620  * Client applications implement this callback to consume responses received from Servers.
621  */
622 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
623     OCClientResponse * clientResponse);
624
625 /**
626  * Client applications using a context pointer implement this callback to delete the
627  * context upon removal of the callback/context pointer from the internal callback-list.
628  */
629 typedef void (* OCClientContextDeleter)(void *context);
630
631 /**
632  * This info is passed from application to OC Stack when initiating a request to Server.
633  */
634 typedef struct OCCallbackData
635 {
636     void *context;
637     /// The pointer to a function the stack will call to handle the requests
638     OCClientResponseHandler cb;
639     /// A pointer to a function to delete the context when this callback is removed
640     OCClientContextDeleter cd;
641 #ifdef __cplusplus
642     OCCallbackData() = default;
643     OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
644         :context(ctx), cb(callback), cd(deleter){}
645 #endif
646 } OCCallbackData;
647
648 /**
649  * Application server implementations must implement this callback to consume requests OTA.
650  * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
651  */
652 typedef OCEntityHandlerResult (*OCEntityHandler)
653 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
654
655 /**
656  * Device Entity handler need to use this call back instead of OCEntityHandler.
657  */
658 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
659 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
660
661 #ifdef __cplusplus
662 }
663 #endif // __cplusplus
664
665 #endif /* OCTYPES_H_ */