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 "platform_features.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"
67 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
69 #define OC_RSRVD_GATEWAY_URI "/oic/gateway"
73 /** Presence URI through which the OIC devices advertise their presence.*/
74 #define OC_RSRVD_PRESENCE_URI "/oic/ad"
76 /** Presence URI through which the OCF devices advertise their device presence.*/
77 #define OCF_RSRVD_DEVICE_PRESENCE_URI "/.well-known/ocf/prs"
79 /** Sets the default time to live (TTL) for presence.*/
80 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
82 /** For multicast Discovery mechanism.*/
83 #define OC_MULTICAST_DISCOVERY_URI "/oic/res"
85 /** Separator for multiple query string.*/
86 #define OC_QUERY_SEPARATOR "&;"
89 * OC_DEFAULT_PRESENCE_TTL_SECONDS sets the default time to live (TTL) for presence.
91 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
94 * OC_MAX_PRESENCE_TTL_SECONDS sets the maximum time to live (TTL) for presence.
95 * NOTE: Changing the setting to a longer duration may lead to unsupported and untested
97 * 60 sec/min * 60 min/hr * 24 hr/day
99 #define OC_MAX_PRESENCE_TTL_SECONDS (60 * 60 * 24)
103 * Presence "Announcement Triggers".
107 #define OC_RSRVD_TRIGGER_CREATE "create"
110 #define OC_RSRVD_TRIGGER_CHANGE "change"
113 #define OC_RSRVD_TRIGGER_DELETE "delete"
116 * Attributes used to form a proper OIC conforming JSON message.
119 #define OC_RSRVD_OC "oic"
123 #define OC_RSRVD_PAYLOAD "payload"
125 /** To represent href */
126 #define OC_RSRVD_HREF "href"
128 /** To represent property*/
129 #define OC_RSRVD_PROPERTY "prop"
131 /** For representation.*/
132 #define OC_RSRVD_REPRESENTATION "rep"
134 /** To represent content type.*/
135 #define OC_RSRVD_CONTENT_TYPE "ct"
137 /** To represent resource type.*/
138 #define OC_RSRVD_RESOURCE_TYPE "rt"
140 /** To represent resource type with presence.*/
141 #define OC_RSRVD_RESOURCE_TYPE_PRESENCE "oic.wk.ad"
143 /** To represent resource type with device.*/
144 #define OC_RSRVD_RESOURCE_TYPE_DEVICE "oic.wk.d"
146 /** To represent resource type with platform.*/
147 #define OC_RSRVD_RESOURCE_TYPE_PLATFORM "oic.wk.p"
149 /** To represent resource type with RES.*/
150 #define OC_RSRVD_RESOURCE_TYPE_RES "oic.wk.res"
152 /** To represent interface.*/
153 #define OC_RSRVD_INTERFACE "if"
155 /** To represent time to live.*/
156 #define OC_RSRVD_TTL "ttl"
158 /** To represent non*/
159 #define OC_RSRVD_NONCE "non"
161 /** To represent trigger type.*/
162 #define OC_RSRVD_TRIGGER "trg"
164 /** To represent links.*/
165 #define OC_RSRVD_LINKS "links"
167 /** To represent default interface.*/
168 #define OC_RSRVD_INTERFACE_DEFAULT "oic.if.baseline"
170 /** To represent read-only interface.*/
171 #define OC_RSRVD_INTERFACE_READ "oic.if.r"
173 /** To represent ll interface.*/
174 #define OC_RSRVD_INTERFACE_LL "oic.if.ll"
176 /** To represent batch interface.*/
177 #define OC_RSRVD_INTERFACE_BATCH "oic.if.b"
179 /** To represent interface group.*/
180 #define OC_RSRVD_INTERFACE_GROUP "oic.mi.grp"
182 /** To represent MFG date.*/
183 #define OC_RSRVD_MFG_DATE "mndt"
185 /** To represent FW version.*/
186 #define OC_RSRVD_FW_VERSION "mnfv"
188 /** To represent host name.*/
189 #define OC_RSRVD_HOST_NAME "hn"
191 /** To represent policy.*/
192 #define OC_RSRVD_POLICY "p"
194 /** To represent bitmap.*/
195 #define OC_RSRVD_BITMAP "bm"
198 #define OC_RSRVD_SECURE "sec"
201 #define OC_RSRVD_HOSTING_PORT "port"
204 #define OC_RSRVD_TCP_PORT "tcp"
206 /** For Server instance ID.*/
207 #define OC_RSRVD_SERVER_INSTANCE_ID "sid"
214 #define OC_RSRVD_PLATFORM_ID "pi"
216 /** Platform MFG NAME. */
217 #define OC_RSRVD_MFG_NAME "mnmn"
220 #define OC_RSRVD_MFG_URL "mnml"
223 #define OC_RSRVD_MODEL_NUM "mnmo"
225 /** Platform MFG Date.*/
226 #define OC_RSRVD_MFG_DATE "mndt"
228 /** Platform versio.n */
229 #define OC_RSRVD_PLATFORM_VERSION "mnpv"
231 /** Platform Operating system version. */
232 #define OC_RSRVD_OS_VERSION "mnos"
234 /** Platform Hardware version. */
235 #define OC_RSRVD_HARDWARE_VERSION "mnhw"
237 /**Platform Firmware version. */
238 #define OC_RSRVD_FIRMWARE_VERSION "mnfv"
240 /** Support URL for the platform. */
241 #define OC_RSRVD_SUPPORT_URL "mnsl"
243 /** System time for the platform. */
244 #define OC_RSRVD_SYSTEM_TIME "st"
251 #define OC_RSRVD_DEVICE_ID "di"
254 #define OC_RSRVD_DEVICE_NAME "n"
256 /** Device specification version.*/
257 #define OC_RSRVD_SPEC_VERSION "icv"
259 /** Device data model.*/
260 #define OC_RSRVD_DATA_MODEL_VERSION "dmv"
262 /** Device specification version.*/
263 #define OC_SPEC_VERSION "core.1.0.0"
265 /** Device Data Model version.*/
266 #define OC_DATA_MODEL_VERSION "res.1.0.0"
269 * These provide backward compatibility - their use is deprecated.
273 /** Multicast Prefix.*/
274 #define OC_MULTICAST_PREFIX "224.0.1.187:5683"
276 /** Multicast IP address.*/
277 #define OC_MULTICAST_IP "224.0.1.187"
279 /** Multicast Port.*/
280 #define OC_MULTICAST_PORT 5683
283 /** Max Device address size. */
285 #define MAX_ADDR_STR_SIZE (256)
287 /** Max Address could be
288 * "coaps+tcp://[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:yyy.yyy.yyy.yyy]:xxxxx"
289 * +1 for null terminator.
291 #define MAX_ADDR_STR_SIZE (66)
294 /** Length of MAC address */
295 #define MAC_ADDR_STR_SIZE (17)
297 /** Blocks of MAC address */
298 #define MAC_ADDR_BLOCKS (6)
300 /** Max identity size. */
301 #define MAX_IDENTITY_SIZE (32)
303 /** Universal unique identity size. */
304 #define UUID_IDENTITY_SIZE (128/8)
306 /** Resource Directory */
308 /** Resource Directory URI used to Discover RD and Publish resources.*/
309 #define OC_RSRVD_RD_URI "/oic/rd"
311 /** To represent resource type with rd.*/
312 #define OC_RSRVD_RESOURCE_TYPE_RD "oic.wk.rd"
314 /** RD Discovery bias factor type. */
315 #define OC_RSRVD_RD_DISCOVERY_SEL "sel"
318 #define OC_RSRVD_BASE_URI "baseURI"
320 /** Unique value per collection/link. */
321 #define OC_RSRVD_INS "ins"
323 /** Allowable resource types in the links. */
324 #define OC_RSRVD_RTS "rts"
326 /** Default relationship. */
327 #define OC_RSRVD_DREL "drel"
329 /** Defines relationship between links. */
330 #define OC_RSRVD_REL "rel"
332 /** Defines title. */
333 #define OC_RSRVD_TITLE "title"
336 #define OC_RSRVD_URI "uri"
338 /** Defines media type. */
339 #define OC_RSRVD_MEDIA_TYPE "mt"
341 /** To represent resource type with Publish RD.*/
342 #define OC_RSRVD_RESOURCE_TYPE_RDPUBLISH "oic.wk.rdpub"
347 #define OC_RSRVD_ACCOUNT_URI "/.well-known/ocf/account"
349 /** Account session URI.*/
350 #define OC_RSRVD_ACCOUNT_SESSION_URI "/.well-known/ocf/account/session"
352 /** Account token refresh URI.*/
353 #define OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI "/.well-known/ocf/account/tokenrefresh"
355 /** Defines auth provider. */
356 #define OC_RSRVD_AUTHPROVIDER "authprovider"
358 /** Defines auth code. */
359 #define OC_RSRVD_AUTHCODE "authcode"
361 /** Defines session. */
362 #define OC_RSRVD_ACCESS_TOKEN "accesstoken"
364 /** Defines status. */
365 #define OC_RSRVD_STATUS "status"
367 /** Defines grant type. */
368 #define OC_RSRVD_GRANT_TYPE "granttype"
370 /** Defines refresh token. */
371 #define OC_RSRVD_REFRESH_TOKEN "refreshtoken"
373 /** To represent grant type with refresh token. */
374 #define OC_RSRVD_GRANT_TYPE_REFRESH_TOKEN "refresh_token"
377 * Mark a parameter as unused. Used to prevent unused variable compiler warnings.
378 * Used in three cases:
379 * 1. in callbacks when one of the parameters are unused
380 * 2. when due to code changes a functions parameter is no longer
381 * used but must be left in place for backward compatibility
383 * 3. a variable is only used in the debug build variant and would
384 * give a build warning in release mode.
386 #define OC_UNUSED(x) (void)(x)
389 * These enums (OCTransportAdapter and OCTransportFlags) must
390 * be kept synchronized with OCConnectivityType (below) as well as
391 * CATransportAdapter and CATransportFlags (in CACommon.h).
395 /** value zero indicates discovery.*/
396 OC_DEFAULT_ADAPTER = 0,
398 /** IPv4 and IPv6, including 6LoWPAN.*/
399 OC_ADAPTER_IP = (1 << 0),
401 /** GATT over Bluetooth LE.*/
402 OC_ADAPTER_GATT_BTLE = (1 << 1),
404 /** RFCOMM over Bluetooth EDR.*/
405 OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
407 /**Remote Access over XMPP.*/
408 OC_ADAPTER_REMOTE_ACCESS = (1 << 3),
411 OC_ADAPTER_TCP = (1 << 4),
413 /** NFC Transport for Messaging.*/
414 OC_ADAPTER_NFC = (1 << 5)
415 } OCTransportAdapter;
418 * Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
422 /** default flag is 0*/
423 OC_DEFAULT_FLAGS = 0,
425 /** Insecure transport is the default (subject to change).*/
426 /** secure the transport path*/
427 OC_FLAG_SECURE = (1 << 4),
429 /** IPv4 & IPv6 auto-selection is the default.*/
430 /** IP & TCP adapter only.*/
431 OC_IP_USE_V6 = (1 << 5),
433 /** IP & TCP adapter only.*/
434 OC_IP_USE_V4 = (1 << 6),
436 /** Multicast only.*/
437 OC_MULTICAST = (1 << 7),
439 /** Link-Local multicast is the default multicast scope for IPv6.
440 * These are placed here to correspond to the IPv6 multicast address bits.*/
442 /** IPv6 Interface-Local scope (loopback).*/
443 OC_SCOPE_INTERFACE = 0x1,
445 /** IPv6 Link-Local scope (default).*/
448 /** IPv6 Realm-Local scope. */
449 OC_SCOPE_REALM = 0x3,
451 /** IPv6 Admin-Local scope. */
452 OC_SCOPE_ADMIN = 0x4,
454 /** IPv6 Site-Local scope. */
457 /** IPv6 Organization-Local scope. */
460 /**IPv6 Global scope. */
461 OC_SCOPE_GLOBAL = 0xE,
465 /** Bit mask for scope.*/
466 #define OC_MASK_SCOPE (0x000F)
468 /** Bit mask for Mods.*/
469 #define OC_MASK_MODS (0x0FF0)
470 #define OC_MASK_FAMS (OC_IP_USE_V6|OC_IP_USE_V4)
472 typedef struct OCStringLL
474 struct OCStringLL *next;
479 * End point identity.
483 /** Identity Length */
486 /** Array of end point identity.*/
487 unsigned char id[MAX_IDENTITY_SIZE];
491 * Universally unique identifier.
495 /** identitifier string.*/
496 unsigned char id[UUID_IDENTITY_SIZE];
500 * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
501 * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
506 OCTransportAdapter adapter;
508 /** transport modifiers.*/
509 OCTransportFlags flags;
514 /** address for all adapters.*/
515 char addr[MAX_ADDR_STR_SIZE];
517 /** usually zero for default interface.*/
519 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
520 char routeData[MAX_ADDR_STR_SIZE]; //destination GatewayID:ClientId
525 * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
526 * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
527 * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
530 * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
534 /** use when defaults are ok. */
537 /** IPv4 and IPv6, including 6LoWPAN.*/
538 CT_ADAPTER_IP = (1 << 16),
540 /** GATT over Bluetooth LE.*/
541 CT_ADAPTER_GATT_BTLE = (1 << 17),
543 /** RFCOMM over Bluetooth EDR.*/
544 CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
547 /** Remote Access over XMPP.*/
548 CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
551 CT_ADAPTER_TCP = (1 << 20),
554 CT_ADAPTER_NFC = (1 << 21),
556 /** Insecure transport is the default (subject to change).*/
558 /** secure the transport path.*/
559 CT_FLAG_SECURE = (1 << 4),
561 /** IPv4 & IPv6 autoselection is the default.*/
563 /** IP adapter only.*/
564 CT_IP_USE_V6 = (1 << 5),
566 /** IP adapter only.*/
567 CT_IP_USE_V4 = (1 << 6),
569 /** Link-Local multicast is the default multicast scope for IPv6.
570 * These are placed here to correspond to the IPv6 address bits.*/
572 /** IPv6 Interface-Local scope(loopback).*/
573 CT_SCOPE_INTERFACE = 0x1,
575 /** IPv6 Link-Local scope (default).*/
578 /** IPv6 Realm-Local scope.*/
579 CT_SCOPE_REALM = 0x3,
581 /** IPv6 Admin-Local scope.*/
582 CT_SCOPE_ADMIN = 0x4,
584 /** IPv6 Site-Local scope.*/
587 /** IPv6 Organization-Local scope.*/
590 /** IPv6 Global scope.*/
591 CT_SCOPE_GLOBAL = 0xE,
592 } OCConnectivityType;
594 /** bit shift required for connectivity adapter.*/
595 #define CT_ADAPTER_SHIFT 16
598 #define CT_MASK_FLAGS 0xFFFF
601 #define CT_MASK_ADAPTER 0xFFFF0000
604 * OCDoResource methods to dispatch the request
608 OC_REST_NOMETHOD = 0,
611 OC_REST_GET = (1 << 0),
614 OC_REST_PUT = (1 << 1),
617 OC_REST_POST = (1 << 2),
620 OC_REST_DELETE = (1 << 3),
622 /** Register observe request for most up date notifications ONLY.*/
623 OC_REST_OBSERVE = (1 << 4),
625 /** Register observe request for all notifications, including stale notifications.*/
626 OC_REST_OBSERVE_ALL = (1 << 5),
628 /** De-register observation, intended for internal use.*/
629 OC_REST_CANCEL_OBSERVE = (1 << 6),
632 /** Subscribe for all presence notifications of a particular resource.*/
633 OC_REST_PRESENCE = (1 << 7),
636 /** Allows OCDoResource caller to do discovery.*/
637 OC_REST_DISCOVER = (1 << 8)
641 * Formats for payload encoding.
647 OC_FORMAT_UNSUPPORTED,
651 * Host Mode of Operation.
658 OC_GATEWAY /**< Client server mode along with routing capabilities.*/
662 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
663 * protocol. The precise definitions of each quality of service level depend on the
664 * implementation. In descriptions below are for the current implementation and may changed
669 /** Packet delivery is best effort.*/
672 /** Packet delivery is best effort.*/
675 /** Acknowledgments are used to confirm delivery.*/
678 /** No Quality is defined, let the stack decide.*/
680 } OCQualityOfService;
683 * Resource Properties.
684 * The value of a policy property is defined as bitmap.
685 * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
686 * Not including the policy property is equivalent to zero.
691 /** When none of the bits are set, the resource is non-discoverable &
692 * non-observable by the client.*/
693 OC_RES_PROP_NONE = (0),
695 /** When this bit is set, the resource is allowed to be discovered by clients.*/
696 OC_DISCOVERABLE = (1 << 0),
698 /** When this bit is set, the resource is allowed to be observed by clients.*/
699 OC_OBSERVABLE = (1 << 1),
701 /** When this bit is set, the resource is initialized, otherwise the resource
702 * is 'inactive'. 'inactive' signifies that the resource has been marked for
703 * deletion or is already deleted.*/
704 OC_ACTIVE = (1 << 2),
706 /** When this bit is set, the resource has been marked as 'slow'.
707 * 'slow' signifies that responses from this resource can expect delays in
708 * processing its requests from clients.*/
712 /** When this bit is set, the resource is a secure resource.*/
713 OC_SECURE = (1 << 4),
718 /** When this bit is set, the resource is allowed to be discovered only
719 * if discovery request contains an explicit querystring.
720 * Ex: GET /oic/res?rt=oic.sec.acl */
721 OC_EXPLICIT_DISCOVERABLE = (1 << 5),
724 /** When this bit is set, the resource is allowed to be published */
725 OC_MQ_PUBLISHER = (1 << 6),
729 /** When this bit is set, the resource is allowed to be notified as MQ broker.*/
730 OC_MQ_BROKER = (1 << 7),
732 } OCResourceProperty;
735 * Transport Protocol IDs.
739 /** For invalid ID.*/
740 OC_INVALID_ID = (1 << 0),
743 OC_COAP_ID = (1 << 1)
744 } OCTransportProtocolID;
747 * Declares Stack Results & Errors.
751 /** Success status code - START HERE.*/
753 OC_STACK_RESOURCE_CREATED,
754 OC_STACK_RESOURCE_DELETED,
756 OC_STACK_RESOURCE_CHANGED,
757 /** Success status code - END HERE.*/
759 /** Error status code - START HERE.*/
760 OC_STACK_INVALID_URI = 20,
761 OC_STACK_INVALID_QUERY,
763 OC_STACK_INVALID_PORT,
764 OC_STACK_INVALID_CALLBACK,
765 OC_STACK_INVALID_METHOD,
767 /** Invalid parameter.*/
768 OC_STACK_INVALID_PARAM,
769 OC_STACK_INVALID_OBSERVE_PARAM,
773 OC_STACK_ADAPTER_NOT_ENABLED,
776 /** Resource not found.*/
777 OC_STACK_NO_RESOURCE,
779 /** e.g: not supported method or interface.*/
780 OC_STACK_RESOURCE_ERROR,
781 OC_STACK_SLOW_RESOURCE,
782 OC_STACK_DUPLICATE_REQUEST,
784 /** Resource has no registered observers.*/
785 OC_STACK_NO_OBSERVERS,
786 OC_STACK_OBSERVER_NOT_FOUND,
787 OC_STACK_VIRTUAL_DO_NOT_HANDLE,
788 OC_STACK_INVALID_OPTION,
790 /** The remote reply contained malformed data.*/
791 OC_STACK_MALFORMED_RESPONSE,
792 OC_STACK_PERSISTENT_BUFFER_REQUIRED,
793 OC_STACK_INVALID_REQUEST_HANDLE,
794 OC_STACK_INVALID_DEVICE_INFO,
795 OC_STACK_INVALID_JSON,
797 /** Request is not authorized by Resource Server. */
798 OC_STACK_UNAUTHORIZED_REQ,
799 OC_STACK_TOO_LARGE_REQ,
801 /** Error code from PDM */
802 OC_STACK_PDM_IS_NOT_INITIALIZED,
803 OC_STACK_DUPLICATE_UUID,
804 OC_STACK_INCONSISTENT_DB,
807 * Error code from OTM
808 * This error is pushed from DTLS interface when handshake failure happens
810 OC_STACK_AUTHENTICATION_FAILURE,
812 /** Insert all new error codes here!.*/
814 OC_STACK_PRESENCE_STOPPED = 128,
815 OC_STACK_PRESENCE_TIMEOUT,
816 OC_STACK_PRESENCE_DO_NOT_HANDLE,
818 /** ERROR in stack.*/
820 /** Error status code - END HERE.*/
824 * Handle to an OCDoResource invocation.
826 typedef void * OCDoHandle;
829 * Handle to an OCResource object owned by the OCStack.
831 typedef void * OCResourceHandle;
834 * Handle to an OCRequest object owned by the OCStack.
836 typedef void * OCRequestHandle;
839 * Unique identifier for each observation request. Used when observations are
840 * registered or de-registered. Used by entity handler to signal specific
841 * observers to be notified of resource changes.
842 * There can be maximum of 256 observations per server.
844 typedef uint8_t OCObservationId;
847 * Action associated with observation.
852 OC_OBSERVE_REGISTER = 0,
854 /** To Deregister. */
855 OC_OBSERVE_DEREGISTER = 1,
858 OC_OBSERVE_NO_OPTION = 2
863 * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
864 * when it calls OCRegisterPersistentStorageHandler.
865 * Persistent storage open handler points to default file path.
866 * It should check file path and whether the file is symbolic link or no.
867 * Application can point to appropriate SVR database path for it's IoTivity Server.
870 /** Persistent storage file path.*/
871 FILE* (* open)(const char *path, const char *mode);
873 /** Persistent storage read handler.*/
874 size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
876 /** Persistent storage write handler.*/
877 size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
879 /** Persistent storage close handler.*/
880 int (* close)(FILE *fp);
882 /** Persistent storage unlink handler.*/
883 int (* unlink)(const char *path);
884 } OCPersistentStorage;
887 * Possible returned values from entity handler.
891 /** Action associated with observation request.*/
892 OCObserveAction action;
894 /** Identifier for observation being registered/deregistered.*/
895 OCObservationId obsId;
899 * Possible returned values from entity handler.
905 OC_EH_RESOURCE_CREATED, // 2.01
906 OC_EH_RESOURCE_DELETED, // 2.02
908 OC_EH_FORBIDDEN, // 4.03
909 OC_EH_RESOURCE_NOT_FOUND, // 4.04
911 OC_EH_CHANGED, // 2.04
912 OC_EH_CONTENT, // 2.05
913 OC_EH_BAD_REQ, // 4.00
914 OC_EH_UNAUTHORIZED_REQ, // 4.01
915 OC_EH_BAD_OPT, // 4.02
916 OC_EH_METHOD_NOT_ALLOWED, // 4.05
917 OC_EH_NOT_ACCEPTABLE, // 4.06
918 OC_EH_INTERNAL_SERVER_ERROR, // 5.00
919 OC_EH_RETRANSMIT_TIMEOUT // 5.04
920 } OCEntityHandlerResult;
923 * This structure will be used to define the vendor specific header options to be included
924 * in communication packets.
926 typedef struct OCHeaderOption
928 /** The protocol ID this option applies to.*/
929 OCTransportProtocolID protocolID;
931 /** The header option ID which will be added to communication packets.*/
934 /** its length 191.*/
935 uint16_t optionLength;
937 /** pointer to its data.*/
938 uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
940 #ifdef SUPPORTS_DEFAULT_CTOR
941 OCHeaderOption() = default;
942 OCHeaderOption(OCTransportProtocolID pid,
945 const uint8_t* optData)
951 // parameter includes the null terminator.
952 optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
953 optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
954 memcpy(optionData, optData, optionLength);
955 optionData[optionLength - 1] = '\0';
962 * This structure describes the platform properties. All non-Null properties will be
963 * included in a platform discovery request.
970 /** Manufacturer name.*/
971 char *manufacturerName;
973 /** Manufacturer URL for platform property.*/
974 char *manufacturerUrl;
979 /** Manufacturer date.*/
980 char *dateOfManufacture;
982 /** Platform version.*/
983 char *platformVersion;
985 /** Operating system version.*/
986 char *operatingSystemVersion;
989 char *hardwareVersion;
992 char *firmwareVersion;
994 /** Platform support URL.*/
1003 * This structure is expected as input for device properties.
1004 * device name is mandatory and expected from the application.
1005 * device id of type UUID will be generated by the stack.
1009 /** Pointer to the device name.*/
1011 /** Pointer to the types.*/
1013 /** Pointer to the device specification version.*/
1015 /** Pointer to the device data model versions (in CSV format).*/
1016 OCStringLL *dataModelVersions;
1021 * callback for bound JID
1023 typedef void (*jid_bound_cb)(char *jid);
1026 * CA Remote Access information for XMPP Client
1031 char *hostname; /**< XMPP server hostname */
1032 uint16_t port; /**< XMPP server serivce port */
1033 char *xmpp_domain; /**< XMPP login domain */
1034 char *username; /**< login username */
1035 char *password; /**< login password */
1036 char *resource; /**< specific resource for login */
1037 char *user_jid; /**< specific JID for login */
1038 jid_bound_cb jidbound; /**< callback when JID bound */
1040 #endif /* RA_ADAPTER */
1043 /** Enum to describe the type of object held by the OCPayload object.*/
1046 /** Contents of the payload are invalid */
1047 PAYLOAD_TYPE_INVALID,
1048 /** The payload is an OCDiscoveryPayload */
1049 PAYLOAD_TYPE_DISCOVERY,
1050 /** The payload is an OCDevicePayload */
1051 PAYLOAD_TYPE_DEVICE,
1052 /** The payload is an OCPlatformPayload */
1053 PAYLOAD_TYPE_PLATFORM,
1054 /** The payload is an OCRepPayload */
1055 PAYLOAD_TYPE_REPRESENTATION,
1056 /** The payload is an OCSecurityPayload */
1057 PAYLOAD_TYPE_SECURITY,
1058 /** The payload is an OCPresencePayload */
1059 PAYLOAD_TYPE_PRESENCE,
1060 /** The payload is an OCRDPayload */
1065 * A generic struct representing a payload returned from a resource operation
1067 * A pointer to OCPayLoad can be cast to a more specific struct to access members
1072 /** The type of message that was received */
1083 OCREP_PROP_BYTE_STRING,
1086 }OCRepPayloadPropType;
1088 /** This structure will be used to represent a binary string for CBOR payloads.*/
1091 /** pointer to data bytes.*/
1094 /** number of data bytes.*/
1098 #define MAX_REP_ARRAY_DEPTH 3
1101 OCRepPayloadPropType type;
1102 size_t dimensions[MAX_REP_ARRAY_DEPTH];
1111 /** pointer to ByteString array.*/
1112 OCByteString* ocByteStrArray;
1114 struct OCRepPayload** objArray;
1116 } OCRepPayloadValueArray;
1118 typedef struct OCRepPayloadValue
1121 OCRepPayloadPropType type;
1129 /** ByteString object.*/
1130 OCByteString ocByteStr;
1132 struct OCRepPayload* obj;
1133 OCRepPayloadValueArray arr;
1135 struct OCRepPayloadValue* next;
1137 } OCRepPayloadValue;
1139 // used for get/set/put/observe/etc representations
1140 typedef struct OCRepPayload
1145 OCStringLL* interfaces;
1146 OCRepPayloadValue* values;
1147 struct OCRepPayload* next;
1150 // used inside a discovery payload
1151 typedef struct OCResourcePayload
1155 OCStringLL* interfaces;
1162 struct OCResourcePayload* next;
1163 } OCResourcePayload;
1166 * Structure holding Links Payload. It is a sub-structure used in
1167 * OCResourceCollectionPayload.
1169 typedef struct OCLinksPayload
1171 /** This is the target relative URI. */
1173 /** Resource Type - A standard OIC specified or vendor defined resource
1174 * type of the resource referenced by the target URI. */
1176 /** Interface - The interfaces supported by the resource referenced by the target URI. */
1178 /** The relation of the target URI referenced by the link to the context URI;
1179 * The default value is null. */
1181 /** Specifies if the resource referenced by the target URIis observable or not. */
1183 /** A title for the link relation. Can be used by the UI to provide a context. */
1185 /** This is used to override the context URI e.g. override the URI of the containing collection. */
1187 /** The instance identifier for this web link in an array of web links - used in links. */
1190 /** An ordinal number that is not repeated - must be unique in the collection context. */
1192 /** Any unique string including a URI. */
1194 /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1195 OCIdentity uniqueUUID;
1197 /** A hint of the media type of the representation of the resource referenced by the target URI. */
1199 /** Holding address of the next resource. */
1200 struct OCLinksPayload *next;
1203 /** Structure holding tags value of the links payload. */
1206 /** Name of tags. */
1208 /** Device identifier. */
1210 /** The base URI where the resources are hold. */
1212 /** Bitmap holds observable, discoverable, secure option flag.*/
1214 /** Port set in case, the secure flag is set above. */
1216 /** Id for each set of links i.e. tag. */
1219 /** An ordinal number that is not repeated - must be unique in the collection context. */
1221 /** Any unique string including a URI. */
1223 /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1224 OCIdentity uniqueUUID;
1226 /** Defines the list of allowable resource types (for Target and anchors) in links included
1227 * in the collection; new links being created can only be from this list. */
1229 /** When specified this is the default relationship to use when an OIC Link does not specify
1230 * an explicit relationship with *rel* parameter. */
1232 /** Time to keep holding resource.*/
1236 /** Resource collection payload. */
1237 typedef struct OCResourceCollectionPayload
1239 /** Collection tags payload.*/
1240 OCTagsPayload *tags;
1241 /** Array of links payload. */
1242 OCLinksPayload *setLinks;
1243 /** Holding address of the next resource. */
1244 struct OCResourceCollectionPayload *next;
1245 } OCResourceCollectionPayload;
1247 typedef struct OCDiscoveryPayload
1254 /** A special case for handling RD address. */
1263 /** Resource Type */
1269 /** This structure holds the old /oic/res response. */
1270 OCResourcePayload *resources;
1272 /** Holding address of the next DiscoveryPayload. */
1273 struct OCDiscoveryPayload *next;
1275 } OCDiscoveryPayload;
1278 * Structure holding discovery payload.
1284 /** Device Identity. */
1286 /** Value holding the bias factor of the RD. */
1288 } OCRDDiscoveryPayload;
1291 * RD Payload that will be transmitted over the wire.
1296 /** Pointer to the discovery response payload.*/
1297 OCRDDiscoveryPayload *rdDiscovery;
1298 /** Pointer to the publish payload.*/
1299 OCResourceCollectionPayload *rdPublish;
1308 OCStringLL *dataModelVersions;
1309 OCStringLL *interfaces;
1317 OCPlatformInfo info;
1319 OCStringLL* interfaces;
1320 } OCPlatformPayload;
1325 uint8_t* securityData;
1327 } OCSecurityPayload;
1329 #ifdef WITH_PRESENCE
1333 uint32_t sequenceNumber;
1335 OCPresenceTrigger trigger;
1337 } OCPresencePayload;
1341 * Incoming requests handled by the server. Requests are passed in as a parameter to the
1342 * OCEntityHandler callback API.
1343 * The OCEntityHandler callback API must be implemented in the application in order
1344 * to receive these requests.
1348 /** Associated resource.*/
1349 OCResourceHandle resource;
1351 /** Associated request handle.*/
1352 OCRequestHandle requestHandle;
1354 /** the REST method retrieved from received request PDU.*/
1357 /** description of endpoint that sent the request.*/
1360 /** resource query send by client.*/
1363 /** Information associated with observation - valid only when OCEntityHandler flag includes
1364 * ::OC_OBSERVE_FLAG.*/
1365 OCObservationInfo obsInfo;
1367 /** Number of the received vendor specific header options.*/
1368 uint8_t numRcvdVendorSpecificHeaderOptions;
1370 /** Pointer to the array of the received vendor specific header options.*/
1371 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1376 /** the payload from the request PDU.*/
1379 } OCEntityHandlerRequest;
1383 * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1387 /** Address of remote server.*/
1390 /** backward compatibility (points to devAddr).*/
1393 /** backward compatibility.*/
1394 OCConnectivityType connType;
1396 /** the security identity of the remote server.*/
1397 OCIdentity identity;
1399 /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1400 OCStackResult result;
1402 /** If associated with observe, this will represent the sequence of notifications from server.*/
1403 uint32_t sequenceNumber;
1406 const char * resourceUri;
1408 /** the payload for the response PDU.*/
1411 /** Number of the received vendor specific header options.*/
1412 uint8_t numRcvdVendorSpecificHeaderOptions;
1414 /** An array of the received vendor specific header options.*/
1415 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1419 * Request handle is passed to server via the entity handler for each incoming request.
1420 * Stack assigns when request is received, server sets to indicate what request response is for.
1424 /** Request handle.*/
1425 OCRequestHandle requestHandle;
1427 /** Resource handle.*/
1428 OCResourceHandle resourceHandle;
1430 /** Allow the entity handler to pass a result with the response.*/
1431 OCEntityHandlerResult ehResult;
1433 /** This is the pointer to server payload data to be transferred.*/
1436 /** number of the vendor specific header options .*/
1437 uint8_t numSendVendorSpecificHeaderOptions;
1439 /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1440 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1442 /** URI of new resource that entity handler might create.*/
1443 char resourceUri[MAX_URI_LENGTH];
1445 /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1446 uint8_t persistentBufferFlag;
1447 } OCEntityHandlerResponse;
1454 /** Request state.*/
1455 OC_REQUEST_FLAG = (1 << 1),
1456 /** Observe state.*/
1457 OC_OBSERVE_FLAG = (1 << 2)
1458 } OCEntityHandlerFlag;
1461 * Possible return values from client application callback
1463 * A client application callback returns an OCStackApplicationResult to indicate whether
1464 * the stack should continue to keep the callback registered.
1468 /** Make no more calls to the callback and call the OCClientContextDeleter for this callback */
1469 OC_STACK_DELETE_TRANSACTION = 0,
1470 /** Keep this callback registered and call it if an apropriate event occurs */
1471 OC_STACK_KEEP_TRANSACTION
1472 } OCStackApplicationResult;
1475 //#ifdef DIRECT_PAIRING
1477 * @brief direct pairing Method Type.
1479 * 1: pre-configured pin
1484 DP_NOT_ALLOWED = 0x0,
1485 DP_PRE_CONFIGURED = (0x1 << 0),
1486 DP_RANDOM_PIN = (0x1 << 1),
1490 * Device Information of discoverd direct pairing device(s).
1492 typedef struct OCDPDev
1495 OCConnectivityType connType;
1496 uint16_t securePort;
1500 OCUUIdentity deviceID;
1501 OCUUIdentity rowner;
1502 struct OCDPDev *next;
1504 //#endif // DIRECT_PAIRING
1507 * -------------------------------------------------------------------------------------------
1508 * Callback function definitions
1509 * -------------------------------------------------------------------------------------------
1513 * Client applications implement this callback to consume responses received from Servers.
1515 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1516 OCClientResponse * clientResponse);
1519 * Client applications using a context pointer implement this callback to delete the
1520 * context upon removal of the callback/context pointer from the internal callback-list.
1522 typedef void (* OCClientContextDeleter)(void *context);
1525 * This info is passed from application to OC Stack when initiating a request to Server.
1527 typedef struct OCCallbackData
1529 /** Pointer to the context.*/
1532 /** The pointer to a function the stack will call to handle the requests.*/
1533 OCClientResponseHandler cb;
1535 /** A pointer to a function to delete the context when this callback is removed.*/
1536 OCClientContextDeleter cd;
1538 #ifdef SUPPORTS_DEFAULT_CTOR
1539 OCCallbackData() = default;
1540 OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1541 :context(ctx), cb(callback), cd(deleter){}
1546 * Application server implementations must implement this callback to consume requests OTA.
1547 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1549 typedef OCEntityHandlerResult (*OCEntityHandler)
1550 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1553 * Device Entity handler need to use this call back instead of OCEntityHandler.
1555 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1556 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1558 //#ifdef DIRECT_PAIRING
1560 * Callback function definition of direct-pairing
1562 * @param[OUT] ctx - user context returned in the callback.
1563 * @param[OUT] peer - pairing device info.
1564 * @param[OUT} result - It's returned with 'OC_STACK_XXX'. It will return 'OC_STACK_OK'
1565 * if D2D pairing is success without error
1567 typedef void (*OCDirectPairingCB)(void *ctx, OCDPDev_t *peer, OCStackResult result);
1568 //#endif // DIRECT_PAIRING
1572 #endif // __cplusplus
1574 #endif /* OCTYPES_H_ */