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 "x.org.iotivity.tcp"
224 /** For Server instance ID.*/
225 #define OC_RSRVD_SERVER_INSTANCE_ID "sid"
232 #define OC_RSRVD_PLATFORM_ID "pi"
234 /** Platform MFG NAME. */
235 #define OC_RSRVD_MFG_NAME "mnmn"
238 #define OC_RSRVD_MFG_URL "mnml"
241 #define OC_RSRVD_MODEL_NUM "mnmo"
243 /** Platform MFG Date.*/
244 #define OC_RSRVD_MFG_DATE "mndt"
246 /** Platform versio.n */
247 #define OC_RSRVD_PLATFORM_VERSION "mnpv"
249 /** Platform Operating system version. */
250 #define OC_RSRVD_OS_VERSION "mnos"
252 /** Platform Hardware version. */
253 #define OC_RSRVD_HARDWARE_VERSION "mnhw"
255 /**Platform Firmware version. */
256 #define OC_RSRVD_FIRMWARE_VERSION "mnfv"
258 /** Support URL for the platform. */
259 #define OC_RSRVD_SUPPORT_URL "mnsl"
261 /** System time for the platform. */
262 #define OC_RSRVD_SYSTEM_TIME "st"
269 #define OC_RSRVD_DEVICE_ID "di"
272 #define OC_RSRVD_DEVICE_NAME "n"
274 /** Device specification version.*/
275 #define OC_RSRVD_SPEC_VERSION "icv"
277 /** Device data model.*/
278 #define OC_RSRVD_DATA_MODEL_VERSION "dmv"
280 /** Device specification version.*/
281 #define OC_SPEC_VERSION "core.1.1.0"
283 /** Device Data Model version.*/
284 #define OC_DATA_MODEL_VERSION "res.1.1.0"
287 * These provide backward compatibility - their use is deprecated.
291 /** Multicast Prefix.*/
292 #define OC_MULTICAST_PREFIX "224.0.1.187:5683"
294 /** Multicast IP address.*/
295 #define OC_MULTICAST_IP "224.0.1.187"
297 /** Multicast Port.*/
298 #define OC_MULTICAST_PORT (5683)
301 /** Max Device address size. */
303 #define MAX_ADDR_STR_SIZE (256)
305 /** Max Address could be
306 * "coaps+tcp://[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:yyy.yyy.yyy.yyy]:xxxxx"
307 * +1 for null terminator.
309 #define MAX_ADDR_STR_SIZE (66)
312 /** Length of MAC address */
313 #define MAC_ADDR_STR_SIZE (17)
315 /** Blocks of MAC address */
316 #define MAC_ADDR_BLOCKS (6)
318 /** Max identity size. */
319 #define MAX_IDENTITY_SIZE (37)
321 /** Universal unique identity size. */
322 #define UUID_IDENTITY_SIZE (128/8)
324 /** Resource Directory */
326 /** Resource Directory URI used to Discover RD and Publish resources.*/
327 #define OC_RSRVD_RD_URI "/oic/rd"
329 /** To represent resource type with rd.*/
330 #define OC_RSRVD_RESOURCE_TYPE_RD "oic.wk.rd"
332 /** RD Discovery bias factor type. */
333 #define OC_RSRVD_RD_DISCOVERY_SEL "sel"
335 /** Resource URI used to discover Proxy */
336 #define OC_RSRVD_PROXY_URI "/oic/chp"
338 /** Resource URI used to discover Proxy */
339 #define OC_RSRVD_PROXY_OPTION_ID 35
342 #define OC_RSRVD_BASE_URI "baseURI"
344 /** Unique value per collection/link. */
345 #define OC_RSRVD_INS "ins"
347 /** Allowable resource types in the links. */
348 #define OC_RSRVD_RTS "rts"
350 /** Default relationship. */
351 #define OC_RSRVD_DREL "drel"
353 /** Defines relationship between links. */
354 #define OC_RSRVD_REL "rel"
356 /** Defines title. */
357 #define OC_RSRVD_TITLE "title"
360 #define OC_RSRVD_URI "anchor"
362 /** Defines media type. */
363 #define OC_RSRVD_MEDIA_TYPE "type"
365 /** To represent resource type with Publish RD.*/
366 #define OC_RSRVD_RESOURCE_TYPE_RDPUBLISH "oic.wk.rdpub"
371 #define OC_RSRVD_ACCOUNT_URI "/oic/account"
373 /** Account user URI.*/
374 #define OC_RSRVD_ACCOUNT_SEARCH_URI "/oic/account/search"
376 /** Account session URI.*/
377 #define OC_RSRVD_ACCOUNT_SESSION_URI "/oic/account/session"
379 /** Account token refresh URI.*/
380 #define OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI "/oic/account/tokenrefresh"
383 #define OC_RSRVD_ACL_GROUP_URI "/oic/acl/group"
385 /** ACL invite URI.*/
386 #define OC_RSRVD_ACL_INVITE_URI "/oic/acl/invite"
388 /** Defines auth provider. */
389 #define OC_RSRVD_AUTHPROVIDER "authprovider"
391 /** Defines auth code. */
392 #define OC_RSRVD_AUTHCODE "authcode"
394 /** Defines access token. */
395 #define OC_RSRVD_ACCESS_TOKEN "accesstoken"
397 /** Defines login. */
398 #define OC_RSRVD_LOGIN "login"
400 /** Defines search. */
401 #define OC_RSRVD_SEARCH "search"
403 /** Defines grant type. */
404 #define OC_RSRVD_GRANT_TYPE "granttype"
406 /** Defines refresh token. */
407 #define OC_RSRVD_REFRESH_TOKEN "refreshtoken"
409 /** Defines user UUID. */
410 #define OC_RSRVD_USER_UUID "uid"
412 /** Defines group ID. */
413 #define OC_RSRVD_GROUP_ID "gid"
415 /** Defines member of group ID. */
416 #define OC_RSRVD_MEMBER_ID "mid"
418 /** Defines invite. */
419 #define OC_RSRVD_INVITE "invite"
421 /** Defines accept. */
422 #define OC_RSRVD_ACCEPT "accept"
424 /** Defines operation. */
425 #define OC_RSRVD_OPERATION "op"
428 #define OC_RSRVD_ADD "add"
430 /** Defines delete. */
431 #define OC_RSRVD_DELETE "delete"
433 /** Defines owner. */
434 #define OC_RSRVD_OWNER "owner"
436 /** Defines members. */
437 #define OC_RSRVD_MEMBERS "members"
439 /** To represent grant type with refresh token. */
440 #define OC_RSRVD_GRANT_TYPE_REFRESH_TOKEN "refresh_token"
443 #define OC_RSRVD_PROV_CRL_URL "/oic/credprov/crl"
445 #define OC_RSRVD_LAST_UPDATE "lu"
447 #define OC_RSRVD_THIS_UPDATE "tu"
449 #define OC_RSRVD_NEXT_UPDATE "nu"
451 #define OC_RSRVD_SERIAL_NUMBERS "rcsn"
453 #define OC_RSRVD_CRL "crl"
455 #define OC_RSRVD_CRL_ID "crlid"
458 #define OC_RSRVD_GROUP_URL "/oic/group"
460 #define OC_RSRVD_ACL_GROUP_URL "/oic/acl/group"
462 #define OC_RSRVD_ACL_INVITE_URL "/oic/acl/invite"
464 #define OC_RSRVD_ACL_VERIFY_URL "/oic/acl/verify"
466 #define OC_RSRVD_ACL_ID_URL "/oic/acl/id"
468 #define OC_RSRVD_MEMBER_ID "mid"
470 #define OC_RSRVD_GROUP_ID "gid"
472 #define OC_RSRVD_OWNER_ID "oid"
474 #define OC_RSRVD_ACL_ID "aclid"
476 #define OC_RSRVD_ACE_ID "aceid"
478 #define OC_RSRVD_DEVICE_ID "di"
480 #define OC_RSRVD_SUBJECT_ID "sid"
482 #define OC_RSRVD_REQUEST_METHOD "rm"
484 #define OC_RSRVD_REQUEST_URI "uri"
486 #define OC_RSRVD_GROUP_MASTER_ID "gmid"
488 #define OC_RSRVD_GROUP_TYPE "gtype"
490 #define OC_RSRVD_SUBJECT_TYPE "stype"
492 #define OC_RSRVD_GROUP_ID_LIST "gidlist"
494 #define OC_RSRVD_MEMBER_ID_LIST "midlist"
496 #define OC_RSRVD_DEVICE_ID_LIST "dilist"
498 #define OC_RSRVD_ACCESS_CONTROL_LIST "aclist"
500 #define OC_RSRVD_RESOURCES "resources"
502 #define OC_RSRVD_VALIDITY "validity"
504 #define OC_RSRVD_PERIOD "period"
506 #define OC_RSRVD_RECURRENCE "recurrence"
508 #define OC_RSRVD_INVITE "invite"
510 #define OC_RSRVD_INVITED "invited"
512 #define OC_RSRVD_ENCODING "encoding"
514 #define OC_OIC_SEC "oic.sec"
516 #define OC_RSRVD_BASE64 "base64"
518 #define OC_RSRVD_DER "der"
520 #define OC_RSRVD_PEM "pem"
522 #define OC_RSRVD_RAW "raw"
524 #define OC_RSRVD_UNKNOWN "unknown"
526 #define OC_RSRVD_DATA "data"
528 #define OC_RSRVD_RESOURCE_OWNER_UUID "rowneruuid"
530 #define OC_RSRVD_SUBJECT_UUID "subjectuuid"
532 #define OC_RSRVD_PERMISSION_MASK "permission"
534 #define OC_RSRVD_GROUP_PERMISSION "gp"
536 #define OC_RSRVD_GROUP_ACL "gacl"
538 /** Certificete Sign Request */
539 #define OC_RSRVD_PROV_CERT_URI "/oic/credprov/cert"
541 #define OC_RSRVD_CSR "csr"
543 #define OC_RSRVD_CERT "cert"
545 #define OC_RSRVD_CACERT "certchain"
547 #define OC_RSRVD_TOKEN_TYPE "tokentype"
549 #define OC_RSRVD_EXPIRES_IN "expiresin"
551 #define OC_RSRVD_REDIRECT_URI "redirecturi"
553 #define OC_RSRVD_CERTIFICATE "certificate"
555 * Mark a parameter as unused. Used to prevent unused variable compiler warnings.
556 * Used in three cases:
557 * 1. in callbacks when one of the parameters are unused
558 * 2. when due to code changes a functions parameter is no longer
559 * used but must be left in place for backward compatibility
561 * 3. a variable is only used in the debug build variant and would
562 * give a build warning in release mode.
564 #define OC_UNUSED(x) (void)(x)
567 * These enums (OCTransportAdapter and OCTransportFlags) must
568 * be kept synchronized with OCConnectivityType (below) as well as
569 * CATransportAdapter and CATransportFlags (in CACommon.h).
573 /** value zero indicates discovery.*/
574 OC_DEFAULT_ADAPTER = 0,
576 /** IPv4 and IPv6, including 6LoWPAN.*/
577 OC_ADAPTER_IP = (1 << 0),
579 /** GATT over Bluetooth LE.*/
580 OC_ADAPTER_GATT_BTLE = (1 << 1),
582 /** RFCOMM over Bluetooth EDR.*/
583 OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
585 /**Remote Access over XMPP.*/
586 OC_ADAPTER_REMOTE_ACCESS = (1 << 3),
589 OC_ADAPTER_TCP = (1 << 4),
591 /** NFC Transport for Messaging.*/
592 OC_ADAPTER_NFC = (1 << 5)
593 } OCTransportAdapter;
596 * Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
600 /** default flag is 0*/
601 OC_DEFAULT_FLAGS = 0,
603 /** Insecure transport is the default (subject to change).*/
604 /** secure the transport path*/
605 OC_FLAG_SECURE = (1 << 4),
607 /** IPv4 & IPv6 auto-selection is the default.*/
608 /** IP & TCP adapter only.*/
609 OC_IP_USE_V6 = (1 << 5),
611 /** IP & TCP adapter only.*/
612 OC_IP_USE_V4 = (1 << 6),
614 /** Multicast only.*/
615 OC_MULTICAST = (1 << 7),
617 /** Link-Local multicast is the default multicast scope for IPv6.
618 * These are placed here to correspond to the IPv6 multicast address bits.*/
620 /** IPv6 Interface-Local scope (loopback).*/
621 OC_SCOPE_INTERFACE = 0x1,
623 /** IPv6 Link-Local scope (default).*/
626 /** IPv6 Realm-Local scope. */
627 OC_SCOPE_REALM = 0x3,
629 /** IPv6 Admin-Local scope. */
630 OC_SCOPE_ADMIN = 0x4,
632 /** IPv6 Site-Local scope. */
635 /** IPv6 Organization-Local scope. */
638 /**IPv6 Global scope. */
639 OC_SCOPE_GLOBAL = 0xE,
643 /** Bit mask for scope.*/
644 #define OC_MASK_SCOPE (0x000F)
646 /** Bit mask for Mods.*/
647 #define OC_MASK_MODS (0x0FF0)
648 #define OC_MASK_FAMS (OC_IP_USE_V6|OC_IP_USE_V4)
650 typedef struct OCStringLL
652 struct OCStringLL *next;
657 * End point identity.
661 /** Identity Length */
664 /** Array of end point identity.*/
665 unsigned char id[MAX_IDENTITY_SIZE];
669 * Universally unique identifier.
673 /** identitifier string.*/
674 unsigned char id[UUID_IDENTITY_SIZE];
678 * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
679 * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
684 OCTransportAdapter adapter;
686 /** transport modifiers.*/
687 OCTransportFlags flags;
692 /** address for all adapters.*/
693 char addr[MAX_ADDR_STR_SIZE];
695 /** usually zero for default interface.*/
697 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
698 char routeData[MAX_ADDR_STR_SIZE]; //destination GatewayID:ClientId
703 * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
704 * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
705 * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
708 * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
712 /** use when defaults are ok. */
715 /** IPv4 and IPv6, including 6LoWPAN.*/
716 CT_ADAPTER_IP = (1 << 16),
718 /** GATT over Bluetooth LE.*/
719 CT_ADAPTER_GATT_BTLE = (1 << 17),
721 /** RFCOMM over Bluetooth EDR.*/
722 CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
725 /** Remote Access over XMPP.*/
726 CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
729 CT_ADAPTER_TCP = (1 << 20),
732 CT_ADAPTER_NFC = (1 << 21),
734 /** Insecure transport is the default (subject to change).*/
736 /** secure the transport path.*/
737 CT_FLAG_SECURE = (1 << 4),
739 /** IPv4 & IPv6 autoselection is the default.*/
741 /** IP adapter only.*/
742 CT_IP_USE_V6 = (1 << 5),
744 /** IP adapter only.*/
745 CT_IP_USE_V4 = (1 << 6),
747 /** Link-Local multicast is the default multicast scope for IPv6.
748 * These are placed here to correspond to the IPv6 address bits.*/
750 /** IPv6 Interface-Local scope(loopback).*/
751 CT_SCOPE_INTERFACE = 0x1,
753 /** IPv6 Link-Local scope (default).*/
756 /** IPv6 Realm-Local scope.*/
757 CT_SCOPE_REALM = 0x3,
759 /** IPv6 Admin-Local scope.*/
760 CT_SCOPE_ADMIN = 0x4,
762 /** IPv6 Site-Local scope.*/
765 /** IPv6 Organization-Local scope.*/
768 /** IPv6 Global scope.*/
769 CT_SCOPE_GLOBAL = 0xE,
770 } OCConnectivityType;
772 /** bit shift required for connectivity adapter.*/
773 #define CT_ADAPTER_SHIFT 16
776 #define CT_MASK_FLAGS 0xFFFF
779 #define CT_MASK_ADAPTER 0xFFFF0000
782 * OCDoResource methods to dispatch the request
786 OC_REST_NOMETHOD = 0,
789 OC_REST_GET = (1 << 0),
792 OC_REST_PUT = (1 << 1),
795 OC_REST_POST = (1 << 2),
798 OC_REST_DELETE = (1 << 3),
800 /** Register observe request for most up date notifications ONLY.*/
801 OC_REST_OBSERVE = (1 << 4),
803 /** Register observe request for all notifications, including stale notifications.*/
804 OC_REST_OBSERVE_ALL = (1 << 5),
807 /** Subscribe for all presence notifications of a particular resource.*/
808 OC_REST_PRESENCE = (1 << 7),
811 /** Allows OCDoResource caller to do discovery.*/
812 OC_REST_DISCOVER = (1 << 8)
816 * Formats for payload encoding.
823 OC_FORMAT_UNSUPPORTED,
827 * Host Mode of Operation.
834 OC_GATEWAY /**< Client server mode along with routing capabilities.*/
838 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
839 * protocol. The precise definitions of each quality of service level depend on the
840 * implementation. In descriptions below are for the current implementation and may changed
845 /** Packet delivery is best effort.*/
848 /** Packet delivery is best effort.*/
851 /** Acknowledgments are used to confirm delivery.*/
854 /** No Quality is defined, let the stack decide.*/
856 } OCQualityOfService;
859 * Resource Properties.
860 * The value of a policy property is defined as bitmap.
861 * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
862 * Not including the policy property is equivalent to zero.
867 /** When none of the bits are set, the resource is non-discoverable &
868 * non-observable by the client.*/
869 OC_RES_PROP_NONE = (0),
871 /** When this bit is set, the resource is allowed to be discovered by clients.*/
872 OC_DISCOVERABLE = (1 << 0),
874 /** When this bit is set, the resource is allowed to be observed by clients.*/
875 OC_OBSERVABLE = (1 << 1),
877 /** When this bit is set, the resource is initialized, otherwise the resource
878 * is 'inactive'. 'inactive' signifies that the resource has been marked for
879 * deletion or is already deleted.*/
880 OC_ACTIVE = (1 << 2),
882 /** When this bit is set, the resource has been marked as 'slow'.
883 * 'slow' signifies that responses from this resource can expect delays in
884 * processing its requests from clients.*/
887 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
888 /** When this bit is set, the resource is a secure resource.*/
889 OC_SECURE = (1 << 4),
894 /** When this bit is set, the resource is allowed to be discovered only
895 * if discovery request contains an explicit querystring.
896 * Ex: GET /oic/res?rt=oic.sec.acl */
897 OC_EXPLICIT_DISCOVERABLE = (1 << 5)
900 /** When this bit is set, the resource is allowed to be published */
901 ,OC_MQ_PUBLISHER = (1 << 6)
905 /** When this bit is set, the resource is allowed to be notified as MQ broker.*/
906 ,OC_MQ_BROKER = (1 << 7)
908 } OCResourceProperty;
911 * Transport Protocol IDs.
915 /** For invalid ID.*/
916 OC_INVALID_ID = (1 << 0),
919 OC_COAP_ID = (1 << 1)
920 } OCTransportProtocolID;
923 * Declares Stack Results & Errors.
927 /** Success status code - START HERE.*/
929 OC_STACK_RESOURCE_CREATED,
930 OC_STACK_RESOURCE_DELETED,
932 OC_STACK_RESOURCE_CHANGED,
933 /** Success status code - END HERE.*/
935 /** Error status code - START HERE.*/
936 OC_STACK_INVALID_URI = 20,
937 OC_STACK_INVALID_QUERY,
939 OC_STACK_INVALID_PORT,
940 OC_STACK_INVALID_CALLBACK,
941 OC_STACK_INVALID_METHOD,
943 /** Invalid parameter.*/
944 OC_STACK_INVALID_PARAM,
945 OC_STACK_INVALID_OBSERVE_PARAM,
949 OC_STACK_ADAPTER_NOT_ENABLED,
952 /** Resource not found.*/
953 OC_STACK_NO_RESOURCE,
955 /** e.g: not supported method or interface.*/
956 OC_STACK_RESOURCE_ERROR,
957 OC_STACK_SLOW_RESOURCE,
958 OC_STACK_DUPLICATE_REQUEST,
960 /** Resource has no registered observers.*/
961 OC_STACK_NO_OBSERVERS,
962 OC_STACK_OBSERVER_NOT_FOUND,
963 OC_STACK_VIRTUAL_DO_NOT_HANDLE,
964 OC_STACK_INVALID_OPTION,
966 /** The remote reply contained malformed data.*/
967 OC_STACK_MALFORMED_RESPONSE,
968 OC_STACK_PERSISTENT_BUFFER_REQUIRED,
969 OC_STACK_INVALID_REQUEST_HANDLE,
970 OC_STACK_INVALID_DEVICE_INFO,
971 OC_STACK_INVALID_JSON,
973 /** Request is not authorized by Resource Server. */
974 OC_STACK_UNAUTHORIZED_REQ,
975 OC_STACK_TOO_LARGE_REQ,
977 /** Error code from PDM */
978 OC_STACK_PDM_IS_NOT_INITIALIZED,
979 OC_STACK_DUPLICATE_UUID,
980 OC_STACK_INCONSISTENT_DB,
983 * Error code from OTM
984 * This error is pushed from DTLS interface when handshake failure happens
986 OC_STACK_AUTHENTICATION_FAILURE,
987 OC_STACK_NOT_ALLOWED_OXM,
989 /** Insert all new error codes here!.*/
991 OC_STACK_PRESENCE_STOPPED = 128,
992 OC_STACK_PRESENCE_TIMEOUT,
993 OC_STACK_PRESENCE_DO_NOT_HANDLE,
996 /** ERROR code from server */
997 OC_STACK_FORBIDDEN_REQ, /** 403*/
998 OC_STACK_INTERNAL_SERVER_ERROR, /** 500*/
1000 /** ERROR in stack.*/
1001 OC_STACK_ERROR = 255
1002 /** Error status code - END HERE.*/
1006 * Handle to an OCDoResource invocation.
1008 typedef void * OCDoHandle;
1011 * Handle to an OCResource object owned by the OCStack.
1013 typedef void * OCResourceHandle;
1016 * Handle to an OCRequest object owned by the OCStack.
1018 typedef void * OCRequestHandle;
1021 * Unique identifier for each observation request. Used when observations are
1022 * registered or de-registered. Used by entity handler to signal specific
1023 * observers to be notified of resource changes.
1024 * There can be maximum of 256 observations per server.
1026 typedef uint8_t OCObservationId;
1029 * Sequence number is a 24 bit field,
1030 * per https://tools.ietf.org/html/rfc7641.
1032 #define MAX_SEQUENCE_NUMBER (0xFFFFFF)
1035 * Action associated with observation.
1040 OC_OBSERVE_REGISTER = 0,
1042 /** To Deregister. */
1043 OC_OBSERVE_DEREGISTER = 1,
1046 OC_OBSERVE_NO_OPTION = 2,
1052 * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
1053 * when it calls OCRegisterPersistentStorageHandler.
1054 * Persistent storage open handler points to default file path.
1055 * It should check file path and whether the file is symbolic link or no.
1056 * Application can point to appropriate SVR database path for it's IoTivity Server.
1059 /** Persistent storage file path.*/
1060 FILE* (* open)(const char *path, const char *mode);
1062 /** Persistent storage read handler.*/
1063 size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
1065 /** Persistent storage write handler.*/
1066 size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
1068 /** Persistent storage close handler.*/
1069 int (* close)(FILE *fp);
1071 /** Persistent storage unlink handler.*/
1072 int (* unlink)(const char *path);
1073 } OCPersistentStorage;
1076 * Possible returned values from entity handler.
1080 /** Action associated with observation request.*/
1081 OCObserveAction action;
1083 /** Identifier for observation being registered/deregistered.*/
1084 OCObservationId obsId;
1085 } OCObservationInfo;
1088 * Possible returned values from entity handler.
1095 OC_EH_RESOURCE_CREATED = 201,
1096 OC_EH_RESOURCE_DELETED = 202,
1098 OC_EH_CHANGED = 204,
1099 OC_EH_CONTENT = 205,
1100 OC_EH_BAD_REQ = 400,
1101 OC_EH_UNAUTHORIZED_REQ = 401,
1102 OC_EH_BAD_OPT = 402,
1103 OC_EH_FORBIDDEN = 403,
1104 OC_EH_RESOURCE_NOT_FOUND = 404,
1105 OC_EH_METHOD_NOT_ALLOWED = 405,
1106 OC_EH_NOT_ACCEPTABLE = 406,
1107 OC_EH_TOO_LARGE = 413,
1108 OC_EH_UNSUPPORTED_MEDIA_TYPE = 415,
1109 OC_EH_INTERNAL_SERVER_ERROR = 500,
1110 OC_EH_BAD_GATEWAY = 502,
1111 OC_EH_SERVICE_UNAVAILABLE = 503,
1112 OC_EH_RETRANSMIT_TIMEOUT = 504
1113 } OCEntityHandlerResult;
1116 * This structure will be used to define the vendor specific header options to be included
1117 * in communication packets.
1119 typedef struct OCHeaderOption
1121 /** The protocol ID this option applies to.*/
1122 OCTransportProtocolID protocolID;
1124 /** The header option ID which will be added to communication packets.*/
1127 /** its length 191.*/
1128 uint16_t optionLength;
1130 /** pointer to its data.*/
1131 uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
1133 #ifdef SUPPORTS_DEFAULT_CTOR
1134 OCHeaderOption() = default;
1135 OCHeaderOption(OCTransportProtocolID pid,
1138 const uint8_t* optData)
1141 optionLength(optlen)
1144 // parameter includes the null terminator.
1145 optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
1146 optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
1147 memcpy(optionData, optData, optionLength);
1148 optionData[optionLength - 1] = '\0';
1154 * This structure describes the platform properties. All non-Null properties will be
1155 * included in a platform discovery request.
1162 /** Manufacturer name.*/
1163 char *manufacturerName;
1165 /** Manufacturer URL for platform property.*/
1166 char *manufacturerUrl;
1171 /** Manufacturer date.*/
1172 char *dateOfManufacture;
1174 /** Platform version.*/
1175 char *platformVersion;
1177 /** Operating system version.*/
1178 char *operatingSystemVersion;
1181 char *hardwareVersion;
1184 char *firmwareVersion;
1186 /** Platform support URL.*/
1195 * This structure is expected as input for device properties.
1196 * device name is mandatory and expected from the application.
1197 * device id of type UUID will be generated by the stack.
1201 /** Pointer to the device name.*/
1203 /** Pointer to the types.*/
1205 /** Pointer to the device specification version.*/
1207 /** Pointer to the device data model versions (in CSV format).*/
1208 OCStringLL *dataModelVersions;
1213 * callback for bound JID
1215 typedef void (*jid_bound_cb)(char *jid);
1218 * CA Remote Access information for XMPP Client
1223 char *hostname; /**< XMPP server hostname */
1224 uint16_t port; /**< XMPP server serivce port */
1225 char *xmpp_domain; /**< XMPP login domain */
1226 char *username; /**< login username */
1227 char *password; /**< login password */
1228 char *resource; /**< specific resource for login */
1229 char *user_jid; /**< specific JID for login */
1230 jid_bound_cb jidbound; /**< callback when JID bound */
1232 #endif /* RA_ADAPTER */
1235 /** Enum to describe the type of object held by the OCPayload object.*/
1238 /** Contents of the payload are invalid */
1239 PAYLOAD_TYPE_INVALID,
1240 /** The payload is an OCDiscoveryPayload */
1241 PAYLOAD_TYPE_DISCOVERY,
1242 /** The payload is an OCDevicePayload */
1243 PAYLOAD_TYPE_DEVICE,
1244 /** The payload is an OCPlatformPayload */
1245 PAYLOAD_TYPE_PLATFORM,
1246 /** The payload is an OCRepPayload */
1247 PAYLOAD_TYPE_REPRESENTATION,
1248 /** The payload is an OCSecurityPayload */
1249 PAYLOAD_TYPE_SECURITY,
1250 /** The payload is an OCPresencePayload */
1251 PAYLOAD_TYPE_PRESENCE
1255 * A generic struct representing a payload returned from a resource operation
1257 * A pointer to OCPayLoad can be cast to a more specific struct to access members
1262 /** The type of message that was received */
1273 OCREP_PROP_BYTE_STRING,
1276 }OCRepPayloadPropType;
1278 /** This structure will be used to represent a binary string for CBOR payloads.*/
1281 /** pointer to data bytes.*/
1284 /** number of data bytes.*/
1288 #define MAX_REP_ARRAY_DEPTH 3
1291 OCRepPayloadPropType type;
1292 size_t dimensions[MAX_REP_ARRAY_DEPTH];
1301 /** pointer to ByteString array.*/
1302 OCByteString* ocByteStrArray;
1304 struct OCRepPayload** objArray;
1306 } OCRepPayloadValueArray;
1308 typedef struct OCRepPayloadValue
1311 OCRepPayloadPropType type;
1319 /** ByteString object.*/
1320 OCByteString ocByteStr;
1322 struct OCRepPayload* obj;
1323 OCRepPayloadValueArray arr;
1325 struct OCRepPayloadValue* next;
1327 } OCRepPayloadValue;
1329 // used for get/set/put/observe/etc representations
1330 typedef struct OCRepPayload
1335 OCStringLL* interfaces;
1336 OCRepPayloadValue* values;
1337 struct OCRepPayload* next;
1340 // used inside a discovery payload
1341 typedef struct OCResourcePayload
1345 OCStringLL* interfaces;
1352 struct OCResourcePayload* next;
1353 } OCResourcePayload;
1355 typedef struct OCDiscoveryPayload
1362 /** A special case for handling RD address. */
1371 /** Resource Type */
1377 /** This structure holds the old /oic/res response. */
1378 OCResourcePayload *resources;
1380 /** Holding address of the next DiscoveryPayload. */
1381 struct OCDiscoveryPayload *next;
1383 } OCDiscoveryPayload;
1391 OCStringLL *dataModelVersions;
1392 OCStringLL *interfaces;
1400 OCPlatformInfo info;
1402 OCStringLL* interfaces;
1403 } OCPlatformPayload;
1408 uint8_t* securityData;
1410 } OCSecurityPayload;
1412 #ifdef WITH_PRESENCE
1416 uint32_t sequenceNumber;
1418 OCPresenceTrigger trigger;
1420 } OCPresencePayload;
1424 * Incoming requests handled by the server. Requests are passed in as a parameter to the
1425 * OCEntityHandler callback API.
1426 * The OCEntityHandler callback API must be implemented in the application in order
1427 * to receive these requests.
1431 /** Associated resource.*/
1432 OCResourceHandle resource;
1434 /** Associated request handle.*/
1435 OCRequestHandle requestHandle;
1437 /** the REST method retrieved from received request PDU.*/
1440 /** description of endpoint that sent the request.*/
1443 /** resource query send by client.*/
1446 /** Information associated with observation - valid only when OCEntityHandler flag includes
1447 * ::OC_OBSERVE_FLAG.*/
1448 OCObservationInfo obsInfo;
1450 /** Number of the received vendor specific header options.*/
1451 uint8_t numRcvdVendorSpecificHeaderOptions;
1453 /** Pointer to the array of the received vendor specific header options.*/
1454 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1459 /** the payload from the request PDU.*/
1462 } OCEntityHandlerRequest;
1466 * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1470 /** Address of remote server.*/
1473 /** backward compatibility (points to devAddr).*/
1476 /** backward compatibility.*/
1477 OCConnectivityType connType;
1479 /** the security identity of the remote server.*/
1480 OCIdentity identity;
1482 /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1483 OCStackResult result;
1485 /** If associated with observe, this will represent the sequence of notifications from server.*/
1486 uint32_t sequenceNumber;
1489 const char * resourceUri;
1491 /** the payload for the response PDU.*/
1494 /** Number of the received vendor specific header options.*/
1495 uint8_t numRcvdVendorSpecificHeaderOptions;
1497 /** An array of the received vendor specific header options.*/
1498 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1502 * Request handle is passed to server via the entity handler for each incoming request.
1503 * Stack assigns when request is received, server sets to indicate what request response is for.
1507 /** Request handle.*/
1508 OCRequestHandle requestHandle;
1510 /** Resource handle.*/
1511 OCResourceHandle resourceHandle;
1513 /** Allow the entity handler to pass a result with the response.*/
1514 OCEntityHandlerResult ehResult;
1516 /** This is the pointer to server payload data to be transferred.*/
1519 /** number of the vendor specific header options .*/
1520 uint8_t numSendVendorSpecificHeaderOptions;
1522 /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1523 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1525 /** URI of new resource that entity handler might create.*/
1526 char resourceUri[MAX_URI_LENGTH];
1528 /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1529 uint8_t persistentBufferFlag;
1530 } OCEntityHandlerResponse;
1537 /** Request state.*/
1538 OC_REQUEST_FLAG = (1 << 1),
1539 /** Observe state.*/
1540 OC_OBSERVE_FLAG = (1 << 2)
1541 } OCEntityHandlerFlag;
1544 * Possible return values from client application callback
1546 * A client application callback returns an OCStackApplicationResult to indicate whether
1547 * the stack should continue to keep the callback registered.
1551 /** Make no more calls to the callback and call the OCClientContextDeleter for this callback */
1552 OC_STACK_DELETE_TRANSACTION = 0,
1553 /** Keep this callback registered and call it if an apropriate event occurs */
1554 OC_STACK_KEEP_TRANSACTION
1555 } OCStackApplicationResult;
1558 //#ifdef DIRECT_PAIRING
1560 * @brief direct pairing Method Type.
1562 * 1: pre-configured pin
1567 DP_NOT_ALLOWED = 0x0,
1568 DP_PRE_CONFIGURED = (0x1 << 0),
1569 DP_RANDOM_PIN = (0x1 << 1),
1573 * Device Information of discoverd direct pairing device(s).
1575 typedef struct OCDPDev
1578 OCConnectivityType connType;
1579 uint16_t securePort;
1583 OCUUIdentity deviceID;
1584 OCUUIdentity rowner;
1585 struct OCDPDev *next;
1587 //#endif // DIRECT_PAIRING
1590 * -------------------------------------------------------------------------------------------
1591 * Callback function definitions
1592 * -------------------------------------------------------------------------------------------
1596 * Client applications implement this callback to consume responses received from Servers.
1598 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1599 OCClientResponse * clientResponse);
1602 * Client applications using a context pointer implement this callback to delete the
1603 * context upon removal of the callback/context pointer from the internal callback-list.
1605 typedef void (* OCClientContextDeleter)(void *context);
1608 * This info is passed from application to OC Stack when initiating a request to Server.
1610 typedef struct OCCallbackData
1612 /** Pointer to the context.*/
1615 /** The pointer to a function the stack will call to handle the requests.*/
1616 OCClientResponseHandler cb;
1618 /** A pointer to a function to delete the context when this callback is removed.*/
1619 OCClientContextDeleter cd;
1621 #ifdef SUPPORTS_DEFAULT_CTOR
1622 OCCallbackData() = default;
1623 OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1624 :context(ctx), cb(callback), cd(deleter){}
1629 * Application server implementations must implement this callback to consume requests OTA.
1630 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1632 * When you set specific return value like OC_EH_CHANGED, OC_EH_CONTENT,
1633 * OC_EH_SLOW and etc in entity handler callback,
1634 * ocstack will be not send response automatically to client
1635 * except for error return value like OC_EH_ERROR.
1637 * If you want to send response to client with specific result,
1638 * OCDoResponse API should be called with the result value.
1642 * OCEntityHandlerResponse response;
1646 * response.ehResult = OC_EH_CHANGED;
1650 * OCDoResponse(&response)
1656 typedef OCEntityHandlerResult (*OCEntityHandler)
1657 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1660 * Device Entity handler need to use this call back instead of OCEntityHandler.
1662 * When you set specific return value like OC_EH_CHANGED, OC_EH_CONTENT,
1663 * OC_EH_SLOW and etc in entity handler callback,
1664 * ocstack will be not send response automatically to client
1665 * except for error return value like OC_EH_ERROR.
1667 * If you want to send response to client with specific result,
1668 * OCDoResponse API should be called with the result value.
1672 * OCEntityHandlerResponse response;
1676 * response.ehResult = OC_EH_CHANGED;
1680 * OCDoResponse(&response)
1686 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1687 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1689 //#ifdef DIRECT_PAIRING
1691 * Callback function definition of direct-pairing
1693 * @param[OUT] ctx - user context returned in the callback.
1694 * @param[OUT] peer - pairing device info.
1695 * @param[OUT] result - It's returned with 'OC_STACK_XXX'. It will return 'OC_STACK_OK'
1696 * if D2D pairing is success without error
1698 typedef void (*OCDirectPairingCB)(void *ctx, OCDPDev_t *peer, OCStackResult result);
1699 //#endif // DIRECT_PAIRING
1701 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
1703 * Callback function definition for Change in TrustCertChain
1705 * @param[IN] ctx - user context returned in the callback.
1706 * @param[IN] credId - trustCertChain changed for this ID
1707 * @param[IN] trustCertChain - trustcertchain binary blob.
1708 * @param[IN] chainSize - size of trustchain
1710 typedef void (*TrustCertChainChangeCB)(void *ctx, uint16_t credId, uint8_t *trustCertChain,
1714 * certChain context structure.
1716 typedef struct trustCertChainContext
1718 TrustCertChainChangeCB callback;
1720 } trustCertChainContext_t;
1725 #endif // __cplusplus
1727 #endif /* OCTYPES_H_ */