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