channel.h.html 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. channel.h
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='bpf.h.html' title=' bpf.h '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='chars.h.html' title=' chars.h '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  24. *
  25. * All rights reserved.
  26. *
  27. * Redistribution and use in source and binary forms, with or
  28. * without modification, are permitted (subject to the limitations
  29. * in the disclaimer below) provided that the following conditions
  30. * are met:
  31. *
  32. * * Redistributions of source code must retain the above copyright
  33. * notice, this list of conditions and the following disclaimer.
  34. *
  35. * * Redistributions in binary form must reproduce the above
  36. * copyright notice, this list of conditions and the following
  37. * disclaimer in the documentation and/or other materials
  38. * provided with the distribution.
  39. *
  40. * * Neither the name of Qualcomm Atheros nor the names of
  41. * its contributors may be used to endorse or promote products
  42. * derived from this software without specific prior written
  43. * permission.
  44. *
  45. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  46. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  47. * COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR
  48. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  49. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  50. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  51. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  52. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  53. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  54. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  55. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  56. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  57. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59. *
  60. *--------------------------------------------------------------------*/
  61. /*====================================================================*
  62. *
  63. * channel.h - raw packet channel definitions and declarations;
  64. *
  65. * the channel structure contains information needed to perform
  66. * ISO Layer 2, raw packet I/O in a variety of environments;
  67. *
  68. *. Qualcomm Atheros HomePlug AV Powerline Toolkit
  69. *: Copyright (c) 2009-2013 by Qualcomm Atheros Inc. ALL RIGHTS RESERVED;
  70. *; For demonstration and evaluation only; Not for production use.
  71. *
  72. * Contributor(s):
  73. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  74. * Nathaniel Houghton &lt;nathaniel.houghton@qca.qualcomm.com&gt;
  75. *
  76. *--------------------------------------------------------------------*/
  77. #ifndef CHANNEL_HEADER
  78. #define CHANNEL_HEADER
  79. /*====================================================================*
  80. * system header files;
  81. *--------------------------------------------------------------------*/
  82. #include &lt;unistd.h&gt;
  83. /*====================================================================*
  84. * custom header files;
  85. *--------------------------------------------------------------------*/
  86. #include &quot;../ether/ether.h&quot;
  87. #include &quot;../tools/types.h&quot;
  88. /*====================================================================*
  89. * sort out the raw socket mess;
  90. *--------------------------------------------------------------------*/
  91. #if defined (__linux__) || defined (__APPLE__) || defined (__OpenBSD__)
  92. # ifdef WINPCAP
  93. # error &quot;Don't enable winpcap on Linux. It won't work.&quot;
  94. # endif
  95. # ifdef LIBPCAP
  96. # error &quot;Don't enable libpcap on Linux. You don't need it.&quot;
  97. # endif
  98. #elif defined (WIN32)
  99. # ifndef WINPCAP
  100. # error &quot;Define preprocessor constant WINPCAP on Windows.&quot;
  101. # endif
  102. # ifdef LIBPCAP
  103. # error &quot;Don't enable libpcap on Windows. It won't work.&quot;
  104. # endif
  105. #elif defined (__CYGWIN__)
  106. # error &quot;cygwin is unsupported!&quot;
  107. #else
  108. # error &quot;unknown environment&quot;
  109. #endif
  110. /*====================================================================*
  111. * channel flagword bitmasks;
  112. *--------------------------------------------------------------------*/
  113. #define CHANNEL_VERBOSE (1 &lt;&lt; 0)
  114. #define CHANNEL_SILENCE (1 &lt;&lt; 1)
  115. #define CHANNEL_WARNING (1 &lt;&lt; 2)
  116. #define CHANNEL_SUCCESS (1 &lt;&lt; 3)
  117. #define CHANNEL_FAILURE (1 &lt;&lt; 4)
  118. #define CHANNEL_MONITOR (1 &lt;&lt; 5)
  119. #define CHANNEL_UPDATE_TARGET (1 &lt;&lt; 5) /* used by efsu only */
  120. #define CHANNEL_UPDATE_SOURCE (1 &lt;&lt; 6) /* used by efsu only */
  121. #define CHANNEL_LISTEN (1 &lt;&lt; 7) /* used by efsu only */
  122. #define CHANNEL_ETHNUMBER 2
  123. #if defined (__linux__)
  124. # define CHANNEL_ETHDEVICE &quot;eth1&quot;
  125. #elif defined (__APPLE__)
  126. # define CHANNEL_ETHDEVICE &quot;en0&quot;
  127. # define CHANNEL_BPFDEVICE &quot;/dev/bpf%d&quot;
  128. #elif defined (__OpenBSD__)
  129. # define CHANNEL_ETHDEVICE &quot;bce0&quot;
  130. # define CHANNEL_BPFDEVICE &quot;/dev/bpf%d&quot;
  131. #else
  132. # define CHANNEL_ETHDEVICE &quot;nic1&quot;
  133. #endif
  134. #define CHANNEL_FOREVER (unsigned)(-1)
  135. #define CHANNEL_BAILOUT 0
  136. #define CHANNEL_FLAGS 0
  137. #if defined (WIN32)
  138. #define CHANNEL_CAPTURE 50
  139. #define CHANNEL_TIMEOUT 200
  140. #else
  141. #define CHANNEL_CAPTURE 15
  142. #define CHANNEL_TIMEOUT 50
  143. #endif
  144. /*====================================================================*
  145. * common channel error messages;
  146. *--------------------------------------------------------------------*/
  147. #define CHANNEL_CANTSEND &quot;%s: Send timeout or network error&quot;, __func__
  148. #define CHANNEL_CANTREAD &quot;%s: Read timeout or network error&quot;, __func__
  149. /*====================================================================*
  150. * channel ethertype definitions;
  151. *--------------------------------------------------------------------*/
  152. #if !defined (__linux__)
  153. # define ETH_P_802_2 1
  154. #endif
  155. /*====================================================================*
  156. * communication channel structure;
  157. *--------------------------------------------------------------------*/
  158. typedef struct channel
  159. {
  160. signed fd;
  161. signed ifstate;
  162. signed ifindex;
  163. char const * ifname;
  164. uint8_t peer [ETHER_ADDR_LEN];
  165. uint8_t host [ETHER_ADDR_LEN];
  166. uint16_t type;
  167. #if defined (__linux__)
  168. #elif defined (__APPLE__) || defined (__OpenBSD__)
  169. struct bpf
  170. {
  171. signed bpf_length;
  172. uint8_t * bpf_buffer;
  173. uint8_t * bpf_bp;
  174. signed bpf_bufused;
  175. }
  176. * bpf;
  177. #elif defined (WINPCAP) || defined (LIBPCAP)
  178. pcap_t * socket;
  179. char errbuf [PCAP_ERRBUF_SIZE];
  180. #else
  181. #error &quot;Unknown Environment&quot;
  182. #endif
  183. signed capture;
  184. signed timeout;
  185. flag_t flags;
  186. }
  187. CHANNEL;
  188. /*====================================================================*
  189. * channel functions;
  190. *--------------------------------------------------------------------*/
  191. signed openchannel (struct channel *);
  192. signed closechannel (struct channel const *);
  193. ssize_t sendpacket (struct channel const *, void * memory, ssize_t extent);
  194. ssize_t readpacket (struct channel const *, void * memory, ssize_t extent);
  195. /*====================================================================*
  196. *
  197. *--------------------------------------------------------------------*/
  198. #endif
  199. </pre>
  200. <div class='footerlink'>
  201. [<a href='bpf.h.html' title=' bpf.h '>PREV</a>]
  202. [<a href='toolkit.html' title=' Index '>HOME</a>]
  203. [<a href='chars.h.html' title=' chars.h '>NEXT</a>]
  204. </div>
  205. </body>
  206. </html>