TCPIP_TCP_PACKET_HANDLER Type

C

typedef bool (* TCPIP_TCP_PACKET_HANDLER)(TCPIP_NET_HANDLE hNet, struct _tag_TCPIP_MAC_PACKET* rxPkt, const void* hParam);

Description

TCP packet handler Pointer

Pointer to a function that will be called by the TCP module when a RX packet is available.

Preconditions

None.

Parameters

ParametersDescription
hNetNetwork handle on which the packet has arrived.
rxPktPointer to incoming packet.
hParamUser passed parameter when handler was registered.

Returns

  • True - If the packet is processed by the external handler. In this case the TCP module will no longer process the packet.

  • False - If the packet needs to be processed internally by the TCP as usual.

Remarks

The packet handler is called in the TCP context. The handler should be kept as short as possible as it affects the processing of all the other TCP RX traffic.

Before calling the external packet handler:

  • the rxPkt->pktFlags has the bit 9 (value 0x0200) set for an IPv6 packet, cleared for IPv4

  • the rxPkt->pTransportLayer points to an TCP_HEADER data structure.

  • the rxPkt->pNetLayer points to an IPV4_HEADER/IPV6_HEADER data structure.

  • the rxPkt->pktIf points to the interface receiving the packet

  • the first data segment segLen is adjusted to store the size of the TCP data

Important! When the packet handler returns true, once it's done processing the packet, it needs to acknowledge it, i.e. return to the owner, which is the MAC driver serving the network interface! This means that the packet acknowledge function needs to be called, with a proper acknowledge parameter and the QUEUED flag needs to be cleared, if needed: if((*rxPkt->ackFunc)(rxPkt, rxPkt->ackParam)) { rxPkt->pktFlags &= ~TCPIP_MAC_PKT_FLAG_QUEUED; } Failure to do that will result in memory leaks and starvation of the MAC driver. See the tcpip_mac.h for details.