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