source: rtems/testsuites/samples/pppd/pppdapp.c @ e313551

4.11
Last change on this file since e313551 was e313551, checked in by Ralf Corsepius <ralf.corsepius@…>, on Feb 22, 2011 at 10:58:44 AM

Add HAVE_CONFIG_H.

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