• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *    Copyright (c) 2020, The OpenThread Authors.
3  *    All rights reserved.
4  *
5  *    Redistribution and use in source and binary forms, with or without
6  *    modification, are permitted provided that the following conditions are met:
7  *    1. Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *    2. Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *    3. Neither the name of the copyright holder nor the
13  *       names of its contributors may be used to endorse or promote products
14  *       derived from this software without specific prior written permission.
15  *
16  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  *    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  *    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  *    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  *    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  *    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  *    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  *    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  *    POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /**
30  * @file
31  * This file includes definitions for types used by d-bus API.
32  */
33 
34 #ifndef OTBR_DBUS_COMMON_TYPES_HPP_
35 #define OTBR_DBUS_COMMON_TYPES_HPP_
36 
37 #include "dbus/common/error.hpp"
38 
39 #include <stdint.h>
40 
41 #include <string>
42 #include <vector>
43 
44 namespace otbr {
45 namespace DBus {
46 
47 enum DeviceRole
48 {
49     OTBR_DEVICE_ROLE_DISABLED = 0,
50     OTBR_DEVICE_ROLE_DETACHED = 1,
51     OTBR_DEVICE_ROLE_CHILD    = 2,
52     OTBR_DEVICE_ROLE_ROUTER   = 3,
53     OTBR_DEVICE_ROLE_LEADER   = 4,
54 };
55 
56 struct ActiveScanResult
57 {
58     uint64_t             mExtAddress;    ///< IEEE 802.15.4 Extended Address
59     std::string          mNetworkName;   ///< Thread Network Name
60     uint64_t             mExtendedPanId; ///< Thread Extended PAN ID
61     std::vector<uint8_t> mSteeringData;  ///< Steering Data
62     uint16_t             mPanId;         ///< IEEE 802.15.4 PAN ID
63     uint16_t             mJoinerUdpPort; ///< Joiner UDP Port
64     uint8_t              mChannel;       ///< IEEE 802.15.4 Channel
65     int8_t               mRssi;          ///< RSSI (dBm)
66     uint8_t              mLqi;           ///< LQI
67     uint8_t              mVersion;       ///< Version
68     bool                 mIsNative;      ///< Native Commissioner flag
69     bool                 mDiscover;      ///< Result from MLE Discovery
70 };
71 
72 struct EnergyScanResult
73 {
74     uint8_t mChannel; ///< IEEE 802.15.4 Channel
75     int8_t  mMaxRssi; ///< The max RSSI (dBm)
76 };
77 
78 struct LinkModeConfig
79 {
80     bool mRxOnWhenIdle; ///< 1, if the sender has its receiver on when not transmitting. 0, otherwise.
81     bool mDeviceType;   ///< 1, if the sender is an FTD. 0, otherwise.
82     bool mNetworkData;  ///< 1, if the sender requires the full Network Data. 0, otherwise.
83 };
84 
85 struct Ip6Prefix
86 {
87     std::vector<uint8_t> mPrefix; ///< The IPv6 prefix.
88 
89     uint8_t mLength; ///< The IPv6 prefix length.
90 };
91 
92 struct OnMeshPrefix
93 {
94     /**
95      * The IPv6 prefix.
96      */
97     Ip6Prefix mPrefix;
98 
99     /**
100      * The Rloc associated with the Border Router prefix.
101      */
102     uint16_t mRloc16;
103 
104     /**
105      * A 2-bit signed integer indicating router preference as defined in RFC 4191.
106      */
107     int8_t mPreference;
108 
109     /**
110      * TRUE, if @p mPrefix is preferred.  FALSE, otherwise.
111      */
112     bool mPreferred;
113 
114     /**
115      * TRUE, if @p mPrefix should be used for address autoconfiguration.  FALSE, otherwise.
116      */
117     bool mSlaac;
118 
119     /**
120      * TRUE, if this border router is a DHCPv6 Agent that supplies IPv6 address configuration.  FALSE, otherwise.
121      */
122     bool mDhcp;
123 
124     /**
125      * TRUE, if this border router is a DHCPv6 Agent that supplies other configuration data.  FALSE, otherwise.
126      */
127     bool mConfigure;
128 
129     /**
130      * TRUE, if this border router is a default route for @p mPrefix.  FALSE, otherwise.
131      */
132     bool mDefaultRoute;
133 
134     /**
135      * TRUE if this prefix is considered on-mesh. FALSE otherwise.
136      */
137     bool mOnMesh;
138 
139     /**
140      * TRUE if this configuration is considered Stable Network Data. FALSE otherwise.
141      */
142     bool mStable;
143 
144     /**
145      * TRUE if this border router can supply DNS information via ND. FALSE otherwise.
146      */
147     bool mNdDns;
148 
149     /**
150      * TRUE if this prefix is a Thread Domain Prefix. FALSE otherwise.
151      */
152     bool mDp;
153 };
154 
155 struct ExternalRoute
156 {
157     /**
158      * The IPv6 prefix.
159      */
160     Ip6Prefix mPrefix;
161 
162     /**
163      * The Rloc associated with the external route entry.
164      *
165      * This value is ignored when adding an external route. For any added route, the device's Rloc is used.
166      */
167     uint16_t mRloc16;
168 
169     /**
170      * A 2-bit signed integer indicating router preference as defined in RFC 4191.
171      */
172     int8_t mPreference;
173 
174     /**
175      * TRUE, if this configuration is considered Stable Network Data.  FALSE, otherwise.
176      */
177     bool mStable;
178 
179     /**
180      * TRUE if the external route entry's next hop is this device itself (i.e., the route was added earlier by this
181      * device). FALSE otherwise.
182      *
183      * This value is ignored when adding an external route. For any added route the next hop is this device.
184      */
185     bool mNextHopIsThisDevice;
186 };
187 
188 /**
189  * This structure represents the MAC layer counters.
190  *
191  */
192 struct MacCounters
193 {
194     /**
195      * The total number of unique MAC frame transmission requests.
196      *
197      * Note that this counter is incremented for each MAC transmission request only by one,
198      * regardless of the amount of CCA failures, CSMA-CA attempts, or retransmissions.
199      *
200      * This incrementation rule applies to the following counters:
201      *   @p mTxUnicast
202      *   @p mTxBroadcast
203      *   @p mTxAckRequested
204      *   @p mTxNoAckRequested
205      *   @p mTxData
206      *   @p mTxDataPoll
207      *   @p mTxBeacon
208      *   @p mTxBeaconRequest
209      *   @p mTxOther
210      *   @p mTxErrAbort
211      *   @p mTxErrBusyChannel
212      *
213      * The following equations are valid:
214      *     @p mTxTotal = @p mTxUnicast + @p mTxBroadcast
215      *     @p mTxTotal = @p mTxAckRequested + @p mTxNoAckRequested
216      *     @p mTxTotal = @p mTxData + @p mTxDataPoll + @p mTxBeacon + @p mTxBeaconRequest + @p mTxOther
217      *
218      */
219     uint32_t mTxTotal;
220 
221     /**
222      * The total number of unique unicast MAC frame transmission requests.
223      *
224      */
225     uint32_t mTxUnicast;
226 
227     /**
228      * The total number of unique broadcast MAC frame transmission requests.
229      *
230      */
231     uint32_t mTxBroadcast;
232 
233     /**
234      * The total number of unique MAC frame transmission requests with requested acknowledgment.
235      *
236      */
237     uint32_t mTxAckRequested;
238 
239     /**
240      * The total number of unique MAC frame transmission requests that were acked.
241      *
242      */
243     uint32_t mTxAcked;
244 
245     /**
246      * The total number of unique MAC frame transmission requests without requested acknowledgment.
247      *
248      */
249     uint32_t mTxNoAckRequested;
250 
251     /**
252      * The total number of unique MAC Data frame transmission requests.
253      *
254      */
255     uint32_t mTxData;
256 
257     /**
258      * The total number of unique MAC Data Poll frame transmission requests.
259      *
260      */
261     uint32_t mTxDataPoll;
262 
263     /**
264      * The total number of unique MAC Beacon frame transmission requests.
265      *
266      */
267     uint32_t mTxBeacon;
268 
269     /**
270      * The total number of unique MAC Beacon Request frame transmission requests.
271      *
272      */
273     uint32_t mTxBeaconRequest;
274 
275     /**
276      * The total number of unique other MAC frame transmission requests.
277      *
278      * This counter is currently unused.
279      *
280      */
281     uint32_t mTxOther;
282 
283     /**
284      * The total number of MAC retransmission attempts.
285      *
286      * Note that this counter is incremented by one for each retransmission attempt that may be
287      * triggered by lack of acknowledgement, CSMA/CA failure, or other type of transmission error.
288      * The @p mTxRetry counter is incremented both for unicast and broadcast MAC frames.
289      *
290      * Check the following configuration parameters to control the amount of retransmissions in the system:
291      *   @sa OPENTHREAD_CONFIG_MAC_DEFAULT_MAX_FRAME_RETRIES_DIRECT
292      *   @sa OPENTHREAD_CONFIG_MAC_DEFAULT_MAX_FRAME_RETRIES_INDIRECT
293      *   @sa OPENTHREAD_CONFIG_MAC_TX_NUM_BCAST
294      *   @sa OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT
295      *   @sa OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_INDIRECT
296      *
297      * Currently, this counter is invalid if the platform's radio driver capability includes
298      * @sa OT_RADIO_CAPS_TRANSMIT_RETRIES.
299      *
300      */
301     uint32_t mTxRetry;
302 
303     /**
304      * The total number of unique MAC transmission packets that meet maximal retry limit for direct packets.
305      *
306      */
307     uint32_t mTxDirectMaxRetryExpiry;
308 
309     /**
310      * The total number of unique MAC transmission packets that meet maximal retry limit for indirect packets.
311      *
312      */
313     uint32_t mTxIndirectMaxRetryExpiry;
314 
315     /**
316      * The total number of CCA failures.
317      *
318      * The meaning of this counter can be different and it depends on the platform's radio driver capabilities.
319      *
320      * If @sa OT_RADIO_CAPS_CSMA_BACKOFF is enabled, this counter represents the total number of full CSMA/CA
321      * failed attempts and it is incremented by one also for each retransmission (in case of a CSMA/CA fail).
322      *
323      * If @sa OT_RADIO_CAPS_TRANSMIT_RETRIES is enabled, this counter represents the total number of full CSMA/CA
324      * failed attempts and it is incremented by one for each individual data frame request (regardless of the amount of
325      * retransmissions).
326      *
327      */
328     uint32_t mTxErrCca;
329 
330     /**
331      * The total number of unique MAC transmission request failures cause by an abort error.
332      *
333      */
334     uint32_t mTxErrAbort;
335 
336     /**
337      * The total number of unique MAC transmission requests failures caused by a busy channel (a CSMA/CA fail).
338      *
339      */
340     uint32_t mTxErrBusyChannel;
341 
342     /**
343      * The total number of received frames.
344      *
345      * This counter counts all frames reported by the platform's radio driver, including frames
346      * that were dropped, for example because of an FCS error.
347      *
348      */
349     uint32_t mRxTotal;
350 
351     /**
352      * The total number of unicast frames received.
353      *
354      */
355     uint32_t mRxUnicast;
356 
357     /**
358      * The total number of broadcast frames received.
359      *
360      */
361     uint32_t mRxBroadcast;
362 
363     /**
364      * The total number of MAC Data frames received.
365      *
366      */
367     uint32_t mRxData;
368 
369     /**
370      * The total number of MAC Data Poll frames received.
371      *
372      */
373     uint32_t mRxDataPoll;
374 
375     /**
376      * The total number of MAC Beacon frames received.
377      *
378      */
379     uint32_t mRxBeacon;
380 
381     /**
382      * The total number of MAC Beacon Request frames received.
383      *
384      */
385     uint32_t mRxBeaconRequest;
386 
387     /**
388      * The total number of other types of frames received.
389      *
390      */
391     uint32_t mRxOther;
392 
393     /**
394      * The total number of frames dropped by MAC Filter module, for example received from denylisted node.
395      *
396      */
397     uint32_t mRxAddressFiltered;
398 
399     /**
400      * The total number of frames dropped by destination address check, for example received frame for other node.
401      *
402      */
403     uint32_t mRxDestAddrFiltered;
404 
405     /**
406      * The total number of frames dropped due to duplication, that is when the frame has been already received.
407      *
408      * This counter may be incremented, for example when ACK frame generated by the receiver hasn't reached
409      * transmitter node which performed retransmission.
410      *
411      */
412     uint32_t mRxDuplicated;
413 
414     /**
415      * The total number of frames dropped because of missing or malformed content.
416      *
417      */
418     uint32_t mRxErrNoFrame;
419 
420     /**
421      * The total number of frames dropped due to unknown neighbor.
422      *
423      */
424     uint32_t mRxErrUnknownNeighbor;
425 
426     /**
427      * The total number of frames dropped due to invalid source address.
428      *
429      */
430     uint32_t mRxErrInvalidSrcAddr;
431 
432     /**
433      * The total number of frames dropped due to security error.
434      *
435      * This counter may be incremented, for example when lower than expected Frame Counter is used
436      * to encrypt the frame.
437      *
438      */
439     uint32_t mRxErrSec;
440 
441     /**
442      * The total number of frames dropped due to invalid FCS.
443      *
444      */
445     uint32_t mRxErrFcs;
446 
447     /**
448      * The total number of frames dropped due to other error.
449      *
450      */
451     uint32_t mRxErrOther;
452 };
453 
454 struct IpCounters
455 {
456     uint32_t mTxSuccess; ///< The number of IPv6 packets successfully transmitted.
457     uint32_t mRxSuccess; ///< The number of IPv6 packets successfully received.
458     uint32_t mTxFailure; ///< The number of IPv6 packets failed to transmit.
459     uint32_t mRxFailure; ///< The number of IPv6 packets failed to receive.
460 };
461 
462 struct ChannelQuality
463 {
464     uint8_t  mChannel;
465     uint16_t mOccupancy;
466 };
467 
468 struct ChildInfo
469 {
470     uint64_t mExtAddress;         ///< IEEE 802.15.4 Extended Address
471     uint32_t mTimeout;            ///< Timeout
472     uint32_t mAge;                ///< Time last heard
473     uint16_t mRloc16;             ///< RLOC16
474     uint16_t mChildId;            ///< Child ID
475     uint8_t  mNetworkDataVersion; ///< Network Data Version
476     uint8_t  mLinkQualityIn;      ///< Link Quality In
477     int8_t   mAverageRssi;        ///< Average RSSI
478     int8_t   mLastRssi;           ///< Last observed RSSI
479     uint16_t mFrameErrorRate;     ///< Frame error rate (0xffff->100%). Requires error tracking feature.
480     uint16_t mMessageErrorRate;   ///< (IPv6) msg error rate (0xffff->100%). Requires error tracking feature.
481     bool     mRxOnWhenIdle;       ///< rx-on-when-idle
482     bool     mFullThreadDevice;   ///< Full Thread Device
483     bool     mFullNetworkData;    ///< Full Network Data
484     bool     mIsStateRestoring;   ///< Is in restoring state
485 };
486 
487 struct NeighborInfo
488 {
489     uint64_t mExtAddress;       ///< IEEE 802.15.4 Extended Address
490     uint32_t mAge;              ///< Time last heard
491     uint16_t mRloc16;           ///< RLOC16
492     uint32_t mLinkFrameCounter; ///< Link Frame Counter
493     uint32_t mMleFrameCounter;  ///< MLE Frame Counter
494     uint8_t  mLinkQualityIn;    ///< Link Quality In
495     int8_t   mAverageRssi;      ///< Average RSSI
496     int8_t   mLastRssi;         ///< Last observed RSSI
497     uint16_t mFrameErrorRate;   ///< Frame error rate (0xffff->100%). Requires error tracking feature.
498     uint16_t mMessageErrorRate; ///< (IPv6) msg error rate (0xffff->100%). Requires error tracking feature.
499     bool     mRxOnWhenIdle;     ///< rx-on-when-idle
500     bool     mFullThreadDevice; ///< Full Thread Device
501     bool     mFullNetworkData;  ///< Full Network Data
502     bool     mIsChild;          ///< Is the neighbor a child
503 };
504 
505 struct LeaderData
506 {
507     uint32_t mPartitionId;       ///< Partition ID
508     uint8_t  mWeighting;         ///< Leader Weight
509     uint8_t  mDataVersion;       ///< Full Network Data Version
510     uint8_t  mStableDataVersion; ///< Stable Network Data Version
511     uint8_t  mLeaderRouterId;    ///< Leader Router ID
512 };
513 
514 struct TxtEntry
515 {
516     std::string          mKey;
517     std::vector<uint8_t> mValue;
518 };
519 
520 enum SrpServerState : uint8_t
521 {
522     OTBR_SRP_SERVER_STATE_DISABLED = 0, ///< The SRP server is disabled.
523     OTBR_SRP_SERVER_STATE_RUNNING  = 1, ///< The SRP server is running.
524     OTBR_SRP_SERVER_STATE_STOPPED  = 2, ///< The SRP server is stopped.
525 };
526 
527 enum SrpServerAddressMode : uint8_t
528 {
529     OTBR_SRP_SERVER_ADDRESS_MODE_UNICAST = 0, ///< Unicast address mode.
530     OTBR_SRP_SERVER_ADDRESS_MODE_ANYCAST = 1, ///< Anycast address mode.
531 };
532 
533 struct SrpServerInfo
534 {
535     struct Registration
536     {
537         uint32_t mFreshCount;        ///< The number of active hosts/services registered on the SRP server
538         uint32_t mDeletedCount;      ///< The number of hosts/services in 'Deleted' state on the SRP server
539         uint64_t mLeaseTimeTotal;    ///< The sum of lease time in milliseconds of all active hosts/services
540                                      ///< on the SRP server
541         uint64_t mKeyLeaseTimeTotal; ///< The sum of key lease time in milliseconds of all active hosts/services on the
542                                      ///< SRP server
543         uint64_t mRemainingLeaseTimeTotal;    ///< The sum of remaining lease time in milliseconds of all active
544                                               ///< hosts/services on the SRP server
545         uint64_t mRemainingKeyLeaseTimeTotal; ///< The sum of remaining key lease time in milliseconds of all active
546                                               ///< hosts/services on the SRP server
547     };
548 
549     struct ResponseCounters
550     {
551         uint32_t mSuccess;       ///< The number of successful responses
552         uint32_t mServerFailure; ///< The number of server failure responses
553         uint32_t mFormatError;   ///< The number of format error responses
554         uint32_t mNameExists;    ///< The number of 'name exists' responses
555         uint32_t mRefused;       ///< The number of refused responses
556         uint32_t mOther;         ///< The number of other responses
557     };
558 
559     SrpServerState       mState;            ///< The state of the SRP server
560     uint16_t             mPort;             ///< The listening port number
561     SrpServerAddressMode mAddressMode;      ///< The address mode {unicast, anycast} of the SRP server
562     Registration         mHosts;            ///< The registration information of hosts on the SRP server
563     Registration         mServices;         ///< The registration information of services on the SRP server
564     ResponseCounters     mResponseCounters; ///< The counters of response codes sent by the SRP server
565 };
566 
567 struct DnssdCounters
568 {
569     uint32_t mSuccessResponse;        ///< The number of successful responses
570     uint32_t mServerFailureResponse;  ///< The number of server failure responses
571     uint32_t mFormatErrorResponse;    ///< The number of format error responses
572     uint32_t mNameErrorResponse;      ///< The number of name error responses
573     uint32_t mNotImplementedResponse; ///< The number of 'not implemented' responses
574     uint32_t mOtherResponse;          ///< The number of other responses
575 
576     uint32_t mResolvedBySrp; ///< The number of queries completely resolved by the local SRP server
577 };
578 
579 struct RadioSpinelMetrics
580 {
581     uint32_t mRcpTimeoutCount;         ///< The number of RCP timeouts.
582     uint32_t mRcpUnexpectedResetCount; ///< The number of RCP unexcepted resets.
583     uint32_t mRcpRestorationCount;     ///< The number of RCP restorations.
584     uint32_t mSpinelParseErrorCount;   ///< The number of spinel frame parse errors.
585 };
586 
587 struct RcpInterfaceMetrics
588 {
589     uint8_t  mRcpInterfaceType;             ///< The RCP interface type.
590     uint64_t mTransferredFrameCount;        ///< The number of transferred frames.
591     uint64_t mTransferredValidFrameCount;   ///< The number of transferred valid frames.
592     uint64_t mTransferredGarbageFrameCount; ///< The number of transferred garbage frames.
593     uint64_t mRxFrameCount;                 ///< The number of received frames.
594     uint64_t mRxFrameByteCount;             ///< The number of received bytes.
595     uint64_t mTxFrameCount;                 ///< The number of transmitted frames.
596     uint64_t mTxFrameByteCount;             ///< The number of transmitted bytes.
597 };
598 
599 struct RadioCoexMetrics
600 {
601     uint32_t mNumGrantGlitch;          ///< Number of grant glitches.
602     uint32_t mNumTxRequest;            ///< Number of tx requests.
603     uint32_t mNumTxGrantImmediate;     ///< Number of tx requests while grant was active.
604     uint32_t mNumTxGrantWait;          ///< Number of tx requests while grant was inactive.
605     uint32_t mNumTxGrantWaitActivated; ///< Number of tx requests while grant was inactive that were ultimately granted.
606     uint32_t mNumTxGrantWaitTimeout;   ///< Number of tx requests while grant was inactive that timed out.
607     uint32_t mNumTxGrantDeactivatedDuringRequest; ///< Number of tx that were in progress when grant was deactivated.
608     uint32_t mNumTxDelayedGrant;                  ///< Number of tx requests that were not granted within 50us.
609     uint32_t mAvgTxRequestToGrantTime;            ///< Average time in usec from tx request to grant.
610     uint32_t mNumRxRequest;                       ///< Number of rx requests.
611     uint32_t mNumRxGrantImmediate;                ///< Number of rx requests while grant was active.
612     uint32_t mNumRxGrantWait;                     ///< Number of rx requests while grant was inactive.
613     uint32_t mNumRxGrantWaitActivated; ///< Number of rx requests while grant was inactive that were ultimately granted.
614     uint32_t mNumRxGrantWaitTimeout;   ///< Number of rx requests while grant was inactive that timed out.
615     uint32_t mNumRxGrantDeactivatedDuringRequest; ///< Number of rx that were in progress when grant was deactivated.
616     uint32_t mNumRxDelayedGrant;                  ///< Number of rx requests that were not granted within 50us.
617     uint32_t mAvgRxRequestToGrantTime;            ///< Average time in usec from rx request to grant.
618     uint32_t mNumRxGrantNone;                     ///< Number of rx requests that completed without receiving grant.
619     bool     mStopped;                            ///< Stats collection stopped due to saturation.
620 };
621 
622 } // namespace DBus
623 } // namespace otbr
624 
625 #endif // OTBR_DBUS_COMMON_TYPES_HPP_
626