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