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