Skip to content

Commit 694d935

Browse files
committed
updates: ternary formats, line length limited to 100
1 parent 69a23d8 commit 694d935

File tree

196 files changed

+6460
-6319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

196 files changed

+6460
-6319
lines changed

cores/esp8266/LwipDhcpServer-NonOS.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ extern "C"
5555
#endif
5656
}
5757

58-
void dhcps_stop()
59-
{
60-
dhcpSoftAP.end();
61-
}
58+
void dhcps_stop() { dhcpSoftAP.end(); }
6259

6360
} // extern "C"

cores/esp8266/LwipDhcpServer.cpp

+47-61
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ struct dhcps_pool
109109
dhcps_state_t state;
110110
};
111111

112-
#define DHCPS_LEASE_TIMER dhcps_lease_time //0x05A0
112+
#define DHCPS_LEASE_TIMER dhcps_lease_time // 0x05A0
113113
#define DHCPS_MAX_LEASE 0x64
114114
#define BOOTP_BROADCAST 0x8000
115115

@@ -161,16 +161,17 @@ const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__;
161161
#endif
162162

163163
#if DHCPS_DEBUG
164-
#define LWIP_IS_OK(what, err) ( \
165-
{ \
166-
int ret = 1, errval = (err); \
167-
if (errval != ERR_OK) \
168-
{ \
169-
os_printf("DHCPS ERROR: %s (lwip:%d)\n", what, errval); \
170-
ret = 0; \
171-
} \
172-
ret; \
173-
})
164+
#define LWIP_IS_OK(what, err) \
165+
( \
166+
{ \
167+
int ret = 1, errval = (err); \
168+
if (errval != ERR_OK) \
169+
{ \
170+
os_printf("DHCPS ERROR: %s (lwip:%d)\n", what, errval); \
171+
ret = 0; \
172+
} \
173+
ret; \
174+
})
174175
#else
175176
#define LWIP_IS_OK(what, err) ((err) == ERR_OK)
176177
#endif
@@ -181,15 +182,14 @@ int fw_has_started_softap_dhcps = 0;
181182

182183
////////////////////////////////////////////////////////////////////////////////////
183184

