• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 namespace ot {
36 namespace Spinel {
37 
SpinelStatusToOtError(spinel_status_t aStatus)38 otError SpinelStatusToOtError(spinel_status_t aStatus)
39 {
40     otError ret;
41 
42     switch (aStatus)
43     {
44     case SPINEL_STATUS_OK:
45         ret = OT_ERROR_NONE;
46         break;
47 
48     case SPINEL_STATUS_FAILURE:
49         ret = OT_ERROR_FAILED;
50         break;
51 
52     case SPINEL_STATUS_DROPPED:
53         ret = OT_ERROR_DROP;
54         break;
55 
56     case SPINEL_STATUS_NOMEM:
57         ret = OT_ERROR_NO_BUFS;
58         break;
59 
60     case SPINEL_STATUS_BUSY:
61         ret = OT_ERROR_BUSY;
62         break;
63 
64     case SPINEL_STATUS_PARSE_ERROR:
65         ret = OT_ERROR_PARSE;
66         break;
67 
68     case SPINEL_STATUS_INVALID_ARGUMENT:
69         ret = OT_ERROR_INVALID_ARGS;
70         break;
71 
72     case SPINEL_STATUS_UNIMPLEMENTED:
73         ret = OT_ERROR_NOT_IMPLEMENTED;
74         break;
75 
76     case SPINEL_STATUS_INVALID_STATE:
77         ret = OT_ERROR_INVALID_STATE;
78         break;
79 
80     case SPINEL_STATUS_NO_ACK:
81         ret = OT_ERROR_NO_ACK;
82         break;
83 
84     case SPINEL_STATUS_CCA_FAILURE:
85         ret = OT_ERROR_CHANNEL_ACCESS_FAILURE;
86         break;
87 
88     case SPINEL_STATUS_ALREADY:
89         ret = OT_ERROR_ALREADY;
90         break;
91 
92     case SPINEL_STATUS_PROP_NOT_FOUND:
93         ret = OT_ERROR_NOT_IMPLEMENTED;
94         break;
95 
96     case SPINEL_STATUS_ITEM_NOT_FOUND:
97         ret = OT_ERROR_NOT_FOUND;
98         break;
99 
100     default:
101         if (aStatus >= SPINEL_STATUS_STACK_NATIVE__BEGIN && aStatus <= SPINEL_STATUS_STACK_NATIVE__END)
102         {
103             ret = static_cast<otError>(aStatus - SPINEL_STATUS_STACK_NATIVE__BEGIN);
104         }
105         else
106         {
107             ret = OT_ERROR_FAILED;
108         }
109         break;
110     }
111 
112     return ret;
113 }
114 
115 } // namespace Spinel
116 } // namespace ot
117