mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-03 21:56:40 +02:00
Compare commits
76 Commits
console_cm
...
eppp-v0.0.
Author | SHA1 | Date | |
---|---|---|---|
a363beea6f | |||
a8035c21a2 | |||
7eefcf084e | |||
18f845275f | |||
ad27414a64 | |||
a7610395ef | |||
9b7c8755e9 | |||
0d0630ed76 | |||
38a3631a27 | |||
96f4ebd994 | |||
247ca41bb7 | |||
891384cc53 | |||
38ef603296 | |||
312982e4aa | |||
d9d377133e | |||
110536ebb2 | |||
d85311880d | |||
5ba7cfab8e | |||
2f7c58259d | |||
2b092e0db4 | |||
f42c0adfc0 | |||
2782277f3f | |||
3225f40c22 | |||
d63f831fff | |||
f62db5cfa2 | |||
68ce794098 | |||
60174f290e | |||
efa26b7062 | |||
7b777948fc | |||
1dc4299eb0 | |||
ce7daddc77 | |||
09e68cc0c0 | |||
fc59f87c4e | |||
7a2b23909f | |||
d3bf773445 | |||
1c29af9237 | |||
b53981a68c | |||
5000a9a20a | |||
2646dcd23a | |||
de8ec67a88 | |||
8dac30781c | |||
ba3f06f942 | |||
a10f0008fb | |||
741d166034 | |||
93d140875f | |||
eb7699388c | |||
585e4b30b2 | |||
aa4e9d5795 | |||
6d2c475c20 | |||
47736a2556 | |||
adde6df6e8 | |||
1393764dc5 | |||
0998f3dd4f | |||
577de67c0e | |||
ae38110d84 | |||
5ab699d6f4 | |||
976e98d6ff | |||
18b2ae103a | |||
52a34c21d0 | |||
9df86641f3 | |||
75af01670e | |||
bf79e2f734 | |||
a22c9e8da9 | |||
8548dabbd6 | |||
d2e4370d30 | |||
e4c353760c | |||
4be5efc84e | |||
7451ec2a75 | |||
19fb36000c | |||
7d0eb5c48c | |||
a0a58e60b5 | |||
8285e9730f | |||
d88cd6123b | |||
10bb738911 | |||
edc3e7251f | |||
f2223dd719 |
@ -15,7 +15,7 @@ jobs:
|
||||
matrix:
|
||||
idf_ver: ["latest", "release-v5.0"]
|
||||
idf_target: ["esp32"]
|
||||
test: [ { app: example, path: "components/console_cmd_ifconfig/examples" }]
|
||||
test: [ { app: ifconfig-basic, path: "components/console_cmd_ifconfig/examples"}]
|
||||
runs-on: ubuntu-20.04
|
||||
container: espressif/idf:${{ matrix.idf_ver }}
|
||||
steps:
|
||||
@ -29,4 +29,4 @@ jobs:
|
||||
run: |
|
||||
${IDF_PATH}/install.sh --enable-pytest
|
||||
. ${IDF_PATH}/export.sh
|
||||
python $IDF_PATH/tools/ci/ci_build_apps.py . --target ${{ matrix.idf_target }} -vv --preserve-all --pytest-app
|
||||
python ../../../ci/build_apps.py ./${{ matrix.test.app }} --target ${{ matrix.idf_target }} -vv --preserve-all --pytest-app
|
||||
|
@ -15,7 +15,7 @@ jobs:
|
||||
matrix:
|
||||
idf_ver: ["latest", "release-v5.0"]
|
||||
idf_target: ["esp32"]
|
||||
test: [ { app: example, path: "components/console_cmd_ping/examples" }]
|
||||
test: [ { app: ping-basic, path: "components/console_cmd_ping/examples" }]
|
||||
runs-on: ubuntu-20.04
|
||||
container: espressif/idf:${{ matrix.idf_ver }}
|
||||
steps:
|
||||
@ -29,4 +29,4 @@ jobs:
|
||||
run: |
|
||||
${IDF_PATH}/install.sh --enable-pytest
|
||||
. ${IDF_PATH}/export.sh
|
||||
python $IDF_PATH/tools/ci/ci_build_apps.py . --target ${{ matrix.idf_target }} -vv --preserve-all --pytest-app
|
||||
python ../../../ci/build_apps.py ./${{ matrix.test.app }} --target ${{ matrix.idf_target }} -vv --preserve-all --pytest-app
|
||||
|
@ -15,7 +15,7 @@ jobs:
|
||||
matrix:
|
||||
idf_ver: ["latest", "release-v5.0"]
|
||||
idf_target: ["esp32"]
|
||||
test: [ { app: example, path: "components/console_cmd_wifi/examples" }]
|
||||
test: [ { app: wifi-basic, path: "components/console_cmd_wifi/examples" }]
|
||||
runs-on: ubuntu-20.04
|
||||
container: espressif/idf:${{ matrix.idf_ver }}
|
||||
steps:
|
||||
@ -29,4 +29,4 @@ jobs:
|
||||
run: |
|
||||
${IDF_PATH}/install.sh --enable-pytest
|
||||
. ${IDF_PATH}/export.sh
|
||||
python $IDF_PATH/tools/ci/ci_build_apps.py . --target ${{ matrix.idf_target }} -vv --preserve-all --pytest-app
|
||||
python ../../../ci/build_apps.py ./${{ matrix.test.app }} --target ${{ matrix.idf_target }} -vv --preserve-all --pytest-app
|
||||
|
@ -15,7 +15,7 @@ jobs:
|
||||
matrix:
|
||||
idf_ver: ["latest", "release-v5.0"]
|
||||
idf_target: ["esp32"]
|
||||
test: [ { app: example, path: "components/console_simple_init/examples" }]
|
||||
test: [ { app: console_basic, path: "components/console_simple_init/examples" }]
|
||||
runs-on: ubuntu-20.04
|
||||
container: espressif/idf:${{ matrix.idf_ver }}
|
||||
steps:
|
||||
@ -29,4 +29,4 @@ jobs:
|
||||
run: |
|
||||
${IDF_PATH}/install.sh --enable-pytest
|
||||
. ${IDF_PATH}/export.sh
|
||||
python $IDF_PATH/tools/ci/ci_build_apps.py . --target ${{ matrix.idf_target }} -vv --preserve-all --pytest-app
|
||||
python ../../../ci/build_apps.py ./${{ matrix.test.app }} --target ${{ matrix.idf_target }} -vv --preserve-all --pytest-app
|
||||
|
28
.github/workflows/eppp__build.yml
vendored
Normal file
28
.github/workflows/eppp__build.yml
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
name: "eppp_link: build-tests"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened, labeled]
|
||||
|
||||
jobs:
|
||||
build_eppp:
|
||||
if: contains(github.event.pull_request.labels.*.name, 'eppp') || github.event_name == 'push'
|
||||
name: Build
|
||||
strategy:
|
||||
matrix:
|
||||
idf_ver: ["latest"]
|
||||
test: [ { app: host, path: "examples/host" }, { app: slave, path: "examples/slave" }, { app: test_app, path: "test/test_app" }]
|
||||
runs-on: ubuntu-20.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 }}
|
||||
shell: bash
|
||||
run: |
|
||||
${IDF_PATH}/install.sh --enable-pytest
|
||||
. ${IDF_PATH}/export.sh
|
||||
python ./ci/build_apps.py ./components/eppp_link/${{matrix.test.path}} -vv --preserve-all
|
40
.github/workflows/modem__build-host-tests.yml
vendored
40
.github/workflows/modem__build-host-tests.yml
vendored
@ -8,25 +8,19 @@ on:
|
||||
types: [opened, synchronize, reopened, labeled]
|
||||
|
||||
jobs:
|
||||
build_esp_modem:
|
||||
build_esp_modem_examples:
|
||||
if: contains(github.event.pull_request.labels.*.name, 'modem') || github.event_name == 'push'
|
||||
name: Build
|
||||
name: Build examples
|
||||
strategy:
|
||||
matrix:
|
||||
idf_ver: ["latest", "release-v4.2", "release-v4.3", "release-v4.4", "release-v5.0"]
|
||||
idf_ver: ["latest", "release-v4.3", "release-v4.4", "release-v5.0"]
|
||||
example: ["pppos_client", "modem_console", "modem_tcp_client", "ap_to_pppos", "simple_cmux_client"]
|
||||
exclude:
|
||||
- idf_ver: "release-v4.2"
|
||||
example: simple_cmux_client
|
||||
- idf_ver: "release-v4.2"
|
||||
example: modem_tcp_client
|
||||
- idf_ver: "release-v4.3"
|
||||
example: modem_tcp_client
|
||||
- idf_ver: "release-v4.4"
|
||||
example: modem_tcp_client
|
||||
include:
|
||||
- idf_ver: "release-v4.2"
|
||||
skip_config: usb
|
||||
- idf_ver: "release-v4.3"
|
||||
skip_config: usb
|
||||
- idf_ver: "release-v5.0"
|
||||
@ -50,7 +44,33 @@ jobs:
|
||||
. ${IDF_PATH}/export.sh
|
||||
python -m pip install idf-build-apps
|
||||
cd $GITHUB_WORKSPACE/protocols
|
||||
python ./ci/build_apps.py components/esp_modem/examples/${{ matrix.example }} -m components/esp_modem/examples/.build-test-rules.yml
|
||||
python ./ci/build_apps.py components/esp_modem/examples/${{ matrix.example }} -m components/esp_modem/.build-test-rules.yml
|
||||
|
||||
build_esp_modem_tests:
|
||||
if: contains(github.event.pull_request.labels.*.name, 'modem') || github.event_name == 'push'
|
||||
name: Build tests
|
||||
strategy:
|
||||
matrix:
|
||||
idf_ver: ["release-v5.0", "release-v5.1", "latest"]
|
||||
test: ["target", "target_ota", "target_iperf"]
|
||||
|
||||
runs-on: ubuntu-20.04
|
||||
container: espressif/idf:${{ matrix.idf_ver }}
|
||||
steps:
|
||||
- name: Checkout esp-protocols
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
path: protocols
|
||||
- name: Build ${{ matrix.test }} with IDF-${{ matrix.idf_ver }}
|
||||
env:
|
||||
EXPECTED_WARNING: ${{ matrix.warning }}
|
||||
shell: bash
|
||||
run: |
|
||||
. ${IDF_PATH}/export.sh
|
||||
python -m pip install idf-build-apps
|
||||
cd $GITHUB_WORKSPACE/protocols
|
||||
python ./ci/build_apps.py components/esp_modem/test/${{ matrix.test }} -m components/esp_modem/.build-test-rules.yml
|
||||
|
||||
|
||||
host_test_esp_modem:
|
||||
if: contains(github.event.pull_request.labels.*.name, 'modem') || github.event_name == 'push'
|
||||
|
4
.github/workflows/mqtt_cxx__build.yml
vendored
4
.github/workflows/mqtt_cxx__build.yml
vendored
@ -15,7 +15,7 @@ jobs:
|
||||
matrix:
|
||||
idf_ver: ["latest", "release-v5.0"]
|
||||
idf_target: ["esp32"]
|
||||
test: [ { app: example, path: "components/esp_mqtt_cxx/examples" }]
|
||||
test: [ { app: mqtt-basic, path: "components/esp_mqtt_cxx/examples" }]
|
||||
runs-on: ubuntu-20.04
|
||||
container: espressif/idf:${{ matrix.idf_ver }}
|
||||
steps:
|
||||
@ -29,4 +29,4 @@ jobs:
|
||||
run: |
|
||||
${IDF_PATH}/install.sh --enable-pytest
|
||||
. ${IDF_PATH}/export.sh
|
||||
python $IDF_PATH/tools/ci/ci_build_apps.py . --target ${{ matrix.idf_target }} -vv --preserve-all --pytest-app
|
||||
python ../../../ci/build_apps.py ./${{ matrix.test.app }} --target ${{ matrix.idf_target }} -vv --preserve-all --pytest-app
|
||||
|
3
.github/workflows/publish-docs-component.yml
vendored
3
.github/workflows/publish-docs-component.yml
vendored
@ -48,7 +48,7 @@ jobs:
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get -y install doxygen clang python3-pip
|
||||
python -m pip install breathe recommonmark esp-docs==1.4.1
|
||||
python -m pip install -r docs/requirements.txt
|
||||
for comp in `ls components`; do
|
||||
if [[ -d $GITHUB_WORKSPACE/docs/${comp} ]]; then
|
||||
cd $GITHUB_WORKSPACE/docs/${comp}
|
||||
@ -92,6 +92,7 @@ jobs:
|
||||
components/esp_modem;
|
||||
components/esp_mqtt_cxx;
|
||||
components/esp_websocket_client;
|
||||
components/eppp_link;
|
||||
components/mdns;
|
||||
components/console_simple_init;
|
||||
components/console_cmd_ping;
|
||||
|
@ -61,8 +61,8 @@ repos:
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: commit message scopes
|
||||
name: "commit message must be scoped with: mdns, modem, websocket, asio, mqtt_cxx, console, common"
|
||||
entry: '\A(?!(feat|fix|ci|bump|test|docs)\((mdns|modem|common|console|websocket|asio|mqtt_cxx|examples)\)\:)'
|
||||
name: "commit message must be scoped with: mdns, modem, websocket, asio, mqtt_cxx, console, common, eppp"
|
||||
entry: '\A(?!(feat|fix|ci|bump|test|docs)\((mdns|modem|common|console|websocket|asio|mqtt_cxx|examples|eppp)\)\:)'
|
||||
language: pygrep
|
||||
args: [--multiline]
|
||||
stages: [commit-msg]
|
||||
|
@ -45,3 +45,11 @@ Please refer to instructions in [ESP-IDF](https://github.com/espressif/esp-idf)
|
||||
### console_cmd_ifconfig
|
||||
|
||||
* Brief introduction [README](components/console_cmd_ifconfig/README.md)
|
||||
|
||||
### console_cmd_wifi
|
||||
|
||||
* Brief introduction [README](components/console_cmd_wifi/README.md)
|
||||
|
||||
### ESP PPP Link (eppp)
|
||||
|
||||
* Brief introduction [README](components/eppp_link/README.md)
|
||||
|
@ -10,6 +10,8 @@ import sys
|
||||
|
||||
from idf_build_apps import build_apps, find_apps, setup_logging
|
||||
from idf_build_apps.constants import SUPPORTED_TARGETS
|
||||
from packaging import version
|
||||
from pkg_resources import get_distribution
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(
|
||||
@ -17,6 +19,12 @@ if __name__ == '__main__':
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
)
|
||||
parser.add_argument('paths', nargs='+', help='Paths to the apps to build.')
|
||||
parser.add_argument(
|
||||
'-v',
|
||||
'--verbose',
|
||||
action='count',
|
||||
help='Increase the LOGGER level of the script. Can be specified multiple times.',
|
||||
)
|
||||
parser.add_argument(
|
||||
'-t',
|
||||
'--target',
|
||||
@ -28,6 +36,8 @@ if __name__ == '__main__':
|
||||
parser.add_argument('-d', '--delete', action='store_true', help='Delete build artifacts')
|
||||
parser.add_argument('-c', '--recursive', action='store_true', help='Build recursively')
|
||||
parser.add_argument('-l', '--linux', action='store_true', help='Include linux build (dont check warnings)')
|
||||
parser.add_argument('--preserve-all', action='store_true', help='Preserve the binaries for all apps when specified.')
|
||||
parser.add_argument('--pytest-apps', action='store_true', help='Only build apps required by pytest scripts.')
|
||||
args = parser.parse_args()
|
||||
|
||||
IDF_PATH = os.environ['IDF_PATH']
|
||||
@ -41,20 +51,36 @@ if __name__ == '__main__':
|
||||
SUPPORTED_TARGETS.append('linux')
|
||||
ignore_warning = 'warning: ' # Ignore all common warnings on linux builds
|
||||
setup_logging(2)
|
||||
apps = find_apps(
|
||||
args.paths,
|
||||
recursive=args.recursive,
|
||||
target=args.target,
|
||||
build_dir='build_@t_@w',
|
||||
config_rules_str=args.rules,
|
||||
build_log_path='build_log.txt',
|
||||
size_json_path='size.json' if not args.linux else None,
|
||||
check_warnings=True,
|
||||
preserve=not args.delete,
|
||||
manifest_files=args.manifests,
|
||||
default_build_targets=SUPPORTED_TARGETS,
|
||||
manifest_rootpath='.',
|
||||
)
|
||||
if version.parse(get_distribution('idf_build_apps').version) >= version.parse('2.0.0'):
|
||||
apps = find_apps(
|
||||
args.paths,
|
||||
recursive=args.recursive,
|
||||
target=args.target,
|
||||
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,
|
||||
check_warnings=True,
|
||||
preserve=not args.delete,
|
||||
manifest_files=args.manifests,
|
||||
default_build_targets=SUPPORTED_TARGETS,
|
||||
manifest_rootpath='.',
|
||||
)
|
||||
else:
|
||||
apps = find_apps(
|
||||
args.paths,
|
||||
recursive=args.recursive,
|
||||
target=args.target,
|
||||
build_dir='build_@t_@w',
|
||||
config_rules_str=args.rules,
|
||||
build_log_path='build_log.txt',
|
||||
size_json_path='size.json' if not args.linux else None,
|
||||
check_warnings=True,
|
||||
preserve=not args.delete,
|
||||
manifest_files=args.manifests,
|
||||
default_build_targets=SUPPORTED_TARGETS,
|
||||
manifest_rootpath='.',
|
||||
)
|
||||
|
||||
for app in apps:
|
||||
print(app)
|
||||
|
@ -3,6 +3,6 @@ commitizen:
|
||||
bump_message: 'bump(console): $current_version -> $new_version'
|
||||
pre_bump_hooks: python ../../ci/changelog.py console_cmd_ifconfig
|
||||
tag_format: console_cmd_ifconfig-v$version
|
||||
version: 1.0.0
|
||||
version: 1.0.1
|
||||
version_files:
|
||||
- idf_component.yml
|
||||
|
@ -1,5 +1,11 @@
|
||||
# Changelog
|
||||
|
||||
## [1.0.1](https://github.com/espressif/esp-protocols/commits/console_cmd_ifconfig-v1.0.1)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Fixed ifconfig command for PPP interface and IPv4 only ([8548dabb](https://github.com/espressif/esp-protocols/commit/8548dabb))
|
||||
|
||||
## [1.0.0](https://github.com/espressif/esp-protocols/commits/console_cmd_ifconfig-v1.0.0)
|
||||
|
||||
### Features
|
||||
|
@ -62,3 +62,52 @@ For more details refer [IDF Component Manager](https://docs.espressif.com/projec
|
||||
ifconfig <iface> dhcp client <enable/disable>: Enable or disable the DHCP client.
|
||||
Note: Disabling the DHCP server and client enables the use of static IP configuration.
|
||||
```
|
||||
|
||||
## Usage:
|
||||
|
||||
### Creating an ethernet interface
|
||||
```
|
||||
esp> ifconfig eth init
|
||||
Internal(IP101): pins: 23,18, Id: 0
|
||||
esp> ifconfig netif create 0
|
||||
```
|
||||
|
||||
### Removing an interface and deinitializing ethernet
|
||||
```
|
||||
esp> ifconfig netif destroy en1
|
||||
I (8351266) ethernet_init: Ethernet(IP101[23,18]) Link Down
|
||||
I (8351266) ethernet_init: Ethernet(IP101[23,18]) Stopped
|
||||
esp> ifconfig eth deinit
|
||||
```
|
||||
|
||||
### Set default interface
|
||||
```
|
||||
esp> ifconfig en1 default
|
||||
```
|
||||
|
||||
### Enable NAPT on an interface
|
||||
```
|
||||
esp> ifconfig en1 napt enable
|
||||
I (8467116) console_ifconfig: Setting napt enable on en1
|
||||
```
|
||||
|
||||
### Enable DHCP client on an interface
|
||||
```
|
||||
esp> ifconfig en1 dhcp client enable
|
||||
```
|
||||
|
||||
### Enable static IP on an interface
|
||||
```
|
||||
esp> ifconfig en1 dhcp client disable
|
||||
```
|
||||
|
||||
### Set static IP address
|
||||
```
|
||||
esp> ifconfig en1 ip 192.168.5.2
|
||||
I (111466) console_ifconfig: Setting ip: 192.168.5.2
|
||||
esp> ifconfig en1 mask 255.255.255.0
|
||||
I (130946) console_ifconfig: Setting mask: 255.255.255.0
|
||||
esp> ifconfig en1 gw 192.168.5.1
|
||||
I (143576) console_ifconfig: Setting gw: 192.168.5.1
|
||||
I (143576) esp_netif_handlers: eth ip: 192.168.5.2, mask: 255.255.255.0, gw: 192.168.5.1
|
||||
```
|
||||
|
@ -16,7 +16,9 @@
|
||||
#include "argtable3/argtable3.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_netif_net_stack.h"
|
||||
#if CONFIG_LWIP_IPV6
|
||||
#include "lwip/ip6.h"
|
||||
#endif
|
||||
#include "lwip/opt.h"
|
||||
#include "ethernet_init.h"
|
||||
#include "console_ifconfig.h"
|
||||
@ -65,7 +67,9 @@ netif_op_t cmd_list[] = {
|
||||
{.name = "ifconfig", .operation = ifcfg_print_op, .arg_cnt = 1, .start_index = 0, .netif_flag = false, .help = "ifconfig: Display a list of all esp_netif interfaces along with their information"},
|
||||
{.name = "ifconfig", .operation = ifcfg_print_op, .arg_cnt = 2, .start_index = 0, .netif_flag = true, .help = "ifconfig <iface>: Provide the details of the named interface"},
|
||||
{.name = "default", .operation = ifcfg_basic_op, .arg_cnt = 3, .start_index = 2, .netif_flag = true, .help = "ifconfig <iface> default: Set the specified interface as the default interface"},
|
||||
#if CONFIG_LWIP_IPV6
|
||||
{.name = "ip6", .operation = ifcfg_basic_op, .arg_cnt = 3, .start_index = 2, .netif_flag = true, .help = "ifconfig <iface> ip6: Enable IPv6 on the specified interface"},
|
||||
#endif
|
||||
{.name = "up", .operation = ifcfg_lwip_op, .arg_cnt = 3, .start_index = 2, .netif_flag = true, .help = "ifconfig <iface> up: Enable the specified interface"},
|
||||
{.name = "down", .operation = ifcfg_lwip_op, .arg_cnt = 3, .start_index = 2, .netif_flag = true, .help = "ifconfig <iface> down: Disable the specified interface"},
|
||||
{.name = "link", .operation = ifcfg_lwip_op, .arg_cnt = 4, .start_index = 2, .netif_flag = true, .help = "ifconfig <iface> link <up/down>: Enable or disable the link of the specified interface"},
|
||||
@ -99,10 +103,10 @@ static esp_netif_t *get_esp_netif_from_ifname(char *if_name)
|
||||
char interface[10];
|
||||
|
||||
/* Get interface details and obtain the global IPv6 address */
|
||||
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
|
||||
while ((esp_netif = esp_netif_next(esp_netif)) != NULL) {
|
||||
#else
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
|
||||
while ((esp_netif = esp_netif_next_unsafe(esp_netif)) != NULL) {
|
||||
#else
|
||||
while ((esp_netif = esp_netif_next(esp_netif)) != NULL) {
|
||||
#endif
|
||||
ret = esp_netif_get_netif_impl_name(esp_netif, interface);
|
||||
|
||||
@ -128,12 +132,13 @@ static esp_err_t ifcfg_basic_op(netif_op_t *self, int argc, char *argv[], esp_ne
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
#if CONFIG_LWIP_IPV6
|
||||
/* Enable IPv6 on this interface */
|
||||
if (!strcmp("ip6", argv[self->start_index])) {
|
||||
ESP_ERROR_CHECK(esp_netif_create_ip6_linklocal(esp_netif));
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
@ -216,10 +221,10 @@ static esp_err_t set_napt(char *if_name, bool state)
|
||||
|
||||
/* Get interface details and own global ipv6 address */
|
||||
for (int i = 0; i < esp_netif_get_nr_of_ifs(); ++i) {
|
||||
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
|
||||
esp_netif = esp_netif_next(esp_netif);
|
||||
#else
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
|
||||
esp_netif = esp_netif_next_unsafe(esp_netif);
|
||||
#else
|
||||
esp_netif = esp_netif_next(esp_netif);
|
||||
#endif
|
||||
ret = esp_netif_get_netif_impl_name(esp_netif, interface);
|
||||
if ((ESP_FAIL == ret) || (NULL == esp_netif)) {
|
||||
@ -228,9 +233,7 @@ static esp_err_t set_napt(char *if_name, bool state)
|
||||
}
|
||||
|
||||
if (!strcmp(interface, if_name)) {
|
||||
struct netif *lwip_netif = esp_netif_get_netif_impl(esp_netif);
|
||||
ip_napt_enable_netif(lwip_netif, state);
|
||||
return ESP_OK;
|
||||
return esp_netif_napt_enable(esp_netif);
|
||||
}
|
||||
}
|
||||
|
||||
@ -303,8 +306,10 @@ static void print_iface_details(esp_netif_t *esp_netif)
|
||||
esp_netif_ip_info_t ip_info;
|
||||
uint8_t mac[NETIF_MAX_HWADDR_LEN];
|
||||
char interface[10];
|
||||
#if CONFIG_LWIP_IPV6
|
||||
int ip6_addrs_count = 0;
|
||||
esp_ip6_addr_t ip6[LWIP_IPV6_NUM_ADDRESSES];
|
||||
#endif
|
||||
esp_err_t ret = ESP_FAIL;
|
||||
esp_netif_dhcp_status_t status;
|
||||
|
||||
@ -326,7 +331,9 @@ static void print_iface_details(esp_netif_t *esp_netif)
|
||||
#else
|
||||
ESP_LOGI(TAG, "Interface Name: %s", interface);
|
||||
#endif
|
||||
ESP_LOGI(TAG, "Interface Number: %d", lwip_netif->num);
|
||||
if (lwip_netif != NULL) {
|
||||
ESP_LOGI(TAG, "Interface Number: %d", lwip_netif->num);
|
||||
}
|
||||
|
||||
/* Print MAC address */
|
||||
esp_netif_get_mac(esp_netif, mac);
|
||||
@ -350,19 +357,25 @@ static void print_iface_details(esp_netif_t *esp_netif)
|
||||
|
||||
#if IP_NAPT
|
||||
/* Print NAPT status*/
|
||||
ESP_LOGI(TAG, "NAPT: %s", lwip_netif->napt ? "enabled" : "disabled");
|
||||
if (lwip_netif != NULL) {
|
||||
ESP_LOGI(TAG, "NAPT: %s", lwip_netif->napt ? "enabled" : "disabled");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_LWIP_IPV6
|
||||
/* Print IPv6 Address */
|
||||
ip6_addrs_count = esp_netif_get_all_ip6(esp_netif, ip6);
|
||||
for (int j = 0; j < ip6_addrs_count; ++j) {
|
||||
ESP_LOGI(TAG, "IPv6 address: " IPV6STR, IPV62STR(ip6[j]));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Print Interface and Link Status*/
|
||||
ESP_LOGI(TAG, "Interface Status: %s", esp_netif_is_netif_up(esp_netif) ? "UP" : "DOWN");
|
||||
ESP_LOGI(TAG, "Link Status: %s\n", netif_is_link_up(lwip_netif) ? "UP" : "DOWN");
|
||||
|
||||
if (lwip_netif != NULL) {
|
||||
ESP_LOGI(TAG, "Link Status: %s", netif_is_link_up(lwip_netif) ? "UP" : "DOWN");
|
||||
}
|
||||
ESP_LOGI(TAG, "");
|
||||
}
|
||||
|
||||
|
||||
@ -376,10 +389,10 @@ static esp_err_t ifcfg_print_op(netif_op_t *self, int argc, char *argv[], esp_ne
|
||||
|
||||
/* Get interface details and own global ipv6 address of all interfaces */
|
||||
for (int i = 0; i < esp_netif_get_nr_of_ifs(); ++i) {
|
||||
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
|
||||
esp_netif = esp_netif_next(esp_netif);
|
||||
#else
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
|
||||
esp_netif = esp_netif_next_unsafe(esp_netif);
|
||||
#else
|
||||
esp_netif = esp_netif_next(esp_netif);
|
||||
#endif
|
||||
print_iface_details(esp_netif);
|
||||
}
|
||||
@ -424,6 +437,7 @@ static esp_err_t get_netif_config(uint16_t id, esp_netif_config_t *eth_cfg_o)
|
||||
return ESP_FAIL;
|
||||
}
|
||||
*esp_eth_base_config = (esp_netif_inherent_config_t)ESP_NETIF_INHERENT_DEFAULT_ETH();
|
||||
|
||||
esp_eth_base_config->if_key = if_key;
|
||||
|
||||
eth_cfg_o->base = esp_eth_base_config;
|
||||
|
@ -1,4 +1,4 @@
|
||||
version: 1.0.0
|
||||
version: 1.0.1
|
||||
url: https://github.com/espressif/esp-protocols/tree/master/components/console_cmd_ifconfig
|
||||
description: The component offers a console that enables runtime network interface configuration and monitoring.
|
||||
dependencies:
|
||||
|
@ -3,6 +3,6 @@ commitizen:
|
||||
bump_message: 'bump(console): $current_version -> $new_version'
|
||||
pre_bump_hooks: python ../../ci/changelog.py console_cmd_wifi
|
||||
tag_format: console_cmd_wifi-v$version
|
||||
version: 1.0.0
|
||||
version: 1.0.1
|
||||
version_files:
|
||||
- idf_component.yml
|
||||
|
@ -1,5 +1,15 @@
|
||||
# Changelog
|
||||
|
||||
## [1.0.1](https://github.com/espressif/esp-protocols/commits/console_cmd_wifi-v1.0.1)
|
||||
|
||||
### Features
|
||||
|
||||
- Console for runtime wifi configuration ([194d1179](https://github.com/espressif/esp-protocols/commit/194d1179))
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Fixed license file for console_cmd_wifi ([8285e973](https://github.com/espressif/esp-protocols/commit/8285e973))
|
||||
|
||||
## [1.0.0](https://github.com/espressif/esp-protocols/commits/console_cmd_wifi-v1.0.0)
|
||||
|
||||
### Features
|
||||
|
201
components/console_cmd_wifi/LICENSE
Normal file
201
components/console_cmd_wifi/LICENSE
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
@ -1,4 +1,4 @@
|
||||
version: 1.0.0
|
||||
version: 1.0.1
|
||||
url: https://github.com/espressif/esp-protocols/tree/master/components/console_cmd_wifi
|
||||
description: The component offers a console that enables runtime wifi configuration and monitoring.
|
||||
dependencies:
|
||||
|
8
components/eppp_link/.cz.yaml
Normal file
8
components/eppp_link/.cz.yaml
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
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.0.1
|
||||
version_files:
|
||||
- idf_component.yml
|
10
components/eppp_link/CHANGELOG.md
Normal file
10
components/eppp_link/CHANGELOG.md
Normal file
@ -0,0 +1,10 @@
|
||||
# Changelog
|
||||
|
||||
## [0.0.1](https://github.com/espressif/esp-protocols/commits/eppp-v0.0.1)
|
||||
|
||||
### Features
|
||||
|
||||
- Added CI job to build examples and tests ([8686977](https://github.com/espressif/esp-protocols/commit/8686977))
|
||||
- Added support for SPI transport ([18f8452](https://github.com/espressif/esp-protocols/commit/18f8452))
|
||||
- Added support for UART transport ([ad27414](https://github.com/espressif/esp-protocols/commit/ad27414))
|
||||
- Introduced ESP-PPP-Link component ([a761039](https://github.com/espressif/esp-protocols/commit/a761039))
|
3
components/eppp_link/CMakeLists.txt
Normal file
3
components/eppp_link/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
||||
idf_component_register(SRCS "eppp_link.c"
|
||||
INCLUDE_DIRS "include"
|
||||
PRIV_REQUIRES esp_netif esp_driver_spi esp_driver_gpio esp_timer driver)
|
35
components/eppp_link/Kconfig
Normal file
35
components/eppp_link/Kconfig
Normal file
@ -0,0 +1,35 @@
|
||||
menu "eppp_link"
|
||||
|
||||
choice EPPP_LINK_DEVICE
|
||||
prompt "Choose PPP device"
|
||||
default EPPP_LINK_DEVICE_UART
|
||||
help
|
||||
Select which peripheral to use for PPP link
|
||||
|
||||
config EPPP_LINK_DEVICE_UART
|
||||
bool "UART"
|
||||
help
|
||||
Use UART.
|
||||
|
||||
config EPPP_LINK_DEVICE_SPI
|
||||
bool "SPI"
|
||||
help
|
||||
Use SPI.
|
||||
endchoice
|
||||
|
||||
config EPPP_LINK_CONN_MAX_RETRY
|
||||
int "Maximum retry"
|
||||
default 6
|
||||
help
|
||||
Set the Maximum retry to infinitely avoid reconnecting
|
||||
This is used only with the simplified API (eppp_connect()
|
||||
and eppp_listen())
|
||||
|
||||
config EPPP_LINK_PACKET_QUEUE_SIZE
|
||||
int "Packet queue size"
|
||||
default 64
|
||||
help
|
||||
Size of the Tx packet queue.
|
||||
You can decrease the number for slower bit rates.
|
||||
|
||||
endmenu
|
202
components/eppp_link/LICENSE
Normal file
202
components/eppp_link/LICENSE
Normal file
@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
52
components/eppp_link/README.md
Normal file
52
components/eppp_link/README.md
Normal file
@ -0,0 +1,52 @@
|
||||
# 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
|
||||
|
||||
## 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.
|
||||
|
||||
```
|
||||
SLAVE micro HOST micro
|
||||
\|/ +----------------+ +----------------+
|
||||
| | | serial line | |
|
||||
+---+ WiFi NAT PPPoS |======== UART / SPI =======| PPPoS client |
|
||||
| (server)| | |
|
||||
+----------------+ +----------------+
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### Client
|
||||
|
||||
* `eppp_connect()` -- Simplified API. Provides the initialization, starts the task and blocks until we're connected
|
||||
|
||||
### Server
|
||||
|
||||
* `eppp_listen()` -- Simplified API. Provides the initialization, starts the task and blocks until the client connects
|
||||
|
||||
### Manual actions
|
||||
|
||||
* `eppp_init()` -- Initializes one endpoint (client/server).
|
||||
* `eppp_deinit()` -- Destroys the endpoint
|
||||
* `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)
|
||||
|
||||
## Throughput
|
||||
|
||||
Tested with WiFi-NAPT example, no IRAM optimizations
|
||||
|
||||
### UART @ 3Mbauds
|
||||
|
||||
* TCP - 2Mbits/s
|
||||
* UDP - 2Mbits/s
|
||||
|
||||
### SPI @ 20MHz
|
||||
|
||||
* TCP - 6Mbits/s
|
||||
* UDP - 10Mbits/s
|
820
components/eppp_link/eppp_link.c
Normal file
820
components/eppp_link/eppp_link.c
Normal file
@ -0,0 +1,820 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2019-2024 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 "esp_netif_ppp.h"
|
||||
#include "eppp_link.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"
|
||||
#endif
|
||||
|
||||
static const int GOT_IPV4 = BIT0;
|
||||
static const int CONNECTION_FAILED = BIT1;
|
||||
#define CONNECT_BITS (GOT_IPV4|CONNECTION_FAILED)
|
||||
|
||||
static EventGroupHandle_t s_event_group = NULL;
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
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
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void 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)
|
||||
{
|
||||
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,
|
||||
.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();
|
||||
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;
|
||||
if (role == EPPP_CLIENT) {
|
||||
base_netif_cfg.if_desc = "pppos_client";
|
||||
} else {
|
||||
base_netif_cfg.if_desc = "pppos_server";
|
||||
}
|
||||
esp_netif_config_t netif_ppp_config = { .base = &base_netif_cfg,
|
||||
.driver = ppp_driver_cfg,
|
||||
.stack = ESP_NETIF_NETSTACK_DEFAULT_PPP
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
return netif;
|
||||
|
||||
}
|
||||
|
||||
esp_err_t eppp_netif_stop(esp_netif_t *netif, int stop_timeout_ms)
|
||||
{
|
||||
esp_netif_action_disconnected(netif, 0, 0, 0);
|
||||
esp_netif_action_stop(netif, 0, 0, 0);
|
||||
struct eppp_handle *h = esp_netif_get_io_driver(netif);
|
||||
for (int wait = 0; wait < 100; wait++) {
|
||||
vTaskDelay(pdMS_TO_TICKS(stop_timeout_ms) / 100);
|
||||
if (h->netif_stop) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!h->netif_stop) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
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);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static int get_netif_num(esp_netif_t *netif)
|
||||
{
|
||||
if (netif == NULL) {
|
||||
return -1;
|
||||
}
|
||||
const char *ifkey = esp_netif_get_ifkey(netif);
|
||||
if (strstr(ifkey, "EPPP") == NULL) {
|
||||
return -1; // not our netif
|
||||
}
|
||||
int netif_cnt = ifkey[4] - '0';
|
||||
if (netif_cnt < 0 || netif_cnt > 9) {
|
||||
ESP_LOGE(TAG, "Unexpected netif key %s", ifkey);
|
||||
return -1;
|
||||
}
|
||||
return netif_cnt;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
int netif_cnt = get_netif_num(netif);
|
||||
if (netif_cnt < 0) {
|
||||
return;
|
||||
}
|
||||
if (event_id == IP_EVENT_PPP_GOT_IP) {
|
||||
ESP_LOGI(TAG, "Got IPv4 event: Interface \"%s(%s)\" address: " IPSTR, esp_netif_get_desc(netif),
|
||||
esp_netif_get_ifkey(netif), IP2STR(&event->ip_info.ip));
|
||||
xEventGroupSetBits(s_event_group, GOT_IPV4 << (netif_cnt * 2));
|
||||
} else if (event_id == IP_EVENT_PPP_LOST_IP) {
|
||||
ESP_LOGI(TAG, "Disconnected");
|
||||
s_retry_num++;
|
||||
if (s_retry_num > CONFIG_EPPP_LINK_CONN_MAX_RETRY) {
|
||||
ESP_LOGE(TAG, "PPP Connection failed %d times, stop reconnecting.", s_retry_num);
|
||||
xEventGroupSetBits(s_event_group, CONNECTION_FAILED << (netif_cnt * 2));
|
||||
} else {
|
||||
ESP_LOGI(TAG, "PPP Connection failed %d times, try to reconnect.", s_retry_num);
|
||||
eppp_netif_start(netif);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
#endif // CONFIG_EPPP_LINK_DEVICE_SPI / UART
|
||||
|
||||
static void ppp_task(void *args)
|
||||
{
|
||||
esp_netif_t *netif = args;
|
||||
while (eppp_perform(netif) != ESP_ERR_TIMEOUT) {}
|
||||
struct eppp_handle *h = esp_netif_get_io_driver(netif);
|
||||
h->exited = true;
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
static bool have_some_eppp_netif(esp_netif_t *netif, void *ctx)
|
||||
{
|
||||
return get_netif_num(netif) > 0;
|
||||
}
|
||||
|
||||
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
|
||||
vEventGroupDelete(s_event_group);
|
||||
s_event_group = NULL;
|
||||
esp_event_handler_unregister(IP_EVENT, ESP_EVENT_ANY_ID, on_ip_event);
|
||||
esp_event_handler_unregister(NETIF_PPP_STATUS, ESP_EVENT_ANY_ID, on_ppp_event);
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
#endif
|
||||
netif_deinit(netif);
|
||||
}
|
||||
|
||||
esp_netif_t *eppp_init(eppp_type_t role, eppp_config_t *config)
|
||||
{
|
||||
esp_netif_t *netif = netif_init(role);
|
||||
if (!netif) {
|
||||
ESP_LOGE(TAG, "Failed to initialize PPP netif");
|
||||
remove_handlers();
|
||||
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);
|
||||
#endif
|
||||
return netif;
|
||||
}
|
||||
|
||||
esp_netif_t *eppp_open(eppp_type_t role, eppp_config_t *config, int connect_timeout_ms)
|
||||
{
|
||||
#if CONFIG_EPPP_LINK_DEVICE_UART
|
||||
if (config->transport != EPPP_TRANSPORT_UART) {
|
||||
ESP_LOGE(TAG, "Invalid transport: UART device must be enabled in Kconfig");
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
#if CONFIG_EPPP_LINK_DEVICE_SPI
|
||||
if (config->transport != EPPP_TRANSPORT_SPI) {
|
||||
ESP_LOGE(TAG, "Invalid transport: SPI device must be enabled in Kconfig");
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (config->task.run_task == false) {
|
||||
ESP_LOGE(TAG, "task.run_task == false is invalid in this API. Please use eppp_init()");
|
||||
return NULL;
|
||||
}
|
||||
if (s_event_group == NULL) {
|
||||
s_event_group = xEventGroupCreate();
|
||||
if (esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, on_ip_event, NULL) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to register IP event handler");
|
||||
remove_handlers();
|
||||
return NULL;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
esp_netif_t *netif = eppp_init(role, config);
|
||||
if (!netif) {
|
||||
remove_handlers();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
eppp_netif_start(netif);
|
||||
|
||||
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;
|
||||
}
|
||||
int netif_cnt = get_netif_num(netif);
|
||||
if (netif_cnt < 0) {
|
||||
eppp_close(netif);
|
||||
return NULL;
|
||||
}
|
||||
ESP_LOGI(TAG, "Waiting for IP address %d", netif_cnt);
|
||||
EventBits_t bits = xEventGroupWaitBits(s_event_group, CONNECT_BITS << (netif_cnt * 2), pdFALSE, pdFALSE, pdMS_TO_TICKS(connect_timeout_ms));
|
||||
if (bits & (CONNECTION_FAILED << (netif_cnt * 2))) {
|
||||
ESP_LOGE(TAG, "Connection failed!");
|
||||
eppp_close(netif);
|
||||
return NULL;
|
||||
}
|
||||
ESP_LOGI(TAG, "Connected! %d", netif_cnt);
|
||||
return netif;
|
||||
}
|
||||
|
||||
esp_netif_t *eppp_connect(eppp_config_t *config)
|
||||
{
|
||||
return eppp_open(EPPP_CLIENT, config, portMAX_DELAY);
|
||||
}
|
||||
|
||||
esp_netif_t *eppp_listen(eppp_config_t *config)
|
||||
{
|
||||
return eppp_open(EPPP_SERVER, config, portMAX_DELAY);
|
||||
}
|
||||
|
||||
void eppp_close(esp_netif_t *netif)
|
||||
{
|
||||
struct eppp_handle *h = esp_netif_get_io_driver(netif);
|
||||
if (eppp_netif_stop(netif, 60000) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Network didn't exit cleanly");
|
||||
}
|
||||
h->stop = true;
|
||||
for (int wait = 0; wait < 100; wait++) {
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
if (h->exited) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!h->exited) {
|
||||
ESP_LOGE(TAG, "Cannot stop ppp_task");
|
||||
}
|
||||
eppp_deinit(netif);
|
||||
remove_handlers();
|
||||
}
|
8
components/eppp_link/examples/host/CMakeLists.txt
Normal file
8
components/eppp_link/examples/host/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
||||
# The following four 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)
|
||||
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/iperf)
|
||||
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(pppos_host)
|
9
components/eppp_link/examples/host/README.md
Normal file
9
components/eppp_link/examples/host/README.md
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
# Client side demo of ESP-PPP-Link
|
||||
|
||||
This is a basic demo of using esp-mqtt library, but connects to the internet using a PPPoS client. To run this example, you would need a PPP server that provides connectivity to the MQTT broker used in this example (by default a public broker accessible on the internet).
|
||||
|
||||
If configured, this example could also run a ping session and an iperf console.
|
||||
|
||||
|
||||
The PPP server could be a Linux computer with `pppd` service or an ESP32 acting like a connection gateway with PPPoS server (see the "slave" project).
|
2
components/eppp_link/examples/host/main/CMakeLists.txt
Normal file
2
components/eppp_link/examples/host/main/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS app_main.c register_iperf.c
|
||||
INCLUDE_DIRS ".")
|
53
components/eppp_link/examples/host/main/Kconfig.projbuild
Normal file
53
components/eppp_link/examples/host/main/Kconfig.projbuild
Normal file
@ -0,0 +1,53 @@
|
||||
menu "Example Configuration"
|
||||
|
||||
config EXAMPLE_GLOBAL_DNS
|
||||
hex "Set global DNS server"
|
||||
range 0 0xFFFFFFFF
|
||||
default 0x08080808
|
||||
help
|
||||
Global DNS server address.
|
||||
|
||||
config EXAMPLE_MQTT
|
||||
bool "Run mqtt example"
|
||||
default y
|
||||
help
|
||||
Run MQTT client after startup.
|
||||
|
||||
config EXAMPLE_BROKER_URL
|
||||
string "Broker URL"
|
||||
depends on EXAMPLE_MQTT
|
||||
default "mqtt://mqtt.eclipseprojects.io"
|
||||
help
|
||||
URL of the broker to connect to.
|
||||
|
||||
config EXAMPLE_IPERF
|
||||
bool "Run iperf"
|
||||
default y
|
||||
help
|
||||
Init and run iperf console.
|
||||
|
||||
config EXAMPLE_UART_TX_PIN
|
||||
int "TXD Pin Number"
|
||||
depends on EPPP_LINK_DEVICE_UART
|
||||
default 10
|
||||
range 0 31
|
||||
help
|
||||
Pin number of UART TX.
|
||||
|
||||
config EXAMPLE_UART_RX_PIN
|
||||
int "RXD Pin Number"
|
||||
depends on EPPP_LINK_DEVICE_UART
|
||||
default 11
|
||||
range 0 31
|
||||
help
|
||||
Pin number of UART RX.
|
||||
|
||||
config EXAMPLE_UART_BAUDRATE
|
||||
int "Baudrate"
|
||||
depends on EPPP_LINK_DEVICE_UART
|
||||
default 2000000
|
||||
range 0 4000000
|
||||
help
|
||||
Baudrate used by the PPP over UART
|
||||
|
||||
endmenu
|
149
components/eppp_link/examples/host/main/app_main.c
Normal file
149
components/eppp_link/examples/host/main/app_main.c
Normal file
@ -0,0 +1,149 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023-2024 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 "nvs_flash.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_netif.h"
|
||||
#include "eppp_link.h"
|
||||
#include "esp_log.h"
|
||||
#include "mqtt_client.h"
|
||||
#include "console_ping.h"
|
||||
|
||||
void register_iperf(void);
|
||||
|
||||
static const char *TAG = "eppp_host_example";
|
||||
|
||||
#if CONFIG_EXAMPLE_MQTT
|
||||
static void mqtt_event_handler(void *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;
|
||||
esp_mqtt_client_handle_t client = event->client;
|
||||
int msg_id;
|
||||
switch ((esp_mqtt_event_id_t)event_id) {
|
||||
case MQTT_EVENT_CONNECTED:
|
||||
ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
|
||||
msg_id = esp_mqtt_client_publish(client, "/topic/qos1", "data_3", 0, 1, 0);
|
||||
ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id);
|
||||
|
||||
msg_id = esp_mqtt_client_subscribe(client, "/topic/qos0", 0);
|
||||
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
|
||||
|
||||
msg_id = esp_mqtt_client_subscribe(client, "/topic/qos1", 1);
|
||||
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
|
||||
|
||||
msg_id = esp_mqtt_client_unsubscribe(client, "/topic/qos1");
|
||||
ESP_LOGI(TAG, "sent unsubscribe successful, msg_id=%d", msg_id);
|
||||
break;
|
||||
case MQTT_EVENT_DISCONNECTED:
|
||||
ESP_LOGI(TAG, "MQTT_EVENT_DISCONNECTED");
|
||||
break;
|
||||
|
||||
case MQTT_EVENT_SUBSCRIBED:
|
||||
ESP_LOGI(TAG, "MQTT_EVENT_SUBSCRIBED, msg_id=%d", event->msg_id);
|
||||
msg_id = esp_mqtt_client_publish(client, "/topic/qos0", "data", 0, 0, 0);
|
||||
ESP_LOGI(TAG, "sent publish successful, msg_id=%d", 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");
|
||||
printf("TOPIC=%.*s\r\n", event->topic_len, event->topic);
|
||||
printf("DATA=%.*s\r\n", event->data_len, event->data);
|
||||
break;
|
||||
case MQTT_EVENT_ERROR:
|
||||
ESP_LOGI(TAG, "MQTT_EVENT_ERROR");
|
||||
if (event->error_handle->error_type == MQTT_ERROR_TYPE_TCP_TRANSPORT) {
|
||||
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 void mqtt_app_start(void)
|
||||
{
|
||||
esp_mqtt_client_config_t mqtt_cfg = {
|
||||
.broker.address.uri = "mqtt://mqtt.eclipseprojects.io",
|
||||
};
|
||||
|
||||
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
|
||||
/* 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, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL);
|
||||
esp_mqtt_client_start(client);
|
||||
}
|
||||
#endif // MQTT
|
||||
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "[APP] Startup..");
|
||||
ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size());
|
||||
ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version());
|
||||
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
|
||||
/* Sets up the default EPPP-connection
|
||||
*/
|
||||
eppp_config_t config = EPPP_DEFAULT_CLIENT_CONFIG();
|
||||
#if CONFIG_EPPP_LINK_DEVICE_SPI
|
||||
config.transport = EPPP_TRANSPORT_SPI;
|
||||
#else
|
||||
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;
|
||||
#endif
|
||||
esp_netif_t *eppp_netif = eppp_connect(&config);
|
||||
if (eppp_netif == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to connect");
|
||||
return ;
|
||||
}
|
||||
// Setup global DNS
|
||||
esp_netif_dns_info_t dns;
|
||||
dns.ip.u_addr.ip4.addr = esp_netif_htonl(CONFIG_EXAMPLE_GLOBAL_DNS);
|
||||
dns.ip.type = ESP_IPADDR_TYPE_V4;
|
||||
ESP_ERROR_CHECK(esp_netif_set_dns_info(eppp_netif, ESP_NETIF_DNS_MAIN, &dns));
|
||||
|
||||
// Initialize console REPL
|
||||
ESP_ERROR_CHECK(console_cmd_init());
|
||||
|
||||
#if CONFIG_EXAMPLE_IPERF
|
||||
register_iperf();
|
||||
|
||||
printf("\n =======================================================\n");
|
||||
printf(" | Steps to Test EPPP-host bandwidth |\n");
|
||||
printf(" | |\n");
|
||||
printf(" | 1. Wait for the ESP32 to get an IP |\n");
|
||||
printf(" | 2. Server: 'iperf -u -s -i 3' (on host) |\n");
|
||||
printf(" | 3. Client: 'iperf -u -c SERVER_IP -t 60 -i 3' |\n");
|
||||
printf(" | |\n");
|
||||
printf(" =======================================================\n\n");
|
||||
|
||||
#endif // CONFIG_EXAMPLE_IPERF
|
||||
|
||||
// Register the ping command
|
||||
ESP_ERROR_CHECK(console_cmd_ping_register());
|
||||
// start console REPL
|
||||
ESP_ERROR_CHECK(console_cmd_start());
|
||||
|
||||
#if CONFIG_EXAMPLE_MQTT
|
||||
mqtt_app_start();
|
||||
#endif
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
dependencies:
|
||||
espressif/eppp_link:
|
||||
version: "*"
|
||||
override_path: "../../.."
|
||||
console_cmd_ping:
|
||||
version: "*"
|
179
components/eppp_link/examples/host/main/register_iperf.c
Normal file
179
components/eppp_link/examples/host/main/register_iperf.c
Normal file
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "sys/socket.h" // for INADDR_ANY
|
||||
#include "esp_netif.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_netif.h"
|
||||
#include "esp_netif_ppp.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/event_groups.h"
|
||||
|
||||
#include "esp_console.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_bit_defs.h"
|
||||
#include "argtable3/argtable3.h"
|
||||
#include "iperf.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
/* "iperf" command */
|
||||
|
||||
static struct {
|
||||
struct arg_str *ip;
|
||||
struct arg_lit *server;
|
||||
struct arg_lit *udp;
|
||||
struct arg_lit *version;
|
||||
struct arg_int *port;
|
||||
struct arg_int *length;
|
||||
struct arg_int *interval;
|
||||
struct arg_int *time;
|
||||
struct arg_int *bw_limit;
|
||||
struct arg_lit *abort;
|
||||
struct arg_end *end;
|
||||
} iperf_args;
|
||||
|
||||
static int ppp_cmd_iperf(int argc, char **argv)
|
||||
{
|
||||
int nerrors = arg_parse(argc, argv, (void **)&iperf_args);
|
||||
// ethernet iperf only support IPV4 address
|
||||
iperf_cfg_t cfg = {.type = IPERF_IP_TYPE_IPV4};
|
||||
|
||||
if (nerrors != 0) {
|
||||
arg_print_errors(stderr, iperf_args.end, argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* iperf -a */
|
||||
if (iperf_args.abort->count != 0) {
|
||||
iperf_stop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (((iperf_args.ip->count == 0) && (iperf_args.server->count == 0)) ||
|
||||
((iperf_args.ip->count != 0) && (iperf_args.server->count != 0))) {
|
||||
ESP_LOGE(__func__, "Wrong mode! ESP32 should run in client or server mode");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* iperf -s */
|
||||
if (iperf_args.ip->count == 0) {
|
||||
cfg.flag |= IPERF_FLAG_SERVER;
|
||||
}
|
||||
/* iperf -c SERVER_ADDRESS */
|
||||
else {
|
||||
cfg.destination_ip4 = esp_ip4addr_aton(iperf_args.ip->sval[0]);
|
||||
cfg.flag |= IPERF_FLAG_CLIENT;
|
||||
}
|
||||
|
||||
if (iperf_args.length->count == 0) {
|
||||
cfg.len_send_buf = 0;
|
||||
} else {
|
||||
cfg.len_send_buf = iperf_args.length->ival[0];
|
||||
}
|
||||
|
||||
cfg.source_ip4 = INADDR_ANY;
|
||||
|
||||
/* iperf -u */
|
||||
if (iperf_args.udp->count == 0) {
|
||||
cfg.flag |= IPERF_FLAG_TCP;
|
||||
} else {
|
||||
cfg.flag |= IPERF_FLAG_UDP;
|
||||
}
|
||||
|
||||
/* iperf -p */
|
||||
if (iperf_args.port->count == 0) {
|
||||
cfg.sport = IPERF_DEFAULT_PORT;
|
||||
cfg.dport = IPERF_DEFAULT_PORT;
|
||||
} else {
|
||||
if (cfg.flag & IPERF_FLAG_SERVER) {
|
||||
cfg.sport = iperf_args.port->ival[0];
|
||||
cfg.dport = IPERF_DEFAULT_PORT;
|
||||
} else {
|
||||
cfg.sport = IPERF_DEFAULT_PORT;
|
||||
cfg.dport = iperf_args.port->ival[0];
|
||||
}
|
||||
}
|
||||
|
||||
/* iperf -i */
|
||||
if (iperf_args.interval->count == 0) {
|
||||
cfg.interval = IPERF_DEFAULT_INTERVAL;
|
||||
} else {
|
||||
cfg.interval = iperf_args.interval->ival[0];
|
||||
if (cfg.interval <= 0) {
|
||||
cfg.interval = IPERF_DEFAULT_INTERVAL;
|
||||
}
|
||||
}
|
||||
|
||||
/* iperf -t */
|
||||
if (iperf_args.time->count == 0) {
|
||||
cfg.time = IPERF_DEFAULT_TIME;
|
||||
} else {
|
||||
cfg.time = iperf_args.time->ival[0];
|
||||
if (cfg.time <= cfg.interval) {
|
||||
cfg.time = cfg.interval;
|
||||
}
|
||||
}
|
||||
|
||||
/* iperf -b */
|
||||
if (iperf_args.bw_limit->count == 0) {
|
||||
cfg.bw_lim = IPERF_DEFAULT_NO_BW_LIMIT;
|
||||
} else {
|
||||
cfg.bw_lim = iperf_args.bw_limit->ival[0];
|
||||
if (cfg.bw_lim <= 0) {
|
||||
cfg.bw_lim = IPERF_DEFAULT_NO_BW_LIMIT;
|
||||
}
|
||||
}
|
||||
|
||||
printf("mode=%s-%s sip=" IPSTR ":%" PRIu16 ", dip=%" PRIu32 ".%" PRIu32 ".%" PRIu32 ".%" PRIu32 ":%" PRIu16 ", interval=%" PRIu32 ", time=%" PRIu32 "\r\n",
|
||||
cfg.flag & IPERF_FLAG_TCP ? "tcp" : "udp",
|
||||
cfg.flag & IPERF_FLAG_SERVER ? "server" : "client",
|
||||
(uint16_t) cfg.source_ip4 & 0xFF,
|
||||
(uint16_t) (cfg.source_ip4 >> 8) & 0xFF,
|
||||
(uint16_t) (cfg.source_ip4 >> 16) & 0xFF,
|
||||
(uint16_t) (cfg.source_ip4 >> 24) & 0xFF,
|
||||
cfg.sport,
|
||||
cfg.destination_ip4 & 0xFF, (cfg.destination_ip4 >> 8) & 0xFF,
|
||||
(cfg.destination_ip4 >> 16) & 0xFF, (cfg.destination_ip4 >> 24) & 0xFF, cfg.dport,
|
||||
cfg.interval, cfg.time);
|
||||
|
||||
iperf_start(&cfg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void register_iperf(void)
|
||||
{
|
||||
|
||||
iperf_args.ip = arg_str0("c", "client", "<ip>",
|
||||
"run in client mode, connecting to <host>");
|
||||
iperf_args.server = arg_lit0("s", "server", "run in server mode");
|
||||
iperf_args.udp = arg_lit0("u", "udp", "use UDP rather than TCP");
|
||||
iperf_args.version = arg_lit0("V", "ipv6_domain", "use IPV6 address rather than IPV4");
|
||||
iperf_args.port = arg_int0("p", "port", "<port>",
|
||||
"server port to listen on/connect to");
|
||||
iperf_args.length = arg_int0("l", "len", "<length>", "set read/write buffer size");
|
||||
iperf_args.interval = arg_int0("i", "interval", "<interval>",
|
||||
"seconds between periodic bandwidth reports");
|
||||
iperf_args.time = arg_int0("t", "time", "<time>", "time in seconds to transmit for (default 10 secs)");
|
||||
iperf_args.bw_limit = arg_int0("b", "bandwidth", "<bandwidth>", "bandwidth to send at in Mbits/sec");
|
||||
iperf_args.abort = arg_lit0("a", "abort", "abort running iperf");
|
||||
iperf_args.end = arg_end(1);
|
||||
const esp_console_cmd_t iperf_cmd = {
|
||||
.command = "iperf",
|
||||
.help = "iperf command",
|
||||
.hint = NULL,
|
||||
.func = &ppp_cmd_iperf,
|
||||
.argtable = &iperf_args
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&iperf_cmd));
|
||||
}
|
1
components/eppp_link/examples/host/sdkconfig.ci.spi
Normal file
1
components/eppp_link/examples/host/sdkconfig.ci.spi
Normal file
@ -0,0 +1 @@
|
||||
CONFIG_EPPP_LINK_DEVICE_SPI=y
|
1
components/eppp_link/examples/host/sdkconfig.ci.uart
Normal file
1
components/eppp_link/examples/host/sdkconfig.ci.uart
Normal file
@ -0,0 +1 @@
|
||||
CONFIG_EPPP_LINK_DEVICE_UART=y
|
4
components/eppp_link/examples/host/sdkconfig.defaults
Normal file
4
components/eppp_link/examples/host/sdkconfig.defaults
Normal file
@ -0,0 +1,4 @@
|
||||
CONFIG_LWIP_PPP_SUPPORT=y
|
||||
CONFIG_LWIP_PPP_SERVER_SUPPORT=y
|
||||
CONFIG_LWIP_PPP_VJ_HEADER_COMPRESSION=n
|
||||
CONFIG_LWIP_PPP_DEBUG_ON=y
|
6
components/eppp_link/examples/slave/CMakeLists.txt
Normal file
6
components/eppp_link/examples/slave/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
||||
# 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(pppos_slave)
|
7
components/eppp_link/examples/slave/README.md
Normal file
7
components/eppp_link/examples/slave/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
# Wi-Fi station to PPPoS server
|
||||
|
||||
This example demonstrate using NAPT to bring connectivity from WiFi station to PPPoS server.
|
||||
|
||||
This example expect a PPPoS client to connect to the server and use the connectivity.
|
||||
The client could be a Linux computer with `pppd` service or another microcontroller with PPP client (or another ESP32 with not WiFi interface)
|
2
components/eppp_link/examples/slave/main/CMakeLists.txt
Normal file
2
components/eppp_link/examples/slave/main/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "eppp_slave.c"
|
||||
INCLUDE_DIRS ".")
|
45
components/eppp_link/examples/slave/main/Kconfig.projbuild
Normal file
45
components/eppp_link/examples/slave/main/Kconfig.projbuild
Normal file
@ -0,0 +1,45 @@
|
||||
menu "Example Configuration"
|
||||
|
||||
config ESP_WIFI_SSID
|
||||
string "WiFi SSID"
|
||||
default "myssid"
|
||||
help
|
||||
SSID (network name) for the example to connect to.
|
||||
|
||||
config ESP_WIFI_PASSWORD
|
||||
string "WiFi Password"
|
||||
default "mypassword"
|
||||
help
|
||||
WiFi password (WPA or WPA2) for the example to use.
|
||||
|
||||
config ESP_MAXIMUM_RETRY
|
||||
int "Maximum retry"
|
||||
default 5
|
||||
help
|
||||
Set the Maximum retry to avoid station reconnecting to the AP unlimited when the AP is really inexistent.
|
||||
|
||||
config EXAMPLE_UART_TX_PIN
|
||||
int "TXD Pin Number"
|
||||
depends on EPPP_LINK_DEVICE_UART
|
||||
default 11
|
||||
range 0 31
|
||||
help
|
||||
Pin number of UART TX.
|
||||
|
||||
config EXAMPLE_UART_RX_PIN
|
||||
int "RXD Pin Number"
|
||||
depends on EPPP_LINK_DEVICE_UART
|
||||
default 10
|
||||
range 0 31
|
||||
help
|
||||
Pin number of UART RX.
|
||||
|
||||
config EXAMPLE_UART_BAUDRATE
|
||||
int "Baudrate"
|
||||
depends on EPPP_LINK_DEVICE_UART
|
||||
default 2000000
|
||||
range 0 4000000
|
||||
help
|
||||
Baudrate used by the PPP over UART
|
||||
|
||||
endmenu
|
147
components/eppp_link/examples/slave/main/eppp_slave.c
Normal file
147
components/eppp_link/examples/slave/main/eppp_slave.c
Normal file
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "eppp_link.h"
|
||||
|
||||
static const char *TAG = "eppp_slave";
|
||||
|
||||
#if CONFIG_SOC_WIFI_SUPPORTED
|
||||
|
||||
/* FreeRTOS event group to signal when we are connected*/
|
||||
static EventGroupHandle_t s_wifi_event_group;
|
||||
|
||||
/* The event group allows multiple bits for each event, but we only care about two events:
|
||||
* - we are connected to the AP with an IP
|
||||
* - we failed to connect after the maximum amount of retries */
|
||||
#define WIFI_CONNECTED_BIT BIT0
|
||||
#define WIFI_FAIL_BIT BIT1
|
||||
|
||||
|
||||
static int s_retry_num = 0;
|
||||
|
||||
static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
|
||||
{
|
||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
|
||||
esp_wifi_connect();
|
||||
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
||||
if (s_retry_num < CONFIG_ESP_MAXIMUM_RETRY) {
|
||||
esp_wifi_connect();
|
||||
s_retry_num++;
|
||||
ESP_LOGI(TAG, "retry to connect to the AP");
|
||||
} else {
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
|
||||
}
|
||||
ESP_LOGI(TAG, "connect to the AP fail");
|
||||
} else 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));
|
||||
s_retry_num = 0;
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
void init_network_interface(void)
|
||||
{
|
||||
s_wifi_event_group = xEventGroupCreate();
|
||||
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
esp_netif_create_default_wifi_sta();
|
||||
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
|
||||
esp_event_handler_instance_t instance_any_id;
|
||||
esp_event_handler_instance_t instance_got_ip;
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
|
||||
ESP_EVENT_ANY_ID,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_any_id));
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
|
||||
IP_EVENT_STA_GOT_IP,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_got_ip));
|
||||
|
||||
wifi_config_t wifi_config = {
|
||||
.sta = {
|
||||
.ssid = CONFIG_ESP_WIFI_SSID,
|
||||
.password = CONFIG_ESP_WIFI_PASSWORD,
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) );
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
|
||||
ESP_ERROR_CHECK(esp_wifi_start() );
|
||||
|
||||
ESP_LOGI(TAG, "wifi_init_sta finished.");
|
||||
|
||||
/* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum
|
||||
* number of re-tries (WIFI_FAIL_BIT). The bits are set by event_handler() (see above) */
|
||||
EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group,
|
||||
WIFI_CONNECTED_BIT | WIFI_FAIL_BIT,
|
||||
pdFALSE,
|
||||
pdFALSE,
|
||||
portMAX_DELAY);
|
||||
|
||||
/* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
|
||||
* happened. */
|
||||
if (bits & WIFI_CONNECTED_BIT) {
|
||||
ESP_LOGI(TAG, "connected to ap SSID:%s password:%s",
|
||||
CONFIG_ESP_WIFI_SSID, CONFIG_ESP_WIFI_PASSWORD);
|
||||
} else if (bits & WIFI_FAIL_BIT) {
|
||||
ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s",
|
||||
CONFIG_ESP_WIFI_SSID, CONFIG_ESP_WIFI_PASSWORD);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "UNEXPECTED EVENT");
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
void init_network_interface(void)
|
||||
{
|
||||
// placeholder to initialize any other network interface if WiFi is not available
|
||||
}
|
||||
|
||||
#endif // SoC WiFi capable chip
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
//Initialize NVS
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
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);
|
||||
|
||||
init_network_interface(); // WiFi station if withing SoC capabilities (otherwise a placeholder)
|
||||
|
||||
eppp_config_t config = EPPP_DEFAULT_SERVER_CONFIG();
|
||||
#if CONFIG_EPPP_LINK_DEVICE_SPI
|
||||
config.transport = EPPP_TRANSPORT_SPI;
|
||||
#else
|
||||
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;
|
||||
#endif
|
||||
esp_netif_t *eppp_netif = eppp_listen(&config);
|
||||
if (eppp_netif == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to setup connection");
|
||||
return ;
|
||||
}
|
||||
ESP_ERROR_CHECK(esp_netif_napt_enable(eppp_netif));
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
dependencies:
|
||||
espressif/eppp_link:
|
||||
version: "*"
|
||||
override_path: "../../.."
|
1
components/eppp_link/examples/slave/sdkconfig.ci.spi
Normal file
1
components/eppp_link/examples/slave/sdkconfig.ci.spi
Normal file
@ -0,0 +1 @@
|
||||
CONFIG_EPPP_LINK_DEVICE_SPI=y
|
1
components/eppp_link/examples/slave/sdkconfig.ci.uart
Normal file
1
components/eppp_link/examples/slave/sdkconfig.ci.uart
Normal file
@ -0,0 +1 @@
|
||||
CONFIG_EPPP_LINK_DEVICE_UART=y
|
6
components/eppp_link/examples/slave/sdkconfig.defaults
Normal file
6
components/eppp_link/examples/slave/sdkconfig.defaults
Normal file
@ -0,0 +1,6 @@
|
||||
CONFIG_LWIP_IP_FORWARD=y
|
||||
CONFIG_LWIP_IPV4_NAPT=y
|
||||
CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=4096
|
||||
CONFIG_LWIP_PPP_SUPPORT=y
|
||||
CONFIG_LWIP_PPP_SERVER_SUPPORT=y
|
||||
CONFIG_LWIP_PPP_VJ_HEADER_COMPRESSION=n
|
6
components/eppp_link/idf_component.yml
Normal file
6
components/eppp_link/idf_component.yml
Normal file
@ -0,0 +1,6 @@
|
||||
version: 0.0.1
|
||||
url: https://github.com/espressif/esp-protocols/tree/master/components/eppp_link
|
||||
description: The component provides a general purpose PPP connectivity, typically used as WiFi-PPP router
|
||||
dependencies:
|
||||
idf:
|
||||
version: '>=5.2'
|
111
components/eppp_link/include/eppp_link.h
Normal file
111
components/eppp_link/include/eppp_link.h
Normal file
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define EPPP_DEFAULT_SERVER_IP() ESP_IP4TOADDR(192, 168, 11, 1)
|
||||
#define EPPP_DEFAULT_CLIENT_IP() ESP_IP4TOADDR(192, 168, 11, 2)
|
||||
|
||||
#define EPPP_DEFAULT_CONFIG(our_ip, their_ip) { \
|
||||
.transport = EPPP_TRANSPORT_UART, \
|
||||
.spi = { \
|
||||
.host = 1, \
|
||||
.mosi = 11, \
|
||||
.miso = 13, \
|
||||
.sclk = 12, \
|
||||
.cs = 10, \
|
||||
.intr = 2, \
|
||||
.freq = 16*1000*1000, \
|
||||
.input_delay_ns = 0, \
|
||||
.cs_ena_pretrans = 0, \
|
||||
.cs_ena_posttrans = 0, \
|
||||
}, \
|
||||
.uart = { \
|
||||
.port = 1, \
|
||||
.baud = 921600, \
|
||||
.tx_io = 25, \
|
||||
.rx_io = 26, \
|
||||
.queue_size = 16, \
|
||||
.rx_buffer_size = 1024, \
|
||||
}, \
|
||||
. task = { \
|
||||
.run_task = true, \
|
||||
.stack_size = 4096, \
|
||||
.priority = 8, \
|
||||
}, \
|
||||
. ppp = { \
|
||||
.our_ip4_addr.addr = our_ip, \
|
||||
.their_ip4_addr.addr = their_ip, \
|
||||
} \
|
||||
}
|
||||
|
||||
#define EPPP_DEFAULT_SERVER_CONFIG() EPPP_DEFAULT_CONFIG(EPPP_DEFAULT_SERVER_IP(), EPPP_DEFAULT_CLIENT_IP())
|
||||
#define EPPP_DEFAULT_CLIENT_CONFIG() EPPP_DEFAULT_CONFIG(EPPP_DEFAULT_CLIENT_IP(), EPPP_DEFAULT_SERVER_IP())
|
||||
|
||||
typedef enum eppp_type {
|
||||
EPPP_SERVER,
|
||||
EPPP_CLIENT,
|
||||
} eppp_type_t;
|
||||
|
||||
typedef enum eppp_transport {
|
||||
EPPP_TRANSPORT_UART,
|
||||
EPPP_TRANSPORT_SPI,
|
||||
} eppp_transport_t;
|
||||
|
||||
|
||||
typedef struct eppp_config_t {
|
||||
eppp_transport_t transport;
|
||||
|
||||
struct eppp_config_spi_s {
|
||||
int host;
|
||||
int mosi;
|
||||
int miso;
|
||||
int sclk;
|
||||
int cs;
|
||||
int intr;
|
||||
int freq;
|
||||
int input_delay_ns;
|
||||
int cs_ena_pretrans;
|
||||
int cs_ena_posttrans;
|
||||
} spi;
|
||||
|
||||
struct eppp_config_uart_s {
|
||||
int port;
|
||||
int baud;
|
||||
int tx_io;
|
||||
int rx_io;
|
||||
int queue_size;
|
||||
int rx_buffer_size;
|
||||
} uart;
|
||||
|
||||
struct eppp_config_task_s {
|
||||
bool run_task;
|
||||
int stack_size;
|
||||
int priority;
|
||||
} task;
|
||||
|
||||
struct eppp_config_pppos_s {
|
||||
esp_ip4_addr_t our_ip4_addr;
|
||||
esp_ip4_addr_t their_ip4_addr;
|
||||
} ppp;
|
||||
|
||||
} eppp_config_t;
|
||||
|
||||
esp_netif_t *eppp_connect(eppp_config_t *config);
|
||||
|
||||
esp_netif_t *eppp_listen(eppp_config_t *config);
|
||||
|
||||
void eppp_close(esp_netif_t *netif);
|
||||
|
||||
esp_netif_t *eppp_init(eppp_type_t role, eppp_config_t *config);
|
||||
|
||||
void eppp_deinit(esp_netif_t *netif);
|
||||
|
||||
esp_netif_t *eppp_open(eppp_type_t role, eppp_config_t *config, int connect_timeout_ms);
|
||||
|
||||
esp_err_t eppp_netif_stop(esp_netif_t *netif, int stop_timeout_ms);
|
||||
|
||||
esp_err_t eppp_netif_start(esp_netif_t *netif);
|
||||
|
||||
esp_err_t eppp_perform(esp_netif_t *netif);
|
7
components/eppp_link/test/test_app/CMakeLists.txt
Normal file
7
components/eppp_link/test/test_app/CMakeLists.txt
Normal file
@ -0,0 +1,7 @@
|
||||
# The following four 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)
|
||||
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/tools/unit-test-app/components)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(test_app)
|
73
components/eppp_link/test/test_app/README.md
Normal file
73
components/eppp_link/test/test_app/README.md
Normal file
@ -0,0 +1,73 @@
|
||||
|
||||
# Test application running both server and client on the same device
|
||||
|
||||
Need to connect client's Tx to server's Rx and vice versa:
|
||||
GPIO25 - GPIO4
|
||||
GPIO26 - GPIO5
|
||||
|
||||
We wait for the connection and then we start pinging the client's address on server's netif.
|
||||
|
||||
## Example of output:
|
||||
|
||||
```
|
||||
I (393) eppp_test_app: [APP] Startup..
|
||||
I (393) eppp_test_app: [APP] Free memory: 296332 bytes
|
||||
I (393) eppp_test_app: [APP] IDF version: v5.3-dev-1154-gf14d9e7431-dirty
|
||||
I (423) uart: ESP_INTR_FLAG_IRAM flag not set while CONFIG_UART_ISR_IN_IRAM is enabled, flag updated
|
||||
I (423) uart: queue free spaces: 16
|
||||
I (433) eppp_link: Waiting for IP address
|
||||
I (433) uart: ESP_INTR_FLAG_IRAM flag not set while CONFIG_UART_ISR_IN_IRAM is enabled, flag updated
|
||||
I (443) uart: queue free spaces: 16
|
||||
I (443) eppp_link: Waiting for IP address
|
||||
I (6473) esp-netif_lwip-ppp: Connected
|
||||
I (6513) eppp_link: Got IPv4 event: Interface "pppos_client" address: 192.168.11.2
|
||||
I (6523) esp-netif_lwip-ppp: Connected
|
||||
I (6513) eppp_link: Connected!
|
||||
I (6523) eppp_link: Got IPv4 event: Interface "pppos_server" address: 192.168.11.1
|
||||
I (6553) main_task: Returned from app_main()
|
||||
64bytes from 192.168.11.2 icmp_seq=1 ttl=255 time=18 ms
|
||||
64bytes from 192.168.11.2 icmp_seq=2 ttl=255 time=19 ms
|
||||
64bytes from 192.168.11.2 icmp_seq=3 ttl=255 time=19 ms
|
||||
64bytes from 192.168.11.2 icmp_seq=4 ttl=255 time=20 ms
|
||||
64bytes from 192.168.11.2 icmp_seq=5 ttl=255 time=19 ms
|
||||
64bytes from 192.168.11.2 icmp_seq=6 ttl=255 time=19 ms
|
||||
64bytes from 192.168.11.2 icmp_seq=7 ttl=255 time=19 ms
|
||||
From 192.168.11.2 icmp_seq=8 timeout // <-- Disconnected Tx-Rx wires
|
||||
From 192.168.11.2 icmp_seq=9 timeout
|
||||
```
|
||||
## Test cases
|
||||
|
||||
This test app exercises these methods of setting up server-client connection:
|
||||
* simple blocking API (eppp_listen() <--> eppp_connect()): Uses network events internally and waits for connection
|
||||
* simplified non-blocking API (eppp_open(EPPP_SERVER, ...) <--> eppp_open(EPPP_SERVER, ...) ): Uses events internally, optionally waits for connecting
|
||||
* manual API (eppp_init(), eppp_netif_start(), eppp_perform()): User to manually drive Rx task
|
||||
- Note that the ping test for this test case takes longer, since we call perform for both server and client from one task, for example:
|
||||
|
||||
```
|
||||
TEST(eppp_test, open_close_taskless)I (28562) uart: ESP_INTR_FLAG_IRAM flag not set while CONFIG_UART_ISR_IN_IRAM is enabled, flag updated
|
||||
I (28572) uart: ESP_INTR_FLAG_IRAM flag not set while CONFIG_UART_ISR_IN_IRAM is enabled, flag updated
|
||||
Note: esp_netif_init() has been called. Until next reset, TCP/IP task will periodicially allocate memory and consume CPU time.
|
||||
I (28602) uart: ESP_INTR_FLAG_IRAM flag not set while CONFIG_UART_ISR_IN_IRAM is enabled, flag updated
|
||||
I (28612) uart: queue free spaces: 16
|
||||
I (28612) uart: ESP_INTR_FLAG_IRAM flag not set while CONFIG_UART_ISR_IN_IRAM is enabled, flag updated
|
||||
I (28622) uart: queue free spaces: 16
|
||||
I (28642) esp-netif_lwip-ppp: Connected
|
||||
I (28642) esp-netif_lwip-ppp: Connected
|
||||
I (28642) test: Got IPv4 event: Interface "pppos_server(EPPP0)" address: 192.168.11.1
|
||||
I (28642) esp-netif_lwip-ppp: Connected
|
||||
I (28652) test: Got IPv4 event: Interface "pppos_client(EPPP1)" address: 192.168.11.2
|
||||
I (28662) esp-netif_lwip-ppp: Connected
|
||||
64bytes from 192.168.11.2 icmp_seq=1 ttl=255 time=93 ms
|
||||
64bytes from 192.168.11.2 icmp_seq=2 ttl=255 time=98 ms
|
||||
64bytes from 192.168.11.2 icmp_seq=3 ttl=255 time=99 ms
|
||||
64bytes from 192.168.11.2 icmp_seq=4 ttl=255 time=99 ms
|
||||
64bytes from 192.168.11.2 icmp_seq=5 ttl=255 time=99 ms
|
||||
5 packets transmitted, 5 received, time 488ms
|
||||
I (29162) esp-netif_lwip-ppp: User interrupt
|
||||
I (29162) test: Disconnected interface "pppos_client(EPPP1)"
|
||||
I (29172) esp-netif_lwip-ppp: User interrupt
|
||||
I (29172) test: Disconnected interface "pppos_server(EPPP0)"
|
||||
MALLOC_CAP_8BIT usage: Free memory delta: 0 Leak threshold: -64
|
||||
MALLOC_CAP_32BIT usage: Free memory delta: 0 Leak threshold: -64
|
||||
PASS
|
||||
```
|
4
components/eppp_link/test/test_app/main/CMakeLists.txt
Normal file
4
components/eppp_link/test/test_app/main/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
||||
idf_component_register(SRCS app_main.c
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES test_utils
|
||||
PRIV_REQUIRES unity nvs_flash esp_netif driver esp_event)
|
344
components/eppp_link/test/test_app/main/app_main.c
Normal file
344
components/eppp_link/test/test_app/main/app_main.c
Normal file
@ -0,0 +1,344 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "esp_system.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_netif.h"
|
||||
#include "esp_netif_ppp.h"
|
||||
#include "eppp_link.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "esp_log.h"
|
||||
#include "ping/ping_sock.h"
|
||||
#include "driver/uart.h"
|
||||
#include "test_utils.h"
|
||||
#include "unity.h"
|
||||
#include "test_utils.h"
|
||||
#include "unity_fixture.h"
|
||||
#include "memory_checks.h"
|
||||
#include "lwip/sys.h"
|
||||
|
||||
#define CLIENT_INFO_CONNECTED BIT0
|
||||
#define CLIENT_INFO_DISCONNECT BIT1
|
||||
#define CLIENT_INFO_CLOSED BIT2
|
||||
#define PING_SUCCEEDED BIT3
|
||||
#define PING_FAILED BIT4
|
||||
#define STOP_WORKER_TASK BIT5
|
||||
#define WORKER_TASK_STOPPED BIT6
|
||||
|
||||
TEST_GROUP(eppp_test);
|
||||
TEST_SETUP(eppp_test)
|
||||
{
|
||||
// Perform some open/close operations to disregard lazy init one-time allocations
|
||||
// LWIP: core protection mutex
|
||||
sys_arch_protect();
|
||||
sys_arch_unprotect(0);
|
||||
// UART: install and delete both drivers to disregard potential leak in allocated interrupt slot
|
||||
TEST_ESP_OK(uart_driver_install(UART_NUM_1, 256, 0, 0, NULL, 0));
|
||||
TEST_ESP_OK(uart_driver_delete(UART_NUM_1));
|
||||
TEST_ESP_OK(uart_driver_install(UART_NUM_2, 256, 0, 0, NULL, 0));
|
||||
TEST_ESP_OK(uart_driver_delete(UART_NUM_2));
|
||||
// PING: used for timestamps
|
||||
struct timeval time;
|
||||
gettimeofday(&time, NULL);
|
||||
|
||||
test_utils_record_free_mem();
|
||||
TEST_ESP_OK(test_utils_set_leak_level(0, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_GENERAL));
|
||||
}
|
||||
|
||||
TEST_TEAR_DOWN(eppp_test)
|
||||
{
|
||||
test_utils_finish_and_evaluate_leaks(32, 64);
|
||||
}
|
||||
|
||||
static void test_on_ping_end(esp_ping_handle_t hdl, void *args)
|
||||
{
|
||||
EventGroupHandle_t event = args;
|
||||
uint32_t transmitted;
|
||||
uint32_t received;
|
||||
uint32_t total_time_ms;
|
||||
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_DURATION, &total_time_ms, sizeof(total_time_ms));
|
||||
printf("%" PRId32 " packets transmitted, %" PRId32 " received, time %" PRId32 "ms\n", transmitted, received, total_time_ms);
|
||||
if (transmitted == received) {
|
||||
xEventGroupSetBits(event, PING_SUCCEEDED);
|
||||
} else {
|
||||
xEventGroupSetBits(event, PING_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_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));
|
||||
printf("%" PRId32 "bytes from %s icmp_seq=%d ttl=%d time=%" PRId32 " ms\n",
|
||||
recv_len, inet_ntoa(target_addr.u_addr.ip4), seqno, ttl, elapsed_time);
|
||||
}
|
||||
|
||||
struct client_info {
|
||||
esp_netif_t *netif;
|
||||
EventGroupHandle_t event;
|
||||
};
|
||||
|
||||
static void open_client_task(void *ctx)
|
||||
{
|
||||
struct client_info *info = ctx;
|
||||
eppp_config_t config = EPPP_DEFAULT_CLIENT_CONFIG();
|
||||
config.uart.port = UART_NUM_2;
|
||||
config.uart.tx_io = 4;
|
||||
config.uart.rx_io = 5;
|
||||
|
||||
info->netif = eppp_connect(&config);
|
||||
xEventGroupSetBits(info->event, CLIENT_INFO_CONNECTED);
|
||||
|
||||
// wait for disconnection trigger
|
||||
EventBits_t bits = xEventGroupWaitBits(info->event, CLIENT_INFO_DISCONNECT, pdFALSE, pdFALSE, pdMS_TO_TICKS(50000));
|
||||
TEST_ASSERT_EQUAL(bits & CLIENT_INFO_DISCONNECT, CLIENT_INFO_DISCONNECT);
|
||||
eppp_close(info->netif);
|
||||
xEventGroupSetBits(info->event, CLIENT_INFO_CLOSED);
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
TEST(eppp_test, init_deinit)
|
||||
{
|
||||
// Init and deinit server size
|
||||
eppp_config_t config = EPPP_DEFAULT_CONFIG(0, 0);
|
||||
esp_netif_t *netif = eppp_init(EPPP_SERVER, &config);
|
||||
TEST_ASSERT_NOT_NULL(netif);
|
||||
eppp_deinit(netif);
|
||||
netif = NULL;
|
||||
// Init and deinit client size
|
||||
netif = eppp_init(EPPP_CLIENT, &config);
|
||||
TEST_ASSERT_NOT_NULL(netif);
|
||||
eppp_deinit(netif);
|
||||
}
|
||||
|
||||
static EventBits_t ping_test(uint32_t addr, esp_netif_t *netif, EventGroupHandle_t event)
|
||||
{
|
||||
ip_addr_t target_addr = { .type = IPADDR_TYPE_V4, .u_addr.ip4.addr = addr };
|
||||
esp_ping_config_t ping_config = ESP_PING_DEFAULT_CONFIG();
|
||||
ping_config.interval_ms = 100;
|
||||
ping_config.target_addr = target_addr;
|
||||
ping_config.interface = esp_netif_get_netif_impl_index(netif);
|
||||
esp_ping_callbacks_t cbs = { .cb_args = event, .on_ping_end = test_on_ping_end, .on_ping_success = test_on_ping_success };
|
||||
esp_ping_handle_t ping;
|
||||
esp_ping_new_session(&ping_config, &cbs, &ping);
|
||||
esp_ping_start(ping);
|
||||
// Wait for the client thread closure and delete locally created objects
|
||||
EventBits_t bits = xEventGroupWaitBits(event, PING_SUCCEEDED | PING_FAILED, pdFALSE, pdFALSE, pdMS_TO_TICKS(50000));
|
||||
TEST_ASSERT_EQUAL(bits & (PING_SUCCEEDED | PING_FAILED), PING_SUCCEEDED);
|
||||
esp_ping_stop(ping);
|
||||
esp_ping_delete_session(ping);
|
||||
return bits;
|
||||
}
|
||||
|
||||
TEST(eppp_test, open_close)
|
||||
{
|
||||
test_case_uses_tcpip();
|
||||
|
||||
eppp_config_t config = EPPP_DEFAULT_SERVER_CONFIG();
|
||||
struct client_info client = { .netif = NULL, .event = xEventGroupCreate()};
|
||||
|
||||
TEST_ESP_OK(esp_event_loop_create_default());
|
||||
|
||||
TEST_ASSERT_NOT_NULL(client.event);
|
||||
|
||||
// Need to connect the client in a separate thread, as the simplified API blocks until connection
|
||||
xTaskCreate(open_client_task, "client_task", 4096, &client, 5, NULL);
|
||||
|
||||
// Now start the server
|
||||
esp_netif_t *eppp_server = eppp_listen(&config);
|
||||
|
||||
// Wait for the client to connect
|
||||
EventBits_t bits = xEventGroupWaitBits(client.event, CLIENT_INFO_CONNECTED, pdFALSE, pdFALSE, pdMS_TO_TICKS(50000));
|
||||
TEST_ASSERT_EQUAL(bits & CLIENT_INFO_CONNECTED, CLIENT_INFO_CONNECTED);
|
||||
|
||||
// Check that both server and client are valid netif pointers
|
||||
TEST_ASSERT_NOT_NULL(eppp_server);
|
||||
TEST_ASSERT_NOT_NULL(client.netif);
|
||||
|
||||
// Now that we're connected, let's try to ping clients address
|
||||
bits = ping_test(config.ppp.their_ip4_addr.addr, eppp_server, client.event);
|
||||
TEST_ASSERT_EQUAL(bits & (PING_SUCCEEDED | PING_FAILED), PING_SUCCEEDED);
|
||||
|
||||
// Trigger client disconnection and close the server
|
||||
xEventGroupSetBits(client.event, CLIENT_INFO_DISCONNECT);
|
||||
eppp_close(eppp_server);
|
||||
|
||||
// Wait for the client thread closure and delete locally created objects
|
||||
bits = xEventGroupWaitBits(client.event, CLIENT_INFO_CLOSED, pdFALSE, pdFALSE, pdMS_TO_TICKS(50000));
|
||||
TEST_ASSERT_EQUAL(bits & CLIENT_INFO_CLOSED, CLIENT_INFO_CLOSED);
|
||||
|
||||
TEST_ESP_OK(esp_event_loop_delete_default());
|
||||
vEventGroupDelete(client.event);
|
||||
|
||||
// wait for the lwip sockets to close cleanly
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
|
||||
static void on_event(void *arg, esp_event_base_t base, int32_t event_id, void *data)
|
||||
{
|
||||
EventGroupHandle_t event = arg;
|
||||
if (base == IP_EVENT && event_id == IP_EVENT_PPP_GOT_IP) {
|
||||
ip_event_got_ip_t *e = (ip_event_got_ip_t *)data;
|
||||
esp_netif_t *netif = e->esp_netif;
|
||||
ESP_LOGI("test", "Got IPv4 event: Interface \"%s(%s)\" address: " IPSTR, esp_netif_get_desc(netif),
|
||||
esp_netif_get_ifkey(netif), IP2STR(&e->ip_info.ip));
|
||||
if (strcmp("pppos_server", esp_netif_get_desc(netif)) == 0) {
|
||||
xEventGroupSetBits(event, 1 << EPPP_SERVER);
|
||||
} else if (strcmp("pppos_client", esp_netif_get_desc(netif)) == 0) {
|
||||
xEventGroupSetBits(event, 1 << EPPP_CLIENT);
|
||||
}
|
||||
} else if (base == NETIF_PPP_STATUS && event_id == NETIF_PPP_ERRORUSER) {
|
||||
esp_netif_t **netif = data;
|
||||
ESP_LOGI("test", "Disconnected interface \"%s(%s)\"", esp_netif_get_desc(*netif), esp_netif_get_ifkey(*netif));
|
||||
if (strcmp("pppos_server", esp_netif_get_desc(*netif)) == 0) {
|
||||
xEventGroupSetBits(event, 1 << EPPP_SERVER);
|
||||
} else if (strcmp("pppos_client", esp_netif_get_desc(*netif)) == 0) {
|
||||
xEventGroupSetBits(event, 1 << EPPP_CLIENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(eppp_test, open_close_nonblocking)
|
||||
{
|
||||
test_case_uses_tcpip();
|
||||
EventGroupHandle_t event = xEventGroupCreate();
|
||||
|
||||
eppp_config_t server_config = EPPP_DEFAULT_SERVER_CONFIG();
|
||||
TEST_ESP_OK(esp_event_loop_create_default());
|
||||
|
||||
// Open the server size
|
||||
TEST_ESP_OK(esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, on_event, event));
|
||||
esp_netif_t *eppp_server = eppp_open(EPPP_SERVER, &server_config, 0);
|
||||
TEST_ASSERT_NOT_NULL(eppp_server);
|
||||
// Open the client size
|
||||
eppp_config_t client_config = EPPP_DEFAULT_SERVER_CONFIG();
|
||||
client_config.uart.port = UART_NUM_2;
|
||||
client_config.uart.tx_io = 4;
|
||||
client_config.uart.rx_io = 5;
|
||||
esp_netif_t *eppp_client = eppp_open(EPPP_CLIENT, &client_config, 0);
|
||||
TEST_ASSERT_NOT_NULL(eppp_client);
|
||||
const EventBits_t wait_bits = (1 << EPPP_SERVER) | (1 << EPPP_CLIENT);
|
||||
EventBits_t bits = xEventGroupWaitBits(event, wait_bits, pdTRUE, pdTRUE, pdMS_TO_TICKS(50000));
|
||||
TEST_ASSERT_EQUAL(bits & wait_bits, wait_bits);
|
||||
|
||||
// Now that we're connected, let's try to ping clients address
|
||||
bits = ping_test(server_config.ppp.their_ip4_addr.addr, eppp_server, event);
|
||||
TEST_ASSERT_EQUAL(bits & (PING_SUCCEEDED | PING_FAILED), PING_SUCCEEDED);
|
||||
|
||||
// stop network for both client and server
|
||||
eppp_netif_stop(eppp_client, 0); // ignore result, since we're not waiting for clean close
|
||||
eppp_close(eppp_server);
|
||||
eppp_close(eppp_client); // finish client close
|
||||
TEST_ESP_OK(esp_event_loop_delete_default());
|
||||
vEventGroupDelete(event);
|
||||
|
||||
// wait for the lwip sockets to close cleanly
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
|
||||
|
||||
struct worker {
|
||||
esp_netif_t *eppp_server;
|
||||
esp_netif_t *eppp_client;
|
||||
EventGroupHandle_t event;
|
||||
};
|
||||
|
||||
static void worker_task(void *ctx)
|
||||
{
|
||||
struct worker *info = ctx;
|
||||
while (1) {
|
||||
eppp_perform(info->eppp_server);
|
||||
eppp_perform(info->eppp_client);
|
||||
if (xEventGroupGetBits(info->event) & STOP_WORKER_TASK) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
xEventGroupSetBits(info->event, WORKER_TASK_STOPPED);
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
TEST(eppp_test, open_close_taskless)
|
||||
{
|
||||
test_case_uses_tcpip();
|
||||
struct worker info = { .event = xEventGroupCreate() };
|
||||
|
||||
TEST_ESP_OK(esp_event_loop_create_default());
|
||||
TEST_ESP_OK(esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, on_event, info.event));
|
||||
TEST_ESP_OK(esp_event_handler_register(NETIF_PPP_STATUS, ESP_EVENT_ANY_ID, on_event, info.event));
|
||||
|
||||
// Create server
|
||||
eppp_config_t server_config = EPPP_DEFAULT_SERVER_CONFIG();
|
||||
info.eppp_server = eppp_init(EPPP_SERVER, &server_config);
|
||||
TEST_ASSERT_NOT_NULL(info.eppp_server);
|
||||
// Create client
|
||||
eppp_config_t client_config = EPPP_DEFAULT_CLIENT_CONFIG();
|
||||
client_config.uart.port = UART_NUM_2;
|
||||
client_config.uart.tx_io = 4;
|
||||
client_config.uart.rx_io = 5;
|
||||
info.eppp_client = eppp_init(EPPP_CLIENT, &client_config);
|
||||
TEST_ASSERT_NOT_NULL(info.eppp_client);
|
||||
// Start workers
|
||||
xTaskCreate(worker_task, "worker", 4096, &info, 5, NULL);
|
||||
// Start network
|
||||
TEST_ESP_OK(eppp_netif_start(info.eppp_server));
|
||||
TEST_ESP_OK(eppp_netif_start(info.eppp_client));
|
||||
|
||||
const EventBits_t wait_bits = (1 << EPPP_SERVER) | (1 << EPPP_CLIENT);
|
||||
EventBits_t bits = xEventGroupWaitBits(info.event, wait_bits, pdTRUE, pdTRUE, pdMS_TO_TICKS(50000));
|
||||
TEST_ASSERT_EQUAL(bits & wait_bits, wait_bits);
|
||||
xEventGroupClearBits(info.event, wait_bits);
|
||||
|
||||
// Now that we're connected, let's try to ping clients address
|
||||
bits = ping_test(server_config.ppp.their_ip4_addr.addr, info.eppp_server, info.event);
|
||||
TEST_ASSERT_EQUAL(bits & (PING_SUCCEEDED | PING_FAILED), PING_SUCCEEDED);
|
||||
|
||||
// stop network for both client and server, we won't wait for completion so expecting ESP_FAIL
|
||||
TEST_ASSERT_EQUAL(eppp_netif_stop(info.eppp_client, 0), ESP_FAIL);
|
||||
TEST_ASSERT_EQUAL(eppp_netif_stop(info.eppp_server, 0), ESP_FAIL);
|
||||
// and wait for completion
|
||||
bits = xEventGroupWaitBits(info.event, wait_bits, pdTRUE, pdTRUE, pdMS_TO_TICKS(50000));
|
||||
TEST_ASSERT_EQUAL(bits & wait_bits, wait_bits);
|
||||
|
||||
// now stop the worker
|
||||
xEventGroupSetBits(info.event, STOP_WORKER_TASK);
|
||||
bits = xEventGroupWaitBits(info.event, WORKER_TASK_STOPPED, pdTRUE, pdTRUE, pdMS_TO_TICKS(50000));
|
||||
TEST_ASSERT_EQUAL(bits & WORKER_TASK_STOPPED, WORKER_TASK_STOPPED);
|
||||
|
||||
// and destroy objects
|
||||
eppp_deinit(info.eppp_server);
|
||||
eppp_deinit(info.eppp_client);
|
||||
TEST_ESP_OK(esp_event_loop_delete_default());
|
||||
vEventGroupDelete(info.event);
|
||||
|
||||
// wait for the lwip sockets to close cleanly
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
|
||||
|
||||
TEST_GROUP_RUNNER(eppp_test)
|
||||
{
|
||||
RUN_TEST_CASE(eppp_test, init_deinit)
|
||||
RUN_TEST_CASE(eppp_test, open_close)
|
||||
RUN_TEST_CASE(eppp_test, open_close_nonblocking)
|
||||
RUN_TEST_CASE(eppp_test, open_close_taskless)
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
UNITY_MAIN(eppp_test);
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
dependencies:
|
||||
espressif/eppp_link:
|
||||
version: "*"
|
||||
override_path: "../../.."
|
9
components/eppp_link/test/test_app/sdkconfig.defaults
Normal file
9
components/eppp_link/test/test_app/sdkconfig.defaults
Normal file
@ -0,0 +1,9 @@
|
||||
CONFIG_IDF_TARGET="esp32"
|
||||
CONFIG_UART_ISR_IN_IRAM=y
|
||||
CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL=0
|
||||
CONFIG_FREERTOS_UNICORE=y
|
||||
CONFIG_LWIP_PPP_SUPPORT=y
|
||||
CONFIG_LWIP_PPP_SERVER_SUPPORT=y
|
||||
CONFIG_LWIP_PPP_VJ_HEADER_COMPRESSION=n
|
||||
CONFIG_LWIP_PPP_DEBUG_ON=y
|
||||
CONFIG_UNITY_ENABLE_FIXTURE=y
|
@ -3,6 +3,6 @@ commitizen:
|
||||
bump_message: 'bump(modem): $current_version -> $new_version'
|
||||
pre_bump_hooks: python ../../ci/changelog.py esp_modem
|
||||
tag_format: modem-v$version
|
||||
version: 1.0.5
|
||||
version: 1.1.0
|
||||
version_files:
|
||||
- idf_component.yml
|
||||
|
@ -1,5 +1,28 @@
|
||||
# Changelog
|
||||
|
||||
## [1.1.0](https://github.com/espressif/esp-protocols/commits/modem-v1.1.0)
|
||||
|
||||
### Features
|
||||
|
||||
- Added support for at_raw() command ([ae38110](https://github.com/espressif/esp-protocols/commit/ae38110), [#471](https://github.com/espressif/esp-protocols/issues/471))
|
||||
- Added iperf test for PPP netifs ([976e98d](https://github.com/espressif/esp-protocols/commit/976e98d))
|
||||
- Added test that performs OTA to exercise modem layers ([f2223dd](https://github.com/espressif/esp-protocols/commit/f2223dd))
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Fixed OTA test to gracefully fail with no verification ([1dc4299](https://github.com/espressif/esp-protocols/commit/1dc4299))
|
||||
- Added C-API to configure APN ([ce7dadd](https://github.com/espressif/esp-protocols/commit/ce7dadd), [#485](https://github.com/espressif/esp-protocols/issues/485))
|
||||
- Fixed AT commands to copy strings to prevent overrides ([741d166](https://github.com/espressif/esp-protocols/commit/741d166), [#463](https://github.com/espressif/esp-protocols/issues/463))
|
||||
- Fixed incorrect dial command format ([0998f3d](https://github.com/espressif/esp-protocols/commit/0998f3d), [#433](https://github.com/espressif/esp-protocols/issues/433))
|
||||
- Fixed documentation and example on creating custom device ([577de67](https://github.com/espressif/esp-protocols/commit/577de67), [#452](https://github.com/espressif/esp-protocols/issues/452))
|
||||
- Removed CI jobs for IDF v4.2 ([d88cd61](https://github.com/espressif/esp-protocols/commit/d88cd61))
|
||||
- Fixed OAT test to verify server cert and CN ([edc3e72](https://github.com/espressif/esp-protocols/commit/edc3e72))
|
||||
- Fixed set_pdp_context() command timeout ([1d80cbc](https://github.com/espressif/esp-protocols/commit/1d80cbc), [#455](https://github.com/espressif/esp-protocols/issues/455))
|
||||
|
||||
### Updated
|
||||
|
||||
- docs(modem): Added description of manual test procedure ([68ce794](https://github.com/espressif/esp-protocols/commit/68ce794))
|
||||
|
||||
## [1.0.5](https://github.com/espressif/esp-protocols/commits/modem-v1.0.5)
|
||||
|
||||
### Major changes
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@ -17,26 +17,20 @@
|
||||
#include "cxx_include/esp_modem_dce_module.hpp"
|
||||
|
||||
/**
|
||||
* @brief Definition of a custom modem which inherits from the GenericModule, uses all its methods
|
||||
* and could override any of them. Here, for demonstration purposes only, we redefine just `get_module_name()`
|
||||
* @brief Definition of a custom DCE uses GenericModule and all its methods
|
||||
* but could override command processing. Here, for demonstration purposes only,
|
||||
* we "inject" URC handler to the actual command processing.
|
||||
* This is possible since we inherit from `CommandableIf` and redefine `command()` method.
|
||||
* Then we're able to use declare all common methods from the command library
|
||||
* to be processed using "our" `command()` method (with custom URC handler).
|
||||
*/
|
||||
class MyShinyModem: public esp_modem::GenericModule {
|
||||
using GenericModule::GenericModule;
|
||||
public:
|
||||
esp_modem::command_result get_module_name(std::string &name) override
|
||||
{
|
||||
name = "Custom Shiny Module";
|
||||
return esp_modem::command_result::OK;
|
||||
}
|
||||
};
|
||||
|
||||
namespace Shiny {
|
||||
|
||||
using namespace esp_modem;
|
||||
|
||||
class DCE : public esp_modem::DCE_T<MyShinyModem>, public CommandableIf {
|
||||
class DCE : public esp_modem::DCE_T<GenericModule>, public CommandableIf {
|
||||
public:
|
||||
using DCE_T<MyShinyModem>::DCE_T;
|
||||
using DCE_T<GenericModule>::DCE_T;
|
||||
|
||||
command_result
|
||||
command(const std::string &cmd, got_line_cb got_line, uint32_t time_ms) override
|
||||
@ -97,7 +91,7 @@ public:
|
||||
std::shared_ptr<esp_modem::DTE> dte,
|
||||
esp_netif_t *netif)
|
||||
{
|
||||
return build_generic_DCE<MyShinyModem, DCE, std::unique_ptr<DCE>>(config, std::move(dte), netif);
|
||||
return build_generic_DCE<GenericModule, DCE, std::unique_ptr<DCE>>(config, std::move(dte), netif);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -29,6 +29,7 @@ public:
|
||||
int read(unsigned char *buf, size_t len);
|
||||
[[nodiscard]] bool set_own_cert(const_buf crt, const_buf key);
|
||||
[[nodiscard]] bool set_ca_cert(const_buf crt);
|
||||
bool set_hostname(const char *name);
|
||||
virtual int send(const unsigned char *buf, size_t len) = 0;
|
||||
virtual int recv(unsigned char *buf, size_t len) = 0;
|
||||
size_t get_available_bytes();
|
||||
|
@ -116,6 +116,16 @@ bool Tls::set_ca_cert(const_buf crt)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Tls::set_hostname(const char *name)
|
||||
{
|
||||
int ret = mbedtls_ssl_set_hostname(&ssl_, name);
|
||||
if (ret < 0) {
|
||||
print_error("mbedtls_ssl_set_hostname", ret);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Tls::Tls()
|
||||
{
|
||||
mbedtls_x509_crt_init(&public_cert_);
|
||||
|
@ -1,4 +1,4 @@
|
||||
version: "1.0.5"
|
||||
version: "1.1.0"
|
||||
description: Library for communicating with cellular modems in command and data modes
|
||||
url: https://github.com/espressif/esp-protocols/tree/master/components/esp_modem
|
||||
issues: https://github.com/espressif/esp-protocols/issues
|
||||
|
@ -54,7 +54,7 @@ command_result power_down_sim76xx(CommandableIf *t);
|
||||
command_result power_down_sim70xx(CommandableIf *t);
|
||||
command_result set_network_bands_sim76xx(CommandableIf *t, const std::string &mode, const int *bands, int size);
|
||||
command_result power_down_sim8xx(CommandableIf *t);
|
||||
command_result set_data_mode_sim8xx(CommandableIf *t);
|
||||
command_result set_data_mode_alt(CommandableIf *t);
|
||||
command_result set_pdp_context(CommandableIf *t, PdpContext &pdp, uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -25,18 +25,16 @@ command_result generic_command(CommandableIf *t, const std::string &command,
|
||||
* @brief Utility command to send command and return reply (after DCE says OK)
|
||||
* @param t Anything that is "command-able"
|
||||
* @param command Command to issue
|
||||
* @param output String to return
|
||||
* @param timeout_ms
|
||||
* @param output String to return (could be either std::string& or std::string_view&)
|
||||
* @param timeout_ms Command timeout in ms
|
||||
* @return Generic command return type (OK, FAIL, TIMEOUT)
|
||||
*/
|
||||
command_result generic_get_string(CommandableIf *t, const std::string &command, std::string &output, uint32_t timeout_ms = 500);
|
||||
template <typename T> command_result generic_get_string(CommandableIf *t, const std::string &command, T &output, uint32_t timeout_ms = 500);
|
||||
|
||||
/**
|
||||
* @brief Generic command that passes on "OK" and fails on "ERROR"
|
||||
* @param t Anything that is "command-able"
|
||||
* @param command Command to issue
|
||||
* @param timeout
|
||||
* @param timeout_ms Command timeout in ms
|
||||
* @return Generic command return type (OK, FAIL, TIMEOUT)
|
||||
*/
|
||||
|
@ -144,6 +144,8 @@ class SIM7070: public GenericModule {
|
||||
using GenericModule::GenericModule;
|
||||
public:
|
||||
command_result power_down() override;
|
||||
command_result set_data_mode() override;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@ -162,7 +164,6 @@ class SIM800: public GenericModule {
|
||||
using GenericModule::GenericModule;
|
||||
public:
|
||||
command_result power_down() override;
|
||||
command_result set_data_mode() override;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -119,8 +119,27 @@ esp_err_t esp_modem_set_error_cb(esp_modem_dce_t *dce, esp_modem_terminal_error_
|
||||
*/
|
||||
esp_err_t esp_modem_set_mode(esp_modem_dce_t *dce, esp_modem_dce_mode_t mode);
|
||||
|
||||
/**
|
||||
* @brief Convenient function to run arbitrary commands from C-API
|
||||
*
|
||||
* @param dce Modem DCE handle
|
||||
* @param command Command to send
|
||||
* @param got_line_cb Callback function which is called whenever we receive a line
|
||||
* @param timeout_ms Command timeout
|
||||
* @return ESP_OK on success, ESP_FAIL on failure
|
||||
*/
|
||||
|
||||
esp_err_t esp_modem_command(esp_modem_dce_t *dce, const char *command, esp_err_t(*got_line_cb)(uint8_t *data, size_t len), uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Sets the APN and configures it into the modem's PDP context
|
||||
*
|
||||
* @param dce Modem DCE handle
|
||||
* @param apn Access Point Name
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t esp_modem_set_apn(esp_modem_dce_t *dce, const char *apn);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
@ -44,6 +44,18 @@ ESP_MODEM_DECLARE_DCE_COMMAND(store_profile, command_result, 0) \
|
||||
*/\
|
||||
ESP_MODEM_DECLARE_DCE_COMMAND(set_pin, command_result, 1, STRING_IN(p1, pin)) \
|
||||
\
|
||||
/**
|
||||
* @brief Execute the supplied AT command in raw mode (doesn't append '\r' to command, returns everything)
|
||||
* @param[in] cmd String command that's send to DTE
|
||||
* @param[out] out Raw output from DTE
|
||||
* @param[in] pass Pattern in response for the API to return OK
|
||||
* @param[in] fail Pattern in response for the API to return FAIL
|
||||
* @param[in] cmd String command that's send to DTE
|
||||
* @param[in] timeout AT command timeout in milliseconds
|
||||
* @return OK, FAIL or TIMEOUT
|
||||
*/\
|
||||
ESP_MODEM_DECLARE_DCE_COMMAND(at_raw, command_result, 5, STRING_IN(p1, cmd), STRING_OUT(p2, out), STRING_IN(p3, pass), STRING_IN(p4, fail), INT_IN(p5, timeout)) \
|
||||
\
|
||||
/**
|
||||
* @brief Execute the supplied AT command
|
||||
* @param[in] cmd AT command
|
||||
|
@ -31,7 +31,7 @@
|
||||
*/
|
||||
struct esp_modem_vfs_uart_creator {
|
||||
const char *dev_name; /*!< VFS device name, e.g. /dev/uart/n */
|
||||
const struct esp_modem_uart_term_config uart; /*!< UART driver init struct */
|
||||
struct esp_modem_uart_term_config uart; /*!< UART driver init struct */
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -17,7 +17,7 @@
|
||||
#include "esp_private/c_api_wrapper.hpp"
|
||||
|
||||
#ifndef ESP_MODEM_C_API_STR_MAX
|
||||
#define ESP_MODEM_C_API_STR_MAX 64
|
||||
#define ESP_MODEM_C_API_STR_MAX 128
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
@ -206,6 +206,20 @@ extern "C" esp_err_t esp_modem_get_imsi(esp_modem_dce_t *dce_wrap, char *p_imsi)
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern "C" esp_err_t esp_modem_at_raw(esp_modem_dce_t *dce_wrap, const char *cmd, char *p_out, const char *pass, const char *fail, int timeout)
|
||||
{
|
||||
if (dce_wrap == nullptr || dce_wrap->dce == nullptr) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
std::string out;
|
||||
auto ret = command_response_to_esp_err(dce_wrap->dce->at_raw(cmd, out, pass, fail, timeout));
|
||||
if ((p_out != NULL) && (!out.empty())) {
|
||||
strlcpy(p_out, out.c_str(), ESP_MODEM_C_API_STR_MAX);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
extern "C" esp_err_t esp_modem_set_flow_control(esp_modem_dce_t *dce_wrap, int dce_flow, int dte_flow)
|
||||
{
|
||||
if (dce_wrap == nullptr || dce_wrap->dce == nullptr) {
|
||||
@ -434,3 +448,10 @@ extern "C" esp_err_t esp_modem_set_baud(esp_modem_dce_t *dce_wrap, int baud)
|
||||
{
|
||||
return command_response_to_esp_err(dce_wrap->dce->set_baud(baud));
|
||||
}
|
||||
|
||||
extern "C" esp_err_t esp_modem_set_apn(esp_modem_dce_t *dce_wrap, const char *apn)
|
||||
{
|
||||
auto new_pdp = std::unique_ptr<PdpContext>(new PdpContext(apn));
|
||||
dce_wrap->dce->get_module()->configure_pdp_context(std::move(new_pdp));
|
||||
return ESP_OK;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -51,7 +51,35 @@ command_result generic_command(CommandableIf *t, const std::string &command,
|
||||
return generic_command(t, command, pass, fail, timeout_ms);
|
||||
}
|
||||
|
||||
static command_result generic_get_string(CommandableIf *t, const std::string &command, std::string_view &output, uint32_t timeout_ms = 500)
|
||||
/*
|
||||
* Purpose of this namespace is to provide different means of assigning the result to a string-like parameter.
|
||||
* By default we assign strings, which comes with an allocation. Alternatively we could take `std::span`
|
||||
* with user's buffer and directly copy the result, thus avoiding allocations (this is not used as of now)
|
||||
*/
|
||||
namespace str_copy {
|
||||
|
||||
bool set(std::string &dest, std::string_view &src)
|
||||
{
|
||||
dest = src;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* This is an example of using std::span output in generic_get_string()
|
||||
bool set(std::span<char> &dest, std::string_view &src)
|
||||
{
|
||||
if (dest.size() >= src.size()) {
|
||||
std::copy(src.begin(), src.end(), dest.data());
|
||||
dest = dest.subspan(0, src.size());
|
||||
return true;
|
||||
}
|
||||
ESP_LOGE(TAG, "Cannot set result of size %d (to span of size %d)", dest.size(), src.size());
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
} // str_copy
|
||||
|
||||
template <typename T> command_result generic_get_string(CommandableIf *t, const std::string &command, T &output, uint32_t timeout_ms)
|
||||
{
|
||||
ESP_LOGV(TAG, "%s", __func__ );
|
||||
return t->command(command, [&](uint8_t *data, size_t len) {
|
||||
@ -70,7 +98,9 @@ static command_result generic_get_string(CommandableIf *t, const std::string &co
|
||||
} else if (token.find("ERROR") != std::string::npos) {
|
||||
return command_result::FAIL;
|
||||
} else if (token.size() > 2) {
|
||||
output = token;
|
||||
if (!str_copy::set(output, token)) {
|
||||
return command_result::FAIL;
|
||||
}
|
||||
}
|
||||
response = response.substr(pos + 1);
|
||||
}
|
||||
@ -78,18 +108,6 @@ static command_result generic_get_string(CommandableIf *t, const std::string &co
|
||||
}, timeout_ms);
|
||||
}
|
||||
|
||||
command_result generic_get_string(CommandableIf *t, const std::string &command, std::string &output, uint32_t timeout_ms)
|
||||
{
|
||||
ESP_LOGV(TAG, "%s", __func__ );
|
||||
std::string_view out;
|
||||
auto ret = generic_get_string(t, command, out, timeout_ms);
|
||||
if (ret == command_result::OK) {
|
||||
output = out;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
command_result generic_command_common(CommandableIf *t, const std::string &command, uint32_t timeout_ms)
|
||||
{
|
||||
ESP_LOGV(TAG, "%s", __func__ );
|
||||
@ -153,7 +171,7 @@ command_result hang_up(CommandableIf *t)
|
||||
command_result get_battery_status(CommandableIf *t, int &voltage, int &bcs, int &bcl)
|
||||
{
|
||||
ESP_LOGV(TAG, "%s", __func__ );
|
||||
std::string_view out;
|
||||
std::string out;
|
||||
auto ret = generic_get_string(t, "AT+CBC\r", out);
|
||||
if (ret != command_result::OK) {
|
||||
return ret;
|
||||
@ -189,7 +207,7 @@ command_result get_battery_status(CommandableIf *t, int &voltage, int &bcs, int
|
||||
command_result get_battery_status_sim7xxx(CommandableIf *t, int &voltage, int &bcs, int &bcl)
|
||||
{
|
||||
ESP_LOGV(TAG, "%s", __func__ );
|
||||
std::string_view out;
|
||||
std::string out;
|
||||
auto ret = generic_get_string(t, "AT+CBC\r", out);
|
||||
if (ret != command_result::OK) {
|
||||
return ret;
|
||||
@ -224,7 +242,7 @@ command_result set_flow_control(CommandableIf *t, int dce_flow, int dte_flow)
|
||||
command_result get_operator_name(CommandableIf *t, std::string &operator_name, int &act)
|
||||
{
|
||||
ESP_LOGV(TAG, "%s", __func__ );
|
||||
std::string_view out;
|
||||
std::string out;
|
||||
auto ret = generic_get_string(t, "AT+COPS?\r", out, 75000);
|
||||
if (ret != command_result::OK) {
|
||||
return ret;
|
||||
@ -277,13 +295,13 @@ command_result set_pdp_context(CommandableIf *t, PdpContext &pdp)
|
||||
command_result set_data_mode(CommandableIf *t)
|
||||
{
|
||||
ESP_LOGV(TAG, "%s", __func__ );
|
||||
return generic_command(t, "ATD*99##\r", "CONNECT", "ERROR", 5000);
|
||||
return generic_command(t, "ATD*99#\r", "CONNECT", "ERROR", 5000);
|
||||
}
|
||||
|
||||
command_result set_data_mode_sim8xx(CommandableIf *t)
|
||||
command_result set_data_mode_alt(CommandableIf *t)
|
||||
{
|
||||
ESP_LOGV(TAG, "%s", __func__ );
|
||||
return generic_command(t, "ATD*99#\r", "CONNECT", "ERROR", 5000);
|
||||
return generic_command(t, "ATD*99##\r", "CONNECT", "ERROR", 5000);
|
||||
}
|
||||
|
||||
command_result resume_data_mode(CommandableIf *t)
|
||||
@ -361,7 +379,7 @@ command_result set_cmux(CommandableIf *t)
|
||||
command_result read_pin(CommandableIf *t, bool &pin_ok)
|
||||
{
|
||||
ESP_LOGV(TAG, "%s", __func__ );
|
||||
std::string_view out;
|
||||
std::string out;
|
||||
auto ret = generic_get_string(t, "AT+CPIN?\r", out);
|
||||
if (ret != command_result::OK) {
|
||||
return ret;
|
||||
@ -394,10 +412,26 @@ command_result at(CommandableIf *t, const std::string &cmd, std::string &out, in
|
||||
return generic_get_string(t, at_command, out, timeout);
|
||||
}
|
||||
|
||||
command_result at_raw(CommandableIf *t, const std::string &cmd, std::string &out, const std::string &pass, const std::string &fail, int timeout = 500)
|
||||
{
|
||||
ESP_LOGV(TAG, "%s", __func__ );
|
||||
return t->command(cmd, [&](uint8_t *data, size_t len) {
|
||||
out.assign(reinterpret_cast<char *>(data), len);
|
||||
|
||||
if (out.find(pass) != std::string::npos) {
|
||||
return command_result::OK;
|
||||
} else if (out.find(fail) != std::string::npos) {
|
||||
return command_result::FAIL;
|
||||
}
|
||||
|
||||
return command_result::TIMEOUT;
|
||||
}, timeout);
|
||||
}
|
||||
|
||||
command_result get_signal_quality(CommandableIf *t, int &rssi, int &ber)
|
||||
{
|
||||
ESP_LOGV(TAG, "%s", __func__ );
|
||||
std::string_view out;
|
||||
std::string out;
|
||||
auto ret = generic_get_string(t, "AT+CSQ\r", out);
|
||||
if (ret != command_result::OK) {
|
||||
return ret;
|
||||
@ -435,7 +469,7 @@ command_result set_network_attachment_state(CommandableIf *t, int state)
|
||||
command_result get_network_attachment_state(CommandableIf *t, int &state)
|
||||
{
|
||||
ESP_LOGV(TAG, "%s", __func__ );
|
||||
std::string_view out;
|
||||
std::string out;
|
||||
auto ret = generic_get_string(t, "AT+CGATT?\r", out);
|
||||
if (ret != command_result::OK) {
|
||||
return ret;
|
||||
@ -462,7 +496,7 @@ command_result set_radio_state(CommandableIf *t, int state)
|
||||
command_result get_radio_state(CommandableIf *t, int &state)
|
||||
{
|
||||
ESP_LOGV(TAG, "%s", __func__ );
|
||||
std::string_view out;
|
||||
std::string out;
|
||||
auto ret = generic_get_string(t, "AT+CFUN?\r", out);
|
||||
if (ret != command_result::OK) {
|
||||
return ret;
|
||||
@ -527,7 +561,7 @@ command_result set_network_bands_sim76xx(CommandableIf *t, const std::string &mo
|
||||
command_result get_network_system_mode(CommandableIf *t, int &mode)
|
||||
{
|
||||
ESP_LOGV(TAG, "%s", __func__ );
|
||||
std::string_view out;
|
||||
std::string out;
|
||||
auto ret = generic_get_string(t, "AT+CNSMOD?\r", out);
|
||||
if (ret != command_result::OK) {
|
||||
return ret;
|
||||
@ -555,7 +589,7 @@ command_result set_gnss_power_mode(CommandableIf *t, int mode)
|
||||
command_result get_gnss_power_mode(CommandableIf *t, int &mode)
|
||||
{
|
||||
ESP_LOGV(TAG, "%s", __func__ );
|
||||
std::string_view out;
|
||||
std::string out;
|
||||
auto ret = generic_get_string(t, "AT+CGNSPWR?\r", out);
|
||||
if (ret != command_result::OK) {
|
||||
return ret;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -67,6 +67,11 @@ command_result SIM7070::power_down()
|
||||
return dce_commands::power_down_sim70xx(dte.get());
|
||||
}
|
||||
|
||||
command_result SIM7070::set_data_mode()
|
||||
{
|
||||
return dce_commands::set_data_mode_alt(dte.get());
|
||||
}
|
||||
|
||||
command_result SIM7000::power_down()
|
||||
{
|
||||
return dce_commands::power_down_sim70xx(dte.get());
|
||||
@ -77,11 +82,6 @@ command_result SIM800::power_down()
|
||||
return dce_commands::power_down_sim8xx(dte.get());
|
||||
}
|
||||
|
||||
command_result SIM800::set_data_mode()
|
||||
{
|
||||
return dce_commands::set_data_mode_sim8xx(dte.get());
|
||||
}
|
||||
|
||||
command_result BG96::set_pdp_context(esp_modem::PdpContext &pdp)
|
||||
{
|
||||
return dce_commands::set_pdp_context(dte.get(), pdp, 300);
|
||||
|
47
components/esp_modem/test/README.md
Normal file
47
components/esp_modem/test/README.md
Normal file
@ -0,0 +1,47 @@
|
||||
# ESP-Modem Testing
|
||||
|
||||
This folder contains automated and manual tests for esp-modem component. Beside these tests, some jobs are executed in CI to exercise standard examples (please refer to the CI definition and CI related sdkconfigs in examples).
|
||||
|
||||
List of test projects:
|
||||
|
||||
* `host_test` -- esp_modem is build on host (linux), modem's terminal in mocked using Loobpack class which creates simple responders to AT and CMUX mode. This test is executed in CI.
|
||||
* `target` -- test executed on target with no modem device, just a pppd running on the test runner. This test is executed in CI.
|
||||
* `target_ota` -- Manual test which perform OTA over PPP.
|
||||
* `target_iperf` -- Manual test to measure data throughput via PPP.
|
||||
|
||||
## Manual testing
|
||||
|
||||
Prior to every `esp_modem` release, these manual tests must be executed and pass
|
||||
(IDF-9074 to move the manual tests to CI)
|
||||
|
||||
### `target_ota`
|
||||
|
||||
Make sure that the UART ISR is not in IRAM, so the error messages are expected in the log, but the ESP32 should recover and continue with downloading the image.
|
||||
|
||||
Perform the test for these devices
|
||||
* SIM7600 (CMUX mode)
|
||||
* BG96 (CMUX mode)
|
||||
* SIM7000 (PPP mode)
|
||||
* A7672 (CMUX mode -- the only device with 2 byte CMUX payload), so the test is expected to fail more often if (`CONFIG_ESP_MODEM_CMUX_DEFRAGMENT_PAYLOAD=y` && `CONFIG_ESP_MODEM_USE_INFLATABLE_BUFFER_IF_NEEDED=n` && dte_buffer < device max payload)
|
||||
* NetworkDCE -- no modem device, pppd (PPP mode)
|
||||
|
||||
Perform the test with these configurations:
|
||||
* CONFIG_TEST_USE_VFS_TERM (y/n)
|
||||
* CONFIG_ESP_HTTP_CLIENT_ENABLE_CUSTOM_TRANSPORT (y/n)
|
||||
* CONFIG_ESP_MODEM_CMUX_DEFRAGMENT_PAYLOAD (y/n)
|
||||
* CONFIG_ESP_MODEM_USE_INFLATABLE_BUFFER_IF_NEEDED (y/n)
|
||||
|
||||
**Criteria for passing the test**
|
||||
|
||||
The test should complete the download with maximum 1 retry (50% of OTA failure)
|
||||
In case of CMUX mode, we're trying to exit CMUX at the end of the test. This step might also fail for some devices, as the CMUX-exit is not supported on certain devices (when the final error message appears that the device failed to exit CMUX, we just verify the new image by reseting the ESP32)
|
||||
|
||||
### `target_iperf`
|
||||
|
||||
Run these 4 `iperf` configurations (either manually or using `pytest`):
|
||||
* tcp_tx_throughput
|
||||
* tcp_rx_throughput
|
||||
* udp_tx_throughput
|
||||
* udp_rx_throughput
|
||||
|
||||
And verify in all four cases the value is about 0.70 Mbps
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@ -36,7 +36,7 @@ int LoopbackTerm::write(uint8_t *data, size_t len)
|
||||
} else if (command == "ATO\r") {
|
||||
response = "ERROR\r\n";
|
||||
} else if (command.find("ATD") != std::string::npos) {
|
||||
response = "CONNECT\r\n";
|
||||
response = "CONNECT\n";
|
||||
} else if (command.find("AT+CSQ\r") != std::string::npos) {
|
||||
response = "+CSQ: 123,456\n\r\nOK\r\n";
|
||||
} else if (command.find("AT+CGMM\r") != std::string::npos) {
|
||||
@ -74,6 +74,9 @@ int LoopbackTerm::write(uint8_t *data, size_t len)
|
||||
}
|
||||
if (len > 2 && data[0] == 0xf9) { // Simple CMUX responder
|
||||
// turn the request into a reply -> implements CMUX loopback
|
||||
// Note: This simple CMUX responder only updates CMUX headers and replaces payload.
|
||||
// It means that all responses (that we test) must be shorter or equal to the requests
|
||||
// For example ATD (dial command): sizeof("ATD*99#") >= sizeof("CONNECT");
|
||||
if (data[2] == 0x3f || data[2] == 0x53) { // SABM command
|
||||
data[2] = 0x73;
|
||||
} else if (data[2] == 0xef) { // Generic request
|
||||
|
10
components/esp_modem/test/target_iperf/CMakeLists.txt
Normal file
10
components/esp_modem/test/target_iperf/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
# 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.5)
|
||||
|
||||
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/system/console/advanced/components
|
||||
$ENV{IDF_PATH}/examples/common_components/iperf
|
||||
"../..")
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(pppd_test)
|
48
components/esp_modem/test/target_iperf/README.md
Normal file
48
components/esp_modem/test/target_iperf/README.md
Normal file
@ -0,0 +1,48 @@
|
||||
# Target test for measuring TCP/UDP network performance
|
||||
|
||||
## Overview
|
||||
|
||||
The aim of this test is to run `iperf` application to measure network throughput of the esp_modem library.
|
||||
|
||||
### Configure PPP server
|
||||
|
||||
This test uses a network DCE device, which only needs a PPP server. To run the PPP server, use this command:
|
||||
```
|
||||
sudo pppd /dev/ttyUSB1 115200 192.168.11.1:192.168.11.2 ms-dns 8.8.8.8 modem local noauth debug nocrtscts nodetach +ipv6
|
||||
```
|
||||
|
||||
### Running using pytest
|
||||
|
||||
For checking the performance, you only need to execute the pytest, which will measure the network throughput automatically and report the resultant values. For running the pytest, you need to:
|
||||
* install IDF pytest packages by running: `./install.sh --enable-pytest`
|
||||
* add IDF internal packages to python path: `export PYTHONPATH=${DIF_PATH}/tools/ci/python_packages/`
|
||||
* run the pytest as **superuser**
|
||||
|
||||
It's useful to note that when running the test multiple times, you can use `pytest --skip-autoflash y` so the pytest wouldn't have to always reprogram the DUT.
|
||||
|
||||
### Performance summary
|
||||
|
||||
Here's an example of the resultant summary logged by the pytest
|
||||
```
|
||||
2023-11-29 18:28:25 INFO [Performance][tcp_tx_throughput]: 0.75 Mbps
|
||||
2023-11-29 18:28:25 INFO [Performance][tcp_rx_throughput]: 0.70 Mbps
|
||||
2023-11-29 18:28:25 INFO [Performance][udp_tx_throughput]: 0.73 Mbps
|
||||
2023-11-29 18:28:25 INFO [Performance][udp_rx_throughput]: 0.70 Mbps
|
||||
```
|
||||
|
||||
### Running the iperf manually
|
||||
|
||||
Execute `idf.py flash monitor` in one terminal and after connecting to the PPP server (after getting an IP address), you can use standard `iperf` commands.
|
||||
In another terminal, you need to execute the iperf counterpart.
|
||||
For example running for checking UDP performance, and running server on ESP32, please run:
|
||||
* iperf -u -s -i 3 (in ESP32 terminal)
|
||||
* iperf -u -c SERVER_IP -t 60 -i 3 (on the host side)
|
||||
|
||||
Note that command `pppd info` will print actual IP addresses:
|
||||
```
|
||||
iperf> pppd info
|
||||
ppp:
|
||||
IP: 192.168.11.2
|
||||
MASK: 255.255.255.255
|
||||
GW: 192.168.11.3
|
||||
```
|
@ -0,0 +1,3 @@
|
||||
idf_component_register(SRCS "NetworkDCE.cpp"
|
||||
"cmd_pppclient.c"
|
||||
"pppd_iperf_main.c")
|
96
components/esp_modem/test/target_iperf/main/NetworkDCE.cpp
Normal file
96
components/esp_modem/test/target_iperf/main/NetworkDCE.cpp
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#include "cxx_include/esp_modem_dte.hpp"
|
||||
#include "esp_modem_config.h"
|
||||
#include "cxx_include/esp_modem_api.hpp"
|
||||
#include "cxx_include/esp_modem_dce_factory.hpp"
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
using namespace esp_modem;
|
||||
using namespace esp_modem::dce_factory;
|
||||
|
||||
class NetModule;
|
||||
typedef DCE_T<NetModule> NetDCE;
|
||||
|
||||
/**
|
||||
* @brief Custom factory which can build and create a DCE using a custom module
|
||||
*/
|
||||
class NetDCE_Factory: public Factory {
|
||||
public:
|
||||
template <typename T, typename ...Args>
|
||||
static DCE_T<T> *create(const config *cfg, Args &&... args)
|
||||
{
|
||||
return build_generic_DCE<T>(cfg, std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This is a null-module, doesn't define any AT commands, just passes everything to pppd
|
||||
*/
|
||||
class NetModule: public ModuleIf {
|
||||
public:
|
||||
explicit NetModule(std::shared_ptr<DTE> dte, const esp_modem_dce_config *cfg):
|
||||
dte(std::move(dte)) {}
|
||||
|
||||
bool setup_data_mode() override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool set_mode(modem_mode mode) override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
static esp_err_t init(esp_netif_t *netif)
|
||||
{
|
||||
// configure
|
||||
esp_modem_dte_config_t dte_config = ESP_MODEM_DTE_DEFAULT_CONFIG();
|
||||
dte_config.uart_config.baud_rate = 921600; // check also 460800
|
||||
esp_modem_dce_config dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG("");
|
||||
|
||||
// create DTE and minimal network DCE
|
||||
auto uart_dte = create_uart_dte(&dte_config);
|
||||
dce = NetDCE_Factory::create<NetModule>(&dce_config, uart_dte, netif);
|
||||
return dce == nullptr ? ESP_FAIL : ESP_OK;
|
||||
}
|
||||
|
||||
static void deinit()
|
||||
{
|
||||
delete dce;
|
||||
}
|
||||
static void start()
|
||||
{
|
||||
dce->set_data();
|
||||
}
|
||||
static void stop()
|
||||
{
|
||||
dce->exit_data();
|
||||
}
|
||||
|
||||
private:
|
||||
static NetDCE *dce;
|
||||
std::shared_ptr<DTE> dte;
|
||||
};
|
||||
|
||||
NetDCE *NetModule::dce = nullptr;
|
||||
|
||||
extern "C" esp_err_t modem_init_network(esp_netif_t *netif)
|
||||
{
|
||||
return NetModule::init(netif);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t modem_start_network()
|
||||
{
|
||||
NetModule::start();
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
extern "C" void modem_stop_network()
|
||||
{
|
||||
NetModule::stop();
|
||||
}
|
289
components/esp_modem/test/target_iperf/main/cmd_pppclient.c
Normal file
289
components/esp_modem/test/target_iperf/main/cmd_pppclient.c
Normal file
@ -0,0 +1,289 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "sys/socket.h" // for INADDR_ANY
|
||||
#include "esp_netif.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_netif.h"
|
||||
#include "esp_netif_ppp.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/event_groups.h"
|
||||
|
||||
#include "esp_console.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_bit_defs.h"
|
||||
#include "argtable3/argtable3.h"
|
||||
#include "iperf.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "network_dce.h"
|
||||
|
||||
static const char *TAG = "pppd_test";
|
||||
static EventGroupHandle_t event_group = NULL;
|
||||
static esp_netif_t *s_ppp_netif;
|
||||
static const int GOTIP_BIT = BIT0;
|
||||
|
||||
static void on_modem_event(void *arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void *event_data)
|
||||
{
|
||||
if (event_base == IP_EVENT) {
|
||||
ESP_LOGD(TAG, "IP event! %" PRIu32, event_id);
|
||||
if (event_id == IP_EVENT_PPP_GOT_IP) {
|
||||
esp_netif_dns_info_t dns_info;
|
||||
|
||||
|
||||
ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data;
|
||||
esp_netif_t *netif = event->esp_netif;
|
||||
|
||||
ESP_LOGI(TAG, "Modem Connect to PPP Server");
|
||||
ESP_LOGI(TAG, "~~~~~~~~~~~~~~");
|
||||
ESP_LOGI(TAG, "IP : " IPSTR, IP2STR(&event->ip_info.ip));
|
||||
ESP_LOGI(TAG, "Netmask : " IPSTR, IP2STR(&event->ip_info.netmask));
|
||||
ESP_LOGI(TAG, "Gateway : " IPSTR, IP2STR(&event->ip_info.gw));
|
||||
esp_netif_get_dns_info(netif, ESP_NETIF_DNS_MAIN, &dns_info);
|
||||
ESP_LOGI(TAG, "Name Server1: " IPSTR, IP2STR(&dns_info.ip.u_addr.ip4));
|
||||
esp_netif_get_dns_info(netif, ESP_NETIF_DNS_BACKUP, &dns_info);
|
||||
ESP_LOGI(TAG, "Name Server2: " IPSTR, IP2STR(&dns_info.ip.u_addr.ip4));
|
||||
ESP_LOGI(TAG, "~~~~~~~~~~~~~~");
|
||||
|
||||
ESP_LOGI(TAG, "GOT ip event!!!");
|
||||
xEventGroupSetBits(event_group, GOTIP_BIT);
|
||||
} else if (event_id == IP_EVENT_PPP_LOST_IP) {
|
||||
ESP_LOGI(TAG, "Modem Disconnect from PPP Server");
|
||||
} else if (event_id == IP_EVENT_GOT_IP6) {
|
||||
ESP_LOGI(TAG, "GOT IPv6 event!");
|
||||
ip_event_got_ip6_t *event = (ip_event_got_ip6_t *)event_data;
|
||||
ESP_LOGI(TAG, "Got IPv6 address " IPV6STR, IPV62STR(event->ip6_info.ip));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void on_ppp_changed(void *arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void *event_data)
|
||||
{
|
||||
ESP_LOGI(TAG, "PPP state changed event %" PRId32, event_id);
|
||||
if (event_id == NETIF_PPP_ERRORUSER) {
|
||||
/* User interrupted event from esp-netif */
|
||||
esp_netif_t *netif = (esp_netif_t *)event_data;
|
||||
ESP_LOGI(TAG, "User interrupted event from netif:%p", netif);
|
||||
xEventGroupSetBits(event_group, 2);
|
||||
}
|
||||
}
|
||||
|
||||
/* "pppd" command */
|
||||
static struct {
|
||||
struct arg_str *control;
|
||||
struct arg_end *end;
|
||||
} pppd_control_args;
|
||||
|
||||
static int pppd_cmd_control(int argc, char **argv)
|
||||
{
|
||||
int nerrors = arg_parse(argc, argv, (void **)&pppd_control_args);
|
||||
if (nerrors != 0) {
|
||||
arg_print_errors(stderr, pppd_control_args.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!strncmp(pppd_control_args.control->sval[0], "info", 4)) {
|
||||
esp_netif_ip_info_t ip;
|
||||
printf("%s:\n", esp_netif_get_desc(s_ppp_netif));
|
||||
esp_netif_get_ip_info(s_ppp_netif, &ip);
|
||||
printf(" IP: " IPSTR "\r\n", IP2STR(&ip.ip));
|
||||
printf(" MASK: " IPSTR "\r\n", IP2STR(&ip.netmask));
|
||||
printf(" GW: " IPSTR "\r\n", IP2STR(&ip.gw));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* "iperf" command */
|
||||
|
||||
static struct {
|
||||
struct arg_str *ip;
|
||||
struct arg_lit *server;
|
||||
struct arg_lit *udp;
|
||||
struct arg_lit *version;
|
||||
struct arg_int *port;
|
||||
struct arg_int *length;
|
||||
struct arg_int *interval;
|
||||
struct arg_int *time;
|
||||
struct arg_int *bw_limit;
|
||||
struct arg_lit *abort;
|
||||
struct arg_end *end;
|
||||
} iperf_args;
|
||||
|
||||
static int ppp_cmd_iperf(int argc, char **argv)
|
||||
{
|
||||
int nerrors = arg_parse(argc, argv, (void **)&iperf_args);
|
||||
iperf_cfg_t cfg;
|
||||
|
||||
if (nerrors != 0) {
|
||||
arg_print_errors(stderr, iperf_args.end, argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(&cfg, 0, sizeof(cfg));
|
||||
|
||||
// ethernet iperf only support IPV4 address
|
||||
cfg.type = IPERF_IP_TYPE_IPV4;
|
||||
|
||||
/* iperf -a */
|
||||
if (iperf_args.abort->count != 0) {
|
||||
iperf_stop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (((iperf_args.ip->count == 0) && (iperf_args.server->count == 0)) ||
|
||||
((iperf_args.ip->count != 0) && (iperf_args.server->count != 0))) {
|
||||
ESP_LOGE(__func__, "Wrong mode! ESP32 should run in client or server mode");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* iperf -s */
|
||||
if (iperf_args.ip->count == 0) {
|
||||
cfg.flag |= IPERF_FLAG_SERVER;
|
||||
}
|
||||
/* iperf -c SERVER_ADDRESS */
|
||||
else {
|
||||
cfg.destination_ip4 = esp_ip4addr_aton(iperf_args.ip->sval[0]);
|
||||
cfg.flag |= IPERF_FLAG_CLIENT;
|
||||
}
|
||||
|
||||
if (iperf_args.length->count == 0) {
|
||||
cfg.len_send_buf = 0;
|
||||
} else {
|
||||
cfg.len_send_buf = iperf_args.length->ival[0];
|
||||
}
|
||||
|
||||
/* wait for ip, could blocked here */
|
||||
xEventGroupWaitBits(event_group, GOTIP_BIT, pdFALSE, pdTRUE, portMAX_DELAY);
|
||||
|
||||
cfg.source_ip4 = INADDR_ANY;
|
||||
|
||||
/* iperf -u */
|
||||
if (iperf_args.udp->count == 0) {
|
||||
cfg.flag |= IPERF_FLAG_TCP;
|
||||
} else {
|
||||
cfg.flag |= IPERF_FLAG_UDP;
|
||||
}
|
||||
|
||||
/* iperf -p */
|
||||
if (iperf_args.port->count == 0) {
|
||||
cfg.sport = IPERF_DEFAULT_PORT;
|
||||
cfg.dport = IPERF_DEFAULT_PORT;
|
||||
} else {
|
||||
if (cfg.flag & IPERF_FLAG_SERVER) {
|
||||
cfg.sport = iperf_args.port->ival[0];
|
||||
cfg.dport = IPERF_DEFAULT_PORT;
|
||||
} else {
|
||||
cfg.sport = IPERF_DEFAULT_PORT;
|
||||
cfg.dport = iperf_args.port->ival[0];
|
||||
}
|
||||
}
|
||||
|
||||
/* iperf -i */
|
||||
if (iperf_args.interval->count == 0) {
|
||||
cfg.interval = IPERF_DEFAULT_INTERVAL;
|
||||
} else {
|
||||
cfg.interval = iperf_args.interval->ival[0];
|
||||
if (cfg.interval <= 0) {
|
||||
cfg.interval = IPERF_DEFAULT_INTERVAL;
|
||||
}
|
||||
}
|
||||
|
||||
/* iperf -t */
|
||||
if (iperf_args.time->count == 0) {
|
||||
cfg.time = IPERF_DEFAULT_TIME;
|
||||
} else {
|
||||
cfg.time = iperf_args.time->ival[0];
|
||||
if (cfg.time <= cfg.interval) {
|
||||
cfg.time = cfg.interval;
|
||||
}
|
||||
}
|
||||
|
||||
/* iperf -b */
|
||||
if (iperf_args.bw_limit->count == 0) {
|
||||
cfg.bw_lim = IPERF_DEFAULT_NO_BW_LIMIT;
|
||||
} else {
|
||||
cfg.bw_lim = iperf_args.bw_limit->ival[0];
|
||||
if (cfg.bw_lim <= 0) {
|
||||
cfg.bw_lim = IPERF_DEFAULT_NO_BW_LIMIT;
|
||||
}
|
||||
}
|
||||
|
||||
printf("mode=%s-%s sip=" IPSTR ":%" PRIu16 ", dip=%" PRIu32 ".%" PRIu32 ".%" PRIu32 ".%" PRIu32 ":%" PRIu16 ", interval=%" PRIu32 ", time=%" PRIu32 "\r\n",
|
||||
cfg.flag & IPERF_FLAG_TCP ? "tcp" : "udp",
|
||||
cfg.flag & IPERF_FLAG_SERVER ? "server" : "client",
|
||||
(uint16_t) cfg.source_ip4 & 0xFF,
|
||||
(uint16_t) (cfg.source_ip4 >> 8) & 0xFF,
|
||||
(uint16_t) (cfg.source_ip4 >> 16) & 0xFF,
|
||||
(uint16_t) (cfg.source_ip4 >> 24) & 0xFF,
|
||||
cfg.sport,
|
||||
cfg.destination_ip4 & 0xFF, (cfg.destination_ip4 >> 8) & 0xFF,
|
||||
(cfg.destination_ip4 >> 16) & 0xFF, (cfg.destination_ip4 >> 24) & 0xFF, cfg.dport,
|
||||
cfg.interval, cfg.time);
|
||||
|
||||
iperf_start(&cfg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void register_pppd(void)
|
||||
{
|
||||
event_group = xEventGroupCreate();
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
|
||||
esp_netif_config_t ppp_netif_config = ESP_NETIF_DEFAULT_PPP();
|
||||
s_ppp_netif = esp_netif_new(&ppp_netif_config);
|
||||
assert(s_ppp_netif);
|
||||
esp_netif_ppp_config_t ppp_config = { true, true };
|
||||
esp_netif_ppp_set_params(s_ppp_netif, &ppp_config);
|
||||
|
||||
ESP_ERROR_CHECK(modem_init_network(s_ppp_netif));
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, on_modem_event, NULL));
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(NETIF_PPP_STATUS, ESP_EVENT_ANY_ID, on_ppp_changed, NULL));
|
||||
|
||||
modem_start_network();
|
||||
|
||||
pppd_control_args.control = arg_str1(NULL, NULL, "<info>", "Get info of pppd");
|
||||
pppd_control_args.end = arg_end(1);
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "pppd",
|
||||
.help = "PPP interface IO control",
|
||||
.hint = NULL,
|
||||
.func = pppd_cmd_control,
|
||||
.argtable = &pppd_control_args
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
||||
|
||||
iperf_args.ip = arg_str0("c", "client", "<ip>",
|
||||
"run in client mode, connecting to <host>");
|
||||
iperf_args.server = arg_lit0("s", "server", "run in server mode");
|
||||
iperf_args.udp = arg_lit0("u", "udp", "use UDP rather than TCP");
|
||||
iperf_args.version = arg_lit0("V", "ipv6_domain", "use IPV6 address rather than IPV4");
|
||||
iperf_args.port = arg_int0("p", "port", "<port>",
|
||||
"server port to listen on/connect to");
|
||||
iperf_args.length = arg_int0("l", "len", "<length>", "set read/write buffer size");
|
||||
iperf_args.interval = arg_int0("i", "interval", "<interval>",
|
||||
"seconds between periodic bandwidth reports");
|
||||
iperf_args.time = arg_int0("t", "time", "<time>", "time in seconds to transmit for (default 10 secs)");
|
||||
iperf_args.bw_limit = arg_int0("b", "bandwidth", "<bandwidth>", "bandwidth to send at in Mbits/sec");
|
||||
iperf_args.abort = arg_lit0("a", "abort", "abort running iperf");
|
||||
iperf_args.end = arg_end(1);
|
||||
const esp_console_cmd_t iperf_cmd = {
|
||||
.command = "iperf",
|
||||
.help = "iperf command",
|
||||
.hint = NULL,
|
||||
.func = &ppp_cmd_iperf,
|
||||
.argtable = &iperf_args
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&iperf_cmd));
|
||||
}
|
26
components/esp_modem/test/target_iperf/main/network_dce.h
Normal file
26
components/esp_modem/test/target_iperf/main/network_dce.h
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "esp_err.h"
|
||||
#include "esp_netif.h"
|
||||
|
||||
/**
|
||||
* @brief Initialize PPP network (with a generic PPP server)
|
||||
* @param netif PPP netif
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t modem_init_network(esp_netif_t *netif);
|
||||
|
||||
/**
|
||||
* @brief Start PPP network
|
||||
*/
|
||||
void modem_start_network();
|
||||
|
||||
/**
|
||||
* @brief Stop PPP network
|
||||
*/
|
||||
void modem_stop_network();
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_console.h"
|
||||
#include "cmd_system.h"
|
||||
|
||||
void register_pppd(void);
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
esp_console_repl_t *repl = NULL;
|
||||
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
|
||||
esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
|
||||
repl_config.prompt = "iperf>";
|
||||
// init console REPL environment
|
||||
ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl));
|
||||
|
||||
/* Register commands */
|
||||
register_system_common();
|
||||
register_pppd();
|
||||
|
||||
printf("\n =======================================================\n");
|
||||
printf(" | Steps to Test PPP Client Bandwidth |\n");
|
||||
printf(" | |\n");
|
||||
printf(" | 1. Enter 'help', check all supported commands |\n");
|
||||
printf(" | 2. Start PPP server on host system |\n");
|
||||
printf(" | - pppd /dev/ttyUSB1 115200 192.168.11.1:192.168.11.2 modem local noauth debug nocrtscts nodetach +ipv6\n");
|
||||
printf(" | 3. Wait ESP32 to get IP from PPP server |\n");
|
||||
printf(" | 4. Enter 'pppd info' (optional) |\n");
|
||||
printf(" | 5. Server: 'iperf -u -s -i 3' |\n");
|
||||
printf(" | 6. Client: 'iperf -u -c SERVER_IP -t 60 -i 3' |\n");
|
||||
printf(" | |\n");
|
||||
printf(" =======================================================\n\n");
|
||||
|
||||
// start console REPL
|
||||
ESP_ERROR_CHECK(esp_console_start_repl(repl));
|
||||
}
|
112
components/esp_modem/test/target_iperf/pytest_ppp_iperf.py
Normal file
112
components/esp_modem/test/target_iperf/pytest_ppp_iperf.py
Normal file
@ -0,0 +1,112 @@
|
||||
# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
"""
|
||||
Test case for iperf example.
|
||||
|
||||
This test case might have problem running on Windows:
|
||||
|
||||
- use `sudo killall iperf` to force kill iperf, didn't implement windows version
|
||||
|
||||
"""
|
||||
from __future__ import division, unicode_literals
|
||||
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
from common_test_methods import get_host_ip4_by_dest_ip
|
||||
from idf_iperf_test_util import IperfUtility
|
||||
from pytest_embedded import Dut
|
||||
|
||||
try:
|
||||
from typing import Any, Callable, Tuple
|
||||
except ImportError:
|
||||
# Only used for type annotations
|
||||
pass
|
||||
|
||||
NO_BANDWIDTH_LIMIT = -1 # iperf send bandwidth is not limited
|
||||
|
||||
|
||||
class IperfTestUtilityEth(IperfUtility.IperfTestUtility):
|
||||
""" iperf test implementation """
|
||||
def __init__(self, dut: str, config_name: str, pc_nic_ip: str, pc_iperf_log_file: str, test_result:Any=None) -> None:
|
||||
IperfUtility.IperfTestUtility.__init__(self, dut, config_name, 'None', 'None', pc_nic_ip, pc_iperf_log_file, test_result)
|
||||
|
||||
def setup(self) -> Tuple[str,int]:
|
||||
"""
|
||||
setup iperf test:
|
||||
|
||||
1. kill current iperf process
|
||||
2. reboot DUT (currently iperf is not very robust, need to reboot DUT)
|
||||
"""
|
||||
try:
|
||||
subprocess.check_output('sudo killall iperf 2>&1 > /dev/null', shell=True)
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
self.dut.write('restart')
|
||||
dut_ip = self.dut.expect(r'pppd_test: IP : (\d+\.\d+\.\d+\.\d+)').group(1)
|
||||
self.dut.expect("Type 'help' to get the list of commands.")
|
||||
self.dut.expect('iperf>')
|
||||
rssi = 0
|
||||
return dut_ip, rssi
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def log_performance(record_property: Callable[[str, object], None]) -> Callable[[str, str], None]:
|
||||
"""
|
||||
log performance item with pre-defined format to the console
|
||||
and record it under the ``properties`` tag in the junit report if available.
|
||||
"""
|
||||
|
||||
def real_func(item: str, value: str) -> None:
|
||||
"""
|
||||
:param item: performance item name
|
||||
:param value: performance value
|
||||
"""
|
||||
logging.info('[Performance][%s]: %s', item, value)
|
||||
|
||||
return real_func
|
||||
|
||||
|
||||
def test_esp_pppd_iperf(
|
||||
dut: Dut,
|
||||
log_performance: Callable[[str, object], None],
|
||||
# check_performance: Callable[[str, float, str], None],
|
||||
) -> None:
|
||||
"""
|
||||
steps: |
|
||||
1. test TCP tx rx and UDP tx rx throughput
|
||||
2. compare with the pre-defined pass standard
|
||||
"""
|
||||
|
||||
# 1. preparing
|
||||
pc_iperf_log_file = os.path.join(dut.logdir, 'pc_iperf_log.md')
|
||||
# 2. wait for DUT
|
||||
dut_ip = dut.expect(r'pppd_test: IP : (\d+\.\d+\.\d+\.\d+)').group(1)
|
||||
|
||||
pc_nic_ip = get_host_ip4_by_dest_ip(dut_ip)
|
||||
test_result = {
|
||||
'tcp_tx': IperfUtility.TestResult('tcp', 'tx', 'ppp_client'),
|
||||
'tcp_rx': IperfUtility.TestResult('tcp', 'rx', 'ppp_client'),
|
||||
'udp_tx': IperfUtility.TestResult('udp', 'tx', 'ppp_client'),
|
||||
'udp_rx': IperfUtility.TestResult('udp', 'rx', 'ppp_client'),
|
||||
}
|
||||
test_utility = IperfTestUtilityEth(dut, 'ppp', pc_nic_ip, pc_iperf_log_file, test_result)
|
||||
|
||||
# 3. run test for TCP Tx, Rx and UDP Tx, Rx
|
||||
test_utility.run_test('tcp', 'tx', 0, 5)
|
||||
test_utility.run_test('tcp', 'rx', 0, 5)
|
||||
test_utility.run_test('udp', 'tx', 0, 5)
|
||||
test_utility.run_test('udp', 'rx', 0, 5)
|
||||
|
||||
# 4. print out performance details
|
||||
for throughput_type in test_result:
|
||||
print('{}_throughput'.format(throughput_type))
|
||||
print(test_result[throughput_type])
|
||||
print('---------------------------')
|
||||
|
||||
# 5. log performance summary
|
||||
for throughput_type in test_result:
|
||||
log_performance('{}_throughput'.format(throughput_type),
|
||||
'{:.02f} Mbps'.format(test_result[throughput_type].get_best_throughput()))
|
@ -0,0 +1,3 @@
|
||||
CONFIG_COMPILER_CXX_EXCEPTIONS=y
|
||||
CONFIG_LWIP_PPP_SUPPORT=y
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096
|
8
components/esp_modem/test/target_ota/CMakeLists.txt
Normal file
8
components/esp_modem/test/target_ota/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
||||
# The following 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.8)
|
||||
|
||||
set(EXTRA_COMPONENT_DIRS "../.." "../../examples/modem_tcp_client/components")
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(ota_test)
|
27
components/esp_modem/test/target_ota/README.md
Normal file
27
components/esp_modem/test/target_ota/README.md
Normal file
@ -0,0 +1,27 @@
|
||||
# Target test running OTA update
|
||||
|
||||
## Overview
|
||||
|
||||
The aim of this test is to exercise the most commonly failing scenario, running OTA over PPPoS with https.
|
||||
|
||||
This project opens a data session, runs basic mqtt operations and initiates OTA update.
|
||||
It supports the following test configurations:
|
||||
* Using a real modem device (default config)
|
||||
* Using VFS device (only to exercise VFS DTE)
|
||||
* Using network-only DCE (connecting directly to PPP server) -- needs some configuration
|
||||
|
||||
### Configuring the PPP server
|
||||
|
||||
You need to run these applications on your host machine:
|
||||
* PPP server
|
||||
```bash
|
||||
sudo pppd /dev/ttyUSB1 115200 192.168.11.1:192.168.11.2 ms-dns 8.8.8.8 modem local noauth debug nocrtscts nodetach +ipv6
|
||||
```
|
||||
* MQTT broker: Running mosquitto in the default config is enough, configuring the broker's URL to the local PPP address: `config.broker.address.uri = "mqtt://192.168.11.1";`
|
||||
* HTTP server: Need to support HTTP/1.1 (to support ranges). You can use the script `http_server.py` and configure the OTA endpoint as `"https://192.168.11.1:1234/esp32.bin"`
|
||||
|
||||
## Potential issues
|
||||
|
||||
When running this test it is expected to experience some buffer overflows or connection interruption.
|
||||
The modem library should recover from these failure modes and continue and complete OTA update.
|
||||
These issues are expected, since UART ISR is deliberately not placed into IRAM in the test configuration to exhibit some minor communication glitches.
|
BIN
components/esp_modem/test/target_ota/bin/blink.bin
Normal file
BIN
components/esp_modem/test/target_ota/bin/blink.bin
Normal file
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
idf_component_register(SRCS manual_ota.cpp transport_batch_tls.cpp
|
||||
INCLUDE_DIRS "."
|
||||
PRIV_REQUIRES extra_tcp_transports esp_http_client app_update)
|
@ -0,0 +1,321 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#include "manual_ota.hpp"
|
||||
#include "esp_log.h"
|
||||
#include "esp_ota_ops.h"
|
||||
#include "esp_app_format.h"
|
||||
#include "esp_http_client.h"
|
||||
#include "esp_partition.h"
|
||||
#include "esp_transport_tcp.h"
|
||||
#include "transport_batch_tls.hpp"
|
||||
|
||||
static const char *TAG = "manual_ota";
|
||||
|
||||
bool manual_ota::begin()
|
||||
{
|
||||
if (status != state::UNDEF) {
|
||||
ESP_LOGE(TAG, "Invalid state for manual_ota::perform");
|
||||
return false;
|
||||
}
|
||||
const esp_partition_t *configured = esp_ota_get_boot_partition();
|
||||
const esp_partition_t *running = esp_ota_get_running_partition();
|
||||
|
||||
if (configured != running) {
|
||||
ESP_LOGE(TAG, "Configured OTA boot partition at offset 0x%08" PRIx32 ", but running from offset 0x%08" PRIx32, configured->address, running->address);
|
||||
return false;
|
||||
}
|
||||
|
||||
status = state::INIT;
|
||||
max_buffer_size_ = size_ * 1024;
|
||||
if (mode_ == mode::BATCH) {
|
||||
#ifdef CONFIG_ESP_HTTP_CLIENT_ENABLE_CUSTOM_TRANSPORT
|
||||
esp_transport_handle_t tcp = esp_transport_tcp_init();
|
||||
ssl_ = esp_transport_batch_tls_init(tcp, max_buffer_size_);
|
||||
http_.config_.transport = ssl_;
|
||||
if (http_.config_.cert_pem == nullptr || common_name_ == nullptr) {
|
||||
ESP_LOGE(TAG, "TLS with no verification is not supported");
|
||||
return fail();
|
||||
}
|
||||
if (!esp_transport_batch_set_ca_cert(ssl_, http_.config_.cert_pem, 0)) {
|
||||
return fail();
|
||||
}
|
||||
if (!esp_transport_batch_set_cn(ssl_, common_name_)) {
|
||||
return fail();
|
||||
}
|
||||
#else
|
||||
ESP_LOGE(TAG, "mode::BATCH Cannot be used without CONFIG_ESP_HTTP_CLIENT_ENABLE_CUSTOM_TRANSPORT");
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!http_.init()) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
image_length_ = http_.get_image_len();
|
||||
if (image_length_ <= 0) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
if (image_length_ > size_) {
|
||||
if (!http_.set_range(0, max_buffer_size_ - 1)) {
|
||||
return fail();
|
||||
}
|
||||
}
|
||||
esp_http_client_set_method(http_.handle_, HTTP_METHOD_GET);
|
||||
|
||||
partition_ = esp_ota_get_next_update_partition(nullptr);
|
||||
if (partition_ == nullptr) {
|
||||
ESP_LOGE(TAG, "Invalid update partition");
|
||||
return false;
|
||||
}
|
||||
ESP_LOGI(TAG, "Writing to partition subtype %d at offset 0x%" PRIx32, partition_->subtype, partition_->address);
|
||||
|
||||
file_length_ = 0;
|
||||
reconnect_attempts_ = 0;
|
||||
buffer_.resize(max_buffer_size_);
|
||||
status = state::IMAGE_CHECK;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool manual_ota::perform()
|
||||
{
|
||||
if (status != state::IMAGE_CHECK && status != state::START) {
|
||||
ESP_LOGE(TAG, "Invalid state for manual_ota::perform");
|
||||
return false;
|
||||
}
|
||||
esp_err_t err = esp_http_client_open(http_.handle_, 0);
|
||||
if (err != ESP_OK) {
|
||||
if (image_length_ == file_length_) {
|
||||
status = state::END;
|
||||
return false;
|
||||
}
|
||||
|
||||
esp_http_client_close(http_.handle_);
|
||||
ESP_LOGI(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err));
|
||||
if (reconnect_attempts_++ < max_reconnect_attempts_) {
|
||||
return true; // will retry in the next iteration
|
||||
}
|
||||
return fail();
|
||||
}
|
||||
esp_http_client_fetch_headers(http_.handle_);
|
||||
|
||||
int batch_len = max_buffer_size_;
|
||||
if (mode_ == mode::BATCH) {
|
||||
batch_len = esp_transport_batch_tls_pre_read(ssl_, max_buffer_size_, timeout_ * 1000);
|
||||
if (batch_len < 0) {
|
||||
ESP_LOGE(TAG, "Error: Failed to pre-read plain text data!");
|
||||
fail();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int data_read = esp_http_client_read(http_.handle_, buffer_.data(), batch_len);
|
||||
|
||||
if (data_read < 0) {
|
||||
ESP_LOGE(TAG, "Error: SSL data read error");
|
||||
return fail();
|
||||
} else if (data_read > 0) {
|
||||
esp_http_client_close(http_.handle_);
|
||||
|
||||
if (status == state::IMAGE_CHECK) {
|
||||
esp_app_desc_t new_app_info;
|
||||
if (data_read > sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) + sizeof(esp_app_desc_t)) {
|
||||
// check current version with downloading
|
||||
memcpy(&new_app_info, &buffer_[sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t)], sizeof(esp_app_desc_t));
|
||||
ESP_LOGI(TAG, "New firmware version: %s", new_app_info.version);
|
||||
|
||||
esp_app_desc_t running_app_info;
|
||||
const esp_partition_t *running = esp_ota_get_running_partition();
|
||||
if (esp_ota_get_partition_description(running, &running_app_info) == ESP_OK) {
|
||||
ESP_LOGI(TAG, "Running firmware version: %s", running_app_info.version);
|
||||
}
|
||||
|
||||
const esp_partition_t *last_invalid_app = esp_ota_get_last_invalid_partition();
|
||||
esp_app_desc_t invalid_app_info;
|
||||
if (esp_ota_get_partition_description(last_invalid_app, &invalid_app_info) == ESP_OK) {
|
||||
ESP_LOGI(TAG, "Last invalid firmware version: %s", invalid_app_info.version);
|
||||
}
|
||||
|
||||
// check current version with last invalid partition
|
||||
if (last_invalid_app != NULL) {
|
||||
if (memcmp(invalid_app_info.version, new_app_info.version, sizeof(new_app_info.version)) == 0) {
|
||||
ESP_LOGW(TAG, "New version is the same as invalid version.");
|
||||
ESP_LOGW(TAG, "Previously, there was an attempt to launch the firmware with %s version, but it failed.", invalid_app_info.version);
|
||||
ESP_LOGW(TAG, "The firmware has been rolled back to the previous version.");
|
||||
return fail();
|
||||
}
|
||||
}
|
||||
|
||||
status = state::START;
|
||||
err = esp_ota_begin(partition_, OTA_WITH_SEQUENTIAL_WRITES, &update_handle_);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "esp_ota_begin failed (%s)", esp_err_to_name(err));
|
||||
return fail();
|
||||
}
|
||||
ota_begin = true;
|
||||
ESP_LOGI(TAG, "esp_ota_begin succeeded");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Received chunk doesn't contain app descriptor");
|
||||
return fail();
|
||||
}
|
||||
}
|
||||
err = esp_ota_write(update_handle_, (const void *)buffer_.data(), data_read);
|
||||
if (err != ESP_OK) {
|
||||
return fail();
|
||||
}
|
||||
file_length_ += data_read;
|
||||
ESP_LOGI(TAG, "Written image length %d", file_length_);
|
||||
|
||||
if (image_length_ == file_length_) {
|
||||
status = state::END;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!prepare_reconnect()) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
} else if (data_read == 0) {
|
||||
if (file_length_ == 0) {
|
||||
// Try to handle possible HTTP redirections
|
||||
if (!http_.handle_redirects()) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
err = esp_http_client_open(http_.handle_, 0);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err));
|
||||
return fail();
|
||||
}
|
||||
esp_http_client_fetch_headers(http_.handle_);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool manual_ota::prepare_reconnect()
|
||||
{
|
||||
esp_http_client_set_method(http_.handle_, HTTP_METHOD_GET);
|
||||
return http_.set_range(file_length_,
|
||||
(image_length_ - file_length_) > max_buffer_size_ ? (file_length_ + max_buffer_size_ - 1) : 0);
|
||||
}
|
||||
|
||||
bool manual_ota::fail()
|
||||
{
|
||||
status = state::FAIL;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool manual_ota::end()
|
||||
{
|
||||
if (status == state::END) {
|
||||
if (!http_.is_data_complete()) {
|
||||
ESP_LOGE(TAG, "Error in receiving complete file");
|
||||
return fail();
|
||||
}
|
||||
esp_err_t err = esp_ota_end(update_handle_);
|
||||
if (err != ESP_OK) {
|
||||
if (err == ESP_ERR_OTA_VALIDATE_FAILED) {
|
||||
ESP_LOGE(TAG, "Image validation failed, image is corrupted");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "esp_ota_end failed (%s)!", esp_err_to_name(err));
|
||||
}
|
||||
return fail();
|
||||
}
|
||||
ota_begin = false;
|
||||
err = esp_ota_set_boot_partition(partition_);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)!", esp_err_to_name(err));
|
||||
return fail();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
manual_ota::~manual_ota()
|
||||
{
|
||||
if (ota_begin) {
|
||||
esp_ota_abort(update_handle_);
|
||||
}
|
||||
}
|
||||
|
||||
bool manual_ota::http_client::handle_redirects()
|
||||
{
|
||||
int status_code = esp_http_client_get_status_code(handle_);
|
||||
ESP_LOGW(TAG, "Status code: %d", status_code);
|
||||
esp_err_t err = esp_http_client_set_redirection(handle_);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "URL redirection Failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
err = esp_http_client_open(handle_, 0);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err));
|
||||
return false;
|
||||
}
|
||||
esp_http_client_fetch_headers(handle_);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool manual_ota::http_client::set_range(size_t from, size_t to)
|
||||
{
|
||||
char *header_val = nullptr;
|
||||
if (to != 0) {
|
||||
asprintf(&header_val, "bytes=%d-%d", from, to);
|
||||
} else {
|
||||
asprintf(&header_val, "bytes=%d-", from);
|
||||
}
|
||||
if (header_val == nullptr) {
|
||||
ESP_LOGE(TAG, "Failed to allocate memory for HTTP header");
|
||||
return false;
|
||||
}
|
||||
esp_http_client_set_header(handle_, "Range", header_val);
|
||||
free(header_val);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool manual_ota::http_client::is_data_complete()
|
||||
{
|
||||
return esp_http_client_is_complete_data_received(handle_);
|
||||
}
|
||||
|
||||
manual_ota::http_client::~http_client()
|
||||
{
|
||||
if (handle_) {
|
||||
esp_http_client_close(handle_);
|
||||
esp_http_client_cleanup(handle_);
|
||||
}
|
||||
}
|
||||
|
||||
bool manual_ota::http_client::init()
|
||||
{
|
||||
handle_ = esp_http_client_init(&config_);
|
||||
return handle_ != nullptr;
|
||||
}
|
||||
|
||||
int64_t manual_ota::http_client::get_image_len()
|
||||
{
|
||||
esp_http_client_set_method(handle_, HTTP_METHOD_HEAD);
|
||||
esp_err_t err = esp_http_client_perform(handle_);
|
||||
if (err == ESP_OK) {
|
||||
int http_status = esp_http_client_get_status_code(handle_);
|
||||
if (http_status != HttpStatus_Ok) {
|
||||
ESP_LOGE(TAG, "Received incorrect http status %d", http_status);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
ESP_LOGE(TAG, "ESP HTTP client perform failed: %d", err);
|
||||
return -1;
|
||||
}
|
||||
int64_t image_length = esp_http_client_get_content_length(handle_);
|
||||
ESP_LOGI(TAG, "image_length = %lld", image_length);
|
||||
esp_http_client_close(handle_);
|
||||
return image_length;
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include "esp_http_client.h"
|
||||
#include "esp_partition.h"
|
||||
#include "esp_transport_tcp.h"
|
||||
#include "esp_ota_ops.h"
|
||||
|
||||
class manual_ota {
|
||||
public:
|
||||
/**
|
||||
* @brief Set the preferred mode
|
||||
*/
|
||||
enum class mode {
|
||||
BATCH, /**< Read data chunk from TCP and pass it to SSL, restore session on reconnection */
|
||||
NORMAL /**< Use standard partial download, continuously passing data from TCP to mbedTLS */
|
||||
} mode_ {mode::BATCH};
|
||||
|
||||
/**
|
||||
* @brief Set the OTA batch size in kB
|
||||
*
|
||||
* This would allocate two big buffers:
|
||||
* - one for reading from TCP socket and
|
||||
* - one for passing to mbedTLS for description
|
||||
*/
|
||||
size_t size_{32};
|
||||
|
||||
/**
|
||||
* @brief Set timeout in seconds
|
||||
*
|
||||
* This is the network timeout, so if less data than the batch size received
|
||||
* the timeout (and no EOF) we should proceed with passing the data to mbedtls
|
||||
*/
|
||||
int timeout_{2};
|
||||
|
||||
/**
|
||||
* @brief Set common name of the server to verify
|
||||
*/
|
||||
const char *common_name_{};
|
||||
/**
|
||||
* @brief Wrapper around the http client -- Please set the http config
|
||||
*/
|
||||
class http_client {
|
||||
friend class manual_ota;
|
||||
~http_client();
|
||||
bool init();
|
||||
esp_http_client_handle_t handle_{nullptr};
|
||||
bool handle_redirects();
|
||||
bool set_range(size_t from, size_t to);
|
||||
bool is_data_complete();
|
||||
int64_t get_image_len();
|
||||
public:
|
||||
esp_http_client_config_t config_{}; /**< Configure the http connection parameters */
|
||||
} http_;
|
||||
|
||||
/**
|
||||
* @brief Construct a new manual ota object
|
||||
*/
|
||||
explicit manual_ota() {}
|
||||
|
||||
~manual_ota();
|
||||
|
||||
/**
|
||||
* @brief Start the manual OTA process
|
||||
*
|
||||
* @return true if started successfully
|
||||
*/
|
||||
bool begin();
|
||||
|
||||
/**
|
||||
* @brief Performs one read-write OTA iteration
|
||||
*
|
||||
* @return true if the process is in progress
|
||||
* @return false if the process finished, call end() to get OTA result
|
||||
*/
|
||||
bool perform();
|
||||
|
||||
/**
|
||||
* @brief Finishes an OTA update
|
||||
*
|
||||
* @return true if the OTA update completed successfully
|
||||
*/
|
||||
bool end();
|
||||
|
||||
private:
|
||||
enum class state {
|
||||
UNDEF,
|
||||
INIT,
|
||||
IMAGE_CHECK,
|
||||
START,
|
||||
END,
|
||||
FAIL,
|
||||
};
|
||||
int64_t image_length_;
|
||||
size_t file_length_;
|
||||
size_t max_buffer_size_{size_ * 1024};
|
||||
const esp_partition_t *partition_{nullptr};
|
||||
state status{state::UNDEF};
|
||||
std::vector<char> buffer_{};
|
||||
int reconnect_attempts_;
|
||||
const int max_reconnect_attempts_{3};
|
||||
esp_transport_handle_t ssl_;
|
||||
esp_ota_handle_t update_handle_{0};
|
||||
bool ota_begin;
|
||||
|
||||
bool prepare_reconnect();
|
||||
bool fail();
|
||||
};
|
@ -0,0 +1,249 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#include <vector>
|
||||
#include "esp_log.h"
|
||||
#include "mbedtls_wrap.hpp"
|
||||
#include "esp_transport_tcp.h"
|
||||
|
||||
#define TAG "batch-tls"
|
||||
|
||||
class TlsTransport: public Tls {
|
||||
public:
|
||||
explicit TlsTransport(esp_transport_handle_t parent):
|
||||
Tls(), transport_(parent), last_timeout(0), read_len(0), offset(0) {}
|
||||
int send(const unsigned char *buf, size_t len) override;
|
||||
int recv(unsigned char *buf, size_t len) override;
|
||||
static bool set_func(esp_transport_handle_t tls_transport);
|
||||
int preread(size_t len, int timeout_ms);
|
||||
bool prepare_buffer(size_t max_size);
|
||||
private:
|
||||
esp_transport_handle_t transport_{};
|
||||
int connect(const char *host, int port, int timeout_ms);
|
||||
void delay() override;
|
||||
|
||||
struct transport {
|
||||
static int connect(esp_transport_handle_t t, const char *host, int port, int timeout_ms);
|
||||
static int read(esp_transport_handle_t t, char *buffer, int len, int timeout_ms);
|
||||
static int write(esp_transport_handle_t t, const char *buffer, int len, int timeout_ms);
|
||||
static int close(esp_transport_handle_t t);
|
||||
static int poll_read(esp_transport_handle_t t, int timeout_ms);
|
||||
static int poll_write(esp_transport_handle_t t, int timeout_ms);
|
||||
static int destroy(esp_transport_handle_t t);
|
||||
};
|
||||
int last_timeout;
|
||||
std::vector<char> buf;
|
||||
size_t read_len;
|
||||
size_t offset;
|
||||
};
|
||||
|
||||
esp_transport_handle_t esp_transport_tls_init(esp_transport_handle_t parent)
|
||||
{
|
||||
esp_transport_handle_t transport_handle = esp_transport_init();
|
||||
auto *tls_context = new TlsTransport(parent);
|
||||
esp_transport_set_context_data(transport_handle, tls_context);
|
||||
TlsTransport::set_func(transport_handle);
|
||||
return transport_handle;
|
||||
}
|
||||
|
||||
int TlsTransport::send(const unsigned char *buf, size_t len)
|
||||
{
|
||||
int ret = esp_transport_write(transport_, reinterpret_cast<const char *>(buf), len, 0);
|
||||
ESP_LOGD(TAG, "writing(len=%d) ret=%d", len, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int TlsTransport::recv(unsigned char *buffer, size_t len)
|
||||
{
|
||||
ESP_LOGD(TAG, "recv(len=%d)", len);
|
||||
if (read_len != 0) {
|
||||
|
||||
if (read_len > len) {
|
||||
memcpy((char *)buffer, buf.data() + offset, len);
|
||||
read_len -= len;
|
||||
offset += len;
|
||||
ESP_LOGD(TAG, "read %d from batch read_len = %d", len, read_len);
|
||||
return len;
|
||||
} else {
|
||||
int remaining = len = read_len;
|
||||
if (remaining > 0) {
|
||||
memcpy((char *)buffer, buf.data() + offset, remaining);
|
||||
read_len = 0;
|
||||
offset = 0;
|
||||
return remaining;
|
||||
|
||||
}
|
||||
read_len = 0;
|
||||
offset = 0;
|
||||
return ERR_TCP_TRANSPORT_CONNECTION_CLOSED_BY_FIN;
|
||||
}
|
||||
}
|
||||
int ret = esp_transport_read(transport_, reinterpret_cast<char *>(buffer), len, last_timeout);
|
||||
|
||||
if (ret == ERR_TCP_TRANSPORT_CONNECTION_TIMEOUT) {
|
||||
return MBEDTLS_ERR_SSL_WANT_READ;
|
||||
}
|
||||
return ret == ERR_TCP_TRANSPORT_CONNECTION_CLOSED_BY_FIN ? 0 : ret;
|
||||
}
|
||||
|
||||
bool TlsTransport::set_func(esp_transport_handle_t tls_transport)
|
||||
{
|
||||
return esp_transport_set_func(tls_transport, TlsTransport::transport::connect, TlsTransport::transport::read, TlsTransport::transport::write, TlsTransport::transport::close, TlsTransport::transport::poll_read, TlsTransport::transport::poll_write, TlsTransport::transport::destroy) == ESP_OK;
|
||||
}
|
||||
|
||||
int TlsTransport::connect(const char *host, int port, int timeout_ms)
|
||||
{
|
||||
return esp_transport_connect(transport_, host, port, timeout_ms);
|
||||
}
|
||||
|
||||
void TlsTransport::delay()
|
||||
{
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
}
|
||||
|
||||
int TlsTransport::transport::connect(esp_transport_handle_t t, const char *host, int port, int timeout_ms)
|
||||
{
|
||||
auto tls = static_cast<TlsTransport *>(esp_transport_get_context_data(t));
|
||||
tls->init(is_server{false}, do_verify{true});
|
||||
|
||||
ESP_LOGD(TAG, "TLS-connect");
|
||||
auto ret = tls->connect(host, port, timeout_ms);
|
||||
if (ret < 0) {
|
||||
ESP_LOGI(TAG, "Failed to connect to transport");
|
||||
return ret;
|
||||
}
|
||||
if (tls->is_session_loaded()) {
|
||||
tls->set_session();
|
||||
}
|
||||
ESP_LOGI(TAG, "Before handshake");
|
||||
ret = tls->handshake();
|
||||
if (ret < 0) {
|
||||
ESP_LOGI(TAG, "Failed to handshake");
|
||||
return ret;
|
||||
}
|
||||
if (!tls->get_session()) {
|
||||
// we're not able to save session, report an error and continue (next connection will be slower)
|
||||
ESP_LOGW(TAG, "Failed to save session");
|
||||
}
|
||||
ESP_LOGI(TAG, "After handshake");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TlsTransport::transport::read(esp_transport_handle_t t, char *buffer, int len, int timeout_ms)
|
||||
{
|
||||
auto tls = static_cast<TlsTransport *>(esp_transport_get_context_data(t));
|
||||
ESP_LOGD(TAG, "available=%d tls->read_len=%d", tls->get_available_bytes(), tls->read_len);
|
||||
if (tls->get_available_bytes() <= 0 && tls->read_len == 0) {
|
||||
ESP_LOGD(TAG, "red(len=%d, timeout=%d) tls->read_len=%d", len, timeout_ms, tls->read_len);
|
||||
tls->last_timeout = timeout_ms;
|
||||
int poll = esp_transport_poll_read(t, timeout_ms);
|
||||
if (poll == -1) {
|
||||
return ERR_TCP_TRANSPORT_CONNECTION_FAILED;
|
||||
}
|
||||
if (poll == 0) {
|
||||
return ERR_TCP_TRANSPORT_CONNECTION_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
auto ret = tls->read(reinterpret_cast<unsigned char *>(buffer), len);
|
||||
if (ret == MBEDTLS_ERR_SSL_WANT_READ) {
|
||||
ret = ERR_TCP_TRANSPORT_CONNECTION_TIMEOUT;
|
||||
}
|
||||
ESP_LOGD(TAG, "red(len=%d, timeout=%d) ret=%d", len, timeout_ms, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int TlsTransport::transport::write(esp_transport_handle_t t, const char *buffer, int len, int timeout_ms)
|
||||
{
|
||||
int poll;
|
||||
if ((poll = esp_transport_poll_write(t, timeout_ms)) <= 0) {
|
||||
ESP_LOGW(TAG, "Poll timeout or error timeout_ms=%d", timeout_ms);
|
||||
return poll;
|
||||
}
|
||||
|
||||
auto tls = static_cast<TlsTransport *>(esp_transport_get_context_data(t));
|
||||
int ret = tls->write(reinterpret_cast<const unsigned char *>(buffer), len);
|
||||
ESP_LOGD(TAG, "write ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int TlsTransport::transport::close(esp_transport_handle_t t)
|
||||
{
|
||||
auto tls = static_cast<TlsTransport *>(esp_transport_get_context_data(t));
|
||||
int ret = esp_transport_close(tls->transport_);
|
||||
tls->deinit();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int TlsTransport::transport::poll_read(esp_transport_handle_t t, int timeout_ms)
|
||||
{
|
||||
auto tls = static_cast<TlsTransport *>(esp_transport_get_context_data(t));
|
||||
return esp_transport_poll_read(tls->transport_, timeout_ms);
|
||||
}
|
||||
|
||||
int TlsTransport::transport::poll_write(esp_transport_handle_t t, int timeout_ms)
|
||||
{
|
||||
auto tls = static_cast<TlsTransport *>(esp_transport_get_context_data(t));
|
||||
return esp_transport_poll_write(tls->transport_, timeout_ms);
|
||||
}
|
||||
|
||||
int TlsTransport::transport::destroy(esp_transport_handle_t t)
|
||||
{
|
||||
auto tls = static_cast<TlsTransport *>(esp_transport_get_context_data(t));
|
||||
return esp_transport_destroy(tls->transport_);
|
||||
}
|
||||
|
||||
|
||||
esp_transport_handle_t esp_transport_batch_tls_init(esp_transport_handle_t parent, const size_t max_buffer_size)
|
||||
{
|
||||
esp_transport_handle_t ssl = esp_transport_init();
|
||||
auto *tls = new TlsTransport(parent);
|
||||
esp_transport_set_context_data(ssl, tls);
|
||||
TlsTransport::set_func(ssl);
|
||||
tls->prepare_buffer(max_buffer_size);
|
||||
return ssl;
|
||||
}
|
||||
|
||||
bool esp_transport_batch_set_ca_cert(esp_transport_handle_t t, const char *ca_cert, size_t cert_len = 0)
|
||||
{
|
||||
auto tls = static_cast<TlsTransport *>(esp_transport_get_context_data(t));
|
||||
const_buf cert((const unsigned char *)ca_cert, cert_len ? cert_len : strlen(ca_cert) + 1);
|
||||
return tls->set_ca_cert(cert);
|
||||
}
|
||||
|
||||
bool esp_transport_batch_set_cn(esp_transport_handle_t t, const char *name)
|
||||
{
|
||||
auto tls = static_cast<TlsTransport *>(esp_transport_get_context_data(t));
|
||||
return tls->set_hostname(name);
|
||||
}
|
||||
|
||||
int TlsTransport::preread(size_t len, int timeout_ms)
|
||||
{
|
||||
while (len != read_len) {
|
||||
int l = esp_transport_read(transport_, buf.data() + read_len, len - read_len, timeout_ms);
|
||||
ESP_LOGD(TAG, "need %d read %d already %d", len, l, read_len);
|
||||
if ((l == ERR_TCP_TRANSPORT_CONNECTION_CLOSED_BY_FIN || l == ERR_TCP_TRANSPORT_CONNECTION_TIMEOUT ) && read_len > 0) {
|
||||
return read_len;
|
||||
}
|
||||
if (l <= 0) {
|
||||
read_len = 0;
|
||||
return read_len;
|
||||
}
|
||||
read_len += l;
|
||||
}
|
||||
return read_len;
|
||||
}
|
||||
|
||||
bool TlsTransport::prepare_buffer(size_t max_size)
|
||||
{
|
||||
buf.resize(max_size);
|
||||
return true;
|
||||
}
|
||||
|
||||
int esp_transport_batch_tls_pre_read(esp_transport_handle_t t, size_t len, int timeout_ms)
|
||||
{
|
||||
auto tls = static_cast<TlsTransport *>(esp_transport_get_context_data(t));
|
||||
return tls->preread(len, timeout_ms);
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @brief Creates batch transport
|
||||
*
|
||||
* @param parent tcp-transport handle to the parent transport
|
||||
* @param max_buffer_size maximum size of one batch
|
||||
* @return created transport handle
|
||||
*/
|
||||
esp_transport_handle_t esp_transport_batch_tls_init(esp_transport_handle_t parent, const size_t max_buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Performs batch read operation from the underlying transport
|
||||
*
|
||||
* @param t Transport handle
|
||||
* @param len Batch size
|
||||
* @param timeout_ms Timeout in ms
|
||||
* @return true If read from the parent transport completed successfully
|
||||
*/
|
||||
bool esp_transport_batch_tls_pre_read(esp_transport_handle_t t, size_t len, int timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Set the CA Certificate to verify the server
|
||||
*
|
||||
* @param ca_cert Pointer to the CA Cert data
|
||||
* @param cert_len CA Cert data len (set to 0 if null terminated string, i.e. PEM format)
|
||||
* @return true on success
|
||||
*/
|
||||
bool esp_transport_batch_set_ca_cert(esp_transport_handle_t t, const char *ca_cert, size_t cert_len);
|
||||
|
||||
/**
|
||||
* @brief Set comman name
|
||||
* @param t
|
||||
* @param ca_cert
|
||||
* @param cert_len
|
||||
* @return
|
||||
*/
|
||||
bool esp_transport_batch_set_cn(esp_transport_handle_t t, const char *name);
|
15
components/esp_modem/test/target_ota/http_server.py
Normal file
15
components/esp_modem/test/target_ota/http_server.py
Normal file
@ -0,0 +1,15 @@
|
||||
# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
import ssl
|
||||
from http.server import HTTPServer
|
||||
|
||||
from RangeHTTPServer import RangeRequestHandler
|
||||
|
||||
server_address = ('0.0.0.0', 1234)
|
||||
httpd = HTTPServer(server_address, RangeRequestHandler)
|
||||
httpd.socket = ssl.wrap_socket(httpd.socket,
|
||||
server_side=True,
|
||||
certfile='srv.crt',
|
||||
keyfile='srv.key',
|
||||
ssl_version=ssl.PROTOCOL_TLS)
|
||||
httpd.serve_forever()
|
2
components/esp_modem/test/target_ota/main/CMakeLists.txt
Normal file
2
components/esp_modem/test/target_ota/main/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS ota_test.cpp
|
||||
INCLUDE_DIRS ".")
|
60
components/esp_modem/test/target_ota/main/Kconfig.projbuild
Normal file
60
components/esp_modem/test/target_ota/main/Kconfig.projbuild
Normal file
@ -0,0 +1,60 @@
|
||||
menu "Test Configuration"
|
||||
|
||||
choice TEST_DEVICE
|
||||
prompt "Choose supported modem device (DCE)"
|
||||
default TEST_DEVICE_MODEM_GENERIC
|
||||
help
|
||||
Select modem device connected to the ESP DTE.
|
||||
|
||||
config TEST_DEVICE_MODEM_GENERIC
|
||||
bool "Common modem device"
|
||||
help
|
||||
Generic device that could be used with most common modems (BG96, SIM76xx, A76xx).
|
||||
|
||||
config TEST_DEVICE_PPPD_SERVER
|
||||
bool "PPPD Server"
|
||||
help
|
||||
Test device is a pppd service in server mode, running on linux.
|
||||
endchoice
|
||||
|
||||
config TEST_MODEM_APN
|
||||
string "Modem APN"
|
||||
depends on TEST_DEVICE_MODEM_GENERIC
|
||||
default "lpwa.vodafone.com"
|
||||
help
|
||||
Set APN (Access Point Name), a logical name to choose data network
|
||||
|
||||
config TEST_USE_VFS_TERM
|
||||
bool "Use VFS terminal"
|
||||
default n
|
||||
help
|
||||
Demonstrate use of VFS as a communication terminal of the DTE.
|
||||
VFS driver implements non-block reads, writes and selects to communicate with esp-modem,
|
||||
but this implementation uses UART resource only.
|
||||
|
||||
config TEST_OTA_URI
|
||||
string "URI of the binary"
|
||||
default "https://192.168.11.1/esp32.bin"
|
||||
help
|
||||
HTTPS address of the update binary.
|
||||
|
||||
config TEST_OTA_CA_CERT
|
||||
string "Server certificate"
|
||||
default "---paste the server side certificate here---"
|
||||
help
|
||||
Insert the CA cert of the server side here. copy the base64 text between -----BEGIN CERTIFICATE-----
|
||||
and -----END CERTIFICATE-----.
|
||||
|
||||
config TEST_OTA_CN
|
||||
string "Server common name"
|
||||
default "192.168.11.1"
|
||||
help
|
||||
Insert the server's common name to be checked within verification of the Server side certificat
|
||||
|
||||
config BROKER_URI
|
||||
string "Broker URL"
|
||||
default "mqtt://test.mosquitto.org"
|
||||
help
|
||||
URL of an mqtt broker which this example connects to.
|
||||
|
||||
endmenu
|
55
components/esp_modem/test/target_ota/main/network_dce.hpp
Normal file
55
components/esp_modem/test/target_ota/main/network_dce.hpp
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
|
||||
#include "cxx_include/esp_modem_dte.hpp"
|
||||
#include "esp_modem_config.h"
|
||||
#include "cxx_include/esp_modem_api.hpp"
|
||||
#include "cxx_include/esp_modem_dce_factory.hpp"
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
class NetModule;
|
||||
|
||||
/**
|
||||
* @brief Custom factory which can build and create a DCE using a custom module
|
||||
*/
|
||||
class NetDCE_Factory: public esp_modem::dce_factory::Factory {
|
||||
public:
|
||||
template <typename T, typename ...Args>
|
||||
static auto create(const esp_modem::dce_factory::config *cfg, Args &&... args) -> std::shared_ptr<esp_modem::DCE_T<T>>
|
||||
{
|
||||
return build_generic_DCE<T, esp_modem::DCE_T<T>, std::shared_ptr<esp_modem::DCE_T<T>>>(cfg, std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This is a null-module, doesn't define any AT commands, just passes everything to pppd
|
||||
*/
|
||||
class NetModule: public esp_modem::ModuleIf {
|
||||
public:
|
||||
explicit NetModule(std::shared_ptr<esp_modem::DTE> dte, const esp_modem_dce_config *cfg):
|
||||
dte(std::move(dte)) {}
|
||||
|
||||
bool setup_data_mode() override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool set_mode(esp_modem::modem_mode mode) override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<esp_modem::DTE> dte;
|
||||
};
|
||||
|
||||
|
||||
std::shared_ptr<esp_modem::DCE_T<NetModule>> create(std::shared_ptr<esp_modem::DTE> dte, esp_netif_t *netif)
|
||||
{
|
||||
const esp_modem::dce_config config = {};
|
||||
return NetDCE_Factory::create<NetModule>(&config, dte, netif);
|
||||
}
|
307
components/esp_modem/test/target_ota/main/ota_test.cpp
Normal file
307
components/esp_modem/test/target_ota/main/ota_test.cpp
Normal file
@ -0,0 +1,307 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_netif.h"
|
||||
#include "esp_netif_ppp.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_event.h"
|
||||
#include "cxx_include/esp_modem_dte.hpp"
|
||||
#include "esp_modem_config.h"
|
||||
#include "cxx_include/esp_modem_api.hpp"
|
||||
#include "esp_vfs_dev.h" // For optional VFS support
|
||||
#include "vfs_resource/vfs_create.hpp"
|
||||
#include "network_dce.hpp"
|
||||
#include "manual_ota.hpp"
|
||||
#include "mqtt_client.h"
|
||||
|
||||
using namespace esp_modem;
|
||||
|
||||
static const char *TAG = "ota_test";
|
||||
|
||||
|
||||
// Wrap event handlers to destruct correctly on returning from main
|
||||
class StatusHandler {
|
||||
public:
|
||||
static constexpr auto IP_Event = SignalGroup::bit0;
|
||||
static constexpr auto MQTT_Connect = SignalGroup::bit1;
|
||||
static constexpr auto MQTT_Data = SignalGroup::bit2;
|
||||
|
||||
StatusHandler()
|
||||
{
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, on_event, this));
|
||||
}
|
||||
|
||||
~StatusHandler()
|
||||
{
|
||||
esp_event_handler_unregister(IP_EVENT, ESP_EVENT_ANY_ID, on_event);
|
||||
}
|
||||
|
||||
void handle_mqtt(esp_mqtt_client_handle_t client)
|
||||
{
|
||||
mqtt = client;
|
||||
esp_mqtt_client_register_event(client, MQTT_EVENT_ANY, on_event, this);
|
||||
}
|
||||
|
||||
void remove_mqtt()
|
||||
{
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
|
||||
esp_mqtt_client_unregister_event(mqtt, MQTT_EVENT_ANY, on_event);
|
||||
#endif
|
||||
mqtt = nullptr;
|
||||
}
|
||||
|
||||
esp_err_t wait_for(decltype(IP_Event) event, int milliseconds)
|
||||
{
|
||||
return signal.wait_any(event, milliseconds);
|
||||
}
|
||||
|
||||
ip_event_t get_ip_event_type()
|
||||
{
|
||||
return ip_event_type;
|
||||
}
|
||||
|
||||
private:
|
||||
static void on_event(void *arg, esp_event_base_t base, int32_t event, void *data)
|
||||
{
|
||||
auto *handler = static_cast<StatusHandler *>(arg);
|
||||
if (base == IP_EVENT) {
|
||||
handler->ip_event(event, data);
|
||||
} else {
|
||||
handler->mqtt_event(event, data);
|
||||
}
|
||||
}
|
||||
|
||||
void ip_event(int32_t id, void *data)
|
||||
{
|
||||
if (id == IP_EVENT_PPP_GOT_IP) {
|
||||
auto *event = (ip_event_got_ip_t *)data;
|
||||
ESP_LOGI(TAG, "IP : " IPSTR, IP2STR(&event->ip_info.ip));
|
||||
ESP_LOGI(TAG, "Netmask : " IPSTR, IP2STR(&event->ip_info.netmask));
|
||||
ESP_LOGI(TAG, "Gateway : " IPSTR, IP2STR(&event->ip_info.gw));
|
||||
signal.set(IP_Event);
|
||||
} else if (id == IP_EVENT_PPP_LOST_IP) {
|
||||
signal.set(IP_Event);
|
||||
}
|
||||
ip_event_type = static_cast<ip_event_t>(id);
|
||||
}
|
||||
|
||||
void mqtt_event(int32_t event, void *data)
|
||||
{
|
||||
if (mqtt && event == MQTT_EVENT_CONNECTED) {
|
||||
signal.set(MQTT_Connect);
|
||||
} else if (mqtt && event == MQTT_EVENT_DATA) {
|
||||
auto event_data = static_cast<esp_mqtt_event_handle_t>(data);
|
||||
ESP_LOGI(TAG, " TOPIC: %.*s", event_data->topic_len, event_data->topic);
|
||||
ESP_LOGI(TAG, " DATA: %.*s", event_data->data_len, event_data->data);
|
||||
signal.set(MQTT_Data);
|
||||
}
|
||||
}
|
||||
|
||||
esp_modem::SignalGroup signal{};
|
||||
esp_mqtt_client_handle_t mqtt{};
|
||||
ip_event_t ip_event_type{};
|
||||
};
|
||||
|
||||
// Wrap MQTT operations to destroy everything on returning from main
|
||||
struct PublishOnce {
|
||||
esp_mqtt_client_handle_t mqtt_;
|
||||
StatusHandler *events_;
|
||||
|
||||
PublishOnce(StatusHandler *events)
|
||||
{
|
||||
esp_mqtt_client_config_t config = { };
|
||||
config.broker.address.uri = CONFIG_BROKER_URI;
|
||||
mqtt_ = esp_mqtt_client_init(&config);
|
||||
events_ = events;
|
||||
events->handle_mqtt(mqtt_);
|
||||
}
|
||||
|
||||
bool Connect()
|
||||
{
|
||||
return esp_mqtt_client_start(mqtt_) == ESP_OK;
|
||||
}
|
||||
|
||||
bool SubscribePublish()
|
||||
{
|
||||
return esp_mqtt_client_subscribe(mqtt_, "/topic/esp-modem", 0) >= 0 &&
|
||||
esp_mqtt_client_publish(mqtt_, "/topic/esp-modem", "Hello modem", 0, 0, 0) >= 0;
|
||||
}
|
||||
|
||||
~PublishOnce()
|
||||
{
|
||||
events_->remove_mqtt();
|
||||
esp_mqtt_client_destroy(mqtt_);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// OTA related
|
||||
static constexpr auto OTA_OK = SignalGroup::bit0;
|
||||
static constexpr auto OTA_FAILED = SignalGroup::bit1;
|
||||
|
||||
void ota_task(void *ctx)
|
||||
{
|
||||
static const char *ca_cert_pem = "-----BEGIN CERTIFICATE-----\n" CONFIG_TEST_OTA_CA_CERT "\n-----END CERTIFICATE-----";
|
||||
auto ota_done = static_cast<esp_modem::SignalGroup *>(ctx);
|
||||
manual_ota ota;
|
||||
ota.http_.config_.url = CONFIG_TEST_OTA_URI;
|
||||
ota.http_.config_.cert_pem = ca_cert_pem;
|
||||
ota.size_ = 32;
|
||||
ota.common_name_ = CONFIG_TEST_OTA_CN;
|
||||
#ifndef CONFIG_ESP_HTTP_CLIENT_ENABLE_CUSTOM_TRANSPORT
|
||||
// will have to use NORMAL mode, before custom transport is supported in IDF
|
||||
ota.mode_ = manual_ota::mode::NORMAL;
|
||||
#endif
|
||||
|
||||
ota.begin();
|
||||
while (true) {
|
||||
if (!ota.perform()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
auto ret = ota.end();
|
||||
ota_done->set(ret ? OTA_OK : OTA_FAILED);
|
||||
vTaskDelete(nullptr);
|
||||
}
|
||||
|
||||
|
||||
// App related
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
esp_log_level_set("*", ESP_LOG_INFO);
|
||||
esp_log_level_set("ota_test", ESP_LOG_DEBUG);
|
||||
|
||||
// Initialize system functions
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
|
||||
// Initialize DTE
|
||||
esp_modem_dte_config_t dte_config = ESP_MODEM_DTE_DEFAULT_CONFIG();
|
||||
#ifdef CONFIG_TEST_USE_VFS_TERM
|
||||
// To code-cover the vfs layers
|
||||
struct esp_modem_vfs_uart_creator uart_config = ESP_MODEM_VFS_DEFAULT_UART_CONFIG("/dev/uart/1");
|
||||
assert(vfs_create_uart(&uart_config, &dte_config.vfs_config) == true);
|
||||
|
||||
auto dte = create_vfs_dte(&dte_config);
|
||||
esp_vfs_dev_uart_use_driver(uart_config.uart.port_num);
|
||||
#else
|
||||
auto dte = create_uart_dte(&dte_config);
|
||||
#endif // CONFIG_TEST_USE_VFS_TERM
|
||||
assert(dte);
|
||||
dte->set_error_cb([](terminal_error err) {
|
||||
ESP_LOGE(TAG, "DTE reported terminal error: %d", static_cast<int>(err));
|
||||
});
|
||||
|
||||
// Initialize PPP netif
|
||||
esp_netif_config_t netif_ppp_config = ESP_NETIF_DEFAULT_PPP();
|
||||
esp_netif_t *esp_netif = esp_netif_new(&netif_ppp_config);
|
||||
assert(esp_netif);
|
||||
|
||||
// Initialize DCE
|
||||
#ifdef CONFIG_TEST_DEVICE_PPPD_SERVER
|
||||
auto dce = create(dte, esp_netif);
|
||||
#else
|
||||
esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG(CONFIG_TEST_MODEM_APN);
|
||||
auto dce = create_generic_dce(&dce_config, dte, esp_netif);
|
||||
assert(dce);
|
||||
#endif
|
||||
|
||||
StatusHandler handler;
|
||||
|
||||
#ifndef CONFIG_TEST_DEVICE_PPPD_SERVER
|
||||
if (dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_MODE) &&
|
||||
dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_SWAP) &&
|
||||
dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_DATA)) {
|
||||
#else
|
||||
if (dce->set_mode(esp_modem::modem_mode::DATA_MODE)) {
|
||||
#endif
|
||||
ESP_LOGI(TAG, "Modem has correctly entered the desired mode (CMUX/DATA/Manual CMUX)");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to configure multiplexed command mode... exiting");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!handler.wait_for(StatusHandler::IP_Event, 60000)) {
|
||||
ESP_LOGE(TAG, "Cannot get IP within specified timeout... exiting");
|
||||
return;
|
||||
} else if (handler.get_ip_event_type() == IP_EVENT_PPP_GOT_IP) {
|
||||
ESP_LOGI(TAG, "Got IP address");
|
||||
|
||||
/* When connected to network, subscribe and publish some MQTT data */
|
||||
PublishOnce publish(&handler);
|
||||
if (!publish.Connect()) {
|
||||
ESP_LOGE(TAG, "Failed to connect to mqtt server");
|
||||
return;
|
||||
}
|
||||
if (!handler.wait_for(StatusHandler::MQTT_Connect, 60000)) {
|
||||
ESP_LOGE(TAG, "Cannot connect to %s within specified timeout... exiting", CONFIG_BROKER_URI);
|
||||
return;
|
||||
}
|
||||
ESP_LOGI(TAG, "Connected");
|
||||
|
||||
if (!publish.SubscribePublish()) {
|
||||
ESP_LOGE(TAG, "Failed to subscribe and publish to mqtt server");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!handler.wait_for(StatusHandler::MQTT_Data, 60000)) {
|
||||
ESP_LOGE(TAG, "Didn't receive published data within specified timeout... exiting");
|
||||
return;
|
||||
}
|
||||
ESP_LOGI(TAG, "Received MQTT data");
|
||||
|
||||
} else if (handler.get_ip_event_type() == IP_EVENT_PPP_LOST_IP) {
|
||||
ESP_LOGE(TAG, "PPP client has lost connection... exiting");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
esp_modem::SignalGroup ota_done{};
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
|
||||
// now stop the LCP keepalive before performing OTA
|
||||
esp_netif_ppp_config_t cfg;
|
||||
ESP_ERROR_CHECK(esp_netif_ppp_get_params(esp_netif, &cfg));
|
||||
cfg.ppp_lcp_echo_disabled = true;
|
||||
ESP_ERROR_CHECK(esp_netif_ppp_set_params(esp_netif, &cfg));
|
||||
#endif
|
||||
|
||||
// Run the OTA in a separate task to keep sending commands to the modem at the same time
|
||||
xTaskCreate(ota_task, "ota_task", 8192, &ota_done, 5, nullptr);
|
||||
|
||||
#ifndef CONFIG_TEST_DEVICE_PPPD_SERVER
|
||||
while (true) {
|
||||
std::string str;
|
||||
if (dce->get_imsi(str) == esp_modem::command_result::OK) {
|
||||
ESP_LOGI(TAG, "Modem IMSI number: %s", str.c_str());
|
||||
}
|
||||
if (ota_done.wait_any(OTA_OK | OTA_FAILED, 100)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
ota_done.wait_any(OTA_OK | OTA_FAILED, portMAX_DELAY);
|
||||
#endif // CONFIG_TEST_DEVICE_PPPD_SERVER
|
||||
|
||||
#ifndef CONFIG_TEST_DEVICE_PPPD_SERVER
|
||||
if (dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_EXIT)) {
|
||||
#else
|
||||
if (dce->set_mode(esp_modem::modem_mode::COMMAND_MODE)) {
|
||||
#endif
|
||||
ESP_LOGI(TAG, "Modem CMUX/DATA mode exit");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to configure desired mode... exiting");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ota_done.is_any(OTA_OK)) {
|
||||
ESP_LOGI(TAG, "Prepare to restart system!");
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
}
|
2
components/esp_modem/test/target_ota/sdkconfig.ci.1
Normal file
2
components/esp_modem/test/target_ota/sdkconfig.ci.1
Normal file
@ -0,0 +1,2 @@
|
||||
CONFIG_TEST_DEVICE_PPPD_SERVER=y
|
||||
CONFIG_ESP_MODEM_CMUX_DEFRAGMENT_PAYLOAD=n
|
4
components/esp_modem/test/target_ota/sdkconfig.ci.2
Normal file
4
components/esp_modem/test/target_ota/sdkconfig.ci.2
Normal file
@ -0,0 +1,4 @@
|
||||
CONFIG_TEST_DEVICE_MODEM_GENERIC=y
|
||||
CONFIG_TEST_OTA_URI="https://raw.githubusercontent.com/espressif/esp-protocols/master/components/esp_modem/test/target_ota/bin/blink.bin"
|
||||
CONFIG_TEST_OTA_CA_CERT="MIIEvjCCA6agAwIBAgIQBtjZBNVYQ0b2ii+nVCJ+xDANBgkqhkiG9w0BAQsFADBhMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBDQTAeFw0yMTA0MTQwMDAwMDBaFw0zMTA0MTMyMzU5NTlaME8xCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxKTAnBgNVBAMTIERpZ2lDZXJ0IFRMUyBSU0EgU0hBMjU2IDIwMjAgQ0ExMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwUuzZUdwvN1PWNvsnO3DZuUfMRNUrUpmRh8sCuxkB+Uu3Ny5CiDt3+PE0J6aqXodgojlEVbbHp9YwlHnLDQNLtKS4VbL8Xlfs7uHyiUDe5pSQWYQYE9XE0nw6Ddng9/n00tnTCJRpt8OmRDtV1F0JuJ9x8piLhMbfyOIJVNvwTRYAIuE//i+p1hJInuWraKImxW8oHzf6VGo1bDtN+I2tIJLYrVJmuzHZ9bjPvXj1hJeRPG/cUJ9WIQDgLGBAfr5yjK7tI4nhyfFK3TUqNaX3sNk+crOU6JWvHgXjkkDKa77SU+kFbnO8lwZV21reacroicgE7XQPUDTITAHk+qZ9QIDAQABo4IBgjCCAX4wEgYDVR0TAQH/BAgwBgEB/wIBADAdBgNVHQ4EFgQUt2ui6qiqhIx56rTaD5iyxZV2ufQwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUwDgYDVR0PAQH/BAQDAgGGMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjB2BggrBgEFBQcBAQRqMGgwJAYIKwYBBQUHMAGGGGh0dHA6Ly9vY3NwLmRpZ2ljZXJ0LmNvbTBABggrBgEFBQcwAoY0aHR0cDovL2NhY2VydHMuZGlnaWNlcnQuY29tL0RpZ2lDZXJ0R2xvYmFsUm9vdENBLmNydDBCBgNVHR8EOzA5MDegNaAzhjFodHRwOi8vY3JsMy5kaWdpY2VydC5jb20vRGlnaUNlcnRHbG9iYWxSb290Q0EuY3JsMD0GA1UdIAQ2MDQwCwYJYIZIAYb9bAIBMAcGBWeBDAEBMAgGBmeBDAECATAIBgZngQwBAgIwCAYGZ4EMAQIDMA0GCSqGSIb3DQEBCwUAA4IBAQCAMs5eC91uWg0Kr+HWhMvAjvqFcO3aXbMM9yt1QP6FCvrzMXi3cEsaiVi6gL3zax3pfs8LulicWdSQ0/1s/dCYbbdxglvPbQtaCdB73sRD2Cqk3p5BJl+7j5nL3a7hqG+fh/50tx8bIKuxT8b1Z11dmzzp/2n3YWzW2fP9NsarA4h20ksudYbj/NhVfSbCEXffPgK2fPOre3qGNm+499iTcc+G33Mw+nur7SpZyEKEOxEXGlLzyQ4UfaJbcme6ce1XR2bFuAJKZTRei9AqPCCcUZlM51Ke92sRKw2Sfh3oius2FkOH6ipjv3U/697EA7sKPPcw7+uvTPyLNhBzPvOk"
|
||||
CONFIG_TEST_OTA_CN="github.com"
|
4
components/esp_modem/test/target_ota/sdkconfig.ci.3
Normal file
4
components/esp_modem/test/target_ota/sdkconfig.ci.3
Normal file
@ -0,0 +1,4 @@
|
||||
CONFIG_TEST_DEVICE_PPPD_SERVER=y
|
||||
CONFIG_ESP_MODEM_CMUX_DEFRAGMENT_PAYLOAD=y
|
||||
CONFIG_ESP_MODEM_USE_INFLATABLE_BUFFER_IF_NEEDED=y
|
||||
CONFIG_TEST_USE_VFS_TERM=y
|
12
components/esp_modem/test/target_ota/sdkconfig.defaults
Normal file
12
components/esp_modem/test/target_ota/sdkconfig.defaults
Normal file
@ -0,0 +1,12 @@
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||
CONFIG_PARTITION_TABLE_TWO_OTA=y
|
||||
CONFIG_COMPILER_CXX_EXCEPTIONS=y
|
||||
# This is not supported in IDF yet
|
||||
# CONFIG_ESP_HTTP_CLIENT_ENABLE_CUSTOM_TRANSPORT=y
|
||||
CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192
|
||||
CONFIG_LWIP_PPP_SUPPORT=y
|
||||
CONFIG_LWIP_PPP_ENABLE_IPV6=n
|
||||
CONFIG_LWIP_ENABLE_LCP_ECHO=y
|
||||
CONFIG_LWIP_LCP_ECHOINTERVAL=1
|
||||
CONFIG_LWIP_LCP_MAXECHOFAILS=2
|
@ -3,6 +3,6 @@ commitizen:
|
||||
bump_message: 'bump(mqtt_cxx): $current_version -> $new_version'
|
||||
pre_bump_hooks: python ../../ci/changelog.py esp_mqtt_cxx
|
||||
tag_format: mqtt_cxx-v$version
|
||||
version: 0.2.0
|
||||
version: 0.3.0
|
||||
version_files:
|
||||
- idf_component.yml
|
||||
|
@ -1,5 +1,13 @@
|
||||
# Changelog
|
||||
|
||||
## [0.3.0](https://github.com/espressif/esp-protocols/commits/mqtt_cxx-v0.3.0)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Incorrect documentation link ([aa4e9d57](https://github.com/espressif/esp-protocols/commit/aa4e9d57))
|
||||
- reference protocol_examples_common from IDF ([e6c0538d](https://github.com/espressif/esp-protocols/commit/e6c0538d))
|
||||
- specify override_path in example manifest files ([fa005c63](https://github.com/espressif/esp-protocols/commit/fa005c63))
|
||||
|
||||
## [0.2.0](https://github.com/espressif/esp-protocols/commits/mqtt_cxx-v0.2.0)
|
||||
|
||||
### Features
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user