#include <ocstack.h>
#include <occoaptoken.h>
#include <ocresource.h>
+#ifdef CA_INT
+#include "cacommon.h"
+#endif
typedef struct OCPresence {
// This is the TTL associated with presence
// callback method to delete context data
OCClientContextDeleter deleteCallback;
// when a response is recvd with this token, above callback will be invoked
+ #ifdef CA_INT
+ CAToken_t token;
+ #else // CA_INT
OCCoAPToken token;
+ #endif // CA_INT
// Invocation handle tied to original call to OCDoResource()
OCDoHandle handle;
// This is used to determine if all responses should be consumed or not.
* @retval OC_STACK_OK for Success, otherwise some error value
*/
//------------------------------------------------------------------------
-OCStackResult AddClientCB(ClientCB** clientCB, OCCallbackData* cbData,
- OCCoAPToken * token, OCDoHandle *handle, OCMethod method,
- unsigned char * requestUri, unsigned char * resourceType);
+OCStackResult
+#ifdef CA_INT
+AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
+ CAToken_t * token, OCDoHandle *handle, OCMethod method,
+ unsigned char * requestUri, unsigned char * resourceTypeName);
+#else // CA_INT
+AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
+ OCCoAPToken * token, OCDoHandle *handle, OCMethod method,
+ unsigned char * requestUri, unsigned char * resourceTypeName);
+#endif // CA_INT
//-- DeleteClientCB -----------------------------------------------------------
/** @ingroup ocstack
* @retval address of the node if found, otherwise NULL
*/
//------------------------------------------------------------------------
+#ifdef CA_INT
+ClientCB* GetClientCB(CAToken_t * token, OCDoHandle handle, const unsigned char * requestUri);
+#else // CA_INT
ClientCB* GetClientCB(OCCoAPToken * token, OCDoHandle handle, const unsigned char * requestUri);
+#endif // CA_INT
/**
#include "ocmalloc.h"
#include <string.h>
+#ifdef CA_INT
+ #include "cacommon.h"
+ #include "cainterface.h"
+#endif
+
/// Module Name
#define TAG PCF("occlientcb")
+#ifdef CA_INT
+// TODO-CA: This has been defined in CA layer as well, but is not exposed externally.
+// Need to expose it from CA and remove the definition below.
+#define CA_MAX_TOKEN_LEN (8)
+#endif //CA_INT
+
struct ClientCB *cbList = NULL;
OCMulticastNode * mcPresenceNodes = NULL;
-OCStackResult AddClientCB(ClientCB** clientCB, OCCallbackData* cbData,
- OCCoAPToken * token, OCDoHandle *handle, OCMethod method,
- unsigned char * requestUri, unsigned char * resourceTypeName) {
+OCStackResult
+#ifdef CA_INT
+AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
+ CAToken_t * token, OCDoHandle *handle, OCMethod method,
+ unsigned char * requestUri, unsigned char * resourceTypeName)
+#else // CA_INT
+AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
+ OCCoAPToken * token, OCDoHandle *handle, OCMethod method,
+ unsigned char * requestUri, unsigned char * resourceTypeName)
+#endif // CA_INT
+{
ClientCB *cbNode = NULL;
cbNode->callBack = cbData->cb;
cbNode->context = cbData->context;
cbNode->deleteCallback = cbData->cd;
+ #ifdef CA_INT
+ cbNode->token = (CAToken_t *)OCMalloc(CA_MAX_TOKEN_LEN);
+ memcpy(&(cbNode->token), token, CA_MAX_TOKEN_LEN);
+ #else // CA_INT
memcpy(&(cbNode->token), token, sizeof(OCCoAPToken));
+ #endif // CA_INT
cbNode->handle = *handle;
cbNode->method = method;
cbNode->sequenceNumber = 0;
if(cbNode) {
LL_DELETE(cbList, cbNode);
OC_LOG(INFO, TAG, PCF("deleting tokens"));
+ #ifdef CA_INT
+ CADestroyToken (cbNode->token);
+ #else
OC_LOG_BUFFER(INFO, TAG, cbNode->token.token, cbNode->token.tokenLength);
+ #endif // CA_INT
OCFree(cbNode->handle);
OCFree(cbNode->requestUri);
if(cbNode->deleteCallback)
}
}
-ClientCB* GetClientCB(OCCoAPToken * token, OCDoHandle handle, const unsigned char * requestUri) {
+#ifdef CA_INT
+ClientCB* GetClientCB(CAToken_t * token, OCDoHandle handle, const unsigned char * requestUri)
+#else // CA_INT
+ClientCB* GetClientCB(OCCoAPToken * token, OCDoHandle handle, const unsigned char * requestUri)
+#endif // CA_INT
+{
ClientCB* out = NULL;
if(token) {
LL_FOREACH(cbList, out) {
OC_LOG(INFO, TAG, PCF("comparing tokens"));
+ #ifdef CA_INT
+ if(memcmp(out->token, token, CA_MAX_TOKEN_LEN) == 0)
+ {
+ return out;
+ }
+ #else // CA_INT
OC_LOG_BUFFER(INFO, TAG, token->token, token->tokenLength);
OC_LOG_BUFFER(INFO, TAG, out->token.token, out->token.tokenLength);
if((out->token.tokenLength == token->tokenLength) &&
(memcmp(out->token.token, token->token, token->tokenLength) == 0) ) {
return out;
}
+ #endif // CA_INT
}
}
else if(handle) {
//TODO: we should allow the server to define this
#define MAX_OBSERVE_AGE (0x2FFFFUL)
+
//-----------------------------------------------------------------------------
// Externs
//-----------------------------------------------------------------------------
void HandleCAResponses(const CARemoteEndpoint_t* endPoint, const CAResponseInfo_t* responseInfo)
{
OC_LOG(INFO, TAG, PCF("Enter HandleCAResponses"));
+ printf ("Received payload: %s\n", (char *)responseInfo->info.payload);
OC_LOG_V(INFO, TAG, PCF("Received payload: %s\n"), (char*)responseInfo->info.payload);
OC_LOG(INFO, TAG, PCF("Exit HandleCAResponses"));
}
CAInfo_t responseData;
CAResponseInfo_t responseInfo;
+ OC_LOG(INFO, TAG, PCF("Enter HandleCARequests"));
// generate the pdu, if the request was CON, then the response is ACK, otherwire NON
memset(&responseData, 0, sizeof(CAInfo_t));
responseData.token = (requestInfo != NULL) ? requestInfo->info.token : "";
OC_LOG(ERROR, TAG, PCF("CASendResponse error"));
}
- OC_LOG(INFO, TAG, PCF("Enter HandleCARequests"));
OC_LOG(INFO, TAG, PCF("Exit HandleCARequests"));
}
unsigned char * resourceType = NULL;
char * newUri = (char *)requiredUri;
(void) referenceUri;
+#ifdef CA_INT
+ CARemoteEndpoint_t* endpoint = NULL;
+ CAResult_t caResult;
+ CAToken_t caToken = NULL;
+ CAInfo_t requestData;
+ CARequestInfo_t requestInfo;
+ // To track if memory is allocated for additional header options
+ uint8_t hdrOptionMemAlloc = 0;
+#endif // CA_INT
OC_LOG(INFO, TAG, PCF("Entering OCDoResource"));
goto exit;
}
+#ifdef CA_INT
+ // CA integration logic - TODO: remove this comment after integration is done
+
+ // Assuming request is not multi-cast
+ // Create remote end point
+ caResult = CACreateRemoteEndpoint(newUri, &endpoint);
+ endpoint->connectivityType = CA_WIFI;
+ if (caResult != CA_STATUS_OK)
+ {
+ OC_LOG(ERROR, TAG, PCF("CACreateRemoteEndpoint error"));
+ goto exit;
+ }
+
+ // create token
+ caResult = CAGenerateToken(&caToken);
+
+ if (caResult != CA_STATUS_OK)
+ {
+ OC_LOG(ERROR, TAG, PCF("CAGenerateToken error"));
+ caToken = NULL;
+ goto exit;
+ }
+
+ memset(&requestData, 0, sizeof(CAInfo_t));
+ // TODO-CA: Map QoS to the right CA msg type
+ requestData.type = CA_MSG_CONFIRM;
+ requestData.token = caToken;
+ requestData.options = (CAHeaderOption_t*)options;
+ requestData.numOptions = numOptions;
+ requestData.payload = (char *)request;
+
+ memset(&requestInfo, 0, sizeof(CARequestInfo_t));
+ requestInfo.method = CA_GET;
+ requestInfo.info = requestData;
+
+ // send request
+ caResult = CASendRequest(endpoint, &requestInfo);
+ if (caResult != CA_STATUS_OK)
+ {
+ OC_LOG(ERROR, TAG, PCF("CASendRequest"));
+ goto exit;
+ }
+
+ if((result = AddClientCB(&clientCB, cbData, &caToken, *handle, method,
+ requestUri, resourceType)) != OC_STACK_OK)
+ {
+ result = OC_STACK_NO_MEMORY;
+ goto exit;
+ }
+
+#else // CA_INT
+
// Generate token which will be used by OCStack to match responses received
// with the request
OCGenerateCoAPToken(&token);
// Make call to OCCoAP layer
result = OCDoCoAPResource(method, qos, &token, newUri, request, options, numOptions);
+#endif // CA_INT
exit:
if(newUri != requiredUri)
OC_LOG(ERROR, TAG, PCF("OCDoResource error"));
FindAndDeleteClientCB(clientCB);
}
+#ifdef CA_INT
+ CADestroyRemoteEndpoint(endpoint);
+ if (hdrOptionMemAlloc)
+ {
+ OCFree(requestData.options);
+ }
+ //TODO-CA: CADestroyToken here
+#endif // CA_INT
return result;
}