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