1*10465441SEvalZero /**
2*10465441SEvalZero * @file
3*10465441SEvalZero * Point To Point Protocol Sequential API module
4*10465441SEvalZero *
5*10465441SEvalZero */
6*10465441SEvalZero
7*10465441SEvalZero /*
8*10465441SEvalZero * Redistribution and use in source and binary forms, with or without modification,
9*10465441SEvalZero * are permitted provided that the following conditions are met:
10*10465441SEvalZero *
11*10465441SEvalZero * 1. Redistributions of source code must retain the above copyright notice,
12*10465441SEvalZero * this list of conditions and the following disclaimer.
13*10465441SEvalZero * 2. Redistributions in binary form must reproduce the above copyright notice,
14*10465441SEvalZero * this list of conditions and the following disclaimer in the documentation
15*10465441SEvalZero * and/or other materials provided with the distribution.
16*10465441SEvalZero * 3. The name of the author may not be used to endorse or promote products
17*10465441SEvalZero * derived from this software without specific prior written permission.
18*10465441SEvalZero *
19*10465441SEvalZero * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
20*10465441SEvalZero * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21*10465441SEvalZero * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22*10465441SEvalZero * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23*10465441SEvalZero * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24*10465441SEvalZero * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*10465441SEvalZero * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*10465441SEvalZero * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27*10465441SEvalZero * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28*10465441SEvalZero * OF SUCH DAMAGE.
29*10465441SEvalZero *
30*10465441SEvalZero * This file is part of the lwIP TCP/IP stack.
31*10465441SEvalZero *
32*10465441SEvalZero */
33*10465441SEvalZero
34*10465441SEvalZero #include "netif/ppp/ppp_opts.h"
35*10465441SEvalZero
36*10465441SEvalZero #if LWIP_PPP_API /* don't build if not configured for use in lwipopts.h */
37*10465441SEvalZero
38*10465441SEvalZero #include "netif/ppp/pppapi.h"
39*10465441SEvalZero #include "lwip/priv/tcpip_priv.h"
40*10465441SEvalZero #include "netif/ppp/pppoe.h"
41*10465441SEvalZero #include "netif/ppp/pppol2tp.h"
42*10465441SEvalZero #include "netif/ppp/pppos.h"
43*10465441SEvalZero
44*10465441SEvalZero #if LWIP_MPU_COMPATIBLE
45*10465441SEvalZero LWIP_MEMPOOL_DECLARE(PPPAPI_MSG, MEMP_NUM_PPP_API_MSG, sizeof(struct pppapi_msg), "PPPAPI_MSG")
46*10465441SEvalZero #endif
47*10465441SEvalZero
48*10465441SEvalZero #define PPPAPI_VAR_REF(name) API_VAR_REF(name)
49*10465441SEvalZero #define PPPAPI_VAR_DECLARE(name) API_VAR_DECLARE(struct pppapi_msg, name)
50*10465441SEvalZero #define PPPAPI_VAR_ALLOC(name) API_VAR_ALLOC_POOL(struct pppapi_msg, PPPAPI_MSG, name, ERR_MEM)
51*10465441SEvalZero #define PPPAPI_VAR_ALLOC_RETURN_NULL(name) API_VAR_ALLOC_POOL(struct pppapi_msg, PPPAPI_MSG, name, NULL)
52*10465441SEvalZero #define PPPAPI_VAR_FREE(name) API_VAR_FREE_POOL(PPPAPI_MSG, name)
53*10465441SEvalZero
54*10465441SEvalZero /**
55*10465441SEvalZero * Call ppp_set_default() inside the tcpip_thread context.
56*10465441SEvalZero */
57*10465441SEvalZero static err_t
pppapi_do_ppp_set_default(struct tcpip_api_call_data * m)58*10465441SEvalZero pppapi_do_ppp_set_default(struct tcpip_api_call_data *m)
59*10465441SEvalZero {
60*10465441SEvalZero /* cast through void* to silence alignment warnings.
61*10465441SEvalZero * We know it works because the structs have been instantiated as struct pppapi_msg */
62*10465441SEvalZero struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
63*10465441SEvalZero
64*10465441SEvalZero ppp_set_default(msg->msg.ppp);
65*10465441SEvalZero return ERR_OK;
66*10465441SEvalZero }
67*10465441SEvalZero
68*10465441SEvalZero /**
69*10465441SEvalZero * Call ppp_set_default() in a thread-safe way by running that function inside the
70*10465441SEvalZero * tcpip_thread context.
71*10465441SEvalZero */
72*10465441SEvalZero err_t
pppapi_set_default(ppp_pcb * pcb)73*10465441SEvalZero pppapi_set_default(ppp_pcb *pcb)
74*10465441SEvalZero {
75*10465441SEvalZero err_t err;
76*10465441SEvalZero PPPAPI_VAR_DECLARE(msg);
77*10465441SEvalZero PPPAPI_VAR_ALLOC(msg);
78*10465441SEvalZero
79*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.ppp = pcb;
80*10465441SEvalZero err = tcpip_api_call(pppapi_do_ppp_set_default, &PPPAPI_VAR_REF(msg).call);
81*10465441SEvalZero PPPAPI_VAR_FREE(msg);
82*10465441SEvalZero return err;
83*10465441SEvalZero }
84*10465441SEvalZero
85*10465441SEvalZero
86*10465441SEvalZero #if PPP_NOTIFY_PHASE
87*10465441SEvalZero /**
88*10465441SEvalZero * Call ppp_set_notify_phase_callback() inside the tcpip_thread context.
89*10465441SEvalZero */
90*10465441SEvalZero static err_t
pppapi_do_ppp_set_notify_phase_callback(struct tcpip_api_call_data * m)91*10465441SEvalZero pppapi_do_ppp_set_notify_phase_callback(struct tcpip_api_call_data *m)
92*10465441SEvalZero {
93*10465441SEvalZero /* cast through void* to silence alignment warnings.
94*10465441SEvalZero * We know it works because the structs have been instantiated as struct pppapi_msg */
95*10465441SEvalZero struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
96*10465441SEvalZero
97*10465441SEvalZero ppp_set_notify_phase_callback(msg->msg.ppp, msg->msg.msg.setnotifyphasecb.notify_phase_cb);
98*10465441SEvalZero return ERR_OK;
99*10465441SEvalZero }
100*10465441SEvalZero
101*10465441SEvalZero /**
102*10465441SEvalZero * Call ppp_set_notify_phase_callback() in a thread-safe way by running that function inside the
103*10465441SEvalZero * tcpip_thread context.
104*10465441SEvalZero */
105*10465441SEvalZero err_t
pppapi_set_notify_phase_callback(ppp_pcb * pcb,ppp_notify_phase_cb_fn notify_phase_cb)106*10465441SEvalZero pppapi_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_phase_cb)
107*10465441SEvalZero {
108*10465441SEvalZero err_t err;
109*10465441SEvalZero PPPAPI_VAR_DECLARE(msg);
110*10465441SEvalZero PPPAPI_VAR_ALLOC(msg);
111*10465441SEvalZero
112*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.ppp = pcb;
113*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.setnotifyphasecb.notify_phase_cb = notify_phase_cb;
114*10465441SEvalZero err = tcpip_api_call(pppapi_do_ppp_set_notify_phase_callback, &PPPAPI_VAR_REF(msg).call);
115*10465441SEvalZero PPPAPI_VAR_FREE(msg);
116*10465441SEvalZero return err;
117*10465441SEvalZero }
118*10465441SEvalZero #endif /* PPP_NOTIFY_PHASE */
119*10465441SEvalZero
120*10465441SEvalZero
121*10465441SEvalZero #if PPPOS_SUPPORT
122*10465441SEvalZero /**
123*10465441SEvalZero * Call pppos_create() inside the tcpip_thread context.
124*10465441SEvalZero */
125*10465441SEvalZero static err_t
pppapi_do_pppos_create(struct tcpip_api_call_data * m)126*10465441SEvalZero pppapi_do_pppos_create(struct tcpip_api_call_data *m)
127*10465441SEvalZero {
128*10465441SEvalZero /* cast through void* to silence alignment warnings.
129*10465441SEvalZero * We know it works because the structs have been instantiated as struct pppapi_msg */
130*10465441SEvalZero struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
131*10465441SEvalZero
132*10465441SEvalZero msg->msg.ppp = pppos_create(msg->msg.msg.serialcreate.pppif, msg->msg.msg.serialcreate.output_cb,
133*10465441SEvalZero msg->msg.msg.serialcreate.link_status_cb, msg->msg.msg.serialcreate.ctx_cb);
134*10465441SEvalZero return ERR_OK;
135*10465441SEvalZero }
136*10465441SEvalZero
137*10465441SEvalZero /**
138*10465441SEvalZero * Call pppos_create() in a thread-safe way by running that function inside the
139*10465441SEvalZero * tcpip_thread context.
140*10465441SEvalZero */
141*10465441SEvalZero ppp_pcb*
pppapi_pppos_create(struct netif * pppif,pppos_output_cb_fn output_cb,ppp_link_status_cb_fn link_status_cb,void * ctx_cb)142*10465441SEvalZero pppapi_pppos_create(struct netif *pppif, pppos_output_cb_fn output_cb,
143*10465441SEvalZero ppp_link_status_cb_fn link_status_cb, void *ctx_cb)
144*10465441SEvalZero {
145*10465441SEvalZero ppp_pcb* result;
146*10465441SEvalZero PPPAPI_VAR_DECLARE(msg);
147*10465441SEvalZero PPPAPI_VAR_ALLOC_RETURN_NULL(msg);
148*10465441SEvalZero
149*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.ppp = NULL;
150*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.serialcreate.pppif = pppif;
151*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.serialcreate.output_cb = output_cb;
152*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.serialcreate.link_status_cb = link_status_cb;
153*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.serialcreate.ctx_cb = ctx_cb;
154*10465441SEvalZero tcpip_api_call(pppapi_do_pppos_create, &PPPAPI_VAR_REF(msg).call);
155*10465441SEvalZero result = PPPAPI_VAR_REF(msg).msg.ppp;
156*10465441SEvalZero PPPAPI_VAR_FREE(msg);
157*10465441SEvalZero return result;
158*10465441SEvalZero }
159*10465441SEvalZero #endif /* PPPOS_SUPPORT */
160*10465441SEvalZero
161*10465441SEvalZero
162*10465441SEvalZero #if PPPOE_SUPPORT
163*10465441SEvalZero /**
164*10465441SEvalZero * Call pppoe_create() inside the tcpip_thread context.
165*10465441SEvalZero */
166*10465441SEvalZero static err_t
pppapi_do_pppoe_create(struct tcpip_api_call_data * m)167*10465441SEvalZero pppapi_do_pppoe_create(struct tcpip_api_call_data *m)
168*10465441SEvalZero {
169*10465441SEvalZero /* cast through void* to silence alignment warnings.
170*10465441SEvalZero * We know it works because the structs have been instantiated as struct pppapi_msg */
171*10465441SEvalZero struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
172*10465441SEvalZero
173*10465441SEvalZero msg->msg.ppp = pppoe_create(msg->msg.msg.ethernetcreate.pppif, msg->msg.msg.ethernetcreate.ethif,
174*10465441SEvalZero msg->msg.msg.ethernetcreate.service_name, msg->msg.msg.ethernetcreate.concentrator_name,
175*10465441SEvalZero msg->msg.msg.ethernetcreate.link_status_cb, msg->msg.msg.ethernetcreate.ctx_cb);
176*10465441SEvalZero return ERR_OK;
177*10465441SEvalZero }
178*10465441SEvalZero
179*10465441SEvalZero /**
180*10465441SEvalZero * Call pppoe_create() in a thread-safe way by running that function inside the
181*10465441SEvalZero * tcpip_thread context.
182*10465441SEvalZero */
183*10465441SEvalZero ppp_pcb*
pppapi_pppoe_create(struct netif * pppif,struct netif * ethif,const char * service_name,const char * concentrator_name,ppp_link_status_cb_fn link_status_cb,void * ctx_cb)184*10465441SEvalZero pppapi_pppoe_create(struct netif *pppif, struct netif *ethif, const char *service_name,
185*10465441SEvalZero const char *concentrator_name, ppp_link_status_cb_fn link_status_cb,
186*10465441SEvalZero void *ctx_cb)
187*10465441SEvalZero {
188*10465441SEvalZero ppp_pcb* result;
189*10465441SEvalZero PPPAPI_VAR_DECLARE(msg);
190*10465441SEvalZero PPPAPI_VAR_ALLOC_RETURN_NULL(msg);
191*10465441SEvalZero
192*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.ppp = NULL;
193*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.pppif = pppif;
194*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.ethif = ethif;
195*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.service_name = service_name;
196*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.concentrator_name = concentrator_name;
197*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.link_status_cb = link_status_cb;
198*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.ctx_cb = ctx_cb;
199*10465441SEvalZero tcpip_api_call(pppapi_do_pppoe_create, &PPPAPI_VAR_REF(msg).call);
200*10465441SEvalZero result = PPPAPI_VAR_REF(msg).msg.ppp;
201*10465441SEvalZero PPPAPI_VAR_FREE(msg);
202*10465441SEvalZero return result;
203*10465441SEvalZero }
204*10465441SEvalZero #endif /* PPPOE_SUPPORT */
205*10465441SEvalZero
206*10465441SEvalZero
207*10465441SEvalZero #if PPPOL2TP_SUPPORT
208*10465441SEvalZero /**
209*10465441SEvalZero * Call pppol2tp_create() inside the tcpip_thread context.
210*10465441SEvalZero */
211*10465441SEvalZero static err_t
pppapi_do_pppol2tp_create(struct tcpip_api_call_data * m)212*10465441SEvalZero pppapi_do_pppol2tp_create(struct tcpip_api_call_data *m)
213*10465441SEvalZero {
214*10465441SEvalZero /* cast through void* to silence alignment warnings.
215*10465441SEvalZero * We know it works because the structs have been instantiated as struct pppapi_msg */
216*10465441SEvalZero struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
217*10465441SEvalZero
218*10465441SEvalZero msg->msg.ppp = pppol2tp_create(msg->msg.msg.l2tpcreate.pppif,
219*10465441SEvalZero msg->msg.msg.l2tpcreate.netif, API_EXPR_REF(msg->msg.msg.l2tpcreate.ipaddr), msg->msg.msg.l2tpcreate.port,
220*10465441SEvalZero #if PPPOL2TP_AUTH_SUPPORT
221*10465441SEvalZero msg->msg.msg.l2tpcreate.secret,
222*10465441SEvalZero msg->msg.msg.l2tpcreate.secret_len,
223*10465441SEvalZero #else /* PPPOL2TP_AUTH_SUPPORT */
224*10465441SEvalZero NULL,
225*10465441SEvalZero 0,
226*10465441SEvalZero #endif /* PPPOL2TP_AUTH_SUPPORT */
227*10465441SEvalZero msg->msg.msg.l2tpcreate.link_status_cb, msg->msg.msg.l2tpcreate.ctx_cb);
228*10465441SEvalZero return ERR_OK;
229*10465441SEvalZero }
230*10465441SEvalZero
231*10465441SEvalZero /**
232*10465441SEvalZero * Call pppol2tp_create() in a thread-safe way by running that function inside the
233*10465441SEvalZero * tcpip_thread context.
234*10465441SEvalZero */
235*10465441SEvalZero ppp_pcb*
pppapi_pppol2tp_create(struct netif * pppif,struct netif * netif,ip_addr_t * ipaddr,u16_t port,const u8_t * secret,u8_t secret_len,ppp_link_status_cb_fn link_status_cb,void * ctx_cb)236*10465441SEvalZero pppapi_pppol2tp_create(struct netif *pppif, struct netif *netif, ip_addr_t *ipaddr, u16_t port,
237*10465441SEvalZero const u8_t *secret, u8_t secret_len,
238*10465441SEvalZero ppp_link_status_cb_fn link_status_cb, void *ctx_cb)
239*10465441SEvalZero {
240*10465441SEvalZero ppp_pcb* result;
241*10465441SEvalZero PPPAPI_VAR_DECLARE(msg);
242*10465441SEvalZero PPPAPI_VAR_ALLOC_RETURN_NULL(msg);
243*10465441SEvalZero #if !PPPOL2TP_AUTH_SUPPORT
244*10465441SEvalZero LWIP_UNUSED_ARG(secret);
245*10465441SEvalZero LWIP_UNUSED_ARG(secret_len);
246*10465441SEvalZero #endif /* !PPPOL2TP_AUTH_SUPPORT */
247*10465441SEvalZero
248*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.ppp = NULL;
249*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.pppif = pppif;
250*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.netif = netif;
251*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.ipaddr = PPPAPI_VAR_REF(ipaddr);
252*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.port = port;
253*10465441SEvalZero #if PPPOL2TP_AUTH_SUPPORT
254*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.secret = secret;
255*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.secret_len = secret_len;
256*10465441SEvalZero #endif /* PPPOL2TP_AUTH_SUPPORT */
257*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.link_status_cb = link_status_cb;
258*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.ctx_cb = ctx_cb;
259*10465441SEvalZero tcpip_api_call(pppapi_do_pppol2tp_create, &PPPAPI_VAR_REF(msg).call);
260*10465441SEvalZero result = PPPAPI_VAR_REF(msg).msg.ppp;
261*10465441SEvalZero PPPAPI_VAR_FREE(msg);
262*10465441SEvalZero return result;
263*10465441SEvalZero }
264*10465441SEvalZero #endif /* PPPOL2TP_SUPPORT */
265*10465441SEvalZero
266*10465441SEvalZero
267*10465441SEvalZero /**
268*10465441SEvalZero * Call ppp_connect() inside the tcpip_thread context.
269*10465441SEvalZero */
270*10465441SEvalZero static err_t
pppapi_do_ppp_connect(struct tcpip_api_call_data * m)271*10465441SEvalZero pppapi_do_ppp_connect(struct tcpip_api_call_data *m)
272*10465441SEvalZero {
273*10465441SEvalZero /* cast through void* to silence alignment warnings.
274*10465441SEvalZero * We know it works because the structs have been instantiated as struct pppapi_msg */
275*10465441SEvalZero struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
276*10465441SEvalZero
277*10465441SEvalZero return ppp_connect(msg->msg.ppp, msg->msg.msg.connect.holdoff);
278*10465441SEvalZero }
279*10465441SEvalZero
280*10465441SEvalZero /**
281*10465441SEvalZero * Call ppp_connect() in a thread-safe way by running that function inside the
282*10465441SEvalZero * tcpip_thread context.
283*10465441SEvalZero */
284*10465441SEvalZero err_t
pppapi_connect(ppp_pcb * pcb,u16_t holdoff)285*10465441SEvalZero pppapi_connect(ppp_pcb *pcb, u16_t holdoff)
286*10465441SEvalZero {
287*10465441SEvalZero err_t err;
288*10465441SEvalZero PPPAPI_VAR_DECLARE(msg);
289*10465441SEvalZero PPPAPI_VAR_ALLOC(msg);
290*10465441SEvalZero
291*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.ppp = pcb;
292*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.connect.holdoff = holdoff;
293*10465441SEvalZero err = tcpip_api_call(pppapi_do_ppp_connect, &PPPAPI_VAR_REF(msg).call);
294*10465441SEvalZero PPPAPI_VAR_FREE(msg);
295*10465441SEvalZero return err;
296*10465441SEvalZero }
297*10465441SEvalZero
298*10465441SEvalZero
299*10465441SEvalZero #if PPP_SERVER
300*10465441SEvalZero /**
301*10465441SEvalZero * Call ppp_listen() inside the tcpip_thread context.
302*10465441SEvalZero */
303*10465441SEvalZero static err_t
pppapi_do_ppp_listen(struct tcpip_api_call_data * m)304*10465441SEvalZero pppapi_do_ppp_listen(struct tcpip_api_call_data *m)
305*10465441SEvalZero {
306*10465441SEvalZero /* cast through void* to silence alignment warnings.
307*10465441SEvalZero * We know it works because the structs have been instantiated as struct pppapi_msg */
308*10465441SEvalZero struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
309*10465441SEvalZero
310*10465441SEvalZero return ppp_listen(msg->msg.ppp);
311*10465441SEvalZero }
312*10465441SEvalZero
313*10465441SEvalZero /**
314*10465441SEvalZero * Call ppp_listen() in a thread-safe way by running that function inside the
315*10465441SEvalZero * tcpip_thread context.
316*10465441SEvalZero */
317*10465441SEvalZero err_t
pppapi_listen(ppp_pcb * pcb)318*10465441SEvalZero pppapi_listen(ppp_pcb *pcb)
319*10465441SEvalZero {
320*10465441SEvalZero err_t err;
321*10465441SEvalZero PPPAPI_VAR_DECLARE(msg);
322*10465441SEvalZero PPPAPI_VAR_ALLOC(msg);
323*10465441SEvalZero
324*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.ppp = pcb;
325*10465441SEvalZero err = tcpip_api_call(pppapi_do_ppp_listen, &PPPAPI_VAR_REF(msg).call);
326*10465441SEvalZero PPPAPI_VAR_FREE(msg);
327*10465441SEvalZero return err;
328*10465441SEvalZero }
329*10465441SEvalZero #endif /* PPP_SERVER */
330*10465441SEvalZero
331*10465441SEvalZero
332*10465441SEvalZero /**
333*10465441SEvalZero * Call ppp_close() inside the tcpip_thread context.
334*10465441SEvalZero */
335*10465441SEvalZero static err_t
pppapi_do_ppp_close(struct tcpip_api_call_data * m)336*10465441SEvalZero pppapi_do_ppp_close(struct tcpip_api_call_data *m)
337*10465441SEvalZero {
338*10465441SEvalZero /* cast through void* to silence alignment warnings.
339*10465441SEvalZero * We know it works because the structs have been instantiated as struct pppapi_msg */
340*10465441SEvalZero struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
341*10465441SEvalZero
342*10465441SEvalZero return ppp_close(msg->msg.ppp, msg->msg.msg.close.nocarrier);
343*10465441SEvalZero }
344*10465441SEvalZero
345*10465441SEvalZero /**
346*10465441SEvalZero * Call ppp_close() in a thread-safe way by running that function inside the
347*10465441SEvalZero * tcpip_thread context.
348*10465441SEvalZero */
349*10465441SEvalZero err_t
pppapi_close(ppp_pcb * pcb,u8_t nocarrier)350*10465441SEvalZero pppapi_close(ppp_pcb *pcb, u8_t nocarrier)
351*10465441SEvalZero {
352*10465441SEvalZero err_t err;
353*10465441SEvalZero PPPAPI_VAR_DECLARE(msg);
354*10465441SEvalZero PPPAPI_VAR_ALLOC(msg);
355*10465441SEvalZero
356*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.ppp = pcb;
357*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.close.nocarrier = nocarrier;
358*10465441SEvalZero err = tcpip_api_call(pppapi_do_ppp_close, &PPPAPI_VAR_REF(msg).call);
359*10465441SEvalZero PPPAPI_VAR_FREE(msg);
360*10465441SEvalZero return err;
361*10465441SEvalZero }
362*10465441SEvalZero
363*10465441SEvalZero
364*10465441SEvalZero /**
365*10465441SEvalZero * Call ppp_free() inside the tcpip_thread context.
366*10465441SEvalZero */
367*10465441SEvalZero static err_t
pppapi_do_ppp_free(struct tcpip_api_call_data * m)368*10465441SEvalZero pppapi_do_ppp_free(struct tcpip_api_call_data *m)
369*10465441SEvalZero {
370*10465441SEvalZero /* cast through void* to silence alignment warnings.
371*10465441SEvalZero * We know it works because the structs have been instantiated as struct pppapi_msg */
372*10465441SEvalZero struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
373*10465441SEvalZero
374*10465441SEvalZero return ppp_free(msg->msg.ppp);
375*10465441SEvalZero }
376*10465441SEvalZero
377*10465441SEvalZero /**
378*10465441SEvalZero * Call ppp_free() in a thread-safe way by running that function inside the
379*10465441SEvalZero * tcpip_thread context.
380*10465441SEvalZero */
381*10465441SEvalZero err_t
pppapi_free(ppp_pcb * pcb)382*10465441SEvalZero pppapi_free(ppp_pcb *pcb)
383*10465441SEvalZero {
384*10465441SEvalZero err_t err;
385*10465441SEvalZero PPPAPI_VAR_DECLARE(msg);
386*10465441SEvalZero PPPAPI_VAR_ALLOC(msg);
387*10465441SEvalZero
388*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.ppp = pcb;
389*10465441SEvalZero err = tcpip_api_call(pppapi_do_ppp_free, &PPPAPI_VAR_REF(msg).call);
390*10465441SEvalZero PPPAPI_VAR_FREE(msg);
391*10465441SEvalZero return err;
392*10465441SEvalZero }
393*10465441SEvalZero
394*10465441SEvalZero
395*10465441SEvalZero /**
396*10465441SEvalZero * Call ppp_ioctl() inside the tcpip_thread context.
397*10465441SEvalZero */
398*10465441SEvalZero static err_t
pppapi_do_ppp_ioctl(struct tcpip_api_call_data * m)399*10465441SEvalZero pppapi_do_ppp_ioctl(struct tcpip_api_call_data *m)
400*10465441SEvalZero {
401*10465441SEvalZero /* cast through void* to silence alignment warnings.
402*10465441SEvalZero * We know it works because the structs have been instantiated as struct pppapi_msg */
403*10465441SEvalZero struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
404*10465441SEvalZero
405*10465441SEvalZero return ppp_ioctl(msg->msg.ppp, msg->msg.msg.ioctl.cmd, msg->msg.msg.ioctl.arg);
406*10465441SEvalZero }
407*10465441SEvalZero
408*10465441SEvalZero /**
409*10465441SEvalZero * Call ppp_ioctl() in a thread-safe way by running that function inside the
410*10465441SEvalZero * tcpip_thread context.
411*10465441SEvalZero */
412*10465441SEvalZero err_t
pppapi_ioctl(ppp_pcb * pcb,u8_t cmd,void * arg)413*10465441SEvalZero pppapi_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg)
414*10465441SEvalZero {
415*10465441SEvalZero err_t err;
416*10465441SEvalZero PPPAPI_VAR_DECLARE(msg);
417*10465441SEvalZero PPPAPI_VAR_ALLOC(msg);
418*10465441SEvalZero
419*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.ppp = pcb;
420*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.ioctl.cmd = cmd;
421*10465441SEvalZero PPPAPI_VAR_REF(msg).msg.msg.ioctl.arg = arg;
422*10465441SEvalZero err = tcpip_api_call(pppapi_do_ppp_ioctl, &PPPAPI_VAR_REF(msg).call);
423*10465441SEvalZero PPPAPI_VAR_FREE(msg);
424*10465441SEvalZero return err;
425*10465441SEvalZero }
426*10465441SEvalZero
427*10465441SEvalZero #endif /* LWIP_PPP_API */
428