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