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