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"
70 /** Presence URI through which the OIC devices advertise their presence.*/
71 #define OC_RSRVD_PRESENCE_URI "/oic/ad"
73 /** Sets the default time to live (TTL) for presence.*/
74 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
76 /** For multicast Discovery mechanism.*/
77 #define OC_MULTICAST_DISCOVERY_URI "/oic/res"
79 /** Separator for multiple query string.*/
80 #define OC_QUERY_SEPARATOR "&;"
83 * OC_DEFAULT_PRESENCE_TTL_SECONDS sets the default time to live (TTL) for presence.
85 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
88 * OC_MAX_PRESENCE_TTL_SECONDS sets the maximum time to live (TTL) for presence.
89 * NOTE: Changing the setting to a longer duration may lead to unsupported and untested
91 * 60 sec/min * 60 min/hr * 24 hr/day
93 #define OC_MAX_PRESENCE_TTL_SECONDS (60 * 60 * 24)
97 * Presence "Announcement Triggers".
101 #define OC_RSRVD_TRIGGER_CREATE "create"
104 #define OC_RSRVD_TRIGGER_CHANGE "change"
107 #define OC_RSRVD_TRIGGER_DELETE "delete"
110 * Attributes used to form a proper OIC conforming JSON message.
113 #define OC_RSRVD_OC "oic"
117 #define OC_RSRVD_PAYLOAD "payload"
119 /** To represent href */
120 #define OC_RSRVD_HREF "href"
122 /** To represent property*/
123 #define OC_RSRVD_PROPERTY "prop"
125 /** For representation.*/
126 #define OC_RSRVD_REPRESENTATION "rep"
128 /** To represent content type.*/
129 #define OC_RSRVD_CONTENT_TYPE "ct"
131 /** To represent resource type.*/
132 #define OC_RSRVD_RESOURCE_TYPE "rt"
134 /** To represent resource type with presence.*/
135 #define OC_RSRVD_RESOURCE_TYPE_PRESENCE "oic.wk.ad"
137 /** To represent interface.*/
138 #define OC_RSRVD_INTERFACE "if"
140 /** To represent time to live.*/
141 #define OC_RSRVD_TTL "ttl"
143 /** To represent non*/
144 #define OC_RSRVD_NONCE "non"
146 /** To represent trigger type.*/
147 #define OC_RSRVD_TRIGGER "trg"
149 /** To represent links.*/
150 #define OC_RSRVD_LINKS "links"
152 /** To represent default interface.*/
153 #define OC_RSRVD_INTERFACE_DEFAULT "oic.if.baseline"
155 /** To represent ll interface.*/
156 #define OC_RSRVD_INTERFACE_LL "oic.if.ll"
158 /** To represent batch interface.*/
159 #define OC_RSRVD_INTERFACE_BATCH "oic.if.b"
161 /** To represent interface group.*/
162 #define OC_RSRVD_INTERFACE_GROUP "oic.mi.grp"
164 /** To represent MFG date.*/
165 #define OC_RSRVD_MFG_DATE "mndt"
167 /** To represent FW version.*/
168 #define OC_RSRVD_FW_VERSION "mnfv"
170 /** To represent host name.*/
171 #define OC_RSRVD_HOST_NAME "hn"
173 /** To represent version.*/
174 #define OC_RSRVD_VERSION "icv"
176 /** To represent policy.*/
177 #define OC_RSRVD_POLICY "p"
179 /** To represent bitmap.*/
180 #define OC_RSRVD_BITMAP "bm"
183 #define OC_RSRVD_SECURE "sec"
186 #define OC_RSRVD_HOSTING_PORT "port"
188 /** For Server instance ID.*/
189 #define OC_RSRVD_SERVER_INSTANCE_ID "sid"
196 #define OC_RSRVD_PLATFORM_ID "pi"
198 /** Platform MFG NAME. */
199 #define OC_RSRVD_MFG_NAME "mnmn"
202 #define OC_RSRVD_MFG_URL "mnml"
205 #define OC_RSRVD_MODEL_NUM "mnmo"
207 /** Platform MFG Date.*/
208 #define OC_RSRVD_MFG_DATE "mndt"
210 /** Platform versio.n */
211 #define OC_RSRVD_PLATFORM_VERSION "mnpv"
213 /** Platform Operating system version. */
214 #define OC_RSRVD_OS_VERSION "mnos"
216 /** Platform Hardware version. */
217 #define OC_RSRVD_HARDWARE_VERSION "mnhw"
219 /**Platform Firmware version. */
220 #define OC_RSRVD_FIRMWARE_VERSION "mnfv"
222 /** Support URL for the platform. */
223 #define OC_RSRVD_SUPPORT_URL "mnsl"
225 /** System time for the platform. */
226 #define OC_RSRVD_SYSTEM_TIME "st"
233 #define OC_RSRVD_DEVICE_ID "di"
236 #define OC_RSRVD_DEVICE_NAME "n"
238 /** Device specification version.*/
239 #define OC_RSRVD_SPEC_VERSION "lcv"
241 /** Device data model.*/
242 #define OC_RSRVD_DATA_MODEL_VERSION "dmv"
244 /** Device specification version.*/
245 #define OC_SPEC_VERSION "0.9.0"
247 /** Device Data Model version.*/
248 #define OC_DATA_MODEL_VERSION "sec.0.95"
251 * These provide backward compatibility - their use is deprecated.
255 /** Multicast Prefix.*/
256 #define OC_MULTICAST_PREFIX "224.0.1.187:5683"
258 /** Multicast IP address.*/
259 #define OC_MULTICAST_IP "224.0.1.187"
261 /** Multicast Port.*/
262 #define OC_MULTICAST_PORT 5683
265 /** Max Device address size. */
267 #define MAX_ADDR_STR_SIZE (256)
269 #define MAX_ADDR_STR_SIZE (40)
272 /** Max identity size. */
273 #define MAX_IDENTITY_SIZE (32)
276 * These enums (OCTransportAdapter and OCTransportFlags) must
277 * be kept synchronized with OCConnectivityType (below) as well as
278 * CATransportAdapter and CATransportFlags (in CACommon.h).
282 /** value zero indicates discovery.*/
283 OC_DEFAULT_ADAPTER = 0,
285 /** IPv4 and IPv6, including 6LoWPAN.*/
286 OC_ADAPTER_IP = (1 << 0),
288 /** GATT over Bluetooth LE.*/
289 OC_ADAPTER_GATT_BTLE = (1 << 1),
291 /** RFCOMM over Bluetooth EDR.*/
292 OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
295 /**Remote Access over XMPP.*/
296 OC_ADAPTER_REMOTE_ACCESS = (1 << 3)
299 } OCTransportAdapter;
302 * Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
306 /** default flag is 0*/
307 OC_DEFAULT_FLAGS = 0,
309 /** Insecure transport is the default (subject to change).*/
310 /** secure the transport path*/
311 OC_FLAG_SECURE = (1 << 4),
313 /** IPv4 & IPv6 auto-selection is the default.*/
314 /** IP adapter only.*/
315 OC_IP_USE_V6 = (1 << 5),
317 /** IP adapter only.*/
318 OC_IP_USE_V4 = (1 << 6),
320 /** internal use only.*/
321 OC_RESERVED1 = (1 << 7), // internal use only
323 /** Link-Local multicast is the default multicast scope for IPv6.
324 * These are placed here to correspond to the IPv6 multicast address bits.*/
326 /** IPv6 Interface-Local scope (loopback).*/
327 OC_SCOPE_INTERFACE = 0x1,
329 /** IPv6 Link-Local scope (default).*/
332 /** IPv6 Realm-Local scope. */
333 OC_SCOPE_REALM = 0x3,
335 /** IPv6 Admin-Local scope. */
336 OC_SCOPE_ADMIN = 0x4,
338 /** IPv6 Site-Local scope. */
341 /** IPv6 Organization-Local scope. */
344 /**IPv6 Global scope. */
345 OC_SCOPE_GLOBAL = 0xE,
349 /** Bit mask for scope.*/
350 #define OC_MASK_SCOPE (0x000F)
352 /** Bit mask for Mods.*/
353 #define OC_MASK_MODS (0x0FF0)
354 #define OC_MASK_FAMS (OC_IP_USE_V6|OC_IP_USE_V4)
357 * End point identity.
361 /** Identity Length */
364 /** Array of end point identity.*/
365 unsigned char id[MAX_IDENTITY_SIZE];
369 * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
370 * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
375 OCTransportAdapter adapter;
377 /** transport modifiers.*/
378 OCTransportFlags flags;
380 /** address for all adapters.*/
381 char addr[MAX_ADDR_STR_SIZE];
383 /** usually zero for default interface.*/
389 /** secure node identity.*/
394 * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
395 * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
396 * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
399 * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
403 /** use when defaults are ok. */
406 /** IPv4 and IPv6, including 6LoWPAN.*/
407 CT_ADAPTER_IP = (1 << 16),
409 /** GATT over Bluetooth LE.*/
410 CT_ADAPTER_GATT_BTLE = (1 << 17),
412 /** RFCOMM over Bluetooth EDR.*/
413 CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
416 /** Remote Access over XMPP.*/
417 CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
420 /** Insecure transport is the default (subject to change).*/
422 /** secure the transport path.*/
423 CT_FLAG_SECURE = (1 << 4),
425 /** IPv4 & IPv6 autoselection is the default.*/
427 /** IP adapter only.*/
428 CT_IP_USE_V6 = (1 << 5),
430 /** IP adapter only.*/
431 CT_IP_USE_V4 = (1 << 6),
433 /** Link-Local multicast is the default multicast scope for IPv6.
434 * These are placed here to correspond to the IPv6 address bits.*/
436 /** IPv6 Interface-Local scope(loopback).*/
437 CT_SCOPE_INTERFACE = 0x1,
439 /** IPv6 Link-Local scope (default).*/
442 /** IPv6 Realm-Local scope.*/
443 CT_SCOPE_REALM = 0x3,
445 /** IPv6 Admin-Local scope.*/
446 CT_SCOPE_ADMIN = 0x4,
448 /** IPv6 Site-Local scope.*/
451 /** IPv6 Organization-Local scope.*/
454 /** IPv6 Global scope.*/
455 CT_SCOPE_GLOBAL = 0xE,
456 } OCConnectivityType;
458 /** bit shift required for connectivity adapter.*/
459 #define CT_ADAPTER_SHIFT 16
462 #define CT_MASK_FLAGS 0xFFFF
465 #define CT_MASK_ADAPTER 0xFFFF0000
468 * OCDoResource methods to dispatch the request
472 OC_REST_NOMETHOD = 0,
475 OC_REST_GET = (1 << 0),
478 OC_REST_PUT = (1 << 1),
481 OC_REST_POST = (1 << 2),
484 OC_REST_DELETE = (1 << 3),
486 /** Register observe request for most up date notifications ONLY.*/
487 OC_REST_OBSERVE = (1 << 4),
489 /** Register observe request for all notifications, including stale notifications.*/
490 OC_REST_OBSERVE_ALL = (1 << 5),
492 /** De-register observation, intended for internal use.*/
493 OC_REST_CANCEL_OBSERVE = (1 << 6),
496 /** Subscribe for all presence notifications of a particular resource.*/
497 OC_REST_PRESENCE = (1 << 7),
500 /** Allows OCDoResource caller to do discovery.*/
501 OC_REST_DISCOVER = (1 << 8)
505 * Host Mode of Operation.
515 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
516 * protocol. The precise definitions of each quality of service level depend on the
517 * implementation. In descriptions below are for the current implementation and may changed
522 /** Packet delivery is best effort.*/
525 /** Packet delivery is best effort.*/
528 /** Acknowledgments are used to confirm delivery.*/
531 /** No Quality is defined, let the stack decide.*/
533 } OCQualityOfService;
536 * Resource Properties.
537 * The value of a policy property is defined as bitmap.
538 * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
539 * Not including the policy property is equivalent to zero.
544 /** When none of the bits are set, the resource is non-discoverable &
545 * non-observable by the client.*/
546 OC_RES_PROP_NONE = (0),
548 /** When this bit is set, the resource is allowed to be discovered by clients.*/
549 OC_DISCOVERABLE = (1 << 0),
551 /** When this bit is set, the resource is allowed to be observed by clients.*/
552 OC_OBSERVABLE = (1 << 1),
554 /** When this bit is set, the resource is initialized, otherwise the resource
555 * is 'inactive'. 'inactive' signifies that the resource has been marked for
556 * deletion or is already deleted.*/
557 OC_ACTIVE = (1 << 2),
559 /** When this bit is set, the resource has been marked as 'slow'.
560 * 'slow' signifies that responses from this resource can expect delays in
561 * processing its requests from clients.*/
564 /** When this bit is set, the resource is a secure resource.*/
565 OC_SECURE = (1 << 4),
567 /** When this bit is set, the resource is allowed to be discovered only
568 * if discovery request contains an explicit querystring.
569 * Ex: GET /oic/res?rt=oic.sec.acl */
570 OC_EXPLICIT_DISCOVERABLE = (1 << 5)
571 } OCResourceProperty;
574 * Transport Protocol IDs.
578 /** For invalid ID.*/
579 OC_INVALID_ID = (1 << 0),
582 OC_COAP_ID = (1 << 1)
583 } OCTransportProtocolID;
586 * Declares Stack Results & Errors.
590 /** Success status code - START HERE.*/
592 OC_STACK_RESOURCE_CREATED,
593 OC_STACK_RESOURCE_DELETED,
595 /** Success status code - END HERE.*/
597 /** Error status code - START HERE.*/
598 OC_STACK_INVALID_URI = 20,
599 OC_STACK_INVALID_QUERY,
601 OC_STACK_INVALID_PORT,
602 OC_STACK_INVALID_CALLBACK,
603 OC_STACK_INVALID_METHOD,
605 /** Invalid parameter.*/
606 OC_STACK_INVALID_PARAM,
607 OC_STACK_INVALID_OBSERVE_PARAM,
611 OC_STACK_ADAPTER_NOT_ENABLED,
614 /** Resource not found.*/
615 OC_STACK_NO_RESOURCE,
617 /** e.g: not supported method or interface.*/
618 OC_STACK_RESOURCE_ERROR,
619 OC_STACK_SLOW_RESOURCE,
620 OC_STACK_DUPLICATE_REQUEST,
622 /** Resource has no registered observers.*/
623 OC_STACK_NO_OBSERVERS,
624 OC_STACK_OBSERVER_NOT_FOUND,
625 OC_STACK_VIRTUAL_DO_NOT_HANDLE,
626 OC_STACK_INVALID_OPTION,
628 /** The remote reply contained malformed data.*/
629 OC_STACK_MALFORMED_RESPONSE,
630 OC_STACK_PERSISTENT_BUFFER_REQUIRED,
631 OC_STACK_INVALID_REQUEST_HANDLE,
632 OC_STACK_INVALID_DEVICE_INFO,
633 OC_STACK_INVALID_JSON,
635 /** Request is not authorized by Resource Server. */
636 OC_STACK_UNAUTHORIZED_REQ,
638 /** Insert all new error codes here!.*/
640 OC_STACK_PRESENCE_STOPPED = 128,
641 OC_STACK_PRESENCE_TIMEOUT,
642 OC_STACK_PRESENCE_DO_NOT_HANDLE,
644 /** ERROR in stack.*/
646 /** Error status code - END HERE.*/
650 * Handle to an OCDoResource invocation.
652 typedef void * OCDoHandle;
655 * Handle to an OCResource object owned by the OCStack.
657 typedef void * OCResourceHandle;
660 * Handle to an OCRequest object owned by the OCStack.
662 typedef void * OCRequestHandle;
665 * Unique identifier for each observation request. Used when observations are
666 * registered or de-registered. Used by entity handler to signal specific
667 * observers to be notified of resource changes.
668 * There can be maximum of 256 observations per server.
670 typedef uint8_t OCObservationId;
673 * Action associated with observation.
678 OC_OBSERVE_REGISTER = 0,
680 /** To Deregister. */
681 OC_OBSERVE_DEREGISTER = 1,
684 OC_OBSERVE_NO_OPTION = 2
689 * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
690 * when it calls OCRegisterPersistentStorageHandler.
691 * Persistent storage open handler points to default file path.
692 * Application can point to appropriate SVR database path for it's IoTivity Server.
695 /** Persistent storage file path.*/
696 FILE* (* open)(const char *path, const char *mode);
698 /** Persistent storage read handler.*/
699 size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
701 /** Persistent storage write handler.*/
702 size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
704 /** Persistent storage close handler.*/
705 int (* close)(FILE *fp);
707 /** Persistent storage unlink handler.*/
708 int (* unlink)(const char *path);
709 } OCPersistentStorage;
712 * Possible returned values from entity handler.
716 /** Action associated with observation request.*/
717 OCObserveAction action;
719 /** Identifier for observation being registered/deregistered.*/
720 OCObservationId obsId;
724 * Possible returned values from entity handler.
730 OC_EH_RESOURCE_CREATED,
731 OC_EH_RESOURCE_DELETED,
734 OC_EH_RESOURCE_NOT_FOUND
735 } OCEntityHandlerResult;
738 * This structure will be used to define the vendor specific header options to be included
739 * in communication packets.
741 typedef struct OCHeaderOption
743 /** The protocol ID this option applies to.*/
744 OCTransportProtocolID protocolID;
746 /** The header option ID which will be added to communication packets.*/
749 /** its length 191.*/
750 uint16_t optionLength;
752 /** pointer to its data.*/
753 uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
755 #ifdef SUPPORTS_DEFAULT_CTOR
756 OCHeaderOption() = default;
757 OCHeaderOption(OCTransportProtocolID pid,
760 const uint8_t* optData)
766 // parameter includes the null terminator.
767 optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
768 optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
769 memcpy(optionData, optData, optionLength);
770 optionData[optionLength - 1] = '\0';
777 * This structure describes the platform properties. All non-Null properties will be
778 * included in a platform discovery request.
785 /** Manufacturer name.*/
786 char *manufacturerName;
788 /** Manufacturer URL for platform property.*/
789 char *manufacturerUrl;
794 /** Manufacturer date.*/
795 char *dateOfManufacture;
797 /** Platform version.*/
798 char *platformVersion;
800 /** Operating system version.*/
801 char *operatingSystemVersion;
804 char *hardwareVersion;
807 char *firmwareVersion;
809 /** Platform support URL.*/
818 * This structure is expected as input for device properties.
819 * device name is mandatory and expected from the application.
820 * device id of type UUID will be generated by the stack.
824 /** Pointer to the device name.*/
831 * CA Remote Access information for XMPP Client
836 char *hostname; /**< XMPP server hostname */
837 uint16_t port; /**< XMPP server serivce port */
838 char *xmpp_domain; /**< XMPP login domain */
839 char *username; /**< login username */
840 char *password; /**< login password */
841 char *resource; /**< specific resource for login */
842 char *user_jid; /**< specific JID for login */
844 #endif /* RA_ADAPTER */
847 /** Enum to describe the type of object held by the OCPayload object.*/
850 PAYLOAD_TYPE_INVALID,
851 PAYLOAD_TYPE_DISCOVERY,
853 PAYLOAD_TYPE_PLATFORM,
854 PAYLOAD_TYPE_REPRESENTATION,
855 PAYLOAD_TYPE_SECURITY,
856 PAYLOAD_TYPE_PRESENCE
861 // The type of message that was received
874 }OCRepPayloadPropType;
876 #define MAX_REP_ARRAY_DEPTH 3
879 OCRepPayloadPropType type;
880 size_t dimensions[MAX_REP_ARRAY_DEPTH];
888 struct OCRepPayload** objArray;
890 } OCRepPayloadValueArray;
892 typedef struct OCRepPayloadValue
895 OCRepPayloadPropType type;
902 struct OCRepPayload* obj;
903 OCRepPayloadValueArray arr;
905 struct OCRepPayloadValue* next;
909 typedef struct OCStringLL
911 struct OCStringLL *next;
915 // used for get/set/put/observe/etc representations
916 typedef struct OCRepPayload
921 OCStringLL* interfaces;
922 OCRepPayloadValue* values;
923 struct OCRepPayload* next;
926 // used inside a discovery payload
927 typedef struct OCResourcePayload
932 OCStringLL* interfaces;
936 struct OCResourcePayload* next;
942 OCResourcePayload* resources;
943 } OCDiscoveryPayload;
952 char* dataModelVersion;
971 uint32_t sequenceNumber;
973 OCPresenceTrigger trigger;
979 * Incoming requests handled by the server. Requests are passed in as a parameter to the
980 * OCEntityHandler callback API.
981 * The OCEntityHandler callback API must be implemented in the application in order
982 * to receive these requests.
986 /** Associated resource.*/
987 OCResourceHandle resource;
989 /** Associated request handle.*/
990 OCRequestHandle requestHandle;
992 /** the REST method retrieved from received request PDU.*/
995 /** description of endpoint that sent the request.*/
998 /** resource query send by client.*/
1001 /** Information associated with observation - valid only when OCEntityHandler flag includes
1002 * ::OC_OBSERVE_FLAG.*/
1003 OCObservationInfo obsInfo;
1005 /** Number of the received vendor specific header options.*/
1006 uint8_t numRcvdVendorSpecificHeaderOptions;
1008 /** Pointer to the array of the received vendor specific header options.*/
1009 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1011 /** the payload from the request PDU.*/
1015 } OCEntityHandlerRequest;
1019 * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1023 /** Address of remote server.*/
1026 /** backward compatibility (points to devAddr).*/
1029 /** backward compatibility.*/
1030 OCConnectivityType connType;
1032 /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1033 OCStackResult result;
1035 /** If associated with observe, this will represent the sequence of notifications from server.*/
1036 uint32_t sequenceNumber;
1039 const char * resourceUri;
1041 /** the payload for the response PDU.*/
1044 /** Number of the received vendor specific header options.*/
1045 uint8_t numRcvdVendorSpecificHeaderOptions;
1047 /** An array of the received vendor specific header options.*/
1048 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1052 * Request handle is passed to server via the entity handler for each incoming request.
1053 * Stack assigns when request is received, server sets to indicate what request response is for.
1057 /** Request handle.*/
1058 OCRequestHandle requestHandle;
1060 /** Resource handle.*/
1061 OCResourceHandle resourceHandle;
1063 /** Allow the entity handler to pass a result with the response.*/
1064 OCEntityHandlerResult ehResult;
1066 /** This is the pointer to server payload data to be transferred.*/
1069 /** number of the vendor specific header options .*/
1070 uint8_t numSendVendorSpecificHeaderOptions;
1072 /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1073 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1075 /** URI of new resource that entity handler might create.*/
1076 char resourceUri[MAX_URI_LENGTH];
1078 /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1079 uint8_t persistentBufferFlag;
1080 } OCEntityHandlerResponse;
1087 /** Request state.*/
1088 OC_REQUEST_FLAG = (1 << 1),
1089 /** Observe state.*/
1090 OC_OBSERVE_FLAG = (1 << 2)
1091 } OCEntityHandlerFlag;
1094 * Possible returned values from client application.
1098 OC_STACK_DELETE_TRANSACTION = 0,
1099 OC_STACK_KEEP_TRANSACTION
1100 } OCStackApplicationResult;
1104 * -------------------------------------------------------------------------------------------
1105 * Callback function definitions
1106 * -------------------------------------------------------------------------------------------
1110 * Client applications implement this callback to consume responses received from Servers.
1112 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1113 OCClientResponse * clientResponse);
1116 * Client applications using a context pointer implement this callback to delete the
1117 * context upon removal of the callback/context pointer from the internal callback-list.
1119 typedef void (* OCClientContextDeleter)(void *context);
1122 * This info is passed from application to OC Stack when initiating a request to Server.
1124 typedef struct OCCallbackData
1126 /** Pointer to the context.*/
1129 /** The pointer to a function the stack will call to handle the requests.*/
1130 OCClientResponseHandler cb;
1132 /** A pointer to a function to delete the context when this callback is removed.*/
1133 OCClientContextDeleter cd;
1135 #ifdef SUPPORTS_DEFAULT_CTOR
1136 OCCallbackData() = default;
1137 OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1138 :context(ctx), cb(callback), cd(deleter){}
1143 * Application server implementations must implement this callback to consume requests OTA.
1144 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1146 typedef OCEntityHandlerResult (*OCEntityHandler)
1147 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1150 * Device Entity handler need to use this call back instead of OCEntityHandler.
1152 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1153 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1157 #endif // __cplusplus
1159 #endif /* OCTYPES_H_ */