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.
mbed-cloud-client/mbed-coap/source/sn_coap_header_check.c@0:276e7a263c35, 2018-07-02 (annotated)
- Committer:
- MACRUM
- Date:
- Mon Jul 02 06:30:39 2018 +0000
- Revision:
- 0:276e7a263c35
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MACRUM | 0:276e7a263c35 | 1 | /* |
MACRUM | 0:276e7a263c35 | 2 | * Copyright (c) 2011-2015 ARM Limited. All rights reserved. |
MACRUM | 0:276e7a263c35 | 3 | * SPDX-License-Identifier: Apache-2.0 |
MACRUM | 0:276e7a263c35 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
MACRUM | 0:276e7a263c35 | 5 | * not use this file except in compliance with the License. |
MACRUM | 0:276e7a263c35 | 6 | * You may obtain a copy of the License at |
MACRUM | 0:276e7a263c35 | 7 | * |
MACRUM | 0:276e7a263c35 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
MACRUM | 0:276e7a263c35 | 9 | * |
MACRUM | 0:276e7a263c35 | 10 | * Unless required by applicable law or agreed to in writing, software |
MACRUM | 0:276e7a263c35 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
MACRUM | 0:276e7a263c35 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
MACRUM | 0:276e7a263c35 | 13 | * See the License for the specific language governing permissions and |
MACRUM | 0:276e7a263c35 | 14 | * limitations under the License. |
MACRUM | 0:276e7a263c35 | 15 | */ |
MACRUM | 0:276e7a263c35 | 16 | |
MACRUM | 0:276e7a263c35 | 17 | /** |
MACRUM | 0:276e7a263c35 | 18 | * \file sn_coap_header_check.c |
MACRUM | 0:276e7a263c35 | 19 | * |
MACRUM | 0:276e7a263c35 | 20 | * \brief CoAP Header validity checker |
MACRUM | 0:276e7a263c35 | 21 | * |
MACRUM | 0:276e7a263c35 | 22 | * Functionality: Checks validity of CoAP Header |
MACRUM | 0:276e7a263c35 | 23 | * |
MACRUM | 0:276e7a263c35 | 24 | */ |
MACRUM | 0:276e7a263c35 | 25 | |
MACRUM | 0:276e7a263c35 | 26 | /* * * * INCLUDE FILES * * * */ |
MACRUM | 0:276e7a263c35 | 27 | #include "ns_types.h" |
MACRUM | 0:276e7a263c35 | 28 | #include "mbed-coap/sn_coap_header.h" |
MACRUM | 0:276e7a263c35 | 29 | #include "mbed-coap/sn_coap_protocol.h" |
MACRUM | 0:276e7a263c35 | 30 | #include "sn_coap_header_internal.h" |
MACRUM | 0:276e7a263c35 | 31 | #include "sn_coap_protocol_internal.h" |
MACRUM | 0:276e7a263c35 | 32 | #include "mbed-trace/mbed_trace.h" |
MACRUM | 0:276e7a263c35 | 33 | |
MACRUM | 0:276e7a263c35 | 34 | #define TRACE_GROUP "coap" |
MACRUM | 0:276e7a263c35 | 35 | |
MACRUM | 0:276e7a263c35 | 36 | /** |
MACRUM | 0:276e7a263c35 | 37 | * \fn int8_t sn_coap_header_validity_check(sn_coap_hdr_s *src_coap_msg_ptr, coap_version_e coap_version) |
MACRUM | 0:276e7a263c35 | 38 | * |
MACRUM | 0:276e7a263c35 | 39 | * \brief Checks validity of given Header |
MACRUM | 0:276e7a263c35 | 40 | * |
MACRUM | 0:276e7a263c35 | 41 | * \param *src_coap_msg_ptr is source for building Packet data |
MACRUM | 0:276e7a263c35 | 42 | * \param coap_version is version of used CoAP specification |
MACRUM | 0:276e7a263c35 | 43 | * |
MACRUM | 0:276e7a263c35 | 44 | * \return Return value is status of validity check. In ok cases 0 and in |
MACRUM | 0:276e7a263c35 | 45 | * failure cases -1 |
MACRUM | 0:276e7a263c35 | 46 | */ |
MACRUM | 0:276e7a263c35 | 47 | int8_t sn_coap_header_validity_check(sn_coap_hdr_s *src_coap_msg_ptr, coap_version_e coap_version) |
MACRUM | 0:276e7a263c35 | 48 | { |
MACRUM | 0:276e7a263c35 | 49 | /* * Check validity of CoAP Version * */ |
MACRUM | 0:276e7a263c35 | 50 | if (coap_version != COAP_VERSION_1) { |
MACRUM | 0:276e7a263c35 | 51 | return -1; |
MACRUM | 0:276e7a263c35 | 52 | } |
MACRUM | 0:276e7a263c35 | 53 | |
MACRUM | 0:276e7a263c35 | 54 | /* * Check validity of Message type * */ |
MACRUM | 0:276e7a263c35 | 55 | switch (src_coap_msg_ptr->msg_type) { |
MACRUM | 0:276e7a263c35 | 56 | case COAP_MSG_TYPE_CONFIRMABLE: |
MACRUM | 0:276e7a263c35 | 57 | case COAP_MSG_TYPE_NON_CONFIRMABLE: |
MACRUM | 0:276e7a263c35 | 58 | case COAP_MSG_TYPE_ACKNOWLEDGEMENT: |
MACRUM | 0:276e7a263c35 | 59 | case COAP_MSG_TYPE_RESET: |
MACRUM | 0:276e7a263c35 | 60 | break; /* Ok cases */ |
MACRUM | 0:276e7a263c35 | 61 | default: |
MACRUM | 0:276e7a263c35 | 62 | tr_error("sn_coap_header_validity_check - unknown message type!"); |
MACRUM | 0:276e7a263c35 | 63 | return -1; /* Failed case */ |
MACRUM | 0:276e7a263c35 | 64 | } |
MACRUM | 0:276e7a263c35 | 65 | |
MACRUM | 0:276e7a263c35 | 66 | /* * Check validity of Message code * */ |
MACRUM | 0:276e7a263c35 | 67 | switch (src_coap_msg_ptr->msg_code) { |
MACRUM | 0:276e7a263c35 | 68 | case COAP_MSG_CODE_EMPTY: |
MACRUM | 0:276e7a263c35 | 69 | case COAP_MSG_CODE_REQUEST_GET: |
MACRUM | 0:276e7a263c35 | 70 | case COAP_MSG_CODE_REQUEST_POST: |
MACRUM | 0:276e7a263c35 | 71 | case COAP_MSG_CODE_REQUEST_PUT: |
MACRUM | 0:276e7a263c35 | 72 | case COAP_MSG_CODE_REQUEST_DELETE: |
MACRUM | 0:276e7a263c35 | 73 | case COAP_MSG_CODE_RESPONSE_CREATED: |
MACRUM | 0:276e7a263c35 | 74 | case COAP_MSG_CODE_RESPONSE_DELETED: |
MACRUM | 0:276e7a263c35 | 75 | case COAP_MSG_CODE_RESPONSE_VALID: |
MACRUM | 0:276e7a263c35 | 76 | case COAP_MSG_CODE_RESPONSE_CHANGED: |
MACRUM | 0:276e7a263c35 | 77 | case COAP_MSG_CODE_RESPONSE_CONTENT: |
MACRUM | 0:276e7a263c35 | 78 | case COAP_MSG_CODE_RESPONSE_BAD_REQUEST: |
MACRUM | 0:276e7a263c35 | 79 | case COAP_MSG_CODE_RESPONSE_UNAUTHORIZED: |
MACRUM | 0:276e7a263c35 | 80 | case COAP_MSG_CODE_RESPONSE_BAD_OPTION: |
MACRUM | 0:276e7a263c35 | 81 | case COAP_MSG_CODE_RESPONSE_FORBIDDEN: |
MACRUM | 0:276e7a263c35 | 82 | case COAP_MSG_CODE_RESPONSE_NOT_FOUND: |
MACRUM | 0:276e7a263c35 | 83 | case COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED: |
MACRUM | 0:276e7a263c35 | 84 | case COAP_MSG_CODE_RESPONSE_NOT_ACCEPTABLE: |
MACRUM | 0:276e7a263c35 | 85 | case COAP_MSG_CODE_RESPONSE_REQUEST_ENTITY_INCOMPLETE: |
MACRUM | 0:276e7a263c35 | 86 | case COAP_MSG_CODE_RESPONSE_PRECONDITION_FAILED: |
MACRUM | 0:276e7a263c35 | 87 | case COAP_MSG_CODE_RESPONSE_REQUEST_ENTITY_TOO_LARGE: |
MACRUM | 0:276e7a263c35 | 88 | case COAP_MSG_CODE_RESPONSE_UNSUPPORTED_CONTENT_FORMAT: |
MACRUM | 0:276e7a263c35 | 89 | case COAP_MSG_CODE_RESPONSE_INTERNAL_SERVER_ERROR: |
MACRUM | 0:276e7a263c35 | 90 | case COAP_MSG_CODE_RESPONSE_NOT_IMPLEMENTED: |
MACRUM | 0:276e7a263c35 | 91 | case COAP_MSG_CODE_RESPONSE_BAD_GATEWAY: |
MACRUM | 0:276e7a263c35 | 92 | case COAP_MSG_CODE_RESPONSE_SERVICE_UNAVAILABLE: |
MACRUM | 0:276e7a263c35 | 93 | case COAP_MSG_CODE_RESPONSE_GATEWAY_TIMEOUT: |
MACRUM | 0:276e7a263c35 | 94 | case COAP_MSG_CODE_RESPONSE_PROXYING_NOT_SUPPORTED: |
MACRUM | 0:276e7a263c35 | 95 | case COAP_MSG_CODE_RESPONSE_CONTINUE: |
MACRUM | 0:276e7a263c35 | 96 | break; /* Ok cases */ |
MACRUM | 0:276e7a263c35 | 97 | default: |
MACRUM | 0:276e7a263c35 | 98 | tr_error("sn_coap_header_validity_check - unknown message code!"); |
MACRUM | 0:276e7a263c35 | 99 | return -1; /* Failed case */ |
MACRUM | 0:276e7a263c35 | 100 | } |
MACRUM | 0:276e7a263c35 | 101 | |
MACRUM | 0:276e7a263c35 | 102 | /* Success */ |
MACRUM | 0:276e7a263c35 | 103 | return 0; |
MACRUM | 0:276e7a263c35 | 104 | } |