• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 && OPENTHREAD_FTD
37 
38 #include <openthread/channel_manager.h>
39 
40 #include "common/as_core_type.hpp"
41 #include "common/locator_getters.hpp"
42 #include "utils/channel_manager.hpp"
43 
44 using namespace ot;
45 
otChannelManagerRequestChannelChange(otInstance * aInstance,uint8_t aChannel)46 void otChannelManagerRequestChannelChange(otInstance *aInstance, uint8_t aChannel)
47 {
48     AsCoreType(aInstance).Get<Utils::ChannelManager>().RequestChannelChange(aChannel);
49 }
50 
otChannelManagerGetRequestedChannel(otInstance * aInstance)51 uint8_t otChannelManagerGetRequestedChannel(otInstance *aInstance)
52 {
53     return AsCoreType(aInstance).Get<Utils::ChannelManager>().GetRequestedChannel();
54 }
55 
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>().RequestChannelSelect(aSkipQualityCheck);
70 }
71 #endif
72 
otChannelManagerSetAutoChannelSelectionEnabled(otInstance * aInstance,bool aEnabled)73 void otChannelManagerSetAutoChannelSelectionEnabled(otInstance *aInstance, bool aEnabled)
74 {
75     AsCoreType(aInstance).Get<Utils::ChannelManager>().SetAutoChannelSelectionEnabled(aEnabled);
76 }
77 
otChannelManagerGetAutoChannelSelectionEnabled(otInstance * aInstance)78 bool otChannelManagerGetAutoChannelSelectionEnabled(otInstance *aInstance)
79 {
80     return AsCoreType(aInstance).Get<Utils::ChannelManager>().GetAutoChannelSelectionEnabled();
81 }
82 
otChannelManagerSetAutoChannelSelectionInterval(otInstance * aInstance,uint32_t aInterval)83 otError otChannelManagerSetAutoChannelSelectionInterval(otInstance *aInstance, uint32_t aInterval)
84 {
85     return AsCoreType(aInstance).Get<Utils::ChannelManager>().SetAutoChannelSelectionInterval(aInterval);
86 }
87 
otChannelManagerGetAutoChannelSelectionInterval(otInstance * aInstance)88 uint32_t otChannelManagerGetAutoChannelSelectionInterval(otInstance *aInstance)
89 {
90     return AsCoreType(aInstance).Get<Utils::ChannelManager>().GetAutoChannelSelectionInterval();
91 }
92 
otChannelManagerGetSupportedChannels(otInstance * aInstance)93 uint32_t otChannelManagerGetSupportedChannels(otInstance *aInstance)
94 {
95     return AsCoreType(aInstance).Get<Utils::ChannelManager>().GetSupportedChannels();
96 }
97 
otChannelManagerSetSupportedChannels(otInstance * aInstance,uint32_t aChannelMask)98 void otChannelManagerSetSupportedChannels(otInstance *aInstance, uint32_t aChannelMask)
99 {
100     return AsCoreType(aInstance).Get<Utils::ChannelManager>().SetSupportedChannels(aChannelMask);
101 }
102 
otChannelManagerGetFavoredChannels(otInstance * aInstance)103 uint32_t otChannelManagerGetFavoredChannels(otInstance *aInstance)
104 {
105     return AsCoreType(aInstance).Get<Utils::ChannelManager>().GetFavoredChannels();
106 }
107 
otChannelManagerSetFavoredChannels(otInstance * aInstance,uint32_t aChannelMask)108 void otChannelManagerSetFavoredChannels(otInstance *aInstance, uint32_t aChannelMask)
109 {
110     return AsCoreType(aInstance).Get<Utils::ChannelManager>().SetFavoredChannels(aChannelMask);
111 }
112 
otChannelManagerGetCcaFailureRateThreshold(otInstance * aInstance)113 uint16_t otChannelManagerGetCcaFailureRateThreshold(otInstance *aInstance)
114 {
115     return AsCoreType(aInstance).Get<Utils::ChannelManager>().GetCcaFailureRateThreshold();
116 }
117 
otChannelManagerSetCcaFailureRateThreshold(otInstance * aInstance,uint16_t aThreshold)118 void otChannelManagerSetCcaFailureRateThreshold(otInstance *aInstance, uint16_t aThreshold)
119 {
120     return AsCoreType(aInstance).Get<Utils::ChannelManager>().SetCcaFailureRateThreshold(aThreshold);
121 }
122 
123 #endif // OPENTHREAD_CONFIG_CHANNEL_MANAGER_ENABLE && OPENTHREAD_FTD
124