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