[logging] add sequence number to the Mac packet log (#7050)

This commit is contained in:
Thomas
2021-10-06 12:20:13 -07:00
committed by GitHub
parent 7342f6cc98
commit 27dc37ea8d
2 changed files with 26 additions and 9 deletions
+20 -4
View File
@@ -179,6 +179,21 @@ void otLogMac(otLogLevel aLogLevel, const char *aFormat, ...)
exit:
return;
}
void otDumpMacFrame(otLogLevel aLogLevel, const char *aId, const void *aBuf, const size_t aLength)
{
constexpr uint8_t kFixedStringPart = 10; // strlen(" seqno=000")
constexpr uint8_t kSeqnoIdx = 2; // index of the sequence number within aBuf
size_t idLength = strlen(aId) + kFixedStringPart + 1; // allow for the '\0' character
char newId[25];
VerifyOrExit(idLength <= sizeof(newId));
snprintf(newId, idLength, "%s seqno=%03u", aId, static_cast<const uint8_t *>(aBuf)[kSeqnoIdx]);
otDump(aLogLevel, OT_LOG_REGION_MAC, newId, aBuf, aLength);
exit:
return;
}
#endif
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
@@ -276,19 +291,20 @@ static void DumpLine(otLogLevel aLogLevel, otLogRegion aLogRegion, const uint8_t
void otDump(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aId, const void *aBuf, const size_t aLength)
{
constexpr uint8_t kWidth = 72;
constexpr uint8_t kWidth = 72;
constexpr uint8_t kFixedStringPart = 10; // strlen("[ len=000]")
size_t idLen = strlen(aId);
size_t idLen = strlen(aId) + kFixedStringPart;
ot::String<kStringLineLength> string;
for (size_t i = 0; i < (kWidth - idLen) / 2 - 5; i++)
for (size_t i = 0; i < (kWidth - idLen) / 2; i++)
{
string.Append("=");
}
string.Append("[%s len=%03u]", aId, static_cast<unsigned>(aLength));
for (size_t i = 0; i < (kWidth - idLen) / 2 - 4; i++)
for (size_t i = 0; i < kWidth - idLen - (kWidth - idLen) / 2; i++)
{
string.Append("=");
}
+6 -5
View File
@@ -2245,11 +2245,12 @@ void otLogOtns(const char *aFormat, ...);
*
*/
#if OPENTHREAD_CONFIG_LOG_MAC
#define otDumpCritMac(aId, aBuf, aLength) otDumpCrit(OT_LOG_REGION_MAC, aId, aBuf, aLength)
#define otDumpWarnMac(aId, aBuf, aLength) otDumpWarn(OT_LOG_REGION_MAC, aId, aBuf, aLength)
#define otDumpNoteMac(aId, aBuf, aLength) otDumpNote(OT_LOG_REGION_MAC, aId, aBuf, aLength)
#define otDumpInfoMac(aId, aBuf, aLength) otDumpInfo(OT_LOG_REGION_MAC, aId, aBuf, aLength)
#define otDumpDebgMac(aId, aBuf, aLength) otDumpDebg(OT_LOG_REGION_MAC, aId, aBuf, aLength)
void otDumpMacFrame(otLogLevel aLogLevel, const char *aId, const void *aBuf, size_t aLength);
#define otDumpCritMac(aId, aBuf, aLength) otDumpMacFrame(OT_LOG_LEVEL_CRIT, aId, aBuf, aLength)
#define otDumpWarnMac(aId, aBuf, aLength) otDumpMacFrame(OT_LOG_LEVEL_WARN, aId, aBuf, aLength)
#define otDumpNoteMac(aId, aBuf, aLength) otDumpMacFrame(OT_LOG_LEVEL_NOTE, aId, aBuf, aLength)
#define otDumpInfoMac(aId, aBuf, aLength) otDumpMacFrame(OT_LOG_LEVEL_INFO, aId, aBuf, aLength)
#define otDumpDebgMac(aId, aBuf, aLength) otDumpMacFrame(OT_LOG_LEVEL_DEBG, aId, aBuf, aLength)
#else
#define otDumpCritMac(aId, aBuf, aLength)
#define otDumpWarnMac(aId, aBuf, aLength)