This library allows a user to add IPv4 network interface drivers to the network stack (to implement wireless network drivers, PPP, and others).
To add a network interface to the network stack, the user needs to implement a function that handles inbound network traffic. After processing the inbound packet (stripping the transport headers, defragmenting the packet, etc.), the inbound packet handler needs to submit the raw IPv4 packet to the network stack using the netif_packetreceived() function (this function duplicates the data and enqueues it provided the packet looks like a valid IPv4 packet).
The second requirement for a user-defined network driver is the transmit function for outbound traffic. This callback function will be called whenever the network stack determines that traffic should be sent on the user-defined interface.
/* User defined transmit function */
int transmit(unsigned char *packet, int len)
{
// ...
return 1; // Sent the packet, don't retry
}
To register a user-defined network driver with the network stack, the user calls the netif_addinterface() function. Up to two user-defined interfaces are supported.
/* Add a non-default interface 10.0.0.3/8 with gateway 10.0.0.1 */
netif_addinterface("user0", 0x0a000003L, 0xff000000L, 0x0a000001L, 0, &transmit, 1500, 128);
The Network Interface Library sample application shows a framework for user-defined network interfaces (the sample application simply prints the packet data that would be sent).
Download