62696872f9562c17ebb908f56886c7ffb3256281
[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  * CA Remote Access information for XMPP Client
861  *
862  */
863 typedef struct
864 {
865     char *hostname;     /**< XMPP server hostname */
866     uint16_t   port;    /**< XMPP server serivce port */
867     char *xmpp_domain;  /**< XMPP login domain */
868     char *username;     /**< login username */
869     char *password;     /**< login password */
870     char *resource;     /**< specific resource for login */
871     char *user_jid;     /**< specific JID for login */
872 } OCRAInfo_t;
873 #endif  /* RA_ADAPTER */
874
875
876 /** Enum to describe the type of object held by the OCPayload object.*/
877 typedef enum
878 {
879     PAYLOAD_TYPE_INVALID,
880     PAYLOAD_TYPE_DISCOVERY,
881     PAYLOAD_TYPE_DEVICE,
882     PAYLOAD_TYPE_PLATFORM,
883     PAYLOAD_TYPE_REPRESENTATION,
884     PAYLOAD_TYPE_SECURITY,
885     PAYLOAD_TYPE_PRESENCE,
886     PAYLOAD_TYPE_RD
887 } OCPayloadType;
888
889 typedef struct
890 {
891     // The type of message that was received
892     OCPayloadType type;
893 } OCPayload;
894
895 typedef enum
896 {
897     OCREP_PROP_NULL,
898     OCREP_PROP_INT,
899     OCREP_PROP_DOUBLE,
900     OCREP_PROP_BOOL,
901     OCREP_PROP_STRING,
902     OCREP_PROP_OBJECT,
903     OCREP_PROP_ARRAY
904 }OCRepPayloadPropType;
905
906 #define MAX_REP_ARRAY_DEPTH 3
907 typedef struct
908 {
909     OCRepPayloadPropType type;
910     size_t dimensions[MAX_REP_ARRAY_DEPTH];
911
912     union
913     {
914         int64_t* iArray;
915         double* dArray;
916         bool* bArray;
917         char** strArray;
918         struct OCRepPayload** objArray;
919     };
920 } OCRepPayloadValueArray;
921
922 typedef struct OCRepPayloadValue
923 {
924     char* name;
925     OCRepPayloadPropType type;
926     union
927     {
928         int64_t i;
929         double d;
930         bool b;
931         char* str;
932         struct OCRepPayload* obj;
933         OCRepPayloadValueArray arr;
934     };
935     struct OCRepPayloadValue* next;
936
937 } OCRepPayloadValue;
938
939 typedef struct OCStringLL
940 {
941     struct OCStringLL *next;
942     char* value;
943 } OCStringLL;
944
945 // used for get/set/put/observe/etc representations
946 typedef struct OCRepPayload
947 {
948     OCPayload base;
949     char* uri;
950     OCStringLL* types;
951     OCStringLL* interfaces;
952     OCRepPayloadValue* values;
953     struct OCRepPayload* next;
954 } OCRepPayload;
955
956 // used inside a discovery payload
957 typedef struct OCResourcePayload
958 {
959     char* uri;
960     uint8_t* sid;
961     OCStringLL* types;
962     OCStringLL* interfaces;
963     uint8_t bitmap;
964     bool secure;
965     uint16_t port;
966     struct OCResourcePayload* next;
967 } OCResourcePayload;
968
969 typedef struct
970 {
971     OCPayload base;
972     OCResourcePayload* resources;
973 } OCDiscoveryPayload;
974
975 typedef struct
976 {
977     OCPayload base;
978     char* uri;
979     uint8_t* sid;
980     char* deviceName;
981     char* specVersion;
982     char* dataModelVersion;
983 } OCDevicePayload;
984
985 typedef struct
986 {
987     OCPayload base;
988     char* uri;
989     OCPlatformInfo info;
990 } OCPlatformPayload;
991
992 typedef struct
993 {
994     OCPayload base;
995     char* securityData;
996 } OCSecurityPayload;
997 #ifdef WITH_PRESENCE
998 typedef struct
999 {
1000     OCPayload base;
1001     uint32_t sequenceNumber;
1002     uint32_t maxAge;
1003     OCPresenceTrigger trigger;
1004     char* resourceType;
1005 } OCPresencePayload;
1006 #endif
1007
1008 /**
1009  * Incoming requests handled by the server. Requests are passed in as a parameter to the
1010  * OCEntityHandler callback API.
1011  * The OCEntityHandler callback API must be implemented in the application in order
1012  * to receive these requests.
1013  */
1014 typedef struct
1015 {
1016     /** Associated resource.*/
1017     OCResourceHandle resource;
1018
1019     /** Associated request handle.*/
1020     OCRequestHandle requestHandle;
1021
1022     /** the REST method retrieved from received request PDU.*/
1023     OCMethod method;
1024
1025     /** description of endpoint that sent the request.*/
1026     OCDevAddr devAddr;
1027
1028     /** resource query send by client.*/
1029     char * query;
1030
1031     /** Information associated with observation - valid only when OCEntityHandler flag includes
1032      * ::OC_OBSERVE_FLAG.*/
1033     OCObservationInfo obsInfo;
1034
1035     /** Number of the received vendor specific header options.*/
1036     uint8_t numRcvdVendorSpecificHeaderOptions;
1037
1038     /** Pointer to the array of the received vendor specific header options.*/
1039     OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1040
1041     /** the payload from the request PDU.*/
1042     OCPayload *payload;
1043
1044 } OCEntityHandlerRequest;
1045
1046
1047 /**
1048  * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1049  */
1050 typedef struct
1051 {
1052     /** Address of remote server.*/
1053     OCDevAddr devAddr;
1054
1055     /** backward compatibility (points to devAddr).*/
1056     OCDevAddr *addr;
1057
1058     /** backward compatibility.*/
1059     OCConnectivityType connType;
1060
1061     /** the security identity of the remote server.*/
1062     OCIdentity identity;
1063
1064     /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1065     OCStackResult result;
1066
1067     /** If associated with observe, this will represent the sequence of notifications from server.*/
1068     uint32_t sequenceNumber;
1069
1070     /** resourceURI.*/
1071     const char * resourceUri;
1072
1073     /** the payload for the response PDU.*/
1074     OCPayload *payload;
1075
1076     /** Number of the received vendor specific header options.*/
1077     uint8_t numRcvdVendorSpecificHeaderOptions;
1078
1079     /** An array of the received vendor specific header options.*/
1080     OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1081 } OCClientResponse;
1082
1083 /**
1084  * Request handle is passed to server via the entity handler for each incoming request.
1085  * Stack assigns when request is received, server sets to indicate what request response is for.
1086  */
1087 typedef struct
1088 {
1089     /** Request handle.*/
1090     OCRequestHandle requestHandle;
1091
1092     /** Resource handle.*/
1093     OCResourceHandle resourceHandle;
1094
1095     /** Allow the entity handler to pass a result with the response.*/
1096     OCEntityHandlerResult  ehResult;
1097
1098     /** This is the pointer to server payload data to be transferred.*/
1099     OCPayload* payload;
1100
1101     /** number of the vendor specific header options .*/
1102     uint8_t numSendVendorSpecificHeaderOptions;
1103
1104     /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1105     OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1106
1107     /** URI of new resource that entity handler might create.*/
1108     char resourceUri[MAX_URI_LENGTH];
1109
1110     /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1111     uint8_t persistentBufferFlag;
1112 } OCEntityHandlerResponse;
1113
1114 /**
1115  * Entity's state
1116  */
1117 typedef enum
1118 {
1119     /** Request state.*/
1120     OC_REQUEST_FLAG = (1 << 1),
1121     /** Observe state.*/
1122     OC_OBSERVE_FLAG = (1 << 2)
1123 } OCEntityHandlerFlag;
1124
1125 /**
1126  * Possible returned values from client application.
1127  */
1128 typedef enum
1129 {
1130     OC_STACK_DELETE_TRANSACTION = 0,
1131     OC_STACK_KEEP_TRANSACTION
1132 } OCStackApplicationResult;
1133
1134
1135 /*
1136  * -------------------------------------------------------------------------------------------
1137  * Callback function definitions
1138  * -------------------------------------------------------------------------------------------
1139  */
1140
1141 /**
1142  * Client applications implement this callback to consume responses received from Servers.
1143  */
1144 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1145     OCClientResponse * clientResponse);
1146
1147 /**
1148  * Client applications using a context pointer implement this callback to delete the
1149  * context upon removal of the callback/context pointer from the internal callback-list.
1150  */
1151 typedef void (* OCClientContextDeleter)(void *context);
1152
1153 /**
1154  * This info is passed from application to OC Stack when initiating a request to Server.
1155  */
1156 typedef struct OCCallbackData
1157 {
1158     /** Pointer to the context.*/
1159     void *context;
1160
1161     /** The pointer to a function the stack will call to handle the requests.*/
1162     OCClientResponseHandler cb;
1163
1164     /** A pointer to a function to delete the context when this callback is removed.*/
1165     OCClientContextDeleter cd;
1166
1167 #ifdef SUPPORTS_DEFAULT_CTOR
1168     OCCallbackData() = default;
1169     OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1170         :context(ctx), cb(callback), cd(deleter){}
1171 #endif
1172 } OCCallbackData;
1173
1174 /**
1175  * Application server implementations must implement this callback to consume requests OTA.
1176  * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1177  */
1178 typedef OCEntityHandlerResult (*OCEntityHandler)
1179 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1180
1181 /**
1182  * Device Entity handler need to use this call back instead of OCEntityHandler.
1183  */
1184 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1185 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1186
1187 #ifdef __cplusplus
1188 }
1189 #endif // __cplusplus
1190
1191 #endif /* OCTYPES_H_ */