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