Microchip® Advanced Software Framework

raw.h File Reference
#include "lwip/opt.h"
#include "lwip/pbuf.h"
#include "lwip/def.h"
#include "lwip/ip.h"
#include "lwip/ip_addr.h"
#include "lwip/ip6_addr.h"

Data Structures

struct  raw_pcb
 

Macros

#define raw_bind_ip6(pcb, ip6addr)   raw_bind(pcb, ip6_2_ip(ip6addr))
 
#define raw_connect_ip6(pcb, ip6addr)   raw_connect(pcb, ip6_2_ip(ip6addr))
 
#define raw_init()   /* Compatibility define, no init needed. */
 
#define RAW_PCB_RECV_IP6   raw_recv_ip6_fn ip6;
 
#define raw_recv_ip6(pcb, recv_ip6_fn, recv_arg)   raw_recv(pcb, (raw_recv_fn)recv_ip6_fn, recv_arg)
 
#define raw_sendto_ip6(pcb, pbuf, ip6addr)   raw_sendto(pcb, pbuf, ip6_2_ip(ip6addr))
 

Typedefs

typedef u8_t(* raw_recv_fn )(void *arg, struct raw_pcb *pcb, struct pbuf *p, ip_addr_t *addr)
 Function prototype for raw pcb receive callback functions. More...
 
typedef u8_t(* raw_recv_ip6_fn )(void *arg, struct raw_pcb *pcb, struct pbuf *p, ip6_addr_t *addr)
 Function prototype for raw pcb IPv6 receive callback functions. More...
 

Functions

err_t raw_bind (struct raw_pcb *pcb, ip_addr_t *ipaddr)
 Bind a RAW PCB. More...
 
err_t raw_connect (struct raw_pcb *pcb, ip_addr_t *ipaddr)
 Connect an RAW PCB. More...
 
u8_t raw_input (struct pbuf *p, struct netif *inp)
 Determine if in incoming IP packet is covered by a RAW PCB and if so, pass it to a user-provided receive callback function. More...
 
struct raw_pcbraw_new (u8_t proto)
 Create a RAW PCB. More...
 
struct raw_pcbraw_new_ip6 (u8_t proto)
 Create a RAW PCB for IPv6. More...
 
void raw_recv (struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg)
 Set the callback function for received packets that match the raw PCB's protocol and binding. More...
 
void raw_remove (struct raw_pcb *pcb)
 Remove an RAW PCB. More...
 
err_t raw_send (struct raw_pcb *pcb, struct pbuf *p)
 Send the raw IP packet to the address given by raw_connect() More...
 
err_t raw_sendto (struct raw_pcb *pcb, struct pbuf *p, ip_addr_t *ipaddr)
 Send the raw IP packet to the given address. More...
 

#define raw_bind_ip6 (   pcb,
  ip6addr 
)    raw_bind(pcb, ip6_2_ip(ip6addr))
#define raw_connect_ip6 (   pcb,
  ip6addr 
)    raw_connect(pcb, ip6_2_ip(ip6addr))
#define raw_init ( )    /* Compatibility define, no init needed. */

Referenced by lwip_init().

#define RAW_PCB_RECV_IP6   raw_recv_ip6_fn ip6;
#define raw_recv_ip6 (   pcb,
  recv_ip6_fn,
  recv_arg 
)    raw_recv(pcb, (raw_recv_fn)recv_ip6_fn, recv_arg)
#define raw_sendto_ip6 (   pcb,
  pbuf,
  ip6addr 
)    raw_sendto(pcb, pbuf, ip6_2_ip(ip6addr))

typedef u8_t(* raw_recv_fn)(void *arg, struct raw_pcb *pcb, struct pbuf *p, ip_addr_t *addr)

Function prototype for raw pcb receive callback functions.

Parameters
arguser supplied argument (raw_pcb.recv_arg)
pcbthe raw_pcb which received data
pthe packet buffer that was received
addrthe remote IP address from which the packet was received
Returns
1 if the packet was 'eaten' (aka. deleted), 0 if the packet lives on If returning 1, the callback is responsible for freeing the pbuf if it's not used any more.
typedef u8_t(* raw_recv_ip6_fn)(void *arg, struct raw_pcb *pcb, struct pbuf *p, ip6_addr_t *addr)

Function prototype for raw pcb IPv6 receive callback functions.

Parameters
arguser supplied argument (raw_pcb.recv_arg)
pcbthe raw_pcb which received data
pthe packet buffer that was received
addrthe remote IPv6 address from which the packet was received
Returns
1 if the packet was 'eaten' (aka. deleted), 0 if the packet lives on If returning 1, the callback is responsible for freeing the pbuf if it's not used any more.

err_t raw_bind ( struct raw_pcb pcb,
ip_addr_t ipaddr 
)

Bind a RAW PCB.

Parameters
pcbRAW PCB to be bound with a local address ipaddr.
ipaddrlocal IP address to bind with. Use IP_ADDR_ANY to bind to all local interfaces.
Returns
lwIP error code.
  • ERR_OK. Successful. No error occurred.
  • ERR_USE. The specified IP address is already bound to by another RAW PCB.
See Also
raw_disconnect()

References ERR_OK, ipX_addr_set_ipaddr, and PCB_ISIPV6.

Referenced by lwip_netconn_do_bind(), and ping_raw_init().

err_t raw_connect ( struct raw_pcb pcb,
ip_addr_t ipaddr 
)

Connect an RAW PCB.

This function is required by upper layers of lwip. Using the raw api you could use raw_sendto() instead

