mirror of
https://github.com/espressif/openthread.git
synced 2026-08-05 10:27:49 +00:00
[cli] add CLI command to enable/disable TREL (#6949)
This commit is contained in:
@@ -53,7 +53,7 @@ extern "C" {
|
||||
* @note This number versions both OpenThread platform and user APIs.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_API_VERSION (157)
|
||||
#define OPENTHREAD_API_VERSION (158)
|
||||
|
||||
/**
|
||||
* @addtogroup api-instance
|
||||
|
||||
@@ -137,6 +137,7 @@ extern void otPlatTrelUdp6HandleReceived(otInstance *aInstance, uint8_t *aBuffer
|
||||
* @param[in] aEnable Indicates whether to enable/disable the TREL interface.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully changed the TREL interface test status (enabled/disabled).
|
||||
* @retval OT_ERROR_FAILED Failed to enable the TREL interface.
|
||||
* @retval OT_ERROR_NOT_IMPLEMENTED This function is not provided by the platform.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -106,6 +106,7 @@ Done
|
||||
- [state](#state)
|
||||
- [srp](README_SRP.md)
|
||||
- [thread](#thread-start)
|
||||
- [trel](#trel-enable)
|
||||
- [txpower](#txpower)
|
||||
- [udp](README_UDP.md)
|
||||
- [unsecureport](#unsecureport-add-port)
|
||||
@@ -2513,6 +2514,30 @@ Get the Thread Version number.
|
||||
Done
|
||||
```
|
||||
|
||||
### trel enable
|
||||
|
||||
Enable TREL radio link.
|
||||
|
||||
`OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE` is required.
|
||||
|
||||
Note: TREL radio link can be enabled only when a valid TREL URL was specified.
|
||||
|
||||
```bash
|
||||
> trel enable
|
||||
Done
|
||||
```
|
||||
|
||||
### trel disable
|
||||
|
||||
Disable TREL radio link.
|
||||
|
||||
`OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE` is required.
|
||||
|
||||
```bash
|
||||
> trel disable
|
||||
Done
|
||||
```
|
||||
|
||||
### txpower
|
||||
|
||||
Get the transmit power in dBm.
|
||||
|
||||
@@ -81,6 +81,9 @@
|
||||
#if (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_DEBUG_UART) && OPENTHREAD_POSIX
|
||||
#include <openthread/platform/debug_uart.h>
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
|
||||
#include <openthread/platform/trel-udp6.h>
|
||||
#endif
|
||||
|
||||
#include "common/logging.hpp"
|
||||
#include "common/new.hpp"
|
||||
@@ -4544,6 +4547,21 @@ exit:
|
||||
}
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
|
||||
otError Interpreter::ProcessTrel(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
bool enable;
|
||||
|
||||
SuccessOrExit(error = ParseEnableOrDisable(aArgs[0], enable));
|
||||
|
||||
error = otPlatTrelUdp6SetTestMode(mInstance, enable);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_DIAG_ENABLE
|
||||
otError Interpreter::ProcessDiag(Arg aArgs[])
|
||||
{
|
||||
|
||||
@@ -667,6 +667,9 @@ private:
|
||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
otError ProcessMacSend(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
|
||||
otError ProcessTrel(Arg aArgs[]);
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_PING_SENDER_ENABLE
|
||||
static void HandlePingReply(const otPingSenderReply *aReply, void *aContext);
|
||||
@@ -931,6 +934,9 @@ private:
|
||||
{"tcp", &Interpreter::ProcessTcp},
|
||||
#endif
|
||||
{"thread", &Interpreter::ProcessThread},
|
||||
#if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
|
||||
{"trel", &Interpreter::ProcessTrel},
|
||||
#endif
|
||||
{"txpower", &Interpreter::ProcessTxPower},
|
||||
{"udp", &Interpreter::ProcessUdp},
|
||||
{"unsecureport", &Interpreter::ProcessUnsecurePort},
|
||||
|
||||
@@ -84,6 +84,7 @@ static TxPacket sTxPacketPool[TREL_PACKET_POOL_SIZE];
|
||||
static TxPacket * sFreeTxPacketHead; // A singly linked list of free/available `TxPacket` from pool.
|
||||
static TxPacket * sTxPacketQueueTail; // A circular linked list for queued tx packets.
|
||||
static char sInterfaceName[IFNAMSIZ + 1];
|
||||
static bool sInitialized = false;
|
||||
static bool sEnabled = false;
|
||||
static int sInterfaceIndex = -1;
|
||||
static int sMulticastSocket = -1;
|
||||
@@ -398,7 +399,10 @@ static void ReceivePacket(int aSocket, otInstance *aInstance)
|
||||
Ip6AddrToString(&sockAddr.sin6_addr), ntohs(sockAddr.sin6_port), sockAddr.sin6_scope_id,
|
||||
BufferToString(sRxPacketBuffer, sRxPacketLength));
|
||||
|
||||
otPlatTrelUdp6HandleReceived(aInstance, sRxPacketBuffer, sRxPacketLength);
|
||||
if (sEnabled)
|
||||
{
|
||||
otPlatTrelUdp6HandleReceived(aInstance, sRxPacketBuffer, sRxPacketLength);
|
||||
}
|
||||
}
|
||||
|
||||
static void InitPacketQueue(void)
|
||||
@@ -620,11 +624,37 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatTrelUdp6SetTestMode(otInstance *aInstance, bool aEnable)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
VerifyOrExit(aEnable != sEnabled);
|
||||
|
||||
if (aEnable)
|
||||
{
|
||||
VerifyOrExit(sInitialized, error = OT_ERROR_FAILED);
|
||||
}
|
||||
|
||||
sEnabled = aEnable;
|
||||
|
||||
if (!sEnabled)
|
||||
{
|
||||
InitPacketQueue();
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
// platformTrel system
|
||||
|
||||
void platformTrelInit(const char *aTrelUrl)
|
||||
{
|
||||
assert(!sInitialized);
|
||||
|
||||
if (aTrelUrl != NULL)
|
||||
{
|
||||
ot::Posix::RadioUrl url(aTrelUrl);
|
||||
@@ -642,11 +672,14 @@ void platformTrelInit(const char *aTrelUrl)
|
||||
InitPacketQueue();
|
||||
|
||||
// Disable trel platform when interface name is empty.
|
||||
sEnabled = (sInterfaceName[0] != '\0');
|
||||
sInitialized = (sInterfaceName[0] != '\0');
|
||||
sEnabled = sInitialized;
|
||||
}
|
||||
|
||||
void platformTrelDeinit(void)
|
||||
{
|
||||
assert(sInitialized);
|
||||
|
||||
if (sSocket != -1)
|
||||
{
|
||||
close(sSocket);
|
||||
@@ -662,6 +695,9 @@ void platformTrelDeinit(void)
|
||||
RemoveUnicastAddress(&sInterfaceAddress);
|
||||
}
|
||||
|
||||
sInitialized = false;
|
||||
sEnabled = false;
|
||||
|
||||
otLogDebgPlat("[trel] platformTrelDeinit()");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user