mirror of
https://github.com/espressif/openthread.git
synced 2026-08-08 19:57:46 +00:00
[cli] new command to enable/disable discovery request callback (#8579)
This commit add `discover reqcallback {enable/disable}` CLI command
which registers callback to output whenever device gets a "MLE
Discovery Request". This command allows the callback to be explicitly
set when needed and avoid having it be enabled by default (since the
extra output from this callback can be treated as unexpected result by
tests that parse the CLI output).
This commit is contained in:
+37
-4
@@ -145,10 +145,6 @@ Interpreter::Interpreter(Instance *aInstance, otCliOutputCallback aCallback, voi
|
||||
#endif
|
||||
#endif // OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||
{
|
||||
#if OPENTHREAD_FTD
|
||||
otThreadSetDiscoveryRequestCallback(GetInstancePtr(), &Interpreter::HandleDiscoveryRequest, this);
|
||||
#endif
|
||||
|
||||
OutputPrompt();
|
||||
}
|
||||
|
||||
@@ -3024,6 +3020,36 @@ template <> otError Interpreter::Process<Cmd("discover")>(Arg aArgs[])
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint32_t scanChannels = 0;
|
||||
|
||||
#if OPENTHREAD_FTD
|
||||
/**
|
||||
* @cli discover reqcallback (enable,disable)
|
||||
* @code
|
||||
* discover reqcallback enable
|
||||
* Done
|
||||
* @endcode
|
||||
* @cparam discover reqcallback @ca{enable|disable}
|
||||
* @par api_copy
|
||||
* #otThreadSetDiscoveryRequestCallback
|
||||
*/
|
||||
if (aArgs[0] == "reqcallback")
|
||||
{
|
||||
bool enable;
|
||||
otThreadDiscoveryRequestCallback callback = nullptr;
|
||||
void *context = nullptr;
|
||||
|
||||
SuccessOrExit(error = ParseEnableOrDisable(aArgs[1], enable));
|
||||
|
||||
if (enable)
|
||||
{
|
||||
callback = &Interpreter::HandleDiscoveryRequest;
|
||||
context = this;
|
||||
}
|
||||
|
||||
otThreadSetDiscoveryRequestCallback(GetInstancePtr(), callback, context);
|
||||
ExitNow();
|
||||
}
|
||||
#endif // OPENTHREAD_FTD
|
||||
|
||||
if (!aArgs[0].IsEmpty())
|
||||
{
|
||||
uint8_t channel;
|
||||
@@ -7155,12 +7181,19 @@ void Interpreter::HandleDetachGracefullyResult(void)
|
||||
OutputResult(OT_ERROR_NONE);
|
||||
}
|
||||
|
||||
#if OPENTHREAD_FTD
|
||||
void Interpreter::HandleDiscoveryRequest(const otThreadDiscoveryRequestInfo *aInfo, void *aContext)
|
||||
{
|
||||
static_cast<Interpreter *>(aContext)->HandleDiscoveryRequest(*aInfo);
|
||||
}
|
||||
|
||||
void Interpreter::HandleDiscoveryRequest(const otThreadDiscoveryRequestInfo &aInfo)
|
||||
{
|
||||
OutputFormat("~ Discovery Request from ");
|
||||
OutputExtAddress(aInfo.mExtAddress);
|
||||
OutputLine(": version=%u,joiner=%d", aInfo.mVersion, aInfo.mIsJoiner);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||
|
||||
|
||||
+4
-5
@@ -503,11 +503,10 @@ private:
|
||||
static void HandleDetachGracefullyResult(void *aContext);
|
||||
void HandleDetachGracefullyResult(void);
|
||||
|
||||
static void HandleDiscoveryRequest(const otThreadDiscoveryRequestInfo *aInfo, void *aContext)
|
||||
{
|
||||
static_cast<Interpreter *>(aContext)->HandleDiscoveryRequest(*aInfo);
|
||||
}
|
||||
void HandleDiscoveryRequest(const otThreadDiscoveryRequestInfo &aInfo);
|
||||
#if OPENTHREAD_FTD
|
||||
static void HandleDiscoveryRequest(const otThreadDiscoveryRequestInfo *aInfo, void *aContext);
|
||||
void HandleDiscoveryRequest(const otThreadDiscoveryRequestInfo &aInfo);
|
||||
#endif
|
||||
|
||||
#endif // OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||
|
||||
|
||||
@@ -57,6 +57,8 @@ expect "channel"
|
||||
expect -re {(\d+)}
|
||||
set channel $expect_out(1,string)
|
||||
expect_line "Done"
|
||||
send "discover reqcallback enable\n"
|
||||
expect_line "Done"
|
||||
|
||||
switch_node 3
|
||||
send "scan $channel\n"
|
||||
|
||||
Reference in New Issue
Block a user