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"
77 /** Presence URI through which the OIC devices advertise their presence.*/
78 #define OC_RSRVD_PRESENCE_URI "/oic/ad"
80 /** Presence URI through which the OIC devices advertise their device presence.*/
81 #define OC_RSRVD_DEVICE_PRESENCE_URI "/oic/prs"
83 /** Sets the default time to live (TTL) for presence.*/
84 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
86 /** For multicast Discovery mechanism.*/
87 #define OC_MULTICAST_DISCOVERY_URI "/oic/res"
89 /** Separator for multiple query string.*/
90 #define OC_QUERY_SEPARATOR "&;"
93 * OC_DEFAULT_PRESENCE_TTL_SECONDS sets the default time to live (TTL) for presence.
95 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
98 * OC_MAX_PRESENCE_TTL_SECONDS sets the maximum time to live (TTL) for presence.
99 * NOTE: Changing the setting to a longer duration may lead to unsupported and untested
101 * 60 sec/min * 60 min/hr * 24 hr/day
103 #define OC_MAX_PRESENCE_TTL_SECONDS (60 * 60 * 24)
107 * Presence "Announcement Triggers".
111 #define OC_RSRVD_TRIGGER_CREATE "create"
114 #define OC_RSRVD_TRIGGER_CHANGE "change"
117 #define OC_RSRVD_TRIGGER_DELETE "delete"
120 * Attributes used to form a proper OIC conforming JSON message.
123 #define OC_RSRVD_OC "oic"
128 #define OC_RSRVD_PAYLOAD "payload"
130 /** To represent href */
131 #define OC_RSRVD_HREF "href"
133 /** To represent property*/
134 #define OC_RSRVD_PROPERTY "prop"
136 /** For representation.*/
137 #define OC_RSRVD_REPRESENTATION "rep"
139 /** To represent content type.*/
140 #define OC_RSRVD_CONTENT_TYPE "ct"
142 /** To represent resource type.*/
143 #define OC_RSRVD_RESOURCE_TYPE "rt"
145 /** To represent resource type with presence.*/
146 #define OC_RSRVD_RESOURCE_TYPE_PRESENCE "oic.wk.ad"
148 /** To represent resource type with device.*/
149 #define OC_RSRVD_RESOURCE_TYPE_DEVICE "oic.wk.d"
151 /** To represent resource type with platform.*/
152 #define OC_RSRVD_RESOURCE_TYPE_PLATFORM "oic.wk.p"
154 /** To represent resource type with RES.*/
155 #define OC_RSRVD_RESOURCE_TYPE_RES "oic.wk.res"
157 /** To represent content type with MQ Broker.*/
158 #define OC_RSRVD_RESOURCE_TYPE_MQ_BROKER "oic.wk.ps"
160 /** To represent content type with MQ Topic.*/
161 #define OC_RSRVD_RESOURCE_TYPE_MQ_TOPIC "oic.wk.ps.topic"
164 /** To represent interface.*/
165 #define OC_RSRVD_INTERFACE "if"
167 /** To indicate how long RD should publish this item.*/
168 #define OC_RSRVD_DEVICE_TTL "lt"
170 /** To represent time to live.*/
171 #define OC_RSRVD_TTL "ttl"
173 /** To represent non*/
174 #define OC_RSRVD_NONCE "non"
176 /** To represent trigger type.*/
177 #define OC_RSRVD_TRIGGER "trg"
179 /** To represent links.*/
180 #define OC_RSRVD_LINKS "links"
182 /** To represent default interface.*/
183 #define OC_RSRVD_INTERFACE_DEFAULT "oic.if.baseline"
185 /** To represent read-only interface.*/
186 #define OC_RSRVD_INTERFACE_READ "oic.if.r"
188 /** To represent ll interface.*/
189 #define OC_RSRVD_INTERFACE_LL "oic.if.ll"
191 /** To represent batch interface.*/
192 #define OC_RSRVD_INTERFACE_BATCH "oic.if.b"
194 /** To represent interface group.*/
195 #define OC_RSRVD_INTERFACE_GROUP "oic.mi.grp"
197 /** To represent MFG date.*/
198 #define OC_RSRVD_MFG_DATE "mndt"
200 /** To represent FW version.*/
201 #define OC_RSRVD_FW_VERSION "mnfv"
203 /** To represent host name.*/
204 #define OC_RSRVD_HOST_NAME "hn"
206 /** To represent policy.*/
207 #define OC_RSRVD_POLICY "p"
209 /** To represent bitmap.*/
210 #define OC_RSRVD_BITMAP "bm"
213 #define OC_RSRVD_SECURE "sec"
216 #define OC_RSRVD_HOSTING_PORT "port"
219 #define OC_RSRVD_TCP_PORT "x.org.iotivity.tcp"
221 /** For Server instance ID.*/
222 #define OC_RSRVD_SERVER_INSTANCE_ID "sid"
229 #define OC_RSRVD_PLATFORM_ID "pi"
231 /** Platform MFG NAME. */
232 #define OC_RSRVD_MFG_NAME "mnmn"
235 #define OC_RSRVD_MFG_URL "mnml"
238 #define OC_RSRVD_MODEL_NUM "mnmo"
240 /** Platform MFG Date.*/
241 #define OC_RSRVD_MFG_DATE "mndt"
243 /** Platform versio.n */
244 #define OC_RSRVD_PLATFORM_VERSION "mnpv"
246 /** Platform Operating system version. */
247 #define OC_RSRVD_OS_VERSION "mnos"
249 /** Platform Hardware version. */
250 #define OC_RSRVD_HARDWARE_VERSION "mnhw"
252 /**Platform Firmware version. */
253 #define OC_RSRVD_FIRMWARE_VERSION "mnfv"
255 /** Support URL for the platform. */
256 #define OC_RSRVD_SUPPORT_URL "mnsl"
258 /** System time for the platform. */
259 #define OC_RSRVD_SYSTEM_TIME "st"
266 #define OC_RSRVD_DEVICE_ID "di"
269 #define OC_RSRVD_DEVICE_NAME "n"
271 /** Device specification version.*/
272 #define OC_RSRVD_SPEC_VERSION "icv"
274 /** Device data model.*/
275 #define OC_RSRVD_DATA_MODEL_VERSION "dmv"
277 /** Device specification version.*/
278 #define OC_SPEC_VERSION "core.1.0.0"
280 /** Device Data Model version.*/
281 #define OC_DATA_MODEL_VERSION "res.1.0.0"
284 * These provide backward compatibility - their use is deprecated.
288 /** Multicast Prefix.*/
289 #define OC_MULTICAST_PREFIX "224.0.1.187:5683"
291 /** Multicast IP address.*/
292 #define OC_MULTICAST_IP "224.0.1.187"
294 /** Multicast Port.*/
295 #define OC_MULTICAST_PORT (5683)
298 /** Max Device address size. */
300 #define MAX_ADDR_STR_SIZE (256)
302 /** Max Address could be
303 * "coaps+tcp://[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:yyy.yyy.yyy.yyy]:xxxxx"
304 * +1 for null terminator.
306 #define MAX_ADDR_STR_SIZE (66)
309 /** Length of MAC address */
310 #define MAC_ADDR_STR_SIZE (17)
312 /** Blocks of MAC address */
313 #define MAC_ADDR_BLOCKS (6)
315 /** Max identity size. */
316 #define MAX_IDENTITY_SIZE (37)
318 /** Universal unique identity size. */
319 #define UUID_IDENTITY_SIZE (128/8)
321 /** Resource Directory */
323 /** Resource Directory URI used to Discover RD and Publish resources.*/
324 #define OC_RSRVD_RD_URI "/oic/rd"
326 /** To represent resource type with rd.*/
327 #define OC_RSRVD_RESOURCE_TYPE_RD "oic.wk.rd"
329 /** RD Discovery bias factor type. */
330 #define OC_RSRVD_RD_DISCOVERY_SEL "sel"
332 /** Resource URI used to discover Proxy */
333 #define OC_RSRVD_PROXY_URI "/oic/chp"
335 /** Resource URI used to discover Proxy */
336 #define OC_RSRVD_PROXY_OPTION_ID 35
339 #define OC_RSRVD_BASE_URI "baseURI"
341 /** Unique value per collection/link. */
342 #define OC_RSRVD_INS "ins"
344 /** Allowable resource types in the links. */
345 #define OC_RSRVD_RTS "rts"
347 /** Default relationship. */
348 #define OC_RSRVD_DREL "drel"
350 /** Defines relationship between links. */
351 #define OC_RSRVD_REL "rel"
353 /** Defines title. */
354 #define OC_RSRVD_TITLE "title"
357 #define OC_RSRVD_URI "anchor"
359 /** Defines media type. */
360 #define OC_RSRVD_MEDIA_TYPE "type"
362 /** To represent resource type with Publish RD.*/
363 #define OC_RSRVD_RESOURCE_TYPE_RDPUBLISH "oic.wk.rdpub"
368 #define OC_RSRVD_ACCOUNT_URI "/oic/account"
370 /** Account session URI.*/
371 #define OC_RSRVD_ACCOUNT_SESSION_URI "/oic/account/session"
373 /** Account token refresh URI.*/
374 #define OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI "/oic/account/tokenrefresh"
377 #define OC_RSRVD_ACL_GROUP_URI "/oic/acl/group"
379 /** ACL invite URI.*/
380 #define OC_RSRVD_ACL_INVITE_URI "/oic/acl/invite"
382 /** Defines auth provider. */
383 #define OC_RSRVD_AUTHPROVIDER "authprovider"
385 /** Defines auth code. */
386 #define OC_RSRVD_AUTHCODE "authcode"
388 /** Defines access token. */
389 #define OC_RSRVD_ACCESS_TOKEN "accesstoken"
391 /** Defines login. */
392 #define OC_RSRVD_LOGIN "login"
394 /** Defines search. */
395 #define OC_RSRVD_SEARCH "search"
397 /** Defines grant type. */
398 #define OC_RSRVD_GRANT_TYPE "granttype"
400 /** Defines refresh token. */
401 #define OC_RSRVD_REFRESH_TOKEN "refreshtoken"
403 /** Defines user UUID. */
404 #define OC_RSRVD_USER_UUID "uid"
406 /** Defines user ID. */
407 #define OC_RSRVD_USER_ID "userid"
409 /** Defines group ID. */
410 #define OC_RSRVD_GROUP_ID "gid"
412 /** Defines group Master ID. */
413 #define OC_RSRVD_GROUP_MASTER_ID "gmid"
415 /** Defines group type. */
416 #define OC_RSRVD_GROUP_TYPE "gtype"
418 /** Defines member of group ID. */
419 #define OC_RSRVD_MEMBER_ID "mid"
421 /** Defines device ID list. */
422 #define OC_RSRVD_DEVICE_ID_LIST "dilist"
424 /** Defines public. */
425 #define OC_RSRVD_PUBLIC "Public"
427 /** Defines private. */
428 #define OC_RSRVD_PRIVATE "Private"
430 /** Defines invite. */
431 #define OC_RSRVD_INVITE "invite"
433 /** To represent grant type with refresh token. */
434 #define OC_RSRVD_GRANT_TYPE_REFRESH_TOKEN "refresh_token"
437 #define OC_RSRVD_PROV_CRL_URL "/oic/credprov/crl"
439 #define OC_RSRVD_LAST_UPDATE "lu"
441 #define OC_RSRVD_THIS_UPDATE "tu"
443 #define OC_RSRVD_NEXT_UPDATE "nu"
445 #define OC_RSRVD_SERIAL_NUMBERS "rcsn"
447 #define OC_RSRVD_CRL "crl"
449 #define OC_RSRVD_CRL_ID "crlid"
452 #define OC_RSRVD_GROUP_URL "/oic/group"
454 #define OC_RSRVD_ACL_GROUP_URL "/oic/acl/group"
456 #define OC_RSRVD_ACL_INVITE_URL "/oic/acl/invite"
458 #define OC_RSRVD_ACL_VERIFY_URL "/oic/acl/verify"
460 #define OC_RSRVD_ACL_ID_URL "/oic/acl/id"
462 #define OC_RSRVD_MEMBER_ID "mid"
464 #define OC_RSRVD_GROUP_ID "gid"
466 #define OC_RSRVD_OWNER_ID "oid"
468 #define OC_RSRVD_ACL_ID "aclid"
470 #define OC_RSRVD_ACE_ID "aceid"
472 #define OC_RSRVD_DEVICE_ID "di"
474 #define OC_RSRVD_SUBJECT_ID "sid"
476 #define OC_RSRVD_REQUEST_METHOD "rm"
478 #define OC_RSRVD_REQUEST_URI "uri"
480 #define OC_RSRVD_GROUP_MASTER_ID "gmid"
482 #define OC_RSRVD_GROUP_TYPE "gtype"
484 #define OC_RSRVD_SUBJECT_TYPE "stype"
486 #define OC_RSRVD_GROUP_ID_LIST "gidlist"
488 #define OC_RSRVD_MEMBER_ID_LIST "midlist"
490 #define OC_RSRVD_DEVICE_ID_LIST "dilist"
492 #define OC_RSRVD_ACCESS_CONTROL_LIST "aclist"
494 #define OC_RSRVD_RESOURCES "resources"
496 #define OC_RSRVD_VALIDITY "validity"
498 #define OC_RSRVD_PERIOD "period"
500 #define OC_RSRVD_RECURRENCE "recurrence"
502 #define OC_RSRVD_INVITE "invite"
504 #define OC_RSRVD_INVITED "invited"
506 #define OC_RSRVD_ENCODING "encoding"
508 #define OC_OIC_SEC "oic.sec"
510 #define OC_RSRVD_BASE64 "base64"
512 #define OC_RSRVD_DER "der"
514 #define OC_RSRVD_PEM "pem"
516 #define OC_RSRVD_RAW "raw"
518 #define OC_RSRVD_UNKNOWN "unknown"
520 #define OC_RSRVD_DATA "data"
522 #define OC_RSRVD_RESOURCE_OWNER_UUID "rowneruuid"
524 #define OC_RSRVD_SUBJECT_UUID "subjectuuid"
526 #define OC_RSRVD_PERMISSION_MASK "permission"
528 #define OC_RSRVD_GROUP_PERMISSION "gp"
530 #define OC_RSRVD_GROUP_ACL "gacl"
532 /** Certificete Sign Request */
533 #define OC_RSRVD_PROV_CERT_URI "/oic/credprov/cert"
535 #define OC_RSRVD_CSR "csr"
537 #define OC_RSRVD_CERT "cert"
539 #define OC_RSRVD_CACERT "certchain"
541 #define OC_RSRVD_TOKEN_TYPE "tokentype"
543 #define OC_RSRVD_EXPIRES_IN "expiresin"
545 #define OC_RSRVD_REDIRECT_URI "redirecturi"
547 #define OC_RSRVD_CERTIFICATE "certificate"
549 * Mark a parameter as unused. Used to prevent unused variable compiler warnings.
550 * Used in three cases:
551 * 1. in callbacks when one of the parameters are unused
552 * 2. when due to code changes a functions parameter is no longer
553 * used but must be left in place for backward compatibility
555 * 3. a variable is only used in the debug build variant and would
556 * give a build warning in release mode.
558 #define OC_UNUSED(x) (void)(x)
561 * These enums (OCTransportAdapter and OCTransportFlags) must
562 * be kept synchronized with OCConnectivityType (below) as well as
563 * CATransportAdapter and CATransportFlags (in CACommon.h).
567 /** value zero indicates discovery.*/
568 OC_DEFAULT_ADAPTER = 0,
570 /** IPv4 and IPv6, including 6LoWPAN.*/
571 OC_ADAPTER_IP = (1 << 0),
573 /** GATT over Bluetooth LE.*/
574 OC_ADAPTER_GATT_BTLE = (1 << 1),
576 /** RFCOMM over Bluetooth EDR.*/
577 OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
579 /**Remote Access over XMPP.*/
580 OC_ADAPTER_REMOTE_ACCESS = (1 << 3),
583 OC_ADAPTER_TCP = (1 << 4),
585 /** NFC Transport for Messaging.*/
586 OC_ADAPTER_NFC = (1 << 5)
587 } OCTransportAdapter;
590 * Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
594 /** default flag is 0*/
595 OC_DEFAULT_FLAGS = 0,
597 /** Insecure transport is the default (subject to change).*/
598 /** secure the transport path*/
599 OC_FLAG_SECURE = (1 << 4),
601 /** IPv4 & IPv6 auto-selection is the default.*/
602 /** IP & TCP adapter only.*/
603 OC_IP_USE_V6 = (1 << 5),
605 /** IP & TCP adapter only.*/
606 OC_IP_USE_V4 = (1 << 6),
608 /** Multicast only.*/
609 OC_MULTICAST = (1 << 7),
611 /** Link-Local multicast is the default multicast scope for IPv6.
612 * These are placed here to correspond to the IPv6 multicast address bits.*/
614 /** IPv6 Interface-Local scope (loopback).*/
615 OC_SCOPE_INTERFACE = 0x1,
617 /** IPv6 Link-Local scope (default).*/
620 /** IPv6 Realm-Local scope. */
621 OC_SCOPE_REALM = 0x3,
623 /** IPv6 Admin-Local scope. */
624 OC_SCOPE_ADMIN = 0x4,
626 /** IPv6 Site-Local scope. */
629 /** IPv6 Organization-Local scope. */
632 /**IPv6 Global scope. */
633 OC_SCOPE_GLOBAL = 0xE,
637 /** Bit mask for scope.*/
638 #define OC_MASK_SCOPE (0x000F)
640 /** Bit mask for Mods.*/
641 #define OC_MASK_MODS (0x0FF0)
642 #define OC_MASK_FAMS (OC_IP_USE_V6|OC_IP_USE_V4)
644 typedef struct OCStringLL
646 struct OCStringLL *next;
651 * End point identity.
655 /** Identity Length */
658 /** Array of end point identity.*/
659 unsigned char id[MAX_IDENTITY_SIZE];
663 * Universally unique identifier.
667 /** identitifier string.*/
668 unsigned char id[UUID_IDENTITY_SIZE];
672 * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
673 * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
678 OCTransportAdapter adapter;
680 /** transport modifiers.*/
681 OCTransportFlags flags;
686 /** address for all adapters.*/
687 char addr[MAX_ADDR_STR_SIZE];
689 /** usually zero for default interface.*/
691 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
692 char routeData[MAX_ADDR_STR_SIZE]; //destination GatewayID:ClientId
697 * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
698 * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
699 * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
702 * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
706 /** use when defaults are ok. */
709 /** IPv4 and IPv6, including 6LoWPAN.*/
710 CT_ADAPTER_IP = (1 << 16),
712 /** GATT over Bluetooth LE.*/
713 CT_ADAPTER_GATT_BTLE = (1 << 17),
715 /** RFCOMM over Bluetooth EDR.*/
716 CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
719 /** Remote Access over XMPP.*/
720 CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
723 CT_ADAPTER_TCP = (1 << 20),
726 CT_ADAPTER_NFC = (1 << 21),
728 /** Insecure transport is the default (subject to change).*/
730 /** secure the transport path.*/
731 CT_FLAG_SECURE = (1 << 4),
733 /** IPv4 & IPv6 autoselection is the default.*/
735 /** IP adapter only.*/
736 CT_IP_USE_V6 = (1 << 5),
738 /** IP adapter only.*/
739 CT_IP_USE_V4 = (1 << 6),
741 /** Link-Local multicast is the default multicast scope for IPv6.
742 * These are placed here to correspond to the IPv6 address bits.*/
744 /** IPv6 Interface-Local scope(loopback).*/
745 CT_SCOPE_INTERFACE = 0x1,
747 /** IPv6 Link-Local scope (default).*/
750 /** IPv6 Realm-Local scope.*/
751 CT_SCOPE_REALM = 0x3,
753 /** IPv6 Admin-Local scope.*/
754 CT_SCOPE_ADMIN = 0x4,
756 /** IPv6 Site-Local scope.*/
759 /** IPv6 Organization-Local scope.*/
762 /** IPv6 Global scope.*/
763 CT_SCOPE_GLOBAL = 0xE,
764 } OCConnectivityType;
766 /** bit shift required for connectivity adapter.*/
767 #define CT_ADAPTER_SHIFT 16
770 #define CT_MASK_FLAGS 0xFFFF
773 #define CT_MASK_ADAPTER 0xFFFF0000
776 * OCDoResource methods to dispatch the request
780 OC_REST_NOMETHOD = 0,
783 OC_REST_GET = (1 << 0),
786 OC_REST_PUT = (1 << 1),
789 OC_REST_POST = (1 << 2),
792 OC_REST_DELETE = (1 << 3),
794 /** Register observe request for most up date notifications ONLY.*/
795 OC_REST_OBSERVE = (1 << 4),
797 /** Register observe request for all notifications, including stale notifications.*/
798 OC_REST_OBSERVE_ALL = (1 << 5),
801 /** Subscribe for all presence notifications of a particular resource.*/
802 OC_REST_PRESENCE = (1 << 7),
805 /** Allows OCDoResource caller to do discovery.*/
806 OC_REST_DISCOVER = (1 << 8)
810 * Formats for payload encoding.
817 OC_FORMAT_UNSUPPORTED,
821 * Host Mode of Operation.
828 OC_GATEWAY /**< Client server mode along with routing capabilities.*/
832 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
833 * protocol. The precise definitions of each quality of service level depend on the
834 * implementation. In descriptions below are for the current implementation and may changed
839 /** Packet delivery is best effort.*/
842 /** Packet delivery is best effort.*/
845 /** Acknowledgments are used to confirm delivery.*/
848 /** No Quality is defined, let the stack decide.*/
850 } OCQualityOfService;
853 * Resource Properties.
854 * The value of a policy property is defined as bitmap.
855 * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
856 * Not including the policy property is equivalent to zero.
861 /** When none of the bits are set, the resource is non-discoverable &
862 * non-observable by the client.*/
863 OC_RES_PROP_NONE = (0),
865 /** When this bit is set, the resource is allowed to be discovered by clients.*/
866 OC_DISCOVERABLE = (1 << 0),
868 /** When this bit is set, the resource is allowed to be observed by clients.*/
869 OC_OBSERVABLE = (1 << 1),
871 /** When this bit is set, the resource is initialized, otherwise the resource
872 * is 'inactive'. 'inactive' signifies that the resource has been marked for
873 * deletion or is already deleted.*/
874 OC_ACTIVE = (1 << 2),
876 /** When this bit is set, the resource has been marked as 'slow'.
877 * 'slow' signifies that responses from this resource can expect delays in
878 * processing its requests from clients.*/
882 /** When this bit is set, the resource is a secure resource.*/
883 OC_SECURE = (1 << 4),
888 /** When this bit is set, the resource is allowed to be discovered only
889 * if discovery request contains an explicit querystring.
890 * Ex: GET /oic/res?rt=oic.sec.acl */
891 OC_EXPLICIT_DISCOVERABLE = (1 << 5)
894 /** When this bit is set, the resource is allowed to be published */
895 ,OC_MQ_PUBLISHER = (1 << 6)
899 /** When this bit is set, the resource is allowed to be notified as MQ broker.*/
900 ,OC_MQ_BROKER = (1 << 7)
902 } OCResourceProperty;
905 * Transport Protocol IDs.
909 /** For invalid ID.*/
910 OC_INVALID_ID = (1 << 0),
913 OC_COAP_ID = (1 << 1)
914 } OCTransportProtocolID;
917 * Declares Stack Results & Errors.
921 /** Success status code - START HERE.*/
923 OC_STACK_RESOURCE_CREATED,
924 OC_STACK_RESOURCE_DELETED,
926 OC_STACK_RESOURCE_CHANGED,
927 /** Success status code - END HERE.*/
929 /** Error status code - START HERE.*/
930 OC_STACK_INVALID_URI = 20,
931 OC_STACK_INVALID_QUERY,
933 OC_STACK_INVALID_PORT,
934 OC_STACK_INVALID_CALLBACK,
935 OC_STACK_INVALID_METHOD,
937 /** Invalid parameter.*/
938 OC_STACK_INVALID_PARAM,
939 OC_STACK_INVALID_OBSERVE_PARAM,
943 OC_STACK_ADAPTER_NOT_ENABLED,
946 /** Resource not found.*/
947 OC_STACK_NO_RESOURCE,
949 /** e.g: not supported method or interface.*/
950 OC_STACK_RESOURCE_ERROR,
951 OC_STACK_SLOW_RESOURCE,
952 OC_STACK_DUPLICATE_REQUEST,
954 /** Resource has no registered observers.*/
955 OC_STACK_NO_OBSERVERS,
956 OC_STACK_OBSERVER_NOT_FOUND,
957 OC_STACK_VIRTUAL_DO_NOT_HANDLE,
958 OC_STACK_INVALID_OPTION,
960 /** The remote reply contained malformed data.*/
961 OC_STACK_MALFORMED_RESPONSE,
962 OC_STACK_PERSISTENT_BUFFER_REQUIRED,
963 OC_STACK_INVALID_REQUEST_HANDLE,
964 OC_STACK_INVALID_DEVICE_INFO,
965 OC_STACK_INVALID_JSON,
967 /** Request is not authorized by Resource Server. */
968 OC_STACK_UNAUTHORIZED_REQ,
969 OC_STACK_TOO_LARGE_REQ,
971 /** Error code from PDM */
972 OC_STACK_PDM_IS_NOT_INITIALIZED,
973 OC_STACK_DUPLICATE_UUID,
974 OC_STACK_INCONSISTENT_DB,
977 * Error code from OTM
978 * This error is pushed from DTLS interface when handshake failure happens
980 OC_STACK_AUTHENTICATION_FAILURE,
982 /** Insert all new error codes here!.*/
984 OC_STACK_PRESENCE_STOPPED = 128,
985 OC_STACK_PRESENCE_TIMEOUT,
986 OC_STACK_PRESENCE_DO_NOT_HANDLE,
988 /** ERROR in stack.*/
990 /** Error status code - END HERE.*/
994 * Handle to an OCDoResource invocation.
996 typedef void * OCDoHandle;
999 * Handle to an OCResource object owned by the OCStack.
1001 typedef void * OCResourceHandle;
1004 * Handle to an OCRequest object owned by the OCStack.
1006 typedef void * OCRequestHandle;
1009 * Unique identifier for each observation request. Used when observations are
1010 * registered or de-registered. Used by entity handler to signal specific
1011 * observers to be notified of resource changes.
1012 * There can be maximum of 256 observations per server.
1014 typedef uint8_t OCObservationId;
1017 * Sequence number is a 24 bit field,
1018 * per https://tools.ietf.org/html/rfc7641.
1020 #define MAX_SEQUENCE_NUMBER (0xFFFFFF)
1023 * Action associated with observation.
1028 OC_OBSERVE_REGISTER = 0,
1030 /** To Deregister. */
1031 OC_OBSERVE_DEREGISTER = 1,
1034 OC_OBSERVE_NO_OPTION = 2,
1040 * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
1041 * when it calls OCRegisterPersistentStorageHandler.
1042 * Persistent storage open handler points to default file path.
1043 * It should check file path and whether the file is symbolic link or no.
1044 * Application can point to appropriate SVR database path for it's IoTivity Server.
1047 /** Persistent storage file path.*/
1048 FILE* (* open)(const char *path, const char *mode);
1050 /** Persistent storage read handler.*/
1051 size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
1053 /** Persistent storage write handler.*/
1054 size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
1056 /** Persistent storage close handler.*/
1057 int (* close)(FILE *fp);
1059 /** Persistent storage unlink handler.*/
1060 int (* unlink)(const char *path);
1061 } OCPersistentStorage;
1064 * Possible returned values from entity handler.
1068 /** Action associated with observation request.*/
1069 OCObserveAction action;
1071 /** Identifier for observation being registered/deregistered.*/
1072 OCObservationId obsId;
1073 } OCObservationInfo;
1076 * Possible returned values from entity handler.
1083 OC_EH_RESOURCE_CREATED = 201,
1084 OC_EH_RESOURCE_DELETED = 202,
1086 OC_EH_CHANGED = 204,
1087 OC_EH_CONTENT = 205,
1088 OC_EH_BAD_REQ = 400,
1089 OC_EH_UNAUTHORIZED_REQ = 401,
1090 OC_EH_BAD_OPT = 402,
1091 OC_EH_FORBIDDEN = 403,
1092 OC_EH_RESOURCE_NOT_FOUND = 404,
1093 OC_EH_METHOD_NOT_ALLOWED = 405,
1094 OC_EH_NOT_ACCEPTABLE = 406,
1095 OC_EH_TOO_LARGE = 413,
1096 OC_EH_UNSUPPORTED_MEDIA_TYPE = 415,
1097 OC_EH_INTERNAL_SERVER_ERROR = 500,
1098 OC_EH_BAD_GATEWAY = 502,
1099 OC_EH_SERVICE_UNAVAILABLE = 503,
1100 OC_EH_RETRANSMIT_TIMEOUT = 504
1101 } OCEntityHandlerResult;
1104 * This structure will be used to define the vendor specific header options to be included
1105 * in communication packets.
1107 typedef struct OCHeaderOption
1109 /** The protocol ID this option applies to.*/
1110 OCTransportProtocolID protocolID;
1112 /** The header option ID which will be added to communication packets.*/
1115 /** its length 191.*/
1116 uint16_t optionLength;
1118 /** pointer to its data.*/
1119 uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
1121 #ifdef SUPPORTS_DEFAULT_CTOR
1122 OCHeaderOption() = default;
1123 OCHeaderOption(OCTransportProtocolID pid,
1126 const uint8_t* optData)
1129 optionLength(optlen)
1132 // parameter includes the null terminator.
1133 optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
1134 optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
1135 memcpy(optionData, optData, optionLength);
1136 optionData[optionLength - 1] = '\0';
1142 * This structure describes the platform properties. All non-Null properties will be
1143 * included in a platform discovery request.
1150 /** Manufacturer name.*/
1151 char *manufacturerName;
1153 /** Manufacturer URL for platform property.*/
1154 char *manufacturerUrl;
1159 /** Manufacturer date.*/
1160 char *dateOfManufacture;
1162 /** Platform version.*/
1163 char *platformVersion;
1165 /** Operating system version.*/
1166 char *operatingSystemVersion;
1169 char *hardwareVersion;
1172 char *firmwareVersion;
1174 /** Platform support URL.*/
1183 * This structure is expected as input for device properties.
1184 * device name is mandatory and expected from the application.
1185 * device id of type UUID will be generated by the stack.
1189 /** Pointer to the device name.*/
1191 /** Pointer to the types.*/
1193 /** Pointer to the device specification version.*/
1195 /** Pointer to the device data model versions (in CSV format).*/
1196 OCStringLL *dataModelVersions;
1201 * callback for bound JID
1203 typedef void (*jid_bound_cb)(char *jid);
1206 * CA Remote Access information for XMPP Client
1211 char *hostname; /**< XMPP server hostname */
1212 uint16_t port; /**< XMPP server serivce port */
1213 char *xmpp_domain; /**< XMPP login domain */
1214 char *username; /**< login username */
1215 char *password; /**< login password */
1216 char *resource; /**< specific resource for login */
1217 char *user_jid; /**< specific JID for login */
1218 jid_bound_cb jidbound; /**< callback when JID bound */
1220 #endif /* RA_ADAPTER */
1223 /** Enum to describe the type of object held by the OCPayload object.*/
1226 /** Contents of the payload are invalid */
1227 PAYLOAD_TYPE_INVALID,
1228 /** The payload is an OCDiscoveryPayload */
1229 PAYLOAD_TYPE_DISCOVERY,
1230 /** The payload is an OCDevicePayload */
1231 PAYLOAD_TYPE_DEVICE,
1232 /** The payload is an OCPlatformPayload */
1233 PAYLOAD_TYPE_PLATFORM,
1234 /** The payload is an OCRepPayload */
1235 PAYLOAD_TYPE_REPRESENTATION,
1236 /** The payload is an OCSecurityPayload */
1237 PAYLOAD_TYPE_SECURITY,
1238 /** The payload is an OCPresencePayload */
1239 PAYLOAD_TYPE_PRESENCE,
1240 /** The payload is an OCRDPayload */
1245 * A generic struct representing a payload returned from a resource operation
1247 * A pointer to OCPayLoad can be cast to a more specific struct to access members
1252 /** The type of message that was received */
1263 OCREP_PROP_BYTE_STRING,
1266 }OCRepPayloadPropType;
1268 /** This structure will be used to represent a binary string for CBOR payloads.*/
1271 /** pointer to data bytes.*/
1274 /** number of data bytes.*/
1278 #define MAX_REP_ARRAY_DEPTH 3
1281 OCRepPayloadPropType type;
1282 size_t dimensions[MAX_REP_ARRAY_DEPTH];
1291 /** pointer to ByteString array.*/
1292 OCByteString* ocByteStrArray;
1294 struct OCRepPayload** objArray;
1296 } OCRepPayloadValueArray;
1298 typedef struct OCRepPayloadValue
1301 OCRepPayloadPropType type;
1309 /** ByteString object.*/
1310 OCByteString ocByteStr;
1312 struct OCRepPayload* obj;
1313 OCRepPayloadValueArray arr;
1315 struct OCRepPayloadValue* next;
1317 } OCRepPayloadValue;
1319 // used for get/set/put/observe/etc representations
1320 typedef struct OCRepPayload
1325 OCStringLL* interfaces;
1326 OCRepPayloadValue* values;
1327 struct OCRepPayload* next;
1330 // used inside a discovery payload
1331 typedef struct OCResourcePayload
1335 OCStringLL* interfaces;
1342 struct OCResourcePayload* next;
1343 } OCResourcePayload;
1346 * Structure holding Links Payload. It is a sub-structure used in
1347 * OCResourceCollectionPayload.
1349 typedef struct OCLinksPayload
1351 /** This is the target relative URI. */
1353 /** The relation of the target URI referenced by the link to the context URI;
1354 * The default value is null. */
1356 /** Resource Type - A standard OIC specified or vendor defined resource
1357 * type of the resource referenced by the target URI. */
1359 /** Interface - The interfaces supported by the resource referenced by the target URI. */
1361 /** Bitmap - The bitmap holds observable, discoverable, secure option flag. */
1363 /** A title for the link relation. Can be used by the UI to provide a context. */
1365 /** This is used to override the context URI e.g. override the URI of the containing collection. */
1367 /** The instance identifier for this web link in an array of web links - used in links. */
1370 /** An ordinal number that is not repeated - must be unique in the collection context. */
1372 /** Any unique string including a URI. */
1374 /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1375 OCIdentity uniqueUUID;
1377 /** Time to keep holding resource.*/
1379 /** A hint of the media type of the representation of the resource referenced by the target URI. */
1381 /** Holding address of the next resource. */
1382 struct OCLinksPayload *next;
1385 /** Structure holding tags value of the links payload. */
1388 /** Name of tags. */
1390 /** Device identifier. */
1392 /** Time to keep holding resource.*/
1396 /** Resource collection payload. */
1397 typedef struct OCResourceCollectionPayload
1399 /** Collection tags payload.*/
1400 OCTagsPayload *tags;
1401 /** Array of links payload. */
1402 OCLinksPayload *setLinks;
1403 } OCResourceCollectionPayload;
1405 typedef struct OCDiscoveryPayload
1412 /** A special case for handling RD address. */
1421 /** Resource Type */
1427 /** This structure holds the old /oic/res response. */
1428 OCResourcePayload *resources;
1430 /** Holding address of the next DiscoveryPayload. */
1431 struct OCDiscoveryPayload *next;
1433 } OCDiscoveryPayload;
1436 * Structure holding discovery payload.
1442 /** Device Identity. */
1444 /** Value holding the bias factor of the RD. */
1446 } OCRDDiscoveryPayload;
1449 * RD Payload that will be transmitted over the wire.
1454 /** Pointer to the discovery response payload.*/
1455 OCRDDiscoveryPayload *rdDiscovery;
1456 /** Pointer to the publish payload.*/
1457 OCResourceCollectionPayload *rdPublish;
1466 OCStringLL *dataModelVersions;
1467 OCStringLL *interfaces;
1475 OCPlatformInfo info;
1477 OCStringLL* interfaces;
1478 } OCPlatformPayload;
1483 uint8_t* securityData;
1485 } OCSecurityPayload;
1487 #ifdef WITH_PRESENCE
1491 uint32_t sequenceNumber;
1493 OCPresenceTrigger trigger;
1495 } OCPresencePayload;
1499 * Incoming requests handled by the server. Requests are passed in as a parameter to the
1500 * OCEntityHandler callback API.
1501 * The OCEntityHandler callback API must be implemented in the application in order
1502 * to receive these requests.
1506 /** Associated resource.*/
1507 OCResourceHandle resource;
1509 /** Associated request handle.*/
1510 OCRequestHandle requestHandle;
1512 /** the REST method retrieved from received request PDU.*/
1515 /** description of endpoint that sent the request.*/
1518 /** resource query send by client.*/
1521 /** Information associated with observation - valid only when OCEntityHandler flag includes
1522 * ::OC_OBSERVE_FLAG.*/
1523 OCObservationInfo obsInfo;
1525 /** Number of the received vendor specific header options.*/
1526 uint8_t numRcvdVendorSpecificHeaderOptions;
1528 /** Pointer to the array of the received vendor specific header options.*/
1529 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1534 /** the payload from the request PDU.*/
1537 } OCEntityHandlerRequest;
1541 * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1545 /** Address of remote server.*/
1548 /** backward compatibility (points to devAddr).*/
1551 /** backward compatibility.*/
1552 OCConnectivityType connType;
1554 /** the security identity of the remote server.*/
1555 OCIdentity identity;
1557 /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1558 OCStackResult result;
1560 /** If associated with observe, this will represent the sequence of notifications from server.*/
1561 uint32_t sequenceNumber;
1564 const char * resourceUri;
1566 /** the payload for the response PDU.*/
1569 /** Number of the received vendor specific header options.*/
1570 uint8_t numRcvdVendorSpecificHeaderOptions;
1572 /** An array of the received vendor specific header options.*/
1573 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1577 * Request handle is passed to server via the entity handler for each incoming request.
1578 * Stack assigns when request is received, server sets to indicate what request response is for.
1582 /** Request handle.*/
1583 OCRequestHandle requestHandle;
1585 /** Resource handle.*/
1586 OCResourceHandle resourceHandle;
1588 /** Allow the entity handler to pass a result with the response.*/
1589 OCEntityHandlerResult ehResult;
1591 /** This is the pointer to server payload data to be transferred.*/
1594 /** number of the vendor specific header options .*/
1595 uint8_t numSendVendorSpecificHeaderOptions;
1597 /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1598 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1600 /** URI of new resource that entity handler might create.*/
1601 char resourceUri[MAX_URI_LENGTH];
1603 /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1604 uint8_t persistentBufferFlag;
1605 } OCEntityHandlerResponse;
1612 /** Request state.*/
1613 OC_REQUEST_FLAG = (1 << 1),
1614 /** Observe state.*/
1615 OC_OBSERVE_FLAG = (1 << 2)
1616 } OCEntityHandlerFlag;
1619 * Possible return values from client application callback
1621 * A client application callback returns an OCStackApplicationResult to indicate whether
1622 * the stack should continue to keep the callback registered.
1626 /** Make no more calls to the callback and call the OCClientContextDeleter for this callback */
1627 OC_STACK_DELETE_TRANSACTION = 0,
1628 /** Keep this callback registered and call it if an apropriate event occurs */
1629 OC_STACK_KEEP_TRANSACTION
1630 } OCStackApplicationResult;
1633 //#ifdef DIRECT_PAIRING
1635 * @brief direct pairing Method Type.
1637 * 1: pre-configured pin
1642 DP_NOT_ALLOWED = 0x0,
1643 DP_PRE_CONFIGURED = (0x1 << 0),
1644 DP_RANDOM_PIN = (0x1 << 1),
1648 * Device Information of discoverd direct pairing device(s).
1650 typedef struct OCDPDev
1653 OCConnectivityType connType;
1654 uint16_t securePort;
1658 OCUUIdentity deviceID;
1659 OCUUIdentity rowner;
1660 struct OCDPDev *next;
1662 //#endif // DIRECT_PAIRING
1665 * -------------------------------------------------------------------------------------------
1666 * Callback function definitions
1667 * -------------------------------------------------------------------------------------------
1671 * Client applications implement this callback to consume responses received from Servers.
1673 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1674 OCClientResponse * clientResponse);
1677 * Client applications using a context pointer implement this callback to delete the
1678 * context upon removal of the callback/context pointer from the internal callback-list.
1680 typedef void (* OCClientContextDeleter)(void *context);
1683 * This info is passed from application to OC Stack when initiating a request to Server.
1685 typedef struct OCCallbackData
1687 /** Pointer to the context.*/
1690 /** The pointer to a function the stack will call to handle the requests.*/
1691 OCClientResponseHandler cb;
1693 /** A pointer to a function to delete the context when this callback is removed.*/
1694 OCClientContextDeleter cd;
1696 #ifdef SUPPORTS_DEFAULT_CTOR
1697 OCCallbackData() = default;
1698 OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1699 :context(ctx), cb(callback), cd(deleter){}
1704 * Application server implementations must implement this callback to consume requests OTA.
1705 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1707 * When you set specific return value like OC_EH_CHANGED, OC_EH_CONTENT,
1708 * OC_EH_SLOW and etc in entity handler callback,
1709 * ocstack will be not send response automatically to client
1710 * except for error return value like OC_EH_ERROR.
1712 * If you want to send response to client with specific result,
1713 * OCDoResponse API should be called with the result value.
1717 * OCEntityHandlerResponse response;
1721 * response.ehResult = OC_EH_CHANGED;
1725 * OCDoResponse(&response)
1731 typedef OCEntityHandlerResult (*OCEntityHandler)
1732 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1735 * Device Entity handler need to use this call back instead of OCEntityHandler.
1737 * When you set specific return value like OC_EH_CHANGED, OC_EH_CONTENT,
1738 * OC_EH_SLOW and etc in entity handler callback,
1739 * ocstack will be not send response automatically to client
1740 * except for error return value like OC_EH_ERROR.
1742 * If you want to send response to client with specific result,
1743 * OCDoResponse API should be called with the result value.
1747 * OCEntityHandlerResponse response;
1751 * response.ehResult = OC_EH_CHANGED;
1755 * OCDoResponse(&response)
1761 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1762 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1764 //#ifdef DIRECT_PAIRING
1766 * Callback function definition of direct-pairing
1768 * @param[OUT] ctx - user context returned in the callback.
1769 * @param[OUT] peer - pairing device info.
1770 * @param[OUT] result - It's returned with 'OC_STACK_XXX'. It will return 'OC_STACK_OK'
1771 * if D2D pairing is success without error
1773 typedef void (*OCDirectPairingCB)(void *ctx, OCDPDev_t *peer, OCStackResult result);
1774 //#endif // DIRECT_PAIRING
1778 #endif // __cplusplus
1780 #endif /* OCTYPES_H_ */