Prusa MINI Firmware overview
inet_chksum.h File Reference
#include "lwip/opt.h"
#include "lwip/pbuf.h"
#include "lwip/ip_addr.h"

Go to the source code of this file.

Macros

#define SWAP_BYTES_IN_WORD(w)   (((w) & 0xff) << 8) | (((w) & 0xff00) >> 8)
 
#define FOLD_U32T(u)   (((u) >> 16) + ((u) & 0x0000ffffUL))
 
#define LWIP_CHKSUM_COPY_ALGORITHM   0
 

Functions

u16_t inet_chksum (const void *dataptr, u16_t len)
 
u16_t inet_chksum_pbuf (struct pbuf *p)
 
u16_t ip_chksum_pseudo (struct pbuf *p, u8_t proto, u16_t proto_len, const ip_addr_t *src, const ip_addr_t *dest)
 
u16_t ip_chksum_pseudo_partial (struct pbuf *p, u8_t proto, u16_t proto_len, u16_t chksum_len, const ip_addr_t *src, const ip_addr_t *dest)
 

Detailed Description

IP checksum calculation functions

Macro Definition Documentation

◆ SWAP_BYTES_IN_WORD

#define SWAP_BYTES_IN_WORD (   w)    (((w) & 0xff) << 8) | (((w) & 0xff00) >> 8)

Swap the bytes in an u16_t: much like lwip_htons() for little-endian

◆ FOLD_U32T

#define FOLD_U32T (   u)    (((u) >> 16) + ((u) & 0x0000ffffUL))

Split an u32_t in two u16_ts and add them up

◆ LWIP_CHKSUM_COPY_ALGORITHM

#define LWIP_CHKSUM_COPY_ALGORITHM   0

Function Documentation

◆ inet_chksum()

u16_t inet_chksum ( const void dataptr,
u16_t  len 
)
556 {
557  return (u16_t)~(unsigned int)LWIP_CHKSUM(dataptr, len);
558 }

◆ inet_chksum_pbuf()

u16_t inet_chksum_pbuf ( struct pbuf p)

Calculate a checksum over a chain of pbufs (without pseudo-header, much like inet_chksum only pbufs are used).

Parameters
ppbuf chain over that the checksum should be calculated
Returns
checksum (as u16_t) to be saved directly in the protocol header
569 {
570  u32_t acc;
571  struct pbuf *q;
572  u8_t swapped;
573 
574  acc = 0;
575  swapped = 0;
576  for (q = p; q != NULL; q = q->next) {
577  acc += LWIP_CHKSUM(q->payload, q->len);
578  acc = FOLD_U32T(acc);
579  if (q->len % 2 != 0) {
580  swapped = 1 - swapped;
581  acc = SWAP_BYTES_IN_WORD(acc);
582  }
583  }
584 
585  if (swapped) {
586  acc = SWAP_BYTES_IN_WORD(acc);
587  }
588  return (u16_t)~(acc & 0xffffUL);
589 }

◆ ip_chksum_pseudo()

u16_t ip_chksum_pseudo ( struct pbuf p,
u8_t  proto,
u16_t  proto_len,
const ip_addr_t src,
const ip_addr_t dest 
)
381 {
382 #if LWIP_IPV6
383  if (IP_IS_V6(dest)) {
384  return ip6_chksum_pseudo(p, proto, proto_len, ip_2_ip6(src), ip_2_ip6(dest));
385  }
386 #endif /* LWIP_IPV6 */
387 #if LWIP_IPV4 && LWIP_IPV6
388  else
389 #endif /* LWIP_IPV4 && LWIP_IPV6 */
390 #if LWIP_IPV4
391  {
392  return inet_chksum_pseudo(p, proto, proto_len, ip_2_ip4(src), ip_2_ip4(dest));
393  }
394 #endif /* LWIP_IPV4 */
395 }

◆ ip_chksum_pseudo_partial()

u16_t ip_chksum_pseudo_partial ( struct pbuf p,
u8_t  proto,
u16_t  proto_len,
u16_t  chksum_len,
const ip_addr_t src,
const ip_addr_t dest 
)
528 {
529 #if LWIP_IPV6
530  if (IP_IS_V6(dest)) {
531  return ip6_chksum_pseudo_partial(p, proto, proto_len, chksum_len, ip_2_ip6(src), ip_2_ip6(dest));
532  }
533 #endif /* LWIP_IPV6 */
534 #if LWIP_IPV4 && LWIP_IPV6
535  else
536 #endif /* LWIP_IPV4 && LWIP_IPV6 */
537 #if LWIP_IPV4
538  {
539  return inet_chksum_pseudo_partial(p, proto, proto_len, chksum_len, ip_2_ip4(src), ip_2_ip4(dest));
540  }
541 #endif /* LWIP_IPV4 */
542 }
IP_IS_V6
#define IP_IS_V6(ipaddr)
Definition: ip_addr.h:296
pbuf::len
u16_t len
Definition: pbuf.h:159
u16_t
uint16_t u16_t
Definition: arch.h:121
u32_t
uint32_t u32_t
Definition: arch.h:123
pbuf::next
struct pbuf * next
Definition: pbuf.h:144
LWIP_CHKSUM
#define LWIP_CHKSUM
Definition: inet_chksum.c:57
NULL
#define NULL
Definition: usbd_def.h:53
SWAP_BYTES_IN_WORD
#define SWAP_BYTES_IN_WORD(w)
Definition: inet_chksum.h:47
fsdata_file::len
int len
Definition: fsdata.h:42
u8_t
uint8_t u8_t
Definition: arch.h:119
ip_2_ip6
#define ip_2_ip6(ipaddr)
Definition: ip_addr.h:301
createSpeedLookupTable.int
int
Definition: createSpeedLookupTable.py:15
FOLD_U32T
#define FOLD_U32T(u)
Definition: inet_chksum.h:52
pbuf
Definition: pbuf.h:142
pbuf::payload
void * payload
Definition: pbuf.h:147