pppapi.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. /**
  2. * @file
  3. * Point To Point Protocol Sequential API module
  4. *
  5. */
  6. /*
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted provided that the following conditions are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright notice,
  13. * this list of conditions and the following disclaimer in the documentation
  14. * and/or other materials provided with the distribution.
  15. * 3. The name of the author may not be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  19. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  20. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  21. * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  23. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  24. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  25. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  26. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  27. * OF SUCH DAMAGE.
  28. *
  29. * This file is part of the lwIP TCP/IP stack.
  30. *
  31. */
  32. #include "lwip/opt.h"
  33. #if LWIP_PPP_API /* don't build if not configured for use in lwipopts.h */
  34. #include "lwip/pppapi.h"
  35. #include "lwip/priv/tcpip_priv.h"
  36. #include "netif/ppp/pppoe.h"
  37. #include "netif/ppp/pppol2tp.h"
  38. #include "netif/ppp/pppos.h"
  39. /**
  40. * Call ppp_set_default() inside the tcpip_thread context.
  41. */
  42. static err_t
  43. pppapi_do_ppp_set_default(struct tcpip_api_call *m)
  44. {
  45. struct pppapi_msg_msg *msg = (struct pppapi_msg_msg *)m;
  46. ppp_set_default(msg->ppp);
  47. return ERR_OK;
  48. }
  49. /**
  50. * Call ppp_set_default() in a thread-safe way by running that function inside the
  51. * tcpip_thread context.
  52. */
  53. void
  54. pppapi_set_default(ppp_pcb *pcb)
  55. {
  56. struct pppapi_msg msg;
  57. msg.msg.ppp = pcb;
  58. tcpip_api_call(pppapi_do_ppp_set_default, &msg.call);
  59. }
  60. /**
  61. * Call ppp_set_auth() inside the tcpip_thread context.
  62. */
  63. static err_t
  64. pppapi_do_ppp_set_auth(struct tcpip_api_call *m)
  65. {
  66. struct pppapi_msg_msg *msg = (struct pppapi_msg_msg *)m;
  67. ppp_set_auth(msg->ppp, msg->msg.setauth.authtype,
  68. msg->msg.setauth.user, msg->msg.setauth.passwd);
  69. return ERR_OK;
  70. }
  71. /**
  72. * Call ppp_set_auth() in a thread-safe way by running that function inside the
  73. * tcpip_thread context.
  74. */
  75. void
  76. pppapi_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *passwd)
  77. {
  78. struct pppapi_msg msg;
  79. msg.msg.ppp = pcb;
  80. msg.msg.msg.setauth.authtype = authtype;
  81. msg.msg.msg.setauth.user = user;
  82. msg.msg.msg.setauth.passwd = passwd;
  83. tcpip_api_call(pppapi_do_ppp_set_auth, &msg.call);
  84. }
  85. #if PPP_NOTIFY_PHASE
  86. /**
  87. * Call ppp_set_notify_phase_callback() inside the tcpip_thread context.
  88. */
  89. static err_t
  90. pppapi_do_ppp_set_notify_phase_callback(struct tcpip_api_call *m)
  91. {
  92. struct pppapi_msg_msg *msg = (struct pppapi_msg_msg *)m;
  93. ppp_set_notify_phase_callback(msg->ppp, msg->msg.setnotifyphasecb.notify_phase_cb);
  94. return ERR_OK;
  95. }
  96. /**
  97. * Call ppp_set_notify_phase_callback() in a thread-safe way by running that function inside the
  98. * tcpip_thread context.
  99. */
  100. void
  101. pppapi_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_phase_cb)
  102. {
  103. struct pppapi_msg msg;
  104. msg.function = pppapi_do_ppp_set_notify_phase_callback;
  105. msg.msg.ppp = pcb;
  106. msg.msg.msg.setnotifyphasecb.notify_phase_cb = notify_phase_cb;
  107. tcpip_api_call(pppapi_do_ppp_set_notify_phase_callback, &msg.call);
  108. }
  109. #endif /* PPP_NOTIFY_PHASE */
  110. #if PPPOS_SUPPORT
  111. /**
  112. * Call pppos_create() inside the tcpip_thread context.
  113. */
  114. static err_t
  115. pppapi_do_pppos_create(struct tcpip_api_call *m)
  116. {
  117. struct pppapi_msg_msg *msg = (struct pppapi_msg_msg *)m;
  118. msg->ppp = pppos_create(msg->msg.serialcreate.pppif, msg->msg.serialcreate.output_cb,
  119. msg->msg.serialcreate.link_status_cb, msg->msg.serialcreate.ctx_cb);
  120. return ERR_OK;
  121. }
  122. /**
  123. * Call pppos_create() in a thread-safe way by running that function inside the
  124. * tcpip_thread context.
  125. */
  126. ppp_pcb*
  127. pppapi_pppos_create(struct netif *pppif, pppos_output_cb_fn output_cb,
  128. ppp_link_status_cb_fn link_status_cb, void *ctx_cb)
  129. {
  130. struct pppapi_msg msg;
  131. msg.msg.msg.serialcreate.pppif = pppif;
  132. msg.msg.msg.serialcreate.output_cb = output_cb;
  133. msg.msg.msg.serialcreate.link_status_cb = link_status_cb;
  134. msg.msg.msg.serialcreate.ctx_cb = ctx_cb;
  135. tcpip_api_call(pppapi_do_pppos_create, &msg.call);
  136. return msg.msg.ppp;
  137. }
  138. #endif /* PPPOS_SUPPORT */
  139. #if PPPOE_SUPPORT
  140. /**
  141. * Call pppoe_create() inside the tcpip_thread context.
  142. */
  143. static err_t
  144. pppapi_do_pppoe_create(struct tcpip_api_call *m)
  145. {
  146. struct pppapi_msg_msg *msg = (struct pppapi_msg_msg *)m;
  147. msg->ppp = pppoe_create(msg->msg.ethernetcreate.pppif, msg->msg.ethernetcreate.ethif,
  148. msg->msg.ethernetcreate.service_name, msg->msg.ethernetcreate.concentrator_name,
  149. msg->msg.ethernetcreate.link_status_cb, msg->msg.ethernetcreate.ctx_cb);
  150. return ERR_OK;
  151. }
  152. /**
  153. * Call pppoe_create() in a thread-safe way by running that function inside the
  154. * tcpip_thread context.
  155. */
  156. ppp_pcb*
  157. pppapi_pppoe_create(struct netif *pppif, struct netif *ethif, const char *service_name,
  158. const char *concentrator_name, ppp_link_status_cb_fn link_status_cb,
  159. void *ctx_cb)
  160. {
  161. struct pppapi_msg msg;
  162. msg.msg.msg.ethernetcreate.pppif = pppif;
  163. msg.msg.msg.ethernetcreate.ethif = ethif;
  164. msg.msg.msg.ethernetcreate.service_name = service_name;
  165. msg.msg.msg.ethernetcreate.concentrator_name = concentrator_name;
  166. msg.msg.msg.ethernetcreate.link_status_cb = link_status_cb;
  167. msg.msg.msg.ethernetcreate.ctx_cb = ctx_cb;
  168. tcpip_api_call(pppapi_do_pppoe_create, &msg.call);
  169. return msg.msg.ppp;
  170. }
  171. #endif /* PPPOE_SUPPORT */
  172. #if PPPOL2TP_SUPPORT
  173. /**
  174. * Call pppol2tp_create() inside the tcpip_thread context.
  175. */
  176. static err_t
  177. pppapi_do_pppol2tp_create(struct tcpip_api_call *m)
  178. {
  179. struct pppapi_msg_msg *msg = (struct pppapi_msg_msg *)m;
  180. msg->ppp = pppol2tp_create(msg->msg.l2tpcreate.pppif,
  181. msg->msg.l2tpcreate.netif, msg->msg.l2tpcreate.ipaddr, msg->msg.l2tpcreate.port,
  182. #if PPPOL2TP_AUTH_SUPPORT
  183. msg->msg.l2tpcreate.secret,
  184. msg->msg.l2tpcreate.secret_len,
  185. #else /* PPPOL2TP_AUTH_SUPPORT */
  186. NULL,
  187. #endif /* PPPOL2TP_AUTH_SUPPORT */
  188. msg->msg.l2tpcreate.link_status_cb, msg->msg.l2tpcreate.ctx_cb);
  189. return ERR_OK;
  190. }
  191. /**
  192. * Call pppol2tp_create() in a thread-safe way by running that function inside the
  193. * tcpip_thread context.
  194. */
  195. ppp_pcb*
  196. pppapi_pppol2tp_create(struct netif *pppif, struct netif *netif, ip_addr_t *ipaddr, u16_t port,
  197. const u8_t *secret, u8_t secret_len,
  198. ppp_link_status_cb_fn link_status_cb, void *ctx_cb)
  199. {
  200. struct pppapi_msg msg;
  201. msg.msg.msg.l2tpcreate.pppif = pppif;
  202. msg.msg.msg.l2tpcreate.netif = netif;
  203. msg.msg.msg.l2tpcreate.ipaddr = ipaddr;
  204. msg.msg.msg.l2tpcreate.port = port;
  205. #if PPPOL2TP_AUTH_SUPPORT
  206. msg.msg.msg.l2tpcreate.secret = secret;
  207. msg.msg.msg.l2tpcreate.secret_len = secret_len;
  208. #endif /* PPPOL2TP_AUTH_SUPPORT */
  209. msg.msg.msg.l2tpcreate.link_status_cb = link_status_cb;
  210. msg.msg.msg.l2tpcreate.ctx_cb = ctx_cb;
  211. tcpip_api_call(pppapi_do_pppol2tp_create, &msg.call);
  212. return msg.msg.ppp;
  213. }
  214. #endif /* PPPOL2TP_SUPPORT */
  215. /**
  216. * Call ppp_connect() inside the tcpip_thread context.
  217. */
  218. static err_t
  219. pppapi_do_ppp_connect(struct tcpip_api_call *m)
  220. {
  221. struct pppapi_msg_msg *msg = (struct pppapi_msg_msg *)m;
  222. return ppp_connect(msg->ppp, msg->msg.connect.holdoff);
  223. }
  224. /**
  225. * Call ppp_connect() in a thread-safe way by running that function inside the
  226. * tcpip_thread context.
  227. */
  228. err_t
  229. pppapi_connect(ppp_pcb *pcb, u16_t holdoff)
  230. {
  231. struct pppapi_msg msg;
  232. msg.msg.ppp = pcb;
  233. msg.msg.msg.connect.holdoff = holdoff;
  234. return tcpip_api_call(pppapi_do_ppp_connect, &msg.call);
  235. }
  236. #if PPP_SERVER
  237. /**
  238. * Call ppp_listen() inside the tcpip_thread context.
  239. */
  240. static void
  241. pppapi_do_ppp_listen(struct pppapi_msg_msg *msg)
  242. {
  243. msg->err = ppp_listen(msg->ppp, msg->msg.listen.addrs);
  244. TCPIP_PPPAPI_ACK(msg);
  245. }
  246. /**
  247. * Call ppp_listen() in a thread-safe way by running that function inside the
  248. * tcpip_thread context.
  249. */
  250. err_t
  251. pppapi_listen(ppp_pcb *pcb, struct ppp_addrs *addrs)
  252. {
  253. struct pppapi_msg msg;
  254. msg.function = pppapi_do_ppp_listen;
  255. msg.msg.ppp = pcb;
  256. msg.msg.msg.listen.addrs = addrs;
  257. TCPIP_PPPAPI(&msg);
  258. return msg.msg.err;
  259. }
  260. #endif /* PPP_SERVER */
  261. /**
  262. * Call ppp_close() inside the tcpip_thread context.
  263. */
  264. static err_t
  265. pppapi_do_ppp_close(struct tcpip_api_call *m)
  266. {
  267. struct pppapi_msg_msg *msg = (struct pppapi_msg_msg *)m;
  268. return ppp_close(msg->ppp, msg->msg.close.nocarrier);
  269. }
  270. /**
  271. * Call ppp_close() in a thread-safe way by running that function inside the
  272. * tcpip_thread context.
  273. */
  274. err_t
  275. pppapi_close(ppp_pcb *pcb, u8_t nocarrier)
  276. {
  277. struct pppapi_msg msg;
  278. msg.msg.ppp = pcb;
  279. msg.msg.msg.close.nocarrier = nocarrier;
  280. return tcpip_api_call(pppapi_do_ppp_close, &msg.call);
  281. }
  282. /**
  283. * Call ppp_free() inside the tcpip_thread context.
  284. */
  285. static err_t
  286. pppapi_do_ppp_free(struct tcpip_api_call *m)
  287. {
  288. struct pppapi_msg_msg *msg = (struct pppapi_msg_msg *)m;
  289. return ppp_free(msg->ppp);
  290. }
  291. /**
  292. * Call ppp_free() in a thread-safe way by running that function inside the
  293. * tcpip_thread context.
  294. */
  295. err_t
  296. pppapi_free(ppp_pcb *pcb)
  297. {
  298. struct pppapi_msg msg;
  299. msg.msg.ppp = pcb;
  300. return tcpip_api_call(pppapi_do_ppp_free, &msg.call);
  301. }
  302. /**
  303. * Call ppp_ioctl() inside the tcpip_thread context.
  304. */
  305. static err_t
  306. pppapi_do_ppp_ioctl(struct tcpip_api_call *m)
  307. {
  308. struct pppapi_msg_msg *msg = (struct pppapi_msg_msg *)m;
  309. return ppp_ioctl(msg->ppp, msg->msg.ioctl.cmd, msg->msg.ioctl.arg);
  310. }
  311. /**
  312. * Call ppp_ioctl() in a thread-safe way by running that function inside the
  313. * tcpip_thread context.
  314. */
  315. err_t
  316. pppapi_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg)
  317. {
  318. struct pppapi_msg msg;
  319. msg.msg.ppp = pcb;
  320. msg.msg.msg.ioctl.cmd = cmd;
  321. msg.msg.msg.ioctl.arg = arg;
  322. return tcpip_api_call(pppapi_do_ppp_ioctl, &msg.call);
  323. }
  324. #endif /* LWIP_PPP_API */