1 /* 2 * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 #ifndef NET_DCSCTP_PACKET_PARAMETER_RECONFIGURATION_RESPONSE_PARAMETER_H_ 11 #define NET_DCSCTP_PACKET_PARAMETER_RECONFIGURATION_RESPONSE_PARAMETER_H_ 12 #include <stddef.h> 13 14 #include <cstdint> 15 #include <string> 16 #include <vector> 17 18 #include "absl/strings/string_view.h" 19 #include "absl/types/optional.h" 20 #include "api/array_view.h" 21 #include "net/dcsctp/common/internal_types.h" 22 #include "net/dcsctp/packet/parameter/parameter.h" 23 #include "net/dcsctp/packet/tlv_trait.h" 24 25 namespace dcsctp { 26 27 // https://tools.ietf.org/html/rfc6525#section-4.4 28 struct ReconfigurationResponseParameterConfig : ParameterConfig { 29 static constexpr int kType = 16; 30 static constexpr size_t kHeaderSize = 12; 31 static constexpr size_t kVariableLengthAlignment = 4; 32 }; 33 34 class ReconfigurationResponseParameter 35 : public Parameter, 36 public TLVTrait<ReconfigurationResponseParameterConfig> { 37 public: 38 static constexpr int kType = ReconfigurationResponseParameterConfig::kType; 39 40 enum class Result { 41 kSuccessNothingToDo = 0, 42 kSuccessPerformed = 1, 43 kDenied = 2, 44 kErrorWrongSSN = 3, 45 kErrorRequestAlreadyInProgress = 4, 46 kErrorBadSequenceNumber = 5, 47 kInProgress = 6, 48 }; 49 ReconfigurationResponseParameter(ReconfigRequestSN response_sequence_number,Result result)50 ReconfigurationResponseParameter(ReconfigRequestSN response_sequence_number, 51 Result result) 52 : response_sequence_number_(response_sequence_number), 53 result_(result), 54 sender_next_tsn_(absl::nullopt), 55 receiver_next_tsn_(absl::nullopt) {} 56 ReconfigurationResponseParameter(ReconfigRequestSN response_sequence_number,Result result,TSN sender_next_tsn,TSN receiver_next_tsn)57 explicit ReconfigurationResponseParameter( 58 ReconfigRequestSN response_sequence_number, 59 Result result, 60 TSN sender_next_tsn, 61 TSN receiver_next_tsn) 62 : response_sequence_number_(response_sequence_number), 63 result_(result), 64 sender_next_tsn_(sender_next_tsn), 65 receiver_next_tsn_(receiver_next_tsn) {} 66 67 static absl::optional<ReconfigurationResponseParameter> Parse( 68 rtc::ArrayView<const uint8_t> data); 69 70 void SerializeTo(std::vector<uint8_t>& out) const override; 71 std::string ToString() const override; 72 response_sequence_number()73 ReconfigRequestSN response_sequence_number() const { 74 return response_sequence_number_; 75 } result()76 Result result() const { return result_; } sender_next_tsn()77 absl::optional<TSN> sender_next_tsn() const { return sender_next_tsn_; } receiver_next_tsn()78 absl::optional<TSN> receiver_next_tsn() const { return receiver_next_tsn_; } 79 80 private: 81 static constexpr size_t kNextTsnHeaderSize = 8; 82 ReconfigRequestSN response_sequence_number_; 83 Result result_; 84 absl::optional<TSN> sender_next_tsn_; 85 absl::optional<TSN> receiver_next_tsn_; 86 }; 87 88 absl::string_view ToString(ReconfigurationResponseParameter::Result result); 89 90 } // namespace dcsctp 91 92 #endif // NET_DCSCTP_PACKET_PARAMETER_RECONFIGURATION_RESPONSE_PARAMETER_H_ 93