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