Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Marshaling of Dialogue
Browse files Browse the repository at this point in the history
linouxis9 committed Mar 26, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent def14b7 commit 53661cd
Showing 3 changed files with 29 additions and 21 deletions.
3 changes: 2 additions & 1 deletion dialogue-pdu.go
Original file line number Diff line number Diff line change
@@ -702,13 +702,14 @@ func (d *DialoguePDU) ContextVersion() string {

// String returns DialoguePDU in human readable string.
func (d *DialoguePDU) String() string {
return fmt.Sprintf("{Type: %#x, Length: %d, ProtocolVersion: %v, ApplicationContextName: %v, Result: %v, ResultSourceDiagnostic: %v, AbortSource: %v}",
return fmt.Sprintf("{Type: %#x, Length: %d, ProtocolVersion: %v, ApplicationContextName: %v, Result: %v, ResultSourceDiagnostic: %v, AbortSource: %v, UserInformation: %v}",
d.Type,
d.Length,
d.ProtocolVersion,
d.ApplicationContextName,
d.Result,
d.ResultSourceDiagnostic,
d.AbortSource,
d.UserInformation,
)
}
46 changes: 26 additions & 20 deletions dialogue.go
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ type Dialogue struct {
ExternalTag Tag
ExternalLength uint8
ObjectIdentifier *IE
SingleAsn1Type *IE
singleAsn1Type *IE
DialoguePDU *DialoguePDU
Payload []byte
}
@@ -39,7 +39,7 @@ func NewDialogue(oid, ver uint8, pdu *DialoguePDU, payload []byte) *Dialogue {
Length: 7,
Value: []byte{0, 17, 134, 5, 1, oid, ver},
},
SingleAsn1Type: &IE{
singleAsn1Type: &IE{
Tag: NewContextSpecificConstructorTag(0),
Length: uint8(pdu.MarshalLen()),
},
@@ -78,21 +78,24 @@ func (d *Dialogue) MarshalTo(b []byte) error {
offset += field.MarshalLen()
}

if field := d.SingleAsn1Type; field != nil {
if err := field.MarshalTo(b[offset : offset+field.MarshalLen()]); err != nil {
return err
if field := d.singleAsn1Type; field != nil {
if field := d.DialoguePDU; field != nil {
d.singleAsn1Type.Value = make([]byte, d.DialoguePDU.MarshalLen())

if err := d.DialoguePDU.MarshalTo(d.singleAsn1Type.Value); err != nil {
return err
}
}
offset += field.MarshalLen()
}

if field := d.DialoguePDU; field != nil {
d.singleAsn1Type.SetLength()
if err := field.MarshalTo(b[offset : offset+field.MarshalLen()]); err != nil {
return err
}
offset += field.MarshalLen()
}

copy(b[offset:], d.Payload)

return nil
}

@@ -125,13 +128,13 @@ func (d *Dialogue) UnmarshalBinary(b []byte) error {
}
offset += d.ObjectIdentifier.MarshalLen()

d.SingleAsn1Type, err = ParseIE(b[offset:])
d.singleAsn1Type, err = ParseIE(b[offset:])
if err != nil {
return err
}
offset += d.SingleAsn1Type.MarshalLen()
offset += d.singleAsn1Type.MarshalLen()

d.DialoguePDU, err = ParseDialoguePDU(d.SingleAsn1Type.Value)
d.DialoguePDU, err = ParseDialoguePDU(d.singleAsn1Type.Value)
if err != nil {
return err
}
@@ -155,7 +158,7 @@ func (d *Dialogue) SetValsFrom(berParsed *IE) error {
case 0x06:
d.ObjectIdentifier = iex
case 0xa0:
d.SingleAsn1Type = iex
d.singleAsn1Type = iex
dpdu = iex.IE[0]
}
}
@@ -190,32 +193,35 @@ func (d *Dialogue) MarshalLen() int {
if field := d.ObjectIdentifier; field != nil {
l += field.MarshalLen()
}
if field := d.SingleAsn1Type; field != nil {
l += field.MarshalLen()
}
if field := d.DialoguePDU; field != nil {
l += field.MarshalLen()
l += field.MarshalLen() + 2 // 2 = singleAsn1Type IE Header
}
l += len(d.Payload)

return l
return l + len(d.Payload)
}

// SetLength sets the length in Length field.
func (d *Dialogue) SetLength() {
if field := d.ObjectIdentifier; field != nil {
d.ObjectIdentifier.SetLength()
}
if field := d.DialoguePDU; field != nil {
d.DialoguePDU.SetLength()
}

d.Length = uint8(d.MarshalLen() - 2)
d.ExternalLength = uint8(d.MarshalLen() - 4)
}

// String returns the SCCP common header values in human readable format.
func (d *Dialogue) String() string {
return fmt.Sprintf("{Tag: %#x, Length: %d, ExternalTag: %x, ExternalLength: %d, ObjectIdentifier: %v, SingleAsn1Type: %v, DialoguePDU: %v, Payload: %x}",
return fmt.Sprintf("{Tag: %#x, Length: %d, ExternalTag: %x, ExternalLength: %d, ObjectIdentifier: %v, singleAsn1Type: %v, DialoguePDU: %v, Payload: %x}",
d.Tag,
d.Length,
d.ExternalTag,
d.ExternalLength,
d.ObjectIdentifier,
d.SingleAsn1Type,
d.singleAsn1Type,
d.DialoguePDU,
d.Payload,
)
1 change: 1 addition & 0 deletions tcap.go
Original file line number Diff line number Diff line change
@@ -114,6 +114,7 @@ func Parse(b []byte) (*TCAP, error) {
if err := t.UnmarshalBinary(b); err != nil {
return nil, err
}

return t, nil
}

0 comments on commit 53661cd

Please sign in to comment.