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