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"
73 #define OC_RSRVD_WELL_KNOWN_MQ_URI "/ocf/ps"
77 /** Presence URI through which the OIC devices advertise their presence.*/
78 #define OC_RSRVD_PRESENCE_URI "/oic/ad"
80 /** Presence URI through which the OCF devices advertise their device presence.*/
81 #define OCF_RSRVD_DEVICE_PRESENCE_URI "/ocf/prs"
83 /** Sets the default time to live (TTL) for presence.*/
84 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
86 /** For multicast Discovery mechanism.*/
87 #define OC_MULTICAST_DISCOVERY_URI "/oic/res"
89 /** Separator for multiple query string.*/
90 #define OC_QUERY_SEPARATOR "&;"
93 * OC_DEFAULT_PRESENCE_TTL_SECONDS sets the default time to live (TTL) for presence.
95 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
98 * OC_MAX_PRESENCE_TTL_SECONDS sets the maximum time to live (TTL) for presence.
99 * NOTE: Changing the setting to a longer duration may lead to unsupported and untested
101 * 60 sec/min * 60 min/hr * 24 hr/day
103 #define OC_MAX_PRESENCE_TTL_SECONDS (60 * 60 * 24)
107 * Presence "Announcement Triggers".
111 #define OC_RSRVD_TRIGGER_CREATE "create"
114 #define OC_RSRVD_TRIGGER_CHANGE "change"
117 #define OC_RSRVD_TRIGGER_DELETE "delete"
120 * Attributes used to form a proper OIC conforming JSON message.
123 #define OC_RSRVD_OC "oic"
127 #define OC_RSRVD_PAYLOAD "payload"
129 /** To represent href */
130 #define OC_RSRVD_HREF "href"
132 /** To represent property*/
133 #define OC_RSRVD_PROPERTY "prop"
135 /** For representation.*/
136 #define OC_RSRVD_REPRESENTATION "rep"
138 /** To represent content type.*/
139 #define OC_RSRVD_CONTENT_TYPE "ct"
141 /** To represent resource type.*/
142 #define OC_RSRVD_RESOURCE_TYPE "rt"
144 /** To represent resource type with presence.*/
145 #define OC_RSRVD_RESOURCE_TYPE_PRESENCE "oic.wk.ad"
147 /** To represent resource type with device.*/
148 #define OC_RSRVD_RESOURCE_TYPE_DEVICE "oic.wk.d"
150 /** To represent resource type with platform.*/
151 #define OC_RSRVD_RESOURCE_TYPE_PLATFORM "oic.wk.p"
153 /** To represent resource type with RES.*/
154 #define OC_RSRVD_RESOURCE_TYPE_RES "oic.wk.res"
157 /** To represent content type with MQ Broker.*/
158 #define OC_RSRVD_RESOURCE_TYPE_MQ_BROKER "ocf.wk.ps"
160 /** To represent content type with MQ Topic.*/
161 #define OC_RSRVD_RESOURCE_TYPE_MQ_TOPIC "ocf.wk.ps.topic"
164 /** To represent interface.*/
165 #define OC_RSRVD_INTERFACE "if"
167 /** To indicate how long RD should publish this item.*/
168 #define OC_RSRVD_DEVICE_TTL "lt"
170 /** To represent time to live.*/
171 #define OC_RSRVD_TTL "ttl"
173 /** To represent non*/
174 #define OC_RSRVD_NONCE "non"
176 /** To represent trigger type.*/
177 #define OC_RSRVD_TRIGGER "trg"
179 /** To represent links.*/
180 #define OC_RSRVD_LINKS "links"
182 /** To represent default interface.*/
183 #define OC_RSRVD_INTERFACE_DEFAULT "oic.if.baseline"
185 /** To represent read-only interface.*/
186 #define OC_RSRVD_INTERFACE_READ "oic.if.r"
188 /** To represent ll interface.*/
189 #define OC_RSRVD_INTERFACE_LL "oic.if.ll"
191 /** To represent batch interface.*/
192 #define OC_RSRVD_INTERFACE_BATCH "oic.if.b"
194 /** To represent interface group.*/
195 #define OC_RSRVD_INTERFACE_GROUP "oic.mi.grp"
197 /** To represent MFG date.*/
198 #define OC_RSRVD_MFG_DATE "mndt"
200 /** To represent FW version.*/
201 #define OC_RSRVD_FW_VERSION "mnfv"
203 /** To represent host name.*/
204 #define OC_RSRVD_HOST_NAME "hn"
206 /** To represent policy.*/
207 #define OC_RSRVD_POLICY "p"
209 /** To represent bitmap.*/
210 #define OC_RSRVD_BITMAP "bm"
213 #define OC_RSRVD_SECURE "sec"
216 #define OC_RSRVD_HOSTING_PORT "port"
219 #define OC_RSRVD_TCP_PORT "x.org.iotivity.tcp"
221 /** For Server instance ID.*/
222 #define OC_RSRVD_SERVER_INSTANCE_ID "sid"
229 #define OC_RSRVD_PLATFORM_ID "pi"
231 /** Platform MFG NAME. */
232 #define OC_RSRVD_MFG_NAME "mnmn"
235 #define OC_RSRVD_MFG_URL "mnml"
238 #define OC_RSRVD_MODEL_NUM "mnmo"
240 /** Platform MFG Date.*/
241 #define OC_RSRVD_MFG_DATE "mndt"
243 /** Platform versio.n */
244 #define OC_RSRVD_PLATFORM_VERSION "mnpv"
246 /** Platform Operating system version. */
247 #define OC_RSRVD_OS_VERSION "mnos"
249 /** Platform Hardware version. */
250 #define OC_RSRVD_HARDWARE_VERSION "mnhw"
252 /**Platform Firmware version. */
253 #define OC_RSRVD_FIRMWARE_VERSION "mnfv"
255 /** Support URL for the platform. */
256 #define OC_RSRVD_SUPPORT_URL "mnsl"
258 /** System time for the platform. */
259 #define OC_RSRVD_SYSTEM_TIME "st"
266 #define OC_RSRVD_DEVICE_ID "di"
269 #define OC_RSRVD_DEVICE_NAME "n"
271 /** Device specification version.*/
272 #define OC_RSRVD_SPEC_VERSION "icv"
274 /** Device data model.*/
275 #define OC_RSRVD_DATA_MODEL_VERSION "dmv"
277 /** Device specification version.*/
278 #define OC_SPEC_VERSION "core.1.0.0"
280 /** Device Data Model version.*/
281 #define OC_DATA_MODEL_VERSION "res.1.0.0"
284 * These provide backward compatibility - their use is deprecated.
288 /** Multicast Prefix.*/
289 #define OC_MULTICAST_PREFIX "224.0.1.187:5683"
291 /** Multicast IP address.*/
292 #define OC_MULTICAST_IP "224.0.1.187"
294 /** Multicast Port.*/
295 #define OC_MULTICAST_PORT 5683
298 /** Max Device address size. */
300 #define MAX_ADDR_STR_SIZE (256)
302 /** Max Address could be
303 * "coaps+tcp://[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:yyy.yyy.yyy.yyy]:xxxxx"
304 * +1 for null terminator.
306 #define MAX_ADDR_STR_SIZE (66)
309 /** Length of MAC address */
310 #define MAC_ADDR_STR_SIZE (17)
312 /** Blocks of MAC address */
313 #define MAC_ADDR_BLOCKS (6)
315 /** Max identity size. */
316 #define MAX_IDENTITY_SIZE (37)
318 /** Universal unique identity size. */
319 #define UUID_IDENTITY_SIZE (128/8)
321 /** Resource Directory */
323 /** Resource Directory URI used to Discover RD and Publish resources.*/
324 #define OC_RSRVD_RD_URI "/oic/rd"
326 /** To represent resource type with rd.*/
327 #define OC_RSRVD_RESOURCE_TYPE_RD "oic.wk.rd"
329 /** RD Discovery bias factor type. */
330 #define OC_RSRVD_RD_DISCOVERY_SEL "sel"
333 #define OC_RSRVD_BASE_URI "baseURI"
335 /** Unique value per collection/link. */
336 #define OC_RSRVD_INS "ins"
338 /** Allowable resource types in the links. */
339 #define OC_RSRVD_RTS "rts"
341 /** Default relationship. */
342 #define OC_RSRVD_DREL "drel"
344 /** Defines relationship between links. */
345 #define OC_RSRVD_REL "rel"
347 /** Defines title. */
348 #define OC_RSRVD_TITLE "title"
351 #define OC_RSRVD_URI "anchor"
353 /** Defines media type. */
354 #define OC_RSRVD_MEDIA_TYPE "type"
356 /** To represent resource type with Publish RD.*/
357 #define OC_RSRVD_RESOURCE_TYPE_RDPUBLISH "oic.wk.rdpub"
362 #define OC_RSRVD_ACCOUNT_URI "/ocf/account"
364 /** Account session URI.*/
365 #define OC_RSRVD_ACCOUNT_SESSION_URI "/ocf/account/session"
367 /** Account token refresh URI.*/
368 #define OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI "/ocf/account/tokenrefresh"
370 /** Defines auth provider. */
371 #define OC_RSRVD_AUTHPROVIDER "authprovider"
373 /** Defines auth code. */
374 #define OC_RSRVD_AUTHCODE "authcode"
376 /** Defines access token. */
377 #define OC_RSRVD_ACCESS_TOKEN "accesstoken"
379 /** Defines login. */
380 #define OC_RSRVD_LOGIN "login"
382 /** Defines search. */
383 #define OC_RSRVD_SEARCH "search"
385 /** Defines grant type. */
386 #define OC_RSRVD_GRANT_TYPE "granttype"
388 /** Defines refresh token. */
389 #define OC_RSRVD_REFRESH_TOKEN "refreshtoken"
391 /** Defines user UUID. */
392 #define OC_RSRVD_USER_UUID "uid"
394 /** Defines options. */
395 #define OC_RSRVD_OPTIONS "options"
397 /** To represent grant type with refresh token. */
398 #define OC_RSRVD_GRANT_TYPE_REFRESH_TOKEN "refresh_token"
401 * Mark a parameter as unused. Used to prevent unused variable compiler warnings.
402 * Used in three cases:
403 * 1. in callbacks when one of the parameters are unused
404 * 2. when due to code changes a functions parameter is no longer
405 * used but must be left in place for backward compatibility
407 * 3. a variable is only used in the debug build variant and would
408 * give a build warning in release mode.
410 #define OC_UNUSED(x) (void)(x)
413 * These enums (OCTransportAdapter and OCTransportFlags) must
414 * be kept synchronized with OCConnectivityType (below) as well as
415 * CATransportAdapter and CATransportFlags (in CACommon.h).
419 /** value zero indicates discovery.*/
420 OC_DEFAULT_ADAPTER = 0,
422 /** IPv4 and IPv6, including 6LoWPAN.*/
423 OC_ADAPTER_IP = (1 << 0),
425 /** GATT over Bluetooth LE.*/
426 OC_ADAPTER_GATT_BTLE = (1 << 1),
428 /** RFCOMM over Bluetooth EDR.*/
429 OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
431 /**Remote Access over XMPP.*/
432 OC_ADAPTER_REMOTE_ACCESS = (1 << 3),
435 OC_ADAPTER_TCP = (1 << 4),
437 /** NFC Transport for Messaging.*/
438 OC_ADAPTER_NFC = (1 << 5)
439 } OCTransportAdapter;
442 * Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
446 /** default flag is 0*/
447 OC_DEFAULT_FLAGS = 0,
449 /** Insecure transport is the default (subject to change).*/
450 /** secure the transport path*/
451 OC_FLAG_SECURE = (1 << 4),
453 /** IPv4 & IPv6 auto-selection is the default.*/
454 /** IP & TCP adapter only.*/
455 OC_IP_USE_V6 = (1 << 5),
457 /** IP & TCP adapter only.*/
458 OC_IP_USE_V4 = (1 << 6),
460 /** Multicast only.*/
461 OC_MULTICAST = (1 << 7),
463 /** Link-Local multicast is the default multicast scope for IPv6.
464 * These are placed here to correspond to the IPv6 multicast address bits.*/
466 /** IPv6 Interface-Local scope (loopback).*/
467 OC_SCOPE_INTERFACE = 0x1,
469 /** IPv6 Link-Local scope (default).*/
472 /** IPv6 Realm-Local scope. */
473 OC_SCOPE_REALM = 0x3,
475 /** IPv6 Admin-Local scope. */
476 OC_SCOPE_ADMIN = 0x4,
478 /** IPv6 Site-Local scope. */
481 /** IPv6 Organization-Local scope. */
484 /**IPv6 Global scope. */
485 OC_SCOPE_GLOBAL = 0xE,
489 /** Bit mask for scope.*/
490 #define OC_MASK_SCOPE (0x000F)
492 /** Bit mask for Mods.*/
493 #define OC_MASK_MODS (0x0FF0)
494 #define OC_MASK_FAMS (OC_IP_USE_V6|OC_IP_USE_V4)
496 typedef struct OCStringLL
498 struct OCStringLL *next;
503 * End point identity.
507 /** Identity Length */
510 /** Array of end point identity.*/
511 unsigned char id[MAX_IDENTITY_SIZE];
515 * Universally unique identifier.
519 /** identitifier string.*/
520 unsigned char id[UUID_IDENTITY_SIZE];
524 * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
525 * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
530 OCTransportAdapter adapter;
532 /** transport modifiers.*/
533 OCTransportFlags flags;
538 /** address for all adapters.*/
539 char addr[MAX_ADDR_STR_SIZE];
541 /** usually zero for default interface.*/
543 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
544 char routeData[MAX_ADDR_STR_SIZE]; //destination GatewayID:ClientId
549 * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
550 * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
551 * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
554 * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
558 /** use when defaults are ok. */
561 /** IPv4 and IPv6, including 6LoWPAN.*/
562 CT_ADAPTER_IP = (1 << 16),
564 /** GATT over Bluetooth LE.*/
565 CT_ADAPTER_GATT_BTLE = (1 << 17),
567 /** RFCOMM over Bluetooth EDR.*/
568 CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
571 /** Remote Access over XMPP.*/
572 CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
575 CT_ADAPTER_TCP = (1 << 20),
578 CT_ADAPTER_NFC = (1 << 21),
580 /** Insecure transport is the default (subject to change).*/
582 /** secure the transport path.*/
583 CT_FLAG_SECURE = (1 << 4),
585 /** IPv4 & IPv6 autoselection is the default.*/
587 /** IP adapter only.*/
588 CT_IP_USE_V6 = (1 << 5),
590 /** IP adapter only.*/
591 CT_IP_USE_V4 = (1 << 6),
593 /** Link-Local multicast is the default multicast scope for IPv6.
594 * These are placed here to correspond to the IPv6 address bits.*/
596 /** IPv6 Interface-Local scope(loopback).*/
597 CT_SCOPE_INTERFACE = 0x1,
599 /** IPv6 Link-Local scope (default).*/
602 /** IPv6 Realm-Local scope.*/
603 CT_SCOPE_REALM = 0x3,
605 /** IPv6 Admin-Local scope.*/
606 CT_SCOPE_ADMIN = 0x4,
608 /** IPv6 Site-Local scope.*/
611 /** IPv6 Organization-Local scope.*/
614 /** IPv6 Global scope.*/
615 CT_SCOPE_GLOBAL = 0xE,
616 } OCConnectivityType;
618 /** bit shift required for connectivity adapter.*/
619 #define CT_ADAPTER_SHIFT 16
622 #define CT_MASK_FLAGS 0xFFFF
625 #define CT_MASK_ADAPTER 0xFFFF0000
628 * OCDoResource methods to dispatch the request
632 OC_REST_NOMETHOD = 0,
635 OC_REST_GET = (1 << 0),
638 OC_REST_PUT = (1 << 1),
641 OC_REST_POST = (1 << 2),
644 OC_REST_DELETE = (1 << 3),
646 /** Register observe request for most up date notifications ONLY.*/
647 OC_REST_OBSERVE = (1 << 4),
649 /** Register observe request for all notifications, including stale notifications.*/
650 OC_REST_OBSERVE_ALL = (1 << 5),
652 /** De-register observation, intended for internal use.*/
653 OC_REST_CANCEL_OBSERVE = (1 << 6),
656 /** Subscribe for all presence notifications of a particular resource.*/
657 OC_REST_PRESENCE = (1 << 7),
660 /** Allows OCDoResource caller to do discovery.*/
661 OC_REST_DISCOVER = (1 << 8)
665 * Formats for payload encoding.
671 OC_FORMAT_UNSUPPORTED,
675 * Host Mode of Operation.
682 OC_GATEWAY /**< Client server mode along with routing capabilities.*/
686 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
687 * protocol. The precise definitions of each quality of service level depend on the
688 * implementation. In descriptions below are for the current implementation and may changed
693 /** Packet delivery is best effort.*/
696 /** Packet delivery is best effort.*/
699 /** Acknowledgments are used to confirm delivery.*/
702 /** No Quality is defined, let the stack decide.*/
704 } OCQualityOfService;
707 * Resource Properties.
708 * The value of a policy property is defined as bitmap.
709 * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
710 * Not including the policy property is equivalent to zero.
715 /** When none of the bits are set, the resource is non-discoverable &
716 * non-observable by the client.*/
717 OC_RES_PROP_NONE = (0),
719 /** When this bit is set, the resource is allowed to be discovered by clients.*/
720 OC_DISCOVERABLE = (1 << 0),
722 /** When this bit is set, the resource is allowed to be observed by clients.*/
723 OC_OBSERVABLE = (1 << 1),
725 /** When this bit is set, the resource is initialized, otherwise the resource
726 * is 'inactive'. 'inactive' signifies that the resource has been marked for
727 * deletion or is already deleted.*/
728 OC_ACTIVE = (1 << 2),
730 /** When this bit is set, the resource has been marked as 'slow'.
731 * 'slow' signifies that responses from this resource can expect delays in
732 * processing its requests from clients.*/
736 /** When this bit is set, the resource is a secure resource.*/
737 OC_SECURE = (1 << 4),
742 /** When this bit is set, the resource is allowed to be discovered only
743 * if discovery request contains an explicit querystring.
744 * Ex: GET /oic/res?rt=oic.sec.acl */
745 OC_EXPLICIT_DISCOVERABLE = (1 << 5)
748 /** When this bit is set, the resource is allowed to be published */
749 ,OC_MQ_PUBLISHER = (1 << 6)
753 /** When this bit is set, the resource is allowed to be notified as MQ broker.*/
754 ,OC_MQ_BROKER = (1 << 7)
756 } OCResourceProperty;
759 * Transport Protocol IDs.
763 /** For invalid ID.*/
764 OC_INVALID_ID = (1 << 0),
767 OC_COAP_ID = (1 << 1)
768 } OCTransportProtocolID;
771 * Declares Stack Results & Errors.
775 /** Success status code - START HERE.*/
777 OC_STACK_RESOURCE_CREATED,
778 OC_STACK_RESOURCE_DELETED,
780 OC_STACK_RESOURCE_CHANGED,
781 /** Success status code - END HERE.*/
783 /** Error status code - START HERE.*/
784 OC_STACK_INVALID_URI = 20,
785 OC_STACK_INVALID_QUERY,
787 OC_STACK_INVALID_PORT,
788 OC_STACK_INVALID_CALLBACK,
789 OC_STACK_INVALID_METHOD,
791 /** Invalid parameter.*/
792 OC_STACK_INVALID_PARAM,
793 OC_STACK_INVALID_OBSERVE_PARAM,
797 OC_STACK_ADAPTER_NOT_ENABLED,
800 /** Resource not found.*/
801 OC_STACK_NO_RESOURCE,
803 /** e.g: not supported method or interface.*/
804 OC_STACK_RESOURCE_ERROR,
805 OC_STACK_SLOW_RESOURCE,
806 OC_STACK_DUPLICATE_REQUEST,
808 /** Resource has no registered observers.*/
809 OC_STACK_NO_OBSERVERS,
810 OC_STACK_OBSERVER_NOT_FOUND,
811 OC_STACK_VIRTUAL_DO_NOT_HANDLE,
812 OC_STACK_INVALID_OPTION,
814 /** The remote reply contained malformed data.*/
815 OC_STACK_MALFORMED_RESPONSE,
816 OC_STACK_PERSISTENT_BUFFER_REQUIRED,
817 OC_STACK_INVALID_REQUEST_HANDLE,
818 OC_STACK_INVALID_DEVICE_INFO,
819 OC_STACK_INVALID_JSON,
821 /** Request is not authorized by Resource Server. */
822 OC_STACK_UNAUTHORIZED_REQ,
823 OC_STACK_TOO_LARGE_REQ,
825 /** Error code from PDM */
826 OC_STACK_PDM_IS_NOT_INITIALIZED,
827 OC_STACK_DUPLICATE_UUID,
828 OC_STACK_INCONSISTENT_DB,
831 * Error code from OTM
832 * This error is pushed from DTLS interface when handshake failure happens
834 OC_STACK_AUTHENTICATION_FAILURE,
836 /** Insert all new error codes here!.*/
838 OC_STACK_PRESENCE_STOPPED = 128,
839 OC_STACK_PRESENCE_TIMEOUT,
840 OC_STACK_PRESENCE_DO_NOT_HANDLE,
842 /** ERROR in stack.*/
844 /** Error status code - END HERE.*/
848 * Handle to an OCDoResource invocation.
850 typedef void * OCDoHandle;
853 * Handle to an OCResource object owned by the OCStack.
855 typedef void * OCResourceHandle;
858 * Handle to an OCRequest object owned by the OCStack.
860 typedef void * OCRequestHandle;
863 * Unique identifier for each observation request. Used when observations are
864 * registered or de-registered. Used by entity handler to signal specific
865 * observers to be notified of resource changes.
866 * There can be maximum of 256 observations per server.
868 typedef uint8_t OCObservationId;
871 * Action associated with observation.
876 OC_OBSERVE_REGISTER = 0,
878 /** To Deregister. */
879 OC_OBSERVE_DEREGISTER = 1,
882 OC_OBSERVE_NO_OPTION = 2,
885 OC_MQ_SUBSCRIBER = 3,
887 OC_MQ_UNSUBSCRIBER = 4,
894 * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
895 * when it calls OCRegisterPersistentStorageHandler.
896 * Persistent storage open handler points to default file path.
897 * It should check file path and whether the file is symbolic link or no.
898 * Application can point to appropriate SVR database path for it's IoTivity Server.
901 /** Persistent storage file path.*/
902 FILE* (* open)(const char *path, const char *mode);
904 /** Persistent storage read handler.*/
905 size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
907 /** Persistent storage write handler.*/
908 size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
910 /** Persistent storage close handler.*/
911 int (* close)(FILE *fp);
913 /** Persistent storage unlink handler.*/
914 int (* unlink)(const char *path);
915 } OCPersistentStorage;
918 * Possible returned values from entity handler.
922 /** Action associated with observation request.*/
923 OCObserveAction action;
925 /** Identifier for observation being registered/deregistered.*/
926 OCObservationId obsId;
930 * Possible returned values from entity handler.
936 OC_EH_RESOURCE_CREATED, // 2.01
937 OC_EH_RESOURCE_DELETED, // 2.02
939 OC_EH_FORBIDDEN, // 4.03
940 OC_EH_RESOURCE_NOT_FOUND, // 4.04
942 OC_EH_CHANGED, // 2.04
943 OC_EH_CONTENT, // 2.05
944 OC_EH_BAD_REQ, // 4.00
945 OC_EH_UNAUTHORIZED_REQ, // 4.01
946 OC_EH_BAD_OPT, // 4.02
947 OC_EH_METHOD_NOT_ALLOWED, // 4.05
948 OC_EH_NOT_ACCEPTABLE, // 4.06
949 OC_EH_INTERNAL_SERVER_ERROR, // 5.00
950 OC_EH_RETRANSMIT_TIMEOUT // 5.04
951 } OCEntityHandlerResult;
954 * This structure will be used to define the vendor specific header options to be included
955 * in communication packets.
957 typedef struct OCHeaderOption
959 /** The protocol ID this option applies to.*/
960 OCTransportProtocolID protocolID;
962 /** The header option ID which will be added to communication packets.*/
965 /** its length 191.*/
966 uint16_t optionLength;
968 /** pointer to its data.*/
969 uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
971 #ifdef SUPPORTS_DEFAULT_CTOR
972 OCHeaderOption() = default;
973 OCHeaderOption(OCTransportProtocolID pid,
976 const uint8_t* optData)
982 // parameter includes the null terminator.
983 optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
984 optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
985 memcpy(optionData, optData, optionLength);
986 optionData[optionLength - 1] = '\0';
993 * This structure describes the platform properties. All non-Null properties will be
994 * included in a platform discovery request.
1001 /** Manufacturer name.*/
1002 char *manufacturerName;
1004 /** Manufacturer URL for platform property.*/
1005 char *manufacturerUrl;
1010 /** Manufacturer date.*/
1011 char *dateOfManufacture;
1013 /** Platform version.*/
1014 char *platformVersion;
1016 /** Operating system version.*/
1017 char *operatingSystemVersion;
1020 char *hardwareVersion;
1023 char *firmwareVersion;
1025 /** Platform support URL.*/
1034 * This structure is expected as input for device properties.
1035 * device name is mandatory and expected from the application.
1036 * device id of type UUID will be generated by the stack.
1040 /** Pointer to the device name.*/
1042 /** Pointer to the types.*/
1044 /** Pointer to the device specification version.*/
1046 /** Pointer to the device data model versions (in CSV format).*/
1047 OCStringLL *dataModelVersions;
1052 * callback for bound JID
1054 typedef void (*jid_bound_cb)(char *jid);
1057 * CA Remote Access information for XMPP Client
1062 char *hostname; /**< XMPP server hostname */
1063 uint16_t port; /**< XMPP server serivce port */
1064 char *xmpp_domain; /**< XMPP login domain */
1065 char *username; /**< login username */
1066 char *password; /**< login password */
1067 char *resource; /**< specific resource for login */
1068 char *user_jid; /**< specific JID for login */
1069 jid_bound_cb jidbound; /**< callback when JID bound */
1071 #endif /* RA_ADAPTER */
1074 /** Enum to describe the type of object held by the OCPayload object.*/
1077 /** Contents of the payload are invalid */
1078 PAYLOAD_TYPE_INVALID,
1079 /** The payload is an OCDiscoveryPayload */
1080 PAYLOAD_TYPE_DISCOVERY,
1081 /** The payload is an OCDevicePayload */
1082 PAYLOAD_TYPE_DEVICE,
1083 /** The payload is an OCPlatformPayload */
1084 PAYLOAD_TYPE_PLATFORM,
1085 /** The payload is an OCRepPayload */
1086 PAYLOAD_TYPE_REPRESENTATION,
1087 /** The payload is an OCSecurityPayload */
1088 PAYLOAD_TYPE_SECURITY,
1089 /** The payload is an OCPresencePayload */
1090 PAYLOAD_TYPE_PRESENCE,
1091 /** The payload is an OCRDPayload */
1096 * A generic struct representing a payload returned from a resource operation
1098 * A pointer to OCPayLoad can be cast to a more specific struct to access members
1103 /** The type of message that was received */
1114 OCREP_PROP_BYTE_STRING,
1117 }OCRepPayloadPropType;
1119 /** This structure will be used to represent a binary string for CBOR payloads.*/
1122 /** pointer to data bytes.*/
1125 /** number of data bytes.*/
1129 #define MAX_REP_ARRAY_DEPTH 3
1132 OCRepPayloadPropType type;
1133 size_t dimensions[MAX_REP_ARRAY_DEPTH];
1142 /** pointer to ByteString array.*/
1143 OCByteString* ocByteStrArray;
1145 struct OCRepPayload** objArray;
1147 } OCRepPayloadValueArray;
1149 typedef struct OCRepPayloadValue
1152 OCRepPayloadPropType type;
1160 /** ByteString object.*/
1161 OCByteString ocByteStr;
1163 struct OCRepPayload* obj;
1164 OCRepPayloadValueArray arr;
1166 struct OCRepPayloadValue* next;
1168 } OCRepPayloadValue;
1170 // used for get/set/put/observe/etc representations
1171 typedef struct OCRepPayload
1176 OCStringLL* interfaces;
1177 OCRepPayloadValue* values;
1178 struct OCRepPayload* next;
1181 // used inside a discovery payload
1182 typedef struct OCResourcePayload
1186 OCStringLL* interfaces;
1193 struct OCResourcePayload* next;
1194 } OCResourcePayload;
1197 * Structure holding Links Payload. It is a sub-structure used in
1198 * OCResourceCollectionPayload.
1200 typedef struct OCLinksPayload
1202 /** This is the target relative URI. */
1204 /** The relation of the target URI referenced by the link to the context URI;
1205 * The default value is null. */
1207 /** Resource Type - A standard OIC specified or vendor defined resource
1208 * type of the resource referenced by the target URI. */
1210 /** Interface - The interfaces supported by the resource referenced by the target URI. */
1212 /** Bitmap - The bitmap holds observable, discoverable, secure option flag. */
1214 /** A title for the link relation. Can be used by the UI to provide a context. */
1216 /** This is used to override the context URI e.g. override the URI of the containing collection. */
1218 /** The instance identifier for this web link in an array of web links - used in links. */
1221 /** An ordinal number that is not repeated - must be unique in the collection context. */
1223 /** Any unique string including a URI. */
1225 /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1226 OCIdentity uniqueUUID;
1228 /** Time to keep holding resource.*/
1230 /** A hint of the media type of the representation of the resource referenced by the target URI. */
1232 /** Holding address of the next resource. */
1233 struct OCLinksPayload *next;
1236 /** Structure holding tags value of the links payload. */
1239 /** Name of tags. */
1241 /** Device identifier. */
1243 /** Time to keep holding resource.*/
1247 /** Resource collection payload. */
1248 typedef struct OCResourceCollectionPayload
1250 /** Collection tags payload.*/
1251 OCTagsPayload *tags;
1252 /** Array of links payload. */
1253 OCLinksPayload *setLinks;
1254 } OCResourceCollectionPayload;
1256 typedef struct OCDiscoveryPayload
1263 /** A special case for handling RD address. */
1272 /** Resource Type */
1278 /** This structure holds the old /oic/res response. */
1279 OCResourcePayload *resources;
1281 /** Holding address of the next DiscoveryPayload. */
1282 struct OCDiscoveryPayload *next;
1284 } OCDiscoveryPayload;
1287 * Structure holding discovery payload.
1293 /** Device Identity. */
1295 /** Value holding the bias factor of the RD. */
1297 } OCRDDiscoveryPayload;
1300 * RD Payload that will be transmitted over the wire.
1305 /** Pointer to the discovery response payload.*/
1306 OCRDDiscoveryPayload *rdDiscovery;
1307 /** Pointer to the publish payload.*/
1308 OCResourceCollectionPayload *rdPublish;
1317 OCStringLL *dataModelVersions;
1318 OCStringLL *interfaces;
1326 OCPlatformInfo info;
1328 OCStringLL* interfaces;
1329 } OCPlatformPayload;
1334 uint8_t* securityData;
1336 } OCSecurityPayload;
1338 #ifdef WITH_PRESENCE
1342 uint32_t sequenceNumber;
1344 OCPresenceTrigger trigger;
1346 } OCPresencePayload;
1350 * Incoming requests handled by the server. Requests are passed in as a parameter to the
1351 * OCEntityHandler callback API.
1352 * The OCEntityHandler callback API must be implemented in the application in order
1353 * to receive these requests.
1357 /** Associated resource.*/
1358 OCResourceHandle resource;
1360 /** Associated request handle.*/
1361 OCRequestHandle requestHandle;
1363 /** the REST method retrieved from received request PDU.*/
1366 /** description of endpoint that sent the request.*/
1369 /** resource query send by client.*/
1372 /** Information associated with observation - valid only when OCEntityHandler flag includes
1373 * ::OC_OBSERVE_FLAG.*/
1374 OCObservationInfo obsInfo;
1376 /** Number of the received vendor specific header options.*/
1377 uint8_t numRcvdVendorSpecificHeaderOptions;
1379 /** Pointer to the array of the received vendor specific header options.*/
1380 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1385 /** the payload from the request PDU.*/
1388 } OCEntityHandlerRequest;
1392 * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1396 /** Address of remote server.*/
1399 /** backward compatibility (points to devAddr).*/
1402 /** backward compatibility.*/
1403 OCConnectivityType connType;
1405 /** the security identity of the remote server.*/
1406 OCIdentity identity;
1408 /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1409 OCStackResult result;
1411 /** If associated with observe, this will represent the sequence of notifications from server.*/
1412 uint32_t sequenceNumber;
1415 const char * resourceUri;
1417 /** the payload for the response PDU.*/
1420 /** Number of the received vendor specific header options.*/
1421 uint8_t numRcvdVendorSpecificHeaderOptions;
1423 /** An array of the received vendor specific header options.*/
1424 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1428 * Request handle is passed to server via the entity handler for each incoming request.
1429 * Stack assigns when request is received, server sets to indicate what request response is for.
1433 /** Request handle.*/
1434 OCRequestHandle requestHandle;
1436 /** Resource handle.*/
1437 OCResourceHandle resourceHandle;
1439 /** Allow the entity handler to pass a result with the response.*/
1440 OCEntityHandlerResult ehResult;
1442 /** This is the pointer to server payload data to be transferred.*/
1445 /** number of the vendor specific header options .*/
1446 uint8_t numSendVendorSpecificHeaderOptions;
1448 /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1449 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1451 /** URI of new resource that entity handler might create.*/
1452 char resourceUri[MAX_URI_LENGTH];
1454 /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1455 uint8_t persistentBufferFlag;
1456 } OCEntityHandlerResponse;
1463 /** Request state.*/
1464 OC_REQUEST_FLAG = (1 << 1),
1465 /** Observe state.*/
1466 OC_OBSERVE_FLAG = (1 << 2)
1467 } OCEntityHandlerFlag;
1470 * Possible return values from client application callback
1472 * A client application callback returns an OCStackApplicationResult to indicate whether
1473 * the stack should continue to keep the callback registered.
1477 /** Make no more calls to the callback and call the OCClientContextDeleter for this callback */
1478 OC_STACK_DELETE_TRANSACTION = 0,
1479 /** Keep this callback registered and call it if an apropriate event occurs */
1480 OC_STACK_KEEP_TRANSACTION
1481 } OCStackApplicationResult;
1484 //#ifdef DIRECT_PAIRING
1486 * @brief direct pairing Method Type.
1488 * 1: pre-configured pin
1493 DP_NOT_ALLOWED = 0x0,
1494 DP_PRE_CONFIGURED = (0x1 << 0),
1495 DP_RANDOM_PIN = (0x1 << 1),
1499 * Device Information of discoverd direct pairing device(s).
1501 typedef struct OCDPDev
1504 OCConnectivityType connType;
1505 uint16_t securePort;
1509 OCUUIdentity deviceID;
1510 OCUUIdentity rowner;
1511 struct OCDPDev *next;
1513 //#endif // DIRECT_PAIRING
1516 * -------------------------------------------------------------------------------------------
1517 * Callback function definitions
1518 * -------------------------------------------------------------------------------------------
1522 * Client applications implement this callback to consume responses received from Servers.
1524 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1525 OCClientResponse * clientResponse);
1528 * Client applications using a context pointer implement this callback to delete the
1529 * context upon removal of the callback/context pointer from the internal callback-list.
1531 typedef void (* OCClientContextDeleter)(void *context);
1534 * This info is passed from application to OC Stack when initiating a request to Server.
1536 typedef struct OCCallbackData
1538 /** Pointer to the context.*/
1541 /** The pointer to a function the stack will call to handle the requests.*/
1542 OCClientResponseHandler cb;
1544 /** A pointer to a function to delete the context when this callback is removed.*/
1545 OCClientContextDeleter cd;
1547 #ifdef SUPPORTS_DEFAULT_CTOR
1548 OCCallbackData() = default;
1549 OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1550 :context(ctx), cb(callback), cd(deleter){}
1555 * Application server implementations must implement this callback to consume requests OTA.
1556 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1558 typedef OCEntityHandlerResult (*OCEntityHandler)
1559 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1562 * Device Entity handler need to use this call back instead of OCEntityHandler.
1564 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1565 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1567 //#ifdef DIRECT_PAIRING
1569 * Callback function definition of direct-pairing
1571 * @param[OUT] ctx - user context returned in the callback.
1572 * @param[OUT] peer - pairing device info.
1573 * @param[OUT} result - It's returned with 'OC_STACK_XXX'. It will return 'OC_STACK_OK'
1574 * if D2D pairing is success without error
1576 typedef void (*OCDirectPairingCB)(void *ctx, OCDPDev_t *peer, OCStackResult result);
1577 //#endif // DIRECT_PAIRING
1581 #endif // __cplusplus
1583 #endif /* OCTYPES_H_ */