TCPIP_STACK_PACKET_HANDLER Type
C
typedef bool (* TCPIP_STACK_PACKET_HANDLER)(TCPIP_NET_HANDLE hNet, struct _tag_TCPIP_MAC_PACKET* rxPkt, uint16_t frameType, const void* hParam);
Description
TCPIP packet handler pointer. Pointer to a function that will be called by the TCP/IP manager when a RX packet is available.
Preconditions
None.
Parameters
Parameters | Description |
---|---|
hNet | Network handle on which packet has arrived. |
rxPkt | Pointer to incoming packet. |
frameType | Type of packet being processed. |
Returns
True - If the packet is processed by the external handler. In this case the TCP/IP manager will no longer process the packet.
False - The packet needs to be processed internally by the stack as usual.
Remarks
Value is converted to host endianess. Standard Ethernet frame value: 0x0800 - IPV4, 0x86DD - IPv6, 0x0806 - ARP, etc. hParam - user passed parameter when handler was registered.
The packet handler is called in the TCP/IP stack manager context. The handler should be kept as short as possible as it affects the processing of all the other RX traffic.
Before calling the external packet handler:
The rxPkt->pktIf points to the interface receiving the packet.
No other processing/checks are done.
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.