Skip to content

Instantly share code, notes, and snippets.

@svinz
Last active March 21, 2022 11:53
Show Gist options
  • Save svinz/558cbefc3f9bb5608de59caeace8e2c4 to your computer and use it in GitHub Desktop.
Save svinz/558cbefc3f9bb5608de59caeace8e2c4 to your computer and use it in GitHub Desktop.

How to stream C-ITS messages from Node-Red and decode them in Wireshark

Node-red

  1. Install Node-red
  2. Copy the flow in this gist, it includes a sample C-ITS message of a signed DENM-message. It basically just adds TZSP-headers and dummy ethernet headers to the payload before converting it to a buffer and stream it to a UDP-port.
  3. Change the IP in the UDP-node to the IP of the computer where Wireshark is installed.
  4. Press "Deploy"

image

Wireshark

  1. Install Wireshark, ensure you install the pcap library as well, as this is the one that does the actual capturing
  2. When installed, open Wireshark and enter a capture filter: udp port 37008. If you dont type in a capture filter, all traffic on the selected interface will be captured. image
  3. Press the interface that have the corresponding IP that is typed in the UDP-node in node-red to start capturing.
  4. Verify that you get a packet in Wiresharkimage

Essential JS code

Add TZSP, ethernt and GeoNetwork headers

// in case the C-ITS message comes with spaces between the 
// hex values, remove them
msg.payload = msg.payload.replace(/\s/g, "")
var tzsp = "0100000101"
// adding spaces between each hex for readability
// the important part is the 8947 value on the end that indicates that 
// this is a GeoNetworking frame
var ethernet = "ff ff ff ff ff ff"+ "00 ff ff ff ff 00" +"8947"
// removing the spaces in the ethernet frame again
msg.payload = tzsp + ethernet.replace(/\s/g, "") + msg.payload
return msg;

Convert to a buffer before sending over UDP

msg.payload = new Buffer(msg.payload,"hex")
return msg;
[{"id":"da3ac445de01333e","type":"tab","label":"C-ITS msg to Wireshark","disabled":false,"info":""},{"id":"d4521b1a9406e663","type":"inject","z":"da3ac445de01333e","name":"Inject a C-ITS message","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"12 00 50 0a 03 81 00 40 03 80 65 20 40 01 80 00 31 0a 00 e1 4a 00 00 14 00 00 02 03 37 42 4d f5 9e d9 0d 23 b6 79 70 06 64 24 bc 80 00 00 00 24 72 11 00 05 31 2d e0 00 c8 00 00 00 00 00 00 07 d2 00 00 02 01 2e 5b f2 71 81 17 2d f9 38 80 00 90 38 ec d8 01 04 19 b1 19 9c 45 a1 6f a0 07 07 af fe 0f ff ff fe 11 db ba 10 a8 c0 00 00 03 02 50 01 25 00 02 07 5f 76 bb 29 13 23 b6 79 70 06 64 24 bc 5a 3c 81 01 01 80 03 00 80 09 70 72 65 a6 17 74 e8 10 83 00 00 00 00 00 22 09 60 86 84 00 c8 01 0e 00 03 08 40 81 80 02 40 42 81 06 05 01 ff ff ff ff 80 03 08 40 83 81 06 05 01 ff ff ff ff 80 01 24 81 04 03 01 ff fc 80 01 25 81 05 04 01 ff ff ff 80 01 89 81 03 02 01 e0 80 01 8a 81 03 02 01 c0 80 01 8b 81 07 06 01 30 c0 01 ff f8 00 01 8d 80 01 35 81 06 05 01 ff ff ff ff 80 01 36 81 06 05 01 ff ff ff ff 80 02 02 7d 81 02 01 01 80 02 02 7e 81 05 04 01 ff ff ff 80 02 02 7f 81 05 04 01 ff ff ff 80 80 82 ca b9 05 2b b0 3c c2 d3 9f c0 e0 93 d8 d3 f9 af e8 cc 9f e7 b3 70 5e 6d 34 23 77 8c b9 b2 b8 ea 81 80 1e 8b 2b 0d a8 80 5b e1 81 8e c0 8f eb 3a ba c0 1c 8a 3f f9 b7 a5 92 f8 78 ef d0 9b 31 67 37 0f 64 ef 7c 89 1f 3e 62 19 bf 06 17 80 0d b7 e6 0c cc 4d a1 34 06 a6 85 04 fd 35 0c e2 91 41 a3 53 80 80 d0 00 6b 3b e1 c1 57 38 ed 26 5e b3 0e b1 c8 9c 8f 97 19 11 20 f8 e3 b6 5b 54 44 dd 70 e9 f6 1c 61 6e 21 fb 61 44 fe 5c f9 92 0f 83 ea f3 4c 82 62 a4 3b 8c 70 96 ce 1f 21 4d 19 f4 a0 67 55 f1","payloadType":"str","x":130,"y":160,"wires":[["78838713d2c911a4"]]},{"id":"78838713d2c911a4","type":"function","z":"da3ac445de01333e","name":"Append TZSP and Ethernet headers","func":"// in case the C-ITS message comes with spaces between the \n// hex values, remove them\nmsg.payload = msg.payload.replace(/\\s/g, \"\")\nvar tzsp = \"0100000101\"\n// adding spaces between each hex for readability\n// the important part is the 8947 value on the end that indicates that \n// this is a GeoNetworking frame\nvar ethernet = \"ff ff ff ff ff ff\"+ \"00 ff ff ff ff 00\" +\"8947\"\n// removing the spaces in the ethernet frame again\nmsg.payload = tzsp + ethernet.replace(/\\s/g, \"\") + msg.payload\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":160,"wires":[["a0e9e4a4e94a050b"]]},{"id":"a0e9e4a4e94a050b","type":"function","z":"da3ac445de01333e","name":"convertToBuffer","func":"msg.payload = new Buffer(msg.payload,\"hex\")\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":660,"y":160,"wires":[["dd3d7318f690394b"]]},{"id":"dd3d7318f690394b","type":"udp out","z":"da3ac445de01333e","name":"","addr":"your ip","iface":"","port":"37008","ipv":"udp4","outport":"","base64":false,"multicast":"false","x":850,"y":160,"wires":[]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment