⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c-4.3upgrade2.html

📁 vxWorks网络协议驱动开发用户手册写协议栈时的好指引
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><link rel="STYLESHEET" type="text/css" href="wrs.css"><title>    Upgrading 4.3 BSD Network Drivers    </title></head><body bgcolor="FFFFFF"><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="c-4.3upgrade.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-4.3upgrade.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-4.3upgrade1.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-4.3upgrade3.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p><font face="Helvetica, sans-serif" class="sans"><h3 class="H2"><i><a name="84250">14.2  &nbsp;&nbsp;Structure of a 4.3 BSD Network Driver</a></i></h3></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84252"> </a>The network drivers currently shipped with VxWorks are based on those available in BSD UNIX version 4.3. These drivers define only one global (user-callable) routine, the driver's <b class="routine"><i class="routine">attach</i></b> routine. Typically, the name of this routine contains the word, <i class="emphasis">attach</i>, prefixed with two letters from the device name. For example, the AMD Lance driver's attach routine is called <b class="routine"><i class="routine">lnattach</i></b><b>(&nbsp;)</b>. The <b class="routine"><i class="routine">xxattach</i></b><b>(&nbsp;)</b> routine hooks in five function pointers that are mapped into an <b class="symbol_lc">ifnet</b> structure. These functions, listed in <a href="c-4.3upgrade2.html#84260">Table&nbsp;14-1</a>, are all called from various places in the IP protocol stack, which has intimate knowledge of the driver.<p class="table"><h4 class="EntityTitle"><a name="84260"><font face="Helvetica, sans-serif" size="-1" class="sans">Table 14-1:&nbsp;&nbsp;Network Interface Procedure Handles</font></a></h4><table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="84266"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Function</font></b></div></th><td width="10">&nbsp;</td><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="84268"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Function Pointer</font></b></div></th><td width="10">&nbsp;</td><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="84270"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Driver-Specific Routine</font></b></div></th><td width="10">&nbsp;</td></tr><tr><td colspan="20"><hr class="tablerule2"></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84272"> </a>initialization</div></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><div class="CellBody"><a name="84274"> </a><b class="symbol_lc">if_init </b></div></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><div class="CellBody"><a name="84276"> </a><b class="routine"><i class="routine">xxInit</i></b><b>(</b>&nbsp;<b>)</b> </div></td><td width="10">&nbsp;</td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84278"> </a>output</div></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><div class="CellBody"><a name="84280"> </a><b class="symbol_lc">if_output </b></div></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><div class="CellBody"><a name="84282"> </a><b class="routine"><i class="routine">xxOutput</i></b><b>(</b>&nbsp;<b>)</b></div></td><td width="10">&nbsp;</td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84284"> </a>control</div></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><div class="CellBody"><a name="84286"> </a><b class="symbol_lc">if_ioctl </b></div></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><div class="CellBody"><a name="84288"> </a><b class="routine"><i class="routine">xxIoctl</i></b><b>(</b>&nbsp;<b>)</b></div></td><td width="10">&nbsp;</td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84290"> </a>reset</div></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><div class="CellBody"><a name="84292"> </a><b class="symbol_lc">if_reset </b></div></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><div class="CellBody"><a name="84294"> </a><b class="routine"><i class="routine">xxReset</i></b><b>(</b>&nbsp;<b>)</b></div></td><td width="10">&nbsp;</td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84296"> </a>watchdog</div></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><div class="CellBody"><a name="84298"> </a><b class="symbol_lc">if_watchdog</b> (optional)<b> </b></div></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><div class="CellBody"><a name="84300"> </a><b class="routine"><i class="routine">xxWatchdog</i></b><b>(</b>&nbsp;<b>)</b> </div></td><td width="10">&nbsp;</td></tr><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p></p><dd><p class="Body"><a name="84302"> </a>Packet reception begins when the driver's interrupt routine is invoked. The interrupt routine does the least work necessary to get the packet off the local hardware, schedules an input handler to run by calling <b class="routine"><i class="routine">netJobAdd</i></b><b>(&nbsp;)</b>, and then returns. The <b class="task">tNetTask</b> calls the function that was added to its work queue. In the case of packet reception, this the driver's <b class="routine"><i class="routine">xxReceive</i></b><b>(&nbsp;)</b> function.<div class="frame"><h4 class="EntityTitle"><a name="84308"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure 14-1:&nbsp;&nbsp;Packet Reception Call Graph</font></a></h4><dl class="margin"><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84329"> </a><img class="figure" border="0" src="images/c-4.3upgrade0.gif"></p><dl class="margin"><dd><p class="ListV"><a name="84330"> </a>[1]    The <b class="routine"><i class="routine">xxReceive</i></b><b>(&nbsp;)</b> first shows the packet to <b class="routine"><i class="routine">etherInputHook</i></b><b>(&nbsp;)</b>. </p><dd><p class="ListV"><a name="84331"> </a>[2]    If <b class="routine"><i class="routine">etherInputHook</i></b><b>(&nbsp;)</b> does not take delivery of the packet, <b class="routine"><i class="routine">xxReceive</i></b><b>(&nbsp;)</b> hands the packet to <b class="routine"><i class="routine">do_protocol_with_type</i></b><b>(&nbsp;)</b>. </p></dl></dl></dl></dl></div></p><dd><p class="Body"><a name="84332"> </a>The <b class="routine"><i class="routine">xxReceive</i></b><b>(&nbsp;)</b> function eventually sends the packet up to a protocol by calling <b class="routine"><i class="routine">do_protocol_with_type</i></b><b>(&nbsp;)</b>. This routine is a switch statement that figures out which protocol to hand the packet off to. This calling sequence is shown in <a href="c-4.3upgrade2.html#84308">Figure&nbsp;14-1</a>.</p><dd><p class="Body"><a name="84341"> </a><a href="c-4.3upgrade2.html#84346">Figure&nbsp;14-2</a> shows the call graph for packet transmission. After a protocol has picked an interface on which to send a packet, it calls the <b class="routine"><i class="routine">xxOutput</i></b><b>(&nbsp;)</b> routine for that interface. The output routine calls the generic <b class="routine"><i class="routine">ether_output</i></b><b>(&nbsp;)</b>function, passing it a pointer to addressing information (usually an <b class="symbol_lc">arpcom</b> structure) as well as the data to be sent. After the data is properly packed, it is placed on the output queue (using the <b class="symbol_UC">IF_ENQUEUE</b> macro), and the driver's start routine is called. The <b class="routine"><i class="routine">xxTxStartup</i></b><b>(&nbsp;)</b>routine dequeues as many packets as it can and transmits them on the physical medium.<div class="frame"><h4 class="EntityTitle"><a name="84346"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure 14-2:&nbsp;&nbsp;Packet Transmission Call Graph</font></a></h4><dl class="margin"><div class="Anchor"><a name="84367"> </a><img class="figure" border="0" src="images/c-4.3upgradea1.gif"></div><dl class="margin"><dl class="margin"><dl class="margin"><dd><p class="ListV"><a name="84368"> </a>[1]    The <b class="routine"><i class="routine">xxTxStartup</i></b><b>(&nbsp;)</b> first shows the packet to <b class="routine"><i class="routine">etherOutputHook</i></b><b>(&nbsp;)</b>. </p><dd><p class="ListV"><a name="84369"> </a>[2]    If <b class="routine"><i class="routine">etherOutputHook</i></b><b>(&nbsp;)</b> does not take delivery of the packet, <b class="routine"><i class="routine">xxTxStartup</i></b><b>(&nbsp;)</b> transmits the packet on the medium. </p></dl></dl></dl></dl></div></p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84370">14.2.1  &nbsp;&nbsp;Etherhook Routines Provides Access to Raw Packets</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84372"> </a>You can use the <b class="routine"><i class="routine">etherInputHook</i></b><b>(&nbsp;)</b>and<b>(&nbsp;)</b><b class="routine"><i class="routine">therOutputHook</i></b><b>(&nbsp;)</b>routines to bypass the TCP/IP stack and thus get access to raw packets. On packet reception, if an <b class="routine"><i class="routine">etherInputHook</i></b><b>(&nbsp;)</b> function is installed, it receives the packet just after the driver has completed reception but before the packet goes to the protocol. If <b class="routine"><i class="routine">etherInputHook</i></b><b>(&nbsp;)</b> decides to prevent others from seeing the packet, <b class="routine"><i class="routine">etherInputHook</i></b><b>(&nbsp;)</b> returns a non-zero value and the driver considers the packet to be delivered. If the <b class="routine"><i class="routine">etherInputHook</i></b><b>(&nbsp;)</b> returns 0, the driver hands the packet to the TCP/IP stack. </p><dd><p class="Body"><a name="84376"> </a>On packet transmission, an installed <b class="routine"><i class="routine">etherOutputHook</i></b><b>(&nbsp;)</b> receives a packet just before it would have been transmitted. If <b class="routine"><i class="routine">etherOutputHook</i></b><b>(&nbsp;)</b> decides to prevent the packet from passing on, <b class="routine"><i class="routine">etherOutputHook</i></b><b>(&nbsp;)</b> returns a non-zero value and the driver considers the packet to be transmitted. If the <b class="routine"><i class="routine">etherOutputHook</i></b><b>(&nbsp;)</b> returns 0, the driver transmits the packet.</p><dd><p class="Body"><a name="84377"> </a>It is only possible to install one <b class="routine"><i class="routine">etherInputHook</i></b><b>(&nbsp;)</b>and one <b class="routine"><i class="routine">etherOutputHook</i></b><b>(&nbsp;)</b>function per driver. This limits the number of alternate protocols to one, unless these <b class="routine"><i class="routine">ether*Hook</i></b> routines then act as a multiplexor for more protocols.</p><dd><p class="Body"><a name="84379"> </a>For more information on etherhooks, see the <i class="title">Tornado BSP Developer's Kit for VxWorks, Tornado 1.0.1, User's Guide: G.4&nbsp;Network Interface Hook Routines.</i> </p></dl></dl><dl class="margin"><dd><p class="table" callout><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td valign="top" width="40"><br><img border="0" alt="*" src="icons/caution.gif"></td><td><hr><div class="CalloutCell"><a name="84686"><b class="symbol_UC"><font face="Helvetica, sans-serif" size="-1" class="sans">CAUTION:  </font></b></a>Future versions of VxWorks will not support etherhooks. </div></td></tr><tr valign="top"><td></td><td><hr></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p callout></dl><a name="foot"><hr></a><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="c-4.3upgrade.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-4.3upgrade.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-4.3upgrade1.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-4.3upgrade3.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p></body></html><!---by WRS Documentation (), Wind River Systems, Inc.    conversion tool:  Quadralay WebWorks Publisher 4.0.11    template:         CSS Template, Jan 1998 - Jefro --->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -