Skip to content

Commit

Permalink
net: openthread: Add modcarrier command to OT diag module.
Browse files Browse the repository at this point in the history
Commit add `modcarrier` shell command for Openthread diagnostic mode.
Command can transmit modulated carrier out of device for test purposes.

Signed-off-by: Przemyslaw Bida <[email protected]>
  • Loading branch information
canisLupus1313 committed Dec 2, 2024
1 parent 6f26952 commit c99f012
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 7 deletions.
1 change: 1 addition & 0 deletions drivers/ieee802154/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 0 additions & 1 deletion modules/openthread/Kconfig.features
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
48 changes: 43 additions & 5 deletions modules/openthread/platform/diag.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>

#include <openthread/error.h>
#include <openthread/platform/diag.h>

#include "platform-zephyr.h"
#include "zephyr/sys/util.h"

/**
* Diagnostics mode variables.
Expand All @@ -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;
Expand All @@ -44,13 +48,20 @@ void otPlatDiagSetOutputCallback(otInstance *aInstance,

otError otPlatDiagProcess(otInstance *aInstance, uint8_t aArgsLength, char *aArgs[])
{
ARG_UNUSED(aInstance);
ARG_UNUSED(aArgsLength);
otError error = OT_ERROR_NOT_IMPLEMENTED;

/* Add more platform specific diagnostics features here. */
diag_output("diag feature '%s' is not supported\r\n", aArgs[0]);
#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS)
if (strcmp(aArgs[0], "modcarrier") == 0) {
error = startModCarrier(aInstance, aArgsLength - 1, aArgs + 1);
}
#endif

return OT_ERROR_NOT_IMPLEMENTED;
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 error;
}

void otPlatDiagModeSet(bool aMode)
Expand Down Expand Up @@ -276,3 +287,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
9 changes: 8 additions & 1 deletion modules/openthread/platform/platform-zephyr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
29 changes: 29 additions & 0 deletions modules/openthread/platform/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*
*/

#include <openthread/error.h>
#define LOG_MODULE_NAME net_otPlat_radio

#include <zephyr/logging/log.h>
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c99f012

Please sign in to comment.