This will associate the RAW PCB with the remote address.

Parameters
pcbRAW PCB to be connected with remote address ipaddr and port.
ipaddrremote IP address to connect with.
Returns
lwIP error code
See Also
raw_disconnect() and raw_sendto()

References ERR_OK, ipX_addr_set_ipaddr, and PCB_ISIPV6.

Referenced by lwip_netconn_do_connect().

u8_t raw_input ( struct pbuf p,
struct netif inp 
)

Determine if in incoming IP packet is covered by a RAW PCB and if so, pass it to a user-provided receive callback function.

Given an incoming IP datagram (as a chain of pbufs) this function finds a corresponding RAW PCB and calls the corresponding receive callback function.

Parameters
ppbuf to be demultiplexed to a RAW PCB.
inpnetwork interface on which the datagram was received.
Returns
- 1 if the packet has been eaten by a RAW PCB receive callback function. The caller MAY NOT not reference the packet any longer, and MAY NOT call pbuf_free().
- 0 if packet is not eaten (pbuf is still referenced by the caller).

References if(), raw_pcb::ip4, ip6_current_src_addr, IP6H_NEXTH, ip_addr_isbroadcast, ip_current_dest_addr, ip_current_src_addr, ip_get_option, IP_PCB_IPVER_INPUT_MATCH, IPH_PROTO, IPH_V, ipX_addr_cmp, ipX_addr_isany, ipX_current_dest_addr, LWIP_ASSERT, LWIP_IPV6, raw_pcb::next, NULL, pbuf::payload, PCB_ISIPV6, raw_pcb::protocol, raw_pcbs, raw_pcb::recv, raw_pcb::recv_arg, and SOF_BROADCAST.

Referenced by ip6_input(), and ip_input().

struct raw_pcb* raw_new ( u8_t  proto)

Create a RAW PCB.

Returns
The RAW PCB which was created. NULL if the PCB data structure could not be allocated.
Parameters
protothe protocol number of the IPs payload (e.g. IP_PROTO_ICMP)
See Also
raw_remove()

References LWIP_DBG_TRACE, LWIP_DEBUGF, memp_malloc(), raw_pcb::next, NULL, raw_pcb::protocol, RAW_DEBUG, and raw_pcbs.

Referenced by pcb_new(), ping_raw_init(), and raw_new_ip6().

struct raw_pcb* raw_new_ip6 ( u8_t  proto)

Create a RAW PCB for IPv6.

Returns
The RAW PCB which was created. NULL if the PCB data structure could not be allocated.
Parameters
protothe protocol number (next header) of the IPv6 packet payload (e.g. IP6_NEXTH_ICMP6)
See Also
raw_remove()

References ip_set_v6, and raw_new().

void raw_recv ( struct raw_pcb pcb,
raw_recv_fn  recv,
void recv_arg 
)

Set the callback function for received packets that match the raw PCB's protocol and binding.

The callback function MUST either

  • eat the packet by calling pbuf_free() and returning non-zero. The packet will not be passed to other raw PCBs or other protocol layers.
  • not free the packet, and return zero. The packet will be matched against further PCBs and/or forwarded to another protocol layers.
Returns
non-zero if the packet was free()d, zero if the packet remains available for others.

References raw_pcb::ip4, raw_pcb::recv, and raw_pcb::recv_arg.

Referenced by pcb_new(), and ping_raw_init().

void raw_remove ( struct raw_pcb pcb)

Remove an RAW PCB.

Parameters
pcbRAW PCB to be removed. The PCB is removed from the list of RAW PCB's and the data structure is freed from memory.
See Also
raw_new()

References memp_free(), raw_pcb::next, and NULL.

Referenced by lwip_netconn_do_delconn().

err_t raw_send ( struct raw_pcb pcb,
struct pbuf p 
)

Send the raw IP packet to the address given by raw_connect()

Parameters
pcbthe raw pcb which to send
pthe IP payload to send

References ipX_2_ip, and raw_sendto().

Referenced by lwip_netconn_do_send().

err_t raw_sendto ( struct raw_pcb pcb,
struct pbuf p,
ip_addr_t ipaddr 
)

Send the raw IP packet to the given address.

Note that actually you cannot modify the IP headers (this is inconsistent with the receive callback where you actually get the IP headers), you can only specify the IP payload here. It requires some more changes in lwIP. (there will be a raw_send() function then.)

Parameters
pcbthe raw pcb which to send
pthe IP payload to send
ipaddrthe destination address of the IP packet

References raw_pcb::chksum_offset, raw_pcb::chksum_reqd, ERR_MEM, ERR_RTE, ERR_VAL, ip6_chksum_pseudo(), IP6_HLEN, ip_2_ipX, ip_addr_isbroadcast, ip_get_option, IP_HLEN, ipX_2_ip, ipX_2_ip6, ipX_addr_debug_print, ipX_addr_isany, ipX_netif_get_local_ipX, ipX_output_if, ipX_route, pbuf::len, LWIP_ASSERT, LWIP_DBG_LEVEL_SERIOUS, LWIP_DBG_LEVEL_WARNING, LWIP_DBG_TRACE, LWIP_DEBUGF, NETIF_SET_HWADDRHINT, NULL, pbuf::payload, pbuf_alloc(), pbuf_chain(), pbuf_free(), pbuf_header(), PBUF_IP, PBUF_RAM, PCB_ISIPV6, raw_pcb::protocol, RAW_DEBUG, SOF_BROADCAST, and pbuf::tot_len.

Referenced by lwip_netconn_do_send(), ping_send(), and raw_send().