/
NAS_DLNASTransport.go
173 lines (165 loc) · 7.75 KB
/
NAS_DLNASTransport.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Code generated by generate.sh, DO NOT EDIT.
package nasMessage
import (
"bytes"
"encoding/binary"
"fmt"
"github.com/free5gc/nas/nasType"
)
type DLNASTransport struct {
nasType.ExtendedProtocolDiscriminator
nasType.SpareHalfOctetAndSecurityHeaderType
nasType.DLNASTRANSPORTMessageIdentity
nasType.SpareHalfOctetAndPayloadContainerType
nasType.PayloadContainer
*nasType.PduSessionID2Value
*nasType.AdditionalInformation
*nasType.Cause5GMM
*nasType.BackoffTimerValue
}
func NewDLNASTransport(iei uint8) (dLNASTransport *DLNASTransport) {
dLNASTransport = &DLNASTransport{}
return dLNASTransport
}
const (
DLNASTransportPduSessionID2ValueType uint8 = 0x12
DLNASTransportAdditionalInformationType uint8 = 0x24
DLNASTransportCause5GMMType uint8 = 0x58
DLNASTransportBackoffTimerValueType uint8 = 0x37
)
func (a *DLNASTransport) EncodeDLNASTransport(buffer *bytes.Buffer) error {
if err := binary.Write(buffer, binary.BigEndian, a.ExtendedProtocolDiscriminator.Octet); err != nil {
return fmt.Errorf("NAS encode error (DLNASTransport/ExtendedProtocolDiscriminator): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.SpareHalfOctetAndSecurityHeaderType.Octet); err != nil {
return fmt.Errorf("NAS encode error (DLNASTransport/SpareHalfOctetAndSecurityHeaderType): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.DLNASTRANSPORTMessageIdentity.Octet); err != nil {
return fmt.Errorf("NAS encode error (DLNASTransport/DLNASTRANSPORTMessageIdentity): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.SpareHalfOctetAndPayloadContainerType.Octet); err != nil {
return fmt.Errorf("NAS encode error (DLNASTransport/SpareHalfOctetAndPayloadContainerType): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.PayloadContainer.GetLen()); err != nil {
return fmt.Errorf("NAS encode error (DLNASTransport/PayloadContainer): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.PayloadContainer.Buffer); err != nil {
return fmt.Errorf("NAS encode error (DLNASTransport/PayloadContainer): %w", err)
}
if a.PduSessionID2Value != nil {
if err := binary.Write(buffer, binary.BigEndian, a.PduSessionID2Value.GetIei()); err != nil {
return fmt.Errorf("NAS encode error (DLNASTransport/PduSessionID2Value): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.PduSessionID2Value.Octet); err != nil {
return fmt.Errorf("NAS encode error (DLNASTransport/PduSessionID2Value): %w", err)
}
}
if a.AdditionalInformation != nil {
if err := binary.Write(buffer, binary.BigEndian, a.AdditionalInformation.GetIei()); err != nil {
return fmt.Errorf("NAS encode error (DLNASTransport/AdditionalInformation): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.AdditionalInformation.GetLen()); err != nil {
return fmt.Errorf("NAS encode error (DLNASTransport/AdditionalInformation): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.AdditionalInformation.Buffer); err != nil {
return fmt.Errorf("NAS encode error (DLNASTransport/AdditionalInformation): %w", err)
}
}
if a.Cause5GMM != nil {
if err := binary.Write(buffer, binary.BigEndian, a.Cause5GMM.GetIei()); err != nil {
return fmt.Errorf("NAS encode error (DLNASTransport/Cause5GMM): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.Cause5GMM.Octet); err != nil {
return fmt.Errorf("NAS encode error (DLNASTransport/Cause5GMM): %w", err)
}
}
if a.BackoffTimerValue != nil {
if err := binary.Write(buffer, binary.BigEndian, a.BackoffTimerValue.GetIei()); err != nil {
return fmt.Errorf("NAS encode error (DLNASTransport/BackoffTimerValue): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.BackoffTimerValue.GetLen()); err != nil {
return fmt.Errorf("NAS encode error (DLNASTransport/BackoffTimerValue): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.BackoffTimerValue.Octet); err != nil {
return fmt.Errorf("NAS encode error (DLNASTransport/BackoffTimerValue): %w", err)
}
}
return nil
}
func (a *DLNASTransport) DecodeDLNASTransport(byteArray *[]byte) error {
buffer := bytes.NewBuffer(*byteArray)
if err := binary.Read(buffer, binary.BigEndian, &a.ExtendedProtocolDiscriminator.Octet); err != nil {
return fmt.Errorf("NAS decode error (DLNASTransport/ExtendedProtocolDiscriminator): %w", err)
}
if err := binary.Read(buffer, binary.BigEndian, &a.SpareHalfOctetAndSecurityHeaderType.Octet); err != nil {
return fmt.Errorf("NAS decode error (DLNASTransport/SpareHalfOctetAndSecurityHeaderType): %w", err)
}
if err := binary.Read(buffer, binary.BigEndian, &a.DLNASTRANSPORTMessageIdentity.Octet); err != nil {
return fmt.Errorf("NAS decode error (DLNASTransport/DLNASTRANSPORTMessageIdentity): %w", err)
}
if err := binary.Read(buffer, binary.BigEndian, &a.SpareHalfOctetAndPayloadContainerType.Octet); err != nil {
return fmt.Errorf("NAS decode error (DLNASTransport/SpareHalfOctetAndPayloadContainerType): %w", err)
}
if err := binary.Read(buffer, binary.BigEndian, &a.PayloadContainer.Len); err != nil {
return fmt.Errorf("NAS decode error (DLNASTransport/PayloadContainer): %w", err)
}
if a.PayloadContainer.Len < 1 {
return fmt.Errorf("invalid ie length (DLNASTransport/PayloadContainer): %d", a.PayloadContainer.Len)
}
a.PayloadContainer.SetLen(a.PayloadContainer.GetLen())
if err := binary.Read(buffer, binary.BigEndian, a.PayloadContainer.Buffer); err != nil {
return fmt.Errorf("NAS decode error (DLNASTransport/PayloadContainer): %w", err)
}
for buffer.Len() > 0 {
var ieiN uint8
var tmpIeiN uint8
if err := binary.Read(buffer, binary.BigEndian, &ieiN); err != nil {
return fmt.Errorf("NAS decode error (DLNASTransport/iei): %w", err)
}
// fmt.Println(ieiN)
if ieiN >= 0x80 {
tmpIeiN = (ieiN & 0xf0) >> 4
} else {
tmpIeiN = ieiN
}
// fmt.Println("type", tmpIeiN)
switch tmpIeiN {
case DLNASTransportPduSessionID2ValueType:
a.PduSessionID2Value = nasType.NewPduSessionID2Value(ieiN)
if err := binary.Read(buffer, binary.BigEndian, &a.PduSessionID2Value.Octet); err != nil {
return fmt.Errorf("NAS decode error (DLNASTransport/PduSessionID2Value): %w", err)
}
case DLNASTransportAdditionalInformationType:
a.AdditionalInformation = nasType.NewAdditionalInformation(ieiN)
if err := binary.Read(buffer, binary.BigEndian, &a.AdditionalInformation.Len); err != nil {
return fmt.Errorf("NAS decode error (DLNASTransport/AdditionalInformation): %w", err)
}
if a.AdditionalInformation.Len < 1 {
return fmt.Errorf("invalid ie length (DLNASTransport/AdditionalInformation): %d", a.AdditionalInformation.Len)
}
a.AdditionalInformation.SetLen(a.AdditionalInformation.GetLen())
if err := binary.Read(buffer, binary.BigEndian, a.AdditionalInformation.Buffer); err != nil {
return fmt.Errorf("NAS decode error (DLNASTransport/AdditionalInformation): %w", err)
}
case DLNASTransportCause5GMMType:
a.Cause5GMM = nasType.NewCause5GMM(ieiN)
if err := binary.Read(buffer, binary.BigEndian, &a.Cause5GMM.Octet); err != nil {
return fmt.Errorf("NAS decode error (DLNASTransport/Cause5GMM): %w", err)
}
case DLNASTransportBackoffTimerValueType:
a.BackoffTimerValue = nasType.NewBackoffTimerValue(ieiN)
if err := binary.Read(buffer, binary.BigEndian, &a.BackoffTimerValue.Len); err != nil {
return fmt.Errorf("NAS decode error (DLNASTransport/BackoffTimerValue): %w", err)
}
if a.BackoffTimerValue.Len != 1 {
return fmt.Errorf("invalid ie length (DLNASTransport/BackoffTimerValue): %d", a.BackoffTimerValue.Len)
}
a.BackoffTimerValue.SetLen(a.BackoffTimerValue.GetLen())
if err := binary.Read(buffer, binary.BigEndian, &a.BackoffTimerValue.Octet); err != nil {
return fmt.Errorf("NAS decode error (DLNASTransport/BackoffTimerValue): %w", err)
}
default:
}
}
return nil
}