Last active
January 2, 2024 11:39
-
-
Save Arathi/ac3e5cb79ee321a9f72251f090286e73 to your computer and use it in GitHub Desktop.
Wireshark CMPP 2.0 协议插件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
---------------- | |
-- 报文结构定义 | |
---------------- | |
CMPPv2_Field_Protos = { | |
Command_Name = { | |
[0x00000001] = "CMPP_CONNECT", | |
[0x80000001] = "CMPP_CONNECT_RESP", | |
[0x00000002] = "CMPP_TERMINATE", | |
[0x80000002] = "CMPP_TERMINATE_RESP", | |
[0x00000004] = "CMPP_SUBMIT", | |
[0x80000004] = "CMPP_SUBMIT_RESP", | |
[0x00000005] = "CMPP_DELIVER", | |
[0x80000005] = "CMPP_DELIVER_RESP", | |
[0x00000006] = "CMPP_QUERY", | |
[0x80000006] = "CMPP_QUERY_RESP", | |
[0x00000007] = "CMPP_CANCEL", | |
[0x80000007] = "CMPP_CANCEL_RESP", | |
[0x00000008] = "CMPP_ACTIVE_TEST", | |
[0x80000008] = "CMPP_ACTIVE_TEST_RESP" | |
}; | |
Submit_Result = { | |
[0] = "正确", | |
[1] = "消息结构错", | |
[2] = "命令字错", | |
[3] = "消息序号重复", | |
[4] = "消息长度错", | |
[5] = "资费代码错", | |
[6] = "超过最大信息长", | |
[7] = "业务代码错", | |
[8] = "流量控制错", | |
[9] = "其他错误" | |
}; | |
Deliver_Type = { | |
[0] = "上行短信", | |
[1] = "状态报告" | |
}; | |
Message_Format = { | |
[0] = "ASCII串", | |
[3] = "短信写卡操作", | |
[4] = "二进制信息", | |
[8] = "UCS2编码", | |
[15] = "GBK编码" | |
}; | |
Version_Name = { | |
[0x20] = "v2.0", | |
[0x30] = "v3.0" | |
}; | |
}; | |
CMPPv2_MsgDef={ | |
CMPPv2_CONNECT={ | |
[1]={ Name="Source_Addr", Length=6, Type="String", DisplayType="Normal", Abbr="source_addr", Display=true }; | |
[2]={ Name="AuthenticatorSource",Length=16, Type="RAW", DisplayType="Normal", Abbr="authenticator_source", Display=true }; | |
[3]={ Name="Version", Length=1, Type="Version", DisplayType="Version_Name", Abbr="version", Display=true }; | |
[4]={ Name="TimeStamp", Length=4, Type="Integer", DisplayType="Normal", Abbr="timestamp", Display=true }; | |
}; | |
CMPPv2_CONNECT_RESP={ | |
[1]={ Name="Status", Length=1, Type="Integer", DisplayType="Status", Abbr="status", Display=true, }; | |
[2]={ Name="AuthenticatorISMG",Length=16, Type="RAW", DisplayType="Normal", Abbr="authenticator_ismg", Display=true, }; | |
[3]={ Name="Version", Length=1, Type="Version", DisplayType="Version_Name", Abbr="version", Display=true, }; | |
}; | |
CMPPv2_SUBMIT={ | |
[1]={ Name="Msg_Id", Length=8, Type="Integer", DisplayType="Normal", Abbr="msg_id", Display=true }; | |
[2]={ Name="Pk_total", Length=1, Type="Integer", DisplayType="Normal", Abbr="pk_total", Display=true }; | |
[3]={ Name="Pk_number", Length=1, Type="Integer", DisplayType="Normal", Abbr="pk_number", Display=true }; | |
[4]={ Name="Registered_Delivery", Length=1, Type="Integer", DisplayType="Normal", Abbr="registered_delivery", Display=true }; | |
[5]={ Name="Msg_level", Length=1, Type="Integer", DisplayType="Normal", Abbr="msg_level", Display=true }; | |
[6]={ Name="Service_Id", Length=10, Type="String", DisplayType="Normal", Abbr="service_id", Display=true }; | |
[7]={ Name="Fee_UserType", Length=1, Type="Integer", DisplayType="Normal", Abbr="fee_usertype", Display=true }; | |
[8]={ Name="Fee_terminal_Id", Length=21, Type="String", DisplayType="Normal", Abbr="fee_terminal_id", Display=true }; | |
[9]={ Name="TP_pId", Length=1, Type="Integer", DisplayType="Normal", Abbr="tp_pid", Display=true }; | |
[10]={ Name="TP_udhi", Length=1, Type="Integer", DisplayType="Normal", Abbr="tp_udhi", Display=true }; | |
[11]={ Name="Msg_Fmt", Length=1, Type="Integer", DisplayType="Message_Format", Abbr="msg_fmt", Display=true }; | |
[12]={ Name="Msg_src", Length=6, Type="String", DisplayType="Normal", Abbr="msg_src", Display=true }; | |
[13]={ Name="FeeType", Length=2, Type="String", DisplayType="Normal", Abbr="fee_type", Display=true }; | |
[14]={ Name="FeeCode", Length=6, Type="String", DisplayType="Normal", Abbr="fee_code", Display=true }; | |
[15]={ Name="Valid_Time", Length=17, Type="String", DisplayType="Normal", Abbr="valid_time", Display=true }; | |
[16]={ Name="At_Time", Length=17, Type="String", DisplayType="Normal", Abbr="at_time", Display=true }; | |
[17]={ Name="Src_Id", Length=21, Type="String", DisplayType="Normal", Abbr="src_id", Display=true }; | |
[18]={ Name="DestUsr_tl", Length=1, Type="Integer", DisplayType="Normal", Abbr="dest_user_tl", Display=true }; | |
[19]={ Name="Dest_terminal_Id", Length=0, Type="String", DisplayType="Normal", Abbr="dest_terminal_id", Display=true }; | |
[20]={ Name="Msg_Length", Length=1, Type="Integer", DisplayType="Normal", Abbr="msg_length", Display=true }; | |
[21]={ Name="Msg_Content", Length=0, Type="String", DisplayType="Normal", Abbr="msg_content", Display=true }; | |
[22]={ Name="Reserve", Length=8, Type="RAW", DisplayType="Normal", Abbr="reserve", Display=false }; | |
}; | |
CMPPv2_SUBMIT_RESP={ | |
[1]={ Name="Msg_Id", Length=8, Type="Integer", DisplayType="Msg_Id", Abbr="msg_id", Display=true }; | |
[2]={ Name="Result", Length=1, Type="Integer", DisplayType="Submit_Result", Abbr="result", Display=true }; | |
}; | |
CMPPv2_DELIVER={ | |
[1]={ Name="Msg_Id", Length=8, Type="Integer", DisplayType="Normal", Abbr="msg_id", Display=true }; | |
[2]={ Name="Dest_Id", Length=21, Type="String", DisplayType="Normal", Abbr="dest_id", Display=true }; | |
[3]={ Name="Service_Id", Length=10, Type="String", DisplayType="Normal", Abbr="service_id", Display=true }; | |
[4]={ Name="TP_pId", Length=1, Type="Integer", DisplayType="Hex", Abbr="tp_pid", Display=true }; | |
[5]={ Name="TP_udhi", Length=1, Type="Integer", DisplayType="Hex", Abbr="tp_udhi", Display=true }; | |
[6]={ Name="Msg_Fmt", Length=1, Type="Integer", DisplayType="Message_Format", Abbr="msg_fmt", Display=true }; | |
[7]={ Name="Src_Terminal_Id", Length=21, Type="String", DisplayType="Normal", Abbr="src_id", Display=true }; | |
[8]={ Name="Registered_Delivery", Length=1, Type="Integer", DisplayType="Deliver_Type", Abbr="registered_delivery", Display=true }; | |
[9]={ Name="Msg_Length", Length=1, Type="Integer", DisplayType="Normal", Abbr="msg_length", Display=true }; | |
[10]={ Name="Msg_Content", Length=0, Type="String", DisplayType="Normal", Abbr="msg_content", Display=true }; | |
[11]={ Name="Reserve", Length=8, Type="RAW", DisplayType="Normal", Abbr="reserve", Display=false }; | |
}; | |
CMPPv2_DELIVER_RESP={ | |
[1]={ Name="Msg_Id", Length=8, Type="Integer", DisplayType="Msg_Id", Abbr="msg_id", Display=true }; | |
[2]={ Name="Result", Length=1, Type="Integer", DisplayType="Submit_Result", Abbr="result", Display=true }; | |
}; | |
CMPPv2_QUERY={ | |
[1]={ Name="Time", Length=8, Type="String", DisplayType="Normal", Abbr="time", Display=true }; | |
[2]={ Name="Query_Type", Length=1, Type="Integer", DisplayType="Normal", Abbr="query_type", Display=true }; | |
[3]={ Name="Query_Code", Length=10, Type="String", DisplayType="Normal", Abbr="query_code", Display=true }; | |
[4]={ Name="Reserve", Length=8, Type="Integer", DisplayType="Normal", Abbr="reserve", Display=true }; | |
}; | |
CMPPv2_QUERY_RESP={ | |
[1]={ Name="Time", Length=8, Type="String", DisplayType="Normal", Abbr="time", Display=true }; | |
[2]={ Name="Query_Type", Length=1, Type="Integer", DisplayType="Normal", Abbr="query_type", Display=true }; | |
[3]={ Name="Query_Code", Length=10, Type="String", DisplayType="Normal", Abbr="query_code", Display=true }; | |
[4]={ Name="MT_TLMsg", Length=4, Type="Integer", DisplayType="Normal", Abbr="mt_tl_msg", Display=true }; | |
[5]={ Name="MT_Tlusr", Length=4, Type="Integer", DisplayType="Normal", Abbr="mt_tl_usr", Display=true }; | |
[6]={ Name="MT_Scs", Length=4, Type="Integer", DisplayType="Normal", Abbr="mt_scs", Display=true }; | |
[7]={ Name="MT_WT", Length=4, Type="Integer", DisplayType="Normal", Abbr="mt_wt", Display=true }; | |
[8]={ Name="MT_FL", Length=4, Type="Integer", DisplayType="Normal", Abbr="mt_fl", Display=true }; | |
[9]={ Name="MO_Scs", Length=4, Type="Integer", DisplayType="Normal", Abbr="mo_scs", Display=true }; | |
[10]={ Name="MO_WT", Length=4, Type="Integer", DisplayType="Normal", Abbr="mo_wt", Display=true }; | |
[11]={ Name="MO_FL", Length=4, Type="Integer", DisplayType="Normal", Abbr="mo_fl", Display=true }; | |
}; | |
CMPPv2_CANCEL={ | |
[1]={ Name="Msg_Id", Length=8, Type="Integer", DisplayType="Normal", Abbr="msg_id", Display=true }; | |
}; | |
CMPPv2_CANCEL_RESP={ | |
[1]={ Name="Success_Id", Length=1, Type="Integer", DisplayType="Normal", Abbr="success", Display=true }; | |
}; | |
CMPPv2_ACTIVE_TEST_RESP={ | |
[1]={ Name="Reserved", Length=1, Type="RAW", DisplayType="Normal", Abbr="reserved", Display=true }; | |
}; | |
-- 30+ MsgId | |
CMPPv2_MSG_ID={ | |
[1]={ Name="Timestamp", Length=0, Type="String", DisplayType="Timestamp_26bits", Abbr="timestamp" }; | |
[2]={ Name="ISMG Code", Length=3, Type="Integer", DisplayType="Normal", Abbr="ismg_code" }; | |
[3]={ Name="Sequence", Length=2, Type="Integer", DisplayType="Normal", Abbr="sequence" }; | |
}; | |
-- 40+ 长短信协议头 | |
CMPPv2_LSMS_INFO={ | |
[0]={ Name="Long SMS Header", Length=0, Type="RAW", DisplayType="Normal", Abbr="lsms_header", Display=true }; | |
[1]={ Name="Unique_Id(8bits)", Length=1, Type="Integer", DisplayType="Normal", Abbr="unique_id", Display=true }; | |
[2]={ Name="Unique_Id(16bits)", Length=2, Type="Integer", DisplayType="Normal", Abbr="unique_id", Display=true }; | |
[3]={ Name="Long_Sms_Count", Length=1, Type="Integer", DisplayType="Normal", Abbr="lsms_count", Display=true }; | |
[4]={ Name="Long_Sms_Index", Length=1, Type="Integer", DisplayType="Normal", Abbr="lsms_index", Display=true }; | |
}; | |
-- 50+ 状态报告 | |
CMPPv2_REPORT_INFO={ | |
[0]={ Name="Detail Deliver Report", Length=7, Type="String", DisplayType="Normal", Abbr="report", Display=true }; | |
[1]={ Name="Submit_Msg_id", Length=8, Type="Integer", DisplayType="Normal", Abbr="submit_id", Display=true }; | |
[2]={ Name="Stat", Length=7, Type="String", DisplayType="Normal", Abbr="stat", Display=true }; | |
[3]={ Name="Submit_time", Length=10, Type="String", DisplayType="Normal", Abbr="submit_time", Display=true }; | |
[4]={ Name="Done_Time", Length=10, Type="String", DisplayType="Normal", Abbr="done_time", Display=true }; | |
[5]={ Name="Dest_terminal_Id", Length=21, Type="String", DisplayType="Normal", Abbr="dest_terminal_id", Display=true }; | |
[6]={ Name="SMSC_Sequence", Length=4, Type="Integer", DisplayType="Normal", Abbr="smsc_sequence", Display=true }; | |
}; | |
}; | |
function getCmppFields(prefix, def) | |
local pfdef = nil; | |
local _desc = nil; | |
local _base = base.DEC; | |
if (def.DisplayType == "Submit_Result") then | |
_desc = CMPPv2_Field_Protos.Submit_Result; | |
end | |
if (def.DisplayType == "Hex") then | |
_base = base.HEX; | |
end | |
if (def.DisplayType == "Message_Format") then | |
_desc = CMPPv2_Field_Protos.Message_Format; | |
end | |
if (def.DisplayType == "Deliver_Type") then | |
_desc = CMPPv2_Field_Protos.Deliver_Type; | |
end | |
if (def.DisplayType == "Version_Name") then | |
_desc = CMPPv2_Field_Protos.Version_Name; | |
_base = base.HEX; | |
end | |
if (def.Type == "Integer" and def.Length == 8) then | |
pfdef = ProtoField.uint64(prefix .. def.Abbr, def.Name, _base, _desc); | |
elseif (def.Type == "Integer" and def.Length == 4) then | |
pfdef = ProtoField.uint32(prefix .. def.Abbr, def.Name, _base, _desc); | |
elseif (def.Type == "Integer" and def.Length == 3) then | |
pfdef = ProtoField.uint24(prefix .. def.Abbr, def.Name, _base, _desc); | |
elseif (def.Type == "Integer" and def.Length == 2) then | |
pfdef = ProtoField.uint16(prefix .. def.Abbr, def.Name, _base, _desc); | |
elseif (def.Type == "Integer" and def.Length == 1) then | |
if (def.DisplayType == "Boolean") then | |
pfdef = ProtoField.bool(prefix .. def.Abbr, def.Name); | |
else | |
pfdef = ProtoField.uint8(prefix .. def.Abbr, def.Name, _base, _desc); | |
end | |
elseif (def.Type == "String") then | |
pfdef = ProtoField.string(prefix .. def.Abbr, def.Name, base.UNICODE); | |
elseif (def.Type == "RAW") then | |
pfdef = ProtoField.bytes(prefix .. def.Abbr, def.Name, base.SPACE); | |
else | |
pfdef = ProtoField.bytes(prefix .. def.Abbr, def.Name, base.SPACE); | |
end | |
return pfdef; | |
end | |
-- 协议注册 | |
CMPPv2_proto = Proto("cmppv2","CMPPv2 Protocol") | |
CMPPv2_CMPPv2_CONNECT = Proto("cmppv2.connect","CONNECT Request") | |
CMPPv2_CMPPv2_CONNECT_RESP = Proto("cmppv2.connect_resp","CONNECT Response") | |
CMPPv2_CMPPv2_TERMINATE = Proto("cmppv2.terminate","TERMINATE Request") | |
CMPPv2_CMPPv2_TERMINATE_RESP = Proto("cmppv2.terminate_resp","TERMINATE Response") | |
CMPPv2_CMPPv2_SUBMIT = Proto("cmppv2.submit","SUBMIT Request") | |
CMPPv2_CMPPv2_SUBMIT_RESP = Proto("cmppv2.submit_resp","SUBMIT Response") | |
CMPPv2_CMPPv2_DELIVER = Proto("cmppv2.deliver","DELIVER Request") | |
CMPPv2_CMPPv2_DELIVER_RESP = Proto("cmppv2.deliver_resp","DELIVER Response") | |
CMPPv2_CMPPv2_QUERY = Proto("cmppv2.query","QUERY Request") | |
CMPPv2_CMPPv2_QUERY_RESP = Proto("cmppv2.query_resp","QUERY Response") | |
CMPPv2_CMPPv2_CANCEL = Proto("cmppv2.cancel", "CANCEL Request") | |
CMPPv2_CMPPv2_CANCEL_RESP = Proto("cmppv2.cancel_resp", "CANCEL Response") | |
CMPPv2_CMPPv2_ACTIVE_TEST = Proto("cmppv2.active_test", "ACTIVE_TEST Request") | |
CMPPv2_CMPPv2_ACTIVE_TEST_RESP = Proto("cmppv2.active_test_resp", "ACTIVE_TEST Response") | |
---------------- | |
-- 协议字段定义 | |
---------------- | |
-- Header | |
pf=CMPPv2_proto.fields | |
pf.length=ProtoField.uint32("cmppv2.length","Total Length",base.DEC) | |
pf.cmd=ProtoField.uint32("cmppv2.cmd_id","Command ID",base.HEX,CMPPv2_Field_Protos.Command_Name) | |
pf.seq=ProtoField.uint32("cmppv2.seq","Seqence ID",base.DEC) | |
-- CONNECT | |
pf_connect=CMPPv2_CMPPv2_CONNECT.fields | |
for i=1, #CMPPv2_MsgDef.CMPPv2_CONNECT | |
do | |
pf_connect[i]=getCmppFields("cmppv2.connect.", CMPPv2_MsgDef.CMPPv2_CONNECT[i]) | |
end | |
-- CONNECT_RESP | |
pf_connect_resp = CMPPv2_CMPPv2_CONNECT_RESP.fields | |
for i=1, #CMPPv2_MsgDef.CMPPv2_CONNECT_RESP | |
do | |
pf_connect_resp[i]=getCmppFields("cmppv2.connect_resp.", CMPPv2_MsgDef.CMPPv2_CONNECT_RESP[i]) | |
end | |
-- TERMINATE 与 TERMINATE_RESP 没有消息体 | |
-- SUBMIT | |
pf_submit = CMPPv2_CMPPv2_SUBMIT.fields | |
for i=1, 22 | |
do | |
pf_submit[i]=getCmppFields("cmppv2.submit.", CMPPv2_MsgDef.CMPPv2_SUBMIT[i]) | |
end | |
-- pf_submit[21] = ProtoField.string("cmppv2.submit.msg_content", "Msg_Content(ASCII)", base.ASCII) | |
pf_submit[35] = ProtoField.string("cmppv2.submit.msg_content", "Msg_Content(UCS2)", base.UNICODE) | |
for i=1, #CMPPv2_MsgDef.CMPPv2_MSG_ID | |
do | |
pf_submit[30+i]=getCmppFields("cmppv2.submit.msg_id.", CMPPv2_MsgDef.CMPPv2_MSG_ID[i]) | |
end | |
for i=1, #CMPPv2_MsgDef.CMPPv2_LSMS_INFO | |
do | |
pf_submit[40+i]=getCmppFields("cmppv2.submit.", CMPPv2_MsgDef.CMPPv2_LSMS_INFO[i]) | |
end | |
-- SUBMIT_RESP | |
pf_submit_resp = CMPPv2_CMPPv2_SUBMIT_RESP.fields | |
for i=1, #CMPPv2_MsgDef.CMPPv2_SUBMIT_RESP | |
do | |
pf_submit_resp[i]=getCmppFields("cmppv2.submit_resp.", CMPPv2_MsgDef.CMPPv2_SUBMIT_RESP[i]) | |
end | |
for i=1, #CMPPv2_MsgDef.CMPPv2_MSG_ID | |
do | |
pf_submit_resp[30+i]=getCmppFields("cmppv2.submit_resp.msg_id.", CMPPv2_MsgDef.CMPPv2_MSG_ID[i]) | |
end | |
-- DELIVER | |
pf_deliver = CMPPv2_CMPPv2_DELIVER.fields | |
for i=1, 11 | |
do | |
pf_deliver[i]=getCmppFields("cmppv2.deliver.", CMPPv2_MsgDef.CMPPv2_DELIVER[i]) | |
end | |
-- pf_deliver[10] = ProtoField.string("cmppv2.deliver.msg_content", "Msg_Content(ASCII)", base.ASCII) | |
pf_deliver[35] = ProtoField.string("cmppv2.deliver.msg_content", "Msg_Content(UCS2)", base.UNICODE) | |
for i=1, #CMPPv2_MsgDef.CMPPv2_MSG_ID | |
do | |
pf_deliver[30+i]=getCmppFields("cmppv2.deliver.msg_id.", CMPPv2_MsgDef.CMPPv2_MSG_ID[i]) | |
end | |
for i=1, #CMPPv2_MsgDef.CMPPv2_LSMS_INFO | |
do | |
pf_deliver[40+i]=getCmppFields("cmppv2.deliver.", CMPPv2_MsgDef.CMPPv2_LSMS_INFO[i]) | |
end | |
for i=0, #CMPPv2_MsgDef.CMPPv2_REPORT_INFO | |
do | |
pf_deliver[50+i]=getCmppFields("cmppv2.deliver.", CMPPv2_MsgDef.CMPPv2_REPORT_INFO[i]) | |
end | |
-- DELIVER_RESP 结构同 SUBMIT_RESP | |
pf_deliver_resp=CMPPv2_CMPPv2_DELIVER_RESP.fields | |
for i=1, #CMPPv2_MsgDef.CMPPv2_DELIVER_RESP | |
do | |
pf_deliver_resp[i]=getCmppFields("cmppv2.deliver_resp.", CMPPv2_MsgDef.CMPPv2_DELIVER_RESP[i]) | |
end | |
for i=1, #CMPPv2_MsgDef.CMPPv2_MSG_ID | |
do | |
pf_deliver_resp[30+i]=getCmppFields("cmppv2.deliver_resp.msg_id.", CMPPv2_MsgDef.CMPPv2_MSG_ID[i]) | |
end | |
-- QUERY | |
pf_query = CMPPv2_CMPPv2_QUERY.fields | |
for i=1, #CMPPv2_MsgDef.CMPPv2_QUERY | |
do | |
pf_query[i]=getCmppFields("cmppv2.query.", CMPPv2_MsgDef.CMPPv2_QUERY[i]) | |
end | |
-- QUERY_RESP | |
pf_query_resp = CMPPv2_CMPPv2_QUERY_RESP.fields | |
for i=1, #CMPPv2_MsgDef.CMPPv2_QUERY_RESP | |
do | |
pf_query_resp[i]=getCmppFields("cmppv2.query_resp.", CMPPv2_MsgDef.CMPPv2_QUERY_RESP[i]) | |
end | |
-- CANCEL | |
pf_cancel = CMPPv2_CMPPv2_CANCEL.fields | |
for i=1, #CMPPv2_MsgDef.CMPPv2_QUERY | |
do | |
pf_cancel[i]=getCmppFields("cmppv2.cancel.", CMPPv2_MsgDef.CMPPv2_QUERY[i]) | |
end | |
for i=1, #CMPPv2_MsgDef.CMPPv2_MSG_ID | |
do | |
pf_cancel[30+i]=getCmppFields("cmppv2.cancel.msg_id.", CMPPv2_MsgDef.CMPPv2_MSG_ID[i]) | |
end | |
-- CANCEL_RESP | |
pf_cancel_resp = CMPPv2_CMPPv2_CANCEL_RESP.fields | |
for i=1, #CMPPv2_MsgDef.CMPPv2_CANCEL_RESP | |
do | |
pf_cancel_resp[i]=getCmppFields("cmppv2.cancel_resp.", CMPPv2_MsgDef.CMPPv2_CANCEL_RESP[i]) | |
end | |
-- ACTIVE_TEST 没有消息体 | |
-- ACTIVE_TEST_RESP 只有一个字节的消息体,而且没用 | |
pf_activetest_resp=CMPPv2_CMPPv2_ACTIVE_TEST_RESP.fields | |
pf_activetest_resp[1]=getCmppFields("cmppv2.activetest_resp.", CMPPv2_MsgDef.CMPPv2_ACTIVE_TEST_RESP[1]) | |
CMPPv2_HEADER_Length = 12 | |
--------------------------- | |
-- 定义各个协议的Dissector | |
--------------------------- | |
function CMPPv2_proto.dissector(tvb, pinfo, tree) | |
pinfo.cols.protocol = "CMPPv2" | |
pinfo.cols.info = "" | |
local offset=0 | |
-- TODO 循环读取,直到报文结束 | |
while (offset+CMPPv2_HEADER_Length < tvb:len()) | |
do | |
local length = tvb(offset,4):uint() | |
local buffer = tvb(offset, length) | |
main_dissector(buffer, pinfo, tree) | |
offset = offset + length | |
-- break | |
end | |
if (pinfo.cols.info == "") then | |
pinfo.cols.info = "CMPP data" | |
end | |
end | |
function main_dissector(buffer, pinfo, tree) | |
local subtree = tree:add(CMPPv2_proto, buffer(), "China Mobile Peer to Peer v2") | |
local headtree=subtree:add(CMPPv2_proto,buffer(0, CMPPv2_HEADER_Length), "Header") | |
local offset = 0 | |
headtree:add(pf.length, buffer(offset,4)) | |
offset=offset+4 | |
headtree:add(pf.cmd, buffer(offset,4)) | |
local cur_cmd=buffer(offset,4):uint(); | |
offset=offset+4 | |
headtree:add(pf.seq, buffer(offset,4)) | |
offset=offset+4 | |
local cmd4seek=cur_cmd | |
if cur_cmd == 0x80000001 then | |
cmd4seek = 0x00000801 | |
elseif cur_cmd == 0x80000002 then | |
cmd4seek = 0x00000802 | |
elseif cur_cmd == 0x80000003 then | |
cmd4seek = 0x00000803 | |
elseif cur_cmd == 0x80000004 then | |
cmd4seek = 0x00000804 | |
elseif cur_cmd == 0x80000005 then | |
cmd4seek = 0x00000805 | |
elseif cur_cmd == 0x80000006 then | |
cmd4seek = 0x00000806 | |
elseif cur_cmd == 0x80000007 then | |
cmd4seek = 0x00000807 | |
elseif cur_cmd== 0x80000008 then | |
cmd4seek = 0x00000808 | |
end | |
local body_dissector=cmppv2_cmd_table:get_dissector(cmd4seek) | |
body_dissector:call(buffer(offset):tvb(),pinfo,subtree) | |
end | |
function msg_id_dissector(proto, bodytree, buffer, current_index) | |
local msgid_tree = bodytree:add(proto[current_index], buffer) | |
local month = buffer:bitfield(0,4) | |
local day = buffer:bitfield(4,5) | |
local hour = buffer:bitfield(9,5) | |
local minute = buffer:bitfield(14,6) | |
local second = buffer:bitfield(20,6) | |
-- TODO Format Time MM-DD hh:mm:ss | |
local timestamp = month .. "-" .. day .. " " .. hour .. ":" .. minute .. ":" .. second | |
msgid_tree:add(proto[31], buffer(0,4), timestamp) | |
msgid_tree:add(proto[32], buffer(3,3), buffer:bitfield(26,22)) | |
msgid_tree:add(proto[33], buffer(6,2), buffer:bitfield(48,16)) | |
end | |
function long_sms_dissector(proto, bodytree, buffer) | |
local offset = 0 | |
-- local msgid_tree = bodytree:add() | |
return offset | |
end | |
function report_dissector(bodytree, buffer) | |
local report_tree = bodytree:add(pf_deliver[50], buffer, "") | |
local offset = 0 | |
local i | |
for i=51, 56 | |
do | |
local length = CMPPv2_MsgDef.CMPPv2_REPORT_INFO[i-50].Length | |
report_tree:add(pf_deliver[i], buffer(offset, length)) | |
offset = offset + length | |
end | |
return 0 | |
end | |
function CMPPv2_CMPPv2_CONNECT.dissector(bodybuffer, pinfo, tree) | |
Offset=0 | |
pinfo.cols.info = "CMPPv2_CONNECT. " | |
local bodytree = tree:add(CMPPv2_CMPPv2_CONNECT, bodybuffer(), "Connect") | |
local i = 0 | |
for i=1, #CMPPv2_MsgDef.CMPPv2_CONNECT | |
do | |
local length = CMPPv2_MsgDef.CMPPv2_CONNECT[i].Length | |
bodytree:add(pf_connect[i], bodybuffer(Offset, length)) | |
Offset = Offset + length | |
end | |
end | |
function CMPPv2_CMPPv2_CONNECT_RESP.dissector(bodybuffer, pinfo, tree) | |
Offset=0 | |
pinfo.cols.info = "CMPPv2_CONNECT_RESP. " | |
local bodytree = tree:add(CMPPv2_CMPPv2_CONNECT, bodybuffer(), "Connect Response") | |
for i=1, #CMPPv2_MsgDef.CMPPv2_CONNECT_RESP | |
do | |
local length = CMPPv2_MsgDef.CMPPv2_CONNECT_RESP[i].Length | |
bodytree:add(pf_connect_resp[i], bodybuffer(Offset, length)) | |
Offset = Offset + length | |
end | |
end | |
function CMPPv2_CMPPv2_TERMINATE.dissector(bodybuffer, pinfo, tree) | |
Offset=0 | |
pinfo.cols.info = pinfo.cols.info .. "CMPPv2_TERMINATE. " | |
end | |
function CMPPv2_CMPPv2_TERMINATE_RESP.dissector(bodybuffer, pinfo, tree) | |
Offset=0 | |
pinfo.cols.info = pinfo.cols.info .. "CMPPv2_TERMINATE_RESP. " | |
end | |
function CMPPv2_CMPPv2_SUBMIT.dissector(bodybuffer, pinfo, tree) | |
Offset=0 | |
pinfo.cols.info = "CMPPv2_SUBMIT. " | |
local tp_udhi = 0 -- 10 | |
local msg_fmt = 0 -- 11 | |
local tl_amount = 0 -- 18 | |
local msg_len = 0 -- 20 | |
local bodytree = tree:add(CMPPv2_CMPPv2_SUBMIT, bodybuffer(), "Submit") | |
msg_id_dissector(pf_submit, bodytree, bodybuffer(Offset, 8), 1) | |
Offset = Offset + 8 | |
local i = 0 | |
for i=2,18 | |
do | |
local length = CMPPv2_MsgDef.CMPPv2_SUBMIT[i].Length | |
bodytree:add(pf_submit[i], bodybuffer(Offset, length)) | |
if (i == 10) then | |
tp_udhi = bodybuffer(Offset, length):uint() | |
end | |
if (i == 11) then | |
msg_fmt = bodybuffer(Offset, length):uint() | |
end | |
if (i == 18) then | |
tl_amount = bodybuffer(Offset, length):uint() | |
end | |
Offset = Offset + length | |
end | |
-- 一般只有一条 | |
for i=1,tl_amount | |
do | |
bodytree:add(pf_submit[19], bodybuffer(Offset, 21)) | |
Offset = Offset + 21 | |
end | |
-- get message length | |
bodytree:add(pf_submit[20], bodybuffer(Offset, 1)) | |
msg_len = bodybuffer(Offset, 1):uint() | |
Offset = Offset + 1 | |
-- get protocol header | |
if (tp_udhi ~= 0) then | |
local left_byte_0 = bodybuffer(Offset, 1):uint() | |
Offset = Offset + 1 | |
local lsmsuid_len = bodybuffer(Offset, 1):uint() | |
Offset = Offset + 1 | |
local left_byte_2 = bodybuffer(Offset, 1):uint() | |
Offset = Offset + 1 | |
local lsmsuid = 0 | |
if (lsmsuid_len == 0) then | |
lsmsuid = bodybuffer(Offset, 1):uint() | |
bodytree:add(pf_submit[41], bodybuffer(Offset, 1)) | |
Offset = Offset + 1 | |
elseif (lsmsuid_len == 8) then | |
lsmsuid = bodybuffer(Offset, 2):uint() | |
bodytree:add(pf_submit[42], bodybuffer(Offset, 2)) | |
Offset = Offset + 2 | |
-- else | |
-- 非法报文 | |
end | |
local lsms_count = bodybuffer(Offset, 1):uint() | |
bodytree:add(pf_submit[43], bodybuffer(Offset, 1)) | |
Offset = Offset + 1 | |
local lsms_index = bodybuffer(Offset, 1):uint() | |
bodytree:add(pf_submit[44], bodybuffer(Offset, 1)) | |
Offset = Offset + 1 | |
msg_len = msg_len - left_byte_0 - 1 | |
end | |
-- get message content | |
local msg_content = nil | |
if (msg_fmt == 8) then | |
msg_content = bodybuffer(Offset, msg_len):ustring() | |
-- elseif (msg_fmt == 15) then | |
-- 暂时无法解决GBK编码转换 | |
-- msg_content = bodybuffer(Offset, msg_len):string() | |
else | |
msg_content = bodybuffer(Offset, msg_len):string() | |
end | |
bodytree:add(pf_submit[21], bodybuffer(Offset, msg_len), msg_content) | |
Offset = Offset + msg_len | |
-- Reserve | |
local reserve_buffer = bodybuffer(Offset, CMPPv2_MsgDef.CMPPv2_SUBMIT[22].Length) | |
bodytree:add(pf_submit[22], reserve_buffer, reserve_buffer:string()) | |
end | |
function CMPPv2_CMPPv2_SUBMIT_RESP.dissector(bodybuffer, pinfo, tree) | |
Offset=0 | |
pinfo.cols.info = "CMPPv2_SUBMIT_RESP. " | |
local bodytree = tree:add(CMPPv2_CMPPv2_SUBMIT_RESP, bodybuffer(), "Submit Response") | |
msg_id_dissector(pf_submit_resp, bodytree, bodybuffer(Offset, 8), 1) | |
Offset = Offset + 8 | |
local i = 0 | |
for i=2,#CMPPv2_MsgDef.CMPPv2_SUBMIT_RESP | |
do | |
bodytree:add(pf_submit_resp[i], bodybuffer(Offset, CMPPv2_MsgDef.CMPPv2_SUBMIT_RESP[i].Length)) | |
Offset = Offset + CMPPv2_MsgDef.CMPPv2_SUBMIT_RESP[i].Length | |
end | |
end | |
function CMPPv2_CMPPv2_DELIVER.dissector(bodybuffer, pinfo, tree) | |
Offset=0 | |
pinfo.cols.info = "CMPPv2_DELIVER. " | |
local msg_fmt = 0 | |
local deliver_type = 0 | |
local msg_len = 0 | |
local tp_udhi = 0 | |
local bodytree = tree:add(CMPPv2_CMPPv2_DELIVER, bodybuffer(), "Deliver Request") | |
msg_id_dissector(pf_deliver, bodytree, bodybuffer(Offset, 8), 1) | |
Offset = Offset + 8 | |
local i = 0 | |
for i=2,9 | |
do | |
local length = CMPPv2_MsgDef.CMPPv2_DELIVER[i].Length | |
bodytree:add(pf_deliver[i], bodybuffer(Offset, length)) | |
if (i == 5) then | |
tp_udhi = bodybuffer(Offset, length):uint() | |
end | |
if (i == 6) then | |
msg_fmt = bodybuffer(Offset, length):uint() | |
end | |
if (i == 8) then | |
deliver_type = bodybuffer(Offset, length):uint() | |
end | |
if (i == 9) then | |
msg_len = bodybuffer(Offset, length):uint() | |
end | |
Offset = Offset + length | |
end | |
-- msg_content | |
if (deliver_type == 0) then | |
-- get protocol header | |
if (tp_udhi ~= 0) then | |
local left_byte_0 = bodybuffer(Offset, 1):uint() | |
Offset = Offset + 1 | |
local lsmsuid_len = bodybuffer(Offset, 1):uint() | |
Offset = Offset + 1 | |
local left_byte_2 = bodybuffer(Offset, 1):uint() | |
Offset = Offset + 1 | |
local lsmsuid = 0 | |
if (lsmsuid_len == 0) then | |
lsmsuid = bodybuffer(Offset, 1):uint() | |
bodytree:add(pf_deliver[41], bodybuffer(Offset, 1)) | |
Offset = Offset + 1 | |
elseif (lsmsuid_len == 8) then | |
lsmsuid = bodybuffer(Offset, 2):uint() | |
bodytree:add(pf_deliver[42], bodybuffer(Offset, 2)) | |
Offset = Offset + 2 | |
-- else | |
-- 非法报文 | |
end | |
local lsms_count = bodybuffer(Offset, 1):uint() | |
bodytree:add(pf_deliver[43], bodybuffer(Offset, 1)) | |
Offset = Offset + 1 | |
local lsms_index = bodybuffer(Offset, 1):uint() | |
bodytree:add(pf_deliver[44], bodybuffer(Offset, 1)) | |
Offset = Offset + 1 | |
msg_len = msg_len - left_byte_0 - 1 | |
end | |
-- reply | |
local msg_content = nil | |
if (msg_fmt == 8) then | |
msg_content = bodybuffer(Offset, msg_len):ustring() | |
else | |
msg_content = bodybuffer(Offset, msg_len):string() | |
end | |
bodytree:add(pf_deliver[10], bodybuffer(Offset, msg_len), msg_content) | |
else | |
-- report | |
local report_buffer = bodybuffer(Offset, msg_len) | |
report_dissector(bodytree, report_buffer) | |
-- for i=1, #CMPPv2_MsgDef.CMPPv2_REPORT_INFO | |
-- do | |
-- local length = CMPPv2_MsgDef.CMPPv2_REPORT_INFO[i].Length | |
-- bodytree:add(pf_deliver[50+i], bodybuffer(Offset, length)) | |
-- Offset = Offset + length | |
-- end | |
end | |
Offset = Offset + msg_len | |
local reserve_buffer = bodybuffer(Offset, CMPPv2_MsgDef.CMPPv2_DELIVER[11].Length) | |
bodytree:add(pf_deliver[11], reserve_buffer, reserve_buffer:string()) | |
end | |
function CMPPv2_CMPPv2_DELIVER_RESP.dissector(bodybuffer, pinfo, tree) | |
Offset=0 | |
pinfo.cols.info = "CMPPv2_DELIVER_RESP. " | |
local bodytree = tree:add(CMPPv2_CMPPv2_DELIVER_RESP, bodybuffer(), "Deliver Response") | |
msg_id_dissector(pf_deliver_resp, bodytree, bodybuffer(Offset, 8), 1) | |
Offset = Offset + 8 | |
local i = 0 | |
for i=2,#CMPPv2_MsgDef.CMPPv2_DELIVER_RESP | |
do | |
bodytree:add(pf_deliver_resp[i], bodybuffer(Offset, CMPPv2_MsgDef.CMPPv2_DELIVER_RESP[i].Length)) | |
Offset = Offset + CMPPv2_MsgDef.CMPPv2_DELIVER_RESP[i].Length | |
end | |
end | |
function CMPPv2_CMPPv2_QUERY.dissector(bodybuffer, pinfo, tree) | |
Offset=0 | |
pinfo.cols.info = "CMPPv2_QUERY. " | |
local i = 0 | |
for i=1, #CMPPv2_MsgDef.CMPPv2_QUERY | |
do | |
local length = CMPPv2_MsgDef.CMPPv2_QUERY[i].Length | |
bodytree:add(pf_query[i], bodybuffer(Offset, length)) | |
Offset = Offset + length | |
end | |
end | |
function CMPPv2_CMPPv2_QUERY_RESP.dissector(bodybuffer, pinfo, tree) | |
Offset=0 | |
pinfo.cols.info = "CMPPv2_QUERY_RESP. " | |
local i = 0 | |
for i=1, #CMPPv2_MsgDef.CMPPv2_QUERY_RESP | |
do | |
local length = CMPPv2_MsgDef.CMPPv2_QUERY_RESP[i].Length | |
bodytree:add(pf_query_resp[i], bodybuffer(Offset, length)) | |
Offset = Offset + length | |
end | |
end | |
function CMPPv2_CMPPv2_CANCEL.dissector(bodybuffer, pinfo, tree) | |
Offset=0 | |
pinfo.cols.info = "CMPPv2_CANCEL. " | |
local i = 0 | |
for i=1, #CMPPv2_MsgDef.CMPPv2_CANCEL | |
do | |
local length = CMPPv2_MsgDef.CMPPv2_CANCEL[i].Length | |
bodytree:add(pf_cancel[i], bodybuffer(Offset, length)) | |
Offset = Offset + length | |
end | |
end | |
function CMPPv2_CMPPv2_CANCEL_RESP.dissector(bodybuffer, pinfo, tree) | |
Offset=0 | |
pinfo.cols.info = "CMPPv2_CANCEL_RESP. " | |
local i = 0 | |
for i=1, #CMPPv2_MsgDef.CMPPv2_CANCEL_RESP | |
do | |
local length = CMPPv2_MsgDef.CMPPv2_CANCEL_RESP[i].Length | |
bodytree:add(pf_cancel_resp[i], bodybuffer(Offset, length)) | |
Offset = Offset + length | |
end | |
end | |
function CMPPv2_CMPPv2_ACTIVE_TEST.dissector(bodybuffer, pinfo, tree) | |
Offset=0 | |
pinfo.cols.info = "CMPPv2_ACTIVE_TEST. " | |
end | |
function CMPPv2_CMPPv2_ACTIVE_TEST_RESP.dissector(bodybuffer, pinfo, tree) | |
Offset=0 | |
pinfo.cols.info = "CMPPv2_ACTIVE_TEST_RESP. " | |
local bodytree = tree:add(CMPPv2_CMPPv2_ACTIVE_TEST_RESP, bodybuffer(), "Active Test Response") | |
local buffer = bodybuffer(Offset, CMPPv2_MsgDef.CMPPv2_ACTIVE_TEST_RESP[1].Length) | |
bodytree:add(pf_activetest_resp[1], buffer, buffer:string()) | |
end | |
--Global Entry Point for this protocol | |
tcp_table = DissectorTable.get("tcp.port") | |
tcp_table:add(7890, CMPPv2_proto) | |
-- tcp_table:add(7060, CMPPv2_proto) | |
cmppv2_cmd_table=DissectorTable.new("cmppv2.cmd_id","cmppv2.cmd.table") | |
cmppv2_cmd_table:add(0x00000001, CMPPv2_CMPPv2_CONNECT) | |
cmppv2_cmd_table:add(0x00000801, CMPPv2_CMPPv2_CONNECT_RESP) | |
cmppv2_cmd_table:add(0x00000002, CMPPv2_CMPPv2_TERMINATE) | |
cmppv2_cmd_table:add(0x00000802, CMPPv2_CMPPv2_TERMINATE_RESP) | |
cmppv2_cmd_table:add(0x00000004, CMPPv2_CMPPv2_SUBMIT) | |
cmppv2_cmd_table:add(0x00000804, CMPPv2_CMPPv2_SUBMIT_RESP) | |
cmppv2_cmd_table:add(0x00000005, CMPPv2_CMPPv2_DELIVER) | |
cmppv2_cmd_table:add(0x00000805, CMPPv2_CMPPv2_DELIVER_RESP) | |
cmppv2_cmd_table:add(0x00000006, CMPPv2_CMPPv2_QUERY) | |
cmppv2_cmd_table:add(0x00000806, CMPPv2_CMPPv2_QUERY_RESP) | |
cmppv2_cmd_table:add(0x00000007, CMPPv2_CMPPv2_CANCEL) | |
cmppv2_cmd_table:add(0x00000807, CMPPv2_CMPPv2_CANCEL_RESP) | |
cmppv2_cmd_table:add(0x00000008, CMPPv2_CMPPv2_ACTIVE_TEST) | |
cmppv2_cmd_table:add(0x00000808, CMPPv2_CMPPv2_ACTIVE_TEST_RESP) |
Author
Arathi
commented
Jul 18, 2018
- 添加了上行长短信解析
- 现在可以输出Reserve,虽然没什么用
- 修改了CONNECT_RESP和ACTIVE_TEST相关报文解析的几个问题
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment