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