| /* |
| * Copyright (c) 2024, The OpenThread Authors. |
| * All rights reserved. |
| * |
| * Redistribution and use in source and binary forms, with or without |
| * modification, are permitted provided that the following conditions are met: |
| * 1. Redistributions of source code must retain the above copyright |
| * notice, this list of conditions and the following disclaimer. |
| * 2. Redistributions in binary form must reproduce the above copyright |
| * notice, this list of conditions and the following disclaimer in the |
| * documentation and/or other materials provided with the distribution. |
| * 3. Neither the name of the copyright holder nor the |
| * names of its contributors may be used to endorse or promote products |
| * derived from this software without specific prior written permission. |
| * |
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| * POSSIBILITY OF SUCH DAMAGE. |
| */ |
| |
| #include "lib/spinel/spinel_helper.hpp" |
| |
| /** |
| * @file This file implements the spinel helper methods. |
| */ |
| |
| namespace ot { |
| namespace Spinel { |
| |
| otError SpinelStatusToOtError(spinel_status_t aStatus) |
| { |
| otError ret; |
| |
| switch (aStatus) |
| { |
| case SPINEL_STATUS_OK: |
| ret = OT_ERROR_NONE; |
| break; |
| |
| case SPINEL_STATUS_FAILURE: |
| ret = OT_ERROR_FAILED; |
| break; |
| |
| case SPINEL_STATUS_DROPPED: |
| ret = OT_ERROR_DROP; |
| break; |
| |
| case SPINEL_STATUS_NOMEM: |
| ret = OT_ERROR_NO_BUFS; |
| break; |
| |
| case SPINEL_STATUS_BUSY: |
| ret = OT_ERROR_BUSY; |
| break; |
| |
| case SPINEL_STATUS_PARSE_ERROR: |
| ret = OT_ERROR_PARSE; |
| break; |
| |
| case SPINEL_STATUS_INVALID_ARGUMENT: |
| ret = OT_ERROR_INVALID_ARGS; |
| break; |
| |
| case SPINEL_STATUS_UNIMPLEMENTED: |
| ret = OT_ERROR_NOT_IMPLEMENTED; |
| break; |
| |
| case SPINEL_STATUS_INVALID_STATE: |
| ret = OT_ERROR_INVALID_STATE; |
| break; |
| |
| case SPINEL_STATUS_NO_ACK: |
| ret = OT_ERROR_NO_ACK; |
| break; |
| |
| case SPINEL_STATUS_CCA_FAILURE: |
| ret = OT_ERROR_CHANNEL_ACCESS_FAILURE; |
| break; |
| |
| case SPINEL_STATUS_ALREADY: |
| ret = OT_ERROR_ALREADY; |
| break; |
| |
| case SPINEL_STATUS_PROP_NOT_FOUND: |
| ret = OT_ERROR_NOT_IMPLEMENTED; |
| break; |
| |
| case SPINEL_STATUS_ITEM_NOT_FOUND: |
| ret = OT_ERROR_NOT_FOUND; |
| break; |
| |
| default: |
| if (aStatus >= SPINEL_STATUS_STACK_NATIVE__BEGIN && aStatus <= SPINEL_STATUS_STACK_NATIVE__END) |
| { |
| ret = static_cast<otError>(aStatus - SPINEL_STATUS_STACK_NATIVE__BEGIN); |
| } |
| else |
| { |
| ret = OT_ERROR_FAILED; |
| } |
| break; |
| } |
| |
| return ret; |
| } |
| |
| } // namespace Spinel |
| } // namespace ot |