USB PPP
PPP 是一种网络中最为基础的协议。PPP 协议(Point-to-Point Protocol) 是一种数据链路层协议,它是为在同等单元之间传输数据包这样的简单链路而设计的。这种链路提供全双工操作,并按照顺序传递数据包。PPP 为基于各种主机、网桥和路由器的简单连接提供一种共通的解决方案。
iot_usbh_modem 组件实现了 USB 主机 PPP 拨号的全流程。支持通过 USB 接口连接 4G Cat.1/4 模块,实现 PPP 拨号上网。
- 特性:
快速启动
支持热插拔
支持 Modem+AT 双接口(需要模组支持)
支持 PPP 标准协议 (大部分 4G 模组均支持)
支持 NAPT 网络地址转换
已支持的模组型号:
下表是已经支持的 4G 模组型号,可以按照 示例代码 添加自己的模组支持。
备注
同一个模组可能存在多个功能固件,具体请咨询对应厂商是否支持 PPP 拨号。
型号 |
固件版本 |
ESP32-S2 |
ESP32-S3 |
ESP32-P4 |
|---|---|---|---|---|
ML302 |
ML302-CNLM_MBRH0S00 |
✅ |
✅ |
✅ |
Air780E |
AirM2M_780EVT_V2010_LTE_AT |
✅ |
✅ |
✅ |
EC600N-CN |
EC600NCNLDR03A03M16_OCP |
✅ |
✅ |
✅ |
EC20 |
EC20CEFHLGR06A07M1G |
✅ |
✅ |
✅ |
YM310 |
YM310.X09S_AT.A60_R2.1.3.241121 |
✅ |
✅ |
✅ |
A7600C1 |
Model: A7600C1-LNASRevision: A7600M6_V8.18.1 |
✅ |
✅ |
✅ |
A7670E |
Model: A7670E-FASERevision: A7670M7_V1.11.1 |
✅ |
✅ |
✅ |
SIM7080G |
Revision: 1951B17SIM7080 |
✅ |
✅ |
✅ |
LE270-CN |
12007.6005.00.02.03.04 |
✅ |
✅ |
✅ |
MC610-EU |
16000.1000.00.97.20.10 |
✅ |
✅ |
✅ |
添加一个新的 4G 模组支持
4G 模组的 USB 描述符通常拥有多个接口,例如 Modem 接口、AT 指令接口、Debug 接口等。主机可以通过虚拟的 Modem 接口与蜂窝通信模组进行数据通信,例如发送AT命令进行控制操作,或者收发网络数据。通常情况下 Modem 接口在拨号成功后变成数据模式传输 PPP 数据,可以通过发送 “+++” 返回命令模式;还有些模组具有一个独立的 AT 指令接口,这时允许数据通信和AT指令交互同时进行。下面是添加一个新的 4G 模组支持的步骤:
确认 4G 模组 支持 USB PPP 拨号;
确认 4G SIM 卡已激活 以及网络访问已打开;
确认 4G 模组的 USB 描述符信息中
Vendor ID、Product ID、Modem 接口号以及可选的 AT 指令接口号,可以通过 usbtreeview 工具查看;将上述描述符中的信息填入到
usbh_modem_config_t结构体中;
备注
不同 4G 模组支持的基本 AT 命令大致相同,但可能存在一些特殊命令需要用户自行实现。
备注
有些模组的 PPP 接口并非标准 CDC 接口,而是 Vendor Specific Class 接口,驱动也支持部分这种模组。
备注
有些 4G 模组通过 PPP 帧就可以自动从数据模式切换到命令模式,无需发送 “+++”。此时需要关闭 MODEM_EXIT_PPP_WITH_AT_CMD 配置选项。
示例代码
API 参考
Header File
Functions
-
esp_err_t usbh_modem_install(const usbh_modem_config_t *config)
Install and initialize the USB modem subsystem.
Sets up the USB modem manager, creates internal resources and prepares the modem for operation according to the provided configuration.
- 参数
config – [in] Pointer to modem configuration
- 返回
ESP_OK: Installed successfully
ESP_ERR_INVALID_ARG: Invalid argument
ESP_ERR_INVALID_STATE: Already installed
ESP_ERR_NO_MEM: Memory allocation failed
-
esp_err_t usbh_modem_uninstall(void)
Uninstall the USB modem subsystem.
Releases resources allocated during installation and stops related tasks.
- 返回
ESP_OK: Uninstalled successfully
ESP_ERR_INVALID_STATE: Not installed
-
esp_netif_t *usbh_modem_get_netif()
Get the ESP-NETIF of the modem.
Returns the network interface created for PPP networking.
- 返回
Pointer to
esp_netif_tif available, otherwise NULL
-
esp_err_t usbh_modem_ppp_auto_connect(bool enable)
Enable or disable PPP auto-connect.
When enabled, the modem will attempt to establish PPP automatically after device connection or recoveries.
备注
PPP auto-connect is enabled by default.
- 参数
enable – [in] true to enable, false to disable
- 返回
ESP_OK on success, error otherwise
-
esp_err_t usbh_modem_ppp_start(TickType_t timeout)
Start PPP connection and wait for link up.
- 参数
timeout – [in] Maximum time to wait for PPP to become connected
- 返回
ESP_OK: PPP connected within timeout
ESP_ERR_TIMEOUT: Timed out waiting for connection
ESP_ERR_INVALID_STATE: Modem not ready
ESP_FAIL: Failed to start PPP
-
esp_err_t usbh_modem_ppp_stop()
Stop PPP connection.
- 返回
ESP_OK: Stopped successfully (or already stopped)
ESP_ERR_INVALID_STATE: Modem not ready
ESP_FAIL: Operation failed
-
at_handle_t usbh_modem_get_atparser()
Get the AT command parser handle associated with the modem.
- 返回
AT parser handle (
at_handle_t), or NULL if unavailable
Structures
-
struct usbh_modem_config_t
USB modem configuration structure.