CAResult_t CAInitializeBlockWiseTransfer(CASendThreadFunc sendThreadFunc,
CAReceiveThreadFunc receivedThreadFunc)
{
- OIC_LOG(DEBUG, TAG, "initialize");
+ OIC_LOG(DEBUG, TAG, "CAInitializeBlockWiseTransfer");
// set block-wise transfer context
if (!g_context.sendThreadFunc)
CAResult_t CATerminateBlockWiseTransfer()
{
- OIC_LOG(DEBUG, TAG, "terminate");
+ OIC_LOG(DEBUG, TAG, "CATerminateBlockWiseTransfer");
if (g_context.dataList)
{
OIC_LOG(DEBUG, TAG, "reset message can't be sent to the block");
return CA_NOT_SUPPORTED;
}
+
+ /*
+ * Other uses of the Block options in conjunction with multicast
+ * messages are for further study.
+ */
+ if (sendData->requestInfo->isMulticast)
+ {
+ OIC_LOG(DEBUG, TAG, "multicast message can't be sent to the block");
+ return CA_NOT_SUPPORTED;
+ }
}
else if (sendData->responseInfo)
{
OIC_LOG(DEBUG, TAG, "reset message can't be sent to the block");
return CA_NOT_SUPPORTED;
}
+ if (sendData->responseInfo->isMulticast)
+ {
+ OIC_LOG(DEBUG, TAG, "multicast message can't be sent to the block");
+ return CA_NOT_SUPPORTED;
+ }
}
// #1. check if it is already included in block data list
}
}
- // check if there is error code
+ // if there is no block option in pdu, check if there is error code.
if (!isBlock1 && !isBlock2)
{
+ CABlockDataID_t* blockDataID = CACreateBlockDatablockId(
+ (CAToken_t)pdu->hdr->coap_hdr_udp_t.token,
+ pdu->hdr->coap_hdr_udp_t.token_length,
+ endpoint->port);
+ if (NULL == blockDataID || blockDataID->idLength < 1)
+ {
+ OIC_LOG(ERROR, TAG, "blockId is null");
+ CADestroyBlockID(blockDataID);
+ return CA_STATUS_FAILED;
+ }
+
uint32_t code = CA_RESPONSE_CODE(pdu->hdr->coap_hdr_udp_t.code);
if (CA_REQUEST_ENTITY_INCOMPLETE == code)
{
- CABlockDataID_t* blockDataID = CACreateBlockDatablockId(
- (CAToken_t)pdu->hdr->coap_hdr_udp_t.token,
- pdu->hdr->coap_hdr_udp_t.token_length,
- endpoint->port);
- if (NULL == blockDataID || blockDataID->idLength < 1)
+ CABlockData_t *data = CAGetBlockDataFromBlockDataList(blockDataID);
+ if (!data)
{
- OIC_LOG(ERROR, TAG, "blockId is null");
+ OIC_LOG(ERROR, TAG, "getting has failed");
CADestroyBlockID(blockDataID);
return CA_STATUS_FAILED;
}
- CABlockData_t *data = CAGetBlockDataFromBlockDataList(blockDataID);
- if (!data)
+ coap_block_t *block = CAGetBlockOption(blockDataID, data->type);
+ if (!block)
{
- OIC_LOG(ERROR, TAG, "getting has failed");
+ OIC_LOG(ERROR, TAG, "block is null");
CADestroyBlockID(blockDataID);
return CA_STATUS_FAILED;
}
+ CAResult_t res = CA_STATUS_OK;
if (COAP_OPTION_BLOCK2 == data->type)
{
- coap_block_t *block2 = CAGetBlockOption(blockDataID, COAP_OPTION_BLOCK2);
- if (!block2)
- {
- OIC_LOG(ERROR, TAG, "block is null");
- CADestroyBlockID(blockDataID);
- return CA_STATUS_FAILED;
- }
-
- CAResult_t res = CASetNextBlockOption2(pdu, endpoint, receivedData, *block2,
- dataLen);
+ res = CASetNextBlockOption2(pdu, endpoint, receivedData, *block, dataLen);
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "setting has failed");
}
else if (COAP_OPTION_BLOCK1 == data->type)
{
- coap_block_t *block1 = CAGetBlockOption(blockDataID, COAP_OPTION_BLOCK1);
- if (!block1)
- {
- OIC_LOG(ERROR, TAG, "block is null");
- CADestroyBlockID(blockDataID);
- return CA_STATUS_FAILED;
- }
-
- CAResult_t res = CASetNextBlockOption1(pdu, endpoint, receivedData, *block1,
- dataLen);
+ res = CASetNextBlockOption1(pdu, endpoint, receivedData, *block, dataLen);
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "setting has failed");
return res;
}
}
- else
- {
- CADestroyBlockID(blockDataID);
- return CA_STATUS_FAILED;
- }
+ CADestroyBlockID(blockDataID);
}
else
{
// and sent data remain in block data list, remove block data
if (receivedData->responseInfo)
{
- CABlockDataID_t* blockDataID = CACreateBlockDatablockId(
- (CAToken_t)pdu->hdr->coap_hdr_udp_t.token,
- pdu->hdr->coap_hdr_udp_t.token_length,
- endpoint->port);
- if (NULL == blockDataID || blockDataID->idLength < 1)
- {
- OIC_LOG(ERROR, TAG, "blockId is null");
- CADestroyBlockID(blockDataID);
- return CA_STATUS_FAILED;
- }
-
CARemoveBlockDataFromList(blockDataID);
- CADestroyBlockID(blockDataID);
}
+ CADestroyBlockID(blockDataID);
return CA_NOT_SUPPORTED;
}
}
-
return CA_STATUS_OK;
}
// check the blcok-wise transfer status for next step
if (CA_BLOCK_UNKNOWN == blockWiseStatus || CA_BLOCK_RECEIVED_ALREADY == blockWiseStatus)
{
- if (0 == block.m) // Last block is received
+ OIC_LOG_V(DEBUG, TAG, "M bit is %d", block.m);
+
+ if (0 == block.m)
{
- OIC_LOG(DEBUG, TAG, "M bit is 0");
+ // Last block is received
blockWiseStatus = CA_OPTION1_REQUEST_LAST_BLOCK;
}
else
{
- OIC_LOG(DEBUG, TAG, "M bit is 1");
blockWiseStatus = CA_OPTION1_REQUEST_BLOCK;
}
}
goto exit;
}
- uint32_t code = (*pdu)->hdr->coap_hdr_udp_t.code;
- if (CA_GET == code || CA_POST == code || CA_PUT == code || CA_DELETE == code)
+ uint32_t repCode = CA_RESPONSE_CODE((*pdu)->hdr->coap_hdr_udp_t.code);
+ if (CA_REQUEST_ENTITY_INCOMPLETE == repCode)
{
- // if received message type is RESET from remote device,
- // we have to use the updated message id of request message to find token.
- res = CAUpdateMessageId(*pdu, blockDataID);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "fail to update message id");
- goto exit;
- }
- }
- else
- {
- uint32_t repCode = CA_RESPONSE_CODE((*pdu)->hdr->coap_hdr_udp_t.code);
- if (CA_REQUEST_ENTITY_INCOMPLETE == repCode)
- {
- OIC_LOG(INFO, TAG, "don't use option");
- res = CA_STATUS_OK;
- goto exit;
- }
+ OIC_LOG(INFO, TAG, "don't use option");
+ res = CA_STATUS_OK;
+ goto exit;
}
uint8_t blockType = CAGetBlockOptionType(blockDataID);
}
}
-exit:
- if (CA_ADAPTER_IP == endpoint->adapter && 0 == endpoint->port)
+ uint32_t code = (*pdu)->hdr->coap_hdr_udp_t.code;
+ if (CA_GET == code || CA_POST == code || CA_PUT == code || CA_DELETE == code)
{
- CARemoveBlockDataFromList(blockDataID);
+ // if received message type is RESET from remote device,
+ // we have to use the updated message id of request message to find token.
+ res = CAUpdateMessageId(*pdu, blockDataID);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "fail to update message id");
+ goto exit;
+ }
}
+
+exit:
CADestroyBlockID(blockDataID);
OIC_LOG(DEBUG, TAG, "OUT-AddBlockOption");
return res;
}
}
+ // add block option to option list.
res = CAAddBlockOptionImpl(block1, COAP_OPTION_BLOCK1, options);
if (CA_STATUS_OK != res)
{
goto exit;
}
+ // add option list to pdu.
res = CAAddOptionToPDU(*pdu, options);
if (CA_STATUS_OK != res)
{
goto exit;
}
+ // add the payload data as the block size.
if (!coap_add_block(*pdu, dataLength, (const unsigned char *) info->payload, block1->num,
block1->szx))
{
else
{
OIC_LOG(DEBUG, TAG, "received response message with block option1");
+
+ // add block option to option list.
res = CAAddBlockOptionImpl(block1, COAP_OPTION_BLOCK1, options);
if (CA_STATUS_OK != res)
{
goto exit;
}
+ // add option list to pdu.
res = CAAddOptionToPDU(*pdu, options);
if (CA_STATUS_OK != res)
{
goto exit;
}
+ // add the payload data as the block size.
if (!coap_add_data(*pdu, dataLength, (const unsigned char *) info->payload))
{
OIC_LOG(ERROR, TAG, "failed to add payload");
return CA_STATUS_FAILED;
}
- // reset block-list after write block
+ // if it is last block message, remove block data from list.
if (0 == block1->m)
{
// remove data from list
for (size_t i = 0; i < len; i++)
{
CABlockData_t *currData = (CABlockData_t *) u_arraylist_get(g_context.dataList, i);
-
if (!currData)
{
continue;
{
return &currData->block2;
}
- else
+ else if (COAP_OPTION_BLOCK1 == blockType)
{
return &currData->block1;
}
}
// destroy memory
- if (currData->sentData)
- {
- CADestroyDataSet(currData->sentData);
- }
+ CADestroyDataSet(currData->sentData);
CADestroyBlockID(currData->blockDataId);
OICFree(currData->payload);
OICFree(currData);