7 #include <satcat5/ip_core.h>
8 #include <satcat5/ptp_interface.h>
9 #include <satcat5/udp_core.h>
13 using satcat5::ptp::PacketType;
18 bool Interface::ptp_dispatch(
const u8* peek,
unsigned length)
21 m_ptp_rx_type = PacketType::NON_PTP;
22 if (!m_ptp_callback)
return false;
25 if (length < 14)
return false;
29 {extract_be_u16(peek + 12)};
31 if (ether_type == satcat5::eth::ETYPE_PTP) {
33 m_ptp_rx_type = PacketType::PTP_L2;
34 }
else if (ether_type == satcat5::eth::ETYPE_IPV4) {
39 if (length < 24)
return false;
41 u8 protocol = peek[23];
42 if (protocol == satcat5::ip::PROTO_UDP) {
44 unsigned header_length = peek[14] & 0x000f;
48 unsigned src_port_index = 14 + header_length * 4;
49 unsigned dst_port_index = 16 + header_length * 4;
52 if (length < dst_port_index + 2)
return false;
58 if (src_port == satcat5::udp::PORT_PTP_EVENT ||
59 src_port == satcat5::udp::PORT_PTP_GENERAL ||
60 dst_port == satcat5::udp::PORT_PTP_EVENT ||
61 dst_port == satcat5::udp::PORT_PTP_GENERAL) {
62 m_ptp_rx_type = PacketType::PTP_L3;
68 return m_ptp_rx_type != PacketType::NON_PTP;
Generic API for network ports that support PTP.
EtherType field (uint16) is used a protocol-ID [1536..65535].
UDP and TCP ports are both 16-bit unsigned integers.
Miscellaneous mathematical utility functions.
u16 extract_be_u16(const u8 *src)
Extract fields from a big-endian byte array.