@@ -34,14 +34,7 @@ static const char *TAG = "eppp_link";
34
34
static int s_retry_num = 0 ;
35
35
static int s_eppp_netif_count = 0 ; // used as a suffix for the netif key
36
36
37
- #if CONFIG_EPPP_LINK_DEVICE_SDIO
38
-
39
- #elif CONFIG_EPPP_LINK_DEVICE_ETH
40
-
41
- #else
42
- #endif
43
-
44
- static void netif_deinit (esp_netif_t * netif )
37
+ void eppp_netif_deinit (esp_netif_t * netif )
45
38
{
46
39
if (netif == NULL ) {
47
40
return ;
@@ -52,47 +45,43 @@ static void netif_deinit(esp_netif_t *netif)
52
45
}
53
46
}
54
47
55
- extern esp_netif_netstack_config_t * netstack_default_slip ;
48
+ #ifdef CONFIG_EPPP_LINK_USES_PPP
49
+ #define NETSTACK_CONFIG () ESP_NETIF_NETSTACK_DEFAULT_PPP
50
+ #else
51
+ #define NETSTACK_CONFIG () g_eppp_netif_config_tun
52
+ extern esp_netif_netstack_config_t * g_eppp_netif_config_tun ;
56
53
#define ESP_NETIF_INHERENT_DEFAULT_SLIP () \
57
54
{ \
58
55
ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(mac) \
59
56
ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(ip_info) \
60
57
.flags = ESP_NETIF_FLAG_EVENT_IP_MODIFIED, \
61
58
.get_ip_event = IP_EVENT_PPP_GOT_IP, \
62
59
.lost_ip_event = IP_EVENT_PPP_LOST_IP, \
63
- .if_key = "SLP_DEF ", \
64
- .if_desc = "slip ", \
60
+ .if_key = "EPPP_TUN ", \
61
+ .if_desc = "eppp ", \
65
62
.route_prio = 1, \
66
63
.bridge_info = NULL \
67
64
};
65
+ #endif // CONFIG_EPPP_LINK_USES_PPP
68
66
69
- static esp_netif_t * netif_init (eppp_type_t role , eppp_transport_handle_t h , eppp_config_t * eppp_config )
67
+ esp_netif_t * eppp_netif_init (eppp_type_t role , eppp_transport_handle_t h , eppp_config_t * eppp_config )
70
68
{
71
69
if (s_eppp_netif_count > 9 ) { // Limit to max 10 netifs, since we use "EPPPx" as the unique key (where x is 0-9)
72
70
ESP_LOGE (TAG , "Cannot create more than 10 instances" );
73
71
return NULL ;
74
72
}
75
73
76
74
h -> role = role ;
77
- // esp_netif_driver_ifconfig_t driver_cfg = {
78
- // .handle = h,
79
- //#if CONFIG_EPPP_LINK_DEVICE_SDIO
80
- // .transmit = role == EPPP_CLIENT ? eppp_sdio_host_tx : eppp_sdio_slave_tx,
81
- //#elif CONFIG_EPPP_LINK_DEVICE_ETH
82
- // .transmit = eppp_transport_tx,
83
- //#else
84
- // .transmit = transmit,
85
- //#endif
86
- // };
87
- // const esp_netif_driver_ifconfig_t *ppp_driver_cfg = &driver_cfg;
75
+ #ifdef CONFIG_EPPP_LINK_USES_PPP
76
+ esp_netif_inherent_config_t base_netif_cfg = ESP_NETIF_INHERENT_DEFAULT_PPP ();
77
+ #else
78
+ esp_netif_inherent_config_t base_netif_cfg = ESP_NETIF_INHERENT_DEFAULT_SLIP ();
88
79
esp_netif_ip_info_t slip_ip4 = {};
89
80
slip_ip4 .ip .addr = eppp_config -> ppp .our_ip4_addr .addr ;
90
81
slip_ip4 .gw .addr = eppp_config -> ppp .their_ip4_addr .addr ;
91
82
slip_ip4 .netmask .addr = ESP_IP4TOADDR (255 , 255 , 255 , 0 );
92
-
93
- esp_netif_inherent_config_t base_netif_cfg = ESP_NETIF_INHERENT_DEFAULT_SLIP ();
94
83
base_netif_cfg .ip_info = & slip_ip4 ;
95
-
84
+ #endif
96
85
char if_key [] = "EPPP0" ; // netif key needs to be unique
97
86
if_key [sizeof (if_key ) - 2 /* 2 = two chars before the terminator */ ] += s_eppp_netif_count ++ ;
98
87
base_netif_cfg .if_key = if_key ;
@@ -104,12 +93,27 @@ static esp_netif_t *netif_init(eppp_type_t role, eppp_transport_handle_t h, eppp
104
93
if (eppp_config -> ppp .netif_prio ) {
105
94
base_netif_cfg .route_prio = eppp_config -> ppp .netif_prio ;
106
95
}
107
- esp_netif_config_t netif_ppp_config = { .base = & base_netif_cfg ,
108
- .driver = NULL ,
109
- .stack = netstack_default_slip ,
110
- };
96
+ esp_netif_config_t netif_config = { .base = & base_netif_cfg ,
97
+ .driver = NULL ,
98
+ .stack = NETSTACK_CONFIG () ,
99
+ };
111
100
112
- return esp_netif_new (& netif_ppp_config );
101
+ #ifdef CONFIG_EPPP_LINK_USES_PPP
102
+ __attribute__((unused )) esp_err_t ret = ESP_OK ;
103
+ esp_netif_t * netif = esp_netif_new (& netif_config );
104
+ esp_netif_ppp_config_t netif_params ;
105
+ ESP_GOTO_ON_ERROR (esp_netif_ppp_get_params (netif , & netif_params ), err , TAG , "Failed to get PPP params" );
106
+ netif_params .ppp_our_ip4_addr = eppp_config -> ppp .our_ip4_addr ;
107
+ netif_params .ppp_their_ip4_addr = eppp_config -> ppp .their_ip4_addr ;
108
+ netif_params .ppp_error_event_enabled = true;
109
+ ESP_GOTO_ON_ERROR (esp_netif_ppp_set_params (netif , & netif_params ), err , TAG , "Failed to set PPP params" );
110
+ return netif ;
111
+ err :
112
+ esp_netif_destroy (netif );
113
+ return NULL ;
114
+ #else
115
+ return esp_netif_new (& netif_config );
116
+ #endif // CONFIG_EPPP_LINK_USES_PPP
113
117
}
114
118
115
119
esp_err_t eppp_netif_stop (esp_netif_t * netif , int stop_timeout_ms )
@@ -130,14 +134,16 @@ esp_err_t eppp_netif_stop(esp_netif_t *netif, int stop_timeout_ms)
130
134
return ESP_OK ;
131
135
}
132
136
133
- void try_ping (esp_netif_t * netif );
134
-
135
137
esp_err_t eppp_netif_start (esp_netif_t * netif )
136
138
{
137
139
esp_netif_action_start (netif , 0 , 0 , 0 );
138
140
esp_netif_action_connected (netif , 0 , 0 , 0 );
139
- try_ping (netif );
141
+ #ifndef CONFIG_EPPP_LINK_USES_PPP
142
+ // PPP provides address negotiation, if not PPP, we need to check connection manually
143
+ return eppp_check_connection (netif );
144
+ #else
140
145
return ESP_OK ;
146
+ #endif
141
147
}
142
148
143
149
static int get_netif_num (esp_netif_t * netif )
@@ -160,7 +166,6 @@ static int get_netif_num(esp_netif_t *netif)
160
166
static void on_ppp_event (void * arg , esp_event_base_t base , int32_t event_id , void * data )
161
167
{
162
168
esp_netif_t * * netif = data ;
163
- ESP_LOGD (TAG , "PPP status event: %" PRId32 , event_id );
164
169
if (base == NETIF_PPP_STATUS && event_id == NETIF_PPP_ERRORUSER ) {
165
170
ESP_LOGI (TAG , "Disconnected %d" , get_netif_num (* netif ));
166
171
struct eppp_handle * h = esp_netif_get_io_driver (* netif );
@@ -193,14 +198,6 @@ static void on_ip_event(void *arg, esp_event_base_t base, int32_t event_id, void
193
198
}
194
199
}
195
200
196
- //#if CONFIG_EPPP_LINK_DEVICE_SPI
197
-
198
- #if CONFIG_EPPP_LINK_DEVICE_SDIO
199
-
200
-
201
-
202
- #endif // UART
203
-
204
201
#if EPPP_NEEDS_TASK
205
202
static void ppp_task (void * args )
206
203
{
@@ -221,7 +218,7 @@ static void remove_handlers(void)
221
218
{
222
219
esp_netif_t * netif = esp_netif_find_if (have_some_eppp_netif , NULL );
223
220
if (netif == NULL ) {
224
- // if EPPP netif in the system, we cleanup the statics
221
+ // if EPPP netif in the system, we clean up the statics
225
222
vEventGroupDelete (s_event_group );
226
223
s_event_group = NULL ;
227
224
esp_event_handler_unregister (IP_EVENT , ESP_EVENT_ANY_ID , on_ip_event );
@@ -235,23 +232,8 @@ void eppp_deinit(esp_netif_t *netif)
235
232
return ;
236
233
}
237
234
struct eppp_handle * h = esp_netif_get_io_driver (netif );
238
- #if CONFIG_EPPP_LINK_DEVICE_SPI
239
- EPPP_TRANSPORT_DEINIT (h );
240
- // if (h->role == EPPP_CLIENT) {
241
- // deinit_master(netif);
242
- // } else {
243
- // deinit_slave(netif);
244
- // }
245
- #elif CONFIG_EPPP_LINK_DEVICE_UART
246
- EPPP_TRANSPORT_DEINIT (h );
247
- // deinit_uart(esp_netif_get_io_driver(netif));
248
- #elif CONFIG_EPPP_LINK_DEVICE_SDIO
249
- // struct eppp_handle *h = esp_netif_get_io_driver(netif);
250
235
EPPP_TRANSPORT_DEINIT (h );
251
- #elif CONFIG_EPPP_LINK_DEVICE_ETH
252
- EPPP_TRANSPORT_DEINIT (h );
253
- #endif
254
- netif_deinit (netif );
236
+ eppp_netif_deinit (netif );
255
237
}
256
238
257
239
esp_netif_t * eppp_init (eppp_type_t role , eppp_config_t * config )
@@ -265,47 +247,15 @@ esp_netif_t *eppp_init(eppp_type_t role, eppp_config_t *config)
265
247
266
248
eppp_transport_handle_t h = EPPP_TRANSPORT_INIT (config );
267
249
ESP_GOTO_ON_FALSE (h , ESP_ERR_NO_MEM , err , TAG , "Failed to init EPPP transport" );
268
- ESP_GOTO_ON_FALSE (netif = netif_init (role , h , config ), ESP_ERR_NO_MEM , err , TAG , "Failed to init EPPP netif" );
269
-
270
- #ifdef CONFIG_EPPP_OVER_PPP
271
- esp_netif_ppp_config_t netif_params ;
272
- ESP_ERROR_CHECK (esp_netif_ppp_get_params (netif , & netif_params ));
273
- netif_params .ppp_our_ip4_addr = config -> ppp .our_ip4_addr ;
274
- netif_params .ppp_their_ip4_addr = config -> ppp .their_ip4_addr ;
275
- netif_params .ppp_error_event_enabled = true;
276
- ESP_ERROR_CHECK (esp_netif_ppp_set_params (netif , & netif_params ));
277
- #endif
278
-
279
- #if CONFIG_EPPP_LINK_DEVICE_UART
280
- // init_uart(esp_netif_get_io_driver(netif), config);
281
- #elif CONFIG_EPPP_LINK_DEVICE_SDIO
282
- // esp_err_t ret;
283
- //// if (role == EPPP_SERVER) {
284
- //// ret = eppp_sdio_slave_init();
285
- //// } else {
286
- //// ret = eppp_sdio_host_init(&config->sdio);
287
- //// }
288
- //
289
- // if (ret != ESP_OK) {
290
- // ESP_LOGE(TAG, "Failed to initialize SDIO %d", ret);
291
- // return NULL;
292
- // }
293
- #elif CONFIG_EPPP_LINK_DEVICE_ETH
294
- // ret = eppp_transport_init(config, netif);
295
- // if (ret != ESP_OK) {
296
- // ESP_LOGE(TAG, "Failed to initialize SDIO %d", ret);
297
- // return NULL;
298
- // }
299
-
300
- #endif
250
+ ESP_GOTO_ON_FALSE (netif = eppp_netif_init (role , h , config ), ESP_ERR_NO_MEM , err , TAG , "Failed to init EPPP netif" );
301
251
ESP_GOTO_ON_ERROR (esp_netif_attach (netif , h ), err , TAG , "Failed to attach netif to EPPP transport" );
302
252
return netif ;
303
253
err :
304
254
if (h ) {
305
255
EPPP_TRANSPORT_DEINIT (h );
306
256
}
307
257
if (netif ) {
308
- netif_deinit (netif );
258
+ eppp_netif_deinit (netif );
309
259
}
310
260
return NULL ;
311
261
}
0 commit comments