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.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
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 "ppp_opts.h" 00035 00036 #if PPP_API 00037 00038 #include "pppapi.h" 00039 #include "pppoe.h" 00040 #include "pppol2tp.h" 00041 #include "pppos.h" 00042 00043 #if PPP_MPU_COMPATIBLE 00044 PPP_MEMPOOL_DECLARE(PPPAPI_MSG, MEMP_NUM_PPP_API_MSG, sizeof(struct pppapi_msg), "PPPAPI_MSG") 00045 #endif 00046 00047 #define PPPAPI_VAR_REF(name) API_VAR_REF(name) 00048 #define PPPAPI_VAR_DECLARE(name) API_VAR_DECLARE(struct pppapi_msg, name) 00049 #define PPPAPI_VAR_ALLOC(name) API_VAR_ALLOC_POOL(struct pppapi_msg, PPPAPI_MSG, name, ERR_MEM) 00050 #define PPPAPI_VAR_ALLOC_RETURN_NULL(name) API_VAR_ALLOC_POOL(struct pppapi_msg, PPPAPI_MSG, name, NULL) 00051 #define PPPAPI_VAR_FREE(name) API_VAR_FREE_POOL(PPPAPI_MSG, name) 00052 00053 /** 00054 * Call ppp_set_default() inside the tcpip_thread context. 00055 */ 00056 static err_t 00057 pppapi_do_ppp_set_default(struct tcpip_api_call_data *m) 00058 { 00059 /* cast through void* to silence alignment warnings. 00060 * We know it works because the structs have been instantiated as struct pppapi_msg */ 00061 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m; 00062 00063 ppp_set_default(msg->msg.ppp); 00064 return ERR_OK; 00065 } 00066 00067 /** 00068 * Call ppp_set_default() in a thread-safe way by running that function inside the 00069 * tcpip_thread context. 00070 */ 00071 err_t 00072 pppapi_set_default(ppp_pcb *pcb) 00073 { 00074 err_t err; 00075 PPPAPI_VAR_DECLARE(msg); 00076 PPPAPI_VAR_ALLOC(msg); 00077 00078 PPPAPI_VAR_REF(msg).msg.ppp = pcb; 00079 err = tcpip_api_call(pppapi_do_ppp_set_default, &PPPAPI_VAR_REF(msg).call); 00080 PPPAPI_VAR_FREE(msg); 00081 return err; 00082 } 00083 00084 00085 #if PPP_NOTIFY_PHASE 00086 /** 00087 * Call ppp_set_notify_phase_callback() inside the tcpip_thread context. 00088 */ 00089 static err_t 00090 pppapi_do_ppp_set_notify_phase_callback(struct tcpip_api_call_data *m) 00091 { 00092 /* cast through void* to silence alignment warnings. 00093 * We know it works because the structs have been instantiated as struct pppapi_msg */ 00094 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m; 00095 00096 ppp_set_notify_phase_callback(msg->msg.ppp, msg->msg.msg.setnotifyphasecb.notify_phase_cb); 00097 return ERR_OK; 00098 } 00099 00100 /** 00101 * Call ppp_set_notify_phase_callback() in a thread-safe way by running that function inside the 00102 * tcpip_thread context. 00103 */ 00104 err_t 00105 pppapi_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_phase_cb) 00106 { 00107 err_t err; 00108 PPPAPI_VAR_DECLARE(msg); 00109 PPPAPI_VAR_ALLOC(msg); 00110 00111 PPPAPI_VAR_REF(msg).msg.ppp = pcb; 00112 PPPAPI_VAR_REF(msg).msg.msg.setnotifyphasecb.notify_phase_cb = notify_phase_cb; 00113 err = tcpip_api_call(pppapi_do_ppp_set_notify_phase_callback, &PPPAPI_VAR_REF(msg).call); 00114 PPPAPI_VAR_FREE(msg); 00115 return err; 00116 } 00117 #endif /* PPP_NOTIFY_PHASE */ 00118 00119 00120 #if PPPOS_SUPPORT 00121 /** 00122 * Call pppos_create() inside the tcpip_thread context. 00123 */ 00124 static err_t 00125 pppapi_do_pppos_create(struct tcpip_api_call_data *m) 00126 { 00127 /* cast through void* to silence alignment warnings. 00128 * We know it works because the structs have been instantiated as struct pppapi_msg */ 00129 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m; 00130 00131 msg->msg.ppp = pppos_create(msg->msg.msg.serialcreate.pppif, msg->msg.msg.serialcreate.output_cb, 00132 msg->msg.msg.serialcreate.link_status_cb, msg->msg.msg.serialcreate.ctx_cb); 00133 return ERR_OK; 00134 } 00135 00136 /** 00137 * Call pppos_create() in a thread-safe way by running that function inside the 00138 * tcpip_thread context. 00139 */ 00140 ppp_pcb* 00141 pppapi_pppos_create(struct netif *pppif, pppos_output_cb_fn output_cb, 00142 ppp_link_status_cb_fn link_status_cb, void *ctx_cb) 00143 { 00144 ppp_pcb* result; 00145 PPPAPI_VAR_DECLARE(msg); 00146 PPPAPI_VAR_ALLOC_RETURN_NULL(msg); 00147 00148 PPPAPI_VAR_REF(msg).msg.ppp = NULL; 00149 PPPAPI_VAR_REF(msg).msg.msg.serialcreate.pppif = pppif; 00150 PPPAPI_VAR_REF(msg).msg.msg.serialcreate.output_cb = output_cb; 00151 PPPAPI_VAR_REF(msg).msg.msg.serialcreate.link_status_cb = link_status_cb; 00152 PPPAPI_VAR_REF(msg).msg.msg.serialcreate.ctx_cb = ctx_cb; 00153 tcpip_api_call(pppapi_do_pppos_create, &PPPAPI_VAR_REF(msg).call); 00154 result = PPPAPI_VAR_REF(msg).msg.ppp; 00155 PPPAPI_VAR_FREE(msg); 00156 return result; 00157 } 00158 #endif /* PPPOS_SUPPORT */ 00159 00160 00161 #if PPPOE_SUPPORT 00162 /** 00163 * Call pppoe_create() inside the tcpip_thread context. 00164 */ 00165 static err_t 00166 pppapi_do_pppoe_create(struct tcpip_api_call_data *m) 00167 { 00168 /* cast through void* to silence alignment warnings. 00169 * We know it works because the structs have been instantiated as struct pppapi_msg */ 00170 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m; 00171 00172 msg->msg.ppp = pppoe_create(msg->msg.msg.ethernetcreate.pppif, msg->msg.msg.ethernetcreate.ethif, 00173 msg->msg.msg.ethernetcreate.service_name, msg->msg.msg.ethernetcreate.concentrator_name, 00174 msg->msg.msg.ethernetcreate.link_status_cb, msg->msg.msg.ethernetcreate.ctx_cb); 00175 return ERR_OK; 00176 } 00177 00178 /** 00179 * Call pppoe_create() in a thread-safe way by running that function inside the 00180 * tcpip_thread context. 00181 */ 00182 ppp_pcb* 00183 pppapi_pppoe_create(struct netif *pppif, struct netif *ethif, const char *service_name, 00184 const char *concentrator_name, ppp_link_status_cb_fn link_status_cb, 00185 void *ctx_cb) 00186 { 00187 ppp_pcb* result; 00188 PPPAPI_VAR_DECLARE(msg); 00189 PPPAPI_VAR_ALLOC_RETURN_NULL(msg); 00190 00191 PPPAPI_VAR_REF(msg).msg.ppp = NULL; 00192 PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.pppif = pppif; 00193 PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.ethif = ethif; 00194 PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.service_name = service_name; 00195 PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.concentrator_name = concentrator_name; 00196 PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.link_status_cb = link_status_cb; 00197 PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.ctx_cb = ctx_cb; 00198 tcpip_api_call(pppapi_do_pppoe_create, &PPPAPI_VAR_REF(msg).call); 00199 result = PPPAPI_VAR_REF(msg).msg.ppp; 00200 PPPAPI_VAR_FREE(msg); 00201 return result; 00202 } 00203 #endif /* PPPOE_SUPPORT */ 00204 00205 00206 #if PPPOL2TP_SUPPORT 00207 /** 00208 * Call pppol2tp_create() inside the tcpip_thread context. 00209 */ 00210 static err_t 00211 pppapi_do_pppol2tp_create(struct tcpip_api_call_data *m) 00212 { 00213 /* cast through void* to silence alignment warnings. 00214 * We know it works because the structs have been instantiated as struct pppapi_msg */ 00215 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m; 00216 00217 msg->msg.ppp = pppol2tp_create(msg->msg.msg.l2tpcreate.pppif, 00218 msg->msg.msg.l2tpcreate.netif, API_EXPR_REF(msg->msg.msg.l2tpcreate.ipaddr), msg->msg.msg.l2tpcreate.port, 00219 #if PPPOL2TP_AUTH_SUPPORT 00220 msg->msg.msg.l2tpcreate.secret, 00221 msg->msg.msg.l2tpcreate.secret_len, 00222 #else /* PPPOL2TP_AUTH_SUPPORT */ 00223 NULL, 00224 0, 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 #if !PPPOL2TP_AUTH_SUPPORT 00243 PPP_UNUSED_ARG(secret); 00244 PPP_UNUSED_ARG(secret_len); 00245 #endif /* !PPPOL2TP_AUTH_SUPPORT */ 00246 00247 PPPAPI_VAR_REF(msg).msg.ppp = NULL; 00248 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.pppif = pppif; 00249 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.netif = netif; 00250 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.ipaddr = PPPAPI_VAR_REF(ipaddr); 00251 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.port = port; 00252 #if PPPOL2TP_AUTH_SUPPORT 00253 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.secret = secret; 00254 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.secret_len = secret_len; 00255 #endif /* PPPOL2TP_AUTH_SUPPORT */ 00256 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.link_status_cb = link_status_cb; 00257 PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.ctx_cb = ctx_cb; 00258 tcpip_api_call(pppapi_do_pppol2tp_create, &PPPAPI_VAR_REF(msg).call); 00259 result = PPPAPI_VAR_REF(msg).msg.ppp; 00260 PPPAPI_VAR_FREE(msg); 00261 return result; 00262 } 00263 #endif /* PPPOL2TP_SUPPORT */ 00264 00265 00266 /** 00267 * Call ppp_connect() inside the tcpip_thread context. 00268 */ 00269 static err_t 00270 pppapi_do_ppp_connect(struct tcpip_api_call_data *m) 00271 { 00272 /* cast through void* to silence alignment warnings. 00273 * We know it works because the structs have been instantiated as struct pppapi_msg */ 00274 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m; 00275 00276 return ppp_connect(msg->msg.ppp, msg->msg.msg.connect.holdoff); 00277 } 00278 00279 /** 00280 * Call ppp_connect() in a thread-safe way by running that function inside the 00281 * tcpip_thread context. 00282 */ 00283 err_t 00284 pppapi_connect(ppp_pcb *pcb, u16_t holdoff) 00285 { 00286 err_t err; 00287 PPPAPI_VAR_DECLARE(msg); 00288 PPPAPI_VAR_ALLOC(msg); 00289 00290 PPPAPI_VAR_REF(msg).msg.ppp = pcb; 00291 PPPAPI_VAR_REF(msg).msg.msg.connect.holdoff = holdoff; 00292 err = tcpip_api_call(pppapi_do_ppp_connect, &PPPAPI_VAR_REF(msg).call); 00293 PPPAPI_VAR_FREE(msg); 00294 return err; 00295 } 00296 00297 00298 #if PPP_SERVER 00299 /** 00300 * Call ppp_listen() inside the tcpip_thread context. 00301 */ 00302 static err_t 00303 pppapi_do_ppp_listen(struct tcpip_api_call_data *m) 00304 { 00305 /* cast through void* to silence alignment warnings. 00306 * We know it works because the structs have been instantiated as struct pppapi_msg */ 00307 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m; 00308 00309 return ppp_listen(msg->msg.ppp); 00310 } 00311 00312 /** 00313 * Call ppp_listen() in a thread-safe way by running that function inside the 00314 * tcpip_thread context. 00315 */ 00316 err_t 00317 pppapi_listen(ppp_pcb *pcb) 00318 { 00319 err_t err; 00320 PPPAPI_VAR_DECLARE(msg); 00321 PPPAPI_VAR_ALLOC(msg); 00322 00323 PPPAPI_VAR_REF(msg).msg.ppp = pcb; 00324 err = tcpip_api_call(pppapi_do_ppp_listen, &PPPAPI_VAR_REF(msg).call); 00325 PPPAPI_VAR_FREE(msg); 00326 return err; 00327 } 00328 #endif /* PPP_SERVER */ 00329 00330 00331 /** 00332 * Call ppp_close() inside the tcpip_thread context. 00333 */ 00334 static err_t 00335 pppapi_do_ppp_close(struct tcpip_api_call_data *m) 00336 { 00337 /* cast through void* to silence alignment warnings. 00338 * We know it works because the structs have been instantiated as struct pppapi_msg */ 00339 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m; 00340 00341 return ppp_close(msg->msg.ppp, msg->msg.msg.close.nocarrier); 00342 } 00343 00344 /** 00345 * Call ppp_close() in a thread-safe way by running that function inside the 00346 * tcpip_thread context. 00347 */ 00348 err_t 00349 pppapi_close(ppp_pcb *pcb, u8_t nocarrier) 00350 { 00351 err_t err; 00352 PPPAPI_VAR_DECLARE(msg); 00353 PPPAPI_VAR_ALLOC(msg); 00354 00355 PPPAPI_VAR_REF(msg).msg.ppp = pcb; 00356 PPPAPI_VAR_REF(msg).msg.msg.close.nocarrier = nocarrier; 00357 err = tcpip_api_call(pppapi_do_ppp_close, &PPPAPI_VAR_REF(msg).call); 00358 PPPAPI_VAR_FREE(msg); 00359 return err; 00360 } 00361 00362 00363 /** 00364 * Call ppp_free() inside the tcpip_thread context. 00365 */ 00366 static err_t 00367 pppapi_do_ppp_free(struct tcpip_api_call_data *m) 00368 { 00369 /* cast through void* to silence alignment warnings. 00370 * We know it works because the structs have been instantiated as struct pppapi_msg */ 00371 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m; 00372 00373 return ppp_free(msg->msg.ppp); 00374 } 00375 00376 /** 00377 * Call ppp_free() in a thread-safe way by running that function inside the 00378 * tcpip_thread context. 00379 */ 00380 err_t 00381 pppapi_free(ppp_pcb *pcb) 00382 { 00383 err_t err; 00384 PPPAPI_VAR_DECLARE(msg); 00385 PPPAPI_VAR_ALLOC(msg); 00386 00387 PPPAPI_VAR_REF(msg).msg.ppp = pcb; 00388 err = tcpip_api_call(pppapi_do_ppp_free, &PPPAPI_VAR_REF(msg).call); 00389 PPPAPI_VAR_FREE(msg); 00390 return err; 00391 } 00392 00393 00394 /** 00395 * Call ppp_ioctl() inside the tcpip_thread context. 00396 */ 00397 static err_t 00398 pppapi_do_ppp_ioctl(struct tcpip_api_call_data *m) 00399 { 00400 /* cast through void* to silence alignment warnings. 00401 * We know it works because the structs have been instantiated as struct pppapi_msg */ 00402 struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m; 00403 00404 return ppp_ioctl(msg->msg.ppp, msg->msg.msg.ioctl.cmd, msg->msg.msg.ioctl.arg); 00405 } 00406 00407 /** 00408 * Call ppp_ioctl() in a thread-safe way by running that function inside the 00409 * tcpip_thread context. 00410 */ 00411 err_t 00412 pppapi_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg) 00413 { 00414 err_t err; 00415 PPPAPI_VAR_DECLARE(msg); 00416 PPPAPI_VAR_ALLOC(msg); 00417 00418 PPPAPI_VAR_REF(msg).msg.ppp = pcb; 00419 PPPAPI_VAR_REF(msg).msg.msg.ioctl.cmd = cmd; 00420 PPPAPI_VAR_REF(msg).msg.msg.ioctl.arg = arg; 00421 err = tcpip_api_call(pppapi_do_ppp_ioctl, &PPPAPI_VAR_REF(msg).call); 00422 PPPAPI_VAR_FREE(msg); 00423 return err; 00424 } 00425 00426 #endif
Generated on Tue Jul 12 2022 13:54:42 by
