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