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