tc_tm_protocols.lua 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  1. -- Define the protocol
  2. TC_TM_PROTOCOL = Proto("tc_tm", "TC_TM")
  3. local f_sof1 = ProtoField.uint8("TC_TM_PROTOCOL.sof1", "SOF1", base.HEX)
  4. local f_sof2 = ProtoField.uint8("TC_TM_PROTOCOL.sof2", "SOF2", base.HEX)
  5. local f_tm_ctrl = ProtoField.uint8("TC_TM_PROTOCOL.tm_ctrl", "TM Ctrl", base.HEX)
  6. local f_GS_Id = ProtoField.uint8("TC_TM_PROTOCOL.GS_Id", "GS Id", base.HEX)
  7. local f_timestamp = ProtoField.string("TC_TM_PROTOCOL.timestamp", "Timestamp", base.NONE)
  8. local f_ist = ProtoField.string("TC_TM_PROTOCOL.timestamp_ist", "IST TIME ", base.NONE)
  9. local f_pst = ProtoField.string("TC_TM_PROTOCOL.timestamp_pst", "PST TIME", base.NONE)
  10. local f_est = ProtoField.string("TC_TM_PROTOCOL.timestamp_est", "EST TIME", base.NONE)
  11. local f_mt = ProtoField.string("TC_TM_PROTOCOL.timestamp", "MST TIME", base.NONE)
  12. local f_sequence_no = ProtoField.uint16("TC_TM_PROTOCOL.sequence_no", "Sequence No", base.DEC)
  13. local f_sat_id = ProtoField.uint16("TC_TM_PROTOCOL.sat_id", "SAT Id", base.DEC)
  14. local f_qos = ProtoField.uint8("TC_TM_PROTOCOL.qos", "QoS", base.DEC)
  15. local f_sa_id = ProtoField.uint16("TC_TM_PROTOCOL.sa_id", "SA Id", base.DEC)
  16. local f_da_id = ProtoField.uint16("TC_TM_PROTOCOL.da_id", "DA Id", base.DEC)
  17. local f_rm_id = ProtoField.uint8("TC_TM_PROTOCOL.rm_id", "RM Id", base.DEC)
  18. local f_tm_id = ProtoField.uint16("TC_TM_PROTOCOL.tm_id", "TM Id", base.DEC)
  19. local f_co_id = ProtoField.uint16("TC_TM_PROTOCOL.co_id", "Co Id", base.DEC)
  20. local f_tm_len = ProtoField.uint16("TC_TM_PROTOCOL.tm_len", "TM Len", base.DEC)
  21. local f_tm_data = ProtoField.uint8("TC_TM_PROTOCOL.tm_data", "TM Data", base.DEC)
  22. local f_ext_header_len = ProtoField.uint8("TC_TM_PROTOCOL.ext_header_len", "Ext Header Len", base.DEC)
  23. local f_ext_header_data = ProtoField.uint8("TC_TM_PROTOCOL.ext_header_data", "Ext Header Data", base.DEC)
  24. local f_crc = ProtoField.uint8("TC_TM_PROTOCOL.crc", "CRC", base.DEC)
  25. local f_c_mac = ProtoField.uint8("TC_TM_PROTOCOL.c_mac", "C MAC", base.DEC)
  26. local f_eof1 = ProtoField.uint8("TC_TM_PROTOCOL.eof1", "EOF", base.HEX)
  27. local f_tc_id = ProtoField.uint16("TC_TM_PROTOCOL.tc_id", "TC Id", base.DEC)
  28. local f_tc_len = ProtoField.uint16("TC_TM_PROTOCOL.tc_len", "TC Len", base.DEC)
  29. local f_tc_data = ProtoField.uint32("TC_TM_PROTOCOL.tc_data", "TC Data", base.DEC)
  30. -- Add the fields to the protocol
  31. TC_TM_PROTOCOL.fields = {
  32. f_sof1, f_sof2, f_tm_ctrl,f_GS_Id, f_timestamp, f_sequence_no, f_sat_id, f_ist, f_pst, f_est, f_mt,
  33. f_qos, f_sa_id, f_da_id, f_rm_id, f_tm_id, f_co_id, f_tm_len, f_tm_data,
  34. f_ext_header_len, f_ext_header_data, f_crc, f_c_mac, f_eof1,f_tc_id ,f_tc_len ,f_tc_data
  35. }
  36. ------------------------------------------------------------------------------------------------------------------------------------
  37. function TC_dissector(buffer, pinfo, tree)
  38. --Set the protocol coloumn name in wireshark
  39. local subtree = tree:add(TC_TM_PROTOCOL, buffer(), "TELECOMMAND")
  40. -- Dissect SOF1 and SOF2
  41. local offset = 0
  42. for i = 0,1000 do
  43. local data = buffer(i,1):le_uint()
  44. if data == 0xa5 then
  45. offset = i
  46. break
  47. end
  48. end
  49. subtree:add(f_sof1 , buffer(offset, 1))
  50. offset = offset + 1
  51. subtree:add(f_sof2, buffer(offset, 1))
  52. offset = offset + 1
  53. -- Dissect TC Control byte (TC_Ctrl)
  54. local tc_ctrl = buffer(offset, 1):le_uint() -- Get the value of TC Ctrl byte
  55. subtree:add(f_tm_ctrl , tc_ctrl)
  56. offset = offset + 1
  57. -- Dissect Timestamp (4 bytes)
  58. if buffer:len() >= offset + 4 then
  59. local timestamp = buffer(offset, 4):le_uint()
  60. local utc_time = os.date("!%Y-%m-%d %H:%M:%S", timestamp)
  61. subtree:add(f_timestamp, timestamp.." ".."("..utc_time..")" )
  62. local time = timestamp + 19800
  63. local ist_time = os.date("!%Y-%m-%d %H:%M:%S", time)
  64. subtree:add(f_ist, ist_time)
  65. time = timestamp - 28800
  66. local pst_time = os.date("!%Y-%m-%d %H:%M:%S", time)
  67. subtree:add(f_pst, pst_time)
  68. time = timestamp - 18000
  69. local est_time = os.date("!%Y-%m-%d %H:%M:%S", time)
  70. subtree:add(f_est, est_time)
  71. time = timestamp - 25200
  72. local mt_time = os.date("!%Y-%m-%d %H:%M:%S", time)
  73. subtree:add(f_mt, mt_time)
  74. offset = offset + 4
  75. else
  76. subtree:add(f_timestamp, "Invalid data (timestamp)")
  77. end
  78. -- Dissect Sequence No (2 bytes)
  79. if buffer:len() >= offset + 2 then
  80. local sequence = buffer(offset, 2):le_uint()
  81. subtree:add(f_sequence_no, sequence)
  82. offset = offset + 2
  83. else
  84. subtree:add(f_sequence_no, "Invalid data (sequence number)")
  85. end
  86. -- Dissect SAT_Id (1 byte)
  87. if buffer:len() >= offset + 1 then
  88. local sat_id = buffer(offset, 1):uint() -- Get SAT Id (1st byte)
  89. --offset = offset + 1
  90. if bit.band(sat_id, 0x80) == 0x80 then --if 7th bit is set and
  91. if buffer:len() >= offset + 1 then
  92. local second = buffer(offset, 2):le_uint()
  93. if bit.band(second, 0x8000) == 0x0000 then --and 15th bit is set then unset 15th bit
  94. sat_id = buffer(offset, 2):le_uint()
  95. sat_id = bit.band(sat_id, 0xFF7F)
  96. offset = offset + 1
  97. else
  98. sat_id = buffer(offset, 2):le_uint()
  99. sat_id = bit.band(sat_id, 0x7FFF) -- and 15th bit is unset then unset the 7th bit
  100. offset = offset + 1
  101. end
  102. end
  103. end
  104. subtree:add(f_sat_id, sat_id)
  105. offset = offset + 1
  106. end
  107. -- Dissect GS_Id (1 byte)
  108. if buffer:len() >= offset + 1 then
  109. local gs_id = buffer(offset, 1):uint() -- Get SAT Id (1st byte)
  110. --offset = offset + 1
  111. if bit.band(gs_id, 0x80) == 0x80 then
  112. if buffer:len() >= offset + 1 then
  113. local second = buffer(offset, 2):le_uint()
  114. if bit.band(second, 0x8000) == 0x0000 then
  115. gs_id = buffer(offset, 2):le_uint()
  116. gs_id = bit.band(gs_id, 0xFF7F)
  117. offset = offset + 1
  118. else
  119. gs_id = buffer(offset, 2):le_uint()
  120. gs_id = bit.band(gs_id, 0x7FFF)
  121. offset = offset + 1
  122. end
  123. end
  124. end
  125. subtree:add(f_GS_Id, gs_id)
  126. offset = offset + 1
  127. end
  128. -- Dissect QoS (1 byte)
  129. if buffer:len() >= offset + 1 then
  130. subtree:add(f_qos, buffer(offset, 1))
  131. offset = offset + 1
  132. end
  133. -- Dissect SA_Id (Source Application ID) and DA_Id (Destination Application ID)
  134. if buffer:len() >= offset + 1 then
  135. local sa_id = buffer(offset, 1):uint() -- Get source Application Id (1st byte)
  136. --offset = offset + 1
  137. if bit.band(sa_id, 0x80) == 0x80 then
  138. if buffer:len() >= offset + 1 then
  139. local second = buffer(offset, 2):le_uint()
  140. if bit.band(second, 0x8000) == 0x0000 then
  141. sa_id = buffer(offset, 2):le_uint()
  142. sa_id = bit.band(sa_id, 0xFF7F)
  143. offset = offset + 1
  144. else
  145. sa_id = buffer(offset, 2):le_uint()
  146. sa_id = bit.band(sa_id, 0x7FFF)
  147. offset = offset + 1
  148. end
  149. end
  150. end
  151. subtree:add(f_sa_id, sa_id)
  152. offset = offset + 1
  153. end
  154. if buffer:len() >= offset + 1 then
  155. --subtree:add(f_DA_Id, buffer(offset, 1))
  156. local da_id = buffer(offset, 1):le_uint() -- Get Destination Application Id (1st byte)
  157. --offset = offset + 1
  158. if bit.band(da_id, 0x80) == 0x80 then
  159. if buffer:len() >= offset + 1 then
  160. local second = buffer(offset, 2):le_uint()
  161. if bit.band(second, 0x8000) == 0x0000 then
  162. da_id = buffer(offset, 2):le_uint()
  163. da_id = bit.band(da_id, 0xFF7F)
  164. offset = offset + 1
  165. else
  166. da_id = buffer(offset, 2):le_uint()
  167. da_id = bit.band(da_id, 0x7FFF)
  168. offset = offset + 1
  169. end
  170. end
  171. end
  172. subtree:add(f_da_id, da_id)
  173. offset = offset + 1
  174. end
  175. -- Dissect RM_Id (1 byte)
  176. if buffer:len() >= offset + 1 then
  177. subtree:add(f_rm_id, buffer(offset, 1))
  178. offset = offset + 1
  179. end
  180. -- Dissect TC_Id (2 bytes)
  181. -- Dissect TC_Id (2 bytes)
  182. local info_display
  183. local tc_id = buffer(offset, 1):le_uint() -- Read 1 byte for tc_id
  184. if tc_id == 100 or tc_id == 102 or tc_id == 103 then
  185. pinfo.cols.protocol = "FTM(UL)"
  186. elseif tc_id == 105 then
  187. pinfo.cols.protocol = "FTM(DL)"
  188. else
  189. pinfo.cols.protocol = "TELECOMMAND"
  190. end
  191. if buffer:len() >= offset + 2 then -- Ensure enough data is available to read 2 bytes
  192. -- Check if the 7th bit (0x80) is set in tc_id
  193. if bit.band(tc_id, 0x80) == 0x80 then
  194. if buffer:len() >= offset + 2 then -- Ensure enough data for the next 2 bytes
  195. local second = buffer(offset, 2):le_uint()
  196. if bit.band(second, 0x8000) == 0x0000 then
  197. tc_id = buffer(offset, 2):le_uint()
  198. tc_id = bit.band(tc_id, 0xFF7F)
  199. offset = offset + 1
  200. else
  201. tc_id = buffer(offset, 2):le_uint()
  202. tc_id = bit.band(tc_id, 0x7FFF)
  203. offset = offset + 1
  204. end
  205. end
  206. end
  207. -- Add tc_id to the subtree (display in dissection tree)
  208. subtree:add(f_tc_id, tc_id)
  209. -- Move the offset forward by 1 (since we initially read 1 byte)
  210. offset = offset + 1
  211. end
  212. -- Dissect TC_Len (2 bytes)
  213. local tc_len = 0 -- Declare tc_len as a local variable here
  214. if buffer:len() >= offset + 2 then
  215. tc_len = buffer(offset, 2):le_uint()
  216. subtree:add(f_tc_len, tc_len)
  217. offset = offset + 2
  218. end
  219. -- Dissect TC_Data (variable length)
  220. --local subtree2 = subtree:add(TC_TM_PROTOCOL, buffer(), TC_DATA())
  221. local data
  222. if buffer:len() >= offset + tc_len then
  223. if tc_len == 0 then
  224. subtree:add("TC DATA : NIL")
  225. else
  226. if tc_id == 621 then
  227. require("hm_dissector")
  228. data = HM_TC_dissector(buffer, pinfo, tree, TC_TM_PROTOCOL, offset)
  229. offset = offset + tc_len
  230. elseif tc_id == 100 then
  231. require("ftci_dissector")
  232. ftci_dissector(buffer, pinfo, tree, TC_TM_PROTOCOL, offset)
  233. offset = offset + tc_len
  234. elseif tc_id == 103 then
  235. require("ftfci_dissector")
  236. ftfci_dissector(buffer, pinfo, tree, TC_TM_PROTOCOL, offset)
  237. offset = offset + tc_len
  238. elseif tc_id == 102 then
  239. require("ftds_dissector")
  240. ftds_dissector(buffer, pinfo, tree, TC_TM_PROTOCOL, offset)
  241. offset = offset + tc_len
  242. elseif tc_id == 105 then
  243. require("ftsr_dissector")
  244. ftsr_dissector(buffer, pinfo, tree, TC_TM_PROTOCOL, offset)
  245. offset = offset + tc_len
  246. elseif tc_id == 202 then
  247. require("eps_wr_stored_param")
  248. eps_tc_wr_stored_param_dissector(buffer, pinfo, tree, TC_TM_PROTOCOL, offset)
  249. offset = offset + tc_len
  250. elseif tc_id == 211 then
  251. require("tc_eps_set_cntrl_chnl_state")
  252. tc_eps_set_cntrl_chnl_state(buffer, pinfo, tree, TC_TM_PROTOCOL, offset)
  253. offset = offset + tc_len
  254. else
  255. for i=0,tc_len - 1 do
  256. subtree:add(f_tc_data, buffer(offset, 1))
  257. offset = offset + 1
  258. end
  259. end
  260. end
  261. end
  262. -- Check if we can dissect Ext_Header_Len
  263. if bit.band(tc_ctrl, 0x80) == 0x80 and buffer:len() >= offset + 1 then
  264. subtree:add(f_ext_header_len, buffer(offset, 1))
  265. local ext_header_len = buffer(offset, 1):uint()
  266. offset = offset + 1
  267. if buffer:len() >= offset + ext_header_len then
  268. for i=1,ext_header_len do
  269. subtree:add(f_ext_header_data, buffer(offset, 1))
  270. offset = offset + 1
  271. end
  272. end
  273. end
  274. -- Dissect CRC (1 byte)
  275. if buffer:len() >= offset + 1 then
  276. subtree:add(f_crc, buffer(offset, 1))
  277. offset = offset + 1
  278. end
  279. -- Dissect C-MAC/H-MAC (if TC Ctrl bit 4 is set)
  280. if bit.band(tc_ctrl, 0x10) == 0x10 and buffer:len() >= offset + 32 then
  281. for i=1,32 do
  282. subtree:add(f_c_mac, buffer(offset, 1))
  283. offset = offset + 1
  284. end
  285. end
  286. -- Dissect EOF (1 byte)
  287. if buffer:len() >= offset + 1 then
  288. subtree:add(f_eof1, buffer(offset, 1))
  289. end
  290. local string
  291. if tc_id == 621 then
  292. local switch = {
  293. [9] = function() return "EPS" end,
  294. [22] = function() return "ADCS" end,
  295. [14] = function() return "SBAND" end,
  296. [15] = function() return "UHF" end,
  297. [42] = function() return "SENSOR" end,
  298. [27] = function() return "OBC" end
  299. }
  300. string = (switch[data] or function() return "All Module" end)()
  301. info_display= {buffer(11, 2):le_uint(),buffer(7, 4):le_uint() ,tc_id, string} --- for info display in wireshark
  302. pinfo.cols.info ="seq_no = " ..info_display[1] ..", TS = " ..info_display[2]..", TC_ID = "..info_display[3]..", Module = " ..info_display[4] -- for info display in wireshark
  303. elseif tc_id == 100 then
  304. string = "FTCI FRAME"
  305. info_display= {buffer(11, 2):le_uint(),buffer(7, 4):le_uint() ,tc_id, string} --- for info display in wireshark
  306. pinfo.cols.info ="seq_no = " ..info_display[1] ..", TS = " ..info_display[2]..", TC_ID = "..info_display[3]..", " ..info_display[4] -- for info display in wireshark
  307. elseif tc_id == 105 then
  308. string = "FTSR FRAME"
  309. info_display= {buffer(11, 2):le_uint(),buffer(7, 4):le_uint() ,tc_id, string} --- for info display in wireshark
  310. pinfo.cols.info ="seq_no = " ..info_display[1] ..", TS = " ..info_display[2]..", TC_ID = "..info_display[3]..", " ..info_display[4] -- for info display in wireshark
  311. elseif tc_id == 102 then
  312. string = "FTDS FRAME"
  313. info_display= {buffer(11, 2):le_uint(),buffer(7, 4):le_uint() ,tc_id, string} --- for info display in wireshark
  314. pinfo.cols.info ="seq_no = " ..info_display[1] ..", TS = " ..info_display[2]..", TC_ID = "..info_display[3]..", " ..info_display[4] -- for info display in wireshark
  315. elseif tc_id == 103 then
  316. string = "FTFCI FRAME"
  317. info_display= {buffer(11, 2):le_uint(),buffer(7, 4):le_uint() ,tc_id, string} --- for info display in wireshark
  318. pinfo.cols.info ="seq_no = " ..info_display[1] ..", TS = " ..info_display[2]..", TC_ID = "..info_display[3]..", " ..info_display[4] -- for info display in wireshark
  319. else
  320. info_display= {buffer(11, 2):le_uint(),buffer(7, 4):le_uint() ,tc_id} --- for info display in wireshark
  321. pinfo.cols.info ="seq_no = " ..info_display[1] ..", TS = " ..info_display[2]..", TC_ID = "..info_display[3] -- for info display in wireshark
  322. end
  323. end
  324. -----------------------------------------------------------------------------------------------------------------------------------
  325. function TM_dissector(buffer, pinfo, tree) -- OBC to GS
  326. local subtree = tree:add(TC_TM_PROTOCOL, buffer(), "TELEMETRY")
  327. -- Extract the fields in order as defined in the structure
  328. local add
  329. for i = 0,1000 do
  330. local data = buffer(i,1):le_uint()
  331. if data == 0xa5 then
  332. add = i
  333. break
  334. end
  335. end
  336. subtree:add(f_sof1, buffer(add, 1):le_uint()) -- SOF1 in HEX
  337. add = add + 1
  338. subtree:add(f_sof2, buffer(add, 1):le_uint()) -- SOF2 in HEX
  339. add = add + 1
  340. local tm_ctrl = buffer(add, 1):le_uint()
  341. subtree:add(f_tm_ctrl, buffer(add, 1):le_uint()) -- TM Ctrl in HEX
  342. add = add + 1
  343. -- Dissect timestamp
  344. local timestamp = buffer(add, 4):le_uint()
  345. local utc_time = os.date("!%Y-%m-%d %H:%M:%S", timestamp)
  346. subtree:add(f_timestamp, timestamp.." ".."("..utc_time..")" )
  347. local time = timestamp + 19800
  348. local ist_time = os.date("!%Y-%m-%d %H:%M:%S", time)
  349. subtree:add(f_ist, ist_time)
  350. time = timestamp - 28800
  351. local pst_time = os.date("!%Y-%m-%d %H:%M:%S", time)
  352. subtree:add(f_pst, pst_time)
  353. time = timestamp - 18000
  354. local est_time = os.date("!%Y-%m-%d %H:%M:%S", time)
  355. subtree:add(f_est, est_time)
  356. time = timestamp - 25200
  357. local mt_time = os.date("!%Y-%m-%d %H:%M:%S", time)
  358. subtree:add(f_mt, mt_time)
  359. add = add + 4
  360. subtree:add(f_sequence_no, buffer(add, 2):le_uint()) -- Sequence No in HEX
  361. add = add + 2
  362. -- My logic for SAT Id
  363. local magic = buffer(add, 1):le_uint()
  364. if bit.band(magic, 0x80) == 0 then
  365. subtree:add(f_sat_id, buffer(add, 1):le_uint()) -- SAT Id in HEX
  366. add=add+1
  367. else
  368. magic=buffer(add, 2):le_uint()
  369. local dummy=magic & 0x8000 --to check 7th byte is 1
  370. if dummy == 0 then
  371. magic = magic & 0xff7f -- if 15th bit is 0 set 7th bit 0
  372. else
  373. magic = magic & 0x7fff -- if 15 bit is 1 set 15th bit to 0
  374. end
  375. subtree:add(f_sat_id, magic) -- SAT Id in HEX
  376. add=add+2
  377. end
  378. -- QoS in HEX
  379. subtree:add(f_qos, buffer(add, 1):le_uint())
  380. add=add+1
  381. -- My logic for SA Id
  382. magic = buffer(add, 1):le_uint()
  383. if bit.band(magic, 0x80) == 0 then
  384. subtree:add(f_sa_id, buffer(add, 1):le_uint()) -- SA Id in HEX
  385. add=add+1
  386. else
  387. magic=buffer(add, 2):le_uint()
  388. local dummy=magic & 0x8000
  389. if dummy == 0 then
  390. magic = magic & 0xff7f
  391. else
  392. magic = magic & 0x7fff
  393. end
  394. subtree:add(f_sa_id,magic) -- SA Id in HEX
  395. add=add+2
  396. end
  397. -- My logic for DA Id
  398. magic = buffer(add, 1):uint()
  399. if bit.band(magic, 0x80) == 0 then
  400. subtree:add(f_da_id, buffer(add, 1):le_uint()) -- DA Id in HEX
  401. add=add+1
  402. else
  403. magic=buffer(add, 2):le_uint()
  404. local dummy=magic & 0x8000
  405. if dummy == 0 then
  406. magic = magic & 0xff7f
  407. else
  408. magic = magic & 0x7fff
  409. end
  410. subtree:add(f_da_id, magic) -- DA Id in HEX
  411. add=add+2
  412. end
  413. -- RM Id in HEX
  414. subtree:add(f_rm_id, buffer(add, 1):le_uint())
  415. add=add+1
  416. -- My logic for TM Id
  417. local info_display -- for display in wireshark
  418. local tm_id
  419. magic = buffer(add, 1):uint()
  420. if bit.band(magic, 0x80) == 0 then
  421. subtree:add(f_tm_id, buffer(add, 1):le_uint()) -- TM Id in HEX
  422. info_display= {buffer(11, 2):le_uint(),buffer(7, 4):le_uint() ,buffer(add, 1):le_uint()} --- for info display in wireshark
  423. add=add+1
  424. else
  425. magic=buffer(add, 2):le_uint()
  426. local dummy=magic & 0x8000
  427. if dummy == 0 then
  428. magic = magic & 0xff7f
  429. else
  430. magic = magic & 0x7fff
  431. end
  432. subtree:add(f_tm_id, magic) -- TM Id in HEX
  433. add=add+2
  434. end
  435. tm_id = magic
  436. if tm_id == 104 or tm_id == 106 or tm_id == 107 then
  437. pinfo.cols.protocol = "FTM(DL)"
  438. elseif tm_id == 101 then
  439. pinfo.cols.protocol = "FTM(UL)"
  440. else
  441. pinfo.cols.protocol = "TELEMETRY"
  442. end
  443. -- Co Id in HEX
  444. subtree:add(f_co_id, buffer(add, 2):le_uint())
  445. add=add+2
  446. -- TM Len in HEX
  447. local tm_len
  448. magic = buffer(add, 2):le_uint()
  449. tm_len = magic
  450. subtree:add(f_tm_len, buffer(add, 2):le_uint())
  451. add=add+2
  452. -- logic for TM Data
  453. local array
  454. --local subtree2 = subtree:add(TC_TM_PROTOCOL, buffer(), "TM_DATA")
  455. -- Dissect TM_Data (variable length)
  456. if tm_id == 621 or tm_id == 815 or tm_id == 104 or tm_id == 107 or tm_id == 101 or tm_id == 106 or tm_id == 200 or tm_id == 201 or tm_id == 202 or
  457. tm_id == 129 or tm_id == 241 or tm_id == 130 or tm_id == 133 or tm_id == 134 or tm_id == 135 or tm_id == 137 or tm_id == 195 or tm_id == 196 or
  458. tm_id == 184 or tm_id == 855 or tm_id == 857 or tm_id == 800 or tm_id == 819 or tm_id == 823 or tm_id == 398 or tm_id == 413 or tm_id == 461 or
  459. tm_id == 463 or tm_id == 464 or tm_id == 468 or tm_id == 474 or tm_id == 475 or tm_id == 412 or tm_id == 253 or tm_id == 411 or tm_id == 211 or
  460. tm_id == 212 then
  461. if tm_id == 621 then
  462. require("hm_dissector")
  463. array = HM_TM_dissector(buffer, pinfo, tree, TC_TM_PROTOCOL, add, tm_len)
  464. add = add + tm_len
  465. elseif tm_id == 815 then
  466. require("bcon")
  467. bcon_dissector(buffer, pinfo, tree, TC_TM_PROTOCOL, add, tm_len)
  468. add = add + tm_len
  469. elseif tm_id == 104 then
  470. require("ftci_dissector")
  471. ftci_dissector(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  472. add = add + tm_len
  473. elseif tm_id == 107 then
  474. require("ftfci_dissector")
  475. ftfci_dissector(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  476. add = add + tm_len
  477. elseif tm_id == 101 then
  478. require("ftsr_dissector")
  479. ftsr_dissector(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  480. add = add + tm_len
  481. elseif tm_id == 106 then
  482. require("ftds_dissector")
  483. ftds_dissector(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  484. add = add + tm_len
  485. elseif tm_id == 200 then
  486. require("eps_get_live_param");
  487. eps_get_live_param_dissector(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  488. add = add + tm_len
  489. elseif tm_id == 201 then
  490. require("eps_rd_stored_param");
  491. eps_rd_stored_param_dissector(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  492. add = add + tm_len
  493. elseif tm_id == 202 then
  494. require("eps_tm_wr_stored_param");
  495. eps_tm_wr_stored_param_dissector(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  496. add = add + tm_len
  497. elseif tm_id == 129 then
  498. require("tm_get_adcs_state");
  499. tm_get_adcs_state(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  500. add = add + tm_len
  501. elseif tm_id == 253 then
  502. require("tm_adcs_state_cfg");
  503. tm_adcs_state_cfg(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  504. add = add + tm_len
  505. elseif tm_id == 241 then
  506. require("tm_adcs_get_est_attitude_angl");
  507. tm_get_adcs_estimated_angle(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  508. add = add + tm_len
  509. elseif tm_id == 130 then
  510. require("tm_get_adcs_tle");
  511. tm_get_adcs_tle(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  512. add = add + tm_len
  513. elseif tm_id == 133 then
  514. require("tm_get_adcs_mag_field_vector");
  515. tm_get_adcs_mag_field_vector(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  516. add = add + tm_len
  517. elseif tm_id == 134 then
  518. require("tm_get_adcs_css_vector");
  519. tm_get_adcs_css_vector(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  520. add = add + tm_len
  521. elseif tm_id == 135 then
  522. require("tm_get_adcs_fss_vector");
  523. tm_get_adcs_fss_vector(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  524. add = add + tm_len
  525. elseif tm_id == 137 then
  526. require("tm_get_adcs_sensor_vector");
  527. tm_get_adcs_sensor_vector(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  528. add = add + tm_len
  529. elseif tm_id == 195 then
  530. require("tm_get_adcs_commanded_wheel_speed");
  531. tm_get_command_wheel_speed(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  532. add = add + tm_len
  533. elseif tm_id == 196 then
  534. require("tm_get_adcs_rw_speed_measure");
  535. tm_get_adcs_rw_speed_measure(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  536. add = add + tm_len
  537. elseif tm_id == 184 then
  538. require("tm_get_adcs_est_rate");
  539. tm_get_adcs_est_rate(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  540. add = add + tm_len
  541. elseif tm_id == 855 then
  542. require("tm_get_sdr_tmr_cfg");
  543. tm_get_sdr_tmr_cfg(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  544. add = add + tm_len
  545. elseif tm_id == 857 then
  546. require("tm_get_sdr_rssi_cfg");
  547. tm_get_sdr_rssi_cfg(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  548. add = add + tm_len
  549. elseif tm_id == 800 then
  550. require("tm_comms_uhf_get_tm_info");
  551. tm_comms_uhf_get_tm_info(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  552. add = add + tm_len
  553. elseif tm_id == 819 then
  554. require("tm_comms_uhf_get_tm_store");
  555. tm_comms_uhf_get_tm_store(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  556. add = add + tm_len
  557. elseif tm_id == 823 then
  558. require("tm_comms_uhf_dbg_cb");
  559. tm_comms_uhf_dbg_cb(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  560. add = add + tm_len
  561. elseif tm_id == 398 then
  562. require("tm_get_comms_tm_info");
  563. tm_get_comms_tm_info(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  564. add = add + tm_len
  565. elseif tm_id == 413 then
  566. require("tm_sband_get_tm_store");
  567. tm_sband_get_tm_store(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  568. add = add + tm_len
  569. elseif tm_id == 461 then
  570. require("tm_get_sband_version");
  571. tm_get_sband_version(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  572. add = add + tm_len
  573. elseif tm_id == 463 then
  574. require("tm_sband_get_device_conf");
  575. tm_sband_get_device_conf(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  576. add = add + tm_len
  577. elseif tm_id == 464 then
  578. require("tm_sband_get_feature_select");
  579. tm_sband_get_feature_select(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  580. add = add + tm_len
  581. elseif tm_id == 468 then
  582. require("tm_sband_get_product_key");
  583. tm_sband_get_product_key(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  584. add = add + tm_len
  585. elseif tm_id == 474 then
  586. require("tm_get_sband_dbg_cb");
  587. tm_get_sband_dbg_cb(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  588. add = add + tm_len
  589. elseif tm_id == 475 then
  590. require("tm_get_sband_tx_rx_on_ts");
  591. tm_get_sband_tx_rx_on_ts(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  592. add = add + tm_len
  593. elseif tm_id == 412 then
  594. require("tm_sband_get_tm_all");
  595. tm_sband_get_tm_all(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  596. add = add + tm_len
  597. elseif tm_id == 411 then
  598. require("tm_comms_beacon_tx");
  599. tm_comms_beacon_tx(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  600. add = add + tm_len
  601. elseif tm_id == 211 then
  602. require("tm_eps_set_cntrl_chnl_state");
  603. tm_eps_set_cntrl_chnl_state(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  604. add = add + tm_len
  605. elseif tm_id == 212 then
  606. require("tm_get_eps_dev_hw_sts");
  607. tm_get_eps_dev_hw_sts(buffer, pinfo, tree, TC_TM_PROTOCOL, add)
  608. add = add + tm_len
  609. end
  610. else
  611. for i=0,magic-1 do
  612. subtree:add(f_tm_data, buffer(add, 1):le_uint())
  613. add=add+1
  614. end
  615. end
  616. -- Ext Header Len in HEX
  617. if bit.band(tm_ctrl, 0x80) == 0x80 then
  618. magic= buffer(add, 1):uint()
  619. subtree:add(f_ext_header_len, buffer(add, 1):uint())
  620. add=add+1
  621. -- logic for Ext Header Data
  622. for i=0,magic-1 do
  623. subtree:add(f_ext_header_data, buffer(add, 1):uint()) -- Ext Header Data in HEX
  624. add=add+1
  625. end
  626. end
  627. -- CRC in HEX
  628. subtree:add(f_crc, buffer(add, 1):le_uint())
  629. add=add+1
  630. -- C MAC in HEX
  631. --magic = buffer(, 1):le_uint() -- tm control
  632. if bit.band(tm_ctrl, 0x10) == 0x10 then
  633. for i=1,32 do
  634. subtree:add(f_c_mac, buffer(add, 1):uint())
  635. add=add+1
  636. end
  637. end
  638. -- EOF1 in HEX
  639. subtree:add(f_eof1, buffer(add, 1):uint())
  640. local string
  641. if tm_id == 621 then
  642. local switch = {
  643. [0] = function() return "EPS" end,
  644. [1] = function() return "ADCS" end,
  645. [2] = function() return "SBAND" end,
  646. [3] = function() return "UHF" end,
  647. [4] = function() return "SENSOR" end,
  648. [5] = function() return "OBC" end,
  649. [6] = function() return "ERROR HANDLER" end
  650. }
  651. string = (switch[array[1]] or function() return "All Module" end)()
  652. info_display= {buffer(11, 2):le_uint(),buffer(7, 4):le_uint() ,tm_id, string, array[2], array[3]} --- for info display in wireshark
  653. pinfo.cols.info ="seq_no = " ..info_display[1]..", TS = " ..info_display[2]..", TM ID = "..info_display[3]..", Module = "..info_display[4]..", Queue id = "..info_display[5]..", Number of instance = "..info_display[6] -- for info display in wireshark
  654. elseif tm_id == 104 then
  655. string = "FTCI FRAME"
  656. info_display= {buffer(11, 2):le_uint(),buffer(7, 4):le_uint() ,tm_id, string} --- for info display in wireshark
  657. pinfo.cols.info ="seq_no = " ..info_display[1] ..", TS = " ..info_display[2]..", TM_ID = "..info_display[3]..", " ..info_display[4] -- for info display in wireshark
  658. elseif tm_id == 101 then
  659. string = "FTSR FRAME"
  660. info_display= {buffer(11, 2):le_uint(),buffer(7, 4):le_uint() ,tm_id, string} --- for info display in wireshark
  661. pinfo.cols.info ="seq_no = " ..info_display[1] ..", TS = " ..info_display[2]..", TM_ID = "..info_display[3]..", " ..info_display[4] --for info display in wireshark
  662. elseif tm_id == 106 then
  663. string = "FTDS FRAME"
  664. info_display= {buffer(11, 2):le_uint(),buffer(7, 4):le_uint() ,tm_id, string} --- for info display in wireshark
  665. pinfo.cols.info ="seq_no = " ..info_display[1] ..", TS = " ..info_display[2]..", TM_ID = "..info_display[3]..", " ..info_display[4] -- for info display in wireshark
  666. elseif tm_id == 107 then
  667. string = "FTFCI FRAME"
  668. info_display= {buffer(11, 2):le_uint(),buffer(7, 4):le_uint() ,tm_id, string} --- for info display in wireshark
  669. pinfo.cols.info ="seq_no = " ..info_display[1] ..", TS = " ..info_display[2]..", TM_ID = "..info_display[3]..", " ..info_display[4] -- for info display in wireshark
  670. elseif tm_id == 815 then
  671. string = "BEACON"
  672. info_display= {buffer(11, 2):le_uint(),buffer(7, 4):le_uint() ,tm_id, string} --- for info display in wireshark
  673. pinfo.cols.info ="seq_no = " ..info_display[1] ..", TS = " ..info_display[2]..", TM_ID = "..info_display[3]..", " ..info_display[4] -- for info display in wireshark
  674. else
  675. info_display= {buffer(11, 2):le_uint(),buffer(7, 4):le_uint() ,tm_id} --- for info display in wireshark
  676. pinfo.cols.info ="seq_no = " ..info_display[1]..", TS = " ..info_display[2]..", TM ID = "..info_display[3] -- for info display in wireshark
  677. end
  678. -- Check if the buffer contains enough data for the expected total length
  679. --if buffer:len() < 38 + buffer(21, 2):uint() then
  680. -- subtree:add_expert_info(PI_MALFORMED, PI_WARN, "Incomplete data")
  681. --end
  682. end
  683. -- Register the dissector for udp port
  684. -------------------------------------------------------------------------------------------------------------------------------
  685. -- Dissector function
  686. function TC_TM_PROTOCOL.dissector(buffer, pinfo, tree)
  687. -- Register protocol in preferences (add this part)
  688. --my_udp_protocol:register_preference()
  689. pinfo.cols.protocol = "TC_TM"
  690. local offset1
  691. for i = 0,1000 do
  692. local data = buffer(i,1):le_uint()
  693. if data == 0xa5 then
  694. offset1 = i
  695. break
  696. end
  697. end
  698. offset1 = offset1 + 2
  699. -- Create a subtree for this protocol
  700. --local subtree = tree:add(my_udp_protocol, buffer(), "TE")
  701. local direction = buffer(offset1, 1):le_uint() -- taking tM or tc control byte
  702. if direction & 0x40 == 0x40 then -- if 6th bit is set then it is TM
  703. TM_dissector(buffer, pinfo, tree) -- OBC to GS
  704. else
  705. TC_dissector(buffer, pinfo, tree) -- GS to OBC
  706. end
  707. end
  708. ------------------------------------------------------------------------------------------------------------------------------------------------
  709. -- Add a preference for the port number
  710. TC_TM_PROTOCOL.prefs.port = Pref.uint("UDP Port", 6779, "UDP port for TC_TM protocol")
  711. -- Register the dissector based on the preference
  712. function TC_TM_PROTOCOL.init()
  713. local udp_table = DissectorTable.get("udp.port")
  714. udp_table:add(TC_TM_PROTOCOL.prefs.port, TC_TM_PROTOCOL)
  715. end