ppp_device.h 3.6 KB

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