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