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