@@ -302,18 +302,32 @@ int CNetIf::begin(const IPAddress &ip, const IPAddress &nm, const IPAddress &gw)
302
302
ip_addr_t _nm = fromArduinoIP (nm);
303
303
ip_addr_t _gw = fromArduinoIP (gw);
304
304
305
- // netif add copies the ip addresses into the netif, no need to store them also in the object
306
- struct netif *_ni = netif_add (
307
- &this ->ni ,
308
- &_ip, &_nm, &_gw, // ip addresses are being copied and not taken as reference, use a local defined variable
309
- this ,
310
- _netif_init,
311
- ethernet_input
312
- );
313
- if (_ni == nullptr ) {
314
- return -1 ;
315
- }
305
+ char name[3 ] = {
306
+ ni.name [0 ],
307
+ ni.name [1 ],
308
+ ni.num + ' 0' ,
309
+ };
310
+ if (netif_find (name) == nullptr ) {
311
+
312
+ // netif add copies the ip addresses into the netif, no need to store them also in the object
313
+ struct netif *_ni = netif_add (
314
+ &this ->ni ,
315
+ &_ip, &_nm, &_gw, // ip addresses are being copied and not taken as reference, use a local defined variable
316
+ this ,
317
+ _netif_init,
318
+ ethernet_input
319
+ );
320
+
321
+ if (_ni == nullptr ) {
322
+ return -1 ;
323
+ }
324
+ } else {
325
+ if (netif_is_link_up (&this ->ni )) {
326
+ netif_set_down (&this ->ni );
327
+ }
316
328
329
+ // TODO check for any changes detected and update the iface
330
+ }
317
331
netif_set_up (&this ->ni );
318
332
319
333
// add the interface to the network stack
@@ -448,7 +462,7 @@ bool CNetIf::dhcpRenew() {
448
462
/* ##########################################################################
449
463
* ETHERNET NETWORK INTERFACE CLASS
450
464
* ########################################################################## */
451
- uint8_t CEth::eth_id = 0 ;
465
+ const char CEth::eth_ifname[] = " en " ;
452
466
453
467
CEth::CEth (NetworkDriver *driver)
454
468
: CNetIf(driver) {
@@ -470,19 +484,42 @@ int CEth::begin(const IPAddress &ip, const IPAddress &nm, const IPAddress &gw, c
470
484
return res;
471
485
}
472
486
487
+ int CEth::begin (
488
+ uint8_t *mac_address,
489
+ const IPAddress &local_ip,
490
+ const IPAddress &dns_server,
491
+ const IPAddress &gateway,
492
+ const IPAddress &subnet,
493
+ const unsigned long timeout,
494
+ const unsigned long responseTimeout) {
495
+
496
+ this ->setMacAddress (mac_address);
497
+
498
+ return this ->begin (local_ip, subnet, gateway, dns_server);
499
+ }
500
+
501
+ int CEth::begin (
502
+ uint8_t *mac_address,
503
+ const unsigned long timeout,
504
+ const unsigned long responseTimeout) {
505
+
506
+ this ->setMacAddress (mac_address);
507
+
508
+ return this ->begin ();
509
+ }
510
+
511
+
473
512
err_t CEth::init (struct netif * ni) {
474
513
// Setting up netif
475
514
#if LWIP_NETIF_HOSTNAME
476
515
ni->hostname = " C33_eth" ;
477
516
#endif
478
- ni->name [0 ] = CEth::eth_ifname_prefix ;
479
- ni->name [1 ] = ' 0 ' + CEth::eth_id++ ;
517
+ ni->name [0 ] = CEth::eth_ifname[ 0 ] ;
518
+ ni->name [1 ] = CEth::eth_ifname[ 1 ] ;
480
519
ni->mtu = 1500 ; // TODO get this from the network
481
520
ni->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;
482
521
483
522
memcpy (ni->hwaddr , this ->driver ->getMacAddress (), 6 ); // FIXME handle this using a constant
484
- // ni->hwaddr = C33EthernetDriver.getMacAddress();
485
- // ni->hwaddr_len = sizeof(macaddress);
486
523
ni->hwaddr_len = 6 ;
487
524
488
525
ni->output = etharp_output;
@@ -549,7 +586,7 @@ void CEth::consume_callback(uint8_t* buffer, uint32_t len) {
549
586
/* ########################################################################## */
550
587
/* CWifiStation NETWORK INTERFACE CLASS */
551
588
/* ########################################################################## */
552
- uint8_t CWifiStation::wifistation_id = 0 ;
589
+ const char CWifiStation::wifistation_ifname[] = " ws " ;
553
590
554
591
CWifiStation::CWifiStation ()
555
592
: hw_init(false ) {
@@ -673,8 +710,8 @@ err_t CWifiStation::init(struct netif* ni) {
673
710
#if LWIP_NETIF_HOSTNAME
674
711
ni->hostname = " C33-WifiSta" ;
675
712
#endif
676
- ni->name [0 ] = CWifiStation::wifistation_ifname_prefix ;
677
- ni->name [1 ] = ' 0 ' + CWifiStation::wifistation_id++ ;
713
+ ni->name [0 ] = CWifiStation::wifistation_ifname[ 0 ] ;
714
+ ni->name [1 ] = CWifiStation::wifistation_ifname[ 1 ] ;
678
715
ni->mtu = 1500 ; // FIXME get this from the network
679
716
ni->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;
680
717
@@ -859,7 +896,7 @@ int CWifiStation::resetLowPowerMode() {
859
896
/* ########################################################################## */
860
897
/* CWifiSoftAp NETWORK INTERFACE CLASS */
861
898
/* ########################################################################## */
862
- uint8_t CWifiSoftAp::softap_id = 0 ;
899
+ const char CWifiSoftAp::softap_ifname[] = " sa " ;
863
900
864
901
// This is required for dhcp server to assign ip addresses to AP clients
865
902
IPAddress default_nm (" 255.255.255.0" );
@@ -883,7 +920,7 @@ int CWifiSoftAp::begin(const IPAddress &ip, const IPAddress &nm, const IPAddress
883
920
return ESP_CONTROL_OK;
884
921
});
885
922
886
- if ((res=CEspControl::getInstance ().initSpiDriver ()) != 0 ) {
923
+ if ((res=CEspControl::getInstance ().initSpiDriver ()) != 0 && !hw_init ) {
887
924
// res = -1; // FIXME put a proper error code
888
925
goto exit ;
889
926
}
@@ -953,8 +990,8 @@ err_t CWifiSoftAp::init(struct netif* ni) {
953
990
// TODO pass the hostname in the constructor os with a setter
954
991
ni->hostname = " C33-SoftAP" ;
955
992
#endif
956
- ni->name [0 ] = CWifiSoftAp::softap_ifname_prefix ;
957
- ni->name [1 ] = ' 0 ' + CWifiSoftAp::softap_id++ ;
993
+ ni->name [0 ] = CWifiSoftAp::softap_ifname[ 0 ] ;
994
+ ni->name [1 ] = CWifiSoftAp::softap_ifname[ 1 ] ;
958
995
ni->mtu = 1500 ; // FIXME get this from the network
959
996
ni->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;
960
997
0 commit comments