1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //******************************************************************
25 * This file contains the definition, types and APIs for resource(s) be implemented.
31 #include "platform_features.h"
32 #include "ocstackconfig.h"
42 /** For the feature presence.*/
45 #include "ocpresence.h"
46 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
51 * OIC Virtual resources supported by every OIC device.
54 * Default discovery mechanism using '/oic/res' is supported by all OIC devices
55 * That are Discoverable.
57 #define OC_RSRVD_WELL_KNOWN_URI "/oic/res"
60 #define OC_RSRVD_DEVICE_URI "/oic/d"
63 #define OC_RSRVD_PLATFORM_URI "/oic/p"
66 #define OC_RSRVD_RESOURCE_TYPES_URI "/oic/res/types/d"
67 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
69 #define OC_RSRVD_GATEWAY_URI "/oic/gateway"
73 /** Presence URI through which the OIC devices advertise their presence.*/
74 #define OC_RSRVD_PRESENCE_URI "/oic/ad"
76 /** Sets the default time to live (TTL) for presence.*/
77 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
79 /** For multicast Discovery mechanism.*/
80 #define OC_MULTICAST_DISCOVERY_URI "/oic/res"
82 /** Separator for multiple query string.*/
83 #define OC_QUERY_SEPARATOR "&;"
86 * OC_DEFAULT_PRESENCE_TTL_SECONDS sets the default time to live (TTL) for presence.
88 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
91 * OC_MAX_PRESENCE_TTL_SECONDS sets the maximum time to live (TTL) for presence.
92 * NOTE: Changing the setting to a longer duration may lead to unsupported and untested
94 * 60 sec/min * 60 min/hr * 24 hr/day
96 #define OC_MAX_PRESENCE_TTL_SECONDS (60 * 60 * 24)
100 * Presence "Announcement Triggers".
104 #define OC_RSRVD_TRIGGER_CREATE "create"
107 #define OC_RSRVD_TRIGGER_CHANGE "change"
110 #define OC_RSRVD_TRIGGER_DELETE "delete"
113 * Attributes used to form a proper OIC conforming JSON message.
116 #define OC_RSRVD_OC "oic"
120 #define OC_RSRVD_PAYLOAD "payload"
122 /** To represent href */
123 #define OC_RSRVD_HREF "href"
125 /** To represent property*/
126 #define OC_RSRVD_PROPERTY "prop"
128 /** For representation.*/
129 #define OC_RSRVD_REPRESENTATION "rep"
131 /** To represent content type.*/
132 #define OC_RSRVD_CONTENT_TYPE "ct"
134 /** To represent resource type.*/
135 #define OC_RSRVD_RESOURCE_TYPE "rt"
137 /** To represent resource type with presence.*/
138 #define OC_RSRVD_RESOURCE_TYPE_PRESENCE "oic.wk.ad"
140 /** To represent resource type with device.*/
141 #define OC_RSRVD_RESOURCE_TYPE_DEVICE "oic.wk.d"
143 /** To represent resource type with platform.*/
144 #define OC_RSRVD_RESOURCE_TYPE_PLATFORM "oic.wk.p"
146 /** To represent resource type with RES.*/
147 #define OC_RSRVD_RESOURCE_TYPE_RES "oic.wk.res"
149 /** To represent interface.*/
150 #define OC_RSRVD_INTERFACE "if"
152 /** To represent time to live.*/
153 #define OC_RSRVD_TTL "ttl"
155 /** To represent non*/
156 #define OC_RSRVD_NONCE "non"
158 /** To represent trigger type.*/
159 #define OC_RSRVD_TRIGGER "trg"
161 /** To represent links.*/
162 #define OC_RSRVD_LINKS "links"
164 /** To represent default interface.*/
165 #define OC_RSRVD_INTERFACE_DEFAULT "oic.if.baseline"
167 /** To represent read-only interface.*/
168 #define OC_RSRVD_INTERFACE_READ "oic.if.r"
170 /** To represent ll interface.*/
171 #define OC_RSRVD_INTERFACE_LL "oic.if.ll"
173 /** To represent batch interface.*/
174 #define OC_RSRVD_INTERFACE_BATCH "oic.if.b"
176 /** To represent interface group.*/
177 #define OC_RSRVD_INTERFACE_GROUP "oic.mi.grp"
179 /** To represent MFG date.*/
180 #define OC_RSRVD_MFG_DATE "mndt"
182 /** To represent FW version.*/
183 #define OC_RSRVD_FW_VERSION "mnfv"
185 /** To represent host name.*/
186 #define OC_RSRVD_HOST_NAME "hn"
188 /** To represent policy.*/
189 #define OC_RSRVD_POLICY "p"
191 /** To represent bitmap.*/
192 #define OC_RSRVD_BITMAP "bm"
195 #define OC_RSRVD_SECURE "sec"
198 #define OC_RSRVD_HOSTING_PORT "port"
201 #define OC_RSRVD_TCP_PORT "tcp"
203 /** For Server instance ID.*/
204 #define OC_RSRVD_SERVER_INSTANCE_ID "sid"
211 #define OC_RSRVD_PLATFORM_ID "pi"
213 /** Platform MFG NAME. */
214 #define OC_RSRVD_MFG_NAME "mnmn"
217 #define OC_RSRVD_MFG_URL "mnml"
220 #define OC_RSRVD_MODEL_NUM "mnmo"
222 /** Platform MFG Date.*/
223 #define OC_RSRVD_MFG_DATE "mndt"
225 /** Platform versio.n */
226 #define OC_RSRVD_PLATFORM_VERSION "mnpv"
228 /** Platform Operating system version. */
229 #define OC_RSRVD_OS_VERSION "mnos"
231 /** Platform Hardware version. */
232 #define OC_RSRVD_HARDWARE_VERSION "mnhw"
234 /**Platform Firmware version. */
235 #define OC_RSRVD_FIRMWARE_VERSION "mnfv"
237 /** Support URL for the platform. */
238 #define OC_RSRVD_SUPPORT_URL "mnsl"
240 /** System time for the platform. */
241 #define OC_RSRVD_SYSTEM_TIME "st"
248 #define OC_RSRVD_DEVICE_ID "di"
251 #define OC_RSRVD_DEVICE_NAME "n"
253 /** Device specification version.*/
254 #define OC_RSRVD_SPEC_VERSION "icv"
256 /** Device data model.*/
257 #define OC_RSRVD_DATA_MODEL_VERSION "dmv"
259 /** Device specification version.*/
260 #define OC_SPEC_VERSION "core.1.0.0"
262 /** Device Data Model version.*/
263 #define OC_DATA_MODEL_VERSION "res.1.0.0"
266 * These provide backward compatibility - their use is deprecated.
270 /** Multicast Prefix.*/
271 #define OC_MULTICAST_PREFIX "224.0.1.187:5683"
273 /** Multicast IP address.*/
274 #define OC_MULTICAST_IP "224.0.1.187"
276 /** Multicast Port.*/
277 #define OC_MULTICAST_PORT 5683
280 /** Max Device address size. */
282 #define MAX_ADDR_STR_SIZE (256)
284 /** Max Address could be
285 * "coap+tcp://[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:yyy.yyy.yyy.yyy]:xxxxx"
286 * +1 for null terminator.
288 #define MAX_ADDR_STR_SIZE (65)
291 /** Length of MAC address */
292 #define MAC_ADDR_STR_SIZE (17)
294 /** Blocks of MAC address */
295 #define MAC_ADDR_BLOCKS (6)
297 /** Max identity size. */
298 #define MAX_IDENTITY_SIZE (32)
300 /** Universal unique identity size. */
301 #define UUID_IDENTITY_SIZE (128/8)
303 /** Resource Directory */
305 /** Resource Directory URI used to Discover RD and Publish resources.*/
306 #define OC_RSRVD_RD_URI "/oic/rd"
308 /** To represent resource type with rd.*/
309 #define OC_RSRVD_RESOURCE_TYPE_RD "oic.wk.rd"
311 /** RD Discovery bias factor type. */
312 #define OC_RSRVD_RD_DISCOVERY_SEL "sel"
315 #define OC_RSRVD_BASE_URI "baseURI"
317 /** Unique value per collection/link. */
318 #define OC_RSRVD_INS "ins"
320 /** Allowable resource types in the links. */
321 #define OC_RSRVD_RTS "rts"
323 /** Default relationship. */
324 #define OC_RSRVD_DREL "drel"
326 /** Defines relationship between links. */
327 #define OC_RSRVD_REL "rel"
329 /** Defines title. */
330 #define OC_RSRVD_TITLE "title"
333 #define OC_RSRVD_URI "uri"
335 /** Defines media type. */
336 #define OC_RSRVD_MEDIA_TYPE "mt"
338 /** To represent resource type with Publish RD.*/
339 #define OC_RSRVD_RESOURCE_TYPE_RDPUBLISH "oic.wk.rdpub"
344 #define OC_RSRVD_ACCOUNT_URI "/.well-known/ocf/account"
346 /** Account session URI.*/
347 #define OC_RSRVD_ACCOUNT_SESSION_URI "/.well-known/ocf/account/session"
349 /** Account token refresh URI.*/
350 #define OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI "/.well-known/ocf/account/tokenrefresh"
352 /** Defines auth provider. */
353 #define OC_RSRVD_AUTHPROVIDER "authprovider"
355 /** Defines auth code. */
356 #define OC_RSRVD_AUTHCODE "authcode"
358 /** Defines session. */
359 #define OC_RSRVD_ACCESS_TOKEN "accesstoken"
361 /** Defines status. */
362 #define OC_RSRVD_STATUS "status"
364 /** Defines grant type. */
365 #define OC_RSRVD_GRANT_TYPE "granttype"
367 /** Defines refresh token. */
368 #define OC_RSRVD_REFRESH_TOKEN "refreshtoken"
370 /** To represent grant type with refresh token. */
371 #define OC_RSRVD_GRANT_TYPE_REFRESH_TOKEN "refresh_token"
374 * Mark a parameter as unused. Used to prevent unused variable compiler warnings.
375 * Used in three cases:
376 * 1. in callbacks when one of the parameters are unused
377 * 2. when due to code changes a functions parameter is no longer
378 * used but must be left in place for backward compatibility
380 * 3. a variable is only used in the debug build variant and would
381 * give a build warning in release mode.
383 #define OC_UNUSED(x) (void)(x)
386 * These enums (OCTransportAdapter and OCTransportFlags) must
387 * be kept synchronized with OCConnectivityType (below) as well as
388 * CATransportAdapter and CATransportFlags (in CACommon.h).
392 /** value zero indicates discovery.*/
393 OC_DEFAULT_ADAPTER = 0,
395 /** IPv4 and IPv6, including 6LoWPAN.*/
396 OC_ADAPTER_IP = (1 << 0),
398 /** GATT over Bluetooth LE.*/
399 OC_ADAPTER_GATT_BTLE = (1 << 1),
401 /** RFCOMM over Bluetooth EDR.*/
402 OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),
404 /**Remote Access over XMPP.*/
405 OC_ADAPTER_REMOTE_ACCESS = (1 << 3),
408 OC_ADAPTER_TCP = (1 << 4),
410 /** NFC Transport for Messaging.*/
411 OC_ADAPTER_NFC = (1 << 5)
412 } OCTransportAdapter;
415 * Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
419 /** default flag is 0*/
420 OC_DEFAULT_FLAGS = 0,
422 /** Insecure transport is the default (subject to change).*/
423 /** secure the transport path*/
424 OC_FLAG_SECURE = (1 << 4),
426 /** IPv4 & IPv6 auto-selection is the default.*/
427 /** IP & TCP adapter only.*/
428 OC_IP_USE_V6 = (1 << 5),
430 /** IP & TCP adapter only.*/
431 OC_IP_USE_V4 = (1 << 6),
433 /** Multicast only.*/
434 OC_MULTICAST = (1 << 7),
436 /** Link-Local multicast is the default multicast scope for IPv6.
437 * These are placed here to correspond to the IPv6 multicast address bits.*/
439 /** IPv6 Interface-Local scope (loopback).*/
440 OC_SCOPE_INTERFACE = 0x1,
442 /** IPv6 Link-Local scope (default).*/
445 /** IPv6 Realm-Local scope. */
446 OC_SCOPE_REALM = 0x3,
448 /** IPv6 Admin-Local scope. */
449 OC_SCOPE_ADMIN = 0x4,
451 /** IPv6 Site-Local scope. */
454 /** IPv6 Organization-Local scope. */
457 /**IPv6 Global scope. */
458 OC_SCOPE_GLOBAL = 0xE,
462 /** Bit mask for scope.*/
463 #define OC_MASK_SCOPE (0x000F)
465 /** Bit mask for Mods.*/
466 #define OC_MASK_MODS (0x0FF0)
467 #define OC_MASK_FAMS (OC_IP_USE_V6|OC_IP_USE_V4)
469 typedef struct OCStringLL
471 struct OCStringLL *next;
476 * End point identity.
480 /** Identity Length */
483 /** Array of end point identity.*/
484 unsigned char id[MAX_IDENTITY_SIZE];
488 * Universally unique identifier.
492 /** identitifier string.*/
493 unsigned char id[UUID_IDENTITY_SIZE];
497 * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
498 * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
503 OCTransportAdapter adapter;
505 /** transport modifiers.*/
506 OCTransportFlags flags;
511 /** address for all adapters.*/
512 char addr[MAX_ADDR_STR_SIZE];
514 /** usually zero for default interface.*/
516 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
517 char routeData[MAX_ADDR_STR_SIZE]; //destination GatewayID:ClientId
522 * This enum type includes elements of both ::OCTransportAdapter and ::OCTransportFlags.
523 * It is defined conditionally because the smaller definition limits expandability on 32/64 bit
524 * integer machines, and the larger definition won't fit into an enum on 16-bit integer machines
527 * This structure must directly correspond to ::OCTransportAdapter and ::OCTransportFlags.
531 /** use when defaults are ok. */
534 /** IPv4 and IPv6, including 6LoWPAN.*/
535 CT_ADAPTER_IP = (1 << 16),
537 /** GATT over Bluetooth LE.*/
538 CT_ADAPTER_GATT_BTLE = (1 << 17),
540 /** RFCOMM over Bluetooth EDR.*/
541 CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),
544 /** Remote Access over XMPP.*/
545 CT_ADAPTER_REMOTE_ACCESS = (1 << 19),
548 CT_ADAPTER_TCP = (1 << 20),
551 CT_ADAPTER_NFC = (1 << 21),
553 /** Insecure transport is the default (subject to change).*/
555 /** secure the transport path.*/
556 CT_FLAG_SECURE = (1 << 4),
558 /** IPv4 & IPv6 autoselection is the default.*/
560 /** IP adapter only.*/
561 CT_IP_USE_V6 = (1 << 5),
563 /** IP adapter only.*/
564 CT_IP_USE_V4 = (1 << 6),
566 /** Link-Local multicast is the default multicast scope for IPv6.
567 * These are placed here to correspond to the IPv6 address bits.*/
569 /** IPv6 Interface-Local scope(loopback).*/
570 CT_SCOPE_INTERFACE = 0x1,
572 /** IPv6 Link-Local scope (default).*/
575 /** IPv6 Realm-Local scope.*/
576 CT_SCOPE_REALM = 0x3,
578 /** IPv6 Admin-Local scope.*/
579 CT_SCOPE_ADMIN = 0x4,
581 /** IPv6 Site-Local scope.*/
584 /** IPv6 Organization-Local scope.*/
587 /** IPv6 Global scope.*/
588 CT_SCOPE_GLOBAL = 0xE,
589 } OCConnectivityType;
591 /** bit shift required for connectivity adapter.*/
592 #define CT_ADAPTER_SHIFT 16
595 #define CT_MASK_FLAGS 0xFFFF
598 #define CT_MASK_ADAPTER 0xFFFF0000
601 * OCDoResource methods to dispatch the request
605 OC_REST_NOMETHOD = 0,
608 OC_REST_GET = (1 << 0),
611 OC_REST_PUT = (1 << 1),
614 OC_REST_POST = (1 << 2),
617 OC_REST_DELETE = (1 << 3),
619 /** Register observe request for most up date notifications ONLY.*/
620 OC_REST_OBSERVE = (1 << 4),
622 /** Register observe request for all notifications, including stale notifications.*/
623 OC_REST_OBSERVE_ALL = (1 << 5),
625 /** De-register observation, intended for internal use.*/
626 OC_REST_CANCEL_OBSERVE = (1 << 6),
629 /** Subscribe for all presence notifications of a particular resource.*/
630 OC_REST_PRESENCE = (1 << 7),
633 /** Allows OCDoResource caller to do discovery.*/
634 OC_REST_DISCOVER = (1 << 8)
638 * Formats for payload encoding.
644 OC_FORMAT_UNSUPPORTED,
648 * Host Mode of Operation.
655 OC_GATEWAY /**< Client server mode along with routing capabilities.*/
659 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
660 * protocol. The precise definitions of each quality of service level depend on the
661 * implementation. In descriptions below are for the current implementation and may changed
666 /** Packet delivery is best effort.*/
669 /** Packet delivery is best effort.*/
672 /** Acknowledgments are used to confirm delivery.*/
675 /** No Quality is defined, let the stack decide.*/
677 } OCQualityOfService;
680 * Resource Properties.
681 * The value of a policy property is defined as bitmap.
682 * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on.
683 * Not including the policy property is equivalent to zero.
688 /** When none of the bits are set, the resource is non-discoverable &
689 * non-observable by the client.*/
690 OC_RES_PROP_NONE = (0),
692 /** When this bit is set, the resource is allowed to be discovered by clients.*/
693 OC_DISCOVERABLE = (1 << 0),
695 /** When this bit is set, the resource is allowed to be observed by clients.*/
696 OC_OBSERVABLE = (1 << 1),
698 /** When this bit is set, the resource is initialized, otherwise the resource
699 * is 'inactive'. 'inactive' signifies that the resource has been marked for
700 * deletion or is already deleted.*/
701 OC_ACTIVE = (1 << 2),
703 /** When this bit is set, the resource has been marked as 'slow'.
704 * 'slow' signifies that responses from this resource can expect delays in
705 * processing its requests from clients.*/
709 /** When this bit is set, the resource is a secure resource.*/
710 OC_SECURE = (1 << 4),
715 /** When this bit is set, the resource is allowed to be discovered only
716 * if discovery request contains an explicit querystring.
717 * Ex: GET /oic/res?rt=oic.sec.acl */
718 OC_EXPLICIT_DISCOVERABLE = (1 << 5),
721 /** When this bit is set, the resource is allowed to be published */
722 OC_MQ_PUBLISHER = (1 << 6),
726 /** When this bit is set, the resource is allowed to be notified as MQ broker.*/
727 OC_MQ_BROKER = (1 << 7),
729 } OCResourceProperty;
732 * Transport Protocol IDs.
736 /** For invalid ID.*/
737 OC_INVALID_ID = (1 << 0),
740 OC_COAP_ID = (1 << 1)
741 } OCTransportProtocolID;
744 * Declares Stack Results & Errors.
748 /** Success status code - START HERE.*/
750 OC_STACK_RESOURCE_CREATED,
751 OC_STACK_RESOURCE_DELETED,
753 OC_STACK_RESOURCE_CHANGED,
754 /** Success status code - END HERE.*/
756 /** Error status code - START HERE.*/
757 OC_STACK_INVALID_URI = 20,
758 OC_STACK_INVALID_QUERY,
760 OC_STACK_INVALID_PORT,
761 OC_STACK_INVALID_CALLBACK,
762 OC_STACK_INVALID_METHOD,
764 /** Invalid parameter.*/
765 OC_STACK_INVALID_PARAM,
766 OC_STACK_INVALID_OBSERVE_PARAM,
770 OC_STACK_ADAPTER_NOT_ENABLED,
773 /** Resource not found.*/
774 OC_STACK_NO_RESOURCE,
776 /** e.g: not supported method or interface.*/
777 OC_STACK_RESOURCE_ERROR,
778 OC_STACK_SLOW_RESOURCE,
779 OC_STACK_DUPLICATE_REQUEST,
781 /** Resource has no registered observers.*/
782 OC_STACK_NO_OBSERVERS,
783 OC_STACK_OBSERVER_NOT_FOUND,
784 OC_STACK_VIRTUAL_DO_NOT_HANDLE,
785 OC_STACK_INVALID_OPTION,
787 /** The remote reply contained malformed data.*/
788 OC_STACK_MALFORMED_RESPONSE,
789 OC_STACK_PERSISTENT_BUFFER_REQUIRED,
790 OC_STACK_INVALID_REQUEST_HANDLE,
791 OC_STACK_INVALID_DEVICE_INFO,
792 OC_STACK_INVALID_JSON,
794 /** Request is not authorized by Resource Server. */
795 OC_STACK_UNAUTHORIZED_REQ,
796 OC_STACK_TOO_LARGE_REQ,
798 /** Error code from PDM */
799 OC_STACK_PDM_IS_NOT_INITIALIZED,
800 OC_STACK_DUPLICATE_UUID,
801 OC_STACK_INCONSISTENT_DB,
804 * Error code from OTM
805 * This error is pushed from DTLS interface when handshake failure happens
807 OC_STACK_AUTHENTICATION_FAILURE,
809 /** Insert all new error codes here!.*/
811 OC_STACK_PRESENCE_STOPPED = 128,
812 OC_STACK_PRESENCE_TIMEOUT,
813 OC_STACK_PRESENCE_DO_NOT_HANDLE,
815 /** ERROR in stack.*/
817 /** Error status code - END HERE.*/
821 * Handle to an OCDoResource invocation.
823 typedef void * OCDoHandle;
826 * Handle to an OCResource object owned by the OCStack.
828 typedef void * OCResourceHandle;
831 * Handle to an OCRequest object owned by the OCStack.
833 typedef void * OCRequestHandle;
836 * Unique identifier for each observation request. Used when observations are
837 * registered or de-registered. Used by entity handler to signal specific
838 * observers to be notified of resource changes.
839 * There can be maximum of 256 observations per server.
841 typedef uint8_t OCObservationId;
844 * Action associated with observation.
849 OC_OBSERVE_REGISTER = 0,
851 /** To Deregister. */
852 OC_OBSERVE_DEREGISTER = 1,
855 OC_OBSERVE_NO_OPTION = 2
860 * Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
861 * when it calls OCRegisterPersistentStorageHandler.
862 * Persistent storage open handler points to default file path.
863 * It should check file path and whether the file is symbolic link or no.
864 * Application can point to appropriate SVR database path for it's IoTivity Server.
867 /** Persistent storage file path.*/
868 FILE* (* open)(const char *path, const char *mode);
870 /** Persistent storage read handler.*/
871 size_t (* read)(void *ptr, size_t size, size_t nmemb, FILE *stream);
873 /** Persistent storage write handler.*/
874 size_t (* write)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
876 /** Persistent storage close handler.*/
877 int (* close)(FILE *fp);
879 /** Persistent storage unlink handler.*/
880 int (* unlink)(const char *path);
881 } OCPersistentStorage;
884 * Possible returned values from entity handler.
888 /** Action associated with observation request.*/
889 OCObserveAction action;
891 /** Identifier for observation being registered/deregistered.*/
892 OCObservationId obsId;
896 * Possible returned values from entity handler.
902 OC_EH_RESOURCE_CREATED, // 2.01
903 OC_EH_RESOURCE_DELETED, // 2.02
905 OC_EH_FORBIDDEN, // 4.03
906 OC_EH_RESOURCE_NOT_FOUND, // 4.04
908 OC_EH_CHANGED, // 2.04
909 OC_EH_CONTENT, // 2.05
910 OC_EH_BAD_REQ, // 4.00
911 OC_EH_UNAUTHORIZED_REQ, // 4.01
912 OC_EH_BAD_OPT, // 4.02
913 OC_EH_METHOD_NOT_ALLOWED, // 4.05
914 OC_EH_NOT_ACCEPTABLE, // 4.06
915 OC_EH_INTERNAL_SERVER_ERROR, // 5.00
916 OC_EH_RETRANSMIT_TIMEOUT // 5.04
917 } OCEntityHandlerResult;
920 * This structure will be used to define the vendor specific header options to be included
921 * in communication packets.
923 typedef struct OCHeaderOption
925 /** The protocol ID this option applies to.*/
926 OCTransportProtocolID protocolID;
928 /** The header option ID which will be added to communication packets.*/
931 /** its length 191.*/
932 uint16_t optionLength;
934 /** pointer to its data.*/
935 uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
937 #ifdef SUPPORTS_DEFAULT_CTOR
938 OCHeaderOption() = default;
939 OCHeaderOption(OCTransportProtocolID pid,
942 const uint8_t* optData)
948 // parameter includes the null terminator.
949 optionLength = optionLength < MAX_HEADER_OPTION_DATA_LENGTH ?
950 optionLength : MAX_HEADER_OPTION_DATA_LENGTH;
951 memcpy(optionData, optData, optionLength);
952 optionData[optionLength - 1] = '\0';
959 * This structure describes the platform properties. All non-Null properties will be
960 * included in a platform discovery request.
967 /** Manufacturer name.*/
968 char *manufacturerName;
970 /** Manufacturer URL for platform property.*/
971 char *manufacturerUrl;
976 /** Manufacturer date.*/
977 char *dateOfManufacture;
979 /** Platform version.*/
980 char *platformVersion;
982 /** Operating system version.*/
983 char *operatingSystemVersion;
986 char *hardwareVersion;
989 char *firmwareVersion;
991 /** Platform support URL.*/
1000 * This structure is expected as input for device properties.
1001 * device name is mandatory and expected from the application.
1002 * device id of type UUID will be generated by the stack.
1006 /** Pointer to the device name.*/
1008 /** Pointer to the types.*/
1010 /** Pointer to the device specification version.*/
1012 /** Pointer to the device data model versions (in CSV format).*/
1013 OCStringLL *dataModelVersions;
1018 * callback for bound JID
1020 typedef void (*jid_bound_cb)(char *jid);
1023 * CA Remote Access information for XMPP Client
1028 char *hostname; /**< XMPP server hostname */
1029 uint16_t port; /**< XMPP server serivce port */
1030 char *xmpp_domain; /**< XMPP login domain */
1031 char *username; /**< login username */
1032 char *password; /**< login password */
1033 char *resource; /**< specific resource for login */
1034 char *user_jid; /**< specific JID for login */
1035 jid_bound_cb jidbound; /**< callback when JID bound */
1037 #endif /* RA_ADAPTER */
1040 /** Enum to describe the type of object held by the OCPayload object.*/
1043 /** Contents of the payload are invalid */
1044 PAYLOAD_TYPE_INVALID,
1045 /** The payload is an OCDiscoveryPayload */
1046 PAYLOAD_TYPE_DISCOVERY,
1047 /** The payload is an OCDevicePayload */
1048 PAYLOAD_TYPE_DEVICE,
1049 /** The payload is an OCPlatformPayload */
1050 PAYLOAD_TYPE_PLATFORM,
1051 /** The payload is an OCRepPayload */
1052 PAYLOAD_TYPE_REPRESENTATION,
1053 /** The payload is an OCSecurityPayload */
1054 PAYLOAD_TYPE_SECURITY,
1055 /** The payload is an OCPresencePayload */
1056 PAYLOAD_TYPE_PRESENCE,
1057 /** The payload is an OCRDPayload */
1062 * A generic struct representing a payload returned from a resource operation
1064 * A pointer to OCPayLoad can be cast to a more specific struct to access members
1069 /** The type of message that was received */
1080 OCREP_PROP_BYTE_STRING,
1083 }OCRepPayloadPropType;
1085 /** This structure will be used to represent a binary string for CBOR payloads.*/
1088 /** pointer to data bytes.*/
1091 /** number of data bytes.*/
1095 #define MAX_REP_ARRAY_DEPTH 3
1098 OCRepPayloadPropType type;
1099 size_t dimensions[MAX_REP_ARRAY_DEPTH];
1108 /** pointer to ByteString array.*/
1109 OCByteString* ocByteStrArray;
1111 struct OCRepPayload** objArray;
1113 } OCRepPayloadValueArray;
1115 typedef struct OCRepPayloadValue
1118 OCRepPayloadPropType type;
1126 /** ByteString object.*/
1127 OCByteString ocByteStr;
1129 struct OCRepPayload* obj;
1130 OCRepPayloadValueArray arr;
1132 struct OCRepPayloadValue* next;
1134 } OCRepPayloadValue;
1136 // used for get/set/put/observe/etc representations
1137 typedef struct OCRepPayload
1142 OCStringLL* interfaces;
1143 OCRepPayloadValue* values;
1144 struct OCRepPayload* next;
1147 // used inside a discovery payload
1148 typedef struct OCResourcePayload
1152 OCStringLL* interfaces;
1159 struct OCResourcePayload* next;
1160 } OCResourcePayload;
1163 * Structure holding Links Payload. It is a sub-structure used in
1164 * OCResourceCollectionPayload.
1166 typedef struct OCLinksPayload
1168 /** This is the target relative URI. */
1170 /** Resource Type - A standard OIC specified or vendor defined resource
1171 * type of the resource referenced by the target URI. */
1173 /** Interface - The interfaces supported by the resource referenced by the target URI. */
1175 /** The relation of the target URI referenced by the link to the context URI;
1176 * The default value is null. */
1178 /** Specifies if the resource referenced by the target URIis observable or not. */
1180 /** A title for the link relation. Can be used by the UI to provide a context. */
1182 /** This is used to override the context URI e.g. override the URI of the containing collection. */
1184 /** The instance identifier for this web link in an array of web links - used in links. */
1187 /** An ordinal number that is not repeated - must be unique in the collection context. */
1189 /** Any unique string including a URI. */
1191 /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1192 OCIdentity uniqueUUID;
1194 /** A hint of the media type of the representation of the resource referenced by the target URI. */
1196 /** Holding address of the next resource. */
1197 struct OCLinksPayload *next;
1200 /** Structure holding tags value of the links payload. */
1203 /** Name of tags. */
1205 /** Device identifier. */
1207 /** The base URI where the resources are hold. */
1209 /** Bitmap holds observable, discoverable, secure option flag.*/
1211 /** Port set in case, the secure flag is set above. */
1213 /** Id for each set of links i.e. tag. */
1216 /** An ordinal number that is not repeated - must be unique in the collection context. */
1218 /** Any unique string including a URI. */
1220 /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
1221 OCIdentity uniqueUUID;
1223 /** Defines the list of allowable resource types (for Target and anchors) in links included
1224 * in the collection; new links being created can only be from this list. */
1226 /** When specified this is the default relationship to use when an OIC Link does not specify
1227 * an explicit relationship with *rel* parameter. */
1229 /** Time to keep holding resource.*/
1233 /** Resource collection payload. */
1234 typedef struct OCResourceCollectionPayload
1236 /** Collection tags payload.*/
1237 OCTagsPayload *tags;
1238 /** Array of links payload. */
1239 OCLinksPayload *setLinks;
1240 /** Holding address of the next resource. */
1241 struct OCResourceCollectionPayload *next;
1242 } OCResourceCollectionPayload;
1244 typedef struct OCDiscoveryPayload
1251 /** A special case for handling RD address. */
1260 /** Resource Type */
1266 /** This structure holds the old /oic/res response. */
1267 OCResourcePayload *resources;
1269 /** Holding address of the next DiscoveryPayload. */
1270 struct OCDiscoveryPayload *next;
1272 } OCDiscoveryPayload;
1275 * Structure holding discovery payload.
1281 /** Device Identity. */
1283 /** Value holding the bias factor of the RD. */
1285 } OCRDDiscoveryPayload;
1288 * RD Payload that will be transmitted over the wire.
1293 /** Pointer to the discovery response payload.*/
1294 OCRDDiscoveryPayload *rdDiscovery;
1295 /** Pointer to the publish payload.*/
1296 OCResourceCollectionPayload *rdPublish;
1305 OCStringLL *dataModelVersions;
1306 OCStringLL *interfaces;
1314 OCPlatformInfo info;
1316 OCStringLL* interfaces;
1317 } OCPlatformPayload;
1322 uint8_t* securityData;
1324 } OCSecurityPayload;
1326 #ifdef WITH_PRESENCE
1330 uint32_t sequenceNumber;
1332 OCPresenceTrigger trigger;
1334 } OCPresencePayload;
1338 * Incoming requests handled by the server. Requests are passed in as a parameter to the
1339 * OCEntityHandler callback API.
1340 * The OCEntityHandler callback API must be implemented in the application in order
1341 * to receive these requests.
1345 /** Associated resource.*/
1346 OCResourceHandle resource;
1348 /** Associated request handle.*/
1349 OCRequestHandle requestHandle;
1351 /** the REST method retrieved from received request PDU.*/
1354 /** description of endpoint that sent the request.*/
1357 /** resource query send by client.*/
1360 /** Information associated with observation - valid only when OCEntityHandler flag includes
1361 * ::OC_OBSERVE_FLAG.*/
1362 OCObservationInfo obsInfo;
1364 /** Number of the received vendor specific header options.*/
1365 uint8_t numRcvdVendorSpecificHeaderOptions;
1367 /** Pointer to the array of the received vendor specific header options.*/
1368 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
1373 /** the payload from the request PDU.*/
1376 } OCEntityHandlerRequest;
1380 * Response from queries to remote servers. Queries are made by calling the OCDoResource API.
1384 /** Address of remote server.*/
1387 /** backward compatibility (points to devAddr).*/
1390 /** backward compatibility.*/
1391 OCConnectivityType connType;
1393 /** the security identity of the remote server.*/
1394 OCIdentity identity;
1396 /** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
1397 OCStackResult result;
1399 /** If associated with observe, this will represent the sequence of notifications from server.*/
1400 uint32_t sequenceNumber;
1403 const char * resourceUri;
1405 /** the payload for the response PDU.*/
1408 /** Number of the received vendor specific header options.*/
1409 uint8_t numRcvdVendorSpecificHeaderOptions;
1411 /** An array of the received vendor specific header options.*/
1412 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1416 * Request handle is passed to server via the entity handler for each incoming request.
1417 * Stack assigns when request is received, server sets to indicate what request response is for.
1421 /** Request handle.*/
1422 OCRequestHandle requestHandle;
1424 /** Resource handle.*/
1425 OCResourceHandle resourceHandle;
1427 /** Allow the entity handler to pass a result with the response.*/
1428 OCEntityHandlerResult ehResult;
1430 /** This is the pointer to server payload data to be transferred.*/
1433 /** number of the vendor specific header options .*/
1434 uint8_t numSendVendorSpecificHeaderOptions;
1436 /** An array of the vendor specific header options the entity handler wishes to use in response.*/
1437 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
1439 /** URI of new resource that entity handler might create.*/
1440 char resourceUri[MAX_URI_LENGTH];
1442 /** Server sets to true for persistent response buffer,false for non-persistent response buffer*/
1443 uint8_t persistentBufferFlag;
1444 } OCEntityHandlerResponse;
1451 /** Request state.*/
1452 OC_REQUEST_FLAG = (1 << 1),
1453 /** Observe state.*/
1454 OC_OBSERVE_FLAG = (1 << 2)
1455 } OCEntityHandlerFlag;
1458 * Possible return values from client application callback
1460 * A client application callback returns an OCStackApplicationResult to indicate whether
1461 * the stack should continue to keep the callback registered.
1465 /** Make no more calls to the callback and call the OCClientContextDeleter for this callback */
1466 OC_STACK_DELETE_TRANSACTION = 0,
1467 /** Keep this callback registered and call it if an apropriate event occurs */
1468 OC_STACK_KEEP_TRANSACTION
1469 } OCStackApplicationResult;
1472 //#ifdef DIRECT_PAIRING
1474 * @brief direct pairing Method Type.
1476 * 1: pre-configured pin
1481 DP_NOT_ALLOWED = 0x0,
1482 DP_PRE_CONFIGURED = (0x1 << 0),
1483 DP_RANDOM_PIN = (0x1 << 1),
1487 * Device Information of discoverd direct pairing device(s).
1489 typedef struct OCDPDev
1492 OCConnectivityType connType;
1493 uint16_t securePort;
1497 OCUUIdentity deviceID;
1498 OCUUIdentity rowner;
1499 struct OCDPDev *next;
1501 //#endif // DIRECT_PAIRING
1504 * -------------------------------------------------------------------------------------------
1505 * Callback function definitions
1506 * -------------------------------------------------------------------------------------------
1510 * Client applications implement this callback to consume responses received from Servers.
1512 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
1513 OCClientResponse * clientResponse);
1516 * Client applications using a context pointer implement this callback to delete the
1517 * context upon removal of the callback/context pointer from the internal callback-list.
1519 typedef void (* OCClientContextDeleter)(void *context);
1522 * This info is passed from application to OC Stack when initiating a request to Server.
1524 typedef struct OCCallbackData
1526 /** Pointer to the context.*/
1529 /** The pointer to a function the stack will call to handle the requests.*/
1530 OCClientResponseHandler cb;
1532 /** A pointer to a function to delete the context when this callback is removed.*/
1533 OCClientContextDeleter cd;
1535 #ifdef SUPPORTS_DEFAULT_CTOR
1536 OCCallbackData() = default;
1537 OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
1538 :context(ctx), cb(callback), cd(deleter){}
1543 * Application server implementations must implement this callback to consume requests OTA.
1544 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
1546 typedef OCEntityHandlerResult (*OCEntityHandler)
1547 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam);
1550 * Device Entity handler need to use this call back instead of OCEntityHandler.
1552 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
1553 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri, void* callbackParam);
1555 //#ifdef DIRECT_PAIRING
1557 * Callback function definition of direct-pairing
1559 * @param[OUT] ctx - user context returned in the callback.
1560 * @param[OUT] peer - pairing device info.
1561 * @param[OUT} result - It's returned with 'OC_STACK_XXX'. It will return 'OC_STACK_OK'
1562 * if D2D pairing is success without error
1564 typedef void (*OCDirectPairingCB)(void *ctx, OCDPDev_t *peer, OCStackResult result);
1565 //#endif // DIRECT_PAIRING
1569 #endif // __cplusplus
1571 #endif /* OCTYPES_H_ */