software.xml 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. <chapter id='software'>
  2. <title>
  3. Software
  4. </title>
  5. <section id='software-intro'>
  6. <title>
  7. Introduction
  8. </title>
  9. <para>
  10. The <application>Open Powerline Toolkit</application> is designed to support hardware engineers and embedded software developers working on GNU/Linux and Linux-like systems. Debian GNU/Linux is the platform of choice because it is open source and has extensive cross-platform support. The toolkit has been compiled and executed on several platforms but Qualcomm Atheros does not necessarily support the toolkit on those platforms. Qualcomm Atheros has made every effort to enable cross-platform compatibility by conforming to POSIX standards and following good programming practice but there are limitations on any such effort.
  11. </para>
  12. </section>
  13. <section id='software-security'>
  14. <title>
  15. Security Considerations
  16. </title>
  17. <para>
  18. Toolkit programs are installed in <filename>/usr/local/bin</filename> with owner <constant>root</constant> and group <constant>root</constant> (<command>chown root:root</command>) and with read and execute permissions for owner, group and others (<command>chmod 0555</command>). This lets anyone execute these programs even though they are owned by user <constant>root</constant>.
  19. </para>
  20. <para>
  21. Additionally, programs that send raw Ethernet frames are installed with seteuid owner (<command>chmod 4555</command>) so that they will execute with <constant>root</constant> user privileges, regardless of the user executing them. This lets any user send raw Ethernet frames but it also presents a security risk on the host computer. For example, program <application>int6k</application> is intended to read and write <filename>.nvm</filename> and <filename>.pib</filename> files but a malicious user could use it to overwrite other files normally protected by standard file permissions.
  22. </para>
  23. <para>
  24. You can change the default file permissions by changing the <command>-m 4555</command> option on the <command>install</command> command in various <filename>Makefiles</filename>. Be aware that doing so will restrict program access to the the <constant>root</constant> user.
  25. </para>
  26. </section>
  27. <section id='software-platform-options'>
  28. <title>
  29. Platform Options
  30. </title>
  31. <para>
  32. Qualcomm Atheros makes no claim that the <application>Open Powerline Toolkit</application> will compile and link in all environments without generating warnings or errors. Different compilers, and compiler versions, treat certain conditions differently and different distributions include different header files or define standard constants and macros differently. Developers should expect to make some source code and makefile modifications to match their environment.
  33. </para>
  34. <para>
  35. The principle consideration is support for raw Ethernet frames. Other considerations include POSIX compliance, system header file locations, compiler version and library support. This section discusses some of these considerations.
  36. </para>
  37. <section id="platform-linux" >
  38. <title>
  39. <application>GNU/Linux</application>
  40. </title>
  41. <para>
  42. The toolkit will compile and execute on <application>GNU/Linux</application> systems without modification by using standard Linux header files and native Linux libraries. Raw socket support is native to the Linux Kernel. This is the preferred environment due to cost, networking speed and ease of access to Layer 2 networking.
  43. </para>
  44. <para>
  45. Qualcomm Atheros has cross-compiled and executed versions of the toolkit on <productname>MontaVista</productname> and <productname>AMiLDA</productname> Linux both for <productname>MIPSEL</productname> processors. Most toolkit makefiles have symbolic hooks for cross-compilers but Qualcomm Atheros does not support cross-compilation efforts on any platform.
  46. </para>
  47. </section>
  48. <section id="platform-linux-libpcap" >
  49. <title>
  50. GNU/Linux with Libpcap
  51. </title>
  52. <para>
  53. The toolkit can compile and will execute on <application>GNU/Linux</application> systems having the <application>libpcap</application> development package and runtime libraries installed; however, this feature is disabled by default because it is not needed on Linux and offers no benefits over native Linux sockets.
  54. </para>
  55. </section>
  56. <section id="platform-linux-bpf">
  57. <title>
  58. GNU/Linux with BPF
  59. </title>
  60. <para>
  61. The toolkit should compile and execute on <application>GNU/Linux</application> systems having <application>BPF</application> compiled into the kernel but modifications would be needed to toolkit source code. This configuration has not been tested but the source code is present to support it. Consult Qualcomm Atheros if this option is of interest to you.
  62. </para>
  63. </section>
  64. <section id="platform-osx-bpf">
  65. <title>
  66. <productname>Mac OS X</productname> with BPF
  67. </title>
  68. <para>
  69. The toolkit will compile and execute on <application>Mac OS X</application> without modification by using native <acronym>BPF</acronym> support compiled into the <application>Darwin</application> kernel. Compilation is clean on <application>Leopard</application> and should be fairly clean on <application>Tiger</application>.
  70. </para>
  71. <para>
  72. You may observe compiler warnings concerning the <constant>size_t</constant> data type and <constant>print</constant> statements. These warning occur because <application>Mac OS X</application> defined the <constant>size_t</constant> data type as a 64-bit integer while most other systems define it as a 32-bit integer. Ignore the warnings. We will eventually eliminate them all.
  73. </para>
  74. <para>
  75. You may observe a compiler warning concerning the definition of intrinsic function <constant>snprinf</constant>. We are not sure what causes this warning but it will be corrected eventually.
  76. </para>
  77. </section>
  78. <section id="platform-windows-winpcap" >
  79. <title>
  80. <productname>Windows XP</productname> with Winpcap
  81. </title>
  82. <para>
  83. The toolkit will compile and execute on Microsoft <productname>Windows XP</productname> having <application>WinPcap 4.0.1</application> runtime libraries installed. To assist windows developers, the toolkit includes a Microsoft <productname>Visual Studio .NET 2003</productname> solution file plus required <application>WinPcap 4.0.1</application> header files and libraries. The resulting programs should execute on any Microsoft <productname>Windows</productname> computer having <application>WinPcap 4.0.1</application> runtime libraries installed. Qualcomm Atheros does not support the toolkit under any Microsoft <productname>Windows</productname> operating system at this time.
  84. </para>
  85. <para>
  86. Recent versions of the toolkit include self-extracting file <filename>.\VisualStudioNET\WinPcap4_0_1.exe</filename> that installs <application>WinPcap 4.0.1</application> libraries on your system in cases where you have another version installed. If this creates a conflict the you must resolve it to satisfy your system requirements.
  87. </para>
  88. <para>
  89. This is not the preferred Toolkit environment due to cost, networking overhead, difficulty accessing Layer network support and lack of a powerful native scripting language. Qualcomm Atheros has not implemented all Toolkit programs on Windows for technical reasons.
  90. </para>
  91. </section>
  92. </section>
  93. <section id='software-makefiles'>
  94. <title>
  95. GNU Makefiles on Linux
  96. </title>
  97. <para>
  98. The toolkit includes recursive GNU makefiles for Linux. The <filename>Makefile</filename> in the root folder calls Makefiles in subordinate folders. Makefiles in subordinate folders can be run independently to produce individual toolkit components. Developers can control which components are compiled and installed by editing the <constant>FOLDERS</constant> symbol in the main Makefile.
  99. </para>
  100. <para>
  101. Component Makefiles have a standard format that includes the following targets:
  102. </para>
  103. <variablelist>
  104. <varlistentry>
  105. <term>
  106. compile
  107. </term>
  108. <listitem>
  109. <para>
  110. Compiles source code files prior to installation. Intermmediate files and target files are created in the same folder as the Makefile. This is the default target. That means that typing <command>make</command> or <command>make compile</command> have the same result.
  111. </para>
  112. </listitem>
  113. </varlistentry>
  114. <varlistentry>
  115. <term>
  116. library
  117. </term>
  118. <listitem>
  119. <para>
  120. Creates any special folders that are needed for installation. This target is built by the <command>install</command> target but it can be built independently.
  121. </para>
  122. </listitem>
  123. </varlistentry>
  124. <varlistentry>
  125. <term>
  126. scripts
  127. </term>
  128. <listitem>
  129. <para>
  130. Installs scripts required for proper toolkit operation. This target must be built explicitly to prevent accidental loss of changes made to existing scripts. This target may be built at any time, before or after the <command>install</command> target.
  131. </para>
  132. </listitem>
  133. </varlistentry>
  134. <varlistentry>
  135. <term>
  136. manuals
  137. </term>
  138. <listitem>
  139. <para>
  140. Creates manuals, documents or html pages. Documentation files are not automatically installed by any target. Installation is left to the user.
  141. </para>
  142. </listitem>
  143. </varlistentry>
  144. <varlistentry>
  145. <term>
  146. install
  147. </term>
  148. <listitem>
  149. <para>
  150. Installs executable files in folder <filename>/usr/local/bin</filename>. This target automatically builds the <command>compile</command> target before installation. This means that <command>make install</command> will compile and install in one step.
  151. </para>
  152. </listitem>
  153. </varlistentry>
  154. <varlistentry>
  155. <term>
  156. uninstall
  157. </term>
  158. <listitem>
  159. <para>
  160. Removes installed components. This target does nothing for Makefiles that have <command>install</command> targets defined.
  161. </para>
  162. </listitem>
  163. </varlistentry>
  164. <varlistentry>
  165. <term>
  166. clean
  167. </term>
  168. <listitem>
  169. <para>
  170. Removes intermmediate and temporary files. Temporary files are defined by variable <varname>TRASH</varname> at the start of each Makefile.
  171. </para>
  172. </listitem>
  173. </varlistentry>
  174. <varlistentry>
  175. <term>
  176. fresh
  177. </term>
  178. <listitem>
  179. <para>
  180. Removes intermmediate and temporary then re-compiles local targets. It is normally equivalent to <command>make clean </command> followed by <command>make compile</command>.
  181. </para>
  182. </listitem>
  183. </varlistentry>
  184. </variablelist>
  185. <para>
  186. Developers wanting to compile the toolkit under <productname>Windows</productname> should use <productname>Visual Studio .NET</productname> solution files instead of makefiles.
  187. </para>
  188. <para>
  189. Developers wanting to compile the toolkit under <application>OpenBSD</application> must make changes to accommodate variations in <application>make</application> program syntax.
  190. </para>
  191. </section>
  192. <section id="software-stand-alone">
  193. <title>
  194. Stand-alone Compiling on GNU/Linux
  195. </title>
  196. <para>
  197. You do not need makefiles to build toolkit programs because source files explicitly include all required components using <command>include</command> statement blocks like that shown below. You will see similar blocks near the top of most programs.
  198. </para>
  199. <example>
  200. <title>
  201. The <constant>MAKEFILE</constant> constant
  202. </title>
  203. <programlisting>
  204. #ifndef MAKEFILE
  205. #include "../tools/getoptv.c"
  206. #include "../tools/putoptv.c"
  207. #include "../tools/version.c"
  208. ...
  209. #endif
  210. </programlisting>
  211. </example>
  212. <para>
  213. This mechanism has several advantages. First, the preprocessor <userinput>include</userinput> statements form a complete inventory of required files. Secondly, the relative pathnames help developers locate needed source files. Third, the complete program can be compiled with one <command>gcc</command> command, like the one shown below. This allows program compilation in environments where the <application>GNU make</application> program or the Atheros <filename>Makefiles</filename> are not available.
  214. </para>
  215. <example>
  216. <title>
  217. Stand-alone Compiling on GNU/Linux
  218. </title>
  219. <screen><![CDATA[
  220. # gcc -o program program.c
  221. ]]></screen>
  222. </example>
  223. <para>
  224. Most toolkit makefiles define the preprocessor constant <constant>MAKEFILE</constant> as a compiler option using <userinput>CFLAGS= ... -DMAKEFILE ...</userinput>. When this constant is defined, the compiler will not include components inside an include block like that shown above and so the <filename>Makefile</filename> is responsible for compiling and linking all components. If the constant is not defined, because no <filename>Makefile</filename> was used, the compiler will merely include everything needed.
  225. </para>
  226. </section>
  227. <section id="software-cross-compile">
  228. <title>
  229. Cross-Compiling on GNU/Linux
  230. </title>
  231. <para>
  232. Makefiles are setup for cross-compilation using custom toolchains. File <filename>make.def</filename>, in the main toolkit folder, defines cross-comilation symbols referenced in lower-level makefiles. Lower-level makefiles include <filename>make.def</filename> before building their targets. The following is an example <filename>make.def</filename> file used when cross-compiling for the ADM5120 MIPSEL-based gateway.
  233. </para>
  234. <example>
  235. <title>
  236. Cross-compiling with make.def
  237. </title>
  238. <programlisting>
  239. # file: make.def
  240. # ====================================================================
  241. # Edimax Hardware;
  242. # --------------------------------------------------------------------
  243. PLATFORM=-D_ADM5120_
  244. MODEL=-D_6104KP_
  245. ENDIAN=-D_LITTLE_ENDIAN_
  246. GATEWAY=y
  247. # ====================================================================
  248. # AMiLDA Software; uncomment these lines when cross-compiling;
  249. # --------------------------------------------------------------------
  250. # CROSS=/export/tools/mipsel-linux-uclibc/bin/mipsel-uclibc-
  251. # CROSS_LINUX=/export/tools/bin/mipsel-linux-
  252. # ====================================================================
  253. # toolchain;
  254. # --------------------------------------------------------------------
  255. CC=$(CROSS)gcc
  256. STRIP=$(CROSS)strip
  257. LD=$(CROSS)ld
  258. AR=$(CROSS)ar
  259. RANLIB=$(CROSS)ranlib
  260. CAS=$(CROSS)gcc -c
  261. CPP=$(CROSS)gcc -E
  262. # ====================================================================
  263. # folders;
  264. # --------------------------------------------------------------------
  265. BIN=/usr/local/bin
  266. MAN=/usr/share/man/man7
  267. WWW=/home/www
  268. DOC=/home/www/software/plc-utils/
  269. # ====================================================================
  270. # permissions;
  271. # --------------------------------------------------------------------
  272. OWNER=0
  273. GROUP=0
  274. </programlisting>
  275. </example>
  276. <para>
  277. Developers are encouraged to make changes in this file rather than adding additional variables to the lower-level makefiles. For example, you can edit variable <varname>BIN</varname> to install toolkit programs in some location other than <filename>/usr/local/bin</filename> or variable <varname>WWW</varname> to install <acronym>HTML</acronym> documentation on your local website.
  278. </para>
  279. </section>
  280. <section id="software-visualstudio">
  281. <title>
  282. Compilation with Visual Studio .NET 2003
  283. </title>
  284. <para>
  285. To build the <application>Open Powerline Toolkit</application> on Windows XP, you must have access to a Windows computer with <application>Visual Studio .NET 2003</application> and <application>WinPcap</application> runtime libraries installed. <application>WinPcap</application> is an open source version of the packet capture library, <application>libpcap</application>, widely used on <application>Linux</application> and <application>OpenBSD</application> systems. It is readily available on the Internet. Installation of these components is beyond the scope of this document.
  286. </para>
  287. <para>
  288. The Windows and Linux versions of the <application>Open Powerline Toolkit</application> use the same code base but the Windows version requires a Microsoft solution file that includes special compiler settings and specific POSIX header files. The solution file and header files are included in the same archive as Linux version.
  289. </para>
  290. <example>
  291. <title>
  292. Microsoft Visual Studio .NET 2003
  293. </title>
  294. <mediaobject>
  295. <imageobject>
  296. <imagedata fileref='VisualStudioNET.png' format='PNG' align="center" />
  297. </imageobject>
  298. </mediaobject>
  299. </example>
  300. <para>
  301. Use an application like <application>WinZip</application> to extract archived files into a build folder of your choice. Use <application>Windows Explorer</application> to locate solution file <filename>.\VisualStudioNET\plc-utils.sln</filename> under the toolkit root folder. Double-click the file to open it with <application>Visual Studio .NET</application>. In <application>Visual Studio .NET</application>, open the <option>Solution Explorer</option> window and observe a display similar to that shown above.
  302. </para>
  303. <para>
  304. Figure 1 illustrates a <application>Visual Studio .NET</application> window with the <option>Solution Explorer</option> pane exposed. In the <constant>Solution Explorer</constant> window, <command>right-click</command> the <constant>plc-utils</constant> solution and select the <option>Rebuild</option> menu option. Compiliation should begin. Watch for comilation errors.
  305. </para>
  306. <para>
  307. On successful compilation of all projects in this solution, you should find executable programs in the <filename>Release</filename> folder under each project folder. If not then look in the <filename>Debug</filename> folder, instead. You can now open a console window, change to each <filename>Release</filename> or <filename>Debug</filename> folder in turn and run the programs located there. Instead, we recommend that you create a <application>Windows Installer</application> package by <command>right-clicking</command> on the <constant>Install</constant> project in the <constant>Solution Explorer</constant> window and selecting the <option>Build</option> menu option. Compilation should resume.
  308. </para>
  309. <para>
  310. On successful completion of the install project build, you should find the <application>Windows Installer</application> file <filename>plc-utils.msi</filename> in the <filename>VisualStudioNET</filename> folder above the <application>install</application> project folder. Double-clicking on this file will start the <application>Windows Installer</application> program.
  311. </para>
  312. <para>
  313. To distribute the toolkit package to other Windows computers, copy the <application>Windows Installer</application> file to a public network share or some type of portable media.
  314. </para>
  315. </section>
  316. <section id='software-solution-files'>
  317. <title>
  318. Microsoft Solution Files
  319. </title>
  320. <para>
  321. The Atheros <application>Open Powerline Toolkit</application> includes a <productname>Visual Studio .NET</productname> solution file, <filename>./VisualStudioNET/plc-utils.sln</filename>, that will build the toolkit on <application>Windows XP SP2</application> from the Linux code base. The following information may be helpful to developers wanting to modify or extend the solution or port it to another version of Microsoft <application>Visual Studio</application>:
  322. </para>
  323. <itemizedlist>
  324. <listitem>
  325. <para>
  326. All projects are WIN32 Console Projects.
  327. </para>
  328. </listitem>
  329. <listitem>
  330. <para>
  331. All projects have pre-compiled headers suppressed.
  332. </para>
  333. </listitem>
  334. <listitem>
  335. <para>
  336. All projects should globally define preprocessor constant <constant>MAKEFILE</constant> to prevent proliferation of "already defined" link errors. See <link linkend="software-stand-alone">Stand-alone Compiling on GNU/Linux</link> for an explanation of this constant.
  337. </para>
  338. </listitem>
  339. <listitem>
  340. <para>
  341. All projects search folder <filename>..\include</filename> for <ulink url="stdint.h.html">stdint.h</ulink> and <ulink url="unistd.h.html">unistd.h</ulink> because Microsoft does not provide them. These header files are customized or abbreviated versions of their POSIX counterparts and should be used when originals are available.
  342. </para>
  343. </listitem>
  344. <listitem>
  345. <para>
  346. Projects that perform raw Ethernet I/O should globally define preprocessor constant <constant>WINPCAP</constant> to enable appropriate code segments. Preprocessor error statements should (but may not) alert you if <constant>WINPCAP</constant> is not defined on <productname>Windows</productname> platforms. </para>
  347. </listitem>
  348. <listitem>
  349. <para>
  350. Projects that perform raw Ethernet I/O search folder <filename>..\include</filename> for <application>WinPcap</application> header files. These files are taken from the <application>WinPcap</application> development package and may require periodic updates. Header files <ulink url="pcap.h.html">pcap.h</ulink>, <ulink url='pcap-stdinc.h.html'>pca-stdinc.h</ulink>, <ulink url='pcap-bpf.h.html'>pcap-bpf.h</ulink>, <ulink url='ipv6_misc.h.html'>ipv6_misc.h</ulink> and <ulink url='bittypes.h.html'>bittypes.h</ulink> belong in folder <filename>VisualStudioNET\include</filename>. Other header files belong in folder <filename>VisualStudioNET\include\pcap</filename>.
  351. </para>
  352. </listitem>
  353. <listitem>
  354. <para>
  355. Projects that perform raw Ethernet I/O should include folder <filename>..\library</filename> for core <application>WinPcap</application> libraries.
  356. </para>
  357. </listitem>
  358. <listitem>
  359. <para>
  360. Projects that perform raw Ethernet I/O should link to libraries <filename>ws2_32.lib</filename>, <filename>packet.lib</filename> and <filename>wpcap.lib</filename>. The first library is the Microsoft <application>Winsock2</application> library. The others are core <application>WinPcap</application> libraries.
  361. </para>
  362. </listitem>
  363. </itemizedlist>
  364. </section>
  365. <section id='software-header-files'>
  366. <title>
  367. Header Files
  368. </title>
  369. <para>
  370. Atheros <application>Open Powerline Toolkit</application> programs reference POSIX functions and constants where possible. Specifically, they make wide use of the data types <constant>uint8_t</constant>, <constant>uint16_t</constant> and <constant>uint32_t</constant> which are defined in file <filename>stdint.h</filename>. Microsoft <productname>Visual C</productname> and <productname>.NET</productname> environments do not include this file. Consequently, Atheros provides an <ulink url='stdint.h.html'>alternative</ulink> in folder <filename>../Windows/include</filename>. This file is open source and was designed to be compatible with the Microsoft development environments; however, you may occassionally experience warnings about the "benign redefinition" for some of these data types.
  371. </para>
  372. <para>
  373. Where possible, this toolkit includes <productname>OpenBSD</productname> network constants because the OpenBSD project pioneered many of the common network protocols and applications used today. Some systems do not include all <productname>OpenBSD</productname> network header files or do not define all <productname>OpenBSD</productname> network constants. Specifically, Microsoft systems do not provide file <filename>netinet/if_ether.h</filename> and so an <ulink url='if_ether.h.html'>alternative</ulink> is included in folder <filename>../Windows/include/netinet</filename> and <productname>Windows</productname> applications should include it.
  374. </para>
  375. <para>
  376. When the <command>gcc -std=iso9899:1999</command> option is enabled, some <productname>OpenBSD</productname> header files found on <application>GNU/Linux</application> systems will exclude required constant definitions because they do not conform to that standard. Atheros is investigating the best way to address this problem.
  377. </para>
  378. <para>
  379. On some systems, such as <productname>OpenBSD</productname>, <productname>FreeBSD</productname> and <productname>Mac OS X</productname>, header files must be included in specific order to avoid compilation errors. We have done our best to deal with this problem. Visit the <ulink url="http://www.gnu.org/software/hello/manual/autoconf/Header-Portability.html">GNU Autocnf Project</ulink> for more information about this.
  380. </para>
  381. </section>
  382. <section id="software-compiler-constants">
  383. <title>
  384. Compiler Constants
  385. </title>
  386. <section id="software-constants-platform">
  387. <title>
  388. Platform Constants
  389. </title>
  390. <para>
  391. Platform constants conditionaly compile source code blocks based on the hardware architecture and host operating system. Hardware architecture constants are normally defined in system header files. Operating system constants are often compiler intrinsic or defined in system header files.
  392. </para>
  393. <variablelist>
  394. <varlistentry>
  395. <term>
  396. <constant>__APPLE__</constant>
  397. </term>
  398. <listitem>
  399. <para>
  400. A intrinsic compiler constant indicating <productname>Mac OS X</productname> operating system support.
  401. </para>
  402. </listitem>
  403. </varlistentry>
  404. <varlistentry>
  405. <term>
  406. <constant>__BYTE_ORDER</constant>
  407. </term>
  408. <listitem>
  409. <para>
  410. A standard constant indicating big or little endian host architecture. Some systems may not define this constant and so an alternative should be used.
  411. </para>
  412. </listitem>
  413. </varlistentry>
  414. <varlistentry>
  415. <term>
  416. <constant>LIBPCAP</constant>
  417. </term>
  418. <listitem>
  419. <para>
  420. An Atheros constant, that must be manually defined in your makefile or solution file, to indicate that the target host will have <application>LibPcap</application> support. It is not used by the toolkit, at this time, and so the associated code has not been tested.
  421. </para>
  422. </listitem>
  423. </varlistentry>
  424. <varlistentry>
  425. <term>
  426. <constant>__linux__</constant>
  427. </term>
  428. <listitem>
  429. <para>
  430. A standard constant indicating <productname>GNU/Linux</productname> kernel support. It is automatically defined on <productname>GNU/Linux</productname> systems.
  431. </para>
  432. </listitem>
  433. </varlistentry>
  434. <varlistentry>
  435. <term>
  436. <constant>__OpenBSD__</constant>
  437. </term>
  438. <listitem>
  439. <para>
  440. A standard constant indicating <productname>OpenBSD</productname> kernel support. It is automatically define on <productname>OpenBSD</productname> systems. It is not used by the toolkit, at this time, and so the associated code has not been extensively tested.
  441. </para>
  442. </listitem>
  443. </varlistentry>
  444. <varlistentry>
  445. <term>
  446. <constant>WIN32</constant>
  447. </term>
  448. <listitem>
  449. <para>
  450. A standard constant indicating Microsoft <productname>Windows</productname> support. It is automatically defined in Microsoft <productname>Windows</productname> environments.
  451. </para>
  452. </listitem>
  453. </varlistentry>
  454. <varlistentry>
  455. <term>
  456. <constant>WINPCAP</constant>
  457. </term>
  458. <listitem>
  459. <para>
  460. An Atheros constant, that must be manually defined in your makefile or solution file, to indicate that the target host will have <application>WinPcap</application> support. The toolkit only defines this constant in Windows Microsoft project files for programs that perform raw Ethernet I/O.
  461. </para>
  462. </listitem>
  463. </varlistentry>
  464. </variablelist>
  465. </section>
  466. <section id="software-constants-ethernet">
  467. <title>
  468. Ethernet Constants
  469. </title>
  470. <para>
  471. The toolkit attempts to use existing definitions for Ethernet related constants where possible. This has been problematic due to inconsistencies in the way different systems structure their header files. Most of the following definitions already exist on <productname>Linux</productname>, <productname>OpenBSD</productname> and <productname>OS X</productname> but there are still some differences between <productname>Linux</productname> distributions and many constants are undefined on <productname>Windows</productname>.
  472. </para>
  473. <para>
  474. The <productname>Windows</productname> version of the toolkit includes an abbreviated <filename>net/ethernet.h</filename> that provides constant definitions mentioned in this section.
  475. </para>
  476. <variablelist>
  477. <varlistentry>
  478. <term>
  479. ETHER_ADDR_LEN
  480. </term>
  481. <listitem>
  482. <para>
  483. The length of an Ethernet hardware address in bytes. The value is <constant>6</constant> bytes. On <productname>Linux</productname> and <productname>OS X</productname>, this is defined in <filename>net/ethernet.h</filename>.
  484. </para>
  485. </listitem>
  486. </varlistentry>
  487. <varlistentry>
  488. <term>
  489. ETHER_CRC_LEN
  490. </term>
  491. <listitem>
  492. <para>
  493. The length of an Ethernet frame <acronym>FCS</acronym> trailer. The value is <constant>4</constant> bytes. On <productname>Linux</productname> and <productname>OS X</productname>, this is defined in <filename>net/ethernet.h</filename>. Atheros also includes a conditional definition in <filename>int6k/int6k.h</filename> because some <productname>Linux</productname> system do not define it anywhere.
  494. </para>
  495. </listitem>
  496. </varlistentry>
  497. <varlistentry>
  498. <term>
  499. ETHER_HDR_LEN
  500. </term>
  501. <listitem>
  502. <para>
  503. The length of an Ethernet frame header including the source address, destination address and type/length field. The value is <constant>14</constant> bytes or <constant>ETHER_ADDR_LEN</constant> + <constant>ETHER_ADDR_LEN</constant> + <constant>ETHER_TYPE_LEN</constant>. On <productname>Linux</productname> and <productname>OS X</productname>, this is defined in <filename>net/ethernet.h</filename>.
  504. </para>
  505. </listitem>
  506. </varlistentry>
  507. <varlistentry>
  508. <term>
  509. ETHER_MAX_LEN
  510. </term>
  511. <listitem>
  512. <para>
  513. The maximum length of an Ethernet frame in bytes. The value is <constant>1518</constant> bytes of <constant>ETHER_HDR_LEN</constant> + <constant>ETHERMTU</constant> + <constant>ETHER_CRC_LEN</constant>. On <productname>Linux</productname> and <productname>OS X</productname>, this is defined in <filename>net/ethernet.h</filename>.
  514. </para>
  515. </listitem>
  516. </varlistentry>
  517. <varlistentry>
  518. <term>
  519. ETHER_MIN_LEN
  520. </term>
  521. <listitem>
  522. <para>
  523. The minimum length of an Ethernet frame in bytes. The value is <constant>64</constant> bytes. On <productname>Linux</productname> and <productname>OS X</productname> this is defined in <filename>net/ethernet.h</filename>
  524. </para>
  525. </listitem>
  526. </varlistentry>
  527. <varlistentry>
  528. <term>
  529. ETHER_TYPE_LEN
  530. </term>
  531. <listitem>
  532. <para>
  533. The length of Ethernet type/length, or ethertype, field in bytes. The value is <constant>2</constant>. On <productname>Linux</productname> and <productname>OS X</productname>, it is defined in <filename>net/ethernet.h</filename>.
  534. </para>
  535. </listitem>
  536. </varlistentry>
  537. <varlistentry>
  538. <term>
  539. ETHERMTU
  540. </term>
  541. <listitem>
  542. <para>
  543. The maximum transfer unit (ie; data handling capacity) for an Ethernet frame in bytes. The value is <constant>1500</constant> bytes. On <productname>Linux</productname> and <productname>OS X</productname>, this is defined in <filename>net/ethernet.h</filename>
  544. </para>
  545. </listitem>
  546. </varlistentry>
  547. </variablelist>
  548. </section>
  549. </section>
  550. <section id="software-packet-capture">
  551. <title>
  552. <application>LibPcap</application>, <application>WinPcap</application> and <application>BPF</application>
  553. </title>
  554. <para>
  555. <application>LibPcap</application> is an open source Ethernet packet capture library that is widely used. It provides core functionality for the <application>Wireshark</application> packet sniffer, formerly known as <application>Ethereal</application>.
  556. <application>LibPcap</application> libraries are available for Linux and OpenBSD. On Linux and OpenBSD you must link applications to <filename>libpcap.a</filename> and <filename>libwpcap.a</filename>. The toolkit does not use either of these libraries on Linux because they are not needed there.
  557. </para>
  558. <para>
  559. <application>WinPcap</application> is an open source version of <application>LibPcap</application> written for Microsoft <productname>Windows</productname>. The <application>WinPcap</application> libraries let Windows applications send and receive raw packets. On <productname>Windows</productname> you must link applications to <filename>Packet.lib</filename> and <filename>wpcap.lib</filename>.
  560. </para>
  561. <para>
  562. In principle, the <application>LibPcap</application> and <application>WinPcap</application> library implementations should function identically but they do not; however, they are similar enough to provide a useful degree of platform independence. Defining preprocessor constants <constant>LIBPCAP</constant> or <constant>WINPCAP</constant> when compiling the toolkit will enable the corresponding source code. This can be done by adding "-DLIBPCAP" or "-DWINPCAP" to variable <varname>LFLAGS</varname> in file <filename>Makefile</filename> in folders int6k, int6k2, efsu and hpav. Constant <constant>WINPCAP</constant> need only be defined this way when compiling the toolkit using <productname>cygwin</productname> or <productname>mingw</productname> environments. Do not define both constants <constant>LIBPCAP</constant> and <constant>WINPCAP</constant> at the same time or compiler errors will occur.
  563. </para>
  564. <para>
  565. Berkeley Packet Filters (<acronym>BPF</acronym>) is an open source Ethernet packet capture mechanism available on many <productname>UNIX</productname>-like systems. Native <acronym>BPF</acronym> is supported on some systems but must be explicitly compiled into the kernel on other systems. <productname>Linux</productname> systems normally do not support <acronym>BPF</acronym> by default but <productname>Mac OS X</productname> does and so we automatically use it whenever compiler constant <constant>__APPLE__</constant> is defined. In principle, one could compile a custom <productname>Linux</productname> kernel with <acronym>BPF</acronym> enabled.
  566. </para>
  567. </section>
  568. <section id='software-struct-packing'>
  569. <title>
  570. Structure Packing
  571. </title>
  572. <para>Programs in this toolkit make extensive use of packed data structures to simplify source code and guarantee reliability; however, this creates portability issues because different compilers implement structure packing in different ways. Three common structure packing mechanisms are:</para>
  573. <variablelist>
  574. <varlistentry>
  575. <term>
  576. _packed
  577. </term>
  578. <listitem>
  579. <para>
  580. The __packed keyword is not part of any C or C++ standard but it is recognized by some compilers, such as the ARM C/C++ and OpenBSD C compiler. This keyword only affects the data structure that it prefaces and it is an ideal way to selectively pack structures. It can be easily defined and undefined using a preprocessor macro. Atheros has elected to insert this keyword wherever it might be appropriate. The ARM C compilers accept this keyword.
  581. </para>
  582. <example>
  583. <title>
  584. Packing Structures with keyword <quote>__packed</quote>
  585. </title>
  586. <programlisting>
  587. typedef struct __packed header_eth
  588. {
  589. uint8_t source [ETHER_ADDR_LEN];
  590. uint8_t target [ETHER_ADDR_LEN];
  591. uint16_t protocol;
  592. }
  593. header_eth;
  594. </programlisting>
  595. </example>
  596. </listitem>
  597. </varlistentry>
  598. <varlistentry>
  599. <term>
  600. __attribute__ ((packed))
  601. </term>
  602. <listitem>
  603. <para>
  604. Attributes are not part of any C or C++ standard but they are recognized by the gcc and Sun Microsystems C compiler. Attributes only affect structures and functions that reference them in their declaration. This is convenient because we can use a preprocessor macro to define the keyword <varname>__packed</varname>, mentioned above, to be <constant>__attribute__ ((packed))</constant>. Atheros includes this definition in <filename>tools/types.h</filename> and OpenBSD does this in their system header files.
  605. </para>
  606. <example>
  607. <title>
  608. Packing Structures with Attribute <quote>packed</quote>
  609. </title>
  610. <programlisting>
  611. typedef struct __attribute__ ((packed)) header_eth
  612. {
  613. uint8_t source [ETHER_ADDR_LEN];
  614. uint8_t target [ETHER_ADDR_LEN];
  615. uint16_t protocol;
  616. }
  617. header_eth;
  618. </programlisting>
  619. </example>
  620. </listitem>
  621. </varlistentry>
  622. <varlistentry>
  623. <term>
  624. #pragrma pack
  625. </term>
  626. <listitem>
  627. <para>
  628. Pragmas are part of most C and C++ language standards but some compilers do not recognize or implement the <varname>pack</varname> pragma. In addition, different compilers implement it in different ways. The <varname>pack</varname> pragma affects all data structures up the next <varname>pack</varname> pragma or end of compile unit. Most pragma implementations accept the push and pop option for pragma nesting. Some pragma pack implementations accept no arguments, most permit either one or two arguments while others allow three arguments. OpenBSD does not recognize this pragma and generates warnings in all cases. Aside from all that, the pack pragma is the most widely supported method for declaring packed structures.
  629. </para>
  630. <example>
  631. <title>
  632. Packing Structures with the Pragma <quote>pack</quote>
  633. </title>
  634. <programlisting>
  635. #pragma pack (push, 1)
  636. struct header_eth
  637. {
  638. uint8_t source [ETHER_ADDR_LEN];
  639. uint8_t target [ETHER_ADDR_LEN];
  640. uint16_t protocol;
  641. }
  642. header_eth;
  643. #pragma pack (pop)
  644. </programlisting>
  645. </example>
  646. </listitem>
  647. </varlistentry>
  648. <varlistentry>
  649. <term>
  650. The Atheros Way
  651. </term>
  652. <listitem>
  653. <para>
  654. Toolkit programs declares packed structures using all three methods, as shown below.
  655. </para>
  656. <example>
  657. <title>
  658. Packing Structures the Atheros Way
  659. </title>
  660. <programlisting><![CDATA[
  661. #ifndef __packed
  662. #ifdef __GNUC__
  663. #define __packed __attribute__ ((packed))
  664. #else
  665. #define __packed
  666. #endif
  667. #endif
  668. #ifndef __GNUC__
  669. #pragma pack (push, 1)
  670. #endif
  671. struct __packed header_eth
  672. {
  673. uint8_t source [ETHER_ADDR_LEN];
  674. uint8_t target [ETHER_ADDR_LEN];
  675. uint16_t protocol;
  676. }
  677. header_eth;
  678. #ifndef __GNUC__
  679. #pragma pack (pop)
  680. #endif
  681. ]]></programlisting>
  682. </example>
  683. </listitem>
  684. </varlistentry>
  685. </variablelist>
  686. </section>
  687. <section id='endianess'>
  688. <title>
  689. Endian-ness
  690. </title>
  691. <para>
  692. Atheros vendor-specific messages contain information in mixed endian format. The Ethernet header portion is sent <emphasis>big endian </emphasis> but the Atheros header and payload are sent in <emphasis>little endian </emphasis>. The traditional endian converstion functions <function>htons()</function>, <function>htonl()</function>, <function>ntohs()</function> and <function>ntohl()</function> can be used to perform platform independent conversions on the Ethernet header but not the Atheros header payload.
  693. </para>
  694. <para>
  695. The Open Powerline Toolkit includes similar macros <function>HTOLE16</function>, <function>HTOLE32</function>, <function>LE16TOH</function> and <function>LE32TOH</function> in <ulink url="endian.h.html">endian.h</ulink> 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.
  696. </para>
  697. <programlisting><![CDATA[
  698. #if BYTE_ORDER == BIG_ENDIAN
  699. # define LE16TOH(x) __bswap_16(x)
  700. # define LE32TOH(x) __bswap_32(x)
  701. # define LE64TOH(x) __bswap_64(x)
  702. # define HTOLE16(x) __bswap_16(x)
  703. # define HTOLE32(x) __bswap_32(x)
  704. # define HTOLE64(x) __bswap_64(x)
  705. #elif BYTE_ORDER == LITTLE_ENDIAN
  706. # define LE16TOH(x) (x)
  707. # define LE32TOH(x) (x)
  708. # define LE64TOH(x) (x)
  709. # define HTOLE16(x) (x)
  710. # define HTOLE32(x) (x)
  711. # define HTOLE64(x) (x)
  712. #else
  713. #error "Undefined host byte order."
  714. #endif
  715. ]]></programlisting>
  716. <para>
  717. In addition, the Open Powerline Toolkit includes function <link linkend='support-endian'>endian</link> that reverses byte order over a variable-length memory region.
  718. </para>
  719. </section>
  720. <section id='packet-basics'>
  721. <title>
  722. Packet Basics
  723. </title>
  724. <para>
  725. Local and remote <trademark class='registered'>HomePlug</trademark> AV powerline devices are managed by sending Ethernet frames that contain <trademark class='registered'>HomePlug AV</trademark> formatted management messages. These frames have an 802.3 Ethernet header and a payload that contains the Management Message (MM).
  726. </para>
  727. <para>
  728. The Ethernet header must be transmitted in newtwork byte order which is big-endian. The Ethernet payload must be sent in <productname>ARM</productname> host byte order which is little endian. You should use standard network functions <varname>htons()</varname> and <varname>htonl()</varname> to write Ethernet headers and <varname>ntohs()</varname> and <varname>ntohl()</varname> to read them. You should use function <varname>HTOLE16()</varname> and <varname>HTOLE32()</varname> to write integer payload values and <varname>LE26TOH()</varname> and <varname>LE32TOH()</varname> to read them.
  729. </para>
  730. <programlisting><![CDATA[
  731. +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ ... +---+---+
  732. | Ethernet Header | Ethernet Payload |
  733. +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ ... +---+---+
  734. ]]></programlisting>
  735. <para>
  736. Ethernet headers consist of a destination address (<constant>ODA</constant>), a source address (<constant>OSA</constant>) and an ethertype (<constant>MTYPE</constant>). The ethertype is always 0x88E1 for Homeplug frames of any type. Programmers may use either function <ulink url="EthernetHeader.c.html">EthernetHeader.c</ulink> or <ulink url="EncodeEthernetHeader.c.html">EncodeEthernetHeader</ulink> to encode a buffer with the ODA and OSA and the HomePlug ethertype. An example appears later on. Structure <constant>header_eth</constant> is defined in <ulink url='ihp.h.html'>ihp.h</ulink> for this purpose.
  737. </para>
  738. <programlisting><![CDATA[
  739. +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ ... +---+---+
  740. | ODA | OSA | MTYPE | Ethernet Payload |
  741. +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ ... +---+---+
  742. ]]></programlisting>
  743. <para>
  744. Management messages consist of a message header (MMHEADER) and a message entry (MMENTRY). The message header identifies the nature of the message entry that follows it. The acronyms MME and MMENTRY both mean Management Message Entry but they are often used to mean the entire management message or Ethernet frame. This imprecise usage can be confusing at times. Structure <constant>header_mme</constant> is defined in <ulink url='ihp.h.html'>ihp.h</ulink> for this purpose.
  745. </para>
  746. <programlisting><![CDATA[
  747. +---+ ... +---+---+---+---+---+---+---+---+---+---+---+ ... +---+---+---+---+---+
  748. | | MMHEADER | MMENTRY |
  749. +---+ ... +---+---+---+---+---+---+---+---+---+---+---+ ... +---+---+---+---+---+
  750. ]]></programlisting>
  751. <para>
  752. The message header contains message protocol version (MMV), message type (MMTYPE) and vendor identifier (OUI). The management message entry (MMENTRY) that follows the header contains information unique to a the request (REQ), confirmation (CNF), response (RSP) or indication (IND). Programmers may use the Atheros EncodeAtherosHeader function to encode a buffer with a specific MMTYPE and the Atheros MMV and OUI. AN example appears later on.
  753. </para>
  754. <programlisting><![CDATA[
  755. +---+ ... +---+---+---+---+---+---+---+---+---+---+---+ ... +---+---+---+---+---+
  756. | |MMV| MMTYPE| OUI | MMENTRY |
  757. +---+ ... +---+---+---+---+---+---+---+---+---+---+---+ ... +---+---+---+---+---+
  758. ]]></programlisting>
  759. <para>
  760. The MMV value, within MMHEADER, indicates the Homeplug AV Management Message protocol version which determines how the message should be interpreted. The protocol version is defined in the HomePlug AV Specification and may change from time to time. One notable change is the recent insertion of an FMI (Fragment Management Information ) field between MMTYPE and OUI , as shown below.
  761. </para>
  762. <para>
  763. In most cases, protocol changes are hidden from the application by the Atheros API functions; however, software developers should set the <constant>HOMEPLUG_MMV</constant> constant, defined in <ulink url='ihp.h.html'>ihp.h</ulink>, to the version appropriate for their firmware or application. The value of this constant enables or disables conditional compilation statements throughout the HomePlug API code base.
  764. </para>
  765. <para>
  766. To send an MME, you must encode an Ethernet frame buffer with information and transmit it. To read an MME, you must read an Ethernet frame buffer and decode it. The information necessary to encode or decode Atheros vendor-specific Ethernet frames is covered in the <trademark>INT6000</trademark> Firmware Technical Reference Manual; however, the Atheros HomePlug API includes many buffer encode and decode functions that support basic operational requirements.
  767. </para>
  768. </section>
  769. <section id='frame-encoding'>
  770. <title>
  771. Frame Encoding
  772. </title>
  773. <para>
  774. The following technique illustrates one way to encode a frame buffer with an Ethernet header followed by an Atheros message header. We first declare the frame buffer then a length variable to keep track of how many bytes have actually been encoded. At any time, the value 'buffer + length' is the address of the next buffer position to encode and the expression 'sizeof (buffer) - length' is the number of un-encoded bytes remaining in the buffer. Each call to an encoding function will increment the length for the next operation. This technique minimizes the number of intermmediate application variables and makes maximum use of compiler generated constants.
  775. </para>
  776. <example>
  777. <title>
  778. Frame Encoding by Offset
  779. </title>
  780. <programlisting><![CDATA[
  781. uint8_t buffer [ETHER_MAX_LEN];
  782. size_t length = 0;
  783. uint8_t OSA [ETHER_ADDR_LEN] = { 0x00, 0xB0, 0x52, 0x00, 0xD4, 0x32 };
  784. uint8_t ODA [ETHER_ADDR_LEN] = { 0x00, 0xB0, 0x52, 0x00, 0x66, 0xF7 };
  785. uint16_t MMTYPE = 0xA050;
  786. length += EncodeEthernetHeader (buffer + length, sizeof (buffer) - length, uint8_t OSA, uint8_t ODA);
  787. length += EncodeAtherosHeader (buffer + length, sizeof (buffer) - length, unit16_t MMTYPE);
  788. if (length < sizeof (MME))
  789. {
  790. error (...);
  791. }
  792. ]]></programlisting>
  793. </example>
  794. <para>
  795. For those who prefer to use pointers, the following technique accomplishes the same thing because. At any given time, the value bp - buffer is the encoded length.
  796. </para>
  797. <example>
  798. <title>
  799. Frame Encoding by Address
  800. </title>
  801. <programlisting><![CDATA[
  802. uint8_t buffer [ETHER_MAX_LEN];
  803. uint8_t bp = buffer;
  804. bp += EncodeEthernetHeader (bp, buffer + sizeof (buffer) - bp, uint8_t OSA, uint8_t ODA);
  805. bp += EncodeAtherosHeader (bp, buffer + sizeof (buffer) - bp, unit16_t MMTYPE);
  806. if (bp < (buffer + sizeof (MME)))
  807. {
  808. error (...);
  809. }
  810. ]]></programlisting>
  811. </example>
  812. </section>
  813. </chapter>