//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
-//-----------------------------------------------------------------------------
-// Internal include file used by lower layers of the OC stack
-//-----------------------------------------------------------------------------
+
+
+/**
+ * @file
+ *
+ * This file contains the Internal include file used by lower layers of the OC stack
+ *
+ */
+
#ifndef OCSTACKINTERNAL_H_
#define OCSTACKINTERNAL_H_
#include "ocstack.h"
#include "ocstackconfig.h"
#include "occlientcb.h"
-#include <logger.h>
#include <ocrandom.h>
#include "cacommon.h"
#include "cainterface.h"
+#include "securevirtualresourcetypes.h"
#ifdef __cplusplus
extern "C" {
//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
+
+/** Default device entity Handler.*/
extern OCDeviceEntityHandler defaultDeviceHandler;
+/** Default Callback parameter.*/
+extern void* defaultDeviceHandlerCallbackParameter;
+
//-----------------------------------------------------------------------------
// Defines
//-----------------------------------------------------------------------------
-#define OC_COAP_SCHEME "coap://"
-#define OC_OFFSET_SEQUENCE_NUMBER (4) // the first outgoing sequence number will be 5
-typedef struct
-{
- // Observe option field
- uint32_t option;
- // IP address & port of client registered for observe
- OCDevAddr *subAddr;
-
- CAToken_t *token;
+/** The coap scheme */
+#define OC_COAP_SCHEME "coap://"
- // The result of the observe request
- OCStackResult result;
-} OCObserveReq;
+/** the first outgoing sequence number will be 5*/
+#define OC_OFFSET_SEQUENCE_NUMBER (4)
-// following structure will be created in occoap and passed up the stack on the server side
+/**
+ * This structure will be created in occoap and passed up the stack on the server side.
+ */
typedef struct
{
- // Observe option field
+ /** Observe option field.*/
uint32_t observationOption;
- // the REST method retrieved from received request PDU
+
+ /** The REST method retrieved from received request PDU.*/
OCMethod method;
- // resourceUrl will be filled in occoap using the path options in received request PDU
+
+ /** the requested payload format. */
+ OCPayloadFormat acceptFormat;
+
+ /** resourceUrl will be filled in occoap using the path options in received request PDU.*/
char resourceUrl[MAX_URI_LENGTH];
- // resource query send by client
+
+ /** resource query send by client.*/
char query[MAX_QUERY_LENGTH];
- // reqJSON is retrieved from the payload of the received request PDU
- char reqJSONPayload[MAX_REQUEST_LENGTH];
- // qos is indicating if the request is CON or NON
+
+ /** reqJSON is retrieved from the payload of the received request PDU.*/
+ uint8_t *payload;
+
+ /** qos is indicating if the request is CON or NON.*/
OCQualityOfService qos;
- // An array of the received vendor specific header options
+
+ /** Number of the received vendor specific header options.*/
uint8_t numRcvdVendorSpecificHeaderOptions;
+
+ /** Array of received vendor specific header option .*/
OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
- /** Remote Endpoint address **/
- //////////////////////////////////////////////////////////
- // TODO: bundle this up as endpoint
- CAAddress_t addressInfo;
- /** Connectivity of the endpoint**/
- CAConnectivityType_t connectivityType;
+ /** Remote end-point address **/
+ OCDevAddr devAddr;
- //token for the observe request
+ /** Token for the observe request.*/
CAToken_t requestToken;
- uint8_t tokenLength; //token length
- // The ID of CoAP pdu
+
+ /** token length.*/
+ uint8_t tokenLength;
+
+ /** The ID of CoAP PDU.*/
uint16_t coapID;
+
+ /** For delayed Response.*/
uint8_t delayedResNeeded;
- uint8_t secured;
- //////////////////////////////////////////////////////////
+
+ /** For More packet.*/
uint8_t reqMorePacket;
+
+ /** The number of requested packet.*/
uint32_t reqPacketNum;
+
+ /** The size of requested packet.*/
uint16_t reqPacketSize;
+
+ /** The number of responded packet.*/
uint32_t resPacketNum;
+
+ /** Responded packet size.*/
uint16_t resPacketSize;
+
+ /** The total size of requested packet.*/
size_t reqTotalSize;
} OCServerProtocolRequest;
+/**
+ * This structure will be created in occoap and passed up the stack on the client side.
+ */
typedef struct
{
- // Observe option field
- uint32_t observationOption;
- // qos is indicating if the request is CON or NON
- OCQualityOfService qos;
- // Allow the entity handler to pass a result with the response
- OCStackResult result;
- // IP address & port of client registered for observe
- OCDevAddr *requesterAddr;
-
- CAToken_t *requestToken;
-
- // The ID of CoAP pdu
- uint16_t coapID;
- // Flag indicating that response is to be delayed before sending
- uint8_t delayedResNeeded;
- uint8_t secured;
- uint8_t slowFlag;
- uint8_t notificationFlag;
- // this is the pointer to server payload data to be transferred
- char *payload;
- // size of server payload data. Don't rely on null terminated data for size
- uint16_t payloadSize;
- // An array of the vendor specific header options the entity handler wishes to use in response
- uint8_t numSendVendorSpecificHeaderOptions;
- OCHeaderOption *sendVendorSpecificHeaderOptions;
- // URI of new resource that entity handler might create
- char * resourceUri;
-} OCServerProtocolResponse;
-
-// following structure will be created in occoap and passed up the stack on the client side
-typedef struct
-{
- // handle is retrieved by comparing the token-handle pair in the PDU.
+ /** handle is retrieved by comparing the token-handle pair in the PDU.*/
ClientCB * cbNode;
- // This is how long this response is valid for (in seconds).
+
+ /** This is how long this response is valid for (in seconds).*/
uint32_t maxAge;
- // This is the Uri of the resource. (ex. "coap://192.168.1.1/a/led")
+
+ /** This is the Uri of the resource. (ex. "coap://192.168.1.1/a/led").*/
char * fullUri;
- // This is the relative Uri of the resource. (ex. "/a/led")
+
+ /** This is the relative Uri of the resource. (ex. "/a/led").*/
char * rcvdUri;
- // This is the received payload.
+
+ /** This is the received payload.*/
char * bufRes;
- // This is the token received OTA.
- CAToken_t * rcvdToken;
+ /** This is the token received OTA.*/
+ CAToken_t rcvdToken;
- // this structure will be passed to client
+ /** this structure will be passed to client.*/
OCClientResponse * clientResponse;
} OCResponse;
-// following typedef is to represent our Server Instance identification.
-typedef uint32_t ServerID;
+/**
+ * This typedef is to represent our Server Instance identification.
+ */
+typedef uint8_t ServerID[16];
//-----------------------------------------------------------------------------
// Internal function prototypes
//-----------------------------------------------------------------------------
-#ifdef WITH_PRESENCE
+
/**
- * Notify Presence subscribers that a resource has been modified
+ * Handler function for sending a response from multiple resources, such as a collection.
+ * Aggregates responses from multiple resource until all responses are received then sends the
+ * concatenated response
+ *
+ * TODO: Need to add a timeout in case a (remote?) resource does not respond
*
- * @param resourceType - Handle to the resourceType linked list of resource
- * that was modified.
+ * @param token Token to search for.
+ * @param tokenLength Length of token.
+ * @param status Feedback status.
* @return
- * OC_STACK_OK - no errors
- * OC_STACK_ERROR - stack process error
+ * ::OCStackResult
*/
-OCStackResult SendPresenceNotification(OCResourceType *resourceType);
+
+OCStackResult OCStackFeedBack(CAToken_t token, uint8_t tokenLength, uint8_t status);
+
+
/**
- * Send Stop Notification to Presence subscribers
+ * Handler function to execute stack requests
+ *
+ * @param protocolRequest Pointer to the protocol requests from server.
*
* @return
- * OC_STACK_OK - no errors
- * OC_STACK_ERROR - stack process error
+ * ::OCStackResult
+ */
+OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
+
+OCStackResult SendDirectStackResponse(const CAEndpoint_t* endPoint, const uint16_t coapID,
+ const CAResponseResult_t responseResult, const CAMessageType_t type,
+ const uint8_t numOptions, const CAHeaderOption_t *options,
+ CAToken_t token, uint8_t tokenLength, const char *resourceUri);
+
+#ifdef WITH_PRESENCE
+
+/**
+ * Notify Presence subscribers that a resource has been modified.
+ *
+ * @param resourceType Handle to the resourceType linked list of resource that was modified.
+ * @param trigger The simplified reason this API was invoked.
+ *
+ * @return ::OC_STACK_OK on success, some other value upon failure.
+ */
+OCStackResult SendPresenceNotification(OCResourceType *resourceType,
+ OCPresenceTrigger trigger);
+
+/**
+ * Send Stop Notification to Presence subscribers.
*
+ * @return ::OC_STACK_OK on success, some other value upon failure.
*/
OCStackResult SendStopNotification();
#endif // WITH_PRESENCE
/**
- * Bind a resource interface to a resource
+ * Function to parse the IPv4 address.
*
- * @param resource - target resource
- * @param resourceInterfaceName - resource interface
- * @return
- * OCStackResult
+ * @param ipAddrStr Pointer to a string of IPv4 address.
+ * @param ipAddr pointer to IPv4 adress.
+ * @param port Port number.
+ *
+ * @return true on success, false upon failure.
+ */
+bool ParseIPv4Address(char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
+
+/**
+ * Bind a resource interface to a resource.
+ *
+ * @param resource Target resource.
+ * @param resourceInterfaceName Resource interface.
+ *
+ * @return ::OC_STACK_OK on success, some other value upon failure.
*/
OCStackResult BindResourceInterfaceToResource(OCResource* resource,
const char *resourceInterfaceName);
/**
- * Bind a resourcetype to a resource
+ * Bind a resource type to a resource.
*
- * @param resource - target resource
- * @param resourceTypeName - resourcetype
- * @return
- * OCStackResult
+ * @param resource Target resource.
+ * @param resourceTypeName Name of resource type.
+ * @return ::OC_STACK_OK on success, some other value upon failure.
*/
OCStackResult BindResourceTypeToResource(OCResource* resource,
const char *resourceTypeName);
+
+
/**
- * Finds a resource type in an OCResourceType link-list.
- *
- * @param resourceTypeList - the link-list to be searched through
- * @param resourceTypeName - the key to search for
+ * Converts a CAResult_t type to a OCStackResult type.
*
- * @return
- * resourceType that matches the key (ie. resourceTypeName)
- * NULL - either an invalid parameter or this function was unable to find the key.
+ * @param caResult CAResult_t value to convert.
+ * @return OCStackResult that was converted from the input CAResult_t value.
*/
-OCResourceType *findResourceType(OCResourceType * resourceTypeList, const char * resourceTypeName);
-
-// returns the internal representation of the server instance ID.
-// Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
-// This is done automatically during the OCInit process (via the call to OCInitCoAP),
-// so ensure that this call is done after that.
-const ServerID OCGetServerInstanceID(void);
-
-// Converts a CAResult_t type to a OCStackResult type.
OCStackResult CAResultToOCResult(CAResult_t caResult);
-// returns a string representation the server instance ID.
-// The memory is managed internal to this function, so freeing externally will result
-// in a compiler error
-// Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
-// This is done automatically during the OCInit process (via the call to OCInitCoAP),
-// so ensure that this call is done after that.
+/**
+ * Get a byte representation of the server instance ID.
+ * The memory is managed internal to this function, so freeing it externally will
+ * result in a runtime error.
+ *
+ * Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
+ * This is done automatically during the OCInit process,
+ * so ensure that this call is done after that.
+ *
+ * @return A uint8_t representation the server instance ID.
+ */
+const OicUuid_t* OCGetServerInstanceID(void);
+
+/**
+ * Get a string representation the server instance ID.
+ * The memory is managed internal to this function, so freeing externally will result
+ * in a runtime error.
+ * Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
+ * This is done automatically during the OCInit process,
+ * so ensure that this call is done after that.
+ *
+ * @return A string representation the server instance ID.
+ */
const char* OCGetServerInstanceIDString(void);
/**
- * Map OCQualityOfService to CAMessageType
+ * Map OCQualityOfService to CAMessageType.
*
- * @param OCQualityOfService - Input qos.
+ * @param qos Input qos.
*
- * Returns CA message type for a given qos.
+ * @return CA message type for a given qos.
*/
CAMessageType_t qualityOfServiceToMessageType(OCQualityOfService qos);
#ifdef WITH_PRESENCE
/**
- * Enable/disable a resource property
+ * Enable/disable a resource property.
*
- * @param inputProperty - pointer to resource property
- * @param resourceProperties - property to be enabled/disabled
- * @param enable - 0:disable, 1:enable
+ * @param inputProperty Pointer to resource property.
+ * @param resourceProperties Property to be enabled/disabled.
+ * @param enable 0:disable, 1:enable.
*
- * @return
- * OCStackResult
+ * @return OCStackResult that was converted from the input CAResult_t value.
*/
//TODO: should the following function be public?
OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
OCResourceProperty resourceProperties, uint8_t enable);
#endif
+const char *convertTriggerEnumToString(OCPresenceTrigger trigger);
+
+OCPresenceTrigger convertTriggerStringToEnum(const char * triggerStr);
+
+void CopyEndpointToDevAddr(const CAEndpoint_t *in, OCDevAddr *out);
+
+void CopyDevAddrToEndpoint(const OCDevAddr *in, CAEndpoint_t *out);
+
#ifdef __cplusplus
}
#endif // __cplusplus