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 session URI.*/
374 #define OC_RSRVD_ACCOUNT_SESSION_URI "/oic/account/session"
376 /** Account token refresh URI.*/
377 #define OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI "/oic/account/tokenrefresh"
380 #define OC_RSRVD_ACL_GROUP_URI "/oic/acl/group"
382 /** ACL invite URI.*/
383 #define OC_RSRVD_ACL_INVITE_URI "/oic/acl/invite"
385 /** Defines auth provider. */
386 #define OC_RSRVD_AUTHPROVIDER "authprovider"
388 /** Defines auth code. */
389 #define OC_RSRVD_AUTHCODE "authcode"
391 /** Defines access token. */
392 #define OC_RSRVD_ACCESS_TOKEN "accesstoken"
394 /** Defines login. */
395 #define OC_RSRVD_LOGIN "login"
397 /** Defines search. */
398 #define OC_RSRVD_SEARCH "search"
400 /** Defines grant type. */
401 #define OC_RSRVD_GRANT_TYPE "granttype"
403 /** Defines refresh token. */
404 #define OC_RSRVD_REFRESH_TOKEN "refreshtoken"
406 /** Defines user UUID. */
407 #define OC_RSRVD_USER_UUID "uid"
409 /** Defines user ID. */
410 #define OC_RSRVD_USER_ID "userid"
412 /** Defines group ID. */
413 #define OC_RSRVD_GROUP_ID "gid"
415 /** Defines group Master ID. */
416 #define OC_RSRVD_GROUP_MASTER_ID "gmid"
418 /** Defines group type. */
419 #define OC_RSRVD_GROUP_TYPE "gtype"
421 /** Defines member of group ID. */
422 #define OC_RSRVD_MEMBER_ID "mid"
424 /** Defines device ID list. */
425 #define OC_RSRVD_DEVICE_ID_LIST "dilist"
427 /** Defines public. */
428 #define OC_RSRVD_PUBLIC "Public"
430 /** Defines private. */
431 #define OC_RSRVD_PRIVATE "Private"
433 /** Defines invite. */
434 #define OC_RSRVD_INVITE "invite"
436 /** To represent grant type with refresh token. */
437 #define OC_RSRVD_GRANT_TYPE_REFRESH_TOKEN "refresh_token"
440 #define OC_RSRVD_PROV_CRL_URL "/oic/credprov/crl"
442 #define OC_RSRVD_LAST_UPDATE "lu"
444 #define OC_RSRVD_THIS_UPDATE "tu"
446 #define OC_RSRVD_NEXT_UPDATE "nu"
448 #define OC_RSRVD_SERIAL_NUMBERS "rcsn"
450 #define OC_RSRVD_CRL "crl"
452 #define OC_RSRVD_CRL_ID "crlid"
455 #define OC_RSRVD_GROUP_URL "/oic/group"
457 #define OC_RSRVD_ACL_GROUP_URL "/oic/acl/group"
459 #define OC_RSRVD_ACL_INVITE_URL "/oic/acl/invite"
461 #define OC_RSRVD_ACL_VERIFY_URL "/oic/acl/verify"
463 #define OC_RSRVD_ACL_ID_URL "/oic/acl/id"
465 #define OC_RSRVD_MEMBER_ID "mid"
467 #define OC_RSRVD_GROUP_ID "gid"
469 #define OC_RSRVD_OWNER_ID "oid"
471 #define OC_RSRVD_ACL_ID "aclid"
473 #define OC_RSRVD_ACE_ID "aceid"
475 #define OC_RSRVD_DEVICE_ID "di"
477 #define OC_RSRVD_SUBJECT_ID "sid"
479 #define OC_RSRVD_REQUEST_METHOD "rm"
481 #define OC_RSRVD_REQUEST_URI "uri"
483 #define OC_RSRVD_GROUP_MASTER_ID "gmid"
485 #define OC_RSRVD_GROUP_TYPE "gtype"
487 #define OC_RSRVD_SUBJECT_TYPE "stype"
489 #define OC_RSRVD_GROUP_ID_LIST "gidlist"
491 #define OC_RSRVD_MEMBER_ID_LIST "midlist"
493 #define OC_RSRVD_DEVICE_ID_LIST "dilist"
495 #define OC_RSRVD_ACCESS_CONTROL_LIST "aclist"
497 #define OC_RSRVD_RESOURCES "resources"
499 #define OC_RSRVD_VALIDITY "validity"
501 #define OC_RSRVD_PERIOD "period"
503 #define OC_RSRVD_RECURRENCE "recurrence"
505 #define OC_RSRVD_INVITE "invite"
507 #define OC_RSRVD_INVITED "invited"
509 #define OC_RSRVD_ENCODING "encoding"
511 #define OC_OIC_SEC "oic.sec"
513 #define OC_RSRVD_BASE64 "base64"
515 #define OC_RSRVD_DER "der"
517 #define OC_RSRVD_PEM "pem"
519 #define OC_RSRVD_RAW "raw"
521 #define OC_RSRVD_UNKNOWN "unknown"
523 #define OC_RSRVD_DATA "data"
525 #define OC_RSRVD_RESOURCE_OWNER_UUID "rowneruuid"
527 #define OC_RSRVD_SUBJECT_UUID "subjectuuid"
529 #define OC_RSRVD_PERMISSION_MASK "permission"
531 #define OC_RSRVD_GROUP_PERMISSION "gp"
533 #define OC_RSRVD_GROUP_ACL "gacl"
535 /** Certificete Sign Request */
536 #define OC_RSRVD_PROV_CERT_URI "/oic/credprov/cert"
538 #define OC_RSRVD_CSR "csr"
540 #define OC_RSRVD_CERT "cert"
542 #define OC_RSRVD_CACERT "certchain"
544 #define OC_RSRVD_TOKEN_TYPE "tokentype"
546 #define OC_RSRVD_EXPIRES_IN "expiresin"
548 #define OC_RSRVD_REDIRECT_URI "redirecturi"
550 #define OC_RSRVD_CERTIFICATE "certificate"
552 * Mark a parameter as unused. Used to prevent unused variable compiler warnings.
553 * Used in three cases:
554 * 1. in callbacks when one of the parameters are unused
555 * 2. when due to code changes a functions parameter is no longer
556 * used but must be left in place for backward compatibility
558 * 3. a variable is only used in the debug build variant and would
559 * give a build warning in release mode.
561 #define OC_UNUSED(x) (void)(x)
564 * These enums (OCTransportAdapter and OCTransportFlags) must
565 * be kept synchronized with OCConnectivityType (below) as well as
566 * CATransportAdapter and CATransportFlags (in CACommon.h).
570 /** value zero indicates discovery.*/
571 OC_DEFAULT_ADAPTER = 0,
573 /** IPv4 and IPv6, including 6LoWPAN.*/
574 OC_ADAPTER_IP = (1 << 0),
576 /** GATT over Bluetooth LE.*/
577 OC_ADAPTER_GATT_BTLE = (1 << 1),
579 /** RFCOMM over Bluetooth EDR.*/
580 OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
582 /**Remote Access over XMPP.*/
583 OC_ADAPTER_REMOTE_ACCESS = (1 << 3),
586 OC_ADAPTER_TCP = (1 << 4),
588 /** NFC Transport for Messaging.*/
589 OC_ADAPTER_NFC = (1 << 5)
590 } OCTransportAdapter;
593 * Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
597 /** default flag is 0*/
598 OC_DEFAULT_FLAGS = 0,
600 /** Insecure transport is the default (subject to change).*/
601 /** secure the transport path*/
602 OC_FLAG_SECURE = (1 << 4),
604 /** IPv4 & IPv6 auto-selection is the default.*/
605 /** IP & TCP adapter only.*/
606 OC_IP_USE_V6 = (1 << 5),
608 /** IP & TCP adapter only.*/
609 OC_IP_USE_V4 = (1 << 6),
611 /** Multicast only.*/
612 OC_MULTICAST = (1 << 7),
614 /** Link-Local multicast is the default multicast scope for IPv6.
615 * These are placed here to correspond to the IPv6 multicast address bits.*/
617 /** IPv6 Interface-Local scope (loopback).*/
618 OC_SCOPE_INTERFACE = 0x1,
620 /** IPv6 Link-Local scope (default).*/
623 /** IPv6 Realm-Local scope. */
624 OC_SCOPE_REALM = 0x3,
626 /** IPv6 Admin-Local scope. */
627 OC_SCOPE_ADMIN = 0x4,
629 /** IPv6 Site-Local scope. */
632 /** IPv6 Organization-Local scope. */
635 /**IPv6 Global scope. */
636 OC_SCOPE_GLOBAL = 0xE,
640 /** Bit mask for scope.*/
641 #define OC_MASK_SCOPE (0x000F)
643 /** Bit mask for Mods.*/
644 #define OC_MASK_MODS (0x0FF0)
645 #define OC_MASK_FAMS (OC_IP_USE_V6|OC_IP_USE_V4)
647 typedef struct OCStringLL
649 struct OCStringLL *next;
654 * End point identity.
658 /** Identity Length */
661 /** Array of end point identity.*/
662 unsigned char id[MAX_IDENTITY_SIZE];
666 * Universally unique identifier.
670 /** identitifier string.*/
671 unsigned char id[UUID_IDENTITY_SIZE];
675 * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
676 * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
681 OCTransportAdapter adapter;
683 /** transport modifiers.*/
684 OCTransportFlags flags;
689 /** address for all adapters.*/
690 char addr[MAX_ADDR_STR_SIZE];
692 /** usually zero for default interface.*/
694 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
695 char routeData[MAX_ADDR_STR_SIZE]; //destination GatewayID:ClientId
700 * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
701 * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
702 * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
705 * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
709 /** use when defaults are ok. */
712 /** IPv4 and IPv6, including 6LoWPAN.*/
713 CT_ADAPTER_IP = (1 << 16),
715 /** GATT over Bluetooth LE.*/
716 CT_ADAPTER_GATT_BTLE = (1 << 17),
718 /** RFCOMM over Bluetooth EDR.*/
719 CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
722 /** Remote Access over XMPP.*/
723 CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
726 CT_ADAPTER_TCP = (1 << 20),
729 CT_ADAPTER_NFC = (1 << 21),
731 /** Insecure transport is the default (subject to change).*/
733 /** secure the transport path.*/
734 CT_FLAG_SECURE = (1 << 4),
736 /** IPv4 & IPv6 autoselection is the default.*/
738 /** IP adapter only.*/
739 CT_IP_USE_V6 = (1 << 5),
741 /** IP adapter only.*/
742 CT_IP_USE_V4 = (1 << 6),
744 /** Link-Local multicast is the default multicast scope for IPv6.
745 * These are placed here to correspond to the IPv6 address bits.*/
747 /** IPv6 Interface-Local scope(loopback).*/
748 CT_SCOPE_INTERFACE = 0x1,
750 /** IPv6 Link-Local scope (default).*/
753 /** IPv6 Realm-Local scope.*/
754 CT_SCOPE_REALM = 0x3,
756 /** IPv6 Admin-Local scope.*/
757 CT_SCOPE_ADMIN = 0x4,
759 /** IPv6 Site-Local scope.*/
762 /** IPv6 Organization-Local scope.*/
765 /** IPv6 Global scope.*/
766 CT_SCOPE_GLOBAL = 0xE,
767 } OCConnectivityType;
769 /** bit shift required for connectivity adapter.*/
770 #define CT_ADAPTER_SHIFT 16
773 #define CT_MASK_FLAGS 0xFFFF
776 #define CT_MASK_ADAPTER 0xFFFF0000
779 * OCDoResource methods to dispatch the request
783 OC_REST_NOMETHOD = 0,
786 OC_REST_GET = (1 << 0),
789 OC_REST_PUT = (1 << 1),
792 OC_REST_POST = (1 << 2),
795 OC_REST_DELETE = (1 << 3),
797 /** Register observe request for most up date notifications ONLY.*/
798 OC_REST_OBSERVE = (1 << 4),
800 /** Register observe request for all notifications, including stale notifications.*/
801 OC_REST_OBSERVE_ALL = (1 << 5),
804 /** Subscribe for all presence notifications of a particular resource.*/
805 OC_REST_PRESENCE = (1 << 7),
808 /** Allows OCDoResource caller to do discovery.*/
809 OC_REST_DISCOVER = (1 << 8)
813 * Formats for payload encoding.
820 OC_FORMAT_UNSUPPORTED,
824 * Host Mode of Operation.
831 OC_GATEWAY /**< Client server mode along with routing capabilities.*/
835 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
836 * protocol. The precise definitions of each quality of service level depend on the
837 * implementation. In descriptions below are for the current implementation and may changed
842 /** Packet delivery is best effort.*/
845 /** Packet delivery is best effort.*/
848 /** Acknowledgments are used to confirm delivery.*/
851 /** No Quality is defined, let the stack decide.*/
853 } OCQualityOfService;
856 * Resource Properties.
857 * The value of a policy property is defined as bitmap.
858 * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
859 * Not including the policy property is equivalent to zero.
864 /** When none of the bits are set, the resource is non-discoverable &
865 * non-observable by the client.*/
866 OC_RES_PROP_NONE = (0),
868 /** When this bit is set, the resource is allowed to be discovered by clients.*/
869 OC_DISCOVERABLE = (1 << 0),
871 /** When this bit is set, the resource is allowed to be observed by clients.*/
872 OC_OBSERVABLE = (1 << 1),
874 /** When this bit is set, the resource is initialized, otherwise the resource
875 * is 'inactive'. 'inactive' signifies that the resource has been marked for
876 * deletion or is already deleted.*/
877 OC_ACTIVE = (1 << 2),
879 /** When this bit is set, the resource has been marked as 'slow'.
880 * 'slow' signifies that responses from this resource can expect delays in
881 * processing its requests from clients.*/
884 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
885 /** When this bit is set, the resource is a secure resource.*/
886 OC_SECURE = (1 << 4),
891 /** When this bit is set, the resource is allowed to be discovered only
892 * if discovery request contains an explicit querystring.
893 * Ex: GET /oic/res?rt=oic.sec.acl */
894 OC_EXPLICIT_DISCOVERABLE = (1 << 5)
897 /** When this bit is set, the resource is allowed to be published */
898 ,OC_MQ_PUBLISHER = (1 << 6)
902 /** When this bit is set, the resource is allowed to be notified as MQ broker.*/
903 ,OC_MQ_BROKER = (1 << 7)
905 } OCResourceProperty;
908 * Transport Protocol IDs.
912 /** For invalid ID.*/
913 OC_INVALID_ID = (1 << 0),
916 OC_COAP_ID = (1 << 1)
917 } OCTransportProtocolID;
920 * Declares Stack Results & Errors.
924 /** Success status code - START HERE.*/
926 OC_STACK_RESOURCE_CREATED,
927 OC_STACK_RESOURCE_DELETED,
929 OC_STACK_RESOURCE_CHANGED,
930 /** Success status code - END HERE.*/
932 /** Error status code - START HERE.*/
933 OC_STACK_INVALID_URI = 20,
934 OC_STACK_INVALID_QUERY,
936 OC_STACK_INVALID_PORT,
937 OC_STACK_INVALID_CALLBACK,
938 OC_STACK_INVALID_METHOD,
940 /** Invalid parameter.*/
941 OC_STACK_INVALID_PARAM,
942 OC_STACK_INVALID_OBSERVE_PARAM,
946 OC_STACK_ADAPTER_NOT_ENABLED,
949 /** Resource not found.*/
950 OC_STACK_NO_RESOURCE,
952 /** e.g: not supported method or interface.*/
953 OC_STACK_RESOURCE_ERROR,
954 OC_STACK_SLOW_RESOURCE,
955 OC_STACK_DUPLICATE_REQUEST,
957 /** Resource has no registered observers.*/
958 OC_STACK_NO_OBSERVERS,
959 OC_STACK_OBSERVER_NOT_FOUND,
960 OC_STACK_VIRTUAL_DO_NOT_HANDLE,
961 OC_STACK_INVALID_OPTION,
963 /** The remote reply contained malformed data.*/
964 OC_STACK_MALFORMED_RESPONSE,
965 OC_STACK_PERSISTENT_BUFFER_REQUIRED,
966 OC_STACK_INVALID_REQUEST_HANDLE,
967 OC_STACK_INVALID_DEVICE_INFO,
968 OC_STACK_INVALID_JSON,
970 /** Request is not authorized by Resource Server. */
971 OC_STACK_UNAUTHORIZED_REQ,
972 OC_STACK_TOO_LARGE_REQ,
974 /** Error code from PDM */
975 OC_STACK_PDM_IS_NOT_INITIALIZED,
976 OC_STACK_DUPLICATE_UUID,
977 OC_STACK_INCONSISTENT_DB,
980 * Error code from OTM
981 * This error is pushed from DTLS interface when handshake failure happens
983 OC_STACK_AUTHENTICATION_FAILURE,
985 /** Insert all new error codes here!.*/
987 OC_STACK_PRESENCE_STOPPED = 128,
988 OC_STACK_PRESENCE_TIMEOUT,
989 OC_STACK_PRESENCE_DO_NOT_HANDLE,
992 /** ERROR code from server */
993 OC_STACK_FORBIDDEN_REQ, /** 403*/
994 OC_STACK_INTERNAL_SERVER_ERROR, /** 500*/
996 /** ERROR in stack.*/
998 /** Error status code - END HERE.*/
1002 * Handle to an OCDoResource invocation.
1004 typedef void * OCDoHandle;
1007 * Handle to an OCResource object owned by the OCStack.
1009 typedef void * OCResourceHandle;
1012 * Handle to an OCRequest object owned by the OCStack.
1014 typedef void * OCRequestHandle;
1017 * Unique identifier for each observation request. Used when observations are
1018 * registered or de-registered. Used by entity handler to signal specific
1019 * observers to be notified of resource changes.
1020 * There can be maximum of 256 observations per server.
1022 typedef uint8_t OCObservationId;
1025 * Sequence number is a 24 bit field,
1026 * per https://tools.ietf.org/html/rfc7641.
1028 #define MAX_SEQUENCE_NUMBER (0xFFFFFF)
1031 * Action associated with observation.
1036 OC_OBSERVE_REGISTER = 0,
1038 /** To Deregister. */
1039 OC_OBSERVE_DEREGISTER = 1,
1042 OC_OBSERVE_NO_OPTION = 2,
1048 * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
1049 * when it calls OCRegisterPersistentStorageHandler.
1050 * Persistent storage open handler points to default file path.
1051 * It should check file path and whether the file is symbolic link or no.
1052 * Application can point to appropriate SVR database path for it's IoTivity Server.
1055 /** Persistent storage file path.*/
1056 FILE* (* open)(const char *path, const char *mode);
1058 /** Persistent storage read handler.*/
1059 size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
1061 /** Persistent storage write handler.*/
1062 size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
1064 /** Persistent storage close handler.*/
1065 int (* close)(FILE *fp);
1067 /** Persistent storage unlink handler.*/
1068 int (* unlink)(const char *path);
1069 } OCPersistentStorage;
1072 * Possible returned values from entity handler.
1076 /** Action associated with observation request.*/
1077 OCObserveAction action;
1079 /** Identifier for observation being registered/deregistered.*/
1080 OCObservationId obsId;
1081 } OCObservationInfo;
1084 * Possible returned values from entity handler.
1091 OC_EH_RESOURCE_CREATED = 201,
1092 OC_EH_RESOURCE_DELETED = 202,
1094 OC_EH_CHANGED = 204,
1095 OC_EH_CONTENT = 205,
1096 OC_EH_BAD_REQ = 400,
1097 OC_EH_UNAUTHORIZED_REQ = 401,
1098 OC_EH_BAD_OPT = 402,
1099 OC_EH_FORBIDDEN = 403,
1100 OC_EH_RESOURCE_NOT_FOUND = 404,
1101 OC_EH_METHOD_NOT_ALLOWED = 405,
1102 OC_EH_NOT_ACCEPTABLE = 406,
1103 OC_EH_TOO_LARGE = 413,
1104 OC_EH_UNSUPPORTED_MEDIA_TYPE = 415,
1105 OC_EH_INTERNAL_SERVER_ERROR = 500,
1106 OC_EH_BAD_GATEWAY = 502,
1107 OC_EH_SERVICE_UNAVAILABLE = 503,
1108 OC_EH_RETRANSMIT_TIMEOUT = 504
1109 } OCEntityHandlerResult;
1112 * This structure will be used to define the vendor specific header options to be included
1113 * in communication packets.
1115 typedef struct OCHeaderOption
1117 /** The protocol ID this option applies to.*/
1118 OCTransportProtocolID protocolID;
1120 /** The header option ID which will be added to communication packets.*/
1123 /** its length 191.*/
1124 uint16_t optionLength;
1126 /** pointer to its data.*/
1127 uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
1129 #ifdef SUPPORTS_DEFAULT_CTOR
1130 OCHeaderOption() = default;
1131 OCHeaderOption(OCTransportProtocolID pid,
1134 const uint8_t* optData)
1137 optionLength(optlen)
1140 // parameter includes the null terminator.
1141 optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
1142 optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
1143 memcpy(optionData, optData, optionLength);
1144 optionData[optionLength - 1] = '\0';
1150 * This structure describes the platform properties. All non-Null properties will be
1151 * included in a platform discovery request.
1158 /** Manufacturer name.*/
1159 char *manufacturerName;
1161 /** Manufacturer URL for platform property.*/
1162 char *manufacturerUrl;
1167 /** Manufacturer date.*/
1168 char *dateOfManufacture;
1170 /** Platform version.*/
1171 char *platformVersion;
1173 /** Operating system version.*/
1174 char *operatingSystemVersion;
1177 char *hardwareVersion;
1180 char *firmwareVersion;
1182 /** Platform support URL.*/
1191 * This structure is expected as input for device properties.
1192 * device name is mandatory and expected from the application.
1193 * device id of type UUID will be generated by the stack.
1197 /** Pointer to the device name.*/
1199 /** Pointer to the types.*/
1201 /** Pointer to the device specification version.*/
1203 /** Pointer to the device data model versions (in CSV format).*/
1204 OCStringLL *dataModelVersions;
1209 * callback for bound JID
1211 typedef void (*jid_bound_cb)(char *jid);
1214 * CA Remote Access information for XMPP Client
1219 char *hostname; /**< XMPP server hostname */
1220 uint16_t port; /**< XMPP server serivce port */
1221 char *xmpp_domain; /**< XMPP login domain */
1222 char *username; /**< login username */
1223 char *password; /**< login password */
1224 char *resource; /**< specific resource for login */
1225 char *user_jid; /**< specific JID for login */
1226 jid_bound_cb jidbound; /**< callback when JID bound */
1228 #endif /* RA_ADAPTER */
1231 /** Enum to describe the type of object held by the OCPayload object.*/
1234 /** Contents of the payload are invalid */
1235 PAYLOAD_TYPE_INVALID,
1236 /** The payload is an OCDiscoveryPayload */
1237 PAYLOAD_TYPE_DISCOVERY,
1238 /** The payload is an OCDevicePayload */
1239 PAYLOAD_TYPE_DEVICE,
1240 /** The payload is an OCPlatformPayload */
1241 PAYLOAD_TYPE_PLATFORM,
1242 /** The payload is an OCRepPayload */
1243 PAYLOAD_TYPE_REPRESENTATION,
1244 /** The payload is an OCSecurityPayload */
1245 PAYLOAD_TYPE_SECURITY,
1246 /** The payload is an OCPresencePayload */
1247 PAYLOAD_TYPE_PRESENCE
1251 * A generic struct representing a payload returned from a resource operation
1253 * A pointer to OCPayLoad can be cast to a more specific struct to access members
1258 /** The type of message that was received */
1269 OCREP_PROP_BYTE_STRING,
1272 }OCRepPayloadPropType;
1274 /** This structure will be used to represent a binary string for CBOR payloads.*/
1277 /** pointer to data bytes.*/
1280 /** number of data bytes.*/
1284 #define MAX_REP_ARRAY_DEPTH 3
1287 OCRepPayloadPropType type;
1288 size_t dimensions[MAX_REP_ARRAY_DEPTH];
1297 /** pointer to ByteString array.*/
1298 OCByteString* ocByteStrArray;
1300 struct OCRepPayload** objArray;
1302 } OCRepPayloadValueArray;
1304 typedef struct OCRepPayloadValue
1307 OCRepPayloadPropType type;
1315 /** ByteString object.*/
1316 OCByteString ocByteStr;
1318 struct OCRepPayload* obj;
1319 OCRepPayloadValueArray arr;
1321 struct OCRepPayloadValue* next;
1323 } OCRepPayloadValue;
1325 // used for get/set/put/observe/etc representations
1326 typedef struct OCRepPayload
1331 OCStringLL* interfaces;
1332 OCRepPayloadValue* values;
1333 struct OCRepPayload* next;
1336 // used inside a discovery payload
1337 typedef struct OCResourcePayload
1341 OCStringLL* interfaces;
1348 struct OCResourcePayload* next;
1349 } OCResourcePayload;
1351 typedef struct OCDiscoveryPayload
1358 /** A special case for handling RD address. */
1367 /** Resource Type */
1373 /** This structure holds the old /oic/res response. */
1374 OCResourcePayload *resources;
1376 /** Holding address of the next DiscoveryPayload. */
1377 struct OCDiscoveryPayload *next;
1379 } OCDiscoveryPayload;
1387 OCStringLL *dataModelVersions;
1388 OCStringLL *interfaces;
1396 OCPlatformInfo info;
1398 OCStringLL* interfaces;
1399 } OCPlatformPayload;
1404 uint8_t* securityData;
1406 } OCSecurityPayload;
1408 #ifdef WITH_PRESENCE
1412 uint32_t sequenceNumber;
1414 OCPresenceTrigger trigger;
1416 } OCPresencePayload;
1420 * Incoming requests handled by the server. Requests are passed in as a parameter to the
1421 * OCEntityHandler callback API.
1422 * The OCEntityHandler callback API must be implemented in the application in order
1423 * to receive these requests.
1427 /** Associated resource.*/
1428 OCResourceHandle resource;
1430 /** Associated request handle.*/
1431 OCRequestHandle requestHandle;
1433 /** the REST method retrieved from received request PDU.*/
1436 /** description of endpoint that sent the request.*/
1439 /** resource query send by client.*/
1442 /** Information associated with observation - valid only when OCEntityHandler flag includes
1443 * ::OC_OBSERVE_FLAG.*/
1444 OCObservationInfo obsInfo;
1446 /** Number of the received vendor specific header options.*/
1447 uint8_t numRcvdVendorSpecificHeaderOptions;
1449 /** Pointer to the array of the received vendor specific header options.*/
1450 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1455 /** the payload from the request PDU.*/
1458 } OCEntityHandlerRequest;
1462 * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1466 /** Address of remote server.*/
1469 /** backward compatibility (points to devAddr).*/
1472 /** backward compatibility.*/
1473 OCConnectivityType connType;
1475 /** the security identity of the remote server.*/
1476 OCIdentity identity;
1478 /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1479 OCStackResult result;
1481 /** If associated with observe, this will represent the sequence of notifications from server.*/
1482 uint32_t sequenceNumber;
1485 const char * resourceUri;
1487 /** the payload for the response PDU.*/
1490 /** Number of the received vendor specific header options.*/
1491 uint8_t numRcvdVendorSpecificHeaderOptions;
1493 /** An array of the received vendor specific header options.*/
1494 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1498 * Request handle is passed to server via the entity handler for each incoming request.
1499 * Stack assigns when request is received, server sets to indicate what request response is for.
1503 /** Request handle.*/
1504 OCRequestHandle requestHandle;
1506 /** Resource handle.*/
1507 OCResourceHandle resourceHandle;
1509 /** Allow the entity handler to pass a result with the response.*/
1510 OCEntityHandlerResult ehResult;
1512 /** This is the pointer to server payload data to be transferred.*/
1515 /** number of the vendor specific header options .*/
1516 uint8_t numSendVendorSpecificHeaderOptions;
1518 /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1519 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1521 /** URI of new resource that entity handler might create.*/
1522 char resourceUri[MAX_URI_LENGTH];
1524 /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1525 uint8_t persistentBufferFlag;
1526 } OCEntityHandlerResponse;
1533 /** Request state.*/
1534 OC_REQUEST_FLAG = (1 << 1),
1535 /** Observe state.*/
1536 OC_OBSERVE_FLAG = (1 << 2)
1537 } OCEntityHandlerFlag;
1540 * Possible return values from client application callback
1542 * A client application callback returns an OCStackApplicationResult to indicate whether
1543 * the stack should continue to keep the callback registered.
1547 /** Make no more calls to the callback and call the OCClientContextDeleter for this callback */
1548 OC_STACK_DELETE_TRANSACTION = 0,
1549 /** Keep this callback registered and call it if an apropriate event occurs */
1550 OC_STACK_KEEP_TRANSACTION
1551 } OCStackApplicationResult;
1554 //#ifdef DIRECT_PAIRING
1556 * @brief direct pairing Method Type.
1558 * 1: pre-configured pin
1563 DP_NOT_ALLOWED = 0x0,
1564 DP_PRE_CONFIGURED = (0x1 << 0),
1565 DP_RANDOM_PIN = (0x1 << 1),
1569 * Device Information of discoverd direct pairing device(s).
1571 typedef struct OCDPDev
1574 OCConnectivityType connType;
1575 uint16_t securePort;
1579 OCUUIdentity deviceID;
1580 OCUUIdentity rowner;
1581 struct OCDPDev *next;
1583 //#endif // DIRECT_PAIRING
1586 * -------------------------------------------------------------------------------------------
1587 * Callback function definitions
1588 * -------------------------------------------------------------------------------------------
1592 * Client applications implement this callback to consume responses received from Servers.
1594 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1595 OCClientResponse * clientResponse);
1598 * Client applications using a context pointer implement this callback to delete the
1599 * context upon removal of the callback/context pointer from the internal callback-list.
1601 typedef void (* OCClientContextDeleter)(void *context);
1604 * This info is passed from application to OC Stack when initiating a request to Server.
1606 typedef struct OCCallbackData
1608 /** Pointer to the context.*/
1611 /** The pointer to a function the stack will call to handle the requests.*/
1612 OCClientResponseHandler cb;
1614 /** A pointer to a function to delete the context when this callback is removed.*/
1615 OCClientContextDeleter cd;
1617 #ifdef SUPPORTS_DEFAULT_CTOR
1618 OCCallbackData() = default;
1619 OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1620 :context(ctx), cb(callback), cd(deleter){}
1625 * Application server implementations must implement this callback to consume requests OTA.
1626 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1628 * When you set specific return value like OC_EH_CHANGED, OC_EH_CONTENT,
1629 * OC_EH_SLOW and etc in entity handler callback,
1630 * ocstack will be not send response automatically to client
1631 * except for error return value like OC_EH_ERROR.
1633 * If you want to send response to client with specific result,
1634 * OCDoResponse API should be called with the result value.
1638 * OCEntityHandlerResponse response;
1642 * response.ehResult = OC_EH_CHANGED;
1646 * OCDoResponse(&response)
1652 typedef OCEntityHandlerResult (*OCEntityHandler)
1653 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1656 * Device Entity handler need to use this call back instead of OCEntityHandler.
1658 * When you set specific return value like OC_EH_CHANGED, OC_EH_CONTENT,
1659 * OC_EH_SLOW and etc in entity handler callback,
1660 * ocstack will be not send response automatically to client
1661 * except for error return value like OC_EH_ERROR.
1663 * If you want to send response to client with specific result,
1664 * OCDoResponse API should be called with the result value.
1668 * OCEntityHandlerResponse response;
1672 * response.ehResult = OC_EH_CHANGED;
1676 * OCDoResponse(&response)
1682 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1683 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1685 //#ifdef DIRECT_PAIRING
1687 * Callback function definition of direct-pairing
1689 * @param[OUT] ctx - user context returned in the callback.
1690 * @param[OUT] peer - pairing device info.
1691 * @param[OUT] result - It's returned with 'OC_STACK_XXX'. It will return 'OC_STACK_OK'
1692 * if D2D pairing is success without error
1694 typedef void (*OCDirectPairingCB)(void *ctx, OCDPDev_t *peer, OCStackResult result);
1695 //#endif // DIRECT_PAIRING
1699 #endif // __cplusplus
1701 #endif /* OCTYPES_H_ */