| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
local edbg_proto = Proto ("EDBG", "Atmel EDBG protocol") |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
local verbose = false |
| 26 |
|
| 27 |
local cmd_table = { |
| 28 |
|
| 29 |
[0x00] = "Info", |
| 30 |
[0x01] = "LED", |
| 31 |
[0x02] = "Connect", |
| 32 |
[0x03] = "Disconnect", |
| 33 |
[0x04] = "Transfer configure", |
| 34 |
[0x0a] = "Reset target", |
| 35 |
[0x11] = "SWD/JTAG clock", |
| 36 |
[0x13] = "SWD configure", |
| 37 |
|
| 38 |
[0x80] = "AVR command", |
| 39 |
[0x81] = "AVR response", |
| 40 |
[0x82] = "AVR event", |
| 41 |
} |
| 42 |
|
| 43 |
local dir_table = { |
| 44 |
[0] = "Request", |
| 45 |
[1] = "Response" |
| 46 |
} |
| 47 |
|
| 48 |
local info_id_table = { |
| 49 |
[0x01] = "Vendor ID", |
| 50 |
[0x02] = "Product ID", |
| 51 |
[0x03] = "Serial number", |
| 52 |
[0x04] = "CMSIS-DAP firmware version", |
| 53 |
[0x05] = "Target device vendor", |
| 54 |
[0x06] = "Target device name", |
| 55 |
[0xf0] = "Capabilities", |
| 56 |
[0xfe] = "Maximum packet count", |
| 57 |
[0xff] = "Maximum packet length" |
| 58 |
} |
| 59 |
|
| 60 |
local led_id_table = { |
| 61 |
[0x00] = "Connect LED", |
| 62 |
[0x01] = "Running LED" |
| 63 |
} |
| 64 |
|
| 65 |
local led_status_table = { |
| 66 |
[0x00] = "Off", |
| 67 |
[0x01] = "On" |
| 68 |
} |
| 69 |
|
| 70 |
local dap_port_table = { |
| 71 |
[0x00] = "Default mode", |
| 72 |
[0x01] = "SWD mode", |
| 73 |
[0x02] = "JTAG mode" |
| 74 |
} |
| 75 |
|
| 76 |
local dap_port_status_table = { |
| 77 |
[0x00] = "Port init failed", |
| 78 |
[0x01] = "SWD init OK", |
| 79 |
[0x02] = "JTAG init OK" |
| 80 |
} |
| 81 |
|
| 82 |
local dap_rsp_status_table = { |
| 83 |
[0x00] = "OK", |
| 84 |
[0xff] = "Error" |
| 85 |
} |
| 86 |
|
| 87 |
local avr_subproto_table = { |
| 88 |
|
| 89 |
[0x00] = "Info", |
| 90 |
[0x01] = "General", |
| 91 |
[0x11] = "AVR ISP", |
| 92 |
[0x12] = "AVR" |
| 93 |
} |
| 94 |
|
| 95 |
local avr_cmd_table = { |
| 96 |
|
| 97 |
|
| 98 |
[0x01] = "Set parameter", |
| 99 |
[0x02] = "Get parameter", |
| 100 |
[0x10] = "Sign-on", |
| 101 |
[0x11] = "Sign-off", |
| 102 |
|
| 103 |
[0x12] = "Device ID", |
| 104 |
[0x13] = "Start debugging", |
| 105 |
[0x14] = "Stop debugging", |
| 106 |
[0x15] = "Enter programming mode", |
| 107 |
[0x16] = "Leave programming mode", |
| 108 |
[0x17] = "MonCon disable", |
| 109 |
[0x20] = "Erase memory", |
| 110 |
[0x21] = "Read memory", |
| 111 |
[0x23] = "Write memory", |
| 112 |
[0x30] = "Reset", |
| 113 |
[0x31] = "Stop", |
| 114 |
[0x32] = "Go", |
| 115 |
[0x33] = "Run to", |
| 116 |
[0x34] = "Step", |
| 117 |
[0x35] = "Read PC", |
| 118 |
[0x36] = "Write PC", |
| 119 |
[0x40] = "Set BP", |
| 120 |
[0x41] = "Clear BP", |
| 121 |
[0x42] = "Set BP Xmega", |
| 122 |
[0x43] = "Set soft BP", |
| 123 |
[0x44] = "Clear soft BP", |
| 124 |
[0x45] = "Cleanup" |
| 125 |
} |
| 126 |
|
| 127 |
local avr_rsp_table = { |
| 128 |
[0x80] = "OK", |
| 129 |
[0x81] = "Info", |
| 130 |
[0x83] = "PC", |
| 131 |
[0x84] = "Data", |
| 132 |
[0xa0] = "Failed" |
| 133 |
} |
| 134 |
|
| 135 |
local avr_rsp_failure_table = { |
| 136 |
[0x10] = "Debugwire", |
| 137 |
[0x1b] = "PDI", |
| 138 |
[0x20] = "No answer", |
| 139 |
[0x22] = "No target power", |
| 140 |
[0x32] = "Wrong mode", |
| 141 |
[0x34] = "Unsupported memory type", |
| 142 |
[0x35] = "Wrong length", |
| 143 |
[0x91] = "Not understood" |
| 144 |
} |
| 145 |
|
| 146 |
local avr_rsp_status_table = { |
| 147 |
[0x00] = "OK" |
| 148 |
|
| 149 |
} |
| 150 |
|
| 151 |
local avr_evt_table = { |
| 152 |
[0x10] = "Power", |
| 153 |
[0x11] = "Sleep/wakeup", |
| 154 |
[0x12] = "Reset", |
| 155 |
[0x40] = "Break", |
| 156 |
[0x41] = "IDR" |
| 157 |
} |
| 158 |
|
| 159 |
local avr_sleep_table = { |
| 160 |
[0x00] = "awake", |
| 161 |
[0x01] = "asleep" |
| 162 |
} |
| 163 |
|
| 164 |
local avr_power_table = { |
| 165 |
[0x00] = "off", |
| 166 |
[0x01] = "on" |
| 167 |
} |
| 168 |
|
| 169 |
local avr_reset_table = { |
| 170 |
[0x00] = "released", |
| 171 |
[0x01] = "applied" |
| 172 |
} |
| 173 |
|
| 174 |
local avr_break_cause_table = { |
| 175 |
[0x00] = "Unspecified", |
| 176 |
[0x01] = "Program breakpoint", |
| 177 |
|
| 178 |
[0x02] = "Data break PDSB", |
| 179 |
[0x03] = "Data break PDMSB" |
| 180 |
} |
| 181 |
|
| 182 |
local avr_parms_gen_sect0_table = { |
| 183 |
[0x00] = "Hardware version", |
| 184 |
[0x01] = "Firmware major version", |
| 185 |
[0x02] = "Firmware minor version", |
| 186 |
[0x03] = "Firmware release" |
| 187 |
} |
| 188 |
|
| 189 |
local avr_parms_gen_sect1_table = { |
| 190 |
[0x00] = "Vtarget" |
| 191 |
} |
| 192 |
|
| 193 |
local avr_parms_gen_sect2_table = { |
| 194 |
[0x00] = "Device description" |
| 195 |
} |
| 196 |
|
| 197 |
local avr_arch_table = { |
| 198 |
[1] = "Tiny", |
| 199 |
[2] = "Mega", |
| 200 |
[3] = "Xmega" |
| 201 |
} |
| 202 |
|
| 203 |
local avr_session_table = { |
| 204 |
[1] = "Programming", |
| 205 |
[2] = "Debugging" |
| 206 |
} |
| 207 |
|
| 208 |
local avr_parms_avr_sect0_table = { |
| 209 |
[0x00] = "Architecture", |
| 210 |
[0x01] = "Session purpose" |
| 211 |
} |
| 212 |
|
| 213 |
local avr_connection_table = { |
| 214 |
[1] = "ISP", |
| 215 |
[4] = "JTAG", |
| 216 |
[5] = "debugWIRE", |
| 217 |
[6] = "PDI" |
| 218 |
} |
| 219 |
|
| 220 |
local avr_parms_avr_sect1_table = { |
| 221 |
[0x00] = "Connection", |
| 222 |
[0x01] = "JTAG chain", |
| 223 |
[0x20] = "JTAG Programming clock, megaAVR", |
| 224 |
[0x21] = "JTAG Debugging clock, megaAVR", |
| 225 |
[0x30] = "JTAG Clock, Xmega", |
| 226 |
[0x31] = "PDI Clock, Xmega" |
| 227 |
} |
| 228 |
|
| 229 |
local avr_parms_avr_sect3_table = { |
| 230 |
[0x00] = "Timers running" |
| 231 |
} |
| 232 |
|
| 233 |
local avr_memory_types_table = { |
| 234 |
[0x20] = "SRAM", |
| 235 |
[0x22] = "EEPROM", |
| 236 |
[0xa0] = "Flash, LPM/SPM", |
| 237 |
[0xb0] = "Flash, paged", |
| 238 |
[0xb1] = "EEPROM, paged", |
| 239 |
[0xb2] = "Fuse bits", |
| 240 |
[0xb3] = "Lock bits", |
| 241 |
[0xb4] = "Signature", |
| 242 |
[0xb5] = "OSCCAL", |
| 243 |
[0xb8] = "Registers", |
| 244 |
[0xc0] = "Application flash", |
| 245 |
[0xc1] = "Boot flash", |
| 246 |
[0xc5] = "User signature", |
| 247 |
[0xc6] = "Production signature" |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
local dir = Field.new("usb.endpoint_number.direction") |
| 252 |
|
| 253 |
|
| 254 |
local f_cmd = ProtoField.uint8("edbg.cmd", "Command", |
| 255 |
base.HEX, cmd_table) |
| 256 |
local f_dir = ProtoField.uint8("edbg.dir", "Direction", |
| 257 |
base.DEC, dir_table) |
| 258 |
|
| 259 |
local f_status = ProtoField.uint8("edbg.status", "DAP status", |
| 260 |
base.HEX, dap_rsp_status_table) |
| 261 |
|
| 262 |
local f_dap_info_id = ProtoField.uint8("edbg.info.id", "DAP info ID", |
| 263 |
base.HEX, info_id_table) |
| 264 |
local f_dap_info_string = ProtoField.string("edbg.info.string", "Info string") |
| 265 |
local f_dap_info_byte = ProtoField.uint8("edbg.info.byte", "Info BYTE", |
| 266 |
base.DEC) |
| 267 |
local f_dap_info_short = ProtoField.uint16("edbg.info.short", "Info SHORT", |
| 268 |
base.DEC) |
| 269 |
|
| 270 |
local f_dap_led_id = ProtoField.uint8("edbg.led.id", "DAP LED ID", |
| 271 |
base.HEX, led_id_table) |
| 272 |
local f_dap_led_status = ProtoField.uint8("edbg.led.status", "DAP LED status", |
| 273 |
base.HEX, led_status_table) |
| 274 |
|
| 275 |
local f_dap_port = ProtoField.uint8("edbg.port", "DAP port", |
| 276 |
base.HEX, dap_port_table) |
| 277 |
local f_dap_port_status = ProtoField.uint8("edbg.port_status", "DAP port status", |
| 278 |
base.HEX, dap_port_status_table) |
| 279 |
|
| 280 |
local f_dap_swj_clock = ProtoField.uint32("edbg.swj.clock", "SWJ clock (Hz)", |
| 281 |
base.DEC) |
| 282 |
|
| 283 |
local f_xfr_idle_cycles = ProtoField.uint8("edbg.xfr.idle_cycles", |
| 284 |
"Number of extra idle cycles after each transfer", |
| 285 |
base.DEC) |
| 286 |
local f_xfr_wait_retry = ProtoField.uint16("edbg.xfr.wait_retry", |
| 287 |
"Number of transfer retries after WAIT response", |
| 288 |
base.DEC) |
| 289 |
local f_xfr_match_retry = ProtoField.uint16("edbg.xfr.match_retry", |
| 290 |
"Number of retries on reads with Value Match in DAP_Transfer", |
| 291 |
base.DEC) |
| 292 |
|
| 293 |
local f_avr_fragment_info = ProtoField.uint8("edbg.avr.fragment_info", |
| 294 |
"Fragment info", |
| 295 |
base.HEX) |
| 296 |
local f_avr_size = ProtoField.uint16("edbg.avr.size", "Wrapped size", |
| 297 |
base.DEC) |
| 298 |
local f_avr_fragment_code = ProtoField.uint8("edbg.avr.fragment_code", |
| 299 |
"Fragment code", |
| 300 |
base.HEX) |
| 301 |
local f_avr_packet = ProtoField.bytes("edbg.avr.packet", "AVR packet") |
| 302 |
local f_avr_sof = ProtoField.uint8("edbg.avr.sof", "AVR SOF", base.HEX) |
| 303 |
local f_avr_proto_version = ProtoField.uint8("edbg.avr.protocol_version", |
| 304 |
"Protocol version", base.HEX) |
| 305 |
local f_avr_seq_id = ProtoField.uint16("edbg.avr.seq_id", "Sequence ID", |
| 306 |
base.DEC) |
| 307 |
local f_avr_subproto_id = ProtoField.uint8("edbg.avr.subproto_id", |
| 308 |
"Subprotocol ID", |
| 309 |
base.HEX, avr_subproto_table) |
| 310 |
local f_avr_cmd = ProtoField.uint8("edbg.avr.cmd", "Subprotocol command", |
| 311 |
base.HEX, avr_cmd_table) |
| 312 |
local f_avr_rsp_code = ProtoField.uint8("edbg.avr.rsp_code", "Response code", |
| 313 |
base.HEX, avr_rsp_table) |
| 314 |
local f_avr_rsp_contents = ProtoField.bytes("edbg.avr.rsp_contents", "Response contents") |
| 315 |
local f_avr_pc = ProtoField.uint32("edbg.avr.pc", "Program counter", base.HEX) |
| 316 |
local f_avr_rsp_failure_code = ProtoField.uint8("edbg.avr.pc", "Failure code", |
| 317 |
base.HEX, avr_rsp_failure_table) |
| 318 |
local f_avr_rsp_status = ProtoField.uint8("edbg.avr.rsp_status", "Response status", |
| 319 |
base.HEX, avr_rsp_status_table) |
| 320 |
|
| 321 |
local f_avr_evt_code = ProtoField.uint8("edbg.avr.evt_code", "Event code", |
| 322 |
base.HEX, avr_evt_table) |
| 323 |
local f_avr_evt_power_state = ProtoField.uint8("edbg.avr.power_state", |
| 324 |
"Power state", |
| 325 |
base.HEX, avr_power_table) |
| 326 |
local f_avr_evt_sleep_state = ProtoField.uint8("edbg.avr.sleep_state", |
| 327 |
"Sleep state", |
| 328 |
base.HEX, avr_sleep_table) |
| 329 |
local f_avr_evt_reset_state = ProtoField.uint8("edbg.avr.reset_state", |
| 330 |
"State of external reset", |
| 331 |
base.HEX, avr_reset_table) |
| 332 |
local f_avr_break_cause = ProtoField.uint8("edbg.avr.break_cause", |
| 333 |
"Break cause", |
| 334 |
base.HEX, avr_break_cause_table) |
| 335 |
local f_avr_idr = ProtoField.uint8("edbg.avr.idr_message", |
| 336 |
"IDR message from MCU", |
| 337 |
base.HEX) |
| 338 |
local f_avr_ext_info = ProtoField.uint16("edbg.avr.ext_info", |
| 339 |
"Extended info", |
| 340 |
base.HEX) |
| 341 |
local f_avr_parms_sect = ProtoField.uint8("edbg.avr.parms.section", |
| 342 |
"Parameter section (context)", |
| 343 |
base.HEX) |
| 344 |
local f_avr_parms_gen_sect0 = ProtoField.uint8("edbg.avr.parms.gen_sect0", |
| 345 |
"General parameters, section 0", |
| 346 |
base.HEX, avr_parms_gen_sect0_table) |
| 347 |
local f_avr_parms_gen_sect1 = ProtoField.uint8("edbg.avr.parms.gen_sect1", |
| 348 |
"General parameters, section 1", |
| 349 |
base.HEX, avr_parms_gen_sect1_table) |
| 350 |
local f_avr_parms_gen_sect2 = ProtoField.uint8("edbg.avr.parms.gen_sect2", |
| 351 |
"General parameters, section 2", |
| 352 |
base.HEX, avr_parms_gen_sect2_table) |
| 353 |
local f_avr_parms_avr_sect0 = ProtoField.uint8("edbg.avr.parms.avr_sect0", |
| 354 |
"AVR parameters, section 0", |
| 355 |
base.HEX, avr_parms_avr_sect0_table) |
| 356 |
local f_avr_parms_avr_sect1 = ProtoField.uint8("edbg.avr.parms.avr_sect1", |
| 357 |
"AVR parameters, section 1", |
| 358 |
base.HEX, avr_parms_avr_sect1_table) |
| 359 |
local f_avr_parms_avr_sect3 = ProtoField.uint8("edbg.avr.parms.avr_sect3", |
| 360 |
"AVR parameters, section 3", |
| 361 |
base.HEX, avr_parms_avr_sect3_table) |
| 362 |
local f_avr_parms_avr_arch = ProtoField.uint8("edbg.avr.parms.avr.arch", |
| 363 |
"AVR Architecture", |
| 364 |
base.DEC, avr_arch_table) |
| 365 |
local f_avr_parms_avr_session = ProtoField.uint8("edbg.avr.parms.avr.sess", |
| 366 |
"Session purpose", |
| 367 |
base.DEC, avr_session_table) |
| 368 |
local f_avr_parms_avr_connection = ProtoField.uint8("edbg.avr.parms.avr.conn", |
| 369 |
"Connection type", |
| 370 |
base.DEC, avr_connection_table) |
| 371 |
local f_avr_parms_nbytes = ProtoField.uint8("edbg.avr.parms.nbytes", |
| 372 |
"Number of parameter bytes to set/get", |
| 373 |
base.DEC) |
| 374 |
local f_avr_parms_bytes = ProtoField.bytes("edbg.avr.parms.bytes", |
| 375 |
"Parameter bytes") |
| 376 |
local f_avr_parms_avr_clock = ProtoField.uint16("edbg.avr.parms.avr.clock", |
| 377 |
"Clock value (kHz)", |
| 378 |
base.DEC) |
| 379 |
local f_avr_mem_type = ProtoField.uint8("edbg.avr.memory.type", |
| 380 |
"Memory type", |
| 381 |
base.HEX, avr_memory_types_table) |
| 382 |
local f_avr_mem_addr = ProtoField.uint32("edbg.avr.memory.address", |
| 383 |
"Memory start address", |
| 384 |
base.HEX) |
| 385 |
local f_avr_mem_size = ProtoField.uint32("edbg.avr.memory.size", |
| 386 |
"Memory size", |
| 387 |
base.HEX) |
| 388 |
local f_avr_mem_bytes = ProtoField.bytes("edbg.avr.memory.bytes", |
| 389 |
"Memory contents") |
| 390 |
|
| 391 |
|
| 392 |
local last_req = "none" |
| 393 |
|
| 394 |
|
| 395 |
function dissect_dap_info_req(buffer, len, pinfo, tree) |
| 396 |
tree:add(f_dap_info_id, buffer(0, 1)) |
| 397 |
if buffer(0, 1):uint() < 0xf0 then |
| 398 |
last_req = "string" |
| 399 |
else |
| 400 |
last_req = "uint" |
| 401 |
end |
| 402 |
end |
| 403 |
|
| 404 |
function dissect_dap_info_rsp(buffer, len, pinfo, tree) |
| 405 |
local rsplen = buffer(0, 1):uint() |
| 406 |
if rsplen <= len - 1 then |
| 407 |
if last_req == "string" then |
| 408 |
|
| 409 |
tree:add(f_dap_info_string, buffer(1, rsplen)) |
| 410 |
elseif last_req == "uint" then |
| 411 |
|
| 412 |
if rsplen == 1 then |
| 413 |
tree:add(f_dap_info_byte, buffer(1, 1)) |
| 414 |
else |
| 415 |
tree:add_le(f_dap_info_short, buffer(1, 2)) |
| 416 |
end |
| 417 |
end |
| 418 |
end |
| 419 |
last_req = "none" |
| 420 |
end |
| 421 |
|
| 422 |
function dissect_avr_cmd_req(buffer, len, pinfo, tree) |
| 423 |
if len >= 9 then |
| 424 |
if verbose then tree:add(f_avr_fragment_info, buffer(0, 1)) end |
| 425 |
tree:add(f_avr_size, buffer(1, 2)) |
| 426 |
local wrappedsize = buffer(1, 2):uint() |
| 427 |
local subtree = tree:add(f_avr_packet, buffer(3, wrappedsize)) |
| 428 |
if verbose then |
| 429 |
subtree:add(f_avr_sof, buffer(3, 1)) |
| 430 |
subtree:add(f_avr_proto_version, buffer(4, 1)) |
| 431 |
end |
| 432 |
subtree:add_le(f_avr_seq_id, buffer(5, 2)) |
| 433 |
subtree:add(f_avr_subproto_id, buffer(7, 1)) |
| 434 |
subtree = subtree:add(f_avr_cmd, buffer(8, 1)) |
| 435 |
|
| 436 |
local cmdval = buffer(8, 1):uint() |
| 437 |
|
| 438 |
if cmdval == 0x01 |
| 439 |
or cmdval == 0x02 |
| 440 |
then |
| 441 |
if wrappedsize >= 10 then |
| 442 |
local scope = buffer(7, 1):uint() |
| 443 |
local section = buffer(10, 1):uint() |
| 444 |
local addr = buffer(11, 1):uint() |
| 445 |
local subsubtree |
| 446 |
subtree:add(f_avr_parms_sect, buffer(10, 1)) |
| 447 |
if scope == 0x01 and section == 0x00 then |
| 448 |
subtree:add(f_avr_parms_gen_sect0, buffer(11, 1)) |
| 449 |
elseif scope == 0x01 and section == 0x01 then |
| 450 |
subtree:add(f_avr_parms_gen_sect1, buffer(11, 1)) |
| 451 |
elseif scope == 0x01 and section == 0x02 then |
| 452 |
subtree:add(f_avr_parms_gen_sect2, buffer(11, 1)) |
| 453 |
elseif scope == 0x12 and section == 0x00 then |
| 454 |
subtree:add(f_avr_parms_avr_sect0, buffer(11, 1)) |
| 455 |
elseif scope == 0x12 and section == 0x01 then |
| 456 |
subsubtree = subtree:add(f_avr_parms_avr_sect1, buffer(11, 1)) |
| 457 |
elseif scope == 0x12 and section == 0x03 then |
| 458 |
subtree:add(f_avr_parms_avr_sect1, buffer(11, 1)) |
| 459 |
end |
| 460 |
subtree:add(f_avr_parms_nbytes, buffer(12, 1)) |
| 461 |
local nbytes = buffer(12, 1):uint() |
| 462 |
if cmdval == 0x01 |
| 463 |
and wrappedsize - 10 >= nbytes then |
| 464 |
subsubtree = subtree:add(f_avr_parms_bytes, buffer(13, nbytes)) |
| 465 |
if scope == 0x12 and section == 0x00 then |
| 466 |
if addr == 0x00 then |
| 467 |
subsubtree:add(f_avr_parms_avr_arch, buffer(13,1)) |
| 468 |
elseif addr == 0x01 then |
| 469 |
subsubtree:add(f_avr_parms_avr_session, buffer(13,1)) |
| 470 |
end |
| 471 |
elseif scope == 0x12 and section == 0x01 then |
| 472 |
if addr == 0x00 then |
| 473 |
subsubtree:add(f_avr_parms_avr_connection, buffer(13,1)) |
| 474 |
elseif addr >= 0x20 then |
| 475 |
|
| 476 |
subsubtree:add_le(f_avr_parms_avr_clock, buffer(13, 2)) |
| 477 |
end |
| 478 |
end |
| 479 |
end |
| 480 |
end |
| 481 |
elseif cmdval == 0x21 |
| 482 |
or cmdval == 0x23 |
| 483 |
then |
| 484 |
if wrappedsize >= 18 then |
| 485 |
subtree:add(f_avr_mem_type, buffer(10, 1)) |
| 486 |
subtree:add_le(f_avr_mem_addr, buffer(11, 4)) |
| 487 |
subtree:add_le(f_avr_mem_size, buffer(15, 4)) |
| 488 |
local nbytes = buffer(15, 4):le_uint() |
| 489 |
if cmdval == 0x23 and wrappedsize - 17 >= nbytes then |
| 490 |
|
| 491 |
subtree:add(f_avr_mem_bytes, buffer(20, nbytes)) |
| 492 |
end |
| 493 |
end |
| 494 |
end |
| 495 |
end |
| 496 |
end |
| 497 |
|
| 498 |
function dissect_avr_cmd_rsp(buffer, len, pinfo, tree) |
| 499 |
if len >= 9 then |
| 500 |
if verbose then tree:add(f_avr_fragment_info, buffer(0, 1)) end |
| 501 |
tree:add(f_avr_size, buffer(1, 2)) |
| 502 |
local wrappedsize = buffer(1, 2):uint() |
| 503 |
local subtree = tree:add(f_avr_packet, buffer(3, wrappedsize)) |
| 504 |
if verbose then subtree:add(f_avr_sof, buffer(3, 1)) end |
| 505 |
subtree:add_le(f_avr_seq_id, buffer(4, 2)) |
| 506 |
subtree:add(f_avr_subproto_id, buffer(6, 1)) |
| 507 |
subtree = subtree:add(f_avr_rsp_code, buffer(7, 1)) |
| 508 |
if verbose then subtree:add(f_avr_proto_version, buffer(8, 1)) end |
| 509 |
if len > 9 and wrappedsize > 6 then |
| 510 |
local rspcode = buffer(7, 1):uint() |
| 511 |
if rspcode == 0x80 then |
| 512 |
|
| 513 |
elseif rspcode == 0x81 or rspcode == 0x84 then |
| 514 |
|
| 515 |
subtree:add(f_avr_rsp_contents, buffer(9, wrappedsize - 7)) |
| 516 |
subtree:add(f_avr_rsp_status, buffer(wrappedsize + 2, 1)) |
| 517 |
elseif rspcode == 0x83 then |
| 518 |
|
| 519 |
if len >= 13 then |
| 520 |
subtree:add_le(f_avr_pc, buffer(9, 4)) |
| 521 |
end |
| 522 |
elseif rspcode == 0x84 then |
| 523 |
|
| 524 |
subtree:add(f_avr_rsp_failure_code, buffer(9, 1)) |
| 525 |
end |
| 526 |
end |
| 527 |
end |
| 528 |
end |
| 529 |
|
| 530 |
function dissect_avr_cmd_evt(buffer, len, pinfo, tree) |
| 531 |
if len >= 8 then |
| 532 |
tree:add(f_avr_size, buffer(1, 2)) |
| 533 |
local wrappedsize = buffer(1, 2):uint() |
| 534 |
local subtree = tree:add(f_avr_packet, buffer(3, wrappedsize)) |
| 535 |
if verbose then subtree:add(f_avr_sof, buffer(3, 1)) end |
| 536 |
subtree:add_le(f_avr_seq_id, buffer(4, 2)) |
| 537 |
subtree:add(f_avr_subproto_id, buffer(6, 1)) |
| 538 |
subtree = subtree:add(f_avr_evt_code, buffer(7, 1)) |
| 539 |
if verbose then subtree:add(f_avr_proto_version, buffer(8, 1)) end |
| 540 |
local wrappedsize = buffer(1, 2):uint() |
| 541 |
if len > 9 and wrappedsize > 6 then |
| 542 |
local evtcode = buffer(7, 1):uint() |
| 543 |
if evtcode == 0x10 then |
| 544 |
|
| 545 |
subtree:add(f_avr_power_state, buffer(9, 1)) |
| 546 |
elseif evtcode == 0x11 then |
| 547 |
|
| 548 |
subtree:add(f_avr_sleep_state, buffer(9, 1)) |
| 549 |
elseif evtcode == 0x12 then |
| 550 |
|
| 551 |
subtree:add(f_avr_reset_state, buffer(9, 1)) |
| 552 |
elseif evtcode == 0x40 then |
| 553 |
|
| 554 |
subtree:add_le(f_avr_pc, buffer(9, 4)) |
| 555 |
subtree:add(f_avr_break_cause, buffer(13, 1)) |
| 556 |
if verbose then subtree:add(f_avr_ext_info, buffer(15, 2)) end |
| 557 |
elseif evtcode == 0x41 then |
| 558 |
subtree:add(f_avr_idr, buffer(9, 1)) |
| 559 |
end |
| 560 |
end |
| 561 |
end |
| 562 |
end |
| 563 |
|
| 564 |
|
| 565 |
function edbg_proto.init() |
| 566 |
|
| 567 |
end |
| 568 |
|
| 569 |
|
| 570 |
function edbg_proto.dissector(buffer, pinfo, tree) |
| 571 |
if buffer:len() > 64 then |
| 572 |
local data = buffer(64, buffer:len() - 64) |
| 573 |
local dlen = data:len() |
| 574 |
pinfo.cols.protocol = "EDBG" |
| 575 |
local subtree = tree:add(edbg_proto, data(0, dlen), |
| 576 |
"EDBG Protocol Data") |
| 577 |
|
| 578 |
local dirval = dir().value |
| 579 |
subtree:add(f_dir, dirval) |
| 580 |
subtree = subtree:add(f_cmd, data(0, 1)) |
| 581 |
|
| 582 |
local cmd = data(0, 1):uint() |
| 583 |
dlen = dlen - 1 |
| 584 |
if dlen > 0 then |
| 585 |
data = data(1, dlen) |
| 586 |
if cmd == 0x00 then |
| 587 |
|
| 588 |
if dirval == 0 then |
| 589 |
dissect_dap_info_req(data, dlen, pinfo, subtree) |
| 590 |
else |
| 591 |
dissect_dap_info_rsp(data, dlen, pinfo, subtree) |
| 592 |
end |
| 593 |
elseif cmd == 0x01 then |
| 594 |
|
| 595 |
if dirval == 0 then |
| 596 |
if dlen >= 2 then |
| 597 |
subtree:add(f_dap_led_id, data(0, 1)) |
| 598 |
subtree:add(f_dap_led_status, data(1, 1)) |
| 599 |
end |
| 600 |
end |
| 601 |
elseif cmd == 0x02 then |
| 602 |
|
| 603 |
if dirval == 0 then |
| 604 |
subtree:add(f_dap_port, data(0, 1)) |
| 605 |
else |
| 606 |
subtree:add(f_dap_port_status, data(0, 1)) |
| 607 |
end |
| 608 |
elseif cmd == 0x03 then |
| 609 |
|
| 610 |
if dirval ~= 0 then |
| 611 |
subtree:add(f_status, data(0, 1)) |
| 612 |
end |
| 613 |
elseif cmd == 0x04 then |
| 614 |
|
| 615 |
if dirval == 0 then |
| 616 |
if dlen >= 5 then |
| 617 |
subtree:add(f_xfr_idle_cycles, data(0, 1)) |
| 618 |
subtree:add_le(f_xfr_wait_retry, data(1, 2)) |
| 619 |
subtree:add_le(f_xfr_match_retry, data(3, 2)) |
| 620 |
end |
| 621 |
else |
| 622 |
subtree:add(f_status, data(0, 1)) |
| 623 |
end |
| 624 |
elseif cmd == 0x11 then |
| 625 |
|
| 626 |
if dirval == 0 then |
| 627 |
if dlen >= 4 then |
| 628 |
subtree:add_le(f_dap_swj_clock, data(0, 4)) |
| 629 |
end |
| 630 |
else |
| 631 |
subtree:add(f_status, data(0, 1)) |
| 632 |
end |
| 633 |
elseif cmd == 0x80 then |
| 634 |
|
| 635 |
if dirval == 0 then |
| 636 |
dissect_avr_cmd_req(data, dlen, pinfo, subtree) |
| 637 |
else |
| 638 |
if verbose then |
| 639 |
subtree:add(f_avr_fragment_code, data(0, 1)) |
| 640 |
end |
| 641 |
end |
| 642 |
elseif cmd == 0x81 then |
| 643 |
|
| 644 |
if dirval ~= 0 then |
| 645 |
dissect_avr_cmd_rsp(data, dlen, pinfo, subtree) |
| 646 |
end |
| 647 |
elseif cmd == 0x82 then |
| 648 |
|
| 649 |
if dirval ~= 0 then |
| 650 |
dissect_avr_cmd_evt(data, dlen, pinfo, subtree) |
| 651 |
end |
| 652 |
end |
| 653 |
end |
| 654 |
end |
| 655 |
end |
| 656 |
|
| 657 |
|
| 658 |
edbg_proto.fields = { |
| 659 |
f_cmd, |
| 660 |
f_dir, |
| 661 |
f_status, |
| 662 |
|
| 663 |
f_dap_info_id, |
| 664 |
f_dap_info_string, |
| 665 |
f_dap_info_byte, |
| 666 |
f_dap_info_short, |
| 667 |
|
| 668 |
f_dap_led_id, |
| 669 |
f_dap_led_status, |
| 670 |
|
| 671 |
f_dap_port, |
| 672 |
f_dap_port_status, |
| 673 |
|
| 674 |
f_dap_swj_clock, |
| 675 |
|
| 676 |
f_xfr_idle_cycles, |
| 677 |
f_xfr_wait_retry, |
| 678 |
f_xfr_match_retry, |
| 679 |
|
| 680 |
f_avr_fragment_info, |
| 681 |
f_avr_size, |
| 682 |
f_avr_fragment_code, |
| 683 |
f_avr_packet, |
| 684 |
|
| 685 |
f_avr_sof, |
| 686 |
f_avr_proto_version, |
| 687 |
f_avr_seq_id, |
| 688 |
f_avr_subproto_id, |
| 689 |
|
| 690 |
f_avr_cmd, |
| 691 |
f_avr_rsp_code, |
| 692 |
f_avr_rsp_contents, |
| 693 |
f_avr_pc, |
| 694 |
f_avr_rsp_failure_code, |
| 695 |
f_avr_rsp_status, |
| 696 |
|
| 697 |
f_avr_evt_code, |
| 698 |
f_avr_power_state, |
| 699 |
f_avr_sleep_state, |
| 700 |
f_avr_reset_state, |
| 701 |
f_avr_break_cause, |
| 702 |
f_avr_idr, |
| 703 |
f_avr_ext_info, |
| 704 |
|
| 705 |
f_avr_parms_sect, |
| 706 |
f_avr_parms_gen_sect0, |
| 707 |
f_avr_parms_gen_sect1, |
| 708 |
f_avr_parms_gen_sect2, |
| 709 |
f_avr_parms_avr_sect0, |
| 710 |
f_avr_parms_avr_sect1, |
| 711 |
f_avr_parms_avr_sect3, |
| 712 |
f_avr_parms_avr_arch, |
| 713 |
f_avr_parms_avr_session, |
| 714 |
f_avr_parms_avr_connection, |
| 715 |
f_avr_parms_nbytes, |
| 716 |
f_avr_parms_bytes, |
| 717 |
f_avr_parms_avr_clock, |
| 718 |
|
| 719 |
f_avr_mem_type, |
| 720 |
f_avr_mem_addr, |
| 721 |
f_avr_mem_size, |
| 722 |
f_avr_mem_bytes |
| 723 |
} |
| 724 |
|
| 725 |
register_postdissector(edbg_proto) |
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|