1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //******************************************************************
25 * This file contains the definition, types and APIs for resource(s) be implemented.
31 #include "platform_features.h"
32 #include "ocstackconfig.h"
42 /** For the feature presence.*/
45 #include "ocpresence.h"
46 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
51 * OIC Virtual resources supported by every OIC device.
54 * Default discovery mechanism using '/oic/res' is supported by all OIC devices
55 * That are Discoverable.
57 #define OC_RSRVD_WELL_KNOWN_URI "/oic/res"
60 #define OC_RSRVD_DEVICE_URI "/oic/d"
63 #define OC_RSRVD_PLATFORM_URI "/oic/p"
66 #define OC_RSRVD_RESOURCE_TYPES_URI "/oic/res/types/d"
67 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
69 #define OC_RSRVD_GATEWAY_URI "/oic/gateway"
73 /** Presence URI through which the OIC devices advertise their presence.*/
74 #define OC_RSRVD_PRESENCE_URI "/oic/ad"
76 /** Sets the default time to live (TTL) for presence.*/
77 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
79 /** For multicast Discovery mechanism.*/
80 #define OC_MULTICAST_DISCOVERY_URI "/oic/res"
82 /** Separator for multiple query string.*/
83 #define OC_QUERY_SEPARATOR "&;"
86 * OC_DEFAULT_PRESENCE_TTL_SECONDS sets the default time to live (TTL) for presence.
88 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
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
94 * 60 sec/min * 60 min/hr * 24 hr/day
96 #define OC_MAX_PRESENCE_TTL_SECONDS (60 * 60 * 24)
100 * Presence "Announcement Triggers".
104 #define OC_RSRVD_TRIGGER_CREATE "create"
107 #define OC_RSRVD_TRIGGER_CHANGE "change"
110 #define OC_RSRVD_TRIGGER_DELETE "delete"
113 * Attributes used to form a proper OIC conforming JSON message.
116 #define OC_RSRVD_OC "oic"
120 #define OC_RSRVD_PAYLOAD "payload"
122 /** To represent href */
123 #define OC_RSRVD_HREF "href"
125 /** To represent property*/
126 #define OC_RSRVD_PROPERTY "prop"
128 /** For representation.*/
129 #define OC_RSRVD_REPRESENTATION "rep"
131 /** To represent content type.*/
132 #define OC_RSRVD_CONTENT_TYPE "ct"
134 /** To represent resource type.*/
135 #define OC_RSRVD_RESOURCE_TYPE "rt"
137 /** To represent resource type with presence.*/
138 #define OC_RSRVD_RESOURCE_TYPE_PRESENCE "oic.wk.ad"
140 /** To represent resource type with device.*/
141 #define OC_RSRVD_RESOURCE_TYPE_DEVICE "oic.wk.d"
143 /** To represent resource type with platform.*/
144 #define OC_RSRVD_RESOURCE_TYPE_PLATFORM "oic.wk.p"
146 /** To represent resource type with RES.*/
147 #define OC_RSRVD_RESOURCE_TYPE_RES "oic.wk.res"
149 /** To represent interface.*/
150 #define OC_RSRVD_INTERFACE "if"
152 /** To represent time to live.*/
153 #define OC_RSRVD_TTL "ttl"
155 /** To represent non*/
156 #define OC_RSRVD_NONCE "non"
158 /** To represent trigger type.*/
159 #define OC_RSRVD_TRIGGER "trg"
161 /** To represent links.*/
162 #define OC_RSRVD_LINKS "links"
164 /** To represent default interface.*/
165 #define OC_RSRVD_INTERFACE_DEFAULT "oic.if.baseline"
167 /** To represent read-only interface.*/
168 #define OC_RSRVD_INTERFACE_READ "oic.if.r"
170 /** To represent ll interface.*/
171 #define OC_RSRVD_INTERFACE_LL "oic.if.ll"
173 /** To represent batch interface.*/
174 #define OC_RSRVD_INTERFACE_BATCH "oic.if.b"
176 /** To represent interface group.*/
177 #define OC_RSRVD_INTERFACE_GROUP "oic.mi.grp"
179 /** To represent MFG date.*/
180 #define OC_RSRVD_MFG_DATE "mndt"
182 /** To represent FW version.*/
183 #define OC_RSRVD_FW_VERSION "mnfv"
185 /** To represent host name.*/
186 #define OC_RSRVD_HOST_NAME "hn"
188 /** To represent policy.*/
189 #define OC_RSRVD_POLICY "p"
191 /** To represent bitmap.*/
192 #define OC_RSRVD_BITMAP "bm"
195 #define OC_RSRVD_SECURE "sec"
198 #define OC_RSRVD_HOSTING_PORT "port"
201 #define OC_RSRVD_TCP_PORT "tcp"
203 /** For Server instance ID.*/
204 #define OC_RSRVD_SERVER_INSTANCE_ID "sid"
211 #define OC_RSRVD_PLATFORM_ID "pi"
213 /** Platform MFG NAME. */
214 #define OC_RSRVD_MFG_NAME "mnmn"
217 #define OC_RSRVD_MFG_URL "mnml"
220 #define OC_RSRVD_MODEL_NUM "mnmo"
222 /** Platform MFG Date.*/
223 #define OC_RSRVD_MFG_DATE "mndt"
225 /** Platform versio.n */
226 #define OC_RSRVD_PLATFORM_VERSION "mnpv"
228 /** Platform Operating system version. */
229 #define OC_RSRVD_OS_VERSION "mnos"
231 /** Platform Hardware version. */
232 #define OC_RSRVD_HARDWARE_VERSION "mnhw"
234 /**Platform Firmware version. */
235 #define OC_RSRVD_FIRMWARE_VERSION "mnfv"
237 /** Support URL for the platform. */
238 #define OC_RSRVD_SUPPORT_URL "mnsl"
240 /** System time for the platform. */
241 #define OC_RSRVD_SYSTEM_TIME "st"
248 #define OC_RSRVD_DEVICE_ID "di"
251 #define OC_RSRVD_DEVICE_NAME "n"
253 /** Device specification version.*/
254 #define OC_RSRVD_SPEC_VERSION "icv"
256 /** Device data model.*/
257 #define OC_RSRVD_DATA_MODEL_VERSION "dmv"
259 /** Device specification version.*/
260 #define OC_SPEC_VERSION "core.1.0.0"
262 /** Device Data Model version.*/
263 #define OC_DATA_MODEL_VERSION "res.1.0.0"
266 * These provide backward compatibility - their use is deprecated.
270 /** Multicast Prefix.*/
271 #define OC_MULTICAST_PREFIX "224.0.1.187:5683"
273 /** Multicast IP address.*/
274 #define OC_MULTICAST_IP "224.0.1.187"
276 /** Multicast Port.*/
277 #define OC_MULTICAST_PORT 5683
280 /** Max Device address size. */
282 #define MAX_ADDR_STR_SIZE (256)
284 /** Max Address could be "coap+tcp://[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx]:xxxxx" */
285 #define MAX_ADDR_STR_SIZE (59)
288 /** Length of MAC address */
289 #define MAC_ADDR_STR_SIZE (17)
291 /** Blocks of MAC address */
292 #define MAC_ADDR_BLOCKS (6)
294 /** Max identity size. */
295 #define MAX_IDENTITY_SIZE (32)
297 /** Universal unique identity size. */
298 #define UUID_IDENTITY_SIZE (128/8)
300 /** Resource Directory */
302 /** Resource Directory URI used to Discover RD and Publish resources.*/
303 #define OC_RSRVD_RD_URI "/oic/rd"
305 /** To represent resource type with rd.*/
306 #define OC_RSRVD_RESOURCE_TYPE_RD "oic.wk.rd"
308 /** RD Discovery bias factor type. */
309 #define OC_RSRVD_RD_DISCOVERY_SEL "sel"
312 #define OC_RSRVD_BASE_URI "baseURI"
314 /** Unique value per collection/link. */
315 #define OC_RSRVD_INS "ins"
317 /** Allowable resource types in the links. */
318 #define OC_RSRVD_RTS "rts"
320 /** Default relationship. */
321 #define OC_RSRVD_DREL "drel"
323 /** Defines relationship between links. */
324 #define OC_RSRVD_REL "rel"
326 /** Defines title. */
327 #define OC_RSRVD_TITLE "title"
330 #define OC_RSRVD_URI "uri"
332 /** Defines media type. */
333 #define OC_RSRVD_MEDIA_TYPE "mt"
335 /** To represent resource type with Publish RD.*/
336 #define OC_RSRVD_RESOURCE_TYPE_RDPUBLISH "oic.wk.rdpub"
339 * Mark a parameter as unused. Used to prevent unused variable compiler warnings.
340 * Used in three cases:
341 * 1. in callbacks when one of the parameters are unused
342 * 2. when due to code changes a functions parameter is no longer
343 * used but must be left in place for backward compatibility
345 * 3. a variable is only used in the debug build variant and would
346 * give a build warning in release mode.
348 #define OC_UNUSED(x) (void)(x)
351 * These enums (OCTransportAdapter and OCTransportFlags) must
352 * be kept synchronized with OCConnectivityType (below) as well as
353 * CATransportAdapter and CATransportFlags (in CACommon.h).
357 /** value zero indicates discovery.*/
358 OC_DEFAULT_ADAPTER = 0,
360 /** IPv4 and IPv6, including 6LoWPAN.*/
361 OC_ADAPTER_IP = (1 << 0),
363 /** GATT over Bluetooth LE.*/
364 OC_ADAPTER_GATT_BTLE = (1 << 1),
366 /** RFCOMM over Bluetooth EDR.*/
367 OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
369 /**Remote Access over XMPP.*/
370 OC_ADAPTER_REMOTE_ACCESS = (1 << 3),
373 OC_ADAPTER_TCP = (1 << 4),
375 /** NFC Transport for Messaging.*/
376 OC_ADAPTER_NFC = (1 << 5)
377 } OCTransportAdapter;
380 * Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
384 /** default flag is 0*/
385 OC_DEFAULT_FLAGS = 0,
387 /** Insecure transport is the default (subject to change).*/
388 /** secure the transport path*/
389 OC_FLAG_SECURE = (1 << 4),
391 /** IPv4 & IPv6 auto-selection is the default.*/
392 /** IP & TCP adapter only.*/
393 OC_IP_USE_V6 = (1 << 5),
395 /** IP & TCP adapter only.*/
396 OC_IP_USE_V4 = (1 << 6),
398 /** internal use only.*/
399 OC_RESERVED1 = (1 << 7), // internal use only
401 /** Link-Local multicast is the default multicast scope for IPv6.
402 * These are placed here to correspond to the IPv6 multicast address bits.*/
404 /** IPv6 Interface-Local scope (loopback).*/
405 OC_SCOPE_INTERFACE = 0x1,
407 /** IPv6 Link-Local scope (default).*/
410 /** IPv6 Realm-Local scope. */
411 OC_SCOPE_REALM = 0x3,
413 /** IPv6 Admin-Local scope. */
414 OC_SCOPE_ADMIN = 0x4,
416 /** IPv6 Site-Local scope. */
419 /** IPv6 Organization-Local scope. */
422 /**IPv6 Global scope. */
423 OC_SCOPE_GLOBAL = 0xE,
427 /** Bit mask for scope.*/
428 #define OC_MASK_SCOPE (0x000F)
430 /** Bit mask for Mods.*/
431 #define OC_MASK_MODS (0x0FF0)
432 #define OC_MASK_FAMS (OC_IP_USE_V6|OC_IP_USE_V4)
434 typedef struct OCStringLL
436 struct OCStringLL *next;
441 * End point identity.
445 /** Identity Length */
448 /** Array of end point identity.*/
449 unsigned char id[MAX_IDENTITY_SIZE];
453 * Universally unique identifier.
457 /** identitifier string.*/
458 unsigned char id[UUID_IDENTITY_SIZE];
462 * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
463 * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
468 OCTransportAdapter adapter;
470 /** transport modifiers.*/
471 OCTransportFlags flags;
476 /** address for all adapters.*/
477 char addr[MAX_ADDR_STR_SIZE];
479 /** usually zero for default interface.*/
481 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
482 char routeData[MAX_ADDR_STR_SIZE]; //destination GatewayID:ClientId
487 * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
488 * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
489 * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
492 * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
496 /** use when defaults are ok. */
499 /** IPv4 and IPv6, including 6LoWPAN.*/
500 CT_ADAPTER_IP = (1 << 16),
502 /** GATT over Bluetooth LE.*/
503 CT_ADAPTER_GATT_BTLE = (1 << 17),
505 /** RFCOMM over Bluetooth EDR.*/
506 CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
509 /** Remote Access over XMPP.*/
510 CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
513 CT_ADAPTER_TCP = (1 << 20),
516 CT_ADAPTER_NFC = (1 << 21),
518 /** Insecure transport is the default (subject to change).*/
520 /** secure the transport path.*/
521 CT_FLAG_SECURE = (1 << 4),
523 /** IPv4 & IPv6 autoselection is the default.*/
525 /** IP adapter only.*/
526 CT_IP_USE_V6 = (1 << 5),
528 /** IP adapter only.*/
529 CT_IP_USE_V4 = (1 << 6),
531 /** Link-Local multicast is the default multicast scope for IPv6.
532 * These are placed here to correspond to the IPv6 address bits.*/
534 /** IPv6 Interface-Local scope(loopback).*/
535 CT_SCOPE_INTERFACE = 0x1,
537 /** IPv6 Link-Local scope (default).*/
540 /** IPv6 Realm-Local scope.*/
541 CT_SCOPE_REALM = 0x3,
543 /** IPv6 Admin-Local scope.*/
544 CT_SCOPE_ADMIN = 0x4,
546 /** IPv6 Site-Local scope.*/
549 /** IPv6 Organization-Local scope.*/
552 /** IPv6 Global scope.*/
553 CT_SCOPE_GLOBAL = 0xE,
554 } OCConnectivityType;
556 /** bit shift required for connectivity adapter.*/
557 #define CT_ADAPTER_SHIFT 16
560 #define CT_MASK_FLAGS 0xFFFF
563 #define CT_MASK_ADAPTER 0xFFFF0000
566 * OCDoResource methods to dispatch the request
570 OC_REST_NOMETHOD = 0,
573 OC_REST_GET = (1 << 0),
576 OC_REST_PUT = (1 << 1),
579 OC_REST_POST = (1 << 2),
582 OC_REST_DELETE = (1 << 3),
584 /** Register observe request for most up date notifications ONLY.*/
585 OC_REST_OBSERVE = (1 << 4),
587 /** Register observe request for all notifications, including stale notifications.*/
588 OC_REST_OBSERVE_ALL = (1 << 5),
590 /** De-register observation, intended for internal use.*/
591 OC_REST_CANCEL_OBSERVE = (1 << 6),
594 /** Subscribe for all presence notifications of a particular resource.*/
595 OC_REST_PRESENCE = (1 << 7),
598 /** Allows OCDoResource caller to do discovery.*/
599 OC_REST_DISCOVER = (1 << 8)
603 * Formats for payload encoding.
609 OC_FORMAT_UNSUPPORTED,
613 * Host Mode of Operation.
620 OC_GATEWAY /**< Client server mode along with routing capabilities.*/
624 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
625 * protocol. The precise definitions of each quality of service level depend on the
626 * implementation. In descriptions below are for the current implementation and may changed
631 /** Packet delivery is best effort.*/
634 /** Packet delivery is best effort.*/
637 /** Acknowledgments are used to confirm delivery.*/
640 /** No Quality is defined, let the stack decide.*/
642 } OCQualityOfService;
645 * Resource Properties.
646 * The value of a policy property is defined as bitmap.
647 * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
648 * Not including the policy property is equivalent to zero.
653 /** When none of the bits are set, the resource is non-discoverable &
654 * non-observable by the client.*/
655 OC_RES_PROP_NONE = (0),
657 /** When this bit is set, the resource is allowed to be discovered by clients.*/
658 OC_DISCOVERABLE = (1 << 0),
660 /** When this bit is set, the resource is allowed to be observed by clients.*/
661 OC_OBSERVABLE = (1 << 1),
663 /** When this bit is set, the resource is initialized, otherwise the resource
664 * is 'inactive'. 'inactive' signifies that the resource has been marked for
665 * deletion or is already deleted.*/
666 OC_ACTIVE = (1 << 2),
668 /** When this bit is set, the resource has been marked as 'slow'.
669 * 'slow' signifies that responses from this resource can expect delays in
670 * processing its requests from clients.*/
673 /** When this bit is set, the resource is a secure resource.*/
674 OC_SECURE = (1 << 4),
676 /** When this bit is set, the resource is allowed to be discovered only
677 * if discovery request contains an explicit querystring.
678 * Ex: GET /oic/res?rt=oic.sec.acl */
679 OC_EXPLICIT_DISCOVERABLE = (1 << 5)
680 } OCResourceProperty;
683 * Transport Protocol IDs.
687 /** For invalid ID.*/
688 OC_INVALID_ID = (1 << 0),
691 OC_COAP_ID = (1 << 1)
692 } OCTransportProtocolID;
695 * Declares Stack Results & Errors.
699 /** Success status code - START HERE.*/
701 OC_STACK_RESOURCE_CREATED,
702 OC_STACK_RESOURCE_DELETED,
704 /** Success status code - END HERE.*/
706 /** Error status code - START HERE.*/
707 OC_STACK_INVALID_URI = 20,
708 OC_STACK_INVALID_QUERY,
710 OC_STACK_INVALID_PORT,
711 OC_STACK_INVALID_CALLBACK,
712 OC_STACK_INVALID_METHOD,
714 /** Invalid parameter.*/
715 OC_STACK_INVALID_PARAM,
716 OC_STACK_INVALID_OBSERVE_PARAM,
720 OC_STACK_ADAPTER_NOT_ENABLED,
723 /** Resource not found.*/
724 OC_STACK_NO_RESOURCE,
726 /** e.g: not supported method or interface.*/
727 OC_STACK_RESOURCE_ERROR,
728 OC_STACK_SLOW_RESOURCE,
729 OC_STACK_DUPLICATE_REQUEST,
731 /** Resource has no registered observers.*/
732 OC_STACK_NO_OBSERVERS,
733 OC_STACK_OBSERVER_NOT_FOUND,
734 OC_STACK_VIRTUAL_DO_NOT_HANDLE,
735 OC_STACK_INVALID_OPTION,
737 /** The remote reply contained malformed data.*/
738 OC_STACK_MALFORMED_RESPONSE,
739 OC_STACK_PERSISTENT_BUFFER_REQUIRED,
740 OC_STACK_INVALID_REQUEST_HANDLE,
741 OC_STACK_INVALID_DEVICE_INFO,
742 OC_STACK_INVALID_JSON,
744 /** Request is not authorized by Resource Server. */
745 OC_STACK_UNAUTHORIZED_REQ,
747 /** Error code from PDM */
748 OC_STACK_PDM_IS_NOT_INITIALIZED,
749 OC_STACK_DUPLICATE_UUID,
750 OC_STACK_INCONSISTENT_DB,
753 * Error code from OTM
754 * This error is pushed from DTLS interface when handshake failure happens
756 OC_STACK_AUTHENTICATION_FAILURE,
758 /** Insert all new error codes here!.*/
760 OC_STACK_PRESENCE_STOPPED = 128,
761 OC_STACK_PRESENCE_TIMEOUT,
762 OC_STACK_PRESENCE_DO_NOT_HANDLE,
764 /** ERROR in stack.*/
766 /** Error status code - END HERE.*/
770 * Handle to an OCDoResource invocation.
772 typedef void * OCDoHandle;
775 * Handle to an OCResource object owned by the OCStack.
777 typedef void * OCResourceHandle;
780 * Handle to an OCRequest object owned by the OCStack.
782 typedef void * OCRequestHandle;
785 * Unique identifier for each observation request. Used when observations are
786 * registered or de-registered. Used by entity handler to signal specific
787 * observers to be notified of resource changes.
788 * There can be maximum of 256 observations per server.
790 typedef uint8_t OCObservationId;
793 * Action associated with observation.
798 OC_OBSERVE_REGISTER = 0,
800 /** To Deregister. */
801 OC_OBSERVE_DEREGISTER = 1,
804 OC_OBSERVE_NO_OPTION = 2
809 * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
810 * when it calls OCRegisterPersistentStorageHandler.
811 * Persistent storage open handler points to default file path.
812 * It should check file path and whether the file is symbolic link or no.
813 * Application can point to appropriate SVR database path for it's IoTivity Server.
816 /** Persistent storage file path.*/
817 FILE* (* open)(const char *path, const char *mode);
819 /** Persistent storage read handler.*/
820 size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
822 /** Persistent storage write handler.*/
823 size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
825 /** Persistent storage close handler.*/
826 int (* close)(FILE *fp);
828 /** Persistent storage unlink handler.*/
829 int (* unlink)(const char *path);
830 } OCPersistentStorage;
833 * Possible returned values from entity handler.
837 /** Action associated with observation request.*/
838 OCObserveAction action;
840 /** Identifier for observation being registered/deregistered.*/
841 OCObservationId obsId;
845 * Possible returned values from entity handler.
851 OC_EH_RESOURCE_CREATED,
852 OC_EH_RESOURCE_DELETED,
855 OC_EH_RESOURCE_NOT_FOUND
856 } OCEntityHandlerResult;
859 * This structure will be used to define the vendor specific header options to be included
860 * in communication packets.
862 typedef struct OCHeaderOption
864 /** The protocol ID this option applies to.*/
865 OCTransportProtocolID protocolID;
867 /** The header option ID which will be added to communication packets.*/
870 /** its length 191.*/
871 uint16_t optionLength;
873 /** pointer to its data.*/
874 uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
876 #ifdef SUPPORTS_DEFAULT_CTOR
877 OCHeaderOption() = default;
878 OCHeaderOption(OCTransportProtocolID pid,
881 const uint8_t* optData)
887 // parameter includes the null terminator.
888 optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
889 optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
890 memcpy(optionData, optData, optionLength);
891 optionData[optionLength - 1] = '\0';
898 * This structure describes the platform properties. All non-Null properties will be
899 * included in a platform discovery request.
906 /** Manufacturer name.*/
907 char *manufacturerName;
909 /** Manufacturer URL for platform property.*/
910 char *manufacturerUrl;
915 /** Manufacturer date.*/
916 char *dateOfManufacture;
918 /** Platform version.*/
919 char *platformVersion;
921 /** Operating system version.*/
922 char *operatingSystemVersion;
925 char *hardwareVersion;
928 char *firmwareVersion;
930 /** Platform support URL.*/
939 * This structure is expected as input for device properties.
940 * device name is mandatory and expected from the application.
941 * device id of type UUID will be generated by the stack.
945 /** Pointer to the device name.*/
947 /** Pointer to the types.*/
953 * callback for bound JID
955 typedef void (*jid_bound_cb)(char *jid);
958 * CA Remote Access information for XMPP Client
963 char *hostname; /**< XMPP server hostname */
964 uint16_t port; /**< XMPP server serivce port */
965 char *xmpp_domain; /**< XMPP login domain */
966 char *username; /**< login username */
967 char *password; /**< login password */
968 char *resource; /**< specific resource for login */
969 char *user_jid; /**< specific JID for login */
970 jid_bound_cb jidbound; /**< callback when JID bound */
972 #endif /* RA_ADAPTER */
975 /** Enum to describe the type of object held by the OCPayload object.*/
978 /** Contents of the payload are invalid */
979 PAYLOAD_TYPE_INVALID,
980 /** The payload is an OCDiscoveryPayload */
981 PAYLOAD_TYPE_DISCOVERY,
982 /** The payload is an OCDevicePayload */
984 /** The payload is an OCPlatformPayload */
985 PAYLOAD_TYPE_PLATFORM,
986 /** The payload is an OCRepPayload */
987 PAYLOAD_TYPE_REPRESENTATION,
988 /** The payload is an OCSecurityPayload */
989 PAYLOAD_TYPE_SECURITY,
990 /** The payload is an OCPresencePayload */
991 PAYLOAD_TYPE_PRESENCE,
992 /** The payload is an OCRDPayload */
997 * A generic struct representing a payload returned from a resource operation
999 * A pointer to OCPayLoad can be cast to a more specific struct to access members
1004 /** The type of message that was received */
1015 OCREP_PROP_BYTE_STRING,
1018 }OCRepPayloadPropType;
1020 /** This structure will be used to represent a binary string for CBOR payloads.*/
1023 /** pointer to data bytes.*/
1026 /** number of data bytes.*/
1030 #define MAX_REP_ARRAY_DEPTH 3
1033 OCRepPayloadPropType type;
1034 size_t dimensions[MAX_REP_ARRAY_DEPTH];
1043 /** pointer to ByteString array.*/
1044 OCByteString* ocByteStrArray;
1046 struct OCRepPayload** objArray;
1048 } OCRepPayloadValueArray;
1050 typedef struct OCRepPayloadValue
1053 OCRepPayloadPropType type;
1061 /** ByteString object.*/
1062 OCByteString ocByteStr;
1064 struct OCRepPayload* obj;
1065 OCRepPayloadValueArray arr;
1067 struct OCRepPayloadValue* next;
1069 } OCRepPayloadValue;
1071 // used for get/set/put/observe/etc representations
1072 typedef struct OCRepPayload
1077 OCStringLL* interfaces;
1078 OCRepPayloadValue* values;
1079 struct OCRepPayload* next;
1082 // used inside a discovery payload
1083 typedef struct OCResourcePayload
1087 OCStringLL* interfaces;
1094 struct OCResourcePayload* next;
1095 } OCResourcePayload;
1098 * Structure holding Links Payload. It is a sub-structure used in
1099 * OCResourceCollectionPayload.
1101 typedef struct OCLinksPayload
1103 /** This is the target relative URI. */
1105 /** Resource Type - A standard OIC specified or vendor defined resource
1106 * type of the resource referenced by the target URI. */
1108 /** Interface - The interfaces supported by the resource referenced by the target URI. */
1110 /** The relation of the target URI referenced by the link to the context URI;
1111 * The default value is null. */
1113 /** Specifies if the resource referenced by the target URIis observable or not. */
1115 /** A title for the link relation. Can be used by the UI to provide a context. */
1117 /** This is used to override the context URI e.g. override the URI of the containing collection. */
1119 /** The instance identifier for this web link in an array of web links - used in links. */
1122 /** An ordinal number that is not repeated - must be unique in the collection context. */
1124 /** Any unique string including a URI. */
1126 /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1127 OCIdentity uniqueUUID;
1129 /** A hint of the media type of the representation of the resource referenced by the target URI. */
1131 /** Holding address of the next resource. */
1132 struct OCLinksPayload *next;
1135 /** Structure holding tags value of the links payload. */
1138 /** Name of tags. */
1140 /** Device identifier. */
1142 /** The base URI where the resources are hold. */
1144 /** Bitmap holds observable, discoverable, secure option flag.*/
1146 /** Port set in case, the secure flag is set above. */
1148 /** Id for each set of links i.e. tag. */
1151 /** An ordinal number that is not repeated - must be unique in the collection context. */
1153 /** Any unique string including a URI. */
1155 /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1156 OCIdentity uniqueUUID;
1158 /** Defines the list of allowable resource types (for Target and anchors) in links included
1159 * in the collection; new links being created can only be from this list. */
1161 /** When specified this is the default relationship to use when an OIC Link does not specify
1162 * an explicit relationship with *rel* parameter. */
1164 /** Time to keep holding resource.*/
1168 /** Resource collection payload. */
1169 typedef struct OCResourceCollectionPayload
1171 /** Collection tags payload.*/
1172 OCTagsPayload *tags;
1173 /** Array of links payload. */
1174 OCLinksPayload *setLinks;
1175 /** Holding address of the next resource. */
1176 struct OCResourceCollectionPayload *next;
1177 } OCResourceCollectionPayload;
1186 /** A special case for handling RD address. */
1195 /** Resource Type */
1201 /** This structure holds the old /oic/res response. */
1202 OCResourcePayload *resources;
1204 } OCDiscoveryPayload;
1207 * Structure holding discovery payload.
1213 /** Device Identity. */
1215 /** Value holding the bias factor of the RD. */
1217 } OCRDDiscoveryPayload;
1220 * RD Payload that will be transmitted over the wire.
1225 /** Pointer to the discovery response payload.*/
1226 OCRDDiscoveryPayload *rdDiscovery;
1227 /** Pointer to the publish payload.*/
1228 OCResourceCollectionPayload *rdPublish;
1237 char* dataModelVersion;
1238 OCStringLL *interfaces;
1246 OCPlatformInfo info;
1248 OCStringLL* interfaces;
1249 } OCPlatformPayload;
1254 uint8_t* securityData;
1256 } OCSecurityPayload;
1258 #ifdef WITH_PRESENCE
1262 uint32_t sequenceNumber;
1264 OCPresenceTrigger trigger;
1266 } OCPresencePayload;
1270 * Incoming requests handled by the server. Requests are passed in as a parameter to the
1271 * OCEntityHandler callback API.
1272 * The OCEntityHandler callback API must be implemented in the application in order
1273 * to receive these requests.
1277 /** Associated resource.*/
1278 OCResourceHandle resource;
1280 /** Associated request handle.*/
1281 OCRequestHandle requestHandle;
1283 /** the REST method retrieved from received request PDU.*/
1286 /** description of endpoint that sent the request.*/
1289 /** resource query send by client.*/
1292 /** Information associated with observation - valid only when OCEntityHandler flag includes
1293 * ::OC_OBSERVE_FLAG.*/
1294 OCObservationInfo obsInfo;
1296 /** Number of the received vendor specific header options.*/
1297 uint8_t numRcvdVendorSpecificHeaderOptions;
1299 /** Pointer to the array of the received vendor specific header options.*/
1300 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1302 /** the payload from the request PDU.*/
1305 } OCEntityHandlerRequest;
1309 * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1313 /** Address of remote server.*/
1316 /** backward compatibility (points to devAddr).*/
1319 /** backward compatibility.*/
1320 OCConnectivityType connType;
1322 /** the security identity of the remote server.*/
1323 OCIdentity identity;
1325 /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1326 OCStackResult result;
1328 /** If associated with observe, this will represent the sequence of notifications from server.*/
1329 uint32_t sequenceNumber;
1332 const char * resourceUri;
1334 /** the payload for the response PDU.*/
1337 /** Number of the received vendor specific header options.*/
1338 uint8_t numRcvdVendorSpecificHeaderOptions;
1340 /** An array of the received vendor specific header options.*/
1341 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1345 * Request handle is passed to server via the entity handler for each incoming request.
1346 * Stack assigns when request is received, server sets to indicate what request response is for.
1350 /** Request handle.*/
1351 OCRequestHandle requestHandle;
1353 /** Resource handle.*/
1354 OCResourceHandle resourceHandle;
1356 /** Allow the entity handler to pass a result with the response.*/
1357 OCEntityHandlerResult ehResult;
1359 /** This is the pointer to server payload data to be transferred.*/
1362 /** number of the vendor specific header options .*/
1363 uint8_t numSendVendorSpecificHeaderOptions;
1365 /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1366 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1368 /** URI of new resource that entity handler might create.*/
1369 char resourceUri[MAX_URI_LENGTH];
1371 /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1372 uint8_t persistentBufferFlag;
1373 } OCEntityHandlerResponse;
1380 /** Request state.*/
1381 OC_REQUEST_FLAG = (1 << 1),
1382 /** Observe state.*/
1383 OC_OBSERVE_FLAG = (1 << 2)
1384 } OCEntityHandlerFlag;
1387 * Possible return values from client application callback
1389 * A client application callback returns an OCStackApplicationResult to indicate whether
1390 * the stack should continue to keep the callback registered.
1394 /** Make no more calls to the callback and call the OCClientContextDeleter for this callback */
1395 OC_STACK_DELETE_TRANSACTION = 0,
1396 /** Keep this callback registered and call it if an apropriate event occurs */
1397 OC_STACK_KEEP_TRANSACTION
1398 } OCStackApplicationResult;
1401 //#ifdef DIRECT_PAIRING
1403 * @brief direct pairing Method Type.
1405 * 1: pre-configured pin
1410 DP_NOT_ALLOWED = 0x0,
1411 DP_PRE_CONFIGURED = (0x1 << 0),
1412 DP_RANDOM_PIN = (0x1 << 1),
1416 * Device Information of discoverd direct pairing device(s).
1418 typedef struct OCDPDev
1421 OCConnectivityType connType;
1422 uint16_t securePort;
1426 OCUUIdentity deviceID;
1427 OCUUIdentity rowner;
1428 struct OCDPDev *next;
1430 //#endif // DIRECT_PAIRING
1433 * -------------------------------------------------------------------------------------------
1434 * Callback function definitions
1435 * -------------------------------------------------------------------------------------------
1439 * Client applications implement this callback to consume responses received from Servers.
1441 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1442 OCClientResponse * clientResponse);
1445 * Client applications using a context pointer implement this callback to delete the
1446 * context upon removal of the callback/context pointer from the internal callback-list.
1448 typedef void (* OCClientContextDeleter)(void *context);
1451 * This info is passed from application to OC Stack when initiating a request to Server.
1453 typedef struct OCCallbackData
1455 /** Pointer to the context.*/
1458 /** The pointer to a function the stack will call to handle the requests.*/
1459 OCClientResponseHandler cb;
1461 /** A pointer to a function to delete the context when this callback is removed.*/
1462 OCClientContextDeleter cd;
1464 #ifdef SUPPORTS_DEFAULT_CTOR
1465 OCCallbackData() = default;
1466 OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1467 :context(ctx), cb(callback), cd(deleter){}
1472 * Application server implementations must implement this callback to consume requests OTA.
1473 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1475 typedef OCEntityHandlerResult (*OCEntityHandler)
1476 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1479 * Device Entity handler need to use this call back instead of OCEntityHandler.
1481 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1482 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1484 //#ifdef DIRECT_PAIRING
1486 * Callback function definition of direct-pairing
1488 * @param[OUT] peer - pairing device info.
1489 * @param[OUT} result - It's returned with 'OC_STACK_XXX'. It will return 'OC_STACK_OK'
1490 * if D2D pairing is success without error
1492 typedef void (*OCDirectPairingCB)(OCDPDev_t *peer, OCStackResult result);
1493 //#endif // DIRECT_PAIRING
1497 #endif // __cplusplus
1499 #endif /* OCTYPES_H_ */