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"
74 #define OC_RSRVD_WELL_KNOWN_MQ_URI "/.well-known/ocf/ps"
79 /** Presence URI through which the OIC devices advertise their presence.*/
80 #define OC_RSRVD_PRESENCE_URI "/oic/ad"
82 /** Presence URI through which the OCF devices advertise their device presence.*/
83 #define OCF_RSRVD_DEVICE_PRESENCE_URI "/.well-known/ocf/prs"
85 /** Sets the default time to live (TTL) for presence.*/
86 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
88 /** For multicast Discovery mechanism.*/
89 #define OC_MULTICAST_DISCOVERY_URI "/oic/res"
91 /** Separator for multiple query string.*/
92 #define OC_QUERY_SEPARATOR "&;"
95 * OC_DEFAULT_PRESENCE_TTL_SECONDS sets the default time to live (TTL) for presence.
97 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
100 * OC_MAX_PRESENCE_TTL_SECONDS sets the maximum time to live (TTL) for presence.
101 * NOTE: Changing the setting to a longer duration may lead to unsupported and untested
103 * 60 sec/min * 60 min/hr * 24 hr/day
105 #define OC_MAX_PRESENCE_TTL_SECONDS (60 * 60 * 24)
109 * Presence "Announcement Triggers".
113 #define OC_RSRVD_TRIGGER_CREATE "create"
116 #define OC_RSRVD_TRIGGER_CHANGE "change"
119 #define OC_RSRVD_TRIGGER_DELETE "delete"
122 * Attributes used to form a proper OIC conforming JSON message.
125 #define OC_RSRVD_OC "oic"
129 #define OC_RSRVD_PAYLOAD "payload"
131 /** To represent href */
132 #define OC_RSRVD_HREF "href"
134 /** To represent property*/
135 #define OC_RSRVD_PROPERTY "prop"
137 /** For representation.*/
138 #define OC_RSRVD_REPRESENTATION "rep"
140 /** To represent content type.*/
141 #define OC_RSRVD_CONTENT_TYPE "ct"
143 /** To represent resource type.*/
144 #define OC_RSRVD_RESOURCE_TYPE "rt"
146 /** To represent resource type with presence.*/
147 #define OC_RSRVD_RESOURCE_TYPE_PRESENCE "oic.wk.ad"
149 /** To represent resource type with device.*/
150 #define OC_RSRVD_RESOURCE_TYPE_DEVICE "oic.wk.d"
152 /** To represent resource type with platform.*/
153 #define OC_RSRVD_RESOURCE_TYPE_PLATFORM "oic.wk.p"
155 /** To represent resource type with RES.*/
156 #define OC_RSRVD_RESOURCE_TYPE_RES "oic.wk.res"
159 /** To represent content type with MQ Broker.*/
160 #define OC_RSRVD_RESOURCE_TYPE_MQ_BROKER "ocf.wk.ps"
162 /** To represent content type with MQ Topic.*/
163 #define OC_RSRVD_RESOURCE_TYPE_MQ_TOPIC "ocf.wk.ps.topic"
166 /** To represent interface.*/
167 #define OC_RSRVD_INTERFACE "if"
169 /** To represent time to live.*/
170 #define OC_RSRVD_TTL "ttl"
172 /** To represent non*/
173 #define OC_RSRVD_NONCE "non"
175 /** To represent trigger type.*/
176 #define OC_RSRVD_TRIGGER "trg"
178 /** To represent links.*/
179 #define OC_RSRVD_LINKS "links"
181 /** To represent default interface.*/
182 #define OC_RSRVD_INTERFACE_DEFAULT "oic.if.baseline"
184 /** To represent read-only interface.*/
185 #define OC_RSRVD_INTERFACE_READ "oic.if.r"
187 /** To represent ll interface.*/
188 #define OC_RSRVD_INTERFACE_LL "oic.if.ll"
190 /** To represent batch interface.*/
191 #define OC_RSRVD_INTERFACE_BATCH "oic.if.b"
193 /** To represent interface group.*/
194 #define OC_RSRVD_INTERFACE_GROUP "oic.mi.grp"
196 /** To represent MFG date.*/
197 #define OC_RSRVD_MFG_DATE "mndt"
199 /** To represent FW version.*/
200 #define OC_RSRVD_FW_VERSION "mnfv"
202 /** To represent host name.*/
203 #define OC_RSRVD_HOST_NAME "hn"
205 /** To represent policy.*/
206 #define OC_RSRVD_POLICY "p"
208 /** To represent bitmap.*/
209 #define OC_RSRVD_BITMAP "bm"
212 #define OC_RSRVD_SECURE "sec"
215 #define OC_RSRVD_HOSTING_PORT "port"
218 #define OC_RSRVD_TCP_PORT "tcp"
220 /** For Server instance ID.*/
221 #define OC_RSRVD_SERVER_INSTANCE_ID "sid"
228 #define OC_RSRVD_PLATFORM_ID "pi"
230 /** Platform MFG NAME. */
231 #define OC_RSRVD_MFG_NAME "mnmn"
234 #define OC_RSRVD_MFG_URL "mnml"
237 #define OC_RSRVD_MODEL_NUM "mnmo"
239 /** Platform MFG Date.*/
240 #define OC_RSRVD_MFG_DATE "mndt"
242 /** Platform versio.n */
243 #define OC_RSRVD_PLATFORM_VERSION "mnpv"
245 /** Platform Operating system version. */
246 #define OC_RSRVD_OS_VERSION "mnos"
248 /** Platform Hardware version. */
249 #define OC_RSRVD_HARDWARE_VERSION "mnhw"
251 /**Platform Firmware version. */
252 #define OC_RSRVD_FIRMWARE_VERSION "mnfv"
254 /** Support URL for the platform. */
255 #define OC_RSRVD_SUPPORT_URL "mnsl"
257 /** System time for the platform. */
258 #define OC_RSRVD_SYSTEM_TIME "st"
265 #define OC_RSRVD_DEVICE_ID "di"
268 #define OC_RSRVD_DEVICE_NAME "n"
270 /** Device specification version.*/
271 #define OC_RSRVD_SPEC_VERSION "icv"
273 /** Device data model.*/
274 #define OC_RSRVD_DATA_MODEL_VERSION "dmv"
276 /** Device specification version.*/
277 #define OC_SPEC_VERSION "core.1.0.0"
279 /** Device Data Model version.*/
280 #define OC_DATA_MODEL_VERSION "res.1.0.0"
283 * These provide backward compatibility - their use is deprecated.
287 /** Multicast Prefix.*/
288 #define OC_MULTICAST_PREFIX "224.0.1.187:5683"
290 /** Multicast IP address.*/
291 #define OC_MULTICAST_IP "224.0.1.187"
293 /** Multicast Port.*/
294 #define OC_MULTICAST_PORT 5683
297 /** Max Device address size. */
299 #define MAX_ADDR_STR_SIZE (256)
301 /** Max Address could be
302 * "coaps+tcp://[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:yyy.yyy.yyy.yyy]:xxxxx"
303 * +1 for null terminator.
305 #define MAX_ADDR_STR_SIZE (66)
308 /** Length of MAC address */
309 #define MAC_ADDR_STR_SIZE (17)
311 /** Blocks of MAC address */
312 #define MAC_ADDR_BLOCKS (6)
314 /** Max identity size. */
315 #define MAX_IDENTITY_SIZE (32)
317 /** Universal unique identity size. */
318 #define UUID_IDENTITY_SIZE (128/8)
320 /** Resource Directory */
322 /** Resource Directory URI used to Discover RD and Publish resources.*/
323 #define OC_RSRVD_RD_URI "/oic/rd"
325 /** To represent resource type with rd.*/
326 #define OC_RSRVD_RESOURCE_TYPE_RD "oic.wk.rd"
328 /** RD Discovery bias factor type. */
329 #define OC_RSRVD_RD_DISCOVERY_SEL "sel"
332 #define OC_RSRVD_BASE_URI "baseURI"
334 /** Unique value per collection/link. */
335 #define OC_RSRVD_INS "ins"
337 /** Allowable resource types in the links. */
338 #define OC_RSRVD_RTS "rts"
340 /** Default relationship. */
341 #define OC_RSRVD_DREL "drel"
343 /** Defines relationship between links. */
344 #define OC_RSRVD_REL "rel"
346 /** Defines title. */
347 #define OC_RSRVD_TITLE "title"
350 #define OC_RSRVD_URI "uri"
352 /** Defines media type. */
353 #define OC_RSRVD_MEDIA_TYPE "mt"
355 /** To represent resource type with Publish RD.*/
356 #define OC_RSRVD_RESOURCE_TYPE_RDPUBLISH "oic.wk.rdpub"
361 #define OC_RSRVD_ACCOUNT_URI "/.well-known/ocf/account"
363 /** Account session URI.*/
364 #define OC_RSRVD_ACCOUNT_SESSION_URI "/.well-known/ocf/account/session"
366 /** Account token refresh URI.*/
367 #define OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI "/.well-known/ocf/account/tokenrefresh"
369 /** Defines auth provider. */
370 #define OC_RSRVD_AUTHPROVIDER "authprovider"
372 /** Defines auth code. */
373 #define OC_RSRVD_AUTHCODE "authcode"
375 /** Defines session. */
376 #define OC_RSRVD_ACCESS_TOKEN "accesstoken"
378 /** Defines status. */
379 #define OC_RSRVD_STATUS "status"
381 /** Defines grant type. */
382 #define OC_RSRVD_GRANT_TYPE "granttype"
384 /** Defines refresh token. */
385 #define OC_RSRVD_REFRESH_TOKEN "refreshtoken"
387 /** To represent grant type with refresh token. */
388 #define OC_RSRVD_GRANT_TYPE_REFRESH_TOKEN "refresh_token"
391 * Mark a parameter as unused. Used to prevent unused variable compiler warnings.
392 * Used in three cases:
393 * 1. in callbacks when one of the parameters are unused
394 * 2. when due to code changes a functions parameter is no longer
395 * used but must be left in place for backward compatibility
397 * 3. a variable is only used in the debug build variant and would
398 * give a build warning in release mode.
400 #define OC_UNUSED(x) (void)(x)
403 * These enums (OCTransportAdapter and OCTransportFlags) must
404 * be kept synchronized with OCConnectivityType (below) as well as
405 * CATransportAdapter and CATransportFlags (in CACommon.h).
409 /** value zero indicates discovery.*/
410 OC_DEFAULT_ADAPTER = 0,
412 /** IPv4 and IPv6, including 6LoWPAN.*/
413 OC_ADAPTER_IP = (1 << 0),
415 /** GATT over Bluetooth LE.*/
416 OC_ADAPTER_GATT_BTLE = (1 << 1),
418 /** RFCOMM over Bluetooth EDR.*/
419 OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
421 /**Remote Access over XMPP.*/
422 OC_ADAPTER_REMOTE_ACCESS = (1 << 3),
425 OC_ADAPTER_TCP = (1 << 4),
427 /** NFC Transport for Messaging.*/
428 OC_ADAPTER_NFC = (1 << 5)
429 } OCTransportAdapter;
432 * Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
436 /** default flag is 0*/
437 OC_DEFAULT_FLAGS = 0,
439 /** Insecure transport is the default (subject to change).*/
440 /** secure the transport path*/
441 OC_FLAG_SECURE = (1 << 4),
443 /** IPv4 & IPv6 auto-selection is the default.*/
444 /** IP & TCP adapter only.*/
445 OC_IP_USE_V6 = (1 << 5),
447 /** IP & TCP adapter only.*/
448 OC_IP_USE_V4 = (1 << 6),
450 /** Multicast only.*/
451 OC_MULTICAST = (1 << 7),
453 /** Link-Local multicast is the default multicast scope for IPv6.
454 * These are placed here to correspond to the IPv6 multicast address bits.*/
456 /** IPv6 Interface-Local scope (loopback).*/
457 OC_SCOPE_INTERFACE = 0x1,
459 /** IPv6 Link-Local scope (default).*/
462 /** IPv6 Realm-Local scope. */
463 OC_SCOPE_REALM = 0x3,
465 /** IPv6 Admin-Local scope. */
466 OC_SCOPE_ADMIN = 0x4,
468 /** IPv6 Site-Local scope. */
471 /** IPv6 Organization-Local scope. */
474 /**IPv6 Global scope. */
475 OC_SCOPE_GLOBAL = 0xE,
479 /** Bit mask for scope.*/
480 #define OC_MASK_SCOPE (0x000F)
482 /** Bit mask for Mods.*/
483 #define OC_MASK_MODS (0x0FF0)
484 #define OC_MASK_FAMS (OC_IP_USE_V6|OC_IP_USE_V4)
486 typedef struct OCStringLL
488 struct OCStringLL *next;
493 * End point identity.
497 /** Identity Length */
500 /** Array of end point identity.*/
501 unsigned char id[MAX_IDENTITY_SIZE];
505 * Universally unique identifier.
509 /** identitifier string.*/
510 unsigned char id[UUID_IDENTITY_SIZE];
514 * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
515 * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
520 OCTransportAdapter adapter;
522 /** transport modifiers.*/
523 OCTransportFlags flags;
528 /** address for all adapters.*/
529 char addr[MAX_ADDR_STR_SIZE];
531 /** usually zero for default interface.*/
533 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
534 char routeData[MAX_ADDR_STR_SIZE]; //destination GatewayID:ClientId
539 * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
540 * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
541 * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
544 * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
548 /** use when defaults are ok. */
551 /** IPv4 and IPv6, including 6LoWPAN.*/
552 CT_ADAPTER_IP = (1 << 16),
554 /** GATT over Bluetooth LE.*/
555 CT_ADAPTER_GATT_BTLE = (1 << 17),
557 /** RFCOMM over Bluetooth EDR.*/
558 CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
561 /** Remote Access over XMPP.*/
562 CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
565 CT_ADAPTER_TCP = (1 << 20),
568 CT_ADAPTER_NFC = (1 << 21),
570 /** Insecure transport is the default (subject to change).*/
572 /** secure the transport path.*/
573 CT_FLAG_SECURE = (1 << 4),
575 /** IPv4 & IPv6 autoselection is the default.*/
577 /** IP adapter only.*/
578 CT_IP_USE_V6 = (1 << 5),
580 /** IP adapter only.*/
581 CT_IP_USE_V4 = (1 << 6),
583 /** Link-Local multicast is the default multicast scope for IPv6.
584 * These are placed here to correspond to the IPv6 address bits.*/
586 /** IPv6 Interface-Local scope(loopback).*/
587 CT_SCOPE_INTERFACE = 0x1,
589 /** IPv6 Link-Local scope (default).*/
592 /** IPv6 Realm-Local scope.*/
593 CT_SCOPE_REALM = 0x3,
595 /** IPv6 Admin-Local scope.*/
596 CT_SCOPE_ADMIN = 0x4,
598 /** IPv6 Site-Local scope.*/
601 /** IPv6 Organization-Local scope.*/
604 /** IPv6 Global scope.*/
605 CT_SCOPE_GLOBAL = 0xE,
606 } OCConnectivityType;
608 /** bit shift required for connectivity adapter.*/
609 #define CT_ADAPTER_SHIFT 16
612 #define CT_MASK_FLAGS 0xFFFF
615 #define CT_MASK_ADAPTER 0xFFFF0000
618 * OCDoResource methods to dispatch the request
622 OC_REST_NOMETHOD = 0,
625 OC_REST_GET = (1 << 0),
628 OC_REST_PUT = (1 << 1),
631 OC_REST_POST = (1 << 2),
634 OC_REST_DELETE = (1 << 3),
636 /** Register observe request for most up date notifications ONLY.*/
637 OC_REST_OBSERVE = (1 << 4),
639 /** Register observe request for all notifications, including stale notifications.*/
640 OC_REST_OBSERVE_ALL = (1 << 5),
642 /** De-register observation, intended for internal use.*/
643 OC_REST_CANCEL_OBSERVE = (1 << 6),
646 /** Subscribe for all presence notifications of a particular resource.*/
647 OC_REST_PRESENCE = (1 << 7),
650 /** Allows OCDoResource caller to do discovery.*/
651 OC_REST_DISCOVER = (1 << 8)
655 * Formats for payload encoding.
661 OC_FORMAT_UNSUPPORTED,
665 * Host Mode of Operation.
672 OC_GATEWAY /**< Client server mode along with routing capabilities.*/
676 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
677 * protocol. The precise definitions of each quality of service level depend on the
678 * implementation. In descriptions below are for the current implementation and may changed
683 /** Packet delivery is best effort.*/
686 /** Packet delivery is best effort.*/
689 /** Acknowledgments are used to confirm delivery.*/
692 /** No Quality is defined, let the stack decide.*/
694 } OCQualityOfService;
697 * Resource Properties.
698 * The value of a policy property is defined as bitmap.
699 * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
700 * Not including the policy property is equivalent to zero.
705 /** When none of the bits are set, the resource is non-discoverable &
706 * non-observable by the client.*/
707 OC_RES_PROP_NONE = (0),
709 /** When this bit is set, the resource is allowed to be discovered by clients.*/
710 OC_DISCOVERABLE = (1 << 0),
712 /** When this bit is set, the resource is allowed to be observed by clients.*/
713 OC_OBSERVABLE = (1 << 1),
715 /** When this bit is set, the resource is initialized, otherwise the resource
716 * is 'inactive'. 'inactive' signifies that the resource has been marked for
717 * deletion or is already deleted.*/
718 OC_ACTIVE = (1 << 2),
720 /** When this bit is set, the resource has been marked as 'slow'.
721 * 'slow' signifies that responses from this resource can expect delays in
722 * processing its requests from clients.*/
726 /** When this bit is set, the resource is a secure resource.*/
727 OC_SECURE = (1 << 4),
732 /** When this bit is set, the resource is allowed to be discovered only
733 * if discovery request contains an explicit querystring.
734 * Ex: GET /oic/res?rt=oic.sec.acl */
735 OC_EXPLICIT_DISCOVERABLE = (1 << 5)
738 /** When this bit is set, the resource is allowed to be published */
739 ,OC_MQ_PUBLISHER = (1 << 6)
743 /** When this bit is set, the resource is allowed to be notified as MQ broker.*/
744 ,OC_MQ_BROKER = (1 << 7)
746 } OCResourceProperty;
749 * Transport Protocol IDs.
753 /** For invalid ID.*/
754 OC_INVALID_ID = (1 << 0),
757 OC_COAP_ID = (1 << 1)
758 } OCTransportProtocolID;
761 * Declares Stack Results & Errors.
765 /** Success status code - START HERE.*/
767 OC_STACK_RESOURCE_CREATED,
768 OC_STACK_RESOURCE_DELETED,
770 OC_STACK_RESOURCE_CHANGED,
771 /** Success status code - END HERE.*/
773 /** Error status code - START HERE.*/
774 OC_STACK_INVALID_URI = 20,
775 OC_STACK_INVALID_QUERY,
777 OC_STACK_INVALID_PORT,
778 OC_STACK_INVALID_CALLBACK,
779 OC_STACK_INVALID_METHOD,
781 /** Invalid parameter.*/
782 OC_STACK_INVALID_PARAM,
783 OC_STACK_INVALID_OBSERVE_PARAM,
787 OC_STACK_ADAPTER_NOT_ENABLED,
790 /** Resource not found.*/
791 OC_STACK_NO_RESOURCE,
793 /** e.g: not supported method or interface.*/
794 OC_STACK_RESOURCE_ERROR,
795 OC_STACK_SLOW_RESOURCE,
796 OC_STACK_DUPLICATE_REQUEST,
798 /** Resource has no registered observers.*/
799 OC_STACK_NO_OBSERVERS,
800 OC_STACK_OBSERVER_NOT_FOUND,
801 OC_STACK_VIRTUAL_DO_NOT_HANDLE,
802 OC_STACK_INVALID_OPTION,
804 /** The remote reply contained malformed data.*/
805 OC_STACK_MALFORMED_RESPONSE,
806 OC_STACK_PERSISTENT_BUFFER_REQUIRED,
807 OC_STACK_INVALID_REQUEST_HANDLE,
808 OC_STACK_INVALID_DEVICE_INFO,
809 OC_STACK_INVALID_JSON,
811 /** Request is not authorized by Resource Server. */
812 OC_STACK_UNAUTHORIZED_REQ,
813 OC_STACK_TOO_LARGE_REQ,
815 /** Error code from PDM */
816 OC_STACK_PDM_IS_NOT_INITIALIZED,
817 OC_STACK_DUPLICATE_UUID,
818 OC_STACK_INCONSISTENT_DB,
821 * Error code from OTM
822 * This error is pushed from DTLS interface when handshake failure happens
824 OC_STACK_AUTHENTICATION_FAILURE,
826 /** Insert all new error codes here!.*/
828 OC_STACK_PRESENCE_STOPPED = 128,
829 OC_STACK_PRESENCE_TIMEOUT,
830 OC_STACK_PRESENCE_DO_NOT_HANDLE,
832 /** ERROR in stack.*/
834 /** Error status code - END HERE.*/
838 * Handle to an OCDoResource invocation.
840 typedef void * OCDoHandle;
843 * Handle to an OCResource object owned by the OCStack.
845 typedef void * OCResourceHandle;
848 * Handle to an OCRequest object owned by the OCStack.
850 typedef void * OCRequestHandle;
853 * Unique identifier for each observation request. Used when observations are
854 * registered or de-registered. Used by entity handler to signal specific
855 * observers to be notified of resource changes.
856 * There can be maximum of 256 observations per server.
858 typedef uint8_t OCObservationId;
861 * Action associated with observation.
866 OC_OBSERVE_REGISTER = 0,
868 /** To Deregister. */
869 OC_OBSERVE_DEREGISTER = 1,
872 OC_OBSERVE_NO_OPTION = 2,
875 OC_MQ_SUBSCRIBER = 3,
877 OC_MQ_UNSUBSCRIBER = 4,
884 * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
885 * when it calls OCRegisterPersistentStorageHandler.
886 * Persistent storage open handler points to default file path.
887 * It should check file path and whether the file is symbolic link or no.
888 * Application can point to appropriate SVR database path for it's IoTivity Server.
891 /** Persistent storage file path.*/
892 FILE* (* open)(const char *path, const char *mode);
894 /** Persistent storage read handler.*/
895 size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
897 /** Persistent storage write handler.*/
898 size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
900 /** Persistent storage close handler.*/
901 int (* close)(FILE *fp);
903 /** Persistent storage unlink handler.*/
904 int (* unlink)(const char *path);
905 } OCPersistentStorage;
908 * Possible returned values from entity handler.
912 /** Action associated with observation request.*/
913 OCObserveAction action;
915 /** Identifier for observation being registered/deregistered.*/
916 OCObservationId obsId;
920 * Possible returned values from entity handler.
926 OC_EH_RESOURCE_CREATED, // 2.01
927 OC_EH_RESOURCE_DELETED, // 2.02
929 OC_EH_FORBIDDEN, // 4.03
930 OC_EH_RESOURCE_NOT_FOUND, // 4.04
932 OC_EH_CHANGED, // 2.04
933 OC_EH_CONTENT, // 2.05
934 OC_EH_BAD_REQ, // 4.00
935 OC_EH_UNAUTHORIZED_REQ, // 4.01
936 OC_EH_BAD_OPT, // 4.02
937 OC_EH_METHOD_NOT_ALLOWED, // 4.05
938 OC_EH_NOT_ACCEPTABLE, // 4.06
939 OC_EH_INTERNAL_SERVER_ERROR, // 5.00
940 OC_EH_RETRANSMIT_TIMEOUT // 5.04
941 } OCEntityHandlerResult;
944 * This structure will be used to define the vendor specific header options to be included
945 * in communication packets.
947 typedef struct OCHeaderOption
949 /** The protocol ID this option applies to.*/
950 OCTransportProtocolID protocolID;
952 /** The header option ID which will be added to communication packets.*/
955 /** its length 191.*/
956 uint16_t optionLength;
958 /** pointer to its data.*/
959 uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
961 #ifdef SUPPORTS_DEFAULT_CTOR
962 OCHeaderOption() = default;
963 OCHeaderOption(OCTransportProtocolID pid,
966 const uint8_t* optData)
972 // parameter includes the null terminator.
973 optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
974 optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
975 memcpy(optionData, optData, optionLength);
976 optionData[optionLength - 1] = '\0';
983 * This structure describes the platform properties. All non-Null properties will be
984 * included in a platform discovery request.
991 /** Manufacturer name.*/
992 char *manufacturerName;
994 /** Manufacturer URL for platform property.*/
995 char *manufacturerUrl;
1000 /** Manufacturer date.*/
1001 char *dateOfManufacture;
1003 /** Platform version.*/
1004 char *platformVersion;
1006 /** Operating system version.*/
1007 char *operatingSystemVersion;
1010 char *hardwareVersion;
1013 char *firmwareVersion;
1015 /** Platform support URL.*/
1024 * This structure is expected as input for device properties.
1025 * device name is mandatory and expected from the application.
1026 * device id of type UUID will be generated by the stack.
1030 /** Pointer to the device name.*/
1032 /** Pointer to the types.*/
1034 /** Pointer to the device specification version.*/
1036 /** Pointer to the device data model versions (in CSV format).*/
1037 OCStringLL *dataModelVersions;
1042 * callback for bound JID
1044 typedef void (*jid_bound_cb)(char *jid);
1047 * CA Remote Access information for XMPP Client
1052 char *hostname; /**< XMPP server hostname */
1053 uint16_t port; /**< XMPP server serivce port */
1054 char *xmpp_domain; /**< XMPP login domain */
1055 char *username; /**< login username */
1056 char *password; /**< login password */
1057 char *resource; /**< specific resource for login */
1058 char *user_jid; /**< specific JID for login */
1059 jid_bound_cb jidbound; /**< callback when JID bound */
1061 #endif /* RA_ADAPTER */
1064 /** Enum to describe the type of object held by the OCPayload object.*/
1067 /** Contents of the payload are invalid */
1068 PAYLOAD_TYPE_INVALID,
1069 /** The payload is an OCDiscoveryPayload */
1070 PAYLOAD_TYPE_DISCOVERY,
1071 /** The payload is an OCDevicePayload */
1072 PAYLOAD_TYPE_DEVICE,
1073 /** The payload is an OCPlatformPayload */
1074 PAYLOAD_TYPE_PLATFORM,
1075 /** The payload is an OCRepPayload */
1076 PAYLOAD_TYPE_REPRESENTATION,
1077 /** The payload is an OCSecurityPayload */
1078 PAYLOAD_TYPE_SECURITY,
1079 /** The payload is an OCPresencePayload */
1080 PAYLOAD_TYPE_PRESENCE,
1081 /** The payload is an OCRDPayload */
1086 * A generic struct representing a payload returned from a resource operation
1088 * A pointer to OCPayLoad can be cast to a more specific struct to access members
1093 /** The type of message that was received */
1104 OCREP_PROP_BYTE_STRING,
1107 }OCRepPayloadPropType;
1109 /** This structure will be used to represent a binary string for CBOR payloads.*/
1112 /** pointer to data bytes.*/
1115 /** number of data bytes.*/
1119 #define MAX_REP_ARRAY_DEPTH 3
1122 OCRepPayloadPropType type;
1123 size_t dimensions[MAX_REP_ARRAY_DEPTH];
1132 /** pointer to ByteString array.*/
1133 OCByteString* ocByteStrArray;
1135 struct OCRepPayload** objArray;
1137 } OCRepPayloadValueArray;
1139 typedef struct OCRepPayloadValue
1142 OCRepPayloadPropType type;
1150 /** ByteString object.*/
1151 OCByteString ocByteStr;
1153 struct OCRepPayload* obj;
1154 OCRepPayloadValueArray arr;
1156 struct OCRepPayloadValue* next;
1158 } OCRepPayloadValue;
1160 // used for get/set/put/observe/etc representations
1161 typedef struct OCRepPayload
1166 OCStringLL* interfaces;
1167 OCRepPayloadValue* values;
1168 struct OCRepPayload* next;
1171 // used inside a discovery payload
1172 typedef struct OCResourcePayload
1176 OCStringLL* interfaces;
1183 struct OCResourcePayload* next;
1184 } OCResourcePayload;
1187 * Structure holding Links Payload. It is a sub-structure used in
1188 * OCResourceCollectionPayload.
1190 typedef struct OCLinksPayload
1192 /** This is the target relative URI. */
1194 /** Resource Type - A standard OIC specified or vendor defined resource
1195 * type of the resource referenced by the target URI. */
1197 /** Interface - The interfaces supported by the resource referenced by the target URI. */
1199 /** The relation of the target URI referenced by the link to the context URI;
1200 * The default value is null. */
1202 /** Specifies if the resource referenced by the target URIis observable or not. */
1204 /** A title for the link relation. Can be used by the UI to provide a context. */
1206 /** This is used to override the context URI e.g. override the URI of the containing collection. */
1208 /** The instance identifier for this web link in an array of web links - used in links. */
1211 /** An ordinal number that is not repeated - must be unique in the collection context. */
1213 /** Any unique string including a URI. */
1215 /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1216 OCIdentity uniqueUUID;
1218 /** A hint of the media type of the representation of the resource referenced by the target URI. */
1220 /** Holding address of the next resource. */
1221 struct OCLinksPayload *next;
1224 /** Structure holding tags value of the links payload. */
1227 /** Name of tags. */
1229 /** Device identifier. */
1231 /** The base URI where the resources are hold. */
1233 /** Bitmap holds observable, discoverable, secure option flag.*/
1235 /** Port set in case, the secure flag is set above. */
1237 /** Id for each set of links i.e. tag. */
1240 /** An ordinal number that is not repeated - must be unique in the collection context. */
1242 /** Any unique string including a URI. */
1244 /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1245 OCIdentity uniqueUUID;
1247 /** Defines the list of allowable resource types (for Target and anchors) in links included
1248 * in the collection; new links being created can only be from this list. */
1250 /** When specified this is the default relationship to use when an OIC Link does not specify
1251 * an explicit relationship with *rel* parameter. */
1253 /** Time to keep holding resource.*/
1257 /** Resource collection payload. */
1258 typedef struct OCResourceCollectionPayload
1260 /** Collection tags payload.*/
1261 OCTagsPayload *tags;
1262 /** Array of links payload. */
1263 OCLinksPayload *setLinks;
1264 /** Holding address of the next resource. */
1265 struct OCResourceCollectionPayload *next;
1266 } OCResourceCollectionPayload;
1268 typedef struct OCDiscoveryPayload
1275 /** A special case for handling RD address. */
1284 /** Resource Type */
1290 /** This structure holds the old /oic/res response. */
1291 OCResourcePayload *resources;
1293 /** Holding address of the next DiscoveryPayload. */
1294 struct OCDiscoveryPayload *next;
1296 } OCDiscoveryPayload;
1299 * Structure holding discovery payload.
1305 /** Device Identity. */
1307 /** Value holding the bias factor of the RD. */
1309 } OCRDDiscoveryPayload;
1312 * RD Payload that will be transmitted over the wire.
1317 /** Pointer to the discovery response payload.*/
1318 OCRDDiscoveryPayload *rdDiscovery;
1319 /** Pointer to the publish payload.*/
1320 OCResourceCollectionPayload *rdPublish;
1329 OCStringLL *dataModelVersions;
1330 OCStringLL *interfaces;
1338 OCPlatformInfo info;
1340 OCStringLL* interfaces;
1341 } OCPlatformPayload;
1346 uint8_t* securityData;
1348 } OCSecurityPayload;
1350 #ifdef WITH_PRESENCE
1354 uint32_t sequenceNumber;
1356 OCPresenceTrigger trigger;
1358 } OCPresencePayload;
1362 * Incoming requests handled by the server. Requests are passed in as a parameter to the
1363 * OCEntityHandler callback API.
1364 * The OCEntityHandler callback API must be implemented in the application in order
1365 * to receive these requests.
1369 /** Associated resource.*/
1370 OCResourceHandle resource;
1372 /** Associated request handle.*/
1373 OCRequestHandle requestHandle;
1375 /** the REST method retrieved from received request PDU.*/
1378 /** description of endpoint that sent the request.*/
1381 /** resource query send by client.*/
1384 /** Information associated with observation - valid only when OCEntityHandler flag includes
1385 * ::OC_OBSERVE_FLAG.*/
1386 OCObservationInfo obsInfo;
1388 /** Number of the received vendor specific header options.*/
1389 uint8_t numRcvdVendorSpecificHeaderOptions;
1391 /** Pointer to the array of the received vendor specific header options.*/
1392 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1397 /** the payload from the request PDU.*/
1400 } OCEntityHandlerRequest;
1404 * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1408 /** Address of remote server.*/
1411 /** backward compatibility (points to devAddr).*/
1414 /** backward compatibility.*/
1415 OCConnectivityType connType;
1417 /** the security identity of the remote server.*/
1418 OCIdentity identity;
1420 /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1421 OCStackResult result;
1423 /** If associated with observe, this will represent the sequence of notifications from server.*/
1424 uint32_t sequenceNumber;
1427 const char * resourceUri;
1429 /** the payload for the response PDU.*/
1432 /** Number of the received vendor specific header options.*/
1433 uint8_t numRcvdVendorSpecificHeaderOptions;
1435 /** An array of the received vendor specific header options.*/
1436 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1440 * Request handle is passed to server via the entity handler for each incoming request.
1441 * Stack assigns when request is received, server sets to indicate what request response is for.
1445 /** Request handle.*/
1446 OCRequestHandle requestHandle;
1448 /** Resource handle.*/
1449 OCResourceHandle resourceHandle;
1451 /** Allow the entity handler to pass a result with the response.*/
1452 OCEntityHandlerResult ehResult;
1454 /** This is the pointer to server payload data to be transferred.*/
1457 /** number of the vendor specific header options .*/
1458 uint8_t numSendVendorSpecificHeaderOptions;
1460 /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1461 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1463 /** URI of new resource that entity handler might create.*/
1464 char resourceUri[MAX_URI_LENGTH];
1466 /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1467 uint8_t persistentBufferFlag;
1468 } OCEntityHandlerResponse;
1475 /** Request state.*/
1476 OC_REQUEST_FLAG = (1 << 1),
1477 /** Observe state.*/
1478 OC_OBSERVE_FLAG = (1 << 2)
1479 } OCEntityHandlerFlag;
1482 * Possible return values from client application callback
1484 * A client application callback returns an OCStackApplicationResult to indicate whether
1485 * the stack should continue to keep the callback registered.
1489 /** Make no more calls to the callback and call the OCClientContextDeleter for this callback */
1490 OC_STACK_DELETE_TRANSACTION = 0,
1491 /** Keep this callback registered and call it if an apropriate event occurs */
1492 OC_STACK_KEEP_TRANSACTION
1493 } OCStackApplicationResult;
1496 //#ifdef DIRECT_PAIRING
1498 * @brief direct pairing Method Type.
1500 * 1: pre-configured pin
1505 DP_NOT_ALLOWED = 0x0,
1506 DP_PRE_CONFIGURED = (0x1 << 0),
1507 DP_RANDOM_PIN = (0x1 << 1),
1511 * Device Information of discoverd direct pairing device(s).
1513 typedef struct OCDPDev
1516 OCConnectivityType connType;
1517 uint16_t securePort;
1521 OCUUIdentity deviceID;
1522 OCUUIdentity rowner;
1523 struct OCDPDev *next;
1525 //#endif // DIRECT_PAIRING
1528 * -------------------------------------------------------------------------------------------
1529 * Callback function definitions
1530 * -------------------------------------------------------------------------------------------
1534 * Client applications implement this callback to consume responses received from Servers.
1536 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1537 OCClientResponse * clientResponse);
1540 * Client applications using a context pointer implement this callback to delete the
1541 * context upon removal of the callback/context pointer from the internal callback-list.
1543 typedef void (* OCClientContextDeleter)(void *context);
1546 * This info is passed from application to OC Stack when initiating a request to Server.
1548 typedef struct OCCallbackData
1550 /** Pointer to the context.*/
1553 /** The pointer to a function the stack will call to handle the requests.*/
1554 OCClientResponseHandler cb;
1556 /** A pointer to a function to delete the context when this callback is removed.*/
1557 OCClientContextDeleter cd;
1559 #ifdef SUPPORTS_DEFAULT_CTOR
1560 OCCallbackData() = default;
1561 OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1562 :context(ctx), cb(callback), cd(deleter){}
1567 * Application server implementations must implement this callback to consume requests OTA.
1568 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1570 typedef OCEntityHandlerResult (*OCEntityHandler)
1571 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1574 * Device Entity handler need to use this call back instead of OCEntityHandler.
1576 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1577 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1579 //#ifdef DIRECT_PAIRING
1581 * Callback function definition of direct-pairing
1583 * @param[OUT] ctx - user context returned in the callback.
1584 * @param[OUT] peer - pairing device info.
1585 * @param[OUT} result - It's returned with 'OC_STACK_XXX'. It will return 'OC_STACK_OK'
1586 * if D2D pairing is success without error
1588 typedef void (*OCDirectPairingCB)(void *ctx, OCDPDev_t *peer, OCStackResult result);
1589 //#endif // DIRECT_PAIRING
1593 #endif // __cplusplus
1595 #endif /* OCTYPES_H_ */