Skip to content

Commit 984cc1a

Browse files
authored
Merge pull request ARMmbed#6032 from jarlamsa/status-callbacks
Status callbacks
2 parents ee52f90 + 8bea5ef commit 984cc1a

File tree

22 files changed

+596
-99
lines changed

22 files changed

+596
-99
lines changed

features/FEATURE_LWIP/lwip-interface/EthernetInterface.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@
1919

2020

2121
/* Interface implementation */
22-
EthernetInterface::EthernetInterface()
23-
: _dhcp(true), _ip_address(), _netmask(), _gateway()
22+
EthernetInterface::EthernetInterface() :
23+
_dhcp(true),
24+
_ip_address(),
25+
_netmask(),
26+
_gateway(),
27+
_connection_status_cb(NULL),
28+
_connect_status(NSAPI_STATUS_DISCONNECTED)
2429
{
2530
}
2631

32+
2733
nsapi_error_t EthernetInterface::set_network(const char *ip_address, const char *netmask, const char *gateway)
2834
{
2935
_dhcp = false;
@@ -94,3 +100,32 @@ NetworkStack *EthernetInterface::get_stack()
94100
{
95101
return nsapi_create_stack(&lwip_stack);
96102
}
103+
104+
void EthernetInterface::attach(
105+
Callback<void(nsapi_event_t, intptr_t)> status_cb)
106+
{
107+
_connection_status_cb = status_cb;
108+
mbed_lwip_attach(netif_status_cb, this);
109+
}
110+
111+
nsapi_connection_status_t EthernetInterface::get_connection_status() const
112+
{
113+
return _connect_status;
114+
}
115+
116+
void EthernetInterface::netif_status_cb(void *ethernet_if_ptr,
117+
nsapi_event_t reason, intptr_t parameter)
118+
{
119+
EthernetInterface *eth_ptr = static_cast<EthernetInterface*>(ethernet_if_ptr);
120+
eth_ptr->_connect_status = (nsapi_connection_status_t)parameter;
121+
if (eth_ptr->_connection_status_cb)
122+
{
123+
eth_ptr->_connection_status_cb(reason, parameter);
124+
}
125+
}
126+
127+
nsapi_error_t EthernetInterface::set_blocking(bool blocking)
128+
{
129+
mbed_lwip_set_blocking(blocking);
130+
return NSAPI_ERROR_OK;
131+
}

features/FEATURE_LWIP/lwip-interface/EthernetInterface.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,26 @@ class EthernetInterface : public EthInterface
100100
*/
101101
virtual const char *get_gateway();
102102

103+
/** Register callback for status reporting
104+
*
105+
* @param status_cb The callback for status changes
106+
*/
107+
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
108+
109+
/** Get the connection status
110+
*
111+
* @return The connection status according to nsapi_connection_status_t
112+
*/
113+
virtual nsapi_connection_status_t get_connection_status() const;
114+
115+
/** Set blocking status of connect() which by default should be blocking
116+
*
117+
* @param blocking true if connect is blocking
118+
* @return 0 on success, negative error code on failure
119+
*/
120+
virtual nsapi_error_t set_blocking(bool blocking);
121+
122+
103123
protected:
104124
/** Provide access to the underlying stack
105125
*
@@ -111,6 +131,11 @@ class EthernetInterface : public EthInterface
111131
char _ip_address[IPADDR_STRLEN_MAX];
112132
char _netmask[NSAPI_IPv4_SIZE];
113133
char _gateway[NSAPI_IPv4_SIZE];
134+
135+
136+
Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
137+
nsapi_connection_status_t _connect_status;
138+
static void netif_status_cb(void *, nsapi_event_t, intptr_t);
114139
};
115140

116141

features/FEATURE_LWIP/lwip-interface/lwip-sys/lwip_tcp_isn.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,11 @@ lwip_hook_tcp_isn(const void *local_ip_ptr, u16_t local_port,
178178
/* The secret and padding are already filled in. */
179179

180180
/* Generate the hash, using MD5. */
181+
lwip_md5_init(&ctx);
181182
lwip_md5_starts(&ctx);
182183
lwip_md5_update(&ctx, input, sizeof(input));
183184
lwip_md5_finish(&ctx, output);
185+
lwip_md5_free(&ctx);
184186

185187
/* Arbitrarily take the first 32 bits from the generated hash. */
186188
MEMCPY(&isn, output, sizeof(isn));

0 commit comments

Comments
 (0)