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