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