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 * callback for bound JID
903 typedef void (*jid_bound_cb)(char *jid);
906 * CA Remote Access information for XMPP Client
911 char *hostname; /**< XMPP server hostname */
912 uint16_t port; /**< XMPP server serivce port */
913 char *xmpp_domain; /**< XMPP login domain */
914 char *username; /**< login username */
915 char *password; /**< login password */
916 char *resource; /**< specific resource for login */
917 char *user_jid; /**< specific JID for login */
918 jid_bound_cb jidbound; /**< callback when JID bound */
920 #endif /* RA_ADAPTER */
923 /** Enum to describe the type of object held by the OCPayload object.*/
926 PAYLOAD_TYPE_INVALID,
927 PAYLOAD_TYPE_DISCOVERY,
929 PAYLOAD_TYPE_PLATFORM,
930 PAYLOAD_TYPE_REPRESENTATION,
931 PAYLOAD_TYPE_SECURITY,
932 PAYLOAD_TYPE_PRESENCE,
938 // The type of message that was received
949 OCREP_PROP_BYTE_STRING,
952 }OCRepPayloadPropType;
954 /** This structure will be used to represent a binary string for CBOR payloads.*/
957 /** pointer to data bytes.*/
960 /** number of data bytes.*/
964 #define MAX_REP_ARRAY_DEPTH 3
967 OCRepPayloadPropType type;
968 size_t dimensions[MAX_REP_ARRAY_DEPTH];
977 /** pointer to ByteString array.*/
978 OCByteString* ocByteStrArray;
980 struct OCRepPayload** objArray;
982 } OCRepPayloadValueArray;
984 typedef struct OCRepPayloadValue
987 OCRepPayloadPropType type;
995 /** ByteString object.*/
996 OCByteString ocByteStr;
998 struct OCRepPayload* obj;
999 OCRepPayloadValueArray arr;
1001 struct OCRepPayloadValue* next;
1003 } OCRepPayloadValue;
1005 typedef struct OCStringLL
1007 struct OCStringLL *next;
1011 // used for get/set/put/observe/etc representations
1012 typedef struct OCRepPayload
1017 OCStringLL* interfaces;
1018 OCRepPayloadValue* values;
1019 struct OCRepPayload* next;
1022 // used inside a discovery payload
1023 typedef struct OCResourcePayload
1027 OCStringLL* interfaces;
1031 struct OCResourcePayload* next;
1032 } OCResourcePayload;
1035 * Structure holding Links Payload. It is a sub-structure used in
1036 * OCResourceCollectionPayload.
1038 typedef struct OCLinksPayload
1040 /** This is the target relative URI. */
1042 /** Resource Type - A standard OIC specified or vendor defined resource
1043 * type of the resource referenced by the target URI. */
1045 /** Interface - The interfaces supported by the resource referenced by the target URI. */
1047 /** The relation of the target URI referenced by the link to the context URI;
1048 * The default value is null. */
1050 /** Specifies if the resource referenced by the target URIis observable or not. */
1052 /** A title for the link relation. Can be used by the UI to provide a context. */
1054 /** This is used to override the context URI e.g. override the URI of the containing collection. */
1056 /** The instance identifier for this web link in an array of web links - used in links. */
1059 /** An ordinal number that is not repeated - must be unique in the collection context. */
1061 /** Any unique string including a URI. */
1063 /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1064 OCIdentity uniqueUUID;
1066 /** A hint of the media type of the representation of the resource referenced by the target URI. */
1068 /** Holding address of the next resource. */
1069 struct OCLinksPayload *next;
1072 /** Structure holding tags value of the links payload. */
1075 /** Name of tags. */
1077 /** Device identifier. */
1079 /** The base URI where the resources are hold. */
1081 /** Bitmap holds observable, discoverable, secure option flag.*/
1083 /** Port set in case, the secure flag is set above. */
1085 /** Id for each set of links i.e. tag. */
1088 /** An ordinal number that is not repeated - must be unique in the collection context. */
1090 /** Any unique string including a URI. */
1092 /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1093 OCIdentity uniqueUUID;
1095 /** Defines the list of allowable resource types (for Target and anchors) in links included
1096 * in the collection; new links being created can only be from this list. */
1098 /** When specified this is the default relationship to use when an OIC Link does not specify
1099 * an explicit relationship with *rel* parameter. */
1101 /** Time to keep holding resource.*/
1105 /** Resource collection payload. */
1106 typedef struct OCResourceCollectionPayload
1108 /** Collection tags payload.*/
1109 OCTagsPayload *tags;
1110 /** Array of links payload. */
1111 OCLinksPayload *setLinks;
1112 /** Holding address of the next resource. */
1113 struct OCResourceCollectionPayload *next;
1114 } OCResourceCollectionPayload;
1122 /** A special case for handling RD address. */
1125 /** This structure holds the old /oic/res response. */
1126 OCResourcePayload *resources;
1128 } OCDiscoveryPayload;
1131 * Structure holding discovery payload.
1137 /** Device Identity. */
1139 /** Value holding the bias factor of the RD. */
1141 } OCRDDiscoveryPayload;
1144 * RD Payload that will be transmitted over the wire.
1149 /** Pointer to the discovery response payload.*/
1150 OCRDDiscoveryPayload *rdDiscovery;
1151 /** Pointer to the publish payload.*/
1152 OCResourceCollectionPayload *rdPublish;
1161 char* dataModelVersion;
1168 OCPlatformInfo info;
1169 } OCPlatformPayload;
1175 } OCSecurityPayload;
1176 #ifdef WITH_PRESENCE
1180 uint32_t sequenceNumber;
1182 OCPresenceTrigger trigger;
1184 } OCPresencePayload;
1188 * Incoming requests handled by the server. Requests are passed in as a parameter to the
1189 * OCEntityHandler callback API.
1190 * The OCEntityHandler callback API must be implemented in the application in order
1191 * to receive these requests.
1195 /** Associated resource.*/
1196 OCResourceHandle resource;
1198 /** Associated request handle.*/
1199 OCRequestHandle requestHandle;
1201 /** the REST method retrieved from received request PDU.*/
1204 /** description of endpoint that sent the request.*/
1207 /** resource query send by client.*/
1210 /** Information associated with observation - valid only when OCEntityHandler flag includes
1211 * ::OC_OBSERVE_FLAG.*/
1212 OCObservationInfo obsInfo;
1214 /** Number of the received vendor specific header options.*/
1215 uint8_t numRcvdVendorSpecificHeaderOptions;
1217 /** Pointer to the array of the received vendor specific header options.*/
1218 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1220 /** the payload from the request PDU.*/
1223 } OCEntityHandlerRequest;
1227 * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1231 /** Address of remote server.*/
1234 /** backward compatibility (points to devAddr).*/
1237 /** backward compatibility.*/
1238 OCConnectivityType connType;
1240 /** the security identity of the remote server.*/
1241 OCIdentity identity;
1243 /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1244 OCStackResult result;
1246 /** If associated with observe, this will represent the sequence of notifications from server.*/
1247 uint32_t sequenceNumber;
1250 const char * resourceUri;
1252 /** the payload for the response PDU.*/
1255 /** Number of the received vendor specific header options.*/
1256 uint8_t numRcvdVendorSpecificHeaderOptions;
1258 /** An array of the received vendor specific header options.*/
1259 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1263 * Request handle is passed to server via the entity handler for each incoming request.
1264 * Stack assigns when request is received, server sets to indicate what request response is for.
1268 /** Request handle.*/
1269 OCRequestHandle requestHandle;
1271 /** Resource handle.*/
1272 OCResourceHandle resourceHandle;
1274 /** Allow the entity handler to pass a result with the response.*/
1275 OCEntityHandlerResult ehResult;
1277 /** This is the pointer to server payload data to be transferred.*/
1280 /** number of the vendor specific header options .*/
1281 uint8_t numSendVendorSpecificHeaderOptions;
1283 /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1284 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1286 /** URI of new resource that entity handler might create.*/
1287 char resourceUri[MAX_URI_LENGTH];
1289 /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1290 uint8_t persistentBufferFlag;
1291 } OCEntityHandlerResponse;
1298 /** Request state.*/
1299 OC_REQUEST_FLAG = (1 << 1),
1300 /** Observe state.*/
1301 OC_OBSERVE_FLAG = (1 << 2)
1302 } OCEntityHandlerFlag;
1305 * Possible returned values from client application.
1309 OC_STACK_DELETE_TRANSACTION = 0,
1310 OC_STACK_KEEP_TRANSACTION
1311 } OCStackApplicationResult;
1315 * -------------------------------------------------------------------------------------------
1316 * Callback function definitions
1317 * -------------------------------------------------------------------------------------------
1321 * Client applications implement this callback to consume responses received from Servers.
1323 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1324 OCClientResponse * clientResponse);
1327 * Client applications using a context pointer implement this callback to delete the
1328 * context upon removal of the callback/context pointer from the internal callback-list.
1330 typedef void (* OCClientContextDeleter)(void *context);
1333 * This info is passed from application to OC Stack when initiating a request to Server.
1335 typedef struct OCCallbackData
1337 /** Pointer to the context.*/
1340 /** The pointer to a function the stack will call to handle the requests.*/
1341 OCClientResponseHandler cb;
1343 /** A pointer to a function to delete the context when this callback is removed.*/
1344 OCClientContextDeleter cd;
1346 #ifdef SUPPORTS_DEFAULT_CTOR
1347 OCCallbackData() = default;
1348 OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1349 :context(ctx), cb(callback), cd(deleter){}
1354 * Application server implementations must implement this callback to consume requests OTA.
1355 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1357 typedef OCEntityHandlerResult (*OCEntityHandler)
1358 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1361 * Device Entity handler need to use this call back instead of OCEntityHandler.
1363 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1364 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1368 #endif // __cplusplus
1370 #endif /* OCTYPES_H_ */