Skip to content

Commit

Permalink
[nrf fromtree] net: openthread: Add modcarrier command to OT diag m…
Browse files Browse the repository at this point in the history
…odule.

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]>
(cherry picked from commit 63e1bb41b103426a15b53e2dcaaf53655b3bafb8)
  • Loading branch information
canisLupus1313 committed Dec 5, 2024
1 parent 98f4625 commit 22ed697
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 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 @@ -136,7 +136,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
37 changes: 37 additions & 0 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 Down Expand Up @@ -47,6 +51,12 @@ otError otPlatDiagProcess(otInstance *aInstance, uint8_t aArgsLength, char *aArg
ARG_UNUSED(aInstance);
ARG_UNUSED(aArgsLength);

#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS)
if (strcmp(aArgs[0], "modcarrier") == 0) {
return startModCarrier(aInstance, aArgsLength - 1, aArgs + 1);
}
#endif

/* Add more platform specific diagnostics features here. */
diag_output("diag feature '%s' is not supported\r\n", aArgs[0]);

Expand Down Expand Up @@ -276,3 +286,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 @@ -832,6 +833,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 22ed697

Please sign in to comment.