• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *    Copyright (c) 2023, 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 "common/api_strings.hpp"
30 
31 #include <openthread/instance.h>
32 
GetDeviceRoleName(otDeviceRole aRole)33 std::string GetDeviceRoleName(otDeviceRole aRole)
34 {
35     std::string roleName;
36 
37     switch (aRole)
38     {
39     case OT_DEVICE_ROLE_DISABLED:
40         roleName = OTBR_ROLE_NAME_DISABLED;
41         break;
42     case OT_DEVICE_ROLE_DETACHED:
43         roleName = OTBR_ROLE_NAME_DETACHED;
44         break;
45     case OT_DEVICE_ROLE_CHILD:
46         roleName = OTBR_ROLE_NAME_CHILD;
47         break;
48     case OT_DEVICE_ROLE_ROUTER:
49         roleName = OTBR_ROLE_NAME_ROUTER;
50         break;
51     case OT_DEVICE_ROLE_LEADER:
52         roleName = OTBR_ROLE_NAME_LEADER;
53         break;
54     }
55 
56     return roleName;
57 }
58 
59 #if OTBR_ENABLE_DHCP6_PD
GetDhcp6PdStateName(otBorderRoutingDhcp6PdState aState)60 std::string GetDhcp6PdStateName(otBorderRoutingDhcp6PdState aState)
61 {
62     std::string stateName;
63 
64     switch (aState)
65     {
66     case OT_BORDER_ROUTING_DHCP6_PD_STATE_DISABLED:
67         stateName = OTBR_DHCP6_PD_STATE_NAME_DISABLED;
68         break;
69     case OT_BORDER_ROUTING_DHCP6_PD_STATE_STOPPED:
70         stateName = OTBR_DHCP6_PD_STATE_NAME_STOPPED;
71         break;
72     case OT_BORDER_ROUTING_DHCP6_PD_STATE_RUNNING:
73         stateName = OTBR_DHCP6_PD_STATE_NAME_RUNNING;
74         break;
75 #if OPENTHREAD_API_VERSION >= 451
76     case OT_BORDER_ROUTING_DHCP6_PD_STATE_IDLE:
77         stateName = OTBR_DHCP6_PD_STATE_NAME_IDLE;
78         break;
79 #endif
80     }
81 
82     return stateName;
83 }
84 #endif // OTBR_ENABLE_DHCP6_PD
85 
GetCommissionerStateName(otCommissionerState aState)86 std::string GetCommissionerStateName(otCommissionerState aState)
87 {
88     std::string stateName;
89 
90     switch (aState)
91     {
92     case OT_COMMISSIONER_STATE_DISABLED:
93         stateName = OTBR_COMMISSIONER_STATE_NAME_DISABLED;
94         break;
95     case OT_COMMISSIONER_STATE_PETITION:
96         stateName = OTBR_COMMISSIONER_STATE_NAME_PETITION;
97         break;
98     case OT_COMMISSIONER_STATE_ACTIVE:
99         stateName = OTBR_COMMISSIONER_STATE_NAME_ACTIVE;
100         break;
101     }
102 
103     return stateName;
104 }
105