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"
47 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
52 * OIC Virtual resources supported by every OIC device.
55 * Default discovery mechanism using '/oic/res' is supported by all OIC devices
56 * That are Discoverable.
58 #define OC_RSRVD_WELL_KNOWN_URI "/oic/res"
61 #define OC_RSRVD_DEVICE_URI "/oic/d"
64 #define OC_RSRVD_PLATFORM_URI "/oic/p"
67 #define OC_RSRVD_RESOURCE_TYPES_URI "/oic/res/types/d"
70 #define OC_RSRVD_GATEWAY_URI "/oic/gateway"
73 #define OC_RSRVD_WELL_KNOWN_MQ_URI "/oic/ps"
76 #define OC_RSRVD_KEEPALIVE_URI "/oic/ping"
81 /** Presence URI through which the OIC devices advertise their presence.*/
82 #define OC_RSRVD_PRESENCE_URI "/oic/ad"
84 /** Presence URI through which the OIC devices advertise their device presence.*/
85 #define OC_RSRVD_DEVICE_PRESENCE_URI "/oic/prs"
87 /** Sets the default time to live (TTL) for presence.*/
88 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
90 /** For multicast Discovery mechanism.*/
91 #define OC_MULTICAST_DISCOVERY_URI "/oic/res"
93 /** Separator for multiple query string.*/
94 #define OC_QUERY_SEPARATOR "&;"
97 * OC_DEFAULT_PRESENCE_TTL_SECONDS sets the default time to live (TTL) for presence.
99 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
102 * OC_MAX_PRESENCE_TTL_SECONDS sets the maximum time to live (TTL) for presence.
103 * NOTE: Changing the setting to a longer duration may lead to unsupported and untested
105 * 60 sec/min * 60 min/hr * 24 hr/day
107 #define OC_MAX_PRESENCE_TTL_SECONDS (60 * 60 * 24)
111 * Presence "Announcement Triggers".
115 #define OC_RSRVD_TRIGGER_CREATE "create"
118 #define OC_RSRVD_TRIGGER_CHANGE "change"
121 #define OC_RSRVD_TRIGGER_DELETE "delete"
124 * Attributes used to form a proper OIC conforming JSON message.
127 #define OC_RSRVD_OC "oic"
132 #define OC_RSRVD_PAYLOAD "payload"
134 /** To represent href */
135 #define OC_RSRVD_HREF "href"
137 /** To represent property*/
138 #define OC_RSRVD_PROPERTY "prop"
140 /** For representation.*/
141 #define OC_RSRVD_REPRESENTATION "rep"
143 /** To represent content type.*/
144 #define OC_RSRVD_CONTENT_TYPE "ct"
146 /** To represent resource type.*/
147 #define OC_RSRVD_RESOURCE_TYPE "rt"
149 /** To represent resource type with presence.*/
150 #define OC_RSRVD_RESOURCE_TYPE_PRESENCE "oic.wk.ad"
152 /** To represent resource type with device.*/
153 #define OC_RSRVD_RESOURCE_TYPE_DEVICE "oic.wk.d"
155 /** To represent resource type with platform.*/
156 #define OC_RSRVD_RESOURCE_TYPE_PLATFORM "oic.wk.p"
158 /** To represent resource type with collection.*/
159 #define OC_RSRVD_RESOURCE_TYPE_COLLECTION "oic.wk.col"
161 /** To represent resource type with RES.*/
162 #define OC_RSRVD_RESOURCE_TYPE_RES "oic.wk.res"
164 /** To represent content type with MQ Broker.*/
165 #define OC_RSRVD_RESOURCE_TYPE_MQ_BROKER "oic.wk.ps"
167 /** To represent content type with MQ Topic.*/
168 #define OC_RSRVD_RESOURCE_TYPE_MQ_TOPIC "oic.wk.ps.topic"
171 /** To represent interface.*/
172 #define OC_RSRVD_INTERFACE "if"
174 /** To indicate how long RD should publish this item.*/
175 #define OC_RSRVD_DEVICE_TTL "lt"
177 /** To represent time to live.*/
178 #define OC_RSRVD_TTL "ttl"
180 /** To represent non*/
181 #define OC_RSRVD_NONCE "non"
183 /** To represent trigger type.*/
184 #define OC_RSRVD_TRIGGER "trg"
186 /** To represent links.*/
187 #define OC_RSRVD_LINKS "links"
189 /** To represent default interface.*/
190 #define OC_RSRVD_INTERFACE_DEFAULT "oic.if.baseline"
192 /** To represent read-only interface.*/
193 #define OC_RSRVD_INTERFACE_READ "oic.if.r"
195 /** To represent read-write interface.*/
196 #define OC_RSRVD_INTERFACE_READ_WRITE "oic.if.rw"
198 /** To represent ll interface.*/
199 #define OC_RSRVD_INTERFACE_LL "oic.if.ll"
201 /** To represent batch interface.*/
202 #define OC_RSRVD_INTERFACE_BATCH "oic.if.b"
204 /** To represent actuator interface.*/
205 #define OC_RSRVD_INTERFACE_ACTUATOR "oic.if.a"
207 /** To represent sensor interface.*/
208 #define OC_RSRVD_INTERFACE_SENSOR "oic.if.s"
210 /** To represent interface group.*/
211 #define OC_RSRVD_INTERFACE_GROUP "oic.mi.grp"
213 /** To represent FW version.*/
214 #define OC_RSRVD_FW_VERSION "mnfv"
216 /** To represent host name.*/
217 #define OC_RSRVD_HOST_NAME "hn"
219 /** To represent policy.*/
220 #define OC_RSRVD_POLICY "p"
222 /** To represent bitmap.*/
223 #define OC_RSRVD_BITMAP "bm"
226 #define OC_RSRVD_SECURE "sec"
229 #define OC_RSRVD_HOSTING_PORT "port"
232 #define OC_RSRVD_TCP_PORT "tcp"
235 #define OC_RSRVD_TLS_PORT "tls"
237 /** For Server instance ID.*/
238 #define OC_RSRVD_SERVER_INSTANCE_ID "sid"
240 /** To represent endpoints.*/
241 #define OC_RSRVD_ENDPOINTS "eps"
243 /** To represent endpoint.*/
244 #define OC_RSRVD_ENDPOINT "ep"
246 /** To represent priority.*/
247 #define OC_RSRVD_PRIORITY "pri"
254 #define OC_RSRVD_PLATFORM_ID "pi"
256 /** Platform MFG NAME. */
257 #define OC_RSRVD_MFG_NAME "mnmn"
260 #define OC_RSRVD_MFG_URL "mnml"
263 #define OC_RSRVD_MODEL_NUM "mnmo"
265 /** Platform MFG Date.*/
266 #define OC_RSRVD_MFG_DATE "mndt"
268 /** Platform versio.n */
269 #define OC_RSRVD_PLATFORM_VERSION "mnpv"
271 /** Platform Operating system version. */
272 #define OC_RSRVD_OS_VERSION "mnos"
274 /** Platform Hardware version. */
275 #define OC_RSRVD_HARDWARE_VERSION "mnhw"
277 /**Platform Firmware version. */
278 #define OC_RSRVD_FIRMWARE_VERSION "mnfv"
280 /** Support URL for the platform. */
281 #define OC_RSRVD_SUPPORT_URL "mnsl"
283 /** System time for the platform. */
284 #define OC_RSRVD_SYSTEM_TIME "st"
286 /** VID for the platform. */
287 #define OC_RSRVD_VID "vid"
293 #define OC_RSRVD_DEVICE_ID "di"
296 #define OC_RSRVD_DEVICE_NAME "n"
298 /** Device specification version.*/
299 #define OC_RSRVD_SPEC_VERSION "icv"
301 /** Device data model.*/
302 #define OC_RSRVD_DATA_MODEL_VERSION "dmv"
304 /** Device specification version.*/
305 #define OC_SPEC_VERSION "core.1.1.0"
307 /** Device Data Model version.*/
308 #define OC_DATA_MODEL_VERSION "res.1.1.0,sh.1.1.0"
310 /** Protocol-Independent ID.*/
311 #define OC_RSRVD_PROTOCOL_INDEPENDENT_ID "piid"
314 * These provide backward compatibility - their use is deprecated.
318 /** Multicast Prefix.*/
319 #define OC_MULTICAST_PREFIX "224.0.1.187:5683"
321 /** Multicast IP address.*/
322 #define OC_MULTICAST_IP "224.0.1.187"
324 /** Multicast Port.*/
325 #define OC_MULTICAST_PORT (5683)
328 /** Max Device address size. */
330 #define MAX_ADDR_STR_SIZE (256)
332 /** Max Address could be
333 * "coaps+tcp://[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:yyy.yyy.yyy.yyy]:xxxxx"
334 * +1 for null terminator.
336 #define MAX_ADDR_STR_SIZE (66)
339 /** Length of MAC address */
340 #define MAC_ADDR_STR_SIZE (17)
342 /** Blocks of MAC address */
343 #define MAC_ADDR_BLOCKS (6)
345 /** Max identity size. */
346 #define MAX_IDENTITY_SIZE (37)
348 /** Universal unique identity size. */
349 #define UUID_IDENTITY_SIZE (128/8)
351 /** Resource Directory */
353 /** Resource Directory URI used to Discover RD and Publish resources.*/
354 #define OC_RSRVD_RD_URI "/oic/rd"
356 /** To represent resource type with rd.*/
357 #define OC_RSRVD_RESOURCE_TYPE_RD "oic.wk.rd"
359 /** RD Discovery bias factor type. */
360 #define OC_RSRVD_RD_DISCOVERY_SEL "sel"
362 /** Resource URI used to discover Proxy */
363 #define OC_RSRVD_PROXY_URI "/oic/chp"
365 /** Resource URI used to discover Proxy */
366 #define OC_RSRVD_PROXY_OPTION_ID 35
369 #define OC_RSRVD_BASE_URI "baseURI"
371 /** Unique value per collection/link. */
372 #define OC_RSRVD_INS "ins"
374 /** Allowable resource types in the links. */
375 #define OC_RSRVD_RTS "rts"
377 /** Default relationship. */
378 #define OC_RSRVD_DREL "drel"
380 /** Defines relationship between links. */
381 #define OC_RSRVD_REL "rel"
383 /** Defines title. */
384 #define OC_RSRVD_TITLE "title"
387 #define OC_RSRVD_URI "anchor"
389 /** Defines media type. */
390 #define OC_RSRVD_MEDIA_TYPE "type"
392 /** To represent resource type with Publish RD.*/
393 #define OC_RSRVD_RESOURCE_TYPE_RDPUBLISH "oic.wk.rdpub"
398 #define OC_RSRVD_ACCOUNT_URI "/oic/account"
400 /** Account user URI.*/
401 #define OC_RSRVD_ACCOUNT_SEARCH_URI "/oic/account/search"
403 /** Account session URI.*/
404 #define OC_RSRVD_ACCOUNT_SESSION_URI "/oic/account/session"
406 /** Account token refresh URI.*/
407 #define OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI "/oic/account/tokenrefresh"
410 #define OC_RSRVD_ACL_GROUP_URI "/oic/acl/group"
412 /** ACL invite URI.*/
413 #define OC_RSRVD_ACL_INVITE_URI "/oic/acl/invite"
415 /** Defines auth provider. */
416 #define OC_RSRVD_AUTHPROVIDER "authprovider"
418 /** Defines auth code. */
419 #define OC_RSRVD_AUTHCODE "authcode"
421 /** Defines access token. */
422 #define OC_RSRVD_ACCESS_TOKEN "accesstoken"
424 /** Defines login. */
425 #define OC_RSRVD_LOGIN "login"
427 /** Defines search. */
428 #define OC_RSRVD_SEARCH "search"
430 /** Defines grant type. */
431 #define OC_RSRVD_GRANT_TYPE "granttype"
433 /** Defines refresh token. */
434 #define OC_RSRVD_REFRESH_TOKEN "refreshtoken"
436 /** Defines user UUID. */
437 #define OC_RSRVD_USER_UUID "uid"
439 /** Defines group ID. */
440 #define OC_RSRVD_GROUP_ID "gid"
442 /** Defines member of group ID. */
443 #define OC_RSRVD_MEMBER_ID "mid"
445 /** Defines invite. */
446 #define OC_RSRVD_INVITE "invite"
448 /** Defines accept. */
449 #define OC_RSRVD_ACCEPT "accept"
451 /** Defines operation. */
452 #define OC_RSRVD_OPERATION "op"
455 #define OC_RSRVD_ADD "add"
457 /** Defines delete. */
458 #define OC_RSRVD_DELETE "delete"
460 /** Defines owner. */
461 #define OC_RSRVD_OWNER "owner"
463 /** Defines members. */
464 #define OC_RSRVD_MEMBERS "members"
466 /** To represent grant type with refresh token. */
467 #define OC_RSRVD_GRANT_TYPE_REFRESH_TOKEN "refresh_token"
470 #define OC_RSRVD_PROV_CRL_URL "/oic/credprov/crl"
472 #define OC_RSRVD_LAST_UPDATE "lu"
474 #define OC_RSRVD_THIS_UPDATE "tu"
476 #define OC_RSRVD_NEXT_UPDATE "nu"
478 #define OC_RSRVD_SERIAL_NUMBERS "rcsn"
480 #define OC_RSRVD_CRL "crl"
482 #define OC_RSRVD_CRL_ID "crlid"
485 #define OC_RSRVD_GROUP_URL "/oic/group"
487 #define OC_RSRVD_ACL_GROUP_URL "/oic/acl/group"
489 #define OC_RSRVD_ACL_INVITE_URL "/oic/acl/invite"
491 #define OC_RSRVD_ACL_VERIFY_URL "/oic/acl/verify"
493 #define OC_RSRVD_ACL_ID_URL "/oic/acl/id"
495 #define OC_RSRVD_MEMBER_ID "mid"
497 #define OC_RSRVD_GROUP_ID "gid"
499 #define OC_RSRVD_OWNER_ID "oid"
501 #define OC_RSRVD_ACL_ID "aclid"
503 #define OC_RSRVD_ACE_ID "aceid"
505 #define OC_RSRVD_DEVICE_ID "di"
507 #define OC_RSRVD_SUBJECT_ID "sid"
509 #define OC_RSRVD_REQUEST_METHOD "rm"
511 #define OC_RSRVD_REQUEST_URI "uri"
513 #define OC_RSRVD_GROUP_MASTER_ID "gmid"
515 #define OC_RSRVD_GROUP_TYPE "gtype"
517 #define OC_RSRVD_SUBJECT_TYPE "stype"
519 #define OC_RSRVD_GROUP_ID_LIST "gidlist"
521 #define OC_RSRVD_MEMBER_ID_LIST "midlist"
523 #define OC_RSRVD_DEVICE_ID_LIST "dilist"
525 #define OC_RSRVD_ACCESS_CONTROL_LIST "aclist"
527 #define OC_RSRVD_RESOURCES "resources"
529 #define OC_RSRVD_VALIDITY "validity"
531 #define OC_RSRVD_PERIOD "period"
533 #define OC_RSRVD_RECURRENCE "recurrence"
535 #define OC_RSRVD_INVITE "invite"
537 #define OC_RSRVD_INVITED "invited"
539 #define OC_RSRVD_ENCODING "encoding"
541 #define OC_OIC_SEC "oic.sec"
543 #define OC_RSRVD_BASE64 "base64"
545 #define OC_RSRVD_DER "der"
547 #define OC_RSRVD_PEM "pem"
549 #define OC_RSRVD_RAW "raw"
551 #define OC_RSRVD_UNKNOWN "unknown"
553 #define OC_RSRVD_DATA "data"
555 #define OC_RSRVD_RESOURCE_OWNER_UUID "rowneruuid"
557 #define OC_RSRVD_SUBJECT_UUID "subjectuuid"
559 #define OC_RSRVD_PERMISSION_MASK "permission"
561 #define OC_RSRVD_GROUP_PERMISSION "gp"
563 #define OC_RSRVD_GROUP_ACL "gacl"
565 /** Certificete Sign Request */
566 #define OC_RSRVD_PROV_CERT_URI "/oic/credprov/cert"
568 #define OC_RSRVD_CSR "csr"
570 #define OC_RSRVD_CERT "cert"
572 #define OC_RSRVD_CACERT "certchain"
574 #define OC_RSRVD_TOKEN_TYPE "tokentype"
576 #define OC_RSRVD_EXPIRES_IN "expiresin"
578 #define OC_RSRVD_REDIRECT_URI "redirecturi"
580 #define OC_RSRVD_CERTIFICATE "certificate"
582 * Mark a parameter as unused. Used to prevent unused variable compiler warnings.
583 * Used in three cases:
584 * 1. in callbacks when one of the parameters are unused
585 * 2. when due to code changes a functions parameter is no longer
586 * used but must be left in place for backward compatibility
588 * 3. a variable is only used in the debug build variant and would
589 * give a build warning in release mode.
591 #define OC_UNUSED(x) (void)(x)
594 * These enums (OCTransportAdapter and OCTransportFlags) must
595 * be kept synchronized with OCConnectivityType (below) as well as
596 * CATransportAdapter and CATransportFlags (in CACommon.h).
600 /** value zero indicates discovery.*/
601 OC_DEFAULT_ADAPTER = 0,
603 /** IPv4 and IPv6, including 6LoWPAN.*/
604 OC_ADAPTER_IP = (1 << 0),
606 /** GATT over Bluetooth LE.*/
607 OC_ADAPTER_GATT_BTLE = (1 << 1),
609 /** RFCOMM over Bluetooth EDR.*/
610 OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
612 /**Remote Access over XMPP.*/
613 OC_ADAPTER_REMOTE_ACCESS = (1 << 3),
616 OC_ADAPTER_TCP = (1 << 4),
618 /** NFC Transport for Messaging.*/
619 OC_ADAPTER_NFC = (1 << 5)
620 } OCTransportAdapter;
623 * Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
627 /** default flag is 0*/
628 OC_DEFAULT_FLAGS = 0,
630 /** Insecure transport is the default (subject to change).*/
631 /** secure the transport path*/
632 OC_FLAG_SECURE = (1 << 4),
634 /** IPv4 & IPv6 auto-selection is the default.*/
635 /** IP & TCP adapter only.*/
636 OC_IP_USE_V6 = (1 << 5),
638 /** IP & TCP adapter only.*/
639 OC_IP_USE_V4 = (1 << 6),
641 /** Multicast only.*/
642 OC_MULTICAST = (1 << 7),
644 /** Link-Local multicast is the default multicast scope for IPv6.
645 * These are placed here to correspond to the IPv6 multicast address bits.*/
647 /** IPv6 Interface-Local scope (loopback).*/
648 OC_SCOPE_INTERFACE = 0x1,
650 /** IPv6 Link-Local scope (default).*/
653 /** IPv6 Realm-Local scope. */
654 OC_SCOPE_REALM = 0x3,
656 /** IPv6 Admin-Local scope. */
657 OC_SCOPE_ADMIN = 0x4,
659 /** IPv6 Site-Local scope. */
662 /** IPv6 Organization-Local scope. */
665 /**IPv6 Global scope. */
666 OC_SCOPE_GLOBAL = 0xE,
670 /** Bit mask for scope.*/
671 #define OC_MASK_SCOPE (0x000F)
673 /** Bit mask for Mods.*/
674 #define OC_MASK_MODS (0x0FF0)
675 #define OC_MASK_FAMS (OC_IP_USE_V6|OC_IP_USE_V4)
677 typedef struct OCStringLL
679 struct OCStringLL *next;
684 * End point identity.
688 /** Identity Length */
691 /** Array of end point identity.*/
692 unsigned char id[MAX_IDENTITY_SIZE];
696 * Universally unique identifier.
700 /** identitifier string.*/
701 unsigned char id[UUID_IDENTITY_SIZE];
705 * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
706 * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
711 OCTransportAdapter adapter;
713 /** transport modifiers.*/
714 OCTransportFlags flags;
719 /** address for all adapters.*/
720 char addr[MAX_ADDR_STR_SIZE];
722 /** usually zero for default interface.*/
725 /** destination GatewayID:ClientId.*/
726 char routeData[MAX_ADDR_STR_SIZE];
728 /** device ID of remote.*/
729 char remoteId[MAX_IDENTITY_SIZE];
734 * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
735 * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
736 * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
739 * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
743 /** use when defaults are ok. */
746 /** IPv4 and IPv6, including 6LoWPAN.*/
747 CT_ADAPTER_IP = (1 << 16),
749 /** GATT over Bluetooth LE.*/
750 CT_ADAPTER_GATT_BTLE = (1 << 17),
752 /** RFCOMM over Bluetooth EDR.*/
753 CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
756 /** Remote Access over XMPP.*/
757 CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
760 CT_ADAPTER_TCP = (1 << 20),
763 CT_ADAPTER_NFC = (1 << 21),
765 /** Insecure transport is the default (subject to change).*/
767 /** secure the transport path.*/
768 CT_FLAG_SECURE = (1 << 4),
770 /** IPv4 & IPv6 autoselection is the default.*/
772 /** IP adapter only.*/
773 CT_IP_USE_V6 = (1 << 5),
775 /** IP adapter only.*/
776 CT_IP_USE_V4 = (1 << 6),
778 /** Link-Local multicast is the default multicast scope for IPv6.
779 * These are placed here to correspond to the IPv6 address bits.*/
781 /** IPv6 Interface-Local scope(loopback).*/
782 CT_SCOPE_INTERFACE = 0x1,
784 /** IPv6 Link-Local scope (default).*/
787 /** IPv6 Realm-Local scope.*/
788 CT_SCOPE_REALM = 0x3,
790 /** IPv6 Admin-Local scope.*/
791 CT_SCOPE_ADMIN = 0x4,
793 /** IPv6 Site-Local scope.*/
796 /** IPv6 Organization-Local scope.*/
799 /** IPv6 Global scope.*/
800 CT_SCOPE_GLOBAL = 0xE,
801 } OCConnectivityType;
803 /** bit shift required for connectivity adapter.*/
804 #define CT_ADAPTER_SHIFT 16
807 #define CT_MASK_FLAGS 0xFFFF
810 #define CT_MASK_ADAPTER 0xFFFF0000
813 * OCDoResource methods to dispatch the request
817 OC_REST_NOMETHOD = 0,
820 OC_REST_GET = (1 << 0),
823 OC_REST_PUT = (1 << 1),
826 OC_REST_POST = (1 << 2),
829 OC_REST_DELETE = (1 << 3),
831 /** Register observe request for most up date notifications ONLY.*/
832 OC_REST_OBSERVE = (1 << 4),
834 /** Register observe request for all notifications, including stale notifications.*/
835 OC_REST_OBSERVE_ALL = (1 << 5),
838 /** Subscribe for all presence notifications of a particular resource.*/
839 OC_REST_PRESENCE = (1 << 7),
842 /** Allows OCDoResource caller to do discovery.*/
843 OC_REST_DISCOVER = (1 << 8)
847 * Formats for payload encoding.
854 OC_FORMAT_UNSUPPORTED,
858 * Host Mode of Operation.
865 OC_GATEWAY /**< Client server mode along with routing capabilities.*/
869 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
870 * protocol. The precise definitions of each quality of service level depend on the
871 * implementation. In descriptions below are for the current implementation and may changed
876 /** Packet delivery is best effort.*/
879 /** Packet delivery is best effort.*/
882 /** Acknowledgments are used to confirm delivery.*/
885 /** No Quality is defined, let the stack decide.*/
887 } OCQualityOfService;
890 * Resource Properties.
891 * The value of a policy property is defined as bitmap.
892 * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
893 * Not including the policy property is equivalent to zero.
898 /** When none of the bits are set, the resource is non-discoverable &
899 * non-observable by the client.*/
900 OC_RES_PROP_NONE = (0),
902 /** When this bit is set, the resource is allowed to be discovered by clients.*/
903 OC_DISCOVERABLE = (1 << 0),
905 /** When this bit is set, the resource is allowed to be observed by clients.*/
906 OC_OBSERVABLE = (1 << 1),
908 /** When this bit is set, the resource is initialized, otherwise the resource
909 * is 'inactive'. 'inactive' signifies that the resource has been marked for
910 * deletion or is already deleted.*/
911 OC_ACTIVE = (1 << 2),
913 /** When this bit is set, the resource has been marked as 'slow'.
914 * 'slow' signifies that responses from this resource can expect delays in
915 * processing its requests from clients.*/
918 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
919 /** When this bit is set, the resource is a secure resource.*/
920 OC_SECURE = (1 << 4),
925 /** When this bit is set, the resource is allowed to be discovered only
926 * if discovery request contains an explicit querystring.
927 * Ex: GET /oic/res?rt=oic.sec.acl */
928 OC_EXPLICIT_DISCOVERABLE = (1 << 5)
931 /** When this bit is set, the resource is allowed to be published */
933 // Since this property is not defined on OCF Spec. it should be set 0 until define it
934 ,OC_MQ_PUBLISHER = (0)
938 /** When this bit is set, the resource is allowed to be notified as MQ broker.*/
940 // Since this property is not defined on OCF Spec. it should be set 0 until define it
943 } OCResourceProperty;
946 * Transport Protocol IDs.
950 /** For invalid ID.*/
951 OC_INVALID_ID = (1 << 0),
954 OC_COAP_ID = (1 << 1)
955 } OCTransportProtocolID;
958 * Declares Stack Results & Errors.
962 /** Success status code - START HERE.*/
963 OC_STACK_OK = 0, /** 203, 205*/
964 OC_STACK_RESOURCE_CREATED, /** 201*/
965 OC_STACK_RESOURCE_DELETED, /** 202*/
967 OC_STACK_RESOURCE_CHANGED, /** 204*/
968 /** Success status code - END HERE.*/
970 /** Error status code - START HERE.*/
971 OC_STACK_INVALID_URI = 20,
972 OC_STACK_INVALID_QUERY, /** 400*/
974 OC_STACK_INVALID_PORT,
975 OC_STACK_INVALID_CALLBACK,
976 OC_STACK_INVALID_METHOD,
978 /** Invalid parameter.*/
979 OC_STACK_INVALID_PARAM,
980 OC_STACK_INVALID_OBSERVE_PARAM,
982 OC_STACK_COMM_ERROR, /** 504*/
984 OC_STACK_ADAPTER_NOT_ENABLED,
987 /** Resource not found.*/
988 OC_STACK_NO_RESOURCE, /** 404*/
990 /** e.g: not supported method or interface.*/
991 OC_STACK_RESOURCE_ERROR,
992 OC_STACK_SLOW_RESOURCE,
993 OC_STACK_DUPLICATE_REQUEST,
995 /** Resource has no registered observers.*/
996 OC_STACK_NO_OBSERVERS,
997 OC_STACK_OBSERVER_NOT_FOUND,
998 OC_STACK_VIRTUAL_DO_NOT_HANDLE,
999 OC_STACK_INVALID_OPTION, /** 402*/
1001 /** The remote reply contained malformed data.*/
1002 OC_STACK_MALFORMED_RESPONSE,
1003 OC_STACK_PERSISTENT_BUFFER_REQUIRED,
1004 OC_STACK_INVALID_REQUEST_HANDLE,
1005 OC_STACK_INVALID_DEVICE_INFO,
1006 OC_STACK_INVALID_JSON,
1008 /** Request is not authorized by Resource Server. */
1009 OC_STACK_UNAUTHORIZED_REQ, /** 401*/
1010 OC_STACK_TOO_LARGE_REQ, /** 413*/
1012 /** Error code from PDM */
1013 OC_STACK_PDM_IS_NOT_INITIALIZED,
1014 OC_STACK_DUPLICATE_UUID,
1015 OC_STACK_INCONSISTENT_DB,
1018 * Error code from OTM
1019 * This error is pushed from DTLS interface when handshake failure happens
1021 OC_STACK_AUTHENTICATION_FAILURE,
1022 OC_STACK_NOT_ALLOWED_OXM,
1024 /** Request come from endpoint which is not mapped to the resource. */
1025 OC_STACK_BAD_ENDPOINT,
1027 /** Insert all new error codes here!.*/
1028 #ifdef WITH_PRESENCE
1029 OC_STACK_PRESENCE_STOPPED = 128,
1030 OC_STACK_PRESENCE_TIMEOUT,
1031 OC_STACK_PRESENCE_DO_NOT_HANDLE,
1034 /** Request is denied by the user*/
1035 OC_STACK_USER_DENIED_REQ,
1037 /** ERROR code from server */
1038 OC_STACK_FORBIDDEN_REQ, /** 403*/
1039 OC_STACK_INTERNAL_SERVER_ERROR, /** 500*/
1041 /** ERROR in stack.*/
1042 OC_STACK_ERROR = 255
1043 /** Error status code - END HERE.*/
1047 * Handle to an OCDoResource invocation.
1049 typedef void * OCDoHandle;
1052 * Handle to an OCResource object owned by the OCStack.
1054 typedef void * OCResourceHandle;
1057 * Handle to an OCRequest object owned by the OCStack.
1059 typedef void * OCRequestHandle;
1062 * Unique identifier for each observation request. Used when observations are
1063 * registered or de-registered. Used by entity handler to signal specific
1064 * observers to be notified of resource changes.
1065 * There can be maximum of 256 observations per server.
1067 typedef uint8_t OCObservationId;
1070 * Sequence number is a 24 bit field,
1071 * per https://tools.ietf.org/html/rfc7641.
1073 #define MAX_SEQUENCE_NUMBER (0xFFFFFF)
1076 * Action associated with observation.
1081 OC_OBSERVE_REGISTER = 0,
1083 /** To Deregister. */
1084 OC_OBSERVE_DEREGISTER = 1,
1087 OC_OBSERVE_NO_OPTION = 2,
1093 * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
1094 * when it calls OCRegisterPersistentStorageHandler.
1095 * Persistent storage open handler points to default file path.
1096 * It should check file path and whether the file is symbolic link or no.
1097 * Application can point to appropriate SVR database path for it's IoTivity Server.
1100 /** Persistent storage file path.*/
1101 FILE* (* open)(const char *path, const char *mode);
1103 /** Persistent storage read handler.*/
1104 size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
1106 /** Persistent storage write handler.*/
1107 size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
1109 /** Persistent storage close handler.*/
1110 int (* close)(FILE *fp);
1112 /** Persistent storage unlink handler.*/
1113 int (* unlink)(const char *path);
1114 } OCPersistentStorage;
1117 * Possible returned values from entity handler.
1121 /** Action associated with observation request.*/
1122 OCObserveAction action;
1124 /** Identifier for observation being registered/deregistered.*/
1125 OCObservationId obsId;
1126 } OCObservationInfo;
1129 * Possible returned values from entity handler.
1136 OC_EH_RESOURCE_CREATED = 201,
1137 OC_EH_RESOURCE_DELETED = 202,
1139 OC_EH_CHANGED = 204,
1140 OC_EH_CONTENT = 205,
1141 OC_EH_BAD_REQ = 400,
1142 OC_EH_UNAUTHORIZED_REQ = 401,
1143 OC_EH_BAD_OPT = 402,
1144 OC_EH_FORBIDDEN = 403,
1145 OC_EH_RESOURCE_NOT_FOUND = 404,
1146 OC_EH_METHOD_NOT_ALLOWED = 405,
1147 OC_EH_NOT_ACCEPTABLE = 406,
1148 OC_EH_TOO_LARGE = 413,
1149 OC_EH_UNSUPPORTED_MEDIA_TYPE = 415,
1150 OC_EH_INTERNAL_SERVER_ERROR = 500,
1151 OC_EH_BAD_GATEWAY = 502,
1152 OC_EH_SERVICE_UNAVAILABLE = 503,
1153 OC_EH_RETRANSMIT_TIMEOUT = 504
1154 } OCEntityHandlerResult;
1157 * This structure will be used to define the vendor specific header options to be included
1158 * in communication packets.
1160 typedef struct OCHeaderOption
1162 /** The protocol ID this option applies to.*/
1163 OCTransportProtocolID protocolID;
1165 /** The header option ID which will be added to communication packets.*/
1168 /** its length 191.*/
1169 uint16_t optionLength;
1171 /** pointer to its data.*/
1172 uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
1174 #ifdef SUPPORTS_DEFAULT_CTOR
1175 OCHeaderOption() = default;
1176 OCHeaderOption(OCTransportProtocolID pid,
1179 const uint8_t* optData)
1182 optionLength(optlen)
1185 // parameter includes the null terminator.
1186 optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
1187 optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
1188 memcpy(optionData, optData, optionLength);
1189 optionData[optionLength - 1] = '\0';
1195 * This structure describes the platform properties. All non-Null properties will be
1196 * included in a platform discovery request.
1197 * @deprecated: Use OCSetPropertyValue to set platform value.
1204 /** Manufacturer name.*/
1205 char *manufacturerName;
1207 /** Manufacturer URL for platform property.*/
1208 char *manufacturerUrl;
1213 /** Manufacturer date.*/
1214 char *dateOfManufacture;
1216 /** Platform version.*/
1217 char *platformVersion;
1219 /** Operating system version.*/
1220 char *operatingSystemVersion;
1223 char *hardwareVersion;
1226 char *firmwareVersion;
1228 /** Platform support URL.*/
1237 * This structure is expected as input for device properties.
1238 * device name is mandatory and expected from the application.
1239 * device id of type UUID will be generated by the stack.
1240 * @deprecated: Use OCSetPropertyValue to set device value.
1244 /** Pointer to the device name.*/
1246 /** Pointer to the types.*/
1248 /** Pointer to the device specification version.*/
1250 /** Pointer to the device data model versions (in CSV format).*/
1251 OCStringLL *dataModelVersions;
1255 * This enum type for indicate Transport Protocol Suites
1259 /** For initialize */
1266 OC_COAPS = (1 << 1),
1270 OC_COAP_TCP = (1 << 2),
1273 OC_COAPS_TCP = (1 << 3),
1280 OC_HTTPS = (1 << 5),
1283 /** coap + rfcomm */
1284 OC_COAP_RFCOMM = (1 << 6),
1286 /** Allow all endpoint.*/
1292 * callback for bound JID
1294 typedef void (*jid_bound_cb)(char *jid);
1297 * CA Remote Access information for XMPP Client
1302 char *hostname; /**< XMPP server hostname */
1303 uint16_t port; /**< XMPP server serivce port */
1304 char *xmpp_domain; /**< XMPP login domain */
1305 char *username; /**< login username */
1306 char *password; /**< login password */
1307 char *resource; /**< specific resource for login */
1308 char *user_jid; /**< specific JID for login */
1309 jid_bound_cb jidbound; /**< callback when JID bound */
1311 #endif /* RA_ADAPTER */
1314 /** Enum to describe the type of object held by the OCPayload object.*/
1317 /** Contents of the payload are invalid */
1318 PAYLOAD_TYPE_INVALID,
1319 /** The payload is an OCDiscoveryPayload */
1320 PAYLOAD_TYPE_DISCOVERY,
1321 /** The payload of the device */
1322 PAYLOAD_TYPE_DEVICE,
1323 /** The payload type of the platform */
1324 PAYLOAD_TYPE_PLATFORM,
1325 /** The payload is an OCRepPayload */
1326 PAYLOAD_TYPE_REPRESENTATION,
1327 /** The payload is an OCSecurityPayload */
1328 PAYLOAD_TYPE_SECURITY,
1329 /** The payload is an OCPresencePayload */
1330 PAYLOAD_TYPE_PRESENCE
1334 * A generic struct representing a payload returned from a resource operation
1336 * A pointer to OCPayLoad can be cast to a more specific struct to access members
1341 /** The type of message that was received */
1352 OCREP_PROP_BYTE_STRING,
1355 }OCRepPayloadPropType;
1357 /** This structure will be used to represent a binary string for CBOR payloads.*/
1360 /** pointer to data bytes.*/
1363 /** number of data bytes.*/
1367 #define MAX_REP_ARRAY_DEPTH 3
1370 OCRepPayloadPropType type;
1371 size_t dimensions[MAX_REP_ARRAY_DEPTH];
1380 /** pointer to ByteString array.*/
1381 OCByteString* ocByteStrArray;
1383 struct OCRepPayload** objArray;
1385 } OCRepPayloadValueArray;
1387 typedef struct OCRepPayloadValue
1390 OCRepPayloadPropType type;
1398 /** ByteString object.*/
1399 OCByteString ocByteStr;
1401 struct OCRepPayload* obj;
1402 OCRepPayloadValueArray arr;
1404 struct OCRepPayloadValue* next;
1406 } OCRepPayloadValue;
1408 // used for get/set/put/observe/etc representations
1409 typedef struct OCRepPayload
1414 OCStringLL* interfaces;
1415 OCRepPayloadValue* values;
1416 struct OCRepPayload* next;
1419 // used inside a resource payload
1420 typedef struct OCEndpointPayload
1424 OCTransportFlags family;
1427 struct OCEndpointPayload* next;
1428 } OCEndpointPayload;
1430 // used inside a discovery payload
1431 typedef struct OCResourcePayload
1435 OCStringLL* interfaces;
1442 struct OCResourcePayload* next;
1443 OCEndpointPayload* eps;
1444 } OCResourcePayload;
1446 typedef struct OCDiscoveryPayload
1453 /** A special case for handling RD address. */
1462 /** Resource Type */
1468 /** This structure holds the old /oic/res response. */
1469 OCResourcePayload *resources;
1471 /** Holding address of the next DiscoveryPayload. */
1472 struct OCDiscoveryPayload *next;
1474 } OCDiscoveryPayload;
1479 uint8_t* securityData;
1481 } OCSecurityPayload;
1483 #ifdef WITH_PRESENCE
1487 uint32_t sequenceNumber;
1489 OCPresenceTrigger trigger;
1491 } OCPresencePayload;
1495 * Incoming requests handled by the server. Requests are passed in as a parameter to the
1496 * OCEntityHandler callback API.
1497 * The OCEntityHandler callback API must be implemented in the application in order
1498 * to receive these requests.
1502 /** Associated resource.*/
1503 OCResourceHandle resource;
1505 /** Associated request handle.*/
1506 OCRequestHandle requestHandle;
1508 /** the REST method retrieved from received request PDU.*/
1511 /** description of endpoint that sent the request.*/
1514 /** resource query send by client.*/
1517 /** Information associated with observation - valid only when OCEntityHandler flag includes
1518 * ::OC_OBSERVE_FLAG.*/
1519 OCObservationInfo obsInfo;
1521 /** Number of the received vendor specific header options.*/
1522 uint8_t numRcvdVendorSpecificHeaderOptions;
1524 /** Pointer to the array of the received vendor specific header options.*/
1525 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1530 /** the payload from the request PDU.*/
1533 } OCEntityHandlerRequest;
1537 * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1541 /** Address of remote server.*/
1544 /** backward compatibility (points to devAddr).*/
1547 /** backward compatibility.*/
1548 OCConnectivityType connType;
1550 /** the security identity of the remote server.*/
1551 OCIdentity identity;
1553 /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1554 OCStackResult result;
1556 /** If associated with observe, this will represent the sequence of notifications from server.*/
1557 uint32_t sequenceNumber;
1560 const char * resourceUri;
1562 /** the payload for the response PDU.*/
1565 /** Number of the received vendor specific header options.*/
1566 uint8_t numRcvdVendorSpecificHeaderOptions;
1568 /** An array of the received vendor specific header options.*/
1569 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1573 * Request handle is passed to server via the entity handler for each incoming request.
1574 * Stack assigns when request is received, server sets to indicate what request response is for.
1578 /** Request handle.*/
1579 OCRequestHandle requestHandle;
1581 /** Resource handle.*/
1582 OCResourceHandle resourceHandle;
1584 /** Allow the entity handler to pass a result with the response.*/
1585 OCEntityHandlerResult ehResult;
1587 /** This is the pointer to server payload data to be transferred.*/
1590 /** number of the vendor specific header options .*/
1591 uint8_t numSendVendorSpecificHeaderOptions;
1593 /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1594 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1596 /** URI of new resource that entity handler might create.*/
1597 char resourceUri[MAX_URI_LENGTH];
1599 /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1600 uint8_t persistentBufferFlag;
1601 } OCEntityHandlerResponse;
1608 /** Request state.*/
1609 OC_REQUEST_FLAG = (1 << 1),
1610 /** Observe state.*/
1611 OC_OBSERVE_FLAG = (1 << 2)
1612 } OCEntityHandlerFlag;
1615 * Possible return values from client application callback
1617 * A client application callback returns an OCStackApplicationResult to indicate whether
1618 * the stack should continue to keep the callback registered.
1622 /** Make no more calls to the callback and call the OCClientContextDeleter for this callback */
1623 OC_STACK_DELETE_TRANSACTION = 0,
1624 /** Keep this callback registered and call it if an apropriate event occurs */
1625 OC_STACK_KEEP_TRANSACTION
1626 } OCStackApplicationResult;
1629 //#ifdef DIRECT_PAIRING
1631 * @brief direct pairing Method Type.
1633 * 1: pre-configured pin
1638 DP_NOT_ALLOWED = 0x0,
1639 DP_PRE_CONFIGURED = (0x1 << 0),
1640 DP_RANDOM_PIN = (0x1 << 1),
1644 * Device Information of discoverd direct pairing device(s).
1646 typedef struct OCDPDev
1649 OCConnectivityType connType;
1650 uint16_t securePort;
1654 OCUUIdentity deviceID;
1655 OCUUIdentity rowner;
1656 struct OCDPDev *next;
1658 //#endif // DIRECT_PAIRING
1661 * -------------------------------------------------------------------------------------------
1662 * Callback function definitions
1663 * -------------------------------------------------------------------------------------------
1667 * Client applications implement this callback to consume responses received from Servers.
1669 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1670 OCClientResponse * clientResponse);
1673 * Client applications using a context pointer implement this callback to delete the
1674 * context upon removal of the callback/context pointer from the internal callback-list.
1676 typedef void (* OCClientContextDeleter)(void *context);
1679 * This info is passed from application to OC Stack when initiating a request to Server.
1681 typedef struct OCCallbackData
1683 /** Pointer to the context.*/
1686 /** The pointer to a function the stack will call to handle the requests.*/
1687 OCClientResponseHandler cb;
1689 /** A pointer to a function to delete the context when this callback is removed.*/
1690 OCClientContextDeleter cd;
1692 #ifdef SUPPORTS_DEFAULT_CTOR
1693 OCCallbackData() = default;
1694 OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1695 :context(ctx), cb(callback), cd(deleter){}
1700 * Application server implementations must implement this callback to consume requests OTA.
1701 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1703 * When you set specific return value like OC_EH_CHANGED, OC_EH_CONTENT,
1704 * OC_EH_SLOW and etc in entity handler callback,
1705 * ocstack will be not send response automatically to client
1706 * except for error return value like OC_EH_ERROR.
1708 * If you want to send response to client with specific result,
1709 * OCDoResponse API should be called with the result value.
1713 * OCEntityHandlerResponse response;
1717 * response.ehResult = OC_EH_CHANGED;
1721 * OCDoResponse(&response)
1727 typedef OCEntityHandlerResult (*OCEntityHandler)
1728 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1731 * Device Entity handler need to use this call back instead of OCEntityHandler.
1733 * When you set specific return value like OC_EH_CHANGED, OC_EH_CONTENT,
1734 * OC_EH_SLOW and etc in entity handler callback,
1735 * ocstack will be not send response automatically to client
1736 * except for error return value like OC_EH_ERROR.
1738 * If you want to send response to client with specific result,
1739 * OCDoResponse API should be called with the result value.
1743 * OCEntityHandlerResponse response;
1747 * response.ehResult = OC_EH_CHANGED;
1751 * OCDoResponse(&response)
1757 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1758 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1760 //#ifdef DIRECT_PAIRING
1762 * Callback function definition of direct-pairing
1764 * @param[OUT] ctx - user context returned in the callback.
1765 * @param[OUT] peer - pairing device info.
1766 * @param[OUT] result - It's returned with 'OC_STACK_XXX'. It will return 'OC_STACK_OK'
1767 * if D2D pairing is success without error
1769 typedef void (*OCDirectPairingCB)(void *ctx, OCDPDev_t *peer, OCStackResult result);
1770 //#endif // DIRECT_PAIRING
1772 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
1774 * Callback function definition for Change in TrustCertChain
1776 * @param[IN] ctx - user context returned in the callback.
1777 * @param[IN] credId - trustCertChain changed for this ID
1778 * @param[IN] trustCertChain - trustcertchain binary blob.
1779 * @param[IN] chainSize - size of trustchain
1781 typedef void (*TrustCertChainChangeCB)(void *ctx, uint16_t credId, uint8_t *trustCertChain,
1785 * certChain context structure.
1787 typedef struct trustCertChainContext
1789 TrustCertChainChangeCB callback;
1791 } trustCertChainContext_t;
1796 #endif // __cplusplus
1798 #endif /* OCTYPES_H_ */