* @return ::CASTATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
*/
CAResult_t CAAddBlockOption(coap_pdu_t **pdu, const CAInfo_t *info,
- const CAEndpoint_t *endpoint);
+ const CAEndpoint_t *endpoint, coap_list_t **options);
/**
* Write the block option2 in pdu binary data.
* @return ::CASTATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
*/
CAResult_t CAAddBlockOption2(coap_pdu_t **pdu, const CAInfo_t *info, size_t dataLength,
- const CABlockDataID_t *blockID);
+ const CABlockDataID_t *blockID, coap_list_t **options);
/**
* Write the block option1 in pdu binary data.
* @return ::CASTATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
*/
CAResult_t CAAddBlockOption1(coap_pdu_t **pdu, const CAInfo_t *info, size_t dataLength,
- const CABlockDataID_t *blockID);
+ const CABlockDataID_t *blockID, coap_list_t **options);
/**
* Add the block option in pdu data.
* @param[in] blockType block option type.
* @return ::CASTATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
*/
-CAResult_t CAAddBlockOptionImpl(coap_pdu_t *pdu, coap_block_t *block, uint8_t blockType);
+CAResult_t CAAddBlockOptionImpl(coap_pdu_t *pdu, coap_block_t *block, uint8_t blockType,
+ coap_list_t **options);
/**
* Add the size option in pdu data.
* @param[in] dataLength the total payload length to be sent.
* @return ::CASTATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
*/
-CAResult_t CAAddBlockSizeOption(coap_pdu_t *pdu, uint16_t sizeType, size_t dataLength);
+CAResult_t CAAddBlockSizeOption(coap_pdu_t *pdu, uint16_t sizeType, size_t dataLength,
+ coap_list_t **options);
/**
* Get the size option from pdu data.
* @param[in] endpoint endpoint information.
* @return generated pdu.
*/
-coap_pdu_t *CAGeneratePDU(uint32_t code, const CAInfo_t *info, const CAEndpoint_t *endpoint);
+coap_pdu_t *CAGeneratePDU(uint32_t code, const CAInfo_t *info, const CAEndpoint_t *endpoint,
+ coap_list_t **optlist, coap_transport_type *transport);
/**
* extracts request information from received pdu.
* @return generated pdu.
*/
coap_pdu_t *CAGeneratePDUImpl(code_t code, const CAInfo_t *info,
- const CAEndpoint_t *endpoint, coap_list_t *options);
+ const CAEndpoint_t *endpoint, coap_list_t *options,
+ coap_transport_type *transport);
/**
* parse the URI and creates the options.
CAResult_t CAInitBlockWiseMutexVariables()
{
- OIC_LOG(DEBUG, TAG, "IN");
-
if (!g_context.blockDataListMutex)
{
g_context.blockDataListMutex = ca_mutex_new();
void CATerminateBlockWiseMutexVariables()
{
- OIC_LOG(DEBUG, TAG, "IN");
-
if (g_context.blockDataListMutex)
{
ca_mutex_free(g_context.blockDataListMutex);
}
CAResult_t CAAddBlockOption(coap_pdu_t **pdu, const CAInfo_t *info,
- const CAEndpoint_t *endpoint)
+ const CAEndpoint_t *endpoint, coap_list_t **options)
{
OIC_LOG(DEBUG, TAG, "IN-AddBlockOption");
VERIFY_NON_NULL(pdu, TAG, "pdu");
VERIFY_NON_NULL((*pdu)->hdr, TAG, "(*pdu)->hdr");
VERIFY_NON_NULL(info, TAG, "info");
VERIFY_NON_NULL(endpoint, TAG, "endpoint");
+ VERIFY_NON_NULL(options, TAG, "options");
size_t dataLength = 0;
if (info->payload)
OIC_LOG_V(DEBUG, TAG, "previous payload - %s", (*pdu)->data);
+ CAResult_t res = CA_STATUS_OK;
uint32_t code = CA_RESPONSE_CODE((*pdu)->hdr->coap_hdr_udp_t.code);
if (CA_REQUEST_ENTITY_INCOMPLETE == code)
{
OIC_LOG(INFO, TAG, "don't use option");
- return CA_STATUS_OK;
+ return res;
}
CABlockDataID_t* blockDataID = CACreateBlockDatablockId(
if(NULL == blockDataID || NULL == blockDataID->id || blockDataID->idLength < 1)
{
OIC_LOG(ERROR, TAG, "blockId is null");
- CADestroyBlockID(blockDataID);
- return CA_STATUS_FAILED;
+ res = CA_STATUS_FAILED;
+ goto exit;
}
uint8_t blockType = CAGetBlockOptionType(blockDataID);
if (COAP_OPTION_BLOCK2 == blockType)
{
- CAResult_t res = CAAddBlockOption2(pdu, info, dataLength,
- blockDataID);
+ res = CAAddBlockOption2(pdu, info, dataLength, blockDataID, options);
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "add has failed");
- CADestroyBlockID(blockDataID);
- return res;
+ goto exit;
}
}
else if (COAP_OPTION_BLOCK1 == blockType)
{
- CAResult_t res = CAAddBlockOption1(pdu, info, dataLength,
- blockDataID);
+ res = CAAddBlockOption1(pdu, info, dataLength, blockDataID, options);
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "add has failed");
- CADestroyBlockID(blockDataID);
- return res;
+ goto exit;
}
}
else
{
OIC_LOG(DEBUG, TAG, "no BLOCK option");
+
+ // in case it is not large data, add option list to pdu.
+ if (*options)
+ {
+ for (coap_list_t *opt = *options; opt; opt = opt->next)
+ {
+ OIC_LOG_V(DEBUG, TAG, "[%s] opt will be added.",
+ COAP_OPTION_DATA(*(coap_option *) opt->data));
+
+ OIC_LOG_V(DEBUG, TAG, "[%d] pdu length", (*pdu)->length);
+ coap_add_option(*pdu, COAP_OPTION_KEY(*(coap_option *) opt->data),
+ COAP_OPTION_LENGTH(*(coap_option *) opt->data),
+ COAP_OPTION_DATA(*(coap_option *) opt->data), coap_udp);
+ }
+ }
+
+ OIC_LOG_V(DEBUG, TAG, "[%d] pdu length after option", (*pdu)->length);
+
// if response data is so large. it have to send as block transfer
if (!coap_add_data(*pdu, dataLength, (const unsigned char *) info->payload))
{
else
{
OIC_LOG(INFO, TAG, "not Blockwise Transfer");
- CADestroyBlockID(blockDataID);
- return CA_STATUS_OK;
+ goto exit;
}
}
- CAResult_t res = CAUpdateMessageId(*pdu, blockDataID);
+ // if received message type is RESET from remote device,
+ // we have to use the updated message id to find token.
+ res = CAUpdateMessageId(*pdu, blockDataID);
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "fail to update CON message id ");
- CADestroyBlockID(blockDataID);
- return res;
+ goto exit;
}
+exit:
+ if (CA_ADAPTER_IP == endpoint->adapter && 0 == endpoint->port)
+ {
+ CARemoveBlockDataFromList(blockDataID);
+ }
CADestroyBlockID(blockDataID);
OIC_LOG(DEBUG, TAG, "OUT-AddBlockOption");
- return CA_STATUS_OK;
+ return res;
}
CAResult_t CAAddBlockOption2(coap_pdu_t **pdu, const CAInfo_t *info, size_t dataLength,
- const CABlockDataID_t *blockID)
+ const CABlockDataID_t *blockID, coap_list_t **options)
{
OIC_LOG(DEBUG, TAG, "IN-AddBlockOption2");
VERIFY_NON_NULL(pdu, TAG, "pdu");
VERIFY_NON_NULL((*pdu)->hdr, TAG, "(*pdu)->hdr");
VERIFY_NON_NULL(info, TAG, "info");
VERIFY_NON_NULL(blockID, TAG, "blockID");
+ VERIFY_NON_NULL(options, TAG, "options");
// get set block data from CABlock list-set.
coap_block_t *block1 = CAGetBlockOption(blockID,
}
CALogBlockInfo(block2);
- if (block1->num)
+ // if block number is 0, add size2 option
+ if (0 == block2->num)
{
- OIC_LOG(DEBUG, TAG, "combining block1 and block2");
- CAResult_t res = CAAddBlockOptionImpl(*pdu, block1, COAP_OPTION_BLOCK1);
+ res = CAAddBlockSizeOption(*pdu, COAP_OPTION_SIZE2, dataLength, options);
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "add has failed");
CARemoveBlockDataFromList(blockID);
return res;
}
- // initialize block number
- block1->num = 0;
}
- // if block number is 0, add size2 option
- if (0 == block2->num)
+ if (block1->num)
{
- res = CAAddBlockSizeOption(*pdu, COAP_OPTION_SIZE2, dataLength);
+ OIC_LOG(DEBUG, TAG, "combining block1 and block2");
+ CAResult_t res = CAAddBlockOptionImpl(*pdu, block1, COAP_OPTION_BLOCK1, options);
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "add has failed");
CARemoveBlockDataFromList(blockID);
return res;
}
+ // initialize block number
+ block1->num = 0;
}
if (!coap_add_block(*pdu, dataLength, (const unsigned char *) info->payload,
else
{
OIC_LOG(DEBUG, TAG, "option2, not ACK msg");
- CAResult_t res = CAAddBlockOptionImpl(*pdu, block2, COAP_OPTION_BLOCK2);
+ CAResult_t res = CAAddBlockOptionImpl(*pdu, block2, COAP_OPTION_BLOCK2, options);
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "add has failed");
}
CAResult_t CAAddBlockOption1(coap_pdu_t **pdu, const CAInfo_t *info, size_t dataLength,
- const CABlockDataID_t *blockID)
+ const CABlockDataID_t *blockID, coap_list_t **options)
{
OIC_LOG(DEBUG, TAG, "IN-AddBlockOption1");
VERIFY_NON_NULL(pdu, TAG, "pdu");
VERIFY_NON_NULL((*pdu)->hdr, TAG, "(*pdu)->hdr");
VERIFY_NON_NULL(info, TAG, "info");
VERIFY_NON_NULL(blockID, TAG, "blockID");
+ VERIFY_NON_NULL(options, TAG, "options");
// get set block data from CABlock list-set.
coap_block_t *block1 = CAGetBlockOption(blockID, COAP_OPTION_BLOCK1);
if (CA_MSG_ACKNOWLEDGE == (*pdu)->hdr->coap_hdr_udp_t.type)
{
OIC_LOG(DEBUG, TAG, "option1 and ACK msg..");
- CAResult_t res = CAAddBlockOptionImpl(*pdu, block1, COAP_OPTION_BLOCK1);
+ CAResult_t res = CAAddBlockOptionImpl(*pdu, block1, COAP_OPTION_BLOCK1, options);
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "add has failed");
else
{
CAGetMoreBitFromBlock(dataLength, block1);
- CAResult_t res = CAAddBlockOptionImpl(*pdu, block1, COAP_OPTION_BLOCK1);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "add has failed");
- CARemoveBlockDataFromList(blockID);
- return res;
- }
- CALogBlockInfo(block1);
+ CAResult_t res = CA_STATUS_OK;
// if block number is 0, add size1 option
if (0 == block1->num)
{
- res = CAAddBlockSizeOption(*pdu, COAP_OPTION_SIZE1, dataLength);
+ res = CAAddBlockSizeOption(*pdu, COAP_OPTION_SIZE1, dataLength, options);
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "add has failed");
}
}
+ res = CAAddBlockOptionImpl(*pdu, block1, COAP_OPTION_BLOCK1, options);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "add has failed");
+ CARemoveBlockDataFromList(blockID);
+ return res;
+ }
+ CALogBlockInfo(block1);
+
if (!coap_add_block(*pdu, dataLength, (const unsigned char *) info->payload,
block1->num, block1->szx))
{
return CA_STATUS_OK;
}
-CAResult_t CAAddBlockOptionImpl(coap_pdu_t *pdu, coap_block_t *block, uint8_t blockType)
+CAResult_t CAAddBlockOptionImpl(coap_pdu_t *pdu, coap_block_t *block, uint8_t blockType,
+ coap_list_t **options)
{
OIC_LOG(DEBUG, TAG, "IN-AddBlockOptionImpl");
VERIFY_NON_NULL(pdu, TAG, "pdu");
VERIFY_NON_NULL(block, TAG, "block");
+ VERIFY_NON_NULL(options, TAG, "options");
+
+ unsigned char buf[BLOCKWISE_OPTION_BUFFER] = { 0 };
+ unsigned int optionLength = coap_encode_var_bytes(buf,
+ ((block->num << BLOCK_NUMBER_IDX)
+ | (block->m << BLOCK_M_BIT_IDX)
+ | block->szx));
- coap_option *option = (coap_option *) OICMalloc(sizeof(coap_option));
- if (!option)
+ int ret = coap_insert(options,
+ CACreateNewOptionNode(blockType, optionLength, (char *) buf),
+ CAOrderOpts);
+ if (ret <= 0)
{
- OIC_LOG(ERROR, TAG, "out of memory");
- return CA_MEMORY_ALLOC_FAILED;
+ return CA_STATUS_INVALID_PARAM;
}
- unsigned char buf[BLOCKWISE_OPTION_BUFFER] = { 0 };
- option->key = blockType;
- option->length = coap_encode_var_bytes(buf,
- ((block->num << BLOCK_NUMBER_IDX)
- | (block->m << BLOCK_M_BIT_IDX) | block->szx));
- if (!coap_add_option(pdu, option->key, option->length, buf, coap_udp))
- {
- OIC_LOG(ERROR, TAG, "coap_add_option has failed");
- OICFree(option);
- return CA_STATUS_FAILED;
+ // after adding the block option to option list, add option list to pdu.
+ if (*options)
+ {
+ for (coap_list_t *opt = *options; opt; opt = opt->next)
+ {
+ OIC_LOG_V(DEBUG, TAG, "[%s] opt will be added.",
+ COAP_OPTION_DATA(*(coap_option *) opt->data));
+
+ OIC_LOG_V(DEBUG, TAG, "[%d] pdu length", pdu->length);
+ coap_add_option(pdu, COAP_OPTION_KEY(*(coap_option *) opt->data),
+ COAP_OPTION_LENGTH(*(coap_option *) opt->data),
+ COAP_OPTION_DATA(*(coap_option *) opt->data), coap_udp);
+ }
}
- OICFree(option);
+ OIC_LOG_V(DEBUG, TAG, "[%d] pdu length after option", pdu->length);
OIC_LOG(DEBUG, TAG, "OUT-AddBlockOptionImpl");
return CA_STATUS_OK;
}
-CAResult_t CAAddBlockSizeOption(coap_pdu_t *pdu, uint16_t sizeType, size_t dataLength)
+CAResult_t CAAddBlockSizeOption(coap_pdu_t *pdu, uint16_t sizeType, size_t dataLength,
+ coap_list_t **options)
{
OIC_LOG(DEBUG, TAG, "IN-CAAddBlockSizeOption");
VERIFY_NON_NULL(pdu, TAG, "pdu");
+ VERIFY_NON_NULL(options, TAG, "options");
if (sizeType != COAP_OPTION_SIZE1 && sizeType != COAP_OPTION_SIZE2)
{
unsigned char value[BLOCKWISE_OPTION_BUFFER] = { 0 };
unsigned int optionLength = coap_encode_var_bytes(value, dataLength);
- if (!coap_add_option(pdu, sizeType, optionLength, value, coap_udp))
+ int ret = coap_insert(options,
+ CACreateNewOptionNode(sizeType, optionLength, (char *) value),
+ CAOrderOpts);
+ if (ret <= 0)
{
- OIC_LOG(ERROR, TAG, "failed to add size option");
- return CA_STATUS_FAILED;
+ return CA_STATUS_INVALID_PARAM;
}
OIC_LOG(DEBUG, TAG, "OUT-CAAddBlockSizeOption");
#ifdef WITH_BWT
void CAAddDataToSendThread(CAData_t *data)
{
- OIC_LOG(DEBUG, TAG, "IN");
VERIFY_NON_NULL_VOID(data, TAG, "data");
// add thread
CAQueueingThreadAddData(&g_sendThread, data, sizeof(CAData_t));
-
- OIC_LOG(DEBUG, TAG, "OUT");
}
void CAAddDataToReceiveThread(CAData_t *data)
{
- OIC_LOG(DEBUG, TAG, "IN - CAAddDataToReceiveThread");
VERIFY_NON_NULL_VOID(data, TAG, "data");
// add thread
CAQueueingThreadAddData(&g_receiveThread, data, sizeof(CAData_t));
-
- OIC_LOG(DEBUG, TAG, "OUT - CAAddDataToReceiveThread");
}
#endif
static void CATimeoutCallback(const CAEndpoint_t *endpoint, const void *pdu, uint32_t size)
{
- OIC_LOG(DEBUG, TAG, "IN");
VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint");
VERIFY_NON_NULL_VOID(pdu, TAG, "pdu");
#else
CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t));
#endif
-
- OIC_LOG(DEBUG, TAG, "OUT");
}
static void CADestroyData(void *data, uint32_t size)
static void CAReceiveThreadProcess(void *threadData)
{
- OIC_LOG(DEBUG, TAG, "IN");
#ifndef SINGLE_HANDLE
CAData_t *data = (CAData_t *) threadData;
CAProcessReceivedData(data);
#else
(void)threadData;
#endif
- OIC_LOG(DEBUG, TAG, "OUT");
}
#endif
static CAResult_t CAProcessSendData(const CAData_t *data)
{
- OIC_LOG(DEBUG, TAG, "IN");
VERIFY_NON_NULL(data, TAG, "data");
VERIFY_NON_NULL(data->remoteEndpoint, TAG, "remoteEndpoint");
coap_pdu_t *pdu = NULL;
CAInfo_t *info = NULL;
+ coap_list_t *options = NULL;
+ coap_transport_type transport;
if (SEND_TYPE_UNICAST == type)
{
#ifdef ROUTING_GATEWAY
skipRetransmission = data->requestInfo->info.skipRetransmission;
#endif
- pdu = CAGeneratePDU(data->requestInfo->method, info, data->remoteEndpoint);
+ pdu = CAGeneratePDU(data->requestInfo->method, info, data->remoteEndpoint,
+ &options, &transport);
}
else if (NULL != data->responseInfo)
{
#ifdef ROUTING_GATEWAY
skipRetransmission = data->responseInfo->info.skipRetransmission;
#endif
- pdu = CAGeneratePDU(data->responseInfo->result, info, data->remoteEndpoint);
+ pdu = CAGeneratePDU(data->responseInfo->result, info, data->remoteEndpoint,
+ &options, &transport);
}
else
{
if (NULL != info)
{
CAResult_t res = CAAddBlockOption(&pdu, info,
- data->remoteEndpoint);
+ data->remoteEndpoint,
+ &options);
if (CA_STATUS_OK != res)
{
OIC_LOG(INFO, TAG, "to write block option has failed");
CAErrorHandler(data->remoteEndpoint, pdu->hdr, pdu->length, res);
+ coap_delete_list(options);
coap_delete_pdu(pdu);
return res;
}
{
OIC_LOG_V(ERROR, TAG, "send failed:%d", res);
CAErrorHandler(data->remoteEndpoint, pdu->hdr, pdu->length, res);
+ coap_delete_list(options);
coap_delete_pdu(pdu);
return res;
}
{
//when retransmission not supported this will return CA_NOT_SUPPORTED, ignore
OIC_LOG_V(INFO, TAG, "retransmission is not enabled due to error, res : %d", res);
+ coap_delete_list(options);
coap_delete_pdu(pdu);
return res;
}
}
+ coap_delete_list(options);
coap_delete_pdu(pdu);
}
else
OIC_LOG(DEBUG, TAG, "requestInfo is available..");
info = &data->requestInfo->info;
- pdu = CAGeneratePDU(CA_GET, info, data->remoteEndpoint);
+ pdu = CAGeneratePDU(CA_GET, info, data->remoteEndpoint, &options, &transport);
+
if (NULL != pdu)
{
#ifdef WITH_BWT
{
// Blockwise transfer
CAResult_t res = CAAddBlockOption(&pdu, &data->requestInfo->info,
- data->remoteEndpoint);
+ data->remoteEndpoint,
+ &options);
if (CA_STATUS_OK != res)
{
OIC_LOG(DEBUG, TAG, "CAAddBlockOption has failed");
CAErrorHandler(data->remoteEndpoint, pdu->hdr, pdu->length, res);
+ coap_delete_list(options);
coap_delete_pdu(pdu);
return res;
}
OIC_LOG(DEBUG, TAG, "responseInfo is available..");
info = &data->responseInfo->info;
- pdu = CAGeneratePDU(data->responseInfo->result, info, data->remoteEndpoint);
+ pdu = CAGeneratePDU(data->responseInfo->result, info, data->remoteEndpoint,
+ &options, &transport);
if (NULL != pdu)
{
if (NULL != info)
{
CAResult_t res = CAAddBlockOption(&pdu, info,
- data->remoteEndpoint);
+ data->remoteEndpoint,
+ &options);
if (CA_STATUS_OK != res)
{
OIC_LOG(INFO, TAG, "to write block option has failed");
CAErrorHandler(data->remoteEndpoint, pdu->hdr, pdu->length, res);
+ coap_delete_list(options);
coap_delete_pdu(pdu);
return res;
}
{
OIC_LOG_V(ERROR, TAG, "send failed:%d", res);
CAErrorHandler(data->remoteEndpoint, pdu->hdr, pdu->length, res);
+ coap_delete_list(options);
coap_delete_pdu(pdu);
return res;
}
+ coap_delete_list(options);
coap_delete_pdu(pdu);
}
static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep,
const void *data, uint32_t dataLen)
{
- OIC_LOG(DEBUG, TAG, "IN");
VERIFY_NON_NULL_VOID(sep, TAG, "remoteEndpoint");
VERIFY_NON_NULL_VOID(data, TAG, "data");
#endif
coap_delete_pdu(pdu);
-
- OIC_LOG(DEBUG, TAG, "OUT");
}
static void CANetworkChangedCallback(const CAEndpoint_t *info, CANetworkStatus_t status)
CAResult_t CADetachRequestMessage(const CAEndpoint_t *object, const CARequestInfo_t *request)
{
- OIC_LOG(DEBUG, TAG, "IN");
-
VERIFY_NON_NULL(object, TAG, "object");
VERIFY_NON_NULL(request, TAG, "request");
}
#endif
- OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
CAResult_t CADetachResponseMessage(const CAEndpoint_t *object,
const CAResponseInfo_t *response)
{
- OIC_LOG(DEBUG, TAG, "IN");
VERIFY_NON_NULL(object, TAG, "object");
VERIFY_NON_NULL(response, TAG, "response");
}
#endif
- OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
void CASetInterfaceCallbacks(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
CAErrorCallback errorHandler)
{
- OIC_LOG(DEBUG, TAG, "IN");
g_requestHandler = ReqHandler;
g_responseHandler = RespHandler;
g_errorHandler = errorHandler;
- OIC_LOG(DEBUG, TAG, "OUT");
}
CAResult_t CAInitializeMessageHandler()
{
- OIC_LOG(DEBUG, TAG, "IN");
CASetPacketReceivedCallback(CAReceivedPacketCallback);
CASetNetworkChangeCallback(CANetworkChangedCallback);
CAInitializeAdapters();
#endif
- OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
void CATerminateMessageHandler()
{
- OIC_LOG(DEBUG, TAG, "IN");
#ifndef SINGLE_THREAD
CATransportAdapter_t connType;
u_arraylist_t *list = CAGetSelectedNetworkList();
CARetransmissionStop(&g_retransmissionContext);
CARetransmissionDestroy(&g_retransmissionContext);
#endif
-
- OIC_LOG(DEBUG, TAG, "OUT");
}
void CALogPDUInfo(coap_pdu_t *pdu, const CAEndpoint_t *endpoint)
CAResult_t CAGetRequestInfoFromPDU(const coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
CARequestInfo_t *outReqInfo)
{
- OIC_LOG(DEBUG, TAG, "IN");
-
if (NULL == pdu || NULL == outReqInfo)
{
OIC_LOG(ERROR, TAG, "parameter is null");
CAResult_t ret = CAGetInfoFromPDU(pdu, endpoint, &code, &(outReqInfo->info));
outReqInfo->method = code;
- OIC_LOG(DEBUG, TAG, "OUT");
return ret;
}
CAResult_t CAGetResponseInfoFromPDU(const coap_pdu_t *pdu, CAResponseInfo_t *outResInfo,
const CAEndpoint_t *endpoint)
{
- OIC_LOG(DEBUG, TAG, "IN");
-
if (NULL == pdu || NULL == outResInfo)
{
OIC_LOG(ERROR, TAG, "parameter is null");
CAResult_t ret = CAGetInfoFromPDU(pdu, endpoint, &code, &(outResInfo->info));
outResInfo->result = code;
- OIC_LOG(DEBUG, TAG, "OUT");
return ret;
}
CAResult_t CAGetErrorInfoFromPDU(const coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
CAErrorInfo_t *errorInfo)
{
- OIC_LOG(DEBUG, TAG, "IN");
-
if (!pdu)
{
OIC_LOG(ERROR, TAG, "parameter is null");
uint32_t code = 0;
CAResult_t ret = CAGetInfoFromPDU(pdu, endpoint, &code, &errorInfo->info);
- OIC_LOG(DEBUG, TAG, "OUT");
+
return ret;
}
-coap_pdu_t *CAGeneratePDU(uint32_t code, const CAInfo_t *info, const CAEndpoint_t *endpoint)
+coap_pdu_t *CAGeneratePDU(uint32_t code, const CAInfo_t *info, const CAEndpoint_t *endpoint,
+ coap_list_t **optlist, coap_transport_type *transport)
{
- OIC_LOG(DEBUG, TAG, "IN");
-
VERIFY_NON_NULL_RET(info, TAG, "info", NULL);
VERIFY_NON_NULL_RET(endpoint, TAG, "endpoint", NULL);
+ VERIFY_NON_NULL_RET(optlist, TAG, "optlist", NULL);
coap_pdu_t *pdu = NULL;
if (CA_MSG_RESET == info->type || (CA_EMPTY == code && CA_MSG_ACKNOWLEDGE == info->type))
{
OIC_LOG(DEBUG, TAG, "code is empty");
- if (!(pdu = CAGeneratePDUImpl((code_t) code, info, endpoint, NULL)))
+ if (!(pdu = CAGeneratePDUImpl((code_t) code, info, endpoint, NULL, transport)))
{
OIC_LOG(ERROR, TAG, "pdu NULL");
return NULL;
}
else
{
- coap_list_t *optlist = NULL;
-
if (CA_MSG_ACKNOWLEDGE != info->type && info->resourceUri)
{
uint32_t length = strlen(info->resourceUri);
OICStrcat(coapUri, uriLength, info->resourceUri);
// parsing options in URI
- CAResult_t res = CAParseURI(coapUri, &optlist);
+ CAResult_t res = CAParseURI(coapUri, optlist);
if (CA_STATUS_OK != res)
{
- if (optlist)
- {
- coap_delete_list(optlist);
- }
OICFree(coapUri);
return NULL;
}
OICFree(coapUri);
}
// parsing options in HeadOption
- CAResult_t ret = CAParseHeadOption(code, info, &optlist);
+ CAResult_t ret = CAParseHeadOption(code, info, optlist);
if (CA_STATUS_OK != ret)
{
- coap_delete_list(optlist);
return NULL;
}
- pdu = CAGeneratePDUImpl((code_t) code, info, endpoint, optlist);
+ pdu = CAGeneratePDUImpl((code_t) code, info, endpoint, *optlist, transport);
if (NULL == pdu)
{
OIC_LOG(ERROR, TAG, "pdu NULL");
- coap_delete_list(optlist);
return NULL;
}
-
- // free option list
- coap_delete_list(optlist);
}
// pdu print method : coap_show_pdu(pdu);
- OIC_LOG(DEBUG, TAG, "OUT");
return pdu;
}
coap_pdu_t *CAParsePDU(const char *data, uint32_t length, uint32_t *outCode,
const CAEndpoint_t *endpoint)
{
- OIC_LOG(DEBUG, TAG, "IN");
-
if (NULL == data)
{
OIC_LOG(ERROR, TAG, "data is null");
(*outCode) = (uint32_t) CA_RESPONSE_CODE(coap_get_code(outpdu, transport));
}
- OIC_LOG(DEBUG, TAG, "OUT");
return outpdu;
}
coap_pdu_t *CAGeneratePDUImpl(code_t code, const CAInfo_t *info,
- const CAEndpoint_t *endpoint, coap_list_t *options)
+ const CAEndpoint_t *endpoint, coap_list_t *options,
+ coap_transport_type *transport)
{
- OIC_LOG(DEBUG, TAG, "IN");
VERIFY_NON_NULL_RET(info, TAG, "info", NULL);
VERIFY_NON_NULL_RET(endpoint, TAG, "endpoint", NULL);
+ VERIFY_NON_NULL_RET(transport, TAG, "transport", NULL);
- coap_transport_type transport;
unsigned int length = COAP_MAX_PDU_SIZE;
#ifdef TCP_ADAPTER
unsigned int msgLength = 0;
{
msgLength = msgLength + info->payloadSize + PAYLOAD_MARKER;
}
- transport = coap_get_tcp_header_type_from_size(msgLength);
- length = msgLength + coap_get_tcp_header_length_for_transport(transport)
+ *transport = coap_get_tcp_header_type_from_size(msgLength);
+ length = msgLength + coap_get_tcp_header_length_for_transport(*transport)
+ info->tokenLength;
}
else
#endif
{
- transport = coap_udp;
+ *transport = coap_udp;
}
- coap_pdu_t *pdu = coap_new_pdu(transport, length);
+ coap_pdu_t *pdu = coap_new_pdu(*transport, length);
if (NULL == pdu)
{
}
OIC_LOG_V(DEBUG, TAG, "transport type: %d, payload size: %d",
- transport, info->payloadSize);
+ *transport, info->payloadSize);
#ifdef TCP_ADAPTER
if (CA_ADAPTER_TCP == endpoint->adapter)
{
- coap_add_length(pdu, transport, msgLength);
+ coap_add_length(pdu, *transport, msgLength);
}
else
#endif
pdu->hdr->coap_hdr_udp_t.type = info->type;
}
- coap_add_code(pdu, transport, code);
+ coap_add_code(pdu, *transport, code);
if (info->token && CA_EMPTY != code)
{
OIC_LOG_V(DEBUG, TAG, "token info token length: %d, token :", tokenLength);
OIC_LOG_BUFFER(DEBUG, TAG, (const uint8_t *)info->token, tokenLength);
- int32_t ret = coap_add_token(pdu, tokenLength, (unsigned char *)info->token, transport);
+ int32_t ret = coap_add_token(pdu, tokenLength, (unsigned char *)info->token, *transport);
if (0 == ret)
{
OIC_LOG(ERROR, TAG, "can't add token");
}
}
+#ifdef WITH_BWT
+ if (CA_ADAPTER_GATT_BTLE != endpoint->adapter
+#ifdef TCP_ADAPTER
+ && CA_ADAPTER_TCP != endpoint->adapter
+#endif
+ )
+ {
+ // option list will be added in blockwise-transfer
+ return pdu;
+ }
+#endif
+
if (options)
{
for (coap_list_t *opt = options; opt; opt = opt->next)
OIC_LOG_V(DEBUG, TAG, "[%d] pdu length", pdu->length);
coap_add_option(pdu, COAP_OPTION_KEY(*(coap_option *) opt->data),
COAP_OPTION_LENGTH(*(coap_option *) opt->data),
- COAP_OPTION_DATA(*(coap_option *) opt->data), transport);
+ COAP_OPTION_DATA(*(coap_option *) opt->data), *transport);
}
}
OIC_LOG_V(DEBUG, TAG, "[%d] pdu length after option", pdu->length);
- bool enabledPayload = false;
-#ifndef WITH_BWT
- enabledPayload = true;
-#endif
-
- if (enabledPayload || CA_ADAPTER_GATT_BTLE == endpoint->adapter
-#ifdef TCP_ADAPTER
- || CA_ADAPTER_TCP == endpoint->adapter
-#endif
- )
+ if (NULL != info->payload && 0 < info->payloadSize)
{
- if (NULL != info->payload && 0 < info->payloadSize)
- {
- OIC_LOG(DEBUG, TAG, "payload is added");
- coap_add_data(pdu, info->payloadSize, (const unsigned char *) info->payload);
- }
+ OIC_LOG(DEBUG, TAG, "payload is added");
+ coap_add_data(pdu, info->payloadSize, (const unsigned char *) info->payload);
}
- OIC_LOG(DEBUG, TAG, "OUT");
return pdu;
}
CAResult_t CAParseURI(const char *uriInfo, coap_list_t **optlist)
{
- OIC_LOG(DEBUG, TAG, "IN");
-
if (NULL == uriInfo)
{
OIC_LOG(ERROR, TAG, "uriInfo is null");
}
}
- OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
CAResult_t CAParseHeadOption(uint32_t code, const CAInfo_t *info, coap_list_t **optlist)
{
(void)code;
- OIC_LOG(DEBUG, TAG, "IN");
VERIFY_NON_NULL_RET(info, TAG, "info is NULL", CA_STATUS_INVALID_PARAM);
OIC_LOG_V(DEBUG, TAG, "parse Head Opt: %d", info->numOptions);
}
}
- OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
coap_list_t *CACreateNewOptionNode(uint16_t key, uint32_t length, const char *data)
{
- OIC_LOG(DEBUG, TAG, "IN");
-
if (!data)
{
OIC_LOG(ERROR, TAG, "invalid pointer parameter");
return NULL;
}
- OIC_LOG(DEBUG, TAG, "OUT");
return node;
}
int CAOrderOpts(void *a, void *b)
{
- OIC_LOG(DEBUG, TAG, "IN");
if (!a || !b)
{
return a < b ? -1 : 1;
return -1;
}
- OIC_LOG(DEBUG, TAG, "OUT");
return COAP_OPTION_KEY(*(coap_option *) a) == COAP_OPTION_KEY(*(coap_option * ) b);
}
uint32_t CAGetOptionCount(coap_opt_iterator_t opt_iter)
{
- OIC_LOG(DEBUG, TAG, "IN");
uint32_t count = 0;
coap_opt_t *option;
}
}
- OIC_LOG(DEBUG, TAG, "OUT");
return count;
}
CAResult_t CAGetInfoFromPDU(const coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
uint32_t *outCode, CAInfo_t *outInfo)
{
- OIC_LOG(DEBUG, TAG, "IN");
-
if (!pdu || !outCode || !outInfo)
{
OIC_LOG(ERROR, TAG, "NULL pointer param");
}
}
- OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
exit:
CAResult_t CAGetTokenFromPDU(const coap_hdr_t *pdu_hdr, CAInfo_t *outInfo,
const CAEndpoint_t *endpoint)
{
- OIC_LOG(DEBUG, TAG, "IN");
if (NULL == pdu_hdr)
{
OIC_LOG(ERROR, TAG, "pdu_hdr is null");
outInfo->tokenLength = token_length;
- OIC_LOG(DEBUG, TAG, "OUT");
-
return CA_STATUS_OK;
}
CAResult_t CAGenerateTokenInternal(CAToken_t *token, uint8_t tokenLength)
{
- OIC_LOG(DEBUG, TAG, "IN");
-
if (!token)
{
OIC_LOG(ERROR, TAG, "invalid token pointer");
OIC_LOG_V(DEBUG, TAG, "token len:%d, token:", tokenLength);
OIC_LOG_BUFFER(DEBUG, TAG, (const uint8_t *)(*token), tokenLength);
- OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
void CADestroyTokenInternal(CAToken_t token)
{
- OIC_LOG(DEBUG, TAG, "IN");
OICFree(token);
- OIC_LOG(DEBUG, TAG, "OUT");
}
void CADestroyInfo(CAInfo_t *info)
{
- OIC_LOG(DEBUG, TAG, "IN");
-
if (NULL != info)
{
OIC_LOG(DEBUG, TAG, "free options");
OIC_LOG(DEBUG, TAG, "free payload");
OICFree(info->payload);
}
-
- OIC_LOG(DEBUG, TAG, "OUT");
}
uint32_t CAGetOptionData(uint16_t key, const uint8_t *data, uint32_t len,