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 /** Sets the default time to live (TTL) for presence.*/
77 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
79 /** For multicast Discovery mechanism.*/
80 #define OC_MULTICAST_DISCOVERY_URI "/oic/res"
82 /** Separator for multiple query string.*/
83 #define OC_QUERY_SEPARATOR "&;"
86 * OC_DEFAULT_PRESENCE_TTL_SECONDS sets the default time to live (TTL) for presence.
88 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
91 * OC_MAX_PRESENCE_TTL_SECONDS sets the maximum time to live (TTL) for presence.
92 * NOTE: Changing the setting to a longer duration may lead to unsupported and untested
94 * 60 sec/min * 60 min/hr * 24 hr/day
96 #define OC_MAX_PRESENCE_TTL_SECONDS (60 * 60 * 24)
100 * Presence "Announcement Triggers".
104 #define OC_RSRVD_TRIGGER_CREATE "create"
107 #define OC_RSRVD_TRIGGER_CHANGE "change"
110 #define OC_RSRVD_TRIGGER_DELETE "delete"
113 * Attributes used to form a proper OIC conforming JSON message.
116 #define OC_RSRVD_OC "oic"
120 #define OC_RSRVD_PAYLOAD "payload"
122 /** To represent href */
123 #define OC_RSRVD_HREF "href"
125 /** To represent property*/
126 #define OC_RSRVD_PROPERTY "prop"
128 /** For representation.*/
129 #define OC_RSRVD_REPRESENTATION "rep"
131 /** To represent content type.*/
132 #define OC_RSRVD_CONTENT_TYPE "ct"
134 /** To represent resource type.*/
135 #define OC_RSRVD_RESOURCE_TYPE "rt"
137 /** To represent resource type with presence.*/
138 #define OC_RSRVD_RESOURCE_TYPE_PRESENCE "oic.wk.ad"
140 /** To represent resource type with device.*/
141 #define OC_RSRVD_RESOURCE_TYPE_DEVICE "oic.wk.d"
143 /** To represent resource type with platform.*/
144 #define OC_RSRVD_RESOURCE_TYPE_PLATFORM "oic.wk.p"
146 /** To represent resource type with RES.*/
147 #define OC_RSRVD_RESOURCE_TYPE_RES "oic.wk.res"
149 /** To represent interface.*/
150 #define OC_RSRVD_INTERFACE "if"
152 /** To represent time to live.*/
153 #define OC_RSRVD_TTL "ttl"
155 /** To represent non*/
156 #define OC_RSRVD_NONCE "non"
158 /** To represent trigger type.*/
159 #define OC_RSRVD_TRIGGER "trg"
161 /** To represent links.*/
162 #define OC_RSRVD_LINKS "links"
164 /** To represent default interface.*/
165 #define OC_RSRVD_INTERFACE_DEFAULT "oic.if.baseline"
167 /** To represent read-only interface.*/
168 #define OC_RSRVD_INTERFACE_READ "oic.if.r"
170 /** To represent ll interface.*/
171 #define OC_RSRVD_INTERFACE_LL "oic.if.ll"
173 /** To represent batch interface.*/
174 #define OC_RSRVD_INTERFACE_BATCH "oic.if.b"
176 /** To represent interface group.*/
177 #define OC_RSRVD_INTERFACE_GROUP "oic.mi.grp"
179 /** To represent MFG date.*/
180 #define OC_RSRVD_MFG_DATE "mndt"
182 /** To represent FW version.*/
183 #define OC_RSRVD_FW_VERSION "mnfv"
185 /** To represent host name.*/
186 #define OC_RSRVD_HOST_NAME "hn"
188 /** To represent policy.*/
189 #define OC_RSRVD_POLICY "p"
191 /** To represent bitmap.*/
192 #define OC_RSRVD_BITMAP "bm"
195 #define OC_RSRVD_SECURE "sec"
198 #define OC_RSRVD_HOSTING_PORT "port"
201 #define OC_RSRVD_TCP_PORT "tcp"
203 /** For Server instance ID.*/
204 #define OC_RSRVD_SERVER_INSTANCE_ID "sid"
211 #define OC_RSRVD_PLATFORM_ID "pi"
213 /** Platform MFG NAME. */
214 #define OC_RSRVD_MFG_NAME "mnmn"
217 #define OC_RSRVD_MFG_URL "mnml"
220 #define OC_RSRVD_MODEL_NUM "mnmo"
222 /** Platform MFG Date.*/
223 #define OC_RSRVD_MFG_DATE "mndt"
225 /** Platform versio.n */
226 #define OC_RSRVD_PLATFORM_VERSION "mnpv"
228 /** Platform Operating system version. */
229 #define OC_RSRVD_OS_VERSION "mnos"
231 /** Platform Hardware version. */
232 #define OC_RSRVD_HARDWARE_VERSION "mnhw"
234 /**Platform Firmware version. */
235 #define OC_RSRVD_FIRMWARE_VERSION "mnfv"
237 /** Support URL for the platform. */
238 #define OC_RSRVD_SUPPORT_URL "mnsl"
240 /** System time for the platform. */
241 #define OC_RSRVD_SYSTEM_TIME "st"
248 #define OC_RSRVD_DEVICE_ID "di"
251 #define OC_RSRVD_DEVICE_NAME "n"
253 /** Device specification version.*/
254 #define OC_RSRVD_SPEC_VERSION "icv"
256 /** Device data model.*/
257 #define OC_RSRVD_DATA_MODEL_VERSION "dmv"
259 /** Device specification version.*/
260 #define OC_SPEC_VERSION "core.1.0.0"
262 /** Device Data Model version.*/
263 #define OC_DATA_MODEL_VERSION "res.1.0.0"
266 * These provide backward compatibility - their use is deprecated.
270 /** Multicast Prefix.*/
271 #define OC_MULTICAST_PREFIX "224.0.1.187:5683"
273 /** Multicast IP address.*/
274 #define OC_MULTICAST_IP "224.0.1.187"
276 /** Multicast Port.*/
277 #define OC_MULTICAST_PORT 5683
280 /** Max Device address size. */
282 #define MAX_ADDR_STR_SIZE (256)
284 /** Max Address could be
285 * "coap+tcp://[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:yyy.yyy.yyy.yyy]:xxxxx"
286 * +1 for null terminator.
288 #define MAX_ADDR_STR_SIZE (65)
291 /** Length of MAC address */
292 #define MAC_ADDR_STR_SIZE (17)
294 /** Blocks of MAC address */
295 #define MAC_ADDR_BLOCKS (6)
297 /** Max identity size. */
298 #define MAX_IDENTITY_SIZE (32)
300 /** Universal unique identity size. */
301 #define UUID_IDENTITY_SIZE (128/8)
303 /** Resource Directory */
305 /** Resource Directory URI used to Discover RD and Publish resources.*/
306 #define OC_RSRVD_RD_URI "/oic/rd"
308 /** To represent resource type with rd.*/
309 #define OC_RSRVD_RESOURCE_TYPE_RD "oic.wk.rd"
311 /** RD Discovery bias factor type. */
312 #define OC_RSRVD_RD_DISCOVERY_SEL "sel"
315 #define OC_RSRVD_BASE_URI "baseURI"
317 /** Unique value per collection/link. */
318 #define OC_RSRVD_INS "ins"
320 /** Allowable resource types in the links. */
321 #define OC_RSRVD_RTS "rts"
323 /** Default relationship. */
324 #define OC_RSRVD_DREL "drel"
326 /** Defines relationship between links. */
327 #define OC_RSRVD_REL "rel"
329 /** Defines title. */
330 #define OC_RSRVD_TITLE "title"
333 #define OC_RSRVD_URI "uri"
335 /** Defines media type. */
336 #define OC_RSRVD_MEDIA_TYPE "mt"
338 /** To represent resource type with Publish RD.*/
339 #define OC_RSRVD_RESOURCE_TYPE_RDPUBLISH "oic.wk.rdpub"
342 * Mark a parameter as unused. Used to prevent unused variable compiler warnings.
343 * Used in three cases:
344 * 1. in callbacks when one of the parameters are unused
345 * 2. when due to code changes a functions parameter is no longer
346 * used but must be left in place for backward compatibility
348 * 3. a variable is only used in the debug build variant and would
349 * give a build warning in release mode.
351 #define OC_UNUSED(x) (void)(x)
354 * These enums (OCTransportAdapter and OCTransportFlags) must
355 * be kept synchronized with OCConnectivityType (below) as well as
356 * CATransportAdapter and CATransportFlags (in CACommon.h).
360 /** value zero indicates discovery.*/
361 OC_DEFAULT_ADAPTER = 0,
363 /** IPv4 and IPv6, including 6LoWPAN.*/
364 OC_ADAPTER_IP = (1 << 0),
366 /** GATT over Bluetooth LE.*/
367 OC_ADAPTER_GATT_BTLE = (1 << 1),
369 /** RFCOMM over Bluetooth EDR.*/
370 OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
372 /**Remote Access over XMPP.*/
373 OC_ADAPTER_REMOTE_ACCESS = (1 << 3),
376 OC_ADAPTER_TCP = (1 << 4),
378 /** NFC Transport for Messaging.*/
379 OC_ADAPTER_NFC = (1 << 5)
380 } OCTransportAdapter;
383 * Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
387 /** default flag is 0*/
388 OC_DEFAULT_FLAGS = 0,
390 /** Insecure transport is the default (subject to change).*/
391 /** secure the transport path*/
392 OC_FLAG_SECURE = (1 << 4),
394 /** IPv4 & IPv6 auto-selection is the default.*/
395 /** IP & TCP adapter only.*/
396 OC_IP_USE_V6 = (1 << 5),
398 /** IP & TCP adapter only.*/
399 OC_IP_USE_V4 = (1 << 6),
401 /** Multicast only.*/
402 OC_MULTICAST = (1 << 7),
404 /** Link-Local multicast is the default multicast scope for IPv6.
405 * These are placed here to correspond to the IPv6 multicast address bits.*/
407 /** IPv6 Interface-Local scope (loopback).*/
408 OC_SCOPE_INTERFACE = 0x1,
410 /** IPv6 Link-Local scope (default).*/
413 /** IPv6 Realm-Local scope. */
414 OC_SCOPE_REALM = 0x3,
416 /** IPv6 Admin-Local scope. */
417 OC_SCOPE_ADMIN = 0x4,
419 /** IPv6 Site-Local scope. */
422 /** IPv6 Organization-Local scope. */
425 /**IPv6 Global scope. */
426 OC_SCOPE_GLOBAL = 0xE,
430 /** Bit mask for scope.*/
431 #define OC_MASK_SCOPE (0x000F)
433 /** Bit mask for Mods.*/
434 #define OC_MASK_MODS (0x0FF0)
435 #define OC_MASK_FAMS (OC_IP_USE_V6|OC_IP_USE_V4)
437 typedef struct OCStringLL
439 struct OCStringLL *next;
444 * End point identity.
448 /** Identity Length */
451 /** Array of end point identity.*/
452 unsigned char id[MAX_IDENTITY_SIZE];
456 * Universally unique identifier.
460 /** identitifier string.*/
461 unsigned char id[UUID_IDENTITY_SIZE];
465 * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
466 * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
471 OCTransportAdapter adapter;
473 /** transport modifiers.*/
474 OCTransportFlags flags;
479 /** address for all adapters.*/
480 char addr[MAX_ADDR_STR_SIZE];
482 /** usually zero for default interface.*/
484 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
485 char routeData[MAX_ADDR_STR_SIZE]; //destination GatewayID:ClientId
490 * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
491 * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
492 * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
495 * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
499 /** use when defaults are ok. */
502 /** IPv4 and IPv6, including 6LoWPAN.*/
503 CT_ADAPTER_IP = (1 << 16),
505 /** GATT over Bluetooth LE.*/
506 CT_ADAPTER_GATT_BTLE = (1 << 17),
508 /** RFCOMM over Bluetooth EDR.*/
509 CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
512 /** Remote Access over XMPP.*/
513 CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
516 CT_ADAPTER_TCP = (1 << 20),
519 CT_ADAPTER_NFC = (1 << 21),
521 /** Insecure transport is the default (subject to change).*/
523 /** secure the transport path.*/
524 CT_FLAG_SECURE = (1 << 4),
526 /** IPv4 & IPv6 autoselection is the default.*/
528 /** IP adapter only.*/
529 CT_IP_USE_V6 = (1 << 5),
531 /** IP adapter only.*/
532 CT_IP_USE_V4 = (1 << 6),
534 /** Link-Local multicast is the default multicast scope for IPv6.
535 * These are placed here to correspond to the IPv6 address bits.*/
537 /** IPv6 Interface-Local scope(loopback).*/
538 CT_SCOPE_INTERFACE = 0x1,
540 /** IPv6 Link-Local scope (default).*/
543 /** IPv6 Realm-Local scope.*/
544 CT_SCOPE_REALM = 0x3,
546 /** IPv6 Admin-Local scope.*/
547 CT_SCOPE_ADMIN = 0x4,
549 /** IPv6 Site-Local scope.*/
552 /** IPv6 Organization-Local scope.*/
555 /** IPv6 Global scope.*/
556 CT_SCOPE_GLOBAL = 0xE,
557 } OCConnectivityType;
559 /** bit shift required for connectivity adapter.*/
560 #define CT_ADAPTER_SHIFT 16
563 #define CT_MASK_FLAGS 0xFFFF
566 #define CT_MASK_ADAPTER 0xFFFF0000
569 * OCDoResource methods to dispatch the request
573 OC_REST_NOMETHOD = 0,
576 OC_REST_GET = (1 << 0),
579 OC_REST_PUT = (1 << 1),
582 OC_REST_POST = (1 << 2),
585 OC_REST_DELETE = (1 << 3),
587 /** Register observe request for most up date notifications ONLY.*/
588 OC_REST_OBSERVE = (1 << 4),
590 /** Register observe request for all notifications, including stale notifications.*/
591 OC_REST_OBSERVE_ALL = (1 << 5),
593 /** De-register observation, intended for internal use.*/
594 OC_REST_CANCEL_OBSERVE = (1 << 6),
597 /** Subscribe for all presence notifications of a particular resource.*/
598 OC_REST_PRESENCE = (1 << 7),
601 /** Allows OCDoResource caller to do discovery.*/
602 OC_REST_DISCOVER = (1 << 8)
606 * Formats for payload encoding.
612 OC_FORMAT_UNSUPPORTED,
616 * Host Mode of Operation.
623 OC_GATEWAY /**< Client server mode along with routing capabilities.*/
627 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
628 * protocol. The precise definitions of each quality of service level depend on the
629 * implementation. In descriptions below are for the current implementation and may changed
634 /** Packet delivery is best effort.*/
637 /** Packet delivery is best effort.*/
640 /** Acknowledgments are used to confirm delivery.*/
643 /** No Quality is defined, let the stack decide.*/
645 } OCQualityOfService;
648 * Resource Properties.
649 * The value of a policy property is defined as bitmap.
650 * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
651 * Not including the policy property is equivalent to zero.
656 /** When none of the bits are set, the resource is non-discoverable &
657 * non-observable by the client.*/
658 OC_RES_PROP_NONE = (0),
660 /** When this bit is set, the resource is allowed to be discovered by clients.*/
661 OC_DISCOVERABLE = (1 << 0),
663 /** When this bit is set, the resource is allowed to be observed by clients.*/
664 OC_OBSERVABLE = (1 << 1),
666 /** When this bit is set, the resource is initialized, otherwise the resource
667 * is 'inactive'. 'inactive' signifies that the resource has been marked for
668 * deletion or is already deleted.*/
669 OC_ACTIVE = (1 << 2),
671 /** When this bit is set, the resource has been marked as 'slow'.
672 * 'slow' signifies that responses from this resource can expect delays in
673 * processing its requests from clients.*/
677 /** When this bit is set, the resource is a secure resource.*/
678 OC_SECURE = (1 << 4),
683 /** When this bit is set, the resource is allowed to be discovered only
684 * if discovery request contains an explicit querystring.
685 * Ex: GET /oic/res?rt=oic.sec.acl */
686 OC_EXPLICIT_DISCOVERABLE = (1 << 5),
689 /** When this bit is set, the resource is allowed to be published */
690 OC_MQ_PUBLISHER = (1 << 6),
694 /** When this bit is set, the resource is allowed to be notified as MQ broker.*/
695 OC_MQ_BROKER = (1 << 7),
697 } OCResourceProperty;
700 * Transport Protocol IDs.
704 /** For invalid ID.*/
705 OC_INVALID_ID = (1 << 0),
708 OC_COAP_ID = (1 << 1)
709 } OCTransportProtocolID;
712 * Declares Stack Results & Errors.
716 /** Success status code - START HERE.*/
718 OC_STACK_RESOURCE_CREATED,
719 OC_STACK_RESOURCE_DELETED,
721 OC_STACK_RESOURCE_CHANGED,
722 /** Success status code - END HERE.*/
724 /** Error status code - START HERE.*/
725 OC_STACK_INVALID_URI = 20,
726 OC_STACK_INVALID_QUERY,
728 OC_STACK_INVALID_PORT,
729 OC_STACK_INVALID_CALLBACK,
730 OC_STACK_INVALID_METHOD,
732 /** Invalid parameter.*/
733 OC_STACK_INVALID_PARAM,
734 OC_STACK_INVALID_OBSERVE_PARAM,
738 OC_STACK_ADAPTER_NOT_ENABLED,
741 /** Resource not found.*/
742 OC_STACK_NO_RESOURCE,
744 /** e.g: not supported method or interface.*/
745 OC_STACK_RESOURCE_ERROR,
746 OC_STACK_SLOW_RESOURCE,
747 OC_STACK_DUPLICATE_REQUEST,
749 /** Resource has no registered observers.*/
750 OC_STACK_NO_OBSERVERS,
751 OC_STACK_OBSERVER_NOT_FOUND,
752 OC_STACK_VIRTUAL_DO_NOT_HANDLE,
753 OC_STACK_INVALID_OPTION,
755 /** The remote reply contained malformed data.*/
756 OC_STACK_MALFORMED_RESPONSE,
757 OC_STACK_PERSISTENT_BUFFER_REQUIRED,
758 OC_STACK_INVALID_REQUEST_HANDLE,
759 OC_STACK_INVALID_DEVICE_INFO,
760 OC_STACK_INVALID_JSON,
762 /** Request is not authorized by Resource Server. */
763 OC_STACK_UNAUTHORIZED_REQ,
764 OC_STACK_TOO_LARGE_REQ,
766 /** Error code from PDM */
767 OC_STACK_PDM_IS_NOT_INITIALIZED,
768 OC_STACK_DUPLICATE_UUID,
769 OC_STACK_INCONSISTENT_DB,
772 * Error code from OTM
773 * This error is pushed from DTLS interface when handshake failure happens
775 OC_STACK_AUTHENTICATION_FAILURE,
777 /** Insert all new error codes here!.*/
779 OC_STACK_PRESENCE_STOPPED = 128,
780 OC_STACK_PRESENCE_TIMEOUT,
781 OC_STACK_PRESENCE_DO_NOT_HANDLE,
783 /** ERROR in stack.*/
785 /** Error status code - END HERE.*/
789 * Handle to an OCDoResource invocation.
791 typedef void * OCDoHandle;
794 * Handle to an OCResource object owned by the OCStack.
796 typedef void * OCResourceHandle;
799 * Handle to an OCRequest object owned by the OCStack.
801 typedef void * OCRequestHandle;
804 * Unique identifier for each observation request. Used when observations are
805 * registered or de-registered. Used by entity handler to signal specific
806 * observers to be notified of resource changes.
807 * There can be maximum of 256 observations per server.
809 typedef uint8_t OCObservationId;
812 * Action associated with observation.
817 OC_OBSERVE_REGISTER = 0,
819 /** To Deregister. */
820 OC_OBSERVE_DEREGISTER = 1,
823 OC_OBSERVE_NO_OPTION = 2
828 * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
829 * when it calls OCRegisterPersistentStorageHandler.
830 * Persistent storage open handler points to default file path.
831 * It should check file path and whether the file is symbolic link or no.
832 * Application can point to appropriate SVR database path for it's IoTivity Server.
835 /** Persistent storage file path.*/
836 FILE* (* open)(const char *path, const char *mode);
838 /** Persistent storage read handler.*/
839 size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
841 /** Persistent storage write handler.*/
842 size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
844 /** Persistent storage close handler.*/
845 int (* close)(FILE *fp);
847 /** Persistent storage unlink handler.*/
848 int (* unlink)(const char *path);
849 } OCPersistentStorage;
852 * Possible returned values from entity handler.
856 /** Action associated with observation request.*/
857 OCObserveAction action;
859 /** Identifier for observation being registered/deregistered.*/
860 OCObservationId obsId;
864 * Possible returned values from entity handler.
870 OC_EH_RESOURCE_CREATED, // 2.01
871 OC_EH_RESOURCE_DELETED, // 2.02
873 OC_EH_FORBIDDEN, // 4.03
874 OC_EH_RESOURCE_NOT_FOUND, // 4.04
876 OC_EH_CHANGED, // 2.04
877 OC_EH_CONTENT, // 2.05
878 OC_EH_BAD_REQ, // 4.00
879 OC_EH_UNAUTHORIZED_REQ, // 4.01
880 OC_EH_BAD_OPT, // 4.02
881 OC_EH_METHOD_NOT_ALLOWED, // 4.05
882 OC_EH_NOT_ACCEPTABLE, // 4.06
883 OC_EH_INTERNAL_SERVER_ERROR, // 5.00
884 OC_EH_RETRANSMIT_TIMEOUT // 5.04
885 } OCEntityHandlerResult;
888 * This structure will be used to define the vendor specific header options to be included
889 * in communication packets.
891 typedef struct OCHeaderOption
893 /** The protocol ID this option applies to.*/
894 OCTransportProtocolID protocolID;
896 /** The header option ID which will be added to communication packets.*/
899 /** its length 191.*/
900 uint16_t optionLength;
902 /** pointer to its data.*/
903 uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
905 #ifdef SUPPORTS_DEFAULT_CTOR
906 OCHeaderOption() = default;
907 OCHeaderOption(OCTransportProtocolID pid,
910 const uint8_t* optData)
916 // parameter includes the null terminator.
917 optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
918 optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
919 memcpy(optionData, optData, optionLength);
920 optionData[optionLength - 1] = '\0';
927 * This structure describes the platform properties. All non-Null properties will be
928 * included in a platform discovery request.
935 /** Manufacturer name.*/
936 char *manufacturerName;
938 /** Manufacturer URL for platform property.*/
939 char *manufacturerUrl;
944 /** Manufacturer date.*/
945 char *dateOfManufacture;
947 /** Platform version.*/
948 char *platformVersion;
950 /** Operating system version.*/
951 char *operatingSystemVersion;
954 char *hardwareVersion;
957 char *firmwareVersion;
959 /** Platform support URL.*/
968 * This structure is expected as input for device properties.
969 * device name is mandatory and expected from the application.
970 * device id of type UUID will be generated by the stack.
974 /** Pointer to the device name.*/
976 /** Pointer to the types.*/
978 /** Pointer to the device specification version.*/
980 /** Pointer to the device data model versions (in CSV format).*/
981 OCStringLL *dataModelVersions;
986 * callback for bound JID
988 typedef void (*jid_bound_cb)(char *jid);
991 * CA Remote Access information for XMPP Client
996 char *hostname; /**< XMPP server hostname */
997 uint16_t port; /**< XMPP server serivce port */
998 char *xmpp_domain; /**< XMPP login domain */
999 char *username; /**< login username */
1000 char *password; /**< login password */
1001 char *resource; /**< specific resource for login */
1002 char *user_jid; /**< specific JID for login */
1003 jid_bound_cb jidbound; /**< callback when JID bound */
1005 #endif /* RA_ADAPTER */
1008 /** Enum to describe the type of object held by the OCPayload object.*/
1011 /** Contents of the payload are invalid */
1012 PAYLOAD_TYPE_INVALID,
1013 /** The payload is an OCDiscoveryPayload */
1014 PAYLOAD_TYPE_DISCOVERY,
1015 /** The payload is an OCDevicePayload */
1016 PAYLOAD_TYPE_DEVICE,
1017 /** The payload is an OCPlatformPayload */
1018 PAYLOAD_TYPE_PLATFORM,
1019 /** The payload is an OCRepPayload */
1020 PAYLOAD_TYPE_REPRESENTATION,
1021 /** The payload is an OCSecurityPayload */
1022 PAYLOAD_TYPE_SECURITY,
1023 /** The payload is an OCPresencePayload */
1024 PAYLOAD_TYPE_PRESENCE,
1025 /** The payload is an OCRDPayload */
1030 * A generic struct representing a payload returned from a resource operation
1032 * A pointer to OCPayLoad can be cast to a more specific struct to access members
1037 /** The type of message that was received */
1048 OCREP_PROP_BYTE_STRING,
1051 }OCRepPayloadPropType;
1053 /** This structure will be used to represent a binary string for CBOR payloads.*/
1056 /** pointer to data bytes.*/
1059 /** number of data bytes.*/
1063 #define MAX_REP_ARRAY_DEPTH 3
1066 OCRepPayloadPropType type;
1067 size_t dimensions[MAX_REP_ARRAY_DEPTH];
1076 /** pointer to ByteString array.*/
1077 OCByteString* ocByteStrArray;
1079 struct OCRepPayload** objArray;
1081 } OCRepPayloadValueArray;
1083 typedef struct OCRepPayloadValue
1086 OCRepPayloadPropType type;
1094 /** ByteString object.*/
1095 OCByteString ocByteStr;
1097 struct OCRepPayload* obj;
1098 OCRepPayloadValueArray arr;
1100 struct OCRepPayloadValue* next;
1102 } OCRepPayloadValue;
1104 // used for get/set/put/observe/etc representations
1105 typedef struct OCRepPayload
1110 OCStringLL* interfaces;
1111 OCRepPayloadValue* values;
1112 struct OCRepPayload* next;
1115 // used inside a discovery payload
1116 typedef struct OCResourcePayload
1120 OCStringLL* interfaces;
1127 struct OCResourcePayload* next;
1128 } OCResourcePayload;
1131 * Structure holding Links Payload. It is a sub-structure used in
1132 * OCResourceCollectionPayload.
1134 typedef struct OCLinksPayload
1136 /** This is the target relative URI. */
1138 /** Resource Type - A standard OIC specified or vendor defined resource
1139 * type of the resource referenced by the target URI. */
1141 /** Interface - The interfaces supported by the resource referenced by the target URI. */
1143 /** The relation of the target URI referenced by the link to the context URI;
1144 * The default value is null. */
1146 /** Specifies if the resource referenced by the target URIis observable or not. */
1148 /** A title for the link relation. Can be used by the UI to provide a context. */
1150 /** This is used to override the context URI e.g. override the URI of the containing collection. */
1152 /** The instance identifier for this web link in an array of web links - used in links. */
1155 /** An ordinal number that is not repeated - must be unique in the collection context. */
1157 /** Any unique string including a URI. */
1159 /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1160 OCIdentity uniqueUUID;
1162 /** A hint of the media type of the representation of the resource referenced by the target URI. */
1164 /** Holding address of the next resource. */
1165 struct OCLinksPayload *next;
1168 /** Structure holding tags value of the links payload. */
1171 /** Name of tags. */
1173 /** Device identifier. */
1175 /** The base URI where the resources are hold. */
1177 /** Bitmap holds observable, discoverable, secure option flag.*/
1179 /** Port set in case, the secure flag is set above. */
1181 /** Id for each set of links i.e. tag. */
1184 /** An ordinal number that is not repeated - must be unique in the collection context. */
1186 /** Any unique string including a URI. */
1188 /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1189 OCIdentity uniqueUUID;
1191 /** Defines the list of allowable resource types (for Target and anchors) in links included
1192 * in the collection; new links being created can only be from this list. */
1194 /** When specified this is the default relationship to use when an OIC Link does not specify
1195 * an explicit relationship with *rel* parameter. */
1197 /** Time to keep holding resource.*/
1201 /** Resource collection payload. */
1202 typedef struct OCResourceCollectionPayload
1204 /** Collection tags payload.*/
1205 OCTagsPayload *tags;
1206 /** Array of links payload. */
1207 OCLinksPayload *setLinks;
1208 /** Holding address of the next resource. */
1209 struct OCResourceCollectionPayload *next;
1210 } OCResourceCollectionPayload;
1212 typedef struct OCDiscoveryPayload
1219 /** A special case for handling RD address. */
1228 /** Resource Type */
1234 /** This structure holds the old /oic/res response. */
1235 OCResourcePayload *resources;
1237 /** Holding address of the next DiscoveryPayload. */
1238 struct OCDiscoveryPayload *next;
1240 } OCDiscoveryPayload;
1243 * Structure holding discovery payload.
1249 /** Device Identity. */
1251 /** Value holding the bias factor of the RD. */
1253 } OCRDDiscoveryPayload;
1256 * RD Payload that will be transmitted over the wire.
1261 /** Pointer to the discovery response payload.*/
1262 OCRDDiscoveryPayload *rdDiscovery;
1263 /** Pointer to the publish payload.*/
1264 OCResourceCollectionPayload *rdPublish;
1273 OCStringLL *dataModelVersions;
1274 OCStringLL *interfaces;
1282 OCPlatformInfo info;
1284 OCStringLL* interfaces;
1285 } OCPlatformPayload;
1290 uint8_t* securityData;
1292 } OCSecurityPayload;
1294 #ifdef WITH_PRESENCE
1298 uint32_t sequenceNumber;
1300 OCPresenceTrigger trigger;
1302 } OCPresencePayload;
1306 * Incoming requests handled by the server. Requests are passed in as a parameter to the
1307 * OCEntityHandler callback API.
1308 * The OCEntityHandler callback API must be implemented in the application in order
1309 * to receive these requests.
1313 /** Associated resource.*/
1314 OCResourceHandle resource;
1316 /** Associated request handle.*/
1317 OCRequestHandle requestHandle;
1319 /** the REST method retrieved from received request PDU.*/
1322 /** description of endpoint that sent the request.*/
1325 /** resource query send by client.*/
1328 /** Information associated with observation - valid only when OCEntityHandler flag includes
1329 * ::OC_OBSERVE_FLAG.*/
1330 OCObservationInfo obsInfo;
1332 /** Number of the received vendor specific header options.*/
1333 uint8_t numRcvdVendorSpecificHeaderOptions;
1335 /** Pointer to the array of the received vendor specific header options.*/
1336 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1341 /** the payload from the request PDU.*/
1344 } OCEntityHandlerRequest;
1348 * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1352 /** Address of remote server.*/
1355 /** backward compatibility (points to devAddr).*/
1358 /** backward compatibility.*/
1359 OCConnectivityType connType;
1361 /** the security identity of the remote server.*/
1362 OCIdentity identity;
1364 /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1365 OCStackResult result;
1367 /** If associated with observe, this will represent the sequence of notifications from server.*/
1368 uint32_t sequenceNumber;
1371 const char * resourceUri;
1373 /** the payload for the response PDU.*/
1376 /** Number of the received vendor specific header options.*/
1377 uint8_t numRcvdVendorSpecificHeaderOptions;
1379 /** An array of the received vendor specific header options.*/
1380 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1384 * Request handle is passed to server via the entity handler for each incoming request.
1385 * Stack assigns when request is received, server sets to indicate what request response is for.
1389 /** Request handle.*/
1390 OCRequestHandle requestHandle;
1392 /** Resource handle.*/
1393 OCResourceHandle resourceHandle;
1395 /** Allow the entity handler to pass a result with the response.*/
1396 OCEntityHandlerResult ehResult;
1398 /** This is the pointer to server payload data to be transferred.*/
1401 /** number of the vendor specific header options .*/
1402 uint8_t numSendVendorSpecificHeaderOptions;
1404 /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1405 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1407 /** URI of new resource that entity handler might create.*/
1408 char resourceUri[MAX_URI_LENGTH];
1410 /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1411 uint8_t persistentBufferFlag;
1412 } OCEntityHandlerResponse;
1419 /** Request state.*/
1420 OC_REQUEST_FLAG = (1 << 1),
1421 /** Observe state.*/
1422 OC_OBSERVE_FLAG = (1 << 2)
1423 } OCEntityHandlerFlag;
1426 * Possible return values from client application callback
1428 * A client application callback returns an OCStackApplicationResult to indicate whether
1429 * the stack should continue to keep the callback registered.
1433 /** Make no more calls to the callback and call the OCClientContextDeleter for this callback */
1434 OC_STACK_DELETE_TRANSACTION = 0,
1435 /** Keep this callback registered and call it if an apropriate event occurs */
1436 OC_STACK_KEEP_TRANSACTION
1437 } OCStackApplicationResult;
1440 //#ifdef DIRECT_PAIRING
1442 * @brief direct pairing Method Type.
1444 * 1: pre-configured pin
1449 DP_NOT_ALLOWED = 0x0,
1450 DP_PRE_CONFIGURED = (0x1 << 0),
1451 DP_RANDOM_PIN = (0x1 << 1),
1455 * Device Information of discoverd direct pairing device(s).
1457 typedef struct OCDPDev
1460 OCConnectivityType connType;
1461 uint16_t securePort;
1465 OCUUIdentity deviceID;
1466 OCUUIdentity rowner;
1467 struct OCDPDev *next;
1469 //#endif // DIRECT_PAIRING
1472 * -------------------------------------------------------------------------------------------
1473 * Callback function definitions
1474 * -------------------------------------------------------------------------------------------
1478 * Client applications implement this callback to consume responses received from Servers.
1480 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1481 OCClientResponse * clientResponse);
1484 * Client applications using a context pointer implement this callback to delete the
1485 * context upon removal of the callback/context pointer from the internal callback-list.
1487 typedef void (* OCClientContextDeleter)(void *context);
1490 * This info is passed from application to OC Stack when initiating a request to Server.
1492 typedef struct OCCallbackData
1494 /** Pointer to the context.*/
1497 /** The pointer to a function the stack will call to handle the requests.*/
1498 OCClientResponseHandler cb;
1500 /** A pointer to a function to delete the context when this callback is removed.*/
1501 OCClientContextDeleter cd;
1503 #ifdef SUPPORTS_DEFAULT_CTOR
1504 OCCallbackData() = default;
1505 OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1506 :context(ctx), cb(callback), cd(deleter){}
1511 * Application server implementations must implement this callback to consume requests OTA.
1512 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1514 typedef OCEntityHandlerResult (*OCEntityHandler)
1515 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1518 * Device Entity handler need to use this call back instead of OCEntityHandler.
1520 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1521 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1523 //#ifdef DIRECT_PAIRING
1525 * Callback function definition of direct-pairing
1527 * @param[OUT] ctx - user context returned in the callback.
1528 * @param[OUT] peer - pairing device info.
1529 * @param[OUT} result - It's returned with 'OC_STACK_XXX'. It will return 'OC_STACK_OK'
1530 * if D2D pairing is success without error
1532 typedef void (*OCDirectPairingCB)(void *ctx, OCDPDev_t *peer, OCStackResult result);
1533 //#endif // DIRECT_PAIRING
1537 #endif // __cplusplus
1539 #endif /* OCTYPES_H_ */