Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-os by
sn_coap_header_check.c
00001 /* 00002 * Copyright (c) 2011-2015 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 /** 00018 * \file sn_coap_header_check.c 00019 * 00020 * \brief CoAP Header validity checker 00021 * 00022 * Functionality: Checks validity of CoAP Header 00023 * 00024 */ 00025 00026 /* * * * INCLUDE FILES * * * */ 00027 #include "ns_types.h" 00028 #include "sn_nsdl.h" 00029 #include "sn_coap_header.h" 00030 #include "sn_coap_protocol.h" 00031 #include "sn_coap_header_internal.h" 00032 #include "sn_coap_protocol_internal.h" 00033 00034 /** 00035 * \fn int8_t sn_coap_header_validity_check(sn_coap_hdr_s *src_coap_msg_ptr, coap_version_e coap_version) 00036 * 00037 * \brief Checks validity of given Header 00038 * 00039 * \param *src_coap_msg_ptr is source for building Packet data 00040 * \param coap_version is version of used CoAP specification 00041 * 00042 * \return Return value is status of validity check. In ok cases 0 and in 00043 * failure cases -1 00044 */ 00045 int8_t sn_coap_header_validity_check(sn_coap_hdr_s *src_coap_msg_ptr, coap_version_e coap_version) 00046 { 00047 /* * Check validity of CoAP Version * */ 00048 if (coap_version != COAP_VERSION_1) { 00049 return -1; 00050 } 00051 00052 /* * Check validity of Message type * */ 00053 switch (src_coap_msg_ptr->msg_type) { 00054 case COAP_MSG_TYPE_CONFIRMABLE: 00055 case COAP_MSG_TYPE_NON_CONFIRMABLE: 00056 case COAP_MSG_TYPE_ACKNOWLEDGEMENT: 00057 case COAP_MSG_TYPE_RESET: 00058 break; /* Ok cases */ 00059 default: 00060 return -1; /* Failed case */ 00061 } 00062 00063 /* * Check validity of Message code * */ 00064 switch (src_coap_msg_ptr->msg_code) { 00065 case COAP_MSG_CODE_EMPTY: 00066 case COAP_MSG_CODE_REQUEST_GET: 00067 case COAP_MSG_CODE_REQUEST_POST: 00068 case COAP_MSG_CODE_REQUEST_PUT: 00069 case COAP_MSG_CODE_REQUEST_DELETE: 00070 case COAP_MSG_CODE_RESPONSE_CREATED: 00071 case COAP_MSG_CODE_RESPONSE_DELETED: 00072 case COAP_MSG_CODE_RESPONSE_VALID: 00073 case COAP_MSG_CODE_RESPONSE_CHANGED: 00074 case COAP_MSG_CODE_RESPONSE_CONTENT: 00075 case COAP_MSG_CODE_RESPONSE_BAD_REQUEST: 00076 case COAP_MSG_CODE_RESPONSE_UNAUTHORIZED: 00077 case COAP_MSG_CODE_RESPONSE_BAD_OPTION: 00078 case COAP_MSG_CODE_RESPONSE_FORBIDDEN: 00079 case COAP_MSG_CODE_RESPONSE_NOT_FOUND: 00080 case COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED: 00081 case COAP_MSG_CODE_RESPONSE_NOT_ACCEPTABLE: 00082 case COAP_MSG_CODE_RESPONSE_REQUEST_ENTITY_INCOMPLETE: 00083 case COAP_MSG_CODE_RESPONSE_PRECONDITION_FAILED: 00084 case COAP_MSG_CODE_RESPONSE_REQUEST_ENTITY_TOO_LARGE: 00085 case COAP_MSG_CODE_RESPONSE_UNSUPPORTED_CONTENT_FORMAT: 00086 case COAP_MSG_CODE_RESPONSE_INTERNAL_SERVER_ERROR: 00087 case COAP_MSG_CODE_RESPONSE_NOT_IMPLEMENTED: 00088 case COAP_MSG_CODE_RESPONSE_BAD_GATEWAY: 00089 case COAP_MSG_CODE_RESPONSE_SERVICE_UNAVAILABLE: 00090 case COAP_MSG_CODE_RESPONSE_GATEWAY_TIMEOUT: 00091 case COAP_MSG_CODE_RESPONSE_PROXYING_NOT_SUPPORTED: 00092 case COAP_MSG_CODE_RESPONSE_CONTINUE: 00093 break; /* Ok cases */ 00094 default: 00095 return -1; /* Failed case */ 00096 } 00097 00098 /* Success */ 00099 return 0; 00100 }
Generated on Tue Jul 12 2022 13:16:06 by
