# structs for non-legacy compilers.
# - warning C4214: bit field types other than int
# - Disabled due to IoTivity not being ANSI compatible
+ # - warning C4221: nonstandard extension used: 'identifier' cannot be initialized using address of automatic variable
+ # - Disabled due to IoTivity not being ANSI compatible
# - warning C4232: nonstandard extension used: 'read': address of dllimport 'fread' is not static, identity not guaranteed
# - fread, frwrite, etc are provided by the platform and cannot be changed.
# - warning C4706: assignment within conditional expression
# - Disabled due to the widespread usage in IoTivity and low impact.
- env.AppendUnique(CCFLAGS=['/wd4127', '/wd4200', '/wd4201', '/wd4204', '/wd4214', '/wd4232', '/wd4706'])
+ env.AppendUnique(CCFLAGS=['/wd4127', '/wd4200', '/wd4201', '/wd4204', '/wd4214', '/wd4221', '/wd4232', '/wd4706'])
env.AppendUnique(CCFLAGS=['/EHsc'])
# define UINT16_MAX 65535
#endif
+/**
+ * Mark a parameter as unused. Used to prevent unused variable compiler warnings.
+ */
+#define OC_UNUSED(x) (void)(x)
+
#endif
print "MQ flag is %s" % with_mq
if target_os in ['msys_nt', 'windows']:
- connectivity_env.AppendUnique(CCFLAGS=['/W3', '/WX'])
+ connectivity_env.AppendUnique(CCFLAGS=['/W4', '/WX'])
targets_disallow_multitransport = ['arduino']
* @param[out] optlist options information.
* @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h).
*/
-CAResult_t CAParseUriPartial(const unsigned char *str, size_t length, int target,
+CAResult_t CAParseUriPartial(const unsigned char *str, size_t length, uint16_t target,
coap_list_t **optlist);
/**
/**
* number of options count.
* @param[in] opt_iter option iteration for count.
- * @return number of options.
+ * @param[out] optionCount number of options.
+ * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h).
*/
-uint32_t CAGetOptionCount(coap_opt_iterator_t opt_iter);
+CAResult_t CAGetOptionCount(coap_opt_iterator_t opt_iter, uint8_t *optionCount);
/**
* gets option data.
*
* @param[in] data Data to be send.
* @param[in] dlen Total data length.
- * @return Payload length
+ * @return Payload length or 0 on error.
*/
size_t CACheckPayloadLengthFromHeader(const void *data, size_t dlen);
typedef struct {
int code;
- int alert;
+ unsigned char alert;
} CrtVerifyAlert_t;
static const CrtVerifyAlert_t crtVerifyAlerts[] = {
{0, 0}
};
-static int GetAlertCode(uint32_t flags)
+static unsigned char GetAlertCode(uint32_t flags)
{
const CrtVerifyAlert_t *cur;
size_t dataToSend = (dataLen > INT_MAX) ? INT_MAX : dataLen;
CAPacketSendCallback sendCallback = g_caSslContext->adapterCallbacks[adapterIndex].sendCallback;
sentLen = sendCallback(&(((SslEndPoint_t * )tep)->sep.endpoint), (const void *) data, dataToSend);
- if (sentLen != dataLen)
+ if (0 > sentLen)
+ {
+ OIC_LOG(ERROR, NET_SSL_TAG, "Error sending packet. The error will be reported in the adapter.");
+ }
+ else if ((size_t)sentLen != dataLen)
{
OIC_LOG_V(DEBUG, NET_SSL_TAG,
"Packet was partially sent - sent/total/remained bytes : %d/%" PRIuPTR "/%" PRIuPTR,
{
int ret;
OIC_LOG_V(DEBUG, NET_SSL_TAG, "In %s", __func__);
- VERIFY_NON_NULL_RET(crt, NET_SSL_TAG, "Param crt is NULL" , -1);
- VERIFY_NON_NULL_RET(buf, NET_SSL_TAG, "Param buf is NULL" , -1);
+ VERIFY_NON_NULL_RET(crt, NET_SSL_TAG, "Param crt is NULL", -1);
+ VERIFY_NON_NULL_RET(buf, NET_SSL_TAG, "Param buf is NULL", -1);
if (NULL != errNum)
{
{
*errNum = ret;
}
-
+
ret = 0;
for (const mbedtls_x509_crt *cur = crt; cur != NULL; cur = cur->next)
{
ret++;
}
-
+
OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__);
return ret;
}
const char* str,
unsigned char msg)
{
+ OC_UNUSED(str);
+
if ((0 != ret) &&
(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY != ret) &&
(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED != ret) &&
OIC_LOG_V(DEBUG, NET_SSL_TAG, "In %s", __func__);
VERIFY_NON_NULL_RET(g_caSslContext, NET_SSL_TAG, "SSL context is not initialized." , CA_STATUS_NOT_INITIALIZED);
- CAResult_t res = CA_STATUS_FAILED;
SslCipher_t index = GetCipherIndex(cipher);
if (SSL_CIPHER_MAX == index)
{
const char *addr, uint16_t port, ssize_t sentLen,
bool isSuccess, const char* message)
{
+#ifndef TB_LOG
+ OC_UNUSED(addr);
+ OC_UNUSED(port);
+ OC_UNUSED(sentLen);
+ OC_UNUSED(message);
+#endif
+
OIC_LOG(DEBUG, CA_ADAPTER_UTILS_TAG, "CALogSendStateInfo");
OIC_LOG(DEBUG, ANALYZER_TAG, "=================================================");
static ssize_t CALESecureSendDataCB(CAEndpoint_t *endpoint,
const void *data, size_t dataLen)
{
- VERIFY_NON_NULL_RET(endpoint, CALEADAPTER_TAG, "endpoint is NULL", 0);
- VERIFY_NON_NULL_RET(data, CALEADAPTER_TAG, "data is NULL", 0);
+ VERIFY_NON_NULL_RET(endpoint, CALEADAPTER_TAG, "endpoint is NULL", -1);
+ VERIFY_NON_NULL_RET(data, CALEADAPTER_TAG, "data is NULL", -1);
OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Secure Data Send - encrypted datalen = %d", dataLen);
{
g_errorHandler(endpoint, data, dataLen, result);
}
- return 0;
+ return -1;
}
}
else if (ADAPTER_CLIENT == g_adapterType ||
{
g_errorHandler(endpoint, data, dataLen, result);
}
- return 0;
+ return -1;
}
}
else
{
OIC_LOG_V(ERROR, CALEADAPTER_TAG,
"Can't Send Message adapterType = %d, dataType = %d", g_adapterType, dataType);
- return 0;
+ return -1;
}
return (ssize_t)dataLen;
return CA_STATUS_FAILED;
}
- coap_block_t *block = CAGetBlockOption(blockDataID, data->type);
- if (!block)
+ coap_block_t *tempBlock = CAGetBlockOption(blockDataID, data->type);
+ if (!tempBlock)
{
- OIC_LOG(ERROR, TAG, "block is null");
+ OIC_LOG(ERROR, TAG, "tempBlock is null");
CADestroyBlockID(blockDataID);
return CA_STATUS_FAILED;
}
CAResult_t res = CA_STATUS_OK;
if (COAP_OPTION_BLOCK2 == data->type)
{
- res = CASetNextBlockOption2(pdu, endpoint, receivedData, *block, dataLen);
+ res = CASetNextBlockOption2(pdu, endpoint, receivedData, *tempBlock, dataLen);
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "setting has failed");
}
else if (COAP_OPTION_BLOCK1 == data->type)
{
- res = CASetNextBlockOption1(pdu, endpoint, receivedData, *block, dataLen);
+ res = CASetNextBlockOption1(pdu, endpoint, receivedData, *tempBlock, dataLen);
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "setting has failed");
else
{
// received message type is response
- uint32_t code = CA_RESPONSE_CODE(pdu->transport_hdr->udp.code);
- if (0 == block.m && (CA_REQUEST_ENTITY_INCOMPLETE != code
- && CA_REQUEST_ENTITY_TOO_LARGE != code))
+ uint32_t responseCode = CA_RESPONSE_CODE(pdu->transport_hdr->udp.code);
+ if (0 == block.m && (CA_REQUEST_ENTITY_INCOMPLETE != responseCode
+ && CA_REQUEST_ENTITY_TOO_LARGE != responseCode))
{
int isBlock2 = coap_get_block(pdu, COAP_OPTION_BLOCK2, &block);
if (isBlock2)
COAP_OPTION_SIZE2,
&(data->payloadLength));
- uint32_t code = CA_RESPONSE_CODE(pdu->transport_hdr->udp.code);
- if (CA_REQUEST_ENTITY_INCOMPLETE != code && CA_REQUEST_ENTITY_TOO_LARGE != code)
+ uint32_t responseCode = CA_RESPONSE_CODE(pdu->transport_hdr->udp.code);
+ if (CA_REQUEST_ENTITY_INCOMPLETE != responseCode && CA_REQUEST_ENTITY_TOO_LARGE != responseCode)
{
// check if received payload is exact
blockWiseStatus = CACheckBlockErrorType(data, &block, receivedData,
goto exit;
}
+ assert(block2->szx <= UINT8_MAX);
if (!coap_add_block(*pdu, (unsigned int)dataLength,
(const unsigned char *) info->payload,
- block2->num, block2->szx))
+ block2->num, (unsigned char)block2->szx))
{
OIC_LOG(ERROR, TAG, "Data length is smaller than the start index");
return CA_STATUS_FAILED;
}
// add the payload data as the block size.
+ assert(block1->szx <= UINT8_MAX);
if (!coap_add_block(*pdu, (unsigned int)dataLength,
(const unsigned char *) info->payload, block1->num,
- block1->szx))
+ (unsigned char)block1->szx))
{
OIC_LOG(ERROR, TAG, "Data length is smaller than the start index");
return CA_STATUS_FAILED;
sentDataLen = g_adapterHandler[index].sendData(endpoint, data, length, dataType);
}
- if (sentDataLen != length)
+ if ((0 > sentDataLen) || ((uint32_t)sentDataLen != length))
{
- OIC_LOG(ERROR, TAG, "error in sending data. Error will be reported in adapter");
+ OIC_LOG(ERROR, TAG, "Error sending data. The error will be reported in adapter.");
#ifdef SINGLE_THREAD
//in case of single thread, no error handler. Report error immediately
return CA_SEND_FAILED;
// Blockwise transfer
if (NULL != info)
{
- CAResult_t res = CAAddBlockOption(&pdu, info,
- data->remoteEndpoint,
- &options);
+ res = CAAddBlockOption(&pdu, info, data->remoteEndpoint, &options);
if (CA_STATUS_OK != res)
{
OIC_LOG(INFO, TAG, "to write block option has failed");
}
}
- size_t payloadLen = (pdu->data) ? (unsigned char *) pdu->hdr + pdu->length - pdu->data : 0;
+#ifdef TB_LOG
+ size_t payloadLen = (pdu->data) ? (unsigned char *)pdu->hdr + pdu->length - pdu->data : 0;
+#endif
OIC_LOG_V(DEBUG, ANALYZER_TAG, "CoAP Message Full Size = [%lu]", pdu->length);
OIC_LOG(DEBUG, ANALYZER_TAG, "CoAP Header (+ 0xFF)");
OIC_LOG_BUFFER(DEBUG, ANALYZER_TAG, (const uint8_t *) pdu->transport_hdr,
OIC_LOG_V(DEBUG, ANALYZER_TAG, "CoAP Header size = [%lu]", pdu->length - payloadLen);
OIC_LOG_V(DEBUG, ANALYZER_TAG, "CoAP Payload");
-// OIC_LOG_BUFFER(DEBUG, ANALYZER_TAG, pdu->data, payloadLen);
+ //OIC_LOG_BUFFER(DEBUG, ANALYZER_TAG, pdu->data, payloadLen);
OIC_LOG_V(DEBUG, ANALYZER_TAG, "CoAP Payload Size = [%lu]", payloadLen);
OIC_LOG(DEBUG, ANALYZER_TAG, "=================================================");
OIC_TRACE_END();
#endif
coap_pdu_t *outpdu =
- coap_pdu_init2(0, 0, ntohs(COAP_INVALID_TID), length, transport);
+ coap_pdu_init2(0, 0, ntohs((unsigned short)COAP_INVALID_TID), length, transport);
if (NULL == outpdu)
{
OIC_LOG(ERROR, TAG, "outpdu is null");
exit:
OIC_LOG(DEBUG, TAG, "data :");
- OIC_LOG_BUFFER(DEBUG, TAG, data, length);
+ OIC_LOG_BUFFER(DEBUG, TAG, (const uint8_t *)data, length);
coap_delete_pdu(outpdu);
return NULL;
}
}
coap_pdu_t *pdu = coap_pdu_init2(0, 0,
- ntohs(COAP_INVALID_TID),
+ ntohs((unsigned short)COAP_INVALID_TID),
length, *transport);
if (NULL == pdu)
return CA_STATUS_OK;
}
-CAResult_t CAParseUriPartial(const unsigned char *str, size_t length, int target,
+CAResult_t CAParseUriPartial(const unsigned char *str, size_t length, uint16_t target,
coap_list_t **optlist)
{
VERIFY_NON_NULL(optlist, TAG, "optlist");
return CA_STATUS_FAILED;
}
- uint32_t id = (info->options + i)->optionID;
+ uint16_t id = (info->options + i)->optionID;
switch (id)
{
case COAP_OPTION_URI_PATH:
return COAP_OPTION_KEY(*(coap_option *) a) == COAP_OPTION_KEY(*(coap_option * ) b);
}
-uint32_t CAGetOptionCount(coap_opt_iterator_t opt_iter)
+CAResult_t CAGetOptionCount(coap_opt_iterator_t opt_iter, uint8_t *optionCount)
{
- uint32_t count = 0;
+ CAResult_t result = CA_STATUS_OK;
coap_opt_t *option = NULL;
+ *optionCount = 0;
while ((option = coap_option_next(&opt_iter)))
{
&& COAP_OPTION_ETAG != opt_iter.type && COAP_OPTION_MAXAGE != opt_iter.type
&& COAP_OPTION_PROXY_SCHEME != opt_iter.type)
{
- count++;
+ if (*optionCount < UINT8_MAX)
+ {
+ (*optionCount)++;
+ }
+ else
+ {
+ // Overflow. Return an error to the caller.
+ assert(false);
+ OIC_LOG_V(ERROR, TAG, "Overflow detected in %s", __func__);
+ *optionCount = 0;
+ result = CA_STATUS_FAILED;
+ break;
+ }
}
}
- return count;
+ return result;
}
CAResult_t CAGetInfoFromPDU(const coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
}
// init HeaderOption list
- uint32_t count = CAGetOptionCount(opt_iter);
+ uint8_t count = 0;
+ CAResult_t countResult = CAGetOptionCount(opt_iter, &count);
+ if (CA_STATUS_OK != countResult)
+ {
+ OIC_LOG_V(ERROR, TAG, "CAGetOptionCount failed with error: %d!", countResult);
+ return countResult;
+ }
+
memset(outInfo, 0, sizeof(*outInfo));
outInfo->numOptions = count;
}
else if (2 == COAP_OPT_LENGTH(option))
{
- outInfo->payloadFormat = CAConvertFormat(
- coap_decode_var_bytes(COAP_OPT_VALUE(option), COAP_OPT_LENGTH(option)));
+ unsigned int decodedFormat = coap_decode_var_bytes(COAP_OPT_VALUE(option), COAP_OPT_LENGTH(option));
+ assert(decodedFormat <= UINT16_MAX);
+ outInfo->payloadFormat = CAConvertFormat((uint16_t)decodedFormat);
}
else
{
{
if (2 == COAP_OPT_LENGTH(option))
{
- outInfo->payloadVersion = coap_decode_var_bytes(COAP_OPT_VALUE(option),
- COAP_OPT_LENGTH(option));
+ unsigned int decodedVersion = coap_decode_var_bytes(COAP_OPT_VALUE(option), COAP_OPT_LENGTH(option));
+ assert(decodedVersion <= UINT16_MAX);
+ outInfo->payloadVersion = (uint16_t)decodedVersion;
}
else
{
{
if (2 == COAP_OPT_LENGTH(option))
{
- outInfo->acceptVersion = coap_decode_var_bytes(COAP_OPT_VALUE(option),
- COAP_OPT_LENGTH(option));
+ unsigned int decodedVersion = coap_decode_var_bytes(COAP_OPT_VALUE(option), COAP_OPT_LENGTH(option));
+ assert(decodedVersion <= UINT16_MAX);
+ outInfo->acceptVersion = (uint16_t)decodedVersion;
}
else
{
}
else if (2 == COAP_OPT_LENGTH(option))
{
- outInfo->acceptFormat = CAConvertFormat(
- coap_decode_var_bytes(COAP_OPT_VALUE(option),
- COAP_OPT_LENGTH(option)));
+ unsigned int decodedFormat = coap_decode_var_bytes(COAP_OPT_VALUE(option), COAP_OPT_LENGTH(option));
+ assert(decodedFormat <= UINT16_MAX);
+ outInfo->acceptFormat = CAConvertFormat((uint16_t)decodedFormat);
}
else
{
if (bufLength <= sizeof(outInfo->options[0].optionData))
{
outInfo->options[idx].optionID = opt_iter.type;
- outInfo->options[idx].optionLength = bufLength;
+ assert(bufLength <= UINT16_MAX);
+ outInfo->options[idx].optionLength = (uint16_t)bufLength;
outInfo->options[idx].protocolID = CA_COAP_ID;
memcpy(outInfo->options[idx].optionData, buf, bufLength);
idx++;
memcpy(outInfo->token, token, token_length);
}
- outInfo->tokenLength = token_length;
+ assert(token_length <= UINT8_MAX);
+ outInfo->tokenLength = (uint8_t)token_length;
// set payload data
size_t dataSize;
memcpy(outInfo->token, token, token_length);
}
- outInfo->tokenLength = token_length;
+ assert(token_length <= UINT8_MAX);
+ outInfo->tokenLength = (uint8_t)token_length;
return CA_STATUS_OK;
}
static void CAInitializeIPGlobals()
{
- caglobals.ip.u6.fd = -1;
- caglobals.ip.u6s.fd = -1;
- caglobals.ip.u4.fd = -1;
- caglobals.ip.u4s.fd = -1;
- caglobals.ip.m6.fd = -1;
- caglobals.ip.m6s.fd = -1;
- caglobals.ip.m4.fd = -1;
- caglobals.ip.m4s.fd = -1;
+ caglobals.ip.u6.fd = OC_INVALID_SOCKET;
+ caglobals.ip.u6s.fd = OC_INVALID_SOCKET;
+ caglobals.ip.u4.fd = OC_INVALID_SOCKET;
+ caglobals.ip.u4s.fd = OC_INVALID_SOCKET;
+ caglobals.ip.m6.fd = OC_INVALID_SOCKET;
+ caglobals.ip.m6s.fd = OC_INVALID_SOCKET;
+ caglobals.ip.m4.fd = OC_INVALID_SOCKET;
+ caglobals.ip.m4s.fd = OC_INVALID_SOCKET;
caglobals.ip.u6.port = 0;
caglobals.ip.u6s.port = 0;
caglobals.ip.u4.port = 0;
static CAResult_t CAReceiveMessage(CASocketFd_t fd, CATransportFlags_t flags)
{
char recvBuffer[COAP_MAX_PDU_SIZE] = {0};
-
- size_t len = 0;
int level = 0;
int type = 0;
int namelen = 0;
struct sockaddr_storage srcAddr = { .ss_family = 0 };
unsigned char *pktinfo = NULL;
#if !defined(WSA_CMSG_DATA)
+ size_t len = 0;
struct cmsghdr *cmp = NULL;
struct iovec iov = { .iov_base = recvBuffer, .iov_len = sizeof (recvBuffer) };
union control
.namelen = namelen,
.lpBuffers = &iov,
.dwBufferCount = 1,
- .Control = {.buf = cmsg.data, .len = sizeof (cmsg)}
+ .Control = {.buf = (char*)cmsg.data, .len = sizeof (cmsg)}
};
uint32_t recvLen = 0;
- uint32_t ret = caglobals.ip.wsaRecvMsg(fd, &msg, &recvLen, 0,0);
+ uint32_t ret = caglobals.ip.wsaRecvMsg(fd, &msg, (LPDWORD)&recvLen, 0,0);
OIC_LOG_V(DEBUG, TAG, "WSARecvMsg recvd %u bytes", recvLen);
if (OC_SOCKET_ERROR == ret)
{
if (flags & CA_SECURE)
{
#ifdef __WITH_DTLS__
- int ret = CAdecryptSsl(&sep, (uint8_t *)recvBuffer, recvLen);
- OIC_LOG_V(DEBUG, TAG, "CAdecryptSsl returns [%d]", ret);
+#ifdef TB_LOG
+ int decryptResult =
+#endif
+ CAdecryptSsl(&sep, (uint8_t *)recvBuffer, recvLen);
+ OIC_LOG_V(DEBUG, TAG, "CAdecryptSsl returns [%d]", decryptResult);
#else
OIC_LOG(ERROR, TAG, "Encrypted message but no DTLS");
-#endif
+#endif // __WITH_DTLS__
}
else
{
return OC_INVALID_SOCKET;
}
#endif
- struct sockaddr_storage sa = { .ss_family = family };
+ struct sockaddr_storage sa = { .ss_family = (short)family };
socklen_t socklen = 0;
if (family == AF_INET6)
else
{
sent += len;
- if (sent != len)
+ if (sent != (size_t)len)
{
OIC_LOG_V(DEBUG, TAG, "%s%s %s sendTo (Partial Send) is successful: "
"currently sent: %ld bytes, "
*/
static struct CAIPCBData_t *g_CAIPNetworkMonitorAdapterCallbackList = NULL;
-static CAInterface_t *AllocateCAInterface(int index, const char *name, int family,
+static CAInterface_t *AllocateCAInterface(int index, const char *name, uint16_t family,
const char *addr, int flags);
static u_arraylist_t *GetInterfaceInformation(int desiredIndex);
MIB_UNICASTIPADDRESS_ROW *row,
MIB_NOTIFICATION_TYPE notificationType)
{
+ OC_UNUSED(notificationType);
+ OC_UNUSED(row);
+ OC_UNUSED(context);
+
oc_mutex_lock(g_CAIPNetworkMonitorMutex);
// Fetch new network address info.
/**
* Allocate a new CAInterface_t entry for a given IP address.
*/
-static CAInterface_t *AllocateCAInterface(int index, const char *name, int family,
+static CAInterface_t *AllocateCAInterface(int index, const char *name, uint16_t family,
const char *addr, int flags)
{
CAInterface_t *ifitem = (CAInterface_t *)OICCalloc(1, sizeof(*ifitem));
// If desiredIndex is non-zero, then only retrieve adapter corresponding to desiredIndex.
// If desiredIndex is zero, then retrieve all adapters.
- if (desiredIndex && (pAdapterAddr->IfIndex != desiredIndex))
+ if (desiredIndex && ((int)pAdapterAddr->IfIndex != desiredIndex))
{
OIC_LOG_V(DEBUG, TAG, "\t\tInterface %i not interesting.", pAdapterAddr->IfIndex);
valid = false;
u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex)
{
+ OC_UNUSED(desiredIndex);
+
u_arraylist_t *iflist = u_arraylist_create();
if (!iflist)
{
static void CAInitializeTCPGlobals()
{
- caglobals.tcp.ipv4.fd = -1;
- caglobals.tcp.ipv4s.fd = -1;
- caglobals.tcp.ipv6.fd = -1;
- caglobals.tcp.ipv6s.fd = -1;
+ caglobals.tcp.ipv4.fd = OC_INVALID_SOCKET;
+ caglobals.tcp.ipv4s.fd = OC_INVALID_SOCKET;
+ caglobals.tcp.ipv6.fd = OC_INVALID_SOCKET;
+ caglobals.tcp.ipv6s.fd = OC_INVALID_SOCKET;
// Set the port number received from application.
caglobals.tcp.ipv4.port = caglobals.ports.tcp.u4;
else
{
// Check payload length from CoAP over TCP format header.
- CAResult_t result = CA_STATUS_OK;
size_t payloadLen = CACheckPayloadLengthFromHeader(tcpData->data, tcpData->dataLen);
if (!payloadLen)
{
}
#ifdef __WITH_TLS__
- if (tcpData->remoteEndpoint && tcpData->remoteEndpoint->flags & CA_SECURE)
- {
- OIC_LOG(DEBUG, TAG, "CAencryptSsl called!");
- result = CAencryptSsl(tcpData->remoteEndpoint, tcpData->data, tcpData->dataLen);
-
- if (CA_STATUS_OK != result)
- {
- OIC_LOG(ERROR, TAG, "CAAdapterNetDtlsEncrypt failed!");
- CASearchAndDeleteTCPSession(tcpData->remoteEndpoint);
- CATCPErrorHandler(tcpData->remoteEndpoint, tcpData->data, tcpData->dataLen,
- CA_SEND_FAILED);
- }
- OIC_LOG_V(DEBUG, TAG,
- "CAAdapterNetDtlsEncrypt returned with result[%d]", result);
- return;
- }
+ CAResult_t result = CA_STATUS_OK;
+ if (tcpData->remoteEndpoint && tcpData->remoteEndpoint->flags & CA_SECURE)
+ {
+ OIC_LOG(DEBUG, TAG, "CAencryptSsl called!");
+ result = CAencryptSsl(tcpData->remoteEndpoint, tcpData->data, tcpData->dataLen);
+
+ if (CA_STATUS_OK != result)
+ {
+ OIC_LOG(ERROR, TAG, "CAAdapterNetDtlsEncrypt failed!");
+ CASearchAndDeleteTCPSession(tcpData->remoteEndpoint);
+ CATCPErrorHandler(tcpData->remoteEndpoint, tcpData->data, tcpData->dataLen,
+ CA_SEND_FAILED);
+ }
+ OIC_LOG_V(DEBUG, TAG,
+ "CAAdapterNetDtlsEncrypt returned with result[%d]", result);
+ return;
+ }
#endif
//Processing for sending unicast
- ssize_t dlen = CATCPSendData(tcpData->remoteEndpoint, tcpData->data, tcpData->dataLen);
- if (-1 == dlen)
- {
- OIC_LOG(ERROR, TAG, "CATCPSendData failed");
- CASearchAndDeleteTCPSession(tcpData->remoteEndpoint);
- CATCPErrorHandler(tcpData->remoteEndpoint, tcpData->data, tcpData->dataLen,
- CA_SEND_FAILED);
- }
+ ssize_t dlen = CATCPSendData(tcpData->remoteEndpoint, tcpData->data, tcpData->dataLen);
+ if (-1 == dlen)
+ {
+ OIC_LOG(ERROR, TAG, "CATCPSendData failed");
+ CASearchAndDeleteTCPSession(tcpData->remoteEndpoint);
+ CATCPErrorHandler(tcpData->remoteEndpoint, tcpData->data, tcpData->dataLen,
+ CA_SEND_FAILED);
+ }
}
}
nbRead = tlsLength - svritem->tlsLen;
}
- len = recv(fd, svritem->tlsdata + svritem->tlsLen, (int)nbRead, 0);
+ len = recv(fd, (char*)svritem->tlsdata + svritem->tlsLen, (int)nbRead, 0);
if (len < 0)
{
OIC_LOG_V(ERROR, TAG, "recv failed %s", strerror(errno));
svritem->protocol = COAP;
// svritem->tlsdata can also be used as receiving buffer in case of raw tcp
- len = recv(fd, svritem->tlsdata, sizeof(svritem->tlsdata), 0);
+ len = recv(fd, (char*)svritem->tlsdata, sizeof(svritem->tlsdata), 0);
if (len < 0)
{
OIC_LOG_V(ERROR, TAG, "recv failed %s", strerror(errno));
svritem->fd = fd;
// #2. convert address from string to binary.
- struct sockaddr_storage sa = { .ss_family = family };
+ struct sockaddr_storage sa = { .ss_family = (short)family };
CAResult_t res = CAConvertNameToAddr(svritem->sep.endpoint.addr,
svritem->sep.endpoint.port, &sa);
if (CA_STATUS_OK != res)
}
socklen_t socklen = 0;
- struct sockaddr_storage server = { .ss_family = family };
+ struct sockaddr_storage server = { .ss_family = (short)family };
CASocketFd_t fd = socket(family, SOCK_STREAM, IPPROTO_TCP);
if (OC_INVALID_SOCKET == fd)
size_t CACheckPayloadLengthFromHeader(const void *data, size_t dlen)
{
- VERIFY_NON_NULL_RET(data, TAG, "data", -1);
+ VERIFY_NON_NULL_RET(data, TAG, "data", 0);
coap_transport_t transport = coap_get_tcp_header_type_from_initbyte(
((unsigned char *)data)[0] >> 4);
coap_pdu_t *pdu = coap_pdu_init2(0, 0,
- ntohs(COAP_INVALID_TID),
+ ntohs((unsigned short)COAP_INVALID_TID),
dlen, transport);
if (!pdu)
{
if target_os not in ['msys_nt', 'windows']:
catest_env.AppendUnique(LIBS = ['m'])
else:
- catest_env.AppendUnique(CCFLAGS=['/W3', '/WX'])
+ catest_env.AppendUnique(CCFLAGS=['/W4', '/WX'])
######################################################################
0x48, 0x45, 0x2d, 0x45, 0x43, 0x44, 0x53, 0x41, 0x2d, 0x57, 0x49, 0x54, 0x48, 0x2d, 0x41, 0x45,
0x53, 0x2d, 0x31, 0x32, 0x38, 0x2d, 0x43, 0x43, 0x4d, 0x3c, 0x2f, 0x70, 0x3e, 0x0d, 0x0a
};
-int control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM);
+size_t control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM);
unsigned char control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM_8[] = {
0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0x0d,
0x53, 0x2d, 0x31, 0x32, 0x38, 0x2d, 0x43, 0x43, 0x4d, 0x2d, 0x38, 0x3c, 0x2f, 0x70, 0x3e, 0x0d,
0x0a
};
-int control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM_8_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM_8);
+size_t control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM_8_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM_8);
unsigned char control_server_message_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256[] = {
0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0x0d,
0x53, 0x2d, 0x31, 0x32, 0x38, 0x2d, 0x43, 0x42, 0x43, 0x2d, 0x53, 0x48, 0x41, 0x32, 0x35, 0x36,
0x3c, 0x2f, 0x70, 0x3e, 0x0d, 0x0a
};
-int control_server_message_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256);
+size_t control_server_message_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256);
unsigned char control_server_message_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256[] = {
0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0x0d,
0x53, 0x2d, 0x31, 0x32, 0x38, 0x2d, 0x47, 0x43, 0x4D, 0x2d, 0x53, 0x48, 0x41, 0x32, 0x35, 0x36,
0x3c, 0x2f, 0x70, 0x3e, 0x0d, 0x0a
};
-int control_server_message_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256);
+size_t control_server_message_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256);
unsigned char control_server_message_ECDHE_ECDSA_WITH_AES_128_CBC_SHA[] = {
0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0x0d,
0x53, 0x2d, 0x31, 0x32, 0x38, 0x2d, 0x43, 0x42, 0x43, 0x2d, 0x53, 0x48, 0x41, 0x3c, 0x2f, 0x70,
0x3e, 0x0d, 0x0a
};
-int control_server_message_ECDHE_ECDSA_WITH_AES_128_CBC_SHA_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_128_CBC_SHA);
+size_t control_server_message_ECDHE_ECDSA_WITH_AES_128_CBC_SHA_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_128_CBC_SHA);
unsigned char control_client_message[] = {
0x47, 0x45, 0x54, 0x20, 0x2f, 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x0d, 0x0a,
0x0d, 0x0a
};
-int control_client_message_len = sizeof(control_client_message);
+size_t control_client_message_len = sizeof(control_client_message);
unsigned char control_server_message_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384[] = {
0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0x0d,
0x53, 0x2d, 0x32, 0x35, 0x36, 0x2d, 0x43, 0x42, 0x43, 0x2d, 0x53, 0x48, 0x41, 0x33, 0x38, 0x34,
0x3c, 0x2f, 0x70, 0x3e, 0x0d, 0x0a
};
-int control_server_message_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384);
+size_t control_server_message_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384);
unsigned char control_server_message_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384[] = {
0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0x0d,
0x53, 0x2d, 0x32, 0x35, 0x36, 0x2d, 0x47, 0x43, 0x4D, 0x2d, 0x53, 0x48, 0x41, 0x33, 0x38, 0x34,
0x3c, 0x2f, 0x70, 0x3e, 0x0d, 0x0a
};
-int control_server_message_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384);
+size_t control_server_message_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384);
static volatile bool socket_error = false;
static bool socketOpen_server()
{
- int portno;
+ unsigned short portno;
struct sockaddr_in serv_addr, cli_addr;
socklen_t clilen;
#define OC_RSRVD_REDIRECT_URI "redirecturi"
#define OC_RSRVD_CERTIFICATE "certificate"
-/**
- * Mark a parameter as unused. Used to prevent unused variable compiler warnings.
- * Used in three cases:
- * 1. in callbacks when one of the parameters are unused
- * 2. when due to code changes a functions parameter is no longer
- * used but must be left in place for backward compatibility
- * reasons.
- * 3. a variable is only used in the debug build variant and would
- * give a build warning in release mode.
- */
-#define OC_UNUSED(x) (void)(x)
/**
* These enums (OCTransportAdapter and OCTransportFlags) must