@@ -302,18 +302,32 @@ int CNetIf::begin(const IPAddress &ip, const IPAddress &nm, const IPAddress &gw)
302302 ip_addr_t _nm = fromArduinoIP (nm);
303303 ip_addr_t _gw = fromArduinoIP (gw);
304304
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+ }
316328
329+ // TODO check for any changes detected and update the iface
330+ }
317331 netif_set_up (&this ->ni );
318332
319333 // add the interface to the network stack
@@ -448,7 +462,7 @@ bool CNetIf::dhcpRenew() {
448462/* ##########################################################################
449463 * ETHERNET NETWORK INTERFACE CLASS
450464 * ########################################################################## */
451- uint8_t CEth::eth_id = 0 ;
465+ const char CEth::eth_ifname[] = " en " ;
452466
453467CEth::CEth (NetworkDriver *driver)
454468: CNetIf(driver) {
@@ -470,19 +484,42 @@ int CEth::begin(const IPAddress &ip, const IPAddress &nm, const IPAddress &gw, c
470484 return res;
471485}
472486
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+
473512err_t CEth::init (struct netif * ni) {
474513 // Setting up netif
475514#if LWIP_NETIF_HOSTNAME
476515 ni->hostname = " C33_eth" ;
477516#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 ] ;
480519 ni->mtu = 1500 ; // TODO get this from the network
481520 ni->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;
482521
483522 memcpy (ni->hwaddr , this ->driver ->getMacAddress (), 6 ); // FIXME handle this using a constant
484- // ni->hwaddr = C33EthernetDriver.getMacAddress();
485- // ni->hwaddr_len = sizeof(macaddress);
486523 ni->hwaddr_len = 6 ;
487524
488525 ni->output = etharp_output;
@@ -549,7 +586,7 @@ void CEth::consume_callback(uint8_t* buffer, uint32_t len) {
549586/* ########################################################################## */
550587/* CWifiStation NETWORK INTERFACE CLASS */
551588/* ########################################################################## */
552- uint8_t CWifiStation::wifistation_id = 0 ;
589+ const char CWifiStation::wifistation_ifname[] = " ws " ;
553590
554591CWifiStation::CWifiStation ()
555592: hw_init(false ) {
@@ -673,8 +710,8 @@ err_t CWifiStation::init(struct netif* ni) {
673710#if LWIP_NETIF_HOSTNAME
674711 ni->hostname = " C33-WifiSta" ;
675712#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 ] ;
678715 ni->mtu = 1500 ; // FIXME get this from the network
679716 ni->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;
680717
@@ -859,7 +896,7 @@ int CWifiStation::resetLowPowerMode() {
859896/* ########################################################################## */
860897/* CWifiSoftAp NETWORK INTERFACE CLASS */
861898/* ########################################################################## */
862- uint8_t CWifiSoftAp::softap_id = 0 ;
899+ const char CWifiSoftAp::softap_ifname[] = " sa " ;
863900
864901// This is required for dhcp server to assign ip addresses to AP clients
865902IPAddress default_nm (" 255.255.255.0" );
@@ -883,7 +920,7 @@ int CWifiSoftAp::begin(const IPAddress &ip, const IPAddress &nm, const IPAddress
883920 return ESP_CONTROL_OK;
884921 });
885922
886- if ((res=CEspControl::getInstance ().initSpiDriver ()) != 0 ) {
923+ if ((res=CEspControl::getInstance ().initSpiDriver ()) != 0 && !hw_init ) {
887924 // res = -1; // FIXME put a proper error code
888925 goto exit;
889926 }
@@ -953,8 +990,8 @@ err_t CWifiSoftAp::init(struct netif* ni) {
953990 // TODO pass the hostname in the constructor os with a setter
954991 ni->hostname = " C33-SoftAP" ;
955992#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 ] ;
958995 ni->mtu = 1500 ; // FIXME get this from the network
959996 ni->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;
960997
0 commit comments