1 /*
2  *  Copyright (c) 2018, 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 /**
30  * @file
31  *   This file implements the OpenThread channel manager APIs.
32  */
33 
34 #include "openthread-core-config.h"
35 
36 #if OPENTHREAD_CONFIG_CHANNEL_MANAGER_ENABLE && \
37     (OPENTHREAD_FTD || OPENTHREAD_CONFIG_CHANNEL_MANAGER_CSL_CHANNEL_SELECT_ENABLE)
38 
39 #include "instance/instance.hpp"
40 
41 using namespace ot;
42 
43 #if OPENTHREAD_FTD
otChannelManagerRequestChannelChange(otInstance * aInstance,uint8_t aChannel)44 void otChannelManagerRequestChannelChange(otInstance *aInstance, uint8_t aChannel)
45 {
46     AsCoreType(aInstance).Get<Utils::ChannelManager>().RequestNetworkChannelChange(aChannel);
47 }
48 #endif
49 
otChannelManagerGetRequestedChannel(otInstance * aInstance)50 uint8_t otChannelManagerGetRequestedChannel(otInstance *aInstance)
51 {
52     return AsCoreType(aInstance).Get<Utils::ChannelManager>().GetRequestedChannel();
53 }
54 
55 #if OPENTHREAD_FTD
otChannelManagerGetDelay(otInstance * aInstance)56 uint16_t otChannelManagerGetDelay(otInstance *aInstance)
57 {
58     return AsCoreType(aInstance).Get<Utils::ChannelManager>().GetDelay();
59 }
60 
otChannelManagerSetDelay(otInstance * aInstance,uint16_t aDelay)61 otError otChannelManagerSetDelay(otInstance *aInstance, uint16_t aDelay)
62 {
63     return AsCoreType(aInstance).Get<Utils::ChannelManager>().SetDelay(aDelay);
64 }
65 
66 #if OPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE
otChannelManagerRequestChannelSelect(otInstance * aInstance,bool aSkipQualityCheck)67 otError otChannelManagerRequestChannelSelect(otInstance *aInstance, bool aSkipQualityCheck)
68 {
69     return AsCoreType(aInstance).Get<Utils::ChannelManager>().RequestNetworkChannelSelect(aSkipQualityCheck);
70 }
71 #endif
72 
otChannelManagerSetAutoChannelSelectionEnabled(otInstance * aInstance,bool aEnabled)73 void otChannelManagerSetAutoChannelSelectionEnabled(otInstance *aInstance, bool aEnabled)
74 {
75     AsCoreType(aInstance).Get<Utils::ChannelManager>().SetAutoNetworkChannelSelectionEnabled(aEnabled);
76 }
77 
otChannelManagerGetAutoChannelSelectionEnabled(otInstance * aInstance)78 bool otChannelManagerGetAutoChannelSelectionEnabled(otInstance *aInstance)
79 {
80     return AsCoreType(aInstance).Get<Utils::ChannelManager>().GetAutoNetworkChannelSelectionEnabled();
81 }
82 #endif // OPENTHREAD_FTD
83 
84 #if OPENTHREAD_CONFIG_CHANNEL_MANAGER_CSL_CHANNEL_SELECT_ENABLE
85 #if OPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE
otChannelManagerRequestCslChannelSelect(otInstance * aInstance,bool aSkipQualityCheck)86 otError otChannelManagerRequestCslChannelSelect(otInstance *aInstance, bool aSkipQualityCheck)
87 {
88     return AsCoreType(aInstance).Get<Utils::ChannelManager>().RequestCslChannelSelect(aSkipQualityCheck);
89 }
90 #endif
91 
otChannelManagerSetAutoCslChannelSelectionEnabled(otInstance * aInstance,bool aEnabled)92 void otChannelManagerSetAutoCslChannelSelectionEnabled(otInstance *aInstance, bool aEnabled)
93 {
94     AsCoreType(aInstance).Get<Utils::ChannelManager>().SetAutoCslChannelSelectionEnabled(aEnabled);
95 }
96 
otChannelManagerGetAutoCslChannelSelectionEnabled(otInstance * aInstance)97 bool otChannelManagerGetAutoCslChannelSelectionEnabled(otInstance *aInstance)
98 {
99     return AsCoreType(aInstance).Get<Utils::ChannelManager>().GetAutoCslChannelSelectionEnabled();
100 }
101 #endif
102 
otChannelManagerSetAutoChannelSelectionInterval(otInstance * aInstance,uint32_t aInterval)103 otError otChannelManagerSetAutoChannelSelectionInterval(otInstance *aInstance, uint32_t aInterval)
104 {
105     return AsCoreType(aInstance).Get<Utils::ChannelManager>().SetAutoChannelSelectionInterval(aInterval);
106 }
107 
otChannelManagerGetAutoChannelSelectionInterval(otInstance * aInstance)108 uint32_t otChannelManagerGetAutoChannelSelectionInterval(otInstance *aInstance)
109 {
110     return AsCoreType(aInstance).Get<Utils::ChannelManager>().GetAutoChannelSelectionInterval();
111 }
112 
otChannelManagerGetSupportedChannels(otInstance * aInstance)113 uint32_t otChannelManagerGetSupportedChannels(otInstance *aInstance)
114 {
115     return AsCoreType(aInstance).Get<Utils::ChannelManager>().GetSupportedChannels();
116 }
117 
otChannelManagerSetSupportedChannels(otInstance * aInstance,uint32_t aChannelMask)118 void otChannelManagerSetSupportedChannels(otInstance *aInstance, uint32_t aChannelMask)
119 {
120     return AsCoreType(aInstance).Get<Utils::ChannelManager>().SetSupportedChannels(aChannelMask);
121 }
122 
otChannelManagerGetFavoredChannels(otInstance * aInstance)123 uint32_t otChannelManagerGetFavoredChannels(otInstance *aInstance)
124 {
125     return AsCoreType(aInstance).Get<Utils::ChannelManager>().GetFavoredChannels();
126 }
127 
otChannelManagerSetFavoredChannels(otInstance * aInstance,uint32_t aChannelMask)128 void otChannelManagerSetFavoredChannels(otInstance *aInstance, uint32_t aChannelMask)
129 {
130     return AsCoreType(aInstance).Get<Utils::ChannelManager>().SetFavoredChannels(aChannelMask);
131 }
132 
otChannelManagerGetCcaFailureRateThreshold(otInstance * aInstance)133 uint16_t otChannelManagerGetCcaFailureRateThreshold(otInstance *aInstance)
134 {
135     return AsCoreType(aInstance).Get<Utils::ChannelManager>().GetCcaFailureRateThreshold();
136 }
137 
otChannelManagerSetCcaFailureRateThreshold(otInstance * aInstance,uint16_t aThreshold)138 void otChannelManagerSetCcaFailureRateThreshold(otInstance *aInstance, uint16_t aThreshold)
139 {
140     return AsCoreType(aInstance).Get<Utils::ChannelManager>().SetCcaFailureRateThreshold(aThreshold);
141 }
142 
143 #endif // OPENTHREAD_CONFIG_CHANNEL_MANAGER_ENABLE && OPENTHREAD_FTD
144