This repository has been archived by the owner on Apr 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
gsm_build.go
126 lines (106 loc) · 5.68 KB
/
gsm_build.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
package smf_context
import (
"free5gc/lib/nas"
"free5gc/lib/nas/nasConvert"
"free5gc/lib/nas/nasMessage"
"free5gc/lib/nas/nasType"
// "free5gc/lib/nas/nasType"
)
func BuildGSMPDUSessionEstablishmentAccept(smContext *SMContext) ([]byte, error) {
m := nas.NewMessage()
m.GsmMessage = nas.NewGsmMessage()
m.GsmHeader.SetMessageType(nas.MsgTypePDUSessionEstablishmentAccept)
m.GsmHeader.SetExtendedProtocolDiscriminator(nasMessage.Epd5GSSessionManagementMessage)
m.PDUSessionEstablishmentAccept = nasMessage.NewPDUSessionEstablishmentAccept(0x0)
pDUSessionEstablishmentAccept := m.PDUSessionEstablishmentAccept
authDefQos := smContext.SessionRule.AuthDefQos
pDUSessionEstablishmentAccept.SetPDUSessionID(uint8(smContext.PDUSessionID))
pDUSessionEstablishmentAccept.SetMessageType(nas.MsgTypePDUSessionEstablishmentAccept)
pDUSessionEstablishmentAccept.SetExtendedProtocolDiscriminator(nasMessage.Epd5GSSessionManagementMessage)
pDUSessionEstablishmentAccept.SetPTI(0x00)
pDUSessionEstablishmentAccept.SetPDUSessionType(smContext.SelectedPDUSessionType)
pDUSessionEstablishmentAccept.SetSSCMode(1)
pDUSessionEstablishmentAccept.SessionAMBR = nasConvert.ModelsToSessionAMBR(smContext.SessionRule.AuthSessAmbr)
pDUSessionEstablishmentAccept.SessionAMBR.SetLen(uint8(len(pDUSessionEstablishmentAccept.SessionAMBR.Octet)))
qoSRules := QoSRules{
QoSRule{
Identifier: 0x01,
DQR: 0x01,
OperationCode: OperationCodeCreateNewQoSRule,
QFI: uint8(authDefQos.Var5qi),
PacketFilterList: []PacketFilter{
PacketFilter{
Identifier: 0x01,
Direction: PacketFilterDirectionBidirectional,
ComponentType: PacketFilterComponentTypeMatchAll,
},
},
},
}
qosRulesBytes, err := qoSRules.MarshalBinary()
if err != nil {
return nil, err
}
pDUSessionEstablishmentAccept.AuthorizedQosRules.SetLen(uint16(len(qosRulesBytes)))
pDUSessionEstablishmentAccept.AuthorizedQosRules.SetQosRule(qosRulesBytes)
if smContext.PDUAddress != nil {
addr, addrLen := smContext.PDUAddressToNAS()
pDUSessionEstablishmentAccept.PDUAddress = nasType.NewPDUAddress(nasMessage.PDUSessionEstablishmentAcceptPDUAddressType)
pDUSessionEstablishmentAccept.PDUAddress.SetLen(addrLen)
pDUSessionEstablishmentAccept.PDUAddress.SetPDUSessionTypeValue(smContext.SelectedPDUSessionType)
pDUSessionEstablishmentAccept.PDUAddress.SetPDUAddressInformation(addr)
}
// pDUSessionEstablishmentAccept.AuthorizedQosFlowDescriptions = nasType.NewAuthorizedQosFlowDescriptions(nasMessage.PDUSessionEstablishmentAcceptAuthorizedQosFlowDescriptionsType)
// pDUSessionEstablishmentAccept.AuthorizedQosFlowDescriptions.SetLen(6)
// pDUSessionEstablishmentAccept.SetQoSFlowDescriptions([]uint8{0x09, 0x20, 0x41, 0x01, 0x01, 0x09})
return m.PlainNasEncode()
}
func BuildGSMPDUSessionReleaseCommand(smContext *SMContext) ([]byte, error) {
m := nas.NewMessage()
m.GsmMessage = nas.NewGsmMessage()
m.GsmHeader.SetMessageType(nas.MsgTypePDUSessionReleaseCommand)
m.GsmHeader.SetExtendedProtocolDiscriminator(nasMessage.Epd5GSSessionManagementMessage)
m.PDUSessionReleaseCommand = nasMessage.NewPDUSessionReleaseCommand(0x0)
pDUSessionReleaseCommand := m.PDUSessionReleaseCommand
pDUSessionReleaseCommand.SetMessageType(nas.MsgTypePDUSessionReleaseCommand)
pDUSessionReleaseCommand.SetExtendedProtocolDiscriminator(nasMessage.Epd5GSSessionManagementMessage)
pDUSessionReleaseCommand.SetPDUSessionID(uint8(smContext.PDUSessionID))
pDUSessionReleaseCommand.SetPTI(0x00)
pDUSessionReleaseCommand.SetCauseValue(0x0)
return m.PlainNasEncode()
}
func BuildGSMPDUSessionModificationCommand(smContext *SMContext) ([]byte, error) {
m := nas.NewMessage()
m.GsmMessage = nas.NewGsmMessage()
m.GsmHeader.SetMessageType(nas.MsgTypePDUSessionModificationCommand)
m.GsmHeader.SetExtendedProtocolDiscriminator(nasMessage.Epd5GSSessionManagementMessage)
m.PDUSessionModificationCommand = nasMessage.NewPDUSessionModificationCommand(0x0)
pDUSessionModificationCommand := m.PDUSessionModificationCommand
pDUSessionModificationCommand.SetExtendedProtocolDiscriminator(nasMessage.Epd5GSSessionManagementMessage)
pDUSessionModificationCommand.SetPDUSessionID(uint8(smContext.PDUSessionID))
pDUSessionModificationCommand.SetPTI(0x00)
pDUSessionModificationCommand.SetMessageType(nas.MsgTypePDUSessionModificationCommand)
// pDUSessionModificationCommand.SetQosRule()
// pDUSessionModificationCommand.AuthorizedQosRules.SetLen()
// pDUSessionModificationCommand.SessionAMBR.SetSessionAMBRForDownlink([2]uint8{0x11, 0x11})
// pDUSessionModificationCommand.SessionAMBR.SetSessionAMBRForUplink([2]uint8{0x11, 0x11})
// pDUSessionModificationCommand.SessionAMBR.SetUnitForSessionAMBRForDownlink(10)
// pDUSessionModificationCommand.SessionAMBR.SetUnitForSessionAMBRForUplink(10)
// pDUSessionModificationCommand.SessionAMBR.SetLen(uint8(len(pDUSessionModificationCommand.SessionAMBR.Octet)))
return m.PlainNasEncode()
}
func BuildGSMPDUSessionReleaseReject(smContext *SMContext) ([]byte, error) {
m := nas.NewMessage()
m.GsmMessage = nas.NewGsmMessage()
m.GsmHeader.SetMessageType(nas.MsgTypePDUSessionReleaseReject)
m.GsmHeader.SetExtendedProtocolDiscriminator(nasMessage.Epd5GSSessionManagementMessage)
m.PDUSessionReleaseReject = nasMessage.NewPDUSessionReleaseReject(0x0)
pDUSessionReleaseReject := m.PDUSessionReleaseReject
pDUSessionReleaseReject.SetMessageType(nas.MsgTypePDUSessionReleaseReject)
pDUSessionReleaseReject.SetExtendedProtocolDiscriminator(nasMessage.Epd5GSSessionManagementMessage)
pDUSessionReleaseReject.SetPDUSessionID(uint8(smContext.PDUSessionID))
pDUSessionReleaseReject.SetPTI(0x00)
// TODO: fix to real value
pDUSessionReleaseReject.SetCauseValue(nasMessage.Cause5GSMRequestRejectedUnspecified)
return m.PlainNasEncode()
}