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