Compare commits

...

346 Commits

Author SHA1 Message Date
david-cermak
7a203cf085 Merge pull request #921 from david-cermak/bump/console_ping
bump(console): 1.1.0 -> 1.2.0
2025-10-29 17:04:32 +01:00
David Cermak
2e269640c6 bump(console): 1.1.0 -> 1.2.0
1.2.0
Features
- Add support for interface argument (90ddb04e)
2025-10-27 14:34:59 +01:00
david-cermak
c078c36361 Merge pull request #886 from david-cermak/feat/console_ping_interface
[console_ping]: Add support for interface argument
2025-10-24 15:17:14 +02:00
David Cermak
90ddb04e53 feat(console_ping): Add support for interface argument 2025-10-24 15:12:05 +02:00
david-cermak
cee3bdea9d Merge pull request #822 from tanyanquan/feat/support_null_value_txt
feat(mdns): support null value for boolean txt records
2025-10-24 14:05:47 +02:00
Tan Yan Quan
fa96de3bd7 feat(mdns): support null value for boolean txt records 2025-10-24 16:12:10 +08:00
bryghtlabs-richard
18f0d02806 feat(websocket): add WEBSOCKET_EVENT_HEADER_RECEIVED (#827)
Send a new event for each HTTP header-line received.

Depends on https://github.com/espressif/esp-idf/pull/16119
Closes https://github.com/espressif/esp-protocols/issues/715
2025-10-22 18:25:31 -03:00
david-cermak
bfa604b5f6 Merge pull request #904 from david-cermak/feat/add_tests_v1.9
[mdns]: Add tests for recent feats/fixes
2025-10-22 11:07:59 +02:00
David Cermak
92a31187ff fix(ci): Use python venv for mdns target tests 2025-10-21 17:16:21 +02:00
David Cermak
0197c994ee fix(mdns): Temporary fix for build issues on IDF master 2025-10-21 17:11:46 +02:00
David Cermak
487a746d14 fix(mdns): Add tests for delegated answers 2025-10-21 17:11:46 +02:00
David Cermak
af6bb1b5ee fix(mdns): Add fuzzing into mdns CI 2025-10-21 17:11:46 +02:00
Suren Gabrielyan
f5e62e83e9 Merge pull request #902 from gabsuren/docs/readme_update
[examples]: enhance example with docs, pytest setup, and standalone test server(IDFGH-16585)
2025-10-21 13:07:38 +04:00
surengab
cad527d2fc feat(examples): enhance example with docs, pytest setup, and standalone test server
- Add comprehensive README with TOC and quick start
    - Add pytest setup and certificate generation scripts
    - Add standalone WebSocket test server with TLS support
    - Add troubleshooting and multiple testing approaches
2025-10-21 12:17:00 +04:00
david-cermak
16cc2dcffb Merge pull request #914 from david-cermak/fix/modem_forwardport_patch
[modem]: Forward-port 1.4.1 patches
2025-10-21 07:14:47 +02:00
david-cermak
d622e41a54 Merge pull request #915 from david-cermak/fix/target_tests
[websockets]: Fix target tests
2025-10-21 07:14:28 +02:00
glmfe
ca6e39aac7 ci(common): Ignore ethernet warning. 2025-10-20 16:27:57 +02:00
David Cermak
e45944e143 fix(websocket): Use venv for running target tests 2025-10-20 16:27:22 +02:00
David Cermak
fe657b9737 fix(modem): Ignore more build warnings 2025-10-20 09:35:00 +02:00
David Cermak
453be4cd79 fix(modem): Fix modem console dependencies 2025-10-20 09:34:15 +02:00
David Cermak
018ba58ec5 fix(modem): Address build issues 2025-10-20 09:30:47 +02:00
David Cermak
67c682d911 fix(modem): Fix driver dependency issue on v6.0 2025-10-20 09:30:41 +02:00
Suren Gabrielyan
91915ce1c7 Merge pull request #901 from bryghtlabs-richard/fix/websocket-asprintf-ret-checks
fix(websocket): fix relying on asprintf() to NULL strp on failure (IDFGH-16595)
2025-10-15 14:27:56 +04:00
david-cermak
ae052e5507 Merge pull request #905 from david-cermak/fix/eppp_netif_rx_err
[eppp]: Fix tun netif to (optionally) return errors
2025-10-09 14:03:03 +02:00
David Cermak
44524f5de0 bump(eppp): 1.1.2 -> 1.1.3
1.1.3
Bug Fixes
- Fix test dependency issue on driver (1ace92c2)
- Fix tun netif to (optionally) return errors (7a6cf0f9)
2025-10-09 13:04:46 +02:00
David Cermak
1ace92c279 fix(eppp): Fix test dependency issue on driver 2025-10-09 13:03:06 +02:00
David Cermak
7a6cf0f9c0 fix(eppp): Fix tun netif to (optionally) return errors 2025-10-08 16:20:18 +02:00
Richard Allen
54eb002758 fix(websocket): fix relying on asprintf() to NULL strp on failure
asprintf()'s return value:
    When successful, these functions return the number of bytes
    printed, just like sprintf(3).  On error, -1 is returned, errno is
    set to indicate the error, and the contents of strp are undefined.

Fixes the following:
    error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
2025-10-03 08:44:00 -05:00
Guilherme Alves Ferreira
318e41b3c3 fix(lws): Update websocket Echo server (#894)
* fix(lws): Update websocket Echo server

- Update Websocket Echo Server, "wss://echo.websocket.events" is no longer available.
2025-10-03 06:17:11 -03:00
david-cermak
6f6237a0cc Merge pull request #813 from tanyanquan/master
fix(mdns): put srv/txt records in additional section for ptr queries
2025-10-01 13:59:03 +02:00
Guilherme Alves Ferreira
18faeb3dfa fix(websocket): Update Remaining Websocket Echo Server (#893) 2025-10-01 07:52:42 -03:00
Guilherme Alves Ferreira
296123c14e Merge pull request #896 from glmfe/fix/ignore-ci-build-warnings
ci(common): Ignore deprecated idf-build-apps parameters
2025-09-30 10:50:22 -03:00
glmfe
4e178f06bd ci(common): Ignore deprecated idf-build-apps parameters
- Added deprecated flash, sign and extract_public_key to global warning list file
2025-09-29 08:21:50 -03:00
Guilherme Alves Ferreira
5ab7e8327e Merge pull request #729 from DazeTechnology/fix/websocket_long_stop
fix(websocket): avoid long stop time when waiting to auto-reconnect (IDFGH-14393)
2025-09-25 10:12:39 -03:00
Paolo Pasinetti
91e7e9fa08 chore(lws): fixed formatting 2025-09-19 15:42:33 +02:00
Paolo Pasinetti
ff5d6021be chore(asio): Fixed formatting 2025-09-19 15:42:33 +02:00
Paolo Pasinetti
2432e41dcb fix(websocket): avoid long stopping time when waiting to auto-reconnect
This commit fixes an issue that occurred when auto-reconnection is enabled,
and the client is disconnected from the server. In this situation, if the
esp_websocket_client_stop() method is called, the caller could remain stuck
waiting for a maximum time equal to half of wait_timeout_ms.

This fix allows the esp_websocket_client_task to be woken up when it is
waiting to reconnect, so it can be closed promptly when requested.
2025-09-19 15:42:33 +02:00
Guilherme Alves Ferreira
870ac91db7 Merge pull request #890 from glmfe/fix/update-ws-echo-server
fix(websocket): Update Websocket Echo Server
2025-09-19 08:35:01 -03:00
glmfe
94bd5b074a fix(websocket): Update Websocket Echo Server 2025-09-19 07:44:12 -03:00
david-cermak
db7baaffba Merge pull request #887 from david-cermak/fix/eppp_uart_deps
[eppp]: Fix uart driver deps with new IDF
2025-09-15 13:41:53 +02:00
David Cermak
1ea93a866b bump(eppp): 1.1.1 -> 1.1.2
1.1.2
Bug Fixes
- Update uart driver deps per IDF > v5.3 (92e14607)
2025-09-15 12:55:14 +02:00
David Cermak
92e1460721 fix(eppp): Update uart driver deps per IDF > v5.3 2025-09-15 12:55:08 +02:00
david-cermak
858d38b55f Merge pull request #885 from david-cermak/fix/eppp_uart_channels
[eppp]: Fix getting context for channel API
2025-09-09 17:03:00 +02:00
David Cermak
6428e68c8e bump(eppp): 1.1.0 -> 1.1.1
1.1.1
Bug Fixes
- Fix getting context for channel API (94563cdc)
- Cover more combinations in build tests (e0b8de8f)
2025-09-09 16:18:11 +02:00
David Cermak
94563cdc1f fix(eppp): Fix getting context for channel API 2025-09-09 13:42:18 +02:00
David Cermak
e0b8de8f38 fix(eppp): Cover more combinations in build tests 2025-09-09 13:42:18 +02:00
Guilherme Alves Ferreira
34b6681576 Merge pull request #771 from glmfe/feat/add-http-redir
feat(websocket): Add websocket HTTP redirect
2025-09-03 12:31:20 -03:00
david-cermak
1f7828f629 Merge pull request #875 from david-cermak/update/eppp_v1.1
[eppp]: Bump 1.0.1 -> 1.1.0
2025-09-03 16:03:05 +02:00
david-cermak
e74db36ebb Merge pull request #881 from david-cermak/fix/minor_ci_fixes
Fixup common CI issues with v6.0 idf-tools
2025-09-03 13:16:49 +02:00
David Cermak
f8d2ed2eed fix(tls_cxx): Remove unnnecessary warning ignore 2025-09-03 12:07:21 +02:00
David Cermak
8bba3a9734 fix(mdns): Host test to use hw_support include dir 2025-09-03 11:37:47 +02:00
David Cermak
9fbb6e6d0a fix(mosq): Fix the version check 2025-09-03 10:20:53 +02:00
David Cermak
e599cd826b fix(common): Fixup common CI issues with v6.0 2025-09-03 10:06:13 +02:00
david-cermak
e2d36b4fbd Merge pull request #879 from david-cermak/fix/modem_sim_napt
[modem_sim]: Enable LWIP-NAPT by default in modem simulator
2025-09-03 09:27:41 +02:00
david-cermak
82a784baf4 Merge pull request #880 from david-cermak/fix/modem_ci
[modem]: Fix recent CI issues
2025-09-02 18:01:05 +02:00
David Cermak
15140e04c6 fix(modem): Fix CI build issues with IDFv6.0
* Fix C++ console struct init in examples
* VFS deprecation in tests
* Add conditional defines over wakeup-cause
2025-09-02 15:47:00 +02:00
glmfe
ce1560acb1 feat(websocket): Add websocket HTTP redirect
- Handle 301 status (moved permanently) and redirect the connection to the new host.
2025-09-02 09:52:20 -03:00
David Cermak
e1be830fb7 fix(modem_sim): Enable LWIP-NAPT by default in modem simulator
As this mode is used by PPP clients
2025-09-01 18:47:47 +02:00
david-cermak
b7cfa31a0b Merge pull request #878 from david-cermak/bump/mosq_2.0.20.4
bump(mosq): 2.0.20~3 -> 2.0.20~4
2025-09-01 11:54:20 +02:00
David Cermak
845a1e2ef8 fix(mosq): Skip serverless example build on master
Due to esp-peer's long list dependencies, which are usually based
from stable IDF releases
2025-09-01 10:08:11 +02:00
David Cermak
6ae7a4d2ba bump(mosq): 2.0.20~3 -> 2.0.20~4
2.0.20~4
Features
- Update brokerless example to work with esp-peer (76e45f72)
Bug Fixes
- drop newlib from PRIV_REQUIRES (6318022c)
- Make esp-peer build optional (03df9ae9)
- Fix esp_webRTC deprecation with new FreeRTOS (78ae2559)
2025-09-01 09:55:34 +02:00
david-cermak
4d52982a69 Merge pull request #876 from Lapshin/master
fix: drop newlib from PRIV_REQUIRES
2025-09-01 09:27:09 +02:00
Alexey Lapshin
6318022cda fix: drop newlib from PRIV_REQUIRES 2025-08-28 16:18:22 +07:00
David Cermak
13591ade3d bump(eppp): 1.0.1 -> 1.1.0
1.1.0
Features
- Add support for UART flow control (cd57f1bb, #870)
Bug Fixes
- Fix SPI transport to allow already init GPIO ISR (497ee2d6, #868)
- Fix stack-overflow in ping task for TUN netif (b2568a3d, #867)
Updated
- ci(common): Update test component dir for IDFv6.0 (18418c83)
2025-08-27 15:11:15 +02:00
david-cermak
d09b302b9e Merge pull request #872 from david-cermak/fix/eppp_minor_fixes
[eppp]: Minor fixes v1.0
2025-08-27 08:57:25 +02:00
david-cermak
39e2333adb Merge pull request #871 from david-cermak/fix/modem_sim_docs
[modem_sim]: Add initial modem simulator docs
2025-08-26 11:00:46 +02:00
David Cermak
cd57f1bb13 feat(eppp): Add support for UART flow control
Closes https://github.com/espressif/esp-protocols/issues/870
2025-08-25 16:30:57 +02:00
David Cermak
497ee2d6d4 fix(eppp): Fix SPI transport to allow already init GPIO ISR
Closes https://github.com/espressif/esp-protocols/issues/868
2025-08-25 15:23:07 +02:00
David Cermak
b2568a3d83 fix(eppp): Fix stack-overflow in ping task for TUN netif
Closes https://github.com/espressif/esp-protocols/issues/867
2025-08-25 14:51:59 +02:00
david-cermak
58a21e39d0 Merge pull request #837 from david-cermak/feat/modem_tcp_client_extend
[modem]: Extend tcp-client example
2025-08-25 08:53:51 +02:00
David Cermak
9c7ee07755 feat(modem_sim): Add initial modem simulator docs 2025-08-25 08:52:48 +02:00
David Cermak
14d3cb6bd1 fix(modem): Add support for ESP-AT based tcp-client example 2025-08-25 06:38:57 +02:00
david-cermak
ccdb45ee94 Merge pull request #869 from david-cermak/fix/test_build_v6.0
fix(CI): Fix test component dir after IDFv6.0 update
2025-08-22 15:01:59 +02:00
David Cermak
18418c83ff ci(common): Update test component dir for IDFv6.0
Update websocket, mdns and eppp test apps
2025-08-22 14:23:43 +02:00
david-cermak
ecb7dae502 Merge pull request #863 from david-cermak/feat/modem_without_ppp
[modem]: Support esp-modem use without PPP
2025-08-21 12:46:29 +02:00
david-cermak
958ff6a584 Merge pull request #866 from david-cermak/fix/modem_sim
[modem_sim]: ESP-AT build failure on v5.4
2025-08-18 17:12:53 +02:00
David Cermak
5ea83be7ce fix(modem_sim): Fix build step 2025-08-18 16:35:07 +02:00
david-cermak
33a3ec54b6 Merge pull request #865 from david-cermak/fix/eppp_ipv4_only
[eppp]: Support for IPv4-only mode
2025-08-18 12:03:07 +02:00
David Cermak
c91578c827 bump(eppp): 1.0.0 -> 1.0.1
1.0.1
Bug Fixes
- Support for IPv4-only mode (653328ba, #864)
2025-08-18 11:09:33 +02:00
David Cermak
653328ba07 fix(eppp): Support for IPv4-only mode
Closes https://github.com/espressif/esp-protocols/issues/864
2025-08-18 11:03:17 +02:00
David Cermak
858f85706d feat(modem): Support esp-modem use without PPP
Closes https://github.com/espressif/esp-protocols/issues/851
2025-08-14 17:29:50 +02:00
david-cermak
f8748e026d Merge pull request #862 from david-cermak/fix/mbedtls_cookie
fix(mbedtls_cxx): Enable mbedtls cookie support
2025-08-13 12:41:48 +02:00
David Cermak
479122b21d fix(mbedtls_cxx): Enable mbedtls cookie support 2025-08-13 12:05:14 +02:00
david-cermak
e8ce8f4739 Merge pull request #861 from david-cermak/fix/minor_links
fix(ci): Use default mqtt public endpoint
2025-08-12 16:23:12 +02:00
David Cermak
03df9ae957 fix(mosq): Make esp-peer build optional 2025-08-12 16:07:02 +02:00
David Cermak
35fa0b1d42 ci(common): Fix the link to CONTRIBUTING guidelines 2025-08-12 14:29:08 +02:00
David Cermak
e9d9b3a8bd fix(modem): Use idf-build-apps for building target tests
Also updates default mqtt broker public endpoint
2025-08-12 14:29:03 +02:00
Euripedes
07e8eddcb6 Merge pull request #856 from david-cermak/fix/mosquitto_build
[mosq]: Fix esp_webRTC-lib deprecation with new FreeRTOS
2025-07-29 08:06:05 +02:00
David Cermak
78ae25598b fix(mosq): Fix esp_webRTC deprecation with new FreeRTOS 2025-07-25 18:55:59 +02:00
david-cermak
ffeee3e87a Merge pull request #852 from david-cermak/fix/mqtt_endpoints
fix(examples): Address MQTT public endpoint availability
2025-07-25 16:04:24 +02:00
David Cermak
6d5411941b fix(modem): Make MQTT public broker endpoint configurable 2025-07-25 11:02:36 +02:00
David Cermak
e71365f835 fix(examples): Use configured public broker for MQTT linux test
Also updated pre-commit hook versions, as some don't work in py3.12
2025-07-25 11:01:53 +02:00
david-cermak
8dbf0e4561 Merge pull request #855 from cosmicKev/mdns-fix-custom-allocator
Fixes case where we create our own malloc/free allocators, therefore … (IDFGH-16053)
2025-07-25 07:48:09 +02:00
kevin filipe
63bf70914b fix(mdns): Fixes case where we create our own malloc/free allocators, therefore we need to call mdns_mem_free and not free 2025-07-24 13:21:55 +02:00
Guilherme Alves Ferreira
29f1dec408 Merge pull request #854 from glmfe/master
bump(websocket): 1.4.0 -> 1.5.0
2025-07-23 08:45:59 -03:00
glmfe
05715d80d7 bump(websocket): 1.4.0 -> 1.5.0
1.5.0
Features
- add separate tx lock for send and receive (250eebf)
- add unregister event to websocket client (ce16050)
- add ability to reconnect after close (19891d8)
Bug Fixes
- release client-lock during WEBSOCKET_EVENT_DATA (030cb75)
2025-07-22 17:54:02 -03:00
Guilherme Alves Ferreira
75d6845194 Merge pull request #850 from shootao/feat/add_ws_tx_lock
esp_websocket: add_ws_tx_lock (IDFGH-15952)
2025-07-21 08:08:13 -03:00
xutao
250eebf3fc feat(websocket): add separate tx lock for send and receive 2025-07-21 10:46:55 +08:00
david-cermak
84b61dca16 Merge pull request #840 from david-cermak/feat/mosq_esp_peer
[mosq]: Add support for esp-peer in brokerless example
2025-07-18 13:13:27 +02:00
David Cermak
76e45f7254 feat(mosq): Update brokerless example to work with esp-peer
* Relax CI criteria to build on v5.2+ (for the brokerless due to
  esp-peer dependency)
2025-07-18 12:49:34 +02:00
Euripedes
462561b8d9 Merge pull request #843 from david-cermak/fix/example_mqtt
[examples]: Use another public broker for MQTT example
2025-07-15 08:44:34 +02:00
David Cermak
ae8cf218c8 fix(examples): Use another public broker for MQTT example 2025-07-11 19:00:28 +02:00
david-cermak
c340f85a90 Merge pull request #836 from david-cermak/fix/modem_urc
[modem]: Fix URC handler processing
2025-07-11 18:14:08 +02:00
David Cermak
b95d8be41d fix(modem_sim): Support of PPPD exit 2025-07-11 17:37:51 +02:00
David Cermak
9302994673 fix(modem): Fix URC handling in DTE data callback
This partially revert 6eceb28f7d
and fixes URC handling and passing full buffer to higher layers
2025-07-11 11:01:28 +02:00
David Cermak
e5787e3d9f feat(modem_sim): Modem simulator based on esp-at 2025-07-11 11:01:17 +02:00
david-cermak
7cddc8c6f5 Merge pull request #834 from david-cermak/fix/modem_build_new_gcc
[modem]: Fix to use compatible iterator types for std::search in new gcc
2025-07-11 09:29:00 +02:00
David Cermak
fac2edbe59 fix(modem): Use another public broker for examples and tests
since mqtt.eclipseprojects.io is no longer available
2025-07-11 08:16:17 +02:00
David Cermak
ed0f633418 fix(modem): Fix incompatible iterator in std::search() in new gcc
Creates a temporary string view and uses find() instead.
2025-07-11 08:15:53 +02:00
david-cermak
a8631eecf5 Merge pull request #814 from david-cermak/feat/eppp_channels
[eppp-link]: Support for channels
2025-07-10 14:45:29 +02:00
David Cermak
3e28a7264c bump(eppp): 0.3.1 -> 1.0.0
1.0.0
Features
- Add support for custom channels (4ee9360f)
2025-07-10 13:57:13 +02:00
David Cermak
4ee9360f53 feat(eppp): Add support for custom channels 2025-07-10 13:55:46 +02:00
david-cermak
e9b21ea7a3 Merge pull request #833 from david-cermak/fix/mosq_minor
[mosq]: Fix some recent bugs
2025-07-01 12:41:01 +02:00
David Cermak
ac1b2b7573 bump(mosq): 2.0.20~2 -> 2.0.20~3
2.0.20~3
Bug Fixes
- Support build on older IDF branches (13b90ad1)
- Fix misleading error when accepting connection (fd410061, #807)
- Make mosquitto component c++ compatible (c4169765, #817)
- include config.h before any system header (1b1ede43)
2025-07-01 12:20:45 +02:00
David Cermak
13b90ad14b fix(mosq): Support build on older IDF branches
and added build jobs to CI
2025-07-01 12:18:08 +02:00
David Cermak
fd41006193 fix(mosq): Fix misleading error when accepting connection
Closes https://github.com/espressif/esp-protocols/issues/807
2025-07-01 11:31:32 +02:00
Euripedes
e71926f6ed Merge pull request #752 from bryghtlabs-richard/feat/websocketReconnectOnClose
feat(websocket): add ability to reconnect after close (IDFGH-15455)
2025-06-27 14:31:16 +02:00
c4169765af fix(mosq): Make mosquitto component c++ compatible
Closes https://github.com/espressif/esp-protocols/issues/817
Closes https://github.com/espressif/esp-protocols/issues/816
2025-06-27 12:36:16 +02:00
david-cermak
f43dd5012f Merge pull request #829 from david-cermak/fix/modem_get_network_state
[modem]: Fix get_network_registration_state() to accept two params
2025-06-25 12:35:45 +02:00
david-cermak
b143894874 Merge pull request #821 from lolrobbe2/fix-urc-line-handler-modem
fix(modem): Consume buffer after handled URC
2025-06-24 10:22:45 +02:00
david-cermak
d1c912c833 Merge pull request #830 from david-cermak/fix/dns_http_event
[dns]: Fix http event handler to accept default case
2025-06-24 10:21:16 +02:00
David Cermak
4fbd86b278 fix(dns): Fix http event handler to accept default case 2025-06-24 09:52:38 +02:00
david-cermak
af8272d441 Merge pull request #825 from david-cermak/fix/modem_auto_mode
[modem]: Fix autodetect to support ACFC mode in PPP frames
2025-06-24 09:09:01 +02:00
David Cermak
8b328a6904 fix(modem): Fix autodetect to support ACFC mode in PPP frames
Closes https://github.com/espressif/esp-protocols/issues/801
2025-06-23 17:13:32 +02:00
David Cermak
5f54d9075e fix(modem): Fix get_network_registration_state() to accept two params
Co-authored-by: Beernaert Robbe <robbe.beernaert@student.howest.be>
Closes https://github.com/espressif/esp-protocols/issues/826
2025-06-23 11:10:36 +02:00
david-cermak
01952f21cb Merge pull request #824 from david-cermak/fix/mdns_host_test
[mdns]: Fix host tests by freezing idf-build-apps to 2.10
2025-06-17 12:43:25 +02:00
David Cermak
5dfe076c94 fix(mdns): Fix host tests by freezing idf-build-apps to 2.10 2025-06-12 17:47:24 +02:00
david-cermak
ea9f29ad14 Merge pull request #823 from david-cermak/fix/eppp_without_pppos
[eppp]: Fix NETIF_PPP_STATUS link issue if PPP disabled in lwip
2025-06-12 14:20:05 +02:00
David Cermak
217e6d90c8 bump(eppp): 0.3.0 -> 0.3.1
0.3.1
Bug Fixes
- Fix NETIF_PPP_STATUS link issue if PPP disabled in lwip (077ea0bb)
2025-06-12 13:53:42 +02:00
David Cermak
077ea0bb1f fix(eppp): Fix NETIF_PPP_STATUS link issue if PPP disabled in lwip 2025-06-12 13:53:20 +02:00
david-cermak
a74b01e7e3 Merge pull request #812 from david-cermak/feat/eppp_transports
feat(eppp): Add support for TUN interface
2025-06-12 12:39:21 +02:00
David Cermak
c5a4a51d82 bump(eppp): 0.2.0 -> 0.3.0
0.3.0
Features
- Add support for TUN interface (2ff150c3)
- Add support for transport via Ethernet link (a21ce883)
2025-06-12 11:59:56 +02:00
David Cermak
2ff150c310 feat(eppp): Add support for TUN interface
* Implement factory pattern
* Make netif type configurable (PPP vs. TUN)
* Use ICMP for TUN netif connection
* Relax deps criteria (mainly for Ethernet)use the tun feature
2025-06-12 11:59:17 +02:00
robbedptechnics
6eceb28f7d fix(modem): Consume buffer after handled URC 2025-06-11 14:50:14 +02:00
Tan Yan Quan
b7b8c5dbd7 fix(mdns): put srv/txt records in additional section for ptr queries 2025-05-08 19:09:52 +08:00
Euripedes
b8cdd373f4 Merge pull request #809 from david-cermak/fix/mqtt_cxx_clang_tidy_warns
fix(mqtt_cxx): Fix clang-tidy warnings with C++ exceptions
2025-05-06 14:29:57 +02:00
david-cermak
66a5ac0190 Merge pull request #808 from Lapshin/master
fix(mosq): include config.h before any system header (IDFGH-15223)
2025-05-02 10:26:41 +02:00
David Cermak
40cce5e926 fix(mqtt_cxx): Fix clang-tidy warnings with C++ exceptions 2025-05-02 10:18:40 +02:00
Alexey Lapshin
1b1ede435d fix(mosq): include config.h before any system header 2025-05-01 23:58:53 +07:00
david-cermak
c6f08ee961 Merge pull request #622 from david-cermak/feat/eppp_emac2emac
[eppp]: Support for transport via Ethernet (phy or emac)
2025-04-30 12:32:48 +02:00
David Cermak
a21ce883ef feat(eppp): Add support for transport via Ethernet link 2025-04-30 11:56:40 +02:00
david-cermak
79d6fa2607 Merge pull request #806 from david-cermak/fix/clang_tidy_disable_lws
fix(lws): Remove clang tidy checks
2025-04-29 14:30:26 +02:00
David Cermak
ad90558420 fix(lws): Remove clang tidy checks
Since lws hardcodes some flags in CMakeLists.txt, which causes compilation issues
with mbedtls, generated lws_config.h and -mlongcalls
2025-04-25 16:50:13 +02:00
Abhik Roy
8541753443 Merge pull request #781 from espressif-abhikroy/component/esp_dns
feat(common): Add ESP DNS module with support for UDP, DoT, and DoH protocols
2025-04-18 21:37:32 +10:00
Abhik Roy
6660f71d03 bump(dns): First version [1.0.0]
1.0.0
Features
- Add ESP DNS module with support for UDP, TCP, DoT, and DoH protocols (57cd6080)
2025-04-16 22:03:33 +10:00
Abhik Roy
57cd60807e feat(dns): Add ESP DNS module with support for UDP, TCP, DoT, and DoH protocols
This commit introduces a custom DNS module for ESP32, enabling DNS resolution capabilities
over various protocols including UDP, TCP, DNS over TLS (DoT), and DNS over HTTPS (DoH).
The module includes initialization and cleanup functionalities, along with
protocol-specific implementations for each DNS type.
2025-04-16 21:30:06 +10:00
david-cermak
03dd8006b2 Merge pull request #798 from david-cermak/fix/lws_clang_tidy
[lws]: Fix many file-not-found errors on clang-tidy job
2025-04-10 17:41:32 +02:00
Guilherme Alves Ferreira
3863c26b79 Merge pull request #704 from bryghtlabs-richard/fix/websocketWriterLag
fix(websocket): release client-lock during WEBSOCKET_EVENT_DATA (IDFGH-14545)
2025-04-10 12:16:31 -03:00
david-cermak
1d1ff365c2 Merge pull request #797 from david-cermak/fix/asio_certs
[asio]: Fixed TLS server-client example failure
2025-04-10 14:50:37 +02:00
David Cermak
ef3870573c fix(lws): Fix many file-not-found errors on clang-tidy job 2025-04-10 12:49:46 +02:00
David Cermak
ad94cc9502 feat(asio): Add mbedtls specific APIs to use TLS stack specific features
Use mbedtls specific API to configure hostname for verification
2025-04-08 17:08:27 +02:00
David Cermak
4885d28294 fix(asio): Fixed TLS server-client example failure per cert expiry 2025-04-07 12:01:30 +02:00
david-cermak
df00a03084 Merge pull request #685 from david-cermak/fix/modem_generate_code
[modem]: Use pre-generated command declarations to improve IDE navigation
2025-04-04 16:25:27 +02:00
David Cermak
e2fa11103c fix(modem): Use generated AT command definitions for IDE navigation
BREAKING CHANGE: inc headers for AT command definitions are no longer used directly, but pregenerated into *.h(pp)
2025-04-04 15:39:39 +02:00
david-cermak
d2e94e5db2 Merge pull request #609 from david-cermak/fix/example_multinetif
[examples]: Make multi-netif example working with DNS_PER_DEFAULT_NETIF
2025-04-02 07:54:49 +02:00
David Cermak
bc8ac4c684 fix(examples): Make multi-netif example working with DNS_PER_DEFAULT_NETIF feature 2025-04-01 12:39:37 +02:00
david-cermak
b710dbd2ad Merge pull request #793 from david-cermak/fix/modem_bump
[modem]: Bump 1.3.0 -> 1.4.0
2025-03-28 14:57:48 +01:00
David Cermak
5eeb29cb94 bump(modem): 1.3.0 -> 1.4.0
1.4.0
Features
- added config_edrx api function (74b7d85d)
- added sqn_gm02s connect function (b97dfc08)
- add support for sequans GM02S modem (8560f021)
Bug Fixes
- Fix cmux log message (6ed672da)
- fixed minor code mistakes. (317faf89)
- handle nullptr in DTE constructors to prevent invalid access (95b56600)
2025-03-28 13:47:52 +01:00
david-cermak
a00117fbdb Merge pull request #790 from david-cermak/fix/modem_cmux_log_pr
[modem]: Fix cmux log message
2025-03-28 08:51:37 +01:00
term-est
6ed672da7b fix(modem): Fix cmux log message 2025-03-26 18:20:03 +01:00
david-cermak
1b4baaed0e Merge pull request #786 from robbedptechnics/support-sqn-gm02s
feat(module): add support for sequans GM02S modem (DPTechnics) (IDFGH-14891)
2025-03-25 12:24:51 +01:00
robbedptechnics
74b7d85d4a feat(modem): added config_edrx api function 2025-03-25 11:28:16 +01:00
robbedptechnics
317faf89ff fix(modem): fixed minor code mistakes. 2025-03-25 11:27:14 +01:00
robbedptechnics
b97dfc08b8 feat(modem): added sqn_gm02s connect function 2025-03-25 11:25:07 +01:00
david-cermak
e9d7350219 Merge pull request #784 from david-cermak/fix/mdns_fuzz_issue
[mdns]: Fix parsing incorrect txt records
2025-03-21 13:11:28 +01:00
David Cermak
61da30b013 bump(mdns): 1.8.1 -> 1.8.2
1.8.2
Bug Fixes
- Fix parsing incorrect txt records (8fd2c99f)
2025-03-21 12:40:42 +01:00
David Cermak
8fd2c99f15 fix(mdns): Fix parsing incorrect txt records
Issue discovered when fuzzing packet parser,
received packet with inconsistent txt section caused issues on final cleanup
2025-03-21 12:40:12 +01:00
robbedptechnics
8560f02191 feat(module): add support for sequans GM02S modem 2025-03-19 14:45:32 +01:00
david-cermak
703c49297f Merge pull request #785 from david-cermak/fix/mosq_test
[mosq]: Fix pytest to use latest embedded packages
2025-03-19 10:25:00 +01:00
David Cermak
2fe8345fa5 fix(mosq): Fix pytest to use latest embedded packages 2025-03-19 08:49:22 +01:00
david-cermak
3fc26a5e5c Merge pull request #780 from david-cermak/fix/mdns_task_delete_race
[mdns]: Fix potential task delete race
2025-03-17 11:31:00 +01:00
David Cermak
5db6be7422 bump(mdns): 1.8.0 -> 1.8.1
1.8.1
Bug Fixes
- Fix potential task delete race (8ca45f34)
2025-03-17 10:51:14 +01:00
David Cermak
8ca45f34fa fix(mdns): Fix potential task delete race
Need to wait for the task to be deleted before destroy its stack
2025-03-17 10:51:02 +01:00
Euripedes
2e28774228 Merge pull request #775 from euripedesrocha/feature/mosquitto_plugin
Add config to enable SYS on mosquito and bump version
2025-03-06 14:48:20 -03:00
Euripedes Rocha
e14e21ab32 bump(mosq): 2.0.20~1 -> 2.0.20~2
##
[2.0.20~2](https://github.com/espressif/esp-protocols/commits/mosq-v2.0.20_2)###
Features- Allow user to enable SYS topic
([905b84fb](https://github.com/espressif/esp-protocols/commit/905b84fb))###
Bug Fixes- Remove temp modification of IDF files
([9162de11](https://github.com/espressif/esp-protocols/commit/9162de11))-
Add a note about stack size
([dbd164dd](https://github.com/espressif/esp-protocols/commit/dbd164dd))
2025-03-06 11:14:26 +01:00
david-cermak
6f00c369fc Merge pull request #774 from david-cermak/ci/fix_deprecated_containers
ci(common): Remove deprecated CI runners on ubuntu-20.04
2025-03-05 15:52:35 +01:00
Euripedes Rocha
905b84fb97 feat(mosq): Allow user to enable SYS topic
Mosquitto provides several topics under $SYS/# to capture logs and load
statistics. This allows users to enable it.
2025-03-05 15:03:59 +01:00
David Cermak
d7f5322a39 ci(common): Remove deprecated CI runners on ubuntu-20.04 2025-03-04 16:11:51 +01:00
david-cermak
eb12d05bf3 Merge pull request #773 from david-cermak/fix/mdns_add_version_macro
[mdns]: Bump 1.7.0 -> 1.8.0
2025-03-04 15:59:54 +01:00
David Cermak
520b8194fc fix(common): Fix clang-tidy runner to use supported versions 2025-03-04 15:29:38 +01:00
David Cermak
40142cdcfd bump(mdns): 1.7.0 -> 1.8.0
1.8.0
Features
- Add version keys (e01e67e7)
Bug Fixes
- Reformat mdns sources per indent-cont=120 (c7663cde)
2025-03-04 15:20:49 +01:00
David Cermak
c7663cdef2 fix(mdns): Reformat mdns sources per indent-cont=120 2025-02-27 10:42:03 +01:00
Adrian Scillato
e01e67e7eb feat(mdns): Add version keys 2025-02-27 10:33:53 +01:00
david-cermak
37f84ee5a4 Merge pull request #768 from deodatomatheus/fix/handle-nullptr-dte-constructors
fix(modem): handle nullptr in DTE constructors to prevent invalid access (IDFGH-14688)
2025-02-27 09:19:16 +01:00
Matheus Deodato
95b56600ed fix(modem): handle nullptr in DTE constructors to prevent invalid access 2025-02-26 11:37:02 -03:00
david-cermak
a22c3da49e Merge pull request #762 from david-cermak/fix/examples_target_tests
[examples]: Test the SLIP netif example on target as well
2025-02-20 14:32:54 +01:00
david-cermak
5d0fd5c1c5 Merge pull request #770 from david-cermak/fix/lws_license
[lws]: Adds missing license info
2025-02-20 14:17:47 +01:00
David Cermak
7ea6879a19 fix(lws): Adds missing license info 2025-02-20 12:34:40 +01:00
David Cermak
2db11bbb8c fix(examples): Fix SLIP netif example to make esp_netif use special netif
by enabling PPP netif, so esp_netif knows that lwip's netif->state
will be reserved for special netif info (slip)

Closes https://github.com/espressif/esp-protocols/issues/759
2025-02-20 11:58:54 +01:00
David Cermak
cdb7bfd188 fix(examples): Test the SLIP netif example on target as well 2025-02-20 11:58:49 +01:00
Guilherme Alves Ferreira
c679ceed85 Merge pull request #718 from glmfe/feat/lws
[lws]: Add initial support for libwebsockets
2025-02-19 11:26:03 -03:00
glmfe
c009892968 bump(lws): First version 4.3.3
4.3.3
Features
- Add initial support libwebsockets component (ef3443d)
2025-02-19 10:21:35 -03:00
glmfe
5f66f35f5f feat(lws): Add initial support libwebsockets component 2025-02-19 10:16:42 -03:00
david-cermak
dea5f1c431 Merge pull request #764 from david-cermak/feat/mdns_malloc_caps
[mdns]: Allow allocate memory with configured caps
2025-02-18 13:23:41 +01:00
David Cermak
384d1c23ba bump(mdns): 1.6.0 -> 1.7.0
1.7.0
Features
- Support user defined allocators (88162d1f)
- Allow allocate memory with configured caps (7d29b476)
Bug Fixes
- Adjust some formatting per indent-cont=120 (5b2077e3)
2025-02-18 12:53:46 +01:00
David Cermak
88162d1f3a feat(mdns): Support user defined allocators
Defines mem-alloc function optionally weak, so users can override them
and implement their own allocation, or a static/bss memory for the mdns
task stack.
2025-02-18 12:52:21 +01:00
David Cermak
e65f22ab6c ci(mdns): Check mdns sources for std alloc functions 2025-02-13 15:02:18 +01:00
David Cermak
7d29b47676 feat(mdns): Allow allocate memory with configured caps 2025-02-13 13:51:22 +01:00
david-cermak
f1a72ec42c Merge pull request #760 from glmfe/feat/add-ws-unregister
feat(websocket): add unregister event to websocket client
2025-02-12 18:50:52 +01:00
glmfe
ce160505dc feat(websocket): add unregister event to websocket client 2025-02-12 08:46:39 -03:00
david-cermak
87e96b4682 Merge pull request #761 from david-cermak/fix/ci_astyle
[ci]: Fix pre-commit hook to call astyle correctly
2025-02-12 11:47:40 +01:00
David Cermak
5b2077e373 fix(common): Adjust some formatting per indent-cont=120
As we updated astyle configuration to be in line with IDF style
2025-02-12 11:40:21 +01:00
Richard Allen
030cb75ece fix(websocket): release client-lock during WEBSOCKET_EVENT_DATA
This resolves:

 1) Deadlock when trying to reserve a lock in WEBSOCKET_EVENT_DATA,
    but lock is held by a thread trying to send a websocket message.
 2) High latency caused by writers serialized with WEBSOCKET_EVENT_DATA
    while calling esp_websocket_client_send(), even when TCP window
    has enough space for the entire message being queued to send.

Multiple writers are still serialized at fragment boundaries, but
only with other writers and websocket error updates.

Fixes #625
2025-02-11 12:04:39 -06:00
David Cermak
b45fe143a4 ci(common): Fix pre-commit hook to call astyle correctly 2025-02-11 17:16:11 +01:00
david-cermak
ee2fbbbee7 Merge pull request #756 from david-cermak/feat/mdns_alloc_task
[mdns]: support allocating mDNS task with caps
2025-02-10 11:50:59 +01:00
David Cermak
cb061c9c38 bump(mdns): 1.5.3 -> 1.6.0
1.6.0
Features
- support allocating mDNS task from SPIRAM (8fcad10c)
Bug Fixes
- Use correct task delete function (eb4ab524)
Updated
- ci(mdns): Fix mdns host test layers with static task creation (0690eba3)
2025-02-10 11:18:55 +01:00
David Cermak
0690eba3a8 ci(mdns): Fix mdns host test layers with static task creation 2025-02-10 11:18:19 +01:00
David Cermak
eb4ab52487 fix(mdns): Use correct task delete function 2025-02-10 11:18:19 +01:00
zwx
8fcad10ccf feat(mdns): support allocating mDNS task from SPIRAM 2025-02-10 11:18:19 +01:00
david-cermak
936e43f9d8 Merge pull request #758 from david-cermak/fix/mdns_ignore_only_invalid_queries
[mdns]: Fix the responder to ignore only invalid queries
2025-02-07 15:11:14 +01:00
David Cermak
64d818b2d3 bump(mdns): 1.5.2 -> 1.5.3
1.5.3
Bug Fixes
- Fix responder to ignore only invalid queries (cd07228f, #754)
2025-02-07 14:31:18 +01:00
David Cermak
cd07228f81 fix(mdns): Fix responder to ignore only invalid queries
not the entire packet, so we can still reply to next questions

Closes https://github.com/espressif/esp-protocols/issues/754
2025-02-07 14:30:10 +01:00
david-cermak
1c6580e22b Merge pull request #753 from david-cermak/fix/ci_mosq
[mosquitto]: Fix minor CI issue
2025-02-03 14:54:07 +01:00
David Cermak
87f835af0f fix(mosq): Run IDF build test only on master or labeled PRs 2025-01-31 11:19:00 +01:00
Richard Allen
19891d8c3c feat(websocket): add ability to reconnect after close
Needed to support protocols like Socket.IO, where some
websocket closes issued by the server are reconnectable.
2025-01-30 12:12:12 -06:00
david-cermak
85a8dac42d Merge pull request #750 from david-cermak/bump/ws_client
[websocket]:  Bump 1.3.0 -> 1.4.0
2025-01-30 08:48:45 +01:00
David Cermak
39866116f5 bump(websocket): 1.3.0 -> 1.4.0
1.4.0
Features
- Support DS peripheral for mutual TLS (55385ec3)
Bug Fixes
- wait for task on destroy (42674b49)
- Fix pytest to verify client correctly (9046af8f)
- propagate error type (eeeb9006)
- fix example buffer leak (5219c39d)
Updated
- chore(websocket): align structure members (beb6e57e)
- chore(websocket): remove unused client variable (15d3a01e)
2025-01-30 07:16:24 +01:00
david-cermak
7740b591b6 Merge pull request #749 from david-cermak/fix/ws_client_test
[websocket]: Fix pytest to verify client correctly
2025-01-30 07:09:34 +01:00
david-cermak
b57979d967 Merge pull request #751 from johanstokking/fix/await-task-on-destroy
fix(websocket): wait for task on destroy (IDFGH-14533)
2025-01-29 15:27:38 +01:00
Johan Stokking
42674b49f9 fix(websocket): wait for task on destroy 2025-01-29 14:30:32 +01:00
david-cermak
e069ae7762 Merge pull request #520 from johanstokking/feature/websocket/client_ds_data
feat(websocket): Support DS peripheral for mutual TLS (IDFGH-12285)
2025-01-28 16:59:34 +01:00
Johan Stokking
44d476fc50 docs(websocket): fix minor readability issues 2025-01-28 14:59:24 +01:00
Johan Stokking
55385ec312 feat(websocket): Support DS peripheral for mutual TLS 2025-01-28 14:58:54 +01:00
david-cermak
a3c2bbed9e Merge pull request #748 from david-cermak/fix/mdns_coverity
[mdns]: Bump v1.5.2
2025-01-28 10:23:24 +01:00
David Cermak
84c47c37f1 bump(mdns): 1.5.1 -> 1.5.2
1.5.2
Bug Fixes
- Fix potential NULL deref when sending sub-buy (e7273c46)
- Fix _mdns_append_fqdn excessive stack usage (bd23c233)
2025-01-28 09:54:54 +01:00
David Cermak
e7273c46ec fix(mdns): Fix potential NULL deref when sending sub-buy
Closes coverity reported issue: 473829 Dereference null return value
2025-01-28 09:54:16 +01:00
david-cermak
2e7d240abd Merge pull request #744 from andrew-lifx/fix/mdns_append_fqdn
fix(mdns): Fix _mdns_append_fqdn excessive stack usage (IDFGH-14506)
2025-01-28 07:28:00 +01:00
david-cermak
d4a004b5b4 Merge pull request #694 from johanstokking/fix/websocket-esp-tls-errors
fix(websocket): propagate error type (IDFGH-14518)
2025-01-27 15:50:32 +01:00
David Cermak
9046af8f8d fix(websocket): Fix pytest to verify client correctly 2025-01-27 15:34:49 +01:00
Johan Stokking
eeeb9006eb fix(websocket): propagate error type 2025-01-25 21:52:06 +01:00
david-cermak
b167aa315f Merge pull request #747 from david-cermak/fix/publish_asio_1.32
bump(asio): Publish 1.32.0 to component manager
2025-01-24 15:53:54 +01:00
David Cermak
72ba24470d bump(asio): Publish 1.32.0 to component manager
Related to the bump-commit: ac6a388cdd
but missed to update idf_component.yml
This publishes ASIO-1.32-0~0
2025-01-24 14:32:20 +01:00
david-cermak
7dc87d28b2 Merge pull request #717 from david-cermak/feat/asio_sync_upstream
[asio]: Drop esp-asio patches in favor of sock-utils
2025-01-24 13:49:53 +01:00
David Cermak
ac6a388cdd bump(asio): 1.28.0 -> 1.32.0
1.32.0
Features
- Upgrade asio to 1.32 (9bdd429c)
- Drop esp/asio patches in favor of sock-utils (27435b7f)
Bug Fixes
- Fix chat example to print only the message body (76aaea08)
- Make asio enable if_nametoindex to fix linking (5db32cce)
- Re-applie refs to common comps idf_component.yml (9fe44a45)
- Reference common component from IDF (74fc228c)
- Revert referencing protocol_examples_common from IDF (f9e0281a)
- reference protocol_examples_common from IDF (09abb18b)
- specify override_path in example manifest files (1d8923cf)
Updated
- docs(asio): Updates asio docs (ce9337d3)
2025-01-24 12:40:45 +01:00
David Cermak
76aaea08d2 fix(asio): Fix chat example to print only the message body 2025-01-24 12:37:39 +01:00
David Cermak
5db32cce30 fix(asio): Make asio enable if_nametoindex to fix linking 2025-01-24 12:37:39 +01:00
David Cermak
9bdd429c7c feat(asio): Upgrade asio to 1.32 2025-01-24 10:47:54 +01:00
David Cermak
6f7c52cc3f fix(asio): Add tests for IDF-v5.4 2025-01-24 10:47:54 +01:00
David Cermak
27435b7f34 feat(asio): Drop esp/asio patches in favor of sock-utils 2025-01-24 10:47:54 +01:00
david-cermak
813331f003 Merge pull request #743 from david-cermak/fix/modem_ci
[modem]: Fix deprecated CI download action
2025-01-24 08:27:37 +01:00
Andrew Chalmers
bd23c233a4 fix(mdns): Fix _mdns_append_fqdn excessive stack usage
Move "mdns_name_t name" declaration inside loop to move it out of scope and reclain stack space before recursion call.
2025-01-24 17:39:04 +10:30
David Cermak
4eda7d472f fix(modem): Fix deprecated download action 2025-01-23 19:15:28 +01:00
david-cermak
163029c0b6 Merge pull request #742 from david-cermak/bump/mdns_1.5.1
[mdns]: Bump 1.5.0 -> 1.5.1
2025-01-23 15:32:49 +01:00
David Cermak
96eae25096 bump(mdns): 1.5.0 -> 1.5.1
1.5.1
Bug Fixes
- Fix incorrect memory free for mdns browse (4451a8c5)
2025-01-23 09:00:01 +01:00
david-cermak
ebec8eff63 Merge pull request #740 from gytxxsy/fix/fix_wrong_mem_free_of_mdns_browse
[mdns]: fix incorrect memory free for mdns browse
2025-01-23 08:58:05 +01:00
Xu Si Yu
4451a8c5ad fix(mdns): Fix incorrect memory free for mdns browse 2025-01-23 09:08:25 +08:00
david-cermak
6d19aabb02 Merge pull request #721 from david-cermak/feat/mosq_target_tests
[mosq]: Add IDF MQTT stress tests to mosquitto CI
2025-01-21 12:55:49 +01:00
David Cermak
9162de1150 fix(mosq): Remove temp modification of IDF files 2025-01-21 12:27:09 +01:00
David Cermak
dbd164dd91 fix(mosq): Add a note about stack size 2025-01-21 12:27:09 +01:00
David Cermak
90d663ad01 feat(mosq): Add IDF MQTT stress tests to mosquitto CI 2025-01-21 12:27:09 +01:00
david-cermak
a83f1b6787 Merge pull request #736 from david-cermak/bump/mdns_1.4.4
[mdns]: Bump 1.4.3 -> 1.5.0
2025-01-21 10:56:48 +01:00
David Cermak
84caca465d bump(mdns): 1.4.3 -> 1.5.0
1.5.0
Features
- supported removal of subtype when updating service (4ad88e29)
Bug Fixes
- Fix zero-sized VLA clang-tidy warnings (196198ec)
- Remove dead store to arg variable shared (e838bf03)
- Fix name mangling not to use strcpy() (99b54ac3)
- Fix potential null derefernce in _mdns_execute_action() (f5be2f41)
- Fix AFL test mock per espressif/esp-idf@a5bc08fb55 (3d8835cf)
- Fixed potential out-of-bound interface error (24f55ce9)
- Fixed incorrect error conversion (8f8516cc)
- Fixed potential overflow when allocating txt data (75a8e864)
- Move MDNS_NAME_BUF_LEN to public headers (907087c0, #724)
- Cleanup includes in mdns.c (68a9e148, #725)
- Allow advertizing service with port==0 (827ea65f)
- Fixed complier warning if MDNS_MAX_SERVICES==0 (95377216, #611)
2025-01-20 17:57:07 +01:00
david-cermak
8f81478fff Merge pull request #735 from david-cermak/fix/docs_build
[common]: Fix esp-docs dependencies
2025-01-20 14:50:32 +01:00
David Cermak
ae5a8ceeda fix(mosq): Run mosquitto version check only on labeled job or push 2025-01-20 12:56:02 +01:00
David Cermak
774bab22ea fix(common): Update esp-docs dependencies to fix docs-build job 2025-01-20 12:52:52 +01:00
david-cermak
265e38d684 Merge pull request #731 from tanyanquan/feat/update_subtype_removal
feat(mdns): supported removal of subtype when updating service (IDFGH-14413)
2025-01-20 09:48:27 +01:00
david-cermak
93f772171c Merge pull request #732 from david-cermak/fix/mdns_clangtiy_warns
[mdns]: Fixes clang-tidy warnings
2025-01-20 09:47:56 +01:00
Tan Yan Quan
4ad88e297f feat(mdns): supported removal of subtype when updating service 2025-01-16 10:56:54 +08:00
David Cermak
196198ecc9 fix(mdns): Fix zero-sized VLA clang-tidy warnings
and some minor leaks in creation of browse results
2025-01-15 14:23:34 +01:00
David Cermak
e838bf03f4 fix(mdns): Remove dead store to arg variable shared
Fixing: warning: Value stored to 'shared' is never read [clang-analyzer-deadcode.DeadStores]
2025-01-15 14:23:34 +01:00
David Cermak
99b54ac384 fix(mdns): Fix name mangling not to use strcpy()
Since it was flagged by clang-tidy as insecture API
2025-01-15 14:23:34 +01:00
David Cermak
f5be2f4115 fix(mdns): Fix potential null derefernce in _mdns_execute_action()
We did check for null-deref before checking 'a->type', but contol
continues and passes potential null-ptr to the processing function
_mdns_execute_action()
Fixed by asserting action != NULL, since it is an invalid state which
should never happen.
2025-01-15 14:21:59 +01:00
david-cermak
9b74256b51 Merge pull request #730 from david-cermak/fix/mdns_minor
[mdns]: Fixed some minor bugs
2025-01-15 12:27:05 +01:00
David Cermak
3d8835cfb9 fix(mdns): Fix AFL test mock per espressif/esp-idf@a5bc08fb55 2025-01-15 11:42:34 +01:00
David Cermak
24f55ce9b4 fix(mdns): Fixed potential out-of-bound interface error
invalid mdns_if was handled for enabling/announcing pcbs,
but not for the consequent browsing

Closes coverity isssue: 470162 Out-of-bounds access
2025-01-15 10:46:15 +01:00
David Cermak
8f8516cc3f fix(mdns): Fixed incorrect error conversion
Mixing esp_err_t (int) with err_t (uint8_t) from lwip.

Closes coverity isssue: 470139 Overflowed return value
2025-01-15 10:46:15 +01:00
David Cermak
75a8e8640a fix(mdns): Fixed potential overflow when allocating txt data
Closes coverity warning: 470092 Overflowed integer argument
2025-01-15 10:46:15 +01:00
David Cermak
907087c09b fix(mdns): Move MDNS_NAME_BUF_LEN to public headers
Since it's used by public API as maximum length of user buffer

Closes https://github.com/espressif/esp-protocols/issues/724
2025-01-15 10:46:10 +01:00
David Cermak
68a9e14898 fix(mdns): Cleanup includes in mdns.c
Closes https://github.com/espressif/esp-protocols/issues/725
2025-01-15 10:44:12 +01:00
David Cermak
827ea65fd5 fix(mdns): Allow advertizing service with port==0
Closes https://github.com/espressif/esp-idf/issues/14335
2025-01-15 10:44:12 +01:00
David Cermak
9537721600 fix(mdns): Fixed complier warning if MDNS_MAX_SERVICES==0
Closes https://github.com/espressif/esp-protocols/issues/611
2025-01-15 10:44:07 +01:00
david-cermak
4394f845fc Merge pull request #728 from david-cermak/bump/mdns_1.4.3
[mdns]: bump: 1.4.2 -> 1.4.3
2025-01-08 10:24:01 +01:00
David Cermak
9b0ba6060f bump(mdns): 1.4.2 -> 1.4.3
1.4.3
Features
- support zero item when update subtype (5bd82c01)
2025-01-08 09:42:38 +01:00
david-cermak
7c6a3098af Merge pull request #726 from zwx1995esp/feature/support_update_zero_item_of_subtype_for_mdns
feat(mdns): support zero item when update subtype (IDFGH-14369)
2025-01-07 18:40:25 +01:00
david-cermak
f3f3e23bec Merge pull request #727 from david-cermak/fix/sockutls_gai_error
fix(sockutls): Fix gai_strerror() impl to return const string
2025-01-07 15:59:24 +01:00
David Cermak
9ed835ba3f bump(sockutls): 0.2.1 -> 0.2.2
0.2.2
Bug Fixes
- Fix gai_strerror() impl to return const string (f12a2056)
2025-01-07 14:06:42 +01:00
David Cermak
f12a205657 fix(sockutls): Fix gai_strerror() impl to return const string
Previous gai_strerror() returned numeric representation of the code,
but used TLS storage, which might cause issues with stack sizes on all
tasks in the system. Alternatively we can leave the storage to static
only (which wouldn't be thread-safe) or we could one-time allocate and
never free (which is wrong).
This option uses hardcoded strings for common error codes used in lwip.
The disadvantage is that we might need to update the impl in the future
when lwip adds more codes.
2025-01-07 14:06:00 +01:00
zwx
5bd82c01a5 feat(mdns): support zero item when update subtype 2025-01-07 10:28:02 +08:00
david-cermak
b4cb8f8a66 Merge pull request #720 from david-cermak/fix/sock_utils_define_conflict
[sock-utils] Fix potential macro conflict
2024-12-20 16:36:08 +01:00
David Cermak
0499ed93df bump(sockutls): 0.2.0 -> 0.2.1
0.2.1
Bug Fixes
- Fix potential macro colission including standard headers (ade9448c)
2024-12-20 15:41:10 +01:00
David Cermak
ade9448c01 fix(sockutls): Fix potential macro colission including standard headers 2024-12-20 15:40:54 +01:00
david-cermak
4745fc8fe1 Merge pull request #719 from david-cermak/bump/mosq_2.2.0_1
[mosq]:  Bump: v2.0.20 -> 2.0.20~1
2024-12-20 15:31:13 +01:00
David Cermak
73e523e736 bump(mosq): 2.0.20 -> 2.0.20~1
2.0.20~1
Bug Fixes
- Use sock_utils instead of func stubs (3cd0ed37)
- Update API docs adding on-message callback (5dcc3330)
2024-12-20 15:09:41 +01:00
David Cermak
3cd0ed377b fix(mosq): Use sock_utils instead of func stubs 2024-12-20 15:07:42 +01:00
David Cermak
95294f5f89 fix(mosq): Add consistency check for api docs and versions 2024-12-20 15:07:37 +01:00
David Cermak
5dcc33300f fix(mosq): Update API docs adding on-message callback 2024-12-20 12:09:48 +01:00
david-cermak
840a561de4 Merge pull request #710 from david-cermak/feat/mosq_p2p_example
[mosq]: Add serverless broker example
2024-12-19 17:11:13 +01:00
David Cermak
e6fb8aa078 bump(mosq): 2.0.18~0 -> 2.0.20~0
2.0.20~0
Features
- Upgrade to mosquitto v2.0.20 (3b2c614d)
- Add support for on-message callback (cdeab8f5)
- Add example with two brokers synced on P2P (d57b8c5b)
Bug Fixes
- Fix dependency issues moving esp-tls to public deps (6cce87e4)
2024-12-19 16:51:49 +01:00
David Cermak
3b2c614d86 feat(mosq): Upgrade to mosquitto v2.0.20
Used tagged version v2.0.20
2024-12-19 16:41:37 +01:00
David Cermak
cdeab8f517 feat(mosq): Add support for on-message callback 2024-12-19 16:41:37 +01:00
David Cermak
6cce87e465 fix(mosq): Fix dependency issues moving esp-tls to public deps
Since esp-tls structs are using in public header files
2024-12-19 16:41:37 +01:00
David Cermak
d57b8c5b29 feat(mosq): Add example with two brokers synced on P2P
Broker-less two chip example which virtual private IoT
networks on MQTT protocol.
2024-12-19 16:40:02 +01:00
david-cermak
9c11003449 Merge pull request #713 from david-cermak/feat/sock_utiis_0.2
[sock-utils]: Bump 0.1 -> 0.2
2024-12-19 11:13:59 +01:00
David Cermak
85a7fc772c bump(sockutls): 0.1.0 -> 0.2.0
0.2.0
Features
- Declare socketpair and gai_strerror via standard headers (b090a3cb)
- Add support for gethostname() (f7c0b756)
2024-12-19 10:57:36 +01:00
David Cermak
b090a3cb69 feat(sockutls): Declare socketpair and gai_strerror via standard headers
Adding a reverse dependency to lwip and define macros, which
enable declarations of socketpair() and gai_strerror() in standard
heders (sys/socket.h and netdb.h)
2024-12-19 10:54:56 +01:00
david-cermak
42cde46c97 Merge pull request #714 from bryghtlabs-richard/chore/websocketTidying
Chore(websocket) tidy up two small issues
2024-12-17 11:35:57 +01:00
Richard Allen
beb6e57e5e chore(websocket): align structure members 2024-12-16 16:20:21 -06:00
Richard Allen
15d3a01e11 chore(websocket): remove unused client variable 2024-12-16 15:46:43 -06:00
david-cermak
e12ecb8e89 Merge pull request #707 from david-cermak/bugfix/sckutls_gethostname
[sock-utils]: Add support for gethostname()
2024-12-16 16:36:32 +01:00
david-cermak
54271a1b96 Merge pull request #709 from david-cermak/bump/modem_1.3
[modem]: bump 1.2.1 -> 1.3.0
2024-12-12 09:46:27 +01:00
David Cermak
886215032f bump(modem): 1.2.1 -> 1.3.0
1.3.0
Features
- Add mode detection to the example (18f196fa)
- Support for pausing network in C-API (1db83cd1)
- Add support for pausing netif (247f1681, #699)
Bug Fixes
- Minor cleanup of pppos example (5e929902)
- Fix PPP mode detection to accept LCP/conf (c989c6ad)
- Refine mode switch data->command (8b6ea331, #692)
- Detect serial ports properly (0cb59ff8)
- Fix CMUX enter to ignore URC before transition (1284f66d, #669)
2024-12-10 12:48:09 +01:00
david-cermak
269351f41c Merge pull request #700 from david-cermak/feat/modem_pause_network
[modem]: Add support for pausing netif
2024-12-10 12:14:10 +01:00
David Cermak
5e929902c7 fix(modem): Minor cleanup of pppos example
* Use CONFIG_EXAMPLE_DETECT_MODE_BEFORE_CONNECT to demonstrate mode
detect
* Use disconnection flag to indicate conneciton issue and gracefully
degrade to command mode
* Remove IDF-verion < v5.0 code
2024-12-10 11:36:10 +01:00
David Cermak
f7c0b7564a feat(sockutls): Add support for gethostname()
Closes https://github.com/espressif/esp-idf/issues/14849
2024-12-09 17:16:59 +01:00
David Cermak
c989c6adae fix(modem): Fix PPP mode detection to accept LCP/conf 2024-12-06 10:12:25 +01:00
David Cermak
18f196fa1e feat(modem): Add mode detection to the example 2024-12-06 09:48:00 +01:00
David Cermak
1db83cd1ca feat(modem): Support for pausing network in C-API
also adds a demo of this feature to pppos client example
2024-12-05 20:16:45 +01:00
David Cermak
247f1681e8 feat(modem): Add support for pausing netif
Closes https://github.com/espressif/esp-protocols/issues/699
2024-12-05 20:16:41 +01:00
david-cermak
32387f7e39 Merge pull request #702 from david-cermak/fix/modem_data_cmd_mode_refine
[modem]: Refine data -> command transition
2024-12-04 15:42:43 +01:00
David Cermak
dbc3ea6809 fix(common): Export IDF environment in bash shell
To avoid issues with IDF_PATH/export with the latest tools
2024-12-04 14:44:43 +01:00
David Cermak
8b6ea3311a fix(modem): Refine mode switch data->command
* netif.stop() moved after setting the transition callback
* send PPP escape sequence if enabled before waiting for transition to
complete
* add newline character before sync() command (after the "+++")

Closes https://github.com/espressif/esp-protocols/issues/692
2024-12-04 14:39:01 +01:00
david-cermak
8e55b93b59 Merge pull request #703 from david-cermak/fix/modem_cmux_data_before_switch
[modem]: CMUX: ignore URC before entering CMUX
2024-12-04 08:18:54 +01:00
David Cermak
0cb59ff80d fix(modem): Detect serial ports properly 2024-11-29 18:27:26 +01:00
David Cermak
1284f66d58 fix(modem): Fix CMUX enter to ignore URC before transition
Closes https://github.com/espressif/esp-protocols/issues/669
2024-11-29 17:32:35 +01:00
Abhik Roy
c5b49de2db Merge pull request #502 from espressif-abhikroy/component/console_cmd_mqtt
feat(console): Added component with mqtt command
2024-11-29 21:53:01 +11:00
Abhik Roy
2e9bb6ee45 bump(console): First version [1.0.0]
1.0.0
Features
- Added component with mqtt command (1fcc5b1d)
2024-11-29 21:48:50 +11:00
Abhik Roy
1fcc5b1d56 feat(console): Added component with mqtt command 2024-11-29 00:59:27 +11:00
david-cermak
849fe7b6cb Merge pull request #698 from david-cermak/fix/modem_minor_fixes_on_1.2
[modem]: Support for URC handler in C-API -> v1.2.1
2024-11-20 16:28:39 +01:00
David Cermak
5eadf1edee bump(modem): 1.2.0 -> 1.2.1
1.2.1
Bug Fixes
- Use higher GPIO range to support new chips (428fdbbd, #558)
- Remove tests and support for IDFv4.4, added IDFv5.4 (433a033f)
- Fix typo GENETIC -> GENERIC in mode types (090b1ff8, #667)
- Add support for URC handler into C-API (295d99df, #180)
2024-11-20 15:47:03 +01:00
David Cermak
428fdbbd80 fix(modem): Use higher GPIO range to support new chips
We can use IDF's Kconfig.env_caps in future, but that's not available on v5.0.

Closes https://github.com/espressif/esp-protocols/issues/558
2024-11-20 11:36:00 +01:00
David Cermak
433a033fcc fix(modem): Remove tests and support for IDFv4.4, added IDFv5.4 2024-11-20 11:35:33 +01:00
David Cermak
090b1ff845 fix(modem): Fix typo GENETIC -> GENERIC in mode types
Closes https://github.com/espressif/esp-protocols/issues/667
2024-11-20 10:25:20 +01:00
David Cermak
295d99df96 fix(modem): Add support for URC handler into C-API
Closes https://github.com/espressif/esp-protocols/issues/180
2024-11-20 10:15:22 +01:00
david-cermak
b65cff3a0b Merge pull request #696 from david-cermak/bump/mdsn_1.4.2
[mdns]: Bump to v1.4.2
2024-11-14 15:31:45 +01:00
David Cermak
e711f26670 bump(mdns): 1.4.1 -> 1.4.2
1.4.2
Features
- support update subtype (062b8dca)
Updated
- chore(mdns): Add more info to idf_component.yml (4a1cb65c)
2024-11-14 12:04:25 +01:00
David Cermak
4a1cb65c67 chore(mdns): Add more info to idf_component.yml
Fixing component manager warnings:
WARNING: A component description has not been provided in the manifest file. Please update your  file and include a brief description of the component.This will help other developers understand the purpose and functionality of your component. Documentation: https://***/projects/idf-component-manager/en/latest/guides/packaging_components.html#create-idf-component-yml
WARNING: A homepage URL has not been provided in the manifest file. Please update your  file and include the URL to the component's homepage. Documentation: https://***/projects/idf-component-manager/en/latest/guides/packaging_components.html#create-idf-component-yml
2024-11-14 12:03:56 +01:00
david-cermak
6c61dd39cf Merge pull request #693 from zwx1995esp/feat/support_add_remove_subtype
feat(mdns): support update subtype (IDFGH-14068)
2024-11-14 10:36:22 +01:00
david-cermak
8821ea3a99 Merge pull request #695 from david-cermak/bump/mdns_1.4.1
bump(mdns): 1.4.0 -> 1.4.1
2024-11-14 10:32:22 +01:00
zwx
062b8dcacc feat(mdns): support update subtype 2024-11-14 11:07:43 +08:00
David Cermak
7de57bb412 bump(mdns): 1.4.0 -> 1.4.1
1.4.1
Features
- Send PTR query for mdns browse when interface is ready (010a404a)
Bug Fixes
- Prevent deadlock when deleting a browse request (3f48f9ea)
- Fix use after free reported by coverity (25b3d5fd)
- Fixed dead-code reported by coverity (11846c7d)
2024-11-13 17:47:19 +01:00
david-cermak
67191f3bb5 Merge pull request #671 from david-cermak/feat/sock_utils
[sock-utils]: Add initial support for socket helpers
2024-11-11 18:29:45 +01:00
David Cermak
6d94ad646d bump(sockutls): Initial version 0.1.0
0.1.0
Features
- Add initial support for socket helpers (31f57ad0)
2024-11-11 16:47:57 +01:00
David Cermak
685d47cd2f fix(common): Disable clang-check for unsecure/deprecated APIs 2024-11-11 16:47:18 +01:00
David Cermak
31f57ad067 feat(sockutls): Add initial support for socket helpers 2024-11-11 16:47:13 +01:00
david-cermak
32ac21b03c Merge pull request #688 from david-cermak/fix/modem_docs_limitations
[modem]: bump: 1.1.0 -> 1.2.0
2024-11-11 16:26:41 +01:00
David Cermak
5b06a3b319 bump(modem): 1.1.0 -> 1.2.0
1.2.0
Features
- Add support for guessing mode (52598e5f)
- Delete CMUX internal implementation even if terminal exit fails (0e0cbd6b)
- Add support for handling URC (1b6a3b3b, #180)
- add ability to change ESP_MODEM_C_API_STR_MAX from Kconfig (17909892)
- Added target test config with CHAP authentication (f8ae7def)
- example add esp32p4 usb support (adafeae5)
- Publish mbedtls component (0140455f)
- host test support of the latest ESP-IDF release (3f74b4e8)
Bug Fixes
- Fix console example to use urc/detect features (1a9eaf3e)
- Update target test builds to use external Catch2 (554f022c)
- Fix arguments names when spawn esp_modem_xxx declarations (b6792c52)
- Remove catch dependency (c3480768)
- Examples: use local configs for MQTT topic/data (f5c13b92)
- Fixed clang-tidy warnings (70fa3af7)
- Fix CI build per IDFv5.3 (d0c17ef0)
- Fixed UART task to check for buffered data periodically (4bdd90cc, #536)
- Cleanup unused configs from PPPoS example (08a62ccc)
- Update CMUX example with SIM7070_gnss cleaned-up (56fe5327)
- Update console example with SIM7070_gnss format comments (5baaf542)
- Fix remaining print format warnings (3b80181d)
Updated
- docs(modem): Fix esp_modem_at_raw() description (C-API) (492a6a00)
- ci(common): updated github actions(checkout, upload, download) v3 to 4, Ubuntu 20.04 to v22.04 (a23a0027)
2024-11-07 12:42:11 +01:00
David Cermak
cc2741d4ad fix(modem): Document CMUX compatibility issue with CAVLI C16QS
Closes https://github.com/espressif/esp-protocols/issues/507
2024-11-07 12:41:47 +01:00
david-cermak
c5653ff204 Merge pull request #677 from david-cermak/fix/docs_links
[asio]: Fix links in documentation
2024-11-06 14:40:23 +01:00
david-cermak
77731c9b36 Merge pull request #678 from david-cermak/fix/modem_docs
[modem]: Fix docs to link tests correctly
2024-11-06 14:40:05 +01:00
david-cermak
2442f6b553 Merge pull request #612 from david-cermak/feat/modem_mode_detect
[modem]: Add support for guessing mode
2024-11-06 14:39:37 +01:00
david-cermak
0b5e362a7b Merge pull request #686 from bryghtlabs-richard/fix/wsExampleLeak
fix(websocket): fix example buffer leak
2024-11-05 17:11:35 +01:00
Richard Allen
5219c39d09 fix(websocket): fix example buffer leak 2024-11-04 08:39:13 -06:00
David Cermak
1a9eaf3e98 fix(modem): Fix console example to use urc/detect features 2024-11-01 15:31:39 +01:00
David Cermak
52598e5f03 feat(modem): Add support for guessing mode 2024-11-01 13:49:52 +01:00
David Cermak
2d9759265b fix(modem): Fix docs to link tests correctly
Closes https://github.com/espressif/esp-protocols/issues/664
2024-10-25 12:56:08 +02:00
David Cermak
8f1f935858 fix(asio): Fix docs to link examples correctly 2024-10-25 12:43:19 +02:00
412 changed files with 21623 additions and 2546 deletions

View File

@@ -13,7 +13,7 @@ jobs:
name: Build
strategy:
matrix:
idf_ver: ["latest", "release-v5.0", "release-v5.1", "release-v5.2", "release-v5.3"]
idf_ver: ["latest", "release-v5.0", "release-v5.1", "release-v5.2", "release-v5.3", "release-v5.4"]
idf_target: ["esp32", "esp32s2"]
example: ["asio_chat", "async_request", "socks4", "ssl_client_server", "tcp_echo_server", "udp_echo_server"]
runs-on: ubuntu-22.04
@@ -64,7 +64,7 @@ jobs:
name: Target tests
strategy:
matrix:
idf_ver: ["latest", "release-v5.0", "release-v5.2", "release-v5.3"]
idf_ver: ["latest", "release-v5.1", "release-v5.2", "release-v5.3", "release-v5.4"]
idf_target: ["esp32"]
example: ["asio_chat", "tcp_echo_server", "udp_echo_server", "ssl_client_server"]
needs: build_asio

View File

@@ -9,12 +9,12 @@ on:
jobs:
build:
name: Run clang-tidy
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
container: espressif/idf:latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: 'true'
submodules: recursive
- name: Install esp-clang
run: |
${IDF_PATH}/tools/idf_tools.py --non-interactive install esp-clang
@@ -24,6 +24,7 @@ jobs:
chmod +x clang-tidy-sarif
curl -sSL https://raw.githubusercontent.com/espressif/idf-extra-components/master/.github/filter_sarif.py -o filter_sarif.py
- name: Install pyclang
shell: bash
run: |
. ${IDF_PATH}/export.sh
pip install pyclang~=0.2.0
@@ -35,7 +36,7 @@ jobs:
working-directory: test_app
run: |
. ${IDF_PATH}/export.sh
idf.py clang-check --include-paths $GITHUB_WORKSPACE --exclude-paths $PWD --run-clang-tidy-py run-clang-tidy
idf.py clang-check --include-paths $GITHUB_WORKSPACE --exclude-paths $PWD --run-clang-tidy-py run-clang-tidy --run-clang-tidy-options "-checks=-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling"
cp warnings.txt ../
- name: Convert clang-tidy results into SARIF output
run: |
@@ -49,7 +50,7 @@ jobs:
results.sarif
results.sarif.raw
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v2
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif
category: clang-tidy

View File

@@ -0,0 +1,32 @@
name: "console_cmd_mqtt: build-tests"
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened, labeled]
jobs:
build_console_cmd_mqtt:
if: contains(github.event.pull_request.labels.*.name, 'console') || github.event_name == 'push'
name: Build
strategy:
matrix:
idf_ver: ["latest", "release-v5.0", "release-v5.1", "release-v5.2", "release-v5.3"]
idf_target: ["esp32"]
test: [ { app: mqtt_ssl_auth_console, path: "components/console_cmd_mqtt/examples" }]
runs-on: ubuntu-22.04
container: espressif/idf:${{ matrix.idf_ver }}
steps:
- name: Checkout esp-protocols
uses: actions/checkout@v4
with:
submodules: recursive
- name: Build ${{ matrix.test.app }} with IDF-${{ matrix.idf_ver }} for ${{ matrix.idf_target }}
shell: bash
working-directory: ${{matrix.test.path}}
run: |
. ${IDF_PATH}/export.sh
pip install idf-component-manager idf-build-apps --upgrade
python ../../../ci/build_apps.py ./${{ matrix.test.app }} --target ${{ matrix.idf_target }} -vv --preserve-all --pytest-app

View File

@@ -13,14 +13,16 @@ jobs:
name: Build
strategy:
matrix:
idf_ver: ["latest", "release-v5.3"]
idf_ver: ["latest", "release-v5.5", "release-v5.4", "release-v5.3"]
test: [ { app: host, path: "examples/host" }, { app: slave, path: "examples/slave" }, { app: test_app, path: "test/test_app" }]
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
container: espressif/idf:${{ matrix.idf_ver }}
steps:
- name: Checkout esp-protocols
uses: actions/checkout@v3
- name: Build ${{ matrix.test.app }} with IDF-${{ matrix.idf_ver }}
env:
EXPECTED_WARNING: "DeprecationWarning: 'MultiCommand' is deprecated and will be removed\nCryptographyDeprecationWarning: Parsed a serial number which wasn't positive"
shell: bash
run: |
. ${IDF_PATH}/export.sh

41
.github/workflows/esp_dns__build.yml vendored Normal file
View File

@@ -0,0 +1,41 @@
name: "esp_dns: build-tests"
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened, labeled]
jobs:
build_esp_dns:
if: contains(github.event.pull_request.labels.*.name, 'dns') || github.event_name == 'push'
name: Build
strategy:
matrix:
idf_ver: ["latest", "release-v5.1", "release-v5.2", "release-v5.3", "release-v5.4"]
idf_target: ["esp32"]
test: [ { app: esp_dns_basic, path: "components/esp_dns/examples"}]
include:
- idf_ver: "latest"
warning: "the choice symbol ETHERNET_PHY_LAN867X\nis deprecated: Please use smi_gpio instead"
runs-on: ubuntu-22.04
container: espressif/idf:${{ matrix.idf_ver }}
steps:
- name: Checkout esp-protocols
uses: actions/checkout@v4
with:
submodules: recursive
- name: Build ${{ matrix.test.app }} with IDF-${{ matrix.idf_ver }} for ${{ matrix.idf_target }}
env:
EXPECTED_WARNING: ${{ matrix.warning }}
shell: bash
working-directory: ${{matrix.test.path}}
run: |
if [[ "${{ matrix.idf_ver }}" == "release-v5.3" || "${{ matrix.idf_ver }}" == "release-v5.4" ]]; then
export EXPECTED_WARNING="unknown kconfig symbol 'LWIP_USE_ESP_GETADDRINFO'"
fi
. ${IDF_PATH}/export.sh
pip install idf-component-manager idf-build-apps --upgrade
python ../../../ci/build_apps.py ./${{ matrix.test.app }} --target ${{ matrix.idf_target }} -vv --preserve-all --pytest-app

View File

@@ -13,12 +13,15 @@ jobs:
name: Build examples
strategy:
matrix:
idf_ver: ["latest", "release-v5.1", "release-v5.2", "release-v5.3"]
idf_ver: ["latest", "release-v5.1", "release-v5.2", "release-v5.3", "release-v5.4"]
include:
- idf_ver: "latest"
warning: "Warning: The smallest app partition is nearly full"
runs-on: ubuntu-22.04
container: espressif/idf:${{ matrix.idf_ver }}
env:
TARGET_TEST: examples/esp_netif/slip_custom_netif/
TARGET_TEST_DIR: build_esp32c3_target
steps:
- name: Checkout esp-protocols
uses: actions/checkout@v4
@@ -31,6 +34,16 @@ jobs:
python -m pip install idf-build-apps
# Build default configs for all targets
python ./ci/build_apps.py examples -m examples/.build-test-rules.yml -d -c
# Build target tests
python ./ci/build_apps.py ${TARGET_TEST} -r sdkconfig.ci=target
cd ${TARGET_TEST}
${GITHUB_WORKSPACE}/ci/clean_build_artifacts.sh `pwd`/${TARGET_TEST_DIR}
zip -qur artifacts.zip ${TARGET_TEST_DIR}
- uses: actions/upload-artifact@v4
with:
name: slip_target_${{ matrix.idf_ver }}
path: ${{ env.TARGET_TEST }}/artifacts.zip
if-no-files-found: error
build_and_run_on_host:
if: contains(github.event.pull_request.labels.*.name, 'examples') || github.event_name == 'push'
@@ -46,8 +59,44 @@ jobs:
- name: Build with IDF-${{ matrix.idf_ver }}
shell: bash
run: |
. ${GITHUB_WORKSPACE}/ci/config_env.sh
. ${IDF_PATH}/export.sh
python -m pip install idf-build-apps
python ./ci/build_apps.py examples/mqtt -l -t linux
timeout 5 ./examples/mqtt/build_linux_default/esp_mqtt_demo.elf | tee test.log || true
python ./ci/build_apps.py examples/mqtt -l -t linux -r 'sdkconfig.ci'
timeout 5 ./examples/mqtt/build_linux/esp_mqtt_demo.elf | tee test.log || true
grep 'MQTT_EVENT_DATA' test.log
run_on_target:
# Skip running on forks since it won't have access to secrets
if: |
github.repository == 'espressif/esp-protocols' &&
( contains(github.event.pull_request.labels.*.name, 'examples') || github.event_name == 'push' )
name: Slip example target test
needs: build_all_examples
strategy:
matrix:
idf_ver: ["release-v5.4", "latest"]
runs-on:
- self-hosted
- modem
env:
TARGET_TEST: examples/esp_netif/slip_custom_netif/
TARGET_TEST_DIR: build_esp32c3_target
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: slip_target_${{ matrix.idf_ver }}
path: ${{ env.TARGET_TEST }}/ci/
- name: Run Test
working-directory: ${{ env.TARGET_TEST }}
run: |
python -m venv .venv
source .venv/bin/activate
pip install --prefer-binary cryptography pytest-embedded pytest-embedded-serial-esp pytest-embedded-idf pytest-custom_exit_code esptool netifaces
unzip ci/artifacts.zip -d ci
for dir in `ls -d ci/build_*`; do
rm -rf build sdkconfig.defaults
mv $dir build
python -m pytest --log-cli-level DEBUG --target=esp32c3
done

86
.github/workflows/lws_build.yml vendored Normal file
View File

@@ -0,0 +1,86 @@
name: "lws: build-tests"
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened, labeled]
jobs:
build_lws:
if: contains(github.event.pull_request.labels.*.name, 'lws') || github.event_name == 'push'
name: Libwebsockets build
strategy:
matrix:
idf_ver: ["latest", "release-v5.3", "release-v5.4"]
test: [ { app: example, path: "examples/client" }]
runs-on: ubuntu-22.04
container: espressif/idf:${{ matrix.idf_ver }}
env:
TEST_DIR: components/libwebsockets/${{ matrix.test.path }}
steps:
- name: Checkout esp-protocols
uses: actions/checkout@v4
with:
submodules: recursive
- name: Build ${{ matrix.example }} with IDF-${{ matrix.idf_ver }}
shell: bash
run: |
. ${IDF_PATH}/export.sh
python -m pip install idf-build-apps
python ./ci/build_apps.py ${TEST_DIR}
cd ${TEST_DIR}
for dir in `ls -d build_esp32_*`; do
$GITHUB_WORKSPACE/ci/clean_build_artifacts.sh `pwd`/$dir
zip -qur artifacts.zip $dir
done
- uses: actions/upload-artifact@v4
with:
name: lws_target_esp32_${{ matrix.idf_ver }}_${{ matrix.test.app }}
path: ${{ env.TEST_DIR }}/artifacts.zip
if-no-files-found: error
run-target-lws:
# Skip running on forks since it won't have access to secrets
if: |
github.repository == 'espressif/esp-protocols' &&
( contains(github.event.pull_request.labels.*.name, 'lws') || github.event_name == 'push' )
name: Target test
needs: build_lws
strategy:
fail-fast: false
matrix:
idf_ver: ["latest", "release-v5.3", "release-v5.4"]
idf_target: ["esp32"]
test: [ { app: example, path: "examples/client" }]
runs-on:
- self-hosted
- ESP32-ETHERNET-KIT
env:
TEST_DIR: components/libwebsockets/${{ matrix.test.path }}
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: lws_target_esp32_${{ matrix.idf_ver }}_${{ matrix.test.app }}
path: ${{ env.TEST_DIR }}/ci/
- name: Install Python packages
env:
PIP_EXTRA_INDEX_URL: "https://www.piwheels.org/simple"
run: |
pip install --only-binary cryptography --extra-index-url https://dl.espressif.com/pypi/ -r $GITHUB_WORKSPACE/ci/requirements.txt
- name: Run Example Test on target
working-directory: ${{ env.TEST_DIR }}
run: |
unzip ci/artifacts.zip -d ci
for dir in `ls -d ci/build_*`; do
rm -rf build sdkconfig.defaults
mv $dir build
python -m pytest --log-cli-level DEBUG --junit-xml=./results_${{ matrix.test.app }}_${{ matrix.idf_target }}_${{ matrix.idf_ver }}_${dir#"ci/build_"}.xml --target=${{ matrix.idf_target }}
done
- uses: actions/upload-artifact@v4
if: always()
with:
name: results_${{ matrix.test.app }}_${{ matrix.idf_target }}_${{ matrix.idf_ver }}.xml
path: components/libwebsockets/${{ matrix.test.path }}/*.xml

View File

@@ -24,6 +24,11 @@ jobs:
shell: bash
run: |
. ${IDF_PATH}/export.sh
if [[ "${{ matrix.idf_ver }}" == "latest" ]]; then
export EXPECTED_WARNING="warning: unknown kconfig symbol 'EXAMPLE_ETH_PHY_IP101'"
else
export EXPECTED_WARNING="warning: unknown kconfig symbol 'EXAMPLE_ETH_PHY_GENERIC'"
fi
python -m pip install idf-build-apps
# Build default configs for all targets
python ./ci/build_apps.py components/mdns/${{ matrix.test.path }} -r default -d
@@ -71,6 +76,22 @@ jobs:
- name: Run ${{ matrix.test.app }} application on ${{ matrix.idf_target }}
working-directory: components/mdns/${{ matrix.test.path }}
run: |
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
if ! pyenv versions --bare | grep -q '^3\.12\.6$'; then
echo "Installing Python 3.12.6..."
pyenv install -s 3.12.6
fi
if ! pyenv virtualenvs --bare | grep -q '^myenv$'; then
echo "Creating pyenv virtualenv 'myenv'..."
pyenv virtualenv 3.12.6 myenv
fi
pyenv activate myenv
python --version
pip install --prefer-binary cryptography pytest-embedded pytest-embedded-serial-esp pytest-embedded-idf pytest-custom_exit_code esptool
pip install --extra-index-url https://dl.espressif.com/pypi/ -r $GITHUB_WORKSPACE/ci/requirements.txt
unzip ci/artifacts.zip -d ci
for dir in `ls -d ci/build_*`; do
rm -rf build sdkconfig.defaults

View File

@@ -24,7 +24,7 @@ jobs:
shell: bash
run: |
. ${IDF_PATH}/export.sh
python -m pip install idf-build-apps dnspython pytest pytest-embedded pytest-embedded-serial-esp pytest-embedded-idf
python -m pip install idf-build-apps==2.10.0 dnspython pytest pytest-embedded pytest-embedded-serial-esp pytest-embedded-idf
cd $GITHUB_WORKSPACE/protocols
# Build host tests app (with all configs and targets supported)
python ./ci/build_apps.py components/mdns/tests/host_test/
@@ -35,30 +35,76 @@ jobs:
# Next we run the pytest (using the console app)
pytest
build_afl_host_test_mdns:
host_compat_checks:
if: contains(github.event.pull_request.labels.*.name, 'mdns') || github.event_name == 'push'
name: Build AFL host test
name: Set of compatibility checks
strategy:
matrix:
idf_ver: ["latest"]
idf_target: ["esp32"]
runs-on: ubuntu-22.04
container: espressif/idf:${{ matrix.idf_ver }}
steps:
- name: Checkout esp-protocols
uses: actions/checkout@v4
with:
path: esp-protocols
- name: Install Necessary Libs
run: |
apt-get update -y
apt-get install -y libbsd-dev
- name: Build ${{ matrix.example }} with IDF-${{ matrix.idf_ver }} for ${{ matrix.idf_target }}
env:
IDF_TARGET: ${{ matrix.idf_target }}
- name: Test AFL compat build
shell: bash
run: |
. ${IDF_PATH}/export.sh
cd $GITHUB_WORKSPACE/esp-protocols/components/mdns/tests/test_afl_fuzz_host/
cd components/mdns/tests/test_afl_fuzz_host/
make INSTR=off
- name: Test no malloc functions
shell: bash
run: |
cd components/mdns
for file in $(ls *.c); do
cp $file /tmp
echo -n "Checking that $file does not call any std allocations directly..."
python mem_prefix_script.py $file
diff -q $file /tmp/$file || exit 1
echo "OK"
done
fuzz_test:
if: contains(github.event.pull_request.labels.*.name, 'mdns-fuzz') || github.event_name == 'push'
name: Fuzzer tests for mdns lib
strategy:
matrix:
idf_ver: ["latest"]
runs-on: ubuntu-22.04
container: aflplusplus/aflplusplus
steps:
- name: Checkout esp-protocols
uses: actions/checkout@v4
- name: Checkout ESP-IDF
uses: actions/checkout@v4
with:
repository: espressif/esp-idf
path: idf
submodules: recursive
- name: Install Necessary Libs
run: |
apt-get update -y
apt-get install -y libbsd-dev
- name: Run AFL++
shell: bash
run: |
export IDF_PATH=$GITHUB_WORKSPACE/idf
cd components/mdns/tests/test_afl_fuzz_host/
make fuzz
- name: Upload Crash Artifacts
if: failure()
uses: actions/upload-artifact@v4
with:
name: fuzz-crashes
path: components/mdns/tests/test_afl_fuzz_host/out/default/crashes.tar.gz
if-no-files-found: ignore

View File

@@ -13,35 +13,21 @@ jobs:
name: Build examples
strategy:
matrix:
idf_ver: ["latest", "release-v4.4", "release-v5.0", "release-v5.1", "release-v5.2", "release-v5.3"]
idf_ver: ["latest", "release-v5.0", "release-v5.1", "release-v5.2", "release-v5.3", "release-v5.4"]
example: ["pppos_client", "modem_console", "modem_tcp_client", "ap_to_pppos", "simple_cmux_client"]
exclude:
- idf_ver: "release-v4.4"
example: modem_tcp_client
include:
- idf_ver: "release-v5.0"
example: "simple_cmux_client"
warning: "Warning: The smallest app partition is nearly full"
runs-on: ubuntu-22.04
container: espressif/idf:${{ matrix.idf_ver }}
steps:
- name: Check out code (v3) # @v4 failed due to Node 20's requirement, incompatible with older IDF versions
if: matrix.idf_ver != 'latest' && matrix.idf_ver < 'release-v5.0'
uses: actions/checkout@v3
with:
path: protocols
- name: Check out code (v4)
if: matrix.idf_ver == 'latest' || matrix.idf_ver >= 'release-v5.0'
- name: Check out code
uses: actions/checkout@v4
with:
path: protocols
- if: ${{ matrix.skip_config }}
run: rm -f $GITHUB_WORKSPACE/protocols/components/esp_modem/examples/${{ matrix.example }}/sdkconfig.ci.${{ matrix.skip_config }}*
- name: Build ${{ matrix.example }} with IDF-${{ matrix.idf_ver }}
env:
EXPECTED_WARNING: ${{ matrix.warning }}
shell: bash
env:
EXPECTED_WARNING: "Warning: The smallest app partition is nearly full\nwarning: unknown kconfig symbol 'ESP32_PANIC_PRINT_HALT'"
run: |
. ${IDF_PATH}/export.sh
python -m pip install idf-build-apps
@@ -53,8 +39,8 @@ jobs:
name: Build tests
strategy:
matrix:
idf_ver: ["release-v5.0", "release-v5.1", "release-v5.2", "release-v5.3", "latest"]
test: ["target", "target_ota", "target_iperf"]
idf_ver: ["release-v5.0", "release-v5.1", "release-v5.2", "release-v5.3", "release-v5.4", "latest"]
test: ["target", "target_ota", "target_iperf", "target_urc"]
runs-on: ubuntu-22.04
container: espressif/idf:${{ matrix.idf_ver }}
@@ -100,3 +86,21 @@ jobs:
run_executable: false
run_coverage: false
pre_run_script: "esp-protocols/components/esp_modem/test/host_test/env.sh"
esp_modem_generated_commands:
if: contains(github.event.pull_request.labels.*.name, 'modem') || github.event_name == 'push'
name: Generated commands compatibility
runs-on: ubuntu-latest
steps:
- name: Checkout esp-protocols
uses: actions/checkout@v4
- name: Compat check
shell: bash
run: |
sudo apt-get update -y
sudo apt-get install -y astyle
cd components/esp_modem
find examples/ -type f -regex '.*/generate/.*\.\(hpp\|cpp\)' -exec ./scripts/generate.sh {} \;
./scripts/generate.sh
git diff --name-only
git diff --quiet

View File

@@ -34,18 +34,16 @@ jobs:
IDF_TARGET: ${{ matrix.idf_target }}
SDKCONFIG: sdkconfig.ci.${{ matrix.test.app }}
shell: bash
working-directory: ${{ env.TEST_DIR }}
run: |
. ${GITHUB_WORKSPACE}/ci/config_env.sh
. ${IDF_PATH}/export.sh
rm -rf sdkconfig build
[ -f ${SDKCONFIG} ] && cp ${SDKCONFIG} sdkconfig.defaults
idf.py set-target ${{ matrix.idf_target }}
idf.py build
$GITHUB_WORKSPACE/ci/clean_build_artifacts.sh ${GITHUB_WORKSPACE}/${TEST_DIR}/build
- uses: actions/upload-artifact@v3
python -m pip install idf-build-apps
python ./ci/build_apps.py ${{ env.TEST_DIR }} -t ${{ matrix.idf_target }} -r 'sdkconfig.ci.${{ matrix.test.app }}'
$GITHUB_WORKSPACE/ci/clean_build_artifacts.sh ${GITHUB_WORKSPACE}/${TEST_DIR}/build_${{ matrix.idf_target }}
- uses: actions/upload-artifact@v4
with:
name: modem_target_bin_${{ matrix.idf_target }}_${{ matrix.idf_ver }}_${{ matrix.test.app }}
path: ${{ env.TEST_DIR }}/build
path: ${{ env.TEST_DIR }}/build_${{ matrix.idf_target }}
if-no-files-found: error
target_tests_esp_modem:
@@ -75,12 +73,17 @@ jobs:
run: |
sudo rm -fr $GITHUB_WORKSPACE && mkdir $GITHUB_WORKSPACE
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: modem_target_bin_${{ matrix.idf_target }}_${{ matrix.idf_ver }}_${{ matrix.test.app }}
path: ${{ env.TEST_DIR }}/build
- name: Run Example Test on target
working-directory: ${{ env.TEST_DIR }}
env:
PIP_EXTRA_INDEX_URL: "https://dl.espressif.com/pypi/"
run: |
python -m pip install -r $GITHUB_WORKSPACE/ci/requirements.txt
python -m venv .venv
source .venv/bin/activate
pip install --prefer-binary cryptography pytest-embedded pytest-embedded-serial-esp pytest-embedded-idf pytest-custom_exit_code esptool
pip install -r $GITHUB_WORKSPACE/ci/requirements.txt
cd ${{ env.TEST_DIR }}
python -m pytest --log-cli-level DEBUG --target=${{ matrix.idf_target }}

32
.github/workflows/modem_sim__build.yml vendored Normal file
View File

@@ -0,0 +1,32 @@
name: "modem_sim: build-tests"
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened, labeled]
jobs:
build_modem_sim:
if: contains(github.event.pull_request.labels.*.name, 'modem_sim') || github.event_name == 'push'
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout esp-protocols
uses: actions/checkout@v3
- name: Checkout idf
uses: actions/checkout@v3
with:
repository: espressif/esp-idf
ref: 8ad0d3d8f2faab752635bee36070313c47c07a13
path: idf
- name: Build ESP-AT with IDF-${{ matrix.idf_ver }}
shell: bash
run: |
export IDF_PATH=$GITHUB_WORKSPACE/idf
${IDF_PATH}/install.sh
cd common_components/modem_sim
./install.sh
source export.sh
idf.py build

View File

@@ -13,11 +13,20 @@ jobs:
name: Mosquitto build
strategy:
matrix:
idf_ver: ["latest", "release-v5.3"]
idf_ver: ["latest", "release-v5.5", "release-v5.4", "release-v5.3", "release-v5.2", "release-v5.1"]
example: ["broker", "serverless_mqtt"]
exclude:
# serverless_mqtt is not supported on v5.1 and master (esp-peer dependency)
- idf_ver: "release-v5.1"
example: "serverless_mqtt"
- idf_ver: "latest"
example: "serverless_mqtt"
runs-on: ubuntu-22.04
container: espressif/idf:${{ matrix.idf_ver }}
env:
TEST_DIR: components/mosquitto/examples/broker
TEST_DIR: components/mosquitto/examples/${{ matrix.example }}
TARGET_TEST: broker
TARGET_TEST_DIR: build_esp32_default
steps:
- name: Checkout esp-protocols
@@ -29,11 +38,15 @@ jobs:
run: |
. ${IDF_PATH}/export.sh
pip install idf-component-manager idf-build-apps --upgrade
python ci/build_apps.py ${TEST_DIR}
cd ${TEST_DIR}
${GITHUB_WORKSPACE}/ci/clean_build_artifacts.sh `pwd`/${TARGET_TEST_DIR}
zip -qur artifacts.zip ${TARGET_TEST_DIR}
python ci/build_apps.py -c ${TEST_DIR} -m components/mosquitto/.build-test-rules.yml
if [ "${{ matrix.example }}" == "${TARGET_TEST}" ]; then
# upload only the target test artifacts
cd ${TEST_DIR}
${GITHUB_WORKSPACE}/ci/clean_build_artifacts.sh `pwd`/${TARGET_TEST_DIR}
zip -qur artifacts.zip ${TARGET_TEST_DIR}
fi
- uses: actions/upload-artifact@v4
if: ${{ matrix.example == 'broker' }}
with:
name: mosq_target_esp32_${{ matrix.idf_ver }}
path: ${{ env.TEST_DIR }}/artifacts.zip
@@ -71,3 +84,108 @@ jobs:
mv $dir build
python -m pytest --log-cli-level DEBUG --junit-xml=./results_esp32_${{ matrix.idf_ver }}_${dir#"ci/build_"}.xml --target=esp32
done
check_consistency:
if: contains(github.event.pull_request.labels.*.name, 'mosquitto') || github.event_name == 'push'
name: Checks that API docs and versions are consistent
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Checks API Docs and versions
run: |
sudo apt-get update
sudo apt-get -y install doxygen
pip install esp-doxybook
cd components/mosquitto
cp api.md api_orig.md
./generate_api_docs.sh
diff -wB api.md api_orig.md
# check version consistency
CONFIG_VERSION=$(grep -Po '(?<=#define VERSION ")[^"]*' port/priv_include/config.h)
CZ_VERSION=$(grep -Po '(?<=version: )[^"]*' .cz.yaml)
COMP_VERSION=$(grep -Po '(?<=version: ")[^"]*' idf_component.yml)
if [ "$CONFIG_VERSION" != "v$CZ_VERSION" ] || [ "$CONFIG_VERSION" != "v$COMP_VERSION" ]; then
echo "Version mismatch detected:"
echo "config.h: $CONFIG_VERSION"
echo ".cz.yaml: $CZ_VERSION"
echo "idf_component.yml: $COMP_VERSION"
exit 1
fi
echo "Versions are consistent: $CONFIG_VERSION"
build_idf_tests_with_mosq:
if: |
github.repository == 'espressif/esp-protocols' &&
( contains(github.event.pull_request.labels.*.name, 'mosquitto') || github.event_name == 'push' )
name: Build IDF tests
strategy:
matrix:
idf_ver: ["latest"]
idf_target: ["esp32"]
test: [ { app: publish, path: "tools/test_apps/protocols/mqtt/publish_connect_test" }]
runs-on: ubuntu-22.04
container: espressif/idf:${{ matrix.idf_ver }}
env:
TARGET_TEST_DIR: build_esp32_local_broker
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
- name: Build ${{ matrix.test.app }} with IDF-${{ matrix.idf_ver }} for ${{ matrix.idf_target }}
shell: bash
run: |
. ${IDF_PATH}/export.sh
pip install idf-component-manager idf-build-apps --upgrade
export MOSQUITTO_PATH=`pwd`/components/mosquitto
# to use the actual version of mosquitto
sed -i '/espressif\/mosquitto:/a \ \ \ \ override_path: "${MOSQUITTO_PATH}"' ${IDF_PATH}/${{matrix.test.path}}/main/idf_component.yml
export PEDANTIC_FLAGS="-DIDF_CI_BUILD -Werror -Werror=deprecated-declarations -Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function"
export EXTRA_CFLAGS="${PEDANTIC_FLAGS} -Wstrict-prototypes"
export EXTRA_CXXFLAGS="${PEDANTIC_FLAGS}"
cd ${IDF_PATH}/${{matrix.test.path}}
idf-build-apps find --config sdkconfig.ci.local_broker -vv --target ${{ matrix.idf_target }} --build-dir=${TARGET_TEST_DIR}
idf-build-apps build --config sdkconfig.ci.local_broker -vv --target ${{ matrix.idf_target }} --build-dir=${TARGET_TEST_DIR}
${GITHUB_WORKSPACE}/ci/clean_build_artifacts.sh `pwd`/${TARGET_TEST_DIR}
# to replace mqtt test configs with specific mosquitto markers
python ${MOSQUITTO_PATH}/test/replace_decorators.py pytest_mqtt_publish_app.py ${TARGET_TEST_DIR}/pytest_mosquitto.py
zip -qur ${GITHUB_WORKSPACE}/artifacts.zip ${TARGET_TEST_DIR}
- uses: actions/upload-artifact@v4
with:
name: mosq_publish_esp32_${{ matrix.idf_ver }}
path: artifacts.zip
if-no-files-found: error
test_idf_ci_with_mosq:
# Skip running on forks since it won't have access to secrets
if: |
github.repository == 'espressif/esp-protocols' &&
( contains(github.event.pull_request.labels.*.name, 'mosquitto') || github.event_name == 'push' )
name: Mosquitto IDF target tests
needs: build_idf_tests_with_mosq
strategy:
matrix:
idf_ver: ["latest"]
runs-on:
- self-hosted
- ESP32-ETHERNET-KIT
env:
TEST_DIR: examples
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: mosq_publish_esp32_${{ matrix.idf_ver }}
path: ${{ env.TEST_DIR }}/ci/
- name: Run Test
working-directory: ${{ env.TEST_DIR }}
run: |
python -m pip install pytest-embedded-serial-esp pytest-embedded-idf pytest-rerunfailures pytest-timeout pytest-ignore-test-results "paho-mqtt<2" --upgrade
unzip ci/artifacts.zip -d ci
for dir in `ls -d ci/build_*`; do
rm -rf build sdkconfig.defaults
mv $dir build
mv build/*.py .
# Run only "test_mosquitto" marked tests
python -m pytest --log-cli-level DEBUG --junit-xml=./results_esp32_${{ matrix.idf_ver }}_${dir#"ci/build_"}.xml --target=esp32 -m test_mosquitto
done

View File

@@ -39,7 +39,7 @@ jobs:
if ! pre-commit run --from-ref origin/HEAD --to-ref HEAD --hook-stage manual --show-diff-on-failure ; then
echo ""
echo "::notice::It looks like the commits in this PR have been made without having pre-commit hooks installed."
echo "::notice::Please see https://github.com/espressif/esp-protocols/CONTRIBUTING.md for instructions."
echo "::notice::Please see https://github.com/espressif/esp-protocols/blob/master/CONTRIBUTING.md for instructions."
echo ""
exit 1
fi

View File

@@ -98,7 +98,11 @@ jobs:
components/console_cmd_ping;
components/console_cmd_ifconfig;
components/console_cmd_wifi;
components/console_cmd_mqtt;
components/mbedtls_cxx;
components/mosquitto;
components/sock_utils;
components/libwebsockets;
components/esp_dns;
namespace: "espressif"
api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }}

95
.github/workflows/sockutls_build.yml vendored Normal file
View File

@@ -0,0 +1,95 @@
name: "sock_utils: build-tests"
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened, labeled]
jobs:
build_sock_utils:
if: contains(github.event.pull_request.labels.*.name, 'sock_utils') || github.event_name == 'push'
name: Socket helpers build
strategy:
matrix:
idf_ver: ["latest", "release-v5.3"]
runs-on: ubuntu-22.04
container: espressif/idf:${{ matrix.idf_ver }}
env:
TEST_DIR: components/sock_utils/examples/simple
TARGET_TEST_DIR: build_esp32_default
steps:
- name: Checkout esp-protocols
uses: actions/checkout@v4
with:
submodules: recursive
- name: Build with IDF-${{ matrix.idf_ver }}
shell: bash
run: |
. ${IDF_PATH}/export.sh
pip install idf-component-manager idf-build-apps --upgrade
python ci/build_apps.py ${TEST_DIR}
cd ${TEST_DIR}
${GITHUB_WORKSPACE}/ci/clean_build_artifacts.sh `pwd`/${TARGET_TEST_DIR}
zip -qur artifacts.zip ${TARGET_TEST_DIR}
- uses: actions/upload-artifact@v4
with:
name: sock_utils_target_esp32_${{ matrix.idf_ver }}
path: ${{ env.TEST_DIR }}/artifacts.zip
if-no-files-found: error
host_test_sock_utils:
if: contains(github.event.pull_request.labels.*.name, 'sock_utils') || github.event_name == 'push'
name: Socket helpers host test
strategy:
matrix:
idf_ver: ["latest", "release-v5.3"]
runs-on: ubuntu-22.04
container: espressif/idf:${{ matrix.idf_ver }}
env:
TEST_DIR: components/sock_utils/test/host
steps:
- name: Checkout esp-protocols
uses: actions/checkout@v4
with:
submodules: recursive
- name: Build with IDF-${{ matrix.idf_ver }}
shell: bash
run: |
. ${IDF_PATH}/export.sh
pip install idf-component-manager idf-build-apps --upgrade
cd ${TEST_DIR}
idf.py build
./build/sock_utils_host_test.elf
test_sock_utils:
# Skip running on forks since it won't have access to secrets
if: |
github.repository == 'espressif/esp-protocols' &&
( contains(github.event.pull_request.labels.*.name, 'sock_utils') || github.event_name == 'push' )
name: Socket helpers target test
needs: build_sock_utils
strategy:
matrix:
idf_ver: ["latest", "release-v5.3"]
runs-on:
- self-hosted
- ESP32-ETHERNET-KIT
env:
TEST_DIR: components/sock_utils/examples/simple
TARGET_TEST_DIR: build_esp32_default
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: sock_utils_target_esp32_${{ matrix.idf_ver }}
path: ${{ env.TEST_DIR }}/ci/
- name: Run Test
working-directory: ${{ env.TEST_DIR }}
run: |
unzip ci/artifacts.zip -d ci
for dir in `ls -d ci/build_*`; do
rm -rf build sdkconfig.defaults
mv $dir build
python -m pytest --log-cli-level DEBUG --junit-xml=./results_esp32_${{ matrix.idf_ver }}_${dir#"ci/build_"}.xml --target=esp32
done

View File

@@ -15,7 +15,7 @@ jobs:
matrix:
idf_ver: ["latest", "release-v5.3", "release-v5.2", "release-v5.1"]
test: [ { app: client, path: "examples/tls_client" }, { app: udp, path: "examples/udp_mutual_auth" }, { app: test, path: "tests/uart_mutual_auth" } ]
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
container: espressif/idf:${{ matrix.idf_ver }}
steps:
- name: Checkout esp-protocols

View File

@@ -65,14 +65,27 @@ jobs:
with:
name: websocket_bin_esp32_${{ matrix.idf_ver }}_${{ matrix.test.app }}
path: ${{ env.TEST_DIR }}/ci/
- name: Install Python packages
- name: Run Example Test on target
working-directory: ${{ env.TEST_DIR }}
env:
PIP_EXTRA_INDEX_URL: "https://www.piwheels.org/simple"
run: |
pip install --only-binary cryptography --extra-index-url https://dl.espressif.com/pypi/ -r $GITHUB_WORKSPACE/ci/requirements.txt
- name: Run Example Test on target
working-directory: ${{ env.TEST_DIR }}
run: |
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
if ! pyenv versions --bare | grep -q '^3\.12\.6$'; then
echo "Installing Python 3.12.6..."
pyenv install -s 3.12.6
fi
if ! pyenv virtualenvs --bare | grep -q '^myenv$'; then
echo "Creating pyenv virtualenv 'myenv'..."
pyenv virtualenv 3.12.6 myenv
fi
pyenv activate myenv
python --version
pip install --prefer-binary cryptography pytest-embedded pytest-embedded-serial-esp pytest-embedded-idf pytest-custom_exit_code esptool
pip install --extra-index-url https://dl.espressif.com/pypi/ -r $GITHUB_WORKSPACE/ci/requirements.txt
unzip ci/artifacts.zip -d ci
for dir in `ls -d ci/build_*`; do
rm -rf build sdkconfig.defaults

6
.gitignore vendored
View File

@@ -94,3 +94,9 @@ docs/html
# esp-idf managed components
**/managed_components/**
# modem simulator uses esp-at clone
common_components/modem_sim/modem_sim_esp32/
# repository release tools
release_notes.txt

5
.gitmodules vendored
View File

@@ -1,6 +1,9 @@
[submodule "components/asio/asio"]
path = components/asio/asio
url = https://github.com/espressif/asio
url = https://github.com/chriskohlhoff/asio
[submodule "components/mosquitto/mosquitto"]
path = components/mosquitto/mosquitto
url = https://github.com/eclipse/mosquitto
[submodule "components/libwebsockets/libwebsockets"]
path = components/libwebsockets/libwebsockets
url = https://github.com/warmcat/libwebsockets.git

View File

@@ -25,12 +25,8 @@ repos:
(?x)^(
.*.py
)$
- repo: https://github.com/myint/unify
rev: v0.5
hooks:
- id: unify
- repo: https://github.com/pre-commit/mirrors-yapf
rev: "v0.32.0"
- repo: https://github.com/google/yapf
rev: "v0.43.0"
hooks:
- id: yapf
args: ['style={based_on_style: google, column_limit: 160, indent_width: 4}']
@@ -39,7 +35,7 @@ repos:
hooks:
- id: isort
- repo: https://github.com/myint/eradicate/
rev: v2.1.0
rev: 3.0.0
hooks:
- id: eradicate
- repo: https://github.com/espressif/check-copyright/
@@ -51,7 +47,7 @@ repos:
rev: v1.0.5
hooks:
- id: astyle_py
args: ['--style=otbs', '--attach-namespaces', '--attach-classes', '--indent=spaces=4', '--convert-tabs', '--align-pointer=name', '--align-reference=name', '--keep-one-line-statements', '--pad-header', '--pad-oper', '--exclude-list=ci/ignore_astyle.txt']
args: ['--style=otbs', '--attach-namespaces', '--attach-classes', '--indent=spaces=4', '--convert-tabs', '--align-reference=name', '--keep-one-line-statements', '--pad-header', '--pad-oper', '--unpad-paren', '--max-continuation-indent=120', '--exclude-list=ci/ignore_astyle.txt']
- repo: https://github.com/commitizen-tools/commitizen
rev: v2.42.1
hooks:
@@ -61,8 +57,8 @@ repos:
- repo: local
hooks:
- id: commit message scopes
name: "commit message must be scoped with: mdns, modem, websocket, asio, mqtt_cxx, console, common, eppp, tls_cxx, mosq"
entry: '\A(?!(feat|fix|ci|bump|test|docs|chore)\((mdns|modem|common|console|websocket|asio|mqtt_cxx|examples|eppp|tls_cxx|mosq)\)\:)'
name: "commit message must be scoped with: mdns, dns, modem, websocket, asio, mqtt_cxx, console, common, eppp, tls_cxx, mosq, sockutls, lws, modem_sim"
entry: '\A(?!(feat|fix|ci|bump|test|docs|chore)\((mdns|dns|modem|common|console|websocket|asio|mqtt_cxx|examples|eppp|tls_cxx|mosq|sockutls|lws|modem_sim)\)\:)'
language: pygrep
args: [--multiline]
stages: [commit-msg]

View File

@@ -62,3 +62,19 @@ Please refer to instructions in [ESP-IDF](https://github.com/espressif/esp-idf)
* Brief introduction [README](components/mosquitto/README.md)
* API documentation [api.md](components/mosquitto/api.md)
### Socket helpers (sock-utils)
* Brief introduction [README](components/sock_utils/README.md)
### libwebsockets
* Brief introduction [README](components/libwebsockets/README.md)
### console_cmd_mqtt
* Brief introduction [README](components/console_cmd_mqtt/README.md)
### esp_dns
* Brief introduction [README](components/esp_dns/README.md)

View File

@@ -56,7 +56,7 @@ if __name__ == '__main__':
build_dir='build_@t_@w',
config_rules_str=args.rules,
build_log_filename='build_log.txt',
size_json_filename='size.json' if not args.linux else None,
size_json_filename=None,
check_warnings=True,
manifest_files=args.manifests,
default_build_targets=SUPPORTED_TARGETS,
@@ -65,6 +65,7 @@ if __name__ == '__main__':
sys.exit(
build_apps(apps,
verbose=2,
dry_run=False,
keep_going=False,
no_preserve=args.delete,

View File

@@ -0,0 +1 @@
components/mosquitto/examples/serverless_mqtt/components/libjuice/port/juice_random.c

7
ci/config_env.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# This script is used to set some common variables for the CI pipeline.
set -e
# MQTT public broker URI
export CI_MQTT_BROKER_URI="test.mosquitto.org"

View File

@@ -1 +1,7 @@
DeprecationWarning: pkg_resources is deprecated as an API
Warning: Deprecated: Option '--flash_size' is deprecated. Use '--flash-size' instead.
Warning: Deprecated: Option '--flash_mode' is deprecated. Use '--flash-mode' instead.
Warning: Deprecated: Option '--flash_freq' is deprecated. Use '--flash-freq' instead.
Warning: Deprecated: Command 'sign_data' is deprecated. Use 'sign-data' instead.
Warning: Deprecated: Command 'extract_public_key' is deprecated. Use 'extract-public-key' instead.
warning: unknown kconfig symbol 'EXAMPLE_ETH_PHY_IP101'

View File

@@ -6,3 +6,4 @@ dpkt
pytest
idf_build_apps
netifaces
esptool>=5.1.0

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -64,7 +64,7 @@ static struct generic_queue_handle *create_generic_queue(queue_type_t type, uint
return h;
}
QueueHandle_t xQueueCreate(uint32_t uxQueueLength, uint32_t uxItemSize )
QueueHandle_t xQueueCreate(uint32_t uxQueueLength, uint32_t uxItemSize)
{
return (QueueHandle_t)create_generic_queue(QUEUE, uxQueueLength, uxItemSize);
}
@@ -75,7 +75,7 @@ uint32_t xQueueSend(QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t
return osal_queue_send(h->q, (uint8_t *)pvItemToQueue, h->item_size) ? pdTRUE : pdFAIL;
}
uint32_t xQueueSendToBack(QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait )
uint32_t xQueueSendToBack(QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait)
{
return xQueueSend(xQueue, pvItemToQueue, xTicksToWait);
}
@@ -86,7 +86,7 @@ uint32_t xQueueReceive(QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksTo
return osal_queue_recv(h->q, (uint8_t *)pvBuffer, h->item_size, xTicksToWait) ? pdTRUE : pdFAIL;
}
BaseType_t xSemaphoreGive( QueueHandle_t xQueue)
BaseType_t xSemaphoreGive(QueueHandle_t xQueue)
{
struct generic_queue_handle *h = xQueue;
if (h->type == MUTEX) {
@@ -96,7 +96,7 @@ BaseType_t xSemaphoreGive( QueueHandle_t xQueue)
return xQueueSend(xQueue, &s_semaphore_data, portMAX_DELAY);
}
BaseType_t xSemaphoreGiveRecursive( QueueHandle_t xQueue)
BaseType_t xSemaphoreGiveRecursive(QueueHandle_t xQueue)
{
struct generic_queue_handle *h = xQueue;
if (h->type == MUTEX_REC) {
@@ -106,7 +106,7 @@ BaseType_t xSemaphoreGiveRecursive( QueueHandle_t xQueue)
return pdFALSE;
}
BaseType_t xSemaphoreTake( QueueHandle_t xQueue, TickType_t pvTask )
BaseType_t xSemaphoreTake(QueueHandle_t xQueue, TickType_t pvTask)
{
struct generic_queue_handle *h = xQueue;
if (h->type == MUTEX) {
@@ -116,7 +116,7 @@ BaseType_t xSemaphoreTake( QueueHandle_t xQueue, TickType_t pvTask )
return xQueueReceive(xQueue, &s_semaphore_data, portMAX_DELAY);
}
BaseType_t xSemaphoreTakeRecursive( QueueHandle_t xQueue, TickType_t pvTask )
BaseType_t xSemaphoreTakeRecursive(QueueHandle_t xQueue, TickType_t pvTask)
{
struct generic_queue_handle *h = xQueue;
if (h->type == MUTEX_REC) {
@@ -126,7 +126,7 @@ BaseType_t xSemaphoreTakeRecursive( QueueHandle_t xQueue, TickType_t pvTask )
return pdFALSE;
}
void vQueueDelete( QueueHandle_t xQueue )
void vQueueDelete(QueueHandle_t xQueue)
{
struct generic_queue_handle *h = xQueue;
if (h->q) {
@@ -166,6 +166,8 @@ void vTaskDelete(TaskHandle_t *task)
if (task == NULL) {
pthread_exit(0);
} else {
pthread_cancel((pthread_t)task);
}
void *thread_rval = NULL;
pthread_join((pthread_t)task, &thread_rval);
@@ -176,14 +178,14 @@ void vTaskSuspend(void *task)
vTaskDelete(task);
}
TickType_t xTaskGetTickCount( void )
TickType_t xTaskGetTickCount(void)
{
struct timespec spec;
clock_gettime(CLOCK_REALTIME, &spec);
return spec.tv_nsec / 1000000 + spec.tv_sec * 1000;
}
void vTaskDelay( const TickType_t xTicksToDelay )
void vTaskDelay(const TickType_t xTicksToDelay)
{
usleep(xTicksToDelay * 1000);
}
@@ -212,13 +214,27 @@ void *pthread_task(void *params)
return NULL;
}
BaseType_t xTaskCreatePinnedToCore( TaskFunction_t pvTaskCode,
const char *const pcName,
const uint32_t usStackDepth,
void *const pvParameters,
UBaseType_t uxPriority,
TaskHandle_t *const pvCreatedTask,
const BaseType_t xCoreID)
TaskHandle_t xTaskCreateStaticPinnedToCore(TaskFunction_t pxTaskCode,
const char *const pcName,
const uint32_t ulStackDepth,
void *const pvParameters,
UBaseType_t uxPriority,
StackType_t *const puxStackBuffer,
StaticTask_t *const pxTaskBuffer,
const BaseType_t xCoreID)
{
static TaskHandle_t pvCreatedTask;
xTaskCreate(pxTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, &pvCreatedTask);
return pvCreatedTask;
}
BaseType_t xTaskCreatePinnedToCore(TaskFunction_t pvTaskCode,
const char *const pcName,
const uint32_t usStackDepth,
void *const pvParameters,
UBaseType_t uxPriority,
TaskHandle_t *const pvCreatedTask,
const BaseType_t xCoreID)
{
xTaskCreate(pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pvCreatedTask);
return pdTRUE;
@@ -266,7 +282,7 @@ void xTaskNotifyGive(TaskHandle_t task)
}
}
BaseType_t xTaskNotifyWait(uint32_t bits_entry_clear, uint32_t bits_exit_clear, uint32_t *value, TickType_t wait_time )
BaseType_t xTaskNotifyWait(uint32_t bits_entry_clear, uint32_t bits_exit_clear, uint32_t *value, TickType_t wait_time)
{
return true;
}
@@ -276,32 +292,32 @@ TaskHandle_t xTaskGetCurrentTaskHandle(void)
return (TaskHandle_t)pthread_self();
}
EventGroupHandle_t xEventGroupCreate( void )
EventGroupHandle_t xEventGroupCreate(void)
{
return osal_signal_create();
}
void vEventGroupDelete( EventGroupHandle_t xEventGroup )
void vEventGroupDelete(EventGroupHandle_t xEventGroup)
{
osal_signal_delete(xEventGroup);
}
EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear )
EventBits_t xEventGroupClearBits(EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear)
{
return osal_signal_clear(xEventGroup, uxBitsToClear);
}
EventBits_t xEventGroupGetBits( EventGroupHandle_t xEventGroup)
EventBits_t xEventGroupGetBits(EventGroupHandle_t xEventGroup)
{
return osal_signal_get(xEventGroup);
}
EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet )
EventBits_t xEventGroupSetBits(EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet)
{
return osal_signal_set(xEventGroup, uxBitsToSet);
}
EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait )
EventBits_t xEventGroupWaitBits(EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait)
{
return osal_signal_wait(xEventGroup, uxBitsToWaitFor, xWaitForAllBits, xTicksToWait);
}

View File

@@ -1,11 +1,12 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "freertos/FreeRTOS.h"
#include "esp_heap_caps.h"
#ifdef __cplusplus
extern "C" {
@@ -15,7 +16,10 @@ extern "C" {
#define TaskHandle_t TaskHandle_t
#define vSemaphoreDelete( xSemaphore ) vQueueDelete( ( QueueHandle_t ) ( xSemaphore ) )
void vTaskDelay( const TickType_t xTicksToDelay );
typedef void *StackType_t;
typedef void *StaticTask_t;
void vTaskDelay(const TickType_t xTicksToDelay);
void xTaskNotifyGive(TaskHandle_t task);
@@ -23,39 +27,48 @@ void ulTaskNotifyTake(bool stuff, uint32_t timeout);
TaskHandle_t xTaskGetCurrentTaskHandle(void);
BaseType_t xTaskNotifyWait(uint32_t bits_entry_clear, uint32_t bits_exit_clear, uint32_t *value, TickType_t wait_time );
BaseType_t xTaskNotifyWait(uint32_t bits_entry_clear, uint32_t bits_exit_clear, uint32_t *value, TickType_t wait_time);
BaseType_t xTaskCreatePinnedToCore( TaskFunction_t pvTaskCode,
const char *const pcName,
const uint32_t usStackDepth,
void *const pvParameters,
UBaseType_t uxPriority,
TaskHandle_t *const pvCreatedTask,
const BaseType_t xCoreID);
TaskHandle_t xTaskCreateStaticPinnedToCore(TaskFunction_t pxTaskCode,
const char *const pcName,
const uint32_t ulStackDepth,
void *const pvParameters,
UBaseType_t uxPriority,
StackType_t *const puxStackBuffer,
StaticTask_t *const pxTaskBuffer,
const BaseType_t xCoreID);
BaseType_t xTaskCreatePinnedToCore(TaskFunction_t pvTaskCode,
const char *const pcName,
const uint32_t usStackDepth,
void *const pvParameters,
UBaseType_t uxPriority,
TaskHandle_t *const pvCreatedTask,
const BaseType_t xCoreID);
BaseType_t xTaskCreate(TaskFunction_t pvTaskCode, const char *const pcName, const uint32_t usStackDepth, void *const pvParameters, UBaseType_t uxPriority, TaskHandle_t *const pvCreatedTask);
TickType_t xTaskGetTickCount( void );
TickType_t xTaskGetTickCount(void);
void vQueueDelete( QueueHandle_t xQueue );
void vQueueDelete(QueueHandle_t xQueue);
QueueHandle_t xSemaphoreCreateBinary(void);
QueueHandle_t xSemaphoreCreateMutex(void);
QueueHandle_t xSemaphoreCreateRecursiveMutex(void);
BaseType_t xSemaphoreGive( QueueHandle_t xQueue);
BaseType_t xSemaphoreGive(QueueHandle_t xQueue);
BaseType_t xSemaphoreTake( QueueHandle_t xQueue, TickType_t pvTask );
BaseType_t xSemaphoreTake(QueueHandle_t xQueue, TickType_t pvTask);
BaseType_t xSemaphoreGiveRecursive( QueueHandle_t xQueue);
BaseType_t xSemaphoreGiveRecursive(QueueHandle_t xQueue);
BaseType_t xSemaphoreTakeRecursive( QueueHandle_t xQueue, TickType_t pvTask );
BaseType_t xSemaphoreTakeRecursive(QueueHandle_t xQueue, TickType_t pvTask);
void vTaskDelete(TaskHandle_t *task);
QueueHandle_t xQueueCreate( uint32_t uxQueueLength,
uint32_t uxItemSize );
QueueHandle_t xQueueCreate(uint32_t uxQueueLength,
uint32_t uxItemSize);
uint32_t xQueueSend(QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait);
@@ -63,23 +76,26 @@ uint32_t xQueueReceive(QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksTo
void vTaskSuspend(void *task);
EventGroupHandle_t xEventGroupCreate( void );
void vEventGroupDelete( EventGroupHandle_t xEventGroup );
EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup,
const EventBits_t uxBitsToClear );
EventGroupHandle_t xEventGroupCreate(void);
void vEventGroupDelete(EventGroupHandle_t xEventGroup);
EventBits_t xEventGroupClearBits(EventGroupHandle_t xEventGroup,
const EventBits_t uxBitsToClear);
EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
const EventBits_t uxBitsToWaitFor,
const BaseType_t xClearOnExit,
const BaseType_t xWaitForAllBits,
TickType_t xTicksToWait );
EventBits_t xEventGroupWaitBits(EventGroupHandle_t xEventGroup,
const EventBits_t uxBitsToWaitFor,
const BaseType_t xClearOnExit,
const BaseType_t xWaitForAllBits,
TickType_t xTicksToWait);
EventBits_t xEventGroupGetBits( EventGroupHandle_t xEventGroup);
EventBits_t xEventGroupGetBits(EventGroupHandle_t xEventGroup);
EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup,
const EventBits_t uxBitsToSet );
EventBits_t xEventGroupSetBits(EventGroupHandle_t xEventGroup,
const EventBits_t uxBitsToSet);
uint32_t xQueueSendToBack(QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait );
uint32_t xQueueSendToBack(QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait);
void *heap_caps_malloc(size_t size, uint32_t caps);
void heap_caps_free(void *ptr);
#ifdef __cplusplus
}

View File

@@ -0,0 +1,51 @@
# Modem Simulator Component
A Wi-Fi modem simulator that extends ESP-AT with PPP server capabilities, turning ESP32 into a fully functional Wi-Fi modem. Perfect for testing AT commands and PPP connections without real hardware dependencies.
## What it does
- Extends ESP-AT firmware with PPP server functionality
- Provides DATA mode for raw IP communication
- Enables existing communication stacks (MQTT, HTTP, custom protocols) to work over Wi-Fi
- Ideal for testing ESP-Modem library and CI reliability
## Quick Start
```bash
cd common_components/modem_sim
./install.sh
source export.sh
idf.py build
```
## Custom Platform/Module
```bash
./install.sh PLATFORM_ESP32S3 WROOM-32
```
## Configuration
The `sdkconfig.defaults` includes:
- Wi-Fi and Bluetooth enabled
- PPP server support
- AT commands for HTTP/MQTT
- 4MB flash configuration
## Project Structure
```
modem_sim/
├── install.sh # Installation script
├── export.sh # Environment setup
├── sdkconfig.defaults # Default configuration
├── pppd_cmd/ # Custom PPP commands
└── modem_sim_esp32/ # Generated ESP-AT build
```
## Use Cases
- Testing ESP-Modem library without real hardware
- Quick Wi-Fi connectivity for existing communication stacks
- CI/CD testing with reliable modem simulation
- Development and debugging of AT command implementations

View File

@@ -0,0 +1,11 @@
#!/bin/bash
source $IDF_PATH/export.sh
export AT_CUSTOM_COMPONENTS="`pwd`/pppd_cmd"
cd modem_sim_esp32/esp-at
python -m pip install -r requirements.txt
python build.py reconfigure

View File

@@ -0,0 +1,64 @@
#!/bin/bash
set -e
# Create directory "modem_sim_esp32", go inside it
# Usage: ./install.sh [platform] [module]
SCRIPT_DIR=$(pwd)
mkdir -p modem_sim_esp32
cd modem_sim_esp32
if [ -z "$IDF_PATH" ]; then
echo "Error: IDF_PATH environment variable is not set"
exit 1
fi
# Default ESP_AT_VERSION uses this specific commit from master to support new chips and features
ESP_AT_VERSION="aa9d7e0e9b741744f7bf5bec3bbf887cff033d5f"
# Shallow clone of esp-at.git at $ESP_AT_VERSION
if [ ! -d "esp-at" ]; then
# cannot shallow clone from a specific commit, so we init, shallow fetch, and checkout
mkdir -p esp-at && cd esp-at && git init && git remote add origin https://github.com/espressif/esp-at.git
git fetch --depth 1 origin $ESP_AT_VERSION && git checkout $ESP_AT_VERSION
else
echo "esp-at directory already exists, skipping clone."
cd esp-at
fi
# Add esp-idf directory which is a symlink to the $IDF_PATH
if [ ! -L "esp-idf" ]; then
ln -sf "$IDF_PATH" esp-idf
else
echo "esp-idf symlink already exists, skipping."
fi
# Create "build" directory
mkdir -p build
# Default values for platform and module
platform="PLATFORM_ESP32"
module="WROOM-32"
# Override defaults if parameters are provided
if [ ! -z "$1" ]; then
platform="$1"
fi
if [ ! -z "$2" ]; then
module="$2"
fi
# Create file "build/module_info.json" with content
cat > build/module_info.json << EOF
{
"platform": "$platform",
"module": "$module",
"description": "4MB, Wi-Fi + BLE, OTA, TX:17 RX:16",
"silence": 0
}
EOF
cp "$SCRIPT_DIR/sdkconfig.defaults" "module_config/module_esp32_default/sdkconfig.defaults"
echo "Installation completed successfully!"
echo "Created modem_sim_esp32 directory with esp-at repository and configuration"

View File

@@ -0,0 +1,6 @@
idf_component_register(
SRCS additional_commands.c
INCLUDE_DIRS include
REQUIRES at freertos nvs_flash)
idf_component_set_property(${COMPONENT_NAME} WHOLE_ARCHIVE TRUE)

View File

@@ -0,0 +1,411 @@
/*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include "esp_at.h"
#include "driver/gpio.h"
#include "driver/uart.h"
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "freertos/semphr.h"
#include "freertos/queue.h"
#include "esp_netif.h"
#include "esp_netif_ppp.h"
#include "esp_check.h"
#include "esp_http_server.h"
#include "esp_timer.h"
static uint8_t at_test_cmd_test(uint8_t *cmd_name)
{
uint8_t buffer[64] = {0};
snprintf((char *)buffer, 64, "test command: <AT%s=?> is executed\r\n", cmd_name);
esp_at_port_write_data(buffer, strlen((char *)buffer));
return ESP_AT_RESULT_CODE_OK;
}
static uint8_t at_query_cmd_test(uint8_t *cmd_name)
{
uint8_t buffer[64] = {0};
snprintf((char *)buffer, 64, "query command: <AT%s?> is executed\r\n", cmd_name);
esp_at_port_write_data(buffer, strlen((char *)buffer));
return ESP_AT_RESULT_CODE_OK;
}
static uint8_t at_setup_cmd_test(uint8_t para_num)
{
uint8_t index = 0;
printf("setup command: <AT%s=%d> is executed\r\n", esp_at_get_current_cmd_name(), para_num);
// get first parameter, and parse it into a digit
int32_t digit = 0;
if (esp_at_get_para_as_digit(index++, &digit) != ESP_AT_PARA_PARSE_RESULT_OK) {
return ESP_AT_RESULT_CODE_ERROR;
}
printf("digit: %d\r\n", digit);
// get second parameter, and parse it into a string
uint8_t *str = NULL;
if (esp_at_get_para_as_str(index++, &str) != ESP_AT_PARA_PARSE_RESULT_OK) {
return ESP_AT_RESULT_CODE_ERROR;
}
printf("string: %s\r\n", str);
// allocate a buffer and construct the data, then send the data to mcu via interface (uart/spi/sdio/socket)
uint8_t *buffer = (uint8_t *)malloc(512);
if (!buffer) {
return ESP_AT_RESULT_CODE_ERROR;
}
int len = snprintf((char *)buffer, 512, "setup command: <AT%s=%d,\"%s\"> is executed\r\n",
esp_at_get_current_cmd_name(), digit, str);
esp_at_port_write_data(buffer, len);
// remember to free the buffer
free(buffer);
return ESP_AT_RESULT_CODE_OK;
}
#define TAG "at_custom_cmd"
static esp_netif_t *s_netif = NULL;
static httpd_handle_t http_server = NULL;
static void on_ppp_event(void *arg, esp_event_base_t base, int32_t event_id, void *data)
{
esp_netif_t **netif = data;
if (base == NETIF_PPP_STATUS && event_id == NETIF_PPP_ERRORUSER) {
printf("Disconnected!");
}
}
static void on_ip_event(void *arg, esp_event_base_t base, int32_t event_id, void *data)
{
ip_event_got_ip_t *event = (ip_event_got_ip_t *)data;
esp_netif_t *netif = event->esp_netif;
if (event_id == IP_EVENT_PPP_GOT_IP) {
printf("Got IPv4 event: Interface \"%s(%s)\" address: " IPSTR, esp_netif_get_desc(netif),
esp_netif_get_ifkey(netif), IP2STR(&event->ip_info.ip));
ESP_ERROR_CHECK(esp_netif_napt_enable(s_netif));
} else if (event_id == IP_EVENT_PPP_LOST_IP) {
ESP_LOGI(TAG, "Disconnected");
}
}
static SemaphoreHandle_t at_sync_sema = NULL;
static void wait_data_callback(void)
{
static uint8_t buffer[1500] = {0};
int len = esp_at_port_read_data(buffer, sizeof(buffer) - 1);
// Check for the escape sequence "+++" in the received data
const uint8_t escape_seq[] = "+++";
uint8_t *escape_ptr = memmem(buffer, len, escape_seq, 3);
if (escape_ptr != NULL) {
printf("Found +++ sequence, signal to the command processing thread\n");
int data_before_escape = escape_ptr - buffer;
if (data_before_escape > 0) {
esp_netif_receive(s_netif, buffer, data_before_escape, NULL);
}
if (at_sync_sema) {
xSemaphoreGive(at_sync_sema);
}
return;
}
esp_netif_receive(s_netif, buffer, len, NULL);
}
static esp_err_t transmit(void *h, void *buffer, size_t len)
{
printf("transmit: %d bytes\n", len);
esp_at_port_write_data(buffer, len);
return ESP_OK;
}
static uint8_t at_exe_cmd_test(uint8_t *cmd_name)
{
uint8_t buffer[64] = {0};
snprintf((char *)buffer, 64, "execute command: <AT%s> is executed\r\n", cmd_name);
esp_at_port_write_data(buffer, strlen((char *)buffer));
printf("Command <AT%s> executed successfully\r\n", cmd_name);
if (!at_sync_sema) {
at_sync_sema = xSemaphoreCreateBinary();
assert(at_sync_sema != NULL);
esp_netif_driver_ifconfig_t driver_cfg = {
.handle = (void *)1,
.transmit = transmit,
};
const esp_netif_driver_ifconfig_t *ppp_driver_cfg = &driver_cfg;
esp_netif_inherent_config_t base_netif_cfg = ESP_NETIF_INHERENT_DEFAULT_PPP();
esp_netif_config_t netif_ppp_config = { .base = &base_netif_cfg,
.driver = ppp_driver_cfg,
.stack = ESP_NETIF_NETSTACK_DEFAULT_PPP
};
s_netif = esp_netif_new(&netif_ppp_config);
esp_netif_ppp_config_t netif_params;
ESP_ERROR_CHECK(esp_netif_ppp_get_params(s_netif, &netif_params));
netif_params.ppp_our_ip4_addr.addr = ESP_IP4TOADDR(192, 168, 11, 1);
netif_params.ppp_their_ip4_addr.addr = ESP_IP4TOADDR(192, 168, 11, 2);
netif_params.ppp_error_event_enabled = true;
ESP_ERROR_CHECK(esp_netif_ppp_set_params(s_netif, &netif_params));
if (esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, on_ip_event, NULL) != ESP_OK) {
printf("Failed to register IP event handler");
}
if (esp_event_handler_register(NETIF_PPP_STATUS, ESP_EVENT_ANY_ID, on_ppp_event, NULL) != ESP_OK) {
printf("Failed to register NETIF_PPP_STATUS event handler");
}
}
esp_at_port_write_data((uint8_t *)"CONNECT\r\n", strlen("CONNECT\r\n"));
// set the callback function which will be called by AT port after receiving the input data
esp_at_port_enter_specific(wait_data_callback);
esp_netif_action_start(s_netif, 0, 0, 0);
esp_netif_action_connected(s_netif, 0, 0, 0);
while (xSemaphoreTake(at_sync_sema, pdMS_TO_TICKS(1000)) == pdFALSE) {
printf(".");
}
return ESP_AT_RESULT_CODE_OK;
}
static uint8_t at_test_cereg(uint8_t *cmd_name)
{
printf("%s: AT command <AT%s> is executed\r\n", __func__, cmd_name);
return ESP_AT_RESULT_CODE_OK;
}
static uint8_t at_query_cereg(uint8_t *cmd_name)
{
printf("%s: AT command <AT%s> is executed\r\n", __func__, cmd_name);
static uint8_t buffer[] = "+CEREG: 7,8\r\n";
esp_at_port_write_data(buffer, sizeof(buffer));
return ESP_AT_RESULT_CODE_OK;
}
static uint8_t at_setup_cereg(uint8_t num)
{
printf("%s: AT command <AT%d> is executed\r\n", __func__, num);
return ESP_AT_RESULT_CODE_OK;
}
static uint8_t at_exe_cereg(uint8_t *cmd_name)
{
printf("%s: AT command <AT%s> is executed\r\n", __func__, cmd_name);
return ESP_AT_RESULT_CODE_OK;
}
static esp_err_t hello_get_handler(httpd_req_t *req)
{
const char* resp_str = "Hello from ESP-AT HTTP Server!";
httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
return ESP_OK;
}
static esp_err_t root_get_handler(httpd_req_t *req)
{
const char* resp_str = "ESP-AT HTTP Server is running";
httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
return ESP_OK;
}
static esp_err_t test_get_handler(httpd_req_t *req)
{
const char* resp_str = "{\"status\":\"success\",\"message\":\"Test endpoint working\",\"timestamp\":12345}";
httpd_resp_set_type(req, "application/json");
httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
return ESP_OK;
}
static esp_err_t async_get_handler(httpd_req_t *req)
{
printf("Starting async chunked response handler\r\n");
// Set content type for plain text response
httpd_resp_set_type(req, "text/plain");
// Static counter to track requests
static uint8_t req_count = 0;
req_count++;
// Send initial response with request count
char buffer[256];
snprintf(buffer, sizeof(buffer), "=== Async Response #%d ===\r\n", req_count);
httpd_resp_sendstr_chunk(req, buffer);
// Long message broken into chunks
const char* chunks[] = {
"This is a simulated slow server response.\r\n",
"Chunk 1: The ESP-AT HTTP server is demonstrating...\r\n",
"Chunk 2: ...asynchronous chunked transfer encoding...\r\n",
"Chunk 3: ...with artificial delays between chunks...\r\n",
"Chunk 4: ...to simulate real-world network conditions.\r\n",
"Chunk 5: Processing data... please wait...\r\n",
"Chunk 6: Still processing... almost done...\r\n",
"Chunk 7: Final chunk - transfer complete!\r\n",
"=== END OF RESPONSE ===\r\n"
};
int num_chunks = sizeof(chunks) / sizeof(chunks[0]);
// Send each chunk with delays
for (int i = 0; i < num_chunks; i++) {
// Add a delay to simulate slow processing
vTaskDelay(pdMS_TO_TICKS(1500)); // 1.5 second delay between chunks
// Add chunk number and timestamp
snprintf(buffer, sizeof(buffer), "[%d/%d] [%d ms] %s",
i + 1, num_chunks, (int)(esp_timer_get_time() / 1000), chunks[i]);
printf("Sending chunk %d: %s", i + 1, chunks[i]);
httpd_resp_sendstr_chunk(req, buffer);
}
// Add final summary
vTaskDelay(pdMS_TO_TICKS(500));
snprintf(buffer, sizeof(buffer), "\r\nTransfer completed in %d chunks with delays.\r\n", num_chunks);
httpd_resp_sendstr_chunk(req, buffer);
// Send NULL to signal end of chunked transfer
httpd_resp_sendstr_chunk(req, NULL);
printf("Async chunked response completed\r\n");
return ESP_OK;
}
static const httpd_uri_t hello = {
.uri = "/hello",
.method = HTTP_GET,
.handler = hello_get_handler,
.user_ctx = NULL
};
static const httpd_uri_t root = {
.uri = "/",
.method = HTTP_GET,
.handler = root_get_handler,
.user_ctx = NULL
};
static const httpd_uri_t test = {
.uri = "/test",
.method = HTTP_GET,
.handler = test_get_handler,
.user_ctx = NULL
};
static const httpd_uri_t async_uri = {
.uri = "/async",
.method = HTTP_GET,
.handler = async_get_handler,
.user_ctx = NULL
};
static esp_err_t start_http_server(void)
{
if (http_server != NULL) {
printf("HTTP server already running\r\n");
return ESP_OK;
}
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
config.server_port = 8080;
config.lru_purge_enable = true;
printf("Starting HTTP server on port: %d\r\n", config.server_port);
if (httpd_start(&http_server, &config) == ESP_OK) {
printf("Registering URI handlers\r\n");
httpd_register_uri_handler(http_server, &hello);
httpd_register_uri_handler(http_server, &root);
httpd_register_uri_handler(http_server, &test);
httpd_register_uri_handler(http_server, &async_uri);
return ESP_OK;
}
printf("Error starting HTTP server!\r\n");
return ESP_FAIL;
}
static esp_err_t stop_http_server(void)
{
if (http_server != NULL) {
httpd_stop(http_server);
http_server = NULL;
printf("HTTP server stopped\r\n");
return ESP_OK;
}
return ESP_OK;
}
/* HTTP Server AT Commands */
static uint8_t at_test_httpd(uint8_t *cmd_name)
{
uint8_t buffer[64] = {0};
snprintf((char *)buffer, 64, "AT%s=<0/1> - Start/Stop HTTP server\r\n", cmd_name);
esp_at_port_write_data(buffer, strlen((char *)buffer));
return ESP_AT_RESULT_CODE_OK;
}
static uint8_t at_query_httpd(uint8_t *cmd_name)
{
uint8_t buffer[64] = {0};
snprintf((char *)buffer, 64, "+HTTPD:%d\r\n", http_server != NULL ? 1 : 0);
esp_at_port_write_data(buffer, strlen((char *)buffer));
return ESP_AT_RESULT_CODE_OK;
}
static uint8_t at_setup_httpd(uint8_t para_num)
{
int32_t action = 0;
if (esp_at_get_para_as_digit(0, &action) != ESP_AT_PARA_PARSE_RESULT_OK) {
return ESP_AT_RESULT_CODE_ERROR;
}
if (action == 1) {
if (start_http_server() == ESP_OK) {
printf("HTTP server started successfully\r\n");
return ESP_AT_RESULT_CODE_OK;
}
} else if (action == 0) {
if (stop_http_server() == ESP_OK) {
return ESP_AT_RESULT_CODE_OK;
}
}
return ESP_AT_RESULT_CODE_ERROR;
}
static uint8_t at_exe_httpd(uint8_t *cmd_name)
{
// Default action: start server
if (start_http_server() == ESP_OK) {
printf("HTTP server started via execute command\r\n");
return ESP_AT_RESULT_CODE_OK;
}
return ESP_AT_RESULT_CODE_ERROR;
}
static const esp_at_cmd_struct at_custom_cmd[] = {
{"+PPPD", at_test_cmd_test, at_query_cmd_test, at_setup_cmd_test, at_exe_cmd_test},
{"+CEREG", at_test_cereg, at_query_cereg, at_setup_cereg, at_exe_cereg},
{"+HTTPD", at_test_httpd, at_query_httpd, at_setup_httpd, at_exe_httpd},
};
bool esp_at_custom_cmd_register(void)
{
return esp_at_custom_cmd_array_regist(at_custom_cmd, sizeof(at_custom_cmd) / sizeof(esp_at_cmd_struct));
}
ESP_AT_CMD_SET_INIT_FN(esp_at_custom_cmd_register, 1);

View File

@@ -0,0 +1,12 @@
/*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "esp_at_core.h"
#include "esp_at.h"
/**
* @brief You can include more header files here for your own AT commands.
*/

View File

@@ -0,0 +1,79 @@
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) 5.4.1 Project Minimal Configuration
#
CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
CONFIG_APP_PROJECT_VER_FROM_CONFIG=y
CONFIG_APP_PROJECT_VER="v4.1.0.0-dev"
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="module_config/module_esp32_default/partitions_at.csv"
CONFIG_PARTITION_TABLE_MD5=n
CONFIG_AT_CUSTOMIZED_PARTITION_TABLE_FILE="module_config/module_esp32_default/at_customize.csv"
CONFIG_BT_ENABLED=y
CONFIG_BT_BTU_TASK_STACK_SIZE=5120
CONFIG_BT_BLE_BLUFI_ENABLE=y
CONFIG_BT_STACK_NO_LOG=y
CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY=y
CONFIG_BTDM_CTRL_MODE_BTDM=y
CONFIG_BTDM_CTRL_LPCLK_SEL_EXT_32K_XTAL=y
CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE=200
CONFIG_ESP_TLS_PSK_VERIFICATION=y
CONFIG_ESP_TLS_INSECURE=y
CONFIG_ESP_TLS_SKIP_SERVER_CERT_VERIFY=y
CONFIG_ESP_ERR_TO_NAME_LOOKUP=n
CONFIG_GPIO_ESP32_SUPPORT_SWITCH_SLP_PULL=y
CONFIG_ETH_DMA_RX_BUFFER_NUM=3
CONFIG_ETH_DMA_TX_BUFFER_NUM=3
CONFIG_HTTPD_MAX_REQ_HDR_LEN=1024
CONFIG_HTTPD_MAX_URI_LEN=1024
CONFIG_ESP_HTTPS_OTA_ALLOW_HTTP=y
CONFIG_RTC_CLK_SRC_EXT_CRYS=y
CONFIG_RTC_EXT_CRYST_ADDIT_CURRENT=y
CONFIG_RTC_CLK_CAL_CYCLES=1024
CONFIG_PM_ENABLE=y
CONFIG_PM_SLP_DISABLE_GPIO=y
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_80=y
CONFIG_ESP_TASK_WDT_PANIC=y
CONFIG_ESP_TASK_WDT_TIMEOUT_S=60
CONFIG_ESP_DEBUG_OCDAWARE=n
CONFIG_ESP_WIFI_IRAM_OPT=n
CONFIG_ESP_WIFI_RX_IRAM_OPT=n
CONFIG_ESP_WIFI_SLP_IRAM_OPT=y
CONFIG_ESP_WIFI_SLP_BEACON_LOST_OPT=y
CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM=0
CONFIG_FATFS_LFN_HEAP=y
CONFIG_FREERTOS_UNICORE=y
CONFIG_FREERTOS_HZ=1000
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=n
CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH=y
CONFIG_HEAP_PLACE_FUNCTION_INTO_FLASH=y
CONFIG_LOG_DEFAULT_LEVEL_ERROR=y
CONFIG_LWIP_MAX_SOCKETS=16
CONFIG_LWIP_SO_LINGER=y
CONFIG_LWIP_SO_RCVBUF=y
CONFIG_LWIP_IP4_REASSEMBLY=y
CONFIG_LWIP_IP6_REASSEMBLY=y
CONFIG_LWIP_IPV6_AUTOCONFIG=y
CONFIG_LWIP_TCP_MAXRTX=6
CONFIG_LWIP_TCP_SYNMAXRTX=3
CONFIG_LWIP_PPP_SUPPORT=y
CONFIG_LWIP_PPP_SERVER_SUPPORT=y
CONFIG_LWIP_SNTP_MAX_SERVERS=3
CONFIG_LWIP_SNTP_STARTUP_DELAY=n
CONFIG_MBEDTLS_DYNAMIC_BUFFER=y
CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA=y
CONFIG_MBEDTLS_SSL_KEEP_PEER_CERTIFICATE=n
CONFIG_MBEDTLS_HAVE_TIME_DATE=y
CONFIG_MBEDTLS_DHM_C=y
CONFIG_NEWLIB_NANO_FORMAT=y
CONFIG_VFS_SUPPORT_TERMIOS=n
CONFIG_WL_SECTOR_SIZE_512=y
CONFIG_AT_PROCESS_TASK_STACK_SIZE=6144
CONFIG_AT_MQTT_COMMAND_SUPPORT=y
CONFIG_AT_HTTP_COMMAND_SUPPORT=y
CONFIG_AT_BLE_COMMAND_SUPPORT=n
CONFIG_AT_BLE_HID_COMMAND_SUPPORT=n
CONFIG_AT_BLUFI_COMMAND_SUPPORT=n
CONFIG_LWIP_IP_FORWARD=y
CONFIG_LWIP_IPV4_NAPT=y

View File

@@ -1,7 +1,8 @@
---
commitizen:
bump_message: 'bump(asio): $current_version -> $new_version'
pre_bump_hooks: python ../../ci/changelog.py asio
tag_format: asio-v$version
version: 1.28.0~0
version: 1.32.0
version_files:
- idf_component.yml

View File

@@ -1,5 +1,26 @@
# Changelog
## [1.32.0](https://github.com/espressif/esp-protocols/commits/asio-v1.32.0)
### Features
- Upgrade asio to 1.32 ([9bdd429c](https://github.com/espressif/esp-protocols/commit/9bdd429c))
- Drop esp/asio patches in favor of sock-utils ([27435b7f](https://github.com/espressif/esp-protocols/commit/27435b7f))
### Bug Fixes
- Fix chat example to print only the message body ([76aaea08](https://github.com/espressif/esp-protocols/commit/76aaea08))
- Make asio enable if_nametoindex to fix linking ([5db32cce](https://github.com/espressif/esp-protocols/commit/5db32cce))
- Re-applie refs to common comps idf_component.yml ([9fe44a45](https://github.com/espressif/esp-protocols/commit/9fe44a45))
- Reference common component from IDF ([74fc228c](https://github.com/espressif/esp-protocols/commit/74fc228c))
- Revert referencing protocol_examples_common from IDF ([f9e0281a](https://github.com/espressif/esp-protocols/commit/f9e0281a))
- reference protocol_examples_common from IDF ([09abb18b](https://github.com/espressif/esp-protocols/commit/09abb18b))
- specify override_path in example manifest files ([1d8923cf](https://github.com/espressif/esp-protocols/commit/1d8923cf))
### Updated
- docs(asio): Updates asio docs ([ce9337d3](https://github.com/espressif/esp-protocols/commit/ce9337d3))
## [1.28.2~0](https://github.com/espressif/esp-protocols/commits/asio-1.28.2_0)
### Bug Fixes

View File

@@ -6,8 +6,8 @@ if(NOT CONFIG_LWIP_IPV6 AND NOT CMAKE_BUILD_EARLY_EXPANSION)
return()
endif()
set(asio_sources "asio/asio/src/asio.cpp")
set(asio_requires lwip)
set(asio_sources "asio/asio/src/asio.cpp" "port/src/asio_stub.cpp")
set(asio_requires lwip sock_utils)
if(CONFIG_ASIO_SSL_SUPPORT)
list(APPEND asio_sources
@@ -18,7 +18,7 @@ if(CONFIG_ASIO_SSL_SUPPORT)
endif()
idf_component_register(SRCS ${asio_sources}
INCLUDE_DIRS "asio/asio/include" "port/include"
INCLUDE_DIRS "port/include" "asio/asio/include"
PRIV_INCLUDE_DIRS ${asio_priv_includes}
PRIV_REQUIRES ${asio_requires})
@@ -30,6 +30,7 @@ target_compile_definitions(${COMPONENT_LIB} PUBLIC SA_RESTART=0x01
ASIO_STANDALONE
ASIO_HAS_PTHREADS
OPENSSL_NO_ENGINE
ASIO_DETAIL_IMPL_POSIX_EVENT_IPP # this replaces asio's posix_event constructor
)
if(NOT CONFIG_COMPILER_CXX_EXCEPTIONS)

View File

@@ -1,6 +1,15 @@
menu "ESP-ASIO"
visible if LWIP_IPV6
config ASIO_IS_ENABLED
# Invisible option that is enabled if ASIO is added to the IDF components.
# This is used to "select" LWIP_NETIF_API option
# which enables if_indextoname() and if_nametoindex() functions
# (these are optionally used in asio)
bool
default "y"
select LWIP_NETIF_API
config ASIO_SSL_SUPPORT
bool "Enable SSL/TLS support of ASIO"
default n

View File

@@ -120,7 +120,7 @@ private:
asio::buffer(read_msg_.body(), read_msg_.body_length()),
[this, self](std::error_code ec, std::size_t /*length*/) {
if (!ec) {
ESP_LOGD("asio-chat:", "%s", read_msg_.body());
ESP_LOGD("asio-chat", "%.*s", read_msg_.body_length(), read_msg_.body());
room_.deliver(read_msg_);
do_read_header();
} else {

View File

@@ -17,6 +17,8 @@
#include "asio/ssl.hpp"
#include "asio/buffer.hpp"
#include "esp_pthread.h"
// allows for direct access to mbedtls specifics
#include "asio/ssl/mbedtls_specific.hpp"
extern const unsigned char server_pem_start[] asm("_binary_srv_crt_start");
extern const unsigned char server_pem_end[] asm("_binary_srv_crt_end");
@@ -217,6 +219,7 @@ void ssl_server_thread()
io_context.run();
}
void ssl_client_thread()
{
asio::io_context io_context;
@@ -229,6 +232,11 @@ void ssl_client_thread()
asio::ssl::context ctx(asio::ssl::context::tls_client);
#if CONFIG_EXAMPLE_CLIENT_VERIFY_PEER
ctx.add_certificate_authority(cert_chain);
// mbedtls (from 3.6.3) requires hostname to be set when performing TLS handshake with verify-peer option
// asio::ssl allows for name verification using verification callback, i.e. socket_.set_verify_callback(asio::ssl::host_name_verification()),
// - which is not supported in Espressif ASIO port yet.
// Therefore we provide a way to directly use mbedtls API and here we just configure the expected hostname to verify
asio::ssl::mbedtls::set_hostname(ctx.native_handle(), server_ip);
#endif // CONFIG_EXAMPLE_CLIENT_VERIFY_PEER
Client c(io_context, ctx, endpoints);

View File

@@ -1,22 +1,22 @@
-----BEGIN CERTIFICATE-----
MIIDkzCCAnugAwIBAgIUNI5wldYysh6rtCzYmda6H414aRswDQYJKoZIhvcNAQEL
MIIDkzCCAnugAwIBAgIUb25LYOLubieEbKPQDiM+8T5p4yUwDQYJKoZIhvcNAQEL
BQAwWTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDESMBAGA1UEAwwJRXNwcmVzc2lmMB4X
DTIwMDEyMTA5MDk0NloXDTI1MDEyMDA5MDk0NlowWTELMAkGA1UEBhMCQVUxEzAR
DTI1MDQwNzA5NDkzOFoXDTQ1MDQwMjA5NDkzOFowWTELMAkGA1UEBhMCQVUxEzAR
BgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5
IEx0ZDESMBAGA1UEAwwJRXNwcmVzc2lmMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A
MIIBCgKCAQEAyadSpRnIQBVbEAsbpkrKrOMlBOMIUmA8AfNyOYPLfv0Oa5lBiMAV
3OQDu5tYyFYKwkCUqq65iAm50fPbSH71w1tkja6nZ1yAIM+TvpMlM/WiFGrhY+Tc
kAcLcKUJyPxrv/glzoVslbqUgIhuhCSKA8uk1+ILcn3nWzPcbcowLx31+AHeZj8h
bIAdj6vjqxMCFStp4IcA+ikmCk75LCN4vkkifdkebb/ZDNYCZZhpCBnCHyFAjPc4
7C+FDVGT3/UUeeTy+Mtn+MqUAhB+W0sPDm1n2h59D4Z/MFm0hl6GQCAKeMJPzssU
BBsRm6zoyPQ4VTqG0uwfNNbORyIfKONMUwIDAQABo1MwUTAdBgNVHQ4EFgQUGYLV
EkgWzxjpltE6texha7zZVxowHwYDVR0jBBgwFoAUGYLVEkgWzxjpltE6texha7zZ
VxowDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAb2EF4Zg2XWNb
eZHnzupCDd9jAhwPqkt7F1OXvxJa/RFUSB9+2izGvikGGhuKY4f0iLuqF+bhExD9
sapDcdFO2Suh4J3onbwEvmKvsv56K3xhapYg8WwPofpkVirnkwFjpQXGzrYxPujg
BPmSy3psQrhvOr/WH7SefJv2qr4ikaugfE+3enY4PL+C1dSQAuNo1QGgWsZIu0c8
TZybNZ13vNVMA+tgj2CM8FR3Etaabwtu3TTcAnO7aoBTix/bLBTuZoczhN8/MhG3
GylmDzFI8a6aKxQL3Fi4PsM82hRKWu3gfs39sR1Ci4V22v8uO5EWBPK0QZvDSc1a
KwwxI4zA0w==
MIIBCgKCAQEArJsjwSNjPOBpTCRW+pIag9gJgRaNIjscea/ilRYRwAnqWKLNssNw
Kye79KmQ5TxnOEvBIYjesArst1l7MghPLaELscCKo96jzCkSmgPLbxPs+5/E4daO
9ItxOSH2mjOgG5yFQLEb8xOvsvWWrJAUBj6RBjhzgSYLYRbesWKAyVi9fxSuzfZm
ROV0B2NsO1PlUDzweo9RYSuvpyNR3kddNnc6lJLXtZhf6IHczjFDFd5/PQuzLIO/
Dbg+5AMpQykbMFhcQI/Y49GlMMXFDIaWjP+XfE/yUJ4GyYd2EzpDFDFMisnkuR9d
LQgSXZNwygO8SIfYnnm1pwcGuG/fCQZYpQIDAQABo1MwUTAdBgNVHQ4EFgQUMTUG
OZ7ujyz7oXSuhDgbpoPRo1cwHwYDVR0jBBgwFoAUMTUGOZ7ujyz7oXSuhDgbpoPR
o1cwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAD5JwzRVEvnTK
R2bfMNy60FmFNTOEEYP+XYoNGBiXVY3MRrWlfbY5Pbs4Nq7sCfzEWMj2UsjFmjZE
DU6FdsaL6rhnps03MR5yiuE5w2aPiH/ijgzVfZtdLe6nKcnrv1YInjEKk+Y3qGu6
2ZC+MEINPBfRiuN6gCAdxGiK81J4FPLlZImLO/g/0fSrIXCzBUzjoYRYjsy5AP60
0kbaoGA/SshP0aeNvWB0wUab40idGXBFJ3vnEfMbLIMdc/uCqnzRpqK0m1DacwrI
nTUMl0bI302Oa/gym+Ma0nJ1nVADcLKoZ1syWjyzIcl6zr+ITY5S+pbeO/geQgKh
NSUkahX6MQ==
-----END CERTIFICATE-----

View File

@@ -0,0 +1,22 @@
#!/bin/bash
# This script generates self-signed certificates for testing purposes only.
# DO NOT use these certificates in production environments.
# These certificates are meant for development and testing of SSL/TLS functionality.
# 1. Generate CA private key
openssl genrsa -out ca.key 2048
# 2. Generate CA certificate (validity: 20 years, CN=Espressif)
openssl req -x509 -new -nodes -key ca.key -sha256 -days 7300 -out ca.crt -subj "/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd/CN=Espressif"
# 3. Generate server private key
openssl genrsa -out server.key 2048
# 4. Generate server Certificate Signing Request (CSR)
openssl req -new -key server.key -out server.csr -subj "/CN=localhost"
# 5. Generate server certificate signed by CA (validity: 20 years)
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out srv.crt -days 7300 -sha256
# 6. Clean up intermediate files
rm server.csr ca.srl

View File

@@ -1,27 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAlUCywNhVv4RO2y9h/XGKZ1azzk3jzHpSBzIGO9LoiA8trC/p
1ykGaUfYPJllYK4HMhC4fUyE3J7tVL2Eskzl26LNPLbEoaBWZM9NhV3iA1/1EtOu
p6umLx+y3sDfvK35YAOUbjdAlBfhnJ4r8h7oTsxl3J5jZ18zgjJnJi2NEFq/yTpO
MiwHLWPjy25fDFixfV9UzSvbgt1JaGPmC7c4QkhHzjyp0+ikuvRIw0p9BBNeqBV2
da3qBMB5FtodUJTAz6o6OKWbTalLjQi6C1H6z9TnY7IrJBUOy/FWkQH/sEsLdscD
hHa1Dz2oT203QjhzyOSfnNF95D/1MdNcMt6l0wIDAQABAoIBAC1JJTOoMFRc48RT
myrYQYNbZlEphv3q+2qdfhC2zMFDwbrmCtCy7PQSzYSNkpoEE8DYG/JAvmtmeWJl
4pZrCK9ctWM/nWfhC3WpBL97nfEiM20T94F+bn0L5Cz8XqaULv839th+QUTt/hGU
WIctY5VNJXcMQ+MAmtNdUbjex1d3iuxiKHUo4nDoZ8digKFNdtdP5B5nlMq5chCL
mxNRcsGsx2dDAxbGUapdTVPWHPJKpLOBoSkluDsfd2KZADFU2R1SJpAX9+RYh3HM
5FTUdHTUaISxbKkgeDKlEM0lqk2TtGUwCyEj098ewi7Wzsu9w60IplPPUJx5FRG6
jp3wzLkCgYEAxKp5T20rf/7ysX7x053I7VCjDXUxAaWOEj1uS3AhOkl0NaZg7Di+
y53fWNkcHdkt2n2LqMt/43UgMYq3TVVcq2eunPNF11e1bJw8CjDafwDs4omwwyVn
lYhPuB4dK2OAib+vU5Zqpp0kZMoxk2MZVgon8z+s8DW/zmB6aFqAWeUCgYEAwkhC
OgmXKMdjOCVy5t2f5UbY8Y9rV3w8eUATuJ47MMwLr4pGYnKoEn9JB4ltWrHv/u5S
fOv3tIrrCEvnCoCbOILwCsY5LqTNXgqova8FB6RpMUQCzhDd8LHuvdHv0WMnMzX1
3PKuqwh8JS55m4WqZRhzr5BFKG4fHPVs4IcaJVcCgYAzzCaJSdqUKqTnJOUydDNQ
ddWMHNqccWs62J0tF0pZHLGT089hSAzQejMyJnSmU+Ykzr4y5e44DUg+ZCelIZ93
saYmxlgVwI8THQ8fLADQRIEfpV4996MRmkZM2vmZzOo03Zyi6lIKsga82Rg3lnk8
1Q3ynknBNpbfF0AGLhfyFQKBgBYlxJ73HutAJ5hr9HhLBYJOnEaVUehMOlycKGNg
bmD2sdJWEgYBChXpurqIORYguLo4EuE4ySkkuPxeIr14wbkkfBbOWBBwKxUwY+IT
xKAFZxR9q1AwbgyVTCEJgKw/AGX/HcMNS0omEnjunmBTUYRq0C1QZgHg490aQUor
PJjLAoGAevzdTpFlVeuKeYh1oDubGO1LinyXpBv7fPFjl+zu4AVbjojcU6yC4OO6
QvqopE6SyAECKy8kAOFcESPsGc9Lta2XUvI203z7pIVlNVEcJ0+90mQh3Mn1U46l
sZ49PdRvNwNb5wvkh1UqNsMlGFbRlzMbIk45ou4311kCobowZek=
MIIEpAIBAAKCAQEA1zQFgwUxyIteLl5SiciuRBZbn/3KWRmsVpyo5JiYCK9NM3Q8
dDur/dyQ4y2Mq0RVuM7uZL7VraRA4F9+Tm8D2BJ8q4Ai3nRDiGQkFEfbvX0Wic6P
P6q7lKm65fnYMvbWHqhMOglr8e4b7dMOFpZdNLRZVcoP4/43+/9dOgOj7TXczTFs
jnlLJBijOnwABf/xlTpTR7ZbQ3uOlckc0TK/Lqxex+NUq4dXQKa96a/wpA6smW38
0XU5hvVBmhA9YNK86CIpAVOny9gNM1Wxv+aAdVZigNNi6Hht75neC0DhFqGbfpMi
nLhW8qGwVtY3T1pM8HrpdAu5plkdvmcDm8tUAwIDAQABAoIBADHwOHc29V58ONa5
vJ2MnCPgrFJsKlCSzJMst2SUpHMfeuK9zmmKj1bRoC2XnFUB/oJsQpXOUveAbi2i
+0RoLpQtdhC2I2FLyYAU/OpX4n4OUPSZolQ74luVJ3HGkI0DCp0CoO220f3KK2D8
4QAM1IQudayavyVBEOzBTXjw71FUCXmg0viBtd7JRSug9FR69PPLWP14uzo1viBA
dtRsLePDyTatW+bfKkPwDG8hhJoummw+fYRPZbM05aWLmVvTiZ/eQtRq1jkwUNSH
zXsJiCQbHLqwoXISiEsdagQM8hNW2bw5B+ijCQhWNj2ZZBZPJIRtI75sXiXGy2eC
kDaP0cECgYEA8GpoGOyVZ+KMm7PVNcNbdLJrjpoNhdVXdGwR+yd3u6EoQ3MMD5tr
4F7pFtN3IxwLoCSM/dnobysNFdKdQRnOB+o3uLADiPn9REM7ebuGUwUP3BWwkb7S
orDVPUMA82A1p0T4Dwi+OAPpS5bUoI7S/6ZwheWTdoGZYjCrtsqkeEUCgYEA5Sc5
sgLFWIqvYUQF/+aLAwjHR/bBD9NkvHgdW8GmgXdnEd0DIKHDpJ2yEK3BbQxVp/Kk
O2KG1NGyJ9UqA9QQ3q5UgpZNHQBWxz2GUl0jHsy8enhgsZr4K2+wvuw5F5bCdXPe
m/dyFIGnUJ7ic+DtvDGjXdcwAR8Cgc97m5Pg06cCgYEAgyjqBb78e6KDJ2biyOP9
fxrfxvqQqhUMEz3qSWTs03ZGaxXW3KTkI5JkA8n2Uzc3uHR4Xv2E6zFHgEJY/G1B
k9vZ7m5IX3BTFezAA9eknqJCVsWWgMzkSVHD5Bor6JryaoEb+8e/TvwDSPPOqJGC
12pMNSBcZOirb4AyDhVbySkCgYB3Lu2dHj/SC1+oMR8Ft7y5eUlcroQ/XO1Z8Qck
ABY/5ABhlBfaUwhUiAhjEFw4AWBTl6m/kUEbU21btkzB7PxRNU6TFOVKnjCENAW2
tOZdUJL/B7kS5s0ImnDM/EO9dxXwzLENYaed7sk870ZMisJbTV3wosk+7Af7yBQ8
GK+opQKBgQCdZy3KX2FT8S/K2SjDuRM8uDzJ+IcaqScDhgbJFMlrbWmTSML69oRD
Ic6xVe5hWkkPIs521gwrQSD5E3dbb2dFmjhUZpZkHdv0u/AUupFN0EaCFb/I2A0P
fRebd9oKoZjlUrEPeID0kjzbmnPGbtG+gFZYmkRb5iLdcCVAn0O1AQ==
-----END RSA PRIVATE KEY-----

View File

@@ -1,18 +1,18 @@
-----BEGIN CERTIFICATE-----
MIIC9DCCAdwCFA1lSIcHwYKdB2UqOrZxZnVgPObTMA0GCSqGSIb3DQEBCwUAMFkx
MIIC9DCCAdwCFHNjaiCN2RT7W7NHXho8HlgxdAygMA0GCSqGSIb3DQEBCwUAMFkx
CzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRl
cm5ldCBXaWRnaXRzIFB0eSBMdGQxEjAQBgNVBAMMCUVzcHJlc3NpZjAeFw0yMDA2
MTIwNjA0MTNaFw0yMjA2MDIwNjA0MTNaMBQxEjAQBgNVBAMMCWxvY2FsaG9zdDCC
ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJVAssDYVb+ETtsvYf1ximdW
s85N48x6UgcyBjvS6IgPLawv6dcpBmlH2DyZZWCuBzIQuH1MhNye7VS9hLJM5dui
zTy2xKGgVmTPTYVd4gNf9RLTrqerpi8fst7A37yt+WADlG43QJQX4ZyeK/Ie6E7M
ZdyeY2dfM4IyZyYtjRBav8k6TjIsBy1j48tuXwxYsX1fVM0r24LdSWhj5gu3OEJI
R848qdPopLr0SMNKfQQTXqgVdnWt6gTAeRbaHVCUwM+qOjilm02pS40IugtR+s/U
52OyKyQVDsvxVpEB/7BLC3bHA4R2tQ89qE9tN0I4c8jkn5zRfeQ/9THTXDLepdMC
AwEAATANBgkqhkiG9w0BAQsFAAOCAQEAnMYGW+idt37bEE4WPgrRorKWuplR+zHD
wJFz53DQzyIZJHmJ2hR5U0jNcHy/nMq7tbdz9LZPrVF4lZJ3TJhnmkOKjMFPCQE8
YcmsP3il6eXgtGqg53InOi/uJqEQ9TfM54cbpp6xKbnmpwk4uprISBRQt7u2ZLk2
40ED6zgjFPDTYmSjSpb2AN6KUB6PflgVs+4p9ViHNq4U3AlYV/BM0+3G4aMX2wNl
ZIpQfOyuaYD5MU50mY+O+gDiiypkpYf6a6S4YJ1sMbavDsP7bW5UMnP0jKYR549q
5hF1fdkXq52DfJ9ya2kl3mANFkKssQV+1KCBMxGoeqfakmJfa03xXA==
cm5ldCBXaWRnaXRzIFB0eSBMdGQxEjAQBgNVBAMMCUVzcHJlc3NpZjAeFw0yNTA0
MDcwOTQ5MzhaFw00NTA0MDIwOTQ5MzhaMBQxEjAQBgNVBAMMCWxvY2FsaG9zdDCC
ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANc0BYMFMciLXi5eUonIrkQW
W5/9ylkZrFacqOSYmAivTTN0PHQ7q/3ckOMtjKtEVbjO7mS+1a2kQOBffk5vA9gS
fKuAIt50Q4hkJBRH2719FonOjz+qu5SpuuX52DL21h6oTDoJa/HuG+3TDhaWXTS0
WVXKD+P+N/v/XToDo+013M0xbI55SyQYozp8AAX/8ZU6U0e2W0N7jpXJHNEyvy6s
XsfjVKuHV0Cmvemv8KQOrJlt/NF1OYb1QZoQPWDSvOgiKQFTp8vYDTNVsb/mgHVW
YoDTYuh4be+Z3gtA4Rahm36TIpy4VvKhsFbWN09aTPB66XQLuaZZHb5nA5vLVAMC
AwEAATANBgkqhkiG9w0BAQsFAAOCAQEAoiuycWVVjmS9IMS1n9ll8UlIqq8dl7vs
Y5ckGMrdSGR8BPgloTrB6ual4vRPgbn2rGBGAvGusdcmhc1vkVbYsI3JRpTTDDoE
PvQqHWXwV2RDRU5kG6ZOsU+o01Ir4b3w3qfP2LT20FCuuAMIMh23PsSmoc7ziFZ8
76+ox6FjhJMPMF2aftiDmP44/fFg16C1t2PFH/Bk4sm4qRdpXVcWeiaHaSF9JkHa
XwW3TuDSxJwlFFU7ffTRgYYkQ61q8B0LjWV4FF1dBBqflAiXEhWcVhljqfsWn7rq
NBJ/QzZ3GhgQO9GOCokh/ckcp/ZMOm9tv9lV2huGz8Akk8/UYhMUEg==
-----END CERTIFICATE-----

View File

@@ -1,4 +1,4 @@
version: "1.28.2~0"
version: "1.32.0"
description: Cross-platform C++ library for network and I/O programming
url: https://github.com/espressif/esp-protocols/tree/master/components/asio
issues: https://github.com/espressif/esp-protocols/issues
@@ -7,3 +7,5 @@ repository: https://github.com/espressif/esp-protocols.git
dependencies:
idf:
version: ">=5.0"
espressif/sock_utils:
version: "^0.1"

View File

@@ -0,0 +1,11 @@
//
// SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
//
// SPDX-License-Identifier: BSL-1.0
//
#pragma once
#include "sys/socket.h"
#include "socketpair.h"
#include_next "asio/detail/config.hpp"

View File

@@ -0,0 +1,29 @@
//
// SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
//
// SPDX-License-Identifier: BSL-1.0
//
#pragma once
#include "asio/ssl/context_base.hpp"
#include "asio/ssl/context.hpp"
#include "asio/ssl/detail/openssl_types.hpp"
namespace asio {
namespace ssl {
namespace mbedtls {
/**
* @brief Configures specific hostname to be used in peer verification
*
* @param handle asio::ssl context handle type
* @param name hostname to be verified (std::string ownership will be moved to ssl::context)
*
* @return true on success
*/
bool set_hostname(asio::ssl::context::native_handle_type handle, std::string name);
};
};
} // namespace asio::ssl::mbedtls

View File

@@ -1,12 +0,0 @@
/*
* SPDX-FileCopyrightText: 2018-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _ESP_ASIO_CONFIG_H_
#define _ESP_ASIO_CONFIG_H_
#define ASIO_SSL_DETAIL_OPENSSL_TYPES_HPP
#include "openssl_stub.hpp"
#endif // _ESP_ASIO_CONFIG_H_

View File

@@ -1,5 +1,5 @@
//
// SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
// SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
//
// SPDX-License-Identifier: BSL-1.0
//
@@ -52,6 +52,12 @@ public:
return nullptr;
}
bool set_hostname(std::string hostname)
{
hostname_ = std::move(hostname);
return true;
}
std::size_t size(container c) const
{
switch (c) {
@@ -70,6 +76,7 @@ public:
const_buffer cert_chain_;
const_buffer private_key_;
const_buffer ca_cert_;
std::string hostname_;
};
/**

View File

@@ -1,5 +1,5 @@
//
// SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
// SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
//
// SPDX-License-Identifier: BSL-1.0
//
@@ -16,6 +16,11 @@ namespace asio {
namespace ssl {
namespace mbedtls {
bool set_hostname(asio::ssl::context::native_handle_type handle, std::string name)
{
return handle->get()->set_hostname(std::move(name));
}
const char *error_message(int error_code)
{
static char error_buf[100];
@@ -25,7 +30,7 @@ const char *error_message(int error_code)
void throw_alloc_failure(const char *location)
{
asio::error_code ec( MBEDTLS_ERR_SSL_ALLOC_FAILED, asio::error::get_mbedtls_category());
asio::error_code ec(MBEDTLS_ERR_SSL_ALLOC_FAILED, asio::error::get_mbedtls_category());
asio::detail::throw_error(ec, location);
}
@@ -269,6 +274,16 @@ private:
} else {
mbedtls_ssl_conf_ca_chain(&conf_, nullptr, nullptr);
}
// Configure hostname before handshake if users pre-configured any
// use NULL if not set (to preserve the default behaviour of mbedtls < v3.6.3)
const char* hostname = !ctx->hostname_.empty() ? ctx->hostname_.c_str() : NULL;
ret = mbedtls_ssl_set_hostname(&ssl_, hostname);
if (ret < 0) {
print_error("mbedtls_ssl_set_hostname", ret);
return false;
}
ret = mbedtls_ssl_setup(&ssl_, &conf_);
if (ret) {
print_error("mbedtls_ssl_setup", ret);

View File

@@ -8,7 +8,7 @@
//
#include "asio/detail/config.hpp"
#include "openssl_stub.hpp"
#include "asio/ssl/detail/openssl_types.hpp"
#include <cstring>
#include "asio/detail/throw_error.hpp"
#include "asio/error.hpp"

View File

@@ -7,7 +7,7 @@
//
#include "asio/detail/config.hpp"
#include "openssl_stub.hpp"
#include "asio/ssl/detail/openssl_types.hpp"
#include "asio/detail/throw_error.hpp"
#include "asio/error.hpp"
#include "asio/ssl/detail/engine.hpp"

View File

@@ -0,0 +1,36 @@
//
// SPDX-FileCopyrightText: 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// SPDX-License-Identifier: BSL-1.0
//
// SPDX-FileContributor: 2024 Espressif Systems (Shanghai) CO LTD
//
#include "asio/detail/posix_event.hpp"
#include "asio/detail/throw_error.hpp"
#include "asio/error.hpp"
#include "asio/detail/push_options.hpp"
#include <unistd.h>
#include <climits>
namespace asio::detail {
// This replaces asio's posix_event constructor
// since the default POSIX version uses pthread_condattr_t operations (init, setclock, destroy),
// which are not available on all IDF versions (some are defined in compilers' headers, others in
// pthread library, but they typically return `ENOSYS` which causes trouble in the event wrapper)
// IMPORTANT: Check implementation of posix_event() when upgrading upstream asio in order not to
// miss any initialization step.
posix_event::posix_event()
: state_(0)
{
int error = ::pthread_cond_init(&cond_, nullptr);
asio::error_code ec(error, asio::error::get_system_category());
asio::detail::throw_error(ec, "event");
}
} // namespace asio::detail
extern "C" int pause(void)
{
while (true) {
::sleep(UINT_MAX);
}
}

View File

@@ -0,0 +1,8 @@
---
commitizen:
bump_message: 'bump(console): $current_version -> $new_version'
pre_bump_hooks: python ../../ci/changelog.py console_cmd_mqtt
tag_format: console_cmd_mqtt-v$version
version: 1.0.0
version_files:
- idf_component.yml

View File

@@ -0,0 +1,7 @@
# Changelog
## [1.0.0](https://github.com/espressif/esp-protocols/commits/console_cmd_mqtt-v1.0.0)
### Features
- Added component with mqtt command ([1fcc5b1d](https://github.com/espressif/esp-protocols/commit/1fcc5b1d))

View File

@@ -0,0 +1,7 @@
idf_component_register(SRCS "console_mqtt.c"
INCLUDE_DIRS "."
PRIV_REQUIRES esp_netif console mqtt)
if(CONFIG_MQTT_CMD_AUTO_REGISTRATION)
target_link_libraries(${COMPONENT_LIB} PRIVATE "-u console_cmd_mqtt_register")
endif()

View File

@@ -0,0 +1,15 @@
menu "MQTT Configuration"
config MQTT_CMD_AUTO_REGISTRATION
bool "Enable Console command mqtt Auto-registration"
default y
help
Enabling this allows for the autoregistration of the wifi command.
config MQTT_BROKER_URL
string "Broker URL or IP address"
default "mqtt://mqtt.eclipseprojects.io"
help
URL or IP address of the broker to connect to
endmenu

View File

@@ -0,0 +1,87 @@
# Console command mqtt
The component provides a console where mqtt commands can be executed.
## MQTT Configuration:
1. Broker: Use menuconfig **"MQTT Configuration"** to configure the broker url.
## API
### Steps to enable console in an example code:
1. Add this component to your project using ```idf.py add-dependency``` command.
2. In the main file of the example, add the following line:
```c
#include "console_mqtt.h"
```
3. Ensure esp-netif is initialized and default event loop is created in your app_main():
```c
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
```
4. In your app_main() function, add the following line as the last line:
```c
ESP_ERROR_CHECK(console_cmd_init()); // Initialize console
// Register all plugin command added to your project
ESP_ERROR_CHECK(console_cmd_all_register());
// To register only mqtt command skip calling console_cmd_all_register()
ESP_ERROR_CHECK(console_cmd_mqtt_register());
ESP_ERROR_CHECK(console_cmd_start()); // Start console
```
Note: Auto-registration of a specific plugin command can be disabled from menuconfig.
### Certificate Integration for Mutual Authentication
To enhance security and enable secure communication over MQTT, three functions have been added to the API, allowing users to set client certificates, client keys, and broker certificates separately.
Setting the client certificate:
```c
set_mqtt_client_cert(client_cert_pem_start, client_cert_pem_end);
```
Setting the client key:
```c
set_mqtt_client_key(client_key_pem_start, client_key_pem_end);
```
Setting the broker certificate:
```c
set_mqtt_broker_certs(broker_cert_pem_start, broker_cert_pem_end);
```
Each function takes pointers to the start and end of the respective PEM-encoded data, allowing users to specify the necessary certificate and key information independently. For a complete secure MQTT setup, users should call all three functions in their application code.
To utilize these certificates, users need to include additional arguments when establishing MQTT connections using the library. Specifically, users should provide the `--cert`, `--key`, and `--cafile` options along with the MQTT connection command.
### Adding a plugin command or component:
To add a plugin command or any component from IDF component manager into your project, simply include an entry within the `idf_component.yml` file.
For more details refer [IDF Component Manager](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-component-manager.html)
## Suported command:
### mqtt:
```
mqtt [-CsD] [-h <host>] [-u <username>] [-P <password>] [--cert] [--key] [--cafile]
mqtt command
-C, --connect Connect to a broker (flag, no argument)
-h, --host=<host> Specify the host uri to connect to
-s, --status Displays the status of the mqtt client (flag, no argument)
-u, --username=<username> Provide a username to be used for authenticating with the broker
-P, --password=<password> Provide a password to be used for authenticating with the broker
--cert Define the PEM encoded certificate for this client, if required by the broker (flag, no argument)
--key Define the PEM encoded private key for this client, if required by the broker (flag, no argument)
--cafile Define the PEM encoded CA certificates that are trusted (flag, no argument)
--use-internal-bundle Use the internal certificate bundle for TLS (flag, no argument)
-D, --disconnect Disconnect from the broker (flag, no argument)
mqtt_pub [-t <topic>] [-m <message>]
mqtt publish command
-t, --topic=<topic> Topic to Subscribe/Publish
-m, --message=<message> Message to Publish
mqtt_sub [-U] [-t <topic>]
mqtt subscribe command
-t, --topic=<topic> Topic to Subscribe/Publish
-U, --unsubscribe Unsubscribe from a topic
```

View File

@@ -0,0 +1,475 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <string.h>
#include "sdkconfig.h"
#include "esp_console.h"
#include "esp_event.h"
#include "esp_log.h"
#include "argtable3/argtable3.h"
#include "console_mqtt.h"
#include "mqtt_client.h"
#if defined(CONFIG_MBEDTLS_CERTIFICATE_BUNDLE)
#include "esp_crt_bundle.h"
#endif
static const char *TAG = "console_mqtt";
#define CONNECT_HELP_MSG "mqtt -C -h <host uri> -u <username> -P <password> --cert --key --cafile\n"
#define PUBLISH_HELP_MSG "Usage: mqtt -P -t <topic> -d <data>\n"
#define SUBSCRIBE_HELP_MSG "Usage: mqtt -S -t <topic>\n"
#define UNSUBSCRIBE_HELP_MSG "Usage: mqtt -U\n"
#define DISCONNECT_HELP_MSG "Usage: mqtt -D\n"
#if CONFIG_MQTT_CMD_AUTO_REGISTRATION
/**
* Static registration of this plugin is achieved by defining the plugin description
* structure and placing it into .console_cmd_desc section.
* The name of the section and its placement is determined by linker.lf file in 'plugins' component.
*/
static const console_cmd_plugin_desc_t __attribute__((section(".console_cmd_desc"), used)) PLUGIN = {
.name = "console_cmd_mqtt",
.plugin_regd_fn = &console_cmd_mqtt_register
};
#endif
static struct {
struct arg_lit *connect;
struct arg_str *uri;
struct arg_lit *status;
struct arg_str *username;
struct arg_str *password;
struct arg_lit *cert;
struct arg_lit *key;
struct arg_lit *cafile;
#if defined(CONFIG_MBEDTLS_CERTIFICATE_BUNDLE)
struct arg_lit *use_internal_bundle;
#endif
struct arg_lit *disconnect;
struct arg_end *end;
} mqtt_args;
static struct {
struct arg_str *topic;
struct arg_lit *unsubscribe;
struct arg_end *end;
} mqtt_sub_args;
static struct {
struct arg_str *topic;
struct arg_str *message;
struct arg_end *end;
} mqtt_pub_args;
typedef enum {
MQTT_STATE_INIT = 0,
MQTT_STATE_DISCONNECTED,
MQTT_STATE_CONNECTED,
MQTT_STATE_ERROR,
MQTT_STATE_STOPPED,
} mqtt_client_state_t;
mqtt_client_state_t client_status = MQTT_STATE_INIT;
static esp_mqtt_client_handle_t client_handle = NULL;
static const uint8_t *s_own_cert_pem_start = NULL;
static const uint8_t *s_own_cert_pem_end = NULL;
static const uint8_t *s_own_key_pem_start = NULL;
static const uint8_t *s_own_key_pem_end = NULL;
static const uint8_t *s_ca_cert_pem_start = NULL;
static const uint8_t *s_ca_cert_pem_end = NULL;
static void log_error_if_nonzero(const char *message, int error_code)
{
if (error_code != 0) {
ESP_LOGE(TAG, "Last error %s: 0x%x", message, error_code);
}
}
/*
* @brief Event handler registered to receive MQTT events
*
* This function is called by the MQTT client event loop.
*
* @param handler_args user data registered to the event.
* @param base Event base for the handler(always MQTT Base in this example).
* @param event_id The id for the received event.
* @param event_data The data for the event, esp_mqtt_event_handle_t.
*/
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
{
ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%" PRIi32, base, event_id);
esp_mqtt_event_handle_t event = event_data;
switch ((esp_mqtt_event_id_t)event_id) {
case MQTT_EVENT_BEFORE_CONNECT:
ESP_LOGI(TAG, "MQTT_EVENT_BEFORE_CONNECT");
break;
case MQTT_EVENT_CONNECTED:
client_status = MQTT_STATE_CONNECTED;
ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
break;
case MQTT_EVENT_DISCONNECTED:
client_status = MQTT_STATE_DISCONNECTED;
ESP_LOGI(TAG, "MQTT_EVENT_DISCONNECTED");
break;
case MQTT_EVENT_SUBSCRIBED:
ESP_LOGI(TAG, "MQTT_EVENT_SUBSCRIBED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_UNSUBSCRIBED:
ESP_LOGI(TAG, "MQTT_EVENT_UNSUBSCRIBED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_PUBLISHED:
ESP_LOGI(TAG, "MQTT_EVENT_PUBLISHED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_DATA:
ESP_LOGI(TAG, "MQTT_EVENT_DATA");
ESP_LOGI(TAG, "TOPIC=%.*s\r\n", event->topic_len, event->topic);
ESP_LOGI(TAG, "DATA=%.*s\r\n", event->data_len, event->data);
break;
case MQTT_EVENT_ERROR:
client_status = MQTT_STATE_ERROR;
ESP_LOGI(TAG, "MQTT_EVENT_ERROR");
if (event->error_handle->error_type == MQTT_ERROR_TYPE_TCP_TRANSPORT) {
log_error_if_nonzero("reported from esp-tls", event->error_handle->esp_tls_last_esp_err);
log_error_if_nonzero("reported from tls stack", event->error_handle->esp_tls_stack_err);
log_error_if_nonzero("captured as transport's socket errno", event->error_handle->esp_transport_sock_errno);
ESP_LOGI(TAG, "Last errno string (%s)", strerror(event->error_handle->esp_transport_sock_errno));
}
break;
default:
ESP_LOGI(TAG, "Other event id:%d", event->event_id);
break;
}
}
static const char *mqtt_state_to_string(mqtt_client_state_t state)
{
switch (state) {
case MQTT_STATE_INIT:
return "Initializing";
case MQTT_STATE_DISCONNECTED:
return "Disconnected";
case MQTT_STATE_CONNECTED:
return "Connected";
case MQTT_STATE_ERROR:
return "Error";
case MQTT_STATE_STOPPED:
return "Disconnected and Stopped";
default:
return "Unknown State";
}
}
static int do_mqtt_cmd(int argc, char **argv)
{
int nerrors = arg_parse(argc, argv, (void **)&mqtt_args);
if (nerrors != 0) {
arg_print_errors(stderr, mqtt_args.end, argv[0]);
return 1;
}
if (mqtt_args.status->count > 0) {
ESP_LOGI(TAG, "MQTT Client Status: %s\n", mqtt_state_to_string(client_status));
return 0;
}
if (mqtt_args.connect->count > 0) {
if (client_handle != NULL) {
ESP_LOGW(TAG, "mqtt client already connected");
ESP_LOGI(TAG, "Try: %s", DISCONNECT_HELP_MSG);
return 0;
}
char *uri = CONFIG_MQTT_BROKER_URL;
if (mqtt_args.uri->count > 0) {
uri = (char *)mqtt_args.uri->sval[0];
}
esp_mqtt_client_config_t mqtt_cfg = {
.broker.address.uri = uri,
};
if ((mqtt_args.username->count > 0) && (mqtt_args.password->count > 0)) {
mqtt_cfg.credentials.username = mqtt_args.username->sval[0];
mqtt_cfg.credentials.authentication.password = mqtt_args.password->sval[0];
}
ESP_LOGI(TAG, "broker: %s", mqtt_cfg.broker.address.uri);
#if defined(CONFIG_MBEDTLS_CERTIFICATE_BUNDLE)
/* Ensure --use_internal_bundle and --cafile are mutually exclusive */
if ((mqtt_args.use_internal_bundle->count > 0) && (mqtt_args.cafile->count > 0)) {
ESP_LOGE(TAG, "Error: Options can't be used together. Use either --use-internal-bundle or --cafile. \n");
return 1;
}
if (mqtt_args.use_internal_bundle->count > 0) {
mqtt_cfg.broker.verification.crt_bundle_attach = esp_crt_bundle_attach;
}
#endif
if (mqtt_args.cafile->count > 0) {
if (s_ca_cert_pem_start && s_ca_cert_pem_end) {
mqtt_cfg.broker.verification.certificate = (const char *)s_ca_cert_pem_start;
} else {
ESP_LOGW(TAG, "cafile not provided");
}
}
if (mqtt_args.cert->count > 0) {
if (s_own_cert_pem_start && s_own_cert_pem_end) {
mqtt_cfg.credentials.authentication.certificate = (const char *)s_own_cert_pem_start;
} else {
ESP_LOGW(TAG, "cert not provided");
}
if (mqtt_args.key->count > 0) {
if (s_own_key_pem_start && s_own_key_pem_end) {
mqtt_cfg.credentials.authentication.key = (const char *)s_own_key_pem_start;
} else {
ESP_LOGW(TAG, "key not provided");
}
} else {
mqtt_cfg.credentials.authentication.key = NULL;
}
}
client_handle = esp_mqtt_client_init(&mqtt_cfg);
if (client_handle == NULL) {
ESP_LOGE(TAG, "ERROR: Client init");
ESP_LOGI(TAG, "Try: %s", DISCONNECT_HELP_MSG);
ESP_LOGE(TAG, CONNECT_HELP_MSG);
return 1;
}
/* The last argument may be used to pass data to the event handler, in this example mqtt_event_handler */
esp_mqtt_client_register_event(client_handle, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL);
esp_mqtt_client_start(client_handle);
} else if (mqtt_args.disconnect->count > 0) {
ESP_LOGD(TAG, "Disconnect command received:");
if (client_handle == NULL) {
ESP_LOGE(TAG, "mqtt client not connected");
return 0;
}
if (esp_mqtt_client_stop(client_handle) != ESP_OK) {
ESP_LOGE(TAG, "Failed to stop mqtt client task");
return 1;
}
client_handle = NULL;
client_status = MQTT_STATE_STOPPED;
ESP_LOGI(TAG, "mqtt client disconnected and stopped");
}
return 0;
}
esp_err_t set_mqtt_client_cert(const uint8_t *client_cert_pem_start_i, const uint8_t *client_cert_pem_end_i)
{
if (!client_cert_pem_start_i || !client_cert_pem_end_i ||
(client_cert_pem_start_i > client_cert_pem_end_i)) {
ESP_LOGE(TAG, "Invalid mqtt Client certs(%d)\n", __LINE__);
return ESP_ERR_INVALID_ARG;
}
s_own_cert_pem_start = client_cert_pem_start_i;
s_own_cert_pem_end = client_cert_pem_end_i;
return ESP_OK;
}
esp_err_t set_mqtt_client_key(const uint8_t *client_key_pem_start_i, const uint8_t *client_key_pem_end_i)
{
if (client_key_pem_start_i && client_key_pem_end_i &&
(client_key_pem_start_i >= client_key_pem_end_i)) {
ESP_LOGE(TAG, "Invalid mqtt Client key(%d)\n", __LINE__);
return ESP_ERR_INVALID_ARG;
}
s_own_key_pem_start = client_key_pem_start_i;
s_own_key_pem_end = client_key_pem_end_i;
return ESP_OK;
}
esp_err_t set_mqtt_broker_certs(const uint8_t *ca_cert_pem_start_i, const uint8_t *ca_cert_pem_end_i)
{
if (!ca_cert_pem_start_i || !ca_cert_pem_end_i ||
(ca_cert_pem_start_i > ca_cert_pem_end_i)) {
ESP_LOGE(TAG, "Invalid mqtt ca cert(%d)\n", __LINE__);
return ESP_ERR_INVALID_ARG;
}
s_ca_cert_pem_start = ca_cert_pem_start_i;
s_ca_cert_pem_end = ca_cert_pem_end_i;
return ESP_OK;
}
static int do_mqtt_sub_cmd(int argc, char **argv)
{
int msg_id;
int nerrors = arg_parse(argc, argv, (void **)&mqtt_sub_args);
if (nerrors != 0) {
arg_print_errors(stderr, mqtt_sub_args.end, argv[0]);
return 1;
}
if (client_handle == NULL) {
ESP_LOGE(TAG, "mqtt client not connected");
return 0;
}
if (mqtt_sub_args.unsubscribe->count > 0) {
if (mqtt_sub_args.topic->count <= 0) {
ESP_LOGE(TAG, UNSUBSCRIBE_HELP_MSG);
return 0;
}
char *topic = (char *)mqtt_sub_args.topic->sval[0];
msg_id = esp_mqtt_client_unsubscribe(client_handle, mqtt_sub_args.topic->sval[0]);
ESP_LOGI(TAG, "Unsubscribe successful, msg_id=%d, topic=%s", msg_id, topic);
} else {
if (mqtt_sub_args.topic->count <= 0) {
ESP_LOGE(TAG, SUBSCRIBE_HELP_MSG);
return 0;
}
char *topic = (char *)mqtt_sub_args.topic->sval[0];
msg_id = esp_mqtt_client_subscribe(client_handle, topic, 0);
ESP_LOGI(TAG, "Subscribe successful, msg_id=%d, topic=%s", msg_id, topic);
}
return 0;
}
static int do_mqtt_pub_cmd(int argc, char **argv)
{
int msg_id;
int nerrors = arg_parse(argc, argv, (void **)&mqtt_pub_args);
if (nerrors != 0) {
arg_print_errors(stderr, mqtt_pub_args.end, argv[0]);
return 1;
}
if (client_handle == NULL) {
ESP_LOGE(TAG, "mqtt client not connected");
return 0;
}
if ((mqtt_pub_args.topic->count <= 0) || (mqtt_pub_args.message->count <= 0)) {
ESP_LOGE(TAG, PUBLISH_HELP_MSG);
}
msg_id = esp_mqtt_client_publish(client_handle,
mqtt_pub_args.topic->sval[0],
mqtt_pub_args.message->sval[0],
0, 1, 0);
if (msg_id == -1) {
ESP_LOGE(TAG, "mqtt client not connected");
return 0;
}
ESP_LOGI(TAG, "Publish successful, msg_id=%d, topic=%s, data=%s",
msg_id, mqtt_pub_args.topic->sval[0], mqtt_pub_args.message->sval[0]);
return 0;
}
/**
* @brief Registers the mqtt commands.
*
* @return
* - esp_err_t
*/
esp_err_t console_cmd_mqtt_register(void)
{
esp_err_t ret = ESP_OK;
/* Register mqtt */
mqtt_args.connect = arg_lit0("C", "connect", "Connect to a broker (flag, no argument)");
mqtt_args.uri = arg_str0("h", "host", "<host>", "Specify the host uri to connect to");
mqtt_args.status = arg_lit0("s", "status", "Displays the status of the mqtt client (flag, no argument)");
mqtt_args.username = arg_str0("u", "username", "<username>", "Provide a username to be used for authenticating with the broker");
mqtt_args.password = arg_str0("P", "password", "<password>", "Provide a password to be used for authenticating with the broker");
mqtt_args.cert = arg_lit0(NULL, "cert", "Define the PEM encoded certificate for this client, if required by the broker (flag, no argument)");
mqtt_args.key = arg_lit0(NULL, "key", "Define the PEM encoded private key for this client, if required by the broker (flag, no argument)");
mqtt_args.cafile = arg_lit0(NULL, "cafile", "Define the PEM encoded CA certificates that are trusted (flag, no argument)");
#if defined(CONFIG_MBEDTLS_CERTIFICATE_BUNDLE)
mqtt_args.use_internal_bundle = arg_lit0(NULL, "use-internal-bundle", "Use the internal certificate bundle for TLS (flag, no argument)");
#endif
mqtt_args.disconnect = arg_lit0("D", "disconnect", "Disconnect from the broker (flag, no argument)");
mqtt_args.end = arg_end(1);
const esp_console_cmd_t mqtt_cmd = {
.command = "mqtt",
.help = "mqtt command",
.hint = NULL,
.func = &do_mqtt_cmd,
.argtable = &mqtt_args
};
ret = esp_console_cmd_register(&mqtt_cmd);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Unable to register mqtt");
return ret;
}
/* Register mqtt_pub */
mqtt_pub_args.topic = arg_str0("t", "topic", "<topic>", "Topic to Subscribe/Publish");
mqtt_pub_args.message = arg_str0("m", "message", "<message>", "Message to Publish");
mqtt_pub_args.end = arg_end(1);
const esp_console_cmd_t mqtt_pub_cmd = {
.command = "mqtt_pub",
.help = "mqtt publish command",
.hint = NULL,
.func = &do_mqtt_pub_cmd,
.argtable = &mqtt_pub_args
};
ret = esp_console_cmd_register(&mqtt_pub_cmd);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Unable to register mqtt_pub");
return ret;
}
/* Register mqtt_sub */
mqtt_sub_args.topic = arg_str0("t", "topic", "<topic>", "Topic to Subscribe/Publish");
mqtt_sub_args.unsubscribe = arg_lit0("U", "unsubscribe", "Unsubscribe from a topic");
mqtt_sub_args.end = arg_end(1);
const esp_console_cmd_t mqtt_sub_cmd = {
.command = "mqtt_sub",
.help = "mqtt subscribe command",
.hint = NULL,
.func = &do_mqtt_sub_cmd,
.argtable = &mqtt_sub_args
};
ret = esp_console_cmd_register(&mqtt_sub_cmd);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Unable to register mqtt_sub");
}
return ret;
}

View File

@@ -0,0 +1,73 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "console_simple_init.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Registers the mqtt command.
*
* @return
* - esp_err_t
*/
esp_err_t console_cmd_mqtt_register(void);
/**
* @brief Set MQTT client certificate
*
* This function sets the MQTT client certificate for secure communication.
* The function takes the PEM(Privacy Enhanced Mail) encoded certificate arguments.
*
* @param client_cert_pem_start_i Pointer to the beginning of the client certificate PEM data.
* @param client_cert_pem_end_i Pointer to the end of the client certificate PEM data.
*
* @return
* ESP_OK on success
* ESP_ERR_INVALID_ARG on invalid arguments
*/
esp_err_t set_mqtt_client_cert(const uint8_t *client_cert_pem_start_i, const uint8_t *client_cert_pem_end_i);
/**
* @brief Set MQTT client key
*
* This function sets the MQTT client key for secure communication.
* The function takes the PEM(Privacy Enhanced Mail) encoded key arguments.
*
* @param client_key_pem_start_i Pointer to the beginning of the client key PEM data.
* @param client_key_pem_end_i Pointer to the end of the client key PEM data.
*
* @return
* ESP_OK on success
* ESP_ERR_INVALID_ARG on invalid arguments
*/
esp_err_t set_mqtt_client_key(const uint8_t *client_key_pem_start_i, const uint8_t *client_key_pem_end_i);
/**
* @brief Set MQTT broker certificate
*
* This function sets the MQTT broker certificate for secure communication.
* The function takes the PEM(Privacy Enhanced Mail) encoded broker certificate arguments.
*
* @param broker_cert_pem_start_i Pointer to the beginning of the broker certificate PEM data.
* @param broker_cert_pem_end_i Pointer to the end of the broker certificate PEM data.
*
* @return
* ESP_OK on success
* ESP_ERR_INVALID_ARG on invalid arguments
*/
esp_err_t set_mqtt_broker_certs(const uint8_t *broker_cert_pem_start_i, const uint8_t *broker_cert_pem_end_i);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,11 @@
# The following five lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(mqtt_ssl_auth_console)
# Certs for mqtts://test.mosquitto.org:8884
target_add_binary_data(${CMAKE_PROJECT_NAME}.elf "certs/client.crt" TEXT)
target_add_binary_data(${CMAKE_PROJECT_NAME}.elf "certs/client.key" TEXT)
target_add_binary_data(${CMAKE_PROJECT_NAME}.elf "certs/mosquitto.org.pem" TEXT)

View File

@@ -0,0 +1,174 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
# ESP-MQTT SSL Authentication Console
This example demonstrates the use of the MQTT command-line component to connect to both secured and unsecured MQTT brokers. It provides multiple modes of connection, including:
* Unsecured transport: Connect to a broker without encryption.
* SSL/TLS transport: Securely connect using SSL/TLS with options for:
* Validating the broker using a provided CA certificate.
* Validating the broker using the internal certificate bundle.
* Performing SSL mutual authentication using client and broker certificates.
Additionally, the example allows subscribing to topics, unsubscribing from topics, and publishing messages to a specified topic through commands. Connections to the broker at test.mosquitto.org are used to demonstrate these features.
(Please note that the public broker is maintained by the community so may not be always available, for details please visit http://test.mosquitto.org)
It uses ESP-MQTT library which implements mqtt client to connect to mqtt broker.
## How to use example
### Hardware Required
This example can be executed on any ESP32 board, the only required interface is WiFi and connection to internet.
### Configure the project
* Open the project configuration menu (`idf.py menuconfig`)
* Configure Wi-Fi or Ethernet under "Example Connection Configuration" menu. See "Establishing Wi-Fi or Ethernet Connection" section in [examples/protocols/README.md](../../README.md) for more details.
* Generate your client keys and certificate (specific to testing with Mosquitto broker)
Note: The following steps are for testing with the Mosquitto broker. If you're using a different broker, you may need to adapt the steps to meet your broker's certificate and key requirements.
#### Steps for SSL Mutual authentication:
Navigate to the certs directory
```
cd certs
```
Generate a client key and a CSR. When you are generating the CSR, do not use the default values. At a minimum, the CSR must include the Country, Organisation and Common Name fields.
```
openssl genrsa -out client.key
openssl req -out client.csr -key client.key -new
```
Paste the generated CSR in the [Mosquitto test certificate signer](https://test.mosquitto.org/ssl/index.php), click Submit and copy the downloaded `client.crt` in the `main` directory.
Please note, that the supplied files `client.crt` and `client.key` in the `main` directory are only placeholders for your client certificate and key (i.e. the example "as is" would compile but would not connect to the broker)
The broker certificate `mosquitto.org.pem` can be downloaded in pem format from [mosquitto.org.crt](https://test.mosquitto.org/ssl/mosquitto.org.crt). Convert it to `mosquitto.org.pem` simply by renaming it.
Note: If your certificate and key file names differ, update the root `CMakeLists.txt` file and main/`mqtt_ssl_auth_console.c` accordingly.
### Build and Flash
Build the project and flash it to the board, then run monitor tool to view serial output:
```
idf.py -p PORT flash monitor
```
(To exit the serial monitor, type ``Ctrl-]``.)
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
Warning: This example might need a bigger app partition size if you're compiling it for debug. To ensere this issue doesn't happen "optimize for size is enabled in menuconfig.
### Command Usage:
```
esp> help
help [<string>]
Print the summary of all registered commands if no arguments are given,
otherwise print summary of given command.
<string> Name of command
mqtt [-CsD] [-h <host>] [-u <username>] [-P <password>] [--cert] [--key] [--cafile]
mqtt command
-C, --connect Connect to a broker (flag, no argument)
-h, --host=<host> Specify the host uri to connect to
-s, --status Displays the status of the mqtt client (flag, no argument)
-u, --username=<username> Provide a username to be used for authenticating with the broker
-P, --password=<password> Provide a password to be used for authenticating with the broker
--cert Define the PEM encoded certificate for this client, if required by the broker (flag, no argument)
--key Define the PEM encoded private key for this client, if required by the broker (flag, no argument)
--cafile Define the PEM encoded CA certificates that are trusted (flag, no argument)
--use-internal-bundle Use the internal certificate bundle for TLS (flag, no argument)
-D, --disconnect Disconnect from the broker (flag, no argument)
mqtt_pub [-t <topic>] [-m <message>]
mqtt publish command
-t, --topic=<topic> Topic to Subscribe/Publish
-m, --message=<message> Message to Publish
mqtt_sub [-U] [-t <topic>]
mqtt subscribe command
-t, --topic=<topic> Topic to Subscribe/Publish
-U, --unsubscribe Unsubscribe from a topic
```
### Connection:
#### Connect without Validating the Broker:
This option connects to the broker without validating its certificate. It is not secure.
```
mqtt -h mqtts://test.mosquitto.org -C
```
or
```
mqtt -h mqtts://mqtt.eclipseprojects.io -C
```
#### Validate the Broker using the Internal Certificate Bundle:
This option uses the ESP-IDF's built-in certificate bundle to verify the broker's identity.
```
mqtt -h mqtts://mqtt.eclipseprojects.io -C --use-internal-bundle
```
or
```
mqtt -h mqtts://test.mosquitto.org -C --use-internal-bundle
```
#### Validate the Broker using a Provided CA Certificate:
This option requires you to provide the broker's CA certificate for validation.
```
mqtt -h mqtts://test.mosquitto.org -C --cafile
```
#### SSL Mutual Authentication(encrypted, client certificate required):
This option performs client authentication in addition to broker validation. It requires the client certificate, private key, and broker CA certificate.
```
mqtt -h mqtts://test.mosquitto.org:8884 -C --cert --key --cafile
```
or
```
mqtt -h mqtts://test.mosquitto.org:8884 -C --cert --key --use-internal-bundle
```
Note: In this example, the broker's certificate is included in the certificate bundle (refer to sdkconfig.default).
### Disconnect:
```
esp> mqtt -D
I (1189949) console_mqtt: mqtt client disconnected
```
### Subscribe/Unsubscribe:
```
esp> mqtt_sub -t test0
I (897289) console_mqtt: Subscribe successful, msg_id=57425, topic=test0
esp> I (897799) console_mqtt: MQTT_EVENT_SUBSCRIBED, msg_id=57425
esp>
esp> mqtt_sub -U -t test0
I (902009) console_mqtt: Unsubscribe successful, msg_id=27663, topic=test0
esp> I (902509) console_mqtt: MQTT_EVENT_UNSUBSCRIBED, msg_id=27663
```
### Publish:
```
esp> mqtt_pub -t test0 -m "Hello, Testing 123"
I (999469) console_mqtt: Publish successful, msg_id=55776, topic=test0, data=Hello, Testing 123
I (1000009) console_mqtt: MQTT_EVENT_PUBLISHED, msg_id=55776
esp>
```
### Receiving data event:
```
esp> I (999999) console_mqtt: MQTT_EVENT_DATA
I (999999) console_mqtt: TOPIC=test0
I (999999) console_mqtt: DATA=Hello, Testing 123
```

View File

@@ -0,0 +1,24 @@
-----BEGIN CERTIFICATE-----
MIIEAzCCAuugAwIBAgIUBY1hlCGvdj4NhBXkZ/uLUZNILAwwDQYJKoZIhvcNAQEL
BQAwgZAxCzAJBgNVBAYTAkdCMRcwFQYDVQQIDA5Vbml0ZWQgS2luZ2RvbTEOMAwG
A1UEBwwFRGVyYnkxEjAQBgNVBAoMCU1vc3F1aXR0bzELMAkGA1UECwwCQ0ExFjAU
BgNVBAMMDW1vc3F1aXR0by5vcmcxHzAdBgkqhkiG9w0BCQEWEHJvZ2VyQGF0Y2hv
by5vcmcwHhcNMjAwNjA5MTEwNjM5WhcNMzAwNjA3MTEwNjM5WjCBkDELMAkGA1UE
BhMCR0IxFzAVBgNVBAgMDlVuaXRlZCBLaW5nZG9tMQ4wDAYDVQQHDAVEZXJieTES
MBAGA1UECgwJTW9zcXVpdHRvMQswCQYDVQQLDAJDQTEWMBQGA1UEAwwNbW9zcXVp
dHRvLm9yZzEfMB0GCSqGSIb3DQEJARYQcm9nZXJAYXRjaG9vLm9yZzCCASIwDQYJ
KoZIhvcNAQEBBQADggEPADCCAQoCggEBAME0HKmIzfTOwkKLT3THHe+ObdizamPg
UZmD64Tf3zJdNeYGYn4CEXbyP6fy3tWc8S2boW6dzrH8SdFf9uo320GJA9B7U1FW
Te3xda/Lm3JFfaHjkWw7jBwcauQZjpGINHapHRlpiCZsquAthOgxW9SgDgYlGzEA
s06pkEFiMw+qDfLo/sxFKB6vQlFekMeCymjLCbNwPJyqyhFmPWwio/PDMruBTzPH
3cioBnrJWKXc3OjXdLGFJOfj7pP0j/dr2LH72eSvv3PQQFl90CZPFhrCUcRHSSxo
E6yjGOdnz7f6PveLIB574kQORwt8ePn0yidrTC1ictikED3nHYhMUOUCAwEAAaNT
MFEwHQYDVR0OBBYEFPVV6xBUFPiGKDyo5V3+Hbh4N9YSMB8GA1UdIwQYMBaAFPVV
6xBUFPiGKDyo5V3+Hbh4N9YSMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEL
BQADggEBAGa9kS21N70ThM6/Hj9D7mbVxKLBjVWe2TPsGfbl3rEDfZ+OKRZ2j6AC
6r7jb4TZO3dzF2p6dgbrlU71Y/4K0TdzIjRj3cQ3KSm41JvUQ0hZ/c04iGDg/xWf
+pp58nfPAYwuerruPNWmlStWAXf0UTqRtg4hQDWBuUFDJTuWuuBvEXudz74eh/wK
sMwfu1HFvjy5Z0iMDU8PUDepjVolOCue9ashlS4EB5IECdSR2TItnAIiIwimx839
LdUdRudafMu5T5Xma182OC0/u/xRlEm+tvKGGmfFcN0piqVl8OrSPBgIlb+1IKJE
m/XriWr/Cq4h/JfB7NTsezVslgkBaoU=
-----END CERTIFICATE-----

View File

@@ -0,0 +1,2 @@
idf_component_register(SRCS "mqtt_ssl_auth_console.c"
INCLUDE_DIRS ".")

View File

@@ -0,0 +1,8 @@
dependencies:
idf:
version: ">=5.0"
protocol_examples_common:
path: ${IDF_PATH}/examples/common_components/protocol_examples_common
console_cmd_mqtt:
version: "*"
override_path: '../../../'

View File

@@ -0,0 +1,51 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdio.h>
#include "nvs_flash.h"
#include "esp_netif.h"
#include "esp_event.h"
#include <netdb.h>
#include "console_mqtt.h"
#include "protocol_examples_common.h"
// Certs for mqtts://test.mosquitto.org:8884
extern const uint8_t g_client_cert_pem_start[] asm("_binary_client_crt_start");
extern const uint8_t g_client_cert_pem_end[] asm("_binary_client_crt_end");
extern const uint8_t g_client_key_pem_start[] asm("_binary_client_key_start");
extern const uint8_t g_client_key_pem_end[] asm("_binary_client_key_end");
extern const uint8_t g_broker_cert_pem_start[] asm("_binary_mosquitto_org_pem_start");
extern const uint8_t g_broker_cert_pem_end[] asm("_binary_mosquitto_org_pem_end");
void app_main(void)
{
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
esp_err_t ret = nvs_flash_init(); //Initialize NVS
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
/* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.
* Read "Establishing Wi-Fi or Ethernet Connection" section in
* ${IDF_PATH}/examples/protocols/README.md for more information about this function.
*/
ESP_ERROR_CHECK(example_connect());
// Initialize console REPL
ESP_ERROR_CHECK(console_cmd_init());
ESP_ERROR_CHECK(console_cmd_all_register());
set_mqtt_client_cert(g_client_cert_pem_start, g_client_cert_pem_end);
set_mqtt_client_key(g_client_key_pem_start, g_client_key_pem_end);
set_mqtt_broker_certs(g_broker_cert_pem_start, g_broker_cert_pem_end);
// start console REPL
ESP_ERROR_CHECK(console_cmd_start());
}

View File

@@ -0,0 +1,19 @@
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
# -*- coding: utf-8 -*-
import pytest
@pytest.mark.esp32
def test_examples_ifconfig_command(dut):
dut.expect('esp>', timeout=30)
dut.write('help mqtt')
dut.expect(r'mqtt \[-CsD\] \[-h <host>\] \[-u <username>\] \[-P <password>\] \[--cert\] \[--key\] \[--cafile\]', timeout=30)
dut.write('help mqtt_pub')
dut.expect(r'mqtt_pub \[-t <topic>\] \[-m <message>\]', timeout=30)
dut.write('help mqtt_sub')
dut.expect(r'mqtt_sub \[-U\] \[-t <topic>\]', timeout=30)

View File

@@ -0,0 +1,7 @@
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) 5.5.0 Project Minimal Configuration
#
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_CMN=y
CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE=y
CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE_PATH="certs/mosquitto.org.pem"

View File

@@ -0,0 +1,11 @@
version: 1.0.0
url: https://github.com/espressif/esp-protocols/tree/master/components/console_cmd_mqtt
description: The component provides a console where the 'mqtt' command can be executed.
license: Apache-2.0
dependencies:
idf:
version: '>=5.0'
espressif/console_simple_init:
version: '>=1.1.0'
override_path: '../console_simple_init'
public: true

View File

@@ -3,6 +3,6 @@ commitizen:
bump_message: 'bump(console): $current_version -> $new_version'
pre_bump_hooks: python ../../ci/changelog.py console_cmd_ping
tag_format: console_cmd_ping-v$version
version: 1.1.0
version: 1.2.0
version_files:
- idf_component.yml

View File

@@ -1,5 +1,11 @@
# Changelog
## [1.2.0](https://github.com/espressif/esp-protocols/commits/console_cmd_ping-v1.2.0)
### Features
- Add support for interface argument ([90ddb04e](https://github.com/espressif/esp-protocols/commit/90ddb04e))
## [1.1.0](https://github.com/espressif/esp-protocols/commits/console_cmd_ping-v1.1.0)
### Features

View File

@@ -48,7 +48,7 @@ For more details refer [IDF Component Manager](https://docs.espressif.com/projec
### ping:
```
ping [-W <t>] [-i <t>] [-s <n>] [-c <n>] [-Q <n>] [-T <n>] <host>
ping [-W <t>] [-i <t>] [-s <n>] [-c <n>] [-Q <n>] [-T <n>] [-I <n>] <host>
send ICMP ECHO_REQUEST to network hosts
-W, --timeout=<t> Time to wait for a response, in seconds
-i, --interval=<t> Wait interval seconds between sending each packet
@@ -56,6 +56,7 @@ ping [-W <t>] [-i <t>] [-s <n>] [-c <n>] [-Q <n>] [-T <n>] <host>
-c, --count=<n> Stop after sending count packets
-Q, --tos=<n> Set Type of Service related bits in IP datagrams
-T, --ttl=<n> Set Time to Live related bits in IP datagrams
-I, --interface=<n> Set Interface number 0=no-interface selected, >0 netif number + 1 (1 is usually 'lo0')
<host> Host address
getaddrinfo [-f <AF>] [-F <FLAGS>]... [-p <port>] <hostname>
@@ -121,8 +122,8 @@ getaddrinfo -f AF_INET -F AI_PASSIVE www.example.com
ping www.example.com
```
2. To specify additional options, such as timeout, interval, packet size, etc.:
2. To specify additional options, such as timeout, interval, packet size, interface, etc.:
```
ping -W 5 -i 1 -s 64 -c 4 -Q 0x10 -T 64 www.example.com
ping -W 5 -i 1 -s 64 -c 4 -Q 0x10 -T 64 -I 0 www.example.com
```

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -99,6 +99,7 @@ static struct {
struct arg_int *count;
struct arg_int *tos;
struct arg_int *ttl;
struct arg_int *interface;
struct arg_str *host;
struct arg_end *end;
} ping_args;
@@ -137,6 +138,10 @@ static int do_ping_cmd(int argc, char **argv)
config.ttl = (uint32_t)(ping_args.ttl->ival[0]);
}
if (ping_args.interface->count > 0) {
config.interface = (uint32_t)(ping_args.interface->ival[0]);
}
// parse IP address
struct sockaddr_in6 sock_addr6;
ip_addr_t target_addr = {0};
@@ -155,12 +160,12 @@ static int do_ping_cmd(int argc, char **argv)
}
if (res->ai_family == AF_INET) {
#if CONFIG_LWIP_IPV4
struct in_addr addr4 = ((struct sockaddr_in *) (res->ai_addr))->sin_addr;
struct in_addr addr4 = ((struct sockaddr_in *)(res->ai_addr))->sin_addr;
inet_addr_to_ip4addr(ip_2_ip4(&target_addr), &addr4);
#endif
} else {
#if CONFIG_LWIP_IPV6
struct in6_addr addr6 = ((struct sockaddr_in6 *) (res->ai_addr))->sin6_addr;
struct in6_addr addr6 = ((struct sockaddr_in6 *)(res->ai_addr))->sin6_addr;
inet6_addr_to_ip6addr(ip_2_ip6(&target_addr), &addr6);
#endif
}
@@ -204,6 +209,7 @@ esp_err_t console_cmd_ping_register(void)
ping_args.count = arg_int0("c", "count", "<n>", "Stop after sending count packets");
ping_args.tos = arg_int0("Q", "tos", "<n>", "Set Type of Service related bits in IP datagrams");
ping_args.ttl = arg_int0("T", "ttl", "<n>", "Set Time to Live related bits in IP datagrams");
ping_args.interface = arg_int0("I", "interface", "<n>", "Set Interface number");
ping_args.host = arg_str1(NULL, NULL, "<host>", "Host address");
ping_args.end = arg_end(1);
const esp_console_cmd_t ping_cmd = {

View File

@@ -1,4 +1,4 @@
version: 1.1.0
version: 1.2.0
url: https://github.com/espressif/esp-protocols/tree/master/components/console_cmd_ping
description: The component provides a console where the 'ping' command can be executed.
dependencies:

View File

@@ -3,6 +3,6 @@ commitizen:
bump_message: 'bump(eppp): $current_version -> $new_version'
pre_bump_hooks: python ../../ci/changelog.py eppp_link
tag_format: eppp-v$version
version: 0.2.0
version: 1.1.3
version_files:
- idf_component.yml

View File

@@ -1,5 +1,65 @@
# Changelog
## [1.1.3](https://github.com/espressif/esp-protocols/commits/eppp-v1.1.3)
### Bug Fixes
- Fix test dependency issue on driver ([1ace92c2](https://github.com/espressif/esp-protocols/commit/1ace92c2))
- Fix tun netif to (optionally) return errors ([7a6cf0f9](https://github.com/espressif/esp-protocols/commit/7a6cf0f9))
## [1.1.2](https://github.com/espressif/esp-protocols/commits/eppp-v1.1.2)
### Bug Fixes
- Update uart driver deps per IDF > v5.3 ([92e14607](https://github.com/espressif/esp-protocols/commit/92e14607))
## [1.1.1](https://github.com/espressif/esp-protocols/commits/eppp-v1.1.1)
### Bug Fixes
- Fix getting context for channel API ([94563cdc](https://github.com/espressif/esp-protocols/commit/94563cdc))
- Cover more combinations in build tests ([e0b8de8f](https://github.com/espressif/esp-protocols/commit/e0b8de8f))
## [1.1.0](https://github.com/espressif/esp-protocols/commits/eppp-v1.1.0)
### Features
- Add support for UART flow control ([cd57f1bb](https://github.com/espressif/esp-protocols/commit/cd57f1bb), [#870](https://github.com/espressif/esp-protocols/issues/870))
### Bug Fixes
- Fix SPI transport to allow already init GPIO ISR ([497ee2d6](https://github.com/espressif/esp-protocols/commit/497ee2d6), [#868](https://github.com/espressif/esp-protocols/issues/868))
- Fix stack-overflow in ping task for TUN netif ([b2568a3d](https://github.com/espressif/esp-protocols/commit/b2568a3d), [#867](https://github.com/espressif/esp-protocols/issues/867))
### Updated
- ci(common): Update test component dir for IDFv6.0 ([18418c83](https://github.com/espressif/esp-protocols/commit/18418c83))
## [1.0.1](https://github.com/espressif/esp-protocols/commits/eppp-v1.0.1)
### Bug Fixes
- Support for IPv4-only mode ([653328ba](https://github.com/espressif/esp-protocols/commit/653328ba), [#864](https://github.com/espressif/esp-protocols/issues/864))
## [1.0.0](https://github.com/espressif/esp-protocols/commits/eppp-v1.0.0)
### Features
- Add support for custom channels ([4ee9360f](https://github.com/espressif/esp-protocols/commit/4ee9360f))
## [0.3.1](https://github.com/espressif/esp-protocols/commits/eppp-v0.3.1)
### Bug Fixes
- Fix NETIF_PPP_STATUS link issue if PPP disabled in lwip ([077ea0bb](https://github.com/espressif/esp-protocols/commit/077ea0bb))
## [0.3.0](https://github.com/espressif/esp-protocols/commits/eppp-v0.3.0)
### Features
- Add support for TUN interface ([2ff150c3](https://github.com/espressif/esp-protocols/commit/2ff150c3))
- Add support for transport via Ethernet link ([a21ce883](https://github.com/espressif/esp-protocols/commit/a21ce883))
## [0.2.0](https://github.com/espressif/esp-protocols/commits/eppp-v0.2.0)
### Features

View File

@@ -1,3 +1,33 @@
idf_component_register(SRCS eppp_link.c eppp_sdio_slave.c eppp_sdio_host.c
if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER "5.3")
set(driver_deps esp_driver_gpio esp_driver_spi esp_driver_uart esp_driver_sdio)
else()
set(driver_deps driver)
endif()
if(CONFIG_EPPP_LINK_DEVICE_ETH)
set(transport_src eppp_eth.c)
endif()
if(CONFIG_EPPP_LINK_DEVICE_SPI)
set(transport_src eppp_spi.c)
endif()
if(CONFIG_EPPP_LINK_DEVICE_UART)
set(transport_src eppp_uart.c)
endif()
if(CONFIG_EPPP_LINK_DEVICE_SDIO)
set(transport_src eppp_sdio.c eppp_sdio_slave.c eppp_sdio_host.c)
endif()
if(NOT CONFIG_EPPP_LINK_USES_PPP)
set(netif_src eppp_netif_tun.c)
endif()
idf_component_register(SRCS eppp_link.c ${transport_src} ${netif_src}
INCLUDE_DIRS "include"
PRIV_REQUIRES esp_netif esp_driver_spi esp_driver_gpio esp_timer driver)
PRIV_REQUIRES esp_netif esp_timer esp_eth ${driver_deps})
if(CONFIG_EPPP_LINK_DEVICE_ETH)
idf_component_optional_requires(PRIVATE ethernet_init espressif__ethernet_init)
endif()

View File

@@ -1,10 +1,16 @@
menu "eppp_link"
config EPPP_LINK_USES_LWIP
bool
default "y"
config EPPP_LINK_USES_PPP
bool "Use PPP network interface"
default "n"
select LWIP_PPP_SUPPORT
select LWIP_PPP_SERVER_SUPPORT
help
Enable this option to use PPP network interface.
This is useful when pairing with another PPP device,
e.g. pppd service on Linux.
By default EPPP_LINK uses plain TUN interface,
relying on transports to split on packet boundaries.
choice EPPP_LINK_DEVICE
prompt "Choose PPP device"
@@ -28,6 +34,16 @@ menu "eppp_link"
help
Use SDIO.
config EPPP_LINK_DEVICE_ETH
bool "Ethernet"
depends on SOC_EMAC_SUPPORTED
help
Use Ethernet.
This transport could employ a full fledged Ethernet connection
between two EPPP nodes via standard Ethernet cable.
It could be also effectively connected directly on PCB, EMAC to EMAC,
without any Ethernet PHY chips (using eth_dummy_phy driver).
endchoice
config EPPP_LINK_CONN_MAX_RETRY
@@ -67,4 +83,31 @@ menu "eppp_link"
endchoice
config EPPP_LINK_ETHERNET_OUR_ADDRESS
string "MAC address our local node"
default "06:00:00:00:00:01"
depends on EPPP_LINK_DEVICE_ETH
config EPPP_LINK_ETHERNET_THEIR_ADDRESS
string "MAC address the remote node"
default "06:00:00:00:00:02"
depends on EPPP_LINK_DEVICE_ETH
config EPPP_LINK_CHANNELS_SUPPORT
bool "Enable channel support (multiple logical channels)"
default n
depends on !EPPP_LINK_DEVICE_ETH
help
Enable support for multiple logical channels in the EPPP link layer.
When enabled, you can configure the number of channels used for communication.
config EPPP_LINK_NR_OF_CHANNELS
int "Number of logical channels"
depends on EPPP_LINK_CHANNELS_SUPPORT && !EPPP_LINK_DEVICE_ETH
range 1 8
default 2
help
Set the number of logical channels for EPPP link communication.
Each channel can be used for independent data streams.
endmenu

View File

@@ -1,24 +1,74 @@
# ESP PPP Link component (eppp_link)
The component provides a general purpose connectivity engine between two microcontrollers, one acting as PPP server (slave), the other one as PPP client (host).
This component could be used for extending network using physical serial connection. Applications could vary from providing PRC engine for multiprocessor solutions to serial connection to POSIX machine. This uses a standard PPP protocol to negotiate IP addresses and networking, so standard PPP toolset could be used, e.g. a `pppd` service on linux. Typical application is a WiFi connectivity provider for chips that do not have WiFi
The component provides a general purpose connectivity engine between two microcontrollers, one acting as PPP server, the other one as PPP client.
This component could be used for extending network using physical serial connection. Applications could vary from providing RPC engine for multiprocessor solutions to serial connection to POSIX machine. This uses a standard PPP protocol (if enabled) to negotiate IP addresses and networking, so standard PPP toolset could be used, e.g. a `pppd` service on linux. Typical application is a WiFi connectivity provider for chips that do not have WiFi.
Uses simplified TUN network interface by default to enable faster data transfer on non-UART transports.
## Typical application
Using this component we can construct a WiFi connectivity gateway on PPP channel. The below diagram depicts an application where
PPP server is running on a WiFi capable chip with NAPT module translating packets between WiFi and PPPoS interface.
We usually call this node a SLAVE microcontroller. The "HOST" microcontroller runs PPP client and connects only to the serial line,
brings in the WiFi connectivity from the "SLAVE" microcontroller.
We usually call this node a communication coprocessor, or a "SLAVE" microcontroller.
The main microcontroller (sometimes also called the "HOST") runs PPP client and connects only to the serial line,
brings in the WiFi connectivity from the communication coprocessor.
```
SLAVE micro HOST micro
\|/ +----------------+ +----------------+
| | | serial line | |
+---+ WiFi NAT PPPoS |=== UART / SPI / SDIO =====| PPPoS client |
| (server)| | |
+----------------+ +----------------+
Communication coprocessor Main microcontroller
\|/ +----------------+ +----------------+
| | | (serial) line | |
+---+ WiFi NAT PPPoS |=== UART / SPI / SDIO / ETH ===| PPPoS client |
| (server)| | |
+----------------+ +----------------+
```
## Features
### Network Interface Modes
Standard PPP Mode (where PPP protocols is preferred) or simple tunnel using TUN Mode.
### Transport layer
UART, SPI, SDIO, Ethernet
### Support for logical channels
Allows channeling custom data (e.g. 802.11 frames)
## (Other) usecases
Besides the communication coprocessor example mentioned above, this component could be used to:
* Bring Wi-Fi connectivity to a computer using ESP32 chip.
* Connect your microcontroller to the internet via a pppd server (running on a raspberry)
* Bridging two networks with two microcontrollers
## Configuration
### Choose the transport layer
Use `idf.py menuconfig` to select the transport layer:
* `CONFIG_EPPP_LINK_UART` -- Use UART transport layer
* `CONFIG_EPPP_LINK_SPI` -- Use SPI transport layer
* `CONFIG_EPPP_LINK_SDIO` -- Use SDIO transport layer
* `CONFIG_EPPP_LINK_ETHERNET` -- Use Ethernet transport
- Note: Ethernet creates it's own task, so calling `eppp_perform()` would not work
- Note: Add dependency to ethernet_init component to use other Ethernet drivers
- Note: You can override functions `eppp_transport_ethernet_deinit()` and `eppp_transport_ethernet_init()` to use your own Ethernet driver
### Choose the network interface
Use PPP netif for UART; Keep the default (TUN) for others
### Channel support (multiple logical channels)
* `CONFIG_EPPP_LINK_CHANNELS_SUPPORT` -- Enable support for multiple logical channels (default: disabled)
* `CONFIG_EPPP_LINK_NR_OF_CHANNELS` -- Number of logical channels (default: 2, range: 1-8, only visible if channel support is enabled)
When channel support is enabled, the EPPP link can multiplex multiple logical data streams over the same transport. The number of channels is configurable. Channel support is not available for Ethernet transport.
To use channels in your application, use the `eppp_add_channels()` API and provide your own channel transmit/receive callbacks. These APIs and related types are only available when channel support is enabled in Kconfig.
## API
### Client
@@ -36,6 +86,9 @@ brings in the WiFi connectivity from the "SLAVE" microcontroller.
* `eppp_netif_start()` -- Starts the network, could be called after startup or whenever a connection is lost
* `eppp_netif_stop()` -- Stops the network
* `eppp_perform()` -- Perform one iteration of the PPP task (need to be called regularly in task-less configuration)
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
* `eppp_add_channels()` -- Register channel transmit/receive callbacks (only available if channel support is enabled)
#endif
## Throughput
@@ -55,3 +108,9 @@ Tested with WiFi-NAPT example
* TCP - 9Mbits/s
* UDP - 11Mbits/s
### Ethernet
- Internal EMAC with real PHY chip
* TCP - 5Mbits/s
* UDP - 8Mbits/s

View File

@@ -0,0 +1,370 @@
# ESP PPP Link Component (eppp_link) - Detailed Documentation
## Overview
The ESP PPP Link component provides a versatile communication bridge between two ESP32 microcontrollers, enabling network connectivity over various physical transport layers. One device acts as a server (typically providing connectivity), while the other acts as a client (consuming connectivity).
## Network Interface Modes
### PPP Mode vs TUN Mode
The component supports two distinct network interface modes:
#### PPP Mode (`CONFIG_EPPP_LINK_USES_PPP=y`)
- **Standard PPP Protocol**: Uses the Point-to-Point Protocol (RFC 1661) with full LCP negotiation
- **Compatibility**: Compatible with standard PPP implementations like Linux `pppd`
- **Features**:
- Automatic IP address negotiation
- Link Control Protocol (LCP) for connection establishment
- Authentication support (if configured)
- Standard PPP framing with escape sequences
- **Use Case**: When interfacing with standard PPP-capable systems or when full PPP compatibility is required
- **Transport Limitation**: Primarily designed for UART transport due to PPP's serial nature
#### TUN Mode (`CONFIG_EPPP_LINK_USES_PPP=n`, default)
- **Simplified Packet Interface**: Uses a custom packet-based protocol without PPP negotiation
- **Performance**: Faster data transfer due to reduced protocol overhead
- **Features**:
- Direct IP packet transmission
- Custom framing for packet boundaries
- No negotiation overhead
- Static IP address configuration
- **Use Case**: Default mode for ESP-to-ESP communication, optimal for non-UART transports
- **Transport Support**: Works efficiently with all transport types (UART, SPI, SDIO, Ethernet)
**Mode Selection**: Configure via `idf.py menuconfig``Component config``eppp_link``Use PPP network interface`
## Transport Layer Options
### UART Transport
- **Configuration**: `CONFIG_EPPP_LINK_DEVICE_UART=y`
- **Features**:
- Simple serial communication
- Configurable baud rate (up to 3Mbps tested)
- Hardware flow control support
- Custom framing for packet boundaries in TUN mode
- **Performance**: ~2 Mbps (TCP/UDP) @ 3 Mbaud
- **Use Case**: Basic connectivity, long-distance communication, debugging
- **Pins**: TX, RX configurable
```c
eppp_config_t config = EPPP_DEFAULT_CLIENT_CONFIG();
config.transport = EPPP_TRANSPORT_UART;
config.uart.tx_io = 25;
config.uart.rx_io = 26;
config.uart.baud = 921600;
```
### SPI Transport
- **Configuration**: `CONFIG_EPPP_LINK_DEVICE_SPI=y`
- **Features**:
- Master/slave configuration
- GPIO interrupt signaling for flow control
- Configurable clock frequency
- Full-duplex communication
- Packet queue for transmission
- **Performance**: ~5 Mbps (TCP), ~8 Mbps (UDP) @ 16MHz
- **Use Case**: High-speed local communication, PCB-level connections
- **Pins**: MOSI, MISO, SCLK, CS, interrupt GPIO
```c
eppp_config_t config = EPPP_DEFAULT_CLIENT_CONFIG();
config.transport = EPPP_TRANSPORT_SPI;
config.spi.is_master = true;
config.spi.freq = 16000000;
config.spi.mosi = 11;
config.spi.miso = 13;
config.spi.sclk = 12;
config.spi.cs = 10;
config.spi.intr = 2;
```
### SDIO Transport
- **Configuration**: `CONFIG_EPPP_LINK_DEVICE_SDIO=y`
- **Features**:
- Host/slave configuration
- High-speed data transfer
- 1-bit or 4-bit bus width
- Hardware flow control
- **Performance**: ~9 Mbps (TCP), ~11 Mbps (UDP)
- **Use Case**: Highest throughput applications, module-to-module communication
- **Pins**: CLK, CMD, D0-D3 (configurable width)
```c
eppp_config_t config = EPPP_DEFAULT_CLIENT_CONFIG();
config.transport = EPPP_TRANSPORT_SDIO;
config.sdio.is_host = true;
config.sdio.width = 4;
config.sdio.clk = 18;
config.sdio.cmd = 19;
config.sdio.d0 = 14;
// ... additional data pins
```
### Ethernet Transport
- **Configuration**: `CONFIG_EPPP_LINK_DEVICE_ETH=y`
- **Features**:
- Direct MAC-to-MAC communication
- Can work with or without PHY chips
- Standard Ethernet framing
- Automatic task management (no `eppp_perform()` needed)
- **Performance**: ~5 Mbps (TCP), ~8 Mbps (UDP) with internal EMAC
- **Use Case**: Board-to-board communication, integration with existing Ethernet infrastructure
- **Pins**: MDC, MDIO, plus PHY-specific pins
```c
eppp_config_t config = EPPP_DEFAULT_CLIENT_CONFIG();
config.transport = EPPP_TRANSPORT_ETHERNET;
config.ethernet.mdc_io = 23;
config.ethernet.mdio_io = 18;
config.ethernet.phy_addr = 1;
config.ethernet.rst_io = 5;
```
## Channel Support (Multiple Logical Channels)
### Overview
Channel support allows multiplexing multiple independent data streams over a single transport connection. This enables applications to separate different types of data (e.g., network traffic, control commands, sensor data) into distinct logical channels.
### Configuration
- **Enable**: `CONFIG_EPPP_LINK_CHANNELS_SUPPORT=y`
- **Count**: `CONFIG_EPPP_LINK_NR_OF_CHANNELS` (1-8 channels, default 2)
- **Limitation**: Not available for Ethernet transport
### Channel Usage
```c
// Channel callback function type
typedef esp_err_t (*eppp_channel_fn_t)(esp_netif_t *netif, int nr, void *buffer, size_t len);
// Register channel callbacks
esp_err_t eppp_add_channels(esp_netif_t *netif,
eppp_channel_fn_t *tx, // Transmit function pointer (output)
const eppp_channel_fn_t rx, // Receive callback (input)
void* context); // User context
// Get user context
void* eppp_get_context(esp_netif_t *netif);
```
### Channel Example
```c
// Channel 0: Default network traffic (handled automatically)
// Channel 1: Control/chat messages
// Channel 2: WiFi data forwarding
static esp_err_t channel_receive(esp_netif_t *netif, int channel, void *buffer, size_t len)
{
switch(channel) {
case 1: // Control channel
process_control_message(buffer, len);
break;
case 2: // WiFi channel
forward_to_wifi(buffer, len);
break;
default:
ESP_LOGE(TAG, "Unknown channel %d", channel);
return ESP_FAIL;
}
return ESP_OK;
}
// Register channels
eppp_channel_fn_t tx_func;
eppp_add_channels(netif, &tx_func, channel_receive, user_context);
// Transmit on specific channel
tx_func(netif, 1, "Hello", 5); // Send to channel 1
```
## API Reference
### Simple API (Recommended for most use cases)
#### Client Side
```c
esp_netif_t *eppp_connect(eppp_config_t *config);
```
- **Purpose**: Simplified client connection
- **Behavior**: Blocks until connection is established
- **Returns**: Configured network interface or NULL on failure
- **Use Case**: Simple applications that don't need fine-grained control
#### Server Side
```c
esp_netif_t *eppp_listen(eppp_config_t *config);
```
- **Purpose**: Simplified server listening
- **Behavior**: Blocks until client connects
- **Returns**: Configured network interface or NULL on failure
- **Use Case**: Simple applications that don't need fine-grained control
#### Connection Management
```c
void eppp_close(esp_netif_t *netif);
```
- **Purpose**: Close connection and cleanup resources
- **Behavior**: Stops tasks, closes transport, destroys network interface
### Advanced API (Manual Control)
#### Initialization
```c
esp_netif_t *eppp_init(eppp_type_t role, eppp_config_t *config);
```
- **Purpose**: Initialize endpoint without starting communication
- **Parameters**:
- `role`: `EPPP_SERVER` or `EPPP_CLIENT`
- `config`: Transport and network configuration
- **Returns**: Network interface handle
- **Use Case**: Applications needing manual control over connection lifecycle
#### Connection Control
```c
esp_err_t eppp_netif_start(esp_netif_t *netif);
esp_err_t eppp_netif_stop(esp_netif_t *netif, int stop_timeout_ms);
```
- **Purpose**: Manual network interface start/stop
- **Use Case**: Dynamic connection management, error recovery
#### Task Management
```c
esp_err_t eppp_perform(esp_netif_t *netif);
```
- **Purpose**: Single iteration of communication task
- **Returns**:
- `ESP_OK`: Continue operation
- `ESP_FAIL`: Operation failed but should continue
- `ESP_ERR_TIMEOUT`: Stop operation requested
- **Use Case**: Task-less operation, integration with custom task schedulers
- **Note**: Not needed for Ethernet transport (has its own task)
#### Resource Management
```c
void eppp_deinit(esp_netif_t *netif);
```
- **Purpose**: Clean up resources without stopping tasks
- **Use Case**: Manual resource management
## Configuration Examples
### Basic Client-Server Setup
**Client (Host) Configuration:**
```c
void app_main(void)
{
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
eppp_config_t config = EPPP_DEFAULT_CLIENT_CONFIG();
config.transport = EPPP_TRANSPORT_UART;
config.uart.tx_io = 25;
config.uart.rx_io = 26;
config.uart.baud = 921600;
esp_netif_t *netif = eppp_connect(&config);
if (netif == NULL) {
ESP_LOGE(TAG, "Failed to connect");
return;
}
ESP_LOGI(TAG, "Connected successfully");
// Use network interface for communication
}
```
**Server (Slave) Configuration:**
```c
void app_main(void)
{
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
// Initialize WiFi or other network interface
init_wifi();
eppp_config_t config = EPPP_DEFAULT_SERVER_CONFIG();
config.transport = EPPP_TRANSPORT_UART;
config.uart.tx_io = 26; // Crossed with client
config.uart.rx_io = 25; // Crossed with client
config.uart.baud = 921600;
esp_netif_t *netif = eppp_listen(&config);
if (netif == NULL) {
ESP_LOGE(TAG, "Failed to setup server");
return;
}
// Enable NAT to share WiFi connection
ESP_ERROR_CHECK(esp_netif_napt_enable(netif));
ESP_LOGI(TAG, "Server ready");
}
```
### Advanced Manual Control
```c
void app_main(void)
{
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
eppp_config_t config = EPPP_DEFAULT_CLIENT_CONFIG();
config.task.run_task = false; // Disable automatic task
esp_netif_t *netif = eppp_init(EPPP_CLIENT, &config);
if (netif == NULL) {
ESP_LOGE(TAG, "Failed to initialize");
return;
}
// Start network interface
ESP_ERROR_CHECK(eppp_netif_start(netif));
// Custom task loop
while (true) {
esp_err_t ret = eppp_perform(netif);
if (ret == ESP_ERR_TIMEOUT) {
ESP_LOGI(TAG, "Operation stopped");
break;
} else if (ret != ESP_OK) {
ESP_LOGE(TAG, "Operation failed: %s", esp_err_to_name(ret));
}
// Add custom processing here
vTaskDelay(pdMS_TO_TICKS(1));
}
eppp_deinit(netif);
}
```
### Multi-Channel Configuration
```c
typedef struct {
eppp_channel_fn_t tx_func;
esp_netif_t *netif;
} channel_context_t;
static esp_err_t channel_rx(esp_netif_t *netif, int channel, void *buffer, size_t len)
{
ESP_LOGI(TAG, "Channel %d received %d bytes", channel, len);
// Process channel data based on channel number
return ESP_OK;
}
void setup_channels(void)
{
eppp_config_t config = EPPP_DEFAULT_CLIENT_CONFIG();
esp_netif_t *netif = eppp_connect(&config);
channel_context_t *ctx = calloc(1, sizeof(channel_context_t));
ctx->netif = netif;
// Register channel callbacks
ESP_ERROR_CHECK(eppp_add_channels(netif, &ctx->tx_func, channel_rx, ctx));
// Send data on channel 1
const char *msg = "Hello on channel 1";
ctx->tx_func(netif, 1, (void*)msg, strlen(msg));
}
```

View File

@@ -0,0 +1,210 @@
/*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <string.h>
#include <stdint.h>
#include <inttypes.h>
#include "esp_log.h"
#include "esp_netif.h"
#include "esp_check.h"
#include "esp_event.h"
#include "esp_mac.h"
#include "esp_idf_version.h"
#include "eppp_link.h"
#include "eppp_transport.h"
#include "esp_eth_driver.h"
#include "esp_eth_spec.h"
#include "eppp_transport_eth.h"
// Use Ethernet Init component if available
// (otherwise use just simple init/deinit with generic MAC/PHY)
#if __has_include("ethernet_init.h")
#define USE_ETHERNET_INIT_COMPONENT
#include "ethernet_init.h"
#endif
typedef struct header {
uint8_t dst[ETH_ADDR_LEN];
uint8_t src[ETH_ADDR_LEN];
uint16_t len;
} __attribute__((packed)) header_t;
static const char *TAG = "eppp_ethernet";
static bool s_is_connected = false;
static esp_eth_handle_t *s_eth_handles = NULL;
static uint8_t s_their_mac[ETH_ADDR_LEN];
static uint8_t s_our_mac[ETH_ADDR_LEN];
#ifndef USE_ETHERNET_INIT_COMPONENT
static esp_eth_handle_t s_handles[1] = { NULL };
static esp_eth_mac_t *s_mac = NULL;
static esp_eth_phy_t *s_phy = NULL;
static void simple_deinit(esp_eth_handle_t *handle_array[])
{
if (s_handles[0] != NULL) {
esp_eth_driver_uninstall(s_handles[0]);
s_handles[0] = NULL;
}
if (s_mac != NULL) {
s_mac->del(s_mac);
s_mac = NULL;
}
if (s_phy != NULL) {
s_phy->del(s_phy);
s_phy = NULL;
}
}
static esp_err_t simple_init(struct eppp_config_ethernet_s *config, esp_eth_handle_t *handle_array[])
{
esp_err_t ret = ESP_OK;
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG();
esp32_emac_config.smi_gpio.mdc_num = config->mdc_io;
esp32_emac_config.smi_gpio.mdio_num = config->mdio_io;
s_mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config);
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
phy_config.phy_addr = config->phy_addr;
phy_config.reset_gpio_num = config->rst_io;
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
s_phy = esp_eth_phy_new_generic(&phy_config);
#else
s_phy = esp_eth_phy_new_ip101(&phy_config);
#endif
esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(s_mac, s_phy);
ESP_GOTO_ON_ERROR(esp_eth_driver_install(&eth_config, &s_handles[0]), err, TAG, "Ethernet driver install failed");
*handle_array = s_handles;
return ESP_OK;
err:
simple_deinit(handle_array);
return ret;
}
#endif // USE_ETHERNET_INIT_COMPONENT
static void event_handler(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data)
{
switch (event_id) {
case ETHERNET_EVENT_CONNECTED:
ESP_LOGI(TAG, "Ethernet Link Up");
s_is_connected = true;
break;
case ETHERNET_EVENT_DISCONNECTED:
ESP_LOGI(TAG, "Ethernet Link Down");
s_is_connected = false;
break;
case ETHERNET_EVENT_START:
ESP_LOGI(TAG, "Ethernet Started");
break;
case ETHERNET_EVENT_STOP:
ESP_LOGI(TAG, "Ethernet Stopped");
break;
default:
break;
}
}
static esp_err_t receive(esp_eth_handle_t h, uint8_t *buffer, uint32_t len, void *netif)
{
header_t *head = (header_t *)buffer;
size_t packet_len = head->len;
if (len >= packet_len) {
esp_err_t ret = esp_netif_receive(netif, buffer + ETH_HEADER_LEN, packet_len, NULL);
free(buffer);
return ret;
}
return ESP_FAIL;
}
__attribute__((weak)) esp_err_t eppp_transport_ethernet_init(struct eppp_config_ethernet_s *config, esp_eth_handle_t *handle_array[])
{
#ifdef USE_ETHERNET_INIT_COMPONENT
uint8_t eth_port_cnt = 0;
ESP_RETURN_ON_ERROR(ethernet_init_all(handle_array, &eth_port_cnt), TAG, "Failed to init common eth drivers");
ESP_RETURN_ON_FALSE(eth_port_cnt == 1, ESP_ERR_INVALID_ARG, TAG, "multiple Ethernet devices detected, please init only one");
return ESP_OK;
#else
return simple_init(config, handle_array);
#endif
}
__attribute__((weak)) void eppp_transport_ethernet_deinit(esp_eth_handle_t *handle_array[])
{
#ifdef USE_ETHERNET_INIT_COMPONENT
ethernet_deinit_all(s_eth_handles);
#else
simple_deinit(handle_array);
#endif
}
esp_err_t eppp_transport_tx(void *h, void *buffer, size_t len)
{
static uint8_t out_buffer[ETH_HEADER_LEN];
if (!s_is_connected) {
return ESP_FAIL;
}
// setup Ethernet header
header_t *head = (header_t *)out_buffer;
memcpy(head->dst, s_their_mac, ETH_ADDR_LEN);
memcpy(head->src, s_our_mac, ETH_ADDR_LEN);
head->len = len;
// support only payloads with len <= ETH_MAX_PAYLOAD_LEN
if (len > ETH_MAX_PAYLOAD_LEN) {
return ESP_FAIL;
}
return esp_eth_transmit_vargs(s_eth_handles[0], 2, out_buffer, ETH_HEADER_LEN, buffer, len);
}
static esp_err_t start_driver(esp_netif_t *esp_netif)
{
ESP_RETURN_ON_ERROR(esp_eth_update_input_path(s_eth_handles[0], receive, esp_netif), TAG, "Failed to set Ethernet Rx callback");
sscanf(CONFIG_EPPP_LINK_ETHERNET_OUR_ADDRESS, "%2" PRIx8 ":%2" PRIx8 ":%2" PRIx8 ":%2" PRIx8 ":%2" PRIx8 ":%2" PRIx8,
&s_our_mac[0], &s_our_mac[1], &s_our_mac[2], &s_our_mac[3], &s_our_mac[4], &s_our_mac[5]);
sscanf(CONFIG_EPPP_LINK_ETHERNET_THEIR_ADDRESS, "%2" PRIx8 ":%2" PRIx8 ":%2" PRIx8 ":%2" PRIx8 ":%2" PRIx8 ":%2" PRIx8,
&s_their_mac[0], &s_their_mac[1], &s_their_mac[2], &s_their_mac[3], &s_their_mac[4], &s_their_mac[5]);
esp_eth_ioctl(s_eth_handles[0], ETH_CMD_S_MAC_ADDR, s_our_mac);
ESP_RETURN_ON_ERROR(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, event_handler, NULL), TAG, "Failed to register Ethernet handlers");
ESP_RETURN_ON_ERROR(esp_eth_start(s_eth_handles[0]), TAG, "Failed to start Ethernet driver");
return ESP_OK;
}
static esp_err_t post_attach(esp_netif_t *esp_netif, void *args)
{
eppp_transport_handle_t h = (eppp_transport_handle_t)args;
ESP_RETURN_ON_FALSE(h, ESP_ERR_INVALID_ARG, TAG, "Transport handle cannot be null");
h->base.netif = esp_netif;
esp_netif_driver_ifconfig_t driver_ifconfig = {
.handle = h,
.transmit = eppp_transport_tx,
};
ESP_RETURN_ON_ERROR(esp_netif_set_driver_config(esp_netif, &driver_ifconfig), TAG, "Failed to set driver config");
ESP_LOGI(TAG, "EPPP Ethernet transport attached to EPPP netif %s", esp_netif_get_desc(esp_netif));
ESP_RETURN_ON_ERROR(start_driver(esp_netif), TAG, "Failed to start EPPP ethernet driver");
ESP_LOGI(TAG, "EPPP Ethernet driver started");
return ESP_OK;
}
eppp_transport_handle_t eppp_eth_init(struct eppp_config_ethernet_s *config)
{
__attribute__((unused)) esp_err_t ret = ESP_OK;
ESP_RETURN_ON_FALSE(config, NULL, TAG, "Config cannot be null");
eppp_transport_handle_t h = calloc(1, sizeof(struct eppp_handle));
ESP_RETURN_ON_FALSE(h, NULL, TAG, "Failed to allocate eppp_handle");
ESP_GOTO_ON_ERROR(eppp_transport_ethernet_init(config, &s_eth_handles), err, TAG, "Failed to init Ethernet transport");
h->base.post_attach = post_attach;
return h;
err:
return NULL;
}
void eppp_eth_deinit(eppp_transport_handle_t h)
{
esp_eth_stop(s_eth_handles[0]);
eppp_transport_ethernet_deinit(&s_eth_handles);
}

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -12,16 +12,17 @@
#include "esp_event.h"
#include "esp_netif_ppp.h"
#include "eppp_link.h"
#include "esp_serial_slave_link/essl_sdio.h"
#include "eppp_transport_eth.h"
#include "eppp_transport_spi.h"
#include "eppp_transport_uart.h"
#include "eppp_transport_sdio.h"
#include "eppp_transport.h"
#if CONFIG_EPPP_LINK_DEVICE_SPI
#include "driver/spi_master.h"
#include "driver/spi_slave.h"
#include "driver/gpio.h"
#include "esp_timer.h"
#include "esp_rom_crc.h"
#elif CONFIG_EPPP_LINK_DEVICE_UART
#include "driver/uart.h"
#if CONFIG_EPPP_LINK_DEVICE_ETH
#define EPPP_NEEDS_TASK 0
#else
#define EPPP_NEEDS_TASK 1
#endif
static const int GOT_IPV4 = BIT0;
@@ -33,204 +34,54 @@ static const char *TAG = "eppp_link";
static int s_retry_num = 0;
static int s_eppp_netif_count = 0; // used as a suffix for the netif key
struct packet {
size_t len;
uint8_t *data;
};
#if CONFIG_EPPP_LINK_DEVICE_SPI
#define MAX_PAYLOAD 1500
#define MIN_TRIGGER_US 20
#define SPI_HEADER_MAGIC 0x1234
static void timer_callback(void *arg);
struct header {
uint16_t magic;
uint16_t size;
uint16_t next_size;
uint16_t check;
} __attribute__((packed));
enum blocked_status {
NONE,
MASTER_BLOCKED,
MASTER_WANTS_READ,
SLAVE_BLOCKED,
SLAVE_WANTS_WRITE,
};
#endif // CONFIG_EPPP_LINK_DEVICE_SPI
struct eppp_handle {
#if CONFIG_EPPP_LINK_DEVICE_SPI
QueueHandle_t out_queue;
QueueHandle_t ready_semaphore;
spi_device_handle_t spi_device;
spi_host_device_t spi_host;
int gpio_intr;
uint16_t next_size;
uint16_t transaction_size;
struct packet outbound;
enum blocked_status blocked;
uint32_t slave_last_edge;
esp_timer_handle_t timer;
#elif CONFIG_EPPP_LINK_DEVICE_UART
QueueHandle_t uart_event_queue;
uart_port_t uart_port;
#endif
esp_netif_t *netif;
eppp_type_t role;
bool stop;
bool exited;
bool netif_stop;
};
typedef esp_err_t (*transmit_t)(void *h, void *buffer, size_t len);
#if CONFIG_EPPP_LINK_DEVICE_SDIO
esp_err_t eppp_sdio_host_tx(void *h, void *buffer, size_t len);
esp_err_t eppp_sdio_host_rx(esp_netif_t *netif);
esp_err_t eppp_sdio_slave_rx(esp_netif_t *netif);
esp_err_t eppp_sdio_slave_tx(void *h, void *buffer, size_t len);
esp_err_t eppp_sdio_host_init(struct eppp_config_sdio_s *config);
esp_err_t eppp_sdio_slave_init(void);
void eppp_sdio_slave_deinit(void);
void eppp_sdio_host_deinit(void);
#else
static esp_err_t transmit(void *h, void *buffer, size_t len)
{
struct eppp_handle *handle = h;
#if CONFIG_EPPP_LINK_DEVICE_SPI
struct packet buf = { };
uint8_t *current_buffer = buffer;
size_t remaining = len;
do { // TODO(IDF-9194): Refactor this loop to allocate only once and perform
// fragmentation after receiving from the queue (applicable only if MTU > MAX_PAYLOAD)
size_t batch = remaining > MAX_PAYLOAD ? MAX_PAYLOAD : remaining;
buf.data = malloc(batch);
if (buf.data == NULL) {
ESP_LOGE(TAG, "Failed to allocate packet");
return ESP_ERR_NO_MEM;
}
buf.len = batch;
remaining -= batch;
memcpy(buf.data, current_buffer, batch);
current_buffer += batch;
BaseType_t ret = xQueueSend(handle->out_queue, &buf, 0);
if (ret != pdTRUE) {
ESP_LOGE(TAG, "Failed to queue packet to slave!");
return ESP_ERR_NO_MEM;
}
} while (remaining > 0);
if (handle->role == EPPP_SERVER && handle->blocked == SLAVE_BLOCKED) {
uint32_t now = esp_timer_get_time();
uint32_t diff = now - handle->slave_last_edge;
if (diff < MIN_TRIGGER_US) {
esp_rom_delay_us(MIN_TRIGGER_US - diff);
}
gpio_set_level(handle->gpio_intr, 0);
}
#elif CONFIG_EPPP_LINK_DEVICE_UART
ESP_LOG_BUFFER_HEXDUMP("ppp_uart_send", buffer, len, ESP_LOG_VERBOSE);
uart_write_bytes(handle->uart_port, buffer, len);
#endif // DEVICE UART or SPI
return ESP_OK;
}
#endif
static void netif_deinit(esp_netif_t *netif)
void eppp_netif_deinit(esp_netif_t *netif)
{
if (netif == NULL) {
return;
}
struct eppp_handle *h = esp_netif_get_io_driver(netif);
if (h == NULL) {
return;
}
#if CONFIG_EPPP_LINK_DEVICE_SPI
struct packet buf = { };
while (xQueueReceive(h->out_queue, &buf, 0) == pdTRUE) {
if (buf.len > 0) {
free(buf.data);
}
}
vQueueDelete(h->out_queue);
if (h->role == EPPP_CLIENT) {
vSemaphoreDelete(h->ready_semaphore);
}
#endif
free(h);
esp_netif_destroy(netif);
if (s_eppp_netif_count > 0) {
s_eppp_netif_count--;
}
}
static esp_netif_t *netif_init(eppp_type_t role, eppp_config_t *eppp_config)
#ifdef CONFIG_EPPP_LINK_USES_PPP
#define NETSTACK_CONFIG() ESP_NETIF_NETSTACK_DEFAULT_PPP
#else
#define NETSTACK_CONFIG() g_eppp_netif_config_tun
extern esp_netif_netstack_config_t *g_eppp_netif_config_tun;
#define ESP_NETIF_INHERENT_DEFAULT_SLIP() \
{ \
ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(mac) \
ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(ip_info) \
.flags = ESP_NETIF_FLAG_EVENT_IP_MODIFIED, \
.get_ip_event = IP_EVENT_PPP_GOT_IP, \
.lost_ip_event = IP_EVENT_PPP_LOST_IP, \
.if_key = "EPPP_TUN", \
.if_desc = "eppp", \
.route_prio = 1, \
.bridge_info = NULL \
};
#endif // CONFIG_EPPP_LINK_USES_PPP
esp_netif_t *eppp_netif_init(eppp_type_t role, eppp_transport_handle_t h, eppp_config_t *eppp_config)
{
if (s_eppp_netif_count > 9) { // Limit to max 10 netifs, since we use "EPPPx" as the unique key (where x is 0-9)
ESP_LOGE(TAG, "Cannot create more than 10 instances");
return NULL;
}
// Create the object first
struct eppp_handle *h = calloc(1, sizeof(struct eppp_handle));
if (!h) {
ESP_LOGE(TAG, "Failed to allocate eppp_handle");
return NULL;
}
h->role = role;
#if CONFIG_EPPP_LINK_DEVICE_SPI
h->out_queue = xQueueCreate(CONFIG_EPPP_LINK_PACKET_QUEUE_SIZE, sizeof(struct packet));
if (!h->out_queue) {
ESP_LOGE(TAG, "Failed to create the packet queue");
free(h);
return NULL;
}
if (role == EPPP_CLIENT) {
h->ready_semaphore = xSemaphoreCreateBinary();
if (!h->ready_semaphore) {
ESP_LOGE(TAG, "Failed to create the packet queue");
vQueueDelete(h->out_queue);
free(h);
return NULL;
}
}
h->transaction_size = 0;
h->outbound.data = NULL;
h->outbound.len = 0;
if (role == EPPP_SERVER) {
esp_timer_create_args_t args = {
.callback = &timer_callback,
.arg = h,
.name = "timer"
};
if (esp_timer_create(&args, &h->timer) != ESP_OK) {
ESP_LOGE(TAG, "Failed to create the packet queue");
vQueueDelete(h->out_queue);
vSemaphoreDelete(h->ready_semaphore);
free(h);
return NULL;
}
}
#endif
esp_netif_driver_ifconfig_t driver_cfg = {
.handle = h,
#if CONFIG_EPPP_LINK_DEVICE_SDIO
.transmit = role == EPPP_CLIENT ? eppp_sdio_host_tx : eppp_sdio_slave_tx,
#else
.transmit = transmit,
#endif
};
const esp_netif_driver_ifconfig_t *ppp_driver_cfg = &driver_cfg;
#ifdef CONFIG_EPPP_LINK_USES_PPP
esp_netif_inherent_config_t base_netif_cfg = ESP_NETIF_INHERENT_DEFAULT_PPP();
#else
esp_netif_inherent_config_t base_netif_cfg = ESP_NETIF_INHERENT_DEFAULT_SLIP();
esp_netif_ip_info_t slip_ip4 = {};
slip_ip4.ip.addr = eppp_config->ppp.our_ip4_addr.addr;
slip_ip4.gw.addr = eppp_config->ppp.their_ip4_addr.addr;
slip_ip4.netmask.addr = ESP_IP4TOADDR(255, 255, 255, 0);
base_netif_cfg.ip_info = &slip_ip4;
#endif
char if_key[] = "EPPP0"; // netif key needs to be unique
if_key[sizeof(if_key) - 2 /* 2 = two chars before the terminator */ ] += s_eppp_netif_count++;
base_netif_cfg.if_key = if_key;
@@ -242,25 +93,27 @@ static esp_netif_t *netif_init(eppp_type_t role, eppp_config_t *eppp_config)
if (eppp_config->ppp.netif_prio) {
base_netif_cfg.route_prio = eppp_config->ppp.netif_prio;
}
esp_netif_config_t netif_ppp_config = { .base = &base_netif_cfg,
.driver = ppp_driver_cfg,
.stack = ESP_NETIF_NETSTACK_DEFAULT_PPP
};
esp_netif_config_t netif_config = { .base = &base_netif_cfg,
.driver = NULL,
.stack = NETSTACK_CONFIG(),
};
esp_netif_t *netif = esp_netif_new(&netif_ppp_config);
if (!netif) {
ESP_LOGE(TAG, "Failed to create esp_netif");
#if CONFIG_EPPP_LINK_DEVICE_SPI
vQueueDelete(h->out_queue);
if (h->ready_semaphore) {
vSemaphoreDelete(h->ready_semaphore);
}
#endif
free(h);
return NULL;
}
#ifdef CONFIG_EPPP_LINK_USES_PPP
__attribute__((unused)) esp_err_t ret = ESP_OK;
esp_netif_t *netif = esp_netif_new(&netif_config);
esp_netif_ppp_config_t netif_params;
ESP_GOTO_ON_ERROR(esp_netif_ppp_get_params(netif, &netif_params), err, TAG, "Failed to get PPP params");
netif_params.ppp_our_ip4_addr = eppp_config->ppp.our_ip4_addr;
netif_params.ppp_their_ip4_addr = eppp_config->ppp.their_ip4_addr;
netif_params.ppp_error_event_enabled = true;
ESP_GOTO_ON_ERROR(esp_netif_ppp_set_params(netif, &netif_params), err, TAG, "Failed to set PPP params");
return netif;
err:
esp_netif_destroy(netif);
return NULL;
#else
return esp_netif_new(&netif_config);
#endif // CONFIG_EPPP_LINK_USES_PPP
}
esp_err_t eppp_netif_stop(esp_netif_t *netif, int stop_timeout_ms)
@@ -285,7 +138,12 @@ esp_err_t eppp_netif_start(esp_netif_t *netif)
{
esp_netif_action_start(netif, 0, 0, 0);
esp_netif_action_connected(netif, 0, 0, 0);
#ifndef CONFIG_EPPP_LINK_USES_PPP
// PPP provides address negotiation, if not PPP, we need to check connection manually
return eppp_check_connection(netif);
#else
return ESP_OK;
#endif
}
static int get_netif_num(esp_netif_t *netif)
@@ -305,16 +163,17 @@ static int get_netif_num(esp_netif_t *netif)
return netif_cnt;
}
#ifdef CONFIG_EPPP_LINK_USES_PPP
static void on_ppp_event(void *arg, esp_event_base_t base, int32_t event_id, void *data)
{
esp_netif_t **netif = data;
ESP_LOGD(TAG, "PPP status event: %" PRId32, event_id);
if (base == NETIF_PPP_STATUS && event_id == NETIF_PPP_ERRORUSER) {
ESP_LOGI(TAG, "Disconnected %d", get_netif_num(*netif));
struct eppp_handle *h = esp_netif_get_io_driver(*netif);
h->netif_stop = true;
}
}
#endif // CONFIG_EPPP_LINK_USES_PPP
static void on_ip_event(void *arg, esp_event_base_t base, int32_t event_id, void *data)
{
@@ -341,356 +200,7 @@ static void on_ip_event(void *arg, esp_event_base_t base, int32_t event_id, void
}
}
#if CONFIG_EPPP_LINK_DEVICE_SPI
#define SPI_ALIGN(size) (((size) + 3U) & ~(3U))
#define TRANSFER_SIZE SPI_ALIGN((MAX_PAYLOAD + 6))
#define NEXT_TRANSACTION_SIZE(a,b) (((a)>(b))?(a):(b)) /* next transaction: whichever is bigger */
static void IRAM_ATTR timer_callback(void *arg)
{
struct eppp_handle *h = arg;
if (h->blocked == SLAVE_WANTS_WRITE) {
gpio_set_level(h->gpio_intr, 0);
}
}
static void IRAM_ATTR gpio_isr_handler(void *arg)
{
static uint32_t s_last_time;
uint32_t now = esp_timer_get_time();
uint32_t diff = now - s_last_time;
if (diff < MIN_TRIGGER_US) { // debounce
return;
}
s_last_time = now;
struct eppp_handle *h = arg;
BaseType_t yield = false;
// Positive edge means SPI slave prepared the data
if (gpio_get_level(h->gpio_intr) == 1) {
xSemaphoreGiveFromISR(h->ready_semaphore, &yield);
if (yield) {
portYIELD_FROM_ISR();
}
return;
}
// Negative edge (when master blocked) means that slave wants to transmit
if (h->blocked == MASTER_BLOCKED) {
struct packet buf = { .data = NULL, .len = -1 };
xQueueSendFromISR(h->out_queue, &buf, &yield);
if (yield) {
portYIELD_FROM_ISR();
}
}
}
static esp_err_t deinit_master(esp_netif_t *netif)
{
struct eppp_handle *h = esp_netif_get_io_driver(netif);
ESP_RETURN_ON_ERROR(spi_bus_remove_device(h->spi_device), TAG, "Failed to remove SPI bus");
ESP_RETURN_ON_ERROR(spi_bus_free(h->spi_host), TAG, "Failed to free SPI bus");
return ESP_OK;
}
static esp_err_t init_master(struct eppp_config_spi_s *config, esp_netif_t *netif)
{
struct eppp_handle *h = esp_netif_get_io_driver(netif);
h->spi_host = config->host;
h->gpio_intr = config->intr;
spi_bus_config_t bus_cfg = {};
bus_cfg.mosi_io_num = config->mosi;
bus_cfg.miso_io_num = config->miso;
bus_cfg.sclk_io_num = config->sclk;
bus_cfg.quadwp_io_num = -1;
bus_cfg.quadhd_io_num = -1;
bus_cfg.max_transfer_sz = TRANSFER_SIZE;
bus_cfg.flags = 0;
bus_cfg.intr_flags = 0;
// TODO: Init and deinit SPI bus separately (per Kconfig?)
if (spi_bus_initialize(config->host, &bus_cfg, SPI_DMA_CH_AUTO) != ESP_OK) {
return ESP_FAIL;
}
spi_device_interface_config_t dev_cfg = {};
dev_cfg.clock_speed_hz = config->freq;
dev_cfg.mode = 0;
dev_cfg.spics_io_num = config->cs;
dev_cfg.cs_ena_pretrans = config->cs_ena_pretrans;
dev_cfg.cs_ena_posttrans = config->cs_ena_posttrans;
dev_cfg.duty_cycle_pos = 128;
dev_cfg.input_delay_ns = config->input_delay_ns;
dev_cfg.pre_cb = NULL;
dev_cfg.post_cb = NULL;
dev_cfg.queue_size = 3;
if (spi_bus_add_device(config->host, &dev_cfg, &h->spi_device) != ESP_OK) {
return ESP_FAIL;
}
//GPIO config for the handshake line.
gpio_config_t io_conf = {
.intr_type = GPIO_INTR_ANYEDGE,
.mode = GPIO_MODE_INPUT,
.pull_up_en = 1,
.pin_bit_mask = BIT64(config->intr),
};
gpio_config(&io_conf);
gpio_install_isr_service(0);
gpio_set_intr_type(config->intr, GPIO_INTR_ANYEDGE);
gpio_isr_handler_add(config->intr, gpio_isr_handler, esp_netif_get_io_driver(netif));
return ESP_OK;
}
static void post_setup(spi_slave_transaction_t *trans)
{
struct eppp_handle *h = trans->user;
h->slave_last_edge = esp_timer_get_time();
gpio_set_level(h->gpio_intr, 1);
if (h->transaction_size == 0) { // If no transaction planned:
if (h->outbound.len == 0) { // we're blocked if we don't have any data
h->blocked = SLAVE_BLOCKED;
} else {
h->blocked = SLAVE_WANTS_WRITE; // we notify the master that we want to write
esp_timer_start_once(h->timer, MIN_TRIGGER_US);
}
}
}
static void post_trans(spi_slave_transaction_t *trans)
{
struct eppp_handle *h = trans->user;
h->blocked = NONE;
gpio_set_level(h->gpio_intr, 0);
}
static esp_err_t deinit_slave(esp_netif_t *netif)
{
struct eppp_handle *h = esp_netif_get_io_driver(netif);
ESP_RETURN_ON_ERROR(spi_slave_free(h->spi_host), TAG, "Failed to free SPI slave host");
ESP_RETURN_ON_ERROR(spi_bus_remove_device(h->spi_device), TAG, "Failed to remove SPI device");
ESP_RETURN_ON_ERROR(spi_bus_free(h->spi_host), TAG, "Failed to free SPI bus");
return ESP_OK;
}
static esp_err_t init_slave(struct eppp_config_spi_s *config, esp_netif_t *netif)
{
struct eppp_handle *h = esp_netif_get_io_driver(netif);
h->spi_host = config->host;
h->gpio_intr = config->intr;
spi_bus_config_t bus_cfg = {};
bus_cfg.mosi_io_num = config->mosi;
bus_cfg.miso_io_num = config->miso;
bus_cfg.sclk_io_num = config->sclk;
bus_cfg.quadwp_io_num = -1;
bus_cfg.quadhd_io_num = -1;
bus_cfg.flags = 0;
bus_cfg.intr_flags = 0;
//Configuration for the SPI slave interface
spi_slave_interface_config_t slvcfg = {
.mode = 0,
.spics_io_num = config->cs,
.queue_size = 3,
.flags = 0,
.post_setup_cb = post_setup,
.post_trans_cb = post_trans,
};
//Configuration for the handshake line
gpio_config_t io_conf = {
.intr_type = GPIO_INTR_DISABLE,
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = BIT64(config->intr),
};
gpio_config(&io_conf);
gpio_set_pull_mode(config->mosi, GPIO_PULLUP_ONLY);
gpio_set_pull_mode(config->sclk, GPIO_PULLUP_ONLY);
gpio_set_pull_mode(config->cs, GPIO_PULLUP_ONLY);
//Initialize SPI slave interface
if (spi_slave_initialize(config->host, &bus_cfg, &slvcfg, SPI_DMA_CH_AUTO) != ESP_OK) {
return ESP_FAIL;
}
return ESP_OK;
}
typedef esp_err_t (*perform_transaction_t)(struct eppp_handle *h, size_t len, const void *tx_buffer, void *rx_buffer);
static esp_err_t perform_transaction_master(struct eppp_handle *h, size_t len, const void *tx_buffer, void *rx_buffer)
{
spi_transaction_t t = {};
t.length = len * 8;
t.tx_buffer = tx_buffer;
t.rx_buffer = rx_buffer;
return spi_device_transmit(h->spi_device, &t);
}
static esp_err_t perform_transaction_slave(struct eppp_handle *h, size_t len, const void *tx_buffer, void *rx_buffer)
{
spi_slave_transaction_t t = {};
t.user = h;
t.length = len * 8;
t.tx_buffer = tx_buffer;
t.rx_buffer = rx_buffer;
return spi_slave_transmit(h->spi_host, &t, portMAX_DELAY);
}
esp_err_t eppp_perform(esp_netif_t *netif)
{
static WORD_ALIGNED_ATTR uint8_t out_buf[TRANSFER_SIZE] = {};
static WORD_ALIGNED_ATTR uint8_t in_buf[TRANSFER_SIZE] = {};
struct eppp_handle *h = esp_netif_get_io_driver(netif);
// Perform transaction for master and slave
const perform_transaction_t perform_transaction = h->role == EPPP_CLIENT ? perform_transaction_master : perform_transaction_slave;
if (h->stop) {
return ESP_ERR_TIMEOUT;
}
BaseType_t tx_queue_stat;
bool allow_test_tx = false;
uint16_t next_tx_size = 0;
if (h->role == EPPP_CLIENT) {
// SPI MASTER only code
if (xSemaphoreTake(h->ready_semaphore, pdMS_TO_TICKS(1000)) != pdTRUE) {
// slave might not be ready, but maybe we just missed an interrupt
allow_test_tx = true;
}
if (h->outbound.len == 0 && h->transaction_size == 0 && h->blocked == NONE) {
h->blocked = MASTER_BLOCKED;
xQueueReceive(h->out_queue, &h->outbound, portMAX_DELAY);
h->blocked = NONE;
if (h->outbound.len == -1) {
h->outbound.len = 0;
h->blocked = MASTER_WANTS_READ;
}
} else if (h->blocked == MASTER_WANTS_READ) {
h->blocked = NONE;
}
}
struct header *head = (void *)out_buf;
if (h->outbound.len <= h->transaction_size && allow_test_tx == false) {
// sending outbound
head->size = h->outbound.len;
if (h->outbound.len > 0) {
memcpy(out_buf + sizeof(struct header), h->outbound.data, h->outbound.len);
free(h->outbound.data);
ESP_LOG_BUFFER_HEXDUMP(TAG, out_buf + sizeof(struct header), head->size, ESP_LOG_VERBOSE);
h->outbound.data = NULL;
h->outbound.len = 0;
}
do {
tx_queue_stat = xQueueReceive(h->out_queue, &h->outbound, 0);
} while (tx_queue_stat == pdTRUE && h->outbound.len == -1);
if (h->outbound.len == -1) { // used as a signal only, no actual data
h->outbound.len = 0;
}
} else {
// outbound is bigger, need to transmit in another transaction (keep this empty)
head->size = 0;
}
next_tx_size = head->next_size = h->outbound.len;
head->magic = SPI_HEADER_MAGIC;
head->check = esp_rom_crc16_le(0, out_buf, sizeof(struct header) - sizeof(uint16_t));
esp_err_t ret = perform_transaction(h, sizeof(struct header) + h->transaction_size, out_buf, in_buf);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "spi_device_transmit failed");
h->transaction_size = 0; // need to start with HEADER only transaction
return ESP_FAIL;
}
head = (void *)in_buf;
uint16_t check = esp_rom_crc16_le(0, in_buf, sizeof(struct header) - sizeof(uint16_t));
if (check != head->check || head->magic != SPI_HEADER_MAGIC) {
h->transaction_size = 0; // need to start with HEADER only transaction
if (allow_test_tx) {
return ESP_OK;
}
ESP_LOGE(TAG, "Wrong checksum or magic");
return ESP_FAIL;
}
if (head->size > 0) {
ESP_LOG_BUFFER_HEXDUMP(TAG, in_buf + sizeof(struct header), head->size, ESP_LOG_VERBOSE);
esp_netif_receive(netif, in_buf + sizeof(struct header), head->size, NULL);
}
h->transaction_size = NEXT_TRANSACTION_SIZE(next_tx_size, head->next_size);
return ESP_OK;
}
#elif CONFIG_EPPP_LINK_DEVICE_UART
#define BUF_SIZE (1024)
static esp_err_t init_uart(struct eppp_handle *h, eppp_config_t *config)
{
h->uart_port = config->uart.port;
uart_config_t uart_config = {};
uart_config.baud_rate = config->uart.baud;
uart_config.data_bits = UART_DATA_8_BITS;
uart_config.parity = UART_PARITY_DISABLE;
uart_config.stop_bits = UART_STOP_BITS_1;
uart_config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
uart_config.source_clk = UART_SCLK_DEFAULT;
ESP_RETURN_ON_ERROR(uart_driver_install(h->uart_port, config->uart.rx_buffer_size, 0, config->uart.queue_size, &h->uart_event_queue, 0), TAG, "Failed to install UART");
ESP_RETURN_ON_ERROR(uart_param_config(h->uart_port, &uart_config), TAG, "Failed to set params");
ESP_RETURN_ON_ERROR(uart_set_pin(h->uart_port, config->uart.tx_io, config->uart.rx_io, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE), TAG, "Failed to set UART pins");
ESP_RETURN_ON_ERROR(uart_set_rx_timeout(h->uart_port, 1), TAG, "Failed to set UART Rx timeout");
return ESP_OK;
}
static void deinit_uart(struct eppp_handle *h)
{
uart_driver_delete(h->uart_port);
}
esp_err_t eppp_perform(esp_netif_t *netif)
{
static uint8_t buffer[BUF_SIZE] = {};
struct eppp_handle *h = esp_netif_get_io_driver(netif);
uart_event_t event = {};
if (h->stop) {
return ESP_ERR_TIMEOUT;
}
if (xQueueReceive(h->uart_event_queue, &event, pdMS_TO_TICKS(100)) != pdTRUE) {
return ESP_OK;
}
if (event.type == UART_DATA) {
size_t len;
uart_get_buffered_data_len(h->uart_port, &len);
if (len) {
len = uart_read_bytes(h->uart_port, buffer, BUF_SIZE, 0);
ESP_LOG_BUFFER_HEXDUMP("ppp_uart_recv", buffer, len, ESP_LOG_VERBOSE);
esp_netif_receive(netif, buffer, len, NULL);
}
} else {
ESP_LOGW(TAG, "Received UART event: %d", event.type);
}
return ESP_OK;
}
#elif CONFIG_EPPP_LINK_DEVICE_SDIO
esp_err_t eppp_perform(esp_netif_t *netif)
{
struct eppp_handle *h = esp_netif_get_io_driver(netif);
if (h->stop) {
return ESP_ERR_TIMEOUT;
}
if (h->role == EPPP_SERVER) {
return eppp_sdio_slave_rx(netif);
} else {
return eppp_sdio_host_rx(netif);
}
}
#endif // CONFIG_EPPP_LINK_DEVICE_SPI / UART
#if EPPP_NEEDS_TASK
static void ppp_task(void *args)
{
esp_netif_t *netif = args;
@@ -699,6 +209,7 @@ static void ppp_task(void *args)
h->exited = true;
vTaskDelete(NULL);
}
#endif
static bool have_some_eppp_netif(esp_netif_t *netif, void *ctx)
{
@@ -709,11 +220,13 @@ static void remove_handlers(void)
{
esp_netif_t *netif = esp_netif_find_if(have_some_eppp_netif, NULL);
if (netif == NULL) {
// if EPPP netif in the system, we cleanup the statics
// if EPPP netif in the system, we clean up the statics
vEventGroupDelete(s_event_group);
s_event_group = NULL;
esp_event_handler_unregister(IP_EVENT, ESP_EVENT_ANY_ID, on_ip_event);
#ifdef CONFIG_EPPP_LINK_USES_PPP
esp_event_handler_unregister(NETIF_PPP_STATUS, ESP_EVENT_ANY_ID, on_ppp_event);
#endif
}
}
@@ -722,67 +235,33 @@ void eppp_deinit(esp_netif_t *netif)
if (netif == NULL) {
return;
}
#if CONFIG_EPPP_LINK_DEVICE_SPI
struct eppp_handle *h = esp_netif_get_io_driver(netif);
if (h->role == EPPP_CLIENT) {
deinit_master(netif);
} else {
deinit_slave(netif);
}
#elif CONFIG_EPPP_LINK_DEVICE_UART
deinit_uart(esp_netif_get_io_driver(netif));
#elif CONFIG_EPPP_LINK_DEVICE_SDIO
struct eppp_handle *h = esp_netif_get_io_driver(netif);
if (h->role == EPPP_CLIENT) {
eppp_sdio_host_deinit();
} else {
eppp_sdio_slave_deinit();
}
#endif
netif_deinit(netif);
EPPP_TRANSPORT_DEINIT(h);
eppp_netif_deinit(netif);
}
esp_netif_t *eppp_init(eppp_type_t role, eppp_config_t *config)
{
__attribute__((unused)) esp_err_t ret = ESP_OK;
esp_netif_t *netif = NULL;
if (config == NULL || (role != EPPP_SERVER && role != EPPP_CLIENT)) {
ESP_LOGE(TAG, "Invalid configuration or role");
return NULL;
}
esp_netif_t *netif = netif_init(role, config);
if (!netif) {
ESP_LOGE(TAG, "Failed to initialize PPP netif");
return NULL;
}
esp_netif_ppp_config_t netif_params;
ESP_ERROR_CHECK(esp_netif_ppp_get_params(netif, &netif_params));
netif_params.ppp_our_ip4_addr = config->ppp.our_ip4_addr;
netif_params.ppp_their_ip4_addr = config->ppp.their_ip4_addr;
netif_params.ppp_error_event_enabled = true;
ESP_ERROR_CHECK(esp_netif_ppp_set_params(netif, &netif_params));
#if CONFIG_EPPP_LINK_DEVICE_SPI
if (role == EPPP_CLIENT) {
init_master(&config->spi, netif);
} else {
init_slave(&config->spi, netif);
}
#elif CONFIG_EPPP_LINK_DEVICE_UART
init_uart(esp_netif_get_io_driver(netif), config);
#elif CONFIG_EPPP_LINK_DEVICE_SDIO
esp_err_t ret;
if (role == EPPP_SERVER) {
ret = eppp_sdio_slave_init();
} else {
ret = eppp_sdio_host_init(&config->sdio);
}
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to initialize SDIO %d", ret);
return NULL;
}
#endif
eppp_transport_handle_t h = EPPP_TRANSPORT_INIT(config);
ESP_GOTO_ON_FALSE(h, ESP_ERR_NO_MEM, err, TAG, "Failed to init EPPP transport");
ESP_GOTO_ON_FALSE(netif = eppp_netif_init(role, h, config), ESP_ERR_NO_MEM, err, TAG, "Failed to init EPPP netif");
ESP_GOTO_ON_ERROR(esp_netif_attach(netif, h), err, TAG, "Failed to attach netif to EPPP transport");
return netif;
err:
if (h) {
EPPP_TRANSPORT_DEINIT(h);
}
if (netif) {
eppp_netif_deinit(netif);
}
return NULL;
}
esp_netif_t *eppp_open(eppp_type_t role, eppp_config_t *config, int connect_timeout_ms)
@@ -821,11 +300,13 @@ esp_netif_t *eppp_open(eppp_type_t role, eppp_config_t *config, int connect_time
remove_handlers();
return NULL;
}
#ifdef CONFIG_EPPP_LINK_USES_PPP
if (esp_event_handler_register(NETIF_PPP_STATUS, ESP_EVENT_ANY_ID, on_ppp_event, NULL) != ESP_OK) {
ESP_LOGE(TAG, "Failed to register PPP status handler");
remove_handlers();
return NULL;
}
#endif // CONFIG_EPPP_LINK_USES_PPP
}
esp_netif_t *netif = eppp_init(role, config);
if (!netif) {
@@ -834,12 +315,13 @@ esp_netif_t *eppp_open(eppp_type_t role, eppp_config_t *config, int connect_time
}
eppp_netif_start(netif);
#if EPPP_NEEDS_TASK
if (xTaskCreate(ppp_task, "ppp connect", config->task.stack_size, netif, config->task.priority, NULL) != pdTRUE) {
ESP_LOGE(TAG, "Failed to create a ppp connection task");
eppp_deinit(netif);
return NULL;
}
#endif
int netif_cnt = get_netif_num(netif);
if (netif_cnt < 0) {
eppp_close(netif);
@@ -885,3 +367,24 @@ void eppp_close(esp_netif_t *netif)
eppp_deinit(netif);
remove_handlers();
}
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
esp_err_t eppp_add_channels(esp_netif_t *netif, eppp_channel_fn_t *tx, const eppp_channel_fn_t rx, void* context)
{
ESP_RETURN_ON_FALSE(netif != NULL && tx != NULL && rx != NULL, ESP_ERR_INVALID_ARG, TAG, "Invalid arguments");
struct eppp_handle *h = esp_netif_get_io_driver(netif);
ESP_RETURN_ON_FALSE(h != NULL && h->channel_tx != NULL, ESP_ERR_INVALID_STATE, TAG, "Transport not initialized");
*tx = h->channel_tx;
h->channel_rx = rx;
h->context = context;
return ESP_OK;
}
void* eppp_get_context(esp_netif_t *netif)
{
ESP_RETURN_ON_FALSE(netif != NULL, NULL, TAG, "Invalid netif");
struct eppp_handle *h = esp_netif_get_io_driver(netif);
ESP_RETURN_ON_FALSE(h != NULL, NULL, TAG, "EPPP Not initialized");
return h->context;
}
#endif

View File

@@ -0,0 +1,207 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <string.h>
#include <stdint.h>
#include "sdkconfig.h"
#include "esp_log.h"
#include "esp_netif.h"
#include "esp_netif_net_stack.h"
#include "lwip/esp_netif_net_stack.h"
#include "lwip/prot/ethernet.h"
#include "lwip/inet.h"
#include "lwip/sockets.h"
#include "ping/ping_sock.h"
#include "esp_check.h"
#include "esp_idf_version.h"
#if defined(CONFIG_ESP_NETIF_RECEIVE_REPORT_ERRORS)
typedef esp_err_t esp_netif_recv_ret_t;
#define ESP_NETIF_OPTIONAL_RETURN_CODE(expr) expr
#else
typedef void esp_netif_recv_ret_t;
#define ESP_NETIF_OPTIONAL_RETURN_CODE(expr)
#endif // CONFIG_ESP_NETIF_RECEIVE_REPORT_ERRORS
static const char *TAG = "eppp_tun_netif";
static esp_netif_recv_ret_t tun_input(void *h, void *buffer, unsigned int len, void *eb)
{
__attribute__((unused)) esp_err_t ret = ESP_OK;
struct netif *netif = h;
struct pbuf *p = NULL;
ESP_LOG_BUFFER_HEXDUMP(TAG, buffer, len, ESP_LOG_VERBOSE);
// need to alloc extra space for the ETH header to support possible packet forwarding
ESP_GOTO_ON_FALSE(p = pbuf_alloc(PBUF_RAW, len + SIZEOF_ETH_HDR, PBUF_RAM), ESP_ERR_NO_MEM, err, TAG, "pbuf_alloc failed");
ESP_GOTO_ON_FALSE(pbuf_remove_header(p, SIZEOF_ETH_HDR) == 0, ESP_FAIL, err, TAG, "pbuf_remove_header failed");
memcpy(p->payload, buffer, len);
ESP_GOTO_ON_FALSE(netif->input(p, netif) == ERR_OK, ESP_FAIL, err, TAG, "failed to input packet to lwip");
return ESP_NETIF_OPTIONAL_RETURN_CODE(ESP_OK);
err:
if (p) {
pbuf_free(p);
}
return ESP_NETIF_OPTIONAL_RETURN_CODE(ret);
}
static err_t tun_output(struct netif *netif, struct pbuf *p)
{
LWIP_ASSERT("netif != NULL", (netif != NULL));
LWIP_ASSERT("netif->state != NULL", (netif->state != NULL));
LWIP_ASSERT("p != NULL", (p != NULL));
esp_err_t ret = esp_netif_transmit(netif->state, p->payload, p->len);
switch (ret) {
case ESP_OK:
return ERR_OK;
case ESP_ERR_NO_MEM:
return ERR_MEM;
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
case ESP_ERR_ESP_NETIF_TX_FAILED:
return ERR_BUF;
#endif
case ESP_ERR_INVALID_ARG:
return ERR_ARG;
default:
return ERR_IF;
}
}
static err_t tun_output_v4(struct netif *netif, struct pbuf *p, const ip4_addr_t *ipaddr)
{
LWIP_UNUSED_ARG(ipaddr);
return tun_output(netif, p);
}
#if LWIP_IPV6
static err_t tun_output_v6(struct netif *netif, struct pbuf *p, const ip6_addr_t *ipaddr)
{
LWIP_UNUSED_ARG(ipaddr);
return tun_output(netif, p);
}
#endif
static err_t tun_init(struct netif *netif)
{
if (netif == NULL) {
return ERR_IF;
}
netif->name[0] = 't';
netif->name[1] = 'u';
#if LWIP_IPV4
netif->output = tun_output_v4;
#endif
#if LWIP_IPV6
netif->output_ip6 = tun_output_v6;
#endif
netif->mtu = 1500;
return ERR_OK;
}
static const struct esp_netif_netstack_config s_config_tun = {
.lwip = {
.init_fn = tun_init,
.input_fn = tun_input,
}
};
const esp_netif_netstack_config_t *g_eppp_netif_config_tun = &s_config_tun;
static void cmd_ping_on_ping_success(esp_ping_handle_t hdl, void *args)
{
uint8_t ttl;
uint16_t seqno;
uint32_t elapsed_time, recv_len;
ip_addr_t target_addr;
esp_ping_get_profile(hdl, ESP_PING_PROF_SEQNO, &seqno, sizeof(seqno));
esp_ping_get_profile(hdl, ESP_PING_PROF_TTL, &ttl, sizeof(ttl));
esp_ping_get_profile(hdl, ESP_PING_PROF_IPADDR, &target_addr, sizeof(target_addr));
esp_ping_get_profile(hdl, ESP_PING_PROF_SIZE, &recv_len, sizeof(recv_len));
esp_ping_get_profile(hdl, ESP_PING_PROF_TIMEGAP, &elapsed_time, sizeof(elapsed_time));
ESP_LOGD(TAG, "%" PRIu32 " bytes from %s icmp_seq=%" PRIu16 " ttl=%" PRIu16 " time=%" PRIu32 " ms\n",
recv_len, ipaddr_ntoa((ip_addr_t *)&target_addr), seqno, ttl, elapsed_time);
if (esp_ping_stop(hdl) != ESP_OK) {
ESP_LOGE(TAG, "Failed to stop ping session");
// continue to delete the session
}
esp_ping_delete_session(hdl);
ESP_LOGI(TAG, "PING success -> stop and post IP");
esp_netif_t *netif = (esp_netif_t *)args;
esp_netif_ip_info_t ip = {0};
esp_netif_get_ip_info(netif, &ip);
esp_netif_set_ip_info(netif, &ip);
}
static void cmd_ping_on_ping_timeout(esp_ping_handle_t hdl, void *args)
{
uint16_t seqno;
ip_addr_t target_addr;
esp_ping_get_profile(hdl, ESP_PING_PROF_SEQNO, &seqno, sizeof(seqno));
esp_ping_get_profile(hdl, ESP_PING_PROF_IPADDR, &target_addr, sizeof(target_addr));
ESP_LOGD(TAG, "From %s icmp_seq=%" PRIu16 "timeout", ipaddr_ntoa((ip_addr_t *)&target_addr), seqno);
}
static void cmd_ping_on_ping_end(esp_ping_handle_t hdl, void *args)
{
ip_addr_t target_addr;
uint32_t transmitted;
uint32_t received;
uint32_t total_time_ms;
uint32_t loss;
esp_ping_get_profile(hdl, ESP_PING_PROF_REQUEST, &transmitted, sizeof(transmitted));
esp_ping_get_profile(hdl, ESP_PING_PROF_REPLY, &received, sizeof(received));
esp_ping_get_profile(hdl, ESP_PING_PROF_IPADDR, &target_addr, sizeof(target_addr));
esp_ping_get_profile(hdl, ESP_PING_PROF_DURATION, &total_time_ms, sizeof(total_time_ms));
if (transmitted > 0) {
loss = (uint32_t)((1 - ((float)received) / transmitted) * 100);
} else {
loss = 0;
}
if (IP_IS_V4(&target_addr)) {
ESP_LOGD(TAG, "\n--- %s ping statistics ---\n", inet_ntoa(*ip_2_ip4(&target_addr)));
}
#if LWIP_IPV6
else {
ESP_LOGD(TAG, "\n--- %s ping statistics ---\n", inet6_ntoa(*ip_2_ip6(&target_addr)));
}
#endif
ESP_LOGI(TAG, "%" PRIu32 " packets transmitted, %" PRIu32 " received, %" PRIu32 "%% packet loss, time %" PRIu32 "ms\n",
transmitted, received, loss, total_time_ms);
esp_ping_delete_session(hdl);
}
esp_err_t eppp_check_connection(esp_netif_t *netif)
{
esp_err_t ret = ESP_OK;
esp_ping_config_t config = ESP_PING_DEFAULT_CONFIG();
#if CONFIG_LOG_MAXIMUM_LEVEL > 3
config.task_stack_size += 1024; // Some additional stack needed for verbose logs
#endif
config.count = 100;
ESP_LOGI(TAG, "Checking connection on EPPP interface #%" PRIu32, config.interface);
ip_addr_t target_addr = {0};
esp_netif_ip_info_t ip;
esp_netif_get_ip_info(netif, &ip);
#if LWIP_IPV6
target_addr.u_addr.ip4.addr = ip.gw.addr;
#else
target_addr.addr = ip.gw.addr;
#endif
config.target_addr = target_addr;
esp_ping_callbacks_t cbs = {
.cb_args = netif,
.on_ping_success = cmd_ping_on_ping_success,
.on_ping_timeout = cmd_ping_on_ping_timeout,
.on_ping_end = cmd_ping_on_ping_end
};
esp_ping_handle_t ping;
ESP_GOTO_ON_ERROR(esp_ping_new_session(&config, &cbs, &ping), err, TAG, "Failed to create ping session");
ESP_GOTO_ON_ERROR(esp_ping_start(ping), err, TAG, "Failed to start ping session");
ESP_LOGI(TAG, "Ping started");
return ret;
err:
ESP_LOGE(TAG, "Failed to start connection check");
return ret;
}

View File

@@ -0,0 +1,92 @@
/*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <string.h>
#include <stdint.h>
#include <inttypes.h>
#include "esp_log.h"
#include "esp_netif.h"
#include "esp_check.h"
#include "esp_mac.h"
#include "eppp_link.h"
#include "eppp_transport.h"
#include "eppp_transport_sdio.h"
#include "eppp_sdio.h"
#define TAG "eppp_sdio"
struct eppp_sdio {
struct eppp_handle parent;
bool is_host;
};
esp_err_t eppp_sdio_host_tx(void *h, void *buffer, size_t len);
esp_err_t eppp_sdio_host_rx(esp_netif_t *netif);
esp_err_t eppp_sdio_slave_rx(esp_netif_t *netif);
esp_err_t eppp_sdio_slave_tx(void *h, void *buffer, size_t len);
esp_err_t eppp_sdio_host_init(struct eppp_config_sdio_s *config);
esp_err_t eppp_sdio_slave_init(struct eppp_config_sdio_s *config);
void eppp_sdio_slave_deinit(void);
void eppp_sdio_host_deinit(void);
esp_err_t eppp_perform(esp_netif_t *netif)
{
struct eppp_handle *h = esp_netif_get_io_driver(netif);
if (h->stop) {
return ESP_ERR_TIMEOUT;
}
struct eppp_sdio *handle = __containerof(h, struct eppp_sdio, parent);;
if (handle->is_host) {
return eppp_sdio_host_rx(netif);
} else {
return eppp_sdio_slave_rx(netif);
}
}
static esp_err_t post_attach(esp_netif_t *esp_netif, void *args)
{
eppp_transport_handle_t h = (eppp_transport_handle_t)args;
ESP_RETURN_ON_FALSE(h, ESP_ERR_INVALID_ARG, TAG, "Transport handle cannot be null");
struct eppp_sdio *sdio = __containerof(h, struct eppp_sdio, parent);
h->base.netif = esp_netif;
esp_netif_driver_ifconfig_t driver_ifconfig = {
.handle = h,
.transmit = sdio->is_host ? eppp_sdio_host_tx : eppp_sdio_slave_tx,
};
ESP_RETURN_ON_ERROR(esp_netif_set_driver_config(esp_netif, &driver_ifconfig), TAG, "Failed to set driver config");
ESP_LOGI(TAG, "EPPP SDIO transport attached to EPPP netif %s", esp_netif_get_desc(esp_netif));
return ESP_OK;
}
eppp_transport_handle_t eppp_sdio_init(struct eppp_config_sdio_s *config)
{
__attribute__((unused)) esp_err_t ret = ESP_OK;
ESP_RETURN_ON_FALSE(config, NULL, TAG, "Config cannot be null");
struct eppp_sdio *h = calloc(1, sizeof(struct eppp_sdio));
ESP_RETURN_ON_FALSE(h, NULL, TAG, "Failed to allocate eppp_handle");
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
h->parent.channel_tx = eppp_sdio_transmit_channel;
#endif
h->parent.base.post_attach = post_attach;
h->is_host = config->is_host;
esp_err_t (*init_fn)(struct eppp_config_sdio_s * eppp_config) = h->is_host ? eppp_sdio_host_init : eppp_sdio_slave_init;
ESP_GOTO_ON_ERROR(init_fn(config), err, TAG, "Failed to init SDIO");
return &h->parent;
err:
free(h);
return NULL;
}
void eppp_sdio_deinit(eppp_transport_handle_t h)
{
struct eppp_sdio *sdio = __containerof(h, struct eppp_sdio, parent);
if (sdio->is_host) {
eppp_sdio_host_deinit();
} else {
eppp_sdio_slave_deinit();
}
}

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -8,8 +8,10 @@
#define MAX_SDIO_PAYLOAD 1500
#define SDIO_ALIGN(size) (((size) + 3U) & ~(3U))
#define SDIO_PAYLOAD SDIO_ALIGN(MAX_SDIO_PAYLOAD)
#define SDIO_PACKET_SIZE SDIO_ALIGN(MAX_SDIO_PAYLOAD + 4)
#define PPP_SOF 0x7E
// Interrupts and registers
#define SLAVE_INTR 0
#define SLAVE_REG_REQ 0
@@ -17,3 +19,11 @@
// Requests from host to slave
#define REQ_RESET 1
#define REQ_INIT 2
struct header {
uint8_t magic;
uint8_t channel;
uint16_t size;
} __attribute__((packed));
esp_err_t eppp_sdio_transmit_channel(esp_netif_t *netif, int channel, void *buffer, size_t len);

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -15,6 +15,7 @@
#include "sdmmc_cmd.h"
#include "esp_check.h"
#include "eppp_link.h"
#include "eppp_transport.h"
#if CONFIG_EPPP_LINK_DEVICE_SDIO_HOST
@@ -28,22 +29,23 @@ static SemaphoreHandle_t s_essl_mutex = NULL;
static essl_handle_t s_essl = NULL;
static sdmmc_card_t *s_card = NULL;
static DRAM_DMA_ALIGNED_ATTR uint8_t send_buffer[SDIO_PAYLOAD];
static DMA_ATTR uint8_t rcv_buffer[SDIO_PAYLOAD];
static DRAM_DMA_ALIGNED_ATTR uint8_t send_buffer[SDIO_PACKET_SIZE];
static DMA_ATTR uint8_t rcv_buffer[SDIO_PACKET_SIZE];
esp_err_t eppp_sdio_host_tx(void *h, void *buffer, size_t len)
static esp_err_t eppp_sdio_host_tx_generic(int channel, void *buffer, size_t len)
{
if (s_essl == NULL || s_essl_mutex == NULL) {
// silently skip the Tx if the SDIO not fully initialized
return ESP_OK;
}
memcpy(send_buffer, buffer, len);
size_t send_len = SDIO_ALIGN(len);
if (send_len > len) {
// pad with SOF's
memset(&send_buffer[len], PPP_SOF, send_len - len);
}
struct header *head = (void *)send_buffer;
head->magic = PPP_SOF;
head->channel = channel;
head->size = len;
memcpy(send_buffer + sizeof(struct header), buffer, len);
size_t send_len = SDIO_ALIGN(len + sizeof(struct header));
xSemaphoreTake(s_essl_mutex, portMAX_DELAY);
esp_err_t ret = essl_send_packet(s_essl, send_buffer, send_len, PACKET_TIMEOUT_MS);
if (ret != ESP_OK) {
@@ -56,6 +58,19 @@ esp_err_t eppp_sdio_host_tx(void *h, void *buffer, size_t len)
return ret;
}
esp_err_t eppp_sdio_host_tx(void *h, void *buffer, size_t len)
{
return eppp_sdio_host_tx_generic(0, buffer, len);
}
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
esp_err_t eppp_sdio_transmit_channel(esp_netif_t *netif, int channel, void *buffer, size_t len)
{
return eppp_sdio_host_tx_generic(channel, buffer, len);
}
#endif
static esp_err_t request_slave_reset(void)
{
esp_err_t ret = ESP_OK;
@@ -145,15 +160,37 @@ esp_err_t eppp_sdio_host_rx(esp_netif_t *netif)
if (intr & ESSL_SDIO_DEF_ESP32.new_packet_intr_mask) {
esp_err_t ret;
do {
size_t size_read = SDIO_PAYLOAD;
ret = essl_get_packet(s_essl, rcv_buffer, SDIO_PAYLOAD, &size_read, PACKET_TIMEOUT_MS);
size_t size_read = SDIO_PACKET_SIZE;
ret = essl_get_packet(s_essl, rcv_buffer, SDIO_PACKET_SIZE, &size_read, PACKET_TIMEOUT_MS);
if (ret == ESP_ERR_NOT_FOUND) {
ESP_LOGE(TAG, "interrupt but no data can be read");
break;
} else if (ret == ESP_OK) {
ESP_LOGD(TAG, "receive data, size: %d", size_read);
struct header *head = (void *)rcv_buffer;
if (head->magic != PPP_SOF) {
ESP_LOGE(TAG, "invalid magic %x", head->magic);
break;
}
if (head->channel > NR_OF_CHANNELS) {
ESP_LOGE(TAG, "invalid channel %x", head->channel);
break;
}
if (head->size > SDIO_PAYLOAD || head->size > size_read) {
ESP_LOGE(TAG, "invalid size %x", head->size);
break;
}
ESP_LOG_BUFFER_HEXDUMP(TAG, rcv_buffer, size_read, ESP_LOG_VERBOSE);
esp_netif_receive(netif, rcv_buffer, size_read, NULL);
if (head->channel == 0) {
esp_netif_receive(netif, rcv_buffer + sizeof(struct header), head->size, NULL);
} else {
#if defined(CONFIG_EPPP_LINK_CHANNELS_SUPPORT)
struct eppp_handle *h = esp_netif_get_io_driver(netif);
if (h->channel_rx) {
h->channel_rx(netif, head->channel, rcv_buffer + sizeof(struct header), head->size);
}
#endif
}
break;
} else {
ESP_LOGE(TAG, "rx packet error: %08X", ret);

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -9,9 +9,10 @@
#include "esp_log.h"
#include "esp_netif.h"
#include "driver/sdio_slave.h"
#include "eppp_link.h"
#include "eppp_transport.h"
#include "eppp_sdio.h"
#include "esp_check.h"
#if CONFIG_EPPP_LINK_DEVICE_SDIO_SLAVE
#define BUFFER_NUM 4
#define BUFFER_SIZE SDIO_PAYLOAD
@@ -20,19 +21,18 @@ static DMA_ATTR uint8_t sdio_slave_rx_buffer[BUFFER_NUM][BUFFER_SIZE];
static DMA_ATTR uint8_t sdio_slave_tx_buffer[SDIO_PAYLOAD];
static int s_slave_request = 0;
esp_err_t eppp_sdio_slave_tx(void *h, void *buffer, size_t len)
static esp_err_t eppp_sdio_host_tx_generic(int channel, void *buffer, size_t len)
{
if (s_slave_request != REQ_INIT) {
// silently skip the Tx if the SDIO not fully initialized
return ESP_OK;
}
memcpy(sdio_slave_tx_buffer, buffer, len);
size_t send_len = SDIO_ALIGN(len);
if (send_len > len) {
// pad with SOF's if the size is not 4 bytes aligned
memset(&sdio_slave_tx_buffer[len], PPP_SOF, send_len - len);
}
struct header *head = (void *)sdio_slave_tx_buffer;
head->magic = PPP_SOF;
head->channel = channel;
head->size = len;
memcpy(sdio_slave_tx_buffer + sizeof(struct header), buffer, len);
size_t send_len = SDIO_ALIGN(len + sizeof(struct header));
ESP_LOG_BUFFER_HEXDUMP(TAG, sdio_slave_tx_buffer, send_len, ESP_LOG_VERBOSE);
esp_err_t ret = sdio_slave_transmit(sdio_slave_tx_buffer, send_len);
if (ret != ESP_OK) {
@@ -43,6 +43,18 @@ esp_err_t eppp_sdio_slave_tx(void *h, void *buffer, size_t len)
return ESP_OK;
}
esp_err_t eppp_sdio_slave_tx(void *h, void *buffer, size_t len)
{
return eppp_sdio_host_tx_generic(0, buffer, len);
}
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
esp_err_t eppp_sdio_transmit_channel(esp_netif_t *netif, int channel, void *buffer, size_t len)
{
return eppp_sdio_host_tx_generic(channel, buffer, len);
}
#endif
static esp_err_t slave_reset(void)
{
esp_err_t ret = ESP_OK;
@@ -81,7 +93,29 @@ esp_err_t eppp_sdio_slave_rx(esp_netif_t *netif)
if (ret == ESP_ERR_NOT_FINISHED || ret == ESP_OK) {
again:
ptr = sdio_slave_recv_get_buf(handle, &length);
esp_netif_receive(netif, ptr, length, NULL);
struct header *head = (void *)ptr;
if (head->magic != PPP_SOF) {
ESP_LOGE(TAG, "invalid magic %x", head->magic);
return ESP_FAIL;
}
if (head->channel > NR_OF_CHANNELS) {
ESP_LOGE(TAG, "invalid channel %x", head->channel);
return ESP_FAIL;
}
if (head->size > SDIO_PAYLOAD || head->size > length) {
ESP_LOGE(TAG, "invalid size %x", head->size);
return ESP_FAIL;
}
if (head->channel == 0) {
esp_netif_receive(netif, ptr + sizeof(struct header), head->size, NULL);
} else {
#if defined(CONFIG_EPPP_LINK_CHANNELS_SUPPORT)
struct eppp_handle *h = esp_netif_get_io_driver(netif);
if (h->channel_rx) {
h->channel_rx(netif, head->channel, ptr + sizeof(struct header), head->size);
}
#endif
}
if (sdio_slave_recv_load_buf(handle) != ESP_OK) {
ESP_LOGE(TAG, "Failed to recycle packet buffer");
return ESP_FAIL;
@@ -109,7 +143,7 @@ static void event_cb(uint8_t pos)
}
}
esp_err_t eppp_sdio_slave_init(void)
esp_err_t eppp_sdio_slave_init(struct eppp_config_sdio_s *eppp_config)
{
sdio_slave_config_t config = {
.sending_mode = SDIO_SLAVE_SEND_PACKET,
@@ -166,7 +200,7 @@ void eppp_sdio_slave_deinit(void)
{
}
esp_err_t eppp_sdio_slave_init(void)
esp_err_t eppp_sdio_slave_init(struct eppp_config_sdio_s *config)
{
return ESP_ERR_NOT_SUPPORTED;
}

View File

@@ -0,0 +1,495 @@
/*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <string.h>
#include <stdint.h>
#include <inttypes.h>
#include "sdkconfig.h"
#include "esp_log.h"
#include "esp_netif.h"
#include "esp_check.h"
#include "esp_event.h"
#include "esp_mac.h"
#include "eppp_link.h"
#include "eppp_transport.h"
#include "eppp_transport_spi.h"
#include "driver/spi_master.h"
#include "driver/spi_slave.h"
#include "driver/gpio.h"
#include "esp_timer.h"
#include "esp_rom_crc.h"
#define TAG "eppp_spi"
#define MAX_PAYLOAD 1500
#define MIN_TRIGGER_US 20
#define PPP_SOF 0x7E
#define SPI_HEADER_MAGIC PPP_SOF
#define SPI_ALIGN(size) (((size) + 3U) & ~(3U))
#define TRANSFER_SIZE SPI_ALIGN((MAX_PAYLOAD + 6))
#define NEXT_TRANSACTION_SIZE(a,b) (((a)>(b))?(a):(b)) /* next transaction: whichever is bigger */
struct packet {
size_t len;
uint8_t *data;
int channel;
};
struct header {
uint8_t magic;
uint8_t channel;
uint16_t size;
uint16_t next_size;
uint16_t check;
} __attribute__((packed));
enum blocked_status {
NONE,
MASTER_BLOCKED,
MASTER_WANTS_READ,
SLAVE_BLOCKED,
SLAVE_WANTS_WRITE,
};
struct eppp_spi {
struct eppp_handle parent;
bool is_master;
QueueHandle_t out_queue;
QueueHandle_t ready_semaphore;
spi_device_handle_t spi_device;
spi_host_device_t spi_host;
int gpio_intr;
uint16_t next_size;
uint16_t transaction_size;
struct packet outbound;
enum blocked_status blocked;
uint32_t slave_last_edge;
esp_timer_handle_t timer;
};
static esp_err_t transmit_generic(struct eppp_spi *handle, int channel, void *buffer, size_t len)
{
struct packet buf = { .channel = channel };
uint8_t *current_buffer = buffer;
size_t remaining = len;
do { // TODO(IDF-9194): Refactor this loop to allocate only once and perform
// fragmentation after receiving from the queue (applicable only if MTU > MAX_PAYLOAD)
size_t batch = remaining > MAX_PAYLOAD ? MAX_PAYLOAD : remaining;
buf.data = malloc(batch);
if (buf.data == NULL) {
ESP_LOGE(TAG, "Failed to allocate packet");
return ESP_ERR_NO_MEM;
}
buf.len = batch;
remaining -= batch;
memcpy(buf.data, current_buffer, batch);
current_buffer += batch;
BaseType_t ret = xQueueSend(handle->out_queue, &buf, 0);
if (ret != pdTRUE) {
ESP_LOGE(TAG, "Failed to queue packet to slave!");
return ESP_ERR_NO_MEM;
}
} while (remaining > 0);
if (!handle->is_master && handle->blocked == SLAVE_BLOCKED) {
uint32_t now = esp_timer_get_time();
uint32_t diff = now - handle->slave_last_edge;
if (diff < MIN_TRIGGER_US) {
esp_rom_delay_us(MIN_TRIGGER_US - diff);
}
gpio_set_level(handle->gpio_intr, 0);
}
return ESP_OK;
}
static esp_err_t transmit(void *h, void *buffer, size_t len)
{
struct eppp_handle *handle = h;
struct eppp_spi *spi_handle = __containerof(handle, struct eppp_spi, parent);;
return transmit_generic(spi_handle, 0, buffer, len);
}
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
static esp_err_t transmit_channel(esp_netif_t *netif, int channel, void *buffer, size_t len)
{
struct eppp_handle *handle = esp_netif_get_io_driver(netif);
struct eppp_spi *spi_handle = __containerof(handle, struct eppp_spi, parent);;
return transmit_generic(spi_handle, channel, buffer, len);
}
#endif
static void IRAM_ATTR timer_callback(void *arg)
{
struct eppp_spi *h = arg;
if (h->blocked == SLAVE_WANTS_WRITE) {
gpio_set_level(h->gpio_intr, 0);
}
}
static void IRAM_ATTR gpio_isr_handler(void *arg)
{
static uint32_t s_last_time;
uint32_t now = esp_timer_get_time();
uint32_t diff = now - s_last_time;
if (diff < MIN_TRIGGER_US) { // debounce
return;
}
s_last_time = now;
struct eppp_spi *h = arg;
BaseType_t yield = false;
// Positive edge means SPI slave prepared the data
if (gpio_get_level(h->gpio_intr) == 1) {
xSemaphoreGiveFromISR(h->ready_semaphore, &yield);
if (yield) {
portYIELD_FROM_ISR();
}
return;
}
// Negative edge (when master blocked) means that slave wants to transmit
if (h->blocked == MASTER_BLOCKED) {
struct packet buf = { .data = NULL, .len = -1 };
xQueueSendFromISR(h->out_queue, &buf, &yield);
if (yield) {
portYIELD_FROM_ISR();
}
}
}
static esp_err_t deinit_master(struct eppp_spi *h)
{
ESP_RETURN_ON_ERROR(spi_bus_remove_device(h->spi_device), TAG, "Failed to remove SPI bus");
ESP_RETURN_ON_ERROR(spi_bus_free(h->spi_host), TAG, "Failed to free SPI bus");
return ESP_OK;
}
static esp_err_t init_master(struct eppp_config_spi_s *config, struct eppp_spi *h)
{
esp_err_t ret = ESP_OK;
h->spi_host = config->host;
h->gpio_intr = config->intr;
spi_bus_config_t bus_cfg = {};
bus_cfg.mosi_io_num = config->mosi;
bus_cfg.miso_io_num = config->miso;
bus_cfg.sclk_io_num = config->sclk;
bus_cfg.quadwp_io_num = -1;
bus_cfg.quadhd_io_num = -1;
bus_cfg.max_transfer_sz = TRANSFER_SIZE;
bus_cfg.flags = 0;
bus_cfg.intr_flags = 0;
// TODO(IDF-13351): Init and deinit SPI bus separately (per Kconfig?)
ESP_RETURN_ON_ERROR(spi_bus_initialize(config->host, &bus_cfg, SPI_DMA_CH_AUTO), TAG, "Failed to init SPI bus");
spi_device_interface_config_t dev_cfg = {};
dev_cfg.clock_speed_hz = config->freq;
dev_cfg.mode = 0;
dev_cfg.spics_io_num = config->cs;
dev_cfg.cs_ena_pretrans = config->cs_ena_pretrans;
dev_cfg.cs_ena_posttrans = config->cs_ena_posttrans;
dev_cfg.duty_cycle_pos = 128;
dev_cfg.input_delay_ns = config->input_delay_ns;
dev_cfg.pre_cb = NULL;
dev_cfg.post_cb = NULL;
dev_cfg.queue_size = 3;
ESP_GOTO_ON_ERROR(spi_bus_add_device(config->host, &dev_cfg, &h->spi_device), err, TAG, "Failed to add SPI device");
//GPIO config for the handshake line.
gpio_config_t io_conf = {
.intr_type = GPIO_INTR_ANYEDGE,
.mode = GPIO_MODE_INPUT,
.pull_up_en = 1,
.pin_bit_mask = BIT64(config->intr),
};
ESP_GOTO_ON_ERROR(gpio_config(&io_conf), err_dev, TAG, "Failed to config interrupt GPIO");
ret = gpio_install_isr_service(0);
ESP_GOTO_ON_FALSE(ret == ESP_OK || ret == ESP_ERR_INVALID_STATE /* In case the GPIO ISR already installed */,
ret, err_dev, TAG, "Failed to install GPIO ISR");
ESP_GOTO_ON_ERROR(gpio_set_intr_type(config->intr, GPIO_INTR_ANYEDGE), err_dev, TAG, "Failed to set ISR type");
ESP_GOTO_ON_ERROR(gpio_isr_handler_add(config->intr, gpio_isr_handler, h), err_dev, TAG, "Failed to add ISR handler");
return ESP_OK;
err_dev:
spi_bus_remove_device(h->spi_device);
err:
spi_bus_free(config->host);
return ret;
}
static void post_setup(spi_slave_transaction_t *trans)
{
struct eppp_spi *h = trans->user;
h->slave_last_edge = esp_timer_get_time();
gpio_set_level(h->gpio_intr, 1);
if (h->transaction_size == 0) { // If no transaction planned:
if (h->outbound.len == 0) { // we're blocked if we don't have any data
h->blocked = SLAVE_BLOCKED;
} else {
h->blocked = SLAVE_WANTS_WRITE; // we notify the master that we want to write
esp_timer_start_once(h->timer, MIN_TRIGGER_US);
}
}
}
static void post_transaction(spi_slave_transaction_t *transaction)
{
struct eppp_spi *h = transaction->user;
h->blocked = NONE;
gpio_set_level(h->gpio_intr, 0);
}
static esp_err_t deinit_slave(struct eppp_spi *h)
{
ESP_RETURN_ON_ERROR(spi_slave_free(h->spi_host), TAG, "Failed to free SPI slave host");
ESP_RETURN_ON_ERROR(spi_bus_remove_device(h->spi_device), TAG, "Failed to remove SPI device");
ESP_RETURN_ON_ERROR(spi_bus_free(h->spi_host), TAG, "Failed to free SPI bus");
return ESP_OK;
}
static esp_err_t init_slave(struct eppp_config_spi_s *config, struct eppp_spi *h)
{
h->spi_host = config->host;
h->gpio_intr = config->intr;
spi_bus_config_t bus_cfg = {};
bus_cfg.mosi_io_num = config->mosi;
bus_cfg.miso_io_num = config->miso;
bus_cfg.sclk_io_num = config->sclk;
bus_cfg.quadwp_io_num = -1;
bus_cfg.quadhd_io_num = -1;
bus_cfg.flags = 0;
bus_cfg.intr_flags = 0;
//Configuration for the SPI slave interface
spi_slave_interface_config_t slvcfg = {
.mode = 0,
.spics_io_num = config->cs,
.queue_size = 3,
.flags = 0,
.post_setup_cb = post_setup,
.post_trans_cb = post_transaction,
};
//Configuration for the handshake line
gpio_config_t io_conf = {
.intr_type = GPIO_INTR_DISABLE,
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = BIT64(config->intr),
};
gpio_config(&io_conf);
gpio_set_pull_mode(config->mosi, GPIO_PULLUP_ONLY);
gpio_set_pull_mode(config->sclk, GPIO_PULLUP_ONLY);
gpio_set_pull_mode(config->cs, GPIO_PULLUP_ONLY);
//Initialize SPI slave interface
if (spi_slave_initialize(config->host, &bus_cfg, &slvcfg, SPI_DMA_CH_AUTO) != ESP_OK) {
return ESP_FAIL;
}
return ESP_OK;
}
typedef esp_err_t (*perform_transaction_t)(struct eppp_spi *h, size_t len, const void *tx_buffer, void *rx_buffer);
static esp_err_t perform_transaction_master(struct eppp_spi *h, size_t len, const void *tx_buffer, void *rx_buffer)
{
spi_transaction_t t = {};
t.length = len * 8;
t.tx_buffer = tx_buffer;
t.rx_buffer = rx_buffer;
return spi_device_transmit(h->spi_device, &t);
}
static esp_err_t perform_transaction_slave(struct eppp_spi *h, size_t len, const void *tx_buffer, void *rx_buffer)
{
spi_slave_transaction_t t = {};
t.user = h;
t.length = len * 8;
t.tx_buffer = tx_buffer;
t.rx_buffer = rx_buffer;
return spi_slave_transmit(h->spi_host, &t, portMAX_DELAY);
}
esp_err_t eppp_perform(esp_netif_t *netif)
{
static WORD_ALIGNED_ATTR uint8_t out_buf[TRANSFER_SIZE] = {};
static WORD_ALIGNED_ATTR uint8_t in_buf[TRANSFER_SIZE] = {};
struct eppp_handle *handle = esp_netif_get_io_driver(netif);
struct eppp_spi *h = __containerof(handle, struct eppp_spi, parent);
// Perform transaction for master and slave
const perform_transaction_t perform_transaction = h->is_master ? perform_transaction_master : perform_transaction_slave;
if (h->parent.stop) {
return ESP_ERR_TIMEOUT;
}
BaseType_t tx_queue_stat;
bool allow_test_tx = false;
uint16_t next_tx_size = 0;
if (h->is_master) {
// SPI MASTER only code
if (xSemaphoreTake(h->ready_semaphore, pdMS_TO_TICKS(1000)) != pdTRUE) {
// slave might not be ready, but maybe we just missed an interrupt
allow_test_tx = true;
}
if (h->outbound.len == 0 && h->transaction_size == 0 && h->blocked == NONE) {
h->blocked = MASTER_BLOCKED;
xQueueReceive(h->out_queue, &h->outbound, portMAX_DELAY);
h->blocked = NONE;
if (h->outbound.len == -1) {
h->outbound.len = 0;
h->blocked = MASTER_WANTS_READ;
}
} else if (h->blocked == MASTER_WANTS_READ) {
h->blocked = NONE;
}
}
struct header *head = (void *)out_buf;
if (h->outbound.len <= h->transaction_size && allow_test_tx == false) {
// sending outbound
head->size = h->outbound.len;
head->channel = h->outbound.channel;
if (h->outbound.len > 0) {
memcpy(out_buf + sizeof(struct header), h->outbound.data, h->outbound.len);
free(h->outbound.data);
ESP_LOG_BUFFER_HEXDUMP(TAG, out_buf + sizeof(struct header), head->size, ESP_LOG_VERBOSE);
h->outbound.data = NULL;
h->outbound.len = 0;
}
do {
tx_queue_stat = xQueueReceive(h->out_queue, &h->outbound, 0);
} while (tx_queue_stat == pdTRUE && h->outbound.len == -1);
if (h->outbound.len == -1) { // used as a signal only, no actual data
h->outbound.len = 0;
}
} else {
// outbound is bigger, need to transmit in another transaction (keep this empty)
head->size = 0;
head->channel = 0;
}
next_tx_size = head->next_size = h->outbound.len;
head->magic = SPI_HEADER_MAGIC;
head->check = esp_rom_crc16_le(0, out_buf, sizeof(struct header) - sizeof(uint16_t));
esp_err_t ret = perform_transaction(h, sizeof(struct header) + h->transaction_size, out_buf, in_buf);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "spi_device_transmit failed");
h->transaction_size = 0; // need to start with HEADER only transaction
return ESP_FAIL;
}
head = (void *)in_buf;
uint16_t check = esp_rom_crc16_le(0, in_buf, sizeof(struct header) - sizeof(uint16_t));
if (check != head->check || head->magic != SPI_HEADER_MAGIC || head->channel > NR_OF_CHANNELS) {
h->transaction_size = 0; // need to start with HEADER only transaction
if (allow_test_tx) {
return ESP_OK;
}
ESP_LOGE(TAG, "Wrong checksum, magic, or channel: %x %x %x", check, head->magic, head->channel);
return ESP_FAIL;
}
if (head->size > 0) {
ESP_LOG_BUFFER_HEXDUMP(TAG, in_buf + sizeof(struct header), head->size, ESP_LOG_VERBOSE);
if (head->channel == 0) {
esp_netif_receive(netif, in_buf + sizeof(struct header), head->size, NULL);
} else {
#if defined(CONFIG_EPPP_LINK_CHANNELS_SUPPORT)
if (h->parent.channel_rx) {
h->parent.channel_rx(netif, head->channel, in_buf + sizeof(struct header), head->size);
}
#endif
}
}
h->transaction_size = NEXT_TRANSACTION_SIZE(next_tx_size, head->next_size);
return ESP_OK;
}
static esp_err_t init_driver(struct eppp_spi *h, struct eppp_config_spi_s *config)
{
if (config->is_master) {
return init_master(config, h);
}
return init_slave(config, h);
}
static esp_err_t post_attach(esp_netif_t *esp_netif, void *args)
{
eppp_transport_handle_t h = (eppp_transport_handle_t)args;
ESP_RETURN_ON_FALSE(h, ESP_ERR_INVALID_ARG, TAG, "Transport handle cannot be null");
h->base.netif = esp_netif;
esp_netif_driver_ifconfig_t driver_ifconfig = {
.handle = h,
.transmit = transmit,
};
ESP_RETURN_ON_ERROR(esp_netif_set_driver_config(esp_netif, &driver_ifconfig), TAG, "Failed to set driver config");
ESP_LOGI(TAG, "EPPP SPI transport attached to EPPP netif %s", esp_netif_get_desc(esp_netif));
return ESP_OK;
}
eppp_transport_handle_t eppp_spi_init(struct eppp_config_spi_s *config)
{
__attribute__((unused)) esp_err_t ret = ESP_OK;
ESP_RETURN_ON_FALSE(config, NULL, TAG, "Config cannot be null");
struct eppp_spi *h = calloc(1, sizeof(struct eppp_spi));
ESP_RETURN_ON_FALSE(h, NULL, TAG, "Failed to allocate eppp_handle");
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
h->parent.channel_tx = transmit_channel;
#endif
h->is_master = config->is_master;
h->parent.base.post_attach = post_attach;
h->out_queue = xQueueCreate(CONFIG_EPPP_LINK_PACKET_QUEUE_SIZE, sizeof(struct packet));
ESP_GOTO_ON_FALSE(h->out_queue, ESP_FAIL, err, TAG, "Failed to create the packet queue");
if (h->is_master) {
ESP_GOTO_ON_FALSE(h->ready_semaphore = xSemaphoreCreateBinary(), ESP_FAIL, err, TAG, "Failed to create the semaphore");
}
h->transaction_size = 0;
h->outbound.data = NULL;
h->outbound.len = 0;
if (!h->is_master) {
esp_timer_create_args_t args = {
.callback = &timer_callback,
.arg = h,
.name = "spi_slave_tmr"
};
ESP_GOTO_ON_ERROR(esp_timer_create(&args, &h->timer), err, TAG, "Failed to create timer");
}
ESP_GOTO_ON_ERROR(init_driver(h, config), err, TAG, "Failed to init SPI driver");
return &h->parent;
err:
if (h->out_queue) {
vQueueDelete(h->out_queue);
}
if (h->ready_semaphore) {
vSemaphoreDelete(h->ready_semaphore);
}
free(h);
return NULL;
}
void eppp_spi_deinit(eppp_transport_handle_t handle)
{
struct eppp_spi *h = __containerof(handle, struct eppp_spi, parent);;
if (h->is_master) {
deinit_master(h);
} else {
deinit_slave(h);
}
struct packet buf = { };
while (xQueueReceive(h->out_queue, &buf, 0) == pdTRUE) {
if (buf.len > 0) {
free(buf.data);
}
}
vQueueDelete(h->out_queue);
if (h->is_master) {
vSemaphoreDelete(h->ready_semaphore);
}
free(h);
}

View File

@@ -0,0 +1,29 @@
/*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "esp_netif_types.h"
#include "sdkconfig.h"
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
#define NR_OF_CHANNELS CONFIG_EPPP_LINK_NR_OF_CHANNELS
#else
#define NR_OF_CHANNELS 1
#endif
struct eppp_handle {
esp_netif_driver_base_t base;
eppp_type_t role;
bool stop;
bool exited;
bool netif_stop;
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
eppp_channel_fn_t channel_tx;
eppp_channel_fn_t channel_rx;
void* context;
#endif
};
esp_err_t eppp_check_connection(esp_netif_t *netif);

View File

@@ -0,0 +1,283 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <string.h>
#include <stdint.h>
#include "sdkconfig.h"
#include "esp_log.h"
#include "esp_netif.h"
#include "esp_check.h"
#include "esp_event.h"
#include "eppp_link.h"
#include "eppp_transport.h"
#include "driver/uart.h"
#define TAG "eppp_uart"
struct eppp_uart {
struct eppp_handle parent;
QueueHandle_t uart_event_queue;
uart_port_t uart_port;
};
#define MAX_PAYLOAD (1500)
#define HEADER_MAGIC (0x7E)
#define HEADER_SIZE (4)
#define MAX_PACKET_SIZE (MAX_PAYLOAD + HEADER_SIZE)
/* Maximum size of a packet sent over UART, including header and payload */
#define UART_BUF_SIZE (MAX_PACKET_SIZE)
struct header {
uint8_t magic;
uint8_t channel;
uint8_t check;
uint16_t size;
} __attribute__((packed));
static esp_err_t transmit_generic(struct eppp_uart *handle, int channel, void *buffer, size_t len)
{
#ifndef CONFIG_EPPP_LINK_USES_PPP
static uint8_t out_buf[MAX_PACKET_SIZE] = {};
struct header *head = (void *)out_buf;
head->magic = HEADER_MAGIC;
head->check = 0;
head->channel = channel;
head->size = len;
head->check = (0xFF & len) ^ (len >> 8);
memcpy(out_buf + sizeof(struct header), buffer, len);
ESP_LOG_BUFFER_HEXDUMP("ppp_uart_send", out_buf, len + sizeof(struct header), ESP_LOG_DEBUG);
uart_write_bytes(handle->uart_port, out_buf, len + sizeof(struct header));
#else
ESP_LOG_BUFFER_HEXDUMP("ppp_uart_send", buffer, len, ESP_LOG_DEBUG);
uart_write_bytes(handle->uart_port, buffer, len);
#endif
return ESP_OK;
}
static esp_err_t transmit(void *h, void *buffer, size_t len)
{
struct eppp_handle *handle = h;
struct eppp_uart *uart_handle = __containerof(handle, struct eppp_uart, parent);
return transmit_generic(uart_handle, 0, buffer, len);
}
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
static esp_err_t transmit_channel(esp_netif_t *netif, int channel, void *buffer, size_t len)
{
struct eppp_handle *handle = esp_netif_get_io_driver(netif);
struct eppp_uart *uart_handle = __containerof(handle, struct eppp_uart, parent);
return transmit_generic(uart_handle, channel, buffer, len);
}
#endif
static esp_err_t init_uart(struct eppp_uart *h, struct eppp_config_uart_s *config)
{
h->uart_port = config->port;
uart_config_t uart_config = {};
uart_config.baud_rate = config->baud;
uart_config.data_bits = UART_DATA_8_BITS;
uart_config.parity = UART_PARITY_DISABLE;
uart_config.stop_bits = UART_STOP_BITS_1;
uart_config.flow_ctrl = config->flow_control;
uart_config.source_clk = UART_SCLK_DEFAULT;
ESP_RETURN_ON_ERROR(uart_driver_install(h->uart_port, config->rx_buffer_size, 0, config->queue_size, &h->uart_event_queue, 0), TAG, "Failed to install UART");
ESP_RETURN_ON_ERROR(uart_param_config(h->uart_port, &uart_config), TAG, "Failed to set params");
ESP_RETURN_ON_ERROR(uart_set_pin(h->uart_port, config->tx_io, config->rx_io, config->rts_io, config->cts_io), TAG, "Failed to set UART pins");
ESP_RETURN_ON_ERROR(uart_set_rx_timeout(h->uart_port, 1), TAG, "Failed to set UART Rx timeout");
return ESP_OK;
}
static void deinit_uart(struct eppp_uart *h)
{
uart_driver_delete(h->uart_port);
}
#ifndef CONFIG_EPPP_LINK_USES_PPP
/**
* @brief Process incoming UART data and extract packets
*/
static void process_packet(esp_netif_t *netif, uart_port_t uart_port, size_t available_data)
{
static uint8_t in_buf[2 * UART_BUF_SIZE] = {};
static size_t buf_start = 0;
static size_t buf_end = 0;
struct header *head;
// Read data directly into our buffer
size_t available_space = sizeof(in_buf) - buf_end;
size_t read_size = (available_data < available_space) ? available_data : available_space;
if (read_size > 0) {
size_t len = uart_read_bytes(uart_port, in_buf + buf_end, read_size, 0);
ESP_LOG_BUFFER_HEXDUMP("ppp_uart_recv", in_buf + buf_end, len, ESP_LOG_DEBUG);
if (buf_end + len <= sizeof(in_buf)) {
buf_end += len;
} else {
ESP_LOGW(TAG, "Buffer overflow, discarding data");
buf_start = buf_end = 0;
return;
}
}
// Process while we have enough data for at least a header
while ((buf_end - buf_start) >= sizeof(struct header)) {
head = (void *)(in_buf + buf_start);
if (head->magic != HEADER_MAGIC) {
goto recover;
}
uint8_t calculated_check = (head->size & 0xFF) ^ (head->size >> 8);
if (head->check != calculated_check) {
ESP_LOGW(TAG, "Checksum mismatch: expected 0x%04x, got 0x%04x", calculated_check, head->check);
goto recover;
}
// Check if we have the complete packet
uint16_t payload_size = head->size;
int channel = head->channel;
size_t total_packet_size = sizeof(struct header) + payload_size;
if (payload_size > MAX_PAYLOAD) {
ESP_LOGW(TAG, "Invalid payload size: %d", payload_size);
goto recover;
}
// If we don't have the complete packet yet, wait for more data
if ((buf_end - buf_start) < total_packet_size) {
ESP_LOGD(TAG, "Incomplete packet: got %d bytes, need %d bytes", (buf_end - buf_start), total_packet_size);
break;
}
// Got a complete packet, pass it to network
if (channel == 0) {
esp_netif_receive(netif, in_buf + buf_start + sizeof(struct header), payload_size, NULL);
} else {
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
struct eppp_handle *handle = esp_netif_get_io_driver(netif);
struct eppp_uart *h = __containerof(handle, struct eppp_uart, parent);
if (h->parent.channel_rx) {
h->parent.channel_rx(netif, channel, in_buf + buf_start + sizeof(struct header), payload_size);
}
#endif
}
// Advance start pointer past this packet
buf_start += total_packet_size;
// compact if we don't have enough space for 1x UART_BUF_SIZE
if (buf_start > (sizeof(in_buf) / 2) || (sizeof(in_buf) - buf_end) < UART_BUF_SIZE) {
if (buf_start < buf_end) {
size_t remaining_data = buf_end - buf_start;
memmove(in_buf, in_buf + buf_start, remaining_data);
buf_end = remaining_data;
} else {
buf_end = 0;
}
buf_start = 0;
}
continue;
recover:
// Search for next HEADER_MAGIC occurrence
uint8_t *next_magic = memchr(in_buf + buf_start + 1, HEADER_MAGIC, buf_end - buf_start - 1);
if (next_magic) {
// Found next potential header, advance start to that position
buf_start = next_magic - in_buf;
// Check if we need to compact after recovery too
if (buf_start > (sizeof(in_buf) / 2) || (sizeof(in_buf) - buf_end) < UART_BUF_SIZE) {
if (buf_start < buf_end) {
size_t remaining_data = buf_end - buf_start;
memmove(in_buf, in_buf + buf_start, remaining_data);
buf_end = remaining_data;
} else {
buf_end = 0;
}
buf_start = 0;
}
} else {
// No more HEADER_MAGIC found, discard all data
buf_start = buf_end = 0;
}
}
}
#endif
esp_err_t eppp_perform(esp_netif_t *netif)
{
struct eppp_handle *handle = esp_netif_get_io_driver(netif);
struct eppp_uart *h = __containerof(handle, struct eppp_uart, parent);
uart_event_t event = {};
if (h->parent.stop) {
return ESP_ERR_TIMEOUT;
}
if (xQueueReceive(h->uart_event_queue, &event, pdMS_TO_TICKS(100)) != pdTRUE) {
return ESP_OK;
}
if (event.type == UART_DATA) {
size_t len;
uart_get_buffered_data_len(h->uart_port, &len);
if (len) {
#ifdef CONFIG_EPPP_LINK_USES_PPP
static uint8_t buffer[UART_BUF_SIZE] = {};
len = uart_read_bytes(h->uart_port, buffer, UART_BUF_SIZE, 0);
ESP_LOG_BUFFER_HEXDUMP("ppp_uart_recv", buffer, len, ESP_LOG_DEBUG);
esp_netif_receive(netif, buffer, len, NULL);
#else
// Read directly in process_packet to save one buffer
process_packet(netif, h->uart_port, len);
#endif
}
} else {
ESP_LOGW(TAG, "Received UART event: %d", event.type);
}
return ESP_OK;
}
static esp_err_t post_attach(esp_netif_t *esp_netif, void *args)
{
eppp_transport_handle_t h = (eppp_transport_handle_t)args;
ESP_RETURN_ON_FALSE(h, ESP_ERR_INVALID_ARG, TAG, "Transport handle cannot be null");
h->base.netif = esp_netif;
esp_netif_driver_ifconfig_t driver_ifconfig = {
.handle = h,
.transmit = transmit,
};
ESP_RETURN_ON_ERROR(esp_netif_set_driver_config(esp_netif, &driver_ifconfig), TAG, "Failed to set driver config");
ESP_LOGI(TAG, "EPPP UART transport attached to EPPP netif %s", esp_netif_get_desc(esp_netif));
return ESP_OK;
}
eppp_transport_handle_t eppp_uart_init(struct eppp_config_uart_s *config)
{
__attribute__((unused)) esp_err_t ret = ESP_OK;
ESP_RETURN_ON_FALSE(config, NULL, TAG, "Config cannot be null");
struct eppp_uart *h = calloc(1, sizeof(struct eppp_uart));
ESP_RETURN_ON_FALSE(h, NULL, TAG, "Failed to allocate eppp_handle");
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
h->parent.channel_tx = transmit_channel;
#endif
h->parent.base.post_attach = post_attach;
ESP_GOTO_ON_ERROR(init_uart(h, config), err, TAG, "Failed to init UART");
return &h->parent;
err:
free(h);
return NULL;
}
void eppp_uart_deinit(eppp_transport_handle_t handle)
{
struct eppp_uart *h = __containerof(handle, struct eppp_uart, parent);
deinit_uart(h);
free(h);
}

View File

@@ -1,2 +1,6 @@
if(CONFIG_EXAMPLE_WIFI_OVER_EPPP_CHANNEL)
set(wifi_over_channels channel_wifi_station.c)
endif()
idf_component_register(SRCS app_main.c register_iperf.c
INCLUDE_DIRS ".")
${wifi_over_channels}
INCLUDE_DIRS ".")

View File

@@ -26,10 +26,66 @@ menu "Example Configuration"
help
Init and run iperf console.
config EXAMPLE_SPI_HOST
int "SPI Host"
depends on EPPP_LINK_DEVICE_SPI
default 1
range 0 2
help
SPI host to use (SPI1_HOST=0, SPI2_HOST=1, SPI3_HOST=2).
config EXAMPLE_SPI_MOSI_PIN
int "MOSI Pin Number"
depends on EPPP_LINK_DEVICE_SPI
default 23
range 0 39
help
Pin number of SPI MOSI.
config EXAMPLE_SPI_MISO_PIN
int "MISO Pin Number"
depends on EPPP_LINK_DEVICE_SPI
default 19
range 0 39
help
Pin number of SPI MISO.
config EXAMPLE_SPI_SCLK_PIN
int "SCLK Pin Number"
depends on EPPP_LINK_DEVICE_SPI
default 18
range 0 39
help
Pin number of SPI SCLK.
config EXAMPLE_SPI_CS_PIN
int "CS Pin Number"
depends on EPPP_LINK_DEVICE_SPI
default 5
range 0 39
help
Pin number of SPI CS.
config EXAMPLE_SPI_INTR_PIN
int "Interrupt Pin Number"
depends on EPPP_LINK_DEVICE_SPI
default 17
range 0 39
help
Pin number of SPI interrupt.
config EXAMPLE_SPI_FREQUENCY
int "SPI Frequency (Hz)"
depends on EPPP_LINK_DEVICE_SPI
default 4000000
range 100000 80000000
help
SPI frequency in Hz.
config EXAMPLE_UART_TX_PIN
int "TXD Pin Number"
depends on EPPP_LINK_DEVICE_UART
default 10
default 17
range 0 31
help
Pin number of UART TX.
@@ -37,7 +93,7 @@ menu "Example Configuration"
config EXAMPLE_UART_RX_PIN
int "RXD Pin Number"
depends on EPPP_LINK_DEVICE_UART
default 11
default 18
range 0 31
help
Pin number of UART RX.
@@ -45,9 +101,19 @@ menu "Example Configuration"
config EXAMPLE_UART_BAUDRATE
int "Baudrate"
depends on EPPP_LINK_DEVICE_UART
default 2000000
default 921600
range 0 4000000
help
Baudrate used by the PPP over UART
config EXAMPLE_WIFI_OVER_EPPP_CHANNEL
bool "Use WiFi over EPPP channel"
default n
depends on EPPP_LINK_CHANNELS_SUPPORT && ESP_WIFI_REMOTE_ENABLED
help
Enable this option to use WiFi over EPPP channel.
If this option is enabled, the example will only start the Wi-Fi driver,
but the Wi-Fi netif will reside on client's end and will channel
the Rx and Tx data via EPPP channels.
endmenu

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -14,6 +14,7 @@
#include "esp_netif.h"
#include "eppp_link.h"
#include "esp_log.h"
#include "esp_check.h"
#include "mqtt_client.h"
#include "console_ping.h"
@@ -88,6 +89,7 @@ static void mqtt_app_start(void)
}
#endif // MQTT
void station_over_eppp_channel(void *arg);
void app_main(void)
{
@@ -104,13 +106,24 @@ void app_main(void)
eppp_config_t config = EPPP_DEFAULT_CLIENT_CONFIG();
#if CONFIG_EPPP_LINK_DEVICE_SPI
config.transport = EPPP_TRANSPORT_SPI;
config.spi.is_master = true;
config.spi.host = CONFIG_EXAMPLE_SPI_HOST;
config.spi.mosi = CONFIG_EXAMPLE_SPI_MOSI_PIN;
config.spi.miso = CONFIG_EXAMPLE_SPI_MISO_PIN;
config.spi.sclk = CONFIG_EXAMPLE_SPI_SCLK_PIN;
config.spi.cs = CONFIG_EXAMPLE_SPI_CS_PIN;
config.spi.intr = CONFIG_EXAMPLE_SPI_INTR_PIN;
config.spi.freq = CONFIG_EXAMPLE_SPI_FREQUENCY;
#elif CONFIG_EPPP_LINK_DEVICE_UART
config.transport = EPPP_TRANSPORT_UART;
config.uart.tx_io = CONFIG_EXAMPLE_UART_TX_PIN;
config.uart.rx_io = CONFIG_EXAMPLE_UART_RX_PIN;
config.uart.baud = CONFIG_EXAMPLE_UART_BAUDRATE;
#elif CONFIG_EPPP_LINK_DEVICE_ETH
config.transport = EPPP_TRANSPORT_ETHERNET;
#else
config.transport = EPPP_TRANSPORT_SDIO;
config.sdio.is_host = true;
#endif
esp_netif_t *eppp_netif = eppp_connect(&config);
if (eppp_netif == NULL) {
@@ -145,6 +158,9 @@ void app_main(void)
// start console REPL
ESP_ERROR_CHECK(console_cmd_start());
#ifdef CONFIG_EXAMPLE_WIFI_OVER_EPPP_CHANNEL
station_over_eppp_channel(eppp_netif);
#endif
#if CONFIG_EXAMPLE_MQTT
mqtt_app_start();
#endif

View File

@@ -0,0 +1,185 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include "esp_system.h"
#include "esp_event.h"
#include "esp_netif.h"
#include "eppp_link.h"
#include "esp_log.h"
#include "esp_check.h"
#include "esp_wifi_remote.h"
#define CHAT_CHANNEL 1
#define WIFI_CHANNEL 2
typedef enum {
UNKNOWN,
HELLO,
START,
ERROR,
} state_t;
typedef struct context {
eppp_channel_fn_t transmit;
EventGroupHandle_t flags;
state_t state;
esp_netif_t *eppp;
} context_t;
#define HELLO_BIT BIT0
#define START_BIT BIT1
#define CONNECT_BIT BIT2
#define SERVER_UP_BIT BIT3
#define ALL_BITS (HELLO_BIT | START_BIT | CONNECT_BIT | SERVER_UP_BIT)
static uint8_t s_wifi_mac_addr[6] = { 0 };
static const char *TAG = "eppp_host_example_with_channels";
esp_netif_t* esp_wifi_remote_create_default_sta(void);
static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
{
ESP_LOGI(TAG, "IP event_handler: event_base=%s event_id=%d", event_base, event_id);
if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data;
ESP_LOGI(TAG, "Got IP:" IPSTR, IP2STR(&event->ip_info.ip));
}
}
esp_err_t esp_wifi_remote_get_mac(wifi_interface_t ifx, uint8_t mac[6])
{
if (ifx != WIFI_IF_STA) {
return ESP_ERR_INVALID_STATE;
}
for (int i = 0; i < sizeof(s_wifi_mac_addr); i++) {
if (s_wifi_mac_addr[i] == 0) {
return ESP_ERR_INVALID_STATE;
}
}
memcpy(mac, s_wifi_mac_addr, sizeof(s_wifi_mac_addr));
return ESP_OK;
}
static esp_err_t eppp_receive(esp_netif_t *netif, int nr, void *buffer, size_t len)
{
context_t *ctx = eppp_get_context(netif);
if (nr == CHAT_CHANNEL) {
ESP_LOGI(TAG, "Received channel=%d len=%d %.*s", nr, (int)len, (int)len, (char *)buffer);
const char hello[] = "Hello client";
const char mac[] = "MAC: ";
const char connected[] = "Connected";
const char server_up[] = "Server up";
size_t mac_len = 5 /* MAC: */ + 6 * 2 /* 6 bytes per char */ + 5 /* : */ + 1 /* \0 */;
if (len == sizeof(server_up) && memcmp(buffer, server_up, len) == 0) {
if (ctx->state == UNKNOWN) {
ESP_LOGI(TAG, "Server is up");
ctx->state = HELLO;
} else {
ESP_LOGE(TAG, "Received server up in unexpected state %d", ctx->state);
ctx->state = ERROR;
}
xEventGroupSetBits(ctx->flags, SERVER_UP_BIT);
} else if (len == sizeof(hello) && memcmp(buffer, hello, len) == 0) {
if (ctx->state == HELLO) {
xEventGroupSetBits(ctx->flags, HELLO_BIT);
} else {
ESP_LOGE(TAG, "Received hello in unexpected state %d", ctx->state);
ctx->state = ERROR;
}
} else if (len == mac_len && memcmp(buffer, mac, 5) == 0) {
if (ctx->state == HELLO) {
uint8_t mac_addr[6];
sscanf((char *)buffer + 5, "%2" PRIx8 ":%2" PRIx8 ":%2" PRIx8 ":%2" PRIx8 ":%2" PRIx8 ":%2" PRIx8,
&mac_addr[0], &mac_addr[1], &mac_addr[2], &mac_addr[3], &mac_addr[4], &mac_addr[5]);
ESP_LOGI(TAG, "Parsed MAC: %02x:%02x:%02x:%02x:%02x:%02x\n", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
memcpy(s_wifi_mac_addr, mac_addr, sizeof(s_wifi_mac_addr));
xEventGroupSetBits(ctx->flags, START_BIT);
} else {
ESP_LOGE(TAG, "Received MAC in unexpected state %d", ctx->state);
ctx->state = ERROR;
}
} else if (len == sizeof(connected) && memcmp(buffer, connected, len) == 0) {
if (ctx->state == START) {
xEventGroupSetBits(ctx->flags, CONNECT_BIT);
} else {
ESP_LOGE(TAG, "Received connected in unexpected state %d", ctx->state);
ctx->state = ERROR;
}
}
} else if (nr == WIFI_CHANNEL) {
ESP_LOGD(TAG, "Received WIFI channel=%d len=%d", nr, (int)len);
ESP_LOG_BUFFER_HEXDUMP("wifi-receive", buffer, len, ESP_LOG_VERBOSE);
return esp_wifi_remote_channel_rx(ctx->eppp, buffer, NULL, len);
} else {
ESP_LOGE(TAG, "Incorrect channel number %d", nr);
return ESP_FAIL;
}
return ESP_OK;
}
static esp_err_t wifi_transmit(void *h, void *buffer, size_t len)
{
esp_netif_t *eppp = (esp_netif_t *)h;
context_t *ctx = eppp_get_context(eppp);
ESP_LOG_BUFFER_HEXDUMP("wifi-transmit", buffer, len, ESP_LOG_VERBOSE);
return ctx->transmit(eppp, WIFI_CHANNEL, buffer, len);
}
void esp_netif_destroy_wifi_remote(void *esp_netif);
void station_over_eppp_channel(void *arg)
{
__attribute__((unused)) esp_err_t ret;
esp_netif_t *wifi = NULL;
context_t ctx = {
.transmit = NULL,
.flags = NULL,
.state = UNKNOWN,
.eppp = (esp_netif_t *)arg
};
ESP_GOTO_ON_FALSE(ctx.eppp != NULL, ESP_FAIL, err, TAG, "Incorrect EPPP netif");
ESP_GOTO_ON_FALSE(ctx.flags = xEventGroupCreate(), ESP_FAIL, err, TAG, "Failed to create event group");
ESP_GOTO_ON_ERROR(eppp_add_channels(ctx.eppp, &ctx.transmit, eppp_receive, &ctx), err, TAG, "Failed to add channels");
ESP_GOTO_ON_FALSE(ctx.transmit, ESP_FAIL, err, TAG, "Channel tx function is not set");
ESP_GOTO_ON_ERROR(esp_wifi_remote_channel_set(WIFI_IF_STA, ctx.eppp, wifi_transmit), err, TAG, "Failed to set wifi channel tx function");
esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, event_handler, &ctx);
while (1) {
EventBits_t bits = xEventGroupWaitBits(ctx.flags, ALL_BITS, pdTRUE, pdFALSE, pdMS_TO_TICKS(1000));
if (bits & HELLO_BIT) {
ESP_LOGI(TAG, "Hello done");
if (wifi == NULL) {
wifi = esp_wifi_remote_create_default_sta();
}
const char command[] = "Get MAC";
ctx.transmit(ctx.eppp, CHAT_CHANNEL, (void*)command, sizeof(command));
} else if (bits & START_BIT) {
ctx.state = START;
ESP_LOGI(TAG, "Starting WIFI");
esp_event_post(WIFI_REMOTE_EVENT, WIFI_EVENT_STA_START, NULL, 0, 0);
} else if (bits & CONNECT_BIT) {
ESP_LOGI(TAG, "WIFI connected");
esp_event_post(WIFI_REMOTE_EVENT, WIFI_EVENT_STA_CONNECTED, NULL, 0, 0);
} else if ((bits & SERVER_UP_BIT) == SERVER_UP_BIT || ctx.state != START) {
if (ctx.state == ERROR) {
esp_netif_destroy_wifi_remote(wifi);
wifi = NULL;
ESP_LOGI(TAG, "WiFi netif has been destroyed");
}
const char hello[] = "Hello server";
ctx.transmit(ctx.eppp, CHAT_CHANNEL, (void*)hello, sizeof(hello));
ctx.state = HELLO;
}
}
err:
vTaskDelete(NULL);
}

Some files were not shown because too many files have changed in this diff Show More