| 1 |
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly> |
| 2 |
// SPDX-License-Identifier: MIT |
| 3 |
|
| 4 |
package sctp |
| 5 |
|
| 6 |
import ( |
| 7 |
"encoding/binary" |
| 8 |
"errors" |
| 9 |
) |
| 10 |
|
| 11 |
const ( |
| 12 |
paramOutgoingResetRequestStreamIdentifiersOffset = 12 |
| 13 |
) |
| 14 |
|
| 15 |
// This parameter is used by the sender to request the reset of some or |
| 16 |
// all outgoing streams. |
| 17 |
// 0 1 2 3 |
| 18 |
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 19 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 20 |
// | Parameter Type = 13 | Parameter Length = 16 + 2 * N | |
| 21 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 22 |
// | Re-configuration Request Sequence Number | |
| 23 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 24 |
// | Re-configuration Response Sequence Number | |
| 25 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 26 |
// | Sender's Last Assigned TSN | |
| 27 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 28 |
// | Stream Number 1 (optional) | Stream Number 2 (optional) | |
| 29 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 30 |
// / ...... / |
| 31 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 32 |
// | Stream Number N-1 (optional) | Stream Number N (optional) | |
| 33 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 34 |
|
| 35 |
type paramOutgoingResetRequest struct { |
| 36 |
paramHeader |
| 37 |
// reconfigRequestSequenceNumber is used to identify the request. It is a monotonically |
| 38 |
// increasing number that is initialized to the same value as the |
| 39 |
// initial TSN. It is increased by 1 whenever sending a new Re- |
| 40 |
// configuration Request Parameter. |
| 41 |
reconfigRequestSequenceNumber uint32 |
| 42 |
// When this Outgoing SSN Reset Request Parameter is sent in response |
| 43 |
// to an Incoming SSN Reset Request Parameter, this parameter is also |
| 44 |
// an implicit response to the incoming request. This field then |
| 45 |
// holds the Re-configuration Request Sequence Number of the incoming |
| 46 |
// request. In other cases, it holds the next expected |
| 47 |
// Re-configuration Request Sequence Number minus 1. |
| 48 |
reconfigResponseSequenceNumber uint32 |
| 49 |
// This value holds the next TSN minus 1 -- in other words, the last |
| 50 |
// TSN that this sender assigned. |
| 51 |
senderLastTSN uint32 |
| 52 |
// This optional field, if included, is used to indicate specific |
| 53 |
// streams that are to be reset. If no streams are listed, then all |
| 54 |
// streams are to be reset. |
| 55 |
streamIdentifiers []uint16 |
| 56 |
} |
| 57 |
|
| 58 |
// Outgoing reset request parameter errors. |
| 59 |
var ( |
| 60 |
ErrSSNResetRequestParamTooShort = errors.New("outgoing SSN reset request parameter too short") |
| 61 |
) |
| 62 |
|
| 63 |
func (r *paramOutgoingResetRequest) marshal() ([]byte, error) { |
| 64 |
r.typ = outSSNResetReq |
| 65 |
r.raw = make([]byte, paramOutgoingResetRequestStreamIdentifiersOffset+2*len(r.streamIdentifiers)) |
| 66 |
binary.BigEndian.PutUint32(r.raw, r.reconfigRequestSequenceNumber) |
| 67 |
binary.BigEndian.PutUint32(r.raw[4:], r.reconfigResponseSequenceNumber) |
| 68 |
binary.BigEndian.PutUint32(r.raw[8:], r.senderLastTSN) |
| 69 |
for i, sID := range r.streamIdentifiers { |
| 70 |
binary.BigEndian.PutUint16(r.raw[paramOutgoingResetRequestStreamIdentifiersOffset+2*i:], sID) |
| 71 |
} |
| 72 |
|
| 73 |
return r.paramHeader.marshal() |
| 74 |
} |
| 75 |
|
| 76 |
func (r *paramOutgoingResetRequest) unmarshal(raw []byte) (param, error) { |
| 77 |
err := r.paramHeader.unmarshal(raw) |
| 78 |
if err != nil { |
| 79 |
return nil, err |
| 80 |
} |
| 81 |
if len(r.raw) < paramOutgoingResetRequestStreamIdentifiersOffset { |
| 82 |
return nil, ErrSSNResetRequestParamTooShort |
| 83 |
} |
| 84 |
r.reconfigRequestSequenceNumber = binary.BigEndian.Uint32(r.raw) |
| 85 |
r.reconfigResponseSequenceNumber = binary.BigEndian.Uint32(r.raw[4:]) |
| 86 |
r.senderLastTSN = binary.BigEndian.Uint32(r.raw[8:]) |
| 87 |
|
| 88 |
lim := (len(r.raw) - paramOutgoingResetRequestStreamIdentifiersOffset) / 2 |
| 89 |
r.streamIdentifiers = make([]uint16, lim) |
| 90 |
for i := range lim { |
| 91 |
r.streamIdentifiers[i] = binary.BigEndian.Uint16(r.raw[paramOutgoingResetRequestStreamIdentifiersOffset+2*i:]) |
| 92 |
} |
| 93 |
|
| 94 |
return r, nil |
| 95 |
} |