diff --git a/gtpv1/README.md b/gtpv1/README.md index d378fb2a..afcc97d0 100644 --- a/gtpv1/README.md +++ b/gtpv1/README.md @@ -416,7 +416,7 @@ _Even there are some missing IEs, you can create any kind of IEs by using `ie.Ne | 190 | Fully Qualified Domain Name | | | 191 | Evolved Allocation Retention Priority I | | | 192 | Evolved Allocation Retention Priority II | | -| 193 | Extended Common Flags | | +| 193 | Extended Common Flags | Yes | | 194 | User CSG Information | | | 195 | CSG Information Reporting Action | | | 196 | CSG ID | | @@ -441,7 +441,7 @@ _Even there are some missing IEs, you can create any kind of IEs by using `ie.Ne | 215 | LHN Id with NSAPI | | | 216 | CN Operator Selection Entity | | | 217 | UE Usage Type | | -| 218 | Extended Common Flags II | | +| 218 | Extended Common Flags II | Yes | | 219 | Node Identifier | | | 220 | CIoT Optimizations Support Indication | | | 221 | SCEF PDN Connection | | diff --git a/gtpv1/ie/extended-common-flags-ii.go b/gtpv1/ie/extended-common-flags-ii.go new file mode 100644 index 00000000..0349042d --- /dev/null +++ b/gtpv1/ie/extended-common-flags-ii.go @@ -0,0 +1,53 @@ +// Copyright 2019-2024 go-gtp authors. All rights reserved. +// Use of this source code is governed by a MIT-style license that can be +// found in the LICENSE file. + +package ie + +import "io" + +// NewExtendedCommonFlagsII creates a new ExtendedCommonFlagsII IE. +// +// Note: each flag should be set in 1 or 0. +func NewExtendedCommonFlagsII(pmtsmi, dtci, pnsi int) *IE { + return New( + ExtendedCommonFlagsII, + []byte{uint8( + pmtsmi<<2 | dtci<<1 | pnsi, + )}, + ) +} + +// ExtendedCommonFlagsII returns ExtendedCommonFlagsII value if type matches. +func (i *IE) ExtendedCommonFlagsII() (uint8, error) { + if i.Type != ExtendedCommonFlagsII { + return 0, &InvalidTypeError{Type: i.Type} + } + if len(i.Payload) == 0 { + return 0, io.ErrUnexpectedEOF + } + + return i.Payload[0], nil +} + +// MustExtendedCommonFlagsII returns ExtendedCommonFlagsII in uint8 if type matches. +// This should only be used if it is assured to have the value. +func (i *IE) MustExtendedCommonFlagsII() uint8 { + v, _ := i.ExtendedCommonFlagsII() + return v +} + +// IsPMTSMI checks if PMTSMI flag exists in ExtendedCommonFlagsII. +func (i *IE) IsPMTSMI() bool { + return ((i.MustExtendedCommonFlagsII() >> 2) & 0x01) != 0 +} + +// IsDTCI checks if DTCI flag exists in ExtendedCommonFlagsII. +func (i *IE) IsDTCI() bool { + return ((i.MustExtendedCommonFlagsII() >> 1) & 0x01) != 0 +} + +// IsPNSI checks if PNSI flag exists in ExtendedCommonFlagsII. +func (i *IE) IsPNSI() bool { + return (i.MustExtendedCommonFlagsII() & 0x01) != 0 +} diff --git a/gtpv1/ie/extended-common-flags.go b/gtpv1/ie/extended-common-flags.go new file mode 100644 index 00000000..e1ee49fb --- /dev/null +++ b/gtpv1/ie/extended-common-flags.go @@ -0,0 +1,78 @@ +// Copyright 2019-2024 go-gtp authors. All rights reserved. +// Use of this source code is governed by a MIT-style license that can be +// found in the LICENSE file. + +package ie + +import "io" + +// NewExtendedCommonFlags creates a new ExtendedCommonFlags IE. +// +// Note: each flag should be set in 1 or 0. +func NewExtendedCommonFlags(uasi, bdwi, pcri, vb, retloc, cpsr, ccrsi, unauthenticatedIMSI int) *IE { + return New( + ExtendedCommonFlags, + []byte{uint8( + uasi<<7 | bdwi<<6 | pcri<<5 | vb<<4 | retloc<<3 | cpsr<<2 | ccrsi<<1 | unauthenticatedIMSI, + )}, + ) +} + +// ExtendedCommonFlags returns ExtendedCommonFlags value if type matches. +func (i *IE) ExtendedCommonFlags() (uint8, error) { + if i.Type != ExtendedCommonFlags { + return 0, &InvalidTypeError{Type: i.Type} + } + if len(i.Payload) == 0 { + return 0, io.ErrUnexpectedEOF + } + + return i.Payload[0], nil +} + +// MustExtendedCommonFlags returns ExtendedCommonFlags in uint8 if type matches. +// This should only be used if it is assured to have the value. +func (i *IE) MustExtendedCommonFlags() uint8 { + v, _ := i.ExtendedCommonFlags() + return v +} + +// IsUASI checks if UASI flag exists in ExtendedCommonFlags. +func (i *IE) IsUASI() bool { + return ((i.MustExtendedCommonFlags() >> 7) & 0x01) != 0 +} + +// IsBDWI checks if BDWI flag exists in ExtendedCommonFlags. +func (i *IE) IsBDWI() bool { + return ((i.MustExtendedCommonFlags() >> 6) & 0x01) != 0 +} + +// IsPCRI checks if PCRI flag exists in ExtendedCommonFlags. +func (i *IE) IsPCRI() bool { + return ((i.MustExtendedCommonFlags() >> 5) & 0x01) != 0 +} + +// IsVB checks if VB flag exists in ExtendedCommonFlags. +func (i *IE) IsVB() bool { + return ((i.MustExtendedCommonFlags() >> 4) & 0x01) != 0 +} + +// IsRetLoc checks if RetLoc flag exists in ExtendedCommonFlags. +func (i *IE) IsRetLoc() bool { + return ((i.MustExtendedCommonFlags() >> 3) & 0x01) != 0 +} + +// IsCPSR checks if CPSR flag exists in ExtendedCommonFlags. +func (i *IE) IsCPSR() bool { + return ((i.MustExtendedCommonFlags() >> 2) & 0x01) != 0 +} + +// IsCCRSI checks if CCRSI flag exists in ExtendedCommonFlags. +func (i *IE) IsCCRSI() bool { + return ((i.MustExtendedCommonFlags() >> 1) & 0x01) != 0 +} + +// IsUnauthenticatedIMSI checks if UnauthenticatedIMSI flag exists in ExtendedCommonFlags. +func (i *IE) IsUnauthenticatedIMSI() bool { + return (i.MustExtendedCommonFlags() & 0x01) != 0 +} diff --git a/gtpv1/message/create-pdp-context-res.go b/gtpv1/message/create-pdp-context-res.go index f4e3386d..babdf1ef 100644 --- a/gtpv1/message/create-pdp-context-res.go +++ b/gtpv1/message/create-pdp-context-res.go @@ -32,7 +32,7 @@ type CreatePDPContextResponse struct { MSInfoChangeReportingAction *ie.IE BearerControlMode *ie.IE EvolvedARPI *ie.IE - ExtendedCommonFlag *ie.IE + ExtendedCommonFlags *ie.IE CSGInformationReportingAction *ie.IE APNAMBR *ie.IE GGSNBackOffTime *ie.IE @@ -99,7 +99,7 @@ func NewCreatePDPContextResponse(teid uint32, seq uint16, ies ...*ie.IE) *Create case ie.EvolvedAllocationRetentionPriorityI: c.EvolvedARPI = i case ie.ExtendedCommonFlags: - c.ExtendedCommonFlag = i + c.ExtendedCommonFlags = i case ie.CSGInformationReportingAction: c.CSGInformationReportingAction = i case ie.AggregateMaximumBitRate: @@ -263,7 +263,7 @@ func (c *CreatePDPContextResponse) MarshalTo(b []byte) error { } offset += ie.MarshalLen() } - if ie := c.ExtendedCommonFlag; ie != nil { + if ie := c.ExtendedCommonFlags; ie != nil { if err := ie.MarshalTo(c.Payload[offset:]); err != nil { return err } @@ -391,7 +391,7 @@ func (c *CreatePDPContextResponse) UnmarshalBinary(b []byte) error { case ie.EvolvedAllocationRetentionPriorityI: c.EvolvedARPI = i case ie.ExtendedCommonFlags: - c.ExtendedCommonFlag = i + c.ExtendedCommonFlags = i case ie.CSGInformationReportingAction: c.CSGInformationReportingAction = i case ie.AggregateMaximumBitRate: @@ -477,7 +477,7 @@ func (c *CreatePDPContextResponse) MarshalLen() int { if ie := c.EvolvedARPI; ie != nil { l += ie.MarshalLen() } - if ie := c.ExtendedCommonFlag; ie != nil { + if ie := c.ExtendedCommonFlags; ie != nil { l += ie.MarshalLen() } if ie := c.CSGInformationReportingAction; ie != nil { diff --git a/gtpv2/ie/indication.go b/gtpv2/ie/indication.go index c0a1a5de..b01b1797 100644 --- a/gtpv2/ie/indication.go +++ b/gtpv2/ie/indication.go @@ -655,8 +655,8 @@ func (i *IE) HasDTCI() bool { return has6thBit(v[4]) } -// HasUACI reports whether an IE has UACI bit. -func (i *IE) HasUACI() bool { +// HasUASI reports whether an IE has UASI bit. +func (i *IE) HasUASI() bool { v, err := i.Indication() if err != nil { return false