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"
225 #define OC_RSRVD_TLS_PORT "tls"
227 /** For Server instance ID.*/
228 #define OC_RSRVD_SERVER_INSTANCE_ID "sid"
235 #define OC_RSRVD_PLATFORM_ID "pi"
237 /** Platform MFG NAME. */
238 #define OC_RSRVD_MFG_NAME "mnmn"
241 #define OC_RSRVD_MFG_URL "mnml"
244 #define OC_RSRVD_MODEL_NUM "mnmo"
246 /** Platform MFG Date.*/
247 #define OC_RSRVD_MFG_DATE "mndt"
249 /** Platform versio.n */
250 #define OC_RSRVD_PLATFORM_VERSION "mnpv"
252 /** Platform Operating system version. */
253 #define OC_RSRVD_OS_VERSION "mnos"
255 /** Platform Hardware version. */
256 #define OC_RSRVD_HARDWARE_VERSION "mnhw"
258 /**Platform Firmware version. */
259 #define OC_RSRVD_FIRMWARE_VERSION "mnfv"
261 /** Support URL for the platform. */
262 #define OC_RSRVD_SUPPORT_URL "mnsl"
264 /** System time for the platform. */
265 #define OC_RSRVD_SYSTEM_TIME "st"
267 /** VID for the platform. */
268 #define OC_RSRVD_VID "vid"
274 #define OC_RSRVD_DEVICE_ID "di"
277 #define OC_RSRVD_DEVICE_NAME "n"
279 /** Device specification version.*/
280 #define OC_RSRVD_SPEC_VERSION "icv"
282 /** Device data model.*/
283 #define OC_RSRVD_DATA_MODEL_VERSION "dmv"
285 /** Device specification version.*/
286 #define OC_SPEC_VERSION "core.1.1.0"
288 /** Device Data Model version.*/
289 #define OC_DATA_MODEL_VERSION "res.1.1.0,sh.1.1.0"
291 * These provide backward compatibility - their use is deprecated.
295 /** Multicast Prefix.*/
296 #define OC_MULTICAST_PREFIX "224.0.1.187:5683"
298 /** Multicast IP address.*/
299 #define OC_MULTICAST_IP "224.0.1.187"
301 /** Multicast Port.*/
302 #define OC_MULTICAST_PORT (5683)
305 /** Max Device address size. */
307 #define MAX_ADDR_STR_SIZE (256)
309 /** Max Address could be
310 * "coaps+tcp://[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:yyy.yyy.yyy.yyy]:xxxxx"
311 * +1 for null terminator.
313 #define MAX_ADDR_STR_SIZE (66)
316 /** Length of MAC address */
317 #define MAC_ADDR_STR_SIZE (17)
319 /** Blocks of MAC address */
320 #define MAC_ADDR_BLOCKS (6)
322 /** Max identity size. */
323 #define MAX_IDENTITY_SIZE (37)
325 /** Universal unique identity size. */
326 #define UUID_IDENTITY_SIZE (128/8)
328 /** Resource Directory */
330 /** Resource Directory URI used to Discover RD and Publish resources.*/
331 #define OC_RSRVD_RD_URI "/oic/rd"
333 /** To represent resource type with rd.*/
334 #define OC_RSRVD_RESOURCE_TYPE_RD "oic.wk.rd"
336 /** RD Discovery bias factor type. */
337 #define OC_RSRVD_RD_DISCOVERY_SEL "sel"
339 /** Resource URI used to discover Proxy */
340 #define OC_RSRVD_PROXY_URI "/oic/chp"
342 /** Resource URI used to discover Proxy */
343 #define OC_RSRVD_PROXY_OPTION_ID 35
346 #define OC_RSRVD_BASE_URI "baseURI"
348 /** Unique value per collection/link. */
349 #define OC_RSRVD_INS "ins"
351 /** Allowable resource types in the links. */
352 #define OC_RSRVD_RTS "rts"
354 /** Default relationship. */
355 #define OC_RSRVD_DREL "drel"
357 /** Defines relationship between links. */
358 #define OC_RSRVD_REL "rel"
360 /** Defines title. */
361 #define OC_RSRVD_TITLE "title"
364 #define OC_RSRVD_URI "anchor"
366 /** Defines media type. */
367 #define OC_RSRVD_MEDIA_TYPE "type"
369 /** To represent resource type with Publish RD.*/
370 #define OC_RSRVD_RESOURCE_TYPE_RDPUBLISH "oic.wk.rdpub"
375 #define OC_RSRVD_ACCOUNT_URI "/oic/account"
377 /** Account user URI.*/
378 #define OC_RSRVD_ACCOUNT_SEARCH_URI "/oic/account/search"
380 /** Account session URI.*/
381 #define OC_RSRVD_ACCOUNT_SESSION_URI "/oic/account/session"
383 /** Account token refresh URI.*/
384 #define OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI "/oic/account/tokenrefresh"
387 #define OC_RSRVD_ACL_GROUP_URI "/oic/acl/group"
389 /** ACL invite URI.*/
390 #define OC_RSRVD_ACL_INVITE_URI "/oic/acl/invite"
392 /** Defines auth provider. */
393 #define OC_RSRVD_AUTHPROVIDER "authprovider"
395 /** Defines auth code. */
396 #define OC_RSRVD_AUTHCODE "authcode"
398 /** Defines access token. */
399 #define OC_RSRVD_ACCESS_TOKEN "accesstoken"
401 /** Defines login. */
402 #define OC_RSRVD_LOGIN "login"
404 /** Defines search. */
405 #define OC_RSRVD_SEARCH "search"
407 /** Defines grant type. */
408 #define OC_RSRVD_GRANT_TYPE "granttype"
410 /** Defines refresh token. */
411 #define OC_RSRVD_REFRESH_TOKEN "refreshtoken"
413 /** Defines user UUID. */
414 #define OC_RSRVD_USER_UUID "uid"
416 /** Defines group ID. */
417 #define OC_RSRVD_GROUP_ID "gid"
419 /** Defines member of group ID. */
420 #define OC_RSRVD_MEMBER_ID "mid"
422 /** Defines invite. */
423 #define OC_RSRVD_INVITE "invite"
425 /** Defines accept. */
426 #define OC_RSRVD_ACCEPT "accept"
428 /** Defines operation. */
429 #define OC_RSRVD_OPERATION "op"
432 #define OC_RSRVD_ADD "add"
434 /** Defines delete. */
435 #define OC_RSRVD_DELETE "delete"
437 /** Defines owner. */
438 #define OC_RSRVD_OWNER "owner"
440 /** Defines members. */
441 #define OC_RSRVD_MEMBERS "members"
443 /** To represent grant type with refresh token. */
444 #define OC_RSRVD_GRANT_TYPE_REFRESH_TOKEN "refresh_token"
447 #define OC_RSRVD_PROV_CRL_URL "/oic/credprov/crl"
449 #define OC_RSRVD_LAST_UPDATE "lu"
451 #define OC_RSRVD_THIS_UPDATE "tu"
453 #define OC_RSRVD_NEXT_UPDATE "nu"
455 #define OC_RSRVD_SERIAL_NUMBERS "rcsn"
457 #define OC_RSRVD_CRL "crl"
459 #define OC_RSRVD_CRL_ID "crlid"
462 #define OC_RSRVD_GROUP_URL "/oic/group"
464 #define OC_RSRVD_ACL_GROUP_URL "/oic/acl/group"
466 #define OC_RSRVD_ACL_INVITE_URL "/oic/acl/invite"
468 #define OC_RSRVD_ACL_VERIFY_URL "/oic/acl/verify"
470 #define OC_RSRVD_ACL_ID_URL "/oic/acl/id"
472 #define OC_RSRVD_MEMBER_ID "mid"
474 #define OC_RSRVD_GROUP_ID "gid"
476 #define OC_RSRVD_OWNER_ID "oid"
478 #define OC_RSRVD_ACL_ID "aclid"
480 #define OC_RSRVD_ACE_ID "aceid"
482 #define OC_RSRVD_DEVICE_ID "di"
484 #define OC_RSRVD_SUBJECT_ID "sid"
486 #define OC_RSRVD_REQUEST_METHOD "rm"
488 #define OC_RSRVD_REQUEST_URI "uri"
490 #define OC_RSRVD_GROUP_MASTER_ID "gmid"
492 #define OC_RSRVD_GROUP_TYPE "gtype"
494 #define OC_RSRVD_SUBJECT_TYPE "stype"
496 #define OC_RSRVD_GROUP_ID_LIST "gidlist"
498 #define OC_RSRVD_MEMBER_ID_LIST "midlist"
500 #define OC_RSRVD_DEVICE_ID_LIST "dilist"
502 #define OC_RSRVD_ACCESS_CONTROL_LIST "aclist"
504 #define OC_RSRVD_RESOURCES "resources"
506 #define OC_RSRVD_VALIDITY "validity"
508 #define OC_RSRVD_PERIOD "period"
510 #define OC_RSRVD_RECURRENCE "recurrence"
512 #define OC_RSRVD_INVITE "invite"
514 #define OC_RSRVD_INVITED "invited"
516 #define OC_RSRVD_ENCODING "encoding"
518 #define OC_OIC_SEC "oic.sec"
520 #define OC_RSRVD_BASE64 "base64"
522 #define OC_RSRVD_DER "der"
524 #define OC_RSRVD_PEM "pem"
526 #define OC_RSRVD_RAW "raw"
528 #define OC_RSRVD_UNKNOWN "unknown"
530 #define OC_RSRVD_DATA "data"
532 #define OC_RSRVD_RESOURCE_OWNER_UUID "rowneruuid"
534 #define OC_RSRVD_SUBJECT_UUID "subjectuuid"
536 #define OC_RSRVD_PERMISSION_MASK "permission"
538 #define OC_RSRVD_GROUP_PERMISSION "gp"
540 #define OC_RSRVD_GROUP_ACL "gacl"
542 /** Certificete Sign Request */
543 #define OC_RSRVD_PROV_CERT_URI "/oic/credprov/cert"
545 #define OC_RSRVD_CSR "csr"
547 #define OC_RSRVD_CERT "cert"
549 #define OC_RSRVD_CACERT "certchain"
551 #define OC_RSRVD_TOKEN_TYPE "tokentype"
553 #define OC_RSRVD_EXPIRES_IN "expiresin"
555 #define OC_RSRVD_REDIRECT_URI "redirecturi"
557 #define OC_RSRVD_CERTIFICATE "certificate"
559 * Mark a parameter as unused. Used to prevent unused variable compiler warnings.
560 * Used in three cases:
561 * 1. in callbacks when one of the parameters are unused
562 * 2. when due to code changes a functions parameter is no longer
563 * used but must be left in place for backward compatibility
565 * 3. a variable is only used in the debug build variant and would
566 * give a build warning in release mode.
568 #define OC_UNUSED(x) (void)(x)
571 * These enums (OCTransportAdapter and OCTransportFlags) must
572 * be kept synchronized with OCConnectivityType (below) as well as
573 * CATransportAdapter and CATransportFlags (in CACommon.h).
577 /** value zero indicates discovery.*/
578 OC_DEFAULT_ADAPTER = 0,
580 /** IPv4 and IPv6, including 6LoWPAN.*/
581 OC_ADAPTER_IP = (1 << 0),
583 /** GATT over Bluetooth LE.*/
584 OC_ADAPTER_GATT_BTLE = (1 << 1),
586 /** RFCOMM over Bluetooth EDR.*/
587 OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
589 /**Remote Access over XMPP.*/
590 OC_ADAPTER_REMOTE_ACCESS = (1 << 3),
593 OC_ADAPTER_TCP = (1 << 4),
595 /** NFC Transport for Messaging.*/
596 OC_ADAPTER_NFC = (1 << 5)
597 } OCTransportAdapter;
600 * Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
604 /** default flag is 0*/
605 OC_DEFAULT_FLAGS = 0,
607 /** Insecure transport is the default (subject to change).*/
608 /** secure the transport path*/
609 OC_FLAG_SECURE = (1 << 4),
611 /** IPv4 & IPv6 auto-selection is the default.*/
612 /** IP & TCP adapter only.*/
613 OC_IP_USE_V6 = (1 << 5),
615 /** IP & TCP adapter only.*/
616 OC_IP_USE_V4 = (1 << 6),
618 /** Multicast only.*/
619 OC_MULTICAST = (1 << 7),
621 /** Link-Local multicast is the default multicast scope for IPv6.
622 * These are placed here to correspond to the IPv6 multicast address bits.*/
624 /** IPv6 Interface-Local scope (loopback).*/
625 OC_SCOPE_INTERFACE = 0x1,
627 /** IPv6 Link-Local scope (default).*/
630 /** IPv6 Realm-Local scope. */
631 OC_SCOPE_REALM = 0x3,
633 /** IPv6 Admin-Local scope. */
634 OC_SCOPE_ADMIN = 0x4,
636 /** IPv6 Site-Local scope. */
639 /** IPv6 Organization-Local scope. */
642 /**IPv6 Global scope. */
643 OC_SCOPE_GLOBAL = 0xE,
647 /** Bit mask for scope.*/
648 #define OC_MASK_SCOPE (0x000F)
650 /** Bit mask for Mods.*/
651 #define OC_MASK_MODS (0x0FF0)
652 #define OC_MASK_FAMS (OC_IP_USE_V6|OC_IP_USE_V4)
654 typedef struct OCStringLL
656 struct OCStringLL *next;
661 * End point identity.
665 /** Identity Length */
668 /** Array of end point identity.*/
669 unsigned char id[MAX_IDENTITY_SIZE];
673 * Universally unique identifier.
677 /** identitifier string.*/
678 unsigned char id[UUID_IDENTITY_SIZE];
682 * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
683 * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
688 OCTransportAdapter adapter;
690 /** transport modifiers.*/
691 OCTransportFlags flags;
696 /** address for all adapters.*/
697 char addr[MAX_ADDR_STR_SIZE];
699 /** usually zero for default interface.*/
701 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
702 char routeData[MAX_ADDR_STR_SIZE]; //destination GatewayID:ClientId
707 * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
708 * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
709 * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
712 * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
716 /** use when defaults are ok. */
719 /** IPv4 and IPv6, including 6LoWPAN.*/
720 CT_ADAPTER_IP = (1 << 16),
722 /** GATT over Bluetooth LE.*/
723 CT_ADAPTER_GATT_BTLE = (1 << 17),
725 /** RFCOMM over Bluetooth EDR.*/
726 CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
729 /** Remote Access over XMPP.*/
730 CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
733 CT_ADAPTER_TCP = (1 << 20),
736 CT_ADAPTER_NFC = (1 << 21),
738 /** Insecure transport is the default (subject to change).*/
740 /** secure the transport path.*/
741 CT_FLAG_SECURE = (1 << 4),
743 /** IPv4 & IPv6 autoselection is the default.*/
745 /** IP adapter only.*/
746 CT_IP_USE_V6 = (1 << 5),
748 /** IP adapter only.*/
749 CT_IP_USE_V4 = (1 << 6),
751 /** Link-Local multicast is the default multicast scope for IPv6.
752 * These are placed here to correspond to the IPv6 address bits.*/
754 /** IPv6 Interface-Local scope(loopback).*/
755 CT_SCOPE_INTERFACE = 0x1,
757 /** IPv6 Link-Local scope (default).*/
760 /** IPv6 Realm-Local scope.*/
761 CT_SCOPE_REALM = 0x3,
763 /** IPv6 Admin-Local scope.*/
764 CT_SCOPE_ADMIN = 0x4,
766 /** IPv6 Site-Local scope.*/
769 /** IPv6 Organization-Local scope.*/
772 /** IPv6 Global scope.*/
773 CT_SCOPE_GLOBAL = 0xE,
774 } OCConnectivityType;
776 /** bit shift required for connectivity adapter.*/
777 #define CT_ADAPTER_SHIFT 16
780 #define CT_MASK_FLAGS 0xFFFF
783 #define CT_MASK_ADAPTER 0xFFFF0000
786 * OCDoResource methods to dispatch the request
790 OC_REST_NOMETHOD = 0,
793 OC_REST_GET = (1 << 0),
796 OC_REST_PUT = (1 << 1),
799 OC_REST_POST = (1 << 2),
802 OC_REST_DELETE = (1 << 3),
804 /** Register observe request for most up date notifications ONLY.*/
805 OC_REST_OBSERVE = (1 << 4),
807 /** Register observe request for all notifications, including stale notifications.*/
808 OC_REST_OBSERVE_ALL = (1 << 5),
811 /** Subscribe for all presence notifications of a particular resource.*/
812 OC_REST_PRESENCE = (1 << 7),
815 /** Allows OCDoResource caller to do discovery.*/
816 OC_REST_DISCOVER = (1 << 8)
820 * Formats for payload encoding.
827 OC_FORMAT_UNSUPPORTED,
831 * Host Mode of Operation.
838 OC_GATEWAY /**< Client server mode along with routing capabilities.*/
842 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
843 * protocol. The precise definitions of each quality of service level depend on the
844 * implementation. In descriptions below are for the current implementation and may changed
849 /** Packet delivery is best effort.*/
852 /** Packet delivery is best effort.*/
855 /** Acknowledgments are used to confirm delivery.*/
858 /** No Quality is defined, let the stack decide.*/
860 } OCQualityOfService;
863 * Resource Properties.
864 * The value of a policy property is defined as bitmap.
865 * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
866 * Not including the policy property is equivalent to zero.
871 /** When none of the bits are set, the resource is non-discoverable &
872 * non-observable by the client.*/
873 OC_RES_PROP_NONE = (0),
875 /** When this bit is set, the resource is allowed to be discovered by clients.*/
876 OC_DISCOVERABLE = (1 << 0),
878 /** When this bit is set, the resource is allowed to be observed by clients.*/
879 OC_OBSERVABLE = (1 << 1),
881 /** When this bit is set, the resource is initialized, otherwise the resource
882 * is 'inactive'. 'inactive' signifies that the resource has been marked for
883 * deletion or is already deleted.*/
884 OC_ACTIVE = (1 << 2),
886 /** When this bit is set, the resource has been marked as 'slow'.
887 * 'slow' signifies that responses from this resource can expect delays in
888 * processing its requests from clients.*/
891 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
892 /** When this bit is set, the resource is a secure resource.*/
893 OC_SECURE = (1 << 4),
898 /** When this bit is set, the resource is allowed to be discovered only
899 * if discovery request contains an explicit querystring.
900 * Ex: GET /oic/res?rt=oic.sec.acl */
901 OC_EXPLICIT_DISCOVERABLE = (1 << 5)
904 /** When this bit is set, the resource is allowed to be published */
905 ,OC_MQ_PUBLISHER = (1 << 6)
909 /** When this bit is set, the resource is allowed to be notified as MQ broker.*/
910 ,OC_MQ_BROKER = (1 << 7)
912 } OCResourceProperty;
915 * Transport Protocol IDs.
919 /** For invalid ID.*/
920 OC_INVALID_ID = (1 << 0),
923 OC_COAP_ID = (1 << 1)
924 } OCTransportProtocolID;
927 * Declares Stack Results & Errors.
931 /** Success status code - START HERE.*/
933 OC_STACK_RESOURCE_CREATED,
934 OC_STACK_RESOURCE_DELETED,
936 OC_STACK_RESOURCE_CHANGED,
937 /** Success status code - END HERE.*/
939 /** Error status code - START HERE.*/
940 OC_STACK_INVALID_URI = 20,
941 OC_STACK_INVALID_QUERY,
943 OC_STACK_INVALID_PORT,
944 OC_STACK_INVALID_CALLBACK,
945 OC_STACK_INVALID_METHOD,
947 /** Invalid parameter.*/
948 OC_STACK_INVALID_PARAM,
949 OC_STACK_INVALID_OBSERVE_PARAM,
953 OC_STACK_ADAPTER_NOT_ENABLED,
956 /** Resource not found.*/
957 OC_STACK_NO_RESOURCE,
959 /** e.g: not supported method or interface.*/
960 OC_STACK_RESOURCE_ERROR,
961 OC_STACK_SLOW_RESOURCE,
962 OC_STACK_DUPLICATE_REQUEST,
964 /** Resource has no registered observers.*/
965 OC_STACK_NO_OBSERVERS,
966 OC_STACK_OBSERVER_NOT_FOUND,
967 OC_STACK_VIRTUAL_DO_NOT_HANDLE,
968 OC_STACK_INVALID_OPTION,
970 /** The remote reply contained malformed data.*/
971 OC_STACK_MALFORMED_RESPONSE,
972 OC_STACK_PERSISTENT_BUFFER_REQUIRED,
973 OC_STACK_INVALID_REQUEST_HANDLE,
974 OC_STACK_INVALID_DEVICE_INFO,
975 OC_STACK_INVALID_JSON,
977 /** Request is not authorized by Resource Server. */
978 OC_STACK_UNAUTHORIZED_REQ,
979 OC_STACK_TOO_LARGE_REQ,
981 /** Error code from PDM */
982 OC_STACK_PDM_IS_NOT_INITIALIZED,
983 OC_STACK_DUPLICATE_UUID,
984 OC_STACK_INCONSISTENT_DB,
987 * Error code from OTM
988 * This error is pushed from DTLS interface when handshake failure happens
990 OC_STACK_AUTHENTICATION_FAILURE,
991 OC_STACK_NOT_ALLOWED_OXM,
993 /** Insert all new error codes here!.*/
995 OC_STACK_PRESENCE_STOPPED = 128,
996 OC_STACK_PRESENCE_TIMEOUT,
997 OC_STACK_PRESENCE_DO_NOT_HANDLE,
1000 /** ERROR code from server */
1001 OC_STACK_FORBIDDEN_REQ, /** 403*/
1002 OC_STACK_INTERNAL_SERVER_ERROR, /** 500*/
1004 /** ERROR in stack.*/
1005 OC_STACK_ERROR = 255
1006 /** Error status code - END HERE.*/
1010 * Handle to an OCDoResource invocation.
1012 typedef void * OCDoHandle;
1015 * Handle to an OCResource object owned by the OCStack.
1017 typedef void * OCResourceHandle;
1020 * Handle to an OCRequest object owned by the OCStack.
1022 typedef uint32_t OCRequestHandle;
1025 * Unique identifier for each observation request. Used when observations are
1026 * registered or de-registered. Used by entity handler to signal specific
1027 * observers to be notified of resource changes.
1028 * There can be maximum of 256 observations per server.
1030 typedef uint8_t OCObservationId;
1033 * Sequence number is a 24 bit field,
1034 * per https://tools.ietf.org/html/rfc7641.
1036 #define MAX_SEQUENCE_NUMBER (0xFFFFFF)
1039 * Action associated with observation.
1044 OC_OBSERVE_REGISTER = 0,
1046 /** To Deregister. */
1047 OC_OBSERVE_DEREGISTER = 1,
1050 OC_OBSERVE_NO_OPTION = 2,
1056 * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
1057 * when it calls OCRegisterPersistentStorageHandler.
1058 * Persistent storage open handler points to default file path.
1059 * It should check file path and whether the file is symbolic link or no.
1060 * Application can point to appropriate SVR database path for it's IoTivity Server.
1063 /** Persistent storage file path.*/
1064 FILE* (* open)(const char *path, const char *mode);
1066 /** Persistent storage read handler.*/
1067 size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
1069 /** Persistent storage write handler.*/
1070 size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
1072 /** Persistent storage close handler.*/
1073 int (* close)(FILE *fp);
1075 /** Persistent storage unlink handler.*/
1076 int (* unlink)(const char *path);
1077 } OCPersistentStorage;
1080 * Possible returned values from entity handler.
1084 /** Action associated with observation request.*/
1085 OCObserveAction action;
1087 /** Identifier for observation being registered/deregistered.*/
1088 OCObservationId obsId;
1089 } OCObservationInfo;
1092 * Possible returned values from entity handler.
1099 OC_EH_RESOURCE_CREATED = 201,
1100 OC_EH_RESOURCE_DELETED = 202,
1102 OC_EH_CHANGED = 204,
1103 OC_EH_CONTENT = 205,
1104 OC_EH_BAD_REQ = 400,
1105 OC_EH_UNAUTHORIZED_REQ = 401,
1106 OC_EH_BAD_OPT = 402,
1107 OC_EH_FORBIDDEN = 403,
1108 OC_EH_RESOURCE_NOT_FOUND = 404,
1109 OC_EH_METHOD_NOT_ALLOWED = 405,
1110 OC_EH_NOT_ACCEPTABLE = 406,
1111 OC_EH_TOO_LARGE = 413,
1112 OC_EH_UNSUPPORTED_MEDIA_TYPE = 415,
1113 OC_EH_INTERNAL_SERVER_ERROR = 500,
1114 OC_EH_BAD_GATEWAY = 502,
1115 OC_EH_SERVICE_UNAVAILABLE = 503,
1116 OC_EH_RETRANSMIT_TIMEOUT = 504
1117 } OCEntityHandlerResult;
1120 * This structure will be used to define the vendor specific header options to be included
1121 * in communication packets.
1123 typedef struct OCHeaderOption
1125 /** The protocol ID this option applies to.*/
1126 OCTransportProtocolID protocolID;
1128 /** The header option ID which will be added to communication packets.*/
1131 /** its length 191.*/
1132 uint16_t optionLength;
1134 /** pointer to its data.*/
1135 uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
1137 #ifdef SUPPORTS_DEFAULT_CTOR
1138 OCHeaderOption() = default;
1139 OCHeaderOption(OCTransportProtocolID pid,
1142 const uint8_t* optData)
1145 optionLength(optlen)
1148 // parameter includes the null terminator.
1149 optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
1150 optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
1151 memcpy(optionData, optData, optionLength);
1152 optionData[optionLength - 1] = '\0';
1158 * This structure describes the platform properties. All non-Null properties will be
1159 * included in a platform discovery request.
1160 * @deprecated: Use OCSetPropertyValue to set platform value.
1167 /** Manufacturer name.*/
1168 char *manufacturerName;
1170 /** Manufacturer URL for platform property.*/
1171 char *manufacturerUrl;
1176 /** Manufacturer date.*/
1177 char *dateOfManufacture;
1179 /** Platform version.*/
1180 char *platformVersion;
1182 /** Operating system version.*/
1183 char *operatingSystemVersion;
1186 char *hardwareVersion;
1189 char *firmwareVersion;
1191 /** Platform support URL.*/
1200 * This structure is expected as input for device properties.
1201 * device name is mandatory and expected from the application.
1202 * device id of type UUID will be generated by the stack.
1203 * @deprecated: Use OCSetPropertyValue to set device value.
1207 /** Pointer to the device name.*/
1209 /** Pointer to the types.*/
1211 /** Pointer to the device specification version.*/
1213 /** Pointer to the device data model versions (in CSV format).*/
1214 OCStringLL *dataModelVersions;
1219 * callback for bound JID
1221 typedef void (*jid_bound_cb)(char *jid);
1224 * CA Remote Access information for XMPP Client
1229 char *hostname; /**< XMPP server hostname */
1230 uint16_t port; /**< XMPP server serivce port */
1231 char *xmpp_domain; /**< XMPP login domain */
1232 char *username; /**< login username */
1233 char *password; /**< login password */
1234 char *resource; /**< specific resource for login */
1235 char *user_jid; /**< specific JID for login */
1236 jid_bound_cb jidbound; /**< callback when JID bound */
1238 #endif /* RA_ADAPTER */
1241 /** Enum to describe the type of object held by the OCPayload object.*/
1244 /** Contents of the payload are invalid */
1245 PAYLOAD_TYPE_INVALID,
1246 /** The payload is an OCDiscoveryPayload */
1247 PAYLOAD_TYPE_DISCOVERY,
1248 /** The payload of the device */
1249 PAYLOAD_TYPE_DEVICE,
1250 /** The payload type of the platform */
1251 PAYLOAD_TYPE_PLATFORM,
1252 /** The payload is an OCRepPayload */
1253 PAYLOAD_TYPE_REPRESENTATION,
1254 /** The payload is an OCSecurityPayload */
1255 PAYLOAD_TYPE_SECURITY,
1256 /** The payload is an OCPresencePayload */
1257 PAYLOAD_TYPE_PRESENCE
1261 * A generic struct representing a payload returned from a resource operation
1263 * A pointer to OCPayLoad can be cast to a more specific struct to access members
1268 /** The type of message that was received */
1279 OCREP_PROP_BYTE_STRING,
1282 }OCRepPayloadPropType;
1284 /** This structure will be used to represent a binary string for CBOR payloads.*/
1287 /** pointer to data bytes.*/
1290 /** number of data bytes.*/
1294 #define MAX_REP_ARRAY_DEPTH 3
1297 OCRepPayloadPropType type;
1298 size_t dimensions[MAX_REP_ARRAY_DEPTH];
1307 /** pointer to ByteString array.*/
1308 OCByteString* ocByteStrArray;
1310 struct OCRepPayload** objArray;
1312 } OCRepPayloadValueArray;
1314 typedef struct OCRepPayloadValue
1317 OCRepPayloadPropType type;
1325 /** ByteString object.*/
1326 OCByteString ocByteStr;
1328 struct OCRepPayload* obj;
1329 OCRepPayloadValueArray arr;
1331 struct OCRepPayloadValue* next;
1333 } OCRepPayloadValue;
1335 // used for get/set/put/observe/etc representations
1336 typedef struct OCRepPayload
1341 OCStringLL* interfaces;
1342 OCRepPayloadValue* values;
1343 struct OCRepPayload* next;
1346 // used inside a discovery payload
1347 typedef struct OCResourcePayload
1351 OCStringLL* interfaces;
1358 struct OCResourcePayload* next;
1359 } OCResourcePayload;
1361 typedef struct OCDiscoveryPayload
1368 /** A special case for handling RD address. */
1377 /** Resource Type */
1383 /** This structure holds the old /oic/res response. */
1384 OCResourcePayload *resources;
1386 /** Holding address of the next DiscoveryPayload. */
1387 struct OCDiscoveryPayload *next;
1389 } OCDiscoveryPayload;
1394 uint8_t* securityData;
1396 } OCSecurityPayload;
1398 #ifdef WITH_PRESENCE
1402 uint32_t sequenceNumber;
1404 OCPresenceTrigger trigger;
1406 } OCPresencePayload;
1410 * Incoming requests handled by the server. Requests are passed in as a parameter to the
1411 * OCEntityHandler callback API.
1412 * The OCEntityHandler callback API must be implemented in the application in order
1413 * to receive these requests.
1417 /** Associated resource.*/
1418 OCResourceHandle resource;
1420 /** Associated request handle.*/
1421 OCRequestHandle requestHandle;
1423 /** the REST method retrieved from received request PDU.*/
1426 /** description of endpoint that sent the request.*/
1429 /** resource query send by client.*/
1432 /** Information associated with observation - valid only when OCEntityHandler flag includes
1433 * ::OC_OBSERVE_FLAG.*/
1434 OCObservationInfo obsInfo;
1436 /** Number of the received vendor specific header options.*/
1437 uint8_t numRcvdVendorSpecificHeaderOptions;
1439 /** Pointer to the array of the received vendor specific header options.*/
1440 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1445 /** the payload from the request PDU.*/
1448 } OCEntityHandlerRequest;
1452 * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1456 /** Address of remote server.*/
1459 /** backward compatibility (points to devAddr).*/
1462 /** backward compatibility.*/
1463 OCConnectivityType connType;
1465 /** the security identity of the remote server.*/
1466 OCIdentity identity;
1468 /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1469 OCStackResult result;
1471 /** If associated with observe, this will represent the sequence of notifications from server.*/
1472 uint32_t sequenceNumber;
1475 const char * resourceUri;
1477 /** the payload for the response PDU.*/
1480 /** Number of the received vendor specific header options.*/
1481 uint8_t numRcvdVendorSpecificHeaderOptions;
1483 /** An array of the received vendor specific header options.*/
1484 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1488 * Request handle is passed to server via the entity handler for each incoming request.
1489 * Stack assigns when request is received, server sets to indicate what request response is for.
1493 /** Request handle.*/
1494 OCRequestHandle requestHandle;
1496 /** Resource handle.*/
1497 OCResourceHandle resourceHandle;
1499 /** Allow the entity handler to pass a result with the response.*/
1500 OCEntityHandlerResult ehResult;
1502 /** This is the pointer to server payload data to be transferred.*/
1505 /** number of the vendor specific header options .*/
1506 uint8_t numSendVendorSpecificHeaderOptions;
1508 /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1509 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1511 /** URI of new resource that entity handler might create.*/
1512 char resourceUri[MAX_URI_LENGTH];
1514 /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1515 uint8_t persistentBufferFlag;
1516 } OCEntityHandlerResponse;
1523 /** Request state.*/
1524 OC_REQUEST_FLAG = (1 << 1),
1525 /** Observe state.*/
1526 OC_OBSERVE_FLAG = (1 << 2)
1527 } OCEntityHandlerFlag;
1530 * Possible return values from client application callback
1532 * A client application callback returns an OCStackApplicationResult to indicate whether
1533 * the stack should continue to keep the callback registered.
1537 /** Make no more calls to the callback and call the OCClientContextDeleter for this callback */
1538 OC_STACK_DELETE_TRANSACTION = 0,
1539 /** Keep this callback registered and call it if an apropriate event occurs */
1540 OC_STACK_KEEP_TRANSACTION
1541 } OCStackApplicationResult;
1544 //#ifdef DIRECT_PAIRING
1546 * @brief direct pairing Method Type.
1548 * 1: pre-configured pin
1553 DP_NOT_ALLOWED = 0x0,
1554 DP_PRE_CONFIGURED = (0x1 << 0),
1555 DP_RANDOM_PIN = (0x1 << 1),
1559 * Device Information of discoverd direct pairing device(s).
1561 typedef struct OCDPDev
1564 OCConnectivityType connType;
1565 uint16_t securePort;
1569 OCUUIdentity deviceID;
1570 OCUUIdentity rowner;
1571 struct OCDPDev *next;
1573 //#endif // DIRECT_PAIRING
1576 * -------------------------------------------------------------------------------------------
1577 * Callback function definitions
1578 * -------------------------------------------------------------------------------------------
1582 * Client applications implement this callback to consume responses received from Servers.
1584 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1585 OCClientResponse * clientResponse);
1588 * Client applications using a context pointer implement this callback to delete the
1589 * context upon removal of the callback/context pointer from the internal callback-list.
1591 typedef void (* OCClientContextDeleter)(void *context);
1594 * This info is passed from application to OC Stack when initiating a request to Server.
1596 typedef struct OCCallbackData
1598 /** Pointer to the context.*/
1601 /** The pointer to a function the stack will call to handle the requests.*/
1602 OCClientResponseHandler cb;
1604 /** A pointer to a function to delete the context when this callback is removed.*/
1605 OCClientContextDeleter cd;
1607 #ifdef SUPPORTS_DEFAULT_CTOR
1608 OCCallbackData() = default;
1609 OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1610 :context(ctx), cb(callback), cd(deleter){}
1615 * Application server implementations must implement this callback to consume requests OTA.
1616 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1618 * When you set specific return value like OC_EH_CHANGED, OC_EH_CONTENT,
1619 * OC_EH_SLOW and etc in entity handler callback,
1620 * ocstack will be not send response automatically to client
1621 * except for error return value like OC_EH_ERROR.
1623 * If you want to send response to client with specific result,
1624 * OCDoResponse API should be called with the result value.
1628 * OCEntityHandlerResponse response;
1632 * response.ehResult = OC_EH_CHANGED;
1636 * OCDoResponse(&response)
1642 typedef OCEntityHandlerResult (*OCEntityHandler)
1643 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1646 * Device Entity handler need to use this call back instead of OCEntityHandler.
1648 * When you set specific return value like OC_EH_CHANGED, OC_EH_CONTENT,
1649 * OC_EH_SLOW and etc in entity handler callback,
1650 * ocstack will be not send response automatically to client
1651 * except for error return value like OC_EH_ERROR.
1653 * If you want to send response to client with specific result,
1654 * OCDoResponse API should be called with the result value.
1658 * OCEntityHandlerResponse response;
1662 * response.ehResult = OC_EH_CHANGED;
1666 * OCDoResponse(&response)
1672 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1673 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1675 //#ifdef DIRECT_PAIRING
1677 * Callback function definition of direct-pairing
1679 * @param[OUT] ctx - user context returned in the callback.
1680 * @param[OUT] peer - pairing device info.
1681 * @param[OUT] result - It's returned with 'OC_STACK_XXX'. It will return 'OC_STACK_OK'
1682 * if D2D pairing is success without error
1684 typedef void (*OCDirectPairingCB)(void *ctx, OCDPDev_t *peer, OCStackResult result);
1685 //#endif // DIRECT_PAIRING
1687 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
1689 * Callback function definition for Change in TrustCertChain
1691 * @param[IN] ctx - user context returned in the callback.
1692 * @param[IN] credId - trustCertChain changed for this ID
1693 * @param[IN] trustCertChain - trustcertchain binary blob.
1694 * @param[IN] chainSize - size of trustchain
1696 typedef void (*TrustCertChainChangeCB)(void *ctx, uint16_t credId, uint8_t *trustCertChain,
1700 * certChain context structure.
1702 typedef struct trustCertChainContext
1704 TrustCertChainChangeCB callback;
1706 } trustCertChainContext_t;
1711 #endif // __cplusplus
1713 #endif /* OCTYPES_H_ */