The Pedigree Project 0.1
pppapi.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
26/*
27 * Redistribution and use in source and binary forms, with or without modification,
28 * are permitted provided that the following conditions are met:
29 *
30 * 1. Redistributions of source code must retain the above copyright notice,
31 * this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright notice,
33 * this list of conditions and the following disclaimer in the documentation
34 * and/or other materials provided with the distribution.
35 * 3. The name of the author may not be used to endorse or promote products
36 * derived from this software without specific prior written permission.
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
39 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
40 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
41 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
42 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
43 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
44 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
45 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
46 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
47 * OF SUCH DAMAGE.
48 *
49 * This file is part of the lwIP TCP/IP stack.
50 *
51 */
52
53#include "netif/ppp/ppp_opts.h"
54
55#if LWIP_PPP_API /* don't build if not configured for use in lwipopts.h */
56
57#include "netif/ppp/pppapi.h"
59#include "netif/ppp/pppoe.h"
60#include "netif/ppp/pppol2tp.h"
61#include "netif/ppp/pppos.h"
62
63#if LWIP_MPU_COMPATIBLE
64LWIP_MEMPOOL_DECLARE(PPPAPI_MSG, MEMP_NUM_PPP_API_MSG, sizeof(struct pppapi_msg), "PPPAPI_MSG")
65#endif
66
67#define PPPAPI_VAR_REF(name) API_VAR_REF(name)
68#define PPPAPI_VAR_DECLARE(name) API_VAR_DECLARE(struct pppapi_msg, name)
69#define PPPAPI_VAR_ALLOC(name) API_VAR_ALLOC_POOL(struct pppapi_msg, PPPAPI_MSG, name, ERR_MEM)
70#define PPPAPI_VAR_ALLOC_RETURN_NULL(name) API_VAR_ALLOC_POOL(struct pppapi_msg, PPPAPI_MSG, name, NULL)
71#define PPPAPI_VAR_FREE(name) API_VAR_FREE_POOL(PPPAPI_MSG, name)
72
76static err_t
77pppapi_do_ppp_set_default(struct tcpip_api_call_data *m)
78{
79 /* cast through void* to silence alignment warnings.
80 * We know it works because the structs have been instantiated as struct pppapi_msg */
81 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
82
83 ppp_set_default(msg->msg.ppp);
84 return ERR_OK;
85}
86
92pppapi_set_default(ppp_pcb *pcb)
93{
94 err_t err;
95 PPPAPI_VAR_DECLARE(msg);
96 PPPAPI_VAR_ALLOC(msg);
97
98 PPPAPI_VAR_REF(msg).msg.ppp = pcb;
99 err = tcpip_api_call(pppapi_do_ppp_set_default, &PPPAPI_VAR_REF(msg).call);
100 PPPAPI_VAR_FREE(msg);
101 return err;
102}
103
104
105#if PPP_NOTIFY_PHASE
109static err_t
110pppapi_do_ppp_set_notify_phase_callback(struct tcpip_api_call_data *m)
111{
112 /* cast through void* to silence alignment warnings.
113 * We know it works because the structs have been instantiated as struct pppapi_msg */
114 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
115
116 ppp_set_notify_phase_callback(msg->msg.ppp, msg->msg.msg.setnotifyphasecb.notify_phase_cb);
117 return ERR_OK;
118}
119
124err_t
125pppapi_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_phase_cb)
126{
127 err_t err;
128 PPPAPI_VAR_DECLARE(msg);
129 PPPAPI_VAR_ALLOC(msg);
130
131 PPPAPI_VAR_REF(msg).msg.ppp = pcb;
132 PPPAPI_VAR_REF(msg).msg.msg.setnotifyphasecb.notify_phase_cb = notify_phase_cb;
133 err = tcpip_api_call(pppapi_do_ppp_set_notify_phase_callback, &PPPAPI_VAR_REF(msg).call);
134 PPPAPI_VAR_FREE(msg);
135 return err;
136}
137#endif /* PPP_NOTIFY_PHASE */
138
139
140#if PPPOS_SUPPORT
144static err_t
145pppapi_do_pppos_create(struct tcpip_api_call_data *m)
146{
147 /* cast through void* to silence alignment warnings.
148 * We know it works because the structs have been instantiated as struct pppapi_msg */
149 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
150
151 msg->msg.ppp = pppos_create(msg->msg.msg.serialcreate.pppif, msg->msg.msg.serialcreate.output_cb,
152 msg->msg.msg.serialcreate.link_status_cb, msg->msg.msg.serialcreate.ctx_cb);
153 return ERR_OK;
154}
155
160ppp_pcb*
161pppapi_pppos_create(struct netif *pppif, pppos_output_cb_fn output_cb,
162 ppp_link_status_cb_fn link_status_cb, void *ctx_cb)
163{
164 ppp_pcb* result;
165 PPPAPI_VAR_DECLARE(msg);
166 PPPAPI_VAR_ALLOC_RETURN_NULL(msg);
167
168 PPPAPI_VAR_REF(msg).msg.ppp = NULL;
169 PPPAPI_VAR_REF(msg).msg.msg.serialcreate.pppif = pppif;
170 PPPAPI_VAR_REF(msg).msg.msg.serialcreate.output_cb = output_cb;
171 PPPAPI_VAR_REF(msg).msg.msg.serialcreate.link_status_cb = link_status_cb;
172 PPPAPI_VAR_REF(msg).msg.msg.serialcreate.ctx_cb = ctx_cb;
173 tcpip_api_call(pppapi_do_pppos_create, &PPPAPI_VAR_REF(msg).call);
174 result = PPPAPI_VAR_REF(msg).msg.ppp;
175 PPPAPI_VAR_FREE(msg);
176 return result;
177}
178#endif /* PPPOS_SUPPORT */
179
180
181#if PPPOE_SUPPORT
185static err_t
186pppapi_do_pppoe_create(struct tcpip_api_call_data *m)
187{
188 /* cast through void* to silence alignment warnings.
189 * We know it works because the structs have been instantiated as struct pppapi_msg */
190 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
191
192 msg->msg.ppp = pppoe_create(msg->msg.msg.ethernetcreate.pppif, msg->msg.msg.ethernetcreate.ethif,
193 msg->msg.msg.ethernetcreate.service_name, msg->msg.msg.ethernetcreate.concentrator_name,
194 msg->msg.msg.ethernetcreate.link_status_cb, msg->msg.msg.ethernetcreate.ctx_cb);
195 return ERR_OK;
196}
197
202ppp_pcb*
203pppapi_pppoe_create(struct netif *pppif, struct netif *ethif, const char *service_name,
204 const char *concentrator_name, ppp_link_status_cb_fn link_status_cb,
205 void *ctx_cb)
206{
207 ppp_pcb* result;
208 PPPAPI_VAR_DECLARE(msg);
209 PPPAPI_VAR_ALLOC_RETURN_NULL(msg);
210
211 PPPAPI_VAR_REF(msg).msg.ppp = NULL;
212 PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.pppif = pppif;
213 PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.ethif = ethif;
214 PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.service_name = service_name;
215 PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.concentrator_name = concentrator_name;
216 PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.link_status_cb = link_status_cb;
217 PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.ctx_cb = ctx_cb;
218 tcpip_api_call(pppapi_do_pppoe_create, &PPPAPI_VAR_REF(msg).call);
219 result = PPPAPI_VAR_REF(msg).msg.ppp;
220 PPPAPI_VAR_FREE(msg);
221 return result;
222}
223#endif /* PPPOE_SUPPORT */
224
225
226#if PPPOL2TP_SUPPORT
230static err_t
231pppapi_do_pppol2tp_create(struct tcpip_api_call_data *m)
232{
233 /* cast through void* to silence alignment warnings.
234 * We know it works because the structs have been instantiated as struct pppapi_msg */
235 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
236
237 msg->msg.ppp = pppol2tp_create(msg->msg.msg.l2tpcreate.pppif,
238 msg->msg.msg.l2tpcreate.netif, API_EXPR_REF(msg->msg.msg.l2tpcreate.ipaddr), msg->msg.msg.l2tpcreate.port,
239#if PPPOL2TP_AUTH_SUPPORT
240 msg->msg.msg.l2tpcreate.secret,
241 msg->msg.msg.l2tpcreate.secret_len,
242#else /* PPPOL2TP_AUTH_SUPPORT */
243 NULL,
244 0,
245#endif /* PPPOL2TP_AUTH_SUPPORT */
246 msg->msg.msg.l2tpcreate.link_status_cb, msg->msg.msg.l2tpcreate.ctx_cb);
247 return ERR_OK;
248}
249
254ppp_pcb*
255pppapi_pppol2tp_create(struct netif *pppif, struct netif *netif, ip_addr_t *ipaddr, u16_t port,
256 const u8_t *secret, u8_t secret_len,
257 ppp_link_status_cb_fn link_status_cb, void *ctx_cb)
258{
259 ppp_pcb* result;
260 PPPAPI_VAR_DECLARE(msg);
261 PPPAPI_VAR_ALLOC_RETURN_NULL(msg);
262#if !PPPOL2TP_AUTH_SUPPORT
263 LWIP_UNUSED_ARG(secret);
264 LWIP_UNUSED_ARG(secret_len);
265#endif /* !PPPOL2TP_AUTH_SUPPORT */
266
267 PPPAPI_VAR_REF(msg).msg.ppp = NULL;
268 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.pppif = pppif;
269 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.netif = netif;
270 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.ipaddr = PPPAPI_VAR_REF(ipaddr);
271 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.port = port;
272#if PPPOL2TP_AUTH_SUPPORT
273 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.secret = secret;
274 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.secret_len = secret_len;
275#endif /* PPPOL2TP_AUTH_SUPPORT */
276 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.link_status_cb = link_status_cb;
277 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.ctx_cb = ctx_cb;
278 tcpip_api_call(pppapi_do_pppol2tp_create, &PPPAPI_VAR_REF(msg).call);
279 result = PPPAPI_VAR_REF(msg).msg.ppp;
280 PPPAPI_VAR_FREE(msg);
281 return result;
282}
283#endif /* PPPOL2TP_SUPPORT */
284
285
289static err_t
290pppapi_do_ppp_connect(struct tcpip_api_call_data *m)
291{
292 /* cast through void* to silence alignment warnings.
293 * We know it works because the structs have been instantiated as struct pppapi_msg */
294 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
295
296 return ppp_connect(msg->msg.ppp, msg->msg.msg.connect.holdoff);
297}
298
303err_t
304pppapi_connect(ppp_pcb *pcb, u16_t holdoff)
305{
306 err_t err;
307 PPPAPI_VAR_DECLARE(msg);
308 PPPAPI_VAR_ALLOC(msg);
309
310 PPPAPI_VAR_REF(msg).msg.ppp = pcb;
311 PPPAPI_VAR_REF(msg).msg.msg.connect.holdoff = holdoff;
312 err = tcpip_api_call(pppapi_do_ppp_connect, &PPPAPI_VAR_REF(msg).call);
313 PPPAPI_VAR_FREE(msg);
314 return err;
315}
316
317
318#if PPP_SERVER
322static err_t
323pppapi_do_ppp_listen(struct tcpip_api_call_data *m)
324{
325 /* cast through void* to silence alignment warnings.
326 * We know it works because the structs have been instantiated as struct pppapi_msg */
327 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
328
329 return ppp_listen(msg->msg.ppp);
330}
331
336err_t
337pppapi_listen(ppp_pcb *pcb)
338{
339 err_t err;
340 PPPAPI_VAR_DECLARE(msg);
341 PPPAPI_VAR_ALLOC(msg);
342
343 PPPAPI_VAR_REF(msg).msg.ppp = pcb;
344 err = tcpip_api_call(pppapi_do_ppp_listen, &PPPAPI_VAR_REF(msg).call);
345 PPPAPI_VAR_FREE(msg);
346 return err;
347}
348#endif /* PPP_SERVER */
349
350
354static err_t
355pppapi_do_ppp_close(struct tcpip_api_call_data *m)
356{
357 /* cast through void* to silence alignment warnings.
358 * We know it works because the structs have been instantiated as struct pppapi_msg */
359 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
360
361 return ppp_close(msg->msg.ppp, msg->msg.msg.close.nocarrier);
362}
363
368err_t
369pppapi_close(ppp_pcb *pcb, u8_t nocarrier)
370{
371 err_t err;
372 PPPAPI_VAR_DECLARE(msg);
373 PPPAPI_VAR_ALLOC(msg);
374
375 PPPAPI_VAR_REF(msg).msg.ppp = pcb;
376 PPPAPI_VAR_REF(msg).msg.msg.close.nocarrier = nocarrier;
377 err = tcpip_api_call(pppapi_do_ppp_close, &PPPAPI_VAR_REF(msg).call);
378 PPPAPI_VAR_FREE(msg);
379 return err;
380}
381
382
386static err_t
387pppapi_do_ppp_free(struct tcpip_api_call_data *m)
388{
389 /* cast through void* to silence alignment warnings.
390 * We know it works because the structs have been instantiated as struct pppapi_msg */
391 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
392
393 return ppp_free(msg->msg.ppp);
394}
395
400err_t
401pppapi_free(ppp_pcb *pcb)
402{
403 err_t err;
404 PPPAPI_VAR_DECLARE(msg);
405 PPPAPI_VAR_ALLOC(msg);
406
407 PPPAPI_VAR_REF(msg).msg.ppp = pcb;
408 err = tcpip_api_call(pppapi_do_ppp_free, &PPPAPI_VAR_REF(msg).call);
409 PPPAPI_VAR_FREE(msg);
410 return err;
411}
412
413
417static err_t
418pppapi_do_ppp_ioctl(struct tcpip_api_call_data *m)
419{
420 /* cast through void* to silence alignment warnings.
421 * We know it works because the structs have been instantiated as struct pppapi_msg */
422 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
423
424 return ppp_ioctl(msg->msg.ppp, msg->msg.msg.ioctl.cmd, msg->msg.msg.ioctl.arg);
425}
426
431err_t
432pppapi_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg)
433{
434 err_t err;
435 PPPAPI_VAR_DECLARE(msg);
436 PPPAPI_VAR_ALLOC(msg);
437
438 PPPAPI_VAR_REF(msg).msg.ppp = pcb;
439 PPPAPI_VAR_REF(msg).msg.msg.ioctl.cmd = cmd;
440 PPPAPI_VAR_REF(msg).msg.msg.ioctl.arg = arg;
441 err = tcpip_api_call(pppapi_do_ppp_ioctl, &PPPAPI_VAR_REF(msg).call);
442 PPPAPI_VAR_FREE(msg);
443 return err;
444}
445
446#endif /* LWIP_PPP_API */
#define LWIP_UNUSED_ARG(x)
Definition arch.h:327
s8_t err_t
Definition err.h:76
@ ERR_OK
Definition err.h:82
#define LWIP_MEMPOOL_DECLARE(name, num, size, desc)
Definition memp.h:112
Definition cmd.h:30
Definition netif.h:244
err_t tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call_data *call)
Definition tcpip.c:529