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