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