netbuf.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #ifndef _NET_NETBUF_H_
  2. #define _NET_NETBUF_H_
  3. /*
  4. * Copyright (C) 2001-2003 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. *
  34. * -
  35. * Portions Copyright (C) 2000 David J. Hudson <dave@humbug.demon.co.uk>
  36. *
  37. * This file is distributed in the hope that it will be useful, but WITHOUT
  38. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  39. * FITNESS FOR A PARTICULAR PURPOSE.
  40. *
  41. * You can redistribute this file and/or modify it under the terms of the GNU
  42. * General Public License (GPL) as published by the Free Software Foundation;
  43. * either version 2 of the License, or (at your discretion) any later version.
  44. * See the accompanying file "copying-gpl.txt" for more details.
  45. *
  46. * As a special exception to the GPL, permission is granted for additional
  47. * uses of the text contained in this file. See the accompanying file
  48. * "copying-liquorice.txt" for details.
  49. * -
  50. * Portions Copyright (c) 1983, 1993 by
  51. * The Regents of the University of California. All rights reserved.
  52. *
  53. * Redistribution and use in source and binary forms, with or without
  54. * modification, are permitted provided that the following conditions
  55. * are met:
  56. * 1. Redistributions of source code must retain the above copyright
  57. * notice, this list of conditions and the following disclaimer.
  58. * 2. Redistributions in binary form must reproduce the above copyright
  59. * notice, this list of conditions and the following disclaimer in the
  60. * documentation and/or other materials provided with the distribution.
  61. * 3. Neither the name of the University nor the names of its contributors
  62. * may be used to endorse or promote products derived from this software
  63. * without specific prior written permission.
  64. *
  65. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  66. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  67. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  68. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  69. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  70. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  71. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  72. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  73. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  74. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  75. * SUCH DAMAGE.
  76. */
  77. /*
  78. * $Log$
  79. * Revision 1.5 2008/08/20 06:58:35 haraldkipp
  80. * Added a new flag to mark unicast packets.
  81. *
  82. * Revision 1.4 2008/08/11 06:59:59 haraldkipp
  83. * BSD types replaced by stdint types (feature request #1282721).
  84. *
  85. * Revision 1.3 2008/08/09 17:35:32 haraldkipp
  86. * Simplified NETBUF allocation and release.
  87. *
  88. * Revision 1.2 2008/04/18 13:31:59 haraldkipp
  89. * Changed size parameter from u_short to int, which is easier to handle
  90. * for 32-bit targets. You need to recompile your ARM code. No impact on
  91. * AVR expected
  92. * I changed u_int to int at some places to avoid some warnings during
  93. * compilation of Nut/Net.
  94. * libs.
  95. *
  96. * Revision 1.1.1.1 2003/05/09 14:41:07 haraldkipp
  97. * Initial using 3.2.1
  98. *
  99. * Revision 1.7 2003/05/06 18:43:03 harald
  100. * Cleanup
  101. *
  102. * Revision 1.6 2003/02/04 18:00:37 harald
  103. * Version 3 released
  104. *
  105. * Revision 1.5 2002/06/26 17:29:15 harald
  106. * First pre-release with 2.4 stack
  107. *
  108. */
  109. #include <sys/types.h>
  110. #include <stdint.h>
  111. /*!
  112. * \file dev/netbuf.h
  113. * \brief Network buffer definitions.
  114. */
  115. /*!
  116. * \addtogroup xgnetbuf
  117. */
  118. /*@{*/
  119. /* lower bits may be used as ref-count, if ever needed */
  120. #define NBAF_REFCNT 0x07 /*!< \brief Reference count mask. */
  121. #define NBAF_UNICAST 0x08 /*!< \brief Unicast address. */
  122. #define NBAF_DATALINK 0x10 /*!< \brief Datalink buffer allocated flag. */
  123. #define NBAF_NETWORK 0x20 /*!< \brief Network buffer allocated flag. */
  124. #define NBAF_TRANSPORT 0x40 /*!< \brief Transport buffer allocated flag. */
  125. #define NBAF_APPLICATION 0x80 /*!< \brief Application buffer allocated flag. */
  126. #define NBAF_ALL 0xf0 /*!< \brief Masks allocated buffer flags flag. */
  127. /*!
  128. * \brief Network buffer type.
  129. */
  130. typedef struct _NETBUF NETBUF;
  131. /*!
  132. * \brief Network buffer data type.
  133. */
  134. typedef struct _NBDATA NBDATA;
  135. /*!
  136. * \struct _NBDATA netbuf.h dev/netbuf.h
  137. * \brief Data part of a network buffer structure.
  138. */
  139. struct _NBDATA {
  140. void *vp; /*!< \brief Pointer to data buffer. */
  141. int sz; /*!< \brief Size of data buffer. */
  142. };
  143. /*!
  144. * \struct _NETBUF netbuf.h dev/netbuf.h
  145. * \brief Network buffer structure.
  146. */
  147. struct _NETBUF {
  148. NETBUF *nb_next; /*!< \brief Link to next structure. */
  149. uint8_t nb_flags; /*!< \brief NBAF_ flags. */
  150. NBDATA nb_dl; /*!< \brief Datalink buffer. */
  151. NBDATA nb_nw; /*!< \brief Network buffer. */
  152. NBDATA nb_tp; /*!< \brief Transport buffer. */
  153. NBDATA nb_ap; /*!< \brief Application buffer. */
  154. NETBUF *nb_ref; /*!< \brief Link to clone origin. */
  155. };
  156. /*@}*/
  157. extern NETBUF *NutNetBufAlloc(NETBUF *nb, uint8_t type, int size);
  158. extern NETBUF *NutNetBufClone(NETBUF *nb);
  159. extern NETBUF *NutNetBufClonePart(NETBUF *nb, uint8_t types);
  160. extern void NutNetBufFree(NETBUF *nb);
  161. extern int NutNetBufCollect(NETBUF * nbq, int total);
  162. #endif