xref: /aosp_15_r20/external/openthread/src/lib/spinel/spinel_helper.cpp (revision cfb92d1480a9e65faed56933e9c12405f45898b4)
1 /*
2  *  Copyright (c) 2024, The OpenThread Authors.
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *  1. Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  *  2. Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *  3. Neither the name of the copyright holder nor the
13  *     names of its contributors may be used to endorse or promote products
14  *     derived from this software without specific prior written permission.
15  *
16  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  *  POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include "lib/spinel/spinel_helper.hpp"
30 
31 /**
32  * @file This file implements the spinel helper methods.
33  *
34  */
35 
36 namespace ot {
37 namespace Spinel {
38 
SpinelStatusToOtError(spinel_status_t aStatus)39 otError SpinelStatusToOtError(spinel_status_t aStatus)
40 {
41     otError ret;
42 
43     switch (aStatus)
44     {
45     case SPINEL_STATUS_OK:
46         ret = OT_ERROR_NONE;
47         break;
48 
49     case SPINEL_STATUS_FAILURE:
50         ret = OT_ERROR_FAILED;
51         break;
52 
53     case SPINEL_STATUS_DROPPED:
54         ret = OT_ERROR_DROP;
55         break;
56 
57     case SPINEL_STATUS_NOMEM:
58         ret = OT_ERROR_NO_BUFS;
59         break;
60 
61     case SPINEL_STATUS_BUSY:
62         ret = OT_ERROR_BUSY;
63         break;
64 
65     case SPINEL_STATUS_PARSE_ERROR:
66         ret = OT_ERROR_PARSE;
67         break;
68 
69     case SPINEL_STATUS_INVALID_ARGUMENT:
70         ret = OT_ERROR_INVALID_ARGS;
71         break;
72 
73     case SPINEL_STATUS_UNIMPLEMENTED:
74         ret = OT_ERROR_NOT_IMPLEMENTED;
75         break;
76 
77     case SPINEL_STATUS_INVALID_STATE:
78         ret = OT_ERROR_INVALID_STATE;
79         break;
80 
81     case SPINEL_STATUS_NO_ACK:
82         ret = OT_ERROR_NO_ACK;
83         break;
84 
85     case SPINEL_STATUS_CCA_FAILURE:
86         ret = OT_ERROR_CHANNEL_ACCESS_FAILURE;
87         break;
88 
89     case SPINEL_STATUS_ALREADY:
90         ret = OT_ERROR_ALREADY;
91         break;
92 
93     case SPINEL_STATUS_PROP_NOT_FOUND:
94         ret = OT_ERROR_NOT_IMPLEMENTED;
95         break;
96 
97     case SPINEL_STATUS_ITEM_NOT_FOUND:
98         ret = OT_ERROR_NOT_FOUND;
99         break;
100 
101     default:
102         if (aStatus >= SPINEL_STATUS_STACK_NATIVE__BEGIN && aStatus <= SPINEL_STATUS_STACK_NATIVE__END)
103         {
104             ret = static_cast<otError>(aStatus - SPINEL_STATUS_STACK_NATIVE__BEGIN);
105         }
106         else
107         {
108             ret = OT_ERROR_FAILED;
109         }
110         break;
111     }
112 
113     return ret;
114 }
115 
116 } // namespace Spinel
117 } // namespace ot
118