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 #ifdef ROUTING_GATEWAY
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 interface.*/
141 #define OC_RSRVD_INTERFACE "if"
143 /** To represent time to live.*/
144 #define OC_RSRVD_TTL "ttl"
146 /** To represent non*/
147 #define OC_RSRVD_NONCE "non"
149 /** To represent trigger type.*/
150 #define OC_RSRVD_TRIGGER "trg"
152 /** To represent links.*/
153 #define OC_RSRVD_LINKS "links"
155 /** To represent default interface.*/
156 #define OC_RSRVD_INTERFACE_DEFAULT "oic.if.baseline"
158 /** To represent ll interface.*/
159 #define OC_RSRVD_INTERFACE_LL "oic.if.ll"
161 /** To represent batch interface.*/
162 #define OC_RSRVD_INTERFACE_BATCH "oic.if.b"
164 /** To represent interface group.*/
165 #define OC_RSRVD_INTERFACE_GROUP "oic.mi.grp"
167 /** To represent MFG date.*/
168 #define OC_RSRVD_MFG_DATE "mndt"
170 /** To represent FW version.*/
171 #define OC_RSRVD_FW_VERSION "mnfv"
173 /** To represent host name.*/
174 #define OC_RSRVD_HOST_NAME "hn"
176 /** To represent version.*/
177 #define OC_RSRVD_VERSION "icv"
179 /** To represent policy.*/
180 #define OC_RSRVD_POLICY "p"
182 /** To represent bitmap.*/
183 #define OC_RSRVD_BITMAP "bm"
186 #define OC_RSRVD_SECURE "sec"
189 #define OC_RSRVD_HOSTING_PORT "port"
191 /** For Server instance ID.*/
192 #define OC_RSRVD_SERVER_INSTANCE_ID "sid"
199 #define OC_RSRVD_PLATFORM_ID "pi"
201 /** Platform MFG NAME. */
202 #define OC_RSRVD_MFG_NAME "mnmn"
205 #define OC_RSRVD_MFG_URL "mnml"
208 #define OC_RSRVD_MODEL_NUM "mnmo"
210 /** Platform MFG Date.*/
211 #define OC_RSRVD_MFG_DATE "mndt"
213 /** Platform versio.n */
214 #define OC_RSRVD_PLATFORM_VERSION "mnpv"
216 /** Platform Operating system version. */
217 #define OC_RSRVD_OS_VERSION "mnos"
219 /** Platform Hardware version. */
220 #define OC_RSRVD_HARDWARE_VERSION "mnhw"
222 /**Platform Firmware version. */
223 #define OC_RSRVD_FIRMWARE_VERSION "mnfv"
225 /** Support URL for the platform. */
226 #define OC_RSRVD_SUPPORT_URL "mnsl"
228 /** System time for the platform. */
229 #define OC_RSRVD_SYSTEM_TIME "st"
236 #define OC_RSRVD_DEVICE_ID "di"
239 #define OC_RSRVD_DEVICE_NAME "n"
241 /** Device specification version.*/
242 #define OC_RSRVD_SPEC_VERSION "lcv"
244 /** Device data model.*/
245 #define OC_RSRVD_DATA_MODEL_VERSION "dmv"
247 /** Device specification version.*/
248 #define OC_SPEC_VERSION "0.9.0"
250 /** Device Data Model version.*/
251 #define OC_DATA_MODEL_VERSION "sec.0.95"
254 * These provide backward compatibility - their use is deprecated.
258 /** Multicast Prefix.*/
259 #define OC_MULTICAST_PREFIX "224.0.1.187:5683"
261 /** Multicast IP address.*/
262 #define OC_MULTICAST_IP "224.0.1.187"
264 /** Multicast Port.*/
265 #define OC_MULTICAST_PORT 5683
268 /** Max Device address size. */
270 #define MAX_ADDR_STR_SIZE (256)
272 #define MAX_ADDR_STR_SIZE (40)
275 /** Max identity size. */
276 #define MAX_IDENTITY_SIZE (32)
279 * These enums (OCTransportAdapter and OCTransportFlags) must
280 * be kept synchronized with OCConnectivityType (below) as well as
281 * CATransportAdapter and CATransportFlags (in CACommon.h).
285 /** value zero indicates discovery.*/
286 OC_DEFAULT_ADAPTER = 0,
288 /** IPv4 and IPv6, including 6LoWPAN.*/
289 OC_ADAPTER_IP = (1 << 0),
291 /** GATT over Bluetooth LE.*/
292 OC_ADAPTER_GATT_BTLE = (1 << 1),
294 /** RFCOMM over Bluetooth EDR.*/
295 OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
298 /**Remote Access over XMPP.*/
299 OC_ADAPTER_REMOTE_ACCESS = (1 << 3),
304 OC_ADAPTER_TCP = (1 << 4)
307 } OCTransportAdapter;
310 * Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
314 /** default flag is 0*/
315 OC_DEFAULT_FLAGS = 0,
317 /** Insecure transport is the default (subject to change).*/
318 /** secure the transport path*/
319 OC_FLAG_SECURE = (1 << 4),
321 /** IPv4 & IPv6 auto-selection is the default.*/
322 /** IP adapter only.*/
323 OC_IP_USE_V6 = (1 << 5),
325 /** IP adapter only.*/
326 OC_IP_USE_V4 = (1 << 6),
328 /** internal use only.*/
329 OC_RESERVED1 = (1 << 7), // internal use only
331 /** Link-Local multicast is the default multicast scope for IPv6.
332 * These are placed here to correspond to the IPv6 multicast address bits.*/
334 /** IPv6 Interface-Local scope (loopback).*/
335 OC_SCOPE_INTERFACE = 0x1,
337 /** IPv6 Link-Local scope (default).*/
340 /** IPv6 Realm-Local scope. */
341 OC_SCOPE_REALM = 0x3,
343 /** IPv6 Admin-Local scope. */
344 OC_SCOPE_ADMIN = 0x4,
346 /** IPv6 Site-Local scope. */
349 /** IPv6 Organization-Local scope. */
352 /**IPv6 Global scope. */
353 OC_SCOPE_GLOBAL = 0xE,
357 /** Bit mask for scope.*/
358 #define OC_MASK_SCOPE (0x000F)
360 /** Bit mask for Mods.*/
361 #define OC_MASK_MODS (0x0FF0)
362 #define OC_MASK_FAMS (OC_IP_USE_V6|OC_IP_USE_V4)
365 * End point identity.
369 /** Identity Length */
372 /** Array of end point identity.*/
373 unsigned char id[MAX_IDENTITY_SIZE];
377 * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
378 * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
383 OCTransportAdapter adapter;
385 /** transport modifiers.*/
386 OCTransportFlags flags;
391 /** address for all adapters.*/
392 char addr[MAX_ADDR_STR_SIZE];
394 /** usually zero for default interface.*/
396 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
397 char routeData[MAX_ADDR_STR_SIZE]; //destination GatewayID:ClientId
402 * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
403 * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
404 * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
407 * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
411 /** use when defaults are ok. */
414 /** IPv4 and IPv6, including 6LoWPAN.*/
415 CT_ADAPTER_IP = (1 << 16),
417 /** GATT over Bluetooth LE.*/
418 CT_ADAPTER_GATT_BTLE = (1 << 17),
420 /** RFCOMM over Bluetooth EDR.*/
421 CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
424 /** Remote Access over XMPP.*/
425 CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
430 CT_ADAPTER_TCP = (1 << 20),
433 /** Insecure transport is the default (subject to change).*/
435 /** secure the transport path.*/
436 CT_FLAG_SECURE = (1 << 4),
438 /** IPv4 & IPv6 autoselection is the default.*/
440 /** IP adapter only.*/
441 CT_IP_USE_V6 = (1 << 5),
443 /** IP adapter only.*/
444 CT_IP_USE_V4 = (1 << 6),
446 /** Link-Local multicast is the default multicast scope for IPv6.
447 * These are placed here to correspond to the IPv6 address bits.*/
449 /** IPv6 Interface-Local scope(loopback).*/
450 CT_SCOPE_INTERFACE = 0x1,
452 /** IPv6 Link-Local scope (default).*/
455 /** IPv6 Realm-Local scope.*/
456 CT_SCOPE_REALM = 0x3,
458 /** IPv6 Admin-Local scope.*/
459 CT_SCOPE_ADMIN = 0x4,
461 /** IPv6 Site-Local scope.*/
464 /** IPv6 Organization-Local scope.*/
467 /** IPv6 Global scope.*/
468 CT_SCOPE_GLOBAL = 0xE,
469 } OCConnectivityType;
471 /** bit shift required for connectivity adapter.*/
472 #define CT_ADAPTER_SHIFT 16
475 #define CT_MASK_FLAGS 0xFFFF
478 #define CT_MASK_ADAPTER 0xFFFF0000
481 * OCDoResource methods to dispatch the request
485 OC_REST_NOMETHOD = 0,
488 OC_REST_GET = (1 << 0),
491 OC_REST_PUT = (1 << 1),
494 OC_REST_POST = (1 << 2),
497 OC_REST_DELETE = (1 << 3),
499 /** Register observe request for most up date notifications ONLY.*/
500 OC_REST_OBSERVE = (1 << 4),
502 /** Register observe request for all notifications, including stale notifications.*/
503 OC_REST_OBSERVE_ALL = (1 << 5),
505 /** De-register observation, intended for internal use.*/
506 OC_REST_CANCEL_OBSERVE = (1 << 6),
509 /** Subscribe for all presence notifications of a particular resource.*/
510 OC_REST_PRESENCE = (1 << 7),
513 /** Allows OCDoResource caller to do discovery.*/
514 OC_REST_DISCOVER = (1 << 8)
518 * Formats for payload encoding.
524 OC_FORMAT_UNSUPPORTED,
528 * Host Mode of Operation.
535 OC_GATEWAY /**< Client server mode along with routing capabilities.*/
539 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
540 * protocol. The precise definitions of each quality of service level depend on the
541 * implementation. In descriptions below are for the current implementation and may changed
546 /** Packet delivery is best effort.*/
549 /** Packet delivery is best effort.*/
552 /** Acknowledgments are used to confirm delivery.*/
555 /** No Quality is defined, let the stack decide.*/
557 } OCQualityOfService;
560 * Resource Properties.
561 * The value of a policy property is defined as bitmap.
562 * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
563 * Not including the policy property is equivalent to zero.
568 /** When none of the bits are set, the resource is non-discoverable &
569 * non-observable by the client.*/
570 OC_RES_PROP_NONE = (0),
572 /** When this bit is set, the resource is allowed to be discovered by clients.*/
573 OC_DISCOVERABLE = (1 << 0),
575 /** When this bit is set, the resource is allowed to be observed by clients.*/
576 OC_OBSERVABLE = (1 << 1),
578 /** When this bit is set, the resource is initialized, otherwise the resource
579 * is 'inactive'. 'inactive' signifies that the resource has been marked for
580 * deletion or is already deleted.*/
581 OC_ACTIVE = (1 << 2),
583 /** When this bit is set, the resource has been marked as 'slow'.
584 * 'slow' signifies that responses from this resource can expect delays in
585 * processing its requests from clients.*/
588 /** When this bit is set, the resource is a secure resource.*/
589 OC_SECURE = (1 << 4),
591 /** When this bit is set, the resource is allowed to be discovered only
592 * if discovery request contains an explicit querystring.
593 * Ex: GET /oic/res?rt=oic.sec.acl */
594 OC_EXPLICIT_DISCOVERABLE = (1 << 5)
595 } OCResourceProperty;
598 * Transport Protocol IDs.
602 /** For invalid ID.*/
603 OC_INVALID_ID = (1 << 0),
606 OC_COAP_ID = (1 << 1)
607 } OCTransportProtocolID;
610 * Declares Stack Results & Errors.
614 /** Success status code - START HERE.*/
616 OC_STACK_RESOURCE_CREATED,
617 OC_STACK_RESOURCE_DELETED,
619 /** Success status code - END HERE.*/
621 /** Error status code - START HERE.*/
622 OC_STACK_INVALID_URI = 20,
623 OC_STACK_INVALID_QUERY,
625 OC_STACK_INVALID_PORT,
626 OC_STACK_INVALID_CALLBACK,
627 OC_STACK_INVALID_METHOD,
629 /** Invalid parameter.*/
630 OC_STACK_INVALID_PARAM,
631 OC_STACK_INVALID_OBSERVE_PARAM,
635 OC_STACK_ADAPTER_NOT_ENABLED,
638 /** Resource not found.*/
639 OC_STACK_NO_RESOURCE,
641 /** e.g: not supported method or interface.*/
642 OC_STACK_RESOURCE_ERROR,
643 OC_STACK_SLOW_RESOURCE,
644 OC_STACK_DUPLICATE_REQUEST,
646 /** Resource has no registered observers.*/
647 OC_STACK_NO_OBSERVERS,
648 OC_STACK_OBSERVER_NOT_FOUND,
649 OC_STACK_VIRTUAL_DO_NOT_HANDLE,
650 OC_STACK_INVALID_OPTION,
652 /** The remote reply contained malformed data.*/
653 OC_STACK_MALFORMED_RESPONSE,
654 OC_STACK_PERSISTENT_BUFFER_REQUIRED,
655 OC_STACK_INVALID_REQUEST_HANDLE,
656 OC_STACK_INVALID_DEVICE_INFO,
657 OC_STACK_INVALID_JSON,
659 /** Request is not authorized by Resource Server. */
660 OC_STACK_UNAUTHORIZED_REQ,
662 /** Error code from PDM */
663 OC_STACK_PDM_IS_NOT_INITIALIZED,
664 OC_STACK_DUPLICATE_UUID,
665 OC_STACK_INCONSISTENT_DB,
667 /** Insert all new error codes here!.*/
669 OC_STACK_PRESENCE_STOPPED = 128,
670 OC_STACK_PRESENCE_TIMEOUT,
671 OC_STACK_PRESENCE_DO_NOT_HANDLE,
673 /** ERROR in stack.*/
675 /** Error status code - END HERE.*/
679 * Handle to an OCDoResource invocation.
681 typedef void * OCDoHandle;
684 * Handle to an OCResource object owned by the OCStack.
686 typedef void * OCResourceHandle;
689 * Handle to an OCRequest object owned by the OCStack.
691 typedef void * OCRequestHandle;
694 * Unique identifier for each observation request. Used when observations are
695 * registered or de-registered. Used by entity handler to signal specific
696 * observers to be notified of resource changes.
697 * There can be maximum of 256 observations per server.
699 typedef uint8_t OCObservationId;
702 * Action associated with observation.
707 OC_OBSERVE_REGISTER = 0,
709 /** To Deregister. */
710 OC_OBSERVE_DEREGISTER = 1,
713 OC_OBSERVE_NO_OPTION = 2
718 * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
719 * when it calls OCRegisterPersistentStorageHandler.
720 * Persistent storage open handler points to default file path.
721 * Application can point to appropriate SVR database path for it's IoTivity Server.
724 /** Persistent storage file path.*/
725 FILE* (* open)(const char *path, const char *mode);
727 /** Persistent storage read handler.*/
728 size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
730 /** Persistent storage write handler.*/
731 size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
733 /** Persistent storage close handler.*/
734 int (* close)(FILE *fp);
736 /** Persistent storage unlink handler.*/
737 int (* unlink)(const char *path);
738 } OCPersistentStorage;
741 * Possible returned values from entity handler.
745 /** Action associated with observation request.*/
746 OCObserveAction action;
748 /** Identifier for observation being registered/deregistered.*/
749 OCObservationId obsId;
753 * Possible returned values from entity handler.
759 OC_EH_RESOURCE_CREATED,
760 OC_EH_RESOURCE_DELETED,
763 OC_EH_RESOURCE_NOT_FOUND
764 } OCEntityHandlerResult;
767 * This structure will be used to define the vendor specific header options to be included
768 * in communication packets.
770 typedef struct OCHeaderOption
772 /** The protocol ID this option applies to.*/
773 OCTransportProtocolID protocolID;
775 /** The header option ID which will be added to communication packets.*/
778 /** its length 191.*/
779 uint16_t optionLength;
781 /** pointer to its data.*/
782 uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
784 #ifdef SUPPORTS_DEFAULT_CTOR
785 OCHeaderOption() = default;
786 OCHeaderOption(OCTransportProtocolID pid,
789 const uint8_t* optData)
795 // parameter includes the null terminator.
796 optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
797 optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
798 memcpy(optionData, optData, optionLength);
799 optionData[optionLength - 1] = '\0';
806 * This structure describes the platform properties. All non-Null properties will be
807 * included in a platform discovery request.
814 /** Manufacturer name.*/
815 char *manufacturerName;
817 /** Manufacturer URL for platform property.*/
818 char *manufacturerUrl;
823 /** Manufacturer date.*/
824 char *dateOfManufacture;
826 /** Platform version.*/
827 char *platformVersion;
829 /** Operating system version.*/
830 char *operatingSystemVersion;
833 char *hardwareVersion;
836 char *firmwareVersion;
838 /** Platform support URL.*/
847 * This structure is expected as input for device properties.
848 * device name is mandatory and expected from the application.
849 * device id of type UUID will be generated by the stack.
853 /** Pointer to the device name.*/
860 * callback for bound JID
862 typedef void (*jid_bound_cb)(char *jid);
865 * CA Remote Access information for XMPP Client
870 char *hostname; /**< XMPP server hostname */
871 uint16_t port; /**< XMPP server serivce port */
872 char *xmpp_domain; /**< XMPP login domain */
873 char *username; /**< login username */
874 char *password; /**< login password */
875 char *resource; /**< specific resource for login */
876 char *user_jid; /**< specific JID for login */
877 jid_bound_cb jidbound; /**< callback when JID bound */
879 #endif /* RA_ADAPTER */
882 /** Enum to describe the type of object held by the OCPayload object.*/
885 PAYLOAD_TYPE_INVALID,
886 PAYLOAD_TYPE_DISCOVERY,
888 PAYLOAD_TYPE_PLATFORM,
889 PAYLOAD_TYPE_REPRESENTATION,
890 PAYLOAD_TYPE_SECURITY,
891 PAYLOAD_TYPE_PRESENCE
896 // The type of message that was received
909 }OCRepPayloadPropType;
911 #define MAX_REP_ARRAY_DEPTH 3
914 OCRepPayloadPropType type;
915 size_t dimensions[MAX_REP_ARRAY_DEPTH];
923 struct OCRepPayload** objArray;
925 } OCRepPayloadValueArray;
927 typedef struct OCRepPayloadValue
930 OCRepPayloadPropType type;
937 struct OCRepPayload* obj;
938 OCRepPayloadValueArray arr;
940 struct OCRepPayloadValue* next;
944 typedef struct OCStringLL
946 struct OCStringLL *next;
950 // used for get/set/put/observe/etc representations
951 typedef struct OCRepPayload
956 OCStringLL* interfaces;
957 OCRepPayloadValue* values;
958 struct OCRepPayload* next;
961 // used inside a discovery payload
962 typedef struct OCResourcePayload
967 OCStringLL* interfaces;
971 struct OCResourcePayload* next;
977 OCResourcePayload* resources;
978 } OCDiscoveryPayload;
987 char* dataModelVersion;
1001 } OCSecurityPayload;
1002 #ifdef WITH_PRESENCE
1006 uint32_t sequenceNumber;
1008 OCPresenceTrigger trigger;
1010 } OCPresencePayload;
1014 * Incoming requests handled by the server. Requests are passed in as a parameter to the
1015 * OCEntityHandler callback API.
1016 * The OCEntityHandler callback API must be implemented in the application in order
1017 * to receive these requests.
1021 /** Associated resource.*/
1022 OCResourceHandle resource;
1024 /** Associated request handle.*/
1025 OCRequestHandle requestHandle;
1027 /** the REST method retrieved from received request PDU.*/
1030 /** description of endpoint that sent the request.*/
1033 /** resource query send by client.*/
1036 /** Information associated with observation - valid only when OCEntityHandler flag includes
1037 * ::OC_OBSERVE_FLAG.*/
1038 OCObservationInfo obsInfo;
1040 /** Number of the received vendor specific header options.*/
1041 uint8_t numRcvdVendorSpecificHeaderOptions;
1043 /** Pointer to the array of the received vendor specific header options.*/
1044 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1046 /** the payload from the request PDU.*/
1049 } OCEntityHandlerRequest;
1053 * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1057 /** Address of remote server.*/
1060 /** backward compatibility (points to devAddr).*/
1063 /** backward compatibility.*/
1064 OCConnectivityType connType;
1066 /** the security identity of the remote server.*/
1067 OCIdentity identity;
1069 /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1070 OCStackResult result;
1072 /** If associated with observe, this will represent the sequence of notifications from server.*/
1073 uint32_t sequenceNumber;
1076 const char * resourceUri;
1078 /** the payload for the response PDU.*/
1081 /** Number of the received vendor specific header options.*/
1082 uint8_t numRcvdVendorSpecificHeaderOptions;
1084 /** An array of the received vendor specific header options.*/
1085 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1089 * Request handle is passed to server via the entity handler for each incoming request.
1090 * Stack assigns when request is received, server sets to indicate what request response is for.
1094 /** Request handle.*/
1095 OCRequestHandle requestHandle;
1097 /** Resource handle.*/
1098 OCResourceHandle resourceHandle;
1100 /** Allow the entity handler to pass a result with the response.*/
1101 OCEntityHandlerResult ehResult;
1103 /** This is the pointer to server payload data to be transferred.*/
1106 /** number of the vendor specific header options .*/
1107 uint8_t numSendVendorSpecificHeaderOptions;
1109 /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1110 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1112 /** URI of new resource that entity handler might create.*/
1113 char resourceUri[MAX_URI_LENGTH];
1115 /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1116 uint8_t persistentBufferFlag;
1117 } OCEntityHandlerResponse;
1124 /** Request state.*/
1125 OC_REQUEST_FLAG = (1 << 1),
1126 /** Observe state.*/
1127 OC_OBSERVE_FLAG = (1 << 2)
1128 } OCEntityHandlerFlag;
1131 * Possible returned values from client application.
1135 OC_STACK_DELETE_TRANSACTION = 0,
1136 OC_STACK_KEEP_TRANSACTION
1137 } OCStackApplicationResult;
1141 * -------------------------------------------------------------------------------------------
1142 * Callback function definitions
1143 * -------------------------------------------------------------------------------------------
1147 * Client applications implement this callback to consume responses received from Servers.
1149 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1150 OCClientResponse * clientResponse);
1153 * Client applications using a context pointer implement this callback to delete the
1154 * context upon removal of the callback/context pointer from the internal callback-list.
1156 typedef void (* OCClientContextDeleter)(void *context);
1159 * This info is passed from application to OC Stack when initiating a request to Server.
1161 typedef struct OCCallbackData
1163 /** Pointer to the context.*/
1166 /** The pointer to a function the stack will call to handle the requests.*/
1167 OCClientResponseHandler cb;
1169 /** A pointer to a function to delete the context when this callback is removed.*/
1170 OCClientContextDeleter cd;
1172 #ifdef SUPPORTS_DEFAULT_CTOR
1173 OCCallbackData() = default;
1174 OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1175 :context(ctx), cb(callback), cd(deleter){}
1180 * Application server implementations must implement this callback to consume requests OTA.
1181 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1183 typedef OCEntityHandlerResult (*OCEntityHandler)
1184 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1187 * Device Entity handler need to use this call back instead of OCEntityHandler.
1189 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1190 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1194 #endif // __cplusplus
1196 #endif /* OCTYPES_H_ */