Skip to content

Conversation

@abhik-roy85
Copy link
Collaborator

@abhik-roy85 abhik-roy85 commented Nov 12, 2025

Description

Related

Testing


Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

Note

Adds the net_connect component providing unified connect/disconnect APIs for WiFi/Ethernet/Thread/PPP, utilities, console commands, Kconfig, and an example app.

  • net_connect component (new):
    • Unified APIs: net_connect(), net_disconnect(), net_get_netif_from_desc() and descriptors for sta/eth/thread/ppp.
    • Interfaces:
      • WiFi: connect logic, event handlers, optional console cmds (wifi_connect, wifi_disconnect).
      • Ethernet: EMAC/OpenETH support, event/IP handling.
      • Thread (OpenThread): task setup, attach/DNS wait, netif glue.
      • PPP: USB CDC/UART backends, event-driven IP acquire/retry.
    • Utils: stdin/stdout UART setup, address parsing from stdin, URI encode/decode helpers.
    • Build/Kconfig: CMakeLists.txt, Kconfig.projbuild with extensive options; idf_component.yml; sdkconfig.rename.
    • Example: examples/net_connect_example project demonstrating initialization and usage.
    • Docs: README.md describing interfaces and PPP setup.
  • Tooling:
    • .pre-commit-config.yaml: add net_connect to allowed commit scopes.

Written by Cursor Bugbot for commit 712046b. This will update automatically on new commits. Configure here.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

wifi_config.sta.channel = (uint8_t)(connect_args.channel->ival[0]);
}
const char *ssid = connect_args.ssid->sval[0];
const char *pass = connect_args.password->sval[0];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Unchecked Optional Argument Causes Undefined Behavior

Accessing connect_args.password->sval[0] without checking connect_args.password->count first causes undefined behavior when password is not provided. Since password is defined as arg_str0 (optional argument), the code must verify count > 0 before dereferencing sval[0], similar to how other optional arguments are handled in the codebase.

Fix in Cursor Fix in Web

// run getaddrinfo() to decide on the IP protocol
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = sock_type;
hints.ai_protocol = IPPROTO_TCP;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Protocol Mismatch Breaks UDP Address Resolution

Hardcoding hints.ai_protocol = IPPROTO_TCP ignores the sock_type parameter. When sock_type is SOCK_DGRAM, the protocol should be IPPROTO_UDP or left unspecified to let getaddrinfo infer it from ai_socktype. This causes UDP socket address resolution to potentially fail or behave incorrectly.

Fix in Cursor Fix in Web


char *rest = NULL;
char *temp = strtok_r(buf, " ", &rest);
strncpy((char*)wifi_config.sta.ssid, temp, sizeof(wifi_config.sta.ssid));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Null Pointer Crash on Empty Input

Null pointer dereference when strtok_r returns NULL. If the user enters only whitespace or an empty line, strtok_r at line 225 returns NULL, causing strncpy at line 226 to crash with a null pointer dereference. The code should verify temp is not NULL before using it.

Fix in Cursor Fix in Web

