mirror of https://github.com/ARMmbed/mbed-os.git
nsapi - Adopted standardized return types in lwip
parent
ba748ac1f8
commit
78b9357c80
|
@ -24,22 +24,22 @@ EthernetInterface::EthernetInterface()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int EthernetInterface::set_network(const char *ip_address, const char *netmask, const char *gateway)
|
nsapi_error_t EthernetInterface::set_network(const char *ip_address, const char *netmask, const char *gateway)
|
||||||
{
|
{
|
||||||
_dhcp = false;
|
_dhcp = false;
|
||||||
strncpy(_ip_address, ip_address ? ip_address : "", sizeof(_ip_address));
|
strncpy(_ip_address, ip_address ? ip_address : "", sizeof(_ip_address));
|
||||||
strncpy(_netmask, netmask ? netmask : "", sizeof(_netmask));
|
strncpy(_netmask, netmask ? netmask : "", sizeof(_netmask));
|
||||||
strncpy(_gateway, gateway ? gateway : "", sizeof(_gateway));
|
strncpy(_gateway, gateway ? gateway : "", sizeof(_gateway));
|
||||||
return 0;
|
return NSAPI_ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EthernetInterface::set_dhcp(bool dhcp)
|
nsapi_error_t EthernetInterface::set_dhcp(bool dhcp)
|
||||||
{
|
{
|
||||||
_dhcp = dhcp;
|
_dhcp = dhcp;
|
||||||
return 0;
|
return NSAPI_ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EthernetInterface::connect()
|
nsapi_error_t EthernetInterface::connect()
|
||||||
{
|
{
|
||||||
return mbed_lwip_bringup(_dhcp,
|
return mbed_lwip_bringup(_dhcp,
|
||||||
_ip_address[0] ? _ip_address : 0,
|
_ip_address[0] ? _ip_address : 0,
|
||||||
|
@ -47,7 +47,7 @@ int EthernetInterface::connect()
|
||||||
_gateway[0] ? _gateway : 0);
|
_gateway[0] ? _gateway : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int EthernetInterface::disconnect()
|
nsapi_error_t EthernetInterface::disconnect()
|
||||||
{
|
{
|
||||||
return mbed_lwip_bringdown();
|
return mbed_lwip_bringdown();
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ const char *EthernetInterface::get_ip_address()
|
||||||
return _ip_address;
|
return _ip_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *EthernetInterface::get_netmask()
|
const char *EthernetInterface::get_netmask()
|
||||||
|
|
|
@ -46,7 +46,8 @@ public:
|
||||||
* @param gateway Null-terminated representation of the local gateway
|
* @param gateway Null-terminated representation of the local gateway
|
||||||
* @return 0 on success, negative error code on failure
|
* @return 0 on success, negative error code on failure
|
||||||
*/
|
*/
|
||||||
virtual int set_network(const char *ip_address, const char *netmask, const char *gateway);
|
virtual nsapi_error_t set_network(
|
||||||
|
const char *ip_address, const char *netmask, const char *gateway);
|
||||||
|
|
||||||
/** Enable or disable DHCP on the network
|
/** Enable or disable DHCP on the network
|
||||||
*
|
*
|
||||||
|
@ -55,17 +56,17 @@ public:
|
||||||
* @param dhcp False to disable dhcp (defaults to enabled)
|
* @param dhcp False to disable dhcp (defaults to enabled)
|
||||||
* @return 0 on success, negative error code on failure
|
* @return 0 on success, negative error code on failure
|
||||||
*/
|
*/
|
||||||
virtual int set_dhcp(bool dhcp);
|
virtual nsapi_error_t set_dhcp(bool dhcp);
|
||||||
|
|
||||||
/** Start the interface
|
/** Start the interface
|
||||||
* @return 0 on success, negative on failure
|
* @return 0 on success, negative on failure
|
||||||
*/
|
*/
|
||||||
virtual int connect();
|
virtual nsapi_error_t connect();
|
||||||
|
|
||||||
/** Stop the interface
|
/** Stop the interface
|
||||||
* @return 0 on success, negative on failure
|
* @return 0 on success, negative on failure
|
||||||
*/
|
*/
|
||||||
virtual int disconnect();
|
virtual nsapi_error_t disconnect();
|
||||||
|
|
||||||
/** Get the local MAC address
|
/** Get the local MAC address
|
||||||
*
|
*
|
||||||
|
|
|
@ -326,7 +326,7 @@ const char *mbed_lwip_get_mac_address(void)
|
||||||
return lwip_mac_address[0] ? lwip_mac_address : 0;
|
return lwip_mac_address[0] ? lwip_mac_address : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *mbed_lwip_get_ip_address(char *buf, int buflen)
|
char *mbed_lwip_get_ip_address(char *buf, nsapi_size_t buflen)
|
||||||
{
|
{
|
||||||
const ip_addr_t *addr = mbed_lwip_get_ip_addr(true, &lwip_netif);
|
const ip_addr_t *addr = mbed_lwip_get_ip_addr(true, &lwip_netif);
|
||||||
if (!addr) {
|
if (!addr) {
|
||||||
|
@ -345,7 +345,7 @@ char *mbed_lwip_get_ip_address(char *buf, int buflen)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *mbed_lwip_get_netmask(char *buf, int buflen)
|
const char *mbed_lwip_get_netmask(char *buf, nsapi_size_t buflen)
|
||||||
{
|
{
|
||||||
#if LWIP_IPV4
|
#if LWIP_IPV4
|
||||||
const ip4_addr_t *addr = netif_ip4_netmask(&lwip_netif);
|
const ip4_addr_t *addr = netif_ip4_netmask(&lwip_netif);
|
||||||
|
@ -359,7 +359,7 @@ const char *mbed_lwip_get_netmask(char *buf, int buflen)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
char *mbed_lwip_get_gateway(char *buf, int buflen)
|
char *mbed_lwip_get_gateway(char *buf, nsapi_size_t buflen)
|
||||||
{
|
{
|
||||||
#if LWIP_IPV4
|
#if LWIP_IPV4
|
||||||
const ip4_addr_t *addr = netif_ip4_gw(&lwip_netif);
|
const ip4_addr_t *addr = netif_ip4_gw(&lwip_netif);
|
||||||
|
@ -373,7 +373,7 @@ char *mbed_lwip_get_gateway(char *buf, int buflen)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int mbed_lwip_init(emac_interface_t *emac)
|
nsapi_error_t mbed_lwip_init(emac_interface_t *emac)
|
||||||
{
|
{
|
||||||
// Check if we've already brought up lwip
|
// Check if we've already brought up lwip
|
||||||
if (!mbed_lwip_get_mac_address()) {
|
if (!mbed_lwip_get_mac_address()) {
|
||||||
|
@ -409,7 +409,7 @@ int mbed_lwip_init(emac_interface_t *emac)
|
||||||
return NSAPI_ERROR_OK;
|
return NSAPI_ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mbed_lwip_bringup(bool dhcp, const char *ip, const char *netmask, const char *gw)
|
nsapi_error_t mbed_lwip_bringup(bool dhcp, const char *ip, const char *netmask, const char *gw)
|
||||||
{
|
{
|
||||||
// Check if we've already connected
|
// Check if we've already connected
|
||||||
if (lwip_connected) {
|
if (lwip_connected) {
|
||||||
|
@ -509,7 +509,7 @@ int mbed_lwip_bringup(bool dhcp, const char *ip, const char *netmask, const char
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mbed_lwip_bringdown(void)
|
nsapi_error_t mbed_lwip_bringdown(void)
|
||||||
{
|
{
|
||||||
// Check if we've connected
|
// Check if we've connected
|
||||||
if (!lwip_connected) {
|
if (!lwip_connected) {
|
||||||
|
@ -533,7 +533,7 @@ int mbed_lwip_bringdown(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* LWIP error remapping */
|
/* LWIP error remapping */
|
||||||
static int mbed_lwip_err_remap(err_t err) {
|
static nsapi_error_t mbed_lwip_err_remap(err_t err) {
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case ERR_OK:
|
case ERR_OK:
|
||||||
case ERR_CLSD:
|
case ERR_CLSD:
|
||||||
|
@ -559,7 +559,7 @@ static int mbed_lwip_err_remap(err_t err) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* LWIP network stack implementation */
|
/* LWIP network stack implementation */
|
||||||
static int mbed_lwip_gethostbyname(nsapi_stack_t *stack, const char *host, nsapi_addr_t *addr, nsapi_version_t version)
|
static nsapi_error_t mbed_lwip_gethostbyname(nsapi_stack_t *stack, const char *host, nsapi_addr_t *addr, nsapi_version_t version)
|
||||||
{
|
{
|
||||||
ip_addr_t lwip_addr;
|
ip_addr_t lwip_addr;
|
||||||
|
|
||||||
|
@ -600,7 +600,7 @@ static int mbed_lwip_gethostbyname(nsapi_stack_t *stack, const char *host, nsapi
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mbed_lwip_socket_open(nsapi_stack_t *stack, nsapi_socket_t *handle, nsapi_protocol_t proto)
|
static nsapi_error_t mbed_lwip_socket_open(nsapi_stack_t *stack, nsapi_socket_t *handle, nsapi_protocol_t proto)
|
||||||
{
|
{
|
||||||
// check if network is connected
|
// check if network is connected
|
||||||
if (!lwip_connected) {
|
if (!lwip_connected) {
|
||||||
|
@ -643,7 +643,7 @@ static int mbed_lwip_socket_open(nsapi_stack_t *stack, nsapi_socket_t *handle, n
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mbed_lwip_socket_close(nsapi_stack_t *stack, nsapi_socket_t handle)
|
static nsapi_error_t mbed_lwip_socket_close(nsapi_stack_t *stack, nsapi_socket_t handle)
|
||||||
{
|
{
|
||||||
struct lwip_socket *s = (struct lwip_socket *)handle;
|
struct lwip_socket *s = (struct lwip_socket *)handle;
|
||||||
|
|
||||||
|
@ -652,7 +652,7 @@ static int mbed_lwip_socket_close(nsapi_stack_t *stack, nsapi_socket_t handle)
|
||||||
return mbed_lwip_err_remap(err);
|
return mbed_lwip_err_remap(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mbed_lwip_socket_bind(nsapi_stack_t *stack, nsapi_socket_t handle, nsapi_addr_t addr, uint16_t port)
|
static nsapi_error_t mbed_lwip_socket_bind(nsapi_stack_t *stack, nsapi_socket_t handle, nsapi_addr_t addr, uint16_t port)
|
||||||
{
|
{
|
||||||
struct lwip_socket *s = (struct lwip_socket *)handle;
|
struct lwip_socket *s = (struct lwip_socket *)handle;
|
||||||
ip_addr_t ip_addr;
|
ip_addr_t ip_addr;
|
||||||
|
@ -670,7 +670,7 @@ static int mbed_lwip_socket_bind(nsapi_stack_t *stack, nsapi_socket_t handle, ns
|
||||||
return mbed_lwip_err_remap(err);
|
return mbed_lwip_err_remap(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mbed_lwip_socket_listen(nsapi_stack_t *stack, nsapi_socket_t handle, int backlog)
|
static nsapi_error_t mbed_lwip_socket_listen(nsapi_stack_t *stack, nsapi_socket_t handle, int backlog)
|
||||||
{
|
{
|
||||||
struct lwip_socket *s = (struct lwip_socket *)handle;
|
struct lwip_socket *s = (struct lwip_socket *)handle;
|
||||||
|
|
||||||
|
@ -678,7 +678,7 @@ static int mbed_lwip_socket_listen(nsapi_stack_t *stack, nsapi_socket_t handle,
|
||||||
return mbed_lwip_err_remap(err);
|
return mbed_lwip_err_remap(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mbed_lwip_socket_connect(nsapi_stack_t *stack, nsapi_socket_t handle, nsapi_addr_t addr, uint16_t port)
|
static nsapi_error_t mbed_lwip_socket_connect(nsapi_stack_t *stack, nsapi_socket_t handle, nsapi_addr_t addr, uint16_t port)
|
||||||
{
|
{
|
||||||
struct lwip_socket *s = (struct lwip_socket *)handle;
|
struct lwip_socket *s = (struct lwip_socket *)handle;
|
||||||
ip_addr_t ip_addr;
|
ip_addr_t ip_addr;
|
||||||
|
@ -694,7 +694,7 @@ static int mbed_lwip_socket_connect(nsapi_stack_t *stack, nsapi_socket_t handle,
|
||||||
return mbed_lwip_err_remap(err);
|
return mbed_lwip_err_remap(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mbed_lwip_socket_accept(nsapi_stack_t *stack, nsapi_socket_t server, nsapi_socket_t *handle, nsapi_addr_t *addr, uint16_t *port)
|
static nsapi_error_t mbed_lwip_socket_accept(nsapi_stack_t *stack, nsapi_socket_t server, nsapi_socket_t *handle, nsapi_addr_t *addr, uint16_t *port)
|
||||||
{
|
{
|
||||||
struct lwip_socket *s = (struct lwip_socket *)server;
|
struct lwip_socket *s = (struct lwip_socket *)server;
|
||||||
struct lwip_socket *ns = mbed_lwip_arena_alloc();
|
struct lwip_socket *ns = mbed_lwip_arena_alloc();
|
||||||
|
@ -718,7 +718,7 @@ static int mbed_lwip_socket_accept(nsapi_stack_t *stack, nsapi_socket_t server,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mbed_lwip_socket_send(nsapi_stack_t *stack, nsapi_socket_t handle, const void *data, unsigned size)
|
static nsapi_size_or_error_t mbed_lwip_socket_send(nsapi_stack_t *stack, nsapi_socket_t handle, const void *data, nsapi_size_t size)
|
||||||
{
|
{
|
||||||
struct lwip_socket *s = (struct lwip_socket *)handle;
|
struct lwip_socket *s = (struct lwip_socket *)handle;
|
||||||
size_t bytes_written = 0;
|
size_t bytes_written = 0;
|
||||||
|
@ -728,10 +728,10 @@ static int mbed_lwip_socket_send(nsapi_stack_t *stack, nsapi_socket_t handle, co
|
||||||
return mbed_lwip_err_remap(err);
|
return mbed_lwip_err_remap(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int)bytes_written;
|
return (nsapi_size_or_error_t)bytes_written;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mbed_lwip_socket_recv(nsapi_stack_t *stack, nsapi_socket_t handle, void *data, unsigned size)
|
static nsapi_size_or_error_t mbed_lwip_socket_recv(nsapi_stack_t *stack, nsapi_socket_t handle, void *data, nsapi_size_t size)
|
||||||
{
|
{
|
||||||
struct lwip_socket *s = (struct lwip_socket *)handle;
|
struct lwip_socket *s = (struct lwip_socket *)handle;
|
||||||
|
|
||||||
|
@ -755,7 +755,7 @@ static int mbed_lwip_socket_recv(nsapi_stack_t *stack, nsapi_socket_t handle, vo
|
||||||
return recv;
|
return recv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mbed_lwip_socket_sendto(nsapi_stack_t *stack, nsapi_socket_t handle, nsapi_addr_t addr, uint16_t port, const void *data, unsigned size)
|
static nsapi_size_or_error_t mbed_lwip_socket_sendto(nsapi_stack_t *stack, nsapi_socket_t handle, nsapi_addr_t addr, uint16_t port, const void *data, nsapi_size_t size)
|
||||||
{
|
{
|
||||||
struct lwip_socket *s = (struct lwip_socket *)handle;
|
struct lwip_socket *s = (struct lwip_socket *)handle;
|
||||||
ip_addr_t ip_addr;
|
ip_addr_t ip_addr;
|
||||||
|
@ -780,7 +780,7 @@ static int mbed_lwip_socket_sendto(nsapi_stack_t *stack, nsapi_socket_t handle,
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mbed_lwip_socket_recvfrom(nsapi_stack_t *stack, nsapi_socket_t handle, nsapi_addr_t *addr, uint16_t *port, void *data, unsigned size)
|
static nsapi_size_or_error_t mbed_lwip_socket_recvfrom(nsapi_stack_t *stack, nsapi_socket_t handle, nsapi_addr_t *addr, uint16_t *port, void *data, nsapi_size_t size)
|
||||||
{
|
{
|
||||||
struct lwip_socket *s = (struct lwip_socket *)handle;
|
struct lwip_socket *s = (struct lwip_socket *)handle;
|
||||||
struct netbuf *buf;
|
struct netbuf *buf;
|
||||||
|
@ -799,7 +799,7 @@ static int mbed_lwip_socket_recvfrom(nsapi_stack_t *stack, nsapi_socket_t handle
|
||||||
return recv;
|
return recv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mbed_lwip_setsockopt(nsapi_stack_t *stack, nsapi_socket_t handle, int level, int optname, const void *optval, unsigned optlen)
|
static nsapi_error_t mbed_lwip_setsockopt(nsapi_stack_t *stack, nsapi_socket_t handle, int level, int optname, const void *optval, unsigned optlen)
|
||||||
{
|
{
|
||||||
struct lwip_socket *s = (struct lwip_socket *)handle;
|
struct lwip_socket *s = (struct lwip_socket *)handle;
|
||||||
|
|
||||||
|
|
|
@ -25,9 +25,9 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Access to lwip through the nsapi
|
// Access to lwip through the nsapi
|
||||||
int mbed_lwip_init(emac_interface_t *emac);
|
nsapi_error_t mbed_lwip_init(emac_interface_t *emac);
|
||||||
int mbed_lwip_bringup(bool dhcp, const char *ip, const char *netmask, const char *gw);
|
nsapi_error_t mbed_lwip_bringup(bool dhcp, const char *ip, const char *netmask, const char *gw);
|
||||||
int mbed_lwip_bringdown(void);
|
nsapi_error_t mbed_lwip_bringdown(void);
|
||||||
|
|
||||||
const char *mbed_lwip_get_mac_address(void);
|
const char *mbed_lwip_get_mac_address(void);
|
||||||
char *mbed_lwip_get_ip_address(char *buf, int buflen);
|
char *mbed_lwip_get_ip_address(char *buf, int buflen);
|
||||||
|
|
Loading…
Reference in New Issue