-
Notifications
You must be signed in to change notification settings - Fork 6
/
nas.go
496 lines (464 loc) · 23.1 KB
/
nas.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
// Copyright 2019 free5GC.org
//
// SPDX-License-Identifier: Apache-2.0
//
package nas
import (
"bytes"
"encoding/binary"
"fmt"
"github.com/omec-project/nas/nasMessage"
)
// Message TODO:description
type Message struct {
SecurityHeader
*GmmMessage
*GsmMessage
}
// SecurityHeader TODO:description
type SecurityHeader struct {
ProtocolDiscriminator uint8
SecurityHeaderType uint8
MessageAuthenticationCode uint32
SequenceNumber uint8
}
const (
SecurityHeaderTypePlainNas uint8 = 0x00
SecurityHeaderTypeIntegrityProtected uint8 = 0x01
SecurityHeaderTypeIntegrityProtectedAndCiphered uint8 = 0x02
SecurityHeaderTypeIntegrityProtectedWithNew5gNasSecurityContext uint8 = 0x03
SecurityHeaderTypeIntegrityProtectedAndCipheredWithNew5gNasSecurityContext uint8 = 0x04
)
// NewMessage TODO:desc
func NewMessage() *Message {
Message := &Message{}
return Message
}
// NewGmmMessage TODO:desc
func NewGmmMessage() *GmmMessage {
GmmMessage := &GmmMessage{}
return GmmMessage
}
// NewGmmMessage TODO:desc
func NewGsmMessage() *GsmMessage {
GsmMessage := &GsmMessage{}
return GsmMessage
}
// GmmHeader Octet1 protocolDiscriminator securityHeaderType
// Octet2 MessageType
type GmmHeader struct {
Octet [3]uint8
}
type GsmHeader struct {
Octet [4]uint8
}
// GetMessageType 9.8
func (a *GmmHeader) GetMessageType() (messageType uint8) {
messageType = a.Octet[2]
return messageType
}
// GetMessageType 9.8
func (a *GmmHeader) SetMessageType(messageType uint8) {
a.Octet[2] = messageType
}
func (a *GmmHeader) GetExtendedProtocolDiscriminator() uint8 {
return a.Octet[0]
}
func (a *GmmHeader) SetExtendedProtocolDiscriminator(epd uint8) {
a.Octet[0] = epd
}
func (a *GsmHeader) GetExtendedProtocolDiscriminator() uint8 {
return a.Octet[0]
}
func (a *GsmHeader) SetExtendedProtocolDiscriminator(epd uint8) {
a.Octet[0] = epd
}
// GetMessageType 9.8
func (a *GsmHeader) GetMessageType() (messageType uint8) {
messageType = a.Octet[3]
return messageType
}
// GetMessageType 9.8
func (a *GsmHeader) SetMessageType(messageType uint8) {
a.Octet[3] = messageType
}
func GetEPD(byteArray []byte) uint8 {
return byteArray[0]
}
func GetSecurityHeaderType(byteArray []byte) uint8 {
return byteArray[1]
}
type GmmMessage struct {
GmmHeader
*nasMessage.AuthenticationRequest // 8.2.1
*nasMessage.AuthenticationResponse // 8.2.2
*nasMessage.AuthenticationResult // 8.2.3
*nasMessage.AuthenticationFailure // 8.2.4
*nasMessage.AuthenticationReject // 8.2.5
*nasMessage.RegistrationRequest // 8.2.6
*nasMessage.RegistrationAccept // 8.2.7
*nasMessage.RegistrationComplete // 8.2.8
*nasMessage.RegistrationReject // 8.2.9
*nasMessage.ULNASTransport // 8.2.10
*nasMessage.DLNASTransport // 8.2.11
*nasMessage.DeregistrationRequestUEOriginatingDeregistration // 8.2.12
*nasMessage.DeregistrationAcceptUEOriginatingDeregistration // 8.2.13
*nasMessage.DeregistrationRequestUETerminatedDeregistration // 8.2.14
*nasMessage.DeregistrationAcceptUETerminatedDeregistration // 8.2.15
*nasMessage.ServiceRequest // 8.2.16
*nasMessage.ServiceAccept // 8.2.17
*nasMessage.ServiceReject // 8.2.18
*nasMessage.ConfigurationUpdateCommand // 8.2.19
*nasMessage.ConfigurationUpdateComplete // 8.2.20
*nasMessage.IdentityRequest // 8.2.21
*nasMessage.IdentityResponse // 8.2.22
*nasMessage.Notification // 8.2.23
*nasMessage.NotificationResponse // 8.2.24
*nasMessage.SecurityModeCommand // 8.2.25
*nasMessage.SecurityModeComplete // 8.2.26
*nasMessage.SecurityModeReject // 8.2.27
*nasMessage.SecurityProtected5GSNASMessage // 8.2.28
*nasMessage.Status5GMM // 8.2.29
}
const (
MsgTypeRegistrationRequest uint8 = 65
MsgTypeRegistrationAccept uint8 = 66
MsgTypeRegistrationComplete uint8 = 67
MsgTypeRegistrationReject uint8 = 68
MsgTypeDeregistrationRequestUEOriginatingDeregistration uint8 = 69
MsgTypeDeregistrationAcceptUEOriginatingDeregistration uint8 = 70
MsgTypeDeregistrationRequestUETerminatedDeregistration uint8 = 71
MsgTypeDeregistrationAcceptUETerminatedDeregistration uint8 = 72
MsgTypeServiceRequest uint8 = 76
MsgTypeServiceReject uint8 = 77
MsgTypeServiceAccept uint8 = 78
MsgTypeConfigurationUpdateCommand uint8 = 84
MsgTypeConfigurationUpdateComplete uint8 = 85
MsgTypeAuthenticationRequest uint8 = 86
MsgTypeAuthenticationResponse uint8 = 87
MsgTypeAuthenticationReject uint8 = 88
MsgTypeAuthenticationFailure uint8 = 89
MsgTypeAuthenticationResult uint8 = 90
MsgTypeIdentityRequest uint8 = 91
MsgTypeIdentityResponse uint8 = 92
MsgTypeSecurityModeCommand uint8 = 93
MsgTypeSecurityModeComplete uint8 = 94
MsgTypeSecurityModeReject uint8 = 95
MsgTypeStatus5GMM uint8 = 100
MsgTypeNotification uint8 = 101
MsgTypeNotificationResponse uint8 = 102
MsgTypeULNASTransport uint8 = 103
MsgTypeDLNASTransport uint8 = 104
)
func (a *Message) PlainNasDecode(byteArray *[]byte) error {
epd := GetEPD(*byteArray)
switch epd {
case nasMessage.Epd5GSMobilityManagementMessage:
return a.GmmMessageDecode(byteArray)
case nasMessage.Epd5GSSessionManagementMessage:
return a.GsmMessageDecode(byteArray)
}
return fmt.Errorf("extended Protocol Discriminator[%d] is not allowed in Nas Message Decode", epd)
}
func (a *Message) PlainNasEncode() ([]byte, error) {
data := new(bytes.Buffer)
if a.GmmMessage != nil {
err := a.GmmMessageEncode(data)
return data.Bytes(), err
} else if a.GsmMessage != nil {
err := a.GsmMessageEncode(data)
return data.Bytes(), err
}
return nil, fmt.Errorf("Gmm/Gsm Message are both empty in Nas Message Encode")
}
func (a *Message) GmmMessageDecode(byteArray *[]byte) error {
buffer := bytes.NewBuffer(*byteArray)
a.GmmMessage = NewGmmMessage()
binary.Read(buffer, binary.BigEndian, &a.GmmMessage.GmmHeader)
switch a.GmmMessage.GmmHeader.GetMessageType() {
case MsgTypeRegistrationRequest:
a.GmmMessage.RegistrationRequest = nasMessage.NewRegistrationRequest(MsgTypeRegistrationRequest)
a.GmmMessage.DecodeRegistrationRequest(byteArray)
case MsgTypeRegistrationAccept:
a.GmmMessage.RegistrationAccept = nasMessage.NewRegistrationAccept(MsgTypeRegistrationAccept)
a.GmmMessage.DecodeRegistrationAccept(byteArray)
case MsgTypeRegistrationComplete:
a.GmmMessage.RegistrationComplete = nasMessage.NewRegistrationComplete(MsgTypeRegistrationComplete)
a.GmmMessage.DecodeRegistrationComplete(byteArray)
case MsgTypeRegistrationReject:
a.GmmMessage.RegistrationReject = nasMessage.NewRegistrationReject(MsgTypeRegistrationReject)
a.GmmMessage.DecodeRegistrationReject(byteArray)
case MsgTypeDeregistrationRequestUEOriginatingDeregistration:
a.GmmMessage.DeregistrationRequestUEOriginatingDeregistration = nasMessage.NewDeregistrationRequestUEOriginatingDeregistration(MsgTypeDeregistrationRequestUEOriginatingDeregistration)
a.GmmMessage.DecodeDeregistrationRequestUEOriginatingDeregistration(byteArray)
case MsgTypeDeregistrationAcceptUEOriginatingDeregistration:
a.GmmMessage.DeregistrationAcceptUEOriginatingDeregistration = nasMessage.NewDeregistrationAcceptUEOriginatingDeregistration(MsgTypeDeregistrationAcceptUEOriginatingDeregistration)
a.GmmMessage.DecodeDeregistrationAcceptUEOriginatingDeregistration(byteArray)
case MsgTypeDeregistrationRequestUETerminatedDeregistration:
a.GmmMessage.DeregistrationRequestUETerminatedDeregistration = nasMessage.NewDeregistrationRequestUETerminatedDeregistration(MsgTypeDeregistrationRequestUETerminatedDeregistration)
a.GmmMessage.DecodeDeregistrationRequestUETerminatedDeregistration(byteArray)
case MsgTypeDeregistrationAcceptUETerminatedDeregistration:
a.GmmMessage.DeregistrationAcceptUETerminatedDeregistration = nasMessage.NewDeregistrationAcceptUETerminatedDeregistration(MsgTypeDeregistrationAcceptUETerminatedDeregistration)
a.GmmMessage.DecodeDeregistrationAcceptUETerminatedDeregistration(byteArray)
case MsgTypeServiceRequest:
a.GmmMessage.ServiceRequest = nasMessage.NewServiceRequest(MsgTypeServiceRequest)
a.GmmMessage.DecodeServiceRequest(byteArray)
case MsgTypeServiceReject:
a.GmmMessage.ServiceReject = nasMessage.NewServiceReject(MsgTypeServiceReject)
a.GmmMessage.DecodeServiceReject(byteArray)
case MsgTypeServiceAccept:
a.GmmMessage.ServiceAccept = nasMessage.NewServiceAccept(MsgTypeServiceAccept)
a.GmmMessage.DecodeServiceAccept(byteArray)
case MsgTypeConfigurationUpdateCommand:
a.GmmMessage.ConfigurationUpdateCommand = nasMessage.NewConfigurationUpdateCommand(MsgTypeConfigurationUpdateCommand)
a.GmmMessage.DecodeConfigurationUpdateCommand(byteArray)
case MsgTypeConfigurationUpdateComplete:
a.GmmMessage.ConfigurationUpdateComplete = nasMessage.NewConfigurationUpdateComplete(MsgTypeConfigurationUpdateComplete)
a.GmmMessage.DecodeConfigurationUpdateComplete(byteArray)
case MsgTypeAuthenticationRequest:
a.GmmMessage.AuthenticationRequest = nasMessage.NewAuthenticationRequest(MsgTypeAuthenticationRequest)
a.GmmMessage.DecodeAuthenticationRequest(byteArray)
case MsgTypeAuthenticationResponse:
a.GmmMessage.AuthenticationResponse = nasMessage.NewAuthenticationResponse(MsgTypeAuthenticationResponse)
a.GmmMessage.DecodeAuthenticationResponse(byteArray)
case MsgTypeAuthenticationReject:
a.GmmMessage.AuthenticationReject = nasMessage.NewAuthenticationReject(MsgTypeAuthenticationReject)
a.GmmMessage.DecodeAuthenticationReject(byteArray)
case MsgTypeAuthenticationFailure:
a.GmmMessage.AuthenticationFailure = nasMessage.NewAuthenticationFailure(MsgTypeAuthenticationFailure)
a.GmmMessage.DecodeAuthenticationFailure(byteArray)
case MsgTypeAuthenticationResult:
a.GmmMessage.AuthenticationResult = nasMessage.NewAuthenticationResult(MsgTypeAuthenticationResult)
a.GmmMessage.DecodeAuthenticationResult(byteArray)
case MsgTypeIdentityRequest:
a.GmmMessage.IdentityRequest = nasMessage.NewIdentityRequest(MsgTypeIdentityRequest)
a.GmmMessage.DecodeIdentityRequest(byteArray)
case MsgTypeIdentityResponse:
a.GmmMessage.IdentityResponse = nasMessage.NewIdentityResponse(MsgTypeIdentityResponse)
a.GmmMessage.DecodeIdentityResponse(byteArray)
case MsgTypeSecurityModeCommand:
a.GmmMessage.SecurityModeCommand = nasMessage.NewSecurityModeCommand(MsgTypeSecurityModeCommand)
a.GmmMessage.DecodeSecurityModeCommand(byteArray)
case MsgTypeSecurityModeComplete:
a.GmmMessage.SecurityModeComplete = nasMessage.NewSecurityModeComplete(MsgTypeSecurityModeComplete)
a.GmmMessage.DecodeSecurityModeComplete(byteArray)
case MsgTypeSecurityModeReject:
a.GmmMessage.SecurityModeReject = nasMessage.NewSecurityModeReject(MsgTypeSecurityModeReject)
a.GmmMessage.DecodeSecurityModeReject(byteArray)
case MsgTypeStatus5GMM:
a.GmmMessage.Status5GMM = nasMessage.NewStatus5GMM(MsgTypeStatus5GMM)
a.GmmMessage.DecodeStatus5GMM(byteArray)
case MsgTypeNotification:
a.GmmMessage.Notification = nasMessage.NewNotification(MsgTypeNotification)
a.GmmMessage.DecodeNotification(byteArray)
case MsgTypeNotificationResponse:
a.GmmMessage.NotificationResponse = nasMessage.NewNotificationResponse(MsgTypeNotificationResponse)
a.GmmMessage.DecodeNotificationResponse(byteArray)
case MsgTypeULNASTransport:
a.GmmMessage.ULNASTransport = nasMessage.NewULNASTransport(MsgTypeULNASTransport)
a.GmmMessage.DecodeULNASTransport(byteArray)
case MsgTypeDLNASTransport:
a.GmmMessage.DLNASTransport = nasMessage.NewDLNASTransport(MsgTypeDLNASTransport)
a.GmmMessage.DecodeDLNASTransport(byteArray)
default:
return fmt.Errorf("NAS decode fail: MsgType[%d] does not exist in GMM Message", a.GmmMessage.GmmHeader.GetMessageType())
}
return nil
}
func (a *Message) GmmMessageEncode(buffer *bytes.Buffer) error {
switch a.GmmMessage.GmmHeader.GetMessageType() {
case MsgTypeRegistrationRequest:
a.GmmMessage.EncodeRegistrationRequest(buffer)
case MsgTypeRegistrationAccept:
a.GmmMessage.EncodeRegistrationAccept(buffer)
case MsgTypeRegistrationComplete:
a.GmmMessage.EncodeRegistrationComplete(buffer)
case MsgTypeRegistrationReject:
a.GmmMessage.EncodeRegistrationReject(buffer)
case MsgTypeDeregistrationRequestUEOriginatingDeregistration:
a.GmmMessage.EncodeDeregistrationRequestUEOriginatingDeregistration(buffer)
case MsgTypeDeregistrationAcceptUEOriginatingDeregistration:
a.GmmMessage.EncodeDeregistrationAcceptUEOriginatingDeregistration(buffer)
case MsgTypeDeregistrationRequestUETerminatedDeregistration:
a.GmmMessage.EncodeDeregistrationRequestUETerminatedDeregistration(buffer)
case MsgTypeDeregistrationAcceptUETerminatedDeregistration:
a.GmmMessage.EncodeDeregistrationAcceptUETerminatedDeregistration(buffer)
case MsgTypeServiceRequest:
a.GmmMessage.EncodeServiceRequest(buffer)
case MsgTypeServiceReject:
a.GmmMessage.EncodeServiceReject(buffer)
case MsgTypeServiceAccept:
a.GmmMessage.EncodeServiceAccept(buffer)
case MsgTypeConfigurationUpdateCommand:
a.GmmMessage.EncodeConfigurationUpdateCommand(buffer)
case MsgTypeConfigurationUpdateComplete:
a.GmmMessage.EncodeConfigurationUpdateComplete(buffer)
case MsgTypeAuthenticationRequest:
a.GmmMessage.EncodeAuthenticationRequest(buffer)
case MsgTypeAuthenticationResponse:
a.GmmMessage.EncodeAuthenticationResponse(buffer)
case MsgTypeAuthenticationReject:
a.GmmMessage.EncodeAuthenticationReject(buffer)
case MsgTypeAuthenticationFailure:
a.GmmMessage.EncodeAuthenticationFailure(buffer)
case MsgTypeAuthenticationResult:
a.GmmMessage.EncodeAuthenticationResult(buffer)
case MsgTypeIdentityRequest:
a.GmmMessage.EncodeIdentityRequest(buffer)
case MsgTypeIdentityResponse:
a.GmmMessage.EncodeIdentityResponse(buffer)
case MsgTypeSecurityModeCommand:
a.GmmMessage.EncodeSecurityModeCommand(buffer)
case MsgTypeSecurityModeComplete:
a.GmmMessage.EncodeSecurityModeComplete(buffer)
case MsgTypeSecurityModeReject:
a.GmmMessage.EncodeSecurityModeReject(buffer)
case MsgTypeStatus5GMM:
a.GmmMessage.EncodeStatus5GMM(buffer)
case MsgTypeNotification:
a.GmmMessage.EncodeNotification(buffer)
case MsgTypeNotificationResponse:
a.GmmMessage.EncodeNotificationResponse(buffer)
case MsgTypeULNASTransport:
a.GmmMessage.EncodeULNASTransport(buffer)
case MsgTypeDLNASTransport:
a.GmmMessage.EncodeDLNASTransport(buffer)
default:
return fmt.Errorf("NAS encode fail: MsgType[%d] does not exist in GMM Message", a.GmmMessage.GmmHeader.GetMessageType())
}
return nil
}
type GsmMessage struct {
GsmHeader
*nasMessage.PDUSessionEstablishmentRequest // 8.3.1
*nasMessage.PDUSessionEstablishmentAccept // 8.3.2
*nasMessage.PDUSessionEstablishmentReject // 8.3.3
*nasMessage.PDUSessionAuthenticationCommand // 8.3.4
*nasMessage.PDUSessionAuthenticationComplete // 8.3.5
*nasMessage.PDUSessionAuthenticationResult // 8.3.6
*nasMessage.PDUSessionModificationRequest // 8.3.7
*nasMessage.PDUSessionModificationReject // 8.3.8
*nasMessage.PDUSessionModificationCommand // 8.3.9
*nasMessage.PDUSessionModificationComplete // 8.3.10
*nasMessage.PDUSessionModificationCommandReject // 8.3.11
*nasMessage.PDUSessionReleaseRequest // 8.3.12
*nasMessage.PDUSessionReleaseReject // 8.3.13
*nasMessage.PDUSessionReleaseCommand // 8.3.14
*nasMessage.PDUSessionReleaseComplete // 8.3.15
*nasMessage.Status5GSM // 8.3.16
}
const (
MsgTypePDUSessionEstablishmentRequest uint8 = 193
MsgTypePDUSessionEstablishmentAccept uint8 = 194
MsgTypePDUSessionEstablishmentReject uint8 = 195
MsgTypePDUSessionAuthenticationCommand uint8 = 197
MsgTypePDUSessionAuthenticationComplete uint8 = 198
MsgTypePDUSessionAuthenticationResult uint8 = 199
MsgTypePDUSessionModificationRequest uint8 = 201
MsgTypePDUSessionModificationReject uint8 = 202
MsgTypePDUSessionModificationCommand uint8 = 203
MsgTypePDUSessionModificationComplete uint8 = 204
MsgTypePDUSessionModificationCommandReject uint8 = 205
MsgTypePDUSessionReleaseRequest uint8 = 209
MsgTypePDUSessionReleaseReject uint8 = 210
MsgTypePDUSessionReleaseCommand uint8 = 211
MsgTypePDUSessionReleaseComplete uint8 = 212
MsgTypeStatus5GSM uint8 = 214
)
func (a *Message) GsmMessageDecode(byteArray *[]byte) error {
buffer := bytes.NewBuffer(*byteArray)
a.GsmMessage = NewGsmMessage()
binary.Read(buffer, binary.BigEndian, &a.GsmMessage.GsmHeader)
switch a.GsmMessage.GsmHeader.GetMessageType() {
case MsgTypePDUSessionEstablishmentRequest:
a.GsmMessage.PDUSessionEstablishmentRequest = nasMessage.NewPDUSessionEstablishmentRequest(MsgTypePDUSessionEstablishmentRequest)
a.GsmMessage.DecodePDUSessionEstablishmentRequest(byteArray)
case MsgTypePDUSessionEstablishmentAccept:
a.GsmMessage.PDUSessionEstablishmentAccept = nasMessage.NewPDUSessionEstablishmentAccept(MsgTypePDUSessionEstablishmentAccept)
a.GsmMessage.DecodePDUSessionEstablishmentAccept(byteArray)
case MsgTypePDUSessionEstablishmentReject:
a.GsmMessage.PDUSessionEstablishmentReject = nasMessage.NewPDUSessionEstablishmentReject(MsgTypePDUSessionEstablishmentReject)
a.GsmMessage.DecodePDUSessionEstablishmentReject(byteArray)
case MsgTypePDUSessionAuthenticationCommand:
a.GsmMessage.PDUSessionAuthenticationCommand = nasMessage.NewPDUSessionAuthenticationCommand(MsgTypePDUSessionAuthenticationCommand)
a.GsmMessage.DecodePDUSessionAuthenticationCommand(byteArray)
case MsgTypePDUSessionAuthenticationComplete:
a.GsmMessage.PDUSessionAuthenticationComplete = nasMessage.NewPDUSessionAuthenticationComplete(MsgTypePDUSessionAuthenticationComplete)
a.GsmMessage.DecodePDUSessionAuthenticationComplete(byteArray)
case MsgTypePDUSessionAuthenticationResult:
a.GsmMessage.PDUSessionAuthenticationResult = nasMessage.NewPDUSessionAuthenticationResult(MsgTypePDUSessionAuthenticationResult)
a.GsmMessage.DecodePDUSessionAuthenticationResult(byteArray)
case MsgTypePDUSessionModificationRequest:
a.GsmMessage.PDUSessionModificationRequest = nasMessage.NewPDUSessionModificationRequest(MsgTypePDUSessionModificationRequest)
a.GsmMessage.DecodePDUSessionModificationRequest(byteArray)
case MsgTypePDUSessionModificationReject:
a.GsmMessage.PDUSessionModificationReject = nasMessage.NewPDUSessionModificationReject(MsgTypePDUSessionModificationReject)
a.GsmMessage.DecodePDUSessionModificationReject(byteArray)
case MsgTypePDUSessionModificationCommand:
a.GsmMessage.PDUSessionModificationCommand = nasMessage.NewPDUSessionModificationCommand(MsgTypePDUSessionModificationCommand)
a.GsmMessage.DecodePDUSessionModificationCommand(byteArray)
case MsgTypePDUSessionModificationComplete:
a.GsmMessage.PDUSessionModificationComplete = nasMessage.NewPDUSessionModificationComplete(MsgTypePDUSessionModificationComplete)
a.GsmMessage.DecodePDUSessionModificationComplete(byteArray)
case MsgTypePDUSessionModificationCommandReject:
a.GsmMessage.PDUSessionModificationCommandReject = nasMessage.NewPDUSessionModificationCommandReject(MsgTypePDUSessionModificationCommandReject)
a.GsmMessage.DecodePDUSessionModificationCommandReject(byteArray)
case MsgTypePDUSessionReleaseRequest:
a.GsmMessage.PDUSessionReleaseRequest = nasMessage.NewPDUSessionReleaseRequest(MsgTypePDUSessionReleaseRequest)
a.GsmMessage.DecodePDUSessionReleaseRequest(byteArray)
case MsgTypePDUSessionReleaseReject:
a.GsmMessage.PDUSessionReleaseReject = nasMessage.NewPDUSessionReleaseReject(MsgTypePDUSessionReleaseReject)
a.GsmMessage.DecodePDUSessionReleaseReject(byteArray)
case MsgTypePDUSessionReleaseCommand:
a.GsmMessage.PDUSessionReleaseCommand = nasMessage.NewPDUSessionReleaseCommand(MsgTypePDUSessionReleaseCommand)
a.GsmMessage.DecodePDUSessionReleaseCommand(byteArray)
case MsgTypePDUSessionReleaseComplete:
a.GsmMessage.PDUSessionReleaseComplete = nasMessage.NewPDUSessionReleaseComplete(MsgTypePDUSessionReleaseComplete)
a.GsmMessage.DecodePDUSessionReleaseComplete(byteArray)
case MsgTypeStatus5GSM:
a.GsmMessage.Status5GSM = nasMessage.NewStatus5GSM(MsgTypeStatus5GSM)
a.GsmMessage.DecodeStatus5GSM(byteArray)
default:
return fmt.Errorf("NAS decode fail: MsgType[%d] does not exist in GSM Message", a.GsmMessage.GsmHeader.GetMessageType())
}
return nil
}
func (a *Message) GsmMessageEncode(buffer *bytes.Buffer) error {
switch a.GsmMessage.GsmHeader.GetMessageType() {
case MsgTypePDUSessionEstablishmentRequest:
a.GsmMessage.EncodePDUSessionEstablishmentRequest(buffer)
case MsgTypePDUSessionEstablishmentAccept:
a.GsmMessage.EncodePDUSessionEstablishmentAccept(buffer)
case MsgTypePDUSessionEstablishmentReject:
a.GsmMessage.EncodePDUSessionEstablishmentReject(buffer)
case MsgTypePDUSessionAuthenticationCommand:
a.GsmMessage.EncodePDUSessionAuthenticationCommand(buffer)
case MsgTypePDUSessionAuthenticationComplete:
a.GsmMessage.EncodePDUSessionAuthenticationComplete(buffer)
case MsgTypePDUSessionAuthenticationResult:
a.GsmMessage.EncodePDUSessionAuthenticationResult(buffer)
case MsgTypePDUSessionModificationRequest:
a.GsmMessage.EncodePDUSessionModificationRequest(buffer)
case MsgTypePDUSessionModificationReject:
a.GsmMessage.EncodePDUSessionModificationReject(buffer)
case MsgTypePDUSessionModificationCommand:
a.GsmMessage.EncodePDUSessionModificationCommand(buffer)
case MsgTypePDUSessionModificationComplete:
a.GsmMessage.EncodePDUSessionModificationComplete(buffer)
case MsgTypePDUSessionModificationCommandReject:
a.GsmMessage.EncodePDUSessionModificationCommandReject(buffer)
case MsgTypePDUSessionReleaseRequest:
a.GsmMessage.EncodePDUSessionReleaseRequest(buffer)
case MsgTypePDUSessionReleaseReject:
a.GsmMessage.EncodePDUSessionReleaseReject(buffer)
case MsgTypePDUSessionReleaseCommand:
a.GsmMessage.EncodePDUSessionReleaseCommand(buffer)
case MsgTypePDUSessionReleaseComplete:
a.GsmMessage.EncodePDUSessionReleaseComplete(buffer)
case MsgTypeStatus5GSM:
a.GsmMessage.EncodeStatus5GSM(buffer)
default:
return fmt.Errorf("NAS encode fail: MsgType[%d] does not exist in GSM Message", a.GsmMessage.GsmHeader.GetMessageType())
}
return nil
}