|
1 | 1 | /*
|
2 |
| - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD |
| 2 | + * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD |
3 | 3 | *
|
4 | 4 | * SPDX-License-Identifier: Apache-2.0
|
5 | 5 | */
|
@@ -65,45 +65,55 @@ static esp_err_t receive(esp_eth_handle_t h, uint8_t *buffer, uint32_t len, void
|
65 | 65 | return ESP_FAIL;
|
66 | 66 | }
|
67 | 67 |
|
68 |
| -esp_err_t eppp_transport_init(eppp_config_t *config, esp_netif_t *esp_netif) |
| 68 | +__attribute__((weak)) esp_err_t eppp_transport_ethernet_init(esp_eth_handle_t *handle_array[]) |
69 | 69 | {
|
70 | 70 | uint8_t eth_port_cnt = 0;
|
71 |
| - ESP_ERROR_CHECK(ethernet_init_all(&s_eth_handles, ð_port_cnt)); |
72 |
| - if (eth_port_cnt > 1) { |
73 |
| - ESP_LOGW(TAG, "multiple Ethernet devices detected, the first initialized is to be used!"); |
74 |
| - } |
75 |
| - ESP_ERROR_CHECK(esp_eth_update_input_path(s_eth_handles[0], receive, esp_netif)); |
| 71 | + ESP_RETURN_ON_ERROR(ethernet_init_all(handle_array, ð_port_cnt), TAG, "Failed to init common eth drivers"); |
| 72 | + ESP_RETURN_ON_FALSE(eth_port_cnt > 1, ESP_ERR_INVALID_ARG, TAG, "multiple Ethernet devices detected, please init only one"); |
| 73 | + return ESP_OK; |
| 74 | +} |
| 75 | + |
| 76 | +__attribute__((weak)) void eppp_transport_ethernet_deinit(esp_eth_handle_t *handle_array) |
| 77 | +{ |
| 78 | + ethernet_deinit_all(s_eth_handles); |
| 79 | +} |
| 80 | + |
| 81 | + |
| 82 | +esp_err_t eppp_transport_init(eppp_config_t *config, esp_netif_t *esp_netif) |
| 83 | +{ |
| 84 | + ESP_RETURN_ON_ERROR(eppp_transport_ethernet_init(&s_eth_handles), TAG, "Failed to initialize Ethernet driver"); |
| 85 | + ESP_RETURN_ON_ERROR(esp_eth_update_input_path(s_eth_handles[0], receive, esp_netif), TAG, "Failed to set Ethernet Rx callback"); |
76 | 86 | sscanf(CONFIG_EPPP_LINK_ETHERNET_OUR_ADDRESS, "%2" PRIu8 ":%2" PRIu8 ":%2" PRIi8 ":%2" PRIu8 ":%2" PRIu8 ":%2" PRIu8,
|
77 | 87 | &s_our_mac[0], &s_our_mac[1], &s_our_mac[2], &s_our_mac[3], &s_our_mac[4], &s_our_mac[5]);
|
78 | 88 |
|
79 | 89 | sscanf(CONFIG_EPPP_LINK_ETHERNET_THEIR_ADDRESS, "%2" PRIu8 ":%2" PRIu8 ":%2" PRIi8 ":%2" PRIu8 ":%2" PRIu8 ":%2" PRIu8,
|
80 | 90 | &s_their_mac[0], &s_their_mac[1], &s_their_mac[2], &s_their_mac[3], &s_their_mac[4], &s_their_mac[5]);
|
81 | 91 | esp_eth_ioctl(s_eth_handles[0], ETH_CMD_S_MAC_ADDR, s_our_mac);
|
82 |
| - ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, event_handler, NULL)); |
83 |
| - ESP_ERROR_CHECK(esp_eth_start(s_eth_handles[0])); |
| 92 | + ESP_RETURN_ON_ERROR(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, event_handler, NULL), TAG, "Failed to register Ethernet handlers"); |
| 93 | + ESP_RETURN_ON_ERROR(esp_eth_start(s_eth_handles[0]), TAG, "Failed to start Ethernet driver"); |
84 | 94 | return ESP_OK;
|
85 | 95 | }
|
86 | 96 |
|
87 | 97 | void eppp_transport_deinit(void)
|
88 | 98 | {
|
89 |
| - ethernet_deinit_all(s_eth_handles); |
| 99 | + esp_eth_stop(s_eth_handles[0]); |
| 100 | + eppp_transport_ethernet_deinit(s_eth_handles); |
90 | 101 | }
|
91 | 102 |
|
92 | 103 | esp_err_t eppp_transport_tx(void *h, void *buffer, size_t len)
|
93 | 104 | {
|
94 | 105 | if (!s_is_connected) {
|
95 |
| - return ESP_OK; |
| 106 | + return ESP_FAIL; |
96 | 107 | }
|
97 | 108 | // setup Ethernet header
|
98 | 109 | header_t *head = (header_t *)s_out_buffer;
|
99 | 110 | memcpy(head->dst, s_their_mac, ETH_ADDR_LEN);
|
100 | 111 | memcpy(head->src, s_our_mac, ETH_ADDR_LEN);
|
101 | 112 | head->len = len;
|
102 |
| - // handle frame size: ETH_MIN_PAYLOAD_LEN <= len <= ETH_MAX_PAYLOAD_LEN |
103 |
| - size_t frame_payload_len = len < ETH_MIN_PAYLOAD_LEN ? ETH_MIN_PAYLOAD_LEN : len; |
104 |
| - if (frame_payload_len > ETH_MAX_PAYLOAD_LEN) { |
| 113 | + // support only payloads with len <= ETH_MAX_PAYLOAD_LEN |
| 114 | + if (len > ETH_MAX_PAYLOAD_LEN) { |
105 | 115 | return ESP_FAIL;
|
106 | 116 | }
|
107 | 117 | memcpy(s_out_buffer + ETH_HEADER_LEN, buffer, len);
|
108 |
| - return esp_eth_transmit(s_eth_handles[0], s_out_buffer, frame_payload_len + ETH_HEADER_LEN); |
| 118 | + return esp_eth_transmit(s_eth_handles[0], s_out_buffer, len + ETH_HEADER_LEN); |
109 | 119 | }
|
0 commit comments