ftsr_dissector.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. function ftsr_dissector(buffer, pinfo, tree, ftsr_protocol, offset)
  2. -- Define the fields for the protocol
  3. local f_session_id = ProtoField.uint8("ftsr_protocol.session_id", "Session ID", base.DEC)
  4. local f_status_code = ProtoField.uint8("ftsr_protocol.status_code", "Response Status Code", base.HEX)
  5. local f_missing_count = ProtoField.uint8("ftsr_protocol.missing_count", "Total Missing Data Segment Count", base.DEC)
  6. local f_reserved = ProtoField.uint16("ftsr_protocol.reserved1", "Reserved", base.HEX)
  7. local f_suspend_timeout_or_sct_db = ProtoField.uint32("ftsr_protocol.suspend_timeout_or_sct_db", "Suspend Waiting Timeout or SCT Database", base.HEX)
  8. local f_missing_segment_seq = ProtoField.bytes("ftsr_protocol.missing_segment_seq", "Missing Segment Sequence Numbers", base.SPACE)
  9. -- Add the fields to the protocol
  10. ftsr_protocol.fields = { f_session_id, f_status_code, f_reserved, f_missing_count, f_suspend_timeout_or_sct_db, f_missing_segment_seq }
  11. local subtree = tree:add(ftsr_protocol, buffer(), "FTSR")
  12. -- Parse the CONTROL FIELD (1 byte)
  13. local control_field = buffer(offset, 1):le_uint()
  14. local session_id = (control_field & 0x07) -- Bits 0-2 for Session ID (3 bits)
  15. local status_code = (control_field >> 3) & 0x1f -- Bits 3-7 for Status Code (5 bits)
  16. -- Add fields to the protocol tree
  17. subtree:add(f_session_id, session_id)
  18. if status_code == 0 then
  19. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR RECEIVER READY (0x%02X)", status_code))
  20. elseif status_code == 1 then
  21. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR RX API NOT FOUND (0x%02X)", status_code))
  22. elseif status_code == 2 then
  23. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR SUSPEND (0x%02X)", status_code))
  24. elseif status_code == 3 then
  25. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR RESUME (0x%02X)", status_code))
  26. elseif status_code == 4 then
  27. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR STOP TRANSFER (0x%02X)", status_code))
  28. elseif status_code == 5 then
  29. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR MISSING PACKETS (0x%02X)", status_code))
  30. elseif status_code == 6 then
  31. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR CRC FAIL (0x%02X)", status_code))
  32. elseif status_code == 7 then
  33. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR FILE NOT FOUND (0x%02X)", status_code))
  34. elseif status_code == 8 then
  35. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR HEAD CHANGE (0x%02X)", status_code))
  36. elseif status_code == 9 then
  37. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR CANCELLED BY SUSPEND TIMEOUT (0x%02X)", status_code))
  38. elseif status_code == 10 then
  39. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR SUSPEND SAVE CONTEXT (0x%02X)", status_code))
  40. elseif status_code == 11 then
  41. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR RESUME SAVE CONTEXT (0x%02X)", status_code))
  42. elseif status_code == 12 then
  43. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR ACK (0x%02X)", status_code))
  44. elseif status_code == 13 then
  45. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR NAK (0x%02X)", status_code))
  46. elseif status_code == 14 then
  47. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR PING (0x%02X)", status_code))
  48. elseif status_code == 15 then
  49. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR DOWNLOAD COMPLETE (0x%02X)", status_code))
  50. elseif status_code == 16 then
  51. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR TERMINATE RX NODE (0x%02X)", status_code))
  52. elseif status_code == 17 then
  53. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR INVALID SESSION ID (0x%02X)", status_code))
  54. elseif status_code == 18 then
  55. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR DOWNLOAD PTR NULL (0x%02X)", status_code))
  56. elseif status_code == 19 then
  57. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR FTM BUSY (0x%02X)", status_code))
  58. elseif status_code == 20 then
  59. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR INVALID CFG INPUT (0x%02X)", status_code))
  60. elseif status_code == 21 then
  61. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR RX SYSTEM ERROR (0x%02X)", status_code))
  62. elseif status_code == 22 then
  63. subtree:add(f_status_code, status_code):set_text(string.format("RESPONSE STATUS CODE: FTSR VERSION MISMATCH (0x%02X)", status_code))
  64. end
  65. offset = offset + 1 -- Move to the next byte
  66. -- Parse the MISSING DATA SEGMENT COUNT (1 byte)
  67. if status_code == 0x05 then
  68. local missing_count = buffer(offset, 1):uint()
  69. subtree:add(f_missing_count, missing_count)
  70. offset = offset + 1
  71. end
  72. -- Parse Reserved bytes (2 bytes)
  73. local reserved_bytes = buffer(offset, 2)
  74. subtree:add(f_reserved, reserved_bytes)
  75. offset = offset + 2
  76. -- Parse SUSPEND WAITING TIMEOUT OR SCT DATABASE (4 bytes)
  77. -- This field is present based on the Response Status Code
  78. if status_code == 0x02 or status_code == 0x0A or status_code == 0x0B then
  79. local suspend_timeout_or_sct_db = buffer(offset, 4)
  80. subtree:add(f_suspend_timeout_or_sct_db, suspend_timeout_or_sct_db)
  81. offset = offset + 4
  82. end
  83. -- Parse the MISSING SEGMENT SEQUENCE NUMBERS (variable length)
  84. if status_code == 0x05 then
  85. -- Missing segment sequence numbers are present when status code is 0x05
  86. local missing_seq_start = offset
  87. local missing_seq_count = missing_count
  88. local missing_segments = buffer(missing_seq_start, missing_seq_count)
  89. subtree:add(f_missing_segment_seq, missing_segments)
  90. end
  91. end