diff --git a/include/openthread/types.h b/include/openthread/types.h index ba75b87d2..abd1be67f 100644 --- a/include/openthread/types.h +++ b/include/openthread/types.h @@ -1017,7 +1017,7 @@ typedef struct otMacCounters uint32_t mRxAddressFiltered; ///< The number of received packets filtered by address filter (whitelist or blacklist). uint32_t mRxDestAddrFiltered; ///< The number of received packets filtered by destination check. uint32_t mRxDuplicated; ///< The number of received duplicated packets. - uint32_t mRxErrNoFrame; ///< The number of received packets that do not contain contents. + uint32_t mRxErrNoFrame; ///< The number of received packets with no or malformed content. uint32_t mRxErrUnknownNeighbor; ///< The number of received packets from unknown neighbor. uint32_t mRxErrInvalidSrcAddr; ///< The number of received packets whose source address is invalid. uint32_t mRxErrSec; ///< The number of received packets with security error. diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index 460d0b208..d69822575 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -197,6 +197,7 @@ const NcpBase::PropertyHandlerEntry NcpBase::mGetPropertyHandlerTable[] = NCP_GET_PROP_HANDLER_ENTRY(CNTR_RX_ERR_BAD_FCS), NCP_GET_PROP_HANDLER_ENTRY(CNTR_RX_ERR_OTHER), NCP_GET_PROP_HANDLER_ENTRY(CNTR_RX_PKT_DUP), + NCP_GET_PROP_HANDLER_ENTRY(CNTR_ALL_MAC_COUNTERS), // NCP counters NCP_GET_PROP_HANDLER_ENTRY(CNTR_TX_IP_SEC_TOTAL), NCP_GET_PROP_HANDLER_ENTRY(CNTR_TX_IP_INSEC_TOTAL), diff --git a/src/ncp/ncp_base.hpp b/src/ncp/ncp_base.hpp index 30607dd2d..2c3a7ae05 100644 --- a/src/ncp/ncp_base.hpp +++ b/src/ncp/ncp_base.hpp @@ -529,6 +529,7 @@ protected: NCP_GET_PROP_HANDLER(THREAD_ACTIVE_DATASET); NCP_GET_PROP_HANDLER(THREAD_PENDING_DATASET); + NCP_GET_PROP_HANDLER(CNTR_ALL_MAC_COUNTERS); NCP_GET_PROP_HANDLER(CNTR_TX_PKT_TOTAL); NCP_GET_PROP_HANDLER(CNTR_TX_PKT_ACK_REQ); NCP_GET_PROP_HANDLER(CNTR_TX_PKT_ACKED); diff --git a/src/ncp/ncp_base_mtd.cpp b/src/ncp/ncp_base_mtd.cpp index 12b1964a5..85e10491c 100644 --- a/src/ncp/ncp_base_mtd.cpp +++ b/src/ncp/ncp_base_mtd.cpp @@ -1771,6 +1771,61 @@ exit: return error; } +otError NcpBase::GetPropertyHandler_CNTR_ALL_MAC_COUNTERS(void) +{ + otError error = OT_ERROR_NONE; + const otMacCounters *counters = otLinkGetCounters(mInstance); + + if (counters == NULL) + { + error = mEncoder.OverwriteWithLastStatusError(SPINEL_STATUS_INVALID_COMMAND_FOR_PROP); + ExitNow(); + } + + // Encode Tx related counters + SuccessOrExit(error = mEncoder.OpenStruct()); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxTotal)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxUnicast)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxBroadcast)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxAckRequested)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxAcked)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxNoAckRequested)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxData)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxDataPoll)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxBeacon)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxBeaconRequest)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxOther)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxRetry)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxErrCca)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxErrAbort)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxErrBusyChannel)); + SuccessOrExit(error = mEncoder.CloseStruct()); + + // Encode Rx related counters + SuccessOrExit(error = mEncoder.OpenStruct()); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxTotal)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxUnicast)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxBroadcast)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxData)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxDataPoll)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxBeacon)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxBeaconRequest)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxOther)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxAddressFiltered)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxDestAddrFiltered)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxDuplicated)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxErrNoFrame)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxErrUnknownNeighbor)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxErrInvalidSrcAddr)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxErrSec)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxErrFcs)); + SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxErrOther)); + SuccessOrExit(error = mEncoder.CloseStruct()); + +exit: + return error; +} + #if OPENTHREAD_ENABLE_MAC_FILTER otError NcpBase::GetPropertyHandler_MAC_WHITELIST(void) diff --git a/src/ncp/spinel.c b/src/ncp/spinel.c index b0a0f7861..a121fe669 100644 --- a/src/ncp/spinel.c +++ b/src/ncp/spinel.c @@ -1785,6 +1785,10 @@ spinel_prop_key_to_cstr(spinel_prop_key_t prop_key) ret = "PROP_MSG_BUFFER_COUNTERS"; break; + case SPINEL_PROP_CNTR_ALL_MAC_COUNTERS: + ret = "PROP_CNTR_ALL_MAC_COUNTERS"; + break; + case SPINEL_PROP_NEST_STREAM_MFG: ret = "PROP_NEST_STREAM_MFG"; break; diff --git a/src/ncp/spinel.h b/src/ncp/spinel.h index 5ec52faf6..db6eb8e80 100644 --- a/src/ncp/spinel.h +++ b/src/ncp/spinel.h @@ -1647,6 +1647,53 @@ typedef enum */ SPINEL_PROP_MSG_BUFFER_COUNTERS = SPINEL_PROP_CNTR__BEGIN + 400, + /// All MAC related counters. + /** Format: t(A(L))t(A(L)) (Read-only) + * + * The contents include two structs, first one corresponds to + * all transmit related MAC counters, second one provides the + * receive related counters. + * + * The transmit structure includes: + * + * 'L': TxTotal (The total number of transmissions). + * 'L': TxUnicast (The total number of unicast transmissions). + * 'L': TxBroadcast (The total number of broadcast transmissions). + * 'L': TxAckRequested (The number of transmissions with ack request). + * 'L': TxAcked (The number of transmissions that were acked). + * 'L': TxNoAckRequested (The number of transmissions without ack request). + * 'L': TxData (The number of transmitted data). + * 'L': TxDataPoll (The number of transmitted data poll). + * 'L': TxBeacon (The number of transmitted beacon). + * 'L': TxBeaconRequest (The number of transmitted beacon request). + * 'L': TxOther (The number of transmitted other types of frames). + * 'L': TxRetry (The number of retransmission times). + * 'L': TxErrCca (The number of CCA failure times). + * 'L': TxErrAbort (The number of frame transmission failures due to abort error). + * 'L': TxErrBusyChannel (The number of frames that were dropped due to a busy channel). + * + * The receive structure includes: + * + * 'L': RxTotal (The total number of received packets). + * 'L': RxUnicast (The total number of unicast packets received). + * 'L': RxBroadcast (The total number of broadcast packets received). + * 'L': RxData (The number of received data). + * 'L': RxDataPoll (The number of received data poll). + * 'L': RxBeacon (The number of received beacon). + * 'L': RxBeaconRequest (The number of received beacon request). + * 'L': RxOther (The number of received other types of frames). + * 'L': RxAddressFiltered (The number of received packets filtered by address filter (whitelist or blacklist)). + * 'L': RxDestAddrFiltered (The number of received packets filtered by destination check). + * 'L': RxDuplicated (The number of received duplicated packets). + * 'L': RxErrNoFrame (The number of received packets with no or malformed content). + * 'L': RxErrUnknownNeighbor (The number of received packets from unknown neighbor). + * 'L': RxErrInvalidSrcAddr (The number of received packets whose source address is invalid). + * 'L': RxErrSec (The number of received packets with security error). + * 'L': RxErrFcs (The number of received packets with FCS error). + * 'L': RxErrOther (The number of received packets with other error). + */ + SPINEL_PROP_CNTR_ALL_MAC_COUNTERS = SPINEL_PROP_CNTR__BEGIN + 401, + SPINEL_PROP_CNTR__END = 2048, SPINEL_PROP_NEST__BEGIN = 15296,