Coverage Report

Created: 2025-10-28 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openthread/tests/nexus/platform/nexus_trel.cpp
Line
Count
Source
1
/*
2
 *  Copyright (c) 2025, 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
#include <openthread/platform/trel.h>
30
31
#include "nexus_core.hpp"
32
#include "nexus_node.hpp"
33
34
#if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
35
36
namespace ot {
37
namespace Nexus {
38
39
//---------------------------------------------------------------------------------------------------------------------
40
// otPlatTrel APIs
41
42
extern "C" {
43
44
24.6k
void otPlatTrelEnable(otInstance *aInstance, uint16_t *aUdpPort) { AsNode(aInstance).mTrel.Enable(*aUdpPort); }
45
46
10
void otPlatTrelDisable(otInstance *aInstance) { AsNode(aInstance).mTrel.Disable(); }
47
48
void otPlatTrelSend(otInstance       *aInstance,
49
                    const uint8_t    *aUdpPayload,
50
                    uint16_t          aUdpPayloadLen,
51
                    const otSockAddr *aDestSockAddr)
52
0
{
53
0
    AsNode(aInstance).mTrel.Send(aUdpPayload, aUdpPayloadLen, AsCoreType(aDestSockAddr));
54
0
}
55
56
void otPlatTrelNotifyPeerSocketAddressDifference(otInstance       *aInstance,
57
                                                 const otSockAddr *aPeerSockAddr,
58
                                                 const otSockAddr *aRxSockAddr)
59
0
{
60
0
    OT_UNUSED_VARIABLE(aInstance);
61
0
    OT_UNUSED_VARIABLE(aPeerSockAddr);
62
0
    OT_UNUSED_VARIABLE(aRxSockAddr);
63
0
}
64
65
23
const otPlatTrelCounters *otPlatTrelGetCounters(otInstance *aInstance) { return &AsNode(aInstance).mTrel.mCounters; }
66
67
0
void otPlatTrelResetCounters(otInstance *aInstance) { AsNode(aInstance).mTrel.ResetCounters(); }
68
69
} // extern "C"
70
71
//---------------------------------------------------------------------------------------------------------------------
72
// Trel
73
74
uint16_t Trel::sLastUsedUdpPort = kUdpPortStart;
75
76
Trel::Trel(void)
77
24.6k
    : mEnabled(false)
78
24.6k
    , mUdpPort(sLastUsedUdpPort++)
79
24.6k
{
80
24.6k
    ClearAllBytes(mCounters);
81
24.6k
}
82
83
void Trel::Reset(void)
84
0
{
85
0
    mEnabled = false;
86
0
    ClearAllBytes(mCounters);
87
0
    mPendingTxList.Free();
88
0
}
89
90
void Trel::Enable(uint16_t &aUdpPort)
91
24.6k
{
92
24.6k
    mEnabled = true;
93
24.6k
    aUdpPort = mUdpPort;
94
24.6k
}
95
96
void Trel::Disable(void)
97
10
{
98
10
    mEnabled = false;
99
10
    mPendingTxList.Free();
100
10
}
101
102
void Trel::Send(const uint8_t *aUdpPayload, uint16_t aUdpPayloadLen, const Ip6::SockAddr &aDestSockAddr)
103
0
{
104
0
    PendingTx *pendingTx = PendingTx::Allocate();
105
106
0
    VerifyOrQuit(pendingTx != nullptr);
107
0
    SuccessOrQuit(pendingTx->mPayloadData.SetFrom(aUdpPayload, aUdpPayloadLen));
108
0
    pendingTx->mDestSockAddr = aDestSockAddr;
109
110
0
    mPendingTxList.PushAfterTail(*pendingTx);
111
112
0
    mCounters.mTxPackets++;
113
0
    mCounters.mTxBytes += aUdpPayloadLen;
114
0
}
115
116
void Trel::Receive(Instance &aInstance, Heap::Data &aPayloadData, const Ip6::SockAddr &aSenderAddr)
117
0
{
118
0
    mCounters.mRxPackets++;
119
0
    mCounters.mRxBytes += aPayloadData.GetLength();
120
121
0
    otPlatTrelHandleReceived(&aInstance, AsNonConst(aPayloadData.GetBytes()), aPayloadData.GetLength(), &aSenderAddr);
122
0
}
123
124
} // namespace Nexus
125
} // namespace ot
126
127
#endif // OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE