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 interface.*/
147 #define OC_RSRVD_INTERFACE "if"
149 /** To represent time to live.*/
150 #define OC_RSRVD_TTL "ttl"
152 /** To represent non*/
153 #define OC_RSRVD_NONCE "non"
155 /** To represent trigger type.*/
156 #define OC_RSRVD_TRIGGER "trg"
158 /** To represent links.*/
159 #define OC_RSRVD_LINKS "links"
161 /** To represent default interface.*/
162 #define OC_RSRVD_INTERFACE_DEFAULT "oic.if.baseline"
164 /** To represent read-only interface.*/
165 #define OC_RSRVD_INTERFACE_READ "oic.if.r"
167 /** To represent ll interface.*/
168 #define OC_RSRVD_INTERFACE_LL "oic.if.ll"
170 /** To represent batch interface.*/
171 #define OC_RSRVD_INTERFACE_BATCH "oic.if.b"
173 /** To represent interface group.*/
174 #define OC_RSRVD_INTERFACE_GROUP "oic.mi.grp"
176 /** To represent MFG date.*/
177 #define OC_RSRVD_MFG_DATE "mndt"
179 /** To represent FW version.*/
180 #define OC_RSRVD_FW_VERSION "mnfv"
182 /** To represent host name.*/
183 #define OC_RSRVD_HOST_NAME "hn"
185 /** To represent policy.*/
186 #define OC_RSRVD_POLICY "p"
188 /** To represent bitmap.*/
189 #define OC_RSRVD_BITMAP "bm"
192 #define OC_RSRVD_SECURE "sec"
195 #define OC_RSRVD_HOSTING_PORT "port"
197 /** For Server instance ID.*/
198 #define OC_RSRVD_SERVER_INSTANCE_ID "sid"
205 #define OC_RSRVD_PLATFORM_ID "pi"
207 /** Platform MFG NAME. */
208 #define OC_RSRVD_MFG_NAME "mnmn"
211 #define OC_RSRVD_MFG_URL "mnml"
214 #define OC_RSRVD_MODEL_NUM "mnmo"
216 /** Platform MFG Date.*/
217 #define OC_RSRVD_MFG_DATE "mndt"
219 /** Platform versio.n */
220 #define OC_RSRVD_PLATFORM_VERSION "mnpv"
222 /** Platform Operating system version. */
223 #define OC_RSRVD_OS_VERSION "mnos"
225 /** Platform Hardware version. */
226 #define OC_RSRVD_HARDWARE_VERSION "mnhw"
228 /**Platform Firmware version. */
229 #define OC_RSRVD_FIRMWARE_VERSION "mnfv"
231 /** Support URL for the platform. */
232 #define OC_RSRVD_SUPPORT_URL "mnsl"
234 /** System time for the platform. */
235 #define OC_RSRVD_SYSTEM_TIME "st"
242 #define OC_RSRVD_DEVICE_ID "di"
245 #define OC_RSRVD_DEVICE_NAME "n"
247 /** Device specification version.*/
248 #define OC_RSRVD_SPEC_VERSION "icv"
250 /** Device data model.*/
251 #define OC_RSRVD_DATA_MODEL_VERSION "dmv"
253 /** Device specification version.*/
254 #define OC_SPEC_VERSION "core.1.0.0"
256 /** Device Data Model version.*/
257 #define OC_DATA_MODEL_VERSION "res.1.0.0"
260 * These provide backward compatibility - their use is deprecated.
264 /** Multicast Prefix.*/
265 #define OC_MULTICAST_PREFIX "224.0.1.187:5683"
267 /** Multicast IP address.*/
268 #define OC_MULTICAST_IP "224.0.1.187"
270 /** Multicast Port.*/
271 #define OC_MULTICAST_PORT 5683
274 /** Max Device address size. */
276 #define MAX_ADDR_STR_SIZE (256)
278 /** Max Address could be "coap+tcp://[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx]:xxxxx" */
279 #define MAX_ADDR_STR_SIZE (59)
282 /** Length of MAC address */
283 #define MAC_ADDR_STR_SIZE (17)
285 /** Blocks of MAC address */
286 #define MAC_ADDR_BLOCKS (6)
288 /** Max identity size. */
289 #define MAX_IDENTITY_SIZE (32)
291 /** Universal unique identity size. */
292 #define UUID_IDENTITY_SIZE (128/8)
294 /** Resource Directory */
296 /** Resource Directory URI used to Discover RD and Publish resources.*/
297 #define OC_RSRVD_RD_URI "/oic/rd"
299 /** To represent resource type with rd.*/
300 #define OC_RSRVD_RESOURCE_TYPE_RD "oic.wk.rd"
302 /** RD Discovery bias factor type. */
303 #define OC_RSRVD_RD_DISCOVERY_SEL "sel"
306 #define OC_RSRVD_BASE_URI "baseURI"
308 /** Unique value per collection/link. */
309 #define OC_RSRVD_INS "ins"
311 /** Allowable resource types in the links. */
312 #define OC_RSRVD_RTS "rts"
314 /** Default relationship. */
315 #define OC_RSRVD_DREL "drel"
317 /** Defines relationship between links. */
318 #define OC_RSRVD_REL "rel"
320 /** Defines title. */
321 #define OC_RSRVD_TITLE "title"
324 #define OC_RSRVD_URI "uri"
326 /** Defines media type. */
327 #define OC_RSRVD_MEDIA_TYPE "mt"
329 /** To represent resource type with Publish RD.*/
330 #define OC_RSRVD_RESOURCE_TYPE_RDPUBLISH "oic.wk.rdPub"
333 * These enums (OCTransportAdapter and OCTransportFlags) must
334 * be kept synchronized with OCConnectivityType (below) as well as
335 * CATransportAdapter and CATransportFlags (in CACommon.h).
339 /** value zero indicates discovery.*/
340 OC_DEFAULT_ADAPTER = 0,
342 /** IPv4 and IPv6, including 6LoWPAN.*/
343 OC_ADAPTER_IP = (1 << 0),
345 /** GATT over Bluetooth LE.*/
346 OC_ADAPTER_GATT_BTLE = (1 << 1),
348 /** RFCOMM over Bluetooth EDR.*/
349 OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
351 /**Remote Access over XMPP.*/
352 OC_ADAPTER_REMOTE_ACCESS = (1 << 3),
355 OC_ADAPTER_TCP = (1 << 4),
357 /** NFC Transport for Messaging.*/
358 OC_ADAPTER_NFC = (1 << 5)
359 } OCTransportAdapter;
362 * Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
366 /** default flag is 0*/
367 OC_DEFAULT_FLAGS = 0,
369 /** Insecure transport is the default (subject to change).*/
370 /** secure the transport path*/
371 OC_FLAG_SECURE = (1 << 4),
373 /** IPv4 & IPv6 auto-selection is the default.*/
374 /** IP adapter only.*/
375 OC_IP_USE_V6 = (1 << 5),
377 /** IP adapter only.*/
378 OC_IP_USE_V4 = (1 << 6),
380 /** internal use only.*/
381 OC_RESERVED1 = (1 << 7), // internal use only
383 /** Link-Local multicast is the default multicast scope for IPv6.
384 * These are placed here to correspond to the IPv6 multicast address bits.*/
386 /** IPv6 Interface-Local scope (loopback).*/
387 OC_SCOPE_INTERFACE = 0x1,
389 /** IPv6 Link-Local scope (default).*/
392 /** IPv6 Realm-Local scope. */
393 OC_SCOPE_REALM = 0x3,
395 /** IPv6 Admin-Local scope. */
396 OC_SCOPE_ADMIN = 0x4,
398 /** IPv6 Site-Local scope. */
401 /** IPv6 Organization-Local scope. */
404 /**IPv6 Global scope. */
405 OC_SCOPE_GLOBAL = 0xE,
409 /** Bit mask for scope.*/
410 #define OC_MASK_SCOPE (0x000F)
412 /** Bit mask for Mods.*/
413 #define OC_MASK_MODS (0x0FF0)
414 #define OC_MASK_FAMS (OC_IP_USE_V6|OC_IP_USE_V4)
417 * End point identity.
421 /** Identity Length */
424 /** Array of end point identity.*/
425 unsigned char id[MAX_IDENTITY_SIZE];
429 * Universally unique identifier.
433 /** identitifier string.*/
434 unsigned char id[UUID_IDENTITY_SIZE];
438 * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
439 * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
444 OCTransportAdapter adapter;
446 /** transport modifiers.*/
447 OCTransportFlags flags;
452 /** address for all adapters.*/
453 char addr[MAX_ADDR_STR_SIZE];
455 /** usually zero for default interface.*/
457 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
458 char routeData[MAX_ADDR_STR_SIZE]; //destination GatewayID:ClientId
463 * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
464 * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
465 * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
468 * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
472 /** use when defaults are ok. */
475 /** IPv4 and IPv6, including 6LoWPAN.*/
476 CT_ADAPTER_IP = (1 << 16),
478 /** GATT over Bluetooth LE.*/
479 CT_ADAPTER_GATT_BTLE = (1 << 17),
481 /** RFCOMM over Bluetooth EDR.*/
482 CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
485 /** Remote Access over XMPP.*/
486 CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
489 CT_ADAPTER_TCP = (1 << 20),
492 CT_ADAPTER_NFC = (1 << 21),
494 /** Insecure transport is the default (subject to change).*/
496 /** secure the transport path.*/
497 CT_FLAG_SECURE = (1 << 4),
499 /** IPv4 & IPv6 autoselection is the default.*/
501 /** IP adapter only.*/
502 CT_IP_USE_V6 = (1 << 5),
504 /** IP adapter only.*/
505 CT_IP_USE_V4 = (1 << 6),
507 /** Link-Local multicast is the default multicast scope for IPv6.
508 * These are placed here to correspond to the IPv6 address bits.*/
510 /** IPv6 Interface-Local scope(loopback).*/
511 CT_SCOPE_INTERFACE = 0x1,
513 /** IPv6 Link-Local scope (default).*/
516 /** IPv6 Realm-Local scope.*/
517 CT_SCOPE_REALM = 0x3,
519 /** IPv6 Admin-Local scope.*/
520 CT_SCOPE_ADMIN = 0x4,
522 /** IPv6 Site-Local scope.*/
525 /** IPv6 Organization-Local scope.*/
528 /** IPv6 Global scope.*/
529 CT_SCOPE_GLOBAL = 0xE,
530 } OCConnectivityType;
532 /** bit shift required for connectivity adapter.*/
533 #define CT_ADAPTER_SHIFT 16
536 #define CT_MASK_FLAGS 0xFFFF
539 #define CT_MASK_ADAPTER 0xFFFF0000
542 * OCDoResource methods to dispatch the request
546 OC_REST_NOMETHOD = 0,
549 OC_REST_GET = (1 << 0),
552 OC_REST_PUT = (1 << 1),
555 OC_REST_POST = (1 << 2),
558 OC_REST_DELETE = (1 << 3),
560 /** Register observe request for most up date notifications ONLY.*/
561 OC_REST_OBSERVE = (1 << 4),
563 /** Register observe request for all notifications, including stale notifications.*/
564 OC_REST_OBSERVE_ALL = (1 << 5),
566 /** De-register observation, intended for internal use.*/
567 OC_REST_CANCEL_OBSERVE = (1 << 6),
570 /** Subscribe for all presence notifications of a particular resource.*/
571 OC_REST_PRESENCE = (1 << 7),
574 /** Allows OCDoResource caller to do discovery.*/
575 OC_REST_DISCOVER = (1 << 8)
579 * Formats for payload encoding.
585 OC_FORMAT_UNSUPPORTED,
589 * Host Mode of Operation.
596 OC_GATEWAY /**< Client server mode along with routing capabilities.*/
600 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
601 * protocol. The precise definitions of each quality of service level depend on the
602 * implementation. In descriptions below are for the current implementation and may changed
607 /** Packet delivery is best effort.*/
610 /** Packet delivery is best effort.*/
613 /** Acknowledgments are used to confirm delivery.*/
616 /** No Quality is defined, let the stack decide.*/
618 } OCQualityOfService;
621 * Resource Properties.
622 * The value of a policy property is defined as bitmap.
623 * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
624 * Not including the policy property is equivalent to zero.
629 /** When none of the bits are set, the resource is non-discoverable &
630 * non-observable by the client.*/
631 OC_RES_PROP_NONE = (0),
633 /** When this bit is set, the resource is allowed to be discovered by clients.*/
634 OC_DISCOVERABLE = (1 << 0),
636 /** When this bit is set, the resource is allowed to be observed by clients.*/
637 OC_OBSERVABLE = (1 << 1),
639 /** When this bit is set, the resource is initialized, otherwise the resource
640 * is 'inactive'. 'inactive' signifies that the resource has been marked for
641 * deletion or is already deleted.*/
642 OC_ACTIVE = (1 << 2),
644 /** When this bit is set, the resource has been marked as 'slow'.
645 * 'slow' signifies that responses from this resource can expect delays in
646 * processing its requests from clients.*/
649 /** When this bit is set, the resource is a secure resource.*/
650 OC_SECURE = (1 << 4),
652 /** When this bit is set, the resource is allowed to be discovered only
653 * if discovery request contains an explicit querystring.
654 * Ex: GET /oic/res?rt=oic.sec.acl */
655 OC_EXPLICIT_DISCOVERABLE = (1 << 5)
656 } OCResourceProperty;
659 * Transport Protocol IDs.
663 /** For invalid ID.*/
664 OC_INVALID_ID = (1 << 0),
667 OC_COAP_ID = (1 << 1)
668 } OCTransportProtocolID;
671 * Declares Stack Results & Errors.
675 /** Success status code - START HERE.*/
677 OC_STACK_RESOURCE_CREATED,
678 OC_STACK_RESOURCE_DELETED,
680 /** Success status code - END HERE.*/
682 /** Error status code - START HERE.*/
683 OC_STACK_INVALID_URI = 20,
684 OC_STACK_INVALID_QUERY,
686 OC_STACK_INVALID_PORT,
687 OC_STACK_INVALID_CALLBACK,
688 OC_STACK_INVALID_METHOD,
690 /** Invalid parameter.*/
691 OC_STACK_INVALID_PARAM,
692 OC_STACK_INVALID_OBSERVE_PARAM,
696 OC_STACK_ADAPTER_NOT_ENABLED,
699 /** Resource not found.*/
700 OC_STACK_NO_RESOURCE,
702 /** e.g: not supported method or interface.*/
703 OC_STACK_RESOURCE_ERROR,
704 OC_STACK_SLOW_RESOURCE,
705 OC_STACK_DUPLICATE_REQUEST,
707 /** Resource has no registered observers.*/
708 OC_STACK_NO_OBSERVERS,
709 OC_STACK_OBSERVER_NOT_FOUND,
710 OC_STACK_VIRTUAL_DO_NOT_HANDLE,
711 OC_STACK_INVALID_OPTION,
713 /** The remote reply contained malformed data.*/
714 OC_STACK_MALFORMED_RESPONSE,
715 OC_STACK_PERSISTENT_BUFFER_REQUIRED,
716 OC_STACK_INVALID_REQUEST_HANDLE,
717 OC_STACK_INVALID_DEVICE_INFO,
718 OC_STACK_INVALID_JSON,
720 /** Request is not authorized by Resource Server. */
721 OC_STACK_UNAUTHORIZED_REQ,
723 /** Error code from PDM */
724 OC_STACK_PDM_IS_NOT_INITIALIZED,
725 OC_STACK_DUPLICATE_UUID,
726 OC_STACK_INCONSISTENT_DB,
729 * Error code from OTM
730 * This error is plused from DTLS interface when handshake failure happens
732 OC_STACK_AUTHENTICATION_FAILURE,
734 /** Insert all new error codes here!.*/
736 OC_STACK_PRESENCE_STOPPED = 128,
737 OC_STACK_PRESENCE_TIMEOUT,
738 OC_STACK_PRESENCE_DO_NOT_HANDLE,
740 /** ERROR in stack.*/
742 /** Error status code - END HERE.*/
746 * Handle to an OCDoResource invocation.
748 typedef void * OCDoHandle;
751 * Handle to an OCResource object owned by the OCStack.
753 typedef void * OCResourceHandle;
756 * Handle to an OCRequest object owned by the OCStack.
758 typedef void * OCRequestHandle;
761 * Unique identifier for each observation request. Used when observations are
762 * registered or de-registered. Used by entity handler to signal specific
763 * observers to be notified of resource changes.
764 * There can be maximum of 256 observations per server.
766 typedef uint8_t OCObservationId;
769 * Action associated with observation.
774 OC_OBSERVE_REGISTER = 0,
776 /** To Deregister. */
777 OC_OBSERVE_DEREGISTER = 1,
780 OC_OBSERVE_NO_OPTION = 2
785 * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
786 * when it calls OCRegisterPersistentStorageHandler.
787 * Persistent storage open handler points to default file path.
788 * Application can point to appropriate SVR database path for it's IoTivity Server.
791 /** Persistent storage file path.*/
792 FILE* (* open)(const char *path, const char *mode);
794 /** Persistent storage read handler.*/
795 size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
797 /** Persistent storage write handler.*/
798 size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
800 /** Persistent storage close handler.*/
801 int (* close)(FILE *fp);
803 /** Persistent storage unlink handler.*/
804 int (* unlink)(const char *path);
805 } OCPersistentStorage;
808 * Possible returned values from entity handler.
812 /** Action associated with observation request.*/
813 OCObserveAction action;
815 /** Identifier for observation being registered/deregistered.*/
816 OCObservationId obsId;
820 * Possible returned values from entity handler.
826 OC_EH_RESOURCE_CREATED,
827 OC_EH_RESOURCE_DELETED,
830 OC_EH_RESOURCE_NOT_FOUND
831 } OCEntityHandlerResult;
834 * This structure will be used to define the vendor specific header options to be included
835 * in communication packets.
837 typedef struct OCHeaderOption
839 /** The protocol ID this option applies to.*/
840 OCTransportProtocolID protocolID;
842 /** The header option ID which will be added to communication packets.*/
845 /** its length 191.*/
846 uint16_t optionLength;
848 /** pointer to its data.*/
849 uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
851 #ifdef SUPPORTS_DEFAULT_CTOR
852 OCHeaderOption() = default;
853 OCHeaderOption(OCTransportProtocolID pid,
856 const uint8_t* optData)
862 // parameter includes the null terminator.
863 optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
864 optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
865 memcpy(optionData, optData, optionLength);
866 optionData[optionLength - 1] = '\0';
873 * This structure describes the platform properties. All non-Null properties will be
874 * included in a platform discovery request.
881 /** Manufacturer name.*/
882 char *manufacturerName;
884 /** Manufacturer URL for platform property.*/
885 char *manufacturerUrl;
890 /** Manufacturer date.*/
891 char *dateOfManufacture;
893 /** Platform version.*/
894 char *platformVersion;
896 /** Operating system version.*/
897 char *operatingSystemVersion;
900 char *hardwareVersion;
903 char *firmwareVersion;
905 /** Platform support URL.*/
914 * This structure is expected as input for device properties.
915 * device name is mandatory and expected from the application.
916 * device id of type UUID will be generated by the stack.
920 /** Pointer to the device name.*/
927 * callback for bound JID
929 typedef void (*jid_bound_cb)(char *jid);
932 * CA Remote Access information for XMPP Client
937 char *hostname; /**< XMPP server hostname */
938 uint16_t port; /**< XMPP server serivce port */
939 char *xmpp_domain; /**< XMPP login domain */
940 char *username; /**< login username */
941 char *password; /**< login password */
942 char *resource; /**< specific resource for login */
943 char *user_jid; /**< specific JID for login */
944 jid_bound_cb jidbound; /**< callback when JID bound */
946 #endif /* RA_ADAPTER */
949 /** Enum to describe the type of object held by the OCPayload object.*/
952 PAYLOAD_TYPE_INVALID,
953 PAYLOAD_TYPE_DISCOVERY,
955 PAYLOAD_TYPE_PLATFORM,
956 PAYLOAD_TYPE_REPRESENTATION,
957 PAYLOAD_TYPE_SECURITY,
958 PAYLOAD_TYPE_PRESENCE,
964 // The type of message that was received
975 OCREP_PROP_BYTE_STRING,
978 }OCRepPayloadPropType;
980 /** This structure will be used to represent a binary string for CBOR payloads.*/
983 /** pointer to data bytes.*/
986 /** number of data bytes.*/
990 #define MAX_REP_ARRAY_DEPTH 3
993 OCRepPayloadPropType type;
994 size_t dimensions[MAX_REP_ARRAY_DEPTH];
1003 /** pointer to ByteString array.*/
1004 OCByteString* ocByteStrArray;
1006 struct OCRepPayload** objArray;
1008 } OCRepPayloadValueArray;
1010 typedef struct OCRepPayloadValue
1013 OCRepPayloadPropType type;
1021 /** ByteString object.*/
1022 OCByteString ocByteStr;
1024 struct OCRepPayload* obj;
1025 OCRepPayloadValueArray arr;
1027 struct OCRepPayloadValue* next;
1029 } OCRepPayloadValue;
1031 typedef struct OCStringLL
1033 struct OCStringLL *next;
1037 // used for get/set/put/observe/etc representations
1038 typedef struct OCRepPayload
1043 OCStringLL* interfaces;
1044 OCRepPayloadValue* values;
1045 struct OCRepPayload* next;
1048 // used inside a discovery payload
1049 typedef struct OCResourcePayload
1053 OCStringLL* interfaces;
1057 struct OCResourcePayload* next;
1058 } OCResourcePayload;
1061 * Structure holding Links Payload. It is a sub-structure used in
1062 * OCResourceCollectionPayload.
1064 typedef struct OCLinksPayload
1066 /** This is the target relative URI. */
1068 /** Resource Type - A standard OIC specified or vendor defined resource
1069 * type of the resource referenced by the target URI. */
1071 /** Interface - The interfaces supported by the resource referenced by the target URI. */
1073 /** The relation of the target URI referenced by the link to the context URI;
1074 * The default value is null. */
1076 /** Specifies if the resource referenced by the target URIis observable or not. */
1078 /** A title for the link relation. Can be used by the UI to provide a context. */
1080 /** This is used to override the context URI e.g. override the URI of the containing collection. */
1082 /** The instance identifier for this web link in an array of web links - used in links. */
1085 /** An ordinal number that is not repeated - must be unique in the collection context. */
1087 /** Any unique string including a URI. */
1089 /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1090 OCIdentity uniqueUUID;
1092 /** A hint of the media type of the representation of the resource referenced by the target URI. */
1094 /** Holding address of the next resource. */
1095 struct OCLinksPayload *next;
1098 /** Structure holding tags value of the links payload. */
1101 /** Name of tags. */
1103 /** Device identifier. */
1105 /** The base URI where the resources are hold. */
1107 /** Bitmap holds observable, discoverable, secure option flag.*/
1109 /** Port set in case, the secure flag is set above. */
1111 /** Id for each set of links i.e. tag. */
1114 /** An ordinal number that is not repeated - must be unique in the collection context. */
1116 /** Any unique string including a URI. */
1118 /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1119 OCIdentity uniqueUUID;
1121 /** Defines the list of allowable resource types (for Target and anchors) in links included
1122 * in the collection; new links being created can only be from this list. */
1124 /** When specified this is the default relationship to use when an OIC Link does not specify
1125 * an explicit relationship with *rel* parameter. */
1127 /** Time to keep holding resource.*/
1131 /** Resource collection payload. */
1132 typedef struct OCResourceCollectionPayload
1134 /** Collection tags payload.*/
1135 OCTagsPayload *tags;
1136 /** Array of links payload. */
1137 OCLinksPayload *setLinks;
1138 /** Holding address of the next resource. */
1139 struct OCResourceCollectionPayload *next;
1140 } OCResourceCollectionPayload;
1148 /** A special case for handling RD address. */
1151 /** This structure holds the old /oic/res response. */
1152 OCResourcePayload *resources;
1154 } OCDiscoveryPayload;
1157 * Structure holding discovery payload.
1163 /** Device Identity. */
1165 /** Value holding the bias factor of the RD. */
1167 } OCRDDiscoveryPayload;
1170 * RD Payload that will be transmitted over the wire.
1175 /** Pointer to the discovery response payload.*/
1176 OCRDDiscoveryPayload *rdDiscovery;
1177 /** Pointer to the publish payload.*/
1178 OCResourceCollectionPayload *rdPublish;
1187 char* dataModelVersion;
1194 OCPlatformInfo info;
1196 OCStringLL* interfaces;
1197 } OCPlatformPayload;
1203 uint8_t *securityData1;
1205 } OCSecurityPayload;
1207 #ifdef WITH_PRESENCE
1211 uint32_t sequenceNumber;
1213 OCPresenceTrigger trigger;
1215 } OCPresencePayload;
1219 * Incoming requests handled by the server. Requests are passed in as a parameter to the
1220 * OCEntityHandler callback API.
1221 * The OCEntityHandler callback API must be implemented in the application in order
1222 * to receive these requests.
1226 /** Associated resource.*/
1227 OCResourceHandle resource;
1229 /** Associated request handle.*/
1230 OCRequestHandle requestHandle;
1232 /** the REST method retrieved from received request PDU.*/
1235 /** description of endpoint that sent the request.*/
1238 /** resource query send by client.*/
1241 /** Information associated with observation - valid only when OCEntityHandler flag includes
1242 * ::OC_OBSERVE_FLAG.*/
1243 OCObservationInfo obsInfo;
1245 /** Number of the received vendor specific header options.*/
1246 uint8_t numRcvdVendorSpecificHeaderOptions;
1248 /** Pointer to the array of the received vendor specific header options.*/
1249 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1251 /** the payload from the request PDU.*/
1254 } OCEntityHandlerRequest;
1258 * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1262 /** Address of remote server.*/
1265 /** backward compatibility (points to devAddr).*/
1268 /** backward compatibility.*/
1269 OCConnectivityType connType;
1271 /** the security identity of the remote server.*/
1272 OCIdentity identity;
1274 /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1275 OCStackResult result;
1277 /** If associated with observe, this will represent the sequence of notifications from server.*/
1278 uint32_t sequenceNumber;
1281 const char * resourceUri;
1283 /** the payload for the response PDU.*/
1286 /** Number of the received vendor specific header options.*/
1287 uint8_t numRcvdVendorSpecificHeaderOptions;
1289 /** An array of the received vendor specific header options.*/
1290 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1294 * Request handle is passed to server via the entity handler for each incoming request.
1295 * Stack assigns when request is received, server sets to indicate what request response is for.
1299 /** Request handle.*/
1300 OCRequestHandle requestHandle;
1302 /** Resource handle.*/
1303 OCResourceHandle resourceHandle;
1305 /** Allow the entity handler to pass a result with the response.*/
1306 OCEntityHandlerResult ehResult;
1308 /** This is the pointer to server payload data to be transferred.*/
1311 /** number of the vendor specific header options .*/
1312 uint8_t numSendVendorSpecificHeaderOptions;
1314 /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1315 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1317 /** URI of new resource that entity handler might create.*/
1318 char resourceUri[MAX_URI_LENGTH];
1320 /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1321 uint8_t persistentBufferFlag;
1322 } OCEntityHandlerResponse;
1329 /** Request state.*/
1330 OC_REQUEST_FLAG = (1 << 1),
1331 /** Observe state.*/
1332 OC_OBSERVE_FLAG = (1 << 2)
1333 } OCEntityHandlerFlag;
1336 * Possible returned values from client application.
1340 OC_STACK_DELETE_TRANSACTION = 0,
1341 OC_STACK_KEEP_TRANSACTION
1342 } OCStackApplicationResult;
1345 //#ifdef DIRECT_PAIRING
1347 * @brief direct pairing Method Type.
1349 * 1: pre-configured pin
1354 DP_NOT_ALLOWED = 0x0,
1355 DP_PRE_CONFIGURED = (0x1 << 0),
1356 DP_RANDOM_PIN = (0x1 << 1),
1360 * Device Information of discoverd direct pairing device(s).
1362 typedef struct OCDPDev
1365 OCConnectivityType connType;
1366 uint16_t securePort;
1370 OCUUIdentity deviceID;
1371 OCUUIdentity rowner;
1372 struct OCDPDev *next;
1374 //#endif // DIRECT_PAIRING
1377 * -------------------------------------------------------------------------------------------
1378 * Callback function definitions
1379 * -------------------------------------------------------------------------------------------
1383 * Client applications implement this callback to consume responses received from Servers.
1385 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1386 OCClientResponse * clientResponse);
1389 * Client applications using a context pointer implement this callback to delete the
1390 * context upon removal of the callback/context pointer from the internal callback-list.
1392 typedef void (* OCClientContextDeleter)(void *context);
1395 * This info is passed from application to OC Stack when initiating a request to Server.
1397 typedef struct OCCallbackData
1399 /** Pointer to the context.*/
1402 /** The pointer to a function the stack will call to handle the requests.*/
1403 OCClientResponseHandler cb;
1405 /** A pointer to a function to delete the context when this callback is removed.*/
1406 OCClientContextDeleter cd;
1408 #ifdef SUPPORTS_DEFAULT_CTOR
1409 OCCallbackData() = default;
1410 OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1411 :context(ctx), cb(callback), cd(deleter){}
1416 * Application server implementations must implement this callback to consume requests OTA.
1417 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1419 typedef OCEntityHandlerResult (*OCEntityHandler)
1420 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1423 * Device Entity handler need to use this call back instead of OCEntityHandler.
1425 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1426 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1428 //#ifdef DIRECT_PAIRING
1430 * Callback function definition of direct-pairing
1432 * @param[OUT] peer - pairing device info.
1433 * @param[OUT} result - It's returned with 'OC_STACK_XXX'. It will return 'OC_STACK_OK'
1434 * if D2D pairing is success without error
1436 typedef void (*OCDirectPairingCB)(OCDPDev_t *peer, OCStackResult result);
1437 //#endif // DIRECT_PAIRING
1441 #endif // __cplusplus
1443 #endif /* OCTYPES_H_ */