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 "iotivity_config.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"
69 #define OC_RSRVD_GATEWAY_URI "/oic/gateway"
72 #define OC_RSRVD_WELL_KNOWN_MQ_URI "/oic/ps"
75 #define OC_RSRVD_KEEPALIVE_URI "/oic/ping"
80 /** Presence URI through which the OIC devices advertise their presence.*/
81 #define OC_RSRVD_PRESENCE_URI "/oic/ad"
83 /** Presence URI through which the OIC devices advertise their device presence.*/
84 #define OC_RSRVD_DEVICE_PRESENCE_URI "/oic/prs"
86 /** Sets the default time to live (TTL) for presence.*/
87 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
89 /** For multicast Discovery mechanism.*/
90 #define OC_MULTICAST_DISCOVERY_URI "/oic/res"
92 /** Separator for multiple query string.*/
93 #define OC_QUERY_SEPARATOR "&;"
96 * OC_DEFAULT_PRESENCE_TTL_SECONDS sets the default time to live (TTL) for presence.
98 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
101 * OC_MAX_PRESENCE_TTL_SECONDS sets the maximum time to live (TTL) for presence.
102 * NOTE: Changing the setting to a longer duration may lead to unsupported and untested
104 * 60 sec/min * 60 min/hr * 24 hr/day
106 #define OC_MAX_PRESENCE_TTL_SECONDS (60 * 60 * 24)
110 * Presence "Announcement Triggers".
114 #define OC_RSRVD_TRIGGER_CREATE "create"
117 #define OC_RSRVD_TRIGGER_CHANGE "change"
120 #define OC_RSRVD_TRIGGER_DELETE "delete"
123 * Attributes used to form a proper OIC conforming JSON message.
126 #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 collection.*/
158 #define OC_RSRVD_RESOURCE_TYPE_COLLECTION "oic.wk.col"
160 /** To represent resource type with RES.*/
161 #define OC_RSRVD_RESOURCE_TYPE_RES "oic.wk.res"
163 /** To represent content type with MQ Broker.*/
164 #define OC_RSRVD_RESOURCE_TYPE_MQ_BROKER "oic.wk.ps"
166 /** To represent content type with MQ Topic.*/
167 #define OC_RSRVD_RESOURCE_TYPE_MQ_TOPIC "oic.wk.ps.topic"
170 /** To represent interface.*/
171 #define OC_RSRVD_INTERFACE "if"
173 /** To indicate how long RD should publish this item.*/
174 #define OC_RSRVD_DEVICE_TTL "lt"
176 /** To represent time to live.*/
177 #define OC_RSRVD_TTL "ttl"
179 /** To represent non*/
180 #define OC_RSRVD_NONCE "non"
182 /** To represent trigger type.*/
183 #define OC_RSRVD_TRIGGER "trg"
185 /** To represent links.*/
186 #define OC_RSRVD_LINKS "links"
188 /** To represent default interface.*/
189 #define OC_RSRVD_INTERFACE_DEFAULT "oic.if.baseline"
191 /** To represent read-only interface.*/
192 #define OC_RSRVD_INTERFACE_READ "oic.if.r"
194 /** To represent ll interface.*/
195 #define OC_RSRVD_INTERFACE_LL "oic.if.ll"
197 /** To represent batch interface.*/
198 #define OC_RSRVD_INTERFACE_BATCH "oic.if.b"
200 /** To represent interface group.*/
201 #define OC_RSRVD_INTERFACE_GROUP "oic.mi.grp"
203 /** To represent MFG date.*/
204 #define OC_RSRVD_MFG_DATE "mndt"
206 /** To represent FW version.*/
207 #define OC_RSRVD_FW_VERSION "mnfv"
209 /** To represent host name.*/
210 #define OC_RSRVD_HOST_NAME "hn"
212 /** To represent policy.*/
213 #define OC_RSRVD_POLICY "p"
215 /** To represent bitmap.*/
216 #define OC_RSRVD_BITMAP "bm"
219 #define OC_RSRVD_SECURE "sec"
222 #define OC_RSRVD_HOSTING_PORT "port"
225 #define OC_RSRVD_TCP_PORT "tcp"
228 #define OC_RSRVD_TLS_PORT "tls"
230 /** For Server instance ID.*/
231 #define OC_RSRVD_SERVER_INSTANCE_ID "sid"
238 #define OC_RSRVD_PLATFORM_ID "pi"
240 /** Platform MFG NAME. */
241 #define OC_RSRVD_MFG_NAME "mnmn"
244 #define OC_RSRVD_MFG_URL "mnml"
247 #define OC_RSRVD_MODEL_NUM "mnmo"
249 /** Platform MFG Date.*/
250 #define OC_RSRVD_MFG_DATE "mndt"
252 /** Platform versio.n */
253 #define OC_RSRVD_PLATFORM_VERSION "mnpv"
255 /** Platform Operating system version. */
256 #define OC_RSRVD_OS_VERSION "mnos"
258 /** Platform Hardware version. */
259 #define OC_RSRVD_HARDWARE_VERSION "mnhw"
261 /**Platform Firmware version. */
262 #define OC_RSRVD_FIRMWARE_VERSION "mnfv"
264 /** Support URL for the platform. */
265 #define OC_RSRVD_SUPPORT_URL "mnsl"
267 /** System time for the platform. */
268 #define OC_RSRVD_SYSTEM_TIME "st"
270 /** VID for the platform. */
271 #define OC_RSRVD_VID "vid"
277 #define OC_RSRVD_DEVICE_ID "di"
280 #define OC_RSRVD_DEVICE_NAME "n"
282 /** Device specification version.*/
283 #define OC_RSRVD_SPEC_VERSION "icv"
285 /** Device data model.*/
286 #define OC_RSRVD_DATA_MODEL_VERSION "dmv"
288 /** Device specification version.*/
289 #define OC_SPEC_VERSION "core.1.1.0"
291 /** Device Data Model version.*/
292 #define OC_DATA_MODEL_VERSION "res.1.1.0,sh.1.1.0"
294 * These provide backward compatibility - their use is deprecated.
298 /** Multicast Prefix.*/
299 #define OC_MULTICAST_PREFIX "224.0.1.187:5683"
301 /** Multicast IP address.*/
302 #define OC_MULTICAST_IP "224.0.1.187"
304 /** Multicast Port.*/
305 #define OC_MULTICAST_PORT (5683)
308 /** Max Device address size. */
310 #define MAX_ADDR_STR_SIZE (256)
312 /** Max Address could be
313 * "coaps+tcp://[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:yyy.yyy.yyy.yyy]:xxxxx"
314 * +1 for null terminator.
316 #define MAX_ADDR_STR_SIZE (66)
319 /** Length of MAC address */
320 #define MAC_ADDR_STR_SIZE (17)
322 /** Blocks of MAC address */
323 #define MAC_ADDR_BLOCKS (6)
325 /** Max identity size. */
326 #define MAX_IDENTITY_SIZE (37)
328 /** Universal unique identity size. */
329 #define UUID_IDENTITY_SIZE (128/8)
331 /** Resource Directory */
333 /** Resource Directory URI used to Discover RD and Publish resources.*/
334 #define OC_RSRVD_RD_URI "/oic/rd"
336 /** To represent resource type with rd.*/
337 #define OC_RSRVD_RESOURCE_TYPE_RD "oic.wk.rd"
339 /** RD Discovery bias factor type. */
340 #define OC_RSRVD_RD_DISCOVERY_SEL "sel"
342 /** Resource URI used to discover Proxy */
343 #define OC_RSRVD_PROXY_URI "/oic/chp"
345 /** Resource URI used to discover Proxy */
346 #define OC_RSRVD_PROXY_OPTION_ID 35
349 #define OC_RSRVD_BASE_URI "baseURI"
351 /** Unique value per collection/link. */
352 #define OC_RSRVD_INS "ins"
354 /** Allowable resource types in the links. */
355 #define OC_RSRVD_RTS "rts"
357 /** Default relationship. */
358 #define OC_RSRVD_DREL "drel"
360 /** Defines relationship between links. */
361 #define OC_RSRVD_REL "rel"
363 /** Defines title. */
364 #define OC_RSRVD_TITLE "title"
367 #define OC_RSRVD_URI "anchor"
369 /** Defines media type. */
370 #define OC_RSRVD_MEDIA_TYPE "type"
372 /** To represent resource type with Publish RD.*/
373 #define OC_RSRVD_RESOURCE_TYPE_RDPUBLISH "oic.wk.rdpub"
378 #define OC_RSRVD_ACCOUNT_URI "/oic/account"
380 /** Account user URI.*/
381 #define OC_RSRVD_ACCOUNT_SEARCH_URI "/oic/account/search"
383 /** Account session URI.*/
384 #define OC_RSRVD_ACCOUNT_SESSION_URI "/oic/account/session"
386 /** Account token refresh URI.*/
387 #define OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI "/oic/account/tokenrefresh"
390 #define OC_RSRVD_ACL_GROUP_URI "/oic/acl/group"
392 /** ACL invite URI.*/
393 #define OC_RSRVD_ACL_INVITE_URI "/oic/acl/invite"
395 /** Defines auth provider. */
396 #define OC_RSRVD_AUTHPROVIDER "authprovider"
398 /** Defines auth code. */
399 #define OC_RSRVD_AUTHCODE "authcode"
401 /** Defines access token. */
402 #define OC_RSRVD_ACCESS_TOKEN "accesstoken"
404 /** Defines login. */
405 #define OC_RSRVD_LOGIN "login"
407 /** Defines search. */
408 #define OC_RSRVD_SEARCH "search"
410 /** Defines grant type. */
411 #define OC_RSRVD_GRANT_TYPE "granttype"
413 /** Defines refresh token. */
414 #define OC_RSRVD_REFRESH_TOKEN "refreshtoken"
416 /** Defines user UUID. */
417 #define OC_RSRVD_USER_UUID "uid"
419 /** Defines group ID. */
420 #define OC_RSRVD_GROUP_ID "gid"
422 /** Defines member of group ID. */
423 #define OC_RSRVD_MEMBER_ID "mid"
425 /** Defines invite. */
426 #define OC_RSRVD_INVITE "invite"
428 /** Defines accept. */
429 #define OC_RSRVD_ACCEPT "accept"
431 /** Defines operation. */
432 #define OC_RSRVD_OPERATION "op"
435 #define OC_RSRVD_ADD "add"
437 /** Defines delete. */
438 #define OC_RSRVD_DELETE "delete"
440 /** Defines owner. */
441 #define OC_RSRVD_OWNER "owner"
443 /** Defines members. */
444 #define OC_RSRVD_MEMBERS "members"
446 /** To represent grant type with refresh token. */
447 #define OC_RSRVD_GRANT_TYPE_REFRESH_TOKEN "refresh_token"
450 #define OC_RSRVD_PROV_CRL_URL "/oic/credprov/crl"
452 #define OC_RSRVD_LAST_UPDATE "lu"
454 #define OC_RSRVD_THIS_UPDATE "tu"
456 #define OC_RSRVD_NEXT_UPDATE "nu"
458 #define OC_RSRVD_SERIAL_NUMBERS "rcsn"
460 #define OC_RSRVD_CRL "crl"
462 #define OC_RSRVD_CRL_ID "crlid"
465 #define OC_RSRVD_GROUP_URL "/oic/group"
467 #define OC_RSRVD_ACL_GROUP_URL "/oic/acl/group"
469 #define OC_RSRVD_ACL_INVITE_URL "/oic/acl/invite"
471 #define OC_RSRVD_ACL_VERIFY_URL "/oic/acl/verify"
473 #define OC_RSRVD_ACL_ID_URL "/oic/acl/id"
475 #define OC_RSRVD_MEMBER_ID "mid"
477 #define OC_RSRVD_GROUP_ID "gid"
479 #define OC_RSRVD_OWNER_ID "oid"
481 #define OC_RSRVD_ACL_ID "aclid"
483 #define OC_RSRVD_ACE_ID "aceid"
485 #define OC_RSRVD_DEVICE_ID "di"
487 #define OC_RSRVD_SUBJECT_ID "sid"
489 #define OC_RSRVD_REQUEST_METHOD "rm"
491 #define OC_RSRVD_REQUEST_URI "uri"
493 #define OC_RSRVD_GROUP_MASTER_ID "gmid"
495 #define OC_RSRVD_GROUP_TYPE "gtype"
497 #define OC_RSRVD_SUBJECT_TYPE "stype"
499 #define OC_RSRVD_GROUP_ID_LIST "gidlist"
501 #define OC_RSRVD_MEMBER_ID_LIST "midlist"
503 #define OC_RSRVD_DEVICE_ID_LIST "dilist"
505 #define OC_RSRVD_ACCESS_CONTROL_LIST "aclist"
507 #define OC_RSRVD_RESOURCES "resources"
509 #define OC_RSRVD_VALIDITY "validity"
511 #define OC_RSRVD_PERIOD "period"
513 #define OC_RSRVD_RECURRENCE "recurrence"
515 #define OC_RSRVD_INVITE "invite"
517 #define OC_RSRVD_INVITED "invited"
519 #define OC_RSRVD_ENCODING "encoding"
521 #define OC_OIC_SEC "oic.sec"
523 #define OC_RSRVD_BASE64 "base64"
525 #define OC_RSRVD_DER "der"
527 #define OC_RSRVD_PEM "pem"
529 #define OC_RSRVD_RAW "raw"
531 #define OC_RSRVD_UNKNOWN "unknown"
533 #define OC_RSRVD_DATA "data"
535 #define OC_RSRVD_RESOURCE_OWNER_UUID "rowneruuid"
537 #define OC_RSRVD_SUBJECT_UUID "subjectuuid"
539 #define OC_RSRVD_PERMISSION_MASK "permission"
541 #define OC_RSRVD_GROUP_PERMISSION "gp"
543 #define OC_RSRVD_GROUP_ACL "gacl"
545 /** Certificete Sign Request */
546 #define OC_RSRVD_PROV_CERT_URI "/oic/credprov/cert"
548 #define OC_RSRVD_CSR "csr"
550 #define OC_RSRVD_CERT "cert"
552 #define OC_RSRVD_CACERT "certchain"
554 #define OC_RSRVD_TOKEN_TYPE "tokentype"
556 #define OC_RSRVD_EXPIRES_IN "expiresin"
558 #define OC_RSRVD_REDIRECT_URI "redirecturi"
560 #define OC_RSRVD_CERTIFICATE "certificate"
562 * Mark a parameter as unused. Used to prevent unused variable compiler warnings.
563 * Used in three cases:
564 * 1. in callbacks when one of the parameters are unused
565 * 2. when due to code changes a functions parameter is no longer
566 * used but must be left in place for backward compatibility
568 * 3. a variable is only used in the debug build variant and would
569 * give a build warning in release mode.
571 #define OC_UNUSED(x) (void)(x)
574 * These enums (OCTransportAdapter and OCTransportFlags) must
575 * be kept synchronized with OCConnectivityType (below) as well as
576 * CATransportAdapter and CATransportFlags (in CACommon.h).
580 /** value zero indicates discovery.*/
581 OC_DEFAULT_ADAPTER = 0,
583 /** IPv4 and IPv6, including 6LoWPAN.*/
584 OC_ADAPTER_IP = (1 << 0),
586 /** GATT over Bluetooth LE.*/
587 OC_ADAPTER_GATT_BTLE = (1 << 1),
589 /** RFCOMM over Bluetooth EDR.*/
590 OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
592 /**Remote Access over XMPP.*/
593 OC_ADAPTER_REMOTE_ACCESS = (1 << 3),
596 OC_ADAPTER_TCP = (1 << 4),
598 /** NFC Transport for Messaging.*/
599 OC_ADAPTER_NFC = (1 << 5)
600 } OCTransportAdapter;
603 * Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
607 /** default flag is 0*/
608 OC_DEFAULT_FLAGS = 0,
610 /** Insecure transport is the default (subject to change).*/
611 /** secure the transport path*/
612 OC_FLAG_SECURE = (1 << 4),
614 /** IPv4 & IPv6 auto-selection is the default.*/
615 /** IP & TCP adapter only.*/
616 OC_IP_USE_V6 = (1 << 5),
618 /** IP & TCP adapter only.*/
619 OC_IP_USE_V4 = (1 << 6),
621 /** Multicast only.*/
622 OC_MULTICAST = (1 << 7),
624 /** Link-Local multicast is the default multicast scope for IPv6.
625 * These are placed here to correspond to the IPv6 multicast address bits.*/
627 /** IPv6 Interface-Local scope (loopback).*/
628 OC_SCOPE_INTERFACE = 0x1,
630 /** IPv6 Link-Local scope (default).*/
633 /** IPv6 Realm-Local scope. */
634 OC_SCOPE_REALM = 0x3,
636 /** IPv6 Admin-Local scope. */
637 OC_SCOPE_ADMIN = 0x4,
639 /** IPv6 Site-Local scope. */
642 /** IPv6 Organization-Local scope. */
645 /**IPv6 Global scope. */
646 OC_SCOPE_GLOBAL = 0xE,
650 /** Bit mask for scope.*/
651 #define OC_MASK_SCOPE (0x000F)
653 /** Bit mask for Mods.*/
654 #define OC_MASK_MODS (0x0FF0)
655 #define OC_MASK_FAMS (OC_IP_USE_V6|OC_IP_USE_V4)
657 typedef struct OCStringLL
659 struct OCStringLL *next;
664 * End point identity.
668 /** Identity Length */
671 /** Array of end point identity.*/
672 unsigned char id[MAX_IDENTITY_SIZE];
676 * Universally unique identifier.
680 /** identitifier string.*/
681 unsigned char id[UUID_IDENTITY_SIZE];
685 * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
686 * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
691 OCTransportAdapter adapter;
693 /** transport modifiers.*/
694 OCTransportFlags flags;
699 /** address for all adapters.*/
700 char addr[MAX_ADDR_STR_SIZE];
702 /** usually zero for default interface.*/
704 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
705 char routeData[MAX_ADDR_STR_SIZE]; //destination GatewayID:ClientId
710 * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
711 * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
712 * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
715 * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
719 /** use when defaults are ok. */
722 /** IPv4 and IPv6, including 6LoWPAN.*/
723 CT_ADAPTER_IP = (1 << 16),
725 /** GATT over Bluetooth LE.*/
726 CT_ADAPTER_GATT_BTLE = (1 << 17),
728 /** RFCOMM over Bluetooth EDR.*/
729 CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
732 /** Remote Access over XMPP.*/
733 CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
736 CT_ADAPTER_TCP = (1 << 20),
739 CT_ADAPTER_NFC = (1 << 21),
741 /** Insecure transport is the default (subject to change).*/
743 /** secure the transport path.*/
744 CT_FLAG_SECURE = (1 << 4),
746 /** IPv4 & IPv6 autoselection is the default.*/
748 /** IP adapter only.*/
749 CT_IP_USE_V6 = (1 << 5),
751 /** IP adapter only.*/
752 CT_IP_USE_V4 = (1 << 6),
754 /** Link-Local multicast is the default multicast scope for IPv6.
755 * These are placed here to correspond to the IPv6 address bits.*/
757 /** IPv6 Interface-Local scope(loopback).*/
758 CT_SCOPE_INTERFACE = 0x1,
760 /** IPv6 Link-Local scope (default).*/
763 /** IPv6 Realm-Local scope.*/
764 CT_SCOPE_REALM = 0x3,
766 /** IPv6 Admin-Local scope.*/
767 CT_SCOPE_ADMIN = 0x4,
769 /** IPv6 Site-Local scope.*/
772 /** IPv6 Organization-Local scope.*/
775 /** IPv6 Global scope.*/
776 CT_SCOPE_GLOBAL = 0xE,
777 } OCConnectivityType;
779 /** bit shift required for connectivity adapter.*/
780 #define CT_ADAPTER_SHIFT 16
783 #define CT_MASK_FLAGS 0xFFFF
786 #define CT_MASK_ADAPTER 0xFFFF0000
789 * OCDoResource methods to dispatch the request
793 OC_REST_NOMETHOD = 0,
796 OC_REST_GET = (1 << 0),
799 OC_REST_PUT = (1 << 1),
802 OC_REST_POST = (1 << 2),
805 OC_REST_DELETE = (1 << 3),
807 /** Register observe request for most up date notifications ONLY.*/
808 OC_REST_OBSERVE = (1 << 4),
810 /** Register observe request for all notifications, including stale notifications.*/
811 OC_REST_OBSERVE_ALL = (1 << 5),
814 /** Subscribe for all presence notifications of a particular resource.*/
815 OC_REST_PRESENCE = (1 << 7),
818 /** Allows OCDoResource caller to do discovery.*/
819 OC_REST_DISCOVER = (1 << 8)
823 * Formats for payload encoding.
830 OC_FORMAT_UNSUPPORTED,
834 * Host Mode of Operation.
841 OC_GATEWAY /**< Client server mode along with routing capabilities.*/
845 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
846 * protocol. The precise definitions of each quality of service level depend on the
847 * implementation. In descriptions below are for the current implementation and may changed
852 /** Packet delivery is best effort.*/
855 /** Packet delivery is best effort.*/
858 /** Acknowledgments are used to confirm delivery.*/
861 /** No Quality is defined, let the stack decide.*/
863 } OCQualityOfService;
866 * Resource Properties.
867 * The value of a policy property is defined as bitmap.
868 * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
869 * Not including the policy property is equivalent to zero.
874 /** When none of the bits are set, the resource is non-discoverable &
875 * non-observable by the client.*/
876 OC_RES_PROP_NONE = (0),
878 /** When this bit is set, the resource is allowed to be discovered by clients.*/
879 OC_DISCOVERABLE = (1 << 0),
881 /** When this bit is set, the resource is allowed to be observed by clients.*/
882 OC_OBSERVABLE = (1 << 1),
884 /** When this bit is set, the resource is initialized, otherwise the resource
885 * is 'inactive'. 'inactive' signifies that the resource has been marked for
886 * deletion or is already deleted.*/
887 OC_ACTIVE = (1 << 2),
889 /** When this bit is set, the resource has been marked as 'slow'.
890 * 'slow' signifies that responses from this resource can expect delays in
891 * processing its requests from clients.*/
894 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
895 /** When this bit is set, the resource is a secure resource.*/
896 OC_SECURE = (1 << 4),
901 /** When this bit is set, the resource is allowed to be discovered only
902 * if discovery request contains an explicit querystring.
903 * Ex: GET /oic/res?rt=oic.sec.acl */
904 OC_EXPLICIT_DISCOVERABLE = (1 << 5)
907 /** When this bit is set, the resource is allowed to be published */
908 ,OC_MQ_PUBLISHER = (1 << 6)
912 /** When this bit is set, the resource is allowed to be notified as MQ broker.*/
913 ,OC_MQ_BROKER = (1 << 7)
915 } OCResourceProperty;
918 * Transport Protocol IDs.
922 /** For invalid ID.*/
923 OC_INVALID_ID = (1 << 0),
926 OC_COAP_ID = (1 << 1)
927 } OCTransportProtocolID;
930 * Declares Stack Results & Errors.
934 /** Success status code - START HERE.*/
936 OC_STACK_RESOURCE_CREATED,
937 OC_STACK_RESOURCE_DELETED,
939 OC_STACK_RESOURCE_CHANGED,
940 /** Success status code - END HERE.*/
942 /** Error status code - START HERE.*/
943 OC_STACK_INVALID_URI = 20,
944 OC_STACK_INVALID_QUERY,
946 OC_STACK_INVALID_PORT,
947 OC_STACK_INVALID_CALLBACK,
948 OC_STACK_INVALID_METHOD,
950 /** Invalid parameter.*/
951 OC_STACK_INVALID_PARAM,
952 OC_STACK_INVALID_OBSERVE_PARAM,
956 OC_STACK_ADAPTER_NOT_ENABLED,
959 /** Resource not found.*/
960 OC_STACK_NO_RESOURCE,
962 /** e.g: not supported method or interface.*/
963 OC_STACK_RESOURCE_ERROR,
964 OC_STACK_SLOW_RESOURCE,
965 OC_STACK_DUPLICATE_REQUEST,
967 /** Resource has no registered observers.*/
968 OC_STACK_NO_OBSERVERS,
969 OC_STACK_OBSERVER_NOT_FOUND,
970 OC_STACK_VIRTUAL_DO_NOT_HANDLE,
971 OC_STACK_INVALID_OPTION,
973 /** The remote reply contained malformed data.*/
974 OC_STACK_MALFORMED_RESPONSE,
975 OC_STACK_PERSISTENT_BUFFER_REQUIRED,
976 OC_STACK_INVALID_REQUEST_HANDLE,
977 OC_STACK_INVALID_DEVICE_INFO,
978 OC_STACK_INVALID_JSON,
980 /** Request is not authorized by Resource Server. */
981 OC_STACK_UNAUTHORIZED_REQ,
982 OC_STACK_TOO_LARGE_REQ,
984 /** Error code from PDM */
985 OC_STACK_PDM_IS_NOT_INITIALIZED,
986 OC_STACK_DUPLICATE_UUID,
987 OC_STACK_INCONSISTENT_DB,
990 * Error code from OTM
991 * This error is pushed from DTLS interface when handshake failure happens
993 OC_STACK_AUTHENTICATION_FAILURE,
994 OC_STACK_NOT_ALLOWED_OXM,
996 /** Insert all new error codes here!.*/
998 OC_STACK_PRESENCE_STOPPED = 128,
999 OC_STACK_PRESENCE_TIMEOUT,
1000 OC_STACK_PRESENCE_DO_NOT_HANDLE,
1003 /** ERROR code from server */
1004 OC_STACK_FORBIDDEN_REQ, /** 403*/
1005 OC_STACK_INTERNAL_SERVER_ERROR, /** 500*/
1007 /** ERROR in stack.*/
1008 OC_STACK_ERROR = 255
1009 /** Error status code - END HERE.*/
1013 * Handle to an OCDoResource invocation.
1015 typedef void * OCDoHandle;
1018 * Handle to an OCResource object owned by the OCStack.
1020 typedef void * OCResourceHandle;
1023 * Handle to an OCRequest object owned by the OCStack.
1025 typedef uint32_t OCRequestHandle;
1028 * Unique identifier for each observation request. Used when observations are
1029 * registered or de-registered. Used by entity handler to signal specific
1030 * observers to be notified of resource changes.
1031 * There can be maximum of 256 observations per server.
1033 typedef uint8_t OCObservationId;
1036 * Sequence number is a 24 bit field,
1037 * per https://tools.ietf.org/html/rfc7641.
1039 #define MAX_SEQUENCE_NUMBER (0xFFFFFF)
1042 * Action associated with observation.
1047 OC_OBSERVE_REGISTER = 0,
1049 /** To Deregister. */
1050 OC_OBSERVE_DEREGISTER = 1,
1053 OC_OBSERVE_NO_OPTION = 2,
1059 * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
1060 * when it calls OCRegisterPersistentStorageHandler.
1061 * Persistent storage open handler points to default file path.
1062 * It should check file path and whether the file is symbolic link or no.
1063 * Application can point to appropriate SVR database path for it's IoTivity Server.
1066 /** Persistent storage file path.*/
1067 FILE* (* open)(const char *path, const char *mode);
1069 /** Persistent storage read handler.*/
1070 size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
1072 /** Persistent storage write handler.*/
1073 size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
1075 /** Persistent storage close handler.*/
1076 int (* close)(FILE *fp);
1078 /** Persistent storage unlink handler.*/
1079 int (* unlink)(const char *path);
1080 } OCPersistentStorage;
1083 * Possible returned values from entity handler.
1087 /** Action associated with observation request.*/
1088 OCObserveAction action;
1090 /** Identifier for observation being registered/deregistered.*/
1091 OCObservationId obsId;
1092 } OCObservationInfo;
1095 * Possible returned values from entity handler.
1102 OC_EH_RESOURCE_CREATED = 201,
1103 OC_EH_RESOURCE_DELETED = 202,
1105 OC_EH_CHANGED = 204,
1106 OC_EH_CONTENT = 205,
1107 OC_EH_BAD_REQ = 400,
1108 OC_EH_UNAUTHORIZED_REQ = 401,
1109 OC_EH_BAD_OPT = 402,
1110 OC_EH_FORBIDDEN = 403,
1111 OC_EH_RESOURCE_NOT_FOUND = 404,
1112 OC_EH_METHOD_NOT_ALLOWED = 405,
1113 OC_EH_NOT_ACCEPTABLE = 406,
1114 OC_EH_TOO_LARGE = 413,
1115 OC_EH_UNSUPPORTED_MEDIA_TYPE = 415,
1116 OC_EH_INTERNAL_SERVER_ERROR = 500,
1117 OC_EH_BAD_GATEWAY = 502,
1118 OC_EH_SERVICE_UNAVAILABLE = 503,
1119 OC_EH_RETRANSMIT_TIMEOUT = 504
1120 } OCEntityHandlerResult;
1123 * This structure will be used to define the vendor specific header options to be included
1124 * in communication packets.
1126 typedef struct OCHeaderOption
1128 /** The protocol ID this option applies to.*/
1129 OCTransportProtocolID protocolID;
1131 /** The header option ID which will be added to communication packets.*/
1134 /** its length 191.*/
1135 uint16_t optionLength;
1137 /** pointer to its data.*/
1138 uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
1140 #ifdef SUPPORTS_DEFAULT_CTOR
1141 OCHeaderOption() = default;
1142 OCHeaderOption(OCTransportProtocolID pid,
1145 const uint8_t* optData)
1148 optionLength(optlen)
1151 // parameter includes the null terminator.
1152 optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
1153 optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
1154 memcpy(optionData, optData, optionLength);
1155 optionData[optionLength - 1] = '\0';
1161 * This structure describes the platform properties. All non-Null properties will be
1162 * included in a platform discovery request.
1163 * @deprecated: Use OCSetPropertyValue to set platform value.
1170 /** Manufacturer name.*/
1171 char *manufacturerName;
1173 /** Manufacturer URL for platform property.*/
1174 char *manufacturerUrl;
1179 /** Manufacturer date.*/
1180 char *dateOfManufacture;
1182 /** Platform version.*/
1183 char *platformVersion;
1185 /** Operating system version.*/
1186 char *operatingSystemVersion;
1189 char *hardwareVersion;
1192 char *firmwareVersion;
1194 /** Platform support URL.*/
1203 * This structure is expected as input for device properties.
1204 * device name is mandatory and expected from the application.
1205 * device id of type UUID will be generated by the stack.
1206 * @deprecated: Use OCSetPropertyValue to set device value.
1210 /** Pointer to the device name.*/
1212 /** Pointer to the types.*/
1214 /** Pointer to the device specification version.*/
1216 /** Pointer to the device data model versions (in CSV format).*/
1217 OCStringLL *dataModelVersions;
1222 * callback for bound JID
1224 typedef void (*jid_bound_cb)(char *jid);
1227 * CA Remote Access information for XMPP Client
1232 char *hostname; /**< XMPP server hostname */
1233 uint16_t port; /**< XMPP server serivce port */
1234 char *xmpp_domain; /**< XMPP login domain */
1235 char *username; /**< login username */
1236 char *password; /**< login password */
1237 char *resource; /**< specific resource for login */
1238 char *user_jid; /**< specific JID for login */
1239 jid_bound_cb jidbound; /**< callback when JID bound */
1241 #endif /* RA_ADAPTER */
1244 /** Enum to describe the type of object held by the OCPayload object.*/
1247 /** Contents of the payload are invalid */
1248 PAYLOAD_TYPE_INVALID,
1249 /** The payload is an OCDiscoveryPayload */
1250 PAYLOAD_TYPE_DISCOVERY,
1251 /** The payload of the device */
1252 PAYLOAD_TYPE_DEVICE,
1253 /** The payload type of the platform */
1254 PAYLOAD_TYPE_PLATFORM,
1255 /** The payload is an OCRepPayload */
1256 PAYLOAD_TYPE_REPRESENTATION,
1257 /** The payload is an OCSecurityPayload */
1258 PAYLOAD_TYPE_SECURITY,
1259 /** The payload is an OCPresencePayload */
1260 PAYLOAD_TYPE_PRESENCE
1264 * A generic struct representing a payload returned from a resource operation
1266 * A pointer to OCPayLoad can be cast to a more specific struct to access members
1271 /** The type of message that was received */
1282 OCREP_PROP_BYTE_STRING,
1285 }OCRepPayloadPropType;
1287 /** This structure will be used to represent a binary string for CBOR payloads.*/
1290 /** pointer to data bytes.*/
1293 /** number of data bytes.*/
1297 #define MAX_REP_ARRAY_DEPTH 3
1300 OCRepPayloadPropType type;
1301 size_t dimensions[MAX_REP_ARRAY_DEPTH];
1310 /** pointer to ByteString array.*/
1311 OCByteString* ocByteStrArray;
1313 struct OCRepPayload** objArray;
1315 } OCRepPayloadValueArray;
1317 typedef struct OCRepPayloadValue
1320 OCRepPayloadPropType type;
1328 /** ByteString object.*/
1329 OCByteString ocByteStr;
1331 struct OCRepPayload* obj;
1332 OCRepPayloadValueArray arr;
1334 struct OCRepPayloadValue* next;
1336 } OCRepPayloadValue;
1338 // used for get/set/put/observe/etc representations
1339 typedef struct OCRepPayload
1344 OCStringLL* interfaces;
1345 OCRepPayloadValue* values;
1346 struct OCRepPayload* next;
1349 // used inside a discovery payload
1350 typedef struct OCResourcePayload
1354 OCStringLL* interfaces;
1361 struct OCResourcePayload* next;
1362 } OCResourcePayload;
1364 typedef struct OCDiscoveryPayload
1371 /** A special case for handling RD address. */
1380 /** Resource Type */
1386 /** This structure holds the old /oic/res response. */
1387 OCResourcePayload *resources;
1389 /** Holding address of the next DiscoveryPayload. */
1390 struct OCDiscoveryPayload *next;
1392 } OCDiscoveryPayload;
1397 uint8_t* securityData;
1399 } OCSecurityPayload;
1401 #ifdef WITH_PRESENCE
1405 uint32_t sequenceNumber;
1407 OCPresenceTrigger trigger;
1409 } OCPresencePayload;
1413 * Incoming requests handled by the server. Requests are passed in as a parameter to the
1414 * OCEntityHandler callback API.
1415 * The OCEntityHandler callback API must be implemented in the application in order
1416 * to receive these requests.
1420 /** Associated resource.*/
1421 OCResourceHandle resource;
1423 /** Associated request handle.*/
1424 OCRequestHandle requestHandle;
1426 /** the REST method retrieved from received request PDU.*/
1429 /** description of endpoint that sent the request.*/
1432 /** resource query send by client.*/
1435 /** Information associated with observation - valid only when OCEntityHandler flag includes
1436 * ::OC_OBSERVE_FLAG.*/
1437 OCObservationInfo obsInfo;
1439 /** Number of the received vendor specific header options.*/
1440 uint8_t numRcvdVendorSpecificHeaderOptions;
1442 /** Pointer to the array of the received vendor specific header options.*/
1443 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1448 /** the payload from the request PDU.*/
1451 } OCEntityHandlerRequest;
1455 * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1459 /** Address of remote server.*/
1462 /** backward compatibility (points to devAddr).*/
1465 /** backward compatibility.*/
1466 OCConnectivityType connType;
1468 /** the security identity of the remote server.*/
1469 OCIdentity identity;
1471 /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1472 OCStackResult result;
1474 /** If associated with observe, this will represent the sequence of notifications from server.*/
1475 uint32_t sequenceNumber;
1478 const char * resourceUri;
1480 /** the payload for the response PDU.*/
1483 /** Number of the received vendor specific header options.*/
1484 uint8_t numRcvdVendorSpecificHeaderOptions;
1486 /** An array of the received vendor specific header options.*/
1487 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1491 * Request handle is passed to server via the entity handler for each incoming request.
1492 * Stack assigns when request is received, server sets to indicate what request response is for.
1496 /** Request handle.*/
1497 OCRequestHandle requestHandle;
1499 /** Resource handle.*/
1500 OCResourceHandle resourceHandle;
1502 /** Allow the entity handler to pass a result with the response.*/
1503 OCEntityHandlerResult ehResult;
1505 /** This is the pointer to server payload data to be transferred.*/
1508 /** number of the vendor specific header options .*/
1509 uint8_t numSendVendorSpecificHeaderOptions;
1511 /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1512 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1514 /** URI of new resource that entity handler might create.*/
1515 char resourceUri[MAX_URI_LENGTH];
1517 /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1518 uint8_t persistentBufferFlag;
1519 } OCEntityHandlerResponse;
1526 /** Request state.*/
1527 OC_REQUEST_FLAG = (1 << 1),
1528 /** Observe state.*/
1529 OC_OBSERVE_FLAG = (1 << 2)
1530 } OCEntityHandlerFlag;
1533 * Possible return values from client application callback
1535 * A client application callback returns an OCStackApplicationResult to indicate whether
1536 * the stack should continue to keep the callback registered.
1540 /** Make no more calls to the callback and call the OCClientContextDeleter for this callback */
1541 OC_STACK_DELETE_TRANSACTION = 0,
1542 /** Keep this callback registered and call it if an apropriate event occurs */
1543 OC_STACK_KEEP_TRANSACTION
1544 } OCStackApplicationResult;
1547 //#ifdef DIRECT_PAIRING
1549 * @brief direct pairing Method Type.
1551 * 1: pre-configured pin
1556 DP_NOT_ALLOWED = 0x0,
1557 DP_PRE_CONFIGURED = (0x1 << 0),
1558 DP_RANDOM_PIN = (0x1 << 1),
1562 * Device Information of discoverd direct pairing device(s).
1564 typedef struct OCDPDev
1567 OCConnectivityType connType;
1568 uint16_t securePort;
1572 OCUUIdentity deviceID;
1573 OCUUIdentity rowner;
1574 struct OCDPDev *next;
1576 //#endif // DIRECT_PAIRING
1579 * -------------------------------------------------------------------------------------------
1580 * Callback function definitions
1581 * -------------------------------------------------------------------------------------------
1585 * Client applications implement this callback to consume responses received from Servers.
1587 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1588 OCClientResponse * clientResponse);
1591 * Client applications using a context pointer implement this callback to delete the
1592 * context upon removal of the callback/context pointer from the internal callback-list.
1594 typedef void (* OCClientContextDeleter)(void *context);
1597 * This info is passed from application to OC Stack when initiating a request to Server.
1599 typedef struct OCCallbackData
1601 /** Pointer to the context.*/
1604 /** The pointer to a function the stack will call to handle the requests.*/
1605 OCClientResponseHandler cb;
1607 /** A pointer to a function to delete the context when this callback is removed.*/
1608 OCClientContextDeleter cd;
1610 #ifdef SUPPORTS_DEFAULT_CTOR
1611 OCCallbackData() = default;
1612 OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1613 :context(ctx), cb(callback), cd(deleter){}
1618 * Application server implementations must implement this callback to consume requests OTA.
1619 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1621 * When you set specific return value like OC_EH_CHANGED, OC_EH_CONTENT,
1622 * OC_EH_SLOW and etc in entity handler callback,
1623 * ocstack will be not send response automatically to client
1624 * except for error return value like OC_EH_ERROR.
1626 * If you want to send response to client with specific result,
1627 * OCDoResponse API should be called with the result value.
1631 * OCEntityHandlerResponse response;
1635 * response.ehResult = OC_EH_CHANGED;
1639 * OCDoResponse(&response)
1645 typedef OCEntityHandlerResult (*OCEntityHandler)
1646 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1649 * Device Entity handler need to use this call back instead of OCEntityHandler.
1651 * When you set specific return value like OC_EH_CHANGED, OC_EH_CONTENT,
1652 * OC_EH_SLOW and etc in entity handler callback,
1653 * ocstack will be not send response automatically to client
1654 * except for error return value like OC_EH_ERROR.
1656 * If you want to send response to client with specific result,
1657 * OCDoResponse API should be called with the result value.
1661 * OCEntityHandlerResponse response;
1665 * response.ehResult = OC_EH_CHANGED;
1669 * OCDoResponse(&response)
1675 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1676 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1678 //#ifdef DIRECT_PAIRING
1680 * Callback function definition of direct-pairing
1682 * @param[OUT] ctx - user context returned in the callback.
1683 * @param[OUT] peer - pairing device info.
1684 * @param[OUT] result - It's returned with 'OC_STACK_XXX'. It will return 'OC_STACK_OK'
1685 * if D2D pairing is success without error
1687 typedef void (*OCDirectPairingCB)(void *ctx, OCDPDev_t *peer, OCStackResult result);
1688 //#endif // DIRECT_PAIRING
1690 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
1692 * Callback function definition for Change in TrustCertChain
1694 * @param[IN] ctx - user context returned in the callback.
1695 * @param[IN] credId - trustCertChain changed for this ID
1696 * @param[IN] trustCertChain - trustcertchain binary blob.
1697 * @param[IN] chainSize - size of trustchain
1699 typedef void (*TrustCertChainChangeCB)(void *ctx, uint16_t credId, uint8_t *trustCertChain,
1703 * certChain context structure.
1705 typedef struct trustCertChainContext
1707 TrustCertChainChangeCB callback;
1709 } trustCertChainContext_t;
1714 #endif // __cplusplus
1716 #endif /* OCTYPES_H_ */