|
| 1 | +/* |
| 2 | + * Copyright (c) 2026, 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 <stdio.h> |
| 30 | + |
| 31 | +#include "platform/nexus_core.hpp" |
| 32 | +#include "platform/nexus_node.hpp" |
| 33 | + |
| 34 | +namespace ot { |
| 35 | +namespace Nexus { |
| 36 | + |
| 37 | +/** |
| 38 | + * Time to advance for a node to form a network and become leader, in milliseconds. |
| 39 | + */ |
| 40 | +static constexpr uint32_t kFormNetworkTime = 13 * 1000; |
| 41 | + |
| 42 | +/** |
| 43 | + * Time to advance for a node to join as a SSED. |
| 44 | + */ |
| 45 | +static constexpr uint32_t kAttachAsSsedTime = 20 * 1000; |
| 46 | + |
| 47 | +/** |
| 48 | + * CSL Period in milliseconds. |
| 49 | + */ |
| 50 | +static constexpr uint32_t kCslPeriodMs = 100; |
| 51 | + |
| 52 | +/** |
| 53 | + * CSL Period in units of 10 symbols. |
| 54 | + */ |
| 55 | +static constexpr uint32_t kCslPeriod = kCslPeriodMs * 1000 / OT_US_PER_TEN_SYMBOLS; |
| 56 | + |
| 57 | +/** |
| 58 | + * Time to advance for CSL synchronization to complete, in milliseconds. |
| 59 | + */ |
| 60 | +static constexpr uint32_t kCslSyncTime = 5 * 1000; |
| 61 | + |
| 62 | +/** |
| 63 | + * Payload size for a standard ICMPv6 Echo Request. |
| 64 | + */ |
| 65 | +static constexpr uint16_t kEchoPayloadSize = 10; |
| 66 | + |
| 67 | +void TestRetransmissionSecurity(void) |
| 68 | +{ |
| 69 | + /** |
| 70 | + * Retransmission Security Test |
| 71 | + * |
| 72 | + * Topology: |
| 73 | + * - Leader (DUT) |
| 74 | + * - SSED_1 |
| 75 | + * |
| 76 | + * Purpose: |
| 77 | + * Validate that retransmitted frames with CSL IE use an incremented frame counter |
| 78 | + * and are correctly encrypted for each attempt. |
| 79 | + */ |
| 80 | + |
| 81 | + Core nexus; |
| 82 | + |
| 83 | + Node &leader = nexus.CreateNode(); |
| 84 | + Node &ssed1 = nexus.CreateNode(); |
| 85 | + |
| 86 | + leader.SetName("LEADER"); |
| 87 | + ssed1.SetName("SSED_1"); |
| 88 | + |
| 89 | + nexus.AdvanceTime(0); |
| 90 | + |
| 91 | + SuccessOrQuit(Instance::SetGlobalLogLevel(kLogLevelNote)); |
| 92 | + |
| 93 | + Log("---------------------------------------------------------------------------------------"); |
| 94 | + Log("Step 1: Network Formation"); |
| 95 | + |
| 96 | + AllowLinkBetween(leader, ssed1); |
| 97 | + |
| 98 | + leader.Form(); |
| 99 | + nexus.AdvanceTime(kFormNetworkTime); |
| 100 | + VerifyOrQuit(leader.Get<Mle::Mle>().IsLeader()); |
| 101 | + |
| 102 | + ssed1.Join(leader, Node::kAsSed); |
| 103 | + nexus.AdvanceTime(kAttachAsSsedTime); |
| 104 | + VerifyOrQuit(ssed1.Get<Mle::Mle>().IsAttached()); |
| 105 | + |
| 106 | + ssed1.Get<Mac::Mac>().SetCslPeriod(kCslPeriod); |
| 107 | + nexus.AdvanceTime(kCslSyncTime); |
| 108 | + VerifyOrQuit(ssed1.Get<Mac::Mac>().IsCslEnabled()); |
| 109 | + |
| 110 | + Log("---------------------------------------------------------------------------------------"); |
| 111 | + Log("Step 2: Trigger Retransmissions (SSED to Leader)"); |
| 112 | + |
| 113 | + // Turn off leader radio so it misses SSED frames and SSED retries |
| 114 | + SuccessOrQuit(otPlatRadioSleep(&leader.GetInstance())); |
| 115 | + |
| 116 | + ssed1.SendEchoRequest(leader.Get<Mle::Mle>().GetMeshLocalEid(), 0x1234, kEchoPayloadSize); |
| 117 | + |
| 118 | + // Advance time enough for multiple retries. |
| 119 | + nexus.AdvanceTime(2000); |
| 120 | + |
| 121 | + // Turn leader radio back on |
| 122 | + SuccessOrQuit(otPlatRadioReceive(&leader.GetInstance(), leader.Get<Mac::Mac>().GetPanChannel())); |
| 123 | + |
| 124 | + nexus.SaveTestInfo("test_retransmission_security.json"); |
| 125 | +} |
| 126 | + |
| 127 | +} // namespace Nexus |
| 128 | +} // namespace ot |
| 129 | + |
| 130 | +int main(void) |
| 131 | +{ |
| 132 | + ot::Nexus::TestRetransmissionSecurity(); |
| 133 | + printf("All tests passed\n"); |
| 134 | + return 0; |
| 135 | +} |
0 commit comments