Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Extended Common Flags and Extended Common Flags II #268

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gtpv1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | |
Expand All @@ -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 | |
Expand Down
53 changes: 53 additions & 0 deletions gtpv1/ie/extended-common-flags-ii.go
Original file line number Diff line number Diff line change
@@ -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
}
78 changes: 78 additions & 0 deletions gtpv1/ie/extended-common-flags.go
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 5 additions & 5 deletions gtpv1/message/create-pdp-context-res.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions gtpv2/ie/indication.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading