2
0

srt-dev.lua 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. -- @brief srt-dev Protocol dissector plugin
  2. -- create a new dissector
  3. local NAME = "SRT-dev"
  4. local srt_dev = Proto(NAME, "SRT-dev Protocol")
  5. -- create a preference of a Protocol
  6. srt_dev.prefs["srt_udp_port"] = Pref.uint("SRT UDP Port", 1935, "SRT UDP Port")
  7. -- create fields of srt_dev
  8. -- Base.HEX, Base.DEC, Base.OCT, Base.UNIT_STRING, Base.NONE
  9. local fields = srt_dev.fields
  10. -- General field
  11. local pack_type_select = {
  12. [0] = "Data Packet",
  13. [1] = "Control Packet"
  14. }
  15. fields.pack_type_tree = ProtoField.uint32(NAME .. ".pack_type_tree", "Packet Type", base.HEX)
  16. fields.pack_type = ProtoField.uint16("srt_dev.pack_type", "Packet Type", base.HEX, pack_type_select, 0x8000)
  17. fields.reserve = ProtoField.uint16("srt_dev.reserve", "Reserve", base.DEC)
  18. fields.additional_info = ProtoField.uint32("srt_dev.additional_info", "Additional Information", base.DEC)
  19. fields.time_stamp = ProtoField.uint32("srt_dev.time_stamp", "Time Stamp", base.DEC)
  20. fields.dst_sock = ProtoField.uint32("srt_dev.dst_sock", "Destination Socket ID", base.DEC)
  21. fields.none = ProtoField.none("srt_dev.none", "none", base.NONE)
  22. -- Data packet fields
  23. fields.data_flag_info_tree = ProtoField.uint8("srt_dev.data_flag_info_tree", "Data Flag Info", base.HEX)
  24. local FF_state_select = {
  25. [0] = "[Middle packet]",
  26. [1] = "[Last packet]",
  27. [2] = "[First packet]",
  28. [3] = "[Single packet]"
  29. }
  30. fields.FF_state = ProtoField.uint8("srt_dev.FF_state", "FF state", base.HEX, FF_state_select, 0xC0)
  31. local O_state_select = {
  32. [0] = "[ORD_RELAX]",
  33. [1] = "[ORD_REQUIRED]"
  34. }
  35. fields.O_state = ProtoField.uint8("srt_dev.O_state", "O state", base.HEX, O_state_select, 0x20)
  36. local KK_state_select = {
  37. [0] = "[Not encrypted]",
  38. [1] = "[Data encrypted with even key]",
  39. [2] = "[Data encrypted with odd key]"
  40. }
  41. fields.KK_state = ProtoField.uint8("srt_dev.KK_state", "KK state", base.HEX, KK_state_select, 0x18)
  42. local R_state_select = {
  43. [0] = "[ORIGINAL]",
  44. [1] = "[RETRANSMITTED]"
  45. }
  46. fields.R_state = ProtoField.uint8("srt_dev.R_state", "R state", base.HEX, R_state_select, 0x04)
  47. fields.seq_num = ProtoField.uint32("srt_dev.seq_num", "Sequence Number", base.DEC)
  48. fields.msg_num = ProtoField.uint32("srt_dev.msg_num", "Message Number", base.DEC)--, nil, 0x3FFFFFF)
  49. -- control packet fields
  50. local msg_type_select = {
  51. [0] = "[HANDSHAKE]",
  52. [1] = "[KEEPALIVE]",
  53. [2] = "[ACK]",
  54. [3] = "[NAK(Loss Report)]",
  55. [4] = "[Congestion Warning]",
  56. [5] = "[Shutdown]",
  57. [6] = "[ACKACK]",
  58. [7] = "[Drop Request]",
  59. [8] = "[Peer Error]",
  60. [0x7FFF] = "[Message Extension Type]"
  61. }
  62. fields.msg_type = ProtoField.uint16("srt_dev.msg_type", "Message Type", base.HEX, msg_type_select, 0x7FFF)
  63. fields.msg_ext_type = ProtoField.uint16("srt_dev.msg_ext_type", "Message Extented Type", base.DEC)
  64. local flag_state_select = {
  65. [0] = "Unset",
  66. [1] = "Set"
  67. }
  68. -- Handshake packet fields
  69. fields.UDT_version = ProtoField.uint32("srt_dev.UDT_version", "UDT Version", base.DEC)
  70. fields.sock_type = ProtoField.uint32("srt_dev.sock_type", "Socket Type", base.DEC)
  71. fields.ency_fld = ProtoField.uint16("srt_dev.ency_fld", "Encryption Field", base.DEC)
  72. fields.ext_fld = ProtoField.uint16("srt_dev.ext_fld", "Extension Fields", base.HEX)
  73. fields.ext_fld_tree = ProtoField.uint16("srt_dev.ext_fld_tree", "Extension Fields Tree", base.HEX)
  74. fields.hsreq = ProtoField.uint16("srt_dev.hsreq", "HS_EXT_HSREQ", base.HEX, flag_state_select, 0x1)
  75. fields.kmreq = ProtoField.uint16("srt_dev.kmreq", "HS_EXT_KMREQ", base.HEX, flag_state_select, 0x2)
  76. fields.config = ProtoField.uint16("srt_dev.config", "HS_EXT_CONFIG", base.HEX, flag_state_select, 0x4)
  77. fields.isn = ProtoField.uint32("srt_dev.isn", "Initial packet sequence number", base.DEC)
  78. fields.mss = ProtoField.uint32("srt_dev.mss", "Max Packet Size", base.DEC)
  79. fields.fc = ProtoField.uint32("srt_dev.fc", "Maximum Flow Window Size", base.DEC)
  80. fields.conn_type = ProtoField.int32("srt_dev.conn_type", "Connection Type", base.DEC)
  81. fields.sock_id = ProtoField.uint32("srt_dev.sock_id", "Socket ID", base.DEC)
  82. fields.syn_cookie = ProtoField.uint32("srt_dev.syn_cookie", "SYN cookie", base.DEC)
  83. fields.peer_ipaddr = ProtoField.none("srt_dev.peer_ipaddr", "Peer IP address", base.NONE)
  84. fields.peer_ipaddr_4 = ProtoField.ipv4("srt_dev.peer_ipaddr", "Peer IP address")
  85. fields.peer_ipaddr_6 = ProtoField.ipv6("srt_dev.peer_ipaddr", "Peer IP address")
  86. local ext_type_select = {
  87. [-1] = "SRT_CMD_NONE",
  88. [0] = "SRT_CMD_REJECT",
  89. [1] = "SRT_CMD_HSREQ",
  90. [2] = "SRT_CMD_HSRSP",
  91. [3] = "SRT_CMD_KMREQ",
  92. [4] = "SRT_CMD_KMRSP",
  93. [5] = "SRT_CMD_SID",
  94. [6] = "SRT_CMD_CONGESTION",
  95. [7] = "SRT_CMD_FILTER",
  96. [8] = "SRT_CMD_GROUP"
  97. }
  98. fields.ext_type_msg_tree = ProtoField.none("srt_dev.ext_type", "Extension Type Message", base.NONE)
  99. fields.ext_type = ProtoField.uint16("srt_dev.ext_type", "Extension Type", base.HEX, ext_type_select, 0xF)
  100. fields.ext_size = ProtoField.uint16("srt_dev.ext_size", "Extension Size", base.DEC)
  101. -- Handshake packet, ext type == SRT_CMD_HSREQ or SRT_CMD_HSRSP field
  102. fields.srt_version = ProtoField.uint32("srt_dev.srt_version", "SRT Version", base.HEX)
  103. fields.srt_flags = ProtoField.uint32("srt_dev.srt_flags", "SRT Flags", base.HEX)
  104. fields.tsbpb_resv = ProtoField.uint16("srt_dev.tsbpb_resv", "TsbPb Receive", base.DEC)
  105. fields.tsbpb_delay = ProtoField.uint16("srt_dev.tsbpb_delay", "TsbPb Delay", base.DEC)
  106. fields.tsbpd_delay = ProtoField.uint16("srt_dev.tsbpd_delay", "TsbPd Delay", base.DEC)
  107. fields.rcv_tsbpd_delay = ProtoField.uint16("srt_dev.rcv_tsbpd_delay", "Receiver TsbPd Delay", base.DEC)
  108. fields.snd_tsbpd_delay = ProtoField.uint16("srt_dev.snd_tsbpd_delay", "Sender TsbPd Delay", base.DEC)
  109. -- V and PT status flag
  110. local V_state_select = {
  111. [1] = "Initial version"
  112. }
  113. fields.V_state = ProtoField.uint8("srt_dev.V_state", "V", base.HEX, V_state_select, 0x70)
  114. local PT_state_select = {
  115. [0] = "Reserved",
  116. [1] = "MSmsg",
  117. [2] = "KMmsg",
  118. [7] = "Reserved to discriminate MPEG-TS packet(0x47=sync byte)"
  119. }
  120. fields.PT_state = ProtoField.uint8("srt_dev.PT_state", "PT", base.HEX, state_table, 0xF)
  121. fields.sign = ProtoField.uint16("srt_dev.sign", "Signature", base.HEX)
  122. local resv_select = {
  123. [0] = "Reserved for flag extension or other usage"
  124. }
  125. fields.resv = ProtoField.uint8("srt_dev.resv", "Resv", base.DEC, state_table, 0xFC)
  126. fields.ext_KK_state = ProtoField.uint8("srt_dev.ext_KK_state", "KK_state", base.HEX, KK_state_select, 0x3)
  127. fields.KEKI = ProtoField.uint32("srt_dev.KEKI", "KEKI", base.DEC)
  128. fields.cipher = ProtoField.uint8("srt_dev.cipher", "Cipher", base.DEC)
  129. fields.auth = ProtoField.uint8("srt_dev.auth", "auth", base.DEC)
  130. fields.SE = ProtoField.uint8("srt_dev.SE", "SE", base.DEC)
  131. fields.resv1 = ProtoField.uint8("srt_dev.resv1", "resv1", base.DEC)
  132. fields.resv2 = ProtoField.uint16("srt_dev.resv2", "resv2", base.DEC)
  133. fields.slen = ProtoField.uint8("srt_dev.slen", "Salt length(bytes)/4", base.DEC)
  134. fields.klen = ProtoField.uint8("srt_dev.klen", "SEK length(bytes)/4", base.DEC)
  135. fields.salt = ProtoField.uint32("srt_dev.salt", "Salt key", base.DEC)
  136. fields.wrap = ProtoField.none("srt_dev.wrap", "Wrap key(s)", base.NONE)
  137. -- Wrap Field
  138. fields.ICV = ProtoField.uint64("srt_dev.ICV", "Integerity Check Vector", base.HEX)
  139. fields.odd_key = ProtoField.stringz("srt_dev.odd_key", "Odd key", base.ASCII)
  140. fields.even_key = ProtoField.stringz("srt_dev.even_key", "Even key", base.ASCII)
  141. -- ext_type == SRT_CMD_SID field
  142. fields.sid = ProtoField.string("srt_dev.sid", "Stream ID", base.ASCII)
  143. -- ext_type == SRT_CMD_CONGESTION field
  144. fields.congestion = ProtoField.string("srt_dev.congestion", "Congestion Controller", base.ASCII)
  145. -- ext_type == SRT_CMD_FILTER field
  146. fields.filter = ProtoField.string("srt_dev.filter", "Filter", base.ASCII)
  147. -- ext_type == SRT_CMD_GROUP field
  148. fields.group = ProtoField.string("srt_dev.group", "Group Data", base.ASCII)
  149. -- SRT flags
  150. fields.srt_opt_tsbpdsnd = ProtoField.uint32("srt_dev.srt_opt_tsbpdsnd", "SRT_OPT_TSBPDSND", base.HEX, flag_state_select, 0x1)
  151. fields.srt_opt_tsbpdrcv = ProtoField.uint32("srt_dev.srt_opt_tsbpdrcv", "SRT_OPT_TSBPDRCV", base.HEX, flag_state_select, 0x2)
  152. fields.srt_opt_haicrypt = ProtoField.uint32("srt_dev.srt_opt_haicrypt", "SRT_OPT_HAICRYPT", base.HEX, flag_state_select, 0x4)
  153. fields.srt_opt_tlpktdrop = ProtoField.uint32("srt_dev.srt_opt_tlpktdrop", "SRT_OPT_TLPKTDROP", base.HEX, flag_state_select, 0x8)
  154. fields.srt_opt_nakreport = ProtoField.uint32("srt_dev.srt_opt_nakreport", "SRT_OPT_NAKREPORT", base.HEX, flag_state_select, 0x10)
  155. fields.srt_opt_rexmitflg = ProtoField.uint32("srt_dev.srt_opt_rexmitflg", "SRT_OPT_REXMITFLG", base.HEX, flag_state_select, 0x20)
  156. fields.srt_opt_stream = ProtoField.uint32("srt_dev.srt_opt_stream", "SRT_OPT_STREAM", base.HEX, flag_state_select, 0x40)
  157. -- ACK fields
  158. fields.last_ack_pack = ProtoField.uint32("srt_dev.last_ack_pack", "Last ACK Packet Sequence Number", base.DEC)
  159. fields.rtt = ProtoField.int32("srt_dev.rtt", "Round Trip Time", base.DEC)
  160. fields.rtt_variance = ProtoField.int32("srt_dev.rtt_variance", "Round Trip Time Variance", base.DEC)
  161. fields.buf_size = ProtoField.uint32("srt_dev.buf_size", "Available Buffer Size", base.DEC)
  162. fields.pack_rcv_rate = ProtoField.uint32("srt_dev.pack_rcv_rate", "Packet Receiving Rate", base.DEC)
  163. fields.est_link_capacity = ProtoField.uint32("srt_dev.est_link_capacity", "Estimated Link Capacity", base.DEC)
  164. fields.rcv_rate = ProtoField.uint32("srt_dev.rcv_rate", "Receiving Rate", base.DEC)
  165. -- ACKACK fields
  166. fields.ack_num = ProtoField.uint32("srt_dev.ack_num", "ACK number", base.DEC)
  167. fields.ctl_info = ProtoField.uint32("srt_dev.ctl_info", "Control Information", base.DEC)
  168. -- KMRSP fields
  169. local srt_km_state_select = {
  170. [0] = "[SRT_KM_UNSECURED]",
  171. [1] = "[SRT_KM_SECURING]",
  172. [2] = "[SRT_KM_SECURED]",
  173. [3] = "[SRT_KM_NOSECRET]",
  174. [4] = "[SRT_KM_BADSECRET]"
  175. }
  176. fields.km_err = ProtoField.uint32("srt_dev.km_err", "Key Message Error", base.HEX, srt_km_state_select, 0xF)
  177. -- NAK Control Packet fields
  178. fields.lost_list_tree = ProtoField.none("srt_dev.lost_list_tree", "Lost Packet List", base.NONE)
  179. fields.lost_pack_seq = ProtoField.uint32("srt_dev.lost_pack_seq", "Lost Packet Sequence Number", base.DEC)
  180. fields.lost_pack_range_tree = ProtoField.none("srt_dev.lost_pack_range_tree", "Lost Packet Range", base.NONE)
  181. fields.lost_start = ProtoField.uint32("srt_dev.lost_start", "Lost Starting Sequence", base.DEC)
  182. fields.lost_up_to = ProtoField.uint32("srt_dev.lost_up_to", "Lost Up To(including)", base.DEC)
  183. -- Dissect packet
  184. function srt_dev.dissector (tvb, pinfo, tree)
  185. -- Packet is based on UDP, so the data can be processed directly after UDP
  186. local subtree = tree:add(srt_dev, tvb())
  187. local offset = 0
  188. -- Changes the protocol name
  189. pinfo.cols.protocol = srt_dev.name
  190. -- Take out the first bit of package
  191. -- 0 -> Data Packet
  192. -- 1 -> Control Packet
  193. local typebit = bit.rshift(tvb(offset, 1):uint(), 7)
  194. pack_type_tree = subtree:add(fields.pack_type_tree, tvb(offset, 4))
  195. if typebit == 1 then
  196. -- Handle Control Packet
  197. pack_type_tree:add(fields.pack_type, tvb(offset, 2))
  198. local msg_type = tvb(offset, 2):uint()
  199. if msg_type ~= 0xFFFF then
  200. -- If type field isn't '0x7FFF',it means packet is normal data packet, then handle type field
  201. msg_type = bit.band(msg_type, 0x7FFF)
  202. function parse_three_param()
  203. -- Ignore Additional Info (this field is not defined in this packet type)
  204. subtree:add(fields.additional_info, tvb(offset, 4)):append_text(" [undefined]")
  205. offset = offset + 4
  206. -- Handle Time Stamp
  207. subtree:add(fields.time_stamp, tvb(offset, 4)):append_text(" μs")
  208. offset = offset + 4
  209. -- Handle Destination Socket
  210. subtree:add(fields.dst_sock, tvb(offset, 4))
  211. offset = offset + 4
  212. end
  213. local switch = {
  214. [0] = function()
  215. pinfo.cols.info:append(" [HANDSHAKE]")
  216. pack_type_tree:append_text(" [HANDSHAKE]")
  217. pack_type_tree:add(fields.msg_type, tvb(offset, 2))
  218. pack_type_tree:add(fields.reserve, tvb(offset + 2, 2)):append_text(" [Undefined]")
  219. offset = offset + 4
  220. -- Handle Additional Info, Timestamp and Destination Socket
  221. parse_three_param()
  222. -- Handle UDT version field
  223. local UDT_version = tvb(offset, 4):uint()
  224. subtree:add(fields.UDT_version, tvb(offset, 4))
  225. offset = offset + 4
  226. if UDT_version == 4 then
  227. -- UDT version is 4, packet is different from UDT version 5
  228. -- Handle sock type
  229. local sock_type = tvb(offset, 4):uint()
  230. if sock_type == 1 then
  231. subtree:add(fields.sock_type, tvb(offset, 4)):append_text(" [SRT_STREAM]")
  232. elseif sock_type == 2 then
  233. subtree:add(fields.sock_type, tvb(offset, 4)):append_text(" [SRT_DRAGAM]")
  234. end
  235. offset = offset + 4
  236. elseif UDT_version == 5 then
  237. -- Handle Encryption Field
  238. local encr_fld = tvb(offset, 2):int()
  239. if encr_fld == 0 then
  240. subtree:add(fields.ency_fld, tvb(offset, 2)):append_text(" (PBKEYLEN not advertised)")
  241. elseif encr_fld == 2 then
  242. subtree:add(fields.ency_fld, tvb(offset, 2)):append_text(" (AES-128)")
  243. elseif encr_fld == 3 then
  244. subtree:add(fields.ency_fld, tvb(offset, 2)):append_text(" (AES-192)")
  245. else
  246. subtree:add(fields.ency_fld, tvb(offset, 2)):append_text(" (AES-256)")
  247. end
  248. offset = offset + 2
  249. -- Handle Extension Field
  250. local ext_fld = tvb(offset, 2):int()
  251. if ext_fld == 0x4A17 then
  252. subtree:add(fields.ext_fld, tvb(offset, 2)):append_text(" [HSv5 MAGIC]")
  253. else
  254. -- Extension Field is HS_EXT_prefix
  255. -- The define is in fiel handshake.h
  256. local ext_fld_tree = subtree:add(fields.ext_fld_tree, tvb(offset, 2))
  257. local str_table = { " [" }
  258. ext_fld_tree:add(fields.hsreq, tvb(offset, 2))
  259. if bit.band(tvb(offset, 2):uint(), 0x1) == 1 then
  260. table.insert(str_table, "HS_EXT_HSREQ")
  261. table.insert(str_table, " | ")
  262. end
  263. ext_fld_tree:add(fields.kmreq, tvb(offset, 2)):append_text(" [HS_EXT_KMREQ]")
  264. if bit.band(tvb(offset, 2):uint(), 0x2) == 2 then
  265. table.insert(str_table, "HS_EXT_KMREQ")
  266. table.insert(str_table, " | ")
  267. end
  268. ext_fld_tree:add(fields.config, tvb(offset, 2)):append_text(" [HS_EXT_CONFIG]")
  269. if bit.band(tvb(offset, 2):uint(), 0x4) == 4 then
  270. table.insert(str_table, "HS_EXT_CONFIG")
  271. table.insert(str_table, " | ")
  272. end
  273. table.remove(str_table)
  274. table.insert(str_table, "]")
  275. if ext_fld ~= 0 then
  276. ext_fld_tree:append_text(table.concat(str_table))
  277. end
  278. end
  279. offset = offset + 2
  280. end
  281. -- Handle Initial packet sequence number
  282. subtree:add(fields.isn, tvb(offset, 4))
  283. offset = offset + 4
  284. -- Handle Maximum Packet Size
  285. subtree:add(fields.mss, tvb(offset, 4))
  286. offset = offset + 4
  287. -- Handle Maximum Flow Window Size
  288. subtree:add(fields.fc, tvb(offset, 4))
  289. offset = offset + 4
  290. -- Handle Connection Type
  291. local conn_type = tvb(offset, 4):int()
  292. local conn_type_tree = subtree:add(fields.conn_type, tvb(offset, 4))
  293. if conn_type == 0 then
  294. conn_type_tree:append_text(" [WAVEAHAND] (Rendezvous Mode)")
  295. pinfo.cols.info:append(" [WAVEAHAND] (Rendezvous Mode)")
  296. elseif conn_type == 1 then
  297. conn_type_tree:append_text(" [INDUCTION]")
  298. elseif conn_type == -1 then
  299. conn_type_tree:append_text(" [CONCLUSION]")
  300. elseif conn_type == -2 then
  301. conn_type_tree:append_text(" [AGREEMENT] (Rendezvous Mode)")
  302. pinfo.cols.info:append(" [AGREEMENT] (Rendezvous Mode)")
  303. end
  304. offset = offset + 4
  305. -- Handle Socket ID
  306. subtree:add(fields.sock_id, tvb(offset, 4))
  307. offset = offset + 4
  308. -- Handle SYN cookie
  309. local syn_cookie = tvb(offset, 4):int()
  310. subtree:add(fields.syn_cookie, tvb(offset, 4))
  311. if syn_cookie == 0 then
  312. conn_type_tree:append_text(" (Caller to Listener)")
  313. pinfo.cols.info:append(" (Caller to Listener)")
  314. else
  315. if conn_type == 1 then
  316. -- reports cookie from listener
  317. conn_type_tree:append_text(" (Listener to Caller)")
  318. pinfo.cols.info:append(" (Listener to Caller)")
  319. end
  320. end
  321. offset = offset + 4
  322. -- Handle Peer IP address
  323. -- Note the network byte order
  324. local the_last_96_bits = 0
  325. the_last_96_bits = the_last_96_bits + math.floor(tvb(offset + 4, 4):int() * (2 ^ 16))
  326. the_last_96_bits = the_last_96_bits + math.floor(tvb(offset + 8, 4):int() * (2 ^ 8))
  327. the_last_96_bits = the_last_96_bits + tvb(offset + 12, 4):int()
  328. if the_last_96_bits == 0 then
  329. subtree:add_le(fields.peer_ipaddr_4, tvb(offset, 4))
  330. else
  331. subtree:add_le(fields.peer_ipaddr, tvb(offset, 16))
  332. end
  333. offset = offset + 16
  334. -- UDT version is 4, packet handle finish
  335. if UDT_version == 4 or offset == tvb:len() then
  336. return
  337. end
  338. function process_ext_type()
  339. -- Handle Ext Type, processing by type
  340. local ext_type = tvb(offset, 2):int()
  341. if ext_type == 1 or ext_type == 2 then
  342. local ext_type_msg_tree = subtree:add(fields.ext_type_msg_tree, tvb(offset, 16))
  343. if ext_type == 1 then
  344. ext_type_msg_tree:append_text(" [SRT_CMD_HSREQ]")
  345. ext_type_msg_tree:add(fields.ext_type, tvb(offset, 2))
  346. conn_type_tree:append_text(" (Caller to Listener)")
  347. pinfo.cols.info:append(" (Caller to Listener)")
  348. else
  349. ext_type_msg_tree:append_text(" [SRT_CMD_HSRSP]")
  350. ext_type_msg_tree:add(fields.ext_type, tvb(offset, 2))
  351. conn_type_tree:append_text(" (Listener to Caller)")
  352. pinfo.cols.info:append(" (Listener to Caller)")
  353. end
  354. offset = offset + 2
  355. -- Handle Ext Size
  356. ext_type_msg_tree:add(fields.ext_size, tvb(offset, 2))
  357. offset = offset + 2
  358. -- Handle SRT Version
  359. ext_type_msg_tree:add(fields.srt_version, tvb(offset, 4))
  360. offset = offset + 4
  361. -- Handle SRT Flags
  362. local SRT_flags_tree = ext_type_msg_tree:add(fields.srt_flags, tvb(offset, 4))
  363. SRT_flags_tree:add(fields.srt_opt_tsbpdsnd, tvb(offset, 4))
  364. SRT_flags_tree:add(fields.srt_opt_tsbpdrcv, tvb(offset, 4))
  365. SRT_flags_tree:add(fields.srt_opt_haicrypt, tvb(offset, 4))
  366. SRT_flags_tree:add(fields.srt_opt_tlpktdrop, tvb(offset, 4))
  367. SRT_flags_tree:add(fields.srt_opt_nakreport, tvb(offset, 4))
  368. SRT_flags_tree:add(fields.srt_opt_rexmitflg, tvb(offset, 4))
  369. SRT_flags_tree:add(fields.srt_opt_stream, tvb(offset, 4))
  370. offset = offset + 4
  371. -- Handle Recv TsbPd Delay and Snd TsbPd Delay
  372. if UDT_version == 4 then
  373. ext_type_msg_tree:add(fields.tsbpd_delay, tvb(offset, 2)):append_text(" [Unused in HSv4]")
  374. offset = offset + 2
  375. ext_type_msg_tree:add(fields.tsbpb_delay, tvb(offset, 2))
  376. offset = offset + 2
  377. else
  378. ext_type_msg_tree:add(fields.rcv_tsbpd_delay, tvb(offset, 2))
  379. offset = offset + 2
  380. ext_type_msg_tree:add(fields.snd_tsbpd_delay, tvb(offset, 2))
  381. offset = offset + 2
  382. end
  383. elseif ext_type == 3 or ext_type == 4 then
  384. local ext_type_msg_tree = subtree:add(fields.ext_type_msg_tree, tvb(offset, 16))
  385. if ext_type == 3 then
  386. ext_type_msg_tree:append_text(" [SRT_CMD_KMREQ]")
  387. ext_type_msg_tree:add(fields.ext_type, tvb(offset, 2))
  388. conn_type_tree:append_text(" (Listener to Caller)")
  389. else
  390. ext_type_msg_tree:append_text(" [SRT_CMD_KMRSP]")
  391. ext_type_msg_tree:add(fields.ext_type, tvb(offset, 2))
  392. end
  393. offset = offset + 2
  394. -- Handle Ext Size
  395. local km_len = tvb(offset, 2):uint()
  396. ext_type_msg_tree:add(fields.ext_size, tvb(offset, 2)):append_text(" (byte/4)")
  397. offset = offset + 2
  398. -- Handle SRT_CMD_KMREQ message
  399. -- V and PT status flag
  400. ext_type_msg_tree:add(fields.V_state, tvb(offset, 1))
  401. ext_type_msg_tree:add(fields.PT_state, tvb(offset, 1))
  402. offset = offset + 1
  403. -- Handle sign
  404. ext_type_msg_tree:add(fields.sign, tvb(offset, 2)):append_text(" (/'HAI/' PnP Vendor ID in big endian order)")
  405. offset = offset + 2
  406. -- Handle resv
  407. ext_type_msg_tree:add(fields.resv, tvb(offset, 1))
  408. -- Handle KK flag
  409. local KK = tvb(offset, 1):uint()
  410. ext_type_msg_tree:add(fields.ext_KK_state, tvb(offset, 1))
  411. offset = offset + 1
  412. -- Handle KEKI
  413. if tvb(offset, 4):uint() == 0 then
  414. ext_type_msg_tree:add(fields.KEKI, tvb(offset, 4)):append_text(" (Default stream associated key(stream/system default))")
  415. else
  416. ext_type_msg_tree:add(fields.KEKI, tvb(offset, 4)):append_text(" (Reserved for manually indexed keys)")
  417. end
  418. offset = offset + 4
  419. -- Handle Cipher
  420. local cipher_node = ext_type_msg_tree:add(fields.cipher, tvb(offset, 1))
  421. local cipher = tvb(offset, 1):uint()
  422. if cipher == 0 then
  423. elseif cipher == 1 then
  424. cipher_node:append_text(" (AES-ECB(potentially for VF 2.0 compatible message))")
  425. elseif cipher == 2 then
  426. cipher_node:append_text(" (AES-CTR[FP800-38A])")
  427. else
  428. cipher_node:append_text(" (AES-CCM or AES-GCM)")
  429. end
  430. offset = offset + 1
  431. -- Handle Auth
  432. if tvb(offset, 1):uint() == 0 then
  433. ext_type_msg_tree:add(fields.auth, tvb(offset, 1)):append_text(" (None or KEKI indexed crypto context)")
  434. else
  435. ext_type_msg_tree:add(fields.auth, tvb(offset, 1))
  436. end
  437. offset = offset + 1
  438. -- Handle SE
  439. local SE_node = ext_type_msg_tree:add(fields.SE, tvb(offset, 1))
  440. local SE = tvb(offset, 1):uint()
  441. if SE == 0 then
  442. SE_node:append_text( " (Unspecified or KEKI indexed crypto context)")
  443. elseif SE == 1 then
  444. SE_node:append_text( " (MPEG-TS/UDP)")
  445. elseif SE == 2 then
  446. SE_node:append_text( " (MPEG-TS/SRT)")
  447. end
  448. offset = offset + 1
  449. -- Handle resv1
  450. ext_type_msg_tree:add(fields.resv1, tvb(offset, 1))
  451. offset = offset + 1
  452. -- Handle resv2
  453. ext_type_msg_tree:add(fields.resv2, tvb(offset, 2))
  454. offset = offset + 2
  455. -- Handle slen
  456. ext_type_msg_tree:add(fields.slen, tvb(offset, 1))
  457. offset = offset + 1
  458. -- Handle klen
  459. local klen = tvb(offset, 1):uint()
  460. ext_type_msg_tree:add(fields.klen, tvb(offset, 1))
  461. offset = offset + 1
  462. -- Handle salt key
  463. ext_type_msg_tree:add(fields.salt, tvb(offset, slen * 4))
  464. offset = offset + slen * 4
  465. -- Handle wrap
  466. -- Handle ICV
  467. local wrap_len = 8 + KK * klen
  468. local wrap_tree = ext_type_msg_tree:add(fields.wrap, tvb(offset, wrap_len))
  469. wrap_tree:add(fields.ICV, tvb(offset, 8))
  470. offset = offset + 8
  471. -- If KK == 2, first key is Even key
  472. if KK == 2 then
  473. wrap_tree:add(fields.even_key, tvb(offset, klen))
  474. offset = offset + klen;
  475. end
  476. -- Handle Odd key
  477. wrap_tree:add(fields.odd_key, tvb(offset, klen))
  478. offset = offset + klen;
  479. elseif ext_type >= 5 and ext_type <= 8 then
  480. local value_size = tvb(offset + 2, 2):uint() * 4
  481. local ext_msg_size = 2 + 2 + value_size
  482. local type_array = { " [SRT_CMD_SID]", " [SRT_CMD_CONGESTION]", " [SRT_CMD_FILTER]", " [SRT_CMD_GROUP]" }
  483. local field_array = { fields.sid, fields.congestion, fields.filter, fields.group }
  484. local ext_type_msg_tree = subtree:add(fields.ext_type_msg_tree, tvb(offset, ext_msg_size)):append_text(type_array[ext_type - 4])
  485. ext_type_msg_tree:add(fields.ext_type, tvb(offset, 2))
  486. offset = offset + 2
  487. -- Handle Ext Msg Value Size
  488. ext_type_msg_tree:add(fields.ext_size, tvb(offset, 2)):append_text(" (byte/4)")
  489. offset = offset + 2
  490. -- Value
  491. local value_table = {}
  492. for pos = 0, value_size - 4, 4 do
  493. table.insert(value_table, string.char(tvb(offset + pos + 3, 1):uint()))
  494. table.insert(value_table, string.char(tvb(offset + pos + 2, 1):uint()))
  495. table.insert(value_table, string.char(tvb(offset + pos + 1, 1):uint()))
  496. table.insert(value_table, string.char(tvb(offset + pos, 1):uint()))
  497. end
  498. local value = table.concat(value_table)
  499. ext_type_msg_tree:add(field_array[ext_type - 4], tvb(offset, value_size), value)
  500. offset = offset + value_size
  501. elseif ext_type == -1 then
  502. local ext_type_msg_tree = subtree:add(fields.ext_type_msg_tree, tvb(offset, tvb:len() - offset)):append_text(" [SRT_CMD_NONE]")
  503. ext_type_msg_tree:add(fields.ext_type, tvb(offset, 2))
  504. offset = offset + 2
  505. -- none
  506. if offset == tvb:len() then
  507. return
  508. end
  509. ext_type_msg_tree:add(fields.none, tvb(offset, tvb:len() - offset))
  510. offset = tvb:len()
  511. end
  512. if offset == tvb:len() then
  513. return
  514. else
  515. process_ext_type()
  516. end
  517. end
  518. process_ext_type()
  519. end,
  520. [1] = function()
  521. pinfo.cols.info:append(" [KEEPALIVE]")
  522. pack_type_tree:append_text(" [KEEPALIVE]")
  523. pack_type_tree:add(fields.msg_type, tvb(offset, 2)):append_text(" [KEEPALIVE]")
  524. pack_type_tree:add(fields.reserve, tvb(offset + 2, 2)):append_text(" [Undefined]")
  525. offset = offset + 4
  526. -- Handle Additional Info, Time Stamp and Destination Socket
  527. parse_three_param()
  528. end,
  529. [2] = function()
  530. pinfo.cols.info:append(" [ACK]")
  531. pack_type_tree:append_text(" [ACK]")
  532. pack_type_tree:add(fields.msg_type, tvb(offset, 2))
  533. pack_type_tree:add(fields.reserve, tvb(offset + 2, 2)):append_text(" [Undefined]")
  534. offset = offset + 4
  535. -- Handle ACK Number
  536. subtree:add(fields.ack_num, tvb(offset, 4))
  537. offset = offset + 4
  538. -- Handle Time Stamp
  539. subtree:add(fields.time_stamp, tvb(offset, 4)):append_text(" μs")
  540. offset = offset + 4
  541. -- Handle Destination Socket
  542. subtree:add(fields.dst_sock, tvb(offset, 4))
  543. offset = offset + 4
  544. -- Handle Last Ack Packet Sequence
  545. local last_ack_pack = tvb(offset, 4):uint()
  546. pinfo.cols.info:append(" (Last ACK Seq:" .. last_ack_pack .. ")")
  547. subtree:add(fields.last_ack_pack, tvb(offset, 4))
  548. offset = offset + 4
  549. -- Handle RTT
  550. local rtt = tvb(offset, 4):int()
  551. subtree:add(fields.rtt, tvb(offset, 4)):append_text(" μs")
  552. offset = offset + 4
  553. -- Handle RTT variance
  554. if rtt < 0 then
  555. subtree:add(fields.rtt_variance, tvb(offset, 4), -tvb(offset, 4):int())
  556. else
  557. subtree:add(fields.rtt_variance, tvb(offset, 4))
  558. end
  559. offset = offset + 4
  560. -- Handle Available Buffer Size(pkts)
  561. subtree:add(fields.buf_size, tvb(offset, 4)):append_text(" pkts")
  562. offset = offset + 4
  563. -- Handle Packets Receiving Rate(Pkts/sec)
  564. subtree:add(fields.pack_rcv_rate, tvb(offset, 4)):append_text(" pkts/sec")
  565. offset = offset + 4
  566. -- Handle Estmated Link Capacity
  567. subtree:add(fields.est_link_capacity, tvb(offset, 4)):append_text(" pkts/sec")
  568. offset = offset + 4
  569. -- Handle Receiving Rate(bps)
  570. subtree:add(fields.rcv_rate, tvb(offset, 4)):append_text(" bps")
  571. offset = offset + 4
  572. end,
  573. [3] = function()
  574. pinfo.cols.info:append(" [NAK(loss Report)]")
  575. pack_type_tree:append_text(" [NAK(loss Report)]")
  576. pack_type_tree:add(fields.msg_type, tvb(offset, 2))
  577. pack_type_tree:add(fields.reserve, tvb(offset + 2, 2)):append_text(" [Undefined]")
  578. offset = offset + 4
  579. -- Handle Additional Info, Timestamp and Destination Socket
  580. parse_three_param()
  581. -- Handle lost packet sequence
  582. -- lua does not support changing loop variables within loops, but in the form of closures
  583. -- https://blog.csdn.net/Ai102iA/article/details/75371239
  584. local start = offset
  585. local ending = tvb:len()
  586. local lost_list_tree = subtree:add(fields.lost_list_tree, tvb(offset, ending - offset))
  587. for start in function()
  588. local first_bit = bit.rshift(tvb(start, 1):uint(), 7)
  589. if first_bit == 1 then
  590. local lost_pack_range_tree = lost_list_tree:add(fields.lost_pack_range_tree, tvb(start, 8))
  591. local lost_start = bit.band(tvb(start, 4):uint(), 0x7FFFFFFF)
  592. lost_pack_range_tree:append_text(" (" .. lost_start .. " -> " .. tvb(start + 4, 4):uint() .. ")")
  593. lost_pack_range_tree:add(fields.lost_start, tvb(start, 4), lost_start)
  594. start = start + 4
  595. lost_pack_range_tree:add(fields.lost_up_to, tvb(start, 4))
  596. start = start + 4
  597. else
  598. lost_list_tree:add(fields.lost_pack_seq, tvb(start, 4))
  599. start = start + 4
  600. end
  601. return start
  602. end
  603. do
  604. if start == ending then
  605. break
  606. end
  607. end
  608. end,
  609. [4] = function()
  610. pinfo.cols.info:append(" [Congestion Warning]")
  611. pack_type_tree:append_text(" [Congestion Warning]")
  612. pack_type_tree:add(fields.msg_type, tvb(offset, 2))
  613. pack_type_tree:add(fields.reserve, tvb(offset + 2, 2)):append_text(" [Undefined]")
  614. offset = offset + 4
  615. end,
  616. [5] = function()
  617. pinfo.cols.info:append(" [Shutdown]")
  618. pack_type_tree:append_text(" [Shutdown]")
  619. pack_type_tree:add(fields.msg_type, tvb(offset, 2))
  620. pack_type_tree:add(fields.reserve, tvb(offset + 2, 2)):append_text(" [Undefined]")
  621. offset = offset + 4
  622. -- Handle Additional Info, Timestamp and Destination Socket
  623. parse_three_param()
  624. end,
  625. [6] = function()
  626. pinfo.cols.info:append(" [ACKACK]")
  627. pack_type_tree:append_text(" [ACKACK]")
  628. pack_type_tree:add(fields.msg_type, tvb(offset, 2))
  629. pack_type_tree:add(fields.reserve, tvb(offset + 2, 2)):append_text(" [Undefined]")
  630. offset = offset + 4
  631. -- Handle ACK sequence number
  632. subtree:add(fields.ack_num, tvb(offset, 4))
  633. offset = offset + 4
  634. -- Handle Time Stamp
  635. subtree:add(fields.time_stamp, tvb(offset, 4)):append_text(" μs")
  636. offset = offset + 4
  637. -- Handle Destination Socket
  638. subtree:add(fields.dst_sock, tvb(offset, 4))
  639. offset = offset + 4
  640. -- Handle Control Information
  641. subtree:add(fields.ctl_info, tvb(offset, 4))
  642. offset = offset + 4
  643. end,
  644. [7] = function()
  645. pinfo.cols.info:append(" [Drop Request]")
  646. pack_type_tree:append_text(" [Drop Request]")
  647. pack_type_tree:add(fields.msg_type, tvb(offset, 2)):append_text(" [Drop Request]")
  648. pack_type_tree:add(fields.reserve, tvb(offset + 2, 2)):append_text(" [Undefined]")
  649. offset = offset + 4
  650. end,
  651. [8] = function()
  652. pinfo.cols.info:append(" [Peer Error]")
  653. pack_type_tree:append_text(" [Peer Error]")
  654. pack_type_tree:add(fields.msg_type, tvb(offset, 2)):append_text(" [Peer Error]")
  655. pack_type_tree:add(fields.reserve, tvb(offset + 2, 2)):append_text(" [Undefined]")
  656. offset = offset + 4
  657. end
  658. }
  659. -- Handle based on msg_type
  660. local case = switch[msg_type]
  661. if case then
  662. case()
  663. else
  664. -- default case
  665. subtree:add(fields.msg_type, tvb(offset, 2)):append_text(" [Unknown Message Type]")
  666. offset = offset + 4
  667. end
  668. else
  669. -- If type field is '0x7FFF', it means an extended type, Handle Reserve field
  670. offset = offset + 2
  671. local msg_ext_type = tvb(offset, 2):uint()
  672. if msg_ext_type == 0 then
  673. pinfo.cols.info:append(" [Message Extension]")
  674. pack_type_tree:add(fields.msg_ext_type, tvb(offset, 2)):append_text(" [Message Extension]")
  675. offset = offset + 2
  676. -- Handle Additional Info, Time Stamp and Destination Socket
  677. parse_three_param()
  678. -- Control information: defined by user
  679. elseif msg_ext_type == 1 or ext_type == 2 then
  680. if msg_ext_type == 1 then
  681. pack_type_tree:add(fields.msg_ext_type, tvb(offset, 2)):append_text(" [SRT Handshake Request]")
  682. pinfo.cols.info:append(" [SRT Handshake Request]")
  683. elseif msg_ext_type == 2 then
  684. pack_type_tree:add(fields.msg_ext_type, tvb(offset, 2)):append_text(" [SRT Handshake Response]")
  685. pinfo.cols.info:append(" [SRT Handshake Response]")
  686. end
  687. offset = offset + 2
  688. -- Ignore additional info (this field is not defined in this packet type)
  689. subtree:add(fields.additional_info, tvb(offset, 4)):append_text(" [undefined]")
  690. offset = offset + 4
  691. -- Handle Time Stamp
  692. subtree:add(fields.time_stamp, tvb(offset, 4)):append_text("μs")
  693. offset = offset + 4
  694. -- Handle Destination Socket
  695. subtree:add(fields.dst_sock, tvb(offset, 4))
  696. offset = offset + 4
  697. -- Handle SRT Version field
  698. subtree:add(fields.srt_version, tvb(offset, 4))
  699. offset = ofssset + 4
  700. -- Handle SRT Flags
  701. local SRT_flags_tree = subtree:add(fields.srt_flags, tvb(offset, 4))
  702. SRT_flags_tree:add(fields.srt_opt_tsbpdsnd, tvb(offset, 4))
  703. SRT_flags_tree:add(fields.srt_opt_tsbpdrcv, tvb(offset, 4))
  704. SRT_flags_tree:add(fields.srt_opt_haicrypt, tvb(offset, 4))
  705. SRT_flags_tree:add(fields.srt_opt_tlpktdrop, tvb(offset, 4))
  706. SRT_flags_tree:add(fields.srt_opt_nakreport, tvb(offset, 4))
  707. SRT_flags_tree:add(fields.srt_opt_rexmitflg, tvb(offset, 4))
  708. SRT_flags_tree:add(fields.srt_opt_stream, tvb(offset, 4))
  709. offset = offset + 4
  710. -- Handle TsbPd Resv
  711. subtree:add(fields.tsbpb_resv, tvb(offset, 2))
  712. offset = offset + 2
  713. -- Handle TsbPb Delay
  714. subtree:add(fields.tsbpb_delay, tvb(offset, 2))
  715. offset = offset + 2
  716. -- Handle Reserved field
  717. subtree:add(fields.reserve, tvb(offset, 4))
  718. offset = offset + 4
  719. elseif msg_ext_type == 3 or msg_ext_type == 4 then
  720. if msg_ext_type == 3 then
  721. pack_type_tree:add(fields.msg_ext_type, tvb(offset, 2)):append_text(" [Encryption Keying Material Request]")
  722. pinfo.cols.info:append(" [Encryption Keying Material Request]")
  723. elseif msg_ext_type == 4 then
  724. pack_type_tree:add(fields.msg_ext_type, tvb(offset, 2)):append_text(" [Encryption Keying Material Response]")
  725. pinfo.cols.info:append(" [Encryption Keying Material Response]")
  726. end
  727. offset = offset + 2
  728. -- Ignore additional info (this field is not defined in this packet type)
  729. subtree:add(fields.additional_info, tvb(offset, 4)):append_text(" [undefined]")
  730. offset = offset + 4
  731. -- Handle Timestamp
  732. subtree:add(fields.time_stamp, tvb(offset, 4)):append_text("μs")
  733. offset = offset + 4
  734. -- Handle Destination Socket
  735. subtree:add(fields.dst_sock, tvb(offset, 4))
  736. offset = offset + 4
  737. -- Handle KmErr
  738. if msg_ext_type == 4 then
  739. subtree:add(fields.km_err, tvb(offset, 4))
  740. offset = offset + 4
  741. return
  742. end
  743. -- The encrypted message is not handled
  744. end
  745. end
  746. else
  747. -- 0 -> Data Packet
  748. pack_type_tree:add(fields.pack_type, tvb(offset, 2))
  749. pack_type_tree:append_text(" (Data Packet)")
  750. local seq_num = tvb(offset, 4):uint()
  751. pinfo.cols.info:append(" (Data Packet)(Seq Num:" .. seq_num .. ")")
  752. -- The first 4 bytes are the package sequence number
  753. subtree:add(fields.seq_num, tvb(offset, 4))
  754. offset = offset + 4
  755. data_flag_info_tree = subtree:add(fields.data_flag_info_tree, tvb(offset, 1))
  756. -- Handle FF flag
  757. local FF_state = bit.rshift(bit.band(tvb(offset, 1):uint(), 0xC0), 6)
  758. if FF_state == 0 then
  759. data_flag_info_tree:append_text(" [Middle packet]")
  760. elseif FF_state == 1 then
  761. data_flag_info_tree:append_text(" [Last packet]")
  762. elseif FF_state == 2 then
  763. data_flag_info_tree:append_text(" [First packet]")
  764. else
  765. data_flag_info_tree:append_text(" [Single packet]")
  766. end
  767. data_flag_info_tree:add(fields.FF_state, tvb(offset, 1))
  768. -- Handle O flag
  769. local O_state = bit.rshift(bit.band(tvb(offset, 1):uint(), 0x20), 5)
  770. if O_state == 0 then
  771. data_flag_info_tree:append_text(" [Data delivered unordered]")
  772. else
  773. data_flag_info_tree:append_text(" [Data delivered in order]")
  774. end
  775. data_flag_info_tree:add(fields.O_state, tvb(offset, 1))
  776. -- Handle KK flag
  777. local KK_state = bit.rshift(bit.band(tvb(offset, 1):uint(), 0x18), 3)
  778. if KK_state == 1 then
  779. data_flag_info_tree:append_text(" [Encrypted with even key]")
  780. elseif KK_state == 2 then
  781. data_flag_info_tree:append_text(" [Encrypted with odd key]")
  782. end
  783. data_flag_info_tree:add(fields.KK_state, tvb(offset, 1))
  784. -- Handle R flag
  785. local R_state = bit.rshift(bit.band(tvb(offset, 1):uint(), 0x04), 2)
  786. if R_state == 1 then
  787. data_flag_info_tree:append_text(" [Retransmit packet]")
  788. pinfo.cols.info:append(" [Retransmit packet]")
  789. end
  790. data_flag_info_tree:add(fields.R_state, tvb(offset, 1))
  791. -- Handle message number
  792. local msg_num = tvb(offset, 4):uint()
  793. msg_num = bit.band(tvb(offset, 4):uint(), 0x03FFFFFF)
  794. -- subtree:add(fields.msg_num, bit.band(tvb(offset, 4):uint(), 0x03FFFFFF))
  795. subtree:add(fields.msg_num, tvb(offset, 4), msg_num)
  796. offset = offset + 4
  797. -- Handle Timestamp
  798. subtree:add(fields.time_stamp, tvb(offset, 4)):append_text(" μs")
  799. offset = offset + 4
  800. -- Handle destination socket
  801. subtree:add(fields.dst_sock, tvb(offset, 4))
  802. offset = offset + 4
  803. end
  804. end
  805. -- Add the protocol into udp table
  806. local port = 1935
  807. local function enable_dissector()
  808. DissectorTable.get("udp.port"):add(port, srt_dev)
  809. end
  810. -- Call it now - enabled by default
  811. enable_dissector()
  812. local function disable_dissector()
  813. DissectorTable.get("udp.port"):remove(port, srt_dev)
  814. end
  815. -- Prefs changed will listen at new port
  816. function srt_dev.prefs_changed()
  817. if port ~= srt_dev.prefs.srt_udp_port then
  818. if port ~= 0 then
  819. disable_dissector()
  820. end
  821. port = srt_dev.prefs.srt_udp_port
  822. if port ~= 0 then
  823. enable_dissector()
  824. end
  825. end
  826. end