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