ppp_device.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. */
  10. #ifndef __PPP_DEVICE_H__
  11. #define __PPP_DEVICE_H__
  12. #include <rtdef.h>
  13. #include <netif/ppp/ppp.h>
  14. #include <netif/ppp/pppos.h>
  15. #include <netif/ppp/pppapi.h>
  16. #include <lwip/dns.h>
  17. #include <lwip/netif.h>
  18. #ifndef PPP_DEVICE_NAME
  19. #define PPP_DEVICE_NAME "pp"
  20. #endif
  21. #define PPP_DAIL_CMD "ATD*99#" /* common dailing cmd */
  22. #ifndef USING_PUBLIC_APN
  23. #define PPP_APN_CMD "AT+CGDCONT=1,\"IP\","PPP_PRIVATE_APN
  24. #else
  25. #ifdef PPP_APN_CMCC
  26. #define PPP_APN_CMD "AT+CGDCONT=1,\"IP\",\"CMNET\"" /* China Mobile Communication Company */
  27. #endif
  28. #ifdef PPP_APN_CUCC
  29. #define PPP_APN_CMD "AT+CGDCONT=1,\"IP\",\"UNINET\"" /* China Unicom Communication Company */
  30. #endif
  31. #ifdef PPP_APN_CTCC
  32. #define PPP_APN_CMD "AT+CGDCONT=1,\"IP\",\"CTNET\"" /* China Telecom Communication Company */
  33. #endif
  34. #endif
  35. #define PPP_CTL_GET_CSQ 1
  36. #define PPP_CTL_GET_IEMI 2
  37. #define PPP_CTL_GET_TYPE 3
  38. #define PPP_CTL_PREPARE 10
  39. #define PPP_FRAME_MAX 1550
  40. #define PPP_DROP_BUF PPP_FRAME_MAX
  41. #define PPP_DEVICE_SW_VERSION "1.0.1"
  42. #define PPP_DEVICE_SW_VERSION_NUM 0x10001
  43. enum ppp_trans_type
  44. {
  45. PPP_TRANS_CHAT,
  46. PPP_TRANS_AT_CLIENT
  47. };
  48. enum ppp_conn_type
  49. {
  50. PPP_CONNET_UART, /* using uart connect ppp */
  51. PPP_CONNET_USB /* using usb connect ppp */
  52. };
  53. /**
  54. * @brief PPPoS Client IP Information
  55. *
  56. */
  57. struct ppp_device
  58. {
  59. struct rt_device parent; /* join rt_device frame */
  60. rt_device_t uart; /* low-level uart device object */
  61. const struct ppp_device_ops *ops; /* ppp device ops interface */
  62. enum ppp_conn_type conn_type; /* using usb or uart */
  63. rt_base_t power_pin; /* power pin, if device need hardware reset */
  64. ppp_pcb *pcb; /* ppp protocol control block */
  65. struct netif pppif;
  66. #ifdef PPP_DEVICE_DEBUG_DROP
  67. rt_size_t dropcnt; /* counter of drop bytes */
  68. rt_size_t droppos; /* valid size of drop buffer */
  69. rt_uint8_t dropbuf[PPP_DROP_BUF]; /* drop buffer */
  70. #endif
  71. rt_size_t rxpos; /* valid size of receive frame buffer */
  72. rt_uint8_t rxbuf[PPP_FRAME_MAX]; /* receive frame buffer */
  73. rt_uint8_t state; /* internal state */
  74. struct rt_event event; /* interthread communication */
  75. rt_thread_t recv_tid; /* recieve thread point */
  76. void *user_data; /* reserve */
  77. };
  78. struct ppp_device_ops
  79. {
  80. rt_err_t (*prepare) (struct ppp_device *dev);
  81. };
  82. enum ppp_reci_status
  83. {
  84. PPP_DATA_VERIFY,
  85. PPP_DATA_START,
  86. PPP_DATA_END
  87. };
  88. /* store at_client rx_callback function */
  89. typedef rt_err_t (*uart_rx_cb)(rt_device_t dev, rt_size_t size);
  90. /* offer register funciton to user */
  91. int ppp_device_register(struct ppp_device *ppp_device, const char *dev_name, const char *uart_name, void *user_data);
  92. int ppp_device_attach(struct ppp_device *ppp_device, const char *uart_name, void *user_data);
  93. int ppp_device_detach(struct ppp_device *ppp_device);
  94. #endif /* __PPP_DEVICE_H__ */