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