xref: /aosp_15_r20/external/openthread/examples/platforms/utils/link_metrics.h (revision cfb92d1480a9e65faed56933e9c12405f45898b4)
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  * @brief
32  *   This file defines the link metrics interface for OpenThread platform radio drivers.
33  *
34  *   APIs defined in this module could be used by a platform to implement Enhanced-ACK Based Probing feature
35  *   (Probing Subject side) in its radio driver.
36  *
37  */
38 
39 #ifndef OPENTHREAD_UTILS_LINK_METRICS_H
40 #define OPENTHREAD_UTILS_LINK_METRICS_H
41 
42 #include <openthread/link_metrics.h>
43 
44 #include "mac_frame.h"
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 /**
51  * Initializes the Link Metrics util module.
52  *
53  * @param[in]  aNoiseFloor    The noise floor used by Link Metrics. It should be set to the platform's
54  *                            noise floor (measured noise floor, receiver sensitivity or a constant).
55  *
56  */
57 void otLinkMetricsInit(int8_t aNoiseFloor);
58 
59 /**
60  * Sets/clears Enhanced-ACK Based Probing for a specific Initiator.
61  *
62  * Can start/stop Enhanced-ACK Based Probing for a neighbor that has the address @p aShortAddress and
63  * @p aExtAddress. Once the Probing is started, the device would record the Link Metrics data of link layer frames
64  * sent from that neighbor and include the data into header IE in Enhanced-ACK sent to that neighbor.
65  *
66  * @param[in]  aShortAddress    The short address of the Initiator.
67  * @param[in]  aExtAddress      A pointer to the extended address of the Initiator.
68  * @param[in]  aLinkMetrics     Flags specifying what metrics to query (Pdu Count would be omitted). When
69  *                              @p aLinkMetrics is equal to `0`, this method clears the Initiator.
70  *
71  * @retval  OT_ERROR_NONE            Successfully configured the Enhanced-ACK Based Probing.
72  * @retval  OT_ERROR_INVALID_ARGS    @p aExtAddress is `nullptr`.
73  * @retval  OT_ERROR_NOT_FOUND       The Initiator indicated by @p aShortAddress is not found when trying to clear.
74  * @retval  OT_ERROR_NO_BUFS         No more Initiator can be supported.
75  *
76  */
77 otError otLinkMetricsConfigureEnhAckProbing(otShortAddress      aShortAddress,
78                                             const otExtAddress *aExtAddress,
79                                             otLinkMetrics       aLinkMetrics);
80 
81 /**
82  * Generates the Link Metrics data (assessed for the acknowledged frame) bytes that would be included in
83  * Vendor-Specific IE.
84  *
85  * First checks what Link Metrics are specified by the Initiator indicated by @p aMacAddress. And then
86  * write the values to @p aData.
87  *
88  * @param[in]  aMacAddress    The Mac address of the Initiator.
89  * @param[in]  aLqi           LQI value of the acknowledged frame.
90  * @param[in]  aRssi          RSSI value of the acknowledged frame.
91  * @param[out] aData          A pointer to the buffer where the data would be written to. The caller should make
92  *                            sure that the size of the buffer is not less than the size of Link Metrics data
93  *                            configured before.
94  *
95  * @returns  The size of data read. Would be `0` if the Initiator is not found or @p aData is invalid.
96  *
97  */
98 uint8_t otLinkMetricsEnhAckGenData(const otMacAddress *aMacAddress, uint8_t aLqi, int8_t aRssi, uint8_t *aData);
99 
100 /**
101  * Returns the data length of Enhanced-ACK Based Probing for a specific Initiator.
102  *
103  * @param[in]  aMacAddress    The Mac address of the Initiator.
104  *
105  * @returns  The size of data. `0` if it's not configured for the Initiator.
106  *
107  */
108 uint8_t otLinkMetricsEnhAckGetDataLen(const otMacAddress *aMacAddress);
109 
110 /**
111  * This method resets Enhanced-ACK Based Probing data.
112  *
113  */
114 void otLinkMetricsResetEnhAckProbing(void);
115 
116 #ifdef __cplusplus
117 } // extern "C"
118 #endif
119 
120 #endif // OPENTHREAD_UTILS_LINK_METRICS_H
121