STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
pppapi.c
Go to the documentation of this file.
1 
7 /*
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  * derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
20  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28  * OF SUCH DAMAGE.
29  *
30  * This file is part of the lwIP TCP/IP stack.
31  *
32  */
33 
34 #include "lwip/opt.h"
35 
36 #if LWIP_PPP_API /* don't build if not configured for use in lwipopts.h */
37 
38 #include "lwip/pppapi.h"
39 #include "lwip/priv/tcpip_priv.h"
40 #include "netif/ppp/pppoe.h"
41 #include "netif/ppp/pppol2tp.h"
42 #include "netif/ppp/pppos.h"
43 
47 static void
48 pppapi_do_ppp_set_default(struct pppapi_msg_msg *msg)
49 {
50  ppp_set_default(msg->ppp);
51  TCPIP_PPPAPI_ACK(msg);
52 }
53 
58 void
59 pppapi_set_default(ppp_pcb *pcb)
60 {
61  struct pppapi_msg msg;
62  msg.function = pppapi_do_ppp_set_default;
63  msg.msg.ppp = pcb;
64  TCPIP_PPPAPI(&msg);
65 }
66 
67 
71 static void
72 pppapi_do_ppp_set_auth(struct pppapi_msg_msg *msg)
73 {
74  ppp_set_auth(msg->ppp, msg->msg.setauth.authtype,
75  msg->msg.setauth.user, msg->msg.setauth.passwd);
76  TCPIP_PPPAPI_ACK(msg);
77 }
78 
83 void
84 pppapi_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *passwd)
85 {
86  struct pppapi_msg msg;
87  msg.function = pppapi_do_ppp_set_auth;
88  msg.msg.ppp = pcb;
89  msg.msg.msg.setauth.authtype = authtype;
90  msg.msg.msg.setauth.user = user;
91  msg.msg.msg.setauth.passwd = passwd;
92  TCPIP_PPPAPI(&msg);
93 }
94 
95 
96 #if PPP_NOTIFY_PHASE
97 
100 static void
101 pppapi_do_ppp_set_notify_phase_callback(struct pppapi_msg_msg *msg)
102 {
103  ppp_set_notify_phase_callback(msg->ppp, msg->msg.setnotifyphasecb.notify_phase_cb);
104  TCPIP_PPPAPI_ACK(msg);
105 }
106 
111 void
112 pppapi_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_phase_cb)
113 {
114  struct pppapi_msg msg;
115  msg.function = pppapi_do_ppp_set_notify_phase_callback;
116  msg.msg.ppp = pcb;
117  msg.msg.msg.setnotifyphasecb.notify_phase_cb = notify_phase_cb;
118  TCPIP_PPPAPI(&msg);
119 }
120 #endif /* PPP_NOTIFY_PHASE */
121 
122 
123 #if PPPOS_SUPPORT
124 
127 static void
128 pppapi_do_pppos_create(struct pppapi_msg_msg *msg)
129 {
130  msg->ppp = pppos_create(msg->msg.serialcreate.pppif, msg->msg.serialcreate.output_cb,
131  msg->msg.serialcreate.link_status_cb, msg->msg.serialcreate.ctx_cb);
132  TCPIP_PPPAPI_ACK(msg);
133 }
134 
139 ppp_pcb*
140 pppapi_pppos_create(struct netif *pppif, pppos_output_cb_fn output_cb,
141  ppp_link_status_cb_fn link_status_cb, void *ctx_cb)
142 {
143  struct pppapi_msg msg;
144  msg.function = pppapi_do_pppos_create;
145  msg.msg.msg.serialcreate.pppif = pppif;
146  msg.msg.msg.serialcreate.output_cb = output_cb;
147  msg.msg.msg.serialcreate.link_status_cb = link_status_cb;
148  msg.msg.msg.serialcreate.ctx_cb = ctx_cb;
149  TCPIP_PPPAPI(&msg);
150  return msg.msg.ppp;
151 }
152 #endif /* PPPOS_SUPPORT */
153 
154 
155 #if PPPOE_SUPPORT
156 
159 static void
160 pppapi_do_pppoe_create(struct pppapi_msg_msg *msg)
161 {
162 
163  msg->ppp = pppoe_create(msg->msg.ethernetcreate.pppif, msg->msg.ethernetcreate.ethif,
164  msg->msg.ethernetcreate.service_name, msg->msg.ethernetcreate.concentrator_name,
165  msg->msg.ethernetcreate.link_status_cb, msg->msg.ethernetcreate.ctx_cb);
166  TCPIP_PPPAPI_ACK(msg);
167 }
168 
173 ppp_pcb*
174 pppapi_pppoe_create(struct netif *pppif, struct netif *ethif, const char *service_name,
175  const char *concentrator_name, ppp_link_status_cb_fn link_status_cb,
176  void *ctx_cb)
177 {
178  struct pppapi_msg msg;
179  msg.function = pppapi_do_pppoe_create;
180  msg.msg.msg.ethernetcreate.pppif = pppif;
181  msg.msg.msg.ethernetcreate.ethif = ethif;
182  msg.msg.msg.ethernetcreate.service_name = service_name;
183  msg.msg.msg.ethernetcreate.concentrator_name = concentrator_name;
184  msg.msg.msg.ethernetcreate.link_status_cb = link_status_cb;
185  msg.msg.msg.ethernetcreate.ctx_cb = ctx_cb;
186  TCPIP_PPPAPI(&msg);
187  return msg.msg.ppp;
188 }
189 #endif /* PPPOE_SUPPORT */
190 
191 
192 #if PPPOL2TP_SUPPORT
193 
196 static void
197 pppapi_do_pppol2tp_create(struct pppapi_msg_msg *msg)
198 {
199  msg->ppp = pppol2tp_create(msg->msg.l2tpcreate.pppif,
200  msg->msg.l2tpcreate.netif, msg->msg.l2tpcreate.ipaddr, msg->msg.l2tpcreate.port,
202  msg->msg.l2tpcreate.secret,
203  msg->msg.l2tpcreate.secret_len,
204 #else /* PPPOL2TP_AUTH_SUPPORT */
205  NULL,
206 #endif /* PPPOL2TP_AUTH_SUPPORT */
207  msg->msg.l2tpcreate.link_status_cb, msg->msg.l2tpcreate.ctx_cb);
208  TCPIP_PPPAPI_ACK(msg);
209 }
210 
215 ppp_pcb*
216 pppapi_pppol2tp_create(struct netif *pppif, struct netif *netif, ip_addr_t *ipaddr, u16_t port,
217  const u8_t *secret, u8_t secret_len,
218  ppp_link_status_cb_fn link_status_cb, void *ctx_cb)
219 {
220  struct pppapi_msg msg;
221  msg.function = pppapi_do_pppol2tp_create;
222  msg.msg.msg.l2tpcreate.pppif = pppif;
223  msg.msg.msg.l2tpcreate.netif = netif;
224  msg.msg.msg.l2tpcreate.ipaddr = ipaddr;
225  msg.msg.msg.l2tpcreate.port = port;
226 #if PPPOL2TP_AUTH_SUPPORT
227  msg.msg.msg.l2tpcreate.secret = secret;
228  msg.msg.msg.l2tpcreate.secret_len = secret_len;
229 #endif /* PPPOL2TP_AUTH_SUPPORT */
230  msg.msg.msg.l2tpcreate.link_status_cb = link_status_cb;
231  msg.msg.msg.l2tpcreate.ctx_cb = ctx_cb;
232  TCPIP_PPPAPI(&msg);
233  return msg.msg.ppp;
234 }
235 #endif /* PPPOL2TP_SUPPORT */
236 
237 
241 static void
242 pppapi_do_ppp_connect(struct pppapi_msg_msg *msg)
243 {
244  msg->err = ppp_connect(msg->ppp, msg->msg.connect.holdoff);
245  TCPIP_PPPAPI_ACK(msg);
246 }
247 
252 err_t
253 pppapi_connect(ppp_pcb *pcb, u16_t holdoff)
254 {
255  struct pppapi_msg msg;
256  msg.function = pppapi_do_ppp_connect;
257  msg.msg.ppp = pcb;
258  msg.msg.msg.connect.holdoff = holdoff;
259  TCPIP_PPPAPI(&msg);
260  return msg.msg.err;
261 }
262 
263 
264 #if PPP_SERVER
265 
268 static void
269 pppapi_do_ppp_listen(struct pppapi_msg_msg *msg)
270 {
271  msg->err = ppp_listen(msg->ppp, msg->msg.listen.addrs);
272  TCPIP_PPPAPI_ACK(msg);
273 }
274 
279 err_t
280 pppapi_listen(ppp_pcb *pcb, struct ppp_addrs *addrs)
281 {
282  struct pppapi_msg msg;
283  msg.function = pppapi_do_ppp_listen;
284  msg.msg.ppp = pcb;
285  msg.msg.msg.listen.addrs = addrs;
286  TCPIP_PPPAPI(&msg);
287  return msg.msg.err;
288 }
289 #endif /* PPP_SERVER */
290 
291 
295 static void
296 pppapi_do_ppp_close(struct pppapi_msg_msg *msg)
297 {
298  msg->err = ppp_close(msg->ppp, msg->msg.close.nocarrier);
299  TCPIP_PPPAPI_ACK(msg);
300 }
301 
306 err_t
307 pppapi_close(ppp_pcb *pcb, u8_t nocarrier)
308 {
309  struct pppapi_msg msg;
310  msg.function = pppapi_do_ppp_close;
311  msg.msg.ppp = pcb;
312  msg.msg.msg.close.nocarrier = nocarrier;
313  TCPIP_PPPAPI(&msg);
314  return msg.msg.err;
315 }
316 
317 
321 static void
322 pppapi_do_ppp_free(struct pppapi_msg_msg *msg)
323 {
324  msg->err = ppp_free(msg->ppp);
325  TCPIP_PPPAPI_ACK(msg);
326 }
327 
332 err_t
333 pppapi_free(ppp_pcb *pcb)
334 {
335  struct pppapi_msg msg;
336  msg.function = pppapi_do_ppp_free;
337  msg.msg.ppp = pcb;
338  TCPIP_PPPAPI(&msg);
339  return msg.msg.err;
340 }
341 
342 
346 static void
347 pppapi_do_ppp_ioctl(struct pppapi_msg_msg *msg)
348 {
349  msg->err = ppp_ioctl(msg->ppp, msg->msg.ioctl.cmd, msg->msg.ioctl.arg);
350  TCPIP_PPPAPI_ACK(msg);
351 }
352 
357 err_t
358 pppapi_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg)
359 {
360  struct pppapi_msg msg;
361  msg.function = pppapi_do_ppp_ioctl;
362  msg.msg.ppp = pcb;
363  msg.msg.msg.ioctl.cmd = cmd;
364  msg.msg.msg.ioctl.arg = arg;
365  TCPIP_PPPAPI(&msg);
366  return msg.msg.err;
367 }
368 
369 
370 #endif /* LWIP_PPP_API */
371 
#define TCPIP_PPPAPI_ACK(m)
Definition: tcpip_priv.h:99
#define PPPOL2TP_AUTH_SUPPORT
Definition: opt.h:1860
#define NULL
Definition: usbd_def.h:53
s8_t err_t
Definition: err.h:47
Definition: netif.h:182
unsigned char u8_t
Definition: cc.h:38
ip6_addr_t ip_addr_t
Definition: ip_addr.h:194
#define TCPIP_PPPAPI(m)
Definition: tcpip_priv.h:98
unsigned short u16_t
Definition: cc.h:40