DMR: Add Handling for IPv4 UDP / ICMP / UNK Protocol PDUs;

This commit is contained in:
lwvmobile
2025-03-04 06:56:42 -05:00
parent 16a84b8d3e
commit 4d5af32ce7

View File

@@ -219,20 +219,40 @@ void dmr_ip_pdu (dsd_opts * opts, dsd_state * state, uint16_t len, uint8_t * DMR
uint16_t hsum = (DMR_PDU[10] << 8) | DMR_PDU[11]; uint16_t hsum = (DMR_PDU[10] << 8) | DMR_PDU[11];
if (opts->payload == 1) if (opts->payload == 1)
fprintf (stderr, "\n IPv%d; Header Len: %d; Type of Service: %d; Total Len: %d; IP ID: %02X; Flags: %X;\n Fragment Offset: %d; TTL: %d; Protocol: %02X; Checksum: %04X; PDU Len: %d;", version, ihl, tos, tlen, iden, ipf, offset, ttl, prot, hsum, len); fprintf (stderr, "\n IPv%d; IHL: %d; Type of Service: %d; Total Len: %d; IP ID: %04X; Flags: %X;\n Fragment Offset: %d; TTL: %d; Protocol: 0x%02X; Checksum: %04X; PDU Len: %d;", version, ihl, tos, tlen, iden, ipf, offset, ttl, prot, hsum, len);
//take a look at the src, dst, and port indicated (assuming both ports will match) //take a look at the src, dst, and port indicated (assuming both ports will match)
uint32_t src24 = (DMR_PDU[13] << 16) | (DMR_PDU[14] << 8) | DMR_PDU[15]; uint32_t src24 = (DMR_PDU[13] << 16) | (DMR_PDU[14] << 8) | DMR_PDU[15];
uint32_t dst24 = (DMR_PDU[17] << 16) | (DMR_PDU[18] << 8) | DMR_PDU[19]; uint32_t dst24 = (DMR_PDU[17] << 16) | (DMR_PDU[18] << 8) | DMR_PDU[19];
uint16_t port1 = (DMR_PDU[20] << 8) | DMR_PDU[21]; uint16_t port1 = (DMR_PDU[20] << 8) | DMR_PDU[21];
uint16_t port2 = (DMR_PDU[22] << 8) | DMR_PDU[23]; uint16_t port2 = (DMR_PDU[22] << 8) | DMR_PDU[23];
fprintf (stderr, "\n SRC(24): %08d; IP: %03d.%03d.%03d.%03d; Port: %04d; ", src24, DMR_PDU[12], DMR_PDU[13], DMR_PDU[14], DMR_PDU[15], port1); fprintf (stderr, "\n SRC(24): %08d; IP: %03d.%03d.%03d.%03d; ", src24, DMR_PDU[12], DMR_PDU[13], DMR_PDU[14], DMR_PDU[15]);
fprintf (stderr, "\n DST(24): %08d; IP: %03d.%03d.%03d.%03d; Port: %04d; ", dst24, DMR_PDU[16], DMR_PDU[17], DMR_PDU[18], DMR_PDU[19], port2); if (prot == 0x11) fprintf (stderr, "Port: %04d; ", port1);
fprintf (stderr, "\n DST(24): %08d; IP: %03d.%03d.%03d.%03d; ", dst24, DMR_PDU[16], DMR_PDU[17], DMR_PDU[18], DMR_PDU[19]);
if (prot == 0x11) fprintf (stderr, "Port: %04d; ", port2);
//IP Protocol List: https://en.wikipedia.org/wiki/List_of_IP_protocol_numbers
if (prot == 0x01) //ICMP
{
uint8_t icmp_type = DMR_PDU[20];
uint8_t icmp_code = DMR_PDU[21];
uint16_t icmp_chk = port2;
fprintf (stderr, "\n ICMP Protocol; Type: %02X; Code: %02X; Checksum: %02X;", icmp_type, icmp_code, icmp_chk);
//see: https://en.wikipedia.org/wiki/Internet_Control_Message_Protocol
//look at attached message, if present
if (DMR_PDU[28] == 0x45) //if another chained IPv4 header and/or message
{
fprintf (stderr, "\n ------------Attached Message-------------");
dmr_ip_pdu(opts, state, len-28, DMR_PDU+28);
}
}
else if (prot == 0x11) //UDP
{
uint16_t udp_len = (DMR_PDU[24] << 8) | DMR_PDU[25]; //This UDP Length information element is the length in bytes of this user datagram including this header and the application data (no IP header) uint16_t udp_len = (DMR_PDU[24] << 8) | DMR_PDU[25]; //This UDP Length information element is the length in bytes of this user datagram including this header and the application data (no IP header)
uint16_t udp_chk = (DMR_PDU[26] << 8) | DMR_PDU[27]; uint16_t udp_chk = (DMR_PDU[26] << 8) | DMR_PDU[27];
if (opts->payload == 1) fprintf (stderr, "\n UDP Protocol; Datagram Len: %d; UDP Checksum: %04X; ", udp_len, udp_chk);
fprintf (stderr, "\n UDP Datagram Len: %d; UDP Checksum: %04X; ", udp_len, udp_chk);
//Are IP DMR PDU types only dictated by Port Number? Or is this just the defaults when programmed? //Are IP DMR PDU types only dictated by Port Number? Or is this just the defaults when programmed?
if (port1 == 231 && port2 == 231) if (port1 == 231 && port2 == 231)
@@ -288,7 +308,11 @@ void dmr_ip_pdu (dsd_opts * opts, dsd_state * state, uint16_t len, uint8_t * DMR
unpack_byte_array_into_bit_array(DMR_PDU+35, DMR_PDU_bits, (len-4-35)*sizeof(uint8_t)); unpack_byte_array_into_bit_array(DMR_PDU+35, DMR_PDU_bits, (len-4-35)*sizeof(uint8_t));
lip_protocol_decoder(opts, state, DMR_PDU_bits); lip_protocol_decoder(opts, state, DMR_PDU_bits);
} }
else fprintf (stderr, "Unknown PDU Contents;"); else fprintf (stderr, "Unknown UDP Contents;");
}
else fprintf (stderr, "Unknown Protocol: %02X;", prot);
} }