*argc = 0;
for (uint32_t i = 0; i < paraLen; i++) {
- if ((para[i] == ' ' || para[i] == '\n') && pos != 0) {
+ if ((para[i] == ' ' || para[i] == ',' || para[i] == '\n') && pos != 0) {
argv[*argc][pos] = '\0';
*argc += 1;
pos = 0;
PPP_DEBUG_WARN("Failed to set socket timeout");
}
#else
- // 在lwIP环境下设置超时 (使用简化方式)
- int timeout_ms = TCP_TEST_CONNECT_TIMEOUT * 1000;
- if (TCP_SETSOCKOPT(fd, TCP_SOL_SOCKET, TCP_SO_RCVTIMEO, &timeout_ms, sizeof(timeout_ms)) < 0 ||
- TCP_SETSOCKOPT(fd, TCP_SOL_SOCKET, TCP_SO_SNDTIMEO, &timeout_ms, sizeof(timeout_ms)) < 0) {
- PPP_DEBUG_WARN("Failed to set socket timeout in lwIP");
+ // 在lwIP环境下设置超时 - 使用正确的数据类型和检查
+ #ifdef LWIP_SO_RCVTIMEO
+ struct timeval timeout;
+ timeout.tv_sec = TCP_TEST_CONNECT_TIMEOUT;
+ timeout.tv_usec = 0;
+
+ if (TCP_SETSOCKOPT(fd, TCP_SOL_SOCKET, TCP_SO_RCVTIMEO, &timeout, sizeof(timeout)) < 0) {
+ PPP_DEBUG_DEBUG("lwIP SO_RCVTIMEO not supported or failed");
}
+ if (TCP_SETSOCKOPT(fd, TCP_SOL_SOCKET, TCP_SO_SNDTIMEO, &timeout, sizeof(timeout)) < 0) {
+ PPP_DEBUG_DEBUG("lwIP SO_SNDTIMEO not supported or failed");
+ }
+ #else
+ // lwIP可能不支持超时选项,使用非阻塞模式代替
+ PPP_DEBUG_INFO("lwIP socket timeout not supported, using default behavior");
+ #endif
#endif
struct sockaddr_in server_addr;
.ring_pin = S_MGPIO21, //CTS cat1 wakeup mcu
.ring_pin_en_value = 2, //2 双边沿中断 , 1 上升沿中断 , 0 下降沿中断
.wakemodem_pin = S_MGPIO22, //RTS mcu wakeup cat1
- .wakemodem_pin_en_value = 1 //1 唤醒cat1 , 0 休眠cat1
+ .wakemodem_pin_en_value = 0 //0 唤醒cat1 , 1 休眠cat1
};
// 注册4G电源控制引脚配置
#ifndef LWIP_PPP_SUPPORT
return PPP_ERR_INVALID_PARAM;
#else
+ /* 参数和状态验证 */
if (!g_lwip_ctx.initialized || !data || length == 0) {
return PPP_ERR_INVALID_PARAM;
}
+
+ // /* 添加合理性检查 - PPP帧长度限制 */
+ // if (length > 1500) { // PPP最大帧长度
+ // PPP_DEBUG_ERROR("PPP frame too large: %u bytes", length);
+ // return PPP_ERR_INVALID_PARAM;
+ // }
+
+ /* 检查PPP控制块是否有效 */
+ if (!g_lwip_ctx.ppp_pcb) {
+ PPP_DEBUG_ERROR("PPP control block is NULL");
+ return PPP_ERR_INVALID_STATE;
+ }
PPP_DEBUG_PRINT("=== PPP Input Data ===\n");
PPP_DEBUG_PRINT("Length: %d bytes\n", length);
PPP_DEBUG_INFO("PPP RX: Got %u bytes (total: %u packets, %u bytes)",
bytes_read, total_packets, total_bytes);
- /* 将接收到的数据添加到流缓冲区 */
+ /* 将接收到的数据添加到流缓冲区 - 加强边界检查 */
if (stream_pos + bytes_read < PPP_RX_BUFFER_SIZE * 2) {
memcpy(stream_buffer + stream_pos, rx_buffer, bytes_read);
stream_pos += bytes_read;
stream_pos = 0;
frame_start = 0;
in_frame = false;
+ continue; // 跳过本次处理,避免缓冲区溢出
}
- /* 处理PPP帧 - 查找0x7E标志 */
- for (uint32_t i = frame_start; i < stream_pos; i++) {
+ /* 处理PPP帧 - 查找0x7E标志并添加边界检查 */
+ for (uint32_t i = frame_start; i < stream_pos && i < PPP_RX_BUFFER_SIZE * 2; i++) {
if (stream_buffer[i] == 0x7E) {
if (in_frame && i > frame_start) {
/* 找到帧结束,处理完整的PPP帧 */
uint32_t frame_len = i - frame_start + 1;
- PPP_DEBUG_DEBUG("PPP complete frame found: %u bytes", frame_len);
-
- /* 将完整帧传递给lwIP - 让lwIP自己验证帧的有效性 */
- ppp_lwip_input(stream_buffer + frame_start, frame_len);
- complete_frames++;
+ /* 添加帧长度合理性检查 */
+ if (frame_len > 0 && frame_len <= 1500) { // PPP最大帧长度
+ PPP_DEBUG_DEBUG("PPP complete frame found: %u bytes", frame_len);
+
+ /* 确保指针和长度有效 */
+ if (frame_start + frame_len <= PPP_RX_BUFFER_SIZE * 2 &&
+ frame_start < PPP_RX_BUFFER_SIZE * 2) {
+ /* 将完整帧传递给lwIP - 让lwIP自己验证帧的有效性 */
+ ppp_lwip_input(stream_buffer + frame_start, frame_len);
+ complete_frames++;
+ } else {
+ PPP_DEBUG_WARN("PPP frame pointer out of bounds: start=%u, len=%u",
+ frame_start, frame_len);
+ }
+ } else {
+ PPP_DEBUG_WARN("Invalid PPP frame length: %u (frame_start=%u, i=%u)",
+ frame_len, frame_start, i);
+ }
}
/* 开始新帧 */
S_MGPIO21,//ring_pin
2,
S_MGPIO22,//wakemodem_pin
- 1,
+ 0,
#else
PIN_NONE, //bat_pin
1,
gpio_level_t val = uapi_gpio_get_val(pin);
if (val == GPIO_LEVEL_HIGH) {
PPP_DEBUG_PRINT("PPP: Cat1 ring interrupt on pin %d high \n", pin);
+ #ifdef PPP_LOW_POWER_MODE
ppp_api_wakeup_cat1(true);
+ #endif
} else {
PPP_DEBUG_PRINT("PPP: Cat1 ring interrupt on pin %d low\n", pin);
+ #ifdef PPP_LOW_POWER_MODE
ppp_api_wakeup_cat1(false);
+ #endif
}
uapi_gpio_clear_interrupt(pin);
}
}
PPP_DEBUG_INFO("=== PPP Serial Write Start ===");
+ #ifdef PPP_LOW_POWER_MODE
ppp_api_wakeup_cat1(true);
+ #endif
osal_msleep(1);
PPP_DEBUG_INFO("Write request: %u bytes in mode %d", length, g_serial_ctx.current_mode);
PPP_DEBUG_INFO("UART Bus: %u", g_serial_ctx.uart_bus);
result == PPP_ERR_OK ? "SUCCESS" : "FAILED", result);
PPP_DEBUG_INFO("Statistics: tx_bytes=%u, tx_errors=%u", g_serial_ctx.tx_bytes, g_serial_ctx.tx_errors);
PPP_DEBUG_INFO("=== PPP Serial Write End ===");
+ #ifdef PPP_LOW_POWER_MODE
ppp_api_wakeup_cat1(false);
+ #endif
return result;
}