ch03s13.html 3.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Endian-ness</title><meta name="generator" content="DocBook XSL Stylesheets V1.76.1"><meta name="keywords" content="Intellon, Atheros, Qualcomm, HomePlug, powerline, communications, INT6000, INT6300, INT6400, AR7400, AR7420"><link rel="home" href="index.html" title="Qualcomm Atheros Open Powerline Toolkit"><link rel="up" href="ch03.html" title="Chapter 3.  Software"><link rel="prev" href="ch03s12.html" title="Structure Packing"><link rel="next" href="ch03s14.html" title="Packet Basics"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">
  2. Endian-ness
  3. </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch03s12.html">Prev</a> </td><th width="60%" align="center">Chapter 3. 
  4. Software
  5. </th><td width="20%" align="right"> <a accesskey="n" href="ch03s14.html">Next</a></td></tr></table><hr></div><div class="section" title="Endian-ness"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="endianess"></a>
  6. Endian-ness
  7. </h2></div></div></div><p>
  8. Atheros vendor-specific messages contain information in mixed endian format. The Ethernet header portion is sent <span class="emphasis"><em>big endian </em></span> but the Atheros header and payload are sent in <span class="emphasis"><em>little endian </em></span>. The traditional endian converstion functions <code class="function">htons()</code>, <code class="function">htonl()</code>, <code class="function">ntohs()</code> and <code class="function">ntohl()</code> can be used to perform platform independent conversions on the Ethernet header but not the Atheros header payload.
  9. </p><p>
  10. The Open Powerline Toolkit includes similar macros <code class="function">HTOLE16</code>, <code class="function">HTOLE32</code>, <code class="function">LE16TOH</code> and <code class="function">LE32TOH</code> in <a class="ulink" href="endian.h.html" target="_top">endian.h</a> which serve the same function but conform to recommendations for standarized byte order function on Linux, OpenBSD and FreeBSD. Observe that the names are independent of any network implications.
  11. </p><pre class="programlisting">
  12. #if BYTE_ORDER == BIG_ENDIAN
  13. # define LE16TOH(x) __bswap_16(x)
  14. # define LE32TOH(x) __bswap_32(x)
  15. # define LE64TOH(x) __bswap_64(x)
  16. # define HTOLE16(x) __bswap_16(x)
  17. # define HTOLE32(x) __bswap_32(x)
  18. # define HTOLE64(x) __bswap_64(x)
  19. #elif BYTE_ORDER == LITTLE_ENDIAN
  20. # define LE16TOH(x) (x)
  21. # define LE32TOH(x) (x)
  22. # define LE64TOH(x) (x)
  23. # define HTOLE16(x) (x)
  24. # define HTOLE32(x) (x)
  25. # define HTOLE64(x) (x)
  26. #else
  27. #error "Undefined host byte order."
  28. #endif
  29. </pre><p>
  30. In addition, the Open Powerline Toolkit includes function <a class="link" href="ch07s05.html#support-endian" title="endian">endian</a> that reverses byte order over a variable-length memory region.
  31. </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch03s12.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch03.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch03s14.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">
  32. Structure Packing
  33.  </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 
  34. Packet Basics
  35. </td></tr></table></div></body></html>