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 #ifdef ROUTING_GATEWAY
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 interface.*/
147 #define OC_RSRVD_INTERFACE "if"
149 /** To represent time to live.*/
150 #define OC_RSRVD_TTL "ttl"
152 /** To represent non*/
153 #define OC_RSRVD_NONCE "non"
155 /** To represent trigger type.*/
156 #define OC_RSRVD_TRIGGER "trg"
158 /** To represent links.*/
159 #define OC_RSRVD_LINKS "links"
161 /** To represent default interface.*/
162 #define OC_RSRVD_INTERFACE_DEFAULT "oic.if.baseline"
164 /** To represent read-only interface.*/
165 #define OC_RSRVD_INTERFACE_READ "oic.if.r"
167 /** To represent ll interface.*/
168 #define OC_RSRVD_INTERFACE_LL "oic.if.ll"
170 /** To represent batch interface.*/
171 #define OC_RSRVD_INTERFACE_BATCH "oic.if.b"
173 /** To represent interface group.*/
174 #define OC_RSRVD_INTERFACE_GROUP "oic.mi.grp"
176 /** To represent MFG date.*/
177 #define OC_RSRVD_MFG_DATE "mndt"
179 /** To represent FW version.*/
180 #define OC_RSRVD_FW_VERSION "mnfv"
182 /** To represent host name.*/
183 #define OC_RSRVD_HOST_NAME "hn"
185 /** To represent version.*/
186 #define OC_RSRVD_VERSION "icv"
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"
200 /** For Server instance ID.*/
201 #define OC_RSRVD_SERVER_INSTANCE_ID "sid"
208 #define OC_RSRVD_PLATFORM_ID "pi"
210 /** Platform MFG NAME. */
211 #define OC_RSRVD_MFG_NAME "mnmn"
214 #define OC_RSRVD_MFG_URL "mnml"
217 #define OC_RSRVD_MODEL_NUM "mnmo"
219 /** Platform MFG Date.*/
220 #define OC_RSRVD_MFG_DATE "mndt"
222 /** Platform versio.n */
223 #define OC_RSRVD_PLATFORM_VERSION "mnpv"
225 /** Platform Operating system version. */
226 #define OC_RSRVD_OS_VERSION "mnos"
228 /** Platform Hardware version. */
229 #define OC_RSRVD_HARDWARE_VERSION "mnhw"
231 /**Platform Firmware version. */
232 #define OC_RSRVD_FIRMWARE_VERSION "mnfv"
234 /** Support URL for the platform. */
235 #define OC_RSRVD_SUPPORT_URL "mnsl"
237 /** System time for the platform. */
238 #define OC_RSRVD_SYSTEM_TIME "st"
245 #define OC_RSRVD_DEVICE_ID "di"
248 #define OC_RSRVD_DEVICE_NAME "n"
250 /** Device specification version.*/
251 #define OC_RSRVD_SPEC_VERSION "lcv"
253 /** Device data model.*/
254 #define OC_RSRVD_DATA_MODEL_VERSION "dmv"
256 /** Device specification version.*/
257 #define OC_SPEC_VERSION "core.1.0.0"
259 /** Device Data Model version.*/
260 #define OC_DATA_MODEL_VERSION "res.1.0.0"
263 * These provide backward compatibility - their use is deprecated.
267 /** Multicast Prefix.*/
268 #define OC_MULTICAST_PREFIX "224.0.1.187:5683"
270 /** Multicast IP address.*/
271 #define OC_MULTICAST_IP "224.0.1.187"
273 /** Multicast Port.*/
274 #define OC_MULTICAST_PORT 5683
277 /** Max Device address size. */
279 #define MAX_ADDR_STR_SIZE (256)
281 #define MAX_ADDR_STR_SIZE (40)
284 /** Max identity size. */
285 #define MAX_IDENTITY_SIZE (32)
287 /** Resource Directory */
289 /** Resource Directory URI used to Discover RD and Publish resources.*/
290 #define OC_RSRVD_RD_URI "/oic/rd"
292 /** To represent resource type with rd.*/
293 #define OC_RSRVD_RESOURCE_TYPE_RD "oic.wk.rd"
295 /** RD Discovery bias factor type. */
296 #define OC_RSRVD_RD_DISCOVERY_SEL "sel"
299 #define OC_RSRVD_BASE_URI "baseURI"
301 /** Unique value per collection/link. */
302 #define OC_RSRVD_INS "ins"
304 /** Allowable resource types in the links. */
305 #define OC_RSRVD_RTS "rts"
307 /** Default relationship. */
308 #define OC_RSRVD_DREL "drel"
310 /** Defines relationship between links. */
311 #define OC_RSRVD_REL "rel"
313 /** Defines title. */
314 #define OC_RSRVD_TITLE "title"
317 #define OC_RSRVD_URI "uri"
319 /** Defines media type. */
320 #define OC_RSRVD_MEDIA_TYPE "mt"
322 /** To represent resource type with Publish RD.*/
323 #define OC_RSRVD_RESOURCE_TYPE_RDPUBLISH "oic.wk.rdPub"
326 * These enums (OCTransportAdapter and OCTransportFlags) must
327 * be kept synchronized with OCConnectivityType (below) as well as
328 * CATransportAdapter and CATransportFlags (in CACommon.h).
332 /** value zero indicates discovery.*/
333 OC_DEFAULT_ADAPTER = 0,
335 /** IPv4 and IPv6, including 6LoWPAN.*/
336 OC_ADAPTER_IP = (1 << 0),
338 /** GATT over Bluetooth LE.*/
339 OC_ADAPTER_GATT_BTLE = (1 << 1),
341 /** RFCOMM over Bluetooth EDR.*/
342 OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
345 /**Remote Access over XMPP.*/
346 OC_ADAPTER_REMOTE_ACCESS = (1 << 3),
349 OC_ADAPTER_TCP = (1 << 4)
351 } OCTransportAdapter;
354 * Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
358 /** default flag is 0*/
359 OC_DEFAULT_FLAGS = 0,
361 /** Insecure transport is the default (subject to change).*/
362 /** secure the transport path*/
363 OC_FLAG_SECURE = (1 << 4),
365 /** IPv4 & IPv6 auto-selection is the default.*/
366 /** IP adapter only.*/
367 OC_IP_USE_V6 = (1 << 5),
369 /** IP adapter only.*/
370 OC_IP_USE_V4 = (1 << 6),
372 /** internal use only.*/
373 OC_RESERVED1 = (1 << 7), // internal use only
375 /** Link-Local multicast is the default multicast scope for IPv6.
376 * These are placed here to correspond to the IPv6 multicast address bits.*/
378 /** IPv6 Interface-Local scope (loopback).*/
379 OC_SCOPE_INTERFACE = 0x1,
381 /** IPv6 Link-Local scope (default).*/
384 /** IPv6 Realm-Local scope. */
385 OC_SCOPE_REALM = 0x3,
387 /** IPv6 Admin-Local scope. */
388 OC_SCOPE_ADMIN = 0x4,
390 /** IPv6 Site-Local scope. */
393 /** IPv6 Organization-Local scope. */
396 /**IPv6 Global scope. */
397 OC_SCOPE_GLOBAL = 0xE,
401 /** Bit mask for scope.*/
402 #define OC_MASK_SCOPE (0x000F)
404 /** Bit mask for Mods.*/
405 #define OC_MASK_MODS (0x0FF0)
406 #define OC_MASK_FAMS (OC_IP_USE_V6|OC_IP_USE_V4)
409 * End point identity.
413 /** Identity Length */
416 /** Array of end point identity.*/
417 unsigned char id[MAX_IDENTITY_SIZE];
421 * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
422 * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
427 OCTransportAdapter adapter;
429 /** transport modifiers.*/
430 OCTransportFlags flags;
435 /** address for all adapters.*/
436 char addr[MAX_ADDR_STR_SIZE];
438 /** usually zero for default interface.*/
440 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
441 char routeData[MAX_ADDR_STR_SIZE]; //destination GatewayID:ClientId
446 * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
447 * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
448 * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
451 * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
455 /** use when defaults are ok. */
458 /** IPv4 and IPv6, including 6LoWPAN.*/
459 CT_ADAPTER_IP = (1 << 16),
461 /** GATT over Bluetooth LE.*/
462 CT_ADAPTER_GATT_BTLE = (1 << 17),
464 /** RFCOMM over Bluetooth EDR.*/
465 CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
468 /** Remote Access over XMPP.*/
469 CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
472 CT_ADAPTER_TCP = (1 << 20),
474 /** Insecure transport is the default (subject to change).*/
476 /** secure the transport path.*/
477 CT_FLAG_SECURE = (1 << 4),
479 /** IPv4 & IPv6 autoselection is the default.*/
481 /** IP adapter only.*/
482 CT_IP_USE_V6 = (1 << 5),
484 /** IP adapter only.*/
485 CT_IP_USE_V4 = (1 << 6),
487 /** Link-Local multicast is the default multicast scope for IPv6.
488 * These are placed here to correspond to the IPv6 address bits.*/
490 /** IPv6 Interface-Local scope(loopback).*/
491 CT_SCOPE_INTERFACE = 0x1,
493 /** IPv6 Link-Local scope (default).*/
496 /** IPv6 Realm-Local scope.*/
497 CT_SCOPE_REALM = 0x3,
499 /** IPv6 Admin-Local scope.*/
500 CT_SCOPE_ADMIN = 0x4,
502 /** IPv6 Site-Local scope.*/
505 /** IPv6 Organization-Local scope.*/
508 /** IPv6 Global scope.*/
509 CT_SCOPE_GLOBAL = 0xE,
510 } OCConnectivityType;
512 /** bit shift required for connectivity adapter.*/
513 #define CT_ADAPTER_SHIFT 16
516 #define CT_MASK_FLAGS 0xFFFF
519 #define CT_MASK_ADAPTER 0xFFFF0000
522 * OCDoResource methods to dispatch the request
526 OC_REST_NOMETHOD = 0,
529 OC_REST_GET = (1 << 0),
532 OC_REST_PUT = (1 << 1),
535 OC_REST_POST = (1 << 2),
538 OC_REST_DELETE = (1 << 3),
540 /** Register observe request for most up date notifications ONLY.*/
541 OC_REST_OBSERVE = (1 << 4),
543 /** Register observe request for all notifications, including stale notifications.*/
544 OC_REST_OBSERVE_ALL = (1 << 5),
546 /** De-register observation, intended for internal use.*/
547 OC_REST_CANCEL_OBSERVE = (1 << 6),
550 /** Subscribe for all presence notifications of a particular resource.*/
551 OC_REST_PRESENCE = (1 << 7),
554 /** Allows OCDoResource caller to do discovery.*/
555 OC_REST_DISCOVER = (1 << 8)
559 * Formats for payload encoding.
565 OC_FORMAT_UNSUPPORTED,
569 * Host Mode of Operation.
576 OC_GATEWAY /**< Client server mode along with routing capabilities.*/
580 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
581 * protocol. The precise definitions of each quality of service level depend on the
582 * implementation. In descriptions below are for the current implementation and may changed
587 /** Packet delivery is best effort.*/
590 /** Packet delivery is best effort.*/
593 /** Acknowledgments are used to confirm delivery.*/
596 /** No Quality is defined, let the stack decide.*/
598 } OCQualityOfService;
601 * Resource Properties.
602 * The value of a policy property is defined as bitmap.
603 * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
604 * Not including the policy property is equivalent to zero.
609 /** When none of the bits are set, the resource is non-discoverable &
610 * non-observable by the client.*/
611 OC_RES_PROP_NONE = (0),
613 /** When this bit is set, the resource is allowed to be discovered by clients.*/
614 OC_DISCOVERABLE = (1 << 0),
616 /** When this bit is set, the resource is allowed to be observed by clients.*/
617 OC_OBSERVABLE = (1 << 1),
619 /** When this bit is set, the resource is initialized, otherwise the resource
620 * is 'inactive'. 'inactive' signifies that the resource has been marked for
621 * deletion or is already deleted.*/
622 OC_ACTIVE = (1 << 2),
624 /** When this bit is set, the resource has been marked as 'slow'.
625 * 'slow' signifies that responses from this resource can expect delays in
626 * processing its requests from clients.*/
629 /** When this bit is set, the resource is a secure resource.*/
630 OC_SECURE = (1 << 4),
632 /** When this bit is set, the resource is allowed to be discovered only
633 * if discovery request contains an explicit querystring.
634 * Ex: GET /oic/res?rt=oic.sec.acl */
635 OC_EXPLICIT_DISCOVERABLE = (1 << 5)
636 } OCResourceProperty;
639 * Transport Protocol IDs.
643 /** For invalid ID.*/
644 OC_INVALID_ID = (1 << 0),
647 OC_COAP_ID = (1 << 1)
648 } OCTransportProtocolID;
651 * Declares Stack Results & Errors.
655 /** Success status code - START HERE.*/
657 OC_STACK_RESOURCE_CREATED,
658 OC_STACK_RESOURCE_DELETED,
660 /** Success status code - END HERE.*/
662 /** Error status code - START HERE.*/
663 OC_STACK_INVALID_URI = 20,
664 OC_STACK_INVALID_QUERY,
666 OC_STACK_INVALID_PORT,
667 OC_STACK_INVALID_CALLBACK,
668 OC_STACK_INVALID_METHOD,
670 /** Invalid parameter.*/
671 OC_STACK_INVALID_PARAM,
672 OC_STACK_INVALID_OBSERVE_PARAM,
676 OC_STACK_ADAPTER_NOT_ENABLED,
679 /** Resource not found.*/
680 OC_STACK_NO_RESOURCE,
682 /** e.g: not supported method or interface.*/
683 OC_STACK_RESOURCE_ERROR,
684 OC_STACK_SLOW_RESOURCE,
685 OC_STACK_DUPLICATE_REQUEST,
687 /** Resource has no registered observers.*/
688 OC_STACK_NO_OBSERVERS,
689 OC_STACK_OBSERVER_NOT_FOUND,
690 OC_STACK_VIRTUAL_DO_NOT_HANDLE,
691 OC_STACK_INVALID_OPTION,
693 /** The remote reply contained malformed data.*/
694 OC_STACK_MALFORMED_RESPONSE,
695 OC_STACK_PERSISTENT_BUFFER_REQUIRED,
696 OC_STACK_INVALID_REQUEST_HANDLE,
697 OC_STACK_INVALID_DEVICE_INFO,
698 OC_STACK_INVALID_JSON,
700 /** Request is not authorized by Resource Server. */
701 OC_STACK_UNAUTHORIZED_REQ,
703 /** Error code from PDM */
704 OC_STACK_PDM_IS_NOT_INITIALIZED,
705 OC_STACK_DUPLICATE_UUID,
706 OC_STACK_INCONSISTENT_DB,
708 /** Insert all new error codes here!.*/
710 OC_STACK_PRESENCE_STOPPED = 128,
711 OC_STACK_PRESENCE_TIMEOUT,
712 OC_STACK_PRESENCE_DO_NOT_HANDLE,
714 /** ERROR in stack.*/
716 /** Error status code - END HERE.*/
720 * Handle to an OCDoResource invocation.
722 typedef void * OCDoHandle;
725 * Handle to an OCResource object owned by the OCStack.
727 typedef void * OCResourceHandle;
730 * Handle to an OCRequest object owned by the OCStack.
732 typedef void * OCRequestHandle;
735 * Unique identifier for each observation request. Used when observations are
736 * registered or de-registered. Used by entity handler to signal specific
737 * observers to be notified of resource changes.
738 * There can be maximum of 256 observations per server.
740 typedef uint8_t OCObservationId;
743 * Action associated with observation.
748 OC_OBSERVE_REGISTER = 0,
750 /** To Deregister. */
751 OC_OBSERVE_DEREGISTER = 1,
754 OC_OBSERVE_NO_OPTION = 2
759 * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
760 * when it calls OCRegisterPersistentStorageHandler.
761 * Persistent storage open handler points to default file path.
762 * Application can point to appropriate SVR database path for it's IoTivity Server.
765 /** Persistent storage file path.*/
766 FILE* (* open)(const char *path, const char *mode);
768 /** Persistent storage read handler.*/
769 size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
771 /** Persistent storage write handler.*/
772 size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
774 /** Persistent storage close handler.*/
775 int (* close)(FILE *fp);
777 /** Persistent storage unlink handler.*/
778 int (* unlink)(const char *path);
779 } OCPersistentStorage;
782 * Possible returned values from entity handler.
786 /** Action associated with observation request.*/
787 OCObserveAction action;
789 /** Identifier for observation being registered/deregistered.*/
790 OCObservationId obsId;
794 * Possible returned values from entity handler.
800 OC_EH_RESOURCE_CREATED,
801 OC_EH_RESOURCE_DELETED,
804 OC_EH_RESOURCE_NOT_FOUND
805 } OCEntityHandlerResult;
808 * This structure will be used to define the vendor specific header options to be included
809 * in communication packets.
811 typedef struct OCHeaderOption
813 /** The protocol ID this option applies to.*/
814 OCTransportProtocolID protocolID;
816 /** The header option ID which will be added to communication packets.*/
819 /** its length 191.*/
820 uint16_t optionLength;
822 /** pointer to its data.*/
823 uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
825 #ifdef SUPPORTS_DEFAULT_CTOR
826 OCHeaderOption() = default;
827 OCHeaderOption(OCTransportProtocolID pid,
830 const uint8_t* optData)
836 // parameter includes the null terminator.
837 optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
838 optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
839 memcpy(optionData, optData, optionLength);
840 optionData[optionLength - 1] = '\0';
847 * This structure describes the platform properties. All non-Null properties will be
848 * included in a platform discovery request.
855 /** Manufacturer name.*/
856 char *manufacturerName;
858 /** Manufacturer URL for platform property.*/
859 char *manufacturerUrl;
864 /** Manufacturer date.*/
865 char *dateOfManufacture;
867 /** Platform version.*/
868 char *platformVersion;
870 /** Operating system version.*/
871 char *operatingSystemVersion;
874 char *hardwareVersion;
877 char *firmwareVersion;
879 /** Platform support URL.*/
888 * This structure is expected as input for device properties.
889 * device name is mandatory and expected from the application.
890 * device id of type UUID will be generated by the stack.
894 /** Pointer to the device name.*/
901 * CA Remote Access information for XMPP Client
906 char *hostname; /**< XMPP server hostname */
907 uint16_t port; /**< XMPP server serivce port */
908 char *xmpp_domain; /**< XMPP login domain */
909 char *username; /**< login username */
910 char *password; /**< login password */
911 char *resource; /**< specific resource for login */
912 char *user_jid; /**< specific JID for login */
914 #endif /* RA_ADAPTER */
917 /** Enum to describe the type of object held by the OCPayload object.*/
920 PAYLOAD_TYPE_INVALID,
921 PAYLOAD_TYPE_DISCOVERY,
923 PAYLOAD_TYPE_PLATFORM,
924 PAYLOAD_TYPE_REPRESENTATION,
925 PAYLOAD_TYPE_SECURITY,
926 PAYLOAD_TYPE_PRESENCE,
932 // The type of message that was received
943 OCREP_PROP_BYTE_STRING,
946 }OCRepPayloadPropType;
948 /** This structure will be used to represent a binary string for CBOR payloads.*/
951 /** pointer to data bytes.*/
954 /** number of data bytes.*/
958 #define MAX_REP_ARRAY_DEPTH 3
961 OCRepPayloadPropType type;
962 size_t dimensions[MAX_REP_ARRAY_DEPTH];
971 /** pointer to ByteString array.*/
972 OCByteString* ocByteStrArray;
974 struct OCRepPayload** objArray;
976 } OCRepPayloadValueArray;
978 typedef struct OCRepPayloadValue
981 OCRepPayloadPropType type;
989 /** ByteString object.*/
990 OCByteString ocByteStr;
992 struct OCRepPayload* obj;
993 OCRepPayloadValueArray arr;
995 struct OCRepPayloadValue* next;
999 typedef struct OCStringLL
1001 struct OCStringLL *next;
1005 // used for get/set/put/observe/etc representations
1006 typedef struct OCRepPayload
1011 OCStringLL* interfaces;
1012 OCRepPayloadValue* values;
1013 struct OCRepPayload* next;
1016 // used inside a discovery payload
1017 typedef struct OCResourcePayload
1021 OCStringLL* interfaces;
1025 struct OCResourcePayload* next;
1026 } OCResourcePayload;
1029 * Structure holding Links Payload. It is a sub-structure used in
1030 * OCResourceCollectionPayload.
1032 typedef struct OCLinksPayload
1034 /** This is the target relative URI. */
1036 /** Resource Type - A standard OIC specified or vendor defined resource
1037 * type of the resource referenced by the target URI. */
1039 /** Interface - The interfaces supported by the resource referenced by the target URI. */
1041 /** The relation of the target URI referenced by the link to the context URI;
1042 * The default value is null. */
1044 /** Specifies if the resource referenced by the target URIis observable or not. */
1046 /** A title for the link relation. Can be used by the UI to provide a context. */
1048 /** This is used to override the context URI e.g. override the URI of the containing collection. */
1050 /** The instance identifier for this web link in an array of web links - used in links. */
1053 /** An ordinal number that is not repeated - must be unique in the collection context. */
1055 /** Any unique string including a URI. */
1057 /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1058 OCIdentity uniqueUUID;
1060 /** A hint of the media type of the representation of the resource referenced by the target URI. */
1062 /** Holding address of the next resource. */
1063 struct OCLinksPayload *next;
1066 /** Structure holding tags value of the links payload. */
1069 /** Name of tags. */
1071 /** Device identifier. */
1073 /** The base URI where the resources are hold. */
1075 /** Bitmap holds observable, discoverable, secure option flag.*/
1077 /** Port set in case, the secure flag is set above. */
1079 /** Id for each set of links i.e. tag. */
1082 /** An ordinal number that is not repeated - must be unique in the collection context. */
1084 /** Any unique string including a URI. */
1086 /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1087 OCIdentity uniqueUUID;
1089 /** Defines the list of allowable resource types (for Target and anchors) in links included
1090 * in the collection; new links being created can only be from this list. */
1092 /** When specified this is the default relationship to use when an OIC Link does not specify
1093 * an explicit relationship with *rel* parameter. */
1095 /** Time to keep holding resource.*/
1099 /** Resource collection payload. */
1100 typedef struct OCResourceCollectionPayload
1102 /** Collection tags payload.*/
1103 OCTagsPayload *tags;
1104 /** Array of links payload. */
1105 OCLinksPayload *setLinks;
1106 /** Holding address of the next resource. */
1107 struct OCResourceCollectionPayload *next;
1108 } OCResourceCollectionPayload;
1116 /** This structure holds the old /oic/res response. */
1117 OCResourcePayload *resources;
1118 /** This structure holds the collection response for the /oic/res. */
1119 OCResourceCollectionPayload *collectionResources;
1120 } OCDiscoveryPayload;
1123 * Structure holding discovery payload.
1129 /** Device Identity. */
1131 /** Value holding the bias factor of the RD. */
1133 } OCRDDiscoveryPayload;
1136 * RD Payload that will be transmitted over the wire.
1141 /** Pointer to the discovery response payload.*/
1142 OCRDDiscoveryPayload *rdDiscovery;
1143 /** Pointer to the publish payload.*/
1144 OCResourceCollectionPayload *rdPublish;
1153 char* dataModelVersion;
1160 OCPlatformInfo info;
1161 } OCPlatformPayload;
1167 } OCSecurityPayload;
1168 #ifdef WITH_PRESENCE
1172 uint32_t sequenceNumber;
1174 OCPresenceTrigger trigger;
1176 } OCPresencePayload;
1180 * Incoming requests handled by the server. Requests are passed in as a parameter to the
1181 * OCEntityHandler callback API.
1182 * The OCEntityHandler callback API must be implemented in the application in order
1183 * to receive these requests.
1187 /** Associated resource.*/
1188 OCResourceHandle resource;
1190 /** Associated request handle.*/
1191 OCRequestHandle requestHandle;
1193 /** the REST method retrieved from received request PDU.*/
1196 /** description of endpoint that sent the request.*/
1199 /** resource query send by client.*/
1202 /** Information associated with observation - valid only when OCEntityHandler flag includes
1203 * ::OC_OBSERVE_FLAG.*/
1204 OCObservationInfo obsInfo;
1206 /** Number of the received vendor specific header options.*/
1207 uint8_t numRcvdVendorSpecificHeaderOptions;
1209 /** Pointer to the array of the received vendor specific header options.*/
1210 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1212 /** the payload from the request PDU.*/
1215 } OCEntityHandlerRequest;
1219 * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1223 /** Address of remote server.*/
1226 /** backward compatibility (points to devAddr).*/
1229 /** backward compatibility.*/
1230 OCConnectivityType connType;
1232 /** the security identity of the remote server.*/
1233 OCIdentity identity;
1235 /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1236 OCStackResult result;
1238 /** If associated with observe, this will represent the sequence of notifications from server.*/
1239 uint32_t sequenceNumber;
1242 const char * resourceUri;
1244 /** the payload for the response PDU.*/
1247 /** Number of the received vendor specific header options.*/
1248 uint8_t numRcvdVendorSpecificHeaderOptions;
1250 /** An array of the received vendor specific header options.*/
1251 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1255 * Request handle is passed to server via the entity handler for each incoming request.
1256 * Stack assigns when request is received, server sets to indicate what request response is for.
1260 /** Request handle.*/
1261 OCRequestHandle requestHandle;
1263 /** Resource handle.*/
1264 OCResourceHandle resourceHandle;
1266 /** Allow the entity handler to pass a result with the response.*/
1267 OCEntityHandlerResult ehResult;
1269 /** This is the pointer to server payload data to be transferred.*/
1272 /** number of the vendor specific header options .*/
1273 uint8_t numSendVendorSpecificHeaderOptions;
1275 /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1276 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1278 /** URI of new resource that entity handler might create.*/
1279 char resourceUri[MAX_URI_LENGTH];
1281 /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1282 uint8_t persistentBufferFlag;
1283 } OCEntityHandlerResponse;
1290 /** Request state.*/
1291 OC_REQUEST_FLAG = (1 << 1),
1292 /** Observe state.*/
1293 OC_OBSERVE_FLAG = (1 << 2)
1294 } OCEntityHandlerFlag;
1297 * Possible returned values from client application.
1301 OC_STACK_DELETE_TRANSACTION = 0,
1302 OC_STACK_KEEP_TRANSACTION
1303 } OCStackApplicationResult;
1307 * -------------------------------------------------------------------------------------------
1308 * Callback function definitions
1309 * -------------------------------------------------------------------------------------------
1313 * Client applications implement this callback to consume responses received from Servers.
1315 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1316 OCClientResponse * clientResponse);
1319 * Client applications using a context pointer implement this callback to delete the
1320 * context upon removal of the callback/context pointer from the internal callback-list.
1322 typedef void (* OCClientContextDeleter)(void *context);
1325 * This info is passed from application to OC Stack when initiating a request to Server.
1327 typedef struct OCCallbackData
1329 /** Pointer to the context.*/
1332 /** The pointer to a function the stack will call to handle the requests.*/
1333 OCClientResponseHandler cb;
1335 /** A pointer to a function to delete the context when this callback is removed.*/
1336 OCClientContextDeleter cd;
1338 #ifdef SUPPORTS_DEFAULT_CTOR
1339 OCCallbackData() = default;
1340 OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1341 :context(ctx), cb(callback), cd(deleter){}
1346 * Application server implementations must implement this callback to consume requests OTA.
1347 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1349 typedef OCEntityHandlerResult (*OCEntityHandler)
1350 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1353 * Device Entity handler need to use this call back instead of OCEntityHandler.
1355 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1356 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1360 #endif // __cplusplus
1362 #endif /* OCTYPES_H_ */