forked from free5gc/pfcp
/
Cause.go
57 lines (47 loc) · 1.05 KB
/
Cause.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
package pfcpType
import (
"fmt"
)
// Acceptance in a response
const (
CauseRequestAccepted uint8 = 1
)
// Rejection in a response
const (
CauseRequestRejected uint8 = iota + 64
CauseSessionContextNotFound
CauseMandatoryIeMissing
CauseConditionalIeMissing
CauseInvalidLength
CauseMandatoryIeIncorrect
CauseInvalidForwardingPolicy
CauseInvalidFTeidAllocationOption
CauseNoEstablishedPfcpAssociation
CauseRuleCreationModificationFailure
CausePfcpEntityInCongestion
CauseNoResourcesAvailable
CauseServiceNotSupported
CauseSystemFailure
)
type Cause struct {
CauseValue uint8
}
func (c *Cause) MarshalBinary() (data []byte, err error) {
// Octet 5
data = append([]byte(""), byte(c.CauseValue))
return data, nil
}
func (c *Cause) UnmarshalBinary(data []byte) error {
length := uint16(len(data))
var idx uint16 = 0
// Octet 5
if length < idx+1 {
return fmt.Errorf("Inadequate TLV length: %d", length)
}
c.CauseValue = uint8(data[idx])
idx = idx + 1
if length != idx {
return fmt.Errorf("Inadequate TLV length: %d", length)
}
return nil
}