diff --git a/drivers/ieee802154/Kconfig b/drivers/ieee802154/Kconfig index af405551f63251..629b492a579978 100644 --- a/drivers/ieee802154/Kconfig +++ b/drivers/ieee802154/Kconfig @@ -102,6 +102,7 @@ config IEEE802154_SELECTIVE_TXCHANNEL config IEEE802154_CARRIER_FUNCTIONS bool "Support for carrier functions" + default y if OPENTHREAD_DIAG help Enable support for functions such as modulated carrier and continuous carrier. diff --git a/modules/openthread/Kconfig.features b/modules/openthread/Kconfig.features index 4c84a698c24c8f..17031467b7c556 100644 --- a/modules/openthread/Kconfig.features +++ b/modules/openthread/Kconfig.features @@ -144,7 +144,6 @@ config OPENTHREAD_DHCP6_SERVER config OPENTHREAD_DIAG bool "Diagnostic functions support" - depends on IEEE802154_CARRIER_FUNCTIONS help Enable OpenThread CLI diagnostic commands diff --git a/modules/openthread/platform/diag.c b/modules/openthread/platform/diag.c index b92e34209b80cb..8c53962fa5a762 100644 --- a/modules/openthread/platform/diag.c +++ b/modules/openthread/platform/diag.c @@ -7,9 +7,11 @@ #include #include +#include #include #include "platform-zephyr.h" +#include "zephyr/sys/util.h" /** * Diagnostics mode variables. @@ -19,6 +21,8 @@ static bool sDiagMode; static void *sDiagCallbackContext; static otPlatDiagOutputCallback sDiagOutputCallback; +static otError startModCarrier(otInstance *aInstance, uint8_t aArgsLength, char *aArgs[]); + static void diag_output(const char *aFormat, ...) { va_list args; @@ -47,10 +51,20 @@ otError otPlatDiagProcess(otInstance *aInstance, uint8_t aArgsLength, char *aArg ARG_UNUSED(aInstance); ARG_UNUSED(aArgsLength); - /* Add more platform specific diagnostics features here. */ - diag_output("diag feature '%s' is not supported\r\n", aArgs[0]); + otError error = OT_ERROR_NOT_IMPLEMENTED; + +#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS) + if (strcmp(aArgs[0], "modcarrier") == 0) { + error = startModCarrier(aInstance, aArgsLength - 1, aArgs + 1); + } +#endif + + if (error == OT_ERROR_NOT_IMPLEMENTED) { + /* Add more platform specific diagnostics features here. */ + diag_output("diag feature '%s' is not supported\r\n", aArgs[0]); + } - return OT_ERROR_NOT_IMPLEMENTED; + return error; } void otPlatDiagModeSet(bool aMode) @@ -276,3 +290,30 @@ otError otPlatDiagGpioGetMode(uint32_t aGpio, otGpioMode *aMode) #endif /* DT_HAS_COMPAT_STATUS_OKAY(openthread_config) && \ * DT_NODE_HAS_PROP(DT_COMPAT_GET_ANY_STATUS_OKAY(openthread_config), diag_gpios) */ + +#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS) + +static otError startModCarrier(otInstance *aInstance, uint8_t aArgsLength, char *aArgs[]) +{ + ARG_UNUSED(aInstance); + ARG_UNUSED(aArgsLength); + + bool enable = true; + uint8_t data[OT_RADIO_FRAME_MAX_SIZE + 1]; + + if (aArgsLength <= 0) { + return OT_ERROR_INVALID_ARGS; + } + + if (strcmp(aArgs[0], "stop") == 0) { + enable = false; + } else { + if (hex2bin(aArgs[0], strlen(aArgs[0]), data, ARRAY_SIZE(data)) == 0) { + return OT_ERROR_INVALID_ARGS; + } + } + + return platformRadioTransmitModulatedCarrier(aInstance, enable, data); +} + +#endif diff --git a/modules/openthread/platform/platform-zephyr.h b/modules/openthread/platform/platform-zephyr.h index 94fd04d70579ac..ca25fedf2b1899 100644 --- a/modules/openthread/platform/platform-zephyr.h +++ b/modules/openthread/platform/platform-zephyr.h @@ -77,13 +77,20 @@ uint16_t platformRadioChannelGet(otInstance *aInstance); otError platformRadioTransmitCarrier(otInstance *aInstance, bool aEnable); #endif /* CONFIG_IEEE802154_CARRIER_FUNCTIONS */ +#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS) +/** + * Start/stop modulated carrier wave transmission. + */ +otError platformRadioTransmitModulatedCarrier(otInstance *aInstance, bool aEnable, + const uint8_t *aData); +#endif + /** * This function initializes the random number service used by OpenThread. * */ void platformRandomInit(void); - /** * Initialize platform Shell driver. */ diff --git a/modules/openthread/platform/radio.c b/modules/openthread/platform/radio.c index 008dab009930f5..0aaa237ee14d93 100644 --- a/modules/openthread/platform/radio.c +++ b/modules/openthread/platform/radio.c @@ -11,6 +11,7 @@ * */ +#include #define LOG_MODULE_NAME net_otPlat_radio #include @@ -846,6 +847,34 @@ otError platformRadioTransmitCarrier(otInstance *aInstance, bool aEnable) return OT_ERROR_NONE; } + +otError platformRadioTransmitModulatedCarrier(otInstance *aInstance, bool aEnable, + const uint8_t *aData) +{ + if (radio_api->modulated_carrier == NULL) { + return OT_ERROR_NOT_IMPLEMENTED; + } + + if (aEnable && sState == OT_RADIO_STATE_RECEIVE) { + if (aData == NULL) { + return OT_ERROR_INVALID_ARGS; + } + + radio_api->set_txpower(radio_dev, get_transmit_power_for_channel(channel)); + + if (radio_api->modulated_carrier(radio_dev, aData) != 0) { + return OT_ERROR_FAILED; + } + sState = OT_RADIO_STATE_TRANSMIT; + } else if ((!aEnable) && sState == OT_RADIO_STATE_TRANSMIT) { + return otPlatRadioReceive(aInstance, channel); + } else { + return OT_ERROR_INVALID_STATE; + } + + return OT_ERROR_NONE; +} + #endif /* CONFIG_IEEE802154_CARRIER_FUNCTIONS */ otRadioState otPlatRadioGetState(otInstance *aInstance)