mirror of
https://github.com/espressif/openthread.git
synced 2026-07-29 23:27:46 +00:00
[netdiag] fix setting DIAG_GET response callback (#6192)
This commit sets the DIAG_GET response callback every time the otThreadSendDiagnosticGet is called. This is because the callback may be changed to other modules (e,g. OTBR_REST, OTBR_UBUS).
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 (78)
|
||||
#define OPENTHREAD_API_VERSION (79)
|
||||
|
||||
/**
|
||||
* @addtogroup api-instance
|
||||
|
||||
@@ -297,34 +297,26 @@ typedef void (*otReceiveDiagnosticGetCallback)(otError aError,
|
||||
void * aContext);
|
||||
|
||||
/**
|
||||
* This function registers a callback to provide received raw Network Diagnostic Get response payload.
|
||||
* Send a Network Diagnostic Get request.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[in] aDestination A pointer to destination address.
|
||||
* @param[in] aTlvTypes An array of Network Diagnostic TLV types.
|
||||
* @param[in] aCount Number of types in aTlvTypes.
|
||||
* @param[in] aCallback A pointer to a function that is called when Network Diagnostic Get response
|
||||
* is received or NULL to disable the callback.
|
||||
* @param[in] aCallbackContext A pointer to application-specific context.
|
||||
*
|
||||
*/
|
||||
void otThreadSetReceiveDiagnosticGetCallback(otInstance * aInstance,
|
||||
otReceiveDiagnosticGetCallback aCallback,
|
||||
void * aCallbackContext);
|
||||
|
||||
/**
|
||||
* Send a Network Diagnostic Get request.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[in] aDestination A pointer to destination address.
|
||||
* @param[in] aTlvTypes An array of Network Diagnostic TLV types.
|
||||
* @param[in] aCount Number of types in aTlvTypes.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully queued the DIAG_GET.req.
|
||||
* @retval OT_ERROR_NO_BUFS Insufficient message buffers available to send DIAG_GET.req.
|
||||
*
|
||||
*/
|
||||
otError otThreadSendDiagnosticGet(otInstance * aInstance,
|
||||
const otIp6Address *aDestination,
|
||||
const uint8_t aTlvTypes[],
|
||||
uint8_t aCount);
|
||||
otError otThreadSendDiagnosticGet(otInstance * aInstance,
|
||||
const otIp6Address * aDestination,
|
||||
const uint8_t aTlvTypes[],
|
||||
uint8_t aCount,
|
||||
otReceiveDiagnosticGetCallback aCallback,
|
||||
void * aCallbackContext);
|
||||
|
||||
/**
|
||||
* Send a Network Diagnostic Reset request.
|
||||
|
||||
+2
-4
@@ -147,9 +147,6 @@ Interpreter::Interpreter(Instance *aInstance)
|
||||
, mSrpServer(*this)
|
||||
#endif
|
||||
{
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
otThreadSetReceiveDiagnosticGetCallback(mInstance, &Interpreter::HandleDiagnosticGetResponse, this);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
otThreadSetDiscoveryRequestCallback(mInstance, &Interpreter::HandleDiscoveryRequest, this);
|
||||
#endif
|
||||
@@ -4850,7 +4847,8 @@ otError Interpreter::ProcessNetworkDiagnostic(uint8_t aArgsLength, char *aArgs[]
|
||||
|
||||
if (strcmp(aArgs[0], "get") == 0)
|
||||
{
|
||||
IgnoreError(otThreadSendDiagnosticGet(mInstance, &address, tlvTypes, count));
|
||||
SuccessOrExit(error = otThreadSendDiagnosticGet(mInstance, &address, tlvTypes, count,
|
||||
&Interpreter::HandleDiagnosticGetResponse, this));
|
||||
ExitNow(error = OT_ERROR_PENDING);
|
||||
}
|
||||
else if (strcmp(aArgs[0], "reset") == 0)
|
||||
|
||||
@@ -49,24 +49,17 @@ otError otThreadGetNextDiagnosticTlv(const otMessage * aMessage,
|
||||
*aIterator, *aNetworkDiagTlv);
|
||||
}
|
||||
|
||||
void otThreadSetReceiveDiagnosticGetCallback(otInstance * aInstance,
|
||||
otReceiveDiagnosticGetCallback aCallback,
|
||||
void * aCallbackContext)
|
||||
{
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
instance.Get<NetworkDiagnostic::NetworkDiagnostic>().SetReceiveDiagnosticGetCallback(aCallback, aCallbackContext);
|
||||
}
|
||||
|
||||
otError otThreadSendDiagnosticGet(otInstance * aInstance,
|
||||
const otIp6Address *aDestination,
|
||||
const uint8_t aTlvTypes[],
|
||||
uint8_t aCount)
|
||||
otError otThreadSendDiagnosticGet(otInstance * aInstance,
|
||||
const otIp6Address * aDestination,
|
||||
const uint8_t aTlvTypes[],
|
||||
uint8_t aCount,
|
||||
otReceiveDiagnosticGetCallback aCallback,
|
||||
void * aCallbackContext)
|
||||
{
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
return instance.Get<NetworkDiagnostic::NetworkDiagnostic>().SendDiagnosticGet(
|
||||
*static_cast<const Ip6::Address *>(aDestination), aTlvTypes, aCount);
|
||||
*static_cast<const Ip6::Address *>(aDestination), aTlvTypes, aCount, aCallback, aCallbackContext);
|
||||
}
|
||||
|
||||
otError otThreadSendDiagnosticReset(otInstance * aInstance,
|
||||
|
||||
@@ -69,16 +69,11 @@ NetworkDiagnostic::NetworkDiagnostic(Instance &aInstance)
|
||||
Get<Tmf::TmfAgent>().AddResource(mDiagnosticReset);
|
||||
}
|
||||
|
||||
void NetworkDiagnostic::SetReceiveDiagnosticGetCallback(otReceiveDiagnosticGetCallback aCallback,
|
||||
void * aCallbackContext)
|
||||
{
|
||||
mReceiveDiagnosticGetCallback = aCallback;
|
||||
mReceiveDiagnosticGetCallbackContext = aCallbackContext;
|
||||
}
|
||||
|
||||
otError NetworkDiagnostic::SendDiagnosticGet(const Ip6::Address &aDestination,
|
||||
const uint8_t aTlvTypes[],
|
||||
uint8_t aCount)
|
||||
otError NetworkDiagnostic::SendDiagnosticGet(const Ip6::Address & aDestination,
|
||||
const uint8_t aTlvTypes[],
|
||||
uint8_t aCount,
|
||||
otReceiveDiagnosticGetCallback aCallback,
|
||||
void * aCallbackContext)
|
||||
{
|
||||
otError error;
|
||||
Coap::Message * message = nullptr;
|
||||
@@ -122,6 +117,9 @@ otError NetworkDiagnostic::SendDiagnosticGet(const Ip6::Address &aDestination,
|
||||
|
||||
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo, handler, this));
|
||||
|
||||
mReceiveDiagnosticGetCallback = aCallback;
|
||||
mReceiveDiagnosticGetCallbackContext = aCallbackContext;
|
||||
|
||||
otLogInfoNetDiag("Sent diagnostic get");
|
||||
|
||||
exit:
|
||||
|
||||
@@ -81,26 +81,23 @@ public:
|
||||
*/
|
||||
explicit NetworkDiagnostic(Instance &aInstance);
|
||||
|
||||
/**
|
||||
* This method registers a callback to provide received raw DIAG_GET.rsp or an DIAG_GET.ans payload.
|
||||
*
|
||||
* @param[in] aCallback A pointer to a function that is called when an DIAG_GET.rsp or an DIAG_GET.ans
|
||||
* is received or nullptr to disable the callback.
|
||||
* @param[in] aCallbackContext A pointer to application-specific context.
|
||||
*
|
||||
*/
|
||||
void SetReceiveDiagnosticGetCallback(otReceiveDiagnosticGetCallback aCallback, void *aCallbackContext);
|
||||
|
||||
/**
|
||||
* This method sends Diagnostic Get request. If the @p aDestination is of multicast type, the DIAG_GET.qry
|
||||
* message is sent or the DIAG_GET.req otherwise.
|
||||
*
|
||||
* @param[in] aDestination A reference to the destination address.
|
||||
* @param[in] aTlvTypes An array of Network Diagnostic TLV types.
|
||||
* @param[in] aCount Number of types in aTlvTypes
|
||||
* @param[in] aDestination A reference to the destination address.
|
||||
* @param[in] aTlvTypes An array of Network Diagnostic TLV types.
|
||||
* @param[in] aCount Number of types in aTlvTypes.
|
||||
* @param[in] aCallback A pointer to a function that is called when Network Diagnostic Get response
|
||||
* is received or NULL to disable the callback.
|
||||
* @param[in] aCallbackContext A pointer to application-specific context.
|
||||
*
|
||||
*/
|
||||
otError SendDiagnosticGet(const Ip6::Address &aDestination, const uint8_t aTlvTypes[], uint8_t aCount);
|
||||
otError SendDiagnosticGet(const Ip6::Address & aDestination,
|
||||
const uint8_t aTlvTypes[],
|
||||
uint8_t aCount,
|
||||
otReceiveDiagnosticGetCallback aCallback,
|
||||
void * aCallbackContext);
|
||||
|
||||
/**
|
||||
* This method sends Diagnostic Reset request.
|
||||
|
||||
Reference in New Issue
Block a user