source: rtems/c/src/tests/samples/pppd/pppdapp.c @ d17d9c81

Last change on this file since d17d9c81 was d17d9c81, checked in by cvs2git <rtems-devel@…>, on 05/27/03 at 16:17:32

This commit was manufactured by cvs2svn to create branch 'rtems-4-6-branch'.

Cherrypick from master 2003-05-27 16:17:31 UTC Ralf Corsepius <ralf.corsepius@…> '2003-05-27 Ralf Corsepius <corsepiu@…>':

c/src/tests/samples/pppd/.cvsignore
c/src/tests/samples/pppd/Makefile-user
c/src/tests/samples/pppd/Makefile.am
c/src/tests/samples/pppd/README
c/src/tests/samples/pppd/init.c
c/src/tests/samples/pppd/netconfig.h
c/src/tests/samples/pppd/ppp.conf
c/src/tests/samples/pppd/pppd.options
c/src/tests/samples/pppd/pppdapp.c
c/src/tests/samples/pppd/system.h
cpukit/include/rtems/stdint.h

  • Property mode set to 100644
File size: 4.3 KB
Line 
1
2#include <stdio.h>
3#include <rtemspppd.h>
4#include "system.h"
5
6
7/* define global variables */
8static unsigned int      pppdapp_linkcount = 0;
9static rtems_id          pppdapp_taskid;
10
11
12static void pppdapp_linkup_hook(void)
13{
14  pppdapp_linkcount++;
15  printf("PPP LINK UP   [%d]\n", pppdapp_linkcount);
16}
17
18static void pppdapp_linkdown_hook(void)
19{
20  printf("PPP LINK DOWN [%d]\n", pppdapp_linkcount);
21}
22
23static void pppdapp_ipup_hook(void)
24{
25  /* send ipup signal to pppdapp task */
26  rtems_event_send(pppdapp_taskid, RTEMS_EVENT_10);
27}
28
29static void pppdapp_ipdown_hook(void)
30{
31  /* send ip down signal to pppdapp task */
32  rtems_event_send(pppdapp_taskid, RTEMS_EVENT_11);
33}
34
35static void pppdapp_setup(void)
36{
37  const char   *pUser     = "oscar";
38  const char   *pPassword = "goldman";
39
40#undef  USE_MODEM
41#ifdef  USE_MODEM
42  const char   *pTelephone        = "5551234";
43  const char   *pInitScript       = "TIMEOUT@5@@AT@@OK@";
44  const char   *pConnectScript    = "TIMEOUT@90@@ATDT%s@CONNECT@@name:@%s@word:@%s@";
45  const char   *pDisconnectScript = "TIMEOUT@5@@ATH0@@OK@";
46  char          pConnect[128];
47
48  /* set the connect string */
49  sprintf(pConnect, pConnectScript, pTelephone, pUser, pPassword);
50
51  /* set pppd options for modem */
52  rtems_pppd_set_option("/dev/ttyS2", NULL);
53  rtems_pppd_set_option("57600", NULL);
54  rtems_pppd_set_option("crtscts", NULL);
55  rtems_pppd_set_option("modem", NULL);
56  rtems_pppd_set_option("noauth", NULL);
57  rtems_pppd_set_option("debug", NULL);
58  rtems_pppd_set_option("init", pInitScript);
59  rtems_pppd_set_option("connect", pConnect);
60  rtems_pppd_set_option("disconnect", pDisconnectScript);
61#else
62  /* set pppd options for null modem direct link serial cable */
63  rtems_pppd_set_option("/dev/ttyS1", NULL);
64  rtems_pppd_set_option("57600", NULL);
65  rtems_pppd_set_option("crtscts", NULL);
66  rtems_pppd_set_option("local", NULL);
67  rtems_pppd_set_option("noauth", NULL);
68  rtems_pppd_set_option("debug", NULL);
69  rtems_pppd_set_option("user", pUser);
70  rtems_pppd_set_option("password", pPassword);
71#endif
72
73  /* set up pppd hooks */
74  rtems_pppd_set_hook(RTEMS_PPPD_LINKUP_HOOK, pppdapp_linkup_hook);
75  rtems_pppd_set_hook(RTEMS_PPPD_LINKDOWN_HOOK, pppdapp_linkdown_hook);
76  rtems_pppd_set_hook(RTEMS_PPPD_IPUP_HOOK, pppdapp_ipup_hook);
77  rtems_pppd_set_hook(RTEMS_PPPD_IPDOWN_HOOK, pppdapp_ipdown_hook);
78}
79
80static rtems_task pppdapp(rtems_task_argument arg)
81{
82  rtems_status_code   sc             = RTEMS_SUCCESSFUL;
83  rtems_interval      tickspersecond = 0;
84  rtems_option        options;
85  rtems_event_set     in;
86  rtems_event_set     out;
87
88  /* initialize ticks per second */
89  rtems_clock_get(RTEMS_CLOCK_GET_TICKS_PER_SECOND, &tickspersecond);
90  if ( tickspersecond == 0 ) {
91    /* ensure value is greater than zero */
92    tickspersecond = 100;
93  }
94
95  /* initiate connection */
96  pppdapp_setup();
97  rtems_pppd_connect();
98
99  /* enter processing loop */
100  in      = (RTEMS_EVENT_10 | RTEMS_EVENT_11);
101  options = (RTEMS_EVENT_ANY | RTEMS_WAIT);
102  while ( sc == RTEMS_SUCCESSFUL ) {
103    /* wait for the next event */
104    sc = rtems_event_receive(in, options, RTEMS_NO_TIMEOUT, &out);
105    if ( sc == RTEMS_SUCCESSFUL ) {
106      /* determine which event was sent */
107      if ( out & RTEMS_EVENT_10 ) {
108        /* ip up recived */
109        /* call disconnect function */
110        rtems_pppd_disconnect();
111      }
112      if ( out & RTEMS_EVENT_11 ) {
113        /* ip down recived */
114        /* sleep 10 seconds and call connect function */
115        rtems_task_wake_after(10*tickspersecond);
116        rtems_pppd_connect();
117      }
118    }
119  }
120
121  /* terminate myself */
122  rtems_task_delete(RTEMS_SELF);
123}
124
125int pppdapp_initialize(void)
126{
127  int                 iReturn = (int)-1;
128  rtems_status_code   status;
129  rtems_name          taskName;
130
131  taskName = rtems_build_name( 'p', 'a', 'p', 'p' );
132  status   = rtems_task_create(taskName,
133                               CONFIGURE_INIT_TASK_PRIORITY,
134                               CONFIGURE_INIT_TASK_STACK_SIZE,
135                               CONFIGURE_INIT_TASK_INITIAL_MODES,
136                               RTEMS_DEFAULT_ATTRIBUTES,
137                               &pppdapp_taskid);
138  if ( status == RTEMS_SUCCESSFUL ) {
139    status = rtems_task_start(pppdapp_taskid, pppdapp, 0);
140    if ( status == RTEMS_SUCCESSFUL ) {
141      iReturn = (int)0;
142    }
143  }
144
145  return ( iReturn );
146}
Note: See TracBrowser for help on using the repository browser.