Advertisement
Borik

Untitled

Apr 21st, 2025
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 4.19 KB | None | 0 0
  1. package libnas
  2.  
  3. import (
  4.     "bytes"
  5.     "testing"
  6. )
  7.  
  8. func TestNewAttachAccept(t *testing.T) {
  9.     xMsg := TEmmAttachAccept{
  10.         ProtocolDiscriminator: PROTOCOL_DISCRIMINATOR_EPS_MOBILITY_MANAGEMENT_MESSAGES,
  11.         SecurityHeaderType:    NAS_SECURITY_PLAIN_NAS_MESSAGE,
  12.         MessageType:           NAS_EMM_MESSAGE_TYPE_ATTACH_ACCEPT,
  13.         EpsAttachResult:       NAS_EPS_ATTACH_RESULT_COMBINED_EPS_IMSI_ATTACH,
  14.         Spare:                 0,
  15.         Timer3412value:        0x49,
  16.         //TaiList:               []byte{0x2, 0x52, 0xf0, 0x99, 0x8e, 0x58, 0x8d, 0xf4, 0x8d, 0x2c},
  17.         TaiList: TIeTaiList{
  18.             taiList: []tTai{
  19.                 {
  20.                     plmn: []byte{0x52, 0xf0, 0x99},
  21.                     tac:  0x8e58,
  22.                 },
  23.                 {
  24.                     plmn: []byte{0x52, 0xf0, 0x99},
  25.                     tac:  0x8df4,
  26.                 },
  27.                 {
  28.                     plmn: []byte{0x52, 0xf0, 0x99},
  29.                     tac:  0x8d2c,
  30.                 },
  31.             },
  32.         },
  33.         EsmMessageContainer: []byte{0x52, 0x1, 0xc1, 0x1, 0x9, 0x27, 0x8, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e,
  34.             0x65, 0x74, 0x7, 0x62, 0x65, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x2, 0x72, 0x75, 0x6, 0x6d, 0x6e, 0x63, 0x30,
  35.             0x39, 0x39, 0x6, 0x6d, 0x63, 0x63, 0x32, 0x35, 0x30, 0x4, 0x67, 0x70, 0x72, 0x73, 0x5, 0x1, 0xa, 0x46, 0xda,
  36.             0x23, 0x5d, 0x1, 0x0, 0x30, 0x10, 0x23, 0x92, 0x1f, 0x91, 0x97, 0xfe, 0xfe, 0x46, 0x48, 0x0, 0x0, 0x0, 0xfa,
  37.             0x0, 0xde, 0x0, 0x32, 0x3, 0x82, 0x5e, 0x6, 0xfe, 0xfe, 0x96, 0xde, 0x2, 0x0, 0x58, 0x32, 0x27, 0x28, 0x80,
  38.             0x80, 0x21, 0xa, 0x3, 0x0, 0x0, 0xa, 0x81, 0x6, 0x55, 0xf9, 0x16, 0xf8, 0x0, 0xd, 0x4, 0x55, 0xf9, 0x16,
  39.             0xf8, 0x0, 0x3, 0x10, 0x20, 0x1, 0x48, 0x60, 0x48, 0x60, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x88, 0x88},
  40.         Guti:                       &[]byte{0xf6, 0x52, 0xf0, 0x99, 0x80, 0x3, 0xc8, 0xc2, 0x1, 0xca, 0x19},
  41.         LocationAreaIdentification: &[]byte{0x52, 0xf0, 0x99, 0xa5, 0x0},
  42.         MsIdentity:                 &[]byte{0xf4, 0x6d, 0x50, 0xc0, 0x15},
  43.         EmmCause:                   nil,
  44.         Timer3402:                  &[]byte{0x2c},
  45.         Timer3423:                  &[]byte{0x2c},
  46.         EquivalentPLMNs:            nil,
  47.         EmergencyNumberList:        nil,
  48.         EpsNetworkFeature:          &[]byte{0x01},
  49.         AdditionalUpdateResults:    &[]byte{0},
  50.     }
  51.     a, err := MarshalNasPdu(&xMsg)
  52.     if err != nil {
  53.         t.Error(err)
  54.     }
  55.     nas, err := NewNAS(a, nil, nil, DIRECTION_DOWNLINK)
  56.     if err != nil {
  57.         t.Error(err)
  58.     }
  59.     var mt TNAS_MESSAGE_TYPE
  60.     if mt, err = nas.Type(); err != nil {
  61.         t.Error(err)
  62.     }
  63.     if mt != NAS_EMM_MESSAGE_TYPE_ATTACH_ACCEPT {
  64.         t.Errorf("Wrong MessageType, expected %d but %d found", NAS_EMM_MESSAGE_TYPE_ATTACH_ACCEPT, mt)
  65.     }
  66.     var msg *TEmmAttachAccept
  67.     var ok bool
  68.     if msg, ok = nas.NasMsg.(*TEmmAttachAccept); !ok {
  69.         t.Error("NasMsg is not a TEmmAttachAccept but a must")
  70.     }
  71.     if msg == nil {
  72.         t.Fatalf("msg is nil")
  73.     }
  74.     if bytes.Compare(msg.EsmMessageContainer, xMsg.EsmMessageContainer) != 0 {
  75.         t.Error("Wrong EsmMessageContainer")
  76.     }
  77.     if msg.ProtocolDiscriminator != xMsg.ProtocolDiscriminator {
  78.         t.Error("Wrong ProtocolDiscriminator")
  79.     }
  80.     if msg.SecurityHeaderType != xMsg.SecurityHeaderType {
  81.         t.Error("Wrong SecurityHeaderType")
  82.     }
  83.     if msg.MessageType != xMsg.MessageType {
  84.         t.Error("Wrong MessageType")
  85.     }
  86.     if msg.EpsAttachResult != xMsg.EpsAttachResult {
  87.         t.Error("Wrong EpsAttachResult")
  88.     }
  89.     if msg.Timer3412value != xMsg.Timer3412value {
  90.         t.Error("Wrong Timer3412value")
  91.     }
  92.     if bytes.Compare(*msg.Guti, *xMsg.Guti) != 0 {
  93.         t.Error("Wrong Guti")
  94.     }
  95.     if bytes.Compare(*msg.LocationAreaIdentification, *xMsg.LocationAreaIdentification) != 0 {
  96.         t.Error("Wrong LocationAreaIdentification")
  97.     }
  98.     if bytes.Compare(*msg.MsIdentity, *xMsg.MsIdentity) != 0 {
  99.         t.Error("Wrong MsIdentity")
  100.     }
  101.     if msg.EmmCause != xMsg.EmmCause {
  102.         t.Error("Wrong EmmCause")
  103.     }
  104.     if bytes.Compare(*msg.Timer3402, *xMsg.Timer3402) != 0 {
  105.         t.Error("Wrong Timer3402")
  106.     }
  107.     if bytes.Compare(*msg.Timer3423, *xMsg.Timer3423) != 0 {
  108.         t.Error("Wrong Timer3423")
  109.     }
  110.     if bytes.Compare(*msg.EpsNetworkFeature, *xMsg.EpsNetworkFeature) != 0 {
  111.         t.Error("Wrong EpsNetworkFeature")
  112.     }
  113.     if bytes.Compare(*msg.AdditionalUpdateResults, *xMsg.AdditionalUpdateResults) != 0 {
  114.         t.Error("Wrong AdditionalUpdateResults")
  115.     }
  116.     if len(msg.TaiList.taiList) != len(xMsg.TaiList.taiList) {
  117.         t.Error("Length of taiList should be the same!")
  118.     }
  119. }
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement