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