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