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