/
NAS_NotificationResponse.go
94 lines (86 loc) · 3.73 KB
/
NAS_NotificationResponse.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
// Code generated by generate.sh, DO NOT EDIT.
package nasMessage
import (
"bytes"
"encoding/binary"
"fmt"
"github.com/free5gc/nas/nasType"
)
type NotificationResponse struct {
nasType.ExtendedProtocolDiscriminator
nasType.SpareHalfOctetAndSecurityHeaderType
nasType.NotificationResponseMessageIdentity
*nasType.PDUSessionStatus
}
func NewNotificationResponse(iei uint8) (notificationResponse *NotificationResponse) {
notificationResponse = &NotificationResponse{}
return notificationResponse
}
const (
NotificationResponsePDUSessionStatusType uint8 = 0x50
)
func (a *NotificationResponse) EncodeNotificationResponse(buffer *bytes.Buffer) error {
if err := binary.Write(buffer, binary.BigEndian, a.ExtendedProtocolDiscriminator.Octet); err != nil {
return fmt.Errorf("NAS encode error (NotificationResponse/ExtendedProtocolDiscriminator): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.SpareHalfOctetAndSecurityHeaderType.Octet); err != nil {
return fmt.Errorf("NAS encode error (NotificationResponse/SpareHalfOctetAndSecurityHeaderType): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.NotificationResponseMessageIdentity.Octet); err != nil {
return fmt.Errorf("NAS encode error (NotificationResponse/NotificationResponseMessageIdentity): %w", err)
}
if a.PDUSessionStatus != nil {
if err := binary.Write(buffer, binary.BigEndian, a.PDUSessionStatus.GetIei()); err != nil {
return fmt.Errorf("NAS encode error (NotificationResponse/PDUSessionStatus): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.PDUSessionStatus.GetLen()); err != nil {
return fmt.Errorf("NAS encode error (NotificationResponse/PDUSessionStatus): %w", err)
}
if err := binary.Write(buffer, binary.BigEndian, a.PDUSessionStatus.Buffer); err != nil {
return fmt.Errorf("NAS encode error (NotificationResponse/PDUSessionStatus): %w", err)
}
}
return nil
}
func (a *NotificationResponse) DecodeNotificationResponse(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 (NotificationResponse/ExtendedProtocolDiscriminator): %w", err)
}
if err := binary.Read(buffer, binary.BigEndian, &a.SpareHalfOctetAndSecurityHeaderType.Octet); err != nil {
return fmt.Errorf("NAS decode error (NotificationResponse/SpareHalfOctetAndSecurityHeaderType): %w", err)
}
if err := binary.Read(buffer, binary.BigEndian, &a.NotificationResponseMessageIdentity.Octet); err != nil {
return fmt.Errorf("NAS decode error (NotificationResponse/NotificationResponseMessageIdentity): %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 (NotificationResponse/iei): %w", err)
}
// fmt.Println(ieiN)
if ieiN >= 0x80 {
tmpIeiN = (ieiN & 0xf0) >> 4
} else {
tmpIeiN = ieiN
}
// fmt.Println("type", tmpIeiN)
switch tmpIeiN {
case NotificationResponsePDUSessionStatusType:
a.PDUSessionStatus = nasType.NewPDUSessionStatus(ieiN)
if err := binary.Read(buffer, binary.BigEndian, &a.PDUSessionStatus.Len); err != nil {
return fmt.Errorf("NAS decode error (NotificationResponse/PDUSessionStatus): %w", err)
}
if a.PDUSessionStatus.Len < 2 || a.PDUSessionStatus.Len > 32 {
return fmt.Errorf("invalid ie length (NotificationResponse/PDUSessionStatus): %d", a.PDUSessionStatus.Len)
}
a.PDUSessionStatus.SetLen(a.PDUSessionStatus.GetLen())
if err := binary.Read(buffer, binary.BigEndian, a.PDUSessionStatus.Buffer); err != nil {
return fmt.Errorf("NAS decode error (NotificationResponse/PDUSessionStatus): %w", err)
}
default:
}
}
return nil
}