ftci_dissector.lua 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. function ftci_dissector(buffer, pinfo, tree, FTCI_protocol, offset)
  2. -- Define ProtoFields for each of the fields in the structure
  3. -- Control Field 1 (1 byte)
  4. local f_session_id = ProtoField.uint8("FileTransfer.session_id", "File Transfer Session ID", base.DEC)
  5. local f_resume_context_mode = ProtoField.uint8("FileTransfer.resume_context_mode", "Resume Context Mode", base.DEC)
  6. local f_seq_loss_detection_mode = ProtoField.string("FileTransfer.seq_loss_detection_mode", "Seq Loss Detection Mode")
  7. local f_file_id = ProtoField.uint8("FileTransfer.file_id", "File ID", base.DEC)
  8. -- Control Field 2 (1 byte)
  9. local f_transfer_mode = ProtoField.uint8("FileTransfer.transfer_mode", "Transfer Mode (TXM)", base.DEC)
  10. local f_file_format = ProtoField.uint8("FileTransfer.file_format", "File Format", base.HEX)
  11. local f_unit_size = ProtoField.uint8("FileTransfer.unit_size", "Unit Size", base.DEC)
  12. local f_size_field_type = ProtoField.uint8("FileTransfer.size_field_type", "Size Field Type", base.HEX)
  13. -- Other fields
  14. local f_checksum = ProtoField.uint32("FileTransfer.checksum", "Checksum",base.HEX)
  15. local f_mtu_size = ProtoField.uint16("FileTransfer.mtu_size", "MTU Size", base.DEC)
  16. local f_rx_con_fail_timeout = ProtoField.uint16("FileTransfer.rx_con_fail_timeout", "Receiver Connection Fail Timeout", base.DEC)
  17. local f_major_version = ProtoField.uint8("FileTransfer.major_version", "Major Version", base.DEC)
  18. local f_minor_version = ProtoField.uint8("FileTransfer.minor_version", "Minor Version", base.DEC)
  19. local f_sct_instance_key = ProtoField.uint32("FileTransfer.sct_instance_key", "SCT Instance Key", base.DEC)
  20. local f_file_mem_size = ProtoField.bytes("FileTransfer.file_mem_size", "File/Mem Size")
  21. local f_dest_storage = ProtoField.uint8("FileTransfer.dest_storage", "Destination Storage", base.DEC)
  22. local f_dest_mem_address = ProtoField.uint32("FileTransfer.dest_mem_address", "Destination Memory Address", base.HEX)
  23. local f_file_path_len = ProtoField.uint8("FileTransfer.file_path_len", "File /Name Length", base.DEC)
  24. local f_file_path = ProtoField.string("FileTransfer.file_path", "File /Name")
  25. -- Add fields to protocol
  26. FTCI_protocol.fields = {
  27. f_session_id, f_resume_context_mode, f_seq_loss_detection_mode, f_file_id,
  28. f_transfer_mode, f_file_format, f_unit_size, f_size_field_type,
  29. f_checksum, f_mtu_size, f_rx_con_fail_timeout, f_major_version, f_minor_version,
  30. f_sct_instance_key, f_file_mem_size, f_dest_storage, f_dest_mem_address,
  31. f_file_path_len, f_file_path
  32. }
  33. -- Loop through the data instances
  34. -- for i = 1, num_of_instance do
  35. -- Add the new structure data as a subtree
  36. local subtree = tree:add( FTCI_protocol, buffer(), "FTCI")
  37. -- dissect CONTROL FIELD 1 (1 byte)
  38. local w=0
  39. local control_field1 = buffer(offset, 1):le_uint()
  40. local session_id = control_field1 & 0x07
  41. local resume_context_mode = (control_field1 >>3) & 0x01
  42. local seq_loss_detection_mode = (control_field1 >> 4) & 0x01
  43. local file_id = (control_field1 >>5) & 0x07
  44. subtree:add(f_session_id, session_id)
  45. subtree:add(f_resume_context_mode, resume_context_mode)
  46. if seq_loss_detection_mode == 0 then
  47. subtree:add(f_seq_loss_detection_mode, "UNACK")
  48. else
  49. subtree:add(f_seq_loss_detection_mode, "ACK")
  50. end
  51. subtree:add(f_file_id, file_id)
  52. offset = offset + 1
  53. -- dissect CONTROL FIELD 2 (1 byte)
  54. local control_field2 = buffer(offset, 1):le_uint()
  55. local transfer_mode = (control_field2 >>0) & 0x01 --txm
  56. local file_format = (control_field2 >>1) & 0x07
  57. local unit_size = (control_field2 >>4) & 0x03
  58. local size_field_type = (control_field2 >>6) & 0x03
  59. if size_field_type == 0x01 then
  60. w=0
  61. elseif size_field_type == 0x02 then
  62. w=1
  63. elseif size_field_type > 0x02 then
  64. w=2
  65. end
  66. subtree:add(f_transfer_mode, transfer_mode)
  67. subtree:add(f_file_format, file_format)
  68. subtree:add(f_unit_size, unit_size)
  69. subtree:add(f_size_field_type, size_field_type)
  70. offset = offset + 1
  71. -- dissect MTU Size (2 bytes)
  72. local mtu_size = buffer(offset, 2):le_uint()
  73. subtree:add(f_mtu_size, mtu_size)
  74. offset = offset + 2
  75. -- dissect Checksum (4 bytes)
  76. local checksum = buffer(offset, 4):le_uint()
  77. subtree:add(f_checksum, checksum)
  78. offset = offset + 4
  79. -- dissect RX Connection Fail Timeout (2 bytes)
  80. local rx_con_fail_timeout = buffer(offset, 2):le_uint()
  81. subtree:add(f_rx_con_fail_timeout, rx_con_fail_timeout)
  82. offset = offset + 2
  83. -- dissect Major Version (1 byte)
  84. local major_version = buffer(offset, 1):le_uint()
  85. subtree:add(f_major_version, major_version)
  86. offset = offset + 1
  87. -- dissect Minor Version (1 byte)
  88. local minor_version = buffer(offset, 1):le_uint()
  89. subtree:add(f_minor_version, minor_version)
  90. offset = offset + 1
  91. -- dissect SCT Instance Key (4 bytes)
  92. local sct_instance_key = buffer(offset, 4):le_uint()
  93. subtree:add(f_sct_instance_key, sct_instance_key)
  94. offset = offset + 4
  95. -- dissect File/Mem Size (1-5 bytes, variable size)
  96. --if unit_size then
  97. local file_mem_size_len = unit_size
  98. local file_mem_size = buffer(offset , file_mem_size_len)
  99. subtree:add(f_file_mem_size, file_mem_size)
  100. offset = offset + file_mem_size_len
  101. --end
  102. -- dissect Destination Storage (1 byte)
  103. if transfer_mode == 0x01 then
  104. local dest_storage = buffer(offset, 1):le_uint()
  105. subtree:add(f_dest_storage, dest_storage)
  106. offset = offset + 1
  107. -- dissect Destination Memory Address (4 bytes)
  108. local dest_mem_address = buffer(offset, 4):le_uint()
  109. subtree:add(f_dest_mem_address, dest_mem_address)
  110. offset = offset + 4
  111. end
  112. -- dissect File Path Length (1 byte)
  113. local file_path_len = buffer(offset + w, 1):le_uint()
  114. subtree:add(f_file_path_len, file_path_len)
  115. --file_path_len=200
  116. offset = offset + 1
  117. -- dissect File Path/Name (variable length)
  118. local substring_start = 0
  119. local count = 0
  120. local file_path = buffer(offset, file_path_len):string()
  121. for i = file_path_len-1, 1, -1 do
  122. local char=string.sub(file_path, i, i)
  123. if char:match("\\.") then
  124. substring_start = i
  125. if count == 1 then
  126. break -- Exit the loop once we find a special character
  127. end
  128. count = count +1
  129. end
  130. end
  131. local new_string = string.sub(file_path, substring_start + 1)
  132. subtree:add(f_file_path, new_string)
  133. offset = offset + file_path_len
  134. -- end
  135. end