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