bea5b00d0f28d4fba6378925d66d1760c87ddf59
[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     /**
709      * Error code from OTM
710      * This error is plused from DTLS interface when handshake failure happens
711      */
712     OC_STACK_AUTHENTICATION_FAILURE,
713
714     /** Insert all new error codes here!.*/
715     #ifdef WITH_PRESENCE
716     OC_STACK_PRESENCE_STOPPED = 128,
717     OC_STACK_PRESENCE_TIMEOUT,
718     OC_STACK_PRESENCE_DO_NOT_HANDLE,
719     #endif
720     /** ERROR in stack.*/
721     OC_STACK_ERROR = 255
722     /** Error status code - END HERE.*/
723 } OCStackResult;
724
725 /**
726  * Handle to an OCDoResource invocation.
727  */
728 typedef void * OCDoHandle;
729
730 /**
731  * Handle to an OCResource object owned by the OCStack.
732  */
733 typedef void * OCResourceHandle;
734
735 /**
736  * Handle to an OCRequest object owned by the OCStack.
737  */
738 typedef void * OCRequestHandle;
739
740 /**
741  * Unique identifier for each observation request. Used when observations are
742  * registered or de-registered. Used by entity handler to signal specific
743  * observers to be notified of resource changes.
744  * There can be maximum of 256 observations per server.
745  */
746 typedef uint8_t OCObservationId;
747
748 /**
749  * Action associated with observation.
750  */
751 typedef enum
752 {
753     /** To Register. */
754     OC_OBSERVE_REGISTER = 0,
755
756     /** To Deregister. */
757     OC_OBSERVE_DEREGISTER = 1,
758
759     /** Others. */
760     OC_OBSERVE_NO_OPTION = 2
761 } OCObserveAction;
762
763
764 /**
765  * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
766  * when it calls OCRegisterPersistentStorageHandler.
767  * Persistent storage open handler points to default file path.
768  * Application can point to appropriate SVR database path for it's IoTivity Server.
769  */
770 typedef struct {
771     /** Persistent storage file path.*/
772     FILE* (* open)(const char *path, const char *mode);
773
774     /** Persistent storage read handler.*/
775     size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
776
777     /** Persistent storage write handler.*/
778     size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
779
780     /** Persistent storage close handler.*/
781     int (* close)(FILE *fp);
782
783     /** Persistent storage unlink handler.*/
784     int (* unlink)(const char *path);
785 } OCPersistentStorage;
786
787 /**
788  * Possible returned values from entity handler.
789  */
790 typedef struct
791 {
792     /** Action associated with observation request.*/
793     OCObserveAction action;
794
795     /** Identifier for observation being registered/deregistered.*/
796     OCObservationId obsId;
797 } OCObservationInfo;
798
799 /**
800  * Possible returned values from entity handler.
801  */
802 typedef enum
803 {
804     OC_EH_OK = 0,
805     OC_EH_ERROR,
806     OC_EH_RESOURCE_CREATED,
807     OC_EH_RESOURCE_DELETED,
808     OC_EH_SLOW,
809     OC_EH_FORBIDDEN,
810     OC_EH_RESOURCE_NOT_FOUND
811 } OCEntityHandlerResult;
812
813 /**
814  * This structure will be used to define the vendor specific header options to be included
815  * in communication packets.
816  */
817 typedef struct OCHeaderOption
818 {
819     /** The protocol ID this option applies to.*/
820     OCTransportProtocolID protocolID;
821
822     /** The header option ID which will be added to communication packets.*/
823     uint16_t optionID;
824
825     /** its length 191.*/
826     uint16_t optionLength;
827
828     /** pointer to its data.*/
829     uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
830
831 #ifdef SUPPORTS_DEFAULT_CTOR
832     OCHeaderOption() = default;
833     OCHeaderOption(OCTransportProtocolID pid,
834                    uint16_t optId,
835                    uint16_t optlen,
836                    const uint8_t* optData)
837         : protocolID(pid),
838           optionID(optId),
839           optionLength(optlen)
840     {
841
842         // parameter includes the null terminator.
843         optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
844                         optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
845         memcpy(optionData, optData, optionLength);
846         optionData[optionLength - 1] = '\0';
847     }
848 #endif
849 } OCHeaderOption;
850
851
852 /**
853  * This structure describes the platform properties. All non-Null properties will be
854  * included in a platform discovery request.
855  */
856 typedef struct
857 {
858     /** Platform ID.*/
859     char *platformID;
860
861     /** Manufacturer name.*/
862     char *manufacturerName;
863
864     /** Manufacturer URL for platform property.*/
865     char *manufacturerUrl;
866
867     /** Model number.*/
868     char *modelNumber;
869
870     /** Manufacturer date.*/
871     char *dateOfManufacture;
872
873     /** Platform version.*/
874     char *platformVersion;
875
876     /** Operating system version.*/
877     char *operatingSystemVersion;
878
879     /** HW version.*/
880     char *hardwareVersion;
881
882     /** FW version.*/
883     char *firmwareVersion;
884
885     /** Platform support URL.*/
886     char *supportUrl;
887
888     /** System time.*/
889     char *systemTime;
890
891 } OCPlatformInfo;
892
893 /**
894  * This structure is expected as input for device properties.
895  * device name is mandatory and expected from the application.
896  * device id of type UUID will be generated by the stack.
897  */
898 typedef struct
899 {
900     /** Pointer to the device name.*/
901     char *deviceName;
902
903 } OCDeviceInfo;
904
905 #ifdef RA_ADAPTER
906 /**
907  * callback for bound JID
908  */
909 typedef void (*jid_bound_cb)(char *jid);
910
911 /**
912  * CA Remote Access information for XMPP Client
913  *
914  */
915 typedef struct
916 {
917     char *hostname;     /**< XMPP server hostname */
918     uint16_t   port;    /**< XMPP server serivce port */
919     char *xmpp_domain;  /**< XMPP login domain */
920     char *username;     /**< login username */
921     char *password;     /**< login password */
922     char *resource;     /**< specific resource for login */
923     char *user_jid;     /**< specific JID for login */
924     jid_bound_cb jidbound;  /**< callback when JID bound */
925 } OCRAInfo_t;
926 #endif  /* RA_ADAPTER */
927
928
929 /** Enum to describe the type of object held by the OCPayload object.*/
930 typedef enum
931 {
932     PAYLOAD_TYPE_INVALID,
933     PAYLOAD_TYPE_DISCOVERY,
934     PAYLOAD_TYPE_DEVICE,
935     PAYLOAD_TYPE_PLATFORM,
936     PAYLOAD_TYPE_REPRESENTATION,
937     PAYLOAD_TYPE_SECURITY,
938     PAYLOAD_TYPE_PRESENCE,
939     PAYLOAD_TYPE_RD
940 } OCPayloadType;
941
942 typedef struct
943 {
944     // The type of message that was received
945     OCPayloadType type;
946 } OCPayload;
947
948 typedef enum
949 {
950     OCREP_PROP_NULL,
951     OCREP_PROP_INT,
952     OCREP_PROP_DOUBLE,
953     OCREP_PROP_BOOL,
954     OCREP_PROP_STRING,
955     OCREP_PROP_BYTE_STRING,
956     OCREP_PROP_OBJECT,
957     OCREP_PROP_ARRAY
958 }OCRepPayloadPropType;
959
960 /** This structure will be used to represent a binary string for CBOR payloads.*/
961 typedef struct
962 {
963     /** pointer to data bytes.*/
964     uint8_t* bytes;
965
966     /** number of data bytes.*/
967     size_t   len;
968 } OCByteString;
969
970 #define MAX_REP_ARRAY_DEPTH 3
971 typedef struct
972 {
973     OCRepPayloadPropType type;
974     size_t dimensions[MAX_REP_ARRAY_DEPTH];
975
976     union
977     {
978         int64_t* iArray;
979         double* dArray;
980         bool* bArray;
981         char** strArray;
982
983         /** pointer to ByteString array.*/
984         OCByteString* ocByteStrArray;
985
986         struct OCRepPayload** objArray;
987     };
988 } OCRepPayloadValueArray;
989
990 typedef struct OCRepPayloadValue
991 {
992     char* name;
993     OCRepPayloadPropType type;
994     union
995     {
996         int64_t i;
997         double d;
998         bool b;
999         char* str;
1000
1001         /** ByteString object.*/
1002         OCByteString ocByteStr;
1003
1004         struct OCRepPayload* obj;
1005         OCRepPayloadValueArray arr;
1006     };
1007     struct OCRepPayloadValue* next;
1008
1009 } OCRepPayloadValue;
1010
1011 typedef struct OCStringLL
1012 {
1013     struct OCStringLL *next;
1014     char* value;
1015 } OCStringLL;
1016
1017 // used for get/set/put/observe/etc representations
1018 typedef struct OCRepPayload
1019 {
1020     OCPayload base;
1021     char* uri;
1022     OCStringLL* types;
1023     OCStringLL* interfaces;
1024     OCRepPayloadValue* values;
1025     struct OCRepPayload* next;
1026 } OCRepPayload;
1027
1028 // used inside a discovery payload
1029 typedef struct OCResourcePayload
1030 {
1031     char* uri;
1032     OCStringLL* types;
1033     OCStringLL* interfaces;
1034     uint8_t bitmap;
1035     bool secure;
1036     uint16_t port;
1037     struct OCResourcePayload* next;
1038 } OCResourcePayload;
1039
1040 /**
1041  * Structure holding Links Payload. It is a sub-structure used in
1042  * OCResourceCollectionPayload.
1043  */
1044 typedef struct OCLinksPayload
1045 {
1046     /** This is the target relative URI. */
1047     char *href;
1048     /** Resource Type - A standard OIC specified or vendor defined resource
1049      * type of the resource referenced by the target URI. */
1050     OCStringLL *rt;
1051     /** Interface - The interfaces supported by the resource referenced by the target URI. */
1052     OCStringLL *itf;
1053     /** The relation of the target URI referenced by the link to the context URI;
1054      * The default value is null. */
1055     char *rel;
1056     /** Specifies if the resource referenced by the target URIis observable or not. */
1057     bool obs;
1058     /** A title for the link relation. Can be used by the UI to provide a context. */
1059     char *title;
1060     /** This is used to override the context URI e.g. override the URI of the containing collection. */
1061     char *uri;
1062     /** The instance identifier for this web link in an array of web links - used in links. */
1063     union
1064     {
1065         /** An ordinal number that is not repeated - must be unique in the collection context. */
1066         uint8_t ins;
1067         /** Any unique string including a URI. */
1068         char *uniqueStr;
1069         /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1070         OCIdentity uniqueUUID;
1071     };
1072     /** A hint of the media type of the representation of the resource referenced by the target URI. */
1073     OCStringLL *mt;
1074     /** Holding address of the next resource. */
1075     struct OCLinksPayload *next;
1076 } OCLinksPayload;
1077
1078 /** Structure holding tags value of the links payload. */
1079 typedef struct
1080 {
1081     /** Name of tags. */
1082     OCDeviceInfo n;
1083     /** Device identifier. */
1084     OCIdentity di;
1085     /** The base URI where the resources are hold. */
1086     char *baseURI;
1087     /** Bitmap holds observable, discoverable, secure option flag.*/
1088     uint8_t bitmap;
1089     /** Port set in case, the secure flag is set above. */
1090     uint16_t port;
1091     /** Id for each set of links i.e. tag. */
1092     union
1093     {
1094         /** An ordinal number that is not repeated - must be unique in the collection context. */
1095         uint8_t ins;
1096         /** Any unique string including a URI. */
1097         char *uniqueStr;
1098         /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1099         OCIdentity uniqueUUID;
1100     };
1101     /** Defines the list of allowable resource types (for Target and anchors) in links included
1102      * in the collection; new links being created can only be from this list. */
1103     char *rts;
1104     /** When specified this is the default relationship to use when an OIC Link does not specify
1105      * an explicit relationship with *rel* parameter. */
1106     char *drel;
1107     /** Time to keep holding resource.*/
1108     uint32_t ttl;
1109 } OCTagsPayload;
1110
1111 /** Resource collection payload. */
1112 typedef struct OCResourceCollectionPayload
1113 {
1114     /** Collection tags payload.*/
1115     OCTagsPayload *tags;
1116     /** Array of links payload. */
1117     OCLinksPayload *setLinks;
1118     /** Holding address of the next resource. */
1119     struct OCResourceCollectionPayload *next;
1120 } OCResourceCollectionPayload;
1121
1122 typedef struct
1123 {
1124     OCPayload base;
1125
1126     uint8_t* sid;
1127
1128     /** A special case for handling RD address. */
1129     char* baseURI;
1130
1131     /** This structure holds the old /oic/res response. */
1132     OCResourcePayload *resources;
1133
1134 } OCDiscoveryPayload;
1135
1136 /**
1137  * Structure holding discovery payload.
1138  */
1139 typedef struct
1140 {
1141     /** Device Name. */
1142     OCDeviceInfo n;
1143     /** Device Identity. */
1144     OCIdentity di;
1145     /** Value holding the bias factor of the RD. */
1146     uint8_t sel;
1147 } OCRDDiscoveryPayload;
1148
1149 /**
1150  * RD Payload that will be transmitted over the wire.
1151  */
1152 typedef struct
1153 {
1154     OCPayload base;
1155     /** Pointer to the discovery response payload.*/
1156     OCRDDiscoveryPayload *rdDiscovery;
1157     /** Pointer to the publish payload.*/
1158     OCResourceCollectionPayload *rdPublish;
1159 } OCRDPayload;
1160
1161 typedef struct
1162 {
1163     OCPayload base;
1164     uint8_t* sid;
1165     char* deviceName;
1166     char* specVersion;
1167     char* dataModelVersion;
1168 } OCDevicePayload;
1169
1170 typedef struct
1171 {
1172     OCPayload base;
1173     char* uri;
1174     OCPlatformInfo info;
1175 } OCPlatformPayload;
1176
1177 typedef struct
1178 {
1179     OCPayload base;
1180     char* securityData;
1181 } OCSecurityPayload;
1182 #ifdef WITH_PRESENCE
1183 typedef struct
1184 {
1185     OCPayload base;
1186     uint32_t sequenceNumber;
1187     uint32_t maxAge;
1188     OCPresenceTrigger trigger;
1189     char* resourceType;
1190 } OCPresencePayload;
1191 #endif
1192
1193 /**
1194  * Incoming requests handled by the server. Requests are passed in as a parameter to the
1195  * OCEntityHandler callback API.
1196  * The OCEntityHandler callback API must be implemented in the application in order
1197  * to receive these requests.
1198  */
1199 typedef struct
1200 {
1201     /** Associated resource.*/
1202     OCResourceHandle resource;
1203
1204     /** Associated request handle.*/
1205     OCRequestHandle requestHandle;
1206
1207     /** the REST method retrieved from received request PDU.*/
1208     OCMethod method;
1209
1210     /** description of endpoint that sent the request.*/
1211     OCDevAddr devAddr;
1212
1213     /** resource query send by client.*/
1214     char * query;
1215
1216     /** Information associated with observation - valid only when OCEntityHandler flag includes
1217      * ::OC_OBSERVE_FLAG.*/
1218     OCObservationInfo obsInfo;
1219
1220     /** Number of the received vendor specific header options.*/
1221     uint8_t numRcvdVendorSpecificHeaderOptions;
1222
1223     /** Pointer to the array of the received vendor specific header options.*/
1224     OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1225
1226     /** the payload from the request PDU.*/
1227     OCPayload *payload;
1228
1229 } OCEntityHandlerRequest;
1230
1231
1232 /**
1233  * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1234  */
1235 typedef struct
1236 {
1237     /** Address of remote server.*/
1238     OCDevAddr devAddr;
1239
1240     /** backward compatibility (points to devAddr).*/
1241     OCDevAddr *addr;
1242
1243     /** backward compatibility.*/
1244     OCConnectivityType connType;
1245
1246     /** the security identity of the remote server.*/
1247     OCIdentity identity;
1248
1249     /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1250     OCStackResult result;
1251
1252     /** If associated with observe, this will represent the sequence of notifications from server.*/
1253     uint32_t sequenceNumber;
1254
1255     /** resourceURI.*/
1256     const char * resourceUri;
1257
1258     /** the payload for the response PDU.*/
1259     OCPayload *payload;
1260
1261     /** Number of the received vendor specific header options.*/
1262     uint8_t numRcvdVendorSpecificHeaderOptions;
1263
1264     /** An array of the received vendor specific header options.*/
1265     OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1266 } OCClientResponse;
1267
1268 /**
1269  * Request handle is passed to server via the entity handler for each incoming request.
1270  * Stack assigns when request is received, server sets to indicate what request response is for.
1271  */
1272 typedef struct
1273 {
1274     /** Request handle.*/
1275     OCRequestHandle requestHandle;
1276
1277     /** Resource handle.*/
1278     OCResourceHandle resourceHandle;
1279
1280     /** Allow the entity handler to pass a result with the response.*/
1281     OCEntityHandlerResult  ehResult;
1282
1283     /** This is the pointer to server payload data to be transferred.*/
1284     OCPayload* payload;
1285
1286     /** number of the vendor specific header options .*/
1287     uint8_t numSendVendorSpecificHeaderOptions;
1288
1289     /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1290     OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1291
1292     /** URI of new resource that entity handler might create.*/
1293     char resourceUri[MAX_URI_LENGTH];
1294
1295     /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1296     uint8_t persistentBufferFlag;
1297 } OCEntityHandlerResponse;
1298
1299 /**
1300  * Entity's state
1301  */
1302 typedef enum
1303 {
1304     /** Request state.*/
1305     OC_REQUEST_FLAG = (1 << 1),
1306     /** Observe state.*/
1307     OC_OBSERVE_FLAG = (1 << 2)
1308 } OCEntityHandlerFlag;
1309
1310 /**
1311  * Possible returned values from client application.
1312  */
1313 typedef enum
1314 {
1315     OC_STACK_DELETE_TRANSACTION = 0,
1316     OC_STACK_KEEP_TRANSACTION
1317 } OCStackApplicationResult;
1318
1319
1320 /*
1321  * -------------------------------------------------------------------------------------------
1322  * Callback function definitions
1323  * -------------------------------------------------------------------------------------------
1324  */
1325
1326 /**
1327  * Client applications implement this callback to consume responses received from Servers.
1328  */
1329 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1330     OCClientResponse * clientResponse);
1331
1332 /**
1333  * Client applications using a context pointer implement this callback to delete the
1334  * context upon removal of the callback/context pointer from the internal callback-list.
1335  */
1336 typedef void (* OCClientContextDeleter)(void *context);
1337
1338 /**
1339  * This info is passed from application to OC Stack when initiating a request to Server.
1340  */
1341 typedef struct OCCallbackData
1342 {
1343     /** Pointer to the context.*/
1344     void *context;
1345
1346     /** The pointer to a function the stack will call to handle the requests.*/
1347     OCClientResponseHandler cb;
1348
1349     /** A pointer to a function to delete the context when this callback is removed.*/
1350     OCClientContextDeleter cd;
1351
1352 #ifdef SUPPORTS_DEFAULT_CTOR
1353     OCCallbackData() = default;
1354     OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1355         :context(ctx), cb(callback), cd(deleter){}
1356 #endif
1357 } OCCallbackData;
1358
1359 /**
1360  * Application server implementations must implement this callback to consume requests OTA.
1361  * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1362  */
1363 typedef OCEntityHandlerResult (*OCEntityHandler)
1364 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1365
1366 /**
1367  * Device Entity handler need to use this call back instead of OCEntityHandler.
1368  */
1369 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1370 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1371
1372 #ifdef __cplusplus
1373 }
1374 #endif // __cplusplus
1375
1376 #endif /* OCTYPES_H_ */