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 RES.*/
158 #define OC_RSRVD_RESOURCE_TYPE_RES "oic.wk.res"
160 /** To represent content type with MQ Broker.*/
161 #define OC_RSRVD_RESOURCE_TYPE_MQ_BROKER "oic.wk.ps"
163 /** To represent content type with MQ Topic.*/
164 #define OC_RSRVD_RESOURCE_TYPE_MQ_TOPIC "oic.wk.ps.topic"
167 /** To represent interface.*/
168 #define OC_RSRVD_INTERFACE "if"
170 /** To indicate how long RD should publish this item.*/
171 #define OC_RSRVD_DEVICE_TTL "lt"
173 /** To represent time to live.*/
174 #define OC_RSRVD_TTL "ttl"
176 /** To represent non*/
177 #define OC_RSRVD_NONCE "non"
179 /** To represent trigger type.*/
180 #define OC_RSRVD_TRIGGER "trg"
182 /** To represent links.*/
183 #define OC_RSRVD_LINKS "links"
185 /** To represent default interface.*/
186 #define OC_RSRVD_INTERFACE_DEFAULT "oic.if.baseline"
188 /** To represent read-only interface.*/
189 #define OC_RSRVD_INTERFACE_READ "oic.if.r"
191 /** To represent ll interface.*/
192 #define OC_RSRVD_INTERFACE_LL "oic.if.ll"
194 /** To represent batch interface.*/
195 #define OC_RSRVD_INTERFACE_BATCH "oic.if.b"
197 /** To represent interface group.*/
198 #define OC_RSRVD_INTERFACE_GROUP "oic.mi.grp"
200 /** To represent MFG date.*/
201 #define OC_RSRVD_MFG_DATE "mndt"
203 /** To represent FW version.*/
204 #define OC_RSRVD_FW_VERSION "mnfv"
206 /** To represent host name.*/
207 #define OC_RSRVD_HOST_NAME "hn"
209 /** To represent policy.*/
210 #define OC_RSRVD_POLICY "p"
212 /** To represent bitmap.*/
213 #define OC_RSRVD_BITMAP "bm"
216 #define OC_RSRVD_SECURE "sec"
219 #define OC_RSRVD_HOSTING_PORT "port"
222 #define OC_RSRVD_TCP_PORT "tcp"
224 /** For Server instance ID.*/
225 #define OC_RSRVD_SERVER_INSTANCE_ID "sid"
232 #define OC_RSRVD_PLATFORM_ID "pi"
234 /** Platform MFG NAME. */
235 #define OC_RSRVD_MFG_NAME "mnmn"
238 #define OC_RSRVD_MFG_URL "mnml"
241 #define OC_RSRVD_MODEL_NUM "mnmo"
243 /** Platform MFG Date.*/
244 #define OC_RSRVD_MFG_DATE "mndt"
246 /** Platform versio.n */
247 #define OC_RSRVD_PLATFORM_VERSION "mnpv"
249 /** Platform Operating system version. */
250 #define OC_RSRVD_OS_VERSION "mnos"
252 /** Platform Hardware version. */
253 #define OC_RSRVD_HARDWARE_VERSION "mnhw"
255 /**Platform Firmware version. */
256 #define OC_RSRVD_FIRMWARE_VERSION "mnfv"
258 /** Support URL for the platform. */
259 #define OC_RSRVD_SUPPORT_URL "mnsl"
261 /** System time for the platform. */
262 #define OC_RSRVD_SYSTEM_TIME "st"
264 /** VID for the platform. */
265 #define OC_RSRVD_VID "vid"
271 #define OC_RSRVD_DEVICE_ID "di"
274 #define OC_RSRVD_DEVICE_NAME "n"
276 /** Device specification version.*/
277 #define OC_RSRVD_SPEC_VERSION "icv"
279 /** Device data model.*/
280 #define OC_RSRVD_DATA_MODEL_VERSION "dmv"
282 /** Device specification version.*/
283 #define OC_SPEC_VERSION "core.1.1.0"
285 /** Device Data Model version.*/
286 #define OC_DATA_MODEL_VERSION "res.1.1.0,sh.1.2.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"
336 /** Resource URI used to discover Proxy */
337 #define OC_RSRVD_PROXY_URI "/oic/chp"
339 /** Resource URI used to discover Proxy */
340 #define OC_RSRVD_PROXY_OPTION_ID 35
343 #define OC_RSRVD_BASE_URI "baseURI"
345 /** Unique value per collection/link. */
346 #define OC_RSRVD_INS "ins"
348 /** Allowable resource types in the links. */
349 #define OC_RSRVD_RTS "rts"
351 /** Default relationship. */
352 #define OC_RSRVD_DREL "drel"
354 /** Defines relationship between links. */
355 #define OC_RSRVD_REL "rel"
357 /** Defines title. */
358 #define OC_RSRVD_TITLE "title"
361 #define OC_RSRVD_URI "anchor"
363 /** Defines media type. */
364 #define OC_RSRVD_MEDIA_TYPE "type"
366 /** To represent resource type with Publish RD.*/
367 #define OC_RSRVD_RESOURCE_TYPE_RDPUBLISH "oic.wk.rdpub"
372 #define OC_RSRVD_ACCOUNT_URI "/oic/account"
374 /** Account user URI.*/
375 #define OC_RSRVD_ACCOUNT_SEARCH_URI "/oic/account/search"
377 /** Account session URI.*/
378 #define OC_RSRVD_ACCOUNT_SESSION_URI "/oic/account/session"
380 /** Account token refresh URI.*/
381 #define OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI "/oic/account/tokenrefresh"
384 #define OC_RSRVD_ACL_GROUP_URI "/oic/acl/group"
386 /** ACL invite URI.*/
387 #define OC_RSRVD_ACL_INVITE_URI "/oic/acl/invite"
389 /** Defines auth provider. */
390 #define OC_RSRVD_AUTHPROVIDER "authprovider"
392 /** Defines auth code. */
393 #define OC_RSRVD_AUTHCODE "authcode"
395 /** Defines access token. */
396 #define OC_RSRVD_ACCESS_TOKEN "accesstoken"
398 /** Defines login. */
399 #define OC_RSRVD_LOGIN "login"
401 /** Defines search. */
402 #define OC_RSRVD_SEARCH "search"
404 /** Defines grant type. */
405 #define OC_RSRVD_GRANT_TYPE "granttype"
407 /** Defines refresh token. */
408 #define OC_RSRVD_REFRESH_TOKEN "refreshtoken"
410 /** Defines user UUID. */
411 #define OC_RSRVD_USER_UUID "uid"
413 /** Defines group ID. */
414 #define OC_RSRVD_GROUP_ID "gid"
416 /** Defines member of group ID. */
417 #define OC_RSRVD_MEMBER_ID "mid"
419 /** Defines invite. */
420 #define OC_RSRVD_INVITE "invite"
422 /** Defines accept. */
423 #define OC_RSRVD_ACCEPT "accept"
425 /** Defines operation. */
426 #define OC_RSRVD_OPERATION "op"
429 #define OC_RSRVD_ADD "add"
431 /** Defines delete. */
432 #define OC_RSRVD_DELETE "delete"
434 /** Defines owner. */
435 #define OC_RSRVD_OWNER "owner"
437 /** Defines members. */
438 #define OC_RSRVD_MEMBERS "members"
440 /** To represent grant type with refresh token. */
441 #define OC_RSRVD_GRANT_TYPE_REFRESH_TOKEN "refresh_token"
444 #define OC_RSRVD_PROV_CRL_URL "/oic/credprov/crl"
446 #define OC_RSRVD_LAST_UPDATE "lu"
448 #define OC_RSRVD_THIS_UPDATE "tu"
450 #define OC_RSRVD_NEXT_UPDATE "nu"
452 #define OC_RSRVD_SERIAL_NUMBERS "rcsn"
454 #define OC_RSRVD_CRL "crl"
456 #define OC_RSRVD_CRL_ID "crlid"
459 #define OC_RSRVD_GROUP_URL "/oic/group"
461 #define OC_RSRVD_ACL_GROUP_URL "/oic/acl/group"
463 #define OC_RSRVD_ACL_INVITE_URL "/oic/acl/invite"
465 #define OC_RSRVD_ACL_VERIFY_URL "/oic/acl/verify"
467 #define OC_RSRVD_ACL_ID_URL "/oic/acl/id"
469 #define OC_RSRVD_MEMBER_ID "mid"
471 #define OC_RSRVD_GROUP_ID "gid"
473 #define OC_RSRVD_OWNER_ID "oid"
475 #define OC_RSRVD_ACL_ID "aclid"
477 #define OC_RSRVD_ACE_ID "aceid"
479 #define OC_RSRVD_DEVICE_ID "di"
481 #define OC_RSRVD_SUBJECT_ID "sid"
483 #define OC_RSRVD_REQUEST_METHOD "rm"
485 #define OC_RSRVD_REQUEST_URI "uri"
487 #define OC_RSRVD_GROUP_MASTER_ID "gmid"
489 #define OC_RSRVD_GROUP_TYPE "gtype"
491 #define OC_RSRVD_SUBJECT_TYPE "stype"
493 #define OC_RSRVD_GROUP_ID_LIST "gidlist"
495 #define OC_RSRVD_MEMBER_ID_LIST "midlist"
497 #define OC_RSRVD_DEVICE_ID_LIST "dilist"
499 #define OC_RSRVD_ACCESS_CONTROL_LIST "aclist"
501 #define OC_RSRVD_RESOURCES "resources"
503 #define OC_RSRVD_VALIDITY "validity"
505 #define OC_RSRVD_PERIOD "period"
507 #define OC_RSRVD_RECURRENCE "recurrence"
509 #define OC_RSRVD_INVITE "invite"
511 #define OC_RSRVD_INVITED "invited"
513 #define OC_RSRVD_ENCODING "encoding"
515 #define OC_OIC_SEC "oic.sec"
517 #define OC_RSRVD_BASE64 "base64"
519 #define OC_RSRVD_DER "der"
521 #define OC_RSRVD_PEM "pem"
523 #define OC_RSRVD_RAW "raw"
525 #define OC_RSRVD_UNKNOWN "unknown"
527 #define OC_RSRVD_DATA "data"
529 #define OC_RSRVD_RESOURCE_OWNER_UUID "rowneruuid"
531 #define OC_RSRVD_SUBJECT_UUID "subjectuuid"
533 #define OC_RSRVD_PERMISSION_MASK "permission"
535 #define OC_RSRVD_GROUP_PERMISSION "gp"
537 #define OC_RSRVD_GROUP_ACL "gacl"
539 /** Certificete Sign Request */
540 #define OC_RSRVD_PROV_CERT_URI "/oic/credprov/cert"
542 #define OC_RSRVD_CSR "csr"
544 #define OC_RSRVD_CERT "cert"
546 #define OC_RSRVD_CACERT "certchain"
548 #define OC_RSRVD_TOKEN_TYPE "tokentype"
550 #define OC_RSRVD_EXPIRES_IN "expiresin"
552 #define OC_RSRVD_REDIRECT_URI "redirecturi"
554 #define OC_RSRVD_CERTIFICATE "certificate"
556 * Mark a parameter as unused. Used to prevent unused variable compiler warnings.
557 * Used in three cases:
558 * 1. in callbacks when one of the parameters are unused
559 * 2. when due to code changes a functions parameter is no longer
560 * used but must be left in place for backward compatibility
562 * 3. a variable is only used in the debug build variant and would
563 * give a build warning in release mode.
565 #define OC_UNUSED(x) (void)(x)
568 * These enums (OCTransportAdapter and OCTransportFlags) must
569 * be kept synchronized with OCConnectivityType (below) as well as
570 * CATransportAdapter and CATransportFlags (in CACommon.h).
574 /** value zero indicates discovery.*/
575 OC_DEFAULT_ADAPTER = 0,
577 /** IPv4 and IPv6, including 6LoWPAN.*/
578 OC_ADAPTER_IP = (1 << 0),
580 /** GATT over Bluetooth LE.*/
581 OC_ADAPTER_GATT_BTLE = (1 << 1),
583 /** RFCOMM over Bluetooth EDR.*/
584 OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
586 /**Remote Access over XMPP.*/
587 OC_ADAPTER_REMOTE_ACCESS = (1 << 3),
590 OC_ADAPTER_TCP = (1 << 4),
592 /** NFC Transport for Messaging.*/
593 OC_ADAPTER_NFC = (1 << 5)
594 } OCTransportAdapter;
597 * Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
601 /** default flag is 0*/
602 OC_DEFAULT_FLAGS = 0,
604 /** Insecure transport is the default (subject to change).*/
605 /** secure the transport path*/
606 OC_FLAG_SECURE = (1 << 4),
608 /** IPv4 & IPv6 auto-selection is the default.*/
609 /** IP & TCP adapter only.*/
610 OC_IP_USE_V6 = (1 << 5),
612 /** IP & TCP adapter only.*/
613 OC_IP_USE_V4 = (1 << 6),
615 /** Multicast only.*/
616 OC_MULTICAST = (1 << 7),
618 /** Link-Local multicast is the default multicast scope for IPv6.
619 * These are placed here to correspond to the IPv6 multicast address bits.*/
621 /** IPv6 Interface-Local scope (loopback).*/
622 OC_SCOPE_INTERFACE = 0x1,
624 /** IPv6 Link-Local scope (default).*/
627 /** IPv6 Realm-Local scope. */
628 OC_SCOPE_REALM = 0x3,
630 /** IPv6 Admin-Local scope. */
631 OC_SCOPE_ADMIN = 0x4,
633 /** IPv6 Site-Local scope. */
636 /** IPv6 Organization-Local scope. */
639 /**IPv6 Global scope. */
640 OC_SCOPE_GLOBAL = 0xE,
644 /** Bit mask for scope.*/
645 #define OC_MASK_SCOPE (0x000F)
647 /** Bit mask for Mods.*/
648 #define OC_MASK_MODS (0x0FF0)
649 #define OC_MASK_FAMS (OC_IP_USE_V6|OC_IP_USE_V4)
651 typedef struct OCStringLL
653 struct OCStringLL *next;
658 * End point identity.
662 /** Identity Length */
665 /** Array of end point identity.*/
666 unsigned char id[MAX_IDENTITY_SIZE];
670 * Universally unique identifier.
674 /** identitifier string.*/
675 unsigned char id[UUID_IDENTITY_SIZE];
679 * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
680 * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
685 OCTransportAdapter adapter;
687 /** transport modifiers.*/
688 OCTransportFlags flags;
693 /** address for all adapters.*/
694 char addr[MAX_ADDR_STR_SIZE];
696 /** usually zero for default interface.*/
698 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
699 char routeData[MAX_ADDR_STR_SIZE]; //destination GatewayID:ClientId
704 * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
705 * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
706 * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
709 * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
713 /** use when defaults are ok. */
716 /** IPv4 and IPv6, including 6LoWPAN.*/
717 CT_ADAPTER_IP = (1 << 16),
719 /** GATT over Bluetooth LE.*/
720 CT_ADAPTER_GATT_BTLE = (1 << 17),
722 /** RFCOMM over Bluetooth EDR.*/
723 CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
726 /** Remote Access over XMPP.*/
727 CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
730 CT_ADAPTER_TCP = (1 << 20),
733 CT_ADAPTER_NFC = (1 << 21),
735 /** Insecure transport is the default (subject to change).*/
737 /** secure the transport path.*/
738 CT_FLAG_SECURE = (1 << 4),
740 /** IPv4 & IPv6 autoselection is the default.*/
742 /** IP adapter only.*/
743 CT_IP_USE_V6 = (1 << 5),
745 /** IP adapter only.*/
746 CT_IP_USE_V4 = (1 << 6),
748 /** Link-Local multicast is the default multicast scope for IPv6.
749 * These are placed here to correspond to the IPv6 address bits.*/
751 /** IPv6 Interface-Local scope(loopback).*/
752 CT_SCOPE_INTERFACE = 0x1,
754 /** IPv6 Link-Local scope (default).*/
757 /** IPv6 Realm-Local scope.*/
758 CT_SCOPE_REALM = 0x3,
760 /** IPv6 Admin-Local scope.*/
761 CT_SCOPE_ADMIN = 0x4,
763 /** IPv6 Site-Local scope.*/
766 /** IPv6 Organization-Local scope.*/
769 /** IPv6 Global scope.*/
770 CT_SCOPE_GLOBAL = 0xE,
771 } OCConnectivityType;
773 /** bit shift required for connectivity adapter.*/
774 #define CT_ADAPTER_SHIFT 16
777 #define CT_MASK_FLAGS 0xFFFF
780 #define CT_MASK_ADAPTER 0xFFFF0000
783 * OCDoResource methods to dispatch the request
787 OC_REST_NOMETHOD = 0,
790 OC_REST_GET = (1 << 0),
793 OC_REST_PUT = (1 << 1),
796 OC_REST_POST = (1 << 2),
799 OC_REST_DELETE = (1 << 3),
801 /** Register observe request for most up date notifications ONLY.*/
802 OC_REST_OBSERVE = (1 << 4),
804 /** Register observe request for all notifications, including stale notifications.*/
805 OC_REST_OBSERVE_ALL = (1 << 5),
808 /** Subscribe for all presence notifications of a particular resource.*/
809 OC_REST_PRESENCE = (1 << 7),
812 /** Allows OCDoResource caller to do discovery.*/
813 OC_REST_DISCOVER = (1 << 8)
817 * Formats for payload encoding.
824 OC_FORMAT_UNSUPPORTED,
828 * Host Mode of Operation.
835 OC_GATEWAY /**< Client server mode along with routing capabilities.*/
839 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
840 * protocol. The precise definitions of each quality of service level depend on the
841 * implementation. In descriptions below are for the current implementation and may changed
846 /** Packet delivery is best effort.*/
849 /** Packet delivery is best effort.*/
852 /** Acknowledgments are used to confirm delivery.*/
855 /** No Quality is defined, let the stack decide.*/
857 } OCQualityOfService;
860 * Resource Properties.
861 * The value of a policy property is defined as bitmap.
862 * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
863 * Not including the policy property is equivalent to zero.
868 /** When none of the bits are set, the resource is non-discoverable &
869 * non-observable by the client.*/
870 OC_RES_PROP_NONE = (0),
872 /** When this bit is set, the resource is allowed to be discovered by clients.*/
873 OC_DISCOVERABLE = (1 << 0),
875 /** When this bit is set, the resource is allowed to be observed by clients.*/
876 OC_OBSERVABLE = (1 << 1),
878 /** When this bit is set, the resource is initialized, otherwise the resource
879 * is 'inactive'. 'inactive' signifies that the resource has been marked for
880 * deletion or is already deleted.*/
881 OC_ACTIVE = (1 << 2),
883 /** When this bit is set, the resource has been marked as 'slow'.
884 * 'slow' signifies that responses from this resource can expect delays in
885 * processing its requests from clients.*/
888 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
889 /** When this bit is set, the resource is a secure resource.*/
890 OC_SECURE = (1 << 4),
895 /** When this bit is set, the resource is allowed to be discovered only
896 * if discovery request contains an explicit querystring.
897 * Ex: GET /oic/res?rt=oic.sec.acl */
898 OC_EXPLICIT_DISCOVERABLE = (1 << 5)
901 /** When this bit is set, the resource is allowed to be published */
902 ,OC_MQ_PUBLISHER = (1 << 6)
906 /** When this bit is set, the resource is allowed to be notified as MQ broker.*/
907 ,OC_MQ_BROKER = (1 << 7)
909 } OCResourceProperty;
912 * Transport Protocol IDs.
916 /** For invalid ID.*/
917 OC_INVALID_ID = (1 << 0),
920 OC_COAP_ID = (1 << 1)
921 } OCTransportProtocolID;
924 * Declares Stack Results & Errors.
928 /** Success status code - START HERE.*/
930 OC_STACK_RESOURCE_CREATED,
931 OC_STACK_RESOURCE_DELETED,
933 OC_STACK_RESOURCE_CHANGED,
934 /** Success status code - END HERE.*/
936 /** Error status code - START HERE.*/
937 OC_STACK_INVALID_URI = 20,
938 OC_STACK_INVALID_QUERY,
940 OC_STACK_INVALID_PORT,
941 OC_STACK_INVALID_CALLBACK,
942 OC_STACK_INVALID_METHOD,
944 /** Invalid parameter.*/
945 OC_STACK_INVALID_PARAM,
946 OC_STACK_INVALID_OBSERVE_PARAM,
950 OC_STACK_ADAPTER_NOT_ENABLED,
953 /** Resource not found.*/
954 OC_STACK_NO_RESOURCE,
956 /** e.g: not supported method or interface.*/
957 OC_STACK_RESOURCE_ERROR,
958 OC_STACK_SLOW_RESOURCE,
959 OC_STACK_DUPLICATE_REQUEST,
961 /** Resource has no registered observers.*/
962 OC_STACK_NO_OBSERVERS,
963 OC_STACK_OBSERVER_NOT_FOUND,
964 OC_STACK_VIRTUAL_DO_NOT_HANDLE,
965 OC_STACK_INVALID_OPTION,
967 /** The remote reply contained malformed data.*/
968 OC_STACK_MALFORMED_RESPONSE,
969 OC_STACK_PERSISTENT_BUFFER_REQUIRED,
970 OC_STACK_INVALID_REQUEST_HANDLE,
971 OC_STACK_INVALID_DEVICE_INFO,
972 OC_STACK_INVALID_JSON,
974 /** Request is not authorized by Resource Server. */
975 OC_STACK_UNAUTHORIZED_REQ,
976 OC_STACK_TOO_LARGE_REQ,
978 /** Error code from PDM */
979 OC_STACK_PDM_IS_NOT_INITIALIZED,
980 OC_STACK_DUPLICATE_UUID,
981 OC_STACK_INCONSISTENT_DB,
984 * Error code from OTM
985 * This error is pushed from DTLS interface when handshake failure happens
987 OC_STACK_AUTHENTICATION_FAILURE,
988 OC_STACK_NOT_ALLOWED_OXM,
990 /** Insert all new error codes here!.*/
992 OC_STACK_PRESENCE_STOPPED = 128,
993 OC_STACK_PRESENCE_TIMEOUT,
994 OC_STACK_PRESENCE_DO_NOT_HANDLE,
997 /** ERROR code from server */
998 OC_STACK_FORBIDDEN_REQ, /** 403*/
999 OC_STACK_INTERNAL_SERVER_ERROR, /** 500*/
1001 /** ERROR in stack.*/
1002 OC_STACK_ERROR = 255
1003 /** Error status code - END HERE.*/
1007 * Handle to an OCDoResource invocation.
1009 typedef void * OCDoHandle;
1012 * Handle to an OCResource object owned by the OCStack.
1014 typedef void * OCResourceHandle;
1017 * Handle to an OCRequest object owned by the OCStack.
1019 typedef uint32_t OCRequestHandle;
1022 * Unique identifier for each observation request. Used when observations are
1023 * registered or de-registered. Used by entity handler to signal specific
1024 * observers to be notified of resource changes.
1025 * There can be maximum of 256 observations per server.
1027 typedef uint8_t OCObservationId;
1030 * Sequence number is a 24 bit field,
1031 * per https://tools.ietf.org/html/rfc7641.
1033 #define MAX_SEQUENCE_NUMBER (0xFFFFFF)
1036 * Action associated with observation.
1041 OC_OBSERVE_REGISTER = 0,
1043 /** To Deregister. */
1044 OC_OBSERVE_DEREGISTER = 1,
1047 OC_OBSERVE_NO_OPTION = 2,
1053 * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
1054 * when it calls OCRegisterPersistentStorageHandler.
1055 * Persistent storage open handler points to default file path.
1056 * It should check file path and whether the file is symbolic link or no.
1057 * Application can point to appropriate SVR database path for it's IoTivity Server.
1060 /** Persistent storage file path.*/
1061 FILE* (* open)(const char *path, const char *mode);
1063 /** Persistent storage read handler.*/
1064 size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
1066 /** Persistent storage write handler.*/
1067 size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
1069 /** Persistent storage close handler.*/
1070 int (* close)(FILE *fp);
1072 /** Persistent storage unlink handler.*/
1073 int (* unlink)(const char *path);
1074 } OCPersistentStorage;
1077 * Possible returned values from entity handler.
1081 /** Action associated with observation request.*/
1082 OCObserveAction action;
1084 /** Identifier for observation being registered/deregistered.*/
1085 OCObservationId obsId;
1086 } OCObservationInfo;
1089 * Possible returned values from entity handler.
1096 OC_EH_RESOURCE_CREATED = 201,
1097 OC_EH_RESOURCE_DELETED = 202,
1099 OC_EH_CHANGED = 204,
1100 OC_EH_CONTENT = 205,
1101 OC_EH_BAD_REQ = 400,
1102 OC_EH_UNAUTHORIZED_REQ = 401,
1103 OC_EH_BAD_OPT = 402,
1104 OC_EH_FORBIDDEN = 403,
1105 OC_EH_RESOURCE_NOT_FOUND = 404,
1106 OC_EH_METHOD_NOT_ALLOWED = 405,
1107 OC_EH_NOT_ACCEPTABLE = 406,
1108 OC_EH_TOO_LARGE = 413,
1109 OC_EH_UNSUPPORTED_MEDIA_TYPE = 415,
1110 OC_EH_INTERNAL_SERVER_ERROR = 500,
1111 OC_EH_BAD_GATEWAY = 502,
1112 OC_EH_SERVICE_UNAVAILABLE = 503,
1113 OC_EH_RETRANSMIT_TIMEOUT = 504
1114 } OCEntityHandlerResult;
1117 * This structure will be used to define the vendor specific header options to be included
1118 * in communication packets.
1120 typedef struct OCHeaderOption
1122 /** The protocol ID this option applies to.*/
1123 OCTransportProtocolID protocolID;
1125 /** The header option ID which will be added to communication packets.*/
1128 /** its length 191.*/
1129 uint16_t optionLength;
1131 /** pointer to its data.*/
1132 uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
1134 #ifdef SUPPORTS_DEFAULT_CTOR
1135 OCHeaderOption() = default;
1136 OCHeaderOption(OCTransportProtocolID pid,
1139 const uint8_t* optData)
1142 optionLength(optlen)
1145 // parameter includes the null terminator.
1146 optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
1147 optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
1148 memcpy(optionData, optData, optionLength);
1149 optionData[optionLength - 1] = '\0';
1155 * This structure describes the platform properties. All non-Null properties will be
1156 * included in a platform discovery request.
1157 * @deprecated: Use OCSetPropertyValue to set platform value.
1164 /** Manufacturer name.*/
1165 char *manufacturerName;
1167 /** Manufacturer URL for platform property.*/
1168 char *manufacturerUrl;
1173 /** Manufacturer date.*/
1174 char *dateOfManufacture;
1176 /** Platform version.*/
1177 char *platformVersion;
1179 /** Operating system version.*/
1180 char *operatingSystemVersion;
1183 char *hardwareVersion;
1186 char *firmwareVersion;
1188 /** Platform support URL.*/
1197 * This structure is expected as input for device properties.
1198 * device name is mandatory and expected from the application.
1199 * device id of type UUID will be generated by the stack.
1200 * @deprecated: Use OCSetPropertyValue to set device value.
1204 /** Pointer to the device name.*/
1206 /** Pointer to the types.*/
1208 /** Pointer to the device specification version.*/
1210 /** Pointer to the device data model versions (in CSV format).*/
1211 OCStringLL *dataModelVersions;
1216 * callback for bound JID
1218 typedef void (*jid_bound_cb)(char *jid);
1221 * CA Remote Access information for XMPP Client
1226 char *hostname; /**< XMPP server hostname */
1227 uint16_t port; /**< XMPP server serivce port */
1228 char *xmpp_domain; /**< XMPP login domain */
1229 char *username; /**< login username */
1230 char *password; /**< login password */
1231 char *resource; /**< specific resource for login */
1232 char *user_jid; /**< specific JID for login */
1233 jid_bound_cb jidbound; /**< callback when JID bound */
1235 #endif /* RA_ADAPTER */
1238 /** Enum to describe the type of object held by the OCPayload object.*/
1241 /** Contents of the payload are invalid */
1242 PAYLOAD_TYPE_INVALID,
1243 /** The payload is an OCDiscoveryPayload */
1244 PAYLOAD_TYPE_DISCOVERY,
1245 /** The payload of the device */
1246 PAYLOAD_TYPE_DEVICE,
1247 /** The payload type of the platform */
1248 PAYLOAD_TYPE_PLATFORM,
1249 /** The payload is an OCRepPayload */
1250 PAYLOAD_TYPE_REPRESENTATION,
1251 /** The payload is an OCSecurityPayload */
1252 PAYLOAD_TYPE_SECURITY,
1253 /** The payload is an OCPresencePayload */
1254 PAYLOAD_TYPE_PRESENCE
1258 * A generic struct representing a payload returned from a resource operation
1260 * A pointer to OCPayLoad can be cast to a more specific struct to access members
1265 /** The type of message that was received */
1276 OCREP_PROP_BYTE_STRING,
1279 }OCRepPayloadPropType;
1281 /** This structure will be used to represent a binary string for CBOR payloads.*/
1284 /** pointer to data bytes.*/
1287 /** number of data bytes.*/
1291 #define MAX_REP_ARRAY_DEPTH 3
1294 OCRepPayloadPropType type;
1295 size_t dimensions[MAX_REP_ARRAY_DEPTH];
1304 /** pointer to ByteString array.*/
1305 OCByteString* ocByteStrArray;
1307 struct OCRepPayload** objArray;
1309 } OCRepPayloadValueArray;
1311 typedef struct OCRepPayloadValue
1314 OCRepPayloadPropType type;
1322 /** ByteString object.*/
1323 OCByteString ocByteStr;
1325 struct OCRepPayload* obj;
1326 OCRepPayloadValueArray arr;
1328 struct OCRepPayloadValue* next;
1330 } OCRepPayloadValue;
1332 // used for get/set/put/observe/etc representations
1333 typedef struct OCRepPayload
1338 OCStringLL* interfaces;
1339 OCRepPayloadValue* values;
1340 struct OCRepPayload* next;
1343 // used inside a discovery payload
1344 typedef struct OCResourcePayload
1348 OCStringLL* interfaces;
1355 struct OCResourcePayload* next;
1356 } OCResourcePayload;
1358 typedef struct OCDiscoveryPayload
1365 /** A special case for handling RD address. */
1374 /** Resource Type */
1380 /** This structure holds the old /oic/res response. */
1381 OCResourcePayload *resources;
1383 /** Holding address of the next DiscoveryPayload. */
1384 struct OCDiscoveryPayload *next;
1386 } OCDiscoveryPayload;
1391 uint8_t* securityData;
1393 } OCSecurityPayload;
1395 #ifdef WITH_PRESENCE
1399 uint32_t sequenceNumber;
1401 OCPresenceTrigger trigger;
1403 } OCPresencePayload;
1407 * Incoming requests handled by the server. Requests are passed in as a parameter to the
1408 * OCEntityHandler callback API.
1409 * The OCEntityHandler callback API must be implemented in the application in order
1410 * to receive these requests.
1414 /** Associated resource.*/
1415 OCResourceHandle resource;
1417 /** Associated request handle.*/
1418 OCRequestHandle requestHandle;
1420 /** the REST method retrieved from received request PDU.*/
1423 /** description of endpoint that sent the request.*/
1426 /** resource query send by client.*/
1429 /** Information associated with observation - valid only when OCEntityHandler flag includes
1430 * ::OC_OBSERVE_FLAG.*/
1431 OCObservationInfo obsInfo;
1433 /** Number of the received vendor specific header options.*/
1434 uint8_t numRcvdVendorSpecificHeaderOptions;
1436 /** Pointer to the array of the received vendor specific header options.*/
1437 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1442 /** the payload from the request PDU.*/
1445 } OCEntityHandlerRequest;
1449 * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1453 /** Address of remote server.*/
1456 /** backward compatibility (points to devAddr).*/
1459 /** backward compatibility.*/
1460 OCConnectivityType connType;
1462 /** the security identity of the remote server.*/
1463 OCIdentity identity;
1465 /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1466 OCStackResult result;
1468 /** If associated with observe, this will represent the sequence of notifications from server.*/
1469 uint32_t sequenceNumber;
1472 const char * resourceUri;
1474 /** the payload for the response PDU.*/
1477 /** Number of the received vendor specific header options.*/
1478 uint8_t numRcvdVendorSpecificHeaderOptions;
1480 /** An array of the received vendor specific header options.*/
1481 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1485 * Request handle is passed to server via the entity handler for each incoming request.
1486 * Stack assigns when request is received, server sets to indicate what request response is for.
1490 /** Request handle.*/
1491 OCRequestHandle requestHandle;
1493 /** Resource handle.*/
1494 OCResourceHandle resourceHandle;
1496 /** Allow the entity handler to pass a result with the response.*/
1497 OCEntityHandlerResult ehResult;
1499 /** This is the pointer to server payload data to be transferred.*/
1502 /** number of the vendor specific header options .*/
1503 uint8_t numSendVendorSpecificHeaderOptions;
1505 /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1506 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1508 /** URI of new resource that entity handler might create.*/
1509 char resourceUri[MAX_URI_LENGTH];
1511 /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1512 uint8_t persistentBufferFlag;
1513 } OCEntityHandlerResponse;
1520 /** Request state.*/
1521 OC_REQUEST_FLAG = (1 << 1),
1522 /** Observe state.*/
1523 OC_OBSERVE_FLAG = (1 << 2)
1524 } OCEntityHandlerFlag;
1527 * Possible return values from client application callback
1529 * A client application callback returns an OCStackApplicationResult to indicate whether
1530 * the stack should continue to keep the callback registered.
1534 /** Make no more calls to the callback and call the OCClientContextDeleter for this callback */
1535 OC_STACK_DELETE_TRANSACTION = 0,
1536 /** Keep this callback registered and call it if an apropriate event occurs */
1537 OC_STACK_KEEP_TRANSACTION
1538 } OCStackApplicationResult;
1541 //#ifdef DIRECT_PAIRING
1543 * @brief direct pairing Method Type.
1545 * 1: pre-configured pin
1550 DP_NOT_ALLOWED = 0x0,
1551 DP_PRE_CONFIGURED = (0x1 << 0),
1552 DP_RANDOM_PIN = (0x1 << 1),
1556 * Device Information of discoverd direct pairing device(s).
1558 typedef struct OCDPDev
1561 OCConnectivityType connType;
1562 uint16_t securePort;
1566 OCUUIdentity deviceID;
1567 OCUUIdentity rowner;
1568 struct OCDPDev *next;
1570 //#endif // DIRECT_PAIRING
1573 * -------------------------------------------------------------------------------------------
1574 * Callback function definitions
1575 * -------------------------------------------------------------------------------------------
1579 * Client applications implement this callback to consume responses received from Servers.
1581 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1582 OCClientResponse * clientResponse);
1585 * Client applications using a context pointer implement this callback to delete the
1586 * context upon removal of the callback/context pointer from the internal callback-list.
1588 typedef void (* OCClientContextDeleter)(void *context);
1591 * This info is passed from application to OC Stack when initiating a request to Server.
1593 typedef struct OCCallbackData
1595 /** Pointer to the context.*/
1598 /** The pointer to a function the stack will call to handle the requests.*/
1599 OCClientResponseHandler cb;
1601 /** A pointer to a function to delete the context when this callback is removed.*/
1602 OCClientContextDeleter cd;
1604 #ifdef SUPPORTS_DEFAULT_CTOR
1605 OCCallbackData() = default;
1606 OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1607 :context(ctx), cb(callback), cd(deleter){}
1612 * Application server implementations must implement this callback to consume requests OTA.
1613 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1615 * When you set specific return value like OC_EH_CHANGED, OC_EH_CONTENT,
1616 * OC_EH_SLOW and etc in entity handler callback,
1617 * ocstack will be not send response automatically to client
1618 * except for error return value like OC_EH_ERROR.
1620 * If you want to send response to client with specific result,
1621 * OCDoResponse API should be called with the result value.
1625 * OCEntityHandlerResponse response;
1629 * response.ehResult = OC_EH_CHANGED;
1633 * OCDoResponse(&response)
1639 typedef OCEntityHandlerResult (*OCEntityHandler)
1640 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1643 * Device Entity handler need to use this call back instead of OCEntityHandler.
1645 * When you set specific return value like OC_EH_CHANGED, OC_EH_CONTENT,
1646 * OC_EH_SLOW and etc in entity handler callback,
1647 * ocstack will be not send response automatically to client
1648 * except for error return value like OC_EH_ERROR.
1650 * If you want to send response to client with specific result,
1651 * OCDoResponse API should be called with the result value.
1655 * OCEntityHandlerResponse response;
1659 * response.ehResult = OC_EH_CHANGED;
1663 * OCDoResponse(&response)
1669 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1670 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1672 //#ifdef DIRECT_PAIRING
1674 * Callback function definition of direct-pairing
1676 * @param[OUT] ctx - user context returned in the callback.
1677 * @param[OUT] peer - pairing device info.
1678 * @param[OUT] result - It's returned with 'OC_STACK_XXX'. It will return 'OC_STACK_OK'
1679 * if D2D pairing is success without error
1681 typedef void (*OCDirectPairingCB)(void *ctx, OCDPDev_t *peer, OCStackResult result);
1682 //#endif // DIRECT_PAIRING
1684 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
1686 * Callback function definition for Change in TrustCertChain
1688 * @param[IN] ctx - user context returned in the callback.
1689 * @param[IN] credId - trustCertChain changed for this ID
1690 * @param[IN] trustCertChain - trustcertchain binary blob.
1691 * @param[IN] chainSize - size of trustchain
1693 typedef void (*TrustCertChainChangeCB)(void *ctx, uint16_t credId, uint8_t *trustCertChain,
1697 * certChain context structure.
1699 typedef struct trustCertChainContext
1701 TrustCertChainChangeCB callback;
1703 } trustCertChainContext_t;
1708 #endif // __cplusplus
1710 #endif /* OCTYPES_H_ */