1*cfb92d14SAndroid Build Coastguard Worker /* 2*cfb92d14SAndroid Build Coastguard Worker * Copyright (c) 2018, The OpenThread Authors. 3*cfb92d14SAndroid Build Coastguard Worker * All rights reserved. 4*cfb92d14SAndroid Build Coastguard Worker * 5*cfb92d14SAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without 6*cfb92d14SAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions are met: 7*cfb92d14SAndroid Build Coastguard Worker * 1. Redistributions of source code must retain the above copyright 8*cfb92d14SAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer. 9*cfb92d14SAndroid Build Coastguard Worker * 2. Redistributions in binary form must reproduce the above copyright 10*cfb92d14SAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer in the 11*cfb92d14SAndroid Build Coastguard Worker * documentation and/or other materials provided with the distribution. 12*cfb92d14SAndroid Build Coastguard Worker * 3. Neither the name of the copyright holder nor the 13*cfb92d14SAndroid Build Coastguard Worker * names of its contributors may be used to endorse or promote products 14*cfb92d14SAndroid Build Coastguard Worker * derived from this software without specific prior written permission. 15*cfb92d14SAndroid Build Coastguard Worker * 16*cfb92d14SAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17*cfb92d14SAndroid Build Coastguard Worker * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*cfb92d14SAndroid Build Coastguard Worker * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*cfb92d14SAndroid Build Coastguard Worker * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20*cfb92d14SAndroid Build Coastguard Worker * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21*cfb92d14SAndroid Build Coastguard Worker * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22*cfb92d14SAndroid Build Coastguard Worker * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23*cfb92d14SAndroid Build Coastguard Worker * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24*cfb92d14SAndroid Build Coastguard Worker * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25*cfb92d14SAndroid Build Coastguard Worker * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26*cfb92d14SAndroid Build Coastguard Worker * POSSIBILITY OF SUCH DAMAGE. 27*cfb92d14SAndroid Build Coastguard Worker */ 28*cfb92d14SAndroid Build Coastguard Worker 29*cfb92d14SAndroid Build Coastguard Worker /** 30*cfb92d14SAndroid Build Coastguard Worker * @file 31*cfb92d14SAndroid Build Coastguard Worker * @brief 32*cfb92d14SAndroid Build Coastguard Worker * This file includes the OpenThread API for channel monitoring feature 33*cfb92d14SAndroid Build Coastguard Worker */ 34*cfb92d14SAndroid Build Coastguard Worker 35*cfb92d14SAndroid Build Coastguard Worker #ifndef OPENTHREAD_CHANNEL_MONITOR_H_ 36*cfb92d14SAndroid Build Coastguard Worker #define OPENTHREAD_CHANNEL_MONITOR_H_ 37*cfb92d14SAndroid Build Coastguard Worker 38*cfb92d14SAndroid Build Coastguard Worker #include <openthread/instance.h> 39*cfb92d14SAndroid Build Coastguard Worker 40*cfb92d14SAndroid Build Coastguard Worker #ifdef __cplusplus 41*cfb92d14SAndroid Build Coastguard Worker extern "C" { 42*cfb92d14SAndroid Build Coastguard Worker #endif 43*cfb92d14SAndroid Build Coastguard Worker 44*cfb92d14SAndroid Build Coastguard Worker /** 45*cfb92d14SAndroid Build Coastguard Worker * @addtogroup api-channel-monitor 46*cfb92d14SAndroid Build Coastguard Worker * 47*cfb92d14SAndroid Build Coastguard Worker * @brief 48*cfb92d14SAndroid Build Coastguard Worker * This module includes functions for channel monitoring feature. 49*cfb92d14SAndroid Build Coastguard Worker * 50*cfb92d14SAndroid Build Coastguard Worker * The functions in this module are available when channel monitor feature 51*cfb92d14SAndroid Build Coastguard Worker * (`OPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE`) is enabled. 52*cfb92d14SAndroid Build Coastguard Worker * 53*cfb92d14SAndroid Build Coastguard Worker * Channel monitoring will periodically monitor all channels to help determine the cleaner channels (channels 54*cfb92d14SAndroid Build Coastguard Worker * with less interference). 55*cfb92d14SAndroid Build Coastguard Worker * 56*cfb92d14SAndroid Build Coastguard Worker * When channel monitoring is active, a zero-duration Energy Scan is performed, collecting a single RSSI sample on 57*cfb92d14SAndroid Build Coastguard Worker * every channel per sample interval. The RSSI samples are compared with a pre-specified RSSI threshold. As an 58*cfb92d14SAndroid Build Coastguard Worker * indicator of channel quality, the channel monitoring module maintains and provides the average rate/percentage of 59*cfb92d14SAndroid Build Coastguard Worker * RSSI samples that are above the threshold within (approximately) a specified sample window (referred to as channel 60*cfb92d14SAndroid Build Coastguard Worker * occupancy). 61*cfb92d14SAndroid Build Coastguard Worker * 62*cfb92d14SAndroid Build Coastguard Worker * @{ 63*cfb92d14SAndroid Build Coastguard Worker * 64*cfb92d14SAndroid Build Coastguard Worker */ 65*cfb92d14SAndroid Build Coastguard Worker 66*cfb92d14SAndroid Build Coastguard Worker /** 67*cfb92d14SAndroid Build Coastguard Worker * Enables or disables the Channel Monitoring operation. 68*cfb92d14SAndroid Build Coastguard Worker * 69*cfb92d14SAndroid Build Coastguard Worker * Once operation starts, any previously collected data is cleared. However, after operation is disabled, the previous 70*cfb92d14SAndroid Build Coastguard Worker * collected data is still valid and can be read. 71*cfb92d14SAndroid Build Coastguard Worker * 72*cfb92d14SAndroid Build Coastguard Worker * @note OpenThread core internally enables or disables the Channel Monitoring operation when the IPv6 interface is 73*cfb92d14SAndroid Build Coastguard Worker * brought up or down, for example in a call to `otIp6SetEnabled()`. 74*cfb92d14SAndroid Build Coastguard Worker * 75*cfb92d14SAndroid Build Coastguard Worker * @param[in] aInstance A pointer to an OpenThread instance. 76*cfb92d14SAndroid Build Coastguard Worker * @param[in] aEnabled TRUE to enable/start Channel Monitoring operation, FALSE to disable/stop it. 77*cfb92d14SAndroid Build Coastguard Worker * 78*cfb92d14SAndroid Build Coastguard Worker * @retval OT_ERROR_NONE Channel Monitoring state changed successfully 79*cfb92d14SAndroid Build Coastguard Worker * @retval OT_ERROR_ALREADY Channel Monitoring is already in the same state. 80*cfb92d14SAndroid Build Coastguard Worker * 81*cfb92d14SAndroid Build Coastguard Worker */ 82*cfb92d14SAndroid Build Coastguard Worker otError otChannelMonitorSetEnabled(otInstance *aInstance, bool aEnabled); 83*cfb92d14SAndroid Build Coastguard Worker 84*cfb92d14SAndroid Build Coastguard Worker /** 85*cfb92d14SAndroid Build Coastguard Worker * Indicates whether the Channel Monitoring operation is enabled and running. 86*cfb92d14SAndroid Build Coastguard Worker * 87*cfb92d14SAndroid Build Coastguard Worker * @param[in] aInstance A pointer to an OpenThread instance. 88*cfb92d14SAndroid Build Coastguard Worker * 89*cfb92d14SAndroid Build Coastguard Worker * @returns TRUE if the Channel Monitoring operation is enabled, FALSE otherwise. 90*cfb92d14SAndroid Build Coastguard Worker * 91*cfb92d14SAndroid Build Coastguard Worker */ 92*cfb92d14SAndroid Build Coastguard Worker bool otChannelMonitorIsEnabled(otInstance *aInstance); 93*cfb92d14SAndroid Build Coastguard Worker 94*cfb92d14SAndroid Build Coastguard Worker /** 95*cfb92d14SAndroid Build Coastguard Worker * Get channel monitoring sample interval in milliseconds. 96*cfb92d14SAndroid Build Coastguard Worker * 97*cfb92d14SAndroid Build Coastguard Worker * @param[in] aInstance A pointer to an OpenThread instance. 98*cfb92d14SAndroid Build Coastguard Worker * 99*cfb92d14SAndroid Build Coastguard Worker * @returns The channel monitor sample interval in milliseconds. 100*cfb92d14SAndroid Build Coastguard Worker * 101*cfb92d14SAndroid Build Coastguard Worker */ 102*cfb92d14SAndroid Build Coastguard Worker uint32_t otChannelMonitorGetSampleInterval(otInstance *aInstance); 103*cfb92d14SAndroid Build Coastguard Worker 104*cfb92d14SAndroid Build Coastguard Worker /** 105*cfb92d14SAndroid Build Coastguard Worker * Get channel monitoring RSSI threshold in dBm. 106*cfb92d14SAndroid Build Coastguard Worker * 107*cfb92d14SAndroid Build Coastguard Worker * @param[in] aInstance A pointer to an OpenThread instance. 108*cfb92d14SAndroid Build Coastguard Worker * 109*cfb92d14SAndroid Build Coastguard Worker * @returns The RSSI threshold in dBm. 110*cfb92d14SAndroid Build Coastguard Worker * 111*cfb92d14SAndroid Build Coastguard Worker */ 112*cfb92d14SAndroid Build Coastguard Worker int8_t otChannelMonitorGetRssiThreshold(otInstance *aInstance); 113*cfb92d14SAndroid Build Coastguard Worker 114*cfb92d14SAndroid Build Coastguard Worker /** 115*cfb92d14SAndroid Build Coastguard Worker * Get channel monitoring averaging sample window length (number of samples). 116*cfb92d14SAndroid Build Coastguard Worker * 117*cfb92d14SAndroid Build Coastguard Worker * @param[in] aInstance A pointer to an OpenThread instance. 118*cfb92d14SAndroid Build Coastguard Worker * 119*cfb92d14SAndroid Build Coastguard Worker * @returns The averaging sample window. 120*cfb92d14SAndroid Build Coastguard Worker * 121*cfb92d14SAndroid Build Coastguard Worker */ 122*cfb92d14SAndroid Build Coastguard Worker uint32_t otChannelMonitorGetSampleWindow(otInstance *aInstance); 123*cfb92d14SAndroid Build Coastguard Worker 124*cfb92d14SAndroid Build Coastguard Worker /** 125*cfb92d14SAndroid Build Coastguard Worker * Get channel monitoring total number of RSSI samples (per channel). 126*cfb92d14SAndroid Build Coastguard Worker * 127*cfb92d14SAndroid Build Coastguard Worker * The count indicates total number samples per channel by channel monitoring module since its start (since Thread 128*cfb92d14SAndroid Build Coastguard Worker * network interface was enabled). 129*cfb92d14SAndroid Build Coastguard Worker * 130*cfb92d14SAndroid Build Coastguard Worker * @param[in] aInstance A pointer to an OpenThread instance. 131*cfb92d14SAndroid Build Coastguard Worker * 132*cfb92d14SAndroid Build Coastguard Worker * @returns Total number of RSSI samples (per channel) taken so far. 133*cfb92d14SAndroid Build Coastguard Worker * 134*cfb92d14SAndroid Build Coastguard Worker */ 135*cfb92d14SAndroid Build Coastguard Worker uint32_t otChannelMonitorGetSampleCount(otInstance *aInstance); 136*cfb92d14SAndroid Build Coastguard Worker 137*cfb92d14SAndroid Build Coastguard Worker /** 138*cfb92d14SAndroid Build Coastguard Worker * Gets the current channel occupancy for a given channel. 139*cfb92d14SAndroid Build Coastguard Worker * 140*cfb92d14SAndroid Build Coastguard Worker * The channel occupancy value represents the average rate/percentage of RSSI samples that were above RSSI threshold 141*cfb92d14SAndroid Build Coastguard Worker * ("bad" RSSI samples). 142*cfb92d14SAndroid Build Coastguard Worker * 143*cfb92d14SAndroid Build Coastguard Worker * For the first "sample window" samples, the average is maintained as the actual percentage (i.e., ratio of number 144*cfb92d14SAndroid Build Coastguard Worker * of "bad" samples by total number of samples). After "window" samples, the averager uses an exponentially 145*cfb92d14SAndroid Build Coastguard Worker * weighted moving average. Practically, this means the average is representative of up to `3 * window` last samples 146*cfb92d14SAndroid Build Coastguard Worker * with highest weight given to the latest `kSampleWindow` samples. 147*cfb92d14SAndroid Build Coastguard Worker * 148*cfb92d14SAndroid Build Coastguard Worker * Max value of `0xffff` indicates all RSSI samples were above RSSI threshold (i.e. 100% of samples were "bad"). 149*cfb92d14SAndroid Build Coastguard Worker * 150*cfb92d14SAndroid Build Coastguard Worker * @param[in] aInstance A pointer to an OpenThread instance. 151*cfb92d14SAndroid Build Coastguard Worker * @param[in] aChannel The channel for which to get the link occupancy. 152*cfb92d14SAndroid Build Coastguard Worker * 153*cfb92d14SAndroid Build Coastguard Worker * @returns The current channel occupancy for the given channel. 154*cfb92d14SAndroid Build Coastguard Worker * 155*cfb92d14SAndroid Build Coastguard Worker */ 156*cfb92d14SAndroid Build Coastguard Worker uint16_t otChannelMonitorGetChannelOccupancy(otInstance *aInstance, uint8_t aChannel); 157*cfb92d14SAndroid Build Coastguard Worker 158*cfb92d14SAndroid Build Coastguard Worker /** 159*cfb92d14SAndroid Build Coastguard Worker * @} 160*cfb92d14SAndroid Build Coastguard Worker * 161*cfb92d14SAndroid Build Coastguard Worker */ 162*cfb92d14SAndroid Build Coastguard Worker 163*cfb92d14SAndroid Build Coastguard Worker #ifdef __cplusplus 164*cfb92d14SAndroid Build Coastguard Worker } // extern "C" 165*cfb92d14SAndroid Build Coastguard Worker #endif 166*cfb92d14SAndroid Build Coastguard Worker 167*cfb92d14SAndroid Build Coastguard Worker #endif // OPENTHREAD_CHANNEL_MONITOR_H_ 168