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