1#include "../../network_stack_driver.h"
3#include "../../ptp_defs.h"
4#include "../../ptp_types.h"
5#include "../../task_ptp.h"
7#include "etherlib/cbd_table.h"
8#include "etherlib/connection_block.h"
9#include "etherlib/eth_interface.h"
10#include "etherlib/global_state.h"
11#include "etherlib/prefab/conn_blocks/custom_ethertype_connblock.h"
12#include "etherlib/prefab/conn_blocks/igmp_connblock.h"
13#include "etherlib/prefab/packet_parsers/ethernet_frame.h"
14#include "etherlib/prefab/packet_parsers/ipv4_types.h"
15#include "etherlib/timestamping.h"
29static void ptp_transmit_cb(uint32_t ts_s, uint32_t ts_ns, uint32_t tag);
30static int ptp_receive_cb(
const Pckt *packet, PcktSieveLayerTag tag);
35 ConnBlock cb = igmp_new_connblock(get_default_interface());
37 void (*igmp_fn)(ConnBlock *, ip4_addr) = join ? igmp_report_membership : igmp_leave_group;
48#define CLOSE_CONNECTION_IF_EXISTS(d) if (d >= CBD_LOWEST_DESCRIPTOR) { close_connection(d); d = 0; }
60 if ((tp == -1) || (dm == -1)) {
68 EthInterface *intf = get_default_interface();
98 uint16_t pcktClass = packet->header->props.ownPacketClass;
100 case ETH_UDP_PACKET_CLASS:
111 ptp_receive_enqueue(packet->payload, packet->payloadSize, packet->time_s, packet->time_ns, tp);
113 MSG(
"Unknown PTP packet class: '%d'!\n", tp);
123 if (pMsg->
pTs != NULL) {
143 udp_sendto_arg(conn, pMsg->
data, pMsg->
size, ipaddr, port, (uint32_t)pMsg);
146 cet_send_arg(
PTP_L2, ethaddr, pMsg->
data, pMsg->
size, (uint32_t)pMsg);
151 memcpy(hwa, get_default_interface()->mac, ETH_HW_ADDR_LEN);
PtpCircBuf gRawTxMsgBuf
Output circular buffers.
static int ptp_receive_cb(const Pckt *packet, PcktSieveLayerTag tag)
void ptp_nsd_transmit_msg(RawPtpMessage *pMsg)
#define CLOSE_CONNECTION_IF_EXISTS(d)
static PtpDelayMechanism DM
void ptp_nsd_igmp_join_leave(bool join)
void ptp_nsd_init(PtpTransportType tp, PtpDelayMechanism dm)
void ptp_nsd_get_interface_address(uint8_t *hwa)
static cbd PTP_L4_GENERAL
static PtpTransportType TP
static void ptp_transmit_cb(uint32_t ts_s, uint32_t ts_ns, uint32_t tag)
const uint8_t PTP_ETHERNET_PEER_DELAY[6]
PTP's L2 Peer_Delay Ethernet address.
const uint8_t PTP_ETHERNET_PRIMARY[6]
PTP's L2 Primary Ethernet address.
const ip_addr_t PTP_IGMP_PRIMARY
Primary IGMP address.
#define ETHERTYPE_PTP
(for lwIP conformity)
#define PTP_PORT_EVENT
PTP event message port.
#define PTP_PORT_GENERAL
PTP general message port.
const ip_addr_t PTP_IGMP_PEER_DELAY
Peer_Delay IGMP address.
void ptp_circ_buf_free(PtpCircBuf *pCircBuf)
PtpTransportType
PTP transport type enumeration.
@ PTP_TP_IPv4
IPv4 Transport Type.
@ PTP_TP_802_3
Ethernet Transport Type.
PtpMessageClass
Enumeration for different PTP message classes.
@ PTP_MC_EVENT
Event Message Class.
PtpDelayMechanism
PTP Delay mechanism enumeration.
@ PTP_DM_E2E
End-to-End Delay Mechanism.
@ PTP_DM_P2P
Peer-to-Peer Delay Mechanism.
Raw PTP message structure.
PtpMessageClass tx_mc
transmit message class
void(* pTxCb)(const struct RawPtpMessage_ *pMsg)
transmit callback function
uint32_t size
Packet size.
TimestampI * pTs
pointer to timestamp
uint8_t data[(128)]
raw packet data
int32_t nanosec
nanoseconds
void ptp_receive_enqueue(const void *pPayload, uint32_t len, uint32_t ts_sec, uint32_t ts_ns, int tp)