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 * @brief 32 * This file includes the OpenThread API for channel monitoring feature 33 */ 34 35 #ifndef OPENTHREAD_CHANNEL_MONITOR_H_ 36 #define OPENTHREAD_CHANNEL_MONITOR_H_ 37 38 #include <openthread/instance.h> 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 /** 45 * @addtogroup api-channel-monitor 46 * 47 * @brief 48 * This module includes functions for channel monitoring feature. 49 * 50 * The functions in this module are available when channel monitor feature 51 * (`OPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE`) is enabled. 52 * 53 * Channel monitoring will periodically monitor all channels to help determine the cleaner channels (channels 54 * with less interference). 55 * 56 * When channel monitoring is active, a zero-duration Energy Scan is performed, collecting a single RSSI sample on 57 * every channel per sample interval. The RSSI samples are compared with a pre-specified RSSI threshold. As an 58 * indicator of channel quality, the channel monitoring module maintains and provides the average rate/percentage of 59 * RSSI samples that are above the threshold within (approximately) a specified sample window (referred to as channel 60 * occupancy). 61 * 62 * @{ 63 */ 64 65 /** 66 * Enables or disables the Channel Monitoring operation. 67 * 68 * Once operation starts, any previously collected data is cleared. However, after operation is disabled, the previous 69 * collected data is still valid and can be read. 70 * 71 * @note OpenThread core internally enables or disables the Channel Monitoring operation when the IPv6 interface is 72 * brought up or down, for example in a call to `otIp6SetEnabled()`. 73 * 74 * @param[in] aInstance A pointer to an OpenThread instance. 75 * @param[in] aEnabled TRUE to enable/start Channel Monitoring operation, FALSE to disable/stop it. 76 * 77 * @retval OT_ERROR_NONE Channel Monitoring state changed successfully 78 * @retval OT_ERROR_ALREADY Channel Monitoring is already in the same state. 79 */ 80 otError otChannelMonitorSetEnabled(otInstance *aInstance, bool aEnabled); 81 82 /** 83 * Indicates whether the Channel Monitoring operation is enabled and running. 84 * 85 * @param[in] aInstance A pointer to an OpenThread instance. 86 * 87 * @returns TRUE if the Channel Monitoring operation is enabled, FALSE otherwise. 88 */ 89 bool otChannelMonitorIsEnabled(otInstance *aInstance); 90 91 /** 92 * Get channel monitoring sample interval in milliseconds. 93 * 94 * @param[in] aInstance A pointer to an OpenThread instance. 95 * 96 * @returns The channel monitor sample interval in milliseconds. 97 */ 98 uint32_t otChannelMonitorGetSampleInterval(otInstance *aInstance); 99 100 /** 101 * Get channel monitoring RSSI threshold in dBm. 102 * 103 * @param[in] aInstance A pointer to an OpenThread instance. 104 * 105 * @returns The RSSI threshold in dBm. 106 */ 107 int8_t otChannelMonitorGetRssiThreshold(otInstance *aInstance); 108 109 /** 110 * Get channel monitoring averaging sample window length (number of samples). 111 * 112 * @param[in] aInstance A pointer to an OpenThread instance. 113 * 114 * @returns The averaging sample window. 115 */ 116 uint32_t otChannelMonitorGetSampleWindow(otInstance *aInstance); 117 118 /** 119 * Get channel monitoring total number of RSSI samples (per channel). 120 * 121 * The count indicates total number samples per channel by channel monitoring module since its start (since Thread 122 * network interface was enabled). 123 * 124 * @param[in] aInstance A pointer to an OpenThread instance. 125 * 126 * @returns Total number of RSSI samples (per channel) taken so far. 127 */ 128 uint32_t otChannelMonitorGetSampleCount(otInstance *aInstance); 129 130 /** 131 * Gets the current channel occupancy for a given channel. 132 * 133 * The channel occupancy value represents the average rate/percentage of RSSI samples that were above RSSI threshold 134 * ("bad" RSSI samples). 135 * 136 * For the first "sample window" samples, the average is maintained as the actual percentage (i.e., ratio of number 137 * of "bad" samples by total number of samples). After "window" samples, the averager uses an exponentially 138 * weighted moving average. Practically, this means the average is representative of up to `3 * window` last samples 139 * with highest weight given to the latest `kSampleWindow` samples. 140 * 141 * Max value of `0xffff` indicates all RSSI samples were above RSSI threshold (i.e. 100% of samples were "bad"). 142 * 143 * @param[in] aInstance A pointer to an OpenThread instance. 144 * @param[in] aChannel The channel for which to get the link occupancy. 145 * 146 * @returns The current channel occupancy for the given channel. 147 */ 148 uint16_t otChannelMonitorGetChannelOccupancy(otInstance *aInstance, uint8_t aChannel); 149 150 /** 151 * @} 152 */ 153 154 #ifdef __cplusplus 155 } // extern "C" 156 #endif 157 158 #endif // OPENTHREAD_CHANNEL_MONITOR_H_ 159