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