1 /* 2 * Copyright (c) 2016, 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 defines the platform diag interface. 33 * 34 */ 35 36 #ifndef OPENTHREAD_PLATFORM_DIAG_H_ 37 #define OPENTHREAD_PLATFORM_DIAG_H_ 38 39 #include <stddef.h> 40 #include <stdint.h> 41 42 #include <openthread/error.h> 43 #include <openthread/platform/radio.h> 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 /** 50 * @addtogroup plat-factory-diagnostics 51 * 52 * @brief 53 * This module includes the platform abstraction for diagnostics features. 54 * 55 * @{ 56 * 57 */ 58 59 /** 60 * Defines the gpio modes. 61 * 62 */ 63 typedef enum 64 { 65 OT_GPIO_MODE_INPUT = 0, ///< Input mode without pull resistor. 66 OT_GPIO_MODE_OUTPUT = 1, ///< Output mode. 67 } otGpioMode; 68 69 /** 70 * Processes a factory diagnostics command line. 71 * 72 * The output of this function (the content written to @p aOutput) MUST terminate with `\0` and the `\0` is within the 73 * output buffer. 74 * 75 * @param[in] aInstance The OpenThread instance for current request. 76 * @param[in] aArgsLength The number of arguments in @p aArgs. 77 * @param[in] aArgs The arguments of diagnostics command line. 78 * @param[out] aOutput The diagnostics execution result. 79 * @param[in] aOutputMaxLen The output buffer size. 80 * 81 * @retval OT_ERROR_INVALID_ARGS The command is supported but invalid arguments provided. 82 * @retval OT_ERROR_NONE The command is successfully process. 83 * @retval OT_ERROR_INVALID_COMMAND The command is not valid or not supported. 84 * 85 */ 86 otError otPlatDiagProcess(otInstance *aInstance, 87 uint8_t aArgsLength, 88 char *aArgs[], 89 char *aOutput, 90 size_t aOutputMaxLen); 91 92 /** 93 * Enables/disables the factory diagnostics mode. 94 * 95 * @param[in] aMode TRUE to enable diagnostics mode, FALSE otherwise. 96 * 97 */ 98 void otPlatDiagModeSet(bool aMode); 99 100 /** 101 * Indicates whether or not factory diagnostics mode is enabled. 102 * 103 * @returns TRUE if factory diagnostics mode is enabled, FALSE otherwise. 104 * 105 */ 106 bool otPlatDiagModeGet(void); 107 108 /** 109 * Sets the channel to use for factory diagnostics. 110 * 111 * @param[in] aChannel The channel value. 112 * 113 */ 114 void otPlatDiagChannelSet(uint8_t aChannel); 115 116 /** 117 * Sets the transmit power to use for factory diagnostics. 118 * 119 * @param[in] aTxPower The transmit power value. 120 * 121 */ 122 void otPlatDiagTxPowerSet(int8_t aTxPower); 123 124 /** 125 * Processes the received radio frame. 126 * 127 * @param[in] aInstance The OpenThread instance for current request. 128 * @param[in] aFrame The received radio frame. 129 * @param[in] aError The received radio frame status. 130 * 131 */ 132 void otPlatDiagRadioReceived(otInstance *aInstance, otRadioFrame *aFrame, otError aError); 133 134 /** 135 * Processes the alarm event. 136 * 137 * @param[in] aInstance The OpenThread instance for current request. 138 * 139 */ 140 void otPlatDiagAlarmCallback(otInstance *aInstance); 141 142 /** 143 * Sets the gpio value. 144 * 145 * @param[in] aGpio The gpio number. 146 * @param[in] aValue true to set the gpio to high level, or false otherwise. 147 * 148 * @retval OT_ERROR_NONE Successfully set the gpio. 149 * @retval OT_ERROR_FAILED A platform error occurred while setting the gpio. 150 * @retval OT_ERROR_INVALID_ARGS @p aGpio is not supported. 151 * @retval OT_ERROR_INVALID_STATE Diagnostic mode was not enabled or @p aGpio is not configured as output. 152 * @retval OT_ERROR_NOT_IMPLEMENTED This function is not implemented or configured on the platform. 153 * 154 */ 155 otError otPlatDiagGpioSet(uint32_t aGpio, bool aValue); 156 157 /** 158 * Gets the gpio value. 159 * 160 * @param[in] aGpio The gpio number. 161 * @param[out] aValue A pointer where to put gpio value. 162 * 163 * @retval OT_ERROR_NONE Successfully got the gpio value. 164 * @retval OT_ERROR_FAILED A platform error occurred while getting the gpio value. 165 * @retval OT_ERROR_INVALID_ARGS @p aGpio is not supported or @p aValue is NULL. 166 * @retval OT_ERROR_INVALID_STATE Diagnostic mode was not enabled or @p aGpio is not configured as input. 167 * @retval OT_ERROR_NOT_IMPLEMENTED This function is not implemented or configured on the platform. 168 * 169 */ 170 otError otPlatDiagGpioGet(uint32_t aGpio, bool *aValue); 171 172 /** 173 * Sets the gpio mode. 174 * 175 * @param[in] aGpio The gpio number. 176 * @param[out] aMode The gpio mode. 177 * 178 * @retval OT_ERROR_NONE Successfully set the gpio mode. 179 * @retval OT_ERROR_FAILED A platform error occurred while setting the gpio mode. 180 * @retval OT_ERROR_INVALID_ARGS @p aGpio or @p aMode is not supported. 181 * @retval OT_ERROR_INVALID_STATE Diagnostic mode was not enabled. 182 * @retval OT_ERROR_NOT_IMPLEMENTED This function is not implemented or configured on the platform. 183 * 184 */ 185 otError otPlatDiagGpioSetMode(uint32_t aGpio, otGpioMode aMode); 186 187 /** 188 * Gets the gpio mode. 189 * 190 * @param[in] aGpio The gpio number. 191 * @param[out] aMode A pointer where to put gpio mode. 192 * 193 * @retval OT_ERROR_NONE Successfully got the gpio mode. 194 * @retval OT_ERROR_FAILED Mode returned by the platform is not implemented in OpenThread or a platform error 195 * occurred while getting the gpio mode. 196 * @retval OT_ERROR_INVALID_ARGS @p aGpio is not supported or @p aMode is NULL. 197 * @retval OT_ERROR_INVALID_STATE Diagnostic mode was not enabled. 198 * @retval OT_ERROR_NOT_IMPLEMENTED This function is not implemented or configured on the platform. 199 * 200 */ 201 otError otPlatDiagGpioGetMode(uint32_t aGpio, otGpioMode *aMode); 202 203 /** 204 * Set the radio raw power setting for diagnostics module. 205 * 206 * @param[in] aInstance The OpenThread instance structure. 207 * @param[in] aRawPowerSetting A pointer to the raw power setting byte array. 208 * @param[in] aRawPowerSettingLength The length of the @p aRawPowerSetting. 209 * 210 * @retval OT_ERROR_NONE Successfully set the raw power setting. 211 * @retval OT_ERROR_INVALID_ARGS The @p aRawPowerSetting is NULL or the @p aRawPowerSettingLength is too long. 212 * @retval OT_ERROR_NOT_IMPLEMENTED This method is not implemented. 213 * 214 */ 215 otError otPlatDiagRadioSetRawPowerSetting(otInstance *aInstance, 216 const uint8_t *aRawPowerSetting, 217 uint16_t aRawPowerSettingLength); 218 219 /** 220 * Get the radio raw power setting for diagnostics module. 221 * 222 * @param[in] aInstance The OpenThread instance structure. 223 * @param[out] aRawPowerSetting A pointer to the raw power setting byte array. 224 * @param[in,out] aRawPowerSettingLength On input, a pointer to the size of @p aRawPowerSetting. 225 * On output, a pointer to the length of the raw power setting data. 226 * 227 * @retval OT_ERROR_NONE Successfully set the raw power setting. 228 * @retval OT_ERROR_INVALID_ARGS The @p aRawPowerSetting or @p aRawPowerSettingLength is NULL or 229 * @aRawPowerSettingLength is too short. 230 * @retval OT_ERROR_NOT_FOUND The raw power setting is not set. 231 * @retval OT_ERROR_NOT_IMPLEMENTED This method is not implemented. 232 * 233 */ 234 otError otPlatDiagRadioGetRawPowerSetting(otInstance *aInstance, 235 uint8_t *aRawPowerSetting, 236 uint16_t *aRawPowerSettingLength); 237 238 /** 239 * Enable/disable the platform layer to use the raw power setting set by `otPlatDiagRadioSetRawPowerSetting()`. 240 * 241 * @param[in] aInstance The OpenThread instance structure. 242 * @param[in] aEnable TRUE to enable or FALSE to disable the raw power setting. 243 * 244 * @retval OT_ERROR_NONE Successfully enabled/disabled the raw power setting. 245 * @retval OT_ERROR_NOT_IMPLEMENTED This method is not implemented. 246 * 247 */ 248 otError otPlatDiagRadioRawPowerSettingEnable(otInstance *aInstance, bool aEnable); 249 250 /** 251 * Start/stop the platform layer to transmit continuous carrier wave. 252 * 253 * @param[in] aInstance The OpenThread instance structure. 254 * @param[in] aEnable TRUE to enable or FALSE to disable the platform layer to transmit continuous carrier wave. 255 * 256 * @retval OT_ERROR_NONE Successfully enabled/disabled . 257 * @retval OT_ERROR_INVALID_STATE The radio was not in the Receive state. 258 * @retval OT_ERROR_NOT_IMPLEMENTED This method is not implemented. 259 * 260 */ 261 otError otPlatDiagRadioTransmitCarrier(otInstance *aInstance, bool aEnable); 262 263 /** 264 * Start/stop the platform layer to transmit stream of characters. 265 * 266 * @param[in] aInstance The OpenThread instance structure. 267 * @param[in] aEnable TRUE to enable or FALSE to disable the platform layer to transmit stream. 268 * 269 * @retval OT_ERROR_NONE Successfully enabled/disabled. 270 * @retval OT_ERROR_INVALID_STATE The radio was not in the Receive state. 271 * @retval OT_ERROR_NOT_IMPLEMENTED This function is not implemented. 272 * 273 */ 274 otError otPlatDiagRadioTransmitStream(otInstance *aInstance, bool aEnable); 275 276 /** 277 * Get the power settings for the given channel. 278 * 279 * @param[in] aInstance The OpenThread instance structure. 280 * @param[in] aChannel The radio channel. 281 * @param[out] aTargetPower The target power in 0.01 dBm. 282 * @param[out] aActualPower The actual power in 0.01 dBm. 283 * @param[out] aRawPowerSetting A pointer to the raw power setting byte array. 284 * @param[in,out] aRawPowerSettingLength On input, a pointer to the size of @p aRawPowerSetting. 285 * On output, a pointer to the length of the raw power setting data. 286 * 287 * @retval OT_ERROR_NONE Successfully got the target power. 288 * @retval OT_ERROR_INVALID_ARGS The @p aChannel is invalid, @aTargetPower, @p aActualPower, @p aRawPowerSetting or 289 * @p aRawPowerSettingLength is NULL or @aRawPowerSettingLength is too short. 290 * @retval OT_ERROR_NOT_FOUND The power settings for the @p aChannel was not found. 291 * @retval OT_ERROR_NOT_IMPLEMENTED This method is not implemented. 292 * 293 */ 294 otError otPlatDiagRadioGetPowerSettings(otInstance *aInstance, 295 uint8_t aChannel, 296 int16_t *aTargetPower, 297 int16_t *aActualPower, 298 uint8_t *aRawPowerSetting, 299 uint16_t *aRawPowerSettingLength); 300 301 /** 302 * @} 303 * 304 */ 305 306 #ifdef __cplusplus 307 } // end of extern "C" 308 #endif 309 310 #endif // OPENTHREAD_PLATFORM_DIAG_H_ 311