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