Changeset aee474b in rtems


Ignore:
Timestamp:
10/12/01 13:43:05 (22 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
cedf9296
Parents:
ba71076
Message:

2001-10-12 Mike Siers <mikes@…>

  • Update to stable working state. Congratulations Mike! :)
  • modem_example: Directory removed.
  • modem_example/16550.h, modem_example/README, modem_example/modem.c, modem_example/modem.h, modem_example/ppp.c, modem_example/ppp.h, modem_example/pppcompress.c: Files removed.
  • pppd/example/pppd.options: New file.
  • pppd/README, pppd/STATUS, pppd/cbcp.c, pppd/cbcp.h, pppd/chat.c, pppd/pppd.h, pppd/rtemsmain.c: Updated.
Files:
2 added
7 deleted
19 edited

Legend:

Unmodified
Added
Removed
  • c/src/exec/libnetworking/ChangeLog

    rba71076 raee474b  
     12001-10-12      Mike Siers <mikes@poliac.com>
     2
     3        * Update to stable working state.  Congratulations Mike! :)
     4        * modem_example: Directory removed.
     5        * modem_example/16550.h, modem_example/README, modem_example/modem.c,
     6        modem_example/modem.h, modem_example/ppp.c, modem_example/ppp.h,
     7        modem_example/pppcompress.c: Files removed.
     8        * pppd/example/pppd.options: New file.
     9        * pppd/README, pppd/STATUS, pppd/cbcp.c, pppd/cbcp.h, pppd/chat.c,
     10        pppd/pppd.h, pppd/rtemsmain.c: Updated.
     11
    1122001-10-11      Ralf Corsepius <corsepiu@faw.uni-ulm.de>
    213
  • c/src/libnetworking/ChangeLog

    rba71076 raee474b  
     12001-10-12      Mike Siers <mikes@poliac.com>
     2
     3        * Update to stable working state.  Congratulations Mike! :)
     4        * modem_example: Directory removed.
     5        * modem_example/16550.h, modem_example/README, modem_example/modem.c,
     6        modem_example/modem.h, modem_example/ppp.c, modem_example/ppp.h,
     7        modem_example/pppcompress.c: Files removed.
     8        * pppd/example/pppd.options: New file.
     9        * pppd/README, pppd/STATUS, pppd/cbcp.c, pppd/cbcp.h, pppd/chat.c,
     10        pppd/pppd.h, pppd/rtemsmain.c: Updated.
     11
    1122001-10-11      Ralf Corsepius <corsepiu@faw.uni-ulm.de>
    213
  • c/src/libnetworking/pppd/README

    rba71076 raee474b  
    1717The port was updated to 2.3.11 by Mike Siers <mikes@poliac.com>
    1818who added an example test.
     19
     20Updated the chat program to return the correct errors and support
     21the ABORT commands.  Removed some dead code and did a lot of
     22testing on a new Coldfire BSP.  Version seems to be very stable.
    1923=================================================================
    2024
  • c/src/libnetworking/pppd/STATUS

    rba71076 raee474b  
    33#
    44
     5The pppd application seems to very stable.  It has been tested using
     6the example application with the i386/pc586 and m68k/sbc5206e BSPs.
     7The tests were executed using a null modem serial cable to connect
     8with a UNIX box running either the ppp or pppd application and with
     9an external modem to dial up a local ISP.
    510
    6 Notes from Mike Siers <mikes@poliac.com>
    7 ========================================
     11If you have problems getting your target to make consistent connections
     12with an ISP, the problem is most likely with the ppp options.  First
     13try using the "novj" and "noaccomp" options.  If you have questions
     14about what other option values are available for the rtems_pppd_set_option
     15function, please look at the pppd.8 man page file or the the source code.
     16The majority of options that are documented in man page should work
     17with this function call.
    818
    9 I know that several users have tried out this version of
    10 pppd under RTEMS.  It has been successfully used as both
    11 a client and server.  Below are the only issues that I
    12 know of.
     19The pppd application requires the BSP termios driver support task
     20driven I/O.  Below is a list of known issues that need to be resolved:
    1321
    14 1) Large packet ping causes RTEMS box to lock up
    15    If you ping the RTEMS box over the ppp link with a packet
    16    size greater than 1500, the RTEMS box locks up.  I think
    17    the problem is in the pppd ethernet driver.
     22  - pppd locks up when it receives large packet pings (> 1500 bytes)
     23  - pppd occasionaly locks up with mbuf allocation error
     24    (problem is rare and may be BSP related)
    1825
    19 2) Upgrade the libnetworking/modem files
    20    This upgrade did not modify the ppp ethernet driver files
    21    in the libnetworking/modem directory.  Would like to
    22    upgrade these files.  Hopefully, it will fix the large
    23    packet ping problem.
     26If you find any other problems or fix some problems, please post your
     27changes to the RTEMS mailing list.
    2428
    25 3) The files cbcp.c and cbcp.h provide a callback feature
    26    that I have not tried to compile or use.  The files in
    27    this directory are identical to the 2.3.11 versions. 
    28    for completeness.
    29 
    30 
    31 JOEL: Are the modifications to the original pppd such that the
    32       real maintainers will accept them?
    33 
    34 No.  The pppd 2.3.11 branch is an old branch.  The current
    35 version is 2.4.x and it contains alot of extra items that
    36 just did not make sense to have in an embedded environment.
    37 I could make the RTEMS changes compatible with the standard
    38 2.3.11 release by using compilation flags.  I have not
    39 contacted the maintainers to see if they are interested.
    40 
     29Good Luck
  • c/src/libnetworking/pppd/cbcp.c

    rba71076 raee474b  
     1/*
     2 * cbcp - Call Back Configuration Protocol.
     3 *
     4 * Copyright (c) 1995 Pedro Roque Marques
     5 * All rights reserved.
     6 *
     7 * Redistribution and use in source and binary forms are permitted
     8 * provided that the above copyright notice and this paragraph are
     9 * duplicated in all such forms and that any documentation,
     10 * advertising materials, and other materials related to such
     11 * distribution and use acknowledge that the software was developed
     12 * by Pedro Roque Marques.  The name of the author may not be used to
     13 * endorse or promote products derived from this software without
     14 * specific prior written permission.
     15 *
     16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
     17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
     18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
     19 */
     20
     21#define RCSID   "$Id$"
     22
     23#include <stdio.h>
     24#include <string.h>
     25#include <sys/types.h>
     26#include <sys/time.h>
     27
     28#include "pppd.h"
     29#include "cbcp.h"
     30#include "fsm.h"
     31#include "lcp.h"
     32
     33static const char rcsid[] = RCSID;
     34
     35/*
     36 * Options.
     37 */
     38static int setcbcp __P((char **));
     39
     40static option_t cbcp_option_list[] = {
     41    { "callback", o_special, setcbcp,
     42      "Ask for callback" },
     43    { NULL }
     44};
     45
     46/*
     47 * Protocol entry points.
     48 */
     49static void cbcp_init      __P((int unit));
     50static void cbcp_open      __P((int unit));
     51static void cbcp_lowerup   __P((int unit));
     52static void cbcp_input     __P((int unit, u_char *pkt, int len));
     53static void cbcp_protrej   __P((int unit));
     54static int  cbcp_printpkt  __P((u_char *pkt, int len,
     55                                void (*printer) __P((void *, char *, ...)),
     56                                void *arg));
     57
     58struct protent cbcp_protent = {
     59    PPP_CBCP,
     60    cbcp_init,
     61    cbcp_input,
     62    cbcp_protrej,
     63    cbcp_lowerup,
     64    NULL,
     65    cbcp_open,
     66    NULL,
     67    cbcp_printpkt,
     68    NULL,
     69    0,
     70    "CBCP",
     71    NULL,
     72    cbcp_option_list,
     73    NULL,
     74    NULL,
     75    NULL
     76};
     77
     78cbcp_state cbcp[NUM_PPP];       
     79
     80/* internal prototypes */
     81
     82static void cbcp_recvreq __P((cbcp_state *us, char *pckt, int len));
     83static void cbcp_resp __P((cbcp_state *us));
     84static void cbcp_up __P((cbcp_state *us));
     85static void cbcp_recvack __P((cbcp_state *us, char *pckt, int len));
     86static void cbcp_send __P((cbcp_state *us, u_char code, u_char *buf, int len));
     87
     88/* option processing */
     89static int
     90setcbcp(argv)
     91    char **argv;
     92{
     93    lcp_wantoptions[0].neg_cbcp = 1;
     94    cbcp_protent.enabled_flag = 1;
     95    cbcp[0].us_number = strdup(*argv);
     96    if (cbcp[0].us_number == 0)
     97        novm("callback number");
     98    cbcp[0].us_type |= (1 << CB_CONF_USER);
     99    cbcp[0].us_type |= (1 << CB_CONF_ADMIN);
     100    return (1);
     101}
     102
     103/* init state */
     104static void
     105cbcp_init(iface)
     106    int iface;
     107{
     108    cbcp_state *us;
     109
     110    us = &cbcp[iface];
     111    memset(us, 0, sizeof(cbcp_state));
     112    us->us_unit = iface;
     113    us->us_type |= (1 << CB_CONF_NO);
     114}
     115
     116/* lower layer is up */
     117static void
     118cbcp_lowerup(iface)
     119    int iface;
     120{
     121    cbcp_state *us = &cbcp[iface];
     122
     123    dbglog("cbcp_lowerup");
     124    dbglog("want: %d", us->us_type);
     125
     126    if (us->us_type == CB_CONF_USER)
     127        dbglog("phone no: %s", us->us_number);
     128}
     129
     130static void
     131cbcp_open(unit)
     132    int unit;
     133{
     134    dbglog("cbcp_open");
     135}
     136
     137/* process an incomming packet */
     138static void
     139cbcp_input(unit, inpacket, pktlen)
     140    int unit;
     141    u_char *inpacket;
     142    int pktlen;
     143{
     144    u_char *inp;
     145    u_char code, id;
     146    u_short len;
     147
     148    cbcp_state *us = &cbcp[unit];
     149
     150    inp = inpacket;
     151
     152    if (pktlen < CBCP_MINLEN) {
     153        error("CBCP packet is too small");
     154        return;
     155    }
     156
     157    GETCHAR(code, inp);
     158    GETCHAR(id, inp);
     159    GETSHORT(len, inp);
     160
     161#if 0
     162    if (len > pktlen) {
     163        error("CBCP packet: invalid length");
     164        return;
     165    }
     166#endif
     167
     168    len -= CBCP_MINLEN;
     169 
     170    switch(code) {
     171    case CBCP_REQ:
     172        us->us_id = id;
     173        cbcp_recvreq(us, inp, len);
     174        break;
     175
     176    case CBCP_RESP:
     177        dbglog("CBCP_RESP received");
     178        break;
     179
     180    case CBCP_ACK:
     181        if (id != us->us_id)
     182            dbglog("id doesn't match: expected %d recv %d",
     183                   us->us_id, id);
     184
     185        cbcp_recvack(us, inp, len);
     186        break;
     187
     188    default:
     189        break;
     190    }
     191}
     192
     193/* protocol was rejected by foe */
     194void cbcp_protrej(int iface)
     195{
     196}
     197
     198char *cbcp_codenames[] = {
     199    "Request", "Response", "Ack"
     200};
     201
     202char *cbcp_optionnames[] = {
     203    "NoCallback",
     204    "UserDefined",
     205    "AdminDefined",
     206    "List"
     207};
     208
     209/* pretty print a packet */
     210static int
     211cbcp_printpkt(p, plen, printer, arg)
     212    u_char *p;
     213    int plen;
     214    void (*printer) __P((void *, char *, ...));
     215    void *arg;
     216{
     217    int code, opt, id, len, olen, delay;
     218    u_char *pstart;
     219
     220    if (plen < HEADERLEN)
     221        return 0;
     222    pstart = p;
     223    GETCHAR(code, p);
     224    GETCHAR(id, p);
     225    GETSHORT(len, p);
     226    if (len < HEADERLEN || len > plen)
     227        return 0;
     228
     229    if (code >= 1 && code <= sizeof(cbcp_codenames) / sizeof(char *))
     230        printer(arg, " %s", cbcp_codenames[code-1]);
     231    else
     232        printer(arg, " code=0x%x", code);
     233
     234    printer(arg, " id=0x%x", id);
     235    len -= HEADERLEN;
     236
     237    switch (code) {
     238    case CBCP_REQ:
     239    case CBCP_RESP:
     240    case CBCP_ACK:
     241        while(len >= 2) {
     242            GETCHAR(opt, p);
     243            GETCHAR(olen, p);
     244
     245            if (olen < 2 || olen > len) {
     246                break;
     247            }
     248
     249            printer(arg, " <");
     250            len -= olen;
     251
     252            if (opt >= 1 && opt <= sizeof(cbcp_optionnames) / sizeof(char *))
     253                printer(arg, " %s", cbcp_optionnames[opt-1]);
     254            else
     255                printer(arg, " option=0x%x", opt);
     256
     257            if (olen > 2) {
     258                GETCHAR(delay, p);
     259                printer(arg, " delay = %d", delay);
     260            }
     261
     262            if (olen > 3) {
     263                int addrt;
     264                char str[256];
     265
     266                GETCHAR(addrt, p);
     267                memcpy(str, p, olen - 4);
     268                str[olen - 4] = 0;
     269                printer(arg, " number = %s", str);
     270            }
     271            printer(arg, ">");
     272            break;
     273        }
     274
     275    default:
     276        break;
     277    }
     278
     279    for (; len > 0; --len) {
     280        GETCHAR(code, p);
     281        printer(arg, " %.2x", code);
     282    }
     283
     284    return p - pstart;
     285}
     286
     287/* received CBCP request */
     288static void
     289cbcp_recvreq(us, pckt, pcktlen)
     290    cbcp_state *us;
     291    char *pckt;
     292    int pcktlen;
     293{
     294    u_char type, opt_len, delay, addr_type;
     295    char address[256];
     296    int len = pcktlen;
     297
     298    address[0] = 0;
     299
     300    while (len) {
     301        dbglog("length: %d", len);
     302
     303        GETCHAR(type, pckt);
     304        GETCHAR(opt_len, pckt);
     305
     306        if (opt_len > 2)
     307            GETCHAR(delay, pckt);
     308
     309        us->us_allowed |= (1 << type);
     310
     311        switch(type) {
     312        case CB_CONF_NO:
     313            dbglog("no callback allowed");
     314            break;
     315
     316        case CB_CONF_USER:
     317            dbglog("user callback allowed");
     318            if (opt_len > 4) {
     319                GETCHAR(addr_type, pckt);
     320                memcpy(address, pckt, opt_len - 4);
     321                address[opt_len - 4] = 0;
     322                if (address[0])
     323                    dbglog("address: %s", address);
     324            }
     325            break;
     326
     327        case CB_CONF_ADMIN:
     328            dbglog("user admin defined allowed");
     329            break;
     330
     331        case CB_CONF_LIST:
     332            break;
     333        }
     334        len -= opt_len;
     335    }
     336
     337    cbcp_resp(us);
     338}
     339
     340static void
     341cbcp_resp(us)
     342    cbcp_state *us;
     343{
     344    u_char cb_type;
     345    u_char buf[256];
     346    u_char *bufp = buf;
     347    int len = 0;
     348
     349    cb_type = us->us_allowed & us->us_type;
     350    dbglog("cbcp_resp cb_type=%d", cb_type);
     351
     352#if 0
     353    if (!cb_type)
     354        lcp_down(us->us_unit);
     355#endif
     356
     357    if (cb_type & ( 1 << CB_CONF_USER ) ) {
     358        dbglog("cbcp_resp CONF_USER");
     359        PUTCHAR(CB_CONF_USER, bufp);
     360        len = 3 + 1 + strlen(us->us_number) + 1;
     361        PUTCHAR(len , bufp);
     362        PUTCHAR(5, bufp); /* delay */
     363        PUTCHAR(1, bufp);
     364        BCOPY(us->us_number, bufp, strlen(us->us_number) + 1);
     365        cbcp_send(us, CBCP_RESP, buf, len);
     366        return;
     367    }
     368
     369    if (cb_type & ( 1 << CB_CONF_ADMIN ) ) {
     370        dbglog("cbcp_resp CONF_ADMIN");
     371        PUTCHAR(CB_CONF_ADMIN, bufp);
     372        len = 3;
     373        PUTCHAR(len, bufp);
     374        PUTCHAR(5, bufp); /* delay */
     375        cbcp_send(us, CBCP_RESP, buf, len);
     376        return;
     377    }
     378
     379    if (cb_type & ( 1 << CB_CONF_NO ) ) {
     380        dbglog("cbcp_resp CONF_NO");
     381        PUTCHAR(CB_CONF_NO, bufp);
     382        len = 3;
     383        PUTCHAR(len , bufp);
     384        PUTCHAR(0, bufp);
     385        cbcp_send(us, CBCP_RESP, buf, len);
     386        start_networks();
     387        return;
     388    }
     389}
     390
     391static void
     392cbcp_send(us, code, buf, len)
     393    cbcp_state *us;
     394    u_char code;
     395    u_char *buf;
     396    int len;
     397{
     398    u_char *outp;
     399    int outlen;
     400
     401    outp = outpacket_buf;
     402
     403    outlen = 4 + len;
     404   
     405    MAKEHEADER(outp, PPP_CBCP);
     406
     407    PUTCHAR(code, outp);
     408    PUTCHAR(us->us_id, outp);
     409    PUTSHORT(outlen, outp);
     410   
     411    if (len)
     412        BCOPY(buf, outp, len);
     413
     414    output(us->us_unit, outpacket_buf, outlen + PPP_HDRLEN);
     415}
     416
     417static void
     418cbcp_recvack(us, pckt, len)
     419    cbcp_state *us;
     420    char *pckt;
     421    int len;
     422{
     423    u_char type, delay, addr_type;
     424    int opt_len;
     425    char address[256];
     426
     427    if (len) {
     428        GETCHAR(type, pckt);
     429        GETCHAR(opt_len, pckt);
     430     
     431        if (opt_len > 2)
     432            GETCHAR(delay, pckt);
     433
     434        if (opt_len > 4) {
     435            GETCHAR(addr_type, pckt);
     436            memcpy(address, pckt, opt_len - 4);
     437            address[opt_len - 4] = 0;
     438            if (address[0])
     439                dbglog("peer will call: %s", address);
     440        }
     441        if (type == CB_CONF_NO)
     442            return;
     443    }
     444
     445    cbcp_up(us);
     446}
     447
     448/* ok peer will do callback */
     449static void
     450cbcp_up(us)
     451    cbcp_state *us;
     452{
     453    persist = 0;
     454    lcp_close(0, "Call me back, please");
     455    status = EXIT_CALLBACK;
     456}
  • c/src/libnetworking/pppd/cbcp.h

    rba71076 raee474b  
     1#ifndef CBCP_H
     2#define CBCP_H
     3
     4typedef struct cbcp_state {
     5    int    us_unit;     /* Interface unit number */
     6    u_char us_id;               /* Current id */
     7    u_char us_allowed;
     8    int    us_type;
     9    char   *us_number;    /* Telefone Number */
     10} cbcp_state;
     11
     12extern cbcp_state cbcp[];
     13
     14extern struct protent cbcp_protent;
     15
     16#define CBCP_MINLEN 4
     17
     18#define CBCP_REQ    1
     19#define CBCP_RESP   2
     20#define CBCP_ACK    3
     21
     22#define CB_CONF_NO     1
     23#define CB_CONF_USER   2
     24#define CB_CONF_ADMIN  3
     25#define CB_CONF_LIST   4
     26#endif
  • c/src/libnetworking/pppd/chat.c

    rba71076 raee474b  
    1515 *
    1616 * -----------------
     17 *      22-May-99 added environment substitutuion, enabled with -E switch.
     18 *      Andreas Arens <andras@cityweb.de>.
     19 *
     20 *      12-May-99 added a feature to read data to be sent from a file,
     21 *      if the send string starts with @.  Idea from gpk <gpk@onramp.net>.
     22 *
    1723 *      added -T and -U option and \T and \U substitution to pass a phone
    1824 *      number into chat script. Two are needed for some ISDN TA applications.
     
    7581 *              (614)451-1883
    7682 *
    77  *
    78  */
    79 
    80 #ifndef lint
    81 /* static char rcsid[] = ""; */
    82 #endif
     83 */
    8384
    8485#include <stdio.h>
     
    8687#include <time.h>
    8788#include <fcntl.h>
    88 #include <signal.h>
    8989#include <errno.h>
    9090#include <string.h>
     
    9494#include <sys/stat.h>
    9595#include <syslog.h>
     96#include <termios.h>
     97#include "pppd.h"
    9698
    9799#undef  TERMIOS
    98100#define TERMIOS
    99101
    100 
    101 #include <termios.h>
    102102
    103103#define STR_LEN 1024
     
    143143char *program_name;
    144144
    145 #define MAX_ABORTS              5
    146 #define MAX_REPORTS             5
     145#define MAX_ABORTS              16
     146#define MAX_REPORTS             16
    147147#define DEFAULT_CHAT_TIMEOUT    45
    148 #define fcntl(a, b,c ) 0
    149 #define MAX_TIMEOUTS 10
    150 
    151 int echo          = 0;
    152 int verbose       = 0;
    153 int to_log        = 1;
    154 int to_stderr     = 0;
    155 int Verbose       = 0;
    156 int quiet         = 0;
    157 int report        = 0;
    158 int exit_code     = 0;
    159 char *report_file = (char *) 0;
    160 char *chat_file   = (char *) 0;
    161 char *phone_num   = (char *) 0;
    162 char *phone_num2  = (char *) 0;
    163 int chat_timeout       = DEFAULT_CHAT_TIMEOUT;
    164 static int timeout       = DEFAULT_CHAT_TIMEOUT;
    165 int have_tty_parameters = 0;
     148#define MAX_TIMEOUTS            10
     149
     150int echo             = 0;
     151int quiet            = 0;
     152int report           = 0;
     153int use_env          = 0;
     154int exit_code        = 0;
     155char *report_file    = (char *) 0;
     156char *chat_file      = (char *) 0;
     157char *phone_num      = (char *) 0;
     158char *phone_num2     = (char *) 0;
     159static int timeout   = DEFAULT_CHAT_TIMEOUT;
    166160
    167161#ifdef TERMIOS
    168162#define term_parms struct termios
    169 #define get_term_param(param) tcgetattr(ttyfd, param)
    170 #define set_term_param(param) tcsetattr(ttyfd, TCSANOW, param)
     163#define get_term_param(param) tcgetattr(0, param)
     164#define set_term_param(param) tcsetattr(0, TCSANOW, param)
    171165struct termios saved_tty_parameters;
    172166#endif
    173167
    174 char *abort_string[MAX_ABORTS]={"BUSY","NO DIALTONE","NO CARRIER","NO ASWER","RINGING\r\n\r\nRINGING"};
    175 char *fail_reason = (char *)0,
    176         fail_buffer[50];
    177 int n_aborts = MAX_ABORTS, abort_next = 0, timeout_next = 0, echo_next = 0;
     168char *fail_reason = (char *)0;
     169char  fail_buffer[50];
     170char *abort_string[MAX_ABORTS]={"BUSY","NO DIALTONE","NO CARRIER","NO ANSWER","RING\r\nRING"};
     171int n_aborts = 5;
     172int abort_next = 0, timeout_next = 0, echo_next = 0;
    178173int clear_abort_next = 0;
    179174
     
    187182void *dup_mem __P((void *b, size_t c));
    188183void *copy_of __P((char *s));
    189 /*
    190 SIGTYPE sigalrm __P((int signo));
    191 SIGTYPE sigint __P((int signo));
    192 SIGTYPE sigterm __P((int signo));
    193 SIGTYPE sighup __P((int signo));
    194 */
    195 void unalarm __P((void));
    196 void init __P((void));
    197 void set_tty_parameters __P((void));
    198 void echo_stderr __P((int));
    199184void break_sequence __P((void));
    200 void terminate __P((int status));
    201 void do_file __P((char *chat_file));
    202185int  get_string __P((register char *string));
    203186int  put_string __P((register char *s));
     
    209192void chat_expect __P((register char *s));
    210193char *clean __P((register char *s, int sending));
    211 void break_sequence __P((void));
    212 void terminate __P((int status));
    213 void pack_array __P((char **array, int end));
    214194char *expect_strtok __P((char *, char *));
    215 int vfmtmsg __P((char *, int, const char *, va_list));  /* vsprintf++ */
    216 
    217 #if 0
    218 int usleep( long usec );                                  /* returns 0 if ok, else -1 */
    219 #endif
    220    
    221 extern int input_fd,output_fd;
    222 
    223 int main __P((int, char *[]));
     195int chatmain __P((char *));
     196
    224197
    225198void *dup_mem(b, c)
     
    229202    void *ans = malloc (c);
    230203    if (!ans)
    231                 return NULL;
    232 
    233     memcpy (ans, b, c);
     204        return NULL;
     205
     206    memcpy(ans, b, c);
    234207    return ans;
    235208}
     
    238211char *s;
    239212{
    240     return dup_mem (s, strlen (s) + 1);
    241 }
    242 
    243 /*
    244  * chat [ -v ] [-T number] [-U number] [ -t timeout ] [ -f chat-file ] \
    245  * [ -r report-file ] \
    246  *              [...[[expect[-say[-expect...]] say expect[-say[-expect]] ...]]]
    247  *
    248  *      Perform a UUCP-dialer-like chat script on stdin and stdout.
    249  */
     213    return dup_mem(s, strlen (s) + 1);
     214}
     215
    250216char *getnextcommand(char **string)
    251217{
    252218        char *buf=*string,*res;
    253         res=strchr(buf,'@');
     219        res=strchr(buf,'|');
    254220        if (res==NULL)
    255221                return NULL;
     
    259225}
    260226
    261  
    262 extern int ttyfd;
    263227int chatmain(argv)
    264228char *argv;
     
    269233  exit_code = 0;
    270234
    271 printf("chat_main: %s\n", argv);
     235  if ( debug ) {
     236    dbglog("chat_main: %s\n", argv);
     237  }
    272238
    273239  /* get first expect string */
    274240  arg = getnextcommand(&argv);
    275   while ( arg != NULL ) {
     241  while (( arg != NULL ) && ( exit_code == 0 )) {
    276242    /* process the expect string */
    277243    chat_expect(arg);
    278 
    279     /* get the next send string */
    280     arg = getnextcommand(&argv);
    281     if ( arg != NULL ) {
    282       /* process the send string */
    283       chat_send(arg);
    284 
    285       /* get the next expect string */
     244    if ( exit_code == 0 ) {
     245      /* get the next send string */
    286246      arg = getnextcommand(&argv);
     247      if ( arg != NULL ) {
     248        /* process the send string */
     249        chat_send(arg);
     250
     251        /* get the next expect string */
     252        arg = getnextcommand(&argv);
     253      }
    287254    }
    288255  }
    289256
    290   return 0;
    291 }
    292 
    293 
    294 
    295 /*
    296  *      Print an error message and terminate.
    297  */
    298 
    299 void init()
    300 {
    301     set_tty_parameters();
    302 }
    303 
    304 void set_tty_parameters()
    305 {
    306     term_parms t;
    307 
    308         if (get_term_param (&t) < 0)
    309                 syslog(LOG_NOTICE,"Can't get terminal parameters:")
    310                 ;
    311        
    312     saved_tty_parameters = t;
    313     have_tty_parameters  = 1;
    314     t.c_iflag     |= IGNBRK | ISTRIP | IGNPAR;
    315     t.c_oflag      = 0;
    316     t.c_lflag      = 0;
    317     t.c_cc[VERASE] =
    318     t.c_cc[VKILL]  = 0;
    319     t.c_cc[VMIN]   = 0;
    320     t.c_cc[VTIME]  = 1;
    321     if (set_term_param (&t) < 0)
    322                 syslog(LOG_NOTICE,"Can't set terminal parameters:")
    323                 ;
     257  if ( exit_code ) {
     258   exit_code = -exit_code;
     259  }
     260
     261  return ( exit_code );
    324262}
    325263
    326264void break_sequence()
    327265{
    328 
    329 /*    tcsendbreak (0, 0);*/
    330 }
    331 
    332 /*void terminate(status)
    333 int status;
    334 {
    335     echo_stderr(-1);
    336 
    337     if (have_tty_parameters) {
    338         if (set_term_param (&saved_tty_parameters) < 0)
    339             fatal(2, "Can't restore terminal parameters: %m");
    340     }
    341 }
    342 */
     266  tcsendbreak(ttyfd, 0);
     267}
     268
    343269/*
    344270 *      'Clean up' this string.
     
    348274int sending;  /* set to 1 when sending (putting) this string. */
    349275{
    350     char temp[STR_LEN], cur_chr;
     276    char temp[STR_LEN], env_str[STR_LEN], cur_chr;
    351277    register char *s1, *phchar;
    352278    int add_return = sending;
    353 #define isoctal(chr) (((chr) >= '0') && ((chr) <= '7'))
     279#define isoctal(chr)    (((chr) >= '0') && ((chr) <= '7'))
     280#define isalnumx(chr)   ((((chr) >= '0') && ((chr) <= '9')) \
     281                         || (((chr) >= 'a') && ((chr) <= 'z')) \
     282                         || (((chr) >= 'A') && ((chr) <= 'Z')) \
     283                         || (chr) == '_')
    354284
    355285    s1 = temp;
     
    368298            continue;
    369299        }
     300       
     301        if (use_env && cur_chr == '$') {                /* ARI */
     302            phchar = env_str;
     303            while (isalnumx(*s))
     304                *phchar++ = *s++;
     305            *phchar = '\0';
     306            phchar = getenv(env_str);
     307            if (phchar)
     308                while (*phchar)
     309                    *s1++ = *phchar++;
     310            continue;
     311        }
    370312
    371313        if (cur_chr != '\\') {
     
    401343            if (sending)
    402344                *s1++ = '\\';
    403 
    404345            *s1++ = cur_chr;
    405346            break;
     
    407348        case 'T':
    408349            if (sending && phone_num) {
    409                 for ( phchar = phone_num; *phchar != '\0'; phchar++)
     350                for (phchar = phone_num; *phchar != '\0'; phchar++)
    410351                    *s1++ = *phchar;
    411352            }
     
    418359        case 'U':
    419360            if (sending && phone_num2) {
    420                 for ( phchar = phone_num2; *phchar != '\0'; phchar++)
     361                for (phchar = phone_num2; *phchar != '\0'; phchar++)
    421362                    *s1++ = *phchar;
    422363            }
     
    456397            break;
    457398           
     399        case '$':                       /* ARI */
     400            if (use_env) {
     401                *s1++ = cur_chr;
     402                break;
     403            }
     404            /* FALL THROUGH */
     405
    458406        default:
    459407            if (isoctal (cur_chr)) {
     
    494442 * A modified version of 'strtok'. This version skips \ sequences.
    495443 */
    496 
    497444char *expect_strtok (s, term)
    498445     char *s, *term;
     
    549496 * Process the expect string
    550497 */
    551 
    552 void   chat_expect (s)
     498void chat_expect (s)
    553499char *s;
    554500{
     
    558504    if (strcmp(s, "HANGUP") == 0) {
    559505        ++hup_next;
    560         return ;
     506        return;
    561507    }
    562508 
    563509    if (strcmp(s, "ABORT") == 0) {
    564510        ++abort_next;
    565         return ;
     511        return;
    566512    }
    567513
    568514    if (strcmp(s, "CLR_ABORT") == 0) {
    569515        ++clear_abort_next;
    570         return ;
     516        return;
    571517    }
    572518
    573519    if (strcmp(s, "REPORT") == 0) {
    574520        ++report_next;
    575         return ;
     521        return;
    576522    }
    577523
    578524    if (strcmp(s, "CLR_REPORT") == 0) {
    579525        ++clear_report_next;
    580         return ;
     526        return;
    581527    }
    582528
    583529    if (strcmp(s, "TIMEOUT") == 0) {
    584530        ++timeout_next;
    585         return ;
     531        return;
    586532    }
    587533
    588534    if (strcmp(s, "ECHO") == 0) {
    589535        ++echo_next;
    590         return ;
     536        return;
    591537    }
    592538
    593539    if (strcmp(s, "SAY") == 0) {
    594540        ++say_next;
    595         return ;
     541        return;
    596542    }
    597543
     
    601547    for (;;) {
    602548        expect = expect_strtok (s, "-");
    603         s      = (char *)0 ;
     549        s      = (char *) 0;
    604550
    605551        if (expect == (char *) 0)
    606             return ;
     552            return;
    607553
    608554        reply = expect_strtok (s, "-");
     
    623569        chat_send (reply);
    624570    }
    625 
    626 /*
    627  * The expectation did not occur. This is terminal.
    628  */
    629     return ;
     571}
     572
     573/*
     574 * Translate the input character to the appropriate string for printing
     575 * the data.
     576 */
     577
     578char *character(c)
     579int c;
     580{
     581    static char string[10];
     582    char *meta;
     583
     584    meta = (c & 0x80) ? "M-" : "";
     585    c &= 0x7F;
     586
     587    if (c < 32)
     588        sprintf(string, "%s^%c", meta, (int)c + '@');
     589    else if (c == 127)
     590        sprintf(string, "%s^?", meta);
     591    else
     592        sprintf(string, "%s%c", meta, c);
     593
     594    return (string);
    630595}
    631596
     
    636601register char *s;
    637602{
     603    char file_data[STR_LEN];
     604
    638605    if (say_next) {
    639606        say_next = 0;
    640         s = clean(s,0);
    641         write(ttyfd, s, strlen(s));
     607        s = clean(s, 1);
     608        write(2, s, strlen(s));
    642609        free(s);
    643610        return;
     
    646613    if (hup_next) {
    647614        hup_next = 0;
     615        return;
    648616    }
    649617
     
    655623
    656624    if (abort_next) {
    657         /* char *s1; */
     625        char *s1;
    658626       
     627        abort_next = 0;
     628        if ( n_aborts < MAX_ABORTS ) {
     629          s1 = clean(s, 0);
     630          if (( strlen(s1) <= strlen(s) ) &&
     631              ( strlen(s1) <  sizeof(fail_buffer))) {
     632
     633            abort_string[n_aborts++] = s1;
     634          }
     635        }
     636        return;
     637    }
     638
     639    if (clear_abort_next) {
     640        clear_abort_next = 0;
     641        return;
     642    }
     643
     644    if (report_next) {
     645        report_next = 0;
     646        return;
     647    }
     648
     649    if (clear_report_next) {
     650        clear_report_next = 0;
     651        return;
     652    }
     653
     654    if (timeout_next) {
     655        timeout_next = 0;
     656        timeout = atoi(s);
    659657       
    660            ;
    661        
    662 
    663         return;
    664     }
    665 
    666     if (timeout_next) {
    667         timeout=atoi(s);
    668         timeout_next = 0;
    669         chat_timeout = atoi(s);
    670        
    671         if (chat_timeout <= 0)
    672             chat_timeout = DEFAULT_CHAT_TIMEOUT;
    673 
    674 
    675         return;
    676     }
     658        if (timeout <= 0)
     659            timeout = DEFAULT_CHAT_TIMEOUT;
     660
     661        return;
     662    }
     663
    677664    if (strcmp(s, "EOT") == 0)
    678665        s = "^D\\c";
     
    680667        s = "\\K\\c";
    681668
    682     if (!put_string(s))
    683             {
    684               exit_code=1;
    685               return;
    686             }
     669    if (!put_string(s)) {
     670      exit_code = 2;
     671    }
    687672}
    688673
     
    709694int c;
    710695{
    711     int status;
    712     char ch = c;
    713 
    714         /* inter-character typing delay (?) */
    715 
    716     status = write(ttyfd, &ch, 1);
    717 
    718     switch (status) {
    719     case 1:
    720         return (0);
    721        
    722     default:
    723        
    724        
    725     }
     696  char ch = c;
     697
     698  write(ttyfd, &ch, 1);
     699
    726700  return 0;
    727701}
     
    775749    }
    776750
    777    /* alarm(0);*/
    778751    return (1);
    779752}
    780753
    781754/*
    782  *      Echo a character to stderr.
    783  *      When called with -1, a '\n' character is generated when
    784  *      the cursor is not at the beginning of a line.
    785  */
    786 void echo_stderr(n)
    787 int n;
    788 {
    789 /*    static int need_lf;
    790     char *s;
    791 
    792     switch (n) {
    793     case '\r':           
    794         break;
    795     case -1:
    796         if (need_lf == 0)
    797             break;
    798  
    799     case '\n':
    800         write(2, "\n", 1);
    801         need_lf = 0;
    802         break;
    803     default:
    804         s = character(n);
    805         write(2, s, strlen(s));
    806         need_lf = 1;
    807         break;
    808     }*/
    809 }
    810 
    811 /*
    812755 *      'Wait for' this string to appear on this file descriptor.
    813756 */
    814 
    815757int get_string(string)
    816758register char *string;
     
    820762    char *logged = temp2;
    821763    struct termios tios;
     764
     765    memset(temp2, 0, sizeof(temp2));
    822766
    823767    tcgetattr(ttyfd, &tios);
     
    839783    }
    840784
    841 
    842785   while ( (c = get_char()) >= 0) {
    843786                int n, abort_len;
     
    845788        *s++ = c;
    846789        *s=0;
    847        
     790
    848791        if (s - temp2 >= len &&
    849792            c == string[len - 1] &&
     
    872815        }
    873816    }
     817
    874818    exit_code = 3;
    875819    return (0);
    876820}
    877 
    878 /*
    879  * Gross kludge to handle Solaris versions >= 2.6 having usleep.
    880  */
    881 
    882 /*
    883   usleep -- support routine for 4.2BSD system call emulations
    884   last edit:  29-Oct-1984     D A Gwyn
    885   */
    886 
    887 
    888 #if 0
    889 int
    890 usleep( usec )                            /* returns 0 if ok, else -1 */
    891     long                usec;           /* delay in microseconds */
    892 {
    893   rtems_status_code status;
    894   rtems_interval    ticks_per_second;
    895   rtems_interval    ticks;
    896   status = rtems_clock_get(
    897     RTEMS_CLOCK_GET_TICKS_PER_SECOND,
    898     &ticks_per_second);
    899     ticks = (usec * (ticks_per_second/1000))/1000;
    900     status = rtems_task_wake_after( ticks );
    901   return 0;
    902 }
    903 #endif
    904 
    905 void pack_array (array, end)
    906     char **array; /* The address of the array of string pointers */
    907     int    end;   /* The index of the next free entry before CLR_ */
    908 {
    909     int i, j;
    910 
    911     for (i = 0; i < end; i++) {
    912         if (array[i] == NULL) {
    913             for (j = i+1; j < end; ++j)
    914                 if (array[j] != NULL)
    915                     array[i++] = array[j];
    916             for (; i < end; ++i)
    917                 array[i] = NULL;
    918             break;
    919         }
    920     }
    921 }
    922 
    923 /*
    924  * vfmtmsg - format a message into a buffer.  Like vsprintf except we
    925  * also specify the length of the output buffer, and we handle the
    926  * %m (error message) format.
    927  * Doesn't do floating-point formats.
    928  * Returns the number of chars put into buf.
    929  */
    930 #define OUTCHAR(c)      (buflen > 0? (--buflen, *buf++ = (c)): 0)
  • c/src/libnetworking/pppd/example/README

    rba71076 raee474b  
    77be renamed to Makefile or the -f option given to make.  The file
    88is renamed to avoid bootstrap -c removing it.
     9
     10The files ppp.conf and pppd.options are sample configuration files
     11that have successfully used to make ppp connections over a null
     12modem serial cable to a UNIX box.  Please review the man pages
     13for either the ppp or pppd applications to ensure they are configured
     14correctly.
     15
  • c/src/libnetworking/pppd/pppd.h

    rba71076 raee474b  
    590590#endif
    591591#define DEBUGMAIN       1
     592#define DEBUGUPAP       1
     593#define DEBUGCHAP       1
    592594
    593595
  • c/src/libnetworking/pppd/rtemsmain.c

    rba71076 raee474b  
    107107int kill_link;
    108108int open_ccp_flag;
    109 
    110 static int waiting;
    111109
    112110char **script_env;              /* Env. variable values for scripts */
     
    234232        setlogmask(LOG_UPTO(LOG_DEBUG));
    235233    */
    236 
    237     waiting = 0;
    238234
    239235    do_callback = 0;
     
    401397        new_phase(PHASE_ESTABLISH);
    402398        while (phase != PHASE_DEAD) {
    403             waiting = 1;
    404399            wait_input(timeleft(&timo));
    405             waiting = 0;
    406 
    407400            calltimeout();
    408401            get_input();
     402
    409403            if (kill_link) {
    410404                lcp_close(0, "User request");
     
    470464            TIMEOUT(holdoff_end, NULL, t);
    471465            do {
    472                 waiting = 1;
    473466                wait_input(timeleft(&timo));
    474                 waiting = 0;
    475467
    476468                calltimeout();
  • cpukit/libnetworking/ChangeLog

    rba71076 raee474b  
     12001-10-12      Mike Siers <mikes@poliac.com>
     2
     3        * Update to stable working state.  Congratulations Mike! :)
     4        * modem_example: Directory removed.
     5        * modem_example/16550.h, modem_example/README, modem_example/modem.c,
     6        modem_example/modem.h, modem_example/ppp.c, modem_example/ppp.h,
     7        modem_example/pppcompress.c: Files removed.
     8        * pppd/example/pppd.options: New file.
     9        * pppd/README, pppd/STATUS, pppd/cbcp.c, pppd/cbcp.h, pppd/chat.c,
     10        pppd/pppd.h, pppd/rtemsmain.c: Updated.
     11
    1122001-10-11      Ralf Corsepius <corsepiu@faw.uni-ulm.de>
    213
  • cpukit/pppd/README

    rba71076 raee474b  
    1717The port was updated to 2.3.11 by Mike Siers <mikes@poliac.com>
    1818who added an example test.
     19
     20Updated the chat program to return the correct errors and support
     21the ABORT commands.  Removed some dead code and did a lot of
     22testing on a new Coldfire BSP.  Version seems to be very stable.
    1923=================================================================
    2024
  • cpukit/pppd/STATUS

    rba71076 raee474b  
    33#
    44
     5The pppd application seems to very stable.  It has been tested using
     6the example application with the i386/pc586 and m68k/sbc5206e BSPs.
     7The tests were executed using a null modem serial cable to connect
     8with a UNIX box running either the ppp or pppd application and with
     9an external modem to dial up a local ISP.
    510
    6 Notes from Mike Siers <mikes@poliac.com>
    7 ========================================
     11If you have problems getting your target to make consistent connections
     12with an ISP, the problem is most likely with the ppp options.  First
     13try using the "novj" and "noaccomp" options.  If you have questions
     14about what other option values are available for the rtems_pppd_set_option
     15function, please look at the pppd.8 man page file or the the source code.
     16The majority of options that are documented in man page should work
     17with this function call.
    818
    9 I know that several users have tried out this version of
    10 pppd under RTEMS.  It has been successfully used as both
    11 a client and server.  Below are the only issues that I
    12 know of.
     19The pppd application requires the BSP termios driver support task
     20driven I/O.  Below is a list of known issues that need to be resolved:
    1321
    14 1) Large packet ping causes RTEMS box to lock up
    15    If you ping the RTEMS box over the ppp link with a packet
    16    size greater than 1500, the RTEMS box locks up.  I think
    17    the problem is in the pppd ethernet driver.
     22  - pppd locks up when it receives large packet pings (> 1500 bytes)
     23  - pppd occasionaly locks up with mbuf allocation error
     24    (problem is rare and may be BSP related)
    1825
    19 2) Upgrade the libnetworking/modem files
    20    This upgrade did not modify the ppp ethernet driver files
    21    in the libnetworking/modem directory.  Would like to
    22    upgrade these files.  Hopefully, it will fix the large
    23    packet ping problem.
     26If you find any other problems or fix some problems, please post your
     27changes to the RTEMS mailing list.
    2428
    25 3) The files cbcp.c and cbcp.h provide a callback feature
    26    that I have not tried to compile or use.  The files in
    27    this directory are identical to the 2.3.11 versions. 
    28    for completeness.
    29 
    30 
    31 JOEL: Are the modifications to the original pppd such that the
    32       real maintainers will accept them?
    33 
    34 No.  The pppd 2.3.11 branch is an old branch.  The current
    35 version is 2.4.x and it contains alot of extra items that
    36 just did not make sense to have in an embedded environment.
    37 I could make the RTEMS changes compatible with the standard
    38 2.3.11 release by using compilation flags.  I have not
    39 contacted the maintainers to see if they are interested.
    40 
     29Good Luck
  • cpukit/pppd/cbcp.c

    rba71076 raee474b  
     1/*
     2 * cbcp - Call Back Configuration Protocol.
     3 *
     4 * Copyright (c) 1995 Pedro Roque Marques
     5 * All rights reserved.
     6 *
     7 * Redistribution and use in source and binary forms are permitted
     8 * provided that the above copyright notice and this paragraph are
     9 * duplicated in all such forms and that any documentation,
     10 * advertising materials, and other materials related to such
     11 * distribution and use acknowledge that the software was developed
     12 * by Pedro Roque Marques.  The name of the author may not be used to
     13 * endorse or promote products derived from this software without
     14 * specific prior written permission.
     15 *
     16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
     17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
     18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
     19 */
     20
     21#define RCSID   "$Id$"
     22
     23#include <stdio.h>
     24#include <string.h>
     25#include <sys/types.h>
     26#include <sys/time.h>
     27
     28#include "pppd.h"
     29#include "cbcp.h"
     30#include "fsm.h"
     31#include "lcp.h"
     32
     33static const char rcsid[] = RCSID;
     34
     35/*
     36 * Options.
     37 */
     38static int setcbcp __P((char **));
     39
     40static option_t cbcp_option_list[] = {
     41    { "callback", o_special, setcbcp,
     42      "Ask for callback" },
     43    { NULL }
     44};
     45
     46/*
     47 * Protocol entry points.
     48 */
     49static void cbcp_init      __P((int unit));
     50static void cbcp_open      __P((int unit));
     51static void cbcp_lowerup   __P((int unit));
     52static void cbcp_input     __P((int unit, u_char *pkt, int len));
     53static void cbcp_protrej   __P((int unit));
     54static int  cbcp_printpkt  __P((u_char *pkt, int len,
     55                                void (*printer) __P((void *, char *, ...)),
     56                                void *arg));
     57
     58struct protent cbcp_protent = {
     59    PPP_CBCP,
     60    cbcp_init,
     61    cbcp_input,
     62    cbcp_protrej,
     63    cbcp_lowerup,
     64    NULL,
     65    cbcp_open,
     66    NULL,
     67    cbcp_printpkt,
     68    NULL,
     69    0,
     70    "CBCP",
     71    NULL,
     72    cbcp_option_list,
     73    NULL,
     74    NULL,
     75    NULL
     76};
     77
     78cbcp_state cbcp[NUM_PPP];       
     79
     80/* internal prototypes */
     81
     82static void cbcp_recvreq __P((cbcp_state *us, char *pckt, int len));
     83static void cbcp_resp __P((cbcp_state *us));
     84static void cbcp_up __P((cbcp_state *us));
     85static void cbcp_recvack __P((cbcp_state *us, char *pckt, int len));
     86static void cbcp_send __P((cbcp_state *us, u_char code, u_char *buf, int len));
     87
     88/* option processing */
     89static int
     90setcbcp(argv)
     91    char **argv;
     92{
     93    lcp_wantoptions[0].neg_cbcp = 1;
     94    cbcp_protent.enabled_flag = 1;
     95    cbcp[0].us_number = strdup(*argv);
     96    if (cbcp[0].us_number == 0)
     97        novm("callback number");
     98    cbcp[0].us_type |= (1 << CB_CONF_USER);
     99    cbcp[0].us_type |= (1 << CB_CONF_ADMIN);
     100    return (1);
     101}
     102
     103/* init state */
     104static void
     105cbcp_init(iface)
     106    int iface;
     107{
     108    cbcp_state *us;
     109
     110    us = &cbcp[iface];
     111    memset(us, 0, sizeof(cbcp_state));
     112    us->us_unit = iface;
     113    us->us_type |= (1 << CB_CONF_NO);
     114}
     115
     116/* lower layer is up */
     117static void
     118cbcp_lowerup(iface)
     119    int iface;
     120{
     121    cbcp_state *us = &cbcp[iface];
     122
     123    dbglog("cbcp_lowerup");
     124    dbglog("want: %d", us->us_type);
     125
     126    if (us->us_type == CB_CONF_USER)
     127        dbglog("phone no: %s", us->us_number);
     128}
     129
     130static void
     131cbcp_open(unit)
     132    int unit;
     133{
     134    dbglog("cbcp_open");
     135}
     136
     137/* process an incomming packet */
     138static void
     139cbcp_input(unit, inpacket, pktlen)
     140    int unit;
     141    u_char *inpacket;
     142    int pktlen;
     143{
     144    u_char *inp;
     145    u_char code, id;
     146    u_short len;
     147
     148    cbcp_state *us = &cbcp[unit];
     149
     150    inp = inpacket;
     151
     152    if (pktlen < CBCP_MINLEN) {
     153        error("CBCP packet is too small");
     154        return;
     155    }
     156
     157    GETCHAR(code, inp);
     158    GETCHAR(id, inp);
     159    GETSHORT(len, inp);
     160
     161#if 0
     162    if (len > pktlen) {
     163        error("CBCP packet: invalid length");
     164        return;
     165    }
     166#endif
     167
     168    len -= CBCP_MINLEN;
     169 
     170    switch(code) {
     171    case CBCP_REQ:
     172        us->us_id = id;
     173        cbcp_recvreq(us, inp, len);
     174        break;
     175
     176    case CBCP_RESP:
     177        dbglog("CBCP_RESP received");
     178        break;
     179
     180    case CBCP_ACK:
     181        if (id != us->us_id)
     182            dbglog("id doesn't match: expected %d recv %d",
     183                   us->us_id, id);
     184
     185        cbcp_recvack(us, inp, len);
     186        break;
     187
     188    default:
     189        break;
     190    }
     191}
     192
     193/* protocol was rejected by foe */
     194void cbcp_protrej(int iface)
     195{
     196}
     197
     198char *cbcp_codenames[] = {
     199    "Request", "Response", "Ack"
     200};
     201
     202char *cbcp_optionnames[] = {
     203    "NoCallback",
     204    "UserDefined",
     205    "AdminDefined",
     206    "List"
     207};
     208
     209/* pretty print a packet */
     210static int
     211cbcp_printpkt(p, plen, printer, arg)
     212    u_char *p;
     213    int plen;
     214    void (*printer) __P((void *, char *, ...));
     215    void *arg;
     216{
     217    int code, opt, id, len, olen, delay;
     218    u_char *pstart;
     219
     220    if (plen < HEADERLEN)
     221        return 0;
     222    pstart = p;
     223    GETCHAR(code, p);
     224    GETCHAR(id, p);
     225    GETSHORT(len, p);
     226    if (len < HEADERLEN || len > plen)
     227        return 0;
     228
     229    if (code >= 1 && code <= sizeof(cbcp_codenames) / sizeof(char *))
     230        printer(arg, " %s", cbcp_codenames[code-1]);
     231    else
     232        printer(arg, " code=0x%x", code);
     233
     234    printer(arg, " id=0x%x", id);
     235    len -= HEADERLEN;
     236
     237    switch (code) {
     238    case CBCP_REQ:
     239    case CBCP_RESP:
     240    case CBCP_ACK:
     241        while(len >= 2) {
     242            GETCHAR(opt, p);
     243            GETCHAR(olen, p);
     244
     245            if (olen < 2 || olen > len) {
     246                break;
     247            }
     248
     249            printer(arg, " <");
     250            len -= olen;
     251
     252            if (opt >= 1 && opt <= sizeof(cbcp_optionnames) / sizeof(char *))
     253                printer(arg, " %s", cbcp_optionnames[opt-1]);
     254            else
     255                printer(arg, " option=0x%x", opt);
     256
     257            if (olen > 2) {
     258                GETCHAR(delay, p);
     259                printer(arg, " delay = %d", delay);
     260            }
     261
     262            if (olen > 3) {
     263                int addrt;
     264                char str[256];
     265
     266                GETCHAR(addrt, p);
     267                memcpy(str, p, olen - 4);
     268                str[olen - 4] = 0;
     269                printer(arg, " number = %s", str);
     270            }
     271            printer(arg, ">");
     272            break;
     273        }
     274
     275    default:
     276        break;
     277    }
     278
     279    for (; len > 0; --len) {
     280        GETCHAR(code, p);
     281        printer(arg, " %.2x", code);
     282    }
     283
     284    return p - pstart;
     285}
     286
     287/* received CBCP request */
     288static void
     289cbcp_recvreq(us, pckt, pcktlen)
     290    cbcp_state *us;
     291    char *pckt;
     292    int pcktlen;
     293{
     294    u_char type, opt_len, delay, addr_type;
     295    char address[256];
     296    int len = pcktlen;
     297
     298    address[0] = 0;
     299
     300    while (len) {
     301        dbglog("length: %d", len);
     302
     303        GETCHAR(type, pckt);
     304        GETCHAR(opt_len, pckt);
     305
     306        if (opt_len > 2)
     307            GETCHAR(delay, pckt);
     308
     309        us->us_allowed |= (1 << type);
     310
     311        switch(type) {
     312        case CB_CONF_NO:
     313            dbglog("no callback allowed");
     314            break;
     315
     316        case CB_CONF_USER:
     317            dbglog("user callback allowed");
     318            if (opt_len > 4) {
     319                GETCHAR(addr_type, pckt);
     320                memcpy(address, pckt, opt_len - 4);
     321                address[opt_len - 4] = 0;
     322                if (address[0])
     323                    dbglog("address: %s", address);
     324            }
     325            break;
     326
     327        case CB_CONF_ADMIN:
     328            dbglog("user admin defined allowed");
     329            break;
     330
     331        case CB_CONF_LIST:
     332            break;
     333        }
     334        len -= opt_len;
     335    }
     336
     337    cbcp_resp(us);
     338}
     339
     340static void
     341cbcp_resp(us)
     342    cbcp_state *us;
     343{
     344    u_char cb_type;
     345    u_char buf[256];
     346    u_char *bufp = buf;
     347    int len = 0;
     348
     349    cb_type = us->us_allowed & us->us_type;
     350    dbglog("cbcp_resp cb_type=%d", cb_type);
     351
     352#if 0
     353    if (!cb_type)
     354        lcp_down(us->us_unit);
     355#endif
     356
     357    if (cb_type & ( 1 << CB_CONF_USER ) ) {
     358        dbglog("cbcp_resp CONF_USER");
     359        PUTCHAR(CB_CONF_USER, bufp);
     360        len = 3 + 1 + strlen(us->us_number) + 1;
     361        PUTCHAR(len , bufp);
     362        PUTCHAR(5, bufp); /* delay */
     363        PUTCHAR(1, bufp);
     364        BCOPY(us->us_number, bufp, strlen(us->us_number) + 1);
     365        cbcp_send(us, CBCP_RESP, buf, len);
     366        return;
     367    }
     368
     369    if (cb_type & ( 1 << CB_CONF_ADMIN ) ) {
     370        dbglog("cbcp_resp CONF_ADMIN");
     371        PUTCHAR(CB_CONF_ADMIN, bufp);
     372        len = 3;
     373        PUTCHAR(len, bufp);
     374        PUTCHAR(5, bufp); /* delay */
     375        cbcp_send(us, CBCP_RESP, buf, len);
     376        return;
     377    }
     378
     379    if (cb_type & ( 1 << CB_CONF_NO ) ) {
     380        dbglog("cbcp_resp CONF_NO");
     381        PUTCHAR(CB_CONF_NO, bufp);
     382        len = 3;
     383        PUTCHAR(len , bufp);
     384        PUTCHAR(0, bufp);
     385        cbcp_send(us, CBCP_RESP, buf, len);
     386        start_networks();
     387        return;
     388    }
     389}
     390
     391static void
     392cbcp_send(us, code, buf, len)
     393    cbcp_state *us;
     394    u_char code;
     395    u_char *buf;
     396    int len;
     397{
     398    u_char *outp;
     399    int outlen;
     400
     401    outp = outpacket_buf;
     402
     403    outlen = 4 + len;
     404   
     405    MAKEHEADER(outp, PPP_CBCP);
     406
     407    PUTCHAR(code, outp);
     408    PUTCHAR(us->us_id, outp);
     409    PUTSHORT(outlen, outp);
     410   
     411    if (len)
     412        BCOPY(buf, outp, len);
     413
     414    output(us->us_unit, outpacket_buf, outlen + PPP_HDRLEN);
     415}
     416
     417static void
     418cbcp_recvack(us, pckt, len)
     419    cbcp_state *us;
     420    char *pckt;
     421    int len;
     422{
     423    u_char type, delay, addr_type;
     424    int opt_len;
     425    char address[256];
     426
     427    if (len) {
     428        GETCHAR(type, pckt);
     429        GETCHAR(opt_len, pckt);
     430     
     431        if (opt_len > 2)
     432            GETCHAR(delay, pckt);
     433
     434        if (opt_len > 4) {
     435            GETCHAR(addr_type, pckt);
     436            memcpy(address, pckt, opt_len - 4);
     437            address[opt_len - 4] = 0;
     438            if (address[0])
     439                dbglog("peer will call: %s", address);
     440        }
     441        if (type == CB_CONF_NO)
     442            return;
     443    }
     444
     445    cbcp_up(us);
     446}
     447
     448/* ok peer will do callback */
     449static void
     450cbcp_up(us)
     451    cbcp_state *us;
     452{
     453    persist = 0;
     454    lcp_close(0, "Call me back, please");
     455    status = EXIT_CALLBACK;
     456}
  • cpukit/pppd/cbcp.h

    rba71076 raee474b  
     1#ifndef CBCP_H
     2#define CBCP_H
     3
     4typedef struct cbcp_state {
     5    int    us_unit;     /* Interface unit number */
     6    u_char us_id;               /* Current id */
     7    u_char us_allowed;
     8    int    us_type;
     9    char   *us_number;    /* Telefone Number */
     10} cbcp_state;
     11
     12extern cbcp_state cbcp[];
     13
     14extern struct protent cbcp_protent;
     15
     16#define CBCP_MINLEN 4
     17
     18#define CBCP_REQ    1
     19#define CBCP_RESP   2
     20#define CBCP_ACK    3
     21
     22#define CB_CONF_NO     1
     23#define CB_CONF_USER   2
     24#define CB_CONF_ADMIN  3
     25#define CB_CONF_LIST   4
     26#endif
  • cpukit/pppd/chat.c

    rba71076 raee474b  
    1515 *
    1616 * -----------------
     17 *      22-May-99 added environment substitutuion, enabled with -E switch.
     18 *      Andreas Arens <andras@cityweb.de>.
     19 *
     20 *      12-May-99 added a feature to read data to be sent from a file,
     21 *      if the send string starts with @.  Idea from gpk <gpk@onramp.net>.
     22 *
    1723 *      added -T and -U option and \T and \U substitution to pass a phone
    1824 *      number into chat script. Two are needed for some ISDN TA applications.
     
    7581 *              (614)451-1883
    7682 *
    77  *
    78  */
    79 
    80 #ifndef lint
    81 /* static char rcsid[] = ""; */
    82 #endif
     83 */
    8384
    8485#include <stdio.h>
     
    8687#include <time.h>
    8788#include <fcntl.h>
    88 #include <signal.h>
    8989#include <errno.h>
    9090#include <string.h>
     
    9494#include <sys/stat.h>
    9595#include <syslog.h>
     96#include <termios.h>
     97#include "pppd.h"
    9698
    9799#undef  TERMIOS
    98100#define TERMIOS
    99101
    100 
    101 #include <termios.h>
    102102
    103103#define STR_LEN 1024
     
    143143char *program_name;
    144144
    145 #define MAX_ABORTS              5
    146 #define MAX_REPORTS             5
     145#define MAX_ABORTS              16
     146#define MAX_REPORTS             16
    147147#define DEFAULT_CHAT_TIMEOUT    45
    148 #define fcntl(a, b,c ) 0
    149 #define MAX_TIMEOUTS 10
    150 
    151 int echo          = 0;
    152 int verbose       = 0;
    153 int to_log        = 1;
    154 int to_stderr     = 0;
    155 int Verbose       = 0;
    156 int quiet         = 0;
    157 int report        = 0;
    158 int exit_code     = 0;
    159 char *report_file = (char *) 0;
    160 char *chat_file   = (char *) 0;
    161 char *phone_num   = (char *) 0;
    162 char *phone_num2  = (char *) 0;
    163 int chat_timeout       = DEFAULT_CHAT_TIMEOUT;
    164 static int timeout       = DEFAULT_CHAT_TIMEOUT;
    165 int have_tty_parameters = 0;
     148#define MAX_TIMEOUTS            10
     149
     150int echo             = 0;
     151int quiet            = 0;
     152int report           = 0;
     153int use_env          = 0;
     154int exit_code        = 0;
     155char *report_file    = (char *) 0;
     156char *chat_file      = (char *) 0;
     157char *phone_num      = (char *) 0;
     158char *phone_num2     = (char *) 0;
     159static int timeout   = DEFAULT_CHAT_TIMEOUT;
    166160
    167161#ifdef TERMIOS
    168162#define term_parms struct termios
    169 #define get_term_param(param) tcgetattr(ttyfd, param)
    170 #define set_term_param(param) tcsetattr(ttyfd, TCSANOW, param)
     163#define get_term_param(param) tcgetattr(0, param)
     164#define set_term_param(param) tcsetattr(0, TCSANOW, param)
    171165struct termios saved_tty_parameters;
    172166#endif
    173167
    174 char *abort_string[MAX_ABORTS]={"BUSY","NO DIALTONE","NO CARRIER","NO ASWER","RINGING\r\n\r\nRINGING"};
    175 char *fail_reason = (char *)0,
    176         fail_buffer[50];
    177 int n_aborts = MAX_ABORTS, abort_next = 0, timeout_next = 0, echo_next = 0;
     168char *fail_reason = (char *)0;
     169char  fail_buffer[50];
     170char *abort_string[MAX_ABORTS]={"BUSY","NO DIALTONE","NO CARRIER","NO ANSWER","RING\r\nRING"};
     171int n_aborts = 5;
     172int abort_next = 0, timeout_next = 0, echo_next = 0;
    178173int clear_abort_next = 0;
    179174
     
    187182void *dup_mem __P((void *b, size_t c));
    188183void *copy_of __P((char *s));
    189 /*
    190 SIGTYPE sigalrm __P((int signo));
    191 SIGTYPE sigint __P((int signo));
    192 SIGTYPE sigterm __P((int signo));
    193 SIGTYPE sighup __P((int signo));
    194 */
    195 void unalarm __P((void));
    196 void init __P((void));
    197 void set_tty_parameters __P((void));
    198 void echo_stderr __P((int));
    199184void break_sequence __P((void));
    200 void terminate __P((int status));
    201 void do_file __P((char *chat_file));
    202185int  get_string __P((register char *string));
    203186int  put_string __P((register char *s));
     
    209192void chat_expect __P((register char *s));
    210193char *clean __P((register char *s, int sending));
    211 void break_sequence __P((void));
    212 void terminate __P((int status));
    213 void pack_array __P((char **array, int end));
    214194char *expect_strtok __P((char *, char *));
    215 int vfmtmsg __P((char *, int, const char *, va_list));  /* vsprintf++ */
    216 
    217 #if 0
    218 int usleep( long usec );                                  /* returns 0 if ok, else -1 */
    219 #endif
    220    
    221 extern int input_fd,output_fd;
    222 
    223 int main __P((int, char *[]));
     195int chatmain __P((char *));
     196
    224197
    225198void *dup_mem(b, c)
     
    229202    void *ans = malloc (c);
    230203    if (!ans)
    231                 return NULL;
    232 
    233     memcpy (ans, b, c);
     204        return NULL;
     205
     206    memcpy(ans, b, c);
    234207    return ans;
    235208}
     
    238211char *s;
    239212{
    240     return dup_mem (s, strlen (s) + 1);
    241 }
    242 
    243 /*
    244  * chat [ -v ] [-T number] [-U number] [ -t timeout ] [ -f chat-file ] \
    245  * [ -r report-file ] \
    246  *              [...[[expect[-say[-expect...]] say expect[-say[-expect]] ...]]]
    247  *
    248  *      Perform a UUCP-dialer-like chat script on stdin and stdout.
    249  */
     213    return dup_mem(s, strlen (s) + 1);
     214}
     215
    250216char *getnextcommand(char **string)
    251217{
    252218        char *buf=*string,*res;
    253         res=strchr(buf,'@');
     219        res=strchr(buf,'|');
    254220        if (res==NULL)
    255221                return NULL;
     
    259225}
    260226
    261  
    262 extern int ttyfd;
    263227int chatmain(argv)
    264228char *argv;
     
    269233  exit_code = 0;
    270234
    271 printf("chat_main: %s\n", argv);
     235  if ( debug ) {
     236    dbglog("chat_main: %s\n", argv);
     237  }
    272238
    273239  /* get first expect string */
    274240  arg = getnextcommand(&argv);
    275   while ( arg != NULL ) {
     241  while (( arg != NULL ) && ( exit_code == 0 )) {
    276242    /* process the expect string */
    277243    chat_expect(arg);
    278 
    279     /* get the next send string */
    280     arg = getnextcommand(&argv);
    281     if ( arg != NULL ) {
    282       /* process the send string */
    283       chat_send(arg);
    284 
    285       /* get the next expect string */
     244    if ( exit_code == 0 ) {
     245      /* get the next send string */
    286246      arg = getnextcommand(&argv);
     247      if ( arg != NULL ) {
     248        /* process the send string */
     249        chat_send(arg);
     250
     251        /* get the next expect string */
     252        arg = getnextcommand(&argv);
     253      }
    287254    }
    288255  }
    289256
    290   return 0;
    291 }
    292 
    293 
    294 
    295 /*
    296  *      Print an error message and terminate.
    297  */
    298 
    299 void init()
    300 {
    301     set_tty_parameters();
    302 }
    303 
    304 void set_tty_parameters()
    305 {
    306     term_parms t;
    307 
    308         if (get_term_param (&t) < 0)
    309                 syslog(LOG_NOTICE,"Can't get terminal parameters:")
    310                 ;
    311        
    312     saved_tty_parameters = t;
    313     have_tty_parameters  = 1;
    314     t.c_iflag     |= IGNBRK | ISTRIP | IGNPAR;
    315     t.c_oflag      = 0;
    316     t.c_lflag      = 0;
    317     t.c_cc[VERASE] =
    318     t.c_cc[VKILL]  = 0;
    319     t.c_cc[VMIN]   = 0;
    320     t.c_cc[VTIME]  = 1;
    321     if (set_term_param (&t) < 0)
    322                 syslog(LOG_NOTICE,"Can't set terminal parameters:")
    323                 ;
     257  if ( exit_code ) {
     258   exit_code = -exit_code;
     259  }
     260
     261  return ( exit_code );
    324262}
    325263
    326264void break_sequence()
    327265{
    328 
    329 /*    tcsendbreak (0, 0);*/
    330 }
    331 
    332 /*void terminate(status)
    333 int status;
    334 {
    335     echo_stderr(-1);
    336 
    337     if (have_tty_parameters) {
    338         if (set_term_param (&saved_tty_parameters) < 0)
    339             fatal(2, "Can't restore terminal parameters: %m");
    340     }
    341 }
    342 */
     266  tcsendbreak(ttyfd, 0);
     267}
     268
    343269/*
    344270 *      'Clean up' this string.
     
    348274int sending;  /* set to 1 when sending (putting) this string. */
    349275{
    350     char temp[STR_LEN], cur_chr;
     276    char temp[STR_LEN], env_str[STR_LEN], cur_chr;
    351277    register char *s1, *phchar;
    352278    int add_return = sending;
    353 #define isoctal(chr) (((chr) >= '0') && ((chr) <= '7'))
     279#define isoctal(chr)    (((chr) >= '0') && ((chr) <= '7'))
     280#define isalnumx(chr)   ((((chr) >= '0') && ((chr) <= '9')) \
     281                         || (((chr) >= 'a') && ((chr) <= 'z')) \
     282                         || (((chr) >= 'A') && ((chr) <= 'Z')) \
     283                         || (chr) == '_')
    354284
    355285    s1 = temp;
     
    368298            continue;
    369299        }
     300       
     301        if (use_env && cur_chr == '$') {                /* ARI */
     302            phchar = env_str;
     303            while (isalnumx(*s))
     304                *phchar++ = *s++;
     305            *phchar = '\0';
     306            phchar = getenv(env_str);
     307            if (phchar)
     308                while (*phchar)
     309                    *s1++ = *phchar++;
     310            continue;
     311        }
    370312
    371313        if (cur_chr != '\\') {
     
    401343            if (sending)
    402344                *s1++ = '\\';
    403 
    404345            *s1++ = cur_chr;
    405346            break;
     
    407348        case 'T':
    408349            if (sending && phone_num) {
    409                 for ( phchar = phone_num; *phchar != '\0'; phchar++)
     350                for (phchar = phone_num; *phchar != '\0'; phchar++)
    410351                    *s1++ = *phchar;
    411352            }
     
    418359        case 'U':
    419360            if (sending && phone_num2) {
    420                 for ( phchar = phone_num2; *phchar != '\0'; phchar++)
     361                for (phchar = phone_num2; *phchar != '\0'; phchar++)
    421362                    *s1++ = *phchar;
    422363            }
     
    456397            break;
    457398           
     399        case '$':                       /* ARI */
     400            if (use_env) {
     401                *s1++ = cur_chr;
     402                break;
     403            }
     404            /* FALL THROUGH */
     405
    458406        default:
    459407            if (isoctal (cur_chr)) {
     
    494442 * A modified version of 'strtok'. This version skips \ sequences.
    495443 */
    496 
    497444char *expect_strtok (s, term)
    498445     char *s, *term;
     
    549496 * Process the expect string
    550497 */
    551 
    552 void   chat_expect (s)
     498void chat_expect (s)
    553499char *s;
    554500{
     
    558504    if (strcmp(s, "HANGUP") == 0) {
    559505        ++hup_next;
    560         return ;
     506        return;
    561507    }
    562508 
    563509    if (strcmp(s, "ABORT") == 0) {
    564510        ++abort_next;
    565         return ;
     511        return;
    566512    }
    567513
    568514    if (strcmp(s, "CLR_ABORT") == 0) {
    569515        ++clear_abort_next;
    570         return ;
     516        return;
    571517    }
    572518
    573519    if (strcmp(s, "REPORT") == 0) {
    574520        ++report_next;
    575         return ;
     521        return;
    576522    }
    577523
    578524    if (strcmp(s, "CLR_REPORT") == 0) {
    579525        ++clear_report_next;
    580         return ;
     526        return;
    581527    }
    582528
    583529    if (strcmp(s, "TIMEOUT") == 0) {
    584530        ++timeout_next;
    585         return ;
     531        return;
    586532    }
    587533
    588534    if (strcmp(s, "ECHO") == 0) {
    589535        ++echo_next;
    590         return ;
     536        return;
    591537    }
    592538
    593539    if (strcmp(s, "SAY") == 0) {
    594540        ++say_next;
    595         return ;
     541        return;
    596542    }
    597543
     
    601547    for (;;) {
    602548        expect = expect_strtok (s, "-");
    603         s      = (char *)0 ;
     549        s      = (char *) 0;
    604550
    605551        if (expect == (char *) 0)
    606             return ;
     552            return;
    607553
    608554        reply = expect_strtok (s, "-");
     
    623569        chat_send (reply);
    624570    }
    625 
    626 /*
    627  * The expectation did not occur. This is terminal.
    628  */
    629     return ;
     571}
     572
     573/*
     574 * Translate the input character to the appropriate string for printing
     575 * the data.
     576 */
     577
     578char *character(c)
     579int c;
     580{
     581    static char string[10];
     582    char *meta;
     583
     584    meta = (c & 0x80) ? "M-" : "";
     585    c &= 0x7F;
     586
     587    if (c < 32)
     588        sprintf(string, "%s^%c", meta, (int)c + '@');
     589    else if (c == 127)
     590        sprintf(string, "%s^?", meta);
     591    else
     592        sprintf(string, "%s%c", meta, c);
     593
     594    return (string);
    630595}
    631596
     
    636601register char *s;
    637602{
     603    char file_data[STR_LEN];
     604
    638605    if (say_next) {
    639606        say_next = 0;
    640         s = clean(s,0);
    641         write(ttyfd, s, strlen(s));
     607        s = clean(s, 1);
     608        write(2, s, strlen(s));
    642609        free(s);
    643610        return;
     
    646613    if (hup_next) {
    647614        hup_next = 0;
     615        return;
    648616    }
    649617
     
    655623
    656624    if (abort_next) {
    657         /* char *s1; */
     625        char *s1;
    658626       
     627        abort_next = 0;
     628        if ( n_aborts < MAX_ABORTS ) {
     629          s1 = clean(s, 0);
     630          if (( strlen(s1) <= strlen(s) ) &&
     631              ( strlen(s1) <  sizeof(fail_buffer))) {
     632
     633            abort_string[n_aborts++] = s1;
     634          }
     635        }
     636        return;
     637    }
     638
     639    if (clear_abort_next) {
     640        clear_abort_next = 0;
     641        return;
     642    }
     643
     644    if (report_next) {
     645        report_next = 0;
     646        return;
     647    }
     648
     649    if (clear_report_next) {
     650        clear_report_next = 0;
     651        return;
     652    }
     653
     654    if (timeout_next) {
     655        timeout_next = 0;
     656        timeout = atoi(s);
    659657       
    660            ;
    661        
    662 
    663         return;
    664     }
    665 
    666     if (timeout_next) {
    667         timeout=atoi(s);
    668         timeout_next = 0;
    669         chat_timeout = atoi(s);
    670        
    671         if (chat_timeout <= 0)
    672             chat_timeout = DEFAULT_CHAT_TIMEOUT;
    673 
    674 
    675         return;
    676     }
     658        if (timeout <= 0)
     659            timeout = DEFAULT_CHAT_TIMEOUT;
     660
     661        return;
     662    }
     663
    677664    if (strcmp(s, "EOT") == 0)
    678665        s = "^D\\c";
     
    680667        s = "\\K\\c";
    681668
    682     if (!put_string(s))
    683             {
    684               exit_code=1;
    685               return;
    686             }
     669    if (!put_string(s)) {
     670      exit_code = 2;
     671    }
    687672}
    688673
     
    709694int c;
    710695{
    711     int status;
    712     char ch = c;
    713 
    714         /* inter-character typing delay (?) */
    715 
    716     status = write(ttyfd, &ch, 1);
    717 
    718     switch (status) {
    719     case 1:
    720         return (0);
    721        
    722     default:
    723        
    724        
    725     }
     696  char ch = c;
     697
     698  write(ttyfd, &ch, 1);
     699
    726700  return 0;
    727701}
     
    775749    }
    776750
    777    /* alarm(0);*/
    778751    return (1);
    779752}
    780753
    781754/*
    782  *      Echo a character to stderr.
    783  *      When called with -1, a '\n' character is generated when
    784  *      the cursor is not at the beginning of a line.
    785  */
    786 void echo_stderr(n)
    787 int n;
    788 {
    789 /*    static int need_lf;
    790     char *s;
    791 
    792     switch (n) {
    793     case '\r':           
    794         break;
    795     case -1:
    796         if (need_lf == 0)
    797             break;
    798  
    799     case '\n':
    800         write(2, "\n", 1);
    801         need_lf = 0;
    802         break;
    803     default:
    804         s = character(n);
    805         write(2, s, strlen(s));
    806         need_lf = 1;
    807         break;
    808     }*/
    809 }
    810 
    811 /*
    812755 *      'Wait for' this string to appear on this file descriptor.
    813756 */
    814 
    815757int get_string(string)
    816758register char *string;
     
    820762    char *logged = temp2;
    821763    struct termios tios;
     764
     765    memset(temp2, 0, sizeof(temp2));
    822766
    823767    tcgetattr(ttyfd, &tios);
     
    839783    }
    840784
    841 
    842785   while ( (c = get_char()) >= 0) {
    843786                int n, abort_len;
     
    845788        *s++ = c;
    846789        *s=0;
    847        
     790
    848791        if (s - temp2 >= len &&
    849792            c == string[len - 1] &&
     
    872815        }
    873816    }
     817
    874818    exit_code = 3;
    875819    return (0);
    876820}
    877 
    878 /*
    879  * Gross kludge to handle Solaris versions >= 2.6 having usleep.
    880  */
    881 
    882 /*
    883   usleep -- support routine for 4.2BSD system call emulations
    884   last edit:  29-Oct-1984     D A Gwyn
    885   */
    886 
    887 
    888 #if 0
    889 int
    890 usleep( usec )                            /* returns 0 if ok, else -1 */
    891     long                usec;           /* delay in microseconds */
    892 {
    893   rtems_status_code status;
    894   rtems_interval    ticks_per_second;
    895   rtems_interval    ticks;
    896   status = rtems_clock_get(
    897     RTEMS_CLOCK_GET_TICKS_PER_SECOND,
    898     &ticks_per_second);
    899     ticks = (usec * (ticks_per_second/1000))/1000;
    900     status = rtems_task_wake_after( ticks );
    901   return 0;
    902 }
    903 #endif
    904 
    905 void pack_array (array, end)
    906     char **array; /* The address of the array of string pointers */
    907     int    end;   /* The index of the next free entry before CLR_ */
    908 {
    909     int i, j;
    910 
    911     for (i = 0; i < end; i++) {
    912         if (array[i] == NULL) {
    913             for (j = i+1; j < end; ++j)
    914                 if (array[j] != NULL)
    915                     array[i++] = array[j];
    916             for (; i < end; ++i)
    917                 array[i] = NULL;
    918             break;
    919         }
    920     }
    921 }
    922 
    923 /*
    924  * vfmtmsg - format a message into a buffer.  Like vsprintf except we
    925  * also specify the length of the output buffer, and we handle the
    926  * %m (error message) format.
    927  * Doesn't do floating-point formats.
    928  * Returns the number of chars put into buf.
    929  */
    930 #define OUTCHAR(c)      (buflen > 0? (--buflen, *buf++ = (c)): 0)
  • cpukit/pppd/example/README

    rba71076 raee474b  
    77be renamed to Makefile or the -f option given to make.  The file
    88is renamed to avoid bootstrap -c removing it.
     9
     10The files ppp.conf and pppd.options are sample configuration files
     11that have successfully used to make ppp connections over a null
     12modem serial cable to a UNIX box.  Please review the man pages
     13for either the ppp or pppd applications to ensure they are configured
     14correctly.
     15
  • cpukit/pppd/pppd.h

    rba71076 raee474b  
    590590#endif
    591591#define DEBUGMAIN       1
     592#define DEBUGUPAP       1
     593#define DEBUGCHAP       1
    592594
    593595
  • cpukit/pppd/rtemsmain.c

    rba71076 raee474b  
    107107int kill_link;
    108108int open_ccp_flag;
    109 
    110 static int waiting;
    111109
    112110char **script_env;              /* Env. variable values for scripts */
     
    234232        setlogmask(LOG_UPTO(LOG_DEBUG));
    235233    */
    236 
    237     waiting = 0;
    238234
    239235    do_callback = 0;
     
    401397        new_phase(PHASE_ESTABLISH);
    402398        while (phase != PHASE_DEAD) {
    403             waiting = 1;
    404399            wait_input(timeleft(&timo));
    405             waiting = 0;
    406 
    407400            calltimeout();
    408401            get_input();
     402
    409403            if (kill_link) {
    410404                lcp_close(0, "User request");
     
    470464            TIMEOUT(holdoff_end, NULL, t);
    471465            do {
    472                 waiting = 1;
    473466                wait_input(timeleft(&timo));
    474                 waiting = 0;
    475467
    476468                calltimeout();
Note: See TracChangeset for help on using the changeset viewer.