ppp_device.h 3.4 KB

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