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