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