mirror of
https://github.com/espressif/openthread.git
synced 2026-08-11 05:07:47 +00:00
DIAG: Add CLI support for Diagnostic DIAG_GET.rsp message. (#1062)
* DIAG: Add CLI support for Diagnostic DIAG_GET.rsp message.
This commit is contained in:
committed by
Jonathan Hui
parent
df6da01f68
commit
dbc1384db2
@@ -1894,6 +1894,29 @@ OTAPI ThreadError OTCALL otGetParentInfo(otInstance *aInstance, otRouterInfo *aP
|
||||
*/
|
||||
OTAPI uint8_t OTCALL otGetStableNetworkDataVersion(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* This function pointer is called when an DIAG_GET.rsp is received.
|
||||
*
|
||||
* @param[in] aMessage A pointer to the message buffer containing the received DIAG_GET.rsp payload.
|
||||
* @param[in] aMessageInfo A pointer to the message info for @p aMessage.
|
||||
* @param[in] aContext A pointer to application-specific context.
|
||||
*
|
||||
*/
|
||||
typedef void (*otReceiveDiagnosticGetCallback)(otMessage aMessage, const otMessageInfo *aMessageInfo,
|
||||
void *aContext);
|
||||
|
||||
/**
|
||||
* This function registers a callback to provide received raw DIAG_GET.rsp payload.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[in] aCallback A pointer to a function that is called when an DIAG_GET.rsp is received or
|
||||
* NULL to disable the callback.
|
||||
* @param[in] aCallbackContext A pointer to application-specific context.
|
||||
*
|
||||
*/
|
||||
void otSetReceiveDiagnosticGetCallback(otInstance *aInstance, otReceiveDiagnosticGetCallback aCallback,
|
||||
void *aCallbackContext);
|
||||
|
||||
/**
|
||||
* Send a Network Diagnostic Get request
|
||||
*
|
||||
|
||||
@@ -143,6 +143,7 @@ Interpreter::Interpreter(otInstance *aInstance):
|
||||
memset(mSlaacAddresses, 0, sizeof(mSlaacAddresses));
|
||||
mInstance->mIp6.mIcmp.SetEchoReplyHandler(&s_HandleEchoResponse, this);
|
||||
otSetStateChangedCallback(mInstance, &Interpreter::s_HandleNetifStateChanged, this);
|
||||
otSetReceiveDiagnosticGetCallback(mInstance, &Interpreter::s_HandleDiagnosticGetResponse, this);
|
||||
}
|
||||
|
||||
int Interpreter::Hex2Bin(const char *aHex, uint8_t *aBin, uint16_t aBinLength)
|
||||
@@ -2652,6 +2653,7 @@ void Interpreter::ProcessNetworkDiagnostic(int argc, char *argv[])
|
||||
if (strcmp(argv[0], "get") == 0)
|
||||
{
|
||||
otSendDiagnosticGet(mInstance, &address, payload, payloadIndex);
|
||||
return;
|
||||
}
|
||||
else if (strcmp(argv[0], "reset") == 0)
|
||||
{
|
||||
@@ -2662,5 +2664,35 @@ exit:
|
||||
AppendResult(error);
|
||||
}
|
||||
|
||||
void Interpreter::s_HandleDiagnosticGetResponse(otMessage aMessage, const otMessageInfo *aMessageInfo,
|
||||
void *aContext)
|
||||
{
|
||||
static_cast<Interpreter *>(aContext)->HandleDiagnosticGetResponse(*static_cast<Message *>(aMessage),
|
||||
*static_cast<const Ip6::MessageInfo *>(aMessageInfo));
|
||||
}
|
||||
|
||||
void Interpreter::HandleDiagnosticGetResponse(Message &aMessage, const Ip6::MessageInfo &)
|
||||
{
|
||||
uint8_t buf[16];
|
||||
uint16_t bytesToPrint;
|
||||
uint16_t bytesPrinted = 0;
|
||||
uint16_t length = aMessage.GetLength() - aMessage.GetOffset();
|
||||
|
||||
sServer->OutputFormat("DIAG_GET.rsp: ");
|
||||
|
||||
while (length > 0)
|
||||
{
|
||||
bytesToPrint = (length < sizeof(buf)) ? length : sizeof(buf);
|
||||
aMessage.Read(aMessage.GetOffset() + bytesPrinted, bytesToPrint, buf);
|
||||
|
||||
OutputBytes(buf, static_cast<uint8_t>(bytesToPrint));
|
||||
|
||||
length -= bytesToPrint;
|
||||
bytesPrinted += bytesToPrint;
|
||||
}
|
||||
|
||||
sServer->OutputFormat("\r\n");
|
||||
}
|
||||
|
||||
} // namespace Cli
|
||||
} // namespace Thread
|
||||
|
||||
@@ -224,6 +224,7 @@ private:
|
||||
static void s_HandleEnergyReport(uint32_t aChannelMask, const uint8_t *aEnergyList, uint8_t aEnergyListLength,
|
||||
void *aContext);
|
||||
static void s_HandlePanIdConflict(uint16_t aPanId, uint32_t aChannelMask, void *aContext);
|
||||
static void s_HandleDiagnosticGetResponse(otMessage aMessage, const otMessageInfo *aMessageInfo, void *aContext);
|
||||
|
||||
void HandleEchoResponse(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
void HandlePingTimer();
|
||||
@@ -232,6 +233,7 @@ private:
|
||||
void HandleLinkPcapReceive(const RadioPacket *aFrame);
|
||||
void HandleEnergyReport(uint32_t aChannelMask, const uint8_t *aEnergyList, uint8_t aEnergyListLength);
|
||||
void HandlePanIdConflict(uint16_t aPanId, uint32_t aChannelMask);
|
||||
void HandleDiagnosticGetResponse(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
static const struct Command sCommands[];
|
||||
|
||||
|
||||
@@ -1189,6 +1189,13 @@ exit:
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void otSetReceiveDiagnosticGetCallback(otInstance *aInstance, otReceiveDiagnosticGetCallback aCallback,
|
||||
void *aCallbackContext)
|
||||
{
|
||||
aInstance->mThreadNetif.GetNetworkDiagnostic().SetReceiveDiagnosticGetCallback(aCallback, aCallbackContext);
|
||||
}
|
||||
|
||||
ThreadError otSendDiagnosticGet(otInstance *aInstance, const otIp6Address *aDestination, const uint8_t aTlvTypes[],
|
||||
uint8_t aCount)
|
||||
{
|
||||
|
||||
@@ -62,12 +62,21 @@ NetworkDiagnostic::NetworkDiagnostic(ThreadNetif &aThreadNetif) :
|
||||
mCoapClient(aThreadNetif.GetCoapClient()),
|
||||
mMle(aThreadNetif.GetMle()),
|
||||
mMac(aThreadNetif.GetMac()),
|
||||
mNetif(aThreadNetif)
|
||||
mNetif(aThreadNetif),
|
||||
mReceiveDiagnosticGetCallback(NULL),
|
||||
mReceiveDiagnosticGetCallbackContext(NULL)
|
||||
{
|
||||
mCoapServer.AddResource(mDiagnosticGet);
|
||||
mCoapServer.AddResource(mDiagnosticReset);
|
||||
}
|
||||
|
||||
void NetworkDiagnostic::SetReceiveDiagnosticGetCallback(otReceiveDiagnosticGetCallback aCallback,
|
||||
void *aCallbackContext)
|
||||
{
|
||||
mReceiveDiagnosticGetCallback = aCallback;
|
||||
mReceiveDiagnosticGetCallbackContext = aCallbackContext;
|
||||
}
|
||||
|
||||
ThreadError NetworkDiagnostic::SendDiagnosticGet(const Ip6::Address &aDestination, const uint8_t aTlvTypes[],
|
||||
uint8_t aCount)
|
||||
{
|
||||
@@ -79,7 +88,6 @@ ThreadError NetworkDiagnostic::SendDiagnosticGet(const Ip6::Address &aDestinatio
|
||||
|
||||
sockaddr.mPort = kCoapUdpPort;
|
||||
|
||||
|
||||
header.Init(kCoapTypeConfirmable, kCoapRequestGet);
|
||||
header.SetToken(Coap::Header::kDefaultTokenLength);
|
||||
header.AppendUriPathOptions(OPENTHREAD_URI_DIAGNOSTIC_GET);
|
||||
@@ -121,14 +129,16 @@ void NetworkDiagnostic::HandleDiagnosticGetResponse(void *aContext, otCoapHeader
|
||||
void NetworkDiagnostic::HandleDiagnosticGetResponse(Coap::Header *aHeader, Message *aMessage,
|
||||
const Ip6::MessageInfo *aMessageInfo, ThreadError aResult)
|
||||
{
|
||||
(void)aMessage;
|
||||
(void)aMessageInfo;
|
||||
|
||||
VerifyOrExit(aResult == kThreadError_None, ;);
|
||||
VerifyOrExit(aHeader->GetCode() == kCoapResponseChanged, ;);
|
||||
|
||||
otLogInfoNetDiag("Network Diagnostic get response received");
|
||||
|
||||
VerifyOrExit(mReceiveDiagnosticGetCallback != NULL, ;);
|
||||
|
||||
// Call application defined callback.
|
||||
mReceiveDiagnosticGetCallback(aMessage, aMessageInfo, mReceiveDiagnosticGetCallbackContext);
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -72,6 +72,16 @@ public:
|
||||
*/
|
||||
explicit NetworkDiagnostic(ThreadNetif &aThreadNetif);
|
||||
|
||||
/**
|
||||
* This method registers a callback to provide received raw DIAG_GET.rsp payload.
|
||||
*
|
||||
* @param[in] aCallback A pointer to a function that is called when an DIAG_GET.rsp is received or
|
||||
* NULL 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.
|
||||
*
|
||||
@@ -132,6 +142,9 @@ private:
|
||||
Mle::MleRouter &mMle;
|
||||
Mac::Mac &mMac;
|
||||
ThreadNetif &mNetif;
|
||||
|
||||
otReceiveDiagnosticGetCallback mReceiveDiagnosticGetCallback;
|
||||
void *mReceiveDiagnosticGetCallbackContext;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user