ESP_ERROR_CHECK(uart_set_pin(UART_NUM_1, CONFIG_NET_CONNECT_CONNECT_UART_TX_PIN, CONFIG_NET_CONNECT_CONNECT_UART_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
ESP_ERROR_CHECK(uart_set_rx_timeout(UART_NUM_1, 1));

char *buffer = (char*)malloc(BUF_SIZE);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Unchecked Memory Allocation Leads to Instability

Missing null check after malloc(BUF_SIZE). If memory allocation fails, buffer will be NULL, causing crashes when used in subsequent operations like uart_read_bytes and ESP_LOG_BUFFER_HEXDUMP. The code should verify allocation succeeded before proceeding.

Fix in Cursor Fix in Web

s_stop_task = false;
if (xTaskCreate(ppp_task, "ppp connect", 4096, NULL, 5, NULL) != pdTRUE) {
ESP_LOGE(TAG, "Failed to create a ppp connection task");
return ESP_FAIL;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Resource Leaks on Task Creation Failure

Resource leak when xTaskCreate fails. The function returns ESP_FAIL without cleaning up previously allocated resources including s_event_group, registered event handler, and s_netif. These resources remain allocated, causing memory and handle leaks.

Fix in Cursor Fix in Web

esp_err_t ret = esp_wifi_connect();
if (ret != ESP_OK) {
ESP_LOGE(TAG, "WiFi connect failed! ret:%x", ret);
return ret;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Connection Failure Causes Resource Leaks

Resource leak when esp_wifi_connect fails. Event handlers registered at lines 149-154 are not unregistered before returning, and if wait is true, the semaphores created at lines 136-145 are not deleted. This causes handle and memory leaks on connection failure.

Fix in Cursor Fix in Web

…ectivity

Port the network connection functionality from esp-idf's
protocol_examples_common component to esp-protocols as a standalone
net_connect component.

Changes:
- Port all network connection code from esp-idf/examples/common_components/protocol_examples_common
- Rename functions from example_* prefix to net_* prefix for consistency
- Add unified API supporting WiFi, Ethernet, Thread, and PPP interfaces
- Add comprehensive Kconfig options for all connection types
- Add net_connect_example demonstrating component usage
- Update component structure with proper CMakeLists.txt and idf_component.yml
- Add README with usage instructions for all supported interfaces

The component provides a unified interface for establishing network
connectivity across multiple transport types, simplifying network setup
in protocol examples and applications.

Supported interfaces:
- WiFi (Station mode with configurable scan methods)
- Ethernet (EMAC and SPI-based)
- Thread (IEEE802.15.4 native or RCP)
- PPP (Point-to-Point Protocol over Serial/USB)

All configuration is done via Kconfig menuconfig, making it easy to
enable/disable specific interfaces and configure connection parameters.
@abhik-roy85 abhik-roy85 force-pushed the component/net_connect branch from 24d6b84 to 712046b Compare November 20, 2025 11:34
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

vSemaphoreDelete(s_semph_get_ip_addrs);
return ESP_ERR_NO_MEM;
}
#endif
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Double-free vulnerability in Ethernet connection failure

If xSemaphoreCreateBinary fails for s_semph_get_ip6_addrs, s_semph_get_ip_addrs is deleted but its static pointer is not set to NULL. This leaves a dangling pointer that causes a double-free if net_connect_ethernet_shutdown is called subsequently (e.g., during manual cleanup).

Fix in Cursor Fix in Web

#if CONFIG_NET_CONNECT_CONNECT_IPV6
xSemaphoreTake(s_semph_get_ip6_addrs, portMAX_DELAY);
#endif
return ESP_OK;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Ethernet connection hangs indefinitely if no IP

The net_connect_ethernet_connect function waits on s_semph_get_ip_addrs with portMAX_DELAY. If the Ethernet link is down or DHCP fails, the semaphore is never given, causing the application to hang indefinitely without a timeout or error return.

Fix in Cursor Fix in Web

/* tear down connection, release resources */
void net_connect_thread_shutdown(void)
{
vTaskDelete(s_ot_task_handle);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Shutdown function deletes calling task if uninitialized

vTaskDelete is called on s_ot_task_handle without checking if it is NULL. If the OpenThread task was not successfully created (e.g., due to net_connect failure), this deletes the calling task (such as the main task), causing an unexpected system termination.

Fix in Cursor Fix in Web

@abhik-roy85 abhik-roy85 marked this pull request as draft November 20, 2025 12:06
Add new APIs for WiFi STA configuration:
- net_configure_wifi_sta() for configuration
- net_connect_wifi() for connection
- net_disconnect_wifi() for disconnection

Maintains backward compatibility with existing API.
- Remove redundant "CONNECT" prefix from all config option names
- Simplify WiFi connection to always use new API with auto-configuration
- Add backward compatibility mappings in sdkconfig.rename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant