Skip to content

Commit 58f9561

Browse files
JAndrassyandreagilardoni
authored andcommitted
CNetIf - added config method to apply new static IP settings
in CWifi::_config netif_set_address call was missing. in Ethernet::begin static IP was not applied if invoked second time now the new CNetIf.config does the static IP change for both.
1 parent 719e63f commit 58f9561

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

libraries/WiFi/src/WiFi.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,18 @@ void CWifi::config(IPAddress local_ip) { // FIXME
7979
extern uint8_t *IpAddress2uint8(IPAddress a);
8080

8181
/* -------------------------------------------------------------------------- */
82-
void CWifi::_config(IPAddress local_ip, IPAddress gateway, IPAddress subnet) { // FIXME
83-
/* -------------------------------------------------------------------------- */
84-
// _useStaticIp = local_ip != INADDR_NONE;
85-
// if(ni != nullptr) {
86-
// ni->DhcpStop();
87-
// ni->DhcpNotUsed();
88-
// IP_ADDR4(&ni->ip, local_ip[0], local_ip[1], local_ip[2], local_ip[3]);
89-
// IP_ADDR4(&ni->gw, gateway[0], gateway[1], gateway[2], gateway[3]);
90-
// IP_ADDR4(&ni->nm, subnet[0], subnet[1], subnet[2], subnet[3]);
91-
// }
92-
// else {
93-
// CNetIf::default_ip = local_ip;
94-
// CNetIf::default_nm = subnet;
95-
// CNetIf::default_gw = gateway;
96-
// CNetIf::default_dhcp_server_ip = local_ip;
97-
// }
82+
void CWifi::_config(IPAddress local_ip, IPAddress gateway, IPAddress subnet) {
83+
/* -------------------------------------------------------------------------- */
84+
_useStaticIp = local_ip != INADDR_NONE;
85+
if(ni != nullptr) {
86+
ni->config(local_ip, gateway, subnet);
87+
}
88+
else {
89+
CNetIf::default_ip = local_ip;
90+
CNetIf::default_nm = subnet;
91+
CNetIf::default_gw = gateway;
92+
CNetIf::default_dhcp_server_ip = local_ip;
93+
}
9894
}
9995

10096
/* -------------------------------------------------------------------------- */

libraries/lwIpWrapper/src/CNetIf.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ err_t CWifiSoftAp::output(struct netif* _ni, struct pbuf* p) {
948948
errval = ERR_OK;
949949
// NETIF_STATS_INCREMENT_TX_BYTES(this->stats, size);
950950
// NETIF_STATS_TX_TIME_AVERAGE(this->stats);
951-
} else {
951+
} else {
952952
// NETIF_STATS_INCREMENT_ERROR(this->stats, err);
953953
// NETIF_STATS_INCREMENT_TX_TRANSMIT_FAILED_CALLS(this->stats);
954954
}
@@ -961,6 +961,25 @@ err_t CWifiSoftAp::output(struct netif* _ni, struct pbuf* p) {
961961
return errval;
962962
}
963963

964+
/* -------------------------------------------------------------------------- */
965+
void CNetIf::config(IPAddress _ip, IPAddress _gw, IPAddress _nm)
966+
{
967+
DhcpStop();
968+
DhcpNotUsed();
969+
970+
IP_ADDR4(&ip, _ip[0], _ip[1], _ip[2], _ip[3]);
971+
IP_ADDR4(&nm, _nm[0], _nm[1], _nm[2], _nm[3]);
972+
IP_ADDR4(&gw, _gw[0], _gw[1], _gw[2], _gw[3]);
973+
974+
netif_set_addr(&ni, &ip, &nm, &gw);
975+
976+
if (netif_is_link_up(&ni)) {
977+
netif_set_down(&ni);
978+
netif_set_up(&ni);
979+
}
980+
}
981+
982+
964983
void CWifiSoftAp::task() {
965984
// calling the base class task, in order to make thigs work
966985
CNetIf::task();

libraries/lwIpWrapper/src/CNetIf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class CNetIf: public NetworkInterface {
160160
// memset(hostname, 0x00, MAX_HOSTNAME_DIM);
161161
// memcpy(hostname, name, strlen(name) < MAX_HOSTNAME_DIM ? strlen(name) : MAX_HOSTNAME_DIM);
162162
// }
163+
void config(IPAddress _ip, IPAddress _gw, IPAddress _nm);
163164

164165

165166
virtual int getMacAddress(uint8_t* mac) = 0;

0 commit comments

Comments
 (0)