| 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 |
"fmt" |
| 10 |
) |
| 11 |
|
| 12 |
// This parameter is used by the receiver of a Re-configuration Request |
| 13 |
// Parameter to respond to the request. |
| 14 |
// |
| 15 |
// 0 1 2 3 |
| 16 |
// 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 |
| 17 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 18 |
// | Parameter Type = 16 | Parameter Length | |
| 19 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 20 |
// | Re-configuration Response Sequence Number | |
| 21 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 22 |
// | Result | |
| 23 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 24 |
// | Sender's Next TSN (optional) | |
| 25 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 26 |
// | Receiver's Next TSN (optional) | |
| 27 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 28 |
|
| 29 |
type paramReconfigResponse struct { |
| 30 |
paramHeader |
| 31 |
// This value is copied from the request parameter and is used by the |
| 32 |
// receiver of the Re-configuration Response Parameter to tie the |
| 33 |
// response to the request. |
| 34 |
reconfigResponseSequenceNumber uint32 |
| 35 |
// This value describes the result of the processing of the request. |
| 36 |
result reconfigResult |
| 37 |
} |
| 38 |
|
| 39 |
type reconfigResult uint32 |
| 40 |
|
| 41 |
const ( |
| 42 |
reconfigResultSuccessNOP reconfigResult = 0 |
| 43 |
reconfigResultSuccessPerformed reconfigResult = 1 |
| 44 |
reconfigResultDenied reconfigResult = 2 |
| 45 |
reconfigResultErrorWrongSSN reconfigResult = 3 |
| 46 |
reconfigResultErrorRequestAlreadyInProgress reconfigResult = 4 |
| 47 |
reconfigResultErrorBadSequenceNumber reconfigResult = 5 |
| 48 |
reconfigResultInProgress reconfigResult = 6 |
| 49 |
) |
| 50 |
|
| 51 |
// Reconfiguration response errors. |
| 52 |
var ( |
| 53 |
ErrReconfigRespParamTooShort = errors.New("reconfig response parameter too short") |
| 54 |
) |
| 55 |
|
| 56 |
func (t reconfigResult) String() string { |
| 57 |
switch t { |
| 58 |
case reconfigResultSuccessNOP: |
| 59 |
return "0: Success - Nothing to do" |
| 60 |
case reconfigResultSuccessPerformed: |
| 61 |
return "1: Success - Performed" |
| 62 |
case reconfigResultDenied: |
| 63 |
return "2: Denied" |
| 64 |
case reconfigResultErrorWrongSSN: |
| 65 |
return "3: Error - Wrong SSN" |
| 66 |
case reconfigResultErrorRequestAlreadyInProgress: |
| 67 |
return "4: Error - Request already in progress" |
| 68 |
case reconfigResultErrorBadSequenceNumber: |
| 69 |
return "5: Error - Bad Sequence Number" |
| 70 |
case reconfigResultInProgress: |
| 71 |
return "6: In progress" |
| 72 |
default: |
| 73 |
return fmt.Sprintf("Unknown reconfigResult: %d", t) |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
func (r *paramReconfigResponse) marshal() ([]byte, error) { |
| 78 |
r.typ = reconfigResp |
| 79 |
r.raw = make([]byte, 8) |
| 80 |
binary.BigEndian.PutUint32(r.raw, r.reconfigResponseSequenceNumber) |
| 81 |
binary.BigEndian.PutUint32(r.raw[4:], uint32(r.result)) |
| 82 |
|
| 83 |
return r.paramHeader.marshal() |
| 84 |
} |
| 85 |
|
| 86 |
func (r *paramReconfigResponse) unmarshal(raw []byte) (param, error) { |
| 87 |
err := r.paramHeader.unmarshal(raw) |
| 88 |
if err != nil { |
| 89 |
return nil, err |
| 90 |
} |
| 91 |
if len(r.raw) < 8 { |
| 92 |
return nil, ErrReconfigRespParamTooShort |
| 93 |
} |
| 94 |
r.reconfigResponseSequenceNumber = binary.BigEndian.Uint32(r.raw) |
| 95 |
r.result = reconfigResult(binary.BigEndian.Uint32(r.raw[4:])) |
| 96 |
|
| 97 |
return r, nil |
| 98 |
} |