#endif
static void CADestroyData(void *data, uint32_t size);
static void CALogPayloadInfo(CAInfo_t *info);
-static bool CADropSecondMessage(CAHistory_t *history, const CAEndpoint_t *endpoint, uint16_t id);
+static bool CADropSecondMessage(CAHistory_t *history, const CAEndpoint_t *endpoint, uint16_t id,
+ CAToken_t token, uint8_t tokenLength);
#ifdef WITH_BWT
void CAAddDataToSendThread(CAData_t *data)
return NULL;
}
- result = CAGetResponseInfoFromPDU(data, resInfo);
+ result = CAGetResponseInfoFromPDU(data, resInfo, endpoint);
if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, TAG, "CAGetResponseInfoFromPDU Failed");
return NULL;
}
- result = CAGetRequestInfoFromPDU(data, reqInfo);
+ result = CAGetRequestInfoFromPDU(data, endpoint, reqInfo);
if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, TAG, "CAGetRequestInfoFromPDU failed");
return NULL;
}
- if (CADropSecondMessage(&caglobals.ca.requestHistory, endpoint, reqInfo->info.messageId))
+ if (CADropSecondMessage(&caglobals.ca.requestHistory, endpoint, reqInfo->info.messageId,
+ reqInfo->info.token, reqInfo->info.tokenLength))
{
OIC_LOG(ERROR, TAG, "Second Request with same Token, Drop it");
CAFreeEndpoint(ep);
return NULL;
}
- CAResult_t result = CAGetErrorInfoFromPDU(data, errorInfo);
+ CAResult_t result = CAGetErrorInfoFromPDU(data, endpoint, errorInfo);
if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, TAG, "CAGetErrorInfoFromPDU failed");
resInfo->info.type = CAGetMessageTypeFromPduBinaryData(pdu, size);
resInfo->info.messageId = CAGetMessageIdFromPduBinaryData(pdu, size);
- CAResult_t res = CAGetTokenFromPDU((const coap_hdr_t *) pdu, &(resInfo->info));
+ CAResult_t res = CAGetTokenFromPDU((const coap_hdr_t *) pdu, &(resInfo->info),
+ endpoint);
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "fail to get Token from retransmission list");
if (SEND_TYPE_UNICAST == type)
{
-
OIC_LOG(DEBUG,TAG,"Unicast message");
+#ifdef ROUTING_GATEWAY
+ /*
+ * When forwarding a packet, do not attempt retransmission as its the responsibility of
+ * packet originator node
+ */
+ bool skipRetransmission = false;
+#endif
+
if (NULL != data->requestInfo)
{
OIC_LOG(DEBUG, TAG, "requestInfo is available..");
info = &data->requestInfo->info;
+#ifdef ROUTING_GATEWAY
+ skipRetransmission = data->requestInfo->info.skipRetransmission;
+#endif
pdu = CAGeneratePDU(data->requestInfo->method, info, data->remoteEndpoint);
}
else if (NULL != data->responseInfo)
OIC_LOG(DEBUG, TAG, "responseInfo is available..");
info = &data->responseInfo->info;
+#ifdef ROUTING_GATEWAY
+ skipRetransmission = data->responseInfo->info.skipRetransmission;
+#endif
pdu = CAGeneratePDU(data->responseInfo->result, info, data->remoteEndpoint);
}
else
if (NULL != pdu)
{
#ifdef WITH_BWT
- if (CA_ADAPTER_GATT_BTLE != data->remoteEndpoint->adapter)
+ if (CA_ADAPTER_GATT_BTLE != data->remoteEndpoint->adapter
+#ifdef TCP_ADAPTER
+ && CA_ADAPTER_TCP != data->remoteEndpoint->adapter
+#endif
+ )
{
// Blockwise transfer
if (NULL != info)
}
}
#endif
- CALogPDUInfo(pdu);
+ CALogPDUInfo(pdu, data->remoteEndpoint);
res = CASendUnicastData(data->remoteEndpoint, pdu->hdr, pdu->length);
if (CA_STATUS_OK != res)
coap_delete_pdu(pdu);
return res;
}
- // for retransmission
- res = CARetransmissionSentData(&g_retransmissionContext, data->remoteEndpoint, pdu->hdr,
- pdu->length);
- if ((CA_STATUS_OK != res) && (CA_NOT_SUPPORTED != res))
+
+#ifdef TCP_ADAPTER
+ if (CA_ADAPTER_TCP == data->remoteEndpoint->adapter)
{
- //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_pdu(pdu);
- return res;
+ OIC_LOG(INFO, TAG, "retransmission will be not worked");
+ }
+ else
+#endif
+#ifdef ROUTING_GATEWAY
+ if(!skipRetransmission)
+#endif
+ {
+ // for retransmission
+ res = CARetransmissionSentData(&g_retransmissionContext, data->remoteEndpoint, pdu->hdr,
+ pdu->length);
+ if ((CA_STATUS_OK != res) && (CA_NOT_SUPPORTED != 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_pdu(pdu);
+ return res;
+ }
}
coap_delete_pdu(pdu);
if (NULL != pdu)
{
#ifdef WITH_BWT
- if (CA_ADAPTER_GATT_BTLE != data->remoteEndpoint->adapter)
+ if (CA_ADAPTER_GATT_BTLE != data->remoteEndpoint->adapter
+#ifdef TCP_ADAPTER
+ && CA_ADAPTER_TCP != data->remoteEndpoint->adapter
+#endif
+ )
{
// Blockwise transfer
CAResult_t res = CAAddBlockOption(&pdu, data->requestInfo->info,
}
}
#endif
- CALogPDUInfo(pdu);
+ }
+ else
+ {
+ OIC_LOG(ERROR,TAG,"Failed to generate multicast PDU");
+ CASendErrorInfo(data->remoteEndpoint, info, CA_SEND_FAILED);
+ return CA_SEND_FAILED;
+ }
+ }
+ else if (NULL != data->responseInfo)
+ {
+ OIC_LOG(DEBUG, TAG, "responseInfo is available..");
- res = CASendMulticastData(data->remoteEndpoint, pdu->hdr, pdu->length);
- if (CA_STATUS_OK != res)
+ info = &data->responseInfo->info;
+ pdu = CAGeneratePDU(data->responseInfo->result, info, data->remoteEndpoint);
+
+ if (NULL != pdu)
+ {
+#ifdef WITH_BWT
+ if (CA_ADAPTER_GATT_BTLE != data->remoteEndpoint->adapter
+#ifdef TCP_ADAPTER
+ && CA_ADAPTER_TCP != data->remoteEndpoint->adapter
+#endif
+ )
{
- OIC_LOG_V(ERROR, TAG, "send failed:%d", res);
- CAErrorHandler(data->remoteEndpoint, pdu->hdr, pdu->length, res);
- coap_delete_pdu(pdu);
- return res;
+ // Blockwise transfer
+ if (NULL != info)
+ {
+ CAResult_t res = CAAddBlockOption(&pdu, *info,
+ data->remoteEndpoint);
+ 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_pdu(pdu);
+ return res;
+ }
+ }
}
-
- coap_delete_pdu(pdu);
+#endif
}
else
{
}
else
{
- OIC_LOG(ERROR, TAG, "request info is empty");
+ OIC_LOG(ERROR, TAG, "request or response info is empty");
return CA_SEND_FAILED;
}
+
+ CALogPDUInfo(pdu, data->remoteEndpoint);
+
+ OIC_LOG(DEBUG, TAG, "pdu to send :");
+ OIC_LOG_BUFFER(DEBUG, TAG, pdu->hdr, pdu->length);
+
+ res = CASendMulticastData(data->remoteEndpoint, pdu->hdr, pdu->length);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG_V(ERROR, TAG, "send failed:%d", res);
+ CAErrorHandler(data->remoteEndpoint, pdu->hdr, pdu->length, res);
+ coap_delete_pdu(pdu);
+ return res;
+ }
+
+ coap_delete_pdu(pdu);
}
- OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
#endif
/*
- * If a second message arrives with the same token and the other address
+ * If a second message arrives with the same message ID, token and the other address
* family, drop it. Typically, IPv6 beats IPv4, so the IPv4 message is dropped.
*/
-static bool CADropSecondMessage(CAHistory_t *history, const CAEndpoint_t *ep, uint16_t id)
+static bool CADropSecondMessage(CAHistory_t *history, const CAEndpoint_t *ep, uint16_t id,
+ CAToken_t token, uint8_t tokenLength)
{
if (!ep)
{
return false;
}
+ if (tokenLength > CA_MAX_TOKEN_LEN)
+ {
+ /*
+ * If token length is more than CA_MAX_TOKEN_LEN,
+ * we compare the first CA_MAX_TOKEN_LEN bytes only.
+ */
+ tokenLength = CA_MAX_TOKEN_LEN;
+ }
+
bool ret = false;
CATransportFlags_t familyFlags = ep->flags & CA_IPFAMILY_MASK;
for (size_t i = 0; i < sizeof(history->items) / sizeof(history->items[0]); i++)
{
CAHistoryItem_t *item = &(history->items[i]);
- if (id == item->messageId)
+ if (id == item->messageId && tokenLength == item->tokenLength
+ && memcmp(item->token, token, tokenLength) == 0)
{
if ((familyFlags ^ item->flags) == CA_IPFAMILY_MASK)
{
history->items[history->nextIndex].flags = familyFlags;
history->items[history->nextIndex].messageId = id;
+ if (token && tokenLength)
+ {
+ memcpy(history->items[history->nextIndex].token, token, tokenLength);
+ history->items[history->nextIndex].tokenLength = tokenLength;
+ }
+
if (++history->nextIndex >= HISTORYSIZE)
{
history->nextIndex = 0;
VERIFY_NON_NULL_VOID(sep, TAG, "remoteEndpoint");
VERIFY_NON_NULL_VOID(data, TAG, "data");
+ OIC_LOG(DEBUG, TAG, "received pdu data :");
+ OIC_LOG_BUFFER(DEBUG, TAG, data, dataLen);
+
uint32_t code = CA_NOT_FOUND;
CAData_t *cadata = NULL;
- coap_pdu_t *pdu = (coap_pdu_t *) CAParsePDU((const char *) data, dataLen, &code);
+ coap_pdu_t *pdu = (coap_pdu_t *) CAParsePDU((const char *) data, dataLen, &code,
+ &(sep->endpoint));
if (NULL == pdu)
{
OIC_LOG(ERROR, TAG, "Parse PDU failed");
return;
}
- // for retransmission
- void *retransmissionPdu = NULL;
- CARetransmissionReceivedData(&g_retransmissionContext, cadata->remoteEndpoint, pdu->hdr,
- pdu->length, &retransmissionPdu);
-
- // get token from saved data in retransmission list
- if (retransmissionPdu && CA_EMPTY == code)
+#ifdef TCP_ADAPTER
+ if (CA_ADAPTER_TCP == sep->endpoint.adapter)
+ {
+ OIC_LOG(INFO, TAG, "retransmission is not supported");
+ }
+ else
+#endif
{
- if (cadata->responseInfo)
+ // for retransmission
+ void *retransmissionPdu = NULL;
+ CARetransmissionReceivedData(&g_retransmissionContext, cadata->remoteEndpoint, pdu->hdr,
+ pdu->length, &retransmissionPdu);
+
+ // get token from saved data in retransmission list
+ if (retransmissionPdu && CA_EMPTY == code)
{
- CAInfo_t *info = &cadata->responseInfo->info;
- CAResult_t res = CAGetTokenFromPDU((const coap_hdr_t *)retransmissionPdu,
- info);
- if (CA_STATUS_OK != res)
+ if (cadata->responseInfo)
{
- OIC_LOG(ERROR, TAG, "fail to get Token from retransmission list");
- OICFree(info->token);
- info->tokenLength = 0;
+ CAInfo_t *info = &cadata->responseInfo->info;
+ CAResult_t res = CAGetTokenFromPDU((const coap_hdr_t *)retransmissionPdu,
+ info, &(sep->endpoint));
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "fail to get Token from retransmission list");
+ OICFree(info->token);
+ info->tokenLength = 0;
+ }
}
}
+ OICFree(retransmissionPdu);
}
- OICFree(retransmissionPdu);
}
cadata->type = SEND_TYPE_UNICAST;
CAProcessReceivedData(cadata);
#else
#ifdef WITH_BWT
- if (CA_ADAPTER_GATT_BTLE != sep->endpoint.adapter)
+ if (CA_ADAPTER_GATT_BTLE != sep->endpoint.adapter
+#ifdef TCP_ADAPTER
+ && CA_ADAPTER_TCP != sep->endpoint.adapter
+#endif
+ )
{
CAResult_t res = CAReceiveBlockWiseData(pdu, &(sep->endpoint), cadata, dataLen);
if (CA_NOT_SUPPORTED == res)
return NULL;
}
- cadata->type = SEND_TYPE_UNICAST;
+ cadata->type = response->isMulticast ? SEND_TYPE_MULTICAST : SEND_TYPE_UNICAST;
cadata->responseInfo = response;
}
else
CADestroyData(data, sizeof(CAData_t));
#else
#ifdef WITH_BWT
- if (CA_ADAPTER_GATT_BTLE != object->adapter)
+ if (CA_ADAPTER_GATT_BTLE != object->adapter
+#ifdef TCP_ADAPTER
+ && CA_ADAPTER_TCP != object->adapter
+#endif
+ )
{
// send block data
CAResult_t res = CASendBlockWiseData(data);
CADestroyData(data, sizeof(CAData_t));
#else
#ifdef WITH_BWT
- if (CA_ADAPTER_GATT_BTLE != object->adapter)
+ if (CA_ADAPTER_GATT_BTLE != object->adapter
+#ifdef TCP_ADAPTER
+ && CA_ADAPTER_TCP != object->adapter
+#endif
+ )
{
// send block data
CAResult_t res = CASendBlockWiseData(data);
OIC_LOG(DEBUG, TAG, "OUT");
}
-void CALogPDUInfo(coap_pdu_t *pdu)
+void CALogPDUInfo(coap_pdu_t *pdu, const CAEndpoint_t *endpoint)
{
VERIFY_NON_NULL_VOID(pdu, TAG, "pdu");
OIC_LOG_V(DEBUG, TAG, "PDU Maker - payload : %s", pdu->data);
- OIC_LOG_V(DEBUG, TAG, "PDU Maker - type : %d", pdu->hdr->type);
+#ifdef TCP_ADAPTER
+ if (CA_ADAPTER_TCP == endpoint->adapter)
+ {
+ OIC_LOG(DEBUG, TAG, "pdu header data :");
+ OIC_LOG_BUFFER(DEBUG, TAG, pdu->hdr, pdu->length);
+ }
+ else
+#endif
+ {
+ OIC_LOG_V(DEBUG, TAG, "PDU Maker - type : %d", pdu->hdr->coap_hdr_udp_t.type);
- OIC_LOG_V(DEBUG, TAG, "PDU Maker - code : %d", pdu->hdr->code);
+ OIC_LOG_V(DEBUG, TAG, "PDU Maker - code : %d", pdu->hdr->coap_hdr_udp_t.code);
- OIC_LOG(DEBUG, TAG, "PDU Maker - token :");
+ OIC_LOG(DEBUG, TAG, "PDU Maker - token :");
- OIC_LOG_BUFFER(DEBUG, TAG, pdu->hdr->token, pdu->hdr->token_length);
+ OIC_LOG_BUFFER(DEBUG, TAG, pdu->hdr->coap_hdr_udp_t.token,
+ pdu->hdr->coap_hdr_udp_t.token_length);
+ }
}
static void CALogPayloadInfo(CAInfo_t *info)
uint32_t code = CA_NOT_FOUND;
//Do not free remoteEndpoint and data. Currently they will be freed in data thread
//Get PDU data
- coap_pdu_t *pdu = (coap_pdu_t *)CAParsePDU((const char *)data, dataLen, &code);
+ coap_pdu_t *pdu = (coap_pdu_t *)CAParsePDU((const char *)data, dataLen, &code, endpoint);
if (NULL == pdu)
{
OIC_LOG(ERROR, TAG, "Parse PDU failed");