Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-os by
lwip_pppapi.c
00001 /** 00002 * @file 00003 * Point To Point Protocol Sequential API module 00004 * 00005 */ 00006 00007 /* 00008 * Redistribution and use in source and binary forms, with or without modification, 00009 * are permitted provided that the following conditions are met: 00010 * 00011 * 1. Redistributions of source code must retain the above copyright notice, 00012 * this list of conditions and the following disclaimer. 00013 * 2. Redistributions in binary form must reproduce the above copyright notice, 00014 * this list of conditions and the following disclaimer in the documentation 00015 * and/or other materials provided with the distribution. 00016 * 3. The name of the author may not be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00020 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00021 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00022 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00023 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00024 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00027 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00028 * OF SUCH DAMAGE. 00029 * 00030 * This file is part of the lwIP TCP/IP stack. 00031 * 00032 */ 00033 00034 #include "netif/ppp/ppp_opts.h" 00035 00036 #if LWIP_PPP_API /* don't build if not configured for use in lwipopts.h */ 00037 00038 #include "netif/ppp/pppapi.h" 00039 #include "lwip/priv/tcpip_priv.h" 00040 #include "netif/ppp/pppoe.h" 00041 #include "netif/ppp/pppol2tp.h" 00042 #include "netif/ppp/pppos.h" 00043 00044 #if LWIP_MPU_COMPATIBLE 00045 LWIP_MEMPOOL_DECLARE(PPPAPI_MSG, MEMP_NUM_PPP_API_MSG, sizeof(struct pppapi_msg), "PPPAPI_MSG") 00046 #endif 00047 00048 #define PPPAPI_VAR_REF(name) API_VAR_REF(name) 00049 #define PPPAPI_VAR_DECLARE(name) API_VAR_DECLARE(struct pppapi_msg, name) 00050 #define PPPAPI_VAR_ALLOC(name) API_VAR_ALLOC_POOL(struct pppapi_msg, PPPAPI_MSG, name, ERR_MEM) 00051 #define PPPAPI_VAR_ALLOC_RETURN_NULL(name) API_VAR_ALLOC_POOL(struct pppapi_msg, PPPAPI_MSG, name, NULL) 00052 #define PPPAPI_VAR_FREE(name) API_VAR_FREE_POOL(PPPAPI_MSG, name) 00053 00054 /** 00055 * Call ppp_set_default() inside the tcpip_thread context. 00056 */ 00057 static err_t 00058 pppapi_do_ppp_set_default(struct tcpip_api_call_data *m) 00059 { 00060 /* cast through void* to silence alignment warnings. 00061 * We know it works because the structs have been instantiated as struct pppapi_msg */ 00062 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m; 00063 00064 ppp_set_default(msg->msg.ppp); 00065 return ERR_OK; 00066 } 00067 00068 /** 00069 * Call ppp_set_default() in a thread-safe way by running that function inside the 00070 * tcpip_thread context. 00071 */ 00072 err_t 00073 pppapi_set_default(ppp_pcb *pcb) 00074 { 00075 err_t err; 00076 PPPAPI_VAR_DECLARE(msg); 00077 PPPAPI_VAR_ALLOC(msg); 00078 00079 PPPAPI_VAR_REF(msg).msg.ppp = pcb; 00080 err = tcpip_api_call(pppapi_do_ppp_set_default, &PPPAPI_VAR_REF(msg).call); 00081 PPPAPI_VAR_FREE(msg); 00082 return err; 00083 } 00084 00085 00086 #if PPP_NOTIFY_PHASE 00087 /** 00088 * Call ppp_set_notify_phase_callback() inside the tcpip_thread context. 00089 */ 00090 static err_t 00091 pppapi_do_ppp_set_notify_phase_callback(struct tcpip_api_call_data *m) 00092 { 00093 /* cast through void* to silence alignment warnings. 00094 * We know it works because the structs have been instantiated as struct pppapi_msg */ 00095 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m; 00096 00097 ppp_set_notify_phase_callback(msg->msg.ppp, msg->msg.msg.setnotifyphasecb.notify_phase_cb); 00098 return ERR_OK; 00099 } 00100 00101 /** 00102 * Call ppp_set_notify_phase_callback() in a thread-safe way by running that function inside the 00103 * tcpip_thread context. 00104 */ 00105 err_t 00106 pppapi_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_phase_cb) 00107 { 00108 err_t err; 00109 PPPAPI_VAR_DECLARE(msg); 00110 PPPAPI_VAR_ALLOC(msg); 00111 00112 PPPAPI_VAR_REF(msg).msg.ppp = pcb; 00113 PPPAPI_VAR_REF(msg).msg.msg.setnotifyphasecb.notify_phase_cb = notify_phase_cb; 00114 err = tcpip_api_call(pppapi_do_ppp_set_notify_phase_callback, &PPPAPI_VAR_REF(msg).call); 00115 PPPAPI_VAR_FREE(msg); 00116 return err; 00117 } 00118 #endif /* PPP_NOTIFY_PHASE */ 00119 00120 00121 #if PPPOS_SUPPORT 00122 /** 00123 * Call pppos_create() inside the tcpip_thread context. 00124 */ 00125 static err_t 00126 pppapi_do_pppos_create(struct tcpip_api_call_data *m) 00127 { 00128 /* cast through void* to silence alignment warnings. 00129 * We know it works because the structs have been instantiated as struct pppapi_msg */ 00130 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m; 00131 00132 msg->msg.ppp = pppos_create(msg->msg.msg.serialcreate.pppif, msg->msg.msg.serialcreate.output_cb, 00133 msg->msg.msg.serialcreate.link_status_cb, msg->msg.msg.serialcreate.ctx_cb); 00134 return ERR_OK; 00135 } 00136 00137 /** 00138 * Call pppos_create() in a thread-safe way by running that function inside the 00139 * tcpip_thread context. 00140 */ 00141 ppp_pcb* 00142 pppapi_pppos_create(struct netif *pppif, pppos_output_cb_fn output_cb, 00143 ppp_link_status_cb_fn link_status_cb, void *ctx_cb) 00144 { 00145 ppp_pcb* result; 00146 PPPAPI_VAR_DECLARE(msg); 00147 PPPAPI_VAR_ALLOC_RETURN_NULL(msg); 00148 00149 PPPAPI_VAR_REF(msg).msg.ppp = NULL; 00150 PPPAPI_VAR_REF(msg).msg.msg.serialcreate.pppif = pppif; 00151 PPPAPI_VAR_REF(msg).msg.msg.serialcreate.output_cb = output_cb; 00152 PPPAPI_VAR_REF(msg).msg.msg.serialcreate.link_status_cb = link_status_cb; 00153 PPPAPI_VAR_REF(msg).msg.msg.serialcreate.ctx_cb = ctx_cb; 00154 tcpip_api_call(pppapi_do_pppos_create, &PPPAPI_VAR_REF(msg).call); 00155 result = PPPAPI_VAR_REF(msg).msg.ppp; 00156 PPPAPI_VAR_FREE(msg); 00157 return result; 00158 } 00159 #endif /* PPPOS_SUPPORT */ 00160 00161 00162 #if PPPOE_SUPPORT 00163 /** 00164 * Call pppoe_create() inside the tcpip_thread context. 00165 */ 00166 static err_t 00167 pppapi_do_pppoe_create(struct tcpip_api_call_data *m) 00168 { 00169 /* cast through void* to silence alignment warnings. 00170 * We know it works because the structs have been instantiated as struct pppapi_msg */ 00171 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m; 00172 00173 msg->msg.ppp = pppoe_create(msg->msg.msg.ethernetcreate.pppif, msg->msg.msg.ethernetcreate.ethif, 00174 msg->msg.msg.ethernetcreate.service_name, msg->msg.msg.ethernetcreate.concentrator_name, 00175 msg->msg.msg.ethernetcreate.link_status_cb, msg->msg.msg.ethernetcreate.ctx_cb); 00176 return ERR_OK; 00177 } 00178 00179 /** 00180 * Call pppoe_create() in a thread-safe way by running that function inside the 00181 * tcpip_thread context. 00182 */ 00183 ppp_pcb* 00184 pppapi_pppoe_create(struct netif *pppif, struct netif *ethif, const char *service_name, 00185 const char *concentrator_name, ppp_link_status_cb_fn link_status_cb, 00186 void *ctx_cb) 00187 { 00188 ppp_pcb* result; 00189 PPPAPI_VAR_DECLARE(msg); 00190 PPPAPI_VAR_ALLOC_RETURN_NULL(msg); 00191 00192 PPPAPI_VAR_REF(msg).msg.ppp = NULL; 00193 PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.pppif = pppif; 00194 PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.ethif = ethif; 00195 PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.service_name = service_name; 00196 PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.concentrator_name = concentrator_name; 00197 PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.link_status_cb = link_status_cb; 00198 PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.ctx_cb = ctx_cb; 00199 tcpip_api_call(pppapi_do_pppoe_create, &PPPAPI_VAR_REF(msg).call); 00200 result = PPPAPI_VAR_REF(msg).msg.ppp; 00201 PPPAPI_VAR_FREE(msg); 00202 return result; 00203 } 00204 #endif /* PPPOE_SUPPORT */ 00205 00206 00207 #if PPPOL2TP_SUPPORT 00208 /** 00209 * Call pppol2tp_create() inside the tcpip_thread context. 00210 */ 00211 static err_t 00212 pppapi_do_pppol2tp_create(struct tcpip_api_call_data *m) 00213 { 00214 /* cast through void* to silence alignment warnings. 00215 * We know it works because the structs have been instantiated as struct pppapi_msg */ 00216 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m; 00217 00218 msg->msg.ppp = pppol2tp_create(msg->msg.msg.l2tpcreate.pppif, 00219 msg->msg.msg.l2tpcreate.netif, API_EXPR_REF(msg->msg.msg.l2tpcreate.ipaddr), msg->msg.msg.l2tpcreate.port, 00220 #if PPPOL2TP_AUTH_SUPPORT 00221 msg->msg.msg.l2tpcreate.secret, 00222 msg->msg.msg.l2tpcreate.secret_len, 00223 #else /* PPPOL2TP_AUTH_SUPPORT */ 00224 NULL, 00225 #endif /* PPPOL2TP_AUTH_SUPPORT */ 00226 msg->msg.msg.l2tpcreate.link_status_cb, msg->msg.msg.l2tpcreate.ctx_cb); 00227 return ERR_OK; 00228 } 00229 00230 /** 00231 * Call pppol2tp_create() in a thread-safe way by running that function inside the 00232 * tcpip_thread context. 00233 */ 00234 ppp_pcb* 00235 pppapi_pppol2tp_create(struct netif *pppif, struct netif *netif, ip_addr_t *ipaddr, u16_t port, 00236 const u8_t *secret, u8_t secret_len, 00237 ppp_link_status_cb_fn link_status_cb, void *ctx_cb) 00238 { 00239 ppp_pcb* result; 00240 PPPAPI_VAR_DECLARE(msg); 00241 PPPAPI_VAR_ALLOC_RETURN_NULL(msg); 00242 00243 PPPAPI_VAR_REF(msg).msg.ppp = NULL; 00244 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.pppif = pppif; 00245 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.netif = netif; 00246 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.ipaddr = PPPAPI_VAR_REF(ipaddr); 00247 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.port = port; 00248 #if PPPOL2TP_AUTH_SUPPORT 00249 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.secret = secret; 00250 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.secret_len = secret_len; 00251 #endif /* PPPOL2TP_AUTH_SUPPORT */ 00252 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.link_status_cb = link_status_cb; 00253 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.ctx_cb = ctx_cb; 00254 tcpip_api_call(pppapi_do_pppol2tp_create, &PPPAPI_VAR_REF(msg).call); 00255 result = PPPAPI_VAR_REF(msg).msg.ppp; 00256 PPPAPI_VAR_FREE(msg); 00257 return result; 00258 } 00259 #endif /* PPPOL2TP_SUPPORT */ 00260 00261 00262 /** 00263 * Call ppp_connect() inside the tcpip_thread context. 00264 */ 00265 static err_t 00266 pppapi_do_ppp_connect(struct tcpip_api_call_data *m) 00267 { 00268 /* cast through void* to silence alignment warnings. 00269 * We know it works because the structs have been instantiated as struct pppapi_msg */ 00270 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m; 00271 00272 return ppp_connect(msg->msg.ppp, msg->msg.msg.connect.holdoff); 00273 } 00274 00275 /** 00276 * Call ppp_connect() in a thread-safe way by running that function inside the 00277 * tcpip_thread context. 00278 */ 00279 err_t 00280 pppapi_connect(ppp_pcb *pcb, u16_t holdoff) 00281 { 00282 err_t err; 00283 PPPAPI_VAR_DECLARE(msg); 00284 PPPAPI_VAR_ALLOC(msg); 00285 00286 PPPAPI_VAR_REF(msg).msg.ppp = pcb; 00287 PPPAPI_VAR_REF(msg).msg.msg.connect.holdoff = holdoff; 00288 err = tcpip_api_call(pppapi_do_ppp_connect, &PPPAPI_VAR_REF(msg).call); 00289 PPPAPI_VAR_FREE(msg); 00290 return err; 00291 } 00292 00293 00294 #if PPP_SERVER 00295 /** 00296 * Call ppp_listen() inside the tcpip_thread context. 00297 */ 00298 static err_t 00299 pppapi_do_ppp_listen(struct tcpip_api_call_data *m) 00300 { 00301 /* cast through void* to silence alignment warnings. 00302 * We know it works because the structs have been instantiated as struct pppapi_msg */ 00303 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m; 00304 00305 return ppp_listen(msg->msg.ppp); 00306 } 00307 00308 /** 00309 * Call ppp_listen() in a thread-safe way by running that function inside the 00310 * tcpip_thread context. 00311 */ 00312 err_t 00313 pppapi_listen(ppp_pcb *pcb) 00314 { 00315 err_t err; 00316 PPPAPI_VAR_DECLARE(msg); 00317 PPPAPI_VAR_ALLOC(msg); 00318 00319 PPPAPI_VAR_REF(msg).msg.ppp = pcb; 00320 err = tcpip_api_call(pppapi_do_ppp_listen, &PPPAPI_VAR_REF(msg).call); 00321 PPPAPI_VAR_FREE(msg); 00322 return err; 00323 } 00324 #endif /* PPP_SERVER */ 00325 00326 00327 /** 00328 * Call ppp_close() inside the tcpip_thread context. 00329 */ 00330 static err_t 00331 pppapi_do_ppp_close(struct tcpip_api_call_data *m) 00332 { 00333 /* cast through void* to silence alignment warnings. 00334 * We know it works because the structs have been instantiated as struct pppapi_msg */ 00335 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m; 00336 00337 return ppp_close(msg->msg.ppp, msg->msg.msg.close.nocarrier); 00338 } 00339 00340 /** 00341 * Call ppp_close() in a thread-safe way by running that function inside the 00342 * tcpip_thread context. 00343 */ 00344 err_t 00345 pppapi_close(ppp_pcb *pcb, u8_t nocarrier) 00346 { 00347 err_t err; 00348 PPPAPI_VAR_DECLARE(msg); 00349 PPPAPI_VAR_ALLOC(msg); 00350 00351 PPPAPI_VAR_REF(msg).msg.ppp = pcb; 00352 PPPAPI_VAR_REF(msg).msg.msg.close.nocarrier = nocarrier; 00353 err = tcpip_api_call(pppapi_do_ppp_close, &PPPAPI_VAR_REF(msg).call); 00354 PPPAPI_VAR_FREE(msg); 00355 return err; 00356 } 00357 00358 00359 /** 00360 * Call ppp_free() inside the tcpip_thread context. 00361 */ 00362 static err_t 00363 pppapi_do_ppp_free(struct tcpip_api_call_data *m) 00364 { 00365 /* cast through void* to silence alignment warnings. 00366 * We know it works because the structs have been instantiated as struct pppapi_msg */ 00367 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m; 00368 00369 return ppp_free(msg->msg.ppp); 00370 } 00371 00372 /** 00373 * Call ppp_free() in a thread-safe way by running that function inside the 00374 * tcpip_thread context. 00375 */ 00376 err_t 00377 pppapi_free(ppp_pcb *pcb) 00378 { 00379 err_t err; 00380 PPPAPI_VAR_DECLARE(msg); 00381 PPPAPI_VAR_ALLOC(msg); 00382 00383 PPPAPI_VAR_REF(msg).msg.ppp = pcb; 00384 err = tcpip_api_call(pppapi_do_ppp_free, &PPPAPI_VAR_REF(msg).call); 00385 PPPAPI_VAR_FREE(msg); 00386 return err; 00387 } 00388 00389 00390 /** 00391 * Call ppp_ioctl() inside the tcpip_thread context. 00392 */ 00393 static err_t 00394 pppapi_do_ppp_ioctl(struct tcpip_api_call_data *m) 00395 { 00396 /* cast through void* to silence alignment warnings. 00397 * We know it works because the structs have been instantiated as struct pppapi_msg */ 00398 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m; 00399 00400 return ppp_ioctl(msg->msg.ppp, msg->msg.msg.ioctl.cmd, msg->msg.msg.ioctl.arg); 00401 } 00402 00403 /** 00404 * Call ppp_ioctl() in a thread-safe way by running that function inside the 00405 * tcpip_thread context. 00406 */ 00407 err_t 00408 pppapi_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg) 00409 { 00410 err_t err; 00411 PPPAPI_VAR_DECLARE(msg); 00412 PPPAPI_VAR_ALLOC(msg); 00413 00414 PPPAPI_VAR_REF(msg).msg.ppp = pcb; 00415 PPPAPI_VAR_REF(msg).msg.msg.ioctl.cmd = cmd; 00416 PPPAPI_VAR_REF(msg).msg.msg.ioctl.arg = arg; 00417 err = tcpip_api_call(pppapi_do_ppp_ioctl, &PPPAPI_VAR_REF(msg).call); 00418 PPPAPI_VAR_FREE(msg); 00419 return err; 00420 } 00421 00422 #endif /* LWIP_PPP_API */
Generated on Tue Jul 12 2022 13:15:54 by
