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