Ethernet Interface

File: csp/interfaces/csp_if_eth.h

Description: Ethernet (ETH) interface.

Ethernet frames holds up to 1500 bytes, and may be limited by an MTU value that is lower, so in order to transmit CSP packets larger than this, a segmentation protocol is required. The Ethernet standard assumes that this is handled by an upper lat protocol, like bt the IP protocol. This Ethernet driver therefore implements a CSP segmentation protocol that is called EFP. It is similar to CAN CFP.

Each packet segment is prepended an EFP header with the following content:

  • Version: 1 bit

  • Unused: 2 bit

  • SegmentId: 5 bit

  • PacketId: 8 bit

  • PacketLengthMSB: 8 bit

  • PacketLengthLSB: 8 bit

The Version is zero. EFP discard Ethernet frames with the leading bit being 1. For a potential new protocol to coexist with EFP the first bit in the meader must be 1. The Unused bits must be zero. The SegmentId is a sequential number that starts at zero for each packet and increments by one for each segment. It wraps around to zero at 32, implying that the larges CSP packet size that can be handled is 32 * MTU. The PacketId is a sequential number that is same for all segments of the same packet, and increments by one for every new packet. It wraps around to zero at 256, implying that the protocol can handle up to 256 packets that are processed in parallel. The PacketLengthMSB and PacketLengthLSB holds the packet length most and least significant bits.

The protocol assumes that a single segment is sent per Ethernet frame. If smaller than the Ethernet payload length zero-padding is applied. Padding may only occur when transferring the last segment. The protocol allows for segments being received out of order.

The protocol differs from CAN CFP by not explicitly storing CSP source and destination addresses in the EFP header. The packets are processed individually, not per CSP connection.

Defines

CSP_ETH_TYPE_CSP
[source]
CSP_ETH_BUF_SIZE
[source]
CSP_ETH_FRAME_SIZE_MAX
[source]
CSP_ETH_ALEN
[source]

Declarations same as found in Linux net/ethernet.h and linux/if_ether.h

Interface Functions

_Bool csp_eth_pack_header(csp_eth_header_t *buf, uint16_t packet_id, uint16_t src_addr, uint16_t seg_size, uint16_t packet_length)
[source]

Pack and byteswapp CSP ethernet header element as required

_Bool csp_eth_unpack_header(csp_eth_header_t *buf, uint32_t *packet_id, uint16_t *seg_size, uint16_t *packet_length)
[source]

Unpack CSP ethernet header element

void csp_eth_arp_set_addr(uint8_t *mac_addr, uint16_t csp_addr)
[source]

Store MAC address for given CSP node

void csp_eth_arp_get_addr(uint8_t *mac_addr, uint16_t csp_addr)
[source]

Find MAC address for given CSP node

int csp_eth_tx(csp_iface_t *iface, uint16_t via, csp_packet_t *packet, int from_me)
[source]

Send CSP packet over CAN (nexthop).

This function will split the CSP packet into several fragments and call csp_eth_tx_frame() for sending each fragment.

Returns:

#CSP_ERR_NONE on success, otherwise an error code.

int csp_eth_rx(csp_iface_t *iface, csp_eth_header_t *eth_frame, uint32_t received_len, int *task_woken)
[source]

Process received CSP ethernet frame.

Called from driver when a single ethernet frame has been received. The function will gather the fragments into a single CSP packet and route it on when complete.

Parameters:
  • iface – incoming interface.

  • eth_frame – received ETH data.

  • received_len – received ETH data length.

  • pxTaskWoken – Valid reference if called from ISR, otherwise NULL!

Returns:

#CSP_ERR_NONE on success, otherwise an error code.