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

📄 ppp-using.html

📁 ecos3.0 beta 的官方文档,html格式
💻 HTML
字号:
<!-- Copyright (C) 2009 Free Software Foundation, Inc.                                -->
<!-- This material may be distributed only subject to the terms      -->
<!-- and conditions set forth in the Open Publication License, v1.0  -->
<!-- or later (the latest version is presently available at          -->
<!-- http://www.opencontent.org/openpub/).                           -->
<!-- Distribution of the work or derivative of the work in any       -->
<!-- standard (paper) book form is prohibited unless prior           -->
<!-- permission is obtained from the copyright holder.               -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Using PPP</TITLE
><meta name="MSSmartTagsPreventParsing" content="TRUE">
<META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="eCos Reference Manual"
HREF="ecos-ref.html"><LINK
REL="UP"
TITLE="eCos PPP User Guide"
HREF="ppp.html"><LINK
REL="PREVIOUS"
TITLE="Features"
HREF="ppp-features.html"><LINK
REL="NEXT"
TITLE="PPP Interface"
HREF="ppp-interface.html"></HEAD
><BODY
CLASS="CHAPTER"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>eCos Reference Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="ppp-features.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="ppp-interface.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="CHAPTER"
><H1
><A
NAME="PPP-USING"
></A
>Chapter 53. Using PPP</H1
><P
>Before going into detail, let's look at a simple example of how the
<SPAN
CLASS="PRODUCTNAME"
>eCos</SPAN
> PPP package is used. Consider the
following example:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>static void ppp_up(void)
{
    cyg_ppp_options_t options;
    cyg_ppp_handle_t ppp_handle;

    // Bring up the TCP/IP network
    init_all_network_interfaces();

    // Initialize the options
    cyg_ppp_options_init( &amp;options );

    // Start up PPP
    ppp_handle = cyg_ppp_up( "/dev/ser0", &amp;options );

    // Wait for it to get running
    if( cyg_ppp_wait_up( ppp_handle ) == 0 )
    {
        // Make use of PPP
        use_ppp();

        // Bring PPP link down
        cyg_ppp_down( ppp_handle );

        // Wait for connection to go down.
        cyg_ppp_wait_down( ppp_handle );
    }
}</PRE
></TD
></TR
></TABLE
><P
>This is a simple example of how to bring up a simple PPP connection to
another computer over a directly connected serial line. The other end
is assumed to already be running PPP on the line and waiting for a
connection.</P
><P
>The first thing this code does is to call
<CODE
CLASS="FUNCTION"
>init_all_network_interfaces()</CODE
> to bring up the
TCP/IP stack and initialize any other network interfaces. It then
calls <CODE
CLASS="FUNCTION"
>cyg_ppp_options_init()</CODE
> to initialize the
PPP options structure to the defaults. As it happens, the default
options are exactly what we want for this example, so we don't need to
make any further changes. We go straight on to bring the PPP interface
up by calling <CODE
CLASS="FUNCTION"
>cyg_ppp_up()</CODE
>. The arguments to this
function give the name of the serial device to use, in this case
<TT
CLASS="LITERAL"
>"/dev/ser0"</TT
>, and a pointer to the options.</P
><P
>When <CODE
CLASS="FUNCTION"
>cyg_ppp_up()</CODE
> returns, it passes back a
handle to the PPP connection which is to be used in other calls.  The
PPP link will not necessarily have been fully initialized at this
time. There is a certain amount of negotiation that goes on between
the ends of a PPP link before it is ready to pass packets. An
application can wait until the link is ready by calling
<CODE
CLASS="FUNCTION"
>cyg_ppp_wait_up()</CODE
>, which returns
zero if the link is up and running, or
<TT
CLASS="LITERAL"
>-1</TT
> if it has gone down or failed to come up.</P
><P
>After a successful return from <CODE
CLASS="FUNCTION"
>cyg_ppp_wait_up()</CODE
>,
the application may make use of the PPP connection. This is
represented here by the call to <CODE
CLASS="FUNCTION"
>use_ppp()</CODE
> but
it may, of course, be accessed by any thread. While the connection is
up the application may use the standard socket calls to make or accept
network connections and transfer data in the normal way.</P
><P
>Once the application has finished with the PPP link, it can bring it
down by calling <CODE
CLASS="FUNCTION"
>cyg_ppp_down()</CODE
>. As with bringing
the connection up, this call is asynchronous, it simply informs the
PPP subsystem to start bringing the link down. The application can
wait for the link to go down fully by calling
<CODE
CLASS="FUNCTION"
>cyg_ppp_wait_down()</CODE
>.</P
><P
>That example showed how to use PPP to connect to a local peer. PPP is
more often used to connect via a modem to a remote server, such as an
ISP. The following example shows how this works:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>&#13;static char *isp_script[] =
{
    "ABORT"             ,       "BUSY"                                  ,
    "ABORT"             ,       "NO CARRIER"                            ,
    "ABORT"             ,       "ERROR"                                 ,
    ""                  ,       "ATZ"                                   ,
    "OK"                ,       "AT S7=45 S0=0 L1 V1 X4 &amp;C1 E1 Q0"      ,
    "OK"                ,       "ATD" CYGPKG_PPP_DEFAULT_DIALUP_NUMBER  ,
    "ogin:--ogin:"      ,       CYGPKG_PPP_AUTH_DEFAULT_USER            ,
    "assword:"          ,       CYGPKG_PPP_AUTH_DEFAULT_PASSWD          ,
    "otocol:"           ,       "ppp"                                   ,
    "HELLO"             ,       "\\c"                                   ,
    0
};

static void ppp_up(void)
{
    cyg_ppp_options_t options;
    cyg_ppp_handle_t ppp_handle;

    // Bring up the TCP/IP network
    init_all_network_interfaces();

    // Initialize the options
    cyg_ppp_options_init( &amp;options );

    options.script = isp_script;
    options.modem  = 1;

    // Start up PPP
    ppp_handle = cyg_ppp_up( "/dev/ser0", &amp;options );

    // Wait for it to get running
    if( cyg_ppp_wait_up( ppp_handle ) == 0 )
    {
        // Make use of PPP
        use_ppp();

        // Bring PPP link down
        cyg_ppp_down( ppp_handle );

        // Wait for connection to go down.
        cyg_ppp_wait_down( ppp_handle );
    }
}</PRE
></TD
></TR
></TABLE
><P
>The majority of this code is exactly the same as the previous
example. The main difference is in the setting of a couple of options
before calling <CODE
CLASS="FUNCTION"
>cyg_ppp_up()</CODE
>. The
<CODE
CLASS="STRUCTFIELD"
>script</CODE
> option is set to point to a CHAT
script to manage the setup of the connection. The
<CODE
CLASS="STRUCTFIELD"
>modem</CODE
> option is set to cause the PPP system
to make use of the modem control lines.</P
><P
>During the PPP bring-up a call will be made to
<CODE
CLASS="FUNCTION"
>cyg_ppp_chat()</CODE
> to run the CHAT script (see <A
HREF="ppp-chat.html"
>Chapter 56</A
>). In the example this script sets up various modem
options and then dials a number supplied as part of the PPP package
configuration (see <A
HREF="ppp-config.html"
>Chapter 55</A
>). When the connection
has been established, the script log on to the server, using a name
and password also supplied by the configuration, and then starts PPP
on the remote end. If this script succeeds the PPP connection will be
brought up and will then function as expected.</P
><P
>The <CODE
CLASS="STRUCTFIELD"
>modem</CODE
> option causes the PPP system to
make use of the modem control lines. In particular it waits for
<TT
CLASS="LITERAL"
>Carrier Detect</TT
> to be asserted, and will bring the
link down if it is lost. See <A
HREF="ppp-options-init.html"
>cyg_ppp_options_init()</A
>
for more details.</P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="ppp-features.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ecos-ref.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="ppp-interface.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Features</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ppp.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>PPP Interface</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>

⌨️ 快捷键说明

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