[IOT-921]Return correct resource type in /oic/d
[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 "platform_features.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 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
68 /** Gateway URI.*/
69 #define OC_RSRVD_GATEWAY_URI                  "/oic/gateway"
70 #endif
71 #ifdef WITH_PRESENCE
72
73 /** Presence URI through which the OIC devices advertise their presence.*/
74 #define OC_RSRVD_PRESENCE_URI                 "/oic/ad"
75
76 /** Sets the default time to live (TTL) for presence.*/
77 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
78
79 /** For multicast Discovery mechanism.*/
80 #define OC_MULTICAST_DISCOVERY_URI           "/oic/res"
81
82 /** Separator for multiple query string.*/
83 #define OC_QUERY_SEPARATOR                "&;"
84
85 /**
86  *  OC_DEFAULT_PRESENCE_TTL_SECONDS sets the default time to live (TTL) for presence.
87  */
88 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
89
90 /**
91  *  OC_MAX_PRESENCE_TTL_SECONDS sets the maximum time to live (TTL) for presence.
92  *  NOTE: Changing the setting to a longer duration may lead to unsupported and untested
93  *  operation.
94  *  60 sec/min * 60 min/hr * 24 hr/day
95  */
96 #define OC_MAX_PRESENCE_TTL_SECONDS     (60 * 60 * 24)
97 #endif
98
99 /**
100  *  Presence "Announcement Triggers".
101  */
102
103 /** To create.*/
104 #define OC_RSRVD_TRIGGER_CREATE         "create"
105
106 /** To change.*/
107 #define OC_RSRVD_TRIGGER_CHANGE         "change"
108
109 /** To delete.*/
110 #define OC_RSRVD_TRIGGER_DELETE         "delete"
111
112 /**
113  *  Attributes used to form a proper OIC conforming JSON message.
114  */
115
116 #define OC_RSRVD_OC                     "oic"
117
118 /** For payload. */
119
120 #define OC_RSRVD_PAYLOAD                "payload"
121
122 /** To represent href */
123 #define OC_RSRVD_HREF                   "href"
124
125 /** To represent property*/
126 #define OC_RSRVD_PROPERTY               "prop"
127
128 /** For representation.*/
129 #define OC_RSRVD_REPRESENTATION         "rep"
130
131 /** To represent content type.*/
132 #define OC_RSRVD_CONTENT_TYPE           "ct"
133
134 /** To represent resource type.*/
135 #define OC_RSRVD_RESOURCE_TYPE          "rt"
136
137 /** To represent resource type with presence.*/
138 #define OC_RSRVD_RESOURCE_TYPE_PRESENCE "oic.wk.ad"
139
140 /** To represent resource type with device.*/
141 #define OC_RSRVD_RESOURCE_TYPE_DEVICE   "oic.wk.d"
142
143 /** To represent resource type with platform.*/
144 #define OC_RSRVD_RESOURCE_TYPE_PLATFORM "oic.wk.p"
145
146 /** To represent interface.*/
147 #define OC_RSRVD_INTERFACE              "if"
148
149 /** To represent time to live.*/
150 #define OC_RSRVD_TTL                    "ttl"
151
152 /** To represent non*/
153 #define OC_RSRVD_NONCE                  "non"
154
155 /** To represent trigger type.*/
156 #define OC_RSRVD_TRIGGER                "trg"
157
158 /** To represent links.*/
159 #define OC_RSRVD_LINKS                  "links"
160
161 /** To represent default interface.*/
162 #define OC_RSRVD_INTERFACE_DEFAULT      "oic.if.baseline"
163
164 /** To represent read-only interface.*/
165 #define OC_RSRVD_INTERFACE_READ         "oic.if.r"
166
167 /** To represent ll interface.*/
168 #define OC_RSRVD_INTERFACE_LL           "oic.if.ll"
169
170 /** To represent batch interface.*/
171 #define OC_RSRVD_INTERFACE_BATCH        "oic.if.b"
172
173 /** To represent interface group.*/
174 #define OC_RSRVD_INTERFACE_GROUP        "oic.mi.grp"
175
176 /** To represent MFG date.*/
177 #define OC_RSRVD_MFG_DATE               "mndt"
178
179 /** To represent FW version.*/
180 #define OC_RSRVD_FW_VERSION             "mnfv"
181
182 /** To represent host name.*/
183 #define OC_RSRVD_HOST_NAME              "hn"
184
185 /** To represent policy.*/
186 #define OC_RSRVD_POLICY                 "p"
187
188 /** To represent bitmap.*/
189 #define OC_RSRVD_BITMAP                 "bm"
190
191 /** For security.*/
192 #define OC_RSRVD_SECURE                 "sec"
193
194 /** Port. */
195 #define OC_RSRVD_HOSTING_PORT           "port"
196
197 /** For Server instance ID.*/
198 #define OC_RSRVD_SERVER_INSTANCE_ID     "sid"
199
200 /**
201  *  Platform.
202  */
203
204 /** Platform ID. */
205 #define OC_RSRVD_PLATFORM_ID            "pi"
206
207 /** Platform MFG NAME. */
208 #define OC_RSRVD_MFG_NAME               "mnmn"
209
210 /** Platform URL. */
211 #define OC_RSRVD_MFG_URL                "mnml"
212
213 /** Model Number.*/
214 #define OC_RSRVD_MODEL_NUM              "mnmo"
215
216 /** Platform MFG Date.*/
217 #define OC_RSRVD_MFG_DATE               "mndt"
218
219 /** Platform versio.n */
220 #define OC_RSRVD_PLATFORM_VERSION       "mnpv"
221
222 /** Platform Operating system version. */
223 #define OC_RSRVD_OS_VERSION             "mnos"
224
225 /** Platform Hardware version. */
226 #define OC_RSRVD_HARDWARE_VERSION       "mnhw"
227
228 /**Platform Firmware version. */
229 #define OC_RSRVD_FIRMWARE_VERSION       "mnfv"
230
231 /** Support URL for the platform. */
232 #define OC_RSRVD_SUPPORT_URL            "mnsl"
233
234 /** System time for the platform. */
235 #define OC_RSRVD_SYSTEM_TIME             "st"
236
237 /**
238  *  Device.
239  */
240
241 /** Device ID.*/
242 #define OC_RSRVD_DEVICE_ID              "di"
243
244 /** Device Name.*/
245 #define OC_RSRVD_DEVICE_NAME            "n"
246
247 /** Device specification version.*/
248 #define OC_RSRVD_SPEC_VERSION           "icv"
249
250 /** Device data model.*/
251 #define OC_RSRVD_DATA_MODEL_VERSION     "dmv"
252
253 /** Device specification version.*/
254 #define OC_SPEC_VERSION                "core.1.0.0"
255
256 /** Device Data Model version.*/
257 #define OC_DATA_MODEL_VERSION          "res.1.0.0"
258
259 /**
260  *  These provide backward compatibility - their use is deprecated.
261  */
262 #ifndef GOING_AWAY
263
264 /** Multicast Prefix.*/
265 #define OC_MULTICAST_PREFIX                  "224.0.1.187:5683"
266
267 /** Multicast IP address.*/
268 #define OC_MULTICAST_IP                      "224.0.1.187"
269
270 /** Multicast Port.*/
271 #define OC_MULTICAST_PORT                    5683
272 #endif // GOING_AWAY
273
274 /** Max Device address size. */
275 #ifdef RA_ADAPTER
276 #define MAX_ADDR_STR_SIZE (256)
277 #else
278 /** Max Address could be "coap+tcp://[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx]:xxxxx" */
279 #define MAX_ADDR_STR_SIZE (59)
280 #endif
281
282 /** Length of MAC address */
283 #define MAC_ADDR_STR_SIZE (17)
284
285 /** Blocks of MAC address */
286 #define MAC_ADDR_BLOCKS (6)
287
288 /** Max identity size. */
289 #define MAX_IDENTITY_SIZE (32)
290
291 /** Universal unique identity size. */
292 #define UUID_IDENTITY_SIZE (128/8)
293
294 /** Resource Directory */
295
296 /** Resource Directory URI used to Discover RD and Publish resources.*/
297 #define OC_RSRVD_RD_URI                  "/oic/rd"
298
299 /** To represent resource type with rd.*/
300 #define OC_RSRVD_RESOURCE_TYPE_RD        "oic.wk.rd"
301
302 /** RD Discovery bias factor type. */
303 #define OC_RSRVD_RD_DISCOVERY_SEL        "sel"
304
305 /** Base URI. */
306 #define OC_RSRVD_BASE_URI                "baseURI"
307
308 /** Unique value per collection/link. */
309 #define OC_RSRVD_INS                     "ins"
310
311 /** Allowable resource types in the links. */
312 #define OC_RSRVD_RTS                     "rts"
313
314 /** Default relationship. */
315 #define OC_RSRVD_DREL                    "drel"
316
317 /** Defines relationship between links. */
318 #define OC_RSRVD_REL                     "rel"
319
320 /** Defines title. */
321 #define OC_RSRVD_TITLE                   "title"
322
323 /** Defines URI. */
324 #define OC_RSRVD_URI                     "uri"
325
326 /** Defines media type. */
327 #define OC_RSRVD_MEDIA_TYPE              "mt"
328
329 /** To represent resource type with Publish RD.*/
330 #define OC_RSRVD_RESOURCE_TYPE_RDPUBLISH "oic.wk.rdPub"
331
332 /**
333  * Mark a parameter as unused. Used to prevent unused variable compiler warnings.
334  * Used in three cases:
335  * 1. in callbacks when one of the parameters are unused
336  * 2. when due to code changes a functions parameter is no longer
337  *    used but must be left in place for backward compatibility
338  *    reasons.
339  * 3. a variable is only used in the debug build variant and would
340  *    give a build warning in release mode.
341  */
342 #define OC_UNUSED(x) (void)(x)
343
344 /**
345  * These enums (OCTransportAdapter and OCTransportFlags) must
346  * be kept synchronized with OCConnectivityType (below) as well as
347  * CATransportAdapter and CATransportFlags (in CACommon.h).
348  */
349 typedef enum
350 {
351     /** value zero indicates discovery.*/
352     OC_DEFAULT_ADAPTER = 0,
353
354     /** IPv4 and IPv6, including 6LoWPAN.*/
355     OC_ADAPTER_IP           = (1 << 0),
356
357     /** GATT over Bluetooth LE.*/
358     OC_ADAPTER_GATT_BTLE    = (1 << 1),
359
360     /** RFCOMM over Bluetooth EDR.*/
361     OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
362 #ifdef RA_ADAPTER
363     /**Remote Access over XMPP.*/
364     OC_ADAPTER_REMOTE_ACCESS = (1 << 3),
365 #endif
366     /** CoAP over TCP.*/
367     OC_ADAPTER_TCP           = (1 << 4),
368
369     /** NFC Transport for Messaging.*/
370     OC_ADAPTER_NFC           = (1 << 5)
371 } OCTransportAdapter;
372
373 /**
374  *  Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
375  */
376 typedef enum
377 {
378     /** default flag is 0*/
379     OC_DEFAULT_FLAGS = 0,
380
381     /** Insecure transport is the default (subject to change).*/
382     /** secure the transport path*/
383     OC_FLAG_SECURE     = (1 << 4),
384
385     /** IPv4 & IPv6 auto-selection is the default.*/
386     /** IP adapter only.*/
387     OC_IP_USE_V6       = (1 << 5),
388
389     /** IP adapter only.*/
390     OC_IP_USE_V4       = (1 << 6),
391
392     /** internal use only.*/
393     OC_RESERVED1       = (1 << 7),   // internal use only
394
395     /** Link-Local multicast is the default multicast scope for IPv6.
396      *  These are placed here to correspond to the IPv6 multicast address bits.*/
397
398     /** IPv6 Interface-Local scope (loopback).*/
399     OC_SCOPE_INTERFACE = 0x1,
400
401     /** IPv6 Link-Local scope (default).*/
402     OC_SCOPE_LINK      = 0x2,
403
404     /** IPv6 Realm-Local scope. */
405     OC_SCOPE_REALM     = 0x3,
406
407     /** IPv6 Admin-Local scope. */
408     OC_SCOPE_ADMIN     = 0x4,
409
410     /** IPv6 Site-Local scope. */
411     OC_SCOPE_SITE      = 0x5,
412
413     /** IPv6 Organization-Local scope. */
414     OC_SCOPE_ORG       = 0x8,
415
416     /**IPv6 Global scope. */
417     OC_SCOPE_GLOBAL    = 0xE,
418
419 } OCTransportFlags;
420
421 /** Bit mask for scope.*/
422 #define OC_MASK_SCOPE    (0x000F)
423
424 /** Bit mask for Mods.*/
425 #define OC_MASK_MODS     (0x0FF0)
426 #define OC_MASK_FAMS     (OC_IP_USE_V6|OC_IP_USE_V4)
427
428 typedef struct OCStringLL
429 {
430     struct OCStringLL *next;
431     char* value;
432 } OCStringLL;
433
434 /**
435  * End point identity.
436  */
437 typedef struct
438 {
439     /** Identity Length */
440     uint16_t id_length;
441
442     /** Array of end point identity.*/
443     unsigned char id[MAX_IDENTITY_SIZE];
444 } OCIdentity;
445
446 /**
447  * Universally unique identifier.
448  */
449 typedef struct
450 {
451     /** identitifier string.*/
452     unsigned char id[UUID_IDENTITY_SIZE];
453 } OCUUIdentity;
454
455 /**
456  * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
457  * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
458  */
459 typedef struct
460 {
461     /** adapter type.*/
462     OCTransportAdapter      adapter;
463
464     /** transport modifiers.*/
465     OCTransportFlags        flags;
466
467     /** for IP.*/
468     uint16_t                port;
469
470     /** address for all adapters.*/
471     char                    addr[MAX_ADDR_STR_SIZE];
472
473     /** usually zero for default interface.*/
474     uint32_t                interface;
475 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
476     char                    routeData[MAX_ADDR_STR_SIZE]; //destination GatewayID:ClientId
477 #endif
478 } OCDevAddr;
479
480 /**
481  * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
482  * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
483  * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
484  * like Arduino.
485  *
486  * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
487  */
488 typedef enum
489 {
490     /** use when defaults are ok. */
491     CT_DEFAULT = 0,
492
493     /** IPv4 and IPv6, including 6LoWPAN.*/
494     CT_ADAPTER_IP           = (1 << 16),
495
496     /** GATT over Bluetooth LE.*/
497     CT_ADAPTER_GATT_BTLE    = (1 << 17),
498
499     /** RFCOMM over Bluetooth EDR.*/
500     CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
501
502 #ifdef RA_ADAPTER
503     /** Remote Access over XMPP.*/
504     CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
505 #endif
506     /** CoAP over TCP.*/
507     CT_ADAPTER_TCP     = (1 << 20),
508
509     /** NFC Transport.*/
510     CT_ADAPTER_NFC     = (1 << 21),
511
512     /** Insecure transport is the default (subject to change).*/
513
514     /** secure the transport path.*/
515     CT_FLAG_SECURE     = (1 << 4),
516
517     /** IPv4 & IPv6 autoselection is the default.*/
518
519     /** IP adapter only.*/
520     CT_IP_USE_V6       = (1 << 5),
521
522     /** IP adapter only.*/
523     CT_IP_USE_V4       = (1 << 6),
524
525     /** Link-Local multicast is the default multicast scope for IPv6.
526      * These are placed here to correspond to the IPv6 address bits.*/
527
528     /** IPv6 Interface-Local scope(loopback).*/
529     CT_SCOPE_INTERFACE = 0x1,
530
531     /** IPv6 Link-Local scope (default).*/
532     CT_SCOPE_LINK      = 0x2,
533
534     /** IPv6 Realm-Local scope.*/
535     CT_SCOPE_REALM     = 0x3,
536
537     /** IPv6 Admin-Local scope.*/
538     CT_SCOPE_ADMIN     = 0x4,
539
540     /** IPv6 Site-Local scope.*/
541     CT_SCOPE_SITE      = 0x5,
542
543     /** IPv6 Organization-Local scope.*/
544     CT_SCOPE_ORG       = 0x8,
545
546     /** IPv6 Global scope.*/
547     CT_SCOPE_GLOBAL    = 0xE,
548 } OCConnectivityType;
549
550 /** bit shift required for connectivity adapter.*/
551 #define CT_ADAPTER_SHIFT 16
552
553 /** Mask Flag.*/
554 #define CT_MASK_FLAGS 0xFFFF
555
556 /** Mask Adapter.*/
557 #define CT_MASK_ADAPTER 0xFFFF0000
558
559 /**
560  *  OCDoResource methods to dispatch the request
561  */
562 typedef enum
563 {
564     OC_REST_NOMETHOD       = 0,
565
566     /** Read.*/
567     OC_REST_GET            = (1 << 0),
568
569     /** Write.*/
570     OC_REST_PUT            = (1 << 1),
571
572     /** Update.*/
573     OC_REST_POST           = (1 << 2),
574
575     /** Delete.*/
576     OC_REST_DELETE         = (1 << 3),
577
578     /** Register observe request for most up date notifications ONLY.*/
579     OC_REST_OBSERVE        = (1 << 4),
580
581     /** Register observe request for all notifications, including stale notifications.*/
582     OC_REST_OBSERVE_ALL    = (1 << 5),
583
584     /** De-register observation, intended for internal use.*/
585     OC_REST_CANCEL_OBSERVE = (1 << 6),
586
587     #ifdef WITH_PRESENCE
588     /** Subscribe for all presence notifications of a particular resource.*/
589     OC_REST_PRESENCE       = (1 << 7),
590
591     #endif
592     /** Allows OCDoResource caller to do discovery.*/
593     OC_REST_DISCOVER       = (1 << 8)
594 } OCMethod;
595
596 /**
597  *  Formats for payload encoding.
598  */
599 typedef enum
600 {
601     OC_FORMAT_CBOR,
602     OC_FORMAT_UNDEFINED,
603     OC_FORMAT_UNSUPPORTED,
604 } OCPayloadFormat;
605
606 /**
607  * Host Mode of Operation.
608  */
609 typedef enum
610 {
611     OC_CLIENT = 0,
612     OC_SERVER,
613     OC_CLIENT_SERVER,
614     OC_GATEWAY          /**< Client server mode along with routing capabilities.*/
615 } OCMode;
616
617 /**
618  * Quality of Service attempts to abstract the guarantees provided by the underlying transport
619  * protocol. The precise definitions of each quality of service level depend on the
620  * implementation. In descriptions below are for the current implementation and may changed
621  * over time.
622  */
623 typedef enum
624 {
625     /** Packet delivery is best effort.*/
626     OC_LOW_QOS = 0,
627
628     /** Packet delivery is best effort.*/
629     OC_MEDIUM_QOS,
630
631     /** Acknowledgments are used to confirm delivery.*/
632     OC_HIGH_QOS,
633
634     /** No Quality is defined, let the stack decide.*/
635     OC_NA_QOS
636 } OCQualityOfService;
637
638 /**
639  * Resource Properties.
640  * The value of a policy property is defined as bitmap.
641  * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
642  * Not including the policy property is equivalent to zero.
643  *
644  */
645 typedef enum
646 {
647     /** When none of the bits are set, the resource is non-discoverable &
648      *  non-observable by the client.*/
649     OC_RES_PROP_NONE = (0),
650
651     /** When this bit is set, the resource is allowed to be discovered by clients.*/
652     OC_DISCOVERABLE  = (1 << 0),
653
654     /** When this bit is set, the resource is allowed to be observed by clients.*/
655     OC_OBSERVABLE    = (1 << 1),
656
657     /** When this bit is set, the resource is initialized, otherwise the resource
658      *  is 'inactive'. 'inactive' signifies that the resource has been marked for
659      *  deletion or is already deleted.*/
660     OC_ACTIVE        = (1 << 2),
661
662     /** When this bit is set, the resource has been marked as 'slow'.
663      * 'slow' signifies that responses from this resource can expect delays in
664      *  processing its requests from clients.*/
665     OC_SLOW          = (1 << 3),
666
667     /** When this bit is set, the resource is a secure resource.*/
668     OC_SECURE        = (1 << 4),
669
670     /** When this bit is set, the resource is allowed to be discovered only
671      *  if discovery request contains an explicit querystring.
672      *  Ex: GET /oic/res?rt=oic.sec.acl */
673     OC_EXPLICIT_DISCOVERABLE   = (1 << 5)
674 } OCResourceProperty;
675
676 /**
677  * Transport Protocol IDs.
678  */
679 typedef enum
680 {
681     /** For invalid ID.*/
682     OC_INVALID_ID   = (1 << 0),
683
684     /* For coap ID.*/
685     OC_COAP_ID      = (1 << 1)
686 } OCTransportProtocolID;
687
688 /**
689  * Declares Stack Results & Errors.
690  */
691 typedef enum
692 {
693     /** Success status code - START HERE.*/
694     OC_STACK_OK = 0,
695     OC_STACK_RESOURCE_CREATED,
696     OC_STACK_RESOURCE_DELETED,
697     OC_STACK_CONTINUE,
698     /** Success status code - END HERE.*/
699
700     /** Error status code - START HERE.*/
701     OC_STACK_INVALID_URI = 20,
702     OC_STACK_INVALID_QUERY,
703     OC_STACK_INVALID_IP,
704     OC_STACK_INVALID_PORT,
705     OC_STACK_INVALID_CALLBACK,
706     OC_STACK_INVALID_METHOD,
707
708     /** Invalid parameter.*/
709     OC_STACK_INVALID_PARAM,
710     OC_STACK_INVALID_OBSERVE_PARAM,
711     OC_STACK_NO_MEMORY,
712     OC_STACK_COMM_ERROR,
713     OC_STACK_TIMEOUT,
714     OC_STACK_ADAPTER_NOT_ENABLED,
715     OC_STACK_NOTIMPL,
716
717     /** Resource not found.*/
718     OC_STACK_NO_RESOURCE,
719
720     /** e.g: not supported method or interface.*/
721     OC_STACK_RESOURCE_ERROR,
722     OC_STACK_SLOW_RESOURCE,
723     OC_STACK_DUPLICATE_REQUEST,
724
725     /** Resource has no registered observers.*/
726     OC_STACK_NO_OBSERVERS,
727     OC_STACK_OBSERVER_NOT_FOUND,
728     OC_STACK_VIRTUAL_DO_NOT_HANDLE,
729     OC_STACK_INVALID_OPTION,
730
731     /** The remote reply contained malformed data.*/
732     OC_STACK_MALFORMED_RESPONSE,
733     OC_STACK_PERSISTENT_BUFFER_REQUIRED,
734     OC_STACK_INVALID_REQUEST_HANDLE,
735     OC_STACK_INVALID_DEVICE_INFO,
736     OC_STACK_INVALID_JSON,
737
738     /** Request is not authorized by Resource Server. */
739     OC_STACK_UNAUTHORIZED_REQ,
740
741     /** Error code from PDM */
742     OC_STACK_PDM_IS_NOT_INITIALIZED,
743     OC_STACK_DUPLICATE_UUID,
744     OC_STACK_INCONSISTENT_DB,
745
746     /**
747      * Error code from OTM
748      * This error is plused from DTLS interface when handshake failure happens
749      */
750     OC_STACK_AUTHENTICATION_FAILURE,
751
752     /** Insert all new error codes here!.*/
753     #ifdef WITH_PRESENCE
754     OC_STACK_PRESENCE_STOPPED = 128,
755     OC_STACK_PRESENCE_TIMEOUT,
756     OC_STACK_PRESENCE_DO_NOT_HANDLE,
757     #endif
758     /** ERROR in stack.*/
759     OC_STACK_ERROR = 255
760     /** Error status code - END HERE.*/
761 } OCStackResult;
762
763 /**
764  * Handle to an OCDoResource invocation.
765  */
766 typedef void * OCDoHandle;
767
768 /**
769  * Handle to an OCResource object owned by the OCStack.
770  */
771 typedef void * OCResourceHandle;
772
773 /**
774  * Handle to an OCRequest object owned by the OCStack.
775  */
776 typedef void * OCRequestHandle;
777
778 /**
779  * Unique identifier for each observation request. Used when observations are
780  * registered or de-registered. Used by entity handler to signal specific
781  * observers to be notified of resource changes.
782  * There can be maximum of 256 observations per server.
783  */
784 typedef uint8_t OCObservationId;
785
786 /**
787  * Action associated with observation.
788  */
789 typedef enum
790 {
791     /** To Register. */
792     OC_OBSERVE_REGISTER = 0,
793
794     /** To Deregister. */
795     OC_OBSERVE_DEREGISTER = 1,
796
797     /** Others. */
798     OC_OBSERVE_NO_OPTION = 2
799 } OCObserveAction;
800
801
802 /**
803  * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
804  * when it calls OCRegisterPersistentStorageHandler.
805  * Persistent storage open handler points to default file path.
806  * Application can point to appropriate SVR database path for it's IoTivity Server.
807  */
808 typedef struct {
809     /** Persistent storage file path.*/
810     FILE* (* open)(const char *path, const char *mode);
811
812     /** Persistent storage read handler.*/
813     size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
814
815     /** Persistent storage write handler.*/
816     size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
817
818     /** Persistent storage close handler.*/
819     int (* close)(FILE *fp);
820
821     /** Persistent storage unlink handler.*/
822     int (* unlink)(const char *path);
823 } OCPersistentStorage;
824
825 /**
826  * Possible returned values from entity handler.
827  */
828 typedef struct
829 {
830     /** Action associated with observation request.*/
831     OCObserveAction action;
832
833     /** Identifier for observation being registered/deregistered.*/
834     OCObservationId obsId;
835 } OCObservationInfo;
836
837 /**
838  * Possible returned values from entity handler.
839  */
840 typedef enum
841 {
842     OC_EH_OK = 0,
843     OC_EH_ERROR,
844     OC_EH_RESOURCE_CREATED,
845     OC_EH_RESOURCE_DELETED,
846     OC_EH_SLOW,
847     OC_EH_FORBIDDEN,
848     OC_EH_RESOURCE_NOT_FOUND
849 } OCEntityHandlerResult;
850
851 /**
852  * This structure will be used to define the vendor specific header options to be included
853  * in communication packets.
854  */
855 typedef struct OCHeaderOption
856 {
857     /** The protocol ID this option applies to.*/
858     OCTransportProtocolID protocolID;
859
860     /** The header option ID which will be added to communication packets.*/
861     uint16_t optionID;
862
863     /** its length 191.*/
864     uint16_t optionLength;
865
866     /** pointer to its data.*/
867     uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
868
869 #ifdef SUPPORTS_DEFAULT_CTOR
870     OCHeaderOption() = default;
871     OCHeaderOption(OCTransportProtocolID pid,
872                    uint16_t optId,
873                    uint16_t optlen,
874                    const uint8_t* optData)
875         : protocolID(pid),
876           optionID(optId),
877           optionLength(optlen)
878     {
879
880         // parameter includes the null terminator.
881         optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
882                         optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
883         memcpy(optionData, optData, optionLength);
884         optionData[optionLength - 1] = '\0';
885     }
886 #endif
887 } OCHeaderOption;
888
889
890 /**
891  * This structure describes the platform properties. All non-Null properties will be
892  * included in a platform discovery request.
893  */
894 typedef struct
895 {
896     /** Platform ID.*/
897     char *platformID;
898
899     /** Manufacturer name.*/
900     char *manufacturerName;
901
902     /** Manufacturer URL for platform property.*/
903     char *manufacturerUrl;
904
905     /** Model number.*/
906     char *modelNumber;
907
908     /** Manufacturer date.*/
909     char *dateOfManufacture;
910
911     /** Platform version.*/
912     char *platformVersion;
913
914     /** Operating system version.*/
915     char *operatingSystemVersion;
916
917     /** HW version.*/
918     char *hardwareVersion;
919
920     /** FW version.*/
921     char *firmwareVersion;
922
923     /** Platform support URL.*/
924     char *supportUrl;
925
926     /** System time.*/
927     char *systemTime;
928
929 } OCPlatformInfo;
930
931 /**
932  * This structure is expected as input for device properties.
933  * device name is mandatory and expected from the application.
934  * device id of type UUID will be generated by the stack.
935  */
936 typedef struct
937 {
938     /** Pointer to the device name.*/
939     char *deviceName;
940     /** Pointer to the types.*/
941     OCStringLL *types;
942 } OCDeviceInfo;
943
944 #ifdef RA_ADAPTER
945 /**
946  * callback for bound JID
947  */
948 typedef void (*jid_bound_cb)(char *jid);
949
950 /**
951  * CA Remote Access information for XMPP Client
952  *
953  */
954 typedef struct
955 {
956     char *hostname;     /**< XMPP server hostname */
957     uint16_t   port;    /**< XMPP server serivce port */
958     char *xmpp_domain;  /**< XMPP login domain */
959     char *username;     /**< login username */
960     char *password;     /**< login password */
961     char *resource;     /**< specific resource for login */
962     char *user_jid;     /**< specific JID for login */
963     jid_bound_cb jidbound;  /**< callback when JID bound */
964 } OCRAInfo_t;
965 #endif  /* RA_ADAPTER */
966
967
968 /** Enum to describe the type of object held by the OCPayload object.*/
969 typedef enum
970 {
971     PAYLOAD_TYPE_INVALID,
972     PAYLOAD_TYPE_DISCOVERY,
973     PAYLOAD_TYPE_DEVICE,
974     PAYLOAD_TYPE_PLATFORM,
975     PAYLOAD_TYPE_REPRESENTATION,
976     PAYLOAD_TYPE_SECURITY,
977     PAYLOAD_TYPE_PRESENCE,
978     PAYLOAD_TYPE_RD
979 } OCPayloadType;
980
981 typedef struct
982 {
983     // The type of message that was received
984     OCPayloadType type;
985 } OCPayload;
986
987 typedef enum
988 {
989     OCREP_PROP_NULL,
990     OCREP_PROP_INT,
991     OCREP_PROP_DOUBLE,
992     OCREP_PROP_BOOL,
993     OCREP_PROP_STRING,
994     OCREP_PROP_BYTE_STRING,
995     OCREP_PROP_OBJECT,
996     OCREP_PROP_ARRAY
997 }OCRepPayloadPropType;
998
999 /** This structure will be used to represent a binary string for CBOR payloads.*/
1000 typedef struct
1001 {
1002     /** pointer to data bytes.*/
1003     uint8_t* bytes;
1004
1005     /** number of data bytes.*/
1006     size_t   len;
1007 } OCByteString;
1008
1009 #define MAX_REP_ARRAY_DEPTH 3
1010 typedef struct
1011 {
1012     OCRepPayloadPropType type;
1013     size_t dimensions[MAX_REP_ARRAY_DEPTH];
1014
1015     union
1016     {
1017         int64_t* iArray;
1018         double* dArray;
1019         bool* bArray;
1020         char** strArray;
1021
1022         /** pointer to ByteString array.*/
1023         OCByteString* ocByteStrArray;
1024
1025         struct OCRepPayload** objArray;
1026     };
1027 } OCRepPayloadValueArray;
1028
1029 typedef struct OCRepPayloadValue
1030 {
1031     char* name;
1032     OCRepPayloadPropType type;
1033     union
1034     {
1035         int64_t i;
1036         double d;
1037         bool b;
1038         char* str;
1039
1040         /** ByteString object.*/
1041         OCByteString ocByteStr;
1042
1043         struct OCRepPayload* obj;
1044         OCRepPayloadValueArray arr;
1045     };
1046     struct OCRepPayloadValue* next;
1047
1048 } OCRepPayloadValue;
1049
1050 // used for get/set/put/observe/etc representations
1051 typedef struct OCRepPayload
1052 {
1053     OCPayload base;
1054     char* uri;
1055     OCStringLL* types;
1056     OCStringLL* interfaces;
1057     OCRepPayloadValue* values;
1058     struct OCRepPayload* next;
1059 } OCRepPayload;
1060
1061 // used inside a discovery payload
1062 typedef struct OCResourcePayload
1063 {
1064     char* uri;
1065     OCStringLL* types;
1066     OCStringLL* interfaces;
1067     uint8_t bitmap;
1068     bool secure;
1069     uint16_t port;
1070     struct OCResourcePayload* next;
1071 } OCResourcePayload;
1072
1073 /**
1074  * Structure holding Links Payload. It is a sub-structure used in
1075  * OCResourceCollectionPayload.
1076  */
1077 typedef struct OCLinksPayload
1078 {
1079     /** This is the target relative URI. */
1080     char *href;
1081     /** Resource Type - A standard OIC specified or vendor defined resource
1082      * type of the resource referenced by the target URI. */
1083     OCStringLL *rt;
1084     /** Interface - The interfaces supported by the resource referenced by the target URI. */
1085     OCStringLL *itf;
1086     /** The relation of the target URI referenced by the link to the context URI;
1087      * The default value is null. */
1088     char *rel;
1089     /** Specifies if the resource referenced by the target URIis observable or not. */
1090     bool obs;
1091     /** A title for the link relation. Can be used by the UI to provide a context. */
1092     char *title;
1093     /** This is used to override the context URI e.g. override the URI of the containing collection. */
1094     char *uri;
1095     /** The instance identifier for this web link in an array of web links - used in links. */
1096     union
1097     {
1098         /** An ordinal number that is not repeated - must be unique in the collection context. */
1099         uint8_t ins;
1100         /** Any unique string including a URI. */
1101         char *uniqueStr;
1102         /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1103         OCIdentity uniqueUUID;
1104     };
1105     /** A hint of the media type of the representation of the resource referenced by the target URI. */
1106     OCStringLL *mt;
1107     /** Holding address of the next resource. */
1108     struct OCLinksPayload *next;
1109 } OCLinksPayload;
1110
1111 /** Structure holding tags value of the links payload. */
1112 typedef struct
1113 {
1114     /** Name of tags. */
1115     OCDeviceInfo n;
1116     /** Device identifier. */
1117     OCIdentity di;
1118     /** The base URI where the resources are hold. */
1119     char *baseURI;
1120     /** Bitmap holds observable, discoverable, secure option flag.*/
1121     uint8_t bitmap;
1122     /** Port set in case, the secure flag is set above. */
1123     uint16_t port;
1124     /** Id for each set of links i.e. tag. */
1125     union
1126     {
1127         /** An ordinal number that is not repeated - must be unique in the collection context. */
1128         uint8_t ins;
1129         /** Any unique string including a URI. */
1130         char *uniqueStr;
1131         /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1132         OCIdentity uniqueUUID;
1133     };
1134     /** Defines the list of allowable resource types (for Target and anchors) in links included
1135      * in the collection; new links being created can only be from this list. */
1136     char *rts;
1137     /** When specified this is the default relationship to use when an OIC Link does not specify
1138      * an explicit relationship with *rel* parameter. */
1139     char *drel;
1140     /** Time to keep holding resource.*/
1141     uint32_t ttl;
1142 } OCTagsPayload;
1143
1144 /** Resource collection payload. */
1145 typedef struct OCResourceCollectionPayload
1146 {
1147     /** Collection tags payload.*/
1148     OCTagsPayload *tags;
1149     /** Array of links payload. */
1150     OCLinksPayload *setLinks;
1151     /** Holding address of the next resource. */
1152     struct OCResourceCollectionPayload *next;
1153 } OCResourceCollectionPayload;
1154
1155 typedef struct
1156 {
1157     OCPayload base;
1158
1159     char *sid;
1160
1161     /** A special case for handling RD address. */
1162     char* baseURI;
1163
1164     /** This structure holds the old /oic/res response. */
1165     OCResourcePayload *resources;
1166
1167 } OCDiscoveryPayload;
1168
1169 /**
1170  * Structure holding discovery payload.
1171  */
1172 typedef struct
1173 {
1174     /** Device Name. */
1175     OCDeviceInfo n;
1176     /** Device Identity. */
1177     OCIdentity di;
1178     /** Value holding the bias factor of the RD. */
1179     uint8_t sel;
1180 } OCRDDiscoveryPayload;
1181
1182 /**
1183  * RD Payload that will be transmitted over the wire.
1184  */
1185 typedef struct
1186 {
1187     OCPayload base;
1188     /** Pointer to the discovery response payload.*/
1189     OCRDDiscoveryPayload *rdDiscovery;
1190     /** Pointer to the publish payload.*/
1191     OCResourceCollectionPayload *rdPublish;
1192 } OCRDPayload;
1193
1194 typedef struct
1195 {
1196     OCPayload base;
1197     char *sid;
1198     OCStringLL *types;
1199     char* deviceName;
1200     char* specVersion;
1201     char* dataModelVersion;
1202 } OCDevicePayload;
1203
1204 typedef struct
1205 {
1206     OCPayload base;
1207     char* uri;
1208     OCPlatformInfo info;
1209 } OCPlatformPayload;
1210
1211 typedef struct
1212 {
1213     OCPayload base;
1214     char* securityData;
1215 } OCSecurityPayload;
1216 #ifdef WITH_PRESENCE
1217 typedef struct
1218 {
1219     OCPayload base;
1220     uint32_t sequenceNumber;
1221     uint32_t maxAge;
1222     OCPresenceTrigger trigger;
1223     char* resourceType;
1224 } OCPresencePayload;
1225 #endif
1226
1227 /**
1228  * Incoming requests handled by the server. Requests are passed in as a parameter to the
1229  * OCEntityHandler callback API.
1230  * The OCEntityHandler callback API must be implemented in the application in order
1231  * to receive these requests.
1232  */
1233 typedef struct
1234 {
1235     /** Associated resource.*/
1236     OCResourceHandle resource;
1237
1238     /** Associated request handle.*/
1239     OCRequestHandle requestHandle;
1240
1241     /** the REST method retrieved from received request PDU.*/
1242     OCMethod method;
1243
1244     /** description of endpoint that sent the request.*/
1245     OCDevAddr devAddr;
1246
1247     /** resource query send by client.*/
1248     char * query;
1249
1250     /** Information associated with observation - valid only when OCEntityHandler flag includes
1251      * ::OC_OBSERVE_FLAG.*/
1252     OCObservationInfo obsInfo;
1253
1254     /** Number of the received vendor specific header options.*/
1255     uint8_t numRcvdVendorSpecificHeaderOptions;
1256
1257     /** Pointer to the array of the received vendor specific header options.*/
1258     OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1259
1260     /** the payload from the request PDU.*/
1261     OCPayload *payload;
1262
1263 } OCEntityHandlerRequest;
1264
1265
1266 /**
1267  * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1268  */
1269 typedef struct
1270 {
1271     /** Address of remote server.*/
1272     OCDevAddr devAddr;
1273
1274     /** backward compatibility (points to devAddr).*/
1275     OCDevAddr *addr;
1276
1277     /** backward compatibility.*/
1278     OCConnectivityType connType;
1279
1280     /** the security identity of the remote server.*/
1281     OCIdentity identity;
1282
1283     /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1284     OCStackResult result;
1285
1286     /** If associated with observe, this will represent the sequence of notifications from server.*/
1287     uint32_t sequenceNumber;
1288
1289     /** resourceURI.*/
1290     const char * resourceUri;
1291
1292     /** the payload for the response PDU.*/
1293     OCPayload *payload;
1294
1295     /** Number of the received vendor specific header options.*/
1296     uint8_t numRcvdVendorSpecificHeaderOptions;
1297
1298     /** An array of the received vendor specific header options.*/
1299     OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1300 } OCClientResponse;
1301
1302 /**
1303  * Request handle is passed to server via the entity handler for each incoming request.
1304  * Stack assigns when request is received, server sets to indicate what request response is for.
1305  */
1306 typedef struct
1307 {
1308     /** Request handle.*/
1309     OCRequestHandle requestHandle;
1310
1311     /** Resource handle.*/
1312     OCResourceHandle resourceHandle;
1313
1314     /** Allow the entity handler to pass a result with the response.*/
1315     OCEntityHandlerResult  ehResult;
1316
1317     /** This is the pointer to server payload data to be transferred.*/
1318     OCPayload* payload;
1319
1320     /** number of the vendor specific header options .*/
1321     uint8_t numSendVendorSpecificHeaderOptions;
1322
1323     /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1324     OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1325
1326     /** URI of new resource that entity handler might create.*/
1327     char resourceUri[MAX_URI_LENGTH];
1328
1329     /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1330     uint8_t persistentBufferFlag;
1331 } OCEntityHandlerResponse;
1332
1333 /**
1334  * Entity's state
1335  */
1336 typedef enum
1337 {
1338     /** Request state.*/
1339     OC_REQUEST_FLAG = (1 << 1),
1340     /** Observe state.*/
1341     OC_OBSERVE_FLAG = (1 << 2)
1342 } OCEntityHandlerFlag;
1343
1344 /**
1345  * Possible returned values from client application.
1346  */
1347 typedef enum
1348 {
1349     OC_STACK_DELETE_TRANSACTION = 0,
1350     OC_STACK_KEEP_TRANSACTION
1351 } OCStackApplicationResult;
1352
1353
1354 //#ifdef DIRECT_PAIRING
1355 /**
1356  * @brief   direct pairing Method Type.
1357  *              0:  not allowed
1358  *              1:  pre-configured pin
1359  *              2:  random pin
1360  */
1361 typedef enum OCPrm
1362 {
1363     DP_NOT_ALLOWED             = 0x0,
1364     DP_PRE_CONFIGURED        = (0x1 << 0),
1365     DP_RANDOM_PIN               = (0x1 << 1),
1366 } OCPrm_t;
1367
1368 /**
1369  * Device Information of discoverd direct pairing device(s).
1370  */
1371 typedef struct OCDPDev
1372 {
1373     OCDevAddr               endpoint;
1374     OCConnectivityType   connType;
1375     uint16_t                     securePort;
1376     bool                  edp;
1377     OCPrm_t           *prm;
1378     size_t                prmLen;
1379     OCUUIdentity     deviceID;
1380     OCUUIdentity     rowner;
1381     struct OCDPDev *next;
1382 } OCDPDev_t;
1383 //#endif // DIRECT_PAIRING
1384
1385 /*
1386  * -------------------------------------------------------------------------------------------
1387  * Callback function definitions
1388  * -------------------------------------------------------------------------------------------
1389  */
1390
1391 /**
1392  * Client applications implement this callback to consume responses received from Servers.
1393  */
1394 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1395     OCClientResponse * clientResponse);
1396
1397 /**
1398  * Client applications using a context pointer implement this callback to delete the
1399  * context upon removal of the callback/context pointer from the internal callback-list.
1400  */
1401 typedef void (* OCClientContextDeleter)(void *context);
1402
1403 /**
1404  * This info is passed from application to OC Stack when initiating a request to Server.
1405  */
1406 typedef struct OCCallbackData
1407 {
1408     /** Pointer to the context.*/
1409     void *context;
1410
1411     /** The pointer to a function the stack will call to handle the requests.*/
1412     OCClientResponseHandler cb;
1413
1414     /** A pointer to a function to delete the context when this callback is removed.*/
1415     OCClientContextDeleter cd;
1416
1417 #ifdef SUPPORTS_DEFAULT_CTOR
1418     OCCallbackData() = default;
1419     OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1420         :context(ctx), cb(callback), cd(deleter){}
1421 #endif
1422 } OCCallbackData;
1423
1424 /**
1425  * Application server implementations must implement this callback to consume requests OTA.
1426  * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1427  */
1428 typedef OCEntityHandlerResult (*OCEntityHandler)
1429 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1430
1431 /**
1432  * Device Entity handler need to use this call back instead of OCEntityHandler.
1433  */
1434 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1435 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1436
1437 //#ifdef DIRECT_PAIRING
1438 /**
1439  * Callback function definition of direct-pairing
1440  *
1441  * @param[OUT] peer - pairing device info.
1442  * @param[OUT} result - It's returned with 'OC_STACK_XXX'. It will return 'OC_STACK_OK'
1443  *                                   if D2D pairing is success without error
1444  */
1445 typedef void (*OCDirectPairingCB)(OCDPDev_t *peer, OCStackResult result);
1446 //#endif // DIRECT_PAIRING
1447
1448 #ifdef __cplusplus
1449 }
1450 #endif // __cplusplus
1451
1452 #endif /* OCTYPES_H_ */