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"
83 /** Presence URI through which the OCF devices advertise their device presence.*/
84 #define OCF_RSRVD_DEVICE_PRESENCE_URI "/.well-known/ocf/prs"
87 /** Sets the default time to live (TTL) for presence.*/
88 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
90 /** For multicast Discovery mechanism.*/
91 #define OC_MULTICAST_DISCOVERY_URI "/oic/res"
93 /** Separator for multiple query string.*/
94 #define OC_QUERY_SEPARATOR "&;"
97 * OC_DEFAULT_PRESENCE_TTL_SECONDS sets the default time to live (TTL) for presence.
99 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
102 * OC_MAX_PRESENCE_TTL_SECONDS sets the maximum time to live (TTL) for presence.
103 * NOTE: Changing the setting to a longer duration may lead to unsupported and untested
105 * 60 sec/min * 60 min/hr * 24 hr/day
107 #define OC_MAX_PRESENCE_TTL_SECONDS (60 * 60 * 24)
111 * Presence "Announcement Triggers".
115 #define OC_RSRVD_TRIGGER_CREATE "create"
118 #define OC_RSRVD_TRIGGER_CHANGE "change"
121 #define OC_RSRVD_TRIGGER_DELETE "delete"
124 * Attributes used to form a proper OIC conforming JSON message.
127 #define OC_RSRVD_OC "oic"
131 #define OC_RSRVD_PAYLOAD "payload"
133 /** To represent href */
134 #define OC_RSRVD_HREF "href"
136 /** To represent property*/
137 #define OC_RSRVD_PROPERTY "prop"
139 /** For representation.*/
140 #define OC_RSRVD_REPRESENTATION "rep"
142 /** To represent content type.*/
143 #define OC_RSRVD_CONTENT_TYPE "ct"
145 /** To represent resource type.*/
146 #define OC_RSRVD_RESOURCE_TYPE "rt"
148 /** To represent resource type with presence.*/
149 #define OC_RSRVD_RESOURCE_TYPE_PRESENCE "oic.wk.ad"
151 /** To represent resource type with device.*/
152 #define OC_RSRVD_RESOURCE_TYPE_DEVICE "oic.wk.d"
154 /** To represent resource type with platform.*/
155 #define OC_RSRVD_RESOURCE_TYPE_PLATFORM "oic.wk.p"
157 /** To represent resource type with RES.*/
158 #define OC_RSRVD_RESOURCE_TYPE_RES "oic.wk.res"
161 /** To represent content type with MQ Broker.*/
162 #define OC_RSRVD_RESOURCE_TYPE_MQ_BROKER "ocf.wk.ps"
164 /** To represent content type with MQ Topic.*/
165 #define OC_RSRVD_RESOURCE_TYPE_MQ_TOPIC "ocf.wk.ps.topic"
168 /** To represent interface.*/
169 #define OC_RSRVD_INTERFACE "if"
171 /** To indicate how long RD should publish this item.*/
172 #define OC_RSRVD_DEVICE_TTL "lt"
174 /** To represent time to live.*/
175 #define OC_RSRVD_TTL "ttl"
177 /** To represent non*/
178 #define OC_RSRVD_NONCE "non"
180 /** To represent trigger type.*/
181 #define OC_RSRVD_TRIGGER "trg"
183 /** To represent links.*/
184 #define OC_RSRVD_LINKS "links"
186 /** To represent default interface.*/
187 #define OC_RSRVD_INTERFACE_DEFAULT "oic.if.baseline"
189 /** To represent read-only interface.*/
190 #define OC_RSRVD_INTERFACE_READ "oic.if.r"
192 /** To represent ll interface.*/
193 #define OC_RSRVD_INTERFACE_LL "oic.if.ll"
195 /** To represent batch interface.*/
196 #define OC_RSRVD_INTERFACE_BATCH "oic.if.b"
198 /** To represent interface group.*/
199 #define OC_RSRVD_INTERFACE_GROUP "oic.mi.grp"
201 /** To represent MFG date.*/
202 #define OC_RSRVD_MFG_DATE "mndt"
204 /** To represent FW version.*/
205 #define OC_RSRVD_FW_VERSION "mnfv"
207 /** To represent host name.*/
208 #define OC_RSRVD_HOST_NAME "hn"
210 /** To represent policy.*/
211 #define OC_RSRVD_POLICY "p"
213 /** To represent bitmap.*/
214 #define OC_RSRVD_BITMAP "bm"
217 #define OC_RSRVD_SECURE "sec"
220 #define OC_RSRVD_HOSTING_PORT "port"
223 #define OC_RSRVD_TCP_PORT "x.org.iotivity.tcp"
225 /** For Server instance ID.*/
226 #define OC_RSRVD_SERVER_INSTANCE_ID "sid"
233 #define OC_RSRVD_PLATFORM_ID "pi"
235 /** Platform MFG NAME. */
236 #define OC_RSRVD_MFG_NAME "mnmn"
239 #define OC_RSRVD_MFG_URL "mnml"
242 #define OC_RSRVD_MODEL_NUM "mnmo"
244 /** Platform MFG Date.*/
245 #define OC_RSRVD_MFG_DATE "mndt"
247 /** Platform versio.n */
248 #define OC_RSRVD_PLATFORM_VERSION "mnpv"
250 /** Platform Operating system version. */
251 #define OC_RSRVD_OS_VERSION "mnos"
253 /** Platform Hardware version. */
254 #define OC_RSRVD_HARDWARE_VERSION "mnhw"
256 /**Platform Firmware version. */
257 #define OC_RSRVD_FIRMWARE_VERSION "mnfv"
259 /** Support URL for the platform. */
260 #define OC_RSRVD_SUPPORT_URL "mnsl"
262 /** System time for the platform. */
263 #define OC_RSRVD_SYSTEM_TIME "st"
270 #define OC_RSRVD_DEVICE_ID "di"
273 #define OC_RSRVD_DEVICE_NAME "n"
275 /** Device specification version.*/
276 #define OC_RSRVD_SPEC_VERSION "icv"
278 /** Device data model.*/
279 #define OC_RSRVD_DATA_MODEL_VERSION "dmv"
281 /** Device specification version.*/
282 #define OC_SPEC_VERSION "core.1.0.0"
284 /** Device Data Model version.*/
285 #define OC_DATA_MODEL_VERSION "res.1.0.0"
288 * These provide backward compatibility - their use is deprecated.
292 /** Multicast Prefix.*/
293 #define OC_MULTICAST_PREFIX "224.0.1.187:5683"
295 /** Multicast IP address.*/
296 #define OC_MULTICAST_IP "224.0.1.187"
298 /** Multicast Port.*/
299 #define OC_MULTICAST_PORT 5683
302 /** Max Device address size. */
304 #define MAX_ADDR_STR_SIZE (256)
306 /** Max Address could be
307 * "coaps+tcp://[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:yyy.yyy.yyy.yyy]:xxxxx"
308 * +1 for null terminator.
310 #define MAX_ADDR_STR_SIZE (66)
313 /** Length of MAC address */
314 #define MAC_ADDR_STR_SIZE (17)
316 /** Blocks of MAC address */
317 #define MAC_ADDR_BLOCKS (6)
319 /** Max identity size. */
320 #define MAX_IDENTITY_SIZE (37)
322 /** Universal unique identity size. */
323 #define UUID_IDENTITY_SIZE (128/8)
325 /** Resource Directory */
327 /** Resource Directory URI used to Discover RD and Publish resources.*/
328 #define OC_RSRVD_RD_URI "/oic/rd"
330 /** To represent resource type with rd.*/
331 #define OC_RSRVD_RESOURCE_TYPE_RD "oic.wk.rd"
333 /** RD Discovery bias factor type. */
334 #define OC_RSRVD_RD_DISCOVERY_SEL "sel"
337 #define OC_RSRVD_BASE_URI "baseURI"
339 /** Unique value per collection/link. */
340 #define OC_RSRVD_INS "ins"
342 /** Allowable resource types in the links. */
343 #define OC_RSRVD_RTS "rts"
345 /** Default relationship. */
346 #define OC_RSRVD_DREL "drel"
348 /** Defines relationship between links. */
349 #define OC_RSRVD_REL "rel"
351 /** Defines title. */
352 #define OC_RSRVD_TITLE "title"
355 #define OC_RSRVD_URI "anchor"
357 /** Defines media type. */
358 #define OC_RSRVD_MEDIA_TYPE "type"
360 /** To represent resource type with Publish RD.*/
361 #define OC_RSRVD_RESOURCE_TYPE_RDPUBLISH "oic.wk.rdpub"
366 #define OC_RSRVD_ACCOUNT_URI "/.well-known/ocf/account"
368 /** Account session URI.*/
369 #define OC_RSRVD_ACCOUNT_SESSION_URI "/.well-known/ocf/account/session"
371 /** Account token refresh URI.*/
372 #define OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI "/.well-known/ocf/account/tokenrefresh"
374 /** Defines auth provider. */
375 #define OC_RSRVD_AUTHPROVIDER "authprovider"
377 /** Defines auth code. */
378 #define OC_RSRVD_AUTHCODE "authcode"
380 /** Defines session. */
381 #define OC_RSRVD_ACCESS_TOKEN "accesstoken"
383 /** Defines status. */
384 #define OC_RSRVD_LOGIN "login"
386 /** Defines grant type. */
387 #define OC_RSRVD_GRANT_TYPE "granttype"
389 /** Defines refresh token. */
390 #define OC_RSRVD_REFRESH_TOKEN "refreshtoken"
392 /** Defines user ID. */
393 #define OC_RSRVD_USER_ID "uid"
395 /** Defines options. */
396 #define OC_RSRVD_OPTIONS "options"
398 /** To represent grant type with refresh token. */
399 #define OC_RSRVD_GRANT_TYPE_REFRESH_TOKEN "refresh_token"
402 * Mark a parameter as unused. Used to prevent unused variable compiler warnings.
403 * Used in three cases:
404 * 1. in callbacks when one of the parameters are unused
405 * 2. when due to code changes a functions parameter is no longer
406 * used but must be left in place for backward compatibility
408 * 3. a variable is only used in the debug build variant and would
409 * give a build warning in release mode.
411 #define OC_UNUSED(x) (void)(x)
414 * These enums (OCTransportAdapter and OCTransportFlags) must
415 * be kept synchronized with OCConnectivityType (below) as well as
416 * CATransportAdapter and CATransportFlags (in CACommon.h).
420 /** value zero indicates discovery.*/
421 OC_DEFAULT_ADAPTER = 0,
423 /** IPv4 and IPv6, including 6LoWPAN.*/
424 OC_ADAPTER_IP = (1 << 0),
426 /** GATT over Bluetooth LE.*/
427 OC_ADAPTER_GATT_BTLE = (1 << 1),
429 /** RFCOMM over Bluetooth EDR.*/
430 OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
432 /**Remote Access over XMPP.*/
433 OC_ADAPTER_REMOTE_ACCESS = (1 << 3),
436 OC_ADAPTER_TCP = (1 << 4),
438 /** NFC Transport for Messaging.*/
439 OC_ADAPTER_NFC = (1 << 5)
440 } OCTransportAdapter;
443 * Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
447 /** default flag is 0*/
448 OC_DEFAULT_FLAGS = 0,
450 /** Insecure transport is the default (subject to change).*/
451 /** secure the transport path*/
452 OC_FLAG_SECURE = (1 << 4),
454 /** IPv4 & IPv6 auto-selection is the default.*/
455 /** IP & TCP adapter only.*/
456 OC_IP_USE_V6 = (1 << 5),
458 /** IP & TCP adapter only.*/
459 OC_IP_USE_V4 = (1 << 6),
461 /** Multicast only.*/
462 OC_MULTICAST = (1 << 7),
464 /** Link-Local multicast is the default multicast scope for IPv6.
465 * These are placed here to correspond to the IPv6 multicast address bits.*/
467 /** IPv6 Interface-Local scope (loopback).*/
468 OC_SCOPE_INTERFACE = 0x1,
470 /** IPv6 Link-Local scope (default).*/
473 /** IPv6 Realm-Local scope. */
474 OC_SCOPE_REALM = 0x3,
476 /** IPv6 Admin-Local scope. */
477 OC_SCOPE_ADMIN = 0x4,
479 /** IPv6 Site-Local scope. */
482 /** IPv6 Organization-Local scope. */
485 /**IPv6 Global scope. */
486 OC_SCOPE_GLOBAL = 0xE,
490 /** Bit mask for scope.*/
491 #define OC_MASK_SCOPE (0x000F)
493 /** Bit mask for Mods.*/
494 #define OC_MASK_MODS (0x0FF0)
495 #define OC_MASK_FAMS (OC_IP_USE_V6|OC_IP_USE_V4)
497 typedef struct OCStringLL
499 struct OCStringLL *next;
504 * End point identity.
508 /** Identity Length */
511 /** Array of end point identity.*/
512 unsigned char id[MAX_IDENTITY_SIZE];
516 * Universally unique identifier.
520 /** identitifier string.*/
521 unsigned char id[UUID_IDENTITY_SIZE];
525 * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
526 * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
531 OCTransportAdapter adapter;
533 /** transport modifiers.*/
534 OCTransportFlags flags;
539 /** address for all adapters.*/
540 char addr[MAX_ADDR_STR_SIZE];
542 /** usually zero for default interface.*/
544 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
545 char routeData[MAX_ADDR_STR_SIZE]; //destination GatewayID:ClientId
550 * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
551 * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
552 * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
555 * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
559 /** use when defaults are ok. */
562 /** IPv4 and IPv6, including 6LoWPAN.*/
563 CT_ADAPTER_IP = (1 << 16),
565 /** GATT over Bluetooth LE.*/
566 CT_ADAPTER_GATT_BTLE = (1 << 17),
568 /** RFCOMM over Bluetooth EDR.*/
569 CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
572 /** Remote Access over XMPP.*/
573 CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
576 CT_ADAPTER_TCP = (1 << 20),
579 CT_ADAPTER_NFC = (1 << 21),
581 /** Insecure transport is the default (subject to change).*/
583 /** secure the transport path.*/
584 CT_FLAG_SECURE = (1 << 4),
586 /** IPv4 & IPv6 autoselection is the default.*/
588 /** IP adapter only.*/
589 CT_IP_USE_V6 = (1 << 5),
591 /** IP adapter only.*/
592 CT_IP_USE_V4 = (1 << 6),
594 /** Link-Local multicast is the default multicast scope for IPv6.
595 * These are placed here to correspond to the IPv6 address bits.*/
597 /** IPv6 Interface-Local scope(loopback).*/
598 CT_SCOPE_INTERFACE = 0x1,
600 /** IPv6 Link-Local scope (default).*/
603 /** IPv6 Realm-Local scope.*/
604 CT_SCOPE_REALM = 0x3,
606 /** IPv6 Admin-Local scope.*/
607 CT_SCOPE_ADMIN = 0x4,
609 /** IPv6 Site-Local scope.*/
612 /** IPv6 Organization-Local scope.*/
615 /** IPv6 Global scope.*/
616 CT_SCOPE_GLOBAL = 0xE,
617 } OCConnectivityType;
619 /** bit shift required for connectivity adapter.*/
620 #define CT_ADAPTER_SHIFT 16
623 #define CT_MASK_FLAGS 0xFFFF
626 #define CT_MASK_ADAPTER 0xFFFF0000
629 * OCDoResource methods to dispatch the request
633 OC_REST_NOMETHOD = 0,
636 OC_REST_GET = (1 << 0),
639 OC_REST_PUT = (1 << 1),
642 OC_REST_POST = (1 << 2),
645 OC_REST_DELETE = (1 << 3),
647 /** Register observe request for most up date notifications ONLY.*/
648 OC_REST_OBSERVE = (1 << 4),
650 /** Register observe request for all notifications, including stale notifications.*/
651 OC_REST_OBSERVE_ALL = (1 << 5),
653 /** De-register observation, intended for internal use.*/
654 OC_REST_CANCEL_OBSERVE = (1 << 6),
657 /** Subscribe for all presence notifications of a particular resource.*/
658 OC_REST_PRESENCE = (1 << 7),
661 /** Allows OCDoResource caller to do discovery.*/
662 OC_REST_DISCOVER = (1 << 8)
666 * Formats for payload encoding.
672 OC_FORMAT_UNSUPPORTED,
676 * Host Mode of Operation.
683 OC_GATEWAY /**< Client server mode along with routing capabilities.*/
687 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
688 * protocol. The precise definitions of each quality of service level depend on the
689 * implementation. In descriptions below are for the current implementation and may changed
694 /** Packet delivery is best effort.*/
697 /** Packet delivery is best effort.*/
700 /** Acknowledgments are used to confirm delivery.*/
703 /** No Quality is defined, let the stack decide.*/
705 } OCQualityOfService;
708 * Resource Properties.
709 * The value of a policy property is defined as bitmap.
710 * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
711 * Not including the policy property is equivalent to zero.
716 /** When none of the bits are set, the resource is non-discoverable &
717 * non-observable by the client.*/
718 OC_RES_PROP_NONE = (0),
720 /** When this bit is set, the resource is allowed to be discovered by clients.*/
721 OC_DISCOVERABLE = (1 << 0),
723 /** When this bit is set, the resource is allowed to be observed by clients.*/
724 OC_OBSERVABLE = (1 << 1),
726 /** When this bit is set, the resource is initialized, otherwise the resource
727 * is 'inactive'. 'inactive' signifies that the resource has been marked for
728 * deletion or is already deleted.*/
729 OC_ACTIVE = (1 << 2),
731 /** When this bit is set, the resource has been marked as 'slow'.
732 * 'slow' signifies that responses from this resource can expect delays in
733 * processing its requests from clients.*/
737 /** When this bit is set, the resource is a secure resource.*/
738 OC_SECURE = (1 << 4),
743 /** When this bit is set, the resource is allowed to be discovered only
744 * if discovery request contains an explicit querystring.
745 * Ex: GET /oic/res?rt=oic.sec.acl */
746 OC_EXPLICIT_DISCOVERABLE = (1 << 5)
749 /** When this bit is set, the resource is allowed to be published */
750 ,OC_MQ_PUBLISHER = (1 << 6)
754 /** When this bit is set, the resource is allowed to be notified as MQ broker.*/
755 ,OC_MQ_BROKER = (1 << 7)
757 } OCResourceProperty;
760 * Transport Protocol IDs.
764 /** For invalid ID.*/
765 OC_INVALID_ID = (1 << 0),
768 OC_COAP_ID = (1 << 1)
769 } OCTransportProtocolID;
772 * Declares Stack Results & Errors.
776 /** Success status code - START HERE.*/
778 OC_STACK_RESOURCE_CREATED,
779 OC_STACK_RESOURCE_DELETED,
781 OC_STACK_RESOURCE_CHANGED,
782 /** Success status code - END HERE.*/
784 /** Error status code - START HERE.*/
785 OC_STACK_INVALID_URI = 20,
786 OC_STACK_INVALID_QUERY,
788 OC_STACK_INVALID_PORT,
789 OC_STACK_INVALID_CALLBACK,
790 OC_STACK_INVALID_METHOD,
792 /** Invalid parameter.*/
793 OC_STACK_INVALID_PARAM,
794 OC_STACK_INVALID_OBSERVE_PARAM,
798 OC_STACK_ADAPTER_NOT_ENABLED,
801 /** Resource not found.*/
802 OC_STACK_NO_RESOURCE,
804 /** e.g: not supported method or interface.*/
805 OC_STACK_RESOURCE_ERROR,
806 OC_STACK_SLOW_RESOURCE,
807 OC_STACK_DUPLICATE_REQUEST,
809 /** Resource has no registered observers.*/
810 OC_STACK_NO_OBSERVERS,
811 OC_STACK_OBSERVER_NOT_FOUND,
812 OC_STACK_VIRTUAL_DO_NOT_HANDLE,
813 OC_STACK_INVALID_OPTION,
815 /** The remote reply contained malformed data.*/
816 OC_STACK_MALFORMED_RESPONSE,
817 OC_STACK_PERSISTENT_BUFFER_REQUIRED,
818 OC_STACK_INVALID_REQUEST_HANDLE,
819 OC_STACK_INVALID_DEVICE_INFO,
820 OC_STACK_INVALID_JSON,
822 /** Request is not authorized by Resource Server. */
823 OC_STACK_UNAUTHORIZED_REQ,
824 OC_STACK_TOO_LARGE_REQ,
826 /** Error code from PDM */
827 OC_STACK_PDM_IS_NOT_INITIALIZED,
828 OC_STACK_DUPLICATE_UUID,
829 OC_STACK_INCONSISTENT_DB,
832 * Error code from OTM
833 * This error is pushed from DTLS interface when handshake failure happens
835 OC_STACK_AUTHENTICATION_FAILURE,
837 /** Insert all new error codes here!.*/
839 OC_STACK_PRESENCE_STOPPED = 128,
840 OC_STACK_PRESENCE_TIMEOUT,
841 OC_STACK_PRESENCE_DO_NOT_HANDLE,
843 /** ERROR in stack.*/
845 /** Error status code - END HERE.*/
849 * Handle to an OCDoResource invocation.
851 typedef void * OCDoHandle;
854 * Handle to an OCResource object owned by the OCStack.
856 typedef void * OCResourceHandle;
859 * Handle to an OCRequest object owned by the OCStack.
861 typedef void * OCRequestHandle;
864 * Unique identifier for each observation request. Used when observations are
865 * registered or de-registered. Used by entity handler to signal specific
866 * observers to be notified of resource changes.
867 * There can be maximum of 256 observations per server.
869 typedef uint8_t OCObservationId;
872 * Action associated with observation.
877 OC_OBSERVE_REGISTER = 0,
879 /** To Deregister. */
880 OC_OBSERVE_DEREGISTER = 1,
883 OC_OBSERVE_NO_OPTION = 2,
886 OC_MQ_SUBSCRIBER = 3,
888 OC_MQ_UNSUBSCRIBER = 4,
895 * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
896 * when it calls OCRegisterPersistentStorageHandler.
897 * Persistent storage open handler points to default file path.
898 * It should check file path and whether the file is symbolic link or no.
899 * Application can point to appropriate SVR database path for it's IoTivity Server.
902 /** Persistent storage file path.*/
903 FILE* (* open)(const char *path, const char *mode);
905 /** Persistent storage read handler.*/
906 size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
908 /** Persistent storage write handler.*/
909 size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
911 /** Persistent storage close handler.*/
912 int (* close)(FILE *fp);
914 /** Persistent storage unlink handler.*/
915 int (* unlink)(const char *path);
916 } OCPersistentStorage;
919 * Possible returned values from entity handler.
923 /** Action associated with observation request.*/
924 OCObserveAction action;
926 /** Identifier for observation being registered/deregistered.*/
927 OCObservationId obsId;
931 * Possible returned values from entity handler.
937 OC_EH_RESOURCE_CREATED, // 2.01
938 OC_EH_RESOURCE_DELETED, // 2.02
940 OC_EH_FORBIDDEN, // 4.03
941 OC_EH_RESOURCE_NOT_FOUND, // 4.04
943 OC_EH_CHANGED, // 2.04
944 OC_EH_CONTENT, // 2.05
945 OC_EH_BAD_REQ, // 4.00
946 OC_EH_UNAUTHORIZED_REQ, // 4.01
947 OC_EH_BAD_OPT, // 4.02
948 OC_EH_METHOD_NOT_ALLOWED, // 4.05
949 OC_EH_NOT_ACCEPTABLE, // 4.06
950 OC_EH_INTERNAL_SERVER_ERROR, // 5.00
951 OC_EH_RETRANSMIT_TIMEOUT // 5.04
952 } OCEntityHandlerResult;
955 * This structure will be used to define the vendor specific header options to be included
956 * in communication packets.
958 typedef struct OCHeaderOption
960 /** The protocol ID this option applies to.*/
961 OCTransportProtocolID protocolID;
963 /** The header option ID which will be added to communication packets.*/
966 /** its length 191.*/
967 uint16_t optionLength;
969 /** pointer to its data.*/
970 uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
972 #ifdef SUPPORTS_DEFAULT_CTOR
973 OCHeaderOption() = default;
974 OCHeaderOption(OCTransportProtocolID pid,
977 const uint8_t* optData)
983 // parameter includes the null terminator.
984 optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
985 optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
986 memcpy(optionData, optData, optionLength);
987 optionData[optionLength - 1] = '\0';
994 * This structure describes the platform properties. All non-Null properties will be
995 * included in a platform discovery request.
1002 /** Manufacturer name.*/
1003 char *manufacturerName;
1005 /** Manufacturer URL for platform property.*/
1006 char *manufacturerUrl;
1011 /** Manufacturer date.*/
1012 char *dateOfManufacture;
1014 /** Platform version.*/
1015 char *platformVersion;
1017 /** Operating system version.*/
1018 char *operatingSystemVersion;
1021 char *hardwareVersion;
1024 char *firmwareVersion;
1026 /** Platform support URL.*/
1035 * This structure is expected as input for device properties.
1036 * device name is mandatory and expected from the application.
1037 * device id of type UUID will be generated by the stack.
1041 /** Pointer to the device name.*/
1043 /** Pointer to the types.*/
1045 /** Pointer to the device specification version.*/
1047 /** Pointer to the device data model versions (in CSV format).*/
1048 OCStringLL *dataModelVersions;
1053 * callback for bound JID
1055 typedef void (*jid_bound_cb)(char *jid);
1058 * CA Remote Access information for XMPP Client
1063 char *hostname; /**< XMPP server hostname */
1064 uint16_t port; /**< XMPP server serivce port */
1065 char *xmpp_domain; /**< XMPP login domain */
1066 char *username; /**< login username */
1067 char *password; /**< login password */
1068 char *resource; /**< specific resource for login */
1069 char *user_jid; /**< specific JID for login */
1070 jid_bound_cb jidbound; /**< callback when JID bound */
1072 #endif /* RA_ADAPTER */
1075 /** Enum to describe the type of object held by the OCPayload object.*/
1078 /** Contents of the payload are invalid */
1079 PAYLOAD_TYPE_INVALID,
1080 /** The payload is an OCDiscoveryPayload */
1081 PAYLOAD_TYPE_DISCOVERY,
1082 /** The payload is an OCDevicePayload */
1083 PAYLOAD_TYPE_DEVICE,
1084 /** The payload is an OCPlatformPayload */
1085 PAYLOAD_TYPE_PLATFORM,
1086 /** The payload is an OCRepPayload */
1087 PAYLOAD_TYPE_REPRESENTATION,
1088 /** The payload is an OCSecurityPayload */
1089 PAYLOAD_TYPE_SECURITY,
1090 /** The payload is an OCPresencePayload */
1091 PAYLOAD_TYPE_PRESENCE,
1092 /** The payload is an OCRDPayload */
1097 * A generic struct representing a payload returned from a resource operation
1099 * A pointer to OCPayLoad can be cast to a more specific struct to access members
1104 /** The type of message that was received */
1115 OCREP_PROP_BYTE_STRING,
1118 }OCRepPayloadPropType;
1120 /** This structure will be used to represent a binary string for CBOR payloads.*/
1123 /** pointer to data bytes.*/
1126 /** number of data bytes.*/
1130 #define MAX_REP_ARRAY_DEPTH 3
1133 OCRepPayloadPropType type;
1134 size_t dimensions[MAX_REP_ARRAY_DEPTH];
1143 /** pointer to ByteString array.*/
1144 OCByteString* ocByteStrArray;
1146 struct OCRepPayload** objArray;
1148 } OCRepPayloadValueArray;
1150 typedef struct OCRepPayloadValue
1153 OCRepPayloadPropType type;
1161 /** ByteString object.*/
1162 OCByteString ocByteStr;
1164 struct OCRepPayload* obj;
1165 OCRepPayloadValueArray arr;
1167 struct OCRepPayloadValue* next;
1169 } OCRepPayloadValue;
1171 // used for get/set/put/observe/etc representations
1172 typedef struct OCRepPayload
1177 OCStringLL* interfaces;
1178 OCRepPayloadValue* values;
1179 struct OCRepPayload* next;
1182 // used inside a discovery payload
1183 typedef struct OCResourcePayload
1187 OCStringLL* interfaces;
1194 struct OCResourcePayload* next;
1195 } OCResourcePayload;
1198 * Structure holding Links Payload. It is a sub-structure used in
1199 * OCResourceCollectionPayload.
1201 typedef struct OCLinksPayload
1203 /** This is the target relative URI. */
1205 /** The relation of the target URI referenced by the link to the context URI;
1206 * The default value is null. */
1208 /** Resource Type - A standard OIC specified or vendor defined resource
1209 * type of the resource referenced by the target URI. */
1211 /** Interface - The interfaces supported by the resource referenced by the target URI. */
1213 /** Bitmap - The bitmap holds observable, discoverable, secure option flag. */
1215 /** A title for the link relation. Can be used by the UI to provide a context. */
1217 /** This is used to override the context URI e.g. override the URI of the containing collection. */
1219 /** The instance identifier for this web link in an array of web links - used in links. */
1222 /** An ordinal number that is not repeated - must be unique in the collection context. */
1224 /** Any unique string including a URI. */
1226 /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1227 OCIdentity uniqueUUID;
1229 /** Time to keep holding resource.*/
1231 /** A hint of the media type of the representation of the resource referenced by the target URI. */
1233 /** Holding address of the next resource. */
1234 struct OCLinksPayload *next;
1237 /** Structure holding tags value of the links payload. */
1240 /** Name of tags. */
1242 /** Device identifier. */
1244 /** Time to keep holding resource.*/
1248 /** Resource collection payload. */
1249 typedef struct OCResourceCollectionPayload
1251 /** Collection tags payload.*/
1252 OCTagsPayload *tags;
1253 /** Array of links payload. */
1254 OCLinksPayload *setLinks;
1255 } OCResourceCollectionPayload;
1257 typedef struct OCDiscoveryPayload
1264 /** A special case for handling RD address. */
1273 /** Resource Type */
1279 /** This structure holds the old /oic/res response. */
1280 OCResourcePayload *resources;
1282 /** Holding address of the next DiscoveryPayload. */
1283 struct OCDiscoveryPayload *next;
1285 } OCDiscoveryPayload;
1288 * Structure holding discovery payload.
1294 /** Device Identity. */
1296 /** Value holding the bias factor of the RD. */
1298 } OCRDDiscoveryPayload;
1301 * RD Payload that will be transmitted over the wire.
1306 /** Pointer to the discovery response payload.*/
1307 OCRDDiscoveryPayload *rdDiscovery;
1308 /** Pointer to the publish payload.*/
1309 OCResourceCollectionPayload *rdPublish;
1318 OCStringLL *dataModelVersions;
1319 OCStringLL *interfaces;
1327 OCPlatformInfo info;
1329 OCStringLL* interfaces;
1330 } OCPlatformPayload;
1335 uint8_t* securityData;
1337 } OCSecurityPayload;
1339 #ifdef WITH_PRESENCE
1343 uint32_t sequenceNumber;
1345 OCPresenceTrigger trigger;
1347 } OCPresencePayload;
1351 * Incoming requests handled by the server. Requests are passed in as a parameter to the
1352 * OCEntityHandler callback API.
1353 * The OCEntityHandler callback API must be implemented in the application in order
1354 * to receive these requests.
1358 /** Associated resource.*/
1359 OCResourceHandle resource;
1361 /** Associated request handle.*/
1362 OCRequestHandle requestHandle;
1364 /** the REST method retrieved from received request PDU.*/
1367 /** description of endpoint that sent the request.*/
1370 /** resource query send by client.*/
1373 /** Information associated with observation - valid only when OCEntityHandler flag includes
1374 * ::OC_OBSERVE_FLAG.*/
1375 OCObservationInfo obsInfo;
1377 /** Number of the received vendor specific header options.*/
1378 uint8_t numRcvdVendorSpecificHeaderOptions;
1380 /** Pointer to the array of the received vendor specific header options.*/
1381 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1386 /** the payload from the request PDU.*/
1389 } OCEntityHandlerRequest;
1393 * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1397 /** Address of remote server.*/
1400 /** backward compatibility (points to devAddr).*/
1403 /** backward compatibility.*/
1404 OCConnectivityType connType;
1406 /** the security identity of the remote server.*/
1407 OCIdentity identity;
1409 /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1410 OCStackResult result;
1412 /** If associated with observe, this will represent the sequence of notifications from server.*/
1413 uint32_t sequenceNumber;
1416 const char * resourceUri;
1418 /** the payload for the response PDU.*/
1421 /** Number of the received vendor specific header options.*/
1422 uint8_t numRcvdVendorSpecificHeaderOptions;
1424 /** An array of the received vendor specific header options.*/
1425 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1429 * Request handle is passed to server via the entity handler for each incoming request.
1430 * Stack assigns when request is received, server sets to indicate what request response is for.
1434 /** Request handle.*/
1435 OCRequestHandle requestHandle;
1437 /** Resource handle.*/
1438 OCResourceHandle resourceHandle;
1440 /** Allow the entity handler to pass a result with the response.*/
1441 OCEntityHandlerResult ehResult;
1443 /** This is the pointer to server payload data to be transferred.*/
1446 /** number of the vendor specific header options .*/
1447 uint8_t numSendVendorSpecificHeaderOptions;
1449 /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1450 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1452 /** URI of new resource that entity handler might create.*/
1453 char resourceUri[MAX_URI_LENGTH];
1455 /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1456 uint8_t persistentBufferFlag;
1457 } OCEntityHandlerResponse;
1464 /** Request state.*/
1465 OC_REQUEST_FLAG = (1 << 1),
1466 /** Observe state.*/
1467 OC_OBSERVE_FLAG = (1 << 2)
1468 } OCEntityHandlerFlag;
1471 * Possible return values from client application callback
1473 * A client application callback returns an OCStackApplicationResult to indicate whether
1474 * the stack should continue to keep the callback registered.
1478 /** Make no more calls to the callback and call the OCClientContextDeleter for this callback */
1479 OC_STACK_DELETE_TRANSACTION = 0,
1480 /** Keep this callback registered and call it if an apropriate event occurs */
1481 OC_STACK_KEEP_TRANSACTION
1482 } OCStackApplicationResult;
1485 //#ifdef DIRECT_PAIRING
1487 * @brief direct pairing Method Type.
1489 * 1: pre-configured pin
1494 DP_NOT_ALLOWED = 0x0,
1495 DP_PRE_CONFIGURED = (0x1 << 0),
1496 DP_RANDOM_PIN = (0x1 << 1),
1500 * Device Information of discoverd direct pairing device(s).
1502 typedef struct OCDPDev
1505 OCConnectivityType connType;
1506 uint16_t securePort;
1510 OCUUIdentity deviceID;
1511 OCUUIdentity rowner;
1512 struct OCDPDev *next;
1514 //#endif // DIRECT_PAIRING
1517 * -------------------------------------------------------------------------------------------
1518 * Callback function definitions
1519 * -------------------------------------------------------------------------------------------
1523 * Client applications implement this callback to consume responses received from Servers.
1525 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1526 OCClientResponse * clientResponse);
1529 * Client applications using a context pointer implement this callback to delete the
1530 * context upon removal of the callback/context pointer from the internal callback-list.
1532 typedef void (* OCClientContextDeleter)(void *context);
1535 * This info is passed from application to OC Stack when initiating a request to Server.
1537 typedef struct OCCallbackData
1539 /** Pointer to the context.*/
1542 /** The pointer to a function the stack will call to handle the requests.*/
1543 OCClientResponseHandler cb;
1545 /** A pointer to a function to delete the context when this callback is removed.*/
1546 OCClientContextDeleter cd;
1548 #ifdef SUPPORTS_DEFAULT_CTOR
1549 OCCallbackData() = default;
1550 OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1551 :context(ctx), cb(callback), cd(deleter){}
1556 * Application server implementations must implement this callback to consume requests OTA.
1557 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1559 typedef OCEntityHandlerResult (*OCEntityHandler)
1560 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1563 * Device Entity handler need to use this call back instead of OCEntityHandler.
1565 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1566 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1568 //#ifdef DIRECT_PAIRING
1570 * Callback function definition of direct-pairing
1572 * @param[OUT] ctx - user context returned in the callback.
1573 * @param[OUT] peer - pairing device info.
1574 * @param[OUT} result - It's returned with 'OC_STACK_XXX'. It will return 'OC_STACK_OK'
1575 * if D2D pairing is success without error
1577 typedef void (*OCDirectPairingCB)(void *ctx, OCDPDev_t *peer, OCStackResult result);
1578 //#endif // DIRECT_PAIRING
1582 #endif // __cplusplus
1584 #endif /* OCTYPES_H_ */