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

4.11
Last change on this file since 3324383c was 3324383c, checked in by Joel Sherrill <joel.sherrill@…>, on May 5, 2014 at 2:47:30 PM

testsuites: Remove BSP_SMALL_MEMORY

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