Revert back cbor related patches.
[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
22 /**
23  * @file
24  *
25  * This file contains the definition, types and APIs for resource(s) be implemented.
26  */
27
28 #ifndef OCTYPES_H_
29 #define OCTYPES_H_
30
31 #include "platform_features.h"
32 #include "ocstackconfig.h"
33 #include <stdbool.h>
34 #include <stdint.h>
35 #include <stdio.h>
36 #ifdef __cplusplus
37 #include <string.h>
38
39 extern "C" {
40 #endif // __cplusplus
41
42 /** For the feature presence.*/
43 #define WITH_PRESENCE
44
45 #include "ocpresence.h"
46 //-----------------------------------------------------------------------------
47 // Defines
48 //-----------------------------------------------------------------------------
49
50 /**
51  * OIC Virtual resources supported by every OIC device.
52  */
53 /**
54  *  Default discovery mechanism using '/oic/res' is supported by all OIC devices
55  *  That are Discoverable.
56  */
57 #define OC_RSRVD_WELL_KNOWN_URI               "/oic/res"
58
59 /** Device URI.*/
60 #define OC_RSRVD_DEVICE_URI                   "/oic/d"
61
62 /** Platform URI.*/
63 #define OC_RSRVD_PLATFORM_URI                 "/oic/p"
64
65 /** Resource Type.*/
66 #define OC_RSRVD_RESOURCE_TYPES_URI           "/oic/res/types/d"
67 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
68 /** Gateway URI.*/
69 #define OC_RSRVD_GATEWAY_URI                  "/oic/gateway"
70 #endif
71 #ifdef WITH_PRESENCE
72
73 /** Presence URI through which the OIC devices advertise their presence.*/
74 #define OC_RSRVD_PRESENCE_URI                 "/oic/ad"
75
76 /** Sets the default time to live (TTL) for presence.*/
77 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
78
79 /** For multicast Discovery mechanism.*/
80 #define OC_MULTICAST_DISCOVERY_URI           "/oic/res"
81
82 /** Separator for multiple query string.*/
83 #define OC_QUERY_SEPARATOR                "&;"
84
85 /**
86  *  OC_DEFAULT_PRESENCE_TTL_SECONDS sets the default time to live (TTL) for presence.
87  */
88 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
89
90 /**
91  *  OC_MAX_PRESENCE_TTL_SECONDS sets the maximum time to live (TTL) for presence.
92  *  NOTE: Changing the setting to a longer duration may lead to unsupported and untested
93  *  operation.
94  *  60 sec/min * 60 min/hr * 24 hr/day
95  */
96 #define OC_MAX_PRESENCE_TTL_SECONDS     (60 * 60 * 24)
97 #endif
98
99 /**
100  *  Presence "Announcement Triggers".
101  */
102
103 /** To create.*/
104 #define OC_RSRVD_TRIGGER_CREATE         "create"
105
106 /** To change.*/
107 #define OC_RSRVD_TRIGGER_CHANGE         "change"
108
109 /** To delete.*/
110 #define OC_RSRVD_TRIGGER_DELETE         "delete"
111
112 /**
113  *  Attributes used to form a proper OIC conforming JSON message.
114  */
115
116 #define OC_RSRVD_OC                     "oic"
117
118 /** For payload. */
119
120 #define OC_RSRVD_PAYLOAD                "payload"
121
122 /** To represent href */
123 #define OC_RSRVD_HREF                   "href"
124
125 /** To represent property*/
126 #define OC_RSRVD_PROPERTY               "prop"
127
128 /** For representation.*/
129 #define OC_RSRVD_REPRESENTATION         "rep"
130
131 /** To represent content type.*/
132 #define OC_RSRVD_CONTENT_TYPE           "ct"
133
134 /** To represent resource type.*/
135 #define OC_RSRVD_RESOURCE_TYPE          "rt"
136
137 /** To represent resource type with presence.*/
138 #define OC_RSRVD_RESOURCE_TYPE_PRESENCE "oic.wk.ad"
139
140 /** To represent resource type with device.*/
141 #define OC_RSRVD_RESOURCE_TYPE_DEVICE   "oic.wk.d"
142
143 /** To represent resource type with platform.*/
144 #define OC_RSRVD_RESOURCE_TYPE_PLATFORM "oic.wk.p"
145
146 /** To represent interface.*/
147 #define OC_RSRVD_INTERFACE              "if"
148
149 /** To represent time to live.*/
150 #define OC_RSRVD_TTL                    "ttl"
151
152 /** To represent non*/
153 #define OC_RSRVD_NONCE                  "non"
154
155 /** To represent trigger type.*/
156 #define OC_RSRVD_TRIGGER                "trg"
157
158 /** To represent links.*/
159 #define OC_RSRVD_LINKS                  "links"
160
161 /** To represent default interface.*/
162 #define OC_RSRVD_INTERFACE_DEFAULT      "oic.if.baseline"
163
164 /** To represent read-only interface.*/
165 #define OC_RSRVD_INTERFACE_READ         "oic.if.r"
166
167 /** To represent ll interface.*/
168 #define OC_RSRVD_INTERFACE_LL           "oic.if.ll"
169
170 /** To represent batch interface.*/
171 #define OC_RSRVD_INTERFACE_BATCH        "oic.if.b"
172
173 /** To represent interface group.*/
174 #define OC_RSRVD_INTERFACE_GROUP        "oic.mi.grp"
175
176 /** To represent MFG date.*/
177 #define OC_RSRVD_MFG_DATE               "mndt"
178
179 /** To represent FW version.*/
180 #define OC_RSRVD_FW_VERSION             "mnfv"
181
182 /** To represent host name.*/
183 #define OC_RSRVD_HOST_NAME              "hn"
184
185 /** To represent policy.*/
186 #define OC_RSRVD_POLICY                 "p"
187
188 /** To represent bitmap.*/
189 #define OC_RSRVD_BITMAP                 "bm"
190
191 /** For security.*/
192 #define OC_RSRVD_SECURE                 "sec"
193
194 /** Port. */
195 #define OC_RSRVD_HOSTING_PORT           "port"
196
197 /** For Server instance ID.*/
198 #define OC_RSRVD_SERVER_INSTANCE_ID     "sid"
199
200 /**
201  *  Platform.
202  */
203
204 /** Platform ID. */
205 #define OC_RSRVD_PLATFORM_ID            "pi"
206
207 /** Platform MFG NAME. */
208 #define OC_RSRVD_MFG_NAME               "mnmn"
209
210 /** Platform URL. */
211 #define OC_RSRVD_MFG_URL                "mnml"
212
213 /** Model Number.*/
214 #define OC_RSRVD_MODEL_NUM              "mnmo"
215
216 /** Platform MFG Date.*/
217 #define OC_RSRVD_MFG_DATE               "mndt"
218
219 /** Platform versio.n */
220 #define OC_RSRVD_PLATFORM_VERSION       "mnpv"
221
222 /** Platform Operating system version. */
223 #define OC_RSRVD_OS_VERSION             "mnos"
224
225 /** Platform Hardware version. */
226 #define OC_RSRVD_HARDWARE_VERSION       "mnhw"
227
228 /**Platform Firmware version. */
229 #define OC_RSRVD_FIRMWARE_VERSION       "mnfv"
230
231 /** Support URL for the platform. */
232 #define OC_RSRVD_SUPPORT_URL            "mnsl"
233
234 /** System time for the platform. */
235 #define OC_RSRVD_SYSTEM_TIME             "st"
236
237 /**
238  *  Device.
239  */
240
241 /** Device ID.*/
242 #define OC_RSRVD_DEVICE_ID              "di"
243
244 /** Device Name.*/
245 #define OC_RSRVD_DEVICE_NAME            "n"
246
247 /** Device specification version.*/
248 #define OC_RSRVD_SPEC_VERSION           "icv"
249
250 /** Device data model.*/
251 #define OC_RSRVD_DATA_MODEL_VERSION     "dmv"
252
253 /** Device specification version.*/
254 #define OC_SPEC_VERSION                "core.1.0.0"
255
256 /** Device Data Model version.*/
257 #define OC_DATA_MODEL_VERSION          "res.1.0.0"
258
259 /**
260  *  These provide backward compatibility - their use is deprecated.
261  */
262 #ifndef GOING_AWAY
263
264 /** Multicast Prefix.*/
265 #define OC_MULTICAST_PREFIX                  "224.0.1.187:5683"
266
267 /** Multicast IP address.*/
268 #define OC_MULTICAST_IP                      "224.0.1.187"
269
270 /** Multicast Port.*/
271 #define OC_MULTICAST_PORT                    5683
272 #endif // GOING_AWAY
273
274 /** Max Device address size. */
275 #ifdef RA_ADAPTER
276 #define MAX_ADDR_STR_SIZE (256)
277 #else
278 /** Max Address could be "coaps://[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx]:xxxxx */
279 #define MAX_ADDR_STR_SIZE (56)
280 #endif
281
282 /** Max identity size. */
283 #define MAX_IDENTITY_SIZE (32)
284
285 /** Universal unique identity size. */
286 #define UUID_IDENTITY_SIZE (128/8)
287
288 /** Resource Directory */
289
290 /** Resource Directory URI used to Discover RD and Publish resources.*/
291 #define OC_RSRVD_RD_URI                  "/oic/rd"
292
293 /** To represent resource type with rd.*/
294 #define OC_RSRVD_RESOURCE_TYPE_RD        "oic.wk.rd"
295
296 /** RD Discovery bias factor type. */
297 #define OC_RSRVD_RD_DISCOVERY_SEL        "sel"
298
299 /** Base URI. */
300 #define OC_RSRVD_BASE_URI                "baseURI"
301
302 /** Unique value per collection/link. */
303 #define OC_RSRVD_INS                     "ins"
304
305 /** Allowable resource types in the links. */
306 #define OC_RSRVD_RTS                     "rts"
307
308 /** Default relationship. */
309 #define OC_RSRVD_DREL                    "drel"
310
311 /** Defines relationship between links. */
312 #define OC_RSRVD_REL                     "rel"
313
314 /** Defines title. */
315 #define OC_RSRVD_TITLE                   "title"
316
317 /** Defines URI. */
318 #define OC_RSRVD_URI                     "uri"
319
320 /** Defines media type. */
321 #define OC_RSRVD_MEDIA_TYPE              "mt"
322
323 /** To represent resource type with Publish RD.*/
324 #define OC_RSRVD_RESOURCE_TYPE_RDPUBLISH "oic.wk.rdPub"
325
326 /**
327  * These enums (OCTransportAdapter and OCTransportFlags) must
328  * be kept synchronized with OCConnectivityType (below) as well as
329  * CATransportAdapter and CATransportFlags (in CACommon.h).
330  */
331 typedef enum
332 {
333     /** value zero indicates discovery.*/
334     OC_DEFAULT_ADAPTER = 0,
335
336     /** IPv4 and IPv6, including 6LoWPAN.*/
337     OC_ADAPTER_IP           = (1 << 0),
338
339     /** GATT over Bluetooth LE.*/
340     OC_ADAPTER_GATT_BTLE    = (1 << 1),
341
342     /** RFCOMM over Bluetooth EDR.*/
343     OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
344 #ifdef RA_ADAPTER
345     /**Remote Access over XMPP.*/
346     OC_ADAPTER_REMOTE_ACCESS = (1 << 3),
347 #endif
348     /** CoAP over TCP.*/
349     OC_ADAPTER_TCP           = (1 << 4),
350
351     /** NFC Transport for Messaging.*/
352     OC_ADAPTER_NFC           = (1 << 5)
353 } OCTransportAdapter;
354
355 /**
356  *  Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
357  */
358 typedef enum
359 {
360     /** default flag is 0*/
361     OC_DEFAULT_FLAGS = 0,
362
363     /** Insecure transport is the default (subject to change).*/
364     /** secure the transport path*/
365     OC_FLAG_SECURE     = (1 << 4),
366
367     /** IPv4 & IPv6 auto-selection is the default.*/
368     /** IP adapter only.*/
369     OC_IP_USE_V6       = (1 << 5),
370
371     /** IP adapter only.*/
372     OC_IP_USE_V4       = (1 << 6),
373
374     /** internal use only.*/
375     OC_RESERVED1       = (1 << 7),   // internal use only
376
377     /** Link-Local multicast is the default multicast scope for IPv6.
378      *  These are placed here to correspond to the IPv6 multicast address bits.*/
379
380     /** IPv6 Interface-Local scope (loopback).*/
381     OC_SCOPE_INTERFACE = 0x1,
382
383     /** IPv6 Link-Local scope (default).*/
384     OC_SCOPE_LINK      = 0x2,
385
386     /** IPv6 Realm-Local scope. */
387     OC_SCOPE_REALM     = 0x3,
388
389     /** IPv6 Admin-Local scope. */
390     OC_SCOPE_ADMIN     = 0x4,
391
392     /** IPv6 Site-Local scope. */
393     OC_SCOPE_SITE      = 0x5,
394
395     /** IPv6 Organization-Local scope. */
396     OC_SCOPE_ORG       = 0x8,
397
398     /**IPv6 Global scope. */
399     OC_SCOPE_GLOBAL    = 0xE,
400
401 } OCTransportFlags;
402
403 /** Bit mask for scope.*/
404 #define OC_MASK_SCOPE    (0x000F)
405
406 /** Bit mask for Mods.*/
407 #define OC_MASK_MODS     (0x0FF0)
408 #define OC_MASK_FAMS     (OC_IP_USE_V6|OC_IP_USE_V4)
409
410 /**
411  * End point identity.
412  */
413 typedef struct
414 {
415     /** Identity Length */
416     uint16_t id_length;
417
418     /** Array of end point identity.*/
419     unsigned char id[MAX_IDENTITY_SIZE];
420 } OCIdentity;
421
422 /**
423  * Universally unique identifier.
424  */
425 typedef struct
426 {
427     /** identitifier string.*/
428     unsigned char id[UUID_IDENTITY_SIZE];
429 } OCUUIdentity;
430
431 /**
432  * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
433  * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
434  */
435 typedef struct
436 {
437     /** adapter type.*/
438     OCTransportAdapter      adapter;
439
440     /** transport modifiers.*/
441     OCTransportFlags        flags;
442
443     /** for IP.*/
444     uint16_t                port;
445
446     /** address for all adapters.*/
447     char                    addr[MAX_ADDR_STR_SIZE];
448
449     /** usually zero for default interface.*/
450     uint32_t                interface;
451 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
452     char                    routeData[MAX_ADDR_STR_SIZE]; //destination GatewayID:ClientId
453 #endif
454 } OCDevAddr;
455
456 /**
457  * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
458  * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
459  * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
460  * like Arduino.
461  *
462  * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
463  */
464 typedef enum
465 {
466     /** use when defaults are ok. */
467     CT_DEFAULT = 0,
468
469     /** IPv4 and IPv6, including 6LoWPAN.*/
470     CT_ADAPTER_IP           = (1 << 16),
471
472     /** GATT over Bluetooth LE.*/
473     CT_ADAPTER_GATT_BTLE    = (1 << 17),
474
475     /** RFCOMM over Bluetooth EDR.*/
476     CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
477
478 #ifdef RA_ADAPTER
479     /** Remote Access over XMPP.*/
480     CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
481 #endif
482     /** CoAP over TCP.*/
483     CT_ADAPTER_TCP     = (1 << 20),
484
485     /** NFC Transport.*/
486     CT_ADAPTER_NFC     = (1 << 21),
487
488     /** Insecure transport is the default (subject to change).*/
489
490     /** secure the transport path.*/
491     CT_FLAG_SECURE     = (1 << 4),
492
493     /** IPv4 & IPv6 autoselection is the default.*/
494
495     /** IP adapter only.*/
496     CT_IP_USE_V6       = (1 << 5),
497
498     /** IP adapter only.*/
499     CT_IP_USE_V4       = (1 << 6),
500
501     /** Link-Local multicast is the default multicast scope for IPv6.
502      * These are placed here to correspond to the IPv6 address bits.*/
503
504     /** IPv6 Interface-Local scope(loopback).*/
505     CT_SCOPE_INTERFACE = 0x1,
506
507     /** IPv6 Link-Local scope (default).*/
508     CT_SCOPE_LINK      = 0x2,
509
510     /** IPv6 Realm-Local scope.*/
511     CT_SCOPE_REALM     = 0x3,
512
513     /** IPv6 Admin-Local scope.*/
514     CT_SCOPE_ADMIN     = 0x4,
515
516     /** IPv6 Site-Local scope.*/
517     CT_SCOPE_SITE      = 0x5,
518
519     /** IPv6 Organization-Local scope.*/
520     CT_SCOPE_ORG       = 0x8,
521
522     /** IPv6 Global scope.*/
523     CT_SCOPE_GLOBAL    = 0xE,
524 } OCConnectivityType;
525
526 /** bit shift required for connectivity adapter.*/
527 #define CT_ADAPTER_SHIFT 16
528
529 /** Mask Flag.*/
530 #define CT_MASK_FLAGS 0xFFFF
531
532 /** Mask Adapter.*/
533 #define CT_MASK_ADAPTER 0xFFFF0000
534
535 /**
536  *  OCDoResource methods to dispatch the request
537  */
538 typedef enum
539 {
540     OC_REST_NOMETHOD       = 0,
541
542     /** Read.*/
543     OC_REST_GET            = (1 << 0),
544
545     /** Write.*/
546     OC_REST_PUT            = (1 << 1),
547
548     /** Update.*/
549     OC_REST_POST           = (1 << 2),
550
551     /** Delete.*/
552     OC_REST_DELETE         = (1 << 3),
553
554     /** Register observe request for most up date notifications ONLY.*/
555     OC_REST_OBSERVE        = (1 << 4),
556
557     /** Register observe request for all notifications, including stale notifications.*/
558     OC_REST_OBSERVE_ALL    = (1 << 5),
559
560     /** De-register observation, intended for internal use.*/
561     OC_REST_CANCEL_OBSERVE = (1 << 6),
562
563     #ifdef WITH_PRESENCE
564     /** Subscribe for all presence notifications of a particular resource.*/
565     OC_REST_PRESENCE       = (1 << 7),
566
567     #endif
568     /** Allows OCDoResource caller to do discovery.*/
569     OC_REST_DISCOVER       = (1 << 8)
570 } OCMethod;
571
572 /**
573  *  Formats for payload encoding.
574  */
575 typedef enum
576 {
577     OC_FORMAT_CBOR,
578     OC_FORMAT_UNDEFINED,
579     OC_FORMAT_UNSUPPORTED,
580 } OCPayloadFormat;
581
582 /**
583  * Host Mode of Operation.
584  */
585 typedef enum
586 {
587     OC_CLIENT = 0,
588     OC_SERVER,
589     OC_CLIENT_SERVER,
590     OC_GATEWAY          /**< Client server mode along with routing capabilities.*/
591 } OCMode;
592
593 /**
594  * Quality of Service attempts to abstract the guarantees provided by the underlying transport
595  * protocol. The precise definitions of each quality of service level depend on the
596  * implementation. In descriptions below are for the current implementation and may changed
597  * over time.
598  */
599 typedef enum
600 {
601     /** Packet delivery is best effort.*/
602     OC_LOW_QOS = 0,
603
604     /** Packet delivery is best effort.*/
605     OC_MEDIUM_QOS,
606
607     /** Acknowledgments are used to confirm delivery.*/
608     OC_HIGH_QOS,
609
610     /** No Quality is defined, let the stack decide.*/
611     OC_NA_QOS
612 } OCQualityOfService;
613
614 /**
615  * Resource Properties.
616  * The value of a policy property is defined as bitmap.
617  * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
618  * Not including the policy property is equivalent to zero.
619  *
620  */
621 typedef enum
622 {
623     /** When none of the bits are set, the resource is non-discoverable &
624      *  non-observable by the client.*/
625     OC_RES_PROP_NONE = (0),
626
627     /** When this bit is set, the resource is allowed to be discovered by clients.*/
628     OC_DISCOVERABLE  = (1 << 0),
629
630     /** When this bit is set, the resource is allowed to be observed by clients.*/
631     OC_OBSERVABLE    = (1 << 1),
632
633     /** When this bit is set, the resource is initialized, otherwise the resource
634      *  is 'inactive'. 'inactive' signifies that the resource has been marked for
635      *  deletion or is already deleted.*/
636     OC_ACTIVE        = (1 << 2),
637
638     /** When this bit is set, the resource has been marked as 'slow'.
639      * 'slow' signifies that responses from this resource can expect delays in
640      *  processing its requests from clients.*/
641     OC_SLOW          = (1 << 3),
642
643     /** When this bit is set, the resource is a secure resource.*/
644     OC_SECURE        = (1 << 4),
645
646     /** When this bit is set, the resource is allowed to be discovered only
647      *  if discovery request contains an explicit querystring.
648      *  Ex: GET /oic/res?rt=oic.sec.acl */
649     OC_EXPLICIT_DISCOVERABLE   = (1 << 5)
650 } OCResourceProperty;
651
652 /**
653  * Transport Protocol IDs.
654  */
655 typedef enum
656 {
657     /** For invalid ID.*/
658     OC_INVALID_ID   = (1 << 0),
659
660     /* For coap ID.*/
661     OC_COAP_ID      = (1 << 1)
662 } OCTransportProtocolID;
663
664 /**
665  * Declares Stack Results & Errors.
666  */
667 typedef enum
668 {
669     /** Success status code - START HERE.*/
670     OC_STACK_OK = 0,
671     OC_STACK_RESOURCE_CREATED,
672     OC_STACK_RESOURCE_DELETED,
673     OC_STACK_CONTINUE,
674     /** Success status code - END HERE.*/
675
676     /** Error status code - START HERE.*/
677     OC_STACK_INVALID_URI = 20,
678     OC_STACK_INVALID_QUERY,
679     OC_STACK_INVALID_IP,
680     OC_STACK_INVALID_PORT,
681     OC_STACK_INVALID_CALLBACK,
682     OC_STACK_INVALID_METHOD,
683
684     /** Invalid parameter.*/
685     OC_STACK_INVALID_PARAM,
686     OC_STACK_INVALID_OBSERVE_PARAM,
687     OC_STACK_NO_MEMORY,
688     OC_STACK_COMM_ERROR,
689     OC_STACK_TIMEOUT,
690     OC_STACK_ADAPTER_NOT_ENABLED,
691     OC_STACK_NOTIMPL,
692
693     /** Resource not found.*/
694     OC_STACK_NO_RESOURCE,
695
696     /** e.g: not supported method or interface.*/
697     OC_STACK_RESOURCE_ERROR,
698     OC_STACK_SLOW_RESOURCE,
699     OC_STACK_DUPLICATE_REQUEST,
700
701     /** Resource has no registered observers.*/
702     OC_STACK_NO_OBSERVERS,
703     OC_STACK_OBSERVER_NOT_FOUND,
704     OC_STACK_VIRTUAL_DO_NOT_HANDLE,
705     OC_STACK_INVALID_OPTION,
706
707     /** The remote reply contained malformed data.*/
708     OC_STACK_MALFORMED_RESPONSE,
709     OC_STACK_PERSISTENT_BUFFER_REQUIRED,
710     OC_STACK_INVALID_REQUEST_HANDLE,
711     OC_STACK_INVALID_DEVICE_INFO,
712     OC_STACK_INVALID_JSON,
713
714     /** Request is not authorized by Resource Server. */
715     OC_STACK_UNAUTHORIZED_REQ,
716
717     /** Error code from PDM */
718     OC_STACK_PDM_IS_NOT_INITIALIZED,
719     OC_STACK_DUPLICATE_UUID,
720     OC_STACK_INCONSISTENT_DB,
721
722     /**
723      * Error code from OTM
724      * This error is plused from DTLS interface when handshake failure happens
725      */
726     OC_STACK_AUTHENTICATION_FAILURE,
727
728     /** Insert all new error codes here!.*/
729     #ifdef WITH_PRESENCE
730     OC_STACK_PRESENCE_STOPPED = 128,
731     OC_STACK_PRESENCE_TIMEOUT,
732     OC_STACK_PRESENCE_DO_NOT_HANDLE,
733     #endif
734     /** ERROR in stack.*/
735     OC_STACK_ERROR = 255
736     /** Error status code - END HERE.*/
737 } OCStackResult;
738
739 /**
740  * Handle to an OCDoResource invocation.
741  */
742 typedef void * OCDoHandle;
743
744 /**
745  * Handle to an OCResource object owned by the OCStack.
746  */
747 typedef void * OCResourceHandle;
748
749 /**
750  * Handle to an OCRequest object owned by the OCStack.
751  */
752 typedef void * OCRequestHandle;
753
754 /**
755  * Unique identifier for each observation request. Used when observations are
756  * registered or de-registered. Used by entity handler to signal specific
757  * observers to be notified of resource changes.
758  * There can be maximum of 256 observations per server.
759  */
760 typedef uint8_t OCObservationId;
761
762 /**
763  * Action associated with observation.
764  */
765 typedef enum
766 {
767     /** To Register. */
768     OC_OBSERVE_REGISTER = 0,
769
770     /** To Deregister. */
771     OC_OBSERVE_DEREGISTER = 1,
772
773     /** Others. */
774     OC_OBSERVE_NO_OPTION = 2
775 } OCObserveAction;
776
777
778 /**
779  * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
780  * when it calls OCRegisterPersistentStorageHandler.
781  * Persistent storage open handler points to default file path.
782  * Application can point to appropriate SVR database path for it's IoTivity Server.
783  */
784 typedef struct {
785     /** Persistent storage file path.*/
786     FILE* (* open)(const char *path, const char *mode);
787
788     /** Persistent storage read handler.*/
789     size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
790
791     /** Persistent storage write handler.*/
792     size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
793
794     /** Persistent storage close handler.*/
795     int (* close)(FILE *fp);
796
797     /** Persistent storage unlink handler.*/
798     int (* unlink)(const char *path);
799 } OCPersistentStorage;
800
801 /**
802  * Possible returned values from entity handler.
803  */
804 typedef struct
805 {
806     /** Action associated with observation request.*/
807     OCObserveAction action;
808
809     /** Identifier for observation being registered/deregistered.*/
810     OCObservationId obsId;
811 } OCObservationInfo;
812
813 /**
814  * Possible returned values from entity handler.
815  */
816 typedef enum
817 {
818     OC_EH_OK = 0,
819     OC_EH_ERROR,
820     OC_EH_RESOURCE_CREATED,
821     OC_EH_RESOURCE_DELETED,
822     OC_EH_SLOW,
823     OC_EH_FORBIDDEN,
824     OC_EH_RESOURCE_NOT_FOUND
825 } OCEntityHandlerResult;
826
827 /**
828  * This structure will be used to define the vendor specific header options to be included
829  * in communication packets.
830  */
831 typedef struct OCHeaderOption
832 {
833     /** The protocol ID this option applies to.*/
834     OCTransportProtocolID protocolID;
835
836     /** The header option ID which will be added to communication packets.*/
837     uint16_t optionID;
838
839     /** its length 191.*/
840     uint16_t optionLength;
841
842     /** pointer to its data.*/
843     uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
844
845 #ifdef SUPPORTS_DEFAULT_CTOR
846     OCHeaderOption() = default;
847     OCHeaderOption(OCTransportProtocolID pid,
848                    uint16_t optId,
849                    uint16_t optlen,
850                    const uint8_t* optData)
851         : protocolID(pid),
852           optionID(optId),
853           optionLength(optlen)
854     {
855
856         // parameter includes the null terminator.
857         optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
858                         optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
859         memcpy(optionData, optData, optionLength);
860         optionData[optionLength - 1] = '\0';
861     }
862 #endif
863 } OCHeaderOption;
864
865
866 /**
867  * This structure describes the platform properties. All non-Null properties will be
868  * included in a platform discovery request.
869  */
870 typedef struct
871 {
872     /** Platform ID.*/
873     char *platformID;
874
875     /** Manufacturer name.*/
876     char *manufacturerName;
877
878     /** Manufacturer URL for platform property.*/
879     char *manufacturerUrl;
880
881     /** Model number.*/
882     char *modelNumber;
883
884     /** Manufacturer date.*/
885     char *dateOfManufacture;
886
887     /** Platform version.*/
888     char *platformVersion;
889
890     /** Operating system version.*/
891     char *operatingSystemVersion;
892
893     /** HW version.*/
894     char *hardwareVersion;
895
896     /** FW version.*/
897     char *firmwareVersion;
898
899     /** Platform support URL.*/
900     char *supportUrl;
901
902     /** System time.*/
903     char *systemTime;
904
905 } OCPlatformInfo;
906
907 /**
908  * This structure is expected as input for device properties.
909  * device name is mandatory and expected from the application.
910  * device id of type UUID will be generated by the stack.
911  */
912 typedef struct
913 {
914     /** Pointer to the device name.*/
915     char *deviceName;
916
917 } OCDeviceInfo;
918
919 #ifdef RA_ADAPTER
920 /**
921  * callback for bound JID
922  */
923 typedef void (*jid_bound_cb)(char *jid);
924
925 /**
926  * CA Remote Access information for XMPP Client
927  *
928  */
929 typedef struct
930 {
931     char *hostname;     /**< XMPP server hostname */
932     uint16_t   port;    /**< XMPP server serivce port */
933     char *xmpp_domain;  /**< XMPP login domain */
934     char *username;     /**< login username */
935     char *password;     /**< login password */
936     char *resource;     /**< specific resource for login */
937     char *user_jid;     /**< specific JID for login */
938     jid_bound_cb jidbound;  /**< callback when JID bound */
939 } OCRAInfo_t;
940 #endif  /* RA_ADAPTER */
941
942
943 /** Enum to describe the type of object held by the OCPayload object.*/
944 typedef enum
945 {
946     PAYLOAD_TYPE_INVALID,
947     PAYLOAD_TYPE_DISCOVERY,
948     PAYLOAD_TYPE_DEVICE,
949     PAYLOAD_TYPE_PLATFORM,
950     PAYLOAD_TYPE_REPRESENTATION,
951     PAYLOAD_TYPE_SECURITY,
952     PAYLOAD_TYPE_PRESENCE,
953     PAYLOAD_TYPE_RD
954 } OCPayloadType;
955
956 typedef struct
957 {
958     // The type of message that was received
959     OCPayloadType type;
960 } OCPayload;
961
962 typedef enum
963 {
964     OCREP_PROP_NULL,
965     OCREP_PROP_INT,
966     OCREP_PROP_DOUBLE,
967     OCREP_PROP_BOOL,
968     OCREP_PROP_STRING,
969     OCREP_PROP_BYTE_STRING,
970     OCREP_PROP_OBJECT,
971     OCREP_PROP_ARRAY
972 }OCRepPayloadPropType;
973
974 /** This structure will be used to represent a binary string for CBOR payloads.*/
975 typedef struct
976 {
977     /** pointer to data bytes.*/
978     uint8_t* bytes;
979
980     /** number of data bytes.*/
981     size_t   len;
982 } OCByteString;
983
984 #define MAX_REP_ARRAY_DEPTH 3
985 typedef struct
986 {
987     OCRepPayloadPropType type;
988     size_t dimensions[MAX_REP_ARRAY_DEPTH];
989
990     union
991     {
992         int64_t* iArray;
993         double* dArray;
994         bool* bArray;
995         char** strArray;
996
997         /** pointer to ByteString array.*/
998         OCByteString* ocByteStrArray;
999
1000         struct OCRepPayload** objArray;
1001     };
1002 } OCRepPayloadValueArray;
1003
1004 typedef struct OCRepPayloadValue
1005 {
1006     char* name;
1007     OCRepPayloadPropType type;
1008     union
1009     {
1010         int64_t i;
1011         double d;
1012         bool b;
1013         char* str;
1014
1015         /** ByteString object.*/
1016         OCByteString ocByteStr;
1017
1018         struct OCRepPayload* obj;
1019         OCRepPayloadValueArray arr;
1020     };
1021     struct OCRepPayloadValue* next;
1022
1023 } OCRepPayloadValue;
1024
1025 typedef struct OCStringLL
1026 {
1027     struct OCStringLL *next;
1028     char* value;
1029 } OCStringLL;
1030
1031 // used for get/set/put/observe/etc representations
1032 typedef struct OCRepPayload
1033 {
1034     OCPayload base;
1035     char* uri;
1036     OCStringLL* types;
1037     OCStringLL* interfaces;
1038     OCRepPayloadValue* values;
1039     struct OCRepPayload* next;
1040 } OCRepPayload;
1041
1042 // used inside a discovery payload
1043 typedef struct OCResourcePayload
1044 {
1045     char* uri;
1046     OCStringLL* types;
1047     OCStringLL* interfaces;
1048     uint8_t bitmap;
1049     bool secure;
1050     uint16_t port;
1051     struct OCResourcePayload* next;
1052 } OCResourcePayload;
1053
1054 /**
1055  * Structure holding Links Payload. It is a sub-structure used in
1056  * OCResourceCollectionPayload.
1057  */
1058 typedef struct OCLinksPayload
1059 {
1060     /** This is the target relative URI. */
1061     char *href;
1062     /** Resource Type - A standard OIC specified or vendor defined resource
1063      * type of the resource referenced by the target URI. */
1064     OCStringLL *rt;
1065     /** Interface - The interfaces supported by the resource referenced by the target URI. */
1066     OCStringLL *itf;
1067     /** The relation of the target URI referenced by the link to the context URI;
1068      * The default value is null. */
1069     char *rel;
1070     /** Specifies if the resource referenced by the target URIis observable or not. */
1071     bool obs;
1072     /** A title for the link relation. Can be used by the UI to provide a context. */
1073     char *title;
1074     /** This is used to override the context URI e.g. override the URI of the containing collection. */
1075     char *uri;
1076     /** The instance identifier for this web link in an array of web links - used in links. */
1077     union
1078     {
1079         /** An ordinal number that is not repeated - must be unique in the collection context. */
1080         uint8_t ins;
1081         /** Any unique string including a URI. */
1082         char *uniqueStr;
1083         /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1084         OCIdentity uniqueUUID;
1085     };
1086     /** A hint of the media type of the representation of the resource referenced by the target URI. */
1087     OCStringLL *mt;
1088     /** Holding address of the next resource. */
1089     struct OCLinksPayload *next;
1090 } OCLinksPayload;
1091
1092 /** Structure holding tags value of the links payload. */
1093 typedef struct
1094 {
1095     /** Name of tags. */
1096     OCDeviceInfo n;
1097     /** Device identifier. */
1098     OCIdentity di;
1099     /** The base URI where the resources are hold. */
1100     char *baseURI;
1101     /** Bitmap holds observable, discoverable, secure option flag.*/
1102     uint8_t bitmap;
1103     /** Port set in case, the secure flag is set above. */
1104     uint16_t port;
1105     /** Id for each set of links i.e. tag. */
1106     union
1107     {
1108         /** An ordinal number that is not repeated - must be unique in the collection context. */
1109         uint8_t ins;
1110         /** Any unique string including a URI. */
1111         char *uniqueStr;
1112         /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1113         OCIdentity uniqueUUID;
1114     };
1115     /** Defines the list of allowable resource types (for Target and anchors) in links included
1116      * in the collection; new links being created can only be from this list. */
1117     char *rts;
1118     /** When specified this is the default relationship to use when an OIC Link does not specify
1119      * an explicit relationship with *rel* parameter. */
1120     char *drel;
1121     /** Time to keep holding resource.*/
1122     uint32_t ttl;
1123 } OCTagsPayload;
1124
1125 /** Resource collection payload. */
1126 typedef struct OCResourceCollectionPayload
1127 {
1128     /** Collection tags payload.*/
1129     OCTagsPayload *tags;
1130     /** Array of links payload. */
1131     OCLinksPayload *setLinks;
1132     /** Holding address of the next resource. */
1133     struct OCResourceCollectionPayload *next;
1134 } OCResourceCollectionPayload;
1135
1136 typedef struct
1137 {
1138     OCPayload base;
1139
1140     char *sid;
1141
1142     /** A special case for handling RD address. */
1143     char* baseURI;
1144
1145     /** This structure holds the old /oic/res response. */
1146     OCResourcePayload *resources;
1147
1148 } OCDiscoveryPayload;
1149
1150 /**
1151  * Structure holding discovery payload.
1152  */
1153 typedef struct
1154 {
1155     /** Device Name. */
1156     OCDeviceInfo n;
1157     /** Device Identity. */
1158     OCIdentity di;
1159     /** Value holding the bias factor of the RD. */
1160     uint8_t sel;
1161 } OCRDDiscoveryPayload;
1162
1163 /**
1164  * RD Payload that will be transmitted over the wire.
1165  */
1166 typedef struct
1167 {
1168     OCPayload base;
1169     /** Pointer to the discovery response payload.*/
1170     OCRDDiscoveryPayload *rdDiscovery;
1171     /** Pointer to the publish payload.*/
1172     OCResourceCollectionPayload *rdPublish;
1173 } OCRDPayload;
1174
1175 typedef struct
1176 {
1177     OCPayload base;
1178     char* sid;
1179     char* deviceName;
1180     char* specVersion;
1181     char* dataModelVersion;
1182 } OCDevicePayload;
1183
1184 typedef struct
1185 {
1186     OCPayload base;
1187     char* uri;
1188     OCPlatformInfo info;
1189     char* rt;
1190     OCStringLL* interfaces;
1191 } OCPlatformPayload;
1192
1193 typedef struct
1194 {
1195     OCPayload base;
1196     char* securityData;
1197 } OCSecurityPayload;
1198
1199 #ifdef WITH_PRESENCE
1200 typedef struct
1201 {
1202     OCPayload base;
1203     uint32_t sequenceNumber;
1204     uint32_t maxAge;
1205     OCPresenceTrigger trigger;
1206     char* resourceType;
1207 } OCPresencePayload;
1208 #endif
1209
1210 /**
1211  * Incoming requests handled by the server. Requests are passed in as a parameter to the
1212  * OCEntityHandler callback API.
1213  * The OCEntityHandler callback API must be implemented in the application in order
1214  * to receive these requests.
1215  */
1216 typedef struct
1217 {
1218     /** Associated resource.*/
1219     OCResourceHandle resource;
1220
1221     /** Associated request handle.*/
1222     OCRequestHandle requestHandle;
1223
1224     /** the REST method retrieved from received request PDU.*/
1225     OCMethod method;
1226
1227     /** description of endpoint that sent the request.*/
1228     OCDevAddr devAddr;
1229
1230     /** resource query send by client.*/
1231     char * query;
1232
1233     /** Information associated with observation - valid only when OCEntityHandler flag includes
1234      * ::OC_OBSERVE_FLAG.*/
1235     OCObservationInfo obsInfo;
1236
1237     /** Number of the received vendor specific header options.*/
1238     uint8_t numRcvdVendorSpecificHeaderOptions;
1239
1240     /** Pointer to the array of the received vendor specific header options.*/
1241     OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1242
1243     /** the payload from the request PDU.*/
1244     OCPayload *payload;
1245
1246 } OCEntityHandlerRequest;
1247
1248
1249 /**
1250  * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1251  */
1252 typedef struct
1253 {
1254     /** Address of remote server.*/
1255     OCDevAddr devAddr;
1256
1257     /** backward compatibility (points to devAddr).*/
1258     OCDevAddr *addr;
1259
1260     /** backward compatibility.*/
1261     OCConnectivityType connType;
1262
1263     /** the security identity of the remote server.*/
1264     OCIdentity identity;
1265
1266     /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1267     OCStackResult result;
1268
1269     /** If associated with observe, this will represent the sequence of notifications from server.*/
1270     uint32_t sequenceNumber;
1271
1272     /** resourceURI.*/
1273     const char * resourceUri;
1274
1275     /** the payload for the response PDU.*/
1276     OCPayload *payload;
1277
1278     /** Number of the received vendor specific header options.*/
1279     uint8_t numRcvdVendorSpecificHeaderOptions;
1280
1281     /** An array of the received vendor specific header options.*/
1282     OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1283 } OCClientResponse;
1284
1285 /**
1286  * Request handle is passed to server via the entity handler for each incoming request.
1287  * Stack assigns when request is received, server sets to indicate what request response is for.
1288  */
1289 typedef struct
1290 {
1291     /** Request handle.*/
1292     OCRequestHandle requestHandle;
1293
1294     /** Resource handle.*/
1295     OCResourceHandle resourceHandle;
1296
1297     /** Allow the entity handler to pass a result with the response.*/
1298     OCEntityHandlerResult  ehResult;
1299
1300     /** This is the pointer to server payload data to be transferred.*/
1301     OCPayload* payload;
1302
1303     /** number of the vendor specific header options .*/
1304     uint8_t numSendVendorSpecificHeaderOptions;
1305
1306     /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1307     OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1308
1309     /** URI of new resource that entity handler might create.*/
1310     char resourceUri[MAX_URI_LENGTH];
1311
1312     /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1313     uint8_t persistentBufferFlag;
1314 } OCEntityHandlerResponse;
1315
1316 /**
1317  * Entity's state
1318  */
1319 typedef enum
1320 {
1321     /** Request state.*/
1322     OC_REQUEST_FLAG = (1 << 1),
1323     /** Observe state.*/
1324     OC_OBSERVE_FLAG = (1 << 2)
1325 } OCEntityHandlerFlag;
1326
1327 /**
1328  * Possible returned values from client application.
1329  */
1330 typedef enum
1331 {
1332     OC_STACK_DELETE_TRANSACTION = 0,
1333     OC_STACK_KEEP_TRANSACTION
1334 } OCStackApplicationResult;
1335
1336
1337 //#ifdef DIRECT_PAIRING
1338 /**
1339  * @brief   direct pairing Method Type.
1340  *              0:  not allowed
1341  *              1:  pre-configured pin
1342  *              2:  random pin
1343  */
1344 typedef enum OCPrm
1345 {
1346     DP_NOT_ALLOWED             = 0x0,
1347     DP_PRE_CONFIGURED        = (0x1 << 0),
1348     DP_RANDOM_PIN               = (0x1 << 1),
1349 } OCPrm_t;
1350
1351 /**
1352  * Device Information of discoverd direct pairing device(s).
1353  */
1354 typedef struct OCDPDev
1355 {
1356     OCDevAddr               endpoint;
1357     OCConnectivityType   connType;
1358     uint16_t                     securePort;
1359     bool                  edp;
1360     OCPrm_t           *prm;
1361     size_t                prmLen;
1362     OCUUIdentity     deviceID;
1363     OCUUIdentity     rowner;
1364     struct OCDPDev *next;
1365 } OCDPDev_t;
1366 //#endif // DIRECT_PAIRING
1367
1368 /*
1369  * -------------------------------------------------------------------------------------------
1370  * Callback function definitions
1371  * -------------------------------------------------------------------------------------------
1372  */
1373
1374 /**
1375  * Client applications implement this callback to consume responses received from Servers.
1376  */
1377 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1378     OCClientResponse * clientResponse);
1379
1380 /**
1381  * Client applications using a context pointer implement this callback to delete the
1382  * context upon removal of the callback/context pointer from the internal callback-list.
1383  */
1384 typedef void (* OCClientContextDeleter)(void *context);
1385
1386 /**
1387  * This info is passed from application to OC Stack when initiating a request to Server.
1388  */
1389 typedef struct OCCallbackData
1390 {
1391     /** Pointer to the context.*/
1392     void *context;
1393
1394     /** The pointer to a function the stack will call to handle the requests.*/
1395     OCClientResponseHandler cb;
1396
1397     /** A pointer to a function to delete the context when this callback is removed.*/
1398     OCClientContextDeleter cd;
1399
1400 #ifdef SUPPORTS_DEFAULT_CTOR
1401     OCCallbackData() = default;
1402     OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1403         :context(ctx), cb(callback), cd(deleter){}
1404 #endif
1405 } OCCallbackData;
1406
1407 /**
1408  * Application server implementations must implement this callback to consume requests OTA.
1409  * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1410  */
1411 typedef OCEntityHandlerResult (*OCEntityHandler)
1412 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1413
1414 /**
1415  * Device Entity handler need to use this call back instead of OCEntityHandler.
1416  */
1417 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1418 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1419
1420 //#ifdef DIRECT_PAIRING
1421 /**
1422  * Callback function definition of direct-pairing
1423  *
1424  * @param[OUT] peer - pairing device info.
1425  * @param[OUT} result - It's returned with 'OC_STACK_XXX'. It will return 'OC_STACK_OK' 
1426  *                                   if D2D pairing is success without error
1427  */
1428 typedef void (*OCDirectPairingCB)(OCDPDev_t *peer, OCStackResult result);
1429 //#endif // DIRECT_PAIRING
1430
1431 #ifdef __cplusplus
1432 }
1433 #endif // __cplusplus
1434
1435 #endif /* OCTYPES_H_ */