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