[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:
kangping
2021-02-23 22:32:57 -08:00
committed by GitHub
parent 33f15fac2f
commit d24327fd71
6 changed files with 39 additions and 61 deletions
+1 -1
View File
@@ -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
+10 -18
View File
@@ -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
View File
@@ -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)
+7 -14
View File
@@ -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,
+8 -10
View File
@@ -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:
+11 -14
View File
@@ -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.