// For glibc information on feature test macros,
// Refer http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
//
-// This file requires #define use due to random() and srandom()
// For details on compatibility and glibc support,
// Refer http://www.gnu.org/software/libc/manual/html_node/BSD-Random.html
#define _DEFAULT_SOURCE
#include "logger.h"
#include "oic_malloc.h"
#include "oic_string.h"
-
-// ARM GCC compiler doesnt define srandom function.
-#if defined(ARDUINO) && !defined(ARDUINO_ARCH_SAM)
-#define HAVE_SRANDOM 1
-#endif
+#include "ocrandom.h"
#define TAG "CA_PRTCL_MSG"
static const char COAP_URI_HEADER[] = "coap://[::]/";
-static unsigned int SEED = 0;
-
CAResult_t CAGetRequestInfoFromPDU(const coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
CARequestInfo_t *outReqInfo)
{
// and ACKNOWLEDGE can use empty message when code is empty.
if (CA_MSG_RESET == info->type || (CA_EMPTY == code && CA_MSG_ACKNOWLEDGE == info->type))
{
+ if ((CA_EMPTY == code) && (info->payloadSize > 0 || info->payload
+ || info->token || info->tokenLength > 0))
+ {
+ OIC_LOG(ERROR, TAG, "Empty message has unnecessary data after messageID");
+ return NULL;
+ }
+
OIC_LOG(DEBUG, TAG, "code is empty");
if (!(pdu = CAGeneratePDUImpl((code_t) code, info, endpoint, NULL, transport)))
{
}
else
{
- if (CA_MSG_ACKNOWLEDGE != info->type && info->resourceUri)
+ if (info->resourceUri)
{
uint32_t length = strlen(info->resourceUri);
if (CA_MAX_URI_LENGTH < length)
return CA_STATUS_INVALID_PARAM;
}
- if (SEED == 0)
- {
-#ifdef ARDUINO
- SEED = now();
-#else
- SEED = time(NULL);
-#endif
- if (SEED == (unsigned int)((time_t)-1))
- {
- OIC_LOG(ERROR, TAG, "seed is not made");
- SEED = 0;
- return CA_STATUS_FAILED;
- }
-#if HAVE_SRANDOM
- srandom(SEED);
-#else
- srand(SEED);
-#endif
- }
-
// memory allocation
char *temp = (char *) OICCalloc(tokenLength, sizeof(char));
if (NULL == temp)
return CA_MEMORY_ALLOC_FAILED;
}
- // set random byte
- for (uint8_t index = 0; index < tokenLength; index++)
- {
- // use valid characters
-#ifdef ARDUINO
- temp[index] = rand() & 0x00FF;
-#else
- temp[index] = random() & 0x00FF;
-#endif
- }
+ OCFillRandomMem((uint8_t *)temp, tokenLength);
// save token
*token = temp;