Commit a29612e9 authored by Nathan Heldt-Sheller's avatar Nathan Heldt-Sheller Committed by Aleksey

[IOT-3261] force content version to 1.0.0

IoTivity should never send Content-Format-Version or
Content-Format-Accept-Version higher than 1.0.0 (per
Specification 2.0.1).  This change forces the outgoing
values to be at most 1.0.0, regardless of what is in
the request header.

Change-Id: I9153993bb8200bb828202c9716dede609fcd5048
Signed-off-by: Nathan Heldt-Sheller's avatarNathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
parent d2c1e975
......@@ -142,6 +142,7 @@ extern "C"
// The Accept Version and Content-Format Version for OCF 1.0.0 (0b0000 1000 0000 0000).
#define DEFAULT_VERSION_VALUE 2048
#define MAX_VERSION_VALUE DEFAULT_VERSION_VALUE /**< only one version supported as of Spec v2.0.1 */
/**
* Option numbers for Signaling messages are specific to the message code.
......
......@@ -119,6 +119,8 @@ coap_pdu_t *CAGeneratePDU(uint32_t code, const CAInfo_t *info, const CAEndpoint_
VERIFY_NON_NULL_RET(endpoint, TAG, "endpoint", NULL);
VERIFY_NON_NULL_RET(optlist, TAG, "optlist", NULL);
OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
OIC_LOG_V(DEBUG, TAG, "generate pdu for [%d]adapter, [%d]flags",
endpoint->adapter, endpoint->flags);
......@@ -195,6 +197,8 @@ coap_pdu_t *CAGeneratePDU(uint32_t code, const CAInfo_t *info, const CAEndpoint_
}
}
OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
// pdu print method : coap_show_pdu(pdu);
return pdu;
}
......@@ -551,6 +555,7 @@ CAResult_t CAParseHeadOption(uint32_t code, const CAInfo_t *info, coap_list_t **
{
(void)code;
VERIFY_NON_NULL_RET(info, TAG, "info", CA_STATUS_INVALID_PARAM);
OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
OIC_LOG_V(DEBUG, TAG, "parse Head Opt: %d", info->numOptions);
......@@ -598,14 +603,31 @@ CAResult_t CAParseHeadOption(uint32_t code, const CAInfo_t *info, coap_list_t **
// insert one extra header with the payload format if applicable.
if (CA_FORMAT_UNDEFINED != info->payloadFormat)
{
CAParsePayloadFormatHeadOption(COAP_OPTION_CONTENT_FORMAT, info->payloadFormat, CA_OPTION_CONTENT_VERSION, info->payloadVersion, optlist);
OIC_LOG_V(DEBUG, TAG, "%s: info->payloadFormat = %d; info->payloadVersion = %d", __func__, info->payloadFormat, info->payloadVersion);
// IoTivity should not send a message with an OCF-Content-Format-Version greater than 1.0.0, per Spec v2.0.1
uint16_t contentFormatVersion = info->payloadVersion;
if(MAX_VERSION_VALUE < contentFormatVersion)
{
contentFormatVersion = MAX_VERSION_VALUE;
}
OIC_LOG_V(DEBUG, TAG, "%s: set contentFormatVersion = %d", __func__, contentFormatVersion);
CAParsePayloadFormatHeadOption(COAP_OPTION_CONTENT_FORMAT, info->payloadFormat, CA_OPTION_CONTENT_VERSION, contentFormatVersion, optlist);
}
if (CA_FORMAT_UNDEFINED != info->acceptFormat)
{
CAParsePayloadFormatHeadOption(COAP_OPTION_ACCEPT, info->acceptFormat, CA_OPTION_ACCEPT_VERSION, info->acceptVersion, optlist);
OIC_LOG_V(DEBUG, TAG, "%s: info->acceptVersion = %d", __func__, info->acceptVersion);
// IoTivity should not send a message with an OCF-Content-Format-Accept-Version greater than 1.0.0, per Spec v2.0.1
uint16_t contentFormatAcceptVersion = info->acceptVersion;
if(MAX_VERSION_VALUE < contentFormatAcceptVersion)
{
contentFormatAcceptVersion = MAX_VERSION_VALUE;
}
OIC_LOG_V(DEBUG, TAG, "%s: set contentFormatAcceptVersion = %d", __func__, contentFormatAcceptVersion);
CAParsePayloadFormatHeadOption(COAP_OPTION_ACCEPT, info->acceptFormat, CA_OPTION_ACCEPT_VERSION, contentFormatAcceptVersion, optlist);
}
OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
return CA_STATUS_OK;
}
......@@ -617,6 +639,8 @@ CAResult_t CAParsePayloadFormatHeadOption(uint16_t formatOption, CAPayloadFormat
uint8_t encodeBuf[CA_ENCODE_BUFFER_SIZE] = { 0 };
uint8_t versionBuf[CA_ENCODE_BUFFER_SIZE] = { 0 };
OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
switch (format)
{
case CA_FORMAT_APPLICATION_CBOR:
......@@ -668,6 +692,7 @@ CAResult_t CAParsePayloadFormatHeadOption(uint16_t formatOption, CAPayloadFormat
return CA_STATUS_INVALID_PARAM;
}
}
OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
return CA_STATUS_OK;
}
......@@ -1131,6 +1156,7 @@ CAResult_t CAGetInfoFromPDU(const coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
exit:
OIC_LOG(ERROR, TAG, "buffer too small");
OIC_LOG_V(ERROR, TAG, "%s: ERROR EXIT", __func__);
OICFree(outInfo->options);
OICFree(optionResult);
return CA_STATUS_FAILED;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment