lwIP
2.1.2
Lightweight IP stack
|
Use this mode if you do not run an OS on your system. #define NO_SYS to 1. Feed incoming packets to netif->input(pbuf, netif) function from mainloop, not from interrupt context. You can allocate a Packet buffers (PBUF) in interrupt context and put them into a queue which is processed from mainloop.
Call sys_check_timeouts() periodically in the mainloop.
Porting: implement all functions in Time, Critical sections and compiler_abstraction.
You can only use "raw" APIs in this mode.
Sample code:
void
eth_mac_irq()
{
if(p != NULL) {
if(!queue_try_put(&queue, p)) {
}
}
}
{
LINK_STATS_INC(link.xmit);
int unicast = ((p->
payload[0] & 0x01) == 0);
if (unicast) {
} else {
}
lock_interrupts();
unlock_interrupts();
}
static void
{
}
{
}
void
main(void)
{
while(1) {
if(link_state_changed()) {
if(link_is_up()) {
} else {
}
}
lock_interrupts();
struct pbuf* p = queue_try_get(&queue);
unlock_interrupts();
if(p != NULL) {
LINK_STATS_INC(link.recv);
int unicast = ((p->
payload[0] & 0x01) == 0);
if (unicast) {
} else {
}
}
}
}
}
◆ ethernet_input()
Process received ethernet frames. Using this function instead of directly calling ip_input and passing ARP frames through etharp in ethernetif_input, the ARP cache is protected from concurrent access.
Don't call directly, pass to netif_add() and call netif->input().
- Parameters
-
p | the received packet, p->payload pointing to the ethernet header |
netif | the network interface on which the packet was received |
- See also
- LWIP_HOOK_UNKNOWN_ETH_PROTOCOL
-
ETHARP_SUPPORT_VLAN
-
LWIP_HOOK_VLAN_CHECK
◆ ip_input()
If both IP versions are enabled, this function can dispatch packets to the correct one. Don't call directly, pass to netif_add() and call netif->input().
◆ lwip_init()
Initialize all modules. Use this in NO_SYS mode. Use tcpip_init() otherwise.
◆ netif_input()
Forwards a received packet for input processing with ethernet_input() or ip_input() depending on netif flags. Don't call directly, pass to netif_add() and call netif->input(). Only works if the netif driver correctly sets NETIF_FLAG_ETHARP and/or NETIF_FLAG_ETHERNET flag!
◆ sys_check_timeouts()
void sys_check_timeouts |
( |
void |
| ) |
|
Handle timeouts for NO_SYS==1 (i.e. without using tcpip_thread/sys_timeouts_mbox_fetch(). Uses sys_now() to call timeout handler functions when timeouts expire.
Must be called periodically from your main loop.
#define NETIF_FLAG_IGMP
Definition: netif.h:104
void netif_set_up(struct netif *netif)
Definition: netif.c:844
err_t dhcp_start(struct netif *netif)
Definition: dhcp.c:737
netif_input_fn input
Definition: netif.h:288
void httpd_init(void)
Definition: httpd.c:2659
char * ip4addr_ntoa(const ip4_addr_t *addr)
Definition: ip4_addr.c:267
u16_t tot_len
Definition: pbuf.h:200
#define MIB2_INIT_NETIF(netif, type, speed)
Definition: snmp.h:119
#define NETIF_FLAG_ETHARP
Definition: netif.h:97
err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len)
Definition: pbuf.c:1196
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:725
u16_t mtu
Definition: netif.h:335
u8_t flags
Definition: netif.h:345
void netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit)
Definition: netif.c:1497
netif_linkoutput_fn linkoutput
Definition: netif.h:299
u16_t pbuf_copy_partial(const struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
Definition: pbuf.c:1027
u8_t hwaddr[6U]
Definition: netif.h:341
#define IP4_ADDR_ANY
Definition: ip_addr.h:388
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
Definition: pbuf.c:224
err_t etharp_output(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr)
Definition: etharp.c:791
#define MIB2_STATS_NETIF_INC(n, x)
Definition: snmp.h:105
u8_t ip6_autoconfig_enabled
Definition: netif.h:353
err_t netif_input(struct pbuf *p, struct netif *inp)
Definition: netif.c:217
u8_t hwaddr_len
Definition: netif.h:343
char name[2]
Definition: netif.h:347
void sys_check_timeouts(void)
Definition: timeouts.c:352
void netif_set_default(struct netif *netif)
Definition: netif.c:822
s8_t err_t
Definition: err.h:96
#define NETIF_FLAG_ETHERNET
Definition: netif.h:101
#define SMEMCPY(dst, src, len)
Definition: opt.h:145
#define MIB2_STATS_NETIF_ADD(n, x, val)
Definition: snmp.h:110
void netif_set_link_down(struct netif *netif)
Definition: netif.c:1026
err_t ethip6_output(struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr)
Definition: ethip6.c:79
void lwip_init(void)
Definition: init.c:335
void netif_set_link_up(struct netif *netif)
Definition: netif.c:988
struct netif * netif_add(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw, void *state, netif_init_fn init, netif_input_fn input)
Definition: netif.c:276
#define NETIF_FLAG_MLD6
Definition: netif.h:107
netif_output_ip6_fn output_ip6
Definition: netif.h:305
void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback)
Definition: netif.c:957
netif_output_fn output
Definition: netif.h:294
void * payload
Definition: pbuf.h:191
#define NETIF_FLAG_BROADCAST
Definition: netif.h:87