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
41 #include "caprotocolmessage.h"
43 #include "oic_malloc.h"
44 #include "oic_string.h"
46 // ARM GCC compiler doesnt define srandom function.
47 #if defined(ARDUINO) && !defined(ARDUINO_ARCH_SAM)
48 #define HAVE_SRANDOM 1
54 * @def VERIFY_NON_NULL_RET
55 * @brief Macro to verify the validity of input argument
57 #define VERIFY_NON_NULL_RET(arg, log_tag, log_message,ret) \
59 OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \
63 #define CA_BUFSIZE (128)
64 #define CA_PDU_MIN_SIZE (4)
65 #define CA_PORT_BUFFER_SIZE (4)
67 static const char COAP_URI_HEADER[] = "coap://[::]/";
69 static uint32_t SEED = 0;
71 CAResult_t CAGetRequestInfoFromPDU(const coap_pdu_t *pdu, CARequestInfo_t *outReqInfo)
73 OIC_LOG(DEBUG, TAG, "IN");
75 if (NULL == pdu || NULL == outReqInfo)
77 OIC_LOG(ERROR, TAG, "parameter is null");
78 return CA_STATUS_INVALID_PARAM;
81 uint32_t code = CA_NOT_FOUND;
82 CAResult_t ret = CAGetInfoFromPDU(pdu, &code, &(outReqInfo->info));
83 outReqInfo->method = code;
85 OIC_LOG(DEBUG, TAG, "OUT");
89 CAResult_t CAGetResponseInfoFromPDU(const coap_pdu_t *pdu, CAResponseInfo_t *outResInfo)
91 OIC_LOG(DEBUG, TAG, "IN");
93 if (NULL == pdu || NULL == outResInfo)
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));
101 outResInfo->result = code;
103 OIC_LOG(DEBUG, TAG, "OUT");
107 CAResult_t CAGetErrorInfoFromPDU(const coap_pdu_t *pdu, CAErrorInfo_t *errorInfo)
109 OIC_LOG(DEBUG, TAG, "IN");
113 OIC_LOG(ERROR, TAG, "parameter is null");
114 return CA_STATUS_INVALID_PARAM;
118 CAResult_t ret = CAGetInfoFromPDU(pdu, &code, &errorInfo->info);
119 OIC_LOG(DEBUG, TAG, "OUT");
123 coap_pdu_t *CAGeneratePDU(uint32_t code, const CAInfo_t *info)
125 OIC_LOG(DEBUG, TAG, "IN");
127 coap_pdu_t *pdu = NULL;
129 // RESET have to use only 4byte (empty message)
130 // and ACKNOWLEDGE can use empty message when code is empty.
131 if (CA_MSG_RESET == info->type || (CA_EMPTY == code && CA_MSG_ACKNOWLEDGE == info->type))
133 OIC_LOG(DEBUG, TAG, "code is empty");
134 if (!(pdu = CAGeneratePDUImpl((code_t) code, NULL, info, NULL, 0)))
136 OIC_LOG(ERROR, TAG, "pdu NULL");
142 coap_list_t *optlist = NULL;
144 if (CA_MSG_ACKNOWLEDGE != info->type)
146 const char *uri = info->resourceUri;
149 OIC_LOG(ERROR, TAG, "uri NULL");
153 uint32_t length = strlen(uri);
154 if (CA_MAX_URI_LENGTH < length)
156 OIC_LOG(ERROR, TAG, "URI len err");
160 uint32_t uriLength = length + sizeof(COAP_URI_HEADER);
161 char *coapUri = (char *) OICCalloc(1, uriLength);
164 OIC_LOG(ERROR, TAG, "out of memory");
167 OICStrcat(coapUri, uriLength, COAP_URI_HEADER);
168 OICStrcat(coapUri, uriLength, uri);
170 // parsing options in URI
171 CAResult_t res = CAParseURI(coapUri, &optlist);
172 if (CA_STATUS_OK != res)
176 coap_delete_list(optlist);
184 // parsing options in HeadOption
185 CAResult_t ret = CAParseHeadOption(code, info, &optlist);
186 if (CA_STATUS_OK != ret)
188 coap_delete_list(optlist);
191 size_t lenPayload = info->payload ? strlen(info->payload) : 0;
192 pdu = CAGeneratePDUImpl((code_t)code, optlist, info, info->payload, lenPayload);
195 OIC_LOG(ERROR, TAG, "pdu NULL");
196 coap_delete_list(optlist);
201 coap_delete_list(optlist);
204 // pdu print method : coap_show_pdu(pdu);
205 OIC_LOG(DEBUG, TAG, "OUT");
209 coap_pdu_t *CAParsePDU(const char *data, uint32_t length, uint32_t *outCode)
211 OIC_LOG(DEBUG, TAG, "IN");
215 OIC_LOG(ERROR, TAG, "data is null");
219 coap_pdu_t *outpdu = coap_new_pdu();
222 OIC_LOG(ERROR, TAG, "outpdu is null");
226 if (0 >= coap_pdu_parse((unsigned char *) data, length, outpdu))
228 OIC_LOG(ERROR, TAG, "pdu parse failed");
229 coap_delete_pdu(outpdu);
235 (*outCode) = (uint32_t) CA_RESPONSE_CODE(outpdu->hdr->code);
238 OIC_LOG(DEBUG, TAG, "OUT");
242 coap_pdu_t *CAGeneratePDUImpl(code_t code, coap_list_t *options, const CAInfo_t *info,
243 const char *payload, size_t payloadSize)
245 OIC_LOG(DEBUG, TAG, "IN");
246 VERIFY_NON_NULL_RET(info, TAG, "info is NULL", NULL);
248 coap_pdu_t *pdu = coap_new_pdu();
252 OIC_LOG(ERROR, TAG, "malloc failed");
256 OIC_LOG_V(DEBUG, TAG, "msgID is %d", info->messageId);
258 if (0 == info->messageId)
260 /* initialize message id */
261 prng((uint8_t * ) &message_id, sizeof(message_id));
263 OIC_LOG_V(DEBUG, TAG, "gen msg id=%d", message_id);
267 /* use saved message id */
268 message_id = info->messageId;
270 pdu->hdr->id = message_id;
271 OIC_LOG_V(DEBUG, TAG, "messageId in pdu is %d, %d", message_id, pdu->hdr->id);
273 pdu->hdr->type = info->type;
274 pdu->hdr->code = COAP_RESPONSE_CODE(code);
276 if (info->token && CA_EMPTY != code)
278 uint32_t tokenLength = info->tokenLength;
279 OIC_LOG_V(DEBUG, TAG, "token info token length: %d, token :", tokenLength);
280 OIC_LOG_BUFFER(DEBUG, TAG, (const uint8_t *)info->token, tokenLength);
282 int32_t ret = coap_add_token(pdu, tokenLength, (unsigned char *)info->token);
285 OIC_LOG(ERROR, TAG, "can't add token");
291 for (coap_list_t *opt = options; opt; opt = opt->next)
293 OIC_LOG_V(DEBUG, TAG, "[%s] opt will be added.",
294 COAP_OPTION_DATA(*(coap_option *) opt->data));
295 coap_add_option(pdu, COAP_OPTION_KEY(*(coap_option *) opt->data),
296 COAP_OPTION_LENGTH(*(coap_option *) opt->data),
297 COAP_OPTION_DATA(*(coap_option *) opt->data));
303 OIC_LOG_V(DEBUG, TAG, "add data, payload:%s", payload);
304 coap_add_data(pdu, payloadSize, (const unsigned char *) payload);
307 OIC_LOG(DEBUG, TAG, "OUT");
311 CAResult_t CAParseURI(const char *uriInfo, coap_list_t **optlist)
313 OIC_LOG(DEBUG, TAG, "IN");
317 OIC_LOG(ERROR, TAG, "uriInfo is null");
318 return CA_STATUS_INVALID_PARAM;
321 OIC_LOG_V(DEBUG, TAG, "url : %s", uriInfo);
325 OIC_LOG(ERROR, TAG, "optlist is null");
326 return CA_STATUS_INVALID_PARAM;
329 /* split arg into Uri-* options */
331 coap_split_uri((unsigned char *) uriInfo, strlen(uriInfo), &uri);
333 if (uri.port != COAP_DEFAULT_PORT)
335 unsigned char portbuf[CA_PORT_BUFFER_SIZE] = { 0 };
336 int ret = coap_insert(optlist,
337 CACreateNewOptionNode(COAP_OPTION_URI_PORT,
338 coap_encode_var_bytes(portbuf, uri.port),
343 return CA_STATUS_INVALID_PARAM;
347 if (uri.path.s && uri.path.length)
349 CAResult_t ret = CAParseUriPartial(uri.path.s, uri.path.length,
350 COAP_OPTION_URI_PATH, optlist);
351 if (CA_STATUS_OK != ret)
353 OIC_LOG(ERROR, TAG, "CAParseUriPartial failed(uri path)");
358 if (uri.query.s && uri.query.length)
360 CAResult_t ret = CAParseUriPartial(uri.query.s, uri.query.length, COAP_OPTION_URI_QUERY,
362 if (CA_STATUS_OK != ret)
364 OIC_LOG(ERROR, TAG, "CAParseUriPartial failed(uri query)");
369 OIC_LOG(DEBUG, TAG, "OUT");
373 CAResult_t CAParseUriPartial(const unsigned char *str, size_t length, int target,
374 coap_list_t **optlist)
378 OIC_LOG(ERROR, TAG, "optlist is null");
379 return CA_STATUS_INVALID_PARAM;
382 if ((target != COAP_OPTION_URI_PATH) && (target != COAP_OPTION_URI_QUERY))
384 // should never occur. Log just in case.
385 OIC_LOG(DEBUG, TAG, "Unexpected URI component.");
386 return CA_NOT_SUPPORTED;
388 else if (str && length)
390 unsigned char uriBuffer[CA_BUFSIZE] = { 0 };
391 unsigned char *pBuf = uriBuffer;
392 size_t buflen = sizeof(uriBuffer);
393 int res = (target == COAP_OPTION_URI_PATH) ? coap_split_path(str, length, pBuf, &buflen) :
394 coap_split_query(str, length, pBuf, &buflen);
401 int ret = coap_insert(optlist,
402 CACreateNewOptionNode(target, COAP_OPT_LENGTH(pBuf),
403 (char *)COAP_OPT_VALUE(pBuf)),
407 return CA_STATUS_INVALID_PARAM;
410 size_t optSize = COAP_OPT_SIZE(pBuf);
411 if ((prevIdx + optSize) < buflen)
420 OIC_LOG_V(ERROR, TAG, "Problem parsing URI : %d for %d", res, target);
421 return CA_STATUS_FAILED;
426 OIC_LOG(ERROR, TAG, "str or length is not available");
427 return CA_STATUS_FAILED;
433 CAResult_t CAParseHeadOption(uint32_t code, const CAInfo_t *info, coap_list_t **optlist)
435 OIC_LOG(DEBUG, TAG, "IN");
436 VERIFY_NON_NULL_RET(info, TAG, "info is NULL", CA_STATUS_INVALID_PARAM);
438 OIC_LOG_V(DEBUG, TAG, "parse Head Opt: %d", info->numOptions);
442 OIC_LOG(ERROR, TAG, "optlist is null");
443 return CA_STATUS_INVALID_PARAM;
446 for (uint32_t i = 0; i < info->numOptions; i++)
448 if(!(info->options + i))
450 OIC_LOG(ERROR, TAG, "options is not available");
451 return CA_STATUS_FAILED;
454 uint32_t id = (info->options + i)->optionID;
455 if (COAP_OPTION_URI_PATH == id || COAP_OPTION_URI_QUERY == id)
457 OIC_LOG_V(DEBUG, TAG, "not Header Opt: %d", id);
461 if ((info->options + i)->optionData && (info->options + i)->optionLength > 0)
463 OIC_LOG_V(DEBUG, TAG, "Head opt ID: %d", id);
464 OIC_LOG_V(DEBUG, TAG, "Head opt data: %s", (info->options + i)->optionData);
465 OIC_LOG_V(DEBUG, TAG, "Head opt length: %d", (info->options + i)->optionLength);
466 int ret = coap_insert(optlist,
467 CACreateNewOptionNode(id, (info->options + i)->optionLength,
468 (info->options + i)->optionData),
472 return CA_STATUS_INVALID_PARAM;
478 OIC_LOG(DEBUG, TAG, "OUT");
482 coap_list_t *CACreateNewOptionNode(uint16_t key, uint32_t length, const char *data)
484 OIC_LOG(DEBUG, TAG, "IN");
488 OIC_LOG(ERROR, TAG, "invalid pointer parameter");
492 coap_option *option = coap_malloc(sizeof(coap_option) + length + 1);
495 OIC_LOG(ERROR, TAG, "Out of memory");
498 memset(option, 0, sizeof(coap_option) + length + 1);
500 COAP_OPTION_KEY(*option) = key;
501 COAP_OPTION_LENGTH(*option) = length;
502 memcpy(COAP_OPTION_DATA(*option), data, length);
504 /* we can pass NULL here as delete function since option is released automatically */
505 coap_list_t *node = coap_new_listnode(option, NULL);
509 OIC_LOG(ERROR, TAG, "node is NULL");
514 OIC_LOG(DEBUG, TAG, "OUT");
518 int CAOrderOpts(void *a, void *b)
520 OIC_LOG(DEBUG, TAG, "IN");
523 return a < b ? -1 : 1;
526 if (COAP_OPTION_KEY(*(coap_option *) a) < COAP_OPTION_KEY(*(coap_option * ) b))
531 OIC_LOG(DEBUG, TAG, "OUT");
532 return COAP_OPTION_KEY(*(coap_option *) a) == COAP_OPTION_KEY(*(coap_option * ) b);
535 uint32_t CAGetOptionCount(coap_opt_iterator_t opt_iter)
537 OIC_LOG(DEBUG, TAG, "IN");
541 while ((option = coap_option_next(&opt_iter)))
543 if (COAP_OPTION_URI_PATH != opt_iter.type && COAP_OPTION_URI_QUERY != opt_iter.type)
549 OIC_LOG(DEBUG, TAG, "OUT");
553 CAResult_t CAGetInfoFromPDU(const coap_pdu_t *pdu, uint32_t *outCode, CAInfo_t *outInfo)
555 OIC_LOG(DEBUG, TAG, "IN");
557 if (!pdu || !outCode || !outInfo)
559 OIC_LOG(ERROR, TAG, "NULL pointer param");
560 return CA_STATUS_INVALID_PARAM;
563 coap_opt_iterator_t opt_iter;
564 coap_option_iterator_init((coap_pdu_t *) pdu, &opt_iter, COAP_OPT_ALL);
568 (*outCode) = (uint32_t) CA_RESPONSE_CODE(pdu->hdr->code);
571 // init HeaderOption list
572 uint32_t count = CAGetOptionCount(opt_iter);
573 memset(outInfo, 0, sizeof(*outInfo));
575 outInfo->numOptions = count;
578 outInfo->type = pdu->hdr->type;
581 outInfo->messageId = pdu->hdr->id;
585 outInfo->options = (CAHeaderOption_t *) OICCalloc(count, sizeof(CAHeaderOption_t));
586 if (NULL == outInfo->options)
588 OIC_LOG(ERROR, TAG, "Out of memory");
589 return CA_MEMORY_ALLOC_FAILED;
594 char optionResult[CA_MAX_URI_LENGTH] = {0};
596 uint32_t optionLength = 0;
597 bool isfirstsetflag = false;
598 bool isQueryBeingProcessed = false;
600 while ((option = coap_option_next(&opt_iter)))
602 char buf[COAP_MAX_PDU_SIZE] = {0};
603 if (CAGetOptionData((uint8_t *)(COAP_OPT_VALUE(option)),
604 COAP_OPT_LENGTH(option), (uint8_t *)buf, sizeof(buf)))
606 OIC_LOG_V(DEBUG, TAG, "COAP URI element : %s", buf);
607 uint32_t bufLength = strlen(buf);
608 if (COAP_OPTION_URI_PATH == opt_iter.type || COAP_OPTION_URI_QUERY == opt_iter.type)
610 if (false == isfirstsetflag)
612 isfirstsetflag = true;
613 optionResult[optionLength] = '/';
615 // Make sure there is enough room in the optionResult buffer
616 if ((optionLength + bufLength) < sizeof(optionResult))
618 memcpy(&optionResult[optionLength], buf, bufLength);
619 optionLength += bufLength;
628 if (COAP_OPTION_URI_PATH == opt_iter.type)
630 // Make sure there is enough room in the optionResult buffer
631 if (optionLength < sizeof(optionResult))
633 optionResult[optionLength] = '/';
641 else if (COAP_OPTION_URI_QUERY == opt_iter.type)
643 if (false == isQueryBeingProcessed)
645 // Make sure there is enough room in the optionResult buffer
646 if (optionLength < sizeof(optionResult))
648 optionResult[optionLength] = '?';
650 isQueryBeingProcessed = true;
659 // Make sure there is enough room in the optionResult buffer
660 if (optionLength < sizeof(optionResult))
662 optionResult[optionLength] = ';';
671 // Make sure there is enough room in the optionResult buffer
672 if ((optionLength + bufLength) < sizeof(optionResult))
674 memcpy(&optionResult[optionLength], buf, bufLength);
675 optionLength += bufLength;
687 uint32_t length = bufLength;
689 if (length <= CA_MAX_HEADER_OPTION_DATA_LENGTH)
691 outInfo->options[idx].optionID = opt_iter.type;
692 outInfo->options[idx].optionLength = length;
693 outInfo->options[idx].protocolID = CA_COAP_ID;
694 memcpy(outInfo->options[idx].optionData, buf, length);
703 if (pdu->hdr->token_length > 0)
705 OIC_LOG_V(DEBUG, TAG, "inside token length : %d", pdu->hdr->token_length);
706 outInfo->token = (char *) OICMalloc(pdu->hdr->token_length);
707 if (NULL == outInfo->token)
709 OIC_LOG(ERROR, TAG, "Out of memory");
710 OICFree(outInfo->options);
711 return CA_MEMORY_ALLOC_FAILED;
713 memcpy(outInfo->token, pdu->hdr->token, pdu->hdr->token_length);
716 outInfo->tokenLength = pdu->hdr->token_length;
719 if (NULL != pdu->data)
721 uint32_t payloadLength = strlen((char*) pdu->data);
722 OIC_LOG(DEBUG, TAG, "inside pdu->data");
723 outInfo->payload = (char *) OICMalloc(payloadLength + 1);
724 if (NULL == outInfo->payload)
726 OIC_LOG(ERROR, TAG, "Out of memory");
727 OICFree(outInfo->options);
728 OICFree(outInfo->token);
729 return CA_MEMORY_ALLOC_FAILED;
731 memcpy(outInfo->payload, pdu->data, payloadLength);
732 outInfo->payload[payloadLength] = '\0';
735 uint32_t length = strlen(optionResult);
736 OIC_LOG_V(DEBUG, TAG, "URL length:%d", length);
738 outInfo->resourceUri = OICMalloc(length + 1);
739 if (!outInfo->resourceUri)
741 OIC_LOG(ERROR, TAG, "Out of memory");
742 OICFree(outInfo->options);
743 OICFree(outInfo->token);
744 return CA_MEMORY_ALLOC_FAILED;
746 memcpy(outInfo->resourceUri, optionResult, length);
747 outInfo->resourceUri[length] = '\0';
748 OIC_LOG_V(DEBUG, TAG, "made URL : %s, %s", optionResult, outInfo->resourceUri);
750 OIC_LOG(DEBUG, TAG, "OUT");
754 OIC_LOG(ERROR, TAG, "buffer too small");
755 OICFree(outInfo->options);
756 return CA_STATUS_FAILED;
759 CAResult_t CAGetTokenFromPDU(const coap_hdr_t *pdu_hdr, CAInfo_t *outInfo)
761 OIC_LOG(DEBUG, TAG, "IN");
764 OIC_LOG(ERROR, TAG, "pdu_hdr is null");
765 return CA_STATUS_INVALID_PARAM;
770 OIC_LOG(ERROR, TAG, "outInfo is null");
771 return CA_STATUS_INVALID_PARAM;
775 if (pdu_hdr->token_length > 0)
777 OIC_LOG_V(DEBUG, TAG, "token len:%d", pdu_hdr->token_length);
778 outInfo->token = (char *) OICMalloc(pdu_hdr->token_length);
779 if (NULL == outInfo->token)
781 OIC_LOG(ERROR, TAG, "out of memory");
782 return CA_MEMORY_ALLOC_FAILED;
784 memcpy(outInfo->token, pdu_hdr->token, pdu_hdr->token_length);
787 outInfo->tokenLength = pdu_hdr->token_length;
789 OIC_LOG(DEBUG, TAG, "OUT");
794 CAResult_t CAGenerateTokenInternal(CAToken_t *token, uint8_t tokenLength)
796 OIC_LOG(DEBUG, TAG, "IN");
800 OIC_LOG(ERROR, TAG, "invalid token pointer");
801 return CA_STATUS_INVALID_PARAM;
804 if ((tokenLength > CA_MAX_TOKEN_LEN) || (0 == tokenLength))
806 OIC_LOG(ERROR, TAG, "invalid token length");
807 return CA_STATUS_INVALID_PARAM;
819 OIC_LOG(ERROR, TAG, "seed is not made");
821 return CA_STATUS_FAILED;
831 char *temp = (char *) OICCalloc(tokenLength, sizeof(char));
834 OIC_LOG(ERROR, TAG, "Out of memory");
835 return CA_MEMORY_ALLOC_FAILED;
839 for (uint8_t index = 0; index < tokenLength; index++)
841 // use valid characters
843 temp[index] = rand() & 0x00FF;
845 temp[index] = random() & 0x00FF;
852 OIC_LOG_V(DEBUG, TAG, "token len:%d, token:", tokenLength);
853 OIC_LOG_BUFFER(DEBUG, TAG, (const uint8_t *)(*token), tokenLength);
855 OIC_LOG(DEBUG, TAG, "OUT");
859 void CADestroyTokenInternal(CAToken_t token)
861 OIC_LOG(DEBUG, TAG, "IN");
863 OIC_LOG(DEBUG, TAG, "OUT");
866 void CADestroyInfo(CAInfo_t *info)
868 OIC_LOG(DEBUG, TAG, "IN");
872 OIC_LOG(DEBUG, TAG, "free options");
873 OICFree(info->options);
875 OIC_LOG(DEBUG, TAG, "free token");
876 OICFree(info->token);
878 OIC_LOG(DEBUG, TAG, "free payload");
879 OICFree(info->payload);
882 OIC_LOG(DEBUG, TAG, "OUT");
885 uint32_t CAGetOptionData(const uint8_t *data, uint32_t len, uint8_t *option, uint32_t buflen)
887 if (0 == buflen || 0 == len)
889 OIC_LOG(ERROR, TAG, "len 0");
893 if (NULL == data || NULL == option)
895 OIC_LOG(ERROR, TAG, "data/option NULL");
901 OIC_LOG(ERROR, TAG, "option buffer too small");
905 memcpy(option, data, len);
911 CAMessageType_t CAGetMessageTypeFromPduBinaryData(const void *pdu, uint32_t size)
915 OIC_LOG(ERROR, TAG, "pdu is null");
916 return CA_MSG_NONCONFIRM;
919 // pdu minimum size is 4 byte.
920 if (size < CA_PDU_MIN_SIZE)
922 OIC_LOG(ERROR, TAG, "min size");
923 return CA_MSG_NONCONFIRM;
926 coap_hdr_t *hdr = (coap_hdr_t *) pdu;
928 return (CAMessageType_t) hdr->type;
931 uint16_t CAGetMessageIdFromPduBinaryData(const void *pdu, uint32_t size)
935 OIC_LOG(ERROR, TAG, "pdu is null");
939 // pdu minimum size is 4 byte.
940 if (size < CA_PDU_MIN_SIZE)
942 OIC_LOG(ERROR, TAG, "min size");
946 coap_hdr_t *hdr = (coap_hdr_t *) pdu;
951 CAResponseResult_t CAGetCodeFromPduBinaryData(const void *pdu, uint32_t size)
955 OIC_LOG(ERROR, TAG, "pdu is null");
959 // pdu minimum size is 4 byte.
960 if (size < CA_PDU_MIN_SIZE)
962 OIC_LOG(ERROR, TAG, "min size");
966 coap_hdr_t *hdr = (coap_hdr_t *) pdu;
968 return (CAResponseResult_t) CA_RESPONSE_CODE(hdr->code);