184-
DhcpServer::DhcpServer(netif* netif) :
185-
_netif(netif)
185+
DhcpServer::DhcpServer(netif* netif) : _netif(netif)
186186
{
187187
pcb_dhcps = nullptr;
188188
dns_address.addr = 0;
189189
plist = nullptr;
190190
offer = 0xFF;
191191
renew = false;
192-
dhcps_lease_time = DHCPS_LEASE_TIME_DEF; //minute
192+
dhcps_lease_time = DHCPS_LEASE_TIME_DEF; // minute
193193

194194
if (netif->num == SOFTAP_IF && fw_has_started_softap_dhcps == 1)
195195
{
@@ -385,13 +385,13 @@ uint8_t* DhcpServer::add_msg_type(uint8_t* optptr, uint8_t type)
385385
///////////////////////////////////////////////////////////////////////////////////
386386
uint8_t* DhcpServer::add_offer_options(uint8_t* optptr)
387387
{
388-
//struct ipv4_addr ipadd;
389-
//ipadd.addr = server_address.addr;
388+
// struct ipv4_addr ipadd;
389+
// ipadd.addr = server_address.addr;
390390
#define ipadd (_netif->ip_addr)
391391

392-
//struct ip_info if_ip;
393-
//bzero(&if_ip, sizeof(struct ip_info));
394-
//wifi_get_ip_info(SOFTAP_IF, &if_ip);
392+
// struct ip_info if_ip;
393+
// bzero(&if_ip, sizeof(struct ip_info));
394+
// wifi_get_ip_info(SOFTAP_IF, &if_ip);
395395
#define if_ip (*_netif)
396396

397397
*optptr++ = DHCP_OPTION_SUBNET_MASK;
@@ -691,7 +691,8 @@ void DhcpServer::send_ack(struct dhcps_msg* m)
691691
#endif
692692
return;
693693
}
694-
if (!LWIP_IS_OK("dhcps send ack", udp_sendto(pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT)))
694+
if (!LWIP_IS_OK("dhcps send ack",
695+
udp_sendto(pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT)))
695696
{
696697
#if DHCPS_DEBUG
697698
os_printf("dhcps: send_ack>>udp_sendto\n");
@@ -736,12 +737,12 @@ uint8_t DhcpServer::parse_options(uint8_t* optptr, sint16_t len)
736737
#endif
737738
switch ((sint16_t)*optptr)
738739
{
739-
case DHCP_OPTION_MSG_TYPE: //53
740+
case DHCP_OPTION_MSG_TYPE: // 53
740741
type = *(optptr + 2);
741742
break;
742743

743-
case DHCP_OPTION_REQ_IPADDR: //50
744-
//os_printf("dhcps:0x%08x,0x%08x\n",client.addr,*(uint32*)(optptr+2));
744+
case DHCP_OPTION_REQ_IPADDR: // 50
745+
// os_printf("dhcps:0x%08x,0x%08x\n",client.addr,*(uint32*)(optptr+2));
745746
if (memcmp((char*)&client.addr, (char*)optptr + 2, 4) == 0)
746747
{
747748
#if DHCPS_DEBUG
@@ -774,14 +775,14 @@ uint8_t DhcpServer::parse_options(uint8_t* optptr, sint16_t len)
774775

775776
switch (type)
776777
{
777-
case DHCPDISCOVER: //1
778+
case DHCPDISCOVER: // 1
778779
s.state = DHCPS_STATE_OFFER;
779780
#if DHCPS_DEBUG
780781
os_printf("dhcps: DHCPD_STATE_OFFER\n");
781782
#endif
782783
break;
783784

784-
case DHCPREQUEST: //3
785+
case DHCPREQUEST: // 3
785786
if (!(s.state == DHCPS_STATE_ACK || s.state == DHCPS_STATE_NAK))
786787
{
787788
if (renew == true)
@@ -798,14 +799,14 @@ uint8_t DhcpServer::parse_options(uint8_t* optptr, sint16_t len)
798799
}
799800
break;
800801

801-
case DHCPDECLINE: //4
802+
case DHCPDECLINE: // 4
802803
s.state = DHCPS_STATE_IDLE;
803804
#if DHCPS_DEBUG
804805
os_printf("dhcps: DHCPD_STATE_IDLE\n");
805806
#endif
806807
break;
807808

808-
case DHCPRELEASE: //7
809+
case DHCPRELEASE: // 7
809810
s.state = DHCPS_STATE_RELEASE;
810811
#if DHCPS_DEBUG
811812
os_printf("dhcps: DHCPD_STATE_IDLE\n");
@@ -821,10 +822,7 @@ uint8_t DhcpServer::parse_options(uint8_t* optptr, sint16_t len)
821822
///////////////////////////////////////////////////////////////////////////////////
822823
sint16_t DhcpServer::parse_msg(struct dhcps_msg* m, u16_t len)
823824
{
824-
if (memcmp((char*)m->options,
825-
&magic_cookie,
826-
sizeof(magic_cookie))
827-
== 0)
825+
if (memcmp((char*)m->options, &magic_cookie, sizeof(magic_cookie)) == 0)
828826
{
829827
struct ipv4_addr ip;
830828
memcpy(&ip.addr, m->ciaddr, sizeof(ip.addr));
@@ -855,21 +853,15 @@ sint16_t DhcpServer::parse_msg(struct dhcps_msg* m, u16_t len)
855853
*/
856854
///////////////////////////////////////////////////////////////////////////////////
857855

858-
void DhcpServer::S_handle_dhcp(void* arg,
859-
struct udp_pcb* pcb,
860-
struct pbuf* p,
861-
const ip_addr_t* addr,
862-
uint16_t port)
856+
void DhcpServer::S_handle_dhcp(void* arg, struct udp_pcb* pcb, struct pbuf* p,
857+
const ip_addr_t* addr, uint16_t port)
863858
{
864859
DhcpServer* instance = reinterpret_cast<DhcpServer*>(arg);
865860
instance->handle_dhcp(pcb, p, addr, port);
866861
}
867862

868-
void DhcpServer::handle_dhcp(
869-
struct udp_pcb* pcb,
870-
struct pbuf* p,
871-
const ip_addr_t* addr,
872-
uint16_t port)
863+
void DhcpServer::handle_dhcp(struct udp_pcb* pcb, struct pbuf* p, const ip_addr_t* addr,
864+
uint16_t port)
873865
{
874866
(void)pcb;
875867
(void)addr;
@@ -931,13 +923,13 @@ void DhcpServer::handle_dhcp(
931923

932924
switch (parse_msg(pmsg_dhcps, tlen - 240))
933925
{
934-
case DHCPS_STATE_OFFER: //1
926+
case DHCPS_STATE_OFFER: // 1
935927
#if DHCPS_DEBUG
936928
os_printf("dhcps: handle_dhcp-> DHCPD_STATE_OFFER\n");
937929
#endif
938930
send_offer(pmsg_dhcps);
939931
break;
940-
case DHCPS_STATE_ACK: //3
932+
case DHCPS_STATE_ACK: // 3
941933
#if DHCPS_DEBUG
942934
os_printf("dhcps: handle_dhcp-> DHCPD_STATE_ACK\n");
943935
#endif
@@ -947,7 +939,7 @@ void DhcpServer::handle_dhcp(
947939
wifi_softap_set_station_info(pmsg_dhcps->chaddr, &client_address);
948940
}
949941
break;
950-
case DHCPS_STATE_NAK: //4
942+
case DHCPS_STATE_NAK: // 4
951943
#if DHCPS_DEBUG
952944
os_printf("dhcps: handle_dhcp-> DHCPD_STATE_NAK\n");
953945
#endif
@@ -1037,15 +1029,16 @@ bool DhcpServer::begin(struct ip_info* info)
10371029
broadcast_dhcps = _netif->ip_addr;
10381030
ip_2_ip4(&broadcast_dhcps)->addr &= ip_2_ip4(&_netif->netmask)->addr;
10391031
ip_2_ip4(&broadcast_dhcps)->addr |= ~ip_2_ip4(&_netif->netmask)->addr;
1040-
//XXXFIXMEIPV6 broadcast address?
1032+
// XXXFIXMEIPV6 broadcast address?
10411033

10421034
server_address = info->ip;
10431035
init_dhcps_lease(server_address.addr);
10441036

10451037
udp_bind(pcb_dhcps, IP_ADDR_ANY, DHCPS_SERVER_PORT);
10461038
udp_recv(pcb_dhcps, S_handle_dhcp, this);
10471039
#if DHCPS_DEBUG
1048-
os_printf("dhcps:dhcps_start->udp_recv function Set a receive callback handle_dhcp for UDP_PCB pcb_dhcps\n");
1040+
os_printf("dhcps:dhcps_start->udp_recv function Set a receive callback handle_dhcp for UDP_PCB "
1041+
"pcb_dhcps\n");
10491042
#endif
10501043

10511044
if (_netif->num == SOFTAP_IF)
@@ -1057,10 +1050,7 @@ bool DhcpServer::begin(struct ip_info* info)
10571050
return true;
10581051
}
10591052

1060-
DhcpServer::~DhcpServer()
1061-
{
1062-
end();
1063-
}
1053+
DhcpServer::~DhcpServer() { end(); }
10641054

10651055
void DhcpServer::end()
10661056
{
@@ -1073,7 +1063,7 @@ void DhcpServer::end()
10731063
udp_remove(pcb_dhcps);
10741064
pcb_dhcps = nullptr;
10751065

1076-
//udp_remove(pcb_dhcps);
1066+
// udp_remove(pcb_dhcps);
10771067
list_node* pnode = nullptr;
10781068
list_node* pback_node = nullptr;
10791069
struct dhcps_pool* dhcp_node = nullptr;
@@ -1087,7 +1077,7 @@ void DhcpServer::end()
10871077
pnode = pback_node->pnext;
10881078
node_remove_from_list(&plist, pback_node);
10891079
dhcp_node = (struct dhcps_pool*)pback_node->pnode;
1090-
//dhcps_client_leave(dhcp_node->mac,&dhcp_node->ip,true); // force to delete
1080+
// dhcps_client_leave(dhcp_node->mac,&dhcp_node->ip,true); // force to delete
10911081
if (_netif->num == SOFTAP_IF)
10921082
{
10931083
wifi_softap_set_station_info(dhcp_node->mac, &ip_zero);
@@ -1099,10 +1089,7 @@ void DhcpServer::end()
10991089
}
11001090
}
11011091

1102-
bool DhcpServer::isRunning()
1103-
{
1104-
return !!_netif->state;
1105-
}
1092+
bool DhcpServer::isRunning() { return !!_netif->state; }
11061093

11071094
/******************************************************************************
11081095
FunctionName : set_dhcps_lease
@@ -1147,8 +1134,7 @@ bool DhcpServer::set_dhcps_lease(struct dhcps_lease* please)
11471134

11481135
/*config ip information must be in the same segment as the local ip*/
11491136
softap_ip >>= 8;
1150-
if ((start_ip >> 8 != softap_ip)
1151-
|| (end_ip >> 8 != softap_ip))
1137+
if ((start_ip >> 8 != softap_ip) || (end_ip >> 8 != softap_ip))
11521138
{
11531139
return false;
11541140
}
@@ -1288,7 +1274,7 @@ void DhcpServer::dhcps_coarse_tmr(void)
12881274
bool DhcpServer::set_dhcps_offer_option(uint8 level, void* optarg)
12891275
{
12901276
bool offer_flag = true;
1291-
//uint8 option = 0;
1277+
// uint8 option = 0;
12921278
if (optarg == nullptr && !isRunning())
12931279
{
12941280
return false;
@@ -1444,7 +1430,7 @@ uint32 DhcpServer::dhcps_client_update(u8* bssid, struct ipv4_addr* ip)
14441430
for (pback_node = plist; pback_node != nullptr; pback_node = pback_node->pnext)
14451431
{
14461432
pdhcps_pool = (struct dhcps_pool*)pback_node->pnode;
1447-
//os_printf("mac:"MACSTR"bssid:"MACSTR"\r\n",MAC2STR(pdhcps_pool->mac),MAC2STR(bssid));
1433+
// os_printf("mac:"MACSTR"bssid:"MACSTR"\r\n",MAC2STR(pdhcps_pool->mac),MAC2STR(bssid));
14481434
if (memcmp(pdhcps_pool->mac, bssid, sizeof(pdhcps_pool->mac)) == 0)
14491435
{
14501436
pmac_node = pback_node;
@@ -1493,7 +1479,7 @@ uint32 DhcpServer::dhcps_client_update(u8* bssid, struct ipv4_addr* ip)
14931479
{
14941480
return IPADDR_ANY;
14951481
}
1496-
//start_ip = htonl((ntohl(start_ip) + 1));
1482+
// start_ip = htonl((ntohl(start_ip) + 1));
14971483
flag = true;
14981484
}
14991485
}

cores/esp8266/LwipDhcpServer.h

+3-10
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,9 @@ class DhcpServer
8383
void send_ack(struct dhcps_msg* m);
8484
uint8_t parse_options(uint8_t* optptr, sint16_t len);
8585
sint16_t parse_msg(struct dhcps_msg* m, u16_t len);
86-
static void S_handle_dhcp(void* arg,
87-
struct udp_pcb* pcb,
88-
struct pbuf* p,
89-
const ip_addr_t* addr,
90-
uint16_t port);
91-
void handle_dhcp(
92-
struct udp_pcb* pcb,
93-
struct pbuf* p,
94-
const ip_addr_t* addr,
95-
uint16_t port);
86+
static void S_handle_dhcp(void* arg, struct udp_pcb* pcb, struct pbuf* p, const ip_addr_t* addr,
87+
uint16_t port);
88+
void handle_dhcp(struct udp_pcb* pcb, struct pbuf* p, const ip_addr_t* addr, uint16_t port);
9689
void kill_oldest_dhcps_pool(void);
9790
void dhcps_coarse_tmr(void); // CURRENTLY NOT CALLED
9891
void dhcps_client_leave(u8* bssid, struct ipv4_addr* ip, bool force);

cores/esp8266/LwipIntf.cpp

+14-15
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,25 @@ extern "C"
2525
//
2626
// result stored into gateway/netmask/dns1
2727

28-
bool LwipIntf::ipAddressReorder(const IPAddress& local_ip, const IPAddress& arg1, const IPAddress& arg2, const IPAddress& arg3,
29-
IPAddress& gateway, IPAddress& netmask, IPAddress& dns1)
28+
bool LwipIntf::ipAddressReorder(const IPAddress& local_ip, const IPAddress& arg1,
29+
const IPAddress& arg2, const IPAddress& arg3, IPAddress& gateway,
30+
IPAddress& netmask, IPAddress& dns1)
3031
{
31-
//To allow compatibility, check first octet of 3rd arg. If 255, interpret as ESP order, otherwise Arduino order.
32+
// To allow compatibility, check first octet of 3rd arg. If 255, interpret as ESP order,
33+
// otherwise Arduino order.
3234
gateway = arg1;
3335
netmask = arg2;
3436
dns1 = arg3;
3537

3638
if (netmask[0] != 255)
3739
{
38-
//octet is not 255 => interpret as Arduino order
40+
// octet is not 255 => interpret as Arduino order
3941
gateway = arg2;
40-
netmask = arg3[0] == 0 ? IPAddress(255, 255, 255, 0) : arg3; //arg order is arduino and 4th arg not given => assign it arduino default
41-
dns1 = arg1;
42+
netmask
43+
= arg3[0] == 0 ?
44+
IPAddress(255, 255, 255, 0) :
45+
arg3; // arg order is arduino and 4th arg not given => assign it arduino default
46+
dns1 = arg1;
4247
}
4348

4449
// check whether all is IPv4 (or gateway not set)
@@ -47,7 +52,7 @@ bool LwipIntf::ipAddressReorder(const IPAddress& local_ip, const IPAddress& arg1
4752
return false;
4853
}
4954

50-
//ip and gateway must be in the same netmask
55+
// ip and gateway must be in the same netmask
5156
if (gateway.isSet() && (local_ip.v4() & netmask.v4()) != (gateway.v4() & netmask.v4()))
5257
{
5358
return false;
@@ -60,19 +65,13 @@ bool LwipIntf::ipAddressReorder(const IPAddress& local_ip, const IPAddress& arg1
6065
Get ESP8266 station DHCP hostname
6166
@return hostname
6267
*/
63-
String LwipIntf::hostname(void)
64-
{
65-
return wifi_station_get_hostname();
66-
}
68+
String LwipIntf::hostname(void) { return wifi_station_get_hostname(); }
6769

6870
/**
6971
Get ESP8266 station DHCP hostname
7072
@return hostname
7173
*/
72-
const char* LwipIntf::getHostname(void)
73-
{
74-
return wifi_station_get_hostname();
75-
}
74+
const char* LwipIntf::getHostname(void) { return wifi_station_get_hostname(); }
7675

7776
/**
7877
Set ESP8266 station DHCP hostname

0 commit comments

Comments
 (0)