/
NAS_AuthenticationRequest.go
158 lines (150 loc) · 7.32 KB
/
NAS_AuthenticationRequest.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
// Code generated by generate.sh, DO NOT EDIT.
package nasMessage
import (
"bytes"
"encoding/binary"
"fmt"
"github.com/free5gc/nas/nasType"
)
type AuthenticationRequest struct {
nasType.ExtendedProtocolDiscriminator
nasType.SpareHalfOctetAndSecurityHeaderType
nasType.AuthenticationRequestMessageIdentity
nasType.SpareHalfOctetAndNgksi
nasType.ABBA
*nasType.AuthenticationParameterRAND
*nasType.AuthenticationParameterAUTN
*nasType.EAPMessage
}
func NewAuthenticationRequest(iei uint8) (authenticationRequest *AuthenticationRequest) {
authenticationRequest = &AuthenticationRequest{}
return authenticationRequest
}
const (
AuthenticationRequestAuthenticationParameterRANDType uint8 = 0x21
AuthenticationRequestAuthenticationParameterAUTNType uint8 = 0x20
AuthenticationRequestEAPMessageType uint8 = 0x78
)
func (a *AuthenticationRequest) EncodeAuthenticationRequest(buffer *bytes.Buffer) error {
if err := binary.Write(buffer, binary.BigEndian, a.ExtendedProtocolDiscriminator.Octet); err != nil {
return fmt.Errorf("NAS encode error (AuthenticationRequest/ExtendedProtocolDiscriminator): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.SpareHalfOctetAndSecurityHeaderType.Octet); err != nil {
return fmt.Errorf("NAS encode error (AuthenticationRequest/SpareHalfOctetAndSecurityHeaderType): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.AuthenticationRequestMessageIdentity.Octet); err != nil {
return fmt.Errorf("NAS encode error (AuthenticationRequest/AuthenticationRequestMessageIdentity): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.SpareHalfOctetAndNgksi.Octet); err != nil {
return fmt.Errorf("NAS encode error (AuthenticationRequest/SpareHalfOctetAndNgksi): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.ABBA.GetLen()); err != nil {
return fmt.Errorf("NAS encode error (AuthenticationRequest/ABBA): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.ABBA.Buffer); err != nil {
return fmt.Errorf("NAS encode error (AuthenticationRequest/ABBA): %w", err)
}
if a.AuthenticationParameterRAND != nil {
if err := binary.Write(buffer, binary.BigEndian, a.AuthenticationParameterRAND.GetIei()); err != nil {
return fmt.Errorf("NAS encode error (AuthenticationRequest/AuthenticationParameterRAND): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.AuthenticationParameterRAND.Octet[:]); err != nil {
return fmt.Errorf("NAS encode error (AuthenticationRequest/AuthenticationParameterRAND): %w", err)
}
}
if a.AuthenticationParameterAUTN != nil {
if err := binary.Write(buffer, binary.BigEndian, a.AuthenticationParameterAUTN.GetIei()); err != nil {
return fmt.Errorf("NAS encode error (AuthenticationRequest/AuthenticationParameterAUTN): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.AuthenticationParameterAUTN.GetLen()); err != nil {
return fmt.Errorf("NAS encode error (AuthenticationRequest/AuthenticationParameterAUTN): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.AuthenticationParameterAUTN.Octet[:]); err != nil {
return fmt.Errorf("NAS encode error (AuthenticationRequest/AuthenticationParameterAUTN): %w", err)
}
}
if a.EAPMessage != nil {
if err := binary.Write(buffer, binary.BigEndian, a.EAPMessage.GetIei()); err != nil {
return fmt.Errorf("NAS encode error (AuthenticationRequest/EAPMessage): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.EAPMessage.GetLen()); err != nil {
return fmt.Errorf("NAS encode error (AuthenticationRequest/EAPMessage): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.EAPMessage.Buffer); err != nil {
return fmt.Errorf("NAS encode error (AuthenticationRequest/EAPMessage): %w", err)
}
}
return nil
}
func (a *AuthenticationRequest) DecodeAuthenticationRequest(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 (AuthenticationRequest/ExtendedProtocolDiscriminator): %w", err)
}
if err := binary.Read(buffer, binary.BigEndian, &a.SpareHalfOctetAndSecurityHeaderType.Octet); err != nil {
return fmt.Errorf("NAS decode error (AuthenticationRequest/SpareHalfOctetAndSecurityHeaderType): %w", err)
}
if err := binary.Read(buffer, binary.BigEndian, &a.AuthenticationRequestMessageIdentity.Octet); err != nil {
return fmt.Errorf("NAS decode error (AuthenticationRequest/AuthenticationRequestMessageIdentity): %w", err)
}
if err := binary.Read(buffer, binary.BigEndian, &a.SpareHalfOctetAndNgksi.Octet); err != nil {
return fmt.Errorf("NAS decode error (AuthenticationRequest/SpareHalfOctetAndNgksi): %w", err)
}
if err := binary.Read(buffer, binary.BigEndian, &a.ABBA.Len); err != nil {
return fmt.Errorf("NAS decode error (AuthenticationRequest/ABBA): %w", err)
}
if a.ABBA.Len < 2 {
return fmt.Errorf("invalid ie length (AuthenticationRequest/ABBA): %d", a.ABBA.Len)
}
a.ABBA.SetLen(a.ABBA.GetLen())
if err := binary.Read(buffer, binary.BigEndian, a.ABBA.Buffer); err != nil {
return fmt.Errorf("NAS decode error (AuthenticationRequest/ABBA): %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 (AuthenticationRequest/iei): %w", err)
}
// fmt.Println(ieiN)
if ieiN >= 0x80 {
tmpIeiN = (ieiN & 0xf0) >> 4
} else {
tmpIeiN = ieiN
}
// fmt.Println("type", tmpIeiN)
switch tmpIeiN {
case AuthenticationRequestAuthenticationParameterRANDType:
a.AuthenticationParameterRAND = nasType.NewAuthenticationParameterRAND(ieiN)
if err := binary.Read(buffer, binary.BigEndian, a.AuthenticationParameterRAND.Octet[:]); err != nil {
return fmt.Errorf("NAS decode error (AuthenticationRequest/AuthenticationParameterRAND): %w", err)
}
case AuthenticationRequestAuthenticationParameterAUTNType:
a.AuthenticationParameterAUTN = nasType.NewAuthenticationParameterAUTN(ieiN)
if err := binary.Read(buffer, binary.BigEndian, &a.AuthenticationParameterAUTN.Len); err != nil {
return fmt.Errorf("NAS decode error (AuthenticationRequest/AuthenticationParameterAUTN): %w", err)
}
if a.AuthenticationParameterAUTN.Len != 16 {
return fmt.Errorf("invalid ie length (AuthenticationRequest/AuthenticationParameterAUTN): %d", a.AuthenticationParameterAUTN.Len)
}
a.AuthenticationParameterAUTN.SetLen(a.AuthenticationParameterAUTN.GetLen())
if err := binary.Read(buffer, binary.BigEndian, a.AuthenticationParameterAUTN.Octet[:]); err != nil {
return fmt.Errorf("NAS decode error (AuthenticationRequest/AuthenticationParameterAUTN): %w", err)
}
case AuthenticationRequestEAPMessageType:
a.EAPMessage = nasType.NewEAPMessage(ieiN)
if err := binary.Read(buffer, binary.BigEndian, &a.EAPMessage.Len); err != nil {
return fmt.Errorf("NAS decode error (AuthenticationRequest/EAPMessage): %w", err)
}
if a.EAPMessage.Len < 4 || a.EAPMessage.Len > 1500 {
return fmt.Errorf("invalid ie length (AuthenticationRequest/EAPMessage): %d", a.EAPMessage.Len)
}
a.EAPMessage.SetLen(a.EAPMessage.GetLen())
if err := binary.Read(buffer, binary.BigEndian, a.EAPMessage.Buffer); err != nil {
return fmt.Errorf("NAS decode error (AuthenticationRequest/EAPMessage): %w", err)
}
default:
}
}
return nil
}