source: rtems/cpukit/pppd/rtemspppd.c @ 4e97166

4.104.114.84.95
Last change on this file since 4e97166 was 689b7b7a, checked in by Joel Sherrill <joel.sherrill@…>, on 11/07/05 at 16:17:14

2005-11-07 Michael Siers <mikes@…>

  • pppd/rtemspppd.c, pppd/rtemspppd.h: Per confirmation from Michael add missing copyright notice.
  • Property mode set to 100644
File size: 5.7 KB
Line 
1/*
2 * COPYRIGHT (c) 2001, Michael Siers <mikes@poliac.com>.
3 *                     Poliac Research, Burnsville, Minnesota USA.
4 * COPYRIGHT (c) 2001, On-Line Applications Research Corporation (OAR).
5 *
6 * The license and distribution terms for this file may be
7 * found in the file LICENSE in this distribution or at
8 * http://www.rtems.com/license/LICENSE.
9 *
10 *  $Id$
11 */
12
13#include <rtems.h>
14#include <rtems/rtems_bsdnet.h>
15#include "pppd.h"
16#include "rtemspppd.h"
17
18
19/* define pppd function prototypes */
20extern void pppasyncattach(void);
21extern int  pppdmain(int, char **);
22
23/* define global variables */
24rtems_id                   rtems_pppd_taskid;
25rtems_pppd_hookfunction    rtems_pppd_errorfp;
26rtems_pppd_hookfunction    rtems_pppd_exitfp;
27
28
29static rtems_task pppTask(rtems_task_argument arg)
30{
31  rtems_status_code   sc = RTEMS_SUCCESSFUL;
32  rtems_option        options;
33  rtems_event_set     in;
34  rtems_event_set     out;
35  int                 iStatus;
36
37  /* call function to setup ppp line discipline */
38  pppasyncattach();
39
40  /* enter processing loop */
41  in      = (RTEMS_EVENT_29 | RTEMS_EVENT_30);
42  options = (RTEMS_EVENT_ANY | RTEMS_WAIT);
43  while ( sc == RTEMS_SUCCESSFUL ) {
44    /* wait for the next event */
45    sc = rtems_event_receive(in, options, RTEMS_NO_TIMEOUT, &out);
46    if ( sc == RTEMS_SUCCESSFUL ) {
47      /* determine which event was sent */
48      if ( out & RTEMS_EVENT_29 ) {
49        /* terminate event received */
50        /* set value to break out of event loop */
51        sc = RTEMS_UNSATISFIED;
52      }
53      else if ( out & RTEMS_EVENT_30 ) {
54        /* connect request */
55        /* execute the pppd main code */
56        iStatus = pppdmain(0, NULL);
57        if ( iStatus == EXIT_OK ) {
58          /* check exit callback */
59          if ( rtems_pppd_exitfp ) {
60            (*rtems_pppd_exitfp)();
61          }
62        }
63        else {
64          /* check error callback */
65          if ( rtems_pppd_errorfp ) {
66            (*rtems_pppd_errorfp)();
67          }
68        }
69      }
70    }
71  }
72
73  /* terminate myself */
74  rtems_pppd_taskid = 0;
75  rtems_task_delete(RTEMS_SELF);
76}
77
78int rtems_pppd_initialize(void)
79{
80  int                 iReturn  = (int)-1;
81  rtems_task_priority priority = 100;
82  rtems_status_code   status;
83  rtems_name          taskName;
84
85  /* determine priority value */
86  if ( rtems_bsdnet_config.network_task_priority ) {
87    priority = rtems_bsdnet_config.network_task_priority;
88  }
89
90  /* initialize the exit hook */
91  rtems_pppd_exitfp = (rtems_pppd_hookfunction)0;
92
93  /* create the rtems task */
94  taskName = rtems_build_name( 'p', 'p', 'p', 'd' );
95  status   = rtems_task_create(taskName, priority, 8192,
96                               (RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0)),
97                               RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
98                               &rtems_pppd_taskid);
99  if ( status == RTEMS_SUCCESSFUL ) {
100    status = rtems_task_start(rtems_pppd_taskid, pppTask, 0);
101    if ( status == RTEMS_SUCCESSFUL ) {
102      iReturn = rtems_pppd_reset_options();
103    }
104  }
105
106  return ( iReturn );
107}
108
109int rtems_pppd_terminate(void)
110{
111  /* send terminate signal to pppd task */
112  rtems_event_send(rtems_pppd_taskid, RTEMS_EVENT_29);
113
114  /* call the disconnect function */
115  rtems_pppd_disconnect();
116
117  return ( 0 );
118}
119
120int rtems_pppd_reset_options(void)
121{
122    int i;
123    struct protent *protp;
124
125    /*
126     * Initialize to the standard option set, then parse, in order,
127     * the system options file, the user's options file,
128     * the tty's options file, and the command line arguments.
129     */
130    for (i = 0; (protp = protocols[i]) != NULL; ++i)
131        (*protp->init)(0);
132
133  return ( 0 );
134}
135
136int rtems_pppd_set_hook(int id, rtems_pppd_hookfunction hookfp)
137{
138  int     iReturn = (int)0;
139
140  switch ( id ) {
141  case RTEMS_PPPD_LINKUP_HOOK:
142    auth_linkup_hook = hookfp;
143    break;
144  case RTEMS_PPPD_LINKDOWN_HOOK:
145    auth_linkdown_hook = hookfp;
146    break;
147  case RTEMS_PPPD_IPUP_HOOK:
148    ip_up_hook = hookfp;
149    break;
150  case RTEMS_PPPD_IPDOWN_HOOK:
151    ip_down_hook = hookfp;
152    break;
153  case RTEMS_PPPD_ERROR_HOOK:
154    rtems_pppd_errorfp = hookfp;
155    break;
156  case RTEMS_PPPD_EXIT_HOOK:
157    rtems_pppd_exitfp = hookfp;
158    break;
159  default:
160    iReturn = (int)-1;
161    break;
162  }
163
164  return ( iReturn );
165}
166
167int rtems_pppd_set_dialer(rtems_pppd_dialerfunction dialerfp)
168{
169  pppd_dialer = dialerfp;
170  return ( (int)0 );
171}
172
173int rtems_pppd_set_option(const char *pOption, const char *pValue)
174{
175  int                iReturn = (int)0;
176  int                prevPhase;
177  struct wordlist    option;
178  struct wordlist    value;
179
180  if ( pOption != (const char *)0 ) {
181    /* initialize the values */
182    option.word = (char *)pOption;
183    option.next = (struct wordlist *)0;
184    if ( pValue != (const char *)0 ) {
185      option.next = &value;
186      value.word  = (char *)pValue;
187      value.next  = (struct wordlist *)0;
188    }
189
190    /* save current phase value */
191    prevPhase = pppd_phase;
192    pppd_phase     = PHASE_INITIALIZE;
193
194    /* process option and reset phase value */
195    iReturn = options_from_list(&option, 1);
196    pppd_phase   = prevPhase;
197  }
198
199  return ( iReturn );
200}
201
202int rtems_pppd_connect(void)
203{
204  /* send connect signal to pppd task */
205  rtems_event_send(rtems_pppd_taskid, RTEMS_EVENT_30);
206
207  return ( 0 );
208}
209
210static void timeout_terminate(void *arg)
211{
212  /* set pppd global variables to disconnect */
213  persist   = 0;
214  pppd_kill_link = 1;
215}
216
217int rtems_pppd_disconnect(void)
218{
219  /* need to wait a little time before we can bring the link down */
220  /* set up time out in 1 seconds */
221  TIMEOUT(timeout_terminate, NULL, 1);
222
223  /* send event to wake up the pppd code */
224  /* pretend its a serial interrput */
225  rtems_event_send(rtems_pppd_taskid, RTEMS_EVENT_31);
226
227  return ( 0 );
228}
Note: See TracBrowser for help on using the repository browser.