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