1 | |
---|
2 | #include <rtems.h> |
---|
3 | #include "pppd.h" |
---|
4 | #include "rtemspppd.h" |
---|
5 | |
---|
6 | |
---|
7 | /* define pppd function prototypes */ |
---|
8 | extern void pppasyncattach(void); |
---|
9 | extern int pppdmain(int, char **); |
---|
10 | |
---|
11 | /* define global variables */ |
---|
12 | rtems_id rtems_pppd_taskid; |
---|
13 | |
---|
14 | |
---|
15 | static rtems_task pppTask(rtems_task_argument arg) |
---|
16 | { |
---|
17 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
18 | rtems_option options; |
---|
19 | rtems_event_set in; |
---|
20 | rtems_event_set out; |
---|
21 | |
---|
22 | /* call function to setup ppp line discipline */ |
---|
23 | pppasyncattach(); |
---|
24 | |
---|
25 | /* enter processing loop */ |
---|
26 | in = (RTEMS_EVENT_29 | RTEMS_EVENT_30); |
---|
27 | options = (RTEMS_EVENT_ANY | RTEMS_WAIT); |
---|
28 | while ( sc == RTEMS_SUCCESSFUL ) { |
---|
29 | /* wait for the next event */ |
---|
30 | sc = rtems_event_receive(in, options, RTEMS_NO_TIMEOUT, &out); |
---|
31 | if ( sc == RTEMS_SUCCESSFUL ) { |
---|
32 | /* determine which event was sent */ |
---|
33 | if ( out & RTEMS_EVENT_29 ) { |
---|
34 | /* terminate event received */ |
---|
35 | /* set value to break out of event loop */ |
---|
36 | sc = RTEMS_UNSATISFIED; |
---|
37 | } |
---|
38 | else if ( out & RTEMS_EVENT_30 ) { |
---|
39 | /* connect request */ |
---|
40 | /* execute the pppd main code */ |
---|
41 | pppdmain(0, NULL); |
---|
42 | } |
---|
43 | } |
---|
44 | } |
---|
45 | |
---|
46 | /* terminate myself */ |
---|
47 | rtems_task_delete(RTEMS_SELF); |
---|
48 | } |
---|
49 | |
---|
50 | int rtems_pppd_initialize(void) |
---|
51 | { |
---|
52 | int iReturn = (int)-1; |
---|
53 | rtems_status_code status; |
---|
54 | rtems_name taskName; |
---|
55 | |
---|
56 | taskName = rtems_build_name( 'p', 'p', 'p', 'd' ); |
---|
57 | status = rtems_task_create(taskName, |
---|
58 | RTEMS_PPPD_TASK_PRIORITY, |
---|
59 | RTEMS_PPPD_TASK_STACK_SIZE, |
---|
60 | RTEMS_PPPD_TASK_INITIAL_MODES, |
---|
61 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
62 | &rtems_pppd_taskid); |
---|
63 | if ( status == RTEMS_SUCCESSFUL ) { |
---|
64 | status = rtems_task_start(rtems_pppd_taskid, pppTask, 0); |
---|
65 | if ( status == RTEMS_SUCCESSFUL ) { |
---|
66 | iReturn = rtems_pppd_reset_options(); |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | return ( iReturn ); |
---|
71 | } |
---|
72 | |
---|
73 | int rtems_pppd_terminate(void) |
---|
74 | { |
---|
75 | /* send terminate signal to pppd task */ |
---|
76 | rtems_event_send(rtems_pppd_taskid, RTEMS_EVENT_29); |
---|
77 | |
---|
78 | /* call the disconnect function */ |
---|
79 | rtems_pppd_disconnect(); |
---|
80 | |
---|
81 | return ( 0 ); |
---|
82 | } |
---|
83 | |
---|
84 | int rtems_pppd_reset_options(void) |
---|
85 | { |
---|
86 | int i; |
---|
87 | struct protent *protp; |
---|
88 | |
---|
89 | /* |
---|
90 | * Initialize to the standard option set, then parse, in order, |
---|
91 | * the system options file, the user's options file, |
---|
92 | * the tty's options file, and the command line arguments. |
---|
93 | */ |
---|
94 | for (i = 0; (protp = protocols[i]) != NULL; ++i) |
---|
95 | (*protp->init)(0); |
---|
96 | |
---|
97 | return ( 0 ); |
---|
98 | } |
---|
99 | |
---|
100 | int rtems_pppd_set_hook(int id, rtems_pppd_hookfunction hookfp) |
---|
101 | { |
---|
102 | int iReturn = (int)0; |
---|
103 | |
---|
104 | switch ( id ) { |
---|
105 | case RTEMS_PPPD_LINKUP_HOOK: |
---|
106 | auth_linkup_hook = hookfp; |
---|
107 | break; |
---|
108 | case RTEMS_PPPD_LINKDOWN_HOOK: |
---|
109 | auth_linkdown_hook = hookfp; |
---|
110 | break; |
---|
111 | case RTEMS_PPPD_IPUP_HOOK: |
---|
112 | ip_up_hook = hookfp; |
---|
113 | break; |
---|
114 | case RTEMS_PPPD_IPDOWN_HOOK: |
---|
115 | ip_down_hook = hookfp; |
---|
116 | break; |
---|
117 | default: |
---|
118 | iReturn = (int)-1; |
---|
119 | break; |
---|
120 | } |
---|
121 | |
---|
122 | return ( iReturn ); |
---|
123 | } |
---|
124 | |
---|
125 | int rtems_pppd_set_option(const char *pOption, const char *pValue) |
---|
126 | { |
---|
127 | int iReturn = (int)0; |
---|
128 | int prevPhase; |
---|
129 | struct wordlist option; |
---|
130 | struct wordlist value; |
---|
131 | |
---|
132 | if ( pOption != (const char *)0 ) { |
---|
133 | /* initialize the values */ |
---|
134 | option.word = (char *)pOption; |
---|
135 | option.next = (struct wordlist *)0; |
---|
136 | if ( pValue != (const char *)0 ) { |
---|
137 | option.next = &value; |
---|
138 | value.word = (char *)pValue; |
---|
139 | value.next = (struct wordlist *)0; |
---|
140 | } |
---|
141 | |
---|
142 | /* save current phase value */ |
---|
143 | prevPhase = phase; |
---|
144 | phase = PHASE_INITIALIZE; |
---|
145 | |
---|
146 | /* process option and reset phase value */ |
---|
147 | iReturn = options_from_list(&option, 1); |
---|
148 | phase = prevPhase; |
---|
149 | } |
---|
150 | |
---|
151 | return ( iReturn ); |
---|
152 | } |
---|
153 | |
---|
154 | int rtems_pppd_connect(void) |
---|
155 | { |
---|
156 | /* send connect signal to pppd task */ |
---|
157 | rtems_event_send(rtems_pppd_taskid, RTEMS_EVENT_30); |
---|
158 | |
---|
159 | return ( 0 ); |
---|
160 | } |
---|
161 | |
---|
162 | int rtems_pppd_disconnect(void) |
---|
163 | { |
---|
164 | /* set pppd global variables to disconnect */ |
---|
165 | persist = 0; |
---|
166 | kill_link = 1; |
---|
167 | |
---|
168 | /* send event to wake up the pppd code */ |
---|
169 | /* pretend its a serial interrput */ |
---|
170 | rtems_event_send(rtems_pppd_taskid, RTEMS_EVENT_31); |
---|
171 | |
---|
172 | return ( 0 ); |
---|
173 | } |
---|