Skip to content

Commit

Permalink
Fix: Deliver_SM UDH not always detected (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
laduchesneau authored Jan 28, 2023
1 parent 79c6649 commit 0d7eb15
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pdu/DeliverSM.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (c *DeliverSM) Unmarshal(b *ByteBuffer) error {
if c.ValidityPeriod, err = b.ReadCString(); err == nil {
if c.RegisteredDelivery, err = b.ReadByte(); err == nil {
if c.ReplaceIfPresentFlag, err = b.ReadByte(); err == nil {
err = c.Message.Unmarshal(b, c.EsmClass == data.SM_UDH_GSM)
err = c.Message.Unmarshal(b, (c.EsmClass&data.SM_UDH_GSM) > 0)
}
}
}
Expand Down
35 changes: 34 additions & 1 deletion pdu/DeliverSM_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,38 @@ func TestDeliverSM(t *testing.T) {
data.DELIVER_SM_RESP,
)

v.ServiceType = "abc"
_ = v.SourceAddr.SetAddress("Alicer")
v.SourceAddr.SetTon(28)
v.SourceAddr.SetNpi(29)
_ = v.DestAddr.SetAddress("Bobo")
v.DestAddr.SetTon(30)
v.DestAddr.SetNpi(31)
v.EsmClass = 13
v.ProtocolID = 99
v.PriorityFlag = 61
v.RegisteredDelivery = 83
_ = v.Message.SetMessageWithEncoding("nghắ nghiêng nghiễng ngả", data.UCS2)
v.Message.message = ""

validate(t,
v,
"0000005e00000005000000000000000d616263001c1d416c69636572001e1f426f626f000d633d00005300080030006e006700681eaf0020006e00670068006900ea006e00670020006e0067006800691ec5006e00670020006e00671ea3",
data.DELIVER_SM,
)
}

func TestDeliverSMwithUDH(t *testing.T) {
v := NewDeliverSM().(*DeliverSM)
require.True(t, v.CanResponse())
v.SequenceNumber = 13

validate(t,
v.GetResponse(),
"0000001180000005000000000000000d00",
data.DELIVER_SM_RESP,
)

v.ServiceType = "abc"
_ = v.SourceAddr.SetAddress("Alicer")
v.SourceAddr.SetTon(28)
Expand All @@ -32,10 +64,11 @@ func TestDeliverSM(t *testing.T) {
v.RegisteredDelivery = 83
_ = v.Message.SetMessageWithEncoding("nghắ nghiêng nghiễng ngả", data.UCS2)
v.Message.message = ""
v.Message.SetUDH(UDH{NewIEConcatMessage(2, 1, 254)})

validate(t,
v,
"0000005e00000005000000000000000d616263001c1d416c69636572001e1f426f626f004d633d00005300080030006e006700681eaf0020006e00670068006900ea006e00670020006e0067006800691ec5006e00670020006e00671ea3",
"0000006400000005000000000000000d616263001c1d416c69636572001e1f426f626f004d633d00005300080036050003fe0201006e006700681eaf0020006e00670068006900ea006e00670020006e0067006800691ec5006e00670020006e00671ea3",
data.DELIVER_SM,
)
}
2 changes: 1 addition & 1 deletion pdu/SubmitMulti.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (c *SubmitMulti) Unmarshal(b *ByteBuffer) error {
if c.ValidityPeriod, err = b.ReadCString(); err == nil {
if c.RegisteredDelivery, err = b.ReadByte(); err == nil {
if c.ReplaceIfPresentFlag, err = b.ReadByte(); err == nil {
err = c.Message.Unmarshal(b, c.EsmClass == data.SM_UDH_GSM)
err = c.Message.Unmarshal(b, (c.EsmClass&data.SM_UDH_GSM) > 0)
}
}
}
Expand Down
53 changes: 52 additions & 1 deletion pdu/SubmitMulti_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,56 @@ func TestSubmitMulti(t *testing.T) {
v.DestAddrs.Add(d1, d2, d3)
require.Equal(t, []DestinationAddress{d1, d2, d3}, v.DestAddrs.Get())

v.EsmClass = 13
v.ProtocolID = 99
v.PriorityFlag = 61
v.RegisteredDelivery = 83

v.Message, err = NewShortMessageWithEncoding("nghắ nghiêng nghiễng ngả", data.UCS2)
require.Nil(t, err)
v.Message.message = ""

validate(t,
v,
"0000006e00000021000000000000000d616263001c1d416c696365720003010000426f623100024c6973743100024c6973743200d633d00005300080030006e006700681eaf0020006e00670068006900ea006e00670020006e0067006800691ec5006e00670020006e00671ea3",
data.SUBMIT_MULTI,
)
}

func TestSubmitMultiwithUDH(t *testing.T) {
v := NewSubmitMulti().(*SubmitMulti)
require.True(t, v.CanResponse())
v.SequenceNumber = 13

validate(t,
v.GetResponse(),
"0000001280000021000000000000000d0000",
data.SUBMIT_MULTI_RESP,
)

v.ServiceType = "abc"
_ = v.SourceAddr.SetAddress("Alicer")
v.SourceAddr.SetTon(28)
v.SourceAddr.SetNpi(29)

addr := NewAddress()
require.Nil(t, addr.SetAddress("Bob1"))
d1 := NewDestinationAddress()
d1.SetAddress(addr)

dl, err := NewDistributionList("List1")
require.Nil(t, err)
d2 := NewDestinationAddress()
d2.SetDistributionList(dl)

dl, err = NewDistributionList("List2")
require.Nil(t, err)
d3 := NewDestinationAddress()
d3.SetDistributionList(dl)

v.DestAddrs.Add(d1, d2, d3)
require.Equal(t, []DestinationAddress{d1, d2, d3}, v.DestAddrs.Get())

v.EsmClass = 77
v.ProtocolID = 99
v.PriorityFlag = 61
Expand All @@ -50,10 +100,11 @@ func TestSubmitMulti(t *testing.T) {
v.Message, err = NewShortMessageWithEncoding("nghắ nghiêng nghiễng ngả", data.UCS2)
require.Nil(t, err)
v.Message.message = ""
v.Message.SetUDH(UDH{NewIEConcatMessage(2, 1, 254)})

validate(t,
v,
"0000006e00000021000000000000000d616263001c1d416c696365720003010000426f623100024c6973743100024c69737432004d633d00005300080030006e006700681eaf0020006e00670068006900ea006e00670020006e0067006800691ec5006e00670020006e00671ea3",
"0000007400000021000000000000000d616263001c1d416c696365720003010000426f623100024c6973743100024c69737432004d633d00005300080036050003fe0201006e006700681eaf0020006e00670068006900ea006e00670020006e0067006800691ec5006e00670020006e00671ea3",
data.SUBMIT_MULTI,
)
}

0 comments on commit 0d7eb15

Please sign in to comment.