From d26e1cbfe95f790dcfb6db5ab3985e6805ded3b6 Mon Sep 17 00:00:00 2001 From: "jihwan.seo" Date: Thu, 11 Feb 2016 08:56:24 +0900 Subject: [PATCH] CoAP over TCP transmission over BLE there is another header for fragmentation is added in CoAP PDU. since CoAP over TCP has message length field, it is better to apply to BLE Change-Id: I35f174f85a114abc5521c42cd6b25eda02cd9f6e Signed-off-by: jihwan.seo Reviewed-on: https://gerrit.iotivity.org/gerrit/4979 Tested-by: jenkins-iotivity Reviewed-by: Jon A. Cruz --- resource/csdk/connectivity/inc/caprotocolmessage.h | 9 ++ .../csdk/connectivity/lib/libcoap-4.1.1/SConscript | 8 +- resource/csdk/connectivity/src/SConscript | 5 +- .../connectivity/src/bt_le_adapter/caleadapter.c | 117 +++++++++++---------- resource/csdk/connectivity/src/camessagehandler.c | 32 +++--- resource/csdk/connectivity/src/caprotocolmessage.c | 48 +++++---- 6 files changed, 125 insertions(+), 94 deletions(-) diff --git a/resource/csdk/connectivity/inc/caprotocolmessage.h b/resource/csdk/connectivity/inc/caprotocolmessage.h index 29b5478..ef88ebe 100644 --- a/resource/csdk/connectivity/inc/caprotocolmessage.h +++ b/resource/csdk/connectivity/inc/caprotocolmessage.h @@ -253,6 +253,15 @@ CAResponseResult_t CAGetCodeFromPduBinaryData(const void *pdu, uint32_t size); */ CAPayloadFormat_t CAConvertFormat(uint8_t format); +#ifdef WITH_TCP +/** + * check whether CoAP over TCP is supported or not. + * @param[in] adapter transport adapter type. + * @return true or false. + */ +bool CAIsSupportedCoAPOverTCP(CATransportAdapter_t adapter); +#endif + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/resource/csdk/connectivity/lib/libcoap-4.1.1/SConscript b/resource/csdk/connectivity/lib/libcoap-4.1.1/SConscript index 1aed354..c538721 100644 --- a/resource/csdk/connectivity/lib/libcoap-4.1.1/SConscript +++ b/resource/csdk/connectivity/lib/libcoap-4.1.1/SConscript @@ -37,12 +37,14 @@ if target_os not in ['windows', 'winrt']: libcoap_env.AppendUnique(CFLAGS = ['-Wall', '-ffunction-sections', '-fdata-sections', '-fno-exceptions']) -if target_os in ['linux', 'tizen', 'android']: +if target_os in ['linux', 'tizen', 'android', 'ios']: if with_tcp == True: libcoap_env.AppendUnique(CPPDEFINES = ['WITH_TCP']) -if target_os == 'android': +if target_os in ['linux', 'tizen', 'android', 'arduino']: libcoap_env.AppendUnique(LIBS = ['log']) + if (('BLE' in ca_transport) or ('BT' in ca_transport) or ('ALL' in ca_transport)): + libcoap_env.AppendUnique(CPPDEFINES = ['WITH_TCP']) if target_os == 'arduino': libcoap_env.AppendUnique(CPPDEFINES = ['NDEBUG', 'WITH_ARDUINO']) @@ -74,4 +76,4 @@ libcoap_src = [ libcoap = libcoap_env.StaticLibrary('libcoap', libcoap_src, OBJPREFIX='libcoap_') -libcoap_env.InstallTarget([libcoap], 'libcoap') +libcoap_env.InstallTarget([libcoap], 'libcoap') \ No newline at end of file diff --git a/resource/csdk/connectivity/src/SConscript b/resource/csdk/connectivity/src/SConscript index 29197e3..d2a50aa 100755 --- a/resource/csdk/connectivity/src/SConscript +++ b/resource/csdk/connectivity/src/SConscript @@ -139,6 +139,10 @@ if ca_os in ['linux', 'tizen', 'android']: env.SConscript(os.path.join(ca_path, 'tcp_adapter/SConscript')) env.AppendUnique(CPPDEFINES = ['WITH_TCP']) +if ca_os in ['linux', 'tizen', 'android', 'arduino', 'ios']: + if (('BLE' in ca_transport) or ('BT' in ca_transport) or ('ALL' in ca_transport)): + env.AppendUnique(CPPDEFINES = ['WITH_TCP']) + print "Include path is %s" % env.get('CPPPATH') print "Files path is %s" % env.get('CA_SRC') if ca_os in ['android', 'tizen']: @@ -152,4 +156,3 @@ if ca_os in ['android', 'tizen']: else: calib = env.StaticLibrary('connectivity_abstraction', env.get('CA_SRC')) env.InstallTarget(calib, 'libconnectivity_abstraction') - diff --git a/resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c b/resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c index 20f0f60..b24df4e 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c @@ -33,6 +33,7 @@ #include "oic_malloc.h" #include "oic_string.h" #include "caremotehandler.h" +#include "pdu.h" /** * Logging tag for module name. @@ -550,6 +551,21 @@ static void CALEClearSenderInfo() CALEClearSenderInfoImpl(&g_bleClientSenderInfo); } +static size_t CAGetMessageLengthFromData(const unsigned char *recvBuffer) +{ + coap_transport_type transport = coap_get_tcp_header_type_from_initbyte( + ((unsigned char *)recvBuffer)[0] >> 4); + size_t optPaylaodLen = coap_get_length_from_header((unsigned char *)recvBuffer, + transport); + size_t headerLen = coap_get_tcp_header_length((unsigned char *)recvBuffer); + + OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "option/paylaod length [%d]", optPaylaodLen); + OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "header length [%d]", headerLen); + OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "total data length [%d]", headerLen + optPaylaodLen); + + return headerLen + optPaylaodLen; +} + static CAResult_t CAInitLEClientSenderQueue() { OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN - CAInitLEClientSenderQueue"); @@ -713,8 +729,9 @@ static void CALEDataReceiverHandler(void *threadData) newSender->remoteEndpoint = NULL; OIC_LOG(DEBUG, CALEADAPTER_TAG, "Parsing the header"); - newSender->totalDataLen = CAParseHeader(bleData->data, - bleData->dataLen); + + newSender->totalDataLen = CAGetMessageLengthFromData(bleData->data); + if(!(newSender->totalDataLen)) { OIC_LOG(ERROR, CALEADAPTER_TAG, "Total Data Length is parsed as 0!!!"); @@ -752,10 +769,20 @@ static void CALEDataReceiverHandler(void *threadData) ca_mutex_unlock(g_bleReceiveDataMutex); return; } - memcpy(newSender->defragData, bleData->data + CA_HEADER_LENGTH, - bleData->dataLen - CA_HEADER_LENGTH); - newSender->recvDataLen += bleData->dataLen - CA_HEADER_LENGTH; - u_arraylist_add(bleData->senderInfo, (void *)newSender); + + if (newSender->recvDataLen + bleData->dataLen > newSender->totalDataLen) + { + OIC_LOG(ERROR, CALEADAPTER_TAG, "buffer is smaller than received data"); + OICFree(newSender->defragData); + CAFreeEndpoint(newSender->remoteEndpoint); + OICFree(newSender); + ca_mutex_unlock(g_bleReceiveDataMutex); + return; + } + memcpy(newSender->defragData, bleData->data, bleData->dataLen); + newSender->recvDataLen += bleData->dataLen; + + u_arraylist_add(bleData->senderInfo,(void *)newSender); //Getting newSender index position in bleSenderInfo array list if(CA_STATUS_OK != @@ -840,10 +867,7 @@ static void CALEServerSendDataThread(void *threadData) return; } - uint8_t * const header = OICCalloc(CA_HEADER_LENGTH, 1); - VERIFY_NON_NULL_VOID(header, CALEADAPTER_TAG, "Malloc failed"); - - const uint32_t totalLength = bleData->dataLen + CA_HEADER_LENGTH; + const uint32_t totalLength = bleData->dataLen; OIC_LOG_V(DEBUG, CALEADAPTER_TAG, @@ -855,39 +879,24 @@ static void CALEServerSendDataThread(void *threadData) if (NULL == dataSegment) { OIC_LOG(ERROR, CALEADAPTER_TAG, "Malloc failed"); - OICFree(header); - return; - } - - CAResult_t result = CAGenerateHeader(header, - CA_HEADER_LENGTH, - bleData->dataLen); - if (CA_STATUS_OK != result ) - { - OIC_LOG(ERROR, CALEADAPTER_TAG, "Generate header failed"); - OICFree(header); - OICFree(dataSegment); return; } - memcpy(dataSegment, header, CA_HEADER_LENGTH); - OICFree(header); - uint32_t length = 0; if (CA_SUPPORTED_BLE_MTU_SIZE > totalLength) { length = totalLength; - memcpy(dataSegment + CA_HEADER_LENGTH, bleData->data, bleData->dataLen); + memcpy(dataSegment, bleData->data, bleData->dataLen); } else { length = CA_SUPPORTED_BLE_MTU_SIZE; - memcpy(dataSegment + CA_HEADER_LENGTH, bleData->data, - CA_SUPPORTED_BLE_MTU_SIZE - CA_HEADER_LENGTH); + memcpy(dataSegment, bleData->data, CA_SUPPORTED_BLE_MTU_SIZE); } uint32_t iter = totalLength / CA_SUPPORTED_BLE_MTU_SIZE; uint32_t index = 0; + CAResult_t result = CA_STATUS_FAILED; // Send the first segment with the header. if (NULL != bleData->remoteEndpoint) // Sending Unicast Data @@ -927,8 +936,9 @@ static void CALEServerSendDataThread(void *threadData) result = CAUpdateCharacteristicsToGattClient( bleData->remoteEndpoint->addr, - bleData->data + ((index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH), + bleData->data + ((index * CA_SUPPORTED_BLE_MTU_SIZE)), CA_SUPPORTED_BLE_MTU_SIZE); + if (CA_STATUS_OK != result) { OIC_LOG_V(ERROR, CALEADAPTER_TAG, @@ -949,10 +959,12 @@ static void CALEServerSendDataThread(void *threadData) // send the last segment of the data (Ex: 22 bytes of 622 // bytes of data when MTU is 200) OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk"); + result = CAUpdateCharacteristicsToGattClient( bleData->remoteEndpoint->addr, - bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH, + bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE), remainingLen); + if (CA_STATUS_OK != result) { OIC_LOG_V(ERROR, @@ -986,9 +998,11 @@ static void CALEServerSendDataThread(void *threadData) { // Send the remaining header. OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Sending the chunk number [%d]", index); + result = CAUpdateCharacteristicsToAllGattClients( - bleData->data + ((index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH), + bleData->data + ((index * CA_SUPPORTED_BLE_MTU_SIZE)), CA_SUPPORTED_BLE_MTU_SIZE); + if (CA_STATUS_OK != result) { OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]", @@ -1006,9 +1020,11 @@ static void CALEServerSendDataThread(void *threadData) { // send the last segment of the data OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk"); + result = CAUpdateCharacteristicsToAllGattClients( - bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH, + bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE), remainingLen); + if (CA_STATUS_OK != result) { OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]", @@ -1036,47 +1052,32 @@ static void CALEClientSendDataThread(void *threadData) return; } - uint8_t * const header = OICCalloc(CA_HEADER_LENGTH, 1); - VERIFY_NON_NULL_VOID(header, CALEADAPTER_TAG, "Malloc failed"); + const uint32_t totalLength = bleData->dataLen; - const uint32_t totalLength = bleData->dataLen + CA_HEADER_LENGTH; uint8_t *dataSegment = OICCalloc(totalLength, 1); if (NULL == dataSegment) { OIC_LOG(ERROR, CALEADAPTER_TAG, "Malloc failed"); - OICFree(header); return; } - CAResult_t result = CAGenerateHeader(header, - CA_HEADER_LENGTH, - bleData->dataLen); - if (CA_STATUS_OK != result ) - { - OIC_LOG(ERROR, CALEADAPTER_TAG, "Generate header failed"); - OICFree(header); - OICFree(dataSegment); - return ; - } - memcpy(dataSegment, header, CA_HEADER_LENGTH); - OICFree(header); - uint32_t length = 0; if (CA_SUPPORTED_BLE_MTU_SIZE > totalLength) { length = totalLength; - memcpy(dataSegment + CA_HEADER_LENGTH, + memcpy(dataSegment, bleData->data, bleData->dataLen); } else { length = CA_SUPPORTED_BLE_MTU_SIZE; - memcpy(dataSegment + CA_HEADER_LENGTH, + memcpy(dataSegment, bleData->data, - CA_SUPPORTED_BLE_MTU_SIZE - CA_HEADER_LENGTH); + CA_SUPPORTED_BLE_MTU_SIZE); } + CAResult_t result = CA_STATUS_FAILED; const uint32_t iter = totalLength / CA_SUPPORTED_BLE_MTU_SIZE; uint32_t index = 0; if (NULL != bleData->remoteEndpoint) //Sending Unicast Data @@ -1115,9 +1116,10 @@ static void CALEClientSendDataThread(void *threadData) // Send the remaining header. result = CAUpdateCharacteristicsToGattServer( bleData->remoteEndpoint->addr, - bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH, + bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE), CA_SUPPORTED_BLE_MTU_SIZE, LE_UNICAST, 0); + if (CA_STATUS_OK != result) { OIC_LOG_V(ERROR, @@ -1138,9 +1140,10 @@ static void CALEClientSendDataThread(void *threadData) // send the last segment of the data (Ex: 22 bytes of 622 // bytes of data when MTU is 200) OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk"); + result = CAUpdateCharacteristicsToGattServer( bleData->remoteEndpoint->addr, - bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH, + bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE), remainingLen, LE_UNICAST, 0); @@ -1174,8 +1177,9 @@ static void CALEClientSendDataThread(void *threadData) for (index = 1; index < iter; index++) { result = CAUpdateCharacteristicsToAllGattServers( - bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH, + bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE), CA_SUPPORTED_BLE_MTU_SIZE); + if (CA_STATUS_OK != result) { OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]", @@ -1196,8 +1200,9 @@ static void CALEClientSendDataThread(void *threadData) OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk"); result = CAUpdateCharacteristicsToAllGattServers( - bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH, + bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE), remainingLen); + if (CA_STATUS_OK != result) { OIC_LOG_V(ERROR, CALEADAPTER_TAG, diff --git a/resource/csdk/connectivity/src/camessagehandler.c b/resource/csdk/connectivity/src/camessagehandler.c index f2a51ca..1be8168 100644 --- a/resource/csdk/connectivity/src/camessagehandler.c +++ b/resource/csdk/connectivity/src/camessagehandler.c @@ -451,8 +451,8 @@ static CAResult_t CAProcessSendData(const CAData_t *data) { #ifdef WITH_BWT if (CA_ADAPTER_GATT_BTLE != data->remoteEndpoint->adapter -#ifdef TCP_ADAPTER - && CA_ADAPTER_TCP != data->remoteEndpoint->adapter +#ifdef WITH_TCP + && !CAIsSupportedCoAPOverTCP(data->remoteEndpoint->adapter) #endif ) { @@ -485,8 +485,8 @@ static CAResult_t CAProcessSendData(const CAData_t *data) return res; } -#ifdef TCP_ADAPTER - if (CA_ADAPTER_TCP == data->remoteEndpoint->adapter) +#ifdef WITH_TCP + if (CAIsSupportedCoAPOverTCP(data->remoteEndpoint->adapter)) { OIC_LOG(INFO, TAG, "retransmission will be not worked"); } @@ -533,8 +533,8 @@ static CAResult_t CAProcessSendData(const CAData_t *data) { #ifdef WITH_BWT if (CA_ADAPTER_GATT_BTLE != data->remoteEndpoint->adapter -#ifdef TCP_ADAPTER - && CA_ADAPTER_TCP != data->remoteEndpoint->adapter +#ifdef WITH_TCP + && !CAIsSupportedCoAPOverTCP(data->remoteEndpoint->adapter) #endif ) { @@ -572,8 +572,8 @@ static CAResult_t CAProcessSendData(const CAData_t *data) { #ifdef WITH_BWT if (CA_ADAPTER_GATT_BTLE != data->remoteEndpoint->adapter -#ifdef TCP_ADAPTER - && CA_ADAPTER_TCP != data->remoteEndpoint->adapter +#ifdef WITH_TCP + && !CAIsSupportedCoAPOverTCP(data->remoteEndpoint->adapter) #endif ) { @@ -743,8 +743,8 @@ static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep, return; } -#ifdef TCP_ADAPTER - if (CA_ADAPTER_TCP == sep->endpoint.adapter) +#ifdef WITH_TCP + if (CAIsSupportedCoAPOverTCP(sep->endpoint.adapter)) { OIC_LOG(INFO, TAG, "retransmission is not supported"); } @@ -783,8 +783,8 @@ static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep, #else #ifdef WITH_BWT if (CA_ADAPTER_GATT_BTLE != sep->endpoint.adapter -#ifdef TCP_ADAPTER - && CA_ADAPTER_TCP != sep->endpoint.adapter +#ifdef WITH_TCP + && !CAIsSupportedCoAPOverTCP(sep->endpoint.adapter) #endif ) { @@ -968,8 +968,8 @@ CAResult_t CADetachSendMessage(const CAEndpoint_t *endpoint, const void *sendMsg #else #ifdef WITH_BWT if (CA_ADAPTER_GATT_BTLE != endpoint->adapter -#ifdef TCP_ADAPTER - && CA_ADAPTER_TCP != endpoint->adapter +#ifdef WITH_TCP + && !CAIsSupportedCoAPOverTCP(data->remoteEndpoint->adapter) #endif ) { @@ -1216,8 +1216,8 @@ void CALogPDUInfo(coap_pdu_t *pdu, const CAEndpoint_t *endpoint) OIC_LOG_V(DEBUG, TAG, "PDU Maker - payload : %s", pdu->data); -#ifdef TCP_ADAPTER - if (CA_ADAPTER_TCP == endpoint->adapter) +#ifdef WITH_TCP + if (CAIsSupportedCoAPOverTCP(endpoint->adapter)) { OIC_LOG(DEBUG, TAG, "pdu header data :"); OIC_LOG_BUFFER(DEBUG, TAG, (const uint8_t *) pdu->hdr, pdu->length); diff --git a/resource/csdk/connectivity/src/caprotocolmessage.c b/resource/csdk/connectivity/src/caprotocolmessage.c index be9b41a..2d2a2f2 100644 --- a/resource/csdk/connectivity/src/caprotocolmessage.c +++ b/resource/csdk/connectivity/src/caprotocolmessage.c @@ -177,8 +177,8 @@ coap_pdu_t *CAParsePDU(const char *data, uint32_t length, uint32_t *outCode, VERIFY_NON_NULL_RET(endpoint, TAG, "endpoint", NULL); coap_transport_type transport; -#ifdef TCP_ADAPTER - if (CA_ADAPTER_TCP == endpoint->adapter) +#ifdef WITH_TCP + if (CAIsSupportedCoAPOverTCP(endpoint->adapter)) { transport = coap_get_tcp_header_type_from_initbyte(((unsigned char *)data)[0] >> 4); } @@ -208,8 +208,8 @@ coap_pdu_t *CAParsePDU(const char *data, uint32_t length, uint32_t *outCode, return NULL; } -#ifdef TCP_ADAPTER - if (CA_ADAPTER_TCP == endpoint->adapter) +#ifdef WITH_TCP + if (CAIsSupportedCoAPOverTCP(endpoint->adapter)) { OIC_LOG(INFO, TAG, "there is no version info in coap header"); } @@ -249,9 +249,9 @@ coap_pdu_t *CAGeneratePDUImpl(code_t code, const CAInfo_t *info, VERIFY_NON_NULL_RET(transport, TAG, "transport", NULL); unsigned int length = COAP_MAX_PDU_SIZE; -#ifdef TCP_ADAPTER +#ifdef WITH_TCP unsigned int msgLength = 0; - if (CA_ADAPTER_TCP == endpoint->adapter) + if (CAIsSupportedCoAPOverTCP(endpoint->adapter)) { if (options) { @@ -305,8 +305,8 @@ coap_pdu_t *CAGeneratePDUImpl(code_t code, const CAInfo_t *info, OIC_LOG_V(DEBUG, TAG, "transport type: %d, payload size: %zu", *transport, info->payloadSize); -#ifdef TCP_ADAPTER - if (CA_ADAPTER_TCP == endpoint->adapter) +#ifdef WITH_TCP + if (CAIsSupportedCoAPOverTCP(endpoint->adapter)) { coap_add_length(pdu, *transport, msgLength); } @@ -350,8 +350,8 @@ coap_pdu_t *CAGeneratePDUImpl(code_t code, const CAInfo_t *info, #ifdef WITH_BWT if (CA_ADAPTER_GATT_BTLE != endpoint->adapter -#ifdef TCP_ADAPTER - && CA_ADAPTER_TCP != endpoint->adapter +#ifdef WITH_TCP + && !CAIsSupportedCoAPOverTCP(endpoint->adapter) #endif ) { @@ -689,8 +689,8 @@ CAResult_t CAGetInfoFromPDU(const coap_pdu_t *pdu, const CAEndpoint_t *endpoint, VERIFY_NON_NULL(outInfo, TAG, "outInfo"); coap_transport_type transport; -#ifdef TCP_ADAPTER - if (CA_ADAPTER_TCP == endpoint->adapter) +#ifdef WITH_TCP + if (CAIsSupportedCoAPOverTCP(endpoint->adapter)) { transport = coap_get_tcp_header_type_from_initbyte(((unsigned char *)pdu->hdr)[0] >> 4); } @@ -716,14 +716,16 @@ CAResult_t CAGetInfoFromPDU(const coap_pdu_t *pdu, const CAEndpoint_t *endpoint, outInfo->numOptions = count; -#ifdef TCP_ADAPTER - if (CA_ADAPTER_TCP == endpoint->adapter) +#ifdef WITH_TCP + if (CAIsSupportedCoAPOverTCP(endpoint->adapter)) { // set type outInfo->type = CA_MSG_NONCONFIRM; outInfo->payloadFormat = CA_FORMAT_UNDEFINED; } else +#else + (void) endpoint; #endif { // set type @@ -951,14 +953,12 @@ CAResult_t CAGetTokenFromPDU(const coap_hdr_t *pdu_hdr, CAInfo_t *outInfo, VERIFY_NON_NULL(endpoint, TAG, "endpoint"); coap_transport_type transport; -#ifdef TCP_ADAPTER - if (CA_ADAPTER_TCP == endpoint->adapter) +#ifdef WITH_TCP + if (CAIsSupportedCoAPOverTCP(endpoint->adapter)) { transport = coap_get_tcp_header_type_from_initbyte(((unsigned char *)pdu_hdr)[0] >> 4); } else -#else - (void) endpoint; #endif { transport = coap_udp; @@ -1138,3 +1138,15 @@ CAPayloadFormat_t CAConvertFormat(uint8_t format) return CA_FORMAT_UNSUPPORTED; } } + +#ifdef WITH_TCP +bool CAIsSupportedCoAPOverTCP(CATransportAdapter_t adapter) +{ + if (CA_ADAPTER_GATT_BTLE == adapter || CA_ADAPTER_RFCOMM_BTEDR == adapter + || CA_ADAPTER_TCP == adapter) + { + return true; + } + return false; +} +#endif -- 2.7.4