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