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 interface.*/
141 #define OC_RSRVD_INTERFACE "if"
143 /** To represent time to live.*/
144 #define OC_RSRVD_TTL "ttl"
146 /** To represent non*/
147 #define OC_RSRVD_NONCE "non"
149 /** To represent trigger type.*/
150 #define OC_RSRVD_TRIGGER "trg"
152 /** To represent links.*/
153 #define OC_RSRVD_LINKS "links"
155 /** To represent default interface.*/
156 #define OC_RSRVD_INTERFACE_DEFAULT "oic.if.baseline"
158 /** To represent ll interface.*/
159 #define OC_RSRVD_INTERFACE_LL "oic.if.ll"
161 /** To represent batch interface.*/
162 #define OC_RSRVD_INTERFACE_BATCH "oic.if.b"
164 /** To represent interface group.*/
165 #define OC_RSRVD_INTERFACE_GROUP "oic.mi.grp"
167 /** To represent MFG date.*/
168 #define OC_RSRVD_MFG_DATE "mndt"
170 /** To represent FW version.*/
171 #define OC_RSRVD_FW_VERSION "mnfv"
173 /** To represent host name.*/
174 #define OC_RSRVD_HOST_NAME "hn"
176 /** To represent version.*/
177 #define OC_RSRVD_VERSION "icv"
179 /** To represent policy.*/
180 #define OC_RSRVD_POLICY "p"
182 /** To represent bitmap.*/
183 #define OC_RSRVD_BITMAP "bm"
186 #define OC_RSRVD_SECURE "sec"
189 #define OC_RSRVD_HOSTING_PORT "port"
191 /** For Server instance ID.*/
192 #define OC_RSRVD_SERVER_INSTANCE_ID "sid"
199 #define OC_RSRVD_PLATFORM_ID "pi"
201 /** Platform MFG NAME. */
202 #define OC_RSRVD_MFG_NAME "mnmn"
205 #define OC_RSRVD_MFG_URL "mnml"
208 #define OC_RSRVD_MODEL_NUM "mnmo"
210 /** Platform MFG Date.*/
211 #define OC_RSRVD_MFG_DATE "mndt"
213 /** Platform versio.n */
214 #define OC_RSRVD_PLATFORM_VERSION "mnpv"
216 /** Platform Operating system version. */
217 #define OC_RSRVD_OS_VERSION "mnos"
219 /** Platform Hardware version. */
220 #define OC_RSRVD_HARDWARE_VERSION "mnhw"
222 /**Platform Firmware version. */
223 #define OC_RSRVD_FIRMWARE_VERSION "mnfv"
225 /** Support URL for the platform. */
226 #define OC_RSRVD_SUPPORT_URL "mnsl"
228 /** System time for the platform. */
229 #define OC_RSRVD_SYSTEM_TIME "st"
236 #define OC_RSRVD_DEVICE_ID "di"
239 #define OC_RSRVD_DEVICE_NAME "n"
241 /** Device specification version.*/
242 #define OC_RSRVD_SPEC_VERSION "lcv"
244 /** Device data model.*/
245 #define OC_RSRVD_DATA_MODEL_VERSION "dmv"
247 /** Device specification version.*/
248 #define OC_SPEC_VERSION "0.9.2"
250 /** Device Data Model version.*/
251 #define OC_DATA_MODEL_VERSION "sec.0.95"
254 * These provide backward compatibility - their use is deprecated.
258 /** Multicast Prefix.*/
259 #define OC_MULTICAST_PREFIX "224.0.1.187:5683"
261 /** Multicast IP address.*/
262 #define OC_MULTICAST_IP "224.0.1.187"
264 /** Multicast Port.*/
265 #define OC_MULTICAST_PORT 5683
268 /** Max Device address size. */
270 #define MAX_ADDR_STR_SIZE (256)
272 #define MAX_ADDR_STR_SIZE (40)
275 /** Max identity size. */
276 #define MAX_IDENTITY_SIZE (32)
278 /** Resource Directory */
280 /** Resource Directory URI used to Discover RD and Publish resources.*/
281 #define OC_RSRVD_RD_URI "/oic/rd"
283 /** To represent resource type with rd.*/
284 #define OC_RSRVD_RESOURCE_TYPE_RD "oic.wk.rd"
286 /** RD Discovery bias factor type. */
287 #define OC_RSRVD_RD_DISCOVERY_SEL "sel"
290 #define OC_RSRVD_BASE_URI "baseURI"
292 /** Unique value per collection/link. */
293 #define OC_RSRVD_INS "ins"
295 /** Allowable resource types in the links. */
296 #define OC_RSRVD_RTS "rts"
298 /** Default relationship. */
299 #define OC_RSRVD_DREL "drel"
301 /** Defines relationship between links. */
302 #define OC_RSRVD_REL "rel"
304 /** Defines title. */
305 #define OC_RSRVD_TITLE "title"
308 #define OC_RSRVD_URI "uri"
310 /** Defines media type. */
311 #define OC_RSRVD_MEDIA_TYPE "mt"
313 /** To represent resource type with Publish RD.*/
314 #define OC_RSRVD_RESOURCE_TYPE_RDPUBLISH "oic.wk.rdPub"
317 * These enums (OCTransportAdapter and OCTransportFlags) must
318 * be kept synchronized with OCConnectivityType (below) as well as
319 * CATransportAdapter and CATransportFlags (in CACommon.h).
323 /** value zero indicates discovery.*/
324 OC_DEFAULT_ADAPTER = 0,
326 /** IPv4 and IPv6, including 6LoWPAN.*/
327 OC_ADAPTER_IP = (1 << 0),
329 /** GATT over Bluetooth LE.*/
330 OC_ADAPTER_GATT_BTLE = (1 << 1),
332 /** RFCOMM over Bluetooth EDR.*/
333 OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
336 /**Remote Access over XMPP.*/
337 OC_ADAPTER_REMOTE_ACCESS = (1 << 3),
342 OC_ADAPTER_TCP = (1 << 4)
345 } OCTransportAdapter;
348 * Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
352 /** default flag is 0*/
353 OC_DEFAULT_FLAGS = 0,
355 /** Insecure transport is the default (subject to change).*/
356 /** secure the transport path*/
357 OC_FLAG_SECURE = (1 << 4),
359 /** IPv4 & IPv6 auto-selection is the default.*/
360 /** IP adapter only.*/
361 OC_IP_USE_V6 = (1 << 5),
363 /** IP adapter only.*/
364 OC_IP_USE_V4 = (1 << 6),
366 /** internal use only.*/
367 OC_RESERVED1 = (1 << 7), // internal use only
369 /** Link-Local multicast is the default multicast scope for IPv6.
370 * These are placed here to correspond to the IPv6 multicast address bits.*/
372 /** IPv6 Interface-Local scope (loopback).*/
373 OC_SCOPE_INTERFACE = 0x1,
375 /** IPv6 Link-Local scope (default).*/
378 /** IPv6 Realm-Local scope. */
379 OC_SCOPE_REALM = 0x3,
381 /** IPv6 Admin-Local scope. */
382 OC_SCOPE_ADMIN = 0x4,
384 /** IPv6 Site-Local scope. */
387 /** IPv6 Organization-Local scope. */
390 /**IPv6 Global scope. */
391 OC_SCOPE_GLOBAL = 0xE,
395 /** Bit mask for scope.*/
396 #define OC_MASK_SCOPE (0x000F)
398 /** Bit mask for Mods.*/
399 #define OC_MASK_MODS (0x0FF0)
400 #define OC_MASK_FAMS (OC_IP_USE_V6|OC_IP_USE_V4)
403 * End point identity.
407 /** Identity Length */
410 /** Array of end point identity.*/
411 unsigned char id[MAX_IDENTITY_SIZE];
415 * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
416 * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
421 OCTransportAdapter adapter;
423 /** transport modifiers.*/
424 OCTransportFlags flags;
429 /** address for all adapters.*/
430 char addr[MAX_ADDR_STR_SIZE];
432 /** usually zero for default interface.*/
434 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
435 char routeData[MAX_ADDR_STR_SIZE]; //destination GatewayID:ClientId
440 * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
441 * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
442 * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
445 * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
449 /** use when defaults are ok. */
452 /** IPv4 and IPv6, including 6LoWPAN.*/
453 CT_ADAPTER_IP = (1 << 16),
455 /** GATT over Bluetooth LE.*/
456 CT_ADAPTER_GATT_BTLE = (1 << 17),
458 /** RFCOMM over Bluetooth EDR.*/
459 CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
462 /** Remote Access over XMPP.*/
463 CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
468 CT_ADAPTER_TCP = (1 << 20),
471 /** Insecure transport is the default (subject to change).*/
473 /** secure the transport path.*/
474 CT_FLAG_SECURE = (1 << 4),
476 /** IPv4 & IPv6 autoselection is the default.*/
478 /** IP adapter only.*/
479 CT_IP_USE_V6 = (1 << 5),
481 /** IP adapter only.*/
482 CT_IP_USE_V4 = (1 << 6),
484 /** Link-Local multicast is the default multicast scope for IPv6.
485 * These are placed here to correspond to the IPv6 address bits.*/
487 /** IPv6 Interface-Local scope(loopback).*/
488 CT_SCOPE_INTERFACE = 0x1,
490 /** IPv6 Link-Local scope (default).*/
493 /** IPv6 Realm-Local scope.*/
494 CT_SCOPE_REALM = 0x3,
496 /** IPv6 Admin-Local scope.*/
497 CT_SCOPE_ADMIN = 0x4,
499 /** IPv6 Site-Local scope.*/
502 /** IPv6 Organization-Local scope.*/
505 /** IPv6 Global scope.*/
506 CT_SCOPE_GLOBAL = 0xE,
507 } OCConnectivityType;
509 /** bit shift required for connectivity adapter.*/
510 #define CT_ADAPTER_SHIFT 16
513 #define CT_MASK_FLAGS 0xFFFF
516 #define CT_MASK_ADAPTER 0xFFFF0000
519 * OCDoResource methods to dispatch the request
523 OC_REST_NOMETHOD = 0,
526 OC_REST_GET = (1 << 0),
529 OC_REST_PUT = (1 << 1),
532 OC_REST_POST = (1 << 2),
535 OC_REST_DELETE = (1 << 3),
537 /** Register observe request for most up date notifications ONLY.*/
538 OC_REST_OBSERVE = (1 << 4),
540 /** Register observe request for all notifications, including stale notifications.*/
541 OC_REST_OBSERVE_ALL = (1 << 5),
543 /** De-register observation, intended for internal use.*/
544 OC_REST_CANCEL_OBSERVE = (1 << 6),
547 /** Subscribe for all presence notifications of a particular resource.*/
548 OC_REST_PRESENCE = (1 << 7),
551 /** Allows OCDoResource caller to do discovery.*/
552 OC_REST_DISCOVER = (1 << 8)
556 * Formats for payload encoding.
562 OC_FORMAT_UNSUPPORTED,
566 * Host Mode of Operation.
573 OC_GATEWAY /**< Client server mode along with routing capabilities.*/
577 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
578 * protocol. The precise definitions of each quality of service level depend on the
579 * implementation. In descriptions below are for the current implementation and may changed
584 /** Packet delivery is best effort.*/
587 /** Packet delivery is best effort.*/
590 /** Acknowledgments are used to confirm delivery.*/
593 /** No Quality is defined, let the stack decide.*/
595 } OCQualityOfService;
598 * Resource Properties.
599 * The value of a policy property is defined as bitmap.
600 * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
601 * Not including the policy property is equivalent to zero.
606 /** When none of the bits are set, the resource is non-discoverable &
607 * non-observable by the client.*/
608 OC_RES_PROP_NONE = (0),
610 /** When this bit is set, the resource is allowed to be discovered by clients.*/
611 OC_DISCOVERABLE = (1 << 0),
613 /** When this bit is set, the resource is allowed to be observed by clients.*/
614 OC_OBSERVABLE = (1 << 1),
616 /** When this bit is set, the resource is initialized, otherwise the resource
617 * is 'inactive'. 'inactive' signifies that the resource has been marked for
618 * deletion or is already deleted.*/
619 OC_ACTIVE = (1 << 2),
621 /** When this bit is set, the resource has been marked as 'slow'.
622 * 'slow' signifies that responses from this resource can expect delays in
623 * processing its requests from clients.*/
626 /** When this bit is set, the resource is a secure resource.*/
627 OC_SECURE = (1 << 4),
629 /** When this bit is set, the resource is allowed to be discovered only
630 * if discovery request contains an explicit querystring.
631 * Ex: GET /oic/res?rt=oic.sec.acl */
632 OC_EXPLICIT_DISCOVERABLE = (1 << 5)
633 } OCResourceProperty;
636 * Transport Protocol IDs.
640 /** For invalid ID.*/
641 OC_INVALID_ID = (1 << 0),
644 OC_COAP_ID = (1 << 1)
645 } OCTransportProtocolID;
648 * Declares Stack Results & Errors.
652 /** Success status code - START HERE.*/
654 OC_STACK_RESOURCE_CREATED,
655 OC_STACK_RESOURCE_DELETED,
657 /** Success status code - END HERE.*/
659 /** Error status code - START HERE.*/
660 OC_STACK_INVALID_URI = 20,
661 OC_STACK_INVALID_QUERY,
663 OC_STACK_INVALID_PORT,
664 OC_STACK_INVALID_CALLBACK,
665 OC_STACK_INVALID_METHOD,
667 /** Invalid parameter.*/
668 OC_STACK_INVALID_PARAM,
669 OC_STACK_INVALID_OBSERVE_PARAM,
673 OC_STACK_ADAPTER_NOT_ENABLED,
676 /** Resource not found.*/
677 OC_STACK_NO_RESOURCE,
679 /** e.g: not supported method or interface.*/
680 OC_STACK_RESOURCE_ERROR,
681 OC_STACK_SLOW_RESOURCE,
682 OC_STACK_DUPLICATE_REQUEST,
684 /** Resource has no registered observers.*/
685 OC_STACK_NO_OBSERVERS,
686 OC_STACK_OBSERVER_NOT_FOUND,
687 OC_STACK_VIRTUAL_DO_NOT_HANDLE,
688 OC_STACK_INVALID_OPTION,
690 /** The remote reply contained malformed data.*/
691 OC_STACK_MALFORMED_RESPONSE,
692 OC_STACK_PERSISTENT_BUFFER_REQUIRED,
693 OC_STACK_INVALID_REQUEST_HANDLE,
694 OC_STACK_INVALID_DEVICE_INFO,
695 OC_STACK_INVALID_JSON,
697 /** Request is not authorized by Resource Server. */
698 OC_STACK_UNAUTHORIZED_REQ,
700 /** Error code from PDM */
701 OC_STACK_PDM_IS_NOT_INITIALIZED,
702 OC_STACK_DUPLICATE_UUID,
703 OC_STACK_INCONSISTENT_DB,
705 /** Insert all new error codes here!.*/
707 OC_STACK_PRESENCE_STOPPED = 128,
708 OC_STACK_PRESENCE_TIMEOUT,
709 OC_STACK_PRESENCE_DO_NOT_HANDLE,
711 /** ERROR in stack.*/
713 /** Error status code - END HERE.*/
717 * Handle to an OCDoResource invocation.
719 typedef void * OCDoHandle;
722 * Handle to an OCResource object owned by the OCStack.
724 typedef void * OCResourceHandle;
727 * Handle to an OCRequest object owned by the OCStack.
729 typedef void * OCRequestHandle;
732 * Unique identifier for each observation request. Used when observations are
733 * registered or de-registered. Used by entity handler to signal specific
734 * observers to be notified of resource changes.
735 * There can be maximum of 256 observations per server.
737 typedef uint8_t OCObservationId;
740 * Action associated with observation.
745 OC_OBSERVE_REGISTER = 0,
747 /** To Deregister. */
748 OC_OBSERVE_DEREGISTER = 1,
751 OC_OBSERVE_NO_OPTION = 2
756 * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
757 * when it calls OCRegisterPersistentStorageHandler.
758 * Persistent storage open handler points to default file path.
759 * Application can point to appropriate SVR database path for it's IoTivity Server.
762 /** Persistent storage file path.*/
763 FILE* (* open)(const char *path, const char *mode);
765 /** Persistent storage read handler.*/
766 size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
768 /** Persistent storage write handler.*/
769 size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
771 /** Persistent storage close handler.*/
772 int (* close)(FILE *fp);
774 /** Persistent storage unlink handler.*/
775 int (* unlink)(const char *path);
776 } OCPersistentStorage;
779 * Possible returned values from entity handler.
783 /** Action associated with observation request.*/
784 OCObserveAction action;
786 /** Identifier for observation being registered/deregistered.*/
787 OCObservationId obsId;
791 * Possible returned values from entity handler.
797 OC_EH_RESOURCE_CREATED,
798 OC_EH_RESOURCE_DELETED,
801 OC_EH_RESOURCE_NOT_FOUND
802 } OCEntityHandlerResult;
805 * This structure will be used to define the vendor specific header options to be included
806 * in communication packets.
808 typedef struct OCHeaderOption
810 /** The protocol ID this option applies to.*/
811 OCTransportProtocolID protocolID;
813 /** The header option ID which will be added to communication packets.*/
816 /** its length 191.*/
817 uint16_t optionLength;
819 /** pointer to its data.*/
820 uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
822 #ifdef SUPPORTS_DEFAULT_CTOR
823 OCHeaderOption() = default;
824 OCHeaderOption(OCTransportProtocolID pid,
827 const uint8_t* optData)
833 // parameter includes the null terminator.
834 optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
835 optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
836 memcpy(optionData, optData, optionLength);
837 optionData[optionLength - 1] = '\0';
844 * This structure describes the platform properties. All non-Null properties will be
845 * included in a platform discovery request.
852 /** Manufacturer name.*/
853 char *manufacturerName;
855 /** Manufacturer URL for platform property.*/
856 char *manufacturerUrl;
861 /** Manufacturer date.*/
862 char *dateOfManufacture;
864 /** Platform version.*/
865 char *platformVersion;
867 /** Operating system version.*/
868 char *operatingSystemVersion;
871 char *hardwareVersion;
874 char *firmwareVersion;
876 /** Platform support URL.*/
885 * This structure is expected as input for device properties.
886 * device name is mandatory and expected from the application.
887 * device id of type UUID will be generated by the stack.
891 /** Pointer to the device name.*/
898 * callback for bound JID
900 typedef void (*jid_bound_cb)(char *jid);
903 * CA Remote Access information for XMPP Client
908 char *hostname; /**< XMPP server hostname */
909 uint16_t port; /**< XMPP server serivce port */
910 char *xmpp_domain; /**< XMPP login domain */
911 char *username; /**< login username */
912 char *password; /**< login password */
913 char *resource; /**< specific resource for login */
914 char *user_jid; /**< specific JID for login */
915 jid_bound_cb jidbound; /**< callback when JID bound */
917 #endif /* RA_ADAPTER */
920 /** Enum to describe the type of object held by the OCPayload object.*/
923 PAYLOAD_TYPE_INVALID,
924 PAYLOAD_TYPE_DISCOVERY,
926 PAYLOAD_TYPE_PLATFORM,
927 PAYLOAD_TYPE_REPRESENTATION,
928 PAYLOAD_TYPE_SECURITY,
929 PAYLOAD_TYPE_PRESENCE,
935 // The type of message that was received
948 }OCRepPayloadPropType;
950 #define MAX_REP_ARRAY_DEPTH 3
953 OCRepPayloadPropType type;
954 size_t dimensions[MAX_REP_ARRAY_DEPTH];
962 struct OCRepPayload** objArray;
964 } OCRepPayloadValueArray;
966 typedef struct OCRepPayloadValue
969 OCRepPayloadPropType type;
976 struct OCRepPayload* obj;
977 OCRepPayloadValueArray arr;
979 struct OCRepPayloadValue* next;
983 typedef struct OCStringLL
985 struct OCStringLL *next;
989 // used for get/set/put/observe/etc representations
990 typedef struct OCRepPayload
995 OCStringLL* interfaces;
996 OCRepPayloadValue* values;
997 struct OCRepPayload* next;
1000 // used inside a discovery payload
1001 typedef struct OCResourcePayload
1006 OCStringLL* interfaces;
1010 struct OCResourcePayload* next;
1011 } OCResourcePayload;
1014 * Structure holding Links Payload. It is a sub-structure used in
1015 * OCResourceCollectionPayload.
1017 typedef struct OCLinksPayload
1019 /** This is the target relative URI. */
1021 /** Resource Type - A standard OIC specified or vendor defined resource
1022 * type of the resource referenced by the target URI. */
1024 /** Interface - The interfaces supported by the resource referenced by the target URI. */
1026 /** The relation of the target URI referenced by the link to the context URI;
1027 * The default value is null. */
1029 /** Specifies if the resource referenced by the target URIis observable or not. */
1031 /** A title for the link relation. Can be used by the UI to provide a context. */
1033 /** This is used to override the context URI e.g. override the URI of the containing collection. */
1035 /** The instance identifier for this web link in an array of web links - used in links. */
1038 /** An ordinal number that is not repeated - must be unique in the collection context. */
1040 /** Any unique string including a URI. */
1042 /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1043 OCIdentity uniqueUUID;
1045 /** A hint of the media type of the representation of the resource referenced by the target URI. */
1047 /** Holding address of the next resource. */
1048 struct OCLinksPayload *next;
1051 /** Structure holding tags value of the links payload. */
1054 /** Name of tags. */
1056 /** Device identifier. */
1058 /** The base URI where the resources are hold. */
1060 /** Bitmap holds observable, discoverable, secure option flag.*/
1062 /** Port set in case, the secure flag is set above. */
1064 /** Id for each set of links i.e. tag. */
1067 /** An ordinal number that is not repeated - must be unique in the collection context. */
1069 /** Any unique string including a URI. */
1071 /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1072 OCIdentity uniqueUUID;
1074 /** Defines the list of allowable resource types (for Target and anchors) in links included
1075 * in the collection; new links being created can only be from this list. */
1077 /** When specified this is the default relationship to use when an OIC Link does not specify
1078 * an explicit relationship with *rel* parameter. */
1080 /** Time to keep holding resource.*/
1084 /** Resource collection payload. */
1085 typedef struct OCResourceCollectionPayload
1087 /** Collection tags payload.*/
1088 OCTagsPayload *tags;
1089 /** Array of links payload. */
1090 OCLinksPayload *setLinks;
1091 /** Holding address of the next resource. */
1092 struct OCResourceCollectionPayload *next;
1093 } OCResourceCollectionPayload;
1098 /** This structure holds the old /oic/res response. */
1099 OCResourcePayload *resources;
1100 /** This structure holds the collection response for the /oic/res. */
1101 OCResourceCollectionPayload *collectionResources;
1102 } OCDiscoveryPayload;
1105 * Structure holding discovery payload.
1111 /** Device Identity. */
1113 /** Value holding the bias factor of the RD. */
1115 } OCRDDiscoveryPayload;
1118 * RD Payload that will be transmitted over the wire.
1123 /** Pointer to the discovery response payload.*/
1124 OCRDDiscoveryPayload *rdDiscovery;
1125 /** Pointer to the publish payload.*/
1126 OCResourceCollectionPayload *rdPublish;
1136 char* dataModelVersion;
1143 OCPlatformInfo info;
1144 } OCPlatformPayload;
1150 } OCSecurityPayload;
1151 #ifdef WITH_PRESENCE
1155 uint32_t sequenceNumber;
1157 OCPresenceTrigger trigger;
1159 } OCPresencePayload;
1163 * Incoming requests handled by the server. Requests are passed in as a parameter to the
1164 * OCEntityHandler callback API.
1165 * The OCEntityHandler callback API must be implemented in the application in order
1166 * to receive these requests.
1170 /** Associated resource.*/
1171 OCResourceHandle resource;
1173 /** Associated request handle.*/
1174 OCRequestHandle requestHandle;
1176 /** the REST method retrieved from received request PDU.*/
1179 /** description of endpoint that sent the request.*/
1182 /** resource query send by client.*/
1185 /** Information associated with observation - valid only when OCEntityHandler flag includes
1186 * ::OC_OBSERVE_FLAG.*/
1187 OCObservationInfo obsInfo;
1189 /** Number of the received vendor specific header options.*/
1190 uint8_t numRcvdVendorSpecificHeaderOptions;
1192 /** Pointer to the array of the received vendor specific header options.*/
1193 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1195 /** the payload from the request PDU.*/
1198 } OCEntityHandlerRequest;
1202 * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1206 /** Address of remote server.*/
1209 /** backward compatibility (points to devAddr).*/
1212 /** backward compatibility.*/
1213 OCConnectivityType connType;
1215 /** the security identity of the remote server.*/
1216 OCIdentity identity;
1218 /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1219 OCStackResult result;
1221 /** If associated with observe, this will represent the sequence of notifications from server.*/
1222 uint32_t sequenceNumber;
1225 const char * resourceUri;
1227 /** the payload for the response PDU.*/
1230 /** Number of the received vendor specific header options.*/
1231 uint8_t numRcvdVendorSpecificHeaderOptions;
1233 /** An array of the received vendor specific header options.*/
1234 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1238 * Request handle is passed to server via the entity handler for each incoming request.
1239 * Stack assigns when request is received, server sets to indicate what request response is for.
1243 /** Request handle.*/
1244 OCRequestHandle requestHandle;
1246 /** Resource handle.*/
1247 OCResourceHandle resourceHandle;
1249 /** Allow the entity handler to pass a result with the response.*/
1250 OCEntityHandlerResult ehResult;
1252 /** This is the pointer to server payload data to be transferred.*/
1255 /** number of the vendor specific header options .*/
1256 uint8_t numSendVendorSpecificHeaderOptions;
1258 /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1259 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1261 /** URI of new resource that entity handler might create.*/
1262 char resourceUri[MAX_URI_LENGTH];
1264 /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1265 uint8_t persistentBufferFlag;
1266 } OCEntityHandlerResponse;
1273 /** Request state.*/
1274 OC_REQUEST_FLAG = (1 << 1),
1275 /** Observe state.*/
1276 OC_OBSERVE_FLAG = (1 << 2)
1277 } OCEntityHandlerFlag;
1280 * Possible returned values from client application.
1284 OC_STACK_DELETE_TRANSACTION = 0,
1285 OC_STACK_KEEP_TRANSACTION
1286 } OCStackApplicationResult;
1290 * -------------------------------------------------------------------------------------------
1291 * Callback function definitions
1292 * -------------------------------------------------------------------------------------------
1296 * Client applications implement this callback to consume responses received from Servers.
1298 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1299 OCClientResponse * clientResponse);
1302 * Client applications using a context pointer implement this callback to delete the
1303 * context upon removal of the callback/context pointer from the internal callback-list.
1305 typedef void (* OCClientContextDeleter)(void *context);
1308 * This info is passed from application to OC Stack when initiating a request to Server.
1310 typedef struct OCCallbackData
1312 /** Pointer to the context.*/
1315 /** The pointer to a function the stack will call to handle the requests.*/
1316 OCClientResponseHandler cb;
1318 /** A pointer to a function to delete the context when this callback is removed.*/
1319 OCClientContextDeleter cd;
1321 #ifdef SUPPORTS_DEFAULT_CTOR
1322 OCCallbackData() = default;
1323 OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1324 :context(ctx), cb(callback), cd(deleter){}
1329 * Application server implementations must implement this callback to consume requests OTA.
1330 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1332 typedef OCEntityHandlerResult (*OCEntityHandler)
1333 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1336 * Device Entity handler need to use this call back instead of OCEntityHandler.
1338 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1339 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1343 #endif // __cplusplus
1345 #endif /* OCTYPES_H_ */