ppp_sample.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) 2006-2019, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-08-15 xiangxistu the first version
  9. * 2019-09-26 xiangxistu add ppp_device_attach and ppp_device_detach
  10. */
  11. #include<rtthread.h>
  12. #include<ppp_device.h>
  13. #define DBG_TAG "ppp.sample"
  14. #ifdef PPP_DEVICE_DEBUG
  15. #define DBG_LVL DBG_LOG
  16. #else
  17. #define DBG_LVL DBG_INFO
  18. #endif
  19. #include <rtdbg.h>
  20. /* if you want connect network again, you can use this function to create a new ppp link */
  21. int ppp_sample_start(void)
  22. {
  23. rt_device_t device = RT_NULL;
  24. device = rt_device_find(PPP_DEVICE_NAME);
  25. if(device == RT_NULL)
  26. {
  27. LOG_E("Can't find device (%s).", PPP_DEVICE_NAME);
  28. return -RT_ERROR;
  29. }
  30. if(ppp_device_attach((struct ppp_device *)device, PPP_CLIENT_NAME, RT_NULL) != RT_EOK)
  31. {
  32. LOG_E("ppp_device_attach execute failed.");
  33. return -RT_ERROR;
  34. }
  35. return RT_EOK;
  36. }
  37. #ifndef PKG_USING_CMUX
  38. INIT_APP_EXPORT(ppp_sample_start);
  39. #endif
  40. MSH_CMD_EXPORT_ALIAS(ppp_sample_start, ppp_start, a sample of ppp device for dailing to network);
  41. /* close ppp link ,turn off modem form network */
  42. int ppp_sample_stop(void)
  43. {
  44. rt_device_t device = RT_NULL;
  45. device = rt_device_find(PPP_DEVICE_NAME);
  46. if(device == RT_NULL)
  47. {
  48. LOG_E("Can't find device (%s).", PPP_DEVICE_NAME);
  49. return -RT_ERROR;
  50. }
  51. if(ppp_device_detach((struct ppp_device *)device) != RT_EOK)
  52. {
  53. LOG_E("ppp_device_detach execute failed.");
  54. return -RT_ERROR;
  55. }
  56. return RT_EOK;
  57. }
  58. MSH_CMD_EXPORT_ALIAS(ppp_sample_stop, ppp_stop, a sample of ppp device for turning off network);
  59. #ifdef PPP_DEVICE_DEBUG_DROP
  60. static int ppp_drop(void)
  61. {
  62. rt_device_t device = RT_NULL;
  63. struct ppp_device *ppp_device;
  64. device = rt_device_find(PPP_DEVICE_NAME);
  65. if(device == RT_NULL)
  66. {
  67. LOG_E("Can't find device (%s).", PPP_DEVICE_NAME);
  68. return -RT_ERROR;
  69. }
  70. ppp_device = (struct ppp_device*)device;
  71. LOG_I("%ld", (unsigned long)(ppp_device->dropcnt + ppp_device->droppos));
  72. return RT_EOK;
  73. }
  74. MSH_CMD_EXPORT_ALIAS(ppp_drop, ppp_drop, show drop statistics);
  75. #endif