ea0df8dc50847c1b68e7829a0b58166146bfb40d
[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 } OCTransportAdapter;
300
301 /**
302  *  Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
303  */
304 typedef enum
305 {
306     /** default flag is 0*/
307     OC_DEFAULT_FLAGS = 0,
308
309     /** Insecure transport is the default (subject to change).*/
310     /** secure the transport path*/
311     OC_FLAG_SECURE     = (1 << 4),
312
313     /** IPv4 & IPv6 auto-selection is the default.*/
314     /** IP adapter only.*/
315     OC_IP_USE_V6       = (1 << 5),
316
317     /** IP adapter only.*/
318     OC_IP_USE_V4       = (1 << 6),
319
320     /** internal use only.*/
321     OC_RESERVED1       = (1 << 7),   // internal use only
322
323     /** Link-Local multicast is the default multicast scope for IPv6.
324      *  These are placed here to correspond to the IPv6 multicast address bits.*/
325
326     /** IPv6 Interface-Local scope (loopback).*/
327     OC_SCOPE_INTERFACE = 0x1,
328
329     /** IPv6 Link-Local scope (default).*/
330     OC_SCOPE_LINK      = 0x2,
331
332     /** IPv6 Realm-Local scope. */
333     OC_SCOPE_REALM     = 0x3,
334
335     /** IPv6 Admin-Local scope. */
336     OC_SCOPE_ADMIN     = 0x4,
337
338     /** IPv6 Site-Local scope. */
339     OC_SCOPE_SITE      = 0x5,
340
341     /** IPv6 Organization-Local scope. */
342     OC_SCOPE_ORG       = 0x8,
343
344     /**IPv6 Global scope. */
345     OC_SCOPE_GLOBAL    = 0xE,
346
347 } OCTransportFlags;
348
349 /** Bit mask for scope.*/
350 #define OC_MASK_SCOPE    (0x000F)
351
352 /** Bit mask for Mods.*/
353 #define OC_MASK_MODS     (0x0FF0)
354 #define OC_MASK_FAMS     (OC_IP_USE_V6|OC_IP_USE_V4)
355
356 /**
357  * End point identity.
358  */
359 typedef struct
360 {
361     /** Identity Length */
362     uint16_t id_length;
363
364     /** Array of end point identity.*/
365     unsigned char id[MAX_IDENTITY_SIZE];
366 } OCIdentity;
367
368 /**
369  * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
370  * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
371  */
372 typedef struct
373 {
374     /** adapter type.*/
375     OCTransportAdapter      adapter;
376
377     /** transport modifiers.*/
378     OCTransportFlags        flags;
379
380     /** for IP.*/
381     uint16_t                port;
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 } OCDevAddr;
390
391 /**
392  * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
393  * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
394  * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
395  * like Arduino.
396  *
397  * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
398  */
399 typedef enum
400 {
401     /** use when defaults are ok. */
402     CT_DEFAULT = 0,
403
404     /** IPv4 and IPv6, including 6LoWPAN.*/
405     CT_ADAPTER_IP           = (1 << 16),
406
407     /** GATT over Bluetooth LE.*/
408     CT_ADAPTER_GATT_BTLE    = (1 << 17),
409
410     /** RFCOMM over Bluetooth EDR.*/
411     CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
412
413 #ifdef RA_ADAPTER
414     /** Remote Access over XMPP.*/
415     CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
416 #endif
417
418     /** Insecure transport is the default (subject to change).*/
419
420     /** secure the transport path.*/
421     CT_FLAG_SECURE     = (1 << 4),
422
423     /** IPv4 & IPv6 autoselection is the default.*/
424
425     /** IP adapter only.*/
426     CT_IP_USE_V6       = (1 << 5),
427
428     /** IP adapter only.*/
429     CT_IP_USE_V4       = (1 << 6),
430
431     /** Link-Local multicast is the default multicast scope for IPv6.
432      * These are placed here to correspond to the IPv6 address bits.*/
433
434     /** IPv6 Interface-Local scope(loopback).*/
435     CT_SCOPE_INTERFACE = 0x1,
436
437     /** IPv6 Link-Local scope (default).*/
438     CT_SCOPE_LINK      = 0x2,
439
440     /** IPv6 Realm-Local scope.*/
441     CT_SCOPE_REALM     = 0x3,
442
443     /** IPv6 Admin-Local scope.*/
444     CT_SCOPE_ADMIN     = 0x4,
445
446     /** IPv6 Site-Local scope.*/
447     CT_SCOPE_SITE      = 0x5,
448
449     /** IPv6 Organization-Local scope.*/
450     CT_SCOPE_ORG       = 0x8,
451
452     /** IPv6 Global scope.*/
453     CT_SCOPE_GLOBAL    = 0xE,
454 } OCConnectivityType;
455
456 /** bit shift required for connectivity adapter.*/
457 #define CT_ADAPTER_SHIFT 16
458
459 /** Mask Flag.*/
460 #define CT_MASK_FLAGS 0xFFFF
461
462 /** Mask Adapter.*/
463 #define CT_MASK_ADAPTER 0xFFFF0000
464
465 /**
466  *  OCDoResource methods to dispatch the request
467  */
468 typedef enum
469 {
470     OC_REST_NOMETHOD       = 0,
471
472     /** Read.*/
473     OC_REST_GET            = (1 << 0),
474
475     /** Write.*/
476     OC_REST_PUT            = (1 << 1),
477
478     /** Update.*/
479     OC_REST_POST           = (1 << 2),
480
481     /** Delete.*/
482     OC_REST_DELETE         = (1 << 3),
483
484     /** Register observe request for most up date notifications ONLY.*/
485     OC_REST_OBSERVE        = (1 << 4),
486
487     /** Register observe request for all notifications, including stale notifications.*/
488     OC_REST_OBSERVE_ALL    = (1 << 5),
489
490     /** De-register observation, intended for internal use.*/
491     OC_REST_CANCEL_OBSERVE = (1 << 6),
492
493     #ifdef WITH_PRESENCE
494     /** Subscribe for all presence notifications of a particular resource.*/
495     OC_REST_PRESENCE       = (1 << 7),
496
497     #endif
498     /** Allows OCDoResource caller to do discovery.*/
499     OC_REST_DISCOVER       = (1 << 8)
500 } OCMethod;
501
502 /**
503  * Host Mode of Operation.
504  */
505 typedef enum
506 {
507     OC_CLIENT = 0,
508     OC_SERVER,
509     OC_CLIENT_SERVER
510 } OCMode;
511
512 /**
513  * Quality of Service attempts to abstract the guarantees provided by the underlying transport
514  * protocol. The precise definitions of each quality of service level depend on the
515  * implementation. In descriptions below are for the current implementation and may changed
516  * over time.
517  */
518 typedef enum
519 {
520     /** Packet delivery is best effort.*/
521     OC_LOW_QOS = 0,
522
523     /** Packet delivery is best effort.*/
524     OC_MEDIUM_QOS,
525
526     /** Acknowledgments are used to confirm delivery.*/
527     OC_HIGH_QOS,
528
529     /** No Quality is defined, let the stack decide.*/
530     OC_NA_QOS
531 } OCQualityOfService;
532
533 /**
534  * Resource Properties.
535  * The value of a policy property is defined as bitmap.
536  * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
537  * Not including the policy property is equivalent to zero.
538  *
539  */
540 typedef enum
541 {
542     /** When none of the bits are set, the resource is non-discoverable &
543      *  non-observable by the client.*/
544     OC_RES_PROP_NONE = (0),
545
546     /** When this bit is set, the resource is allowed to be discovered by clients.*/
547     OC_DISCOVERABLE  = (1 << 0),
548
549     /** When this bit is set, the resource is allowed to be observed by clients.*/
550     OC_OBSERVABLE    = (1 << 1),
551
552     /** When this bit is set, the resource is initialized, otherwise the resource
553      *  is 'inactive'. 'inactive' signifies that the resource has been marked for
554      *  deletion or is already deleted.*/
555     OC_ACTIVE        = (1 << 2),
556
557     /** When this bit is set, the resource has been marked as 'slow'.
558      * 'slow' signifies that responses from this resource can expect delays in
559      *  processing its requests from clients.*/
560     OC_SLOW          = (1 << 3),
561
562     /** When this bit is set, the resource is a secure resource.*/
563     OC_SECURE        = (1 << 4),
564
565     /** When this bit is set, the resource is allowed to be discovered only
566      *  if discovery request contains an explicit querystring.
567      *  Ex: GET /oic/res?rt=oic.sec.acl */
568     OC_EXPLICIT_DISCOVERABLE   = (1 << 5)
569 } OCResourceProperty;
570
571 /**
572  * Transport Protocol IDs.
573  */
574 typedef enum
575 {
576     /** For invalid ID.*/
577     OC_INVALID_ID   = (1 << 0),
578
579     /* For coap ID.*/
580     OC_COAP_ID      = (1 << 1)
581 } OCTransportProtocolID;
582
583 /**
584  * Declares Stack Results & Errors.
585  */
586 typedef enum
587 {
588     /** Success status code - START HERE.*/
589     OC_STACK_OK = 0,
590     OC_STACK_RESOURCE_CREATED,
591     OC_STACK_RESOURCE_DELETED,
592     OC_STACK_CONTINUE,
593     /** Success status code - END HERE.*/
594
595     /** Error status code - START HERE.*/
596     OC_STACK_INVALID_URI = 20,
597     OC_STACK_INVALID_QUERY,
598     OC_STACK_INVALID_IP,
599     OC_STACK_INVALID_PORT,
600     OC_STACK_INVALID_CALLBACK,
601     OC_STACK_INVALID_METHOD,
602
603     /** Invalid parameter.*/
604     OC_STACK_INVALID_PARAM,
605     OC_STACK_INVALID_OBSERVE_PARAM,
606     OC_STACK_NO_MEMORY,
607     OC_STACK_COMM_ERROR,
608     OC_STACK_TIMEOUT,
609     OC_STACK_ADAPTER_NOT_ENABLED,
610     OC_STACK_NOTIMPL,
611
612     /** Resource not found.*/
613     OC_STACK_NO_RESOURCE,
614
615     /** e.g: not supported method or interface.*/
616     OC_STACK_RESOURCE_ERROR,
617     OC_STACK_SLOW_RESOURCE,
618     OC_STACK_DUPLICATE_REQUEST,
619
620     /** Resource has no registered observers.*/
621     OC_STACK_NO_OBSERVERS,
622     OC_STACK_OBSERVER_NOT_FOUND,
623     OC_STACK_VIRTUAL_DO_NOT_HANDLE,
624     OC_STACK_INVALID_OPTION,
625
626     /** The remote reply contained malformed data.*/
627     OC_STACK_MALFORMED_RESPONSE,
628     OC_STACK_PERSISTENT_BUFFER_REQUIRED,
629     OC_STACK_INVALID_REQUEST_HANDLE,
630     OC_STACK_INVALID_DEVICE_INFO,
631     OC_STACK_INVALID_JSON,
632
633     /** Request is not authorized by Resource Server. */
634     OC_STACK_UNAUTHORIZED_REQ,
635
636     /** Insert all new error codes here!.*/
637     #ifdef WITH_PRESENCE
638     OC_STACK_PRESENCE_STOPPED = 128,
639     OC_STACK_PRESENCE_TIMEOUT,
640     OC_STACK_PRESENCE_DO_NOT_HANDLE,
641     #endif
642     /** ERROR in stack.*/
643     OC_STACK_ERROR = 255
644     /** Error status code - END HERE.*/
645 } OCStackResult;
646
647 /**
648  * Handle to an OCDoResource invocation.
649  */
650 typedef void * OCDoHandle;
651
652 /**
653  * Handle to an OCResource object owned by the OCStack.
654  */
655 typedef void * OCResourceHandle;
656
657 /**
658  * Handle to an OCRequest object owned by the OCStack.
659  */
660 typedef void * OCRequestHandle;
661
662 /**
663  * Unique identifier for each observation request. Used when observations are
664  * registered or de-registered. Used by entity handler to signal specific
665  * observers to be notified of resource changes.
666  * There can be maximum of 256 observations per server.
667  */
668 typedef uint8_t OCObservationId;
669
670 /**
671  * Action associated with observation.
672  */
673 typedef enum
674 {
675     /** To Register. */
676     OC_OBSERVE_REGISTER = 0,
677
678     /** To Deregister. */
679     OC_OBSERVE_DEREGISTER = 1,
680
681     /** Others. */
682     OC_OBSERVE_NO_OPTION = 2
683 } OCObserveAction;
684
685
686 /**
687  * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
688  * when it calls OCRegisterPersistentStorageHandler.
689  * Persistent storage open handler points to default file path.
690  * Application can point to appropriate SVR database path for it's IoTivity Server.
691  */
692 typedef struct {
693     /** Persistent storage file path.*/
694     FILE* (* open)(const char *path, const char *mode);
695
696     /** Persistent storage read handler.*/
697     size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
698
699     /** Persistent storage write handler.*/
700     size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
701
702     /** Persistent storage close handler.*/
703     int (* close)(FILE *fp);
704
705     /** Persistent storage unlink handler.*/
706     int (* unlink)(const char *path);
707 } OCPersistentStorage;
708
709 /**
710  * Possible returned values from entity handler.
711  */
712 typedef struct
713 {
714     /** Action associated with observation request.*/
715     OCObserveAction action;
716
717     /** Identifier for observation being registered/deregistered.*/
718     OCObservationId obsId;
719 } OCObservationInfo;
720
721 /**
722  * Possible returned values from entity handler.
723  */
724 typedef enum
725 {
726     OC_EH_OK = 0,
727     OC_EH_ERROR,
728     OC_EH_RESOURCE_CREATED,
729     OC_EH_RESOURCE_DELETED,
730     OC_EH_SLOW,
731     OC_EH_FORBIDDEN,
732     OC_EH_RESOURCE_NOT_FOUND
733 } OCEntityHandlerResult;
734
735 /**
736  * This structure will be used to define the vendor specific header options to be included
737  * in communication packets.
738  */
739 typedef struct OCHeaderOption
740 {
741     /** The protocol ID this option applies to.*/
742     OCTransportProtocolID protocolID;
743
744     /** The header option ID which will be added to communication packets.*/
745     uint16_t optionID;
746
747     /** its length 191.*/
748     uint16_t optionLength;
749
750     /** pointer to its data.*/
751     uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
752
753 #ifdef SUPPORTS_DEFAULT_CTOR
754     OCHeaderOption() = default;
755     OCHeaderOption(OCTransportProtocolID pid,
756                    uint16_t optId,
757                    uint16_t optlen,
758                    const uint8_t* optData)
759         : protocolID(pid),
760           optionID(optId),
761           optionLength(optlen)
762     {
763
764         // parameter includes the null terminator.
765         optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
766                         optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
767         memcpy(optionData, optData, optionLength);
768         optionData[optionLength - 1] = '\0';
769     }
770 #endif
771 } OCHeaderOption;
772
773
774 /**
775  * This structure describes the platform properties. All non-Null properties will be
776  * included in a platform discovery request.
777  */
778 typedef struct
779 {
780     /** Platform ID.*/
781     char *platformID;
782
783     /** Manufacturer name.*/
784     char *manufacturerName;
785
786     /** Manufacturer URL for platform property.*/
787     char *manufacturerUrl;
788
789     /** Model number.*/
790     char *modelNumber;
791
792     /** Manufacturer date.*/
793     char *dateOfManufacture;
794
795     /** Platform version.*/
796     char *platformVersion;
797
798     /** Operating system version.*/
799     char *operatingSystemVersion;
800
801     /** HW version.*/
802     char *hardwareVersion;
803
804     /** FW version.*/
805     char *firmwareVersion;
806
807     /** Platform support URL.*/
808     char *supportUrl;
809
810     /** System time.*/
811     char *systemTime;
812
813 } OCPlatformInfo;
814
815 /**
816  * This structure is expected as input for device properties.
817  * device name is mandatory and expected from the application.
818  * device id of type UUID will be generated by the stack.
819  */
820 typedef struct
821 {
822     /** Pointer to the device name.*/
823     char *deviceName;
824
825 } OCDeviceInfo;
826
827 #ifdef RA_ADAPTER
828 /**
829  * CA Remote Access information for XMPP Client
830  *
831  */
832 typedef struct
833 {
834     char *hostname;     /**< XMPP server hostname */
835     uint16_t   port;    /**< XMPP server serivce port */
836     char *xmpp_domain;  /**< XMPP login domain */
837     char *username;     /**< login username */
838     char *password;     /**< login password */
839     char *resource;     /**< specific resource for login */
840     char *user_jid;     /**< specific JID for login */
841 } OCRAInfo_t;
842 #endif  /* RA_ADAPTER */
843
844
845 /** Enum to describe the type of object held by the OCPayload object.*/
846 typedef enum
847 {
848     PAYLOAD_TYPE_INVALID,
849     PAYLOAD_TYPE_DISCOVERY,
850     PAYLOAD_TYPE_DEVICE,
851     PAYLOAD_TYPE_PLATFORM,
852     PAYLOAD_TYPE_REPRESENTATION,
853     PAYLOAD_TYPE_SECURITY,
854     PAYLOAD_TYPE_PRESENCE
855 } OCPayloadType;
856
857 typedef struct
858 {
859     // The type of message that was received
860     OCPayloadType type;
861 } OCPayload;
862
863 typedef enum
864 {
865     OCREP_PROP_NULL,
866     OCREP_PROP_INT,
867     OCREP_PROP_DOUBLE,
868     OCREP_PROP_BOOL,
869     OCREP_PROP_STRING,
870     OCREP_PROP_OBJECT,
871     OCREP_PROP_ARRAY
872 }OCRepPayloadPropType;
873
874 #define MAX_REP_ARRAY_DEPTH 3
875 typedef struct
876 {
877     OCRepPayloadPropType type;
878     size_t dimensions[MAX_REP_ARRAY_DEPTH];
879
880     union
881     {
882         int64_t* iArray;
883         double* dArray;
884         bool* bArray;
885         char** strArray;
886         struct OCRepPayload** objArray;
887     };
888 } OCRepPayloadValueArray;
889
890 typedef struct OCRepPayloadValue
891 {
892     char* name;
893     OCRepPayloadPropType type;
894     union
895     {
896         int64_t i;
897         double d;
898         bool b;
899         char* str;
900         struct OCRepPayload* obj;
901         OCRepPayloadValueArray arr;
902     };
903     struct OCRepPayloadValue* next;
904
905 } OCRepPayloadValue;
906
907 typedef struct OCStringLL
908 {
909     struct OCStringLL *next;
910     char* value;
911 } OCStringLL;
912
913 // used for get/set/put/observe/etc representations
914 typedef struct OCRepPayload
915 {
916     OCPayload base;
917     char* uri;
918     OCStringLL* types;
919     OCStringLL* interfaces;
920     OCRepPayloadValue* values;
921     struct OCRepPayload* next;
922 } OCRepPayload;
923
924 // used inside a discovery payload
925 typedef struct OCResourcePayload
926 {
927     char* uri;
928     uint8_t* sid;
929     OCStringLL* types;
930     OCStringLL* interfaces;
931     uint8_t bitmap;
932     bool secure;
933     uint16_t port;
934     struct OCResourcePayload* next;
935 } OCResourcePayload;
936
937 typedef struct
938 {
939     OCPayload base;
940     OCResourcePayload* resources;
941 } OCDiscoveryPayload;
942
943 typedef struct
944 {
945     OCPayload base;
946     char* uri;
947     uint8_t* sid;
948     char* deviceName;
949     char* specVersion;
950     char* dataModelVersion;
951 } OCDevicePayload;
952
953 typedef struct
954 {
955     OCPayload base;
956     char* uri;
957     OCPlatformInfo info;
958 } OCPlatformPayload;
959
960 typedef struct
961 {
962     OCPayload base;
963     char* securityData;
964 } OCSecurityPayload;
965 #ifdef WITH_PRESENCE
966 typedef struct
967 {
968     OCPayload base;
969     uint32_t sequenceNumber;
970     uint32_t maxAge;
971     OCPresenceTrigger trigger;
972     char* resourceType;
973 } OCPresencePayload;
974 #endif
975
976 /**
977  * Incoming requests handled by the server. Requests are passed in as a parameter to the
978  * OCEntityHandler callback API.
979  * The OCEntityHandler callback API must be implemented in the application in order
980  * to receive these requests.
981  */
982 typedef struct
983 {
984     /** Associated resource.*/
985     OCResourceHandle resource;
986
987     /** Associated request handle.*/
988     OCRequestHandle requestHandle;
989
990     /** the REST method retrieved from received request PDU.*/
991     OCMethod method;
992
993     /** description of endpoint that sent the request.*/
994     OCDevAddr devAddr;
995
996     /** resource query send by client.*/
997     char * query;
998
999     /** Information associated with observation - valid only when OCEntityHandler flag includes
1000      * ::OC_OBSERVE_FLAG.*/
1001     OCObservationInfo obsInfo;
1002
1003     /** Number of the received vendor specific header options.*/
1004     uint8_t numRcvdVendorSpecificHeaderOptions;
1005
1006     /** Pointer to the array of the received vendor specific header options.*/
1007     OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1008
1009     /** the payload from the request PDU.*/
1010     OCPayload *payload;
1011
1012
1013 } OCEntityHandlerRequest;
1014
1015
1016 /**
1017  * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1018  */
1019 typedef struct
1020 {
1021     /** Address of remote server.*/
1022     OCDevAddr devAddr;
1023
1024     /** backward compatibility (points to devAddr).*/
1025     OCDevAddr *addr;
1026
1027     /** backward compatibility.*/
1028     OCConnectivityType connType;
1029
1030     /** the security identity of the remote server.*/
1031     OCIdentity identity;
1032
1033     /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1034     OCStackResult result;
1035
1036     /** If associated with observe, this will represent the sequence of notifications from server.*/
1037     uint32_t sequenceNumber;
1038
1039     /** resourceURI.*/
1040     const char * resourceUri;
1041
1042     /** the payload for the response PDU.*/
1043     OCPayload *payload;
1044
1045     /** Number of the received vendor specific header options.*/
1046     uint8_t numRcvdVendorSpecificHeaderOptions;
1047
1048     /** An array of the received vendor specific header options.*/
1049     OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1050 } OCClientResponse;
1051
1052 /**
1053  * Request handle is passed to server via the entity handler for each incoming request.
1054  * Stack assigns when request is received, server sets to indicate what request response is for.
1055  */
1056 typedef struct
1057 {
1058     /** Request handle.*/
1059     OCRequestHandle requestHandle;
1060
1061     /** Resource handle.*/
1062     OCResourceHandle resourceHandle;
1063
1064     /** Allow the entity handler to pass a result with the response.*/
1065     OCEntityHandlerResult  ehResult;
1066
1067     /** This is the pointer to server payload data to be transferred.*/
1068     OCPayload* payload;
1069
1070     /** number of the vendor specific header options .*/
1071     uint8_t numSendVendorSpecificHeaderOptions;
1072
1073     /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1074     OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1075
1076     /** URI of new resource that entity handler might create.*/
1077     char resourceUri[MAX_URI_LENGTH];
1078
1079     /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1080     uint8_t persistentBufferFlag;
1081 } OCEntityHandlerResponse;
1082
1083 /**
1084  * Entity's state
1085  */
1086 typedef enum
1087 {
1088     /** Request state.*/
1089     OC_REQUEST_FLAG = (1 << 1),
1090     /** Observe state.*/
1091     OC_OBSERVE_FLAG = (1 << 2)
1092 } OCEntityHandlerFlag;
1093
1094 /**
1095  * Possible returned values from client application.
1096  */
1097 typedef enum
1098 {
1099     OC_STACK_DELETE_TRANSACTION = 0,
1100     OC_STACK_KEEP_TRANSACTION
1101 } OCStackApplicationResult;
1102
1103
1104 /*
1105  * -------------------------------------------------------------------------------------------
1106  * Callback function definitions
1107  * -------------------------------------------------------------------------------------------
1108  */
1109
1110 /**
1111  * Client applications implement this callback to consume responses received from Servers.
1112  */
1113 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1114     OCClientResponse * clientResponse);
1115
1116 /**
1117  * Client applications using a context pointer implement this callback to delete the
1118  * context upon removal of the callback/context pointer from the internal callback-list.
1119  */
1120 typedef void (* OCClientContextDeleter)(void *context);
1121
1122 /**
1123  * This info is passed from application to OC Stack when initiating a request to Server.
1124  */
1125 typedef struct OCCallbackData
1126 {
1127     /** Pointer to the context.*/
1128     void *context;
1129
1130     /** The pointer to a function the stack will call to handle the requests.*/
1131     OCClientResponseHandler cb;
1132
1133     /** A pointer to a function to delete the context when this callback is removed.*/
1134     OCClientContextDeleter cd;
1135
1136 #ifdef SUPPORTS_DEFAULT_CTOR
1137     OCCallbackData() = default;
1138     OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1139         :context(ctx), cb(callback), cd(deleter){}
1140 #endif
1141 } OCCallbackData;
1142
1143 /**
1144  * Application server implementations must implement this callback to consume requests OTA.
1145  * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1146  */
1147 typedef OCEntityHandlerResult (*OCEntityHandler)
1148 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1149
1150 /**
1151  * Device Entity handler need to use this call back instead of OCEntityHandler.
1152  */
1153 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1154 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1155
1156 #ifdef __cplusplus
1157 }
1158 #endif // __cplusplus
1159
1160 #endif /* OCTYPES_H_ */