Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status callbacks #6032

Merged
merged 6 commits into from
Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions features/FEATURE_LWIP/lwip-interface/EthernetInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@


/* Interface implementation */
EthernetInterface::EthernetInterface()
: _dhcp(true), _ip_address(), _netmask(), _gateway()
EthernetInterface::EthernetInterface() :
_dhcp(true),
_ip_address(),
_netmask(),
_gateway(),
_connection_status_cb(NULL),
_connect_status(NSAPI_STATUS_DISCONNECTED)
{
}


nsapi_error_t EthernetInterface::set_network(const char *ip_address, const char *netmask, const char *gateway)
{
_dhcp = false;
Expand Down Expand Up @@ -94,3 +100,32 @@ NetworkStack *EthernetInterface::get_stack()
{
return nsapi_create_stack(&lwip_stack);
}

void EthernetInterface::attach(
Callback<void(nsapi_event_t, intptr_t)> status_cb)
{
_connection_status_cb = status_cb;
mbed_lwip_attach(netif_status_cb, this);
}

nsapi_connection_status_t EthernetInterface::get_connection_status() const
{
return _connect_status;
}

void EthernetInterface::netif_status_cb(void *ethernet_if_ptr,
nsapi_event_t reason, intptr_t parameter)
{
EthernetInterface *eth_ptr = static_cast<EthernetInterface*>(ethernet_if_ptr);
eth_ptr->_connect_status = (nsapi_connection_status_t)parameter;
if (eth_ptr->_connection_status_cb)
{
eth_ptr->_connection_status_cb(reason, parameter);
}
}

nsapi_error_t EthernetInterface::set_blocking(bool blocking)
{
mbed_lwip_set_blocking(blocking);
return NSAPI_ERROR_OK;
}
25 changes: 25 additions & 0 deletions features/FEATURE_LWIP/lwip-interface/EthernetInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,26 @@ class EthernetInterface : public EthInterface
*/
virtual const char *get_gateway();

/** Register callback for status reporting
*
* @param status_cb The callback for status changes
*/
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);

/** Get the connection status
*
* @return The connection status according to nsapi_connection_status_t
*/
virtual nsapi_connection_status_t get_connection_status() const;

/** Set blocking status of connect() which by default should be blocking
*
* @param blocking true if connect is blocking
* @return 0 on success, negative error code on failure
*/
virtual nsapi_error_t set_blocking(bool blocking);


protected:
/** Provide access to the underlying stack
*
Expand All @@ -111,6 +131,11 @@ class EthernetInterface : public EthInterface
char _ip_address[IPADDR_STRLEN_MAX];
char _netmask[NSAPI_IPv4_SIZE];
char _gateway[NSAPI_IPv4_SIZE];


Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
nsapi_connection_status_t _connect_status;
static void netif_status_cb(void *, nsapi_event_t, intptr_t);
};


Expand Down
2 changes: 2 additions & 0 deletions features/FEATURE_LWIP/lwip-interface/lwip-sys/lwip_tcp_isn.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@ lwip_hook_tcp_isn(const void *local_ip_ptr, u16_t local_port,
/* The secret and padding are already filled in. */

/* Generate the hash, using MD5. */
lwip_md5_init(&ctx);
lwip_md5_starts(&ctx);
lwip_md5_update(&ctx, input, sizeof(input));
lwip_md5_finish(&ctx, output);
lwip_md5_free(&ctx);

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