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