#define CA_BUFSIZE (128)
#define CA_PDU_MIN_SIZE (4)
-#define CA_PORT_BUFFER_SIZE (4)
+#define CA_ENCODE_BUFFER_SIZE (4)
static const char COAP_URI_HEADER[] = "coap://[::]/";
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);
}
else
-#else
- (void) endpoint;
#endif
{
transport = coap_udp;
if (0 >= ret)
{
OIC_LOG(ERROR, TAG, "pdu parse failed");
- coap_delete_pdu(outpdu);
- return NULL;
+ goto exit;
}
-#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");
}
{
OIC_LOG_V(ERROR, TAG, "coap version is not available : %d",
outpdu->hdr->coap_hdr_udp_t.version);
- coap_delete_pdu(outpdu);
- return NULL;
+ goto exit;
}
if (outpdu->hdr->coap_hdr_udp_t.token_length > CA_MAX_TOKEN_LEN)
{
OIC_LOG_V(ERROR, TAG, "token length has been exceed : %d",
outpdu->hdr->coap_hdr_udp_t.token_length);
- coap_delete_pdu(outpdu);
- return NULL;
+ goto exit;
}
}
}
return outpdu;
+
+exit:
+ coap_delete_pdu(outpdu);
+ return NULL;
}
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)
{
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);
}
#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
)
{
if (uri.port != COAP_DEFAULT_PORT)
{
- unsigned char portbuf[CA_PORT_BUFFER_SIZE] = { 0 };
+ unsigned char portbuf[CA_ENCODE_BUFFER_SIZE] = { 0 };
int ret = coap_insert(optlist,
CACreateNewOptionNode(COAP_OPTION_URI_PORT,
coap_encode_var_bytes(portbuf, uri.port),
if (CA_FORMAT_UNDEFINED != info->payloadFormat)
{
coap_list_t* node = NULL;
- uint8_t buf[3] = {0};
+ uint8_t buf[CA_ENCODE_BUFFER_SIZE] = {0};
switch (info->payloadFormat)
{
case CA_FORMAT_APPLICATION_CBOR:
node = CACreateNewOptionNode(
COAP_OPTION_CONTENT_FORMAT,
- coap_encode_var_bytes(buf, (uint16_t)COAP_MEDIATYPE_APPLICATION_CBOR),
+ coap_encode_var_bytes(buf, (unsigned short)COAP_MEDIATYPE_APPLICATION_CBOR),
(char *)buf);
break;
default:
if (CA_FORMAT_UNDEFINED != info->acceptFormat)
{
coap_list_t* node = NULL;
- uint8_t buf[3] = {0};
+ uint8_t buf[CA_ENCODE_BUFFER_SIZE] = {0};
switch (info->acceptFormat)
{
case CA_FORMAT_APPLICATION_CBOR:
node = CACreateNewOptionNode(
COAP_OPTION_ACCEPT,
- coap_encode_var_bytes(buf, (uint16_t)COAP_MEDIATYPE_APPLICATION_CBOR),
+ coap_encode_var_bytes(buf, (unsigned short)COAP_MEDIATYPE_APPLICATION_CBOR),
(char *)buf);
break;
default:
&& COAP_OPTION_BLOCK1 != opt_iter.type && COAP_OPTION_BLOCK2 != opt_iter.type
&& COAP_OPTION_SIZE1 != opt_iter.type && COAP_OPTION_SIZE2 != opt_iter.type
&& COAP_OPTION_CONTENT_FORMAT != opt_iter.type
- && COAP_OPTION_ACCEPT != opt_iter.type)
+ && COAP_OPTION_ACCEPT != opt_iter.type
+ && COAP_OPTION_URI_HOST != opt_iter.type && COAP_OPTION_URI_PORT != opt_iter.type
+ && COAP_OPTION_ETAG != opt_iter.type && COAP_OPTION_MAXAGE != opt_iter.type
+ && COAP_OPTION_PROXY_URI != opt_iter.type && COAP_OPTION_PROXY_SCHEME != opt_iter.type)
{
count++;
}
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);
}
else
-#else
- (void) endpoint;
#endif
{
transport = coap_udp;
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
{
outInfo->payloadFormat = CA_FORMAT_UNSUPPORTED;
OIC_LOG_V(DEBUG, TAG, "option[%d] has an unsupported format [%d]",
- opt_iter.type, (uint8_t)buf[0]);
+ opt_iter.type, (uint8_t)buf[0]);
}
}
else if (COAP_OPTION_ACCEPT == opt_iter.type)
outInfo->acceptFormat = CA_FORMAT_UNSUPPORTED;
}
OIC_LOG_V(DEBUG, TAG, "option[%d] has an unsupported format [%d]",
- opt_iter.type, (uint8_t)buf[0]);
+ opt_iter.type, (uint8_t)buf[0]);
+ }
+ else if (COAP_OPTION_URI_PORT == opt_iter.type ||
+ COAP_OPTION_URI_HOST == opt_iter.type ||
+ COAP_OPTION_ETAG == opt_iter.type ||
+ COAP_OPTION_MAXAGE == opt_iter.type ||
+ COAP_OPTION_PROXY_URI == opt_iter.type ||
+ COAP_OPTION_PROXY_SCHEME== opt_iter.type)
+ {
+ OIC_LOG_V(INFO, TAG, "option[%d] has an unsupported format [%d]",
+ opt_iter.type, (uint8_t)buf[0]);
}
else
{
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;
OICFree(token);
}
-void CADestroyInfo(CAInfo_t *info)
-{
- if (NULL != info)
- {
- OIC_LOG(DEBUG, TAG, "free options");
- OICFree(info->options);
-
- OIC_LOG(DEBUG, TAG, "free token");
- OICFree(info->token);
-
- OIC_LOG(DEBUG, TAG, "free payload");
- OICFree(info->payload);
- }
-}
-
uint32_t CAGetOptionData(uint16_t key, const uint8_t *data, uint32_t len,
uint8_t *option, uint32_t buflen)
{
return CA_FORMAT_UNSUPPORTED;
}
}
+
+#ifdef WITH_BWT
+bool CAIsSupportedBlockwiseTransfer(CATransportAdapter_t adapter)
+{
+ if (CA_ADAPTER_IP & adapter || CA_ADAPTER_NFC & adapter
+ || CA_DEFAULT_ADAPTER == adapter)
+ {
+ return true;
+ }
+ return false;
+}
+#endif
+
+#ifdef WITH_TCP
+bool CAIsSupportedCoAPOverTCP(CATransportAdapter_t adapter)
+{
+ if (CA_ADAPTER_GATT_BTLE & adapter || CA_ADAPTER_RFCOMM_BTEDR & adapter
+ || CA_ADAPTER_TCP & adapter || CA_DEFAULT_ADAPTER == adapter)
+ {
+ return true;
+ }
+ return false;
+}
+#endif