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