/// <summary> /// 该方法调用其他方法解析一条s1ap报文中的cause及信令名称,id pair /// </summary> /// <param name="s1ap">s1ap报文</param> public void s1apIeDec(byte[] s1ap) { str1 = s1ap_name1.s1ap_decode1(s1ap); MmeUeS1apId = id1.s1ap_id(s1ap); LengthMme = id1.Length; indexMme = id1.Index; EnbUeS1apId = id2.s1ap_id(s1ap); LengthEnb = id2.Length; IndexEnb = id2.Index; cause1.decodeCause(s1ap); str2 = cause1.str1; //cause类型 str3 = cause1.str2; //cause名称 IndexCause = cause1.Index; LengthCause = cause1.Length; }
public int LengthS1ap = 0; //指示nas前面的s1ap的长度 /// <summary> /// 该方法将输入的E-rab modify request信令编码中截取nas编码 /// </summary> /// <param name="s1ap">s1ap信令编码</param> /// <returns>nas信令编码</returns> public byte[] nasIE(byte[] s1ap) { #region //变量声明 ushort tlength = 0; //s1ap信令的所有信元编码总长度 ushort slength = 0; //单个信元的编码长度 ushort listLength = 0; ushort itemLength = 0; ushort nasLength = 1; ushort nasLength1 = 0; ushort len1 = 0; //用于判定总长度所占字节的变量 ushort len2 = 0; //用于判定单个信元长度所占字节的变量 ushort len3 = 0; ushort len4 = 0; ushort id = 0; byte Gbr_or = 0; //用来判定e-rab level qos parameter中是否有GBR(16byte) List <byte> nas = new List <byte>(); byte[] nasShuzu = new byte[nasLength]; //用于接收nas的内容 #endregion s1ap_name dir = new s1ap_name(); dir.s1ap_decode1(s1ap);//获取信令的direction direction = (byte)dir.direction; len1 = s1ap[3];//用于判断当前信元的长度 if (len1 >= 128) { tlength = (ushort)((s1ap[3] & 0x0f) * 256 + s1ap[4]); } else { tlength = s1ap[3]; } if (tlength >= 128)//信令编码总长度大于128 { #region for (int i = 8; i < s1ap.Length;) { id = (ushort)(s1ap[i] * 256 + s1ap[i + 1]); if (id == 30) { #region len2 = s1ap[i + 3]; //用来判断list信元的长度 if (len2 >= 128) //list信元的长度大于128 { #region slength = (ushort)((s1ap[i + 3] & 0x0f) * 256 + s1ap[i + 4]); listLength = 2; //该信元长度域占2字节 len3 = s1ap[i + 9]; //用来判断item信元的长度 if (len3 >= 128) //item的长度 { #region itemLength = (ushort)((s1ap[i + 9] & 0x0f) * 256 + s1ap[i + 10]); Gbr_or = s1ap[i + 12];//该字节包含e-rab level qos parameter的标志位,若为80则,含有Gbr信元;若为00则不含GBR if (Gbr_or == 0x00) { #region len4 = s1ap[i + 15]; //用于判断nas长度 if (len4 >= 128) //nas长度 { nasLength = (ushort)((s1ap[i + 15] & 0x0f) * 256 + s1ap[i + 16]); nasLength1 = 2;//nas 长度域所占字节 byte[] b1 = new byte[nasLength]; Array.Copy(s1ap, i + 17, b1, 0, nasLength); LengthS1ap = i + 17; nasShuzu = b1; break; } else//nas长度 { nasLength = len4; nasLength1 = 1; byte[] b1 = new byte[nasLength]; Array.Copy(s1ap, i + 16, b1, 0, nasLength); LengthS1ap = i + 16; nasShuzu = b1; break; } #endregion } else if (Gbr_or == 0x80)//该字节包含e-rab level qos parameter的标志位,若为80则,含有Gbr信元;若为00则不含GBR { #region int bitrate1_len = ((s1ap[i + 15] & 0x38) >> 3) + 2; int bitrate2_len = ((s1ap[i + 15 + bitrate1_len] & 0xe0) >> 5) + 2; int bitrate3_len = ((s1ap[i + 15 + bitrate1_len + bitrate2_len] & 0xe0) >> 5) + 2; int bitrate4_len = ((s1ap[i + 15 + bitrate1_len + bitrate2_len + bitrate3_len] & 0xe0) >> 5) + 2; int bitrate_len = bitrate1_len + bitrate2_len + bitrate3_len + bitrate4_len; len4 = s1ap[i + 15 + bitrate_len]; //用于判断nas长度,GBR占16字节 if (len4 >= 128) //nas长度 { nasLength = (ushort)((s1ap[i + 15 + bitrate_len] & 0x0f) * 256 + s1ap[i + 16 + bitrate_len]); nasLength1 = 2;//nas 长度域所占字节 byte[] b1 = new byte[nasLength]; Array.Copy(s1ap, i + 17 + bitrate_len, b1, 0, nasLength); LengthS1ap = i + 17 + bitrate_len; nasShuzu = b1; break; } else//nas长度 { nasLength = len4; byte[] b1 = new byte[nasLength]; Array.Copy(s1ap, i + 16 + bitrate_len, b1, 0, nasLength); nasShuzu = b1; LengthS1ap = i + 16 + bitrate_len; break; } #endregion } #endregion } else//item的长度小于128 { #region Gbr_or = s1ap[i + 11]; if (Gbr_or == 0x80) { int bitrate1_len = ((s1ap[i + 14] & 0x38) >> 3) + 2; int bitrate2_len = ((s1ap[i + 14 + bitrate1_len] & 0xe0) >> 5) + 2; int bitrate3_len = ((s1ap[i + 14 + bitrate1_len + bitrate2_len] & 0xe0) >> 5) + 2; int bitrate4_len = ((s1ap[i + 14 + bitrate1_len + bitrate2_len + bitrate3_len] & 0xe0) >> 5) + 2; int bitrate_len = bitrate1_len + bitrate2_len + bitrate3_len + bitrate4_len; len4 = s1ap[i + 14 + bitrate_len];//用于判断nas长度,GBR占16字节 nasLength = s1ap[i + 14 + bitrate_len]; byte[] b1 = new byte[nasLength]; Array.Copy(s1ap, i + 15 + bitrate_len, b1, 0, nasLength); nasShuzu = b1; LengthS1ap = i + 15 + bitrate_len; break; } else if (Gbr_or == 0x00) { nasLength = s1ap[i + 14]; byte[] b1 = new byte[nasLength]; Array.Copy(s1ap, i + 15, b1, 0, nasLength); nasShuzu = b1; LengthS1ap = i + 15; break; } #endregion } #endregion } else//list的长度小于128 { #region Gbr_or = s1ap[i + 10]; if (Gbr_or == 0x80) { int bitrate1_len = ((s1ap[i + 13] & 0x38) >> 3) + 2; int bitrate2_len = ((s1ap[i + 13 + bitrate1_len] & 0xe0) >> 5) + 2; int bitrate3_len = ((s1ap[i + 13 + bitrate1_len + bitrate2_len] & 0xe0) >> 5) + 2; int bitrate4_len = ((s1ap[i + 13 + bitrate1_len + bitrate2_len + bitrate3_len] & 0xe0) >> 5) + 2; int bitrate_len = bitrate1_len + bitrate2_len + bitrate3_len + bitrate4_len; nasLength = s1ap[i + 13 + bitrate_len]; byte[] b1 = new byte[nasLength]; Array.Copy(s1ap, i + 14 + bitrate_len, b1, 0, nasLength); nasShuzu = b1; LengthS1ap = i + 14 + bitrate_len; break; } else if (Gbr_or == 0x00) { nasLength = s1ap[i + 13]; byte[] b1 = new byte[nasLength]; Array.Copy(s1ap, i + 14, b1, 0, nasLength); nasShuzu = b1; LengthS1ap = i + 14; break; } #endregion } #endregion } else//id !=30 { #region slength = s1ap[i + 3]; if (slength < 128) { i = (ushort)(i + slength + 4); } else { slength = (ushort)((s1ap[i + 3] & 0x0f) * 256 + s1ap[i + 4]); i = (ushort)(i + slength + 5);//当信元的编码长度超过128时,则长度域的编码为0x80yy(2个字节),且yy才是实际的编码长度 } #endregion } } #endregion } else//tlength < 128 { #region for (int i = 7; i < s1ap.Length;) { id = (ushort)(s1ap[i] * 256 + s1ap[i + 1]); slength = s1ap[i + 3]; if (id == 30) { #region listLength = 1;//该信元长度域占1字节 Gbr_or = s1ap[i + 10]; if (Gbr_or == 0x80) { int bitrate1_len = ((s1ap[i + 13] & 0x38) >> 3) + 2; int bitrate2_len = ((s1ap[i + 13 + bitrate1_len] & 0xe0) >> 5) + 2; int bitrate3_len = ((s1ap[i + 13 + bitrate1_len + bitrate2_len] & 0xe0) >> 5) + 2; int bitrate4_len = ((s1ap[i + 13 + bitrate1_len + bitrate2_len + bitrate3_len] & 0xe0) >> 5) + 2; int bitrate_len = bitrate1_len + bitrate2_len + bitrate3_len + bitrate4_len; nasLength = s1ap[i + 13 + bitrate_len]; byte[] b1 = new byte[nasLength]; Array.Copy(s1ap, i + 14 + bitrate_len, b1, 0, nasLength); nasShuzu = b1; LengthS1ap = i + 14 + bitrate_len; break;//找到该信元以后,解析之后直接跳出循环 } else if (Gbr_or == 0x00) { nasLength = s1ap[i + 13]; byte[] b1 = new byte[nasLength]; Array.Copy(s1ap, i + 14, b1, 0, nasLength); nasShuzu = b1; LengthS1ap = i + 14; break;//找到该信元以后,解析之后直接跳出循环 } #endregion } if (id != 30) { i = (ushort)(i + slength + 4); } } #endregion } return(nasShuzu); }
public byte direction = 1; //E-rab setuo request的方向是 public byte[] setup_list(byte[] a) { ushort tlength = 0; //s1ap信令的所有信元编码总长度 ushort slength = 0; //单个信元的编码长度 ushort listLength = 0; ushort itemLength = 0; ushort itemLength1 = 0; ushort nasLength = 1; ushort nasLength1 = 0; ushort len1 = 0; //用于判定总长度所占字节的变量 ushort len2 = 0; //用于判定单个信元长度所占字节的变量 ushort len3 = 0; ushort len4 = 0; ushort id = 0; byte Gbr_or = 0;//用来判定e-rab level qos parameter中是否有GBR(16byte) byte[] nasShuzu = new byte[nasLength]; s1ap_name dir = new s1ap_name(); dir.s1ap_decode1(a);//获取信令的direction direction = (byte)dir.direction; len1 = a[3];//用于判断当前信元的长度 if (len1 >= 128) { tlength = (ushort)((a[3] & 0x0f) * 256 + a[4]); } else { tlength = a[3]; } if (tlength >= 128)//信令编码总长度大于128 { for (int i = 8; i < a.Length;) { id = (ushort)(a[i] * 256 + a[i + 1]); if (id == 16) { #region len2 = a[i + 3]; //用来判断list信元的长度 if (len2 >= 128) //list的长度大于128 { #region slength = (ushort)((a[i + 3] & 0x0f) * 256 + a[i + 4]); listLength = 2; //该信元长度域占2字节 len3 = a[i + 9]; //用来判断item信元的长度 if (len3 >= 128) //item的长度 { #region itemLength = (ushort)((a[i + 9] & 0x0f) * 256 + a[i + 10]); Gbr_or = a[i + 12];//该字节包含e-rab level qos parameter的标志位,若为80则,含有Gbr信元;若为00则不含GBR if (Gbr_or == 0x00) { #region len4 = a[i + 25]; //用于判断nas长度 if (len4 >= 128) //nas长度 { nasLength = (ushort)((a[i + 25] & 0x0f) * 256 + a[i + 26]); nasLength1 = 2;//nas 长度域所占字节 byte[] b1 = new byte[nasLength]; Array.Copy(a, i + 27, b1, 0, nasLength); nasShuzu = b1; LengthS1ap = i + 27; break; } else//nas长度 { nasLength = len4; nasLength1 = 1; byte[] b1 = new byte[nasLength]; Array.Copy(a, i + 26, b1, 0, nasLength); nasShuzu = b1; LengthS1ap = i + 26; break; } #endregion } else if (Gbr_or == 0x80)//该字节包含e-rab level qos parameter的标志位,若为80则,含有Gbr信元;若为00则不含GBR { #region int bitrate1_len = ((a[i + 15] & 0x38) >> 3) + 2; //byte bitrate2 = a[i + 15 + bitrate1_len]; int bitrate2_len = ((a[i + 15 + bitrate1_len] & 0xe0) >> 5) + 2; //byte bitrate3 = a[i + 15 + bitrate1_len+bitrate2_len]; int bitrate3_len = ((a[i + 15 + bitrate1_len + bitrate2_len] & 0xe0) >> 5) + 2; //byte bitrate4 = a[i + 15 + bitrate1_len + bitrate2_len + bitrate3_len]; int bitrate4_len = ((a[i + 15 + bitrate1_len + bitrate2_len + bitrate3_len] & 0xe0) >> 5) + 2; int bitrate_len = bitrate1_len + bitrate2_len + bitrate3_len + bitrate4_len; len4 = a[i + 15 + bitrate_len + 10]; //用于判断nas长度,GBR占16字节 if (len4 >= 128) //nas长度 { nasLength = (ushort)((a[i + 15 + bitrate_len + 10] & 0x0f) * 256 + a[i + 15 + bitrate_len + 11]); nasLength1 = 2;//nas 长度域所占字节 byte[] b1 = new byte[nasLength]; Array.Copy(a, i + 15 + bitrate_len + 12, b1, 0, nasLength); nasShuzu = b1; LengthS1ap = i + 15 + bitrate_len + 12; break; } else//nas长度 { nasLength = len4; byte[] b1 = new byte[nasLength]; Array.Copy(a, i + 15 + bitrate_len + 11, b1, 0, nasLength); nasShuzu = b1; LengthS1ap = i + 15 + bitrate_len + 11; break; } #endregion } #endregion } else//item的长度小于128 { #region Gbr_or = a[i + 11]; if (Gbr_or == 0x80) { int bitrate1_len = ((a[i + 14] & 0x38) >> 3) + 2; int bitrate2_len = ((a[i + 14 + bitrate1_len] & 0xe0) >> 5) + 2; int bitrate3_len = ((a[i + 14 + bitrate1_len + bitrate2_len] & 0xe0) >> 5) + 2; int bitrate4_len = ((a[i + 14 + bitrate1_len + bitrate2_len + bitrate3_len] & 0xe0) >> 5) + 2; int bitrate_len = bitrate1_len + bitrate2_len + bitrate3_len + bitrate4_len; len4 = a[i + 14 + bitrate_len + 10];//用于判断nas长度,GBR占16字节 nasLength = a[i + 14 + bitrate_len + 10]; byte[] b1 = new byte[nasLength]; Array.Copy(a, i + 14 + bitrate_len + 11, b1, 0, nasLength); LengthS1ap = i + 14 + bitrate_len + 11; nasShuzu = b1; break; } else if (Gbr_or == 0x00) { nasLength = a[i + 24]; byte[] b1 = new byte[nasLength]; Array.Copy(a, i + 25, b1, 0, nasLength); nasShuzu = b1; LengthS1ap = i + 25; break; } #endregion } #endregion } else//list的长度小于128 { #region Gbr_or = a[i + 10]; if (Gbr_or == 0x80) { int bitrate1_len = ((a[i + 13] & 0x38) >> 3) + 2; int bitrate2_len = ((a[i + 13 + bitrate1_len] & 0xe0) >> 5) + 2; int bitrate3_len = ((a[i + 13 + bitrate1_len + bitrate2_len] & 0xe0) >> 5) + 2; int bitrate4_len = ((a[i + 13 + bitrate1_len + bitrate2_len + bitrate3_len] & 0xe0) >> 5) + 2; int bitrate_len = bitrate1_len + bitrate2_len + bitrate3_len + bitrate4_len; nasLength = a[i + 13 + bitrate_len + 10]; byte[] b1 = new byte[nasLength]; Array.Copy(a, i + 13 + bitrate_len + 11, b1, 0, nasLength); nasShuzu = b1; LengthS1ap = i + 13 + bitrate_len + 11; break; } else if (Gbr_or == 0x00) { nasLength = a[i + 23]; byte[] b1 = new byte[nasLength]; Array.Copy(a, i + 24, b1, 0, nasLength); nasShuzu = b1; LengthS1ap = i + 24; break; } #endregion } #endregion } if (id != 16) { #region slength = a[i + 3]; if (slength < 128) { i = (ushort)(i + slength + 4); } else { i = (ushort)(i + slength + 5);//当信元的编码长度超过128时,则长度域的编码为0x80yy(2个字节),且yy才是实际的编码长度 } #endregion } } } if (tlength < 128) { #region for (int i = 7; i < a.Length;) { id = (ushort)(a[i] * 256 + a[i + 1]); slength = a[i + 3]; if (id == 16) { #region listLength = 1;//该信元长度域占1字节 Gbr_or = a[i + 10]; if (Gbr_or == 0x80) { int bitrate1_len = ((a[i + 13] & 0x38) >> 3) + 2; int bitrate2_len = ((a[i + 13 + bitrate1_len] & 0xe0) >> 5) + 2; int bitrate3_len = ((a[i + 13 + bitrate1_len + bitrate2_len] & 0xe0) >> 5) + 2; int bitrate4_len = ((a[i + 13 + bitrate1_len + bitrate2_len + bitrate3_len] & 0xe0) >> 5) + 2; int bitrate_len = bitrate1_len + bitrate2_len + bitrate3_len + bitrate4_len; nasLength = a[i + 13 + bitrate_len + 10]; byte[] b1 = new byte[nasLength]; Array.Copy(a, i + 13 + bitrate_len + 11, b1, 0, nasLength); LengthS1ap = i + 13 + bitrate_len + 11; nasShuzu = b1; break;//找到该信元以后,解析之后直接跳出循环 } else if (Gbr_or == 0x00) { nasLength = a[i + 23]; byte[] b1 = new byte[nasLength]; Array.Copy(a, i + 24, b1, 0, nasLength); LengthS1ap = i + 24; nasShuzu = b1; break;//找到该信元以后,解析之后直接跳出循环 } #endregion } if (id != 16) { i = (ushort)(i + slength + 4); } } #endregion } return(nasShuzu); }
public int LengthS1ap = 0;//指示nas前面的s1ap的长度 /// <summary> /// 该方法将从含有nas信令的s1ap信令编码中取出nas编码 /// </summary> /// <param name="s1ap">s1ap信令编码</param> /// <returns>nas编码</returns> public byte[] nasShuzu(byte[] s1ap) { ushort tlength = 0; //s1ap信令的所有信元编码总长度 ushort slength = 0; //单个信元的编码长度 ushort len1 = 0; //用于判定总长度所占字节的变量 ushort len2 = 0; //用于判定单个信元长度所占字节的变量 ushort id = 0; //用于表示信元的类型 byte headLength = 0, headLength1 = 0; byte[] Nasshuzu = new byte[1]; //用于接收解析出的nas数据流(注意:使用此种数组时一定要考虑所有情况中都需要将其初始化,否则就会出现“未初始化的数组”) s1ap_name dir = new s1ap_name(); //用来获得direction dir.s1ap_decode1(s1ap); //获取信令的direction direction = (byte)dir.direction; len1 = s1ap[3]; if (len1 >= 128)//s1ap编码总长度超过128,则长度编码为2字节 { tlength = (ushort)((s1ap[3] & 0x0f) * 256 + s1ap[4]); headLength = 8;//一条s1ap消息的头部长度 } else { tlength = s1ap[3]; headLength = 7; } byte[] b = new byte[s1ap.Length - headLength]; Array.Copy(s1ap, headLength, b, 0, b.Length); if (tlength >= 128) { #region for (int i = 0; (b.Length != 0) && (i < b.Length);) //每进行一次循环i都指向信元的首部 { id = (ushort)(b[i] * 256 + b[i + 1]); len2 = b[i + 3]; if (len2 >= 128) { slength = (ushort)((b[i + 3] & 0x0f) * 256 + b[i + 4]); headLength1 = 5;//表示一个信元的头部长度 } else { slength = b[i + 3]; headLength1 = 4; } if (id == 26)//该信元是NAS-pdu { LengthS1ap = headLength + i + 5; byte nasLength = 0; nasLength = b[i + 4]; byte[] nas_pdu = new byte[nasLength]; Array.Copy(b, 5 + i, nas_pdu, 0, nas_pdu.Length);//nas_pdu存放的数据是nas从headerType开始到nas结束的部分(即NAS-PDU除去type,临界,两个长度值的部分) Nasshuzu = nas_pdu; break; } else { i = (ushort)(i + slength + headLength1); } } #endregion } else//s1ap编码总长度不超过128,则长度编码为1字节 { #region for (int i = 0; (b.Length != 0) && (i < b.Length);) { id = (ushort)(b[i] * 256 + b[i + 1]); slength = b[i + 3]; if (id == 26)//假设NAS-PDU的长度不超过128 { LengthS1ap = headLength + i + 5; byte nasLength = 0; nasLength = b[i + 4]; byte[] nas_pdu = new byte[nasLength]; Array.Copy(b, i + 5, nas_pdu, 0, nas_pdu.Length);//nas_pdu存放的数据是nas从headerType开始到nas结束的部分(即NAS-PDU除去type,临界,两个长度值的部分) Nasshuzu = nas_pdu; break; } else { i = (ushort)(i + slength + 4); } } #endregion } return(Nasshuzu); }