1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
21 // Defining _BSD_SOURCE or _DEFAULT_SOURCE causes header files to expose
22 // definitions that may otherwise be skipped. Skipping can cause implicit
23 // declaration warnings and/or bugs and subtle problems in code execution.
24 // For glibc information on feature test macros,
25 // Refer http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
27 // This file requires #define use due to random() and srandom()
28 // For details on compatibility and glibc support,
29 // Refer http://www.gnu.org/software/libc/manual/html_node/BSD-Random.html
30 #define _DEFAULT_SOURCE
33 // Include files from the arduino platform do not provide these conversions:
35 #define htons(x) ( ((x)<< 8 & 0xFF00) | ((x)>> 8 & 0x00FF) )
36 #define ntohs(x) htons(x)
49 #include "caprotocolmessage.h"
51 #include "oic_malloc.h"
53 // ARM GCC compiler doesnt define srandom function.
54 #if defined(ARDUINO) && !defined(ARDUINO_ARCH_SAM)
55 #define HAVE_SRANDOM 1
60 #define CA_BUFSIZE (128)
61 #define CA_PDU_MIN_SIZE (4)
62 #define CA_PORT_BUFFER_SIZE (2)
64 static const char COAP_URI_HEADER[] = "coap://[::]/";
66 static uint32_t SEED = 0;
68 CAResult_t CAGetRequestInfoFromPDU(const coap_pdu_t *pdu, CARequestInfo_t *outReqInfo,
69 char *outUri, uint32_t buflen)
71 OIC_LOG(DEBUG, TAG, "IN");
73 if (NULL == pdu || NULL == outReqInfo || NULL == outUri)
75 OIC_LOG(ERROR, TAG, "parameter is null");
76 return CA_STATUS_INVALID_PARAM;
79 uint32_t code = CA_NOT_FOUND;
81 OIC_LOG_V(DEBUG, TAG, "buffer length : %d", buflen);
82 CAResult_t ret = CAGetInfoFromPDU(pdu, &code, &(outReqInfo->info), outUri, buflen);
83 outReqInfo->method = code;
84 OIC_LOG(DEBUG, TAG, "OUT");
88 CAResult_t CAGetResponseInfoFromPDU(const coap_pdu_t *pdu, CAResponseInfo_t *outResInfo,
89 char *outUri, uint32_t buflen)
91 OIC_LOG(DEBUG, TAG, "IN");
93 if (NULL == pdu || NULL == outResInfo || NULL == outUri)
95 OIC_LOG(ERROR, TAG, "parameter is null");
96 return CA_STATUS_INVALID_PARAM;
99 uint32_t code = CA_NOT_FOUND;
100 CAResult_t ret = CAGetInfoFromPDU(pdu, &code, &(outResInfo->info), outUri, buflen);
101 outResInfo->result = code;
102 OIC_LOG(DEBUG, TAG, "OUT");
106 coap_pdu_t *CAGeneratePDU(const char *uri, uint32_t code, const CAInfo_t info)
108 OIC_LOG(DEBUG, TAG, "IN");
110 coap_pdu_t *pdu = NULL;
112 // RESET have to use only 4byte (empty message)
113 // and ACKNOWLEDGE can use empty message when code is empty.
114 if (CA_MSG_RESET == info.type || (CA_EMPTY == code && CA_MSG_ACKNOWLEDGE == info.type))
116 OIC_LOG(DEBUG, TAG, "code is empty");
117 if (!(pdu = CAGeneratePDUImpl((code_t) code, NULL, info, NULL, 0)))
119 OIC_LOG(ERROR, TAG, "pdu NULL");
125 coap_list_t *optlist = NULL;
127 if (CA_MSG_ACKNOWLEDGE != info.type)
131 OIC_LOG(ERROR, TAG, "uri NULL");
135 uint32_t length = strlen(uri);
136 if (CA_MAX_URI_LENGTH < length)
138 OIC_LOG(ERROR, TAG, "URI len err");
142 uint32_t uriLength = length + sizeof(COAP_URI_HEADER);
143 char *coapUri = (char *) OICCalloc(1, uriLength);
146 OIC_LOG(ERROR, TAG, "out of memory");
149 strcat(coapUri, COAP_URI_HEADER);
150 strcat(coapUri, uri);
152 // parsing options in URI
153 CAResult_t res = CAParseURI(coapUri, &optlist);
154 if (CA_STATUS_OK != res)
158 coap_delete_list(optlist);
166 // parsing options in HeadOption
167 CAResult_t ret = CAParseHeadOption(code, info, &optlist);
168 if (CA_STATUS_OK != ret)
170 coap_delete_list(optlist);
174 pdu = CAGeneratePDUImpl((code_t) code, optlist, info, info.payload, strlen(info.payload));
177 OIC_LOG(ERROR, TAG, "pdu NULL");
178 coap_delete_list(optlist);
183 coap_delete_list(optlist);
186 // pdu print method : coap_show_pdu(pdu);
187 OIC_LOG(DEBUG, TAG, "OUT");
191 coap_pdu_t *CAParsePDU(const char *data, uint32_t length, uint32_t *outCode)
193 OIC_LOG(DEBUG, TAG, "IN");
197 OIC_LOG(ERROR, TAG, "data is null");
201 coap_pdu_t *outpdu = coap_new_pdu();
204 OIC_LOG(ERROR, TAG, "outpdu is null");
208 if (0 >= coap_pdu_parse((unsigned char *) data, length, outpdu))
210 OIC_LOG(ERROR, TAG, "pdu parse failed");
211 coap_delete_pdu(outpdu);
217 (*outCode) = (uint32_t) CA_RESPONSE_CODE(outpdu->hdr->code);
220 OIC_LOG(DEBUG, TAG, "OUT");
224 coap_pdu_t *CAGeneratePDUImpl(code_t code, coap_list_t *options, const CAInfo_t info,
225 const char *payload, size_t payloadSize)
227 OIC_LOG(DEBUG, TAG, "IN");
229 coap_pdu_t *pdu = coap_new_pdu();
233 OIC_LOG(ERROR, TAG, "malloc failed");
237 OIC_LOG_V(DEBUG, TAG, "msgID is %d", info.messageId);
239 if (0 == info.messageId)
241 /* initialize message id */
242 prng((uint8_t * ) &message_id, sizeof(message_id));
244 OIC_LOG_V(DEBUG, TAG, "gen msg id=%d", message_id);
248 /* use saved message id */
249 message_id = info.messageId;
251 pdu->hdr->id = message_id;
252 OIC_LOG_V(DEBUG, TAG, "messageId in pdu is %d, %d", message_id, pdu->hdr->id);
254 pdu->hdr->type = info.type;
255 pdu->hdr->code = COAP_RESPONSE_CODE(code);
257 if (info.token && CA_EMPTY != code)
259 uint32_t tokenLength = info.tokenLength;
260 OIC_LOG_V(DEBUG, TAG, "token info token length: %d, token :", tokenLength);
261 OIC_LOG_BUFFER(DEBUG, TAG, (const uint8_t *)info.token, tokenLength);
263 int32_t ret = coap_add_token(pdu, tokenLength, (unsigned char *) info.token);
266 OIC_LOG(ERROR, TAG, "can't add token");
272 for (coap_list_t *opt = options; opt; opt = opt->next)
274 OIC_LOG_V(DEBUG, TAG, "[%s] opt will be added.",
275 COAP_OPTION_DATA(*(coap_option *) opt->data));
276 coap_add_option(pdu, COAP_OPTION_KEY(*(coap_option *) opt->data),
277 COAP_OPTION_LENGTH(*(coap_option *) opt->data),
278 COAP_OPTION_DATA(*(coap_option *) opt->data));
284 OIC_LOG_V(DEBUG, TAG, "add data, payload:%s", payload);
285 coap_add_data(pdu, payloadSize, (const unsigned char *) payload);
288 OIC_LOG(DEBUG, TAG, "OUT");
292 CAResult_t CAParseURI(const char *uriInfo, coap_list_t **optlist)
294 OIC_LOG(DEBUG, TAG, "IN");
298 OIC_LOG(ERROR, TAG, "uriInfo is null");
299 return CA_STATUS_INVALID_PARAM;
302 OIC_LOG_V(DEBUG, TAG, "url : %s", uriInfo);
306 OIC_LOG(ERROR, TAG, "optlist is null");
307 return CA_STATUS_INVALID_PARAM;
310 /* split arg into Uri-* options */
312 coap_split_uri((unsigned char *) uriInfo, strlen(uriInfo), &uri);
314 if (uri.port != COAP_DEFAULT_PORT)
316 unsigned char portbuf[CA_PORT_BUFFER_SIZE] = { 0 };
317 int ret = coap_insert(optlist,
318 CACreateNewOptionNode(COAP_OPTION_URI_PORT,
319 coap_encode_var_bytes(portbuf, uri.port),
324 return CA_STATUS_INVALID_PARAM;
328 if (uri.path.s && uri.path.length)
330 CAResult_t ret = CAParseUriPartial(uri.path.s, uri.path.length, COAP_OPTION_URI_PATH,
332 if (CA_STATUS_OK != ret)
334 OIC_LOG(ERROR, TAG, "CAParseUriPartial failed(uri path)");
339 if (uri.query.s && uri.query.length)
341 CAResult_t ret = CAParseUriPartial(uri.query.s, uri.query.length, COAP_OPTION_URI_QUERY,
343 if (CA_STATUS_OK != ret)
345 OIC_LOG(ERROR, TAG, "CAParseUriPartial failed(uri query)");
350 OIC_LOG(DEBUG, TAG, "OUT");
354 CAResult_t CAParseUriPartial(const unsigned char *str, size_t length, int target,
355 coap_list_t **optlist)
359 OIC_LOG(ERROR, TAG, "optlist is null");
360 return CA_STATUS_INVALID_PARAM;
363 if ((target != COAP_OPTION_URI_PATH) && (target != COAP_OPTION_URI_QUERY))
365 // should never occur. Log just in case.
366 OIC_LOG(DEBUG, TAG, "Unexpected URI component.");
367 return CA_NOT_SUPPORTED;
369 else if (str && length)
371 unsigned char uriBuffer[CA_BUFSIZE] = { 0 };
372 unsigned char *pBuf = uriBuffer;
373 size_t buflen = sizeof(uriBuffer);
374 int res = (target == COAP_OPTION_URI_PATH) ? coap_split_path(str, length, pBuf, &buflen) :
375 coap_split_query(str, length, pBuf, &buflen);
382 int ret = coap_insert(optlist,
383 CACreateNewOptionNode(target, COAP_OPT_LENGTH(pBuf),
384 COAP_OPT_VALUE(pBuf)),
388 return CA_STATUS_INVALID_PARAM;
391 size_t optSize = COAP_OPT_SIZE(pBuf);
392 if ((prevIdx + optSize) < buflen)
401 OIC_LOG_V(ERROR, TAG, "Problem parsing URI : %d for %d", res, target);
402 return CA_STATUS_FAILED;
407 OIC_LOG(ERROR, TAG, "str or length is not available");
408 return CA_STATUS_FAILED;
414 CAResult_t CAParseHeadOption(uint32_t code, const CAInfo_t info, coap_list_t **optlist)
416 OIC_LOG(DEBUG, TAG, "IN");
418 OIC_LOG_V(DEBUG, TAG, "parse Head Opt: %d", info.numOptions);
422 OIC_LOG(ERROR, TAG, "optlist is null");
423 return CA_STATUS_INVALID_PARAM;
426 for (uint32_t i = 0; i < info.numOptions; i++)
428 if(!(info.options + i))
430 OIC_LOG(ERROR, TAG, "options is not available");
431 return CA_STATUS_FAILED;
434 uint32_t id = (info.options + i)->optionID;
435 if (COAP_OPTION_URI_PATH == id || COAP_OPTION_URI_QUERY == id)
437 OIC_LOG_V(DEBUG, TAG, "not Header Opt: %d", id);
441 if ((info.options + i)->optionData && (info.options + i)->optionLength > 0)
443 OIC_LOG_V(DEBUG, TAG, "Head opt ID: %d", id);
444 OIC_LOG_V(DEBUG, TAG, "Head opt data: %s", (info.options + i)->optionData);
445 OIC_LOG_V(DEBUG, TAG, "Head opt length: %d", (info.options + i)->optionLength);
446 int ret = coap_insert(optlist,
447 CACreateNewOptionNode(id, (info.options + i)->optionLength,
448 (info.options + i)->optionData),
452 return CA_STATUS_INVALID_PARAM;
458 OIC_LOG(DEBUG, TAG, "OUT");
462 coap_list_t *CACreateNewOptionNode(uint16_t key, uint32_t length, const uint8_t *data)
464 OIC_LOG(DEBUG, TAG, "IN");
468 OIC_LOG(ERROR, TAG, "invalid pointer parameter");
472 coap_option *option = coap_malloc(sizeof(coap_option) + length + 1);
475 OIC_LOG(ERROR, TAG, "Out of memory");
478 memset(option, 0, sizeof(coap_option) + length + 1);
480 COAP_OPTION_KEY(*option) = key;
481 COAP_OPTION_LENGTH(*option) = length;
482 memcpy(COAP_OPTION_DATA(*option), data, length);
484 /* we can pass NULL here as delete function since option is released automatically */
485 coap_list_t *node = coap_new_listnode(option, NULL);
489 OIC_LOG(ERROR, TAG, "node is NULL");
494 OIC_LOG(DEBUG, TAG, "OUT");
498 int CAOrderOpts(void *a, void *b)
500 OIC_LOG(DEBUG, TAG, "IN");
503 return a < b ? -1 : 1;
506 if (COAP_OPTION_KEY(*(coap_option *) a) < COAP_OPTION_KEY(*(coap_option * ) b))
511 OIC_LOG(DEBUG, TAG, "OUT");
512 return COAP_OPTION_KEY(*(coap_option *) a) == COAP_OPTION_KEY(*(coap_option * ) b);
515 uint32_t CAGetOptionCount(coap_opt_iterator_t opt_iter)
517 OIC_LOG(DEBUG, TAG, "IN");
521 while ((option = coap_option_next(&opt_iter)))
523 if (COAP_OPTION_URI_PATH != opt_iter.type && COAP_OPTION_URI_QUERY != opt_iter.type)
529 OIC_LOG(DEBUG, TAG, "OUT");
533 CAResult_t CAGetInfoFromPDU(const coap_pdu_t *pdu, uint32_t *outCode, CAInfo_t *outInfo,
534 char *outUri, uint32_t buflen)
536 OIC_LOG(DEBUG, TAG, "IN");
538 if (!pdu || !outCode || !outInfo || !outUri)
540 OIC_LOG(ERROR, TAG, "NULL pointer param");
541 return CA_STATUS_INVALID_PARAM;
544 coap_opt_iterator_t opt_iter;
545 coap_option_iterator_init((coap_pdu_t *) pdu, &opt_iter, COAP_OPT_ALL);
549 (*outCode) = (uint32_t) CA_RESPONSE_CODE(pdu->hdr->code);
552 // init HeaderOption list
553 uint32_t count = CAGetOptionCount(opt_iter);
554 memset(outInfo, 0, sizeof(*outInfo));
556 outInfo->numOptions = count;
559 outInfo->type = pdu->hdr->type;
562 outInfo->messageId = pdu->hdr->id;
566 outInfo->options = (CAHeaderOption_t *) OICCalloc(count, sizeof(CAHeaderOption_t));
567 if (NULL == outInfo->options)
569 OIC_LOG(ERROR, TAG, "Out of memory");
570 return CA_MEMORY_ALLOC_FAILED;
575 char optionResult[CA_MAX_URI_LENGTH] = {0};
577 uint32_t optionLength = 0;
578 bool isfirstsetflag = false;
579 bool isQueryBeingProcessed = false;
581 while ((option = coap_option_next(&opt_iter)))
583 char buf[COAP_MAX_PDU_SIZE] = {0};
584 if (CAGetOptionData((uint8_t *)(COAP_OPT_VALUE(option)),
585 COAP_OPT_LENGTH(option), (uint8_t *)buf, sizeof(buf)))
587 OIC_LOG_V(DEBUG, TAG, "COAP URI element : %s", buf);
588 uint32_t bufLength = strlen(buf);
589 if (COAP_OPTION_URI_PATH == opt_iter.type || COAP_OPTION_URI_QUERY == opt_iter.type)
591 if (false == isfirstsetflag)
593 isfirstsetflag = true;
594 optionResult[optionLength] = '/';
596 // Make sure there is enough room in the optionResult buffer
597 if ((optionLength + bufLength) < sizeof(optionResult))
599 memcpy(optionResult + optionLength, buf, bufLength);
600 optionLength += bufLength;
609 if (COAP_OPTION_URI_PATH == opt_iter.type)
611 // Make sure there is enough room in the optionResult buffer
612 if (optionLength < sizeof(optionResult))
614 optionResult[optionLength] = '/';
622 else if (COAP_OPTION_URI_QUERY == opt_iter.type)
624 if (false == isQueryBeingProcessed)
626 // Make sure there is enough room in the optionResult buffer
627 if (optionLength < sizeof(optionResult))
629 optionResult[optionLength] = '?';
631 isQueryBeingProcessed = true;
640 // Make sure there is enough room in the optionResult buffer
641 if (optionLength < sizeof(optionResult))
643 optionResult[optionLength] = '&';
652 // Make sure there is enough room in the optionResult buffer
653 if ((optionLength + bufLength) < sizeof(optionResult))
655 memcpy(optionResult + optionLength, buf, bufLength);
656 optionLength += bufLength;
668 uint32_t length = bufLength;
670 if (length <= CA_MAX_HEADER_OPTION_DATA_LENGTH)
672 outInfo->options[idx].optionID = opt_iter.type;
673 outInfo->options[idx].optionLength = length;
674 outInfo->options[idx].protocolID = CA_COAP_ID;
675 memcpy(outInfo->options[idx].optionData, buf, length);
684 if (pdu->hdr->token_length > 0)
686 OIC_LOG_V(DEBUG, TAG, "inside token length : %d", pdu->hdr->token_length);
687 outInfo->token = (char *) OICMalloc(pdu->hdr->token_length);
688 if (NULL == outInfo->token)
690 OIC_LOG(ERROR, TAG, "Out of memory");
691 OICFree(outInfo->options);
692 return CA_MEMORY_ALLOC_FAILED;
694 memcpy(outInfo->token, pdu->hdr->token, pdu->hdr->token_length);
697 outInfo->tokenLength = pdu->hdr->token_length;
700 if (NULL != pdu->data)
702 uint32_t payloadLength = strlen((char*) pdu->data);
703 OIC_LOG(DEBUG, TAG, "inside pdu->data");
704 outInfo->payload = (char *) OICMalloc(payloadLength + 1);
705 if (NULL == outInfo->payload)
707 OIC_LOG(ERROR, TAG, "Out of memory");
708 OICFree(outInfo->options);
709 OICFree(outInfo->token);
710 return CA_MEMORY_ALLOC_FAILED;
712 memcpy(outInfo->payload, pdu->data, payloadLength);
713 outInfo->payload[payloadLength] = '\0';
716 uint32_t length = strlen(optionResult);
717 OIC_LOG_V(DEBUG, TAG, "URL length:%d,%d,%d", length, buflen, strlen(outUri));
718 if (buflen >= length)
720 memcpy(outUri, optionResult, length);
721 outUri[length] = '\0';
723 OIC_LOG_V(DEBUG, TAG, "made URL:%s\n", optionResult);
725 OIC_LOG_V(DEBUG, TAG, "made URL : %s, %s", optionResult, outUri);
728 OIC_LOG(DEBUG, TAG, "OUT");
732 OIC_LOG(ERROR, TAG, "buffer too small");
733 OICFree(outInfo->options);
734 return CA_STATUS_FAILED;
737 CAResult_t CAGetTokenFromPDU(const coap_hdr_t *pdu_hdr, CAInfo_t *outInfo)
739 OIC_LOG(DEBUG, TAG, "IN");
742 OIC_LOG(ERROR, TAG, "pdu_hdr is null");
743 return CA_STATUS_INVALID_PARAM;
748 OIC_LOG(ERROR, TAG, "outInfo is null");
749 return CA_STATUS_INVALID_PARAM;
753 if (pdu_hdr->token_length > 0)
755 OIC_LOG_V(DEBUG, TAG, "token len:%d", pdu_hdr->token_length);
756 outInfo->token = (char *) OICMalloc(pdu_hdr->token_length);
757 if (NULL == outInfo->token)
759 OIC_LOG(ERROR, TAG, "out of memory");
760 return CA_MEMORY_ALLOC_FAILED;
762 memcpy(outInfo->token, pdu_hdr->token, pdu_hdr->token_length);
765 outInfo->tokenLength = pdu_hdr->token_length;
767 OIC_LOG(DEBUG, TAG, "OUT");
772 CAResult_t CAGenerateTokenInternal(CAToken_t *token, uint8_t tokenLength)
774 OIC_LOG(DEBUG, TAG, "IN");
778 OIC_LOG(ERROR, TAG, "invalid token pointer");
779 return CA_STATUS_INVALID_PARAM;
782 if ((tokenLength > CA_MAX_TOKEN_LEN) || (0 == tokenLength))
784 OIC_LOG(ERROR, TAG, "invalid token length");
785 return CA_STATUS_INVALID_PARAM;
797 OIC_LOG(ERROR, TAG, "seed is not made");
799 return CA_STATUS_FAILED;
809 char *temp = (char *) OICCalloc(tokenLength, sizeof(char));
812 OIC_LOG(ERROR, TAG, "Out of memory");
813 return CA_MEMORY_ALLOC_FAILED;
817 for (uint8_t index = 0; index < tokenLength; index++)
819 // use valid characters
821 temp[index] = rand() & 0x00FF;
823 temp[index] = random() & 0x00FF;
830 OIC_LOG_V(DEBUG, TAG, "token len:%d, token:", tokenLength);
831 OIC_LOG_BUFFER(DEBUG, TAG, (const uint8_t *)(*token), tokenLength);
833 OIC_LOG(DEBUG, TAG, "OUT");
837 void CADestroyTokenInternal(CAToken_t token)
839 OIC_LOG(DEBUG, TAG, "IN");
841 OIC_LOG(DEBUG, TAG, "OUT");
844 void CADestroyInfo(CAInfo_t *info)
846 OIC_LOG(DEBUG, TAG, "IN");
850 OIC_LOG(DEBUG, TAG, "free options");
851 OICFree(info->options);
853 OIC_LOG(DEBUG, TAG, "free token");
854 OICFree(info->token);
856 OIC_LOG(DEBUG, TAG, "free payload");
857 OICFree(info->payload);
860 OIC_LOG(DEBUG, TAG, "OUT");
863 uint32_t CAGetOptionData(const uint8_t *data, uint32_t len, uint8_t *option, uint32_t buflen)
865 if (0 == buflen || 0 == len)
867 OIC_LOG(ERROR, TAG, "len 0");
871 if (NULL == data || NULL == option)
873 OIC_LOG(ERROR, TAG, "data/option NULL");
879 OIC_LOG(ERROR, TAG, "option buffer too small");
883 memcpy(option, data, len);
889 CAMessageType_t CAGetMessageTypeFromPduBinaryData(const void *pdu, uint32_t size)
893 OIC_LOG(ERROR, TAG, "pdu is null");
894 return CA_MSG_NONCONFIRM;
897 // pdu minimum size is 4 byte.
898 if (size < CA_PDU_MIN_SIZE)
900 OIC_LOG(ERROR, TAG, "min size");
901 return CA_MSG_NONCONFIRM;
904 coap_hdr_t *hdr = (coap_hdr_t *) pdu;
907 return CA_MSG_NONCONFIRM;
910 return (CAMessageType_t) hdr->type;
913 uint16_t CAGetMessageIdFromPduBinaryData(const void *pdu, uint32_t size)
917 OIC_LOG(ERROR, TAG, "pdu is null");
921 // pdu minimum size is 4 byte.
922 if (size < CA_PDU_MIN_SIZE)
924 OIC_LOG(ERROR, TAG, "min size");
928 coap_hdr_t *hdr = (coap_hdr_t *) pdu;
937 CAResponseResult_t CAGetCodeFromPduBinaryData(const void *pdu, uint32_t size)
941 OIC_LOG(ERROR, TAG, "pdu is null");
945 // pdu minimum size is 4 byte.
946 if (size < CA_PDU_MIN_SIZE)
948 OIC_LOG(ERROR, TAG, "min size");
952 coap_hdr_t *hdr = (coap_hdr_t *) pdu;
955 OIC_LOG(ERROR, TAG, "hdr is null");
959 return (CAResponseResult_t) CA_RESPONSE_CODE(hdr->code);