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