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 "ocstackconfig.h"
41 /** For the feature presence.*/
44 #include "ocpresence.h"
45 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
50 * OIC Virtual resources supported by every OIC device.
53 * Default discovery mechanism using '/oic/res' is supported by all OIC devices
54 * That are Discoverable.
56 #define OC_RSRVD_WELL_KNOWN_URI "/oic/res"
59 #define OC_RSRVD_DEVICE_URI "/oic/d"
62 #define OC_RSRVD_PLATFORM_URI "/oic/p"
65 #define OC_RSRVD_RESOURCE_TYPES_URI "/oic/res/types/d"
69 /** Presence URI through which the OIC devices advertise their presence.*/
70 #define OC_RSRVD_PRESENCE_URI "/oic/ad"
72 /** Sets the default time to live (TTL) for presence.*/
73 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
75 /** For multicast Discovery mechanism.*/
76 #define OC_MULTICAST_DISCOVERY_URI "/oic/res"
78 /** Separator for multiple query string.*/
79 #define OC_QUERY_SEPARATOR "&;"
82 * OC_DEFAULT_PRESENCE_TTL_SECONDS sets the default time to live (TTL) for presence.
84 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
87 * OC_MAX_PRESENCE_TTL_SECONDS sets the maximum time to live (TTL) for presence.
88 * NOTE: Changing the setting to a longer duration may lead to unsupported and untested
90 * 60 sec/min * 60 min/hr * 24 hr/day
92 #define OC_MAX_PRESENCE_TTL_SECONDS (60 * 60 * 24)
96 * Presence "Announcement Triggers".
100 #define OC_RSRVD_TRIGGER_CREATE "create"
103 #define OC_RSRVD_TRIGGER_CHANGE "change"
106 #define OC_RSRVD_TRIGGER_DELETE "delete"
109 * Attributes used to form a proper OIC conforming JSON message.
112 #define OC_RSRVD_OC "oic"
116 #define OC_RSRVD_PAYLOAD "payload"
118 /** To represent href */
119 #define OC_RSRVD_HREF "href"
121 /** To represent property*/
122 #define OC_RSRVD_PROPERTY "prop"
124 /** For representation.*/
125 #define OC_RSRVD_REPRESENTATION "rep"
127 /** To represent content type.*/
128 #define OC_RSRVD_CONTENT_TYPE "ct"
130 /** To represent resource type.*/
131 #define OC_RSRVD_RESOURCE_TYPE "rt"
133 /** To represent resource type with presence.*/
134 #define OC_RSRVD_RESOURCE_TYPE_PRESENCE "oic.wk.ad"
136 /** To represent interface.*/
137 #define OC_RSRVD_INTERFACE "if"
139 /** To represent time to live.*/
140 #define OC_RSRVD_TTL "ttl"
142 /** To represent non*/
143 #define OC_RSRVD_NONCE "non"
145 /** To represent trigger type.*/
146 #define OC_RSRVD_TRIGGER "trg"
148 /** To represent links.*/
149 #define OC_RSRVD_LINKS "links"
151 /** To represent default interface.*/
152 #define OC_RSRVD_INTERFACE_DEFAULT "oic.if.baseline"
154 /** To represent ll interface.*/
155 #define OC_RSRVD_INTERFACE_LL "oic.if.ll"
157 /** To represent batch interface.*/
158 #define OC_RSRVD_INTERFACE_BATCH "oic.if.b"
160 /** To represent interface group.*/
161 #define OC_RSRVD_INTERFACE_GROUP "oic.mi.grp"
163 /** To represent MFG date.*/
164 #define OC_RSRVD_MFG_DATE "mndt"
166 /** To represent FW version.*/
167 #define OC_RSRVD_FW_VERSION "mnfv"
169 /** To represent host name.*/
170 #define OC_RSRVD_HOST_NAME "hn"
172 /** To represent version.*/
173 #define OC_RSRVD_VERSION "icv"
175 /** To represent policy.*/
176 #define OC_RSRVD_POLICY "p"
178 /** To represent bitmap.*/
179 #define OC_RSRVD_BITMAP "bm"
182 #define OC_RSRVD_SECURE "sec"
185 #define OC_RSRVD_HOSTING_PORT "port"
187 /** For Server instance ID.*/
188 #define OC_RSRVD_SERVER_INSTANCE_ID "sid"
195 #define OC_RSRVD_PLATFORM_ID "pi"
197 /** Platform MFG NAME. */
198 #define OC_RSRVD_MFG_NAME "mnmn"
201 #define OC_RSRVD_MFG_URL "mnml"
204 #define OC_RSRVD_MODEL_NUM "mnmo"
206 /** Platform MFG Date.*/
207 #define OC_RSRVD_MFG_DATE "mndt"
209 /** Platform versio.n */
210 #define OC_RSRVD_PLATFORM_VERSION "mnpv"
212 /** Platform Operating system version. */
213 #define OC_RSRVD_OS_VERSION "mnos"
215 /** Platform Hardware version. */
216 #define OC_RSRVD_HARDWARE_VERSION "mnhw"
218 /**Platform Firmware version. */
219 #define OC_RSRVD_FIRMWARE_VERSION "mnfv"
221 /** Support URL for the platform. */
222 #define OC_RSRVD_SUPPORT_URL "mnsl"
224 /** System time for the platform. */
225 #define OC_RSRVD_SYSTEM_TIME "st"
232 #define OC_RSRVD_DEVICE_ID "di"
235 #define OC_RSRVD_DEVICE_NAME "n"
237 /** Device specification version.*/
238 #define OC_RSRVD_SPEC_VERSION "lcv"
240 /** Device data model.*/
241 #define OC_RSRVD_DATA_MODEL_VERSION "dmv"
243 /** Device specification version.*/
244 #define OC_SPEC_VERSION "0.9.0"
246 /** Device Data Model version.*/
247 #define OC_DATA_MODEL_VERSION "sec.0.95"
250 * These provide backward compatibility - their use is deprecated.
254 /** Multicast Prefix.*/
255 #define OC_MULTICAST_PREFIX "224.0.1.187:5683"
257 /** Multicast IP address.*/
258 #define OC_MULTICAST_IP "224.0.1.187"
260 /** Multicast Port.*/
261 #define OC_MULTICAST_PORT 5683
264 /** Max Device address size. */
266 #define MAX_ADDR_STR_SIZE (256)
268 #define MAX_ADDR_STR_SIZE (40)
271 /** Max identity size. */
272 #define MAX_IDENTITY_SIZE (32)
275 * These enums (OCTransportAdapter and OCTransportFlags) must
276 * be kept synchronized with OCConnectivityType (below) as well as
277 * CATransportAdapter and CATransportFlags (in CACommon.h).
281 /** value zero indicates discovery.*/
282 OC_DEFAULT_ADAPTER = 0,
284 /** IPv4 and IPv6, including 6LoWPAN.*/
285 OC_ADAPTER_IP = (1 << 0),
287 /** GATT over Bluetooth LE.*/
288 OC_ADAPTER_GATT_BTLE = (1 << 1),
290 /** RFCOMM over Bluetooth EDR.*/
291 OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
294 /**Remote Access over XMPP.*/
295 OC_ADAPTER_REMOTE_ACCESS = (1 << 3)
298 } OCTransportAdapter;
301 * Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
305 /** default flag is 0*/
306 OC_DEFAULT_FLAGS = 0,
308 /** Insecure transport is the default (subject to change).*/
309 /** secure the transport path*/
310 OC_FLAG_SECURE = (1 << 4),
312 /** IPv4 & IPv6 auto-selection is the default.*/
313 /** IP adapter only.*/
314 OC_IP_USE_V6 = (1 << 5),
316 /** IP adapter only.*/
317 OC_IP_USE_V4 = (1 << 6),
319 /** internal use only.*/
320 OC_RESERVED1 = (1 << 7), // internal use only
322 /** Link-Local multicast is the default multicast scope for IPv6.
323 * These are placed here to correspond to the IPv6 multicast address bits.*/
325 /** IPv6 Interface-Local scope (loopback).*/
326 OC_SCOPE_INTERFACE = 0x1,
328 /** IPv6 Link-Local scope (default).*/
331 /** IPv6 Realm-Local scope. */
332 OC_SCOPE_REALM = 0x3,
334 /** IPv6 Admin-Local scope. */
335 OC_SCOPE_ADMIN = 0x4,
337 /** IPv6 Site-Local scope. */
340 /** IPv6 Organization-Local scope. */
343 /**IPv6 Global scope. */
344 OC_SCOPE_GLOBAL = 0xE,
348 /** Bit mask for scope.*/
349 #define OC_MASK_SCOPE (0x000F)
351 /** Bit mask for Mods.*/
352 #define OC_MASK_MODS (0x0FF0)
353 #define OC_MASK_FAMS (OC_IP_USE_V6|OC_IP_USE_V4)
356 * End point identity.
360 /** Identity Length */
363 /** Array of end point identity.*/
364 unsigned char id[MAX_IDENTITY_SIZE];
368 * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
369 * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
374 OCTransportAdapter adapter;
376 /** transport modifiers.*/
377 OCTransportFlags flags;
379 /** address for all adapters.*/
380 char addr[MAX_ADDR_STR_SIZE];
382 /** usually zero for default interface.*/
388 /** secure node identity.*/
393 * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
394 * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
395 * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
398 * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
402 /** use when defaults are ok. */
406 #if defined (__UINT32_MAX__) && (__UINT32_MAX__ == 65535)
408 /** IPv4 and IPv6, including 6LoWPAN.*/
409 CT_ADAPTER_IP = (1 << 10),
411 /** GATT over Bluetooth LE.*/
412 CT_ADAPTER_GATT_BTLE = (1 << 11),
414 /** RFCOMM over Bluetooth EDR.*/
415 CT_ADAPTER_RFCOMM_BTEDR = (1 << 12),
417 /** assume 32-bit int. */
420 /** IPv4 and IPv6, including 6LoWPAN.*/
421 CT_ADAPTER_IP = (1 << 16),
423 /** GATT over Bluetooth LE.*/
424 CT_ADAPTER_GATT_BTLE = (1 << 17),
426 /** RFCOMM over Bluetooth EDR.*/
427 CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
430 /** Remote Access over XMPP.*/
431 CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
434 /** bit shift required for connectivity adapter.*/
435 #define CT_ADAPTER_SHIFT 10
438 #define CT_MASK_FLAGS 0x03FF
441 #define CT_MASK_ADAPTER 0xFC00
445 /** Insecure transport is the default (subject to change).*/
447 /** secure the transport path.*/
448 CT_FLAG_SECURE = (1 << 4),
450 /** IPv4 & IPv6 autoselection is the default.*/
452 /** IP adapter only.*/
453 CT_IP_USE_V6 = (1 << 5),
455 /** IP adapter only.*/
456 CT_IP_USE_V4 = (1 << 6),
458 /** Link-Local multicast is the default multicast scope for IPv6.
459 * These are placed here to correspond to the IPv6 address bits.*/
461 /** IPv6 Interface-Local scope(loopback).*/
462 CT_SCOPE_INTERFACE = 0x1,
464 /** IPv6 Link-Local scope (default).*/
467 /** IPv6 Realm-Local scope.*/
468 CT_SCOPE_REALM = 0x3,
470 /** IPv6 Admin-Local scope.*/
471 CT_SCOPE_ADMIN = 0x4,
473 /** IPv6 Site-Local scope.*/
476 /** IPv6 Organization-Local scope.*/
479 /** IPv6 Global scope.*/
480 CT_SCOPE_GLOBAL = 0xE,
481 } OCConnectivityType;
484 * OCDoResource methods to dispatch the request
488 OC_REST_NOMETHOD = 0,
491 OC_REST_GET = (1 << 0),
494 OC_REST_PUT = (1 << 1),
497 OC_REST_POST = (1 << 2),
500 OC_REST_DELETE = (1 << 3),
502 /** Register observe request for most up date notifications ONLY.*/
503 OC_REST_OBSERVE = (1 << 4),
505 /** Register observe request for all notifications, including stale notifications.*/
506 OC_REST_OBSERVE_ALL = (1 << 5),
508 /** De-register observation, intended for internal use.*/
509 OC_REST_CANCEL_OBSERVE = (1 << 6),
512 /** Subscribe for all presence notifications of a particular resource.*/
513 OC_REST_PRESENCE = (1 << 7),
516 /** Allows OCDoResource caller to do discovery.*/
517 OC_REST_DISCOVER = (1 << 8)
521 * Host Mode of Operation.
531 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
532 * protocol. The precise definitions of each quality of service level depend on the
533 * implementation. In descriptions below are for the current implementation and may changed
538 /** Packet delivery is best effort.*/
541 /** Packet delivery is best effort.*/
544 /** Acknowledgments are used to confirm delivery.*/
547 /** No Quality is defined, let the stack decide.*/
549 } OCQualityOfService;
552 * Resource Properties.
553 * The value of a policy property is defined as bitmap.
554 * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
555 * Not including the policy property is equivalent to zero.
557 * ::OC_RES_PROP_NONE When none of the bits are set, the resource is non-discoverable &
558 * non-observable by the client.
559 * ::OC_DISCOVERABLE When this bit is set, the resource is allowed to be discovered by clients.
560 * ::OC_OBSERVABLE When this bit is set, the resource is allowed to be observed by clients.
565 /** When none of the bits are set, the resource is non-discoverable &
566 * non-observable by the client.*/
567 OC_RES_PROP_NONE = (0),
569 /** When this bit is set, the resource is allowed to be discovered by clients.*/
570 OC_DISCOVERABLE = (1 << 0),
572 /** When this bit is set, the resource is allowed to be observed by clients.*/
573 OC_OBSERVABLE = (1 << 1),
575 /** When this bit is set, the resource is initialized, otherwise the resource
576 * is 'inactive'. 'inactive' signifies that the resource has been marked for
577 * deletion or is already deleted.*/
578 OC_ACTIVE = (1 << 2),
580 /** When this bit is set, the resource has been marked as 'slow'.
581 * 'slow' signifies that responses from this resource can expect delays in
582 * processing its requests from clients.*/
585 /** When this bit is set, the resource is a secure resource.*/
587 } OCResourceProperty;
590 * Transport Protocol IDs.
594 /** For invalid ID.*/
595 OC_INVALID_ID = (1 << 0),
598 OC_COAP_ID = (1 << 1)
599 } OCTransportProtocolID;
602 * Declares Stack Results & Errors.
606 /** Success status code - START HERE.*/
608 OC_STACK_RESOURCE_CREATED,
609 OC_STACK_RESOURCE_DELETED,
611 /** Success status code - END HERE.*/
613 /** Error status code - START HERE.*/
614 OC_STACK_INVALID_URI = 20,
615 OC_STACK_INVALID_QUERY,
617 OC_STACK_INVALID_PORT,
618 OC_STACK_INVALID_CALLBACK,
619 OC_STACK_INVALID_METHOD,
621 /** Invalid parameter.*/
622 OC_STACK_INVALID_PARAM,
623 OC_STACK_INVALID_OBSERVE_PARAM,
627 OC_STACK_ADAPTER_NOT_ENABLED,
630 /** Resource not found.*/
631 OC_STACK_NO_RESOURCE,
633 /** e.g: not supported method or interface.*/
634 OC_STACK_RESOURCE_ERROR,
635 OC_STACK_SLOW_RESOURCE,
636 OC_STACK_DUPLICATE_REQUEST,
638 /** Resource has no registered observers.*/
639 OC_STACK_NO_OBSERVERS,
640 OC_STACK_OBSERVER_NOT_FOUND,
641 OC_STACK_VIRTUAL_DO_NOT_HANDLE,
642 OC_STACK_INVALID_OPTION,
644 /** The remote reply contained malformed data.*/
645 OC_STACK_MALFORMED_RESPONSE,
646 OC_STACK_PERSISTENT_BUFFER_REQUIRED,
647 OC_STACK_INVALID_REQUEST_HANDLE,
648 OC_STACK_INVALID_DEVICE_INFO,
649 OC_STACK_INVALID_JSON,
651 /** Request is not authorized by Resource Server. */
652 OC_STACK_UNAUTHORIZED_REQ,
654 /** Insert all new error codes here!.*/
656 OC_STACK_PRESENCE_STOPPED = 128,
657 OC_STACK_PRESENCE_TIMEOUT,
658 OC_STACK_PRESENCE_DO_NOT_HANDLE,
660 /** ERROR in stack.*/
662 /** Error status code - END HERE.*/
666 * Handle to an OCDoResource invocation.
668 typedef void * OCDoHandle;
671 * Handle to an OCResource object owned by the OCStack.
673 typedef void * OCResourceHandle;
676 * Handle to an OCRequest object owned by the OCStack.
678 typedef void * OCRequestHandle;
681 * Unique identifier for each observation request. Used when observations are
682 * registered or de-registered. Used by entity handler to signal specific
683 * observers to be notified of resource changes.
684 * There can be maximum of 256 observations per server.
686 typedef uint8_t OCObservationId;
689 * Action associated with observation.
694 OC_OBSERVE_REGISTER = 0,
696 /** To Deregister. */
697 OC_OBSERVE_DEREGISTER = 1,
700 OC_OBSERVE_NO_OPTION = 2
705 * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
706 * when it calls OCRegisterPersistentStorageHandler.
707 * Persistent storage open handler points to default file path.
708 * Application can point to appropriate SVR database path for it's IoTivity Server.
711 /** Persistent storage file path.*/
712 FILE* (* open)(const char *path, const char *mode);
714 /** Persistent storage read handler.*/
715 size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
717 /** Persistent storage write handler.*/
718 size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
720 /** Persistent storage close handler.*/
721 int (* close)(FILE *fp);
723 /** Persistent storage unlink handler.*/
724 int (* unlink)(const char *path);
725 } OCPersistentStorage;
728 * Possible returned values from entity handler.
732 /** Action associated with observation request.*/
733 OCObserveAction action;
735 /** Identifier for observation being registered/deregistered.*/
736 OCObservationId obsId;
740 * Possible returned values from entity handler.
746 OC_EH_RESOURCE_CREATED,
747 OC_EH_RESOURCE_DELETED,
750 OC_EH_RESOURCE_NOT_FOUND
751 } OCEntityHandlerResult;
754 * This structure will be used to define the vendor specific header options to be included
755 * in communication packets.
757 typedef struct OCHeaderOption
759 /** The protocol ID this option applies to.*/
760 OCTransportProtocolID protocolID;
762 /** The header option ID which will be added to communication packets.*/
765 /** its length 191.*/
766 uint16_t optionLength;
768 /** pointer to its data.*/
769 uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
772 OCHeaderOption() = default;
773 OCHeaderOption(OCTransportProtocolID pid,
776 const uint8_t* optData)
782 // parameter includes the null terminator.
783 optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
784 optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
785 memcpy(optionData, optData, optionLength);
786 optionData[optionLength - 1] = '\0';
793 * This structure describes the platform properties. All non-Null properties will be
794 * included in a platform discovery request.
801 /** Manufacturer name.*/
802 char *manufacturerName;
804 /** Manufacturer URL for platform property.*/
805 char *manufacturerUrl;
810 /** Manufacturer date.*/
811 char *dateOfManufacture;
813 /** Platform version.*/
814 char *platformVersion;
816 /** Operating system version.*/
817 char *operatingSystemVersion;
820 char *hardwareVersion;
823 char *firmwareVersion;
825 /** Platform support URL.*/
834 * This structure is expected as input for device properties.
835 * device name is mandatory and expected from the application.
836 * device id of type UUID will be generated by the stack.
840 /** Pointer to the device name.*/
847 * CA Remote Access information for XMPP Client
852 char *hostname; /**< XMPP server hostname */
853 uint16_t port; /**< XMPP server serivce port */
854 char *xmpp_domain; /**< XMPP login domain */
855 char *username; /**< login username */
856 char *password; /**< login password */
857 char *resource; /**< specific resource for login */
858 char *user_jid; /**< specific JID for login */
860 #endif /* RA_ADAPTER */
863 /** Enum to describe the type of object held by the OCPayload object.*/
866 PAYLOAD_TYPE_INVALID,
867 PAYLOAD_TYPE_DISCOVERY,
869 PAYLOAD_TYPE_PLATFORM,
870 PAYLOAD_TYPE_REPRESENTATION,
871 PAYLOAD_TYPE_SECURITY,
872 PAYLOAD_TYPE_PRESENCE
877 // The type of message that was received
890 }OCRepPayloadPropType;
892 #define MAX_REP_ARRAY_DEPTH 3
895 OCRepPayloadPropType type;
896 size_t dimensions[MAX_REP_ARRAY_DEPTH];
904 struct OCRepPayload** objArray;
906 } OCRepPayloadValueArray;
908 typedef struct OCRepPayloadValue
911 OCRepPayloadPropType type;
918 struct OCRepPayload* obj;
919 OCRepPayloadValueArray arr;
921 struct OCRepPayloadValue* next;
925 typedef struct OCStringLL
927 struct OCStringLL *next;
931 // used for get/set/put/observe/etc representations
932 typedef struct OCRepPayload
937 OCStringLL* interfaces;
938 OCRepPayloadValue* values;
939 struct OCRepPayload* next;
942 // used inside a discovery payload
943 typedef struct OCResourcePayload
948 OCStringLL* interfaces;
952 struct OCResourcePayload* next;
958 OCResourcePayload* resources;
959 } OCDiscoveryPayload;
968 char* dataModelVersion;
987 uint32_t sequenceNumber;
989 OCPresenceTrigger trigger;
995 * Incoming requests handled by the server. Requests are passed in as a parameter to the
996 * OCEntityHandler callback API.
997 * The OCEntityHandler callback API must be implemented in the application in order
998 * to receive these requests.
1002 /** Associated resource.*/
1003 OCResourceHandle resource;
1005 /** Associated request handle.*/
1006 OCRequestHandle requestHandle;
1008 /** the REST method retrieved from received request PDU.*/
1011 /** description of endpoint that sent the request.*/
1014 /** resource query send by client.*/
1017 /** Information associated with observation - valid only when OCEntityHandler flag includes
1018 * ::OC_OBSERVE_FLAG.*/
1019 OCObservationInfo obsInfo;
1021 /** Number of the received vendor specific header options.*/
1022 uint8_t numRcvdVendorSpecificHeaderOptions;
1024 /** Pointer to the array of the received vendor specific header options.*/
1025 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1027 /** the payload from the request PDU.*/
1031 } OCEntityHandlerRequest;
1035 * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1039 /** Address of remote server.*/
1042 /** backward compatibility (points to devAddr).*/
1045 /** backward compatibility.*/
1046 OCConnectivityType connType;
1048 /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1049 OCStackResult result;
1051 /** If associated with observe, this will represent the sequence of notifications from server.*/
1052 uint32_t sequenceNumber;
1055 const char * resourceUri;
1057 /** the payload for the response PDU.*/
1060 /** Number of the received vendor specific header options.*/
1061 uint8_t numRcvdVendorSpecificHeaderOptions;
1063 /** An array of the received vendor specific header options.*/
1064 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1068 * Request handle is passed to server via the entity handler for each incoming request.
1069 * Stack assigns when request is received, server sets to indicate what request response is for.
1073 /** Request handle.*/
1074 OCRequestHandle requestHandle;
1076 /** Resource handle.*/
1077 OCResourceHandle resourceHandle;
1079 /** Allow the entity handler to pass a result with the response.*/
1080 OCEntityHandlerResult ehResult;
1082 /** This is the pointer to server payload data to be transferred.*/
1085 /** number of the vendor specific header options .*/
1086 uint8_t numSendVendorSpecificHeaderOptions;
1088 /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1089 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1091 /** URI of new resource that entity handler might create.*/
1092 char resourceUri[MAX_URI_LENGTH];
1094 /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1095 uint8_t persistentBufferFlag;
1096 } OCEntityHandlerResponse;
1103 /** Request state.*/
1104 OC_REQUEST_FLAG = (1 << 1),
1105 /** Observe state.*/
1106 OC_OBSERVE_FLAG = (1 << 2)
1107 } OCEntityHandlerFlag;
1110 * Possible returned values from client application.
1114 OC_STACK_DELETE_TRANSACTION = 0,
1115 OC_STACK_KEEP_TRANSACTION
1116 } OCStackApplicationResult;
1120 * -------------------------------------------------------------------------------------------
1121 * Callback function definitions
1122 * -------------------------------------------------------------------------------------------
1126 * Client applications implement this callback to consume responses received from Servers.
1128 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1129 OCClientResponse * clientResponse);
1132 * Client applications using a context pointer implement this callback to delete the
1133 * context upon removal of the callback/context pointer from the internal callback-list.
1135 typedef void (* OCClientContextDeleter)(void *context);
1138 * This info is passed from application to OC Stack when initiating a request to Server.
1140 typedef struct OCCallbackData
1142 /** Pointer to the context.*/
1145 /** The pointer to a function the stack will call to handle the requests.*/
1146 OCClientResponseHandler cb;
1148 /** A pointer to a function to delete the context when this callback is removed.*/
1149 OCClientContextDeleter cd;
1152 OCCallbackData() = default;
1153 OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1154 :context(ctx), cb(callback), cd(deleter){}
1159 * Application server implementations must implement this callback to consume requests OTA.
1160 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1162 typedef OCEntityHandlerResult (*OCEntityHandler)
1163 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1166 * Device Entity handler need to use this call back instead of OCEntityHandler.
1168 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1169 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1173 #endif // __cplusplus
1175 #endif /* OCTYPES_H_ */