[IOT-1413,IOT-1415] Fixed request handling bugs for /oic/ping resource
[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     /** ERROR in stack.*/
992     OC_STACK_ERROR = 255
993     /** Error status code - END HERE.*/
994 } OCStackResult;
995
996 /**
997  * Handle to an OCDoResource invocation.
998  */
999 typedef void * OCDoHandle;
1000
1001 /**
1002  * Handle to an OCResource object owned by the OCStack.
1003  */
1004 typedef void * OCResourceHandle;
1005
1006 /**
1007  * Handle to an OCRequest object owned by the OCStack.
1008  */
1009 typedef void * OCRequestHandle;
1010
1011 /**
1012  * Unique identifier for each observation request. Used when observations are
1013  * registered or de-registered. Used by entity handler to signal specific
1014  * observers to be notified of resource changes.
1015  * There can be maximum of 256 observations per server.
1016  */
1017 typedef uint8_t OCObservationId;
1018
1019 /**
1020  * Sequence number is a 24 bit field,
1021  * per https://tools.ietf.org/html/rfc7641.
1022  */
1023 #define MAX_SEQUENCE_NUMBER              (0xFFFFFF)
1024
1025 /**
1026  * Action associated with observation.
1027  */
1028 typedef enum
1029 {
1030     /** To Register. */
1031     OC_OBSERVE_REGISTER = 0,
1032
1033     /** To Deregister. */
1034     OC_OBSERVE_DEREGISTER = 1,
1035
1036     /** Others. */
1037     OC_OBSERVE_NO_OPTION = 2,
1038
1039 } OCObserveAction;
1040
1041
1042 /**
1043  * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
1044  * when it calls OCRegisterPersistentStorageHandler.
1045  * Persistent storage open handler points to default file path.
1046  * It should check file path and whether the file is symbolic link or no.
1047  * Application can point to appropriate SVR database path for it's IoTivity Server.
1048  */
1049 typedef struct {
1050     /** Persistent storage file path.*/
1051     FILE* (* open)(const char *path, const char *mode);
1052
1053     /** Persistent storage read handler.*/
1054     size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
1055
1056     /** Persistent storage write handler.*/
1057     size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
1058
1059     /** Persistent storage close handler.*/
1060     int (* close)(FILE *fp);
1061
1062     /** Persistent storage unlink handler.*/
1063     int (* unlink)(const char *path);
1064 } OCPersistentStorage;
1065
1066 /**
1067  * Possible returned values from entity handler.
1068  */
1069 typedef struct
1070 {
1071     /** Action associated with observation request.*/
1072     OCObserveAction action;
1073
1074     /** Identifier for observation being registered/deregistered.*/
1075     OCObservationId obsId;
1076 } OCObservationInfo;
1077
1078 /**
1079  * Possible returned values from entity handler.
1080  */
1081 typedef enum
1082 {
1083     OC_EH_OK = 0,
1084     OC_EH_ERROR,
1085     OC_EH_SLOW,
1086     OC_EH_RESOURCE_CREATED = 201,
1087     OC_EH_RESOURCE_DELETED = 202,
1088     OC_EH_VALID = 203,
1089     OC_EH_CHANGED = 204,
1090     OC_EH_CONTENT = 205,
1091     OC_EH_BAD_REQ = 400,
1092     OC_EH_UNAUTHORIZED_REQ = 401,
1093     OC_EH_BAD_OPT = 402,
1094     OC_EH_FORBIDDEN = 403,
1095     OC_EH_RESOURCE_NOT_FOUND = 404,
1096     OC_EH_METHOD_NOT_ALLOWED = 405,
1097     OC_EH_NOT_ACCEPTABLE = 406,
1098     OC_EH_TOO_LARGE = 413,
1099     OC_EH_UNSUPPORTED_MEDIA_TYPE = 415,
1100     OC_EH_INTERNAL_SERVER_ERROR = 500,
1101     OC_EH_BAD_GATEWAY = 502,
1102     OC_EH_SERVICE_UNAVAILABLE = 503,
1103     OC_EH_RETRANSMIT_TIMEOUT = 504
1104 } OCEntityHandlerResult;
1105
1106 /**
1107  * This structure will be used to define the vendor specific header options to be included
1108  * in communication packets.
1109  */
1110 typedef struct OCHeaderOption
1111 {
1112     /** The protocol ID this option applies to.*/
1113     OCTransportProtocolID protocolID;
1114
1115     /** The header option ID which will be added to communication packets.*/
1116     uint16_t optionID;
1117
1118     /** its length 191.*/
1119     uint16_t optionLength;
1120
1121     /** pointer to its data.*/
1122     uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
1123
1124 #ifdef SUPPORTS_DEFAULT_CTOR
1125     OCHeaderOption() = default;
1126     OCHeaderOption(OCTransportProtocolID pid,
1127                    uint16_t optId,
1128                    uint16_t optlen,
1129                    const uint8_t* optData)
1130         : protocolID(pid),
1131           optionID(optId),
1132           optionLength(optlen)
1133     {
1134
1135         // parameter includes the null terminator.
1136         optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
1137                         optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
1138         memcpy(optionData, optData, optionLength);
1139         optionData[optionLength - 1] = '\0';
1140     }
1141 #endif
1142 } OCHeaderOption;
1143
1144 /**
1145  * This structure describes the platform properties. All non-Null properties will be
1146  * included in a platform discovery request.
1147  */
1148 typedef struct
1149 {
1150     /** Platform ID.*/
1151     char *platformID;
1152
1153     /** Manufacturer name.*/
1154     char *manufacturerName;
1155
1156     /** Manufacturer URL for platform property.*/
1157     char *manufacturerUrl;
1158
1159     /** Model number.*/
1160     char *modelNumber;
1161
1162     /** Manufacturer date.*/
1163     char *dateOfManufacture;
1164
1165     /** Platform version.*/
1166     char *platformVersion;
1167
1168     /** Operating system version.*/
1169     char *operatingSystemVersion;
1170
1171     /** HW version.*/
1172     char *hardwareVersion;
1173
1174     /** FW version.*/
1175     char *firmwareVersion;
1176
1177     /** Platform support URL.*/
1178     char *supportUrl;
1179
1180     /** System time.*/
1181     char *systemTime;
1182
1183 } OCPlatformInfo;
1184
1185 /**
1186  * This structure is expected as input for device properties.
1187  * device name is mandatory and expected from the application.
1188  * device id of type UUID will be generated by the stack.
1189  */
1190 typedef struct
1191 {
1192     /** Pointer to the device name.*/
1193     char *deviceName;
1194     /** Pointer to the types.*/
1195     OCStringLL *types;
1196     /** Pointer to the device specification version.*/
1197     char *specVersion;
1198     /** Pointer to the device data model versions (in CSV format).*/
1199     OCStringLL *dataModelVersions;
1200 } OCDeviceInfo;
1201
1202 #ifdef RA_ADAPTER
1203 /**
1204  * callback for bound JID
1205  */
1206 typedef void (*jid_bound_cb)(char *jid);
1207
1208 /**
1209  * CA Remote Access information for XMPP Client
1210  *
1211  */
1212 typedef struct
1213 {
1214     char *hostname;     /**< XMPP server hostname */
1215     uint16_t   port;    /**< XMPP server serivce port */
1216     char *xmpp_domain;  /**< XMPP login domain */
1217     char *username;     /**< login username */
1218     char *password;     /**< login password */
1219     char *resource;     /**< specific resource for login */
1220     char *user_jid;     /**< specific JID for login */
1221     jid_bound_cb jidbound;  /**< callback when JID bound */
1222 } OCRAInfo_t;
1223 #endif  /* RA_ADAPTER */
1224
1225
1226 /** Enum to describe the type of object held by the OCPayload object.*/
1227 typedef enum
1228 {
1229     /** Contents of the payload are invalid */
1230     PAYLOAD_TYPE_INVALID,
1231     /** The payload is an OCDiscoveryPayload */
1232     PAYLOAD_TYPE_DISCOVERY,
1233     /** The payload is an OCDevicePayload */
1234     PAYLOAD_TYPE_DEVICE,
1235     /** The payload is an OCPlatformPayload */
1236     PAYLOAD_TYPE_PLATFORM,
1237     /** The payload is an OCRepPayload */
1238     PAYLOAD_TYPE_REPRESENTATION,
1239     /** The payload is an OCSecurityPayload */
1240     PAYLOAD_TYPE_SECURITY,
1241     /** The payload is an OCPresencePayload */
1242     PAYLOAD_TYPE_PRESENCE
1243 } OCPayloadType;
1244
1245 /**
1246  * A generic struct representing a payload returned from a resource operation
1247  *
1248  * A pointer to OCPayLoad can be cast to a more specific struct to access members
1249  * for the its type.
1250  */
1251 typedef struct
1252 {
1253     /** The type of message that was received */
1254     OCPayloadType type;
1255 } OCPayload;
1256
1257 typedef enum
1258 {
1259     OCREP_PROP_NULL,
1260     OCREP_PROP_INT,
1261     OCREP_PROP_DOUBLE,
1262     OCREP_PROP_BOOL,
1263     OCREP_PROP_STRING,
1264     OCREP_PROP_BYTE_STRING,
1265     OCREP_PROP_OBJECT,
1266     OCREP_PROP_ARRAY
1267 }OCRepPayloadPropType;
1268
1269 /** This structure will be used to represent a binary string for CBOR payloads.*/
1270 typedef struct
1271 {
1272     /** pointer to data bytes.*/
1273     uint8_t* bytes;
1274
1275     /** number of data bytes.*/
1276     size_t   len;
1277 } OCByteString;
1278
1279 #define MAX_REP_ARRAY_DEPTH 3
1280 typedef struct
1281 {
1282     OCRepPayloadPropType type;
1283     size_t dimensions[MAX_REP_ARRAY_DEPTH];
1284
1285     union
1286     {
1287         int64_t* iArray;
1288         double* dArray;
1289         bool* bArray;
1290         char** strArray;
1291
1292         /** pointer to ByteString array.*/
1293         OCByteString* ocByteStrArray;
1294
1295         struct OCRepPayload** objArray;
1296     };
1297 } OCRepPayloadValueArray;
1298
1299 typedef struct OCRepPayloadValue
1300 {
1301     char* name;
1302     OCRepPayloadPropType type;
1303     union
1304     {
1305         int64_t i;
1306         double d;
1307         bool b;
1308         char* str;
1309
1310         /** ByteString object.*/
1311         OCByteString ocByteStr;
1312
1313         struct OCRepPayload* obj;
1314         OCRepPayloadValueArray arr;
1315     };
1316     struct OCRepPayloadValue* next;
1317
1318 } OCRepPayloadValue;
1319
1320 // used for get/set/put/observe/etc representations
1321 typedef struct OCRepPayload
1322 {
1323     OCPayload base;
1324     char* uri;
1325     OCStringLL* types;
1326     OCStringLL* interfaces;
1327     OCRepPayloadValue* values;
1328     struct OCRepPayload* next;
1329 } OCRepPayload;
1330
1331 // used inside a discovery payload
1332 typedef struct OCResourcePayload
1333 {
1334     char* uri;
1335     OCStringLL* types;
1336     OCStringLL* interfaces;
1337     uint8_t bitmap;
1338     bool secure;
1339     uint16_t port;
1340 #ifdef TCP_ADAPTER
1341     uint16_t tcpPort;
1342 #endif
1343     struct OCResourcePayload* next;
1344 } OCResourcePayload;
1345
1346 typedef struct OCDiscoveryPayload
1347 {
1348     OCPayload base;
1349
1350     /** Device Id */
1351     char *sid;
1352
1353     /** A special case for handling RD address. */
1354     char* baseURI;
1355
1356     /** Name */
1357     char *name;
1358
1359     /** HREF */
1360     char *uri;
1361
1362     /** Resource Type */
1363     OCStringLL *type;
1364
1365     /** Interface */
1366     OCStringLL *iface;
1367
1368     /** This structure holds the old /oic/res response. */
1369     OCResourcePayload *resources;
1370
1371     /** Holding address of the next DiscoveryPayload. */
1372     struct OCDiscoveryPayload *next;
1373
1374 } OCDiscoveryPayload;
1375
1376 typedef struct
1377 {
1378     OCPayload base;
1379     char *sid;
1380     char* deviceName;
1381     char* specVersion;
1382     OCStringLL *dataModelVersions;
1383     OCStringLL *interfaces;
1384     OCStringLL *types;
1385 } OCDevicePayload;
1386
1387 typedef struct
1388 {
1389     OCPayload base;
1390     char* uri;
1391     OCPlatformInfo info;
1392     OCStringLL* rt;
1393     OCStringLL* interfaces;
1394 } OCPlatformPayload;
1395
1396 typedef struct
1397 {
1398     OCPayload base;
1399     uint8_t* securityData;
1400     size_t payloadSize;
1401 } OCSecurityPayload;
1402
1403 #ifdef WITH_PRESENCE
1404 typedef struct
1405 {
1406     OCPayload base;
1407     uint32_t sequenceNumber;
1408     uint32_t maxAge;
1409     OCPresenceTrigger trigger;
1410     char* resourceType;
1411 } OCPresencePayload;
1412 #endif
1413
1414 /**
1415  * Incoming requests handled by the server. Requests are passed in as a parameter to the
1416  * OCEntityHandler callback API.
1417  * The OCEntityHandler callback API must be implemented in the application in order
1418  * to receive these requests.
1419  */
1420 typedef struct
1421 {
1422     /** Associated resource.*/
1423     OCResourceHandle resource;
1424
1425     /** Associated request handle.*/
1426     OCRequestHandle requestHandle;
1427
1428     /** the REST method retrieved from received request PDU.*/
1429     OCMethod method;
1430
1431     /** description of endpoint that sent the request.*/
1432     OCDevAddr devAddr;
1433
1434     /** resource query send by client.*/
1435     char * query;
1436
1437     /** Information associated with observation - valid only when OCEntityHandler flag includes
1438      * ::OC_OBSERVE_FLAG.*/
1439     OCObservationInfo obsInfo;
1440
1441     /** Number of the received vendor specific header options.*/
1442     uint8_t numRcvdVendorSpecificHeaderOptions;
1443
1444     /** Pointer to the array of the received vendor specific header options.*/
1445     OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1446
1447     /** Message id.*/
1448     uint16_t messageID;
1449
1450     /** the payload from the request PDU.*/
1451     OCPayload *payload;
1452
1453 } OCEntityHandlerRequest;
1454
1455
1456 /**
1457  * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1458  */
1459 typedef struct
1460 {
1461     /** Address of remote server.*/
1462     OCDevAddr devAddr;
1463
1464     /** backward compatibility (points to devAddr).*/
1465     OCDevAddr *addr;
1466
1467     /** backward compatibility.*/
1468     OCConnectivityType connType;
1469
1470     /** the security identity of the remote server.*/
1471     OCIdentity identity;
1472
1473     /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1474     OCStackResult result;
1475
1476     /** If associated with observe, this will represent the sequence of notifications from server.*/
1477     uint32_t sequenceNumber;
1478
1479     /** resourceURI.*/
1480     const char * resourceUri;
1481
1482     /** the payload for the response PDU.*/
1483     OCPayload *payload;
1484
1485     /** Number of the received vendor specific header options.*/
1486     uint8_t numRcvdVendorSpecificHeaderOptions;
1487
1488     /** An array of the received vendor specific header options.*/
1489     OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1490 } OCClientResponse;
1491
1492 /**
1493  * Request handle is passed to server via the entity handler for each incoming request.
1494  * Stack assigns when request is received, server sets to indicate what request response is for.
1495  */
1496 typedef struct
1497 {
1498     /** Request handle.*/
1499     OCRequestHandle requestHandle;
1500
1501     /** Resource handle.*/
1502     OCResourceHandle resourceHandle;
1503
1504     /** Allow the entity handler to pass a result with the response.*/
1505     OCEntityHandlerResult  ehResult;
1506
1507     /** This is the pointer to server payload data to be transferred.*/
1508     OCPayload* payload;
1509
1510     /** number of the vendor specific header options .*/
1511     uint8_t numSendVendorSpecificHeaderOptions;
1512
1513     /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1514     OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1515
1516     /** URI of new resource that entity handler might create.*/
1517     char resourceUri[MAX_URI_LENGTH];
1518
1519     /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1520     uint8_t persistentBufferFlag;
1521 } OCEntityHandlerResponse;
1522
1523 /**
1524  * Entity's state
1525  */
1526 typedef enum
1527 {
1528     /** Request state.*/
1529     OC_REQUEST_FLAG = (1 << 1),
1530     /** Observe state.*/
1531     OC_OBSERVE_FLAG = (1 << 2)
1532 } OCEntityHandlerFlag;
1533
1534 /**
1535  * Possible return values from client application callback
1536  *
1537  * A client application callback returns an OCStackApplicationResult to indicate whether
1538  * the stack should continue to keep the callback registered.
1539  */
1540 typedef enum
1541 {
1542     /** Make no more calls to the callback and call the OCClientContextDeleter for this callback */
1543     OC_STACK_DELETE_TRANSACTION = 0,
1544     /** Keep this callback registered and call it if an apropriate event occurs */
1545     OC_STACK_KEEP_TRANSACTION
1546 } OCStackApplicationResult;
1547
1548
1549 //#ifdef DIRECT_PAIRING
1550 /**
1551  * @brief   direct pairing Method Type.
1552  *              0:  not allowed
1553  *              1:  pre-configured pin
1554  *              2:  random pin
1555  */
1556 typedef enum OCPrm
1557 {
1558     DP_NOT_ALLOWED             = 0x0,
1559     DP_PRE_CONFIGURED        = (0x1 << 0),
1560     DP_RANDOM_PIN               = (0x1 << 1),
1561 } OCPrm_t;
1562
1563 /**
1564  * Device Information of discoverd direct pairing device(s).
1565  */
1566 typedef struct OCDPDev
1567 {
1568     OCDevAddr               endpoint;
1569     OCConnectivityType   connType;
1570     uint16_t                     securePort;
1571     bool                  edp;
1572     OCPrm_t           *prm;
1573     size_t                prmLen;
1574     OCUUIdentity     deviceID;
1575     OCUUIdentity     rowner;
1576     struct OCDPDev *next;
1577 } OCDPDev_t;
1578 //#endif // DIRECT_PAIRING
1579
1580 /*
1581  * -------------------------------------------------------------------------------------------
1582  * Callback function definitions
1583  * -------------------------------------------------------------------------------------------
1584  */
1585
1586 /**
1587  * Client applications implement this callback to consume responses received from Servers.
1588  */
1589 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1590     OCClientResponse * clientResponse);
1591
1592 /**
1593  * Client applications using a context pointer implement this callback to delete the
1594  * context upon removal of the callback/context pointer from the internal callback-list.
1595  */
1596 typedef void (* OCClientContextDeleter)(void *context);
1597
1598 /**
1599  * This info is passed from application to OC Stack when initiating a request to Server.
1600  */
1601 typedef struct OCCallbackData
1602 {
1603     /** Pointer to the context.*/
1604     void *context;
1605
1606     /** The pointer to a function the stack will call to handle the requests.*/
1607     OCClientResponseHandler cb;
1608
1609     /** A pointer to a function to delete the context when this callback is removed.*/
1610     OCClientContextDeleter cd;
1611
1612 #ifdef SUPPORTS_DEFAULT_CTOR
1613     OCCallbackData() = default;
1614     OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1615         :context(ctx), cb(callback), cd(deleter){}
1616 #endif
1617 } OCCallbackData;
1618
1619 /**
1620  * Application server implementations must implement this callback to consume requests OTA.
1621  * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1622  *
1623  * When you set specific return value like OC_EH_CHANGED, OC_EH_CONTENT,
1624  * OC_EH_SLOW and etc in entity handler callback,
1625  * ocstack will be not send response automatically to client
1626  * except for error return value like OC_EH_ERROR.
1627  *
1628  * If you want to send response to client with specific result,
1629  * OCDoResponse API should be called with the result value.
1630  *
1631  * e.g)
1632  *
1633  * OCEntityHandlerResponse response;
1634  *
1635  * ..
1636  *
1637  * response.ehResult = OC_EH_CHANGED;
1638  *
1639  * ..
1640  *
1641  * OCDoResponse(&response)
1642  *
1643  * ..
1644  *
1645  * return OC_EH_OK;
1646  */
1647 typedef OCEntityHandlerResult (*OCEntityHandler)
1648 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1649
1650 /**
1651  * Device Entity handler need to use this call back instead of OCEntityHandler.
1652  *
1653  * When you set specific return value like OC_EH_CHANGED, OC_EH_CONTENT,
1654  * OC_EH_SLOW and etc in entity handler callback,
1655  * ocstack will be not send response automatically to client
1656  * except for error return value like OC_EH_ERROR.
1657  *
1658  * If you want to send response to client with specific result,
1659  * OCDoResponse API should be called with the result value.
1660  *
1661  * e.g)
1662  *
1663  * OCEntityHandlerResponse response;
1664  *
1665  * ..
1666  *
1667  * response.ehResult = OC_EH_CHANGED;
1668  *
1669  * ..
1670  *
1671  * OCDoResponse(&response)
1672  *
1673  * ..
1674  *
1675  * return OC_EH_OK;
1676  */
1677 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1678 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1679
1680 //#ifdef DIRECT_PAIRING
1681 /**
1682  * Callback function definition of direct-pairing
1683  *
1684  * @param[OUT] ctx - user context returned in the callback.
1685  * @param[OUT] peer - pairing device info.
1686  * @param[OUT] result - It's returned with 'OC_STACK_XXX'. It will return 'OC_STACK_OK'
1687  *                                   if D2D pairing is success without error
1688  */
1689 typedef void (*OCDirectPairingCB)(void *ctx, OCDPDev_t *peer, OCStackResult result);
1690 //#endif // DIRECT_PAIRING
1691
1692 #ifdef __cplusplus
1693 }
1694 #endif // __cplusplus
1695
1696 #endif /* OCTYPES_H_ */