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 * Pointer to callback to output platform diag messages. 71 * 72 * @param[in] aFormat The format string. 73 * @param[in] aArguments The format string arguments. 74 * @param[out] aContext A pointer to the user context. 75 * 76 */ 77 typedef void (*otPlatDiagOutputCallback)(const char *aFormat, va_list aArguments, void *aContext); 78 79 /** 80 * Sets the platform diag output callback. 81 * 82 * @param[in] aInstance The OpenThread instance structure. 83 * @param[in] aCallback A pointer to a function that is called on outputting diag messages. 84 * @param[in] aContext A pointer to the user context. 85 * 86 */ 87 void otPlatDiagSetOutputCallback(otInstance *aInstance, otPlatDiagOutputCallback aCallback, void *aContext); 88 89 /** 90 * Processes a factory diagnostics command line. 91 * 92 * @param[in] aInstance The OpenThread instance for current request. 93 * @param[in] aArgsLength The number of arguments in @p aArgs. 94 * @param[in] aArgs The arguments of diagnostics command line. 95 * 96 * @retval OT_ERROR_INVALID_ARGS The command is supported but invalid arguments provided. 97 * @retval OT_ERROR_NONE The command is successfully process. 98 * @retval OT_ERROR_INVALID_COMMAND The command is not valid or not supported. 99 * 100 */ 101 otError otPlatDiagProcess(otInstance *aInstance, uint8_t aArgsLength, char *aArgs[]); 102 103 /** 104 * Enables/disables the factory diagnostics mode. 105 * 106 * @param[in] aMode TRUE to enable diagnostics mode, FALSE otherwise. 107 * 108 */ 109 void otPlatDiagModeSet(bool aMode); 110 111 /** 112 * Indicates whether or not factory diagnostics mode is enabled. 113 * 114 * @returns TRUE if factory diagnostics mode is enabled, FALSE otherwise. 115 * 116 */ 117 bool otPlatDiagModeGet(void); 118 119 /** 120 * Sets the channel to use for factory diagnostics. 121 * 122 * @param[in] aChannel The channel value. 123 * 124 */ 125 void otPlatDiagChannelSet(uint8_t aChannel); 126 127 /** 128 * Sets the transmit power to use for factory diagnostics. 129 * 130 * @param[in] aTxPower The transmit power value. 131 * 132 */ 133 void otPlatDiagTxPowerSet(int8_t aTxPower); 134 135 /** 136 * Processes the received radio frame. 137 * 138 * @param[in] aInstance The OpenThread instance for current request. 139 * @param[in] aFrame The received radio frame. 140 * @param[in] aError The received radio frame status. 141 * 142 */ 143 void otPlatDiagRadioReceived(otInstance *aInstance, otRadioFrame *aFrame, otError aError); 144 145 /** 146 * Processes the alarm event. 147 * 148 * @param[in] aInstance The OpenThread instance for current request. 149 * 150 */ 151 void otPlatDiagAlarmCallback(otInstance *aInstance); 152 153 /** 154 * Sets the gpio value. 155 * 156 * @param[in] aGpio The gpio number. 157 * @param[in] aValue true to set the gpio to high level, or false otherwise. 158 * 159 * @retval OT_ERROR_NONE Successfully set the gpio. 160 * @retval OT_ERROR_FAILED A platform error occurred while setting the gpio. 161 * @retval OT_ERROR_INVALID_ARGS @p aGpio is not supported. 162 * @retval OT_ERROR_INVALID_STATE Diagnostic mode was not enabled or @p aGpio is not configured as output. 163 * @retval OT_ERROR_NOT_IMPLEMENTED This function is not implemented or configured on the platform. 164 * 165 */ 166 otError otPlatDiagGpioSet(uint32_t aGpio, bool aValue); 167 168 /** 169 * Gets the gpio value. 170 * 171 * @param[in] aGpio The gpio number. 172 * @param[out] aValue A pointer where to put gpio value. 173 * 174 * @retval OT_ERROR_NONE Successfully got the gpio value. 175 * @retval OT_ERROR_FAILED A platform error occurred while getting the gpio value. 176 * @retval OT_ERROR_INVALID_ARGS @p aGpio is not supported or @p aValue is NULL. 177 * @retval OT_ERROR_INVALID_STATE Diagnostic mode was not enabled or @p aGpio is not configured as input. 178 * @retval OT_ERROR_NOT_IMPLEMENTED This function is not implemented or configured on the platform. 179 * 180 */ 181 otError otPlatDiagGpioGet(uint32_t aGpio, bool *aValue); 182 183 /** 184 * Sets the gpio mode. 185 * 186 * @param[in] aGpio The gpio number. 187 * @param[out] aMode The gpio mode. 188 * 189 * @retval OT_ERROR_NONE Successfully set the gpio mode. 190 * @retval OT_ERROR_FAILED A platform error occurred while setting the gpio mode. 191 * @retval OT_ERROR_INVALID_ARGS @p aGpio or @p aMode is not supported. 192 * @retval OT_ERROR_INVALID_STATE Diagnostic mode was not enabled. 193 * @retval OT_ERROR_NOT_IMPLEMENTED This function is not implemented or configured on the platform. 194 * 195 */ 196 otError otPlatDiagGpioSetMode(uint32_t aGpio, otGpioMode aMode); 197 198 /** 199 * Gets the gpio mode. 200 * 201 * @param[in] aGpio The gpio number. 202 * @param[out] aMode A pointer where to put gpio mode. 203 * 204 * @retval OT_ERROR_NONE Successfully got the gpio mode. 205 * @retval OT_ERROR_FAILED Mode returned by the platform is not implemented in OpenThread or a platform error 206 * occurred while getting the gpio mode. 207 * @retval OT_ERROR_INVALID_ARGS @p aGpio is not supported or @p aMode is NULL. 208 * @retval OT_ERROR_INVALID_STATE Diagnostic mode was not enabled. 209 * @retval OT_ERROR_NOT_IMPLEMENTED This function is not implemented or configured on the platform. 210 * 211 */ 212 otError otPlatDiagGpioGetMode(uint32_t aGpio, otGpioMode *aMode); 213 214 /** 215 * Set the radio raw power setting for diagnostics module. 216 * 217 * @param[in] aInstance The OpenThread instance structure. 218 * @param[in] aRawPowerSetting A pointer to the raw power setting byte array. 219 * @param[in] aRawPowerSettingLength The length of the @p aRawPowerSetting. 220 * 221 * @retval OT_ERROR_NONE Successfully set the raw power setting. 222 * @retval OT_ERROR_INVALID_ARGS The @p aRawPowerSetting is NULL or the @p aRawPowerSettingLength is too long. 223 * @retval OT_ERROR_NOT_IMPLEMENTED This method is not implemented. 224 * 225 */ 226 otError otPlatDiagRadioSetRawPowerSetting(otInstance *aInstance, 227 const uint8_t *aRawPowerSetting, 228 uint16_t aRawPowerSettingLength); 229 230 /** 231 * Get the radio raw power setting for diagnostics module. 232 * 233 * @param[in] aInstance The OpenThread instance structure. 234 * @param[out] aRawPowerSetting A pointer to the raw power setting byte array. 235 * @param[in,out] aRawPowerSettingLength On input, a pointer to the size of @p aRawPowerSetting. 236 * On output, a pointer to the length of the raw power setting data. 237 * 238 * @retval OT_ERROR_NONE Successfully set the raw power setting. 239 * @retval OT_ERROR_INVALID_ARGS The @p aRawPowerSetting or @p aRawPowerSettingLength is NULL or 240 * @aRawPowerSettingLength is too short. 241 * @retval OT_ERROR_NOT_FOUND The raw power setting is not set. 242 * @retval OT_ERROR_NOT_IMPLEMENTED This method is not implemented. 243 * 244 */ 245 otError otPlatDiagRadioGetRawPowerSetting(otInstance *aInstance, 246 uint8_t *aRawPowerSetting, 247 uint16_t *aRawPowerSettingLength); 248 249 /** 250 * Enable/disable the platform layer to use the raw power setting set by `otPlatDiagRadioSetRawPowerSetting()`. 251 * 252 * @param[in] aInstance The OpenThread instance structure. 253 * @param[in] aEnable TRUE to enable or FALSE to disable the raw power setting. 254 * 255 * @retval OT_ERROR_NONE Successfully enabled/disabled the raw power setting. 256 * @retval OT_ERROR_NOT_IMPLEMENTED This method is not implemented. 257 * 258 */ 259 otError otPlatDiagRadioRawPowerSettingEnable(otInstance *aInstance, bool aEnable); 260 261 /** 262 * Start/stop the platform layer to transmit continuous carrier wave. 263 * 264 * @param[in] aInstance The OpenThread instance structure. 265 * @param[in] aEnable TRUE to enable or FALSE to disable the platform layer to transmit continuous carrier wave. 266 * 267 * @retval OT_ERROR_NONE Successfully enabled/disabled . 268 * @retval OT_ERROR_INVALID_STATE The radio was not in the Receive state. 269 * @retval OT_ERROR_NOT_IMPLEMENTED This method is not implemented. 270 * 271 */ 272 otError otPlatDiagRadioTransmitCarrier(otInstance *aInstance, bool aEnable); 273 274 /** 275 * Start/stop the platform layer to transmit stream of characters. 276 * 277 * @param[in] aInstance The OpenThread instance structure. 278 * @param[in] aEnable TRUE to enable or FALSE to disable the platform layer to transmit stream. 279 * 280 * @retval OT_ERROR_NONE Successfully enabled/disabled. 281 * @retval OT_ERROR_INVALID_STATE The radio was not in the Receive state. 282 * @retval OT_ERROR_NOT_IMPLEMENTED This function is not implemented. 283 * 284 */ 285 otError otPlatDiagRadioTransmitStream(otInstance *aInstance, bool aEnable); 286 287 /** 288 * Get the power settings for the given channel. 289 * 290 * @param[in] aInstance The OpenThread instance structure. 291 * @param[in] aChannel The radio channel. 292 * @param[out] aTargetPower The target power in 0.01 dBm. 293 * @param[out] aActualPower The actual power in 0.01 dBm. 294 * @param[out] aRawPowerSetting A pointer to the raw power setting byte array. 295 * @param[in,out] aRawPowerSettingLength On input, a pointer to the size of @p aRawPowerSetting. 296 * On output, a pointer to the length of the raw power setting data. 297 * 298 * @retval OT_ERROR_NONE Successfully got the target power. 299 * @retval OT_ERROR_INVALID_ARGS The @p aChannel is invalid, @aTargetPower, @p aActualPower, @p aRawPowerSetting or 300 * @p aRawPowerSettingLength is NULL or @aRawPowerSettingLength is too short. 301 * @retval OT_ERROR_NOT_FOUND The power settings for the @p aChannel was not found. 302 * @retval OT_ERROR_NOT_IMPLEMENTED This method is not implemented. 303 * 304 */ 305 otError otPlatDiagRadioGetPowerSettings(otInstance *aInstance, 306 uint8_t aChannel, 307 int16_t *aTargetPower, 308 int16_t *aActualPower, 309 uint8_t *aRawPowerSetting, 310 uint16_t *aRawPowerSettingLength); 311 312 /** 313 * @} 314 * 315 */ 316 317 #ifdef __cplusplus 318 } // end of extern "C" 319 #endif 320 321 #endif // OPENTHREAD_PLATFORM_DIAG_H_ 322