netb.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*!
  2. * Copyright (C) Fraunhofer-Institut for Photonic Microsystems (IPMS)
  3. * Maria-Reiche-Str. 2
  4. * 01109 Dresden
  5. *
  6. * Unauthorized copying of this file, via any medium is strictly prohibited
  7. * Proprietary and confidential
  8. *
  9. * \file netb.h
  10. * \author zimmerli
  11. * \date 2020-01-20
  12. * \brief Network buffer
  13. *
  14. */
  15. #ifndef NETB_H_
  16. #define NETB_H_
  17. #include <stdint.h>
  18. #include <kernel/base/kernel.h>
  19. /**
  20. * \brief network buffer
  21. *
  22. * head, data, tail, end: compatible to linux kernel sk_buff
  23. * netdev: set by netdev layer
  24. * tstamp_id: 0 for no timestamping, otherwise registered netdev tstamp_id
  25. */
  26. struct netb_s {
  27. addr_t head; //!< start address of buffer
  28. addr_t data; //!< start address of used data
  29. addr_t tail; //!< end address of used data
  30. addr_t end; //!< end address of buffer
  31. int64_t timestamp; //!< rx timestamp in nanoseconds (local time)
  32. void *netdev; //!< network device
  33. uint8_t tstamp_id; //!< tx timestamping id, 0 for no timestamping
  34. uint8_t priority; //!< priority code, see ether.h ETH_PRIO_*
  35. };
  36. /**
  37. * \brief Get length of used data
  38. * @param netb pointer to network buffer
  39. */
  40. #define netb_length(netb) (netb->tail - netb->data)
  41. #define netb_remaininglength(netb) (netb->end - netb->data)
  42. // object functions
  43. void netb_set_empty(struct netb_s *netb);
  44. void netb_reserve(struct netb_s *netb, uint32_t len);
  45. uint8_t *netb_push(struct netb_s *netb, uint32_t len);
  46. uint8_t *netb_pull(struct netb_s *netb, uint32_t len);
  47. uint8_t *netb_put(struct netb_s *netb, uint32_t len);
  48. #endif /* NETB_H